mirror of
https://github.com/morluto/rea.git
synced 2026-11-14 10:43:30 +00:00
* refactor: prune internal seams and preserve configuration ownership * fix(setup): keep YAML aliases and inherited registration settings on refresh - Reuse an unchanged YAML collection only while every alias in it still resolves after the edit; otherwise rebuild it so the alias becomes its value. A sibling anchor replaced or moved in the same refresh no longer leaves an unresolved alias in Hermes or Goose output. - Keep a connection selector whose existing value already chooses stdio (for example an inherited Hermes transport: stdio) instead of superseding it; remote selectors are still replaced. Explicit stdio selectors are therefore no longer rewritten (Kimi expectation updated). - When the whole Hermes registration is inherited through a merge, override it with that merge and write only the changed fields. * fix(setup): edit registration fields whose YAML key is an alias A key written as an alias to a string scalar (for example *field with field: &field env) was treated as a source-only key, so any change to its value was refused in Hermes and Goose. Resolve such keys to their string, keep the aliased spelling while its anchor survives the edit, and write the plain key when the same edit rebuilds the anchor. * test(process): bound cleanup-boundary waits and always release gates Both cancellation tests awaited a bare started promise and released their gates only on success, so a missed boundary waited for the outer deadline and could leave cleanup parked. Use awaitAcknowledgement and release and join the cleanup in finally. * fix(setup): repair only aliases an edit leaves unresolved Replace the pre-edit alias survival guess, which expanded aliases to sibling anchors that survive unchanged, with an exact repair: record what each alias in the replaced value resolves to, write the edit, then replace only aliases left without a preceding anchor by that value. - Keep an aliased key's source position, so its anchor stays ahead of later aliases. - Treat an aliased key as its string only when no other key in the map resolves to the same string; an ambiguous one stays guarded. - Override an inherited Hermes registration only when the requested entry keeps every inherited field, so an explicit replacement can drop remote selectors. * fix(setup): repair aliases whose binding an edit changes, keeping comments An alias whose own anchor was removed could resolve to an earlier anchor with the same name and silently change value. Record the node each alias resolved to and repair any alias that no longer resolves to that node. Carry the alias's comments and spacing onto the repaired value. * test(setup): split the Hermes anchor and merge refresh cases * fix(setup): refuse removing an overridden key its merge would restore The merge-retention check skipped keys the mapping also overrides, so dropping such a key (for example a remote url during an explicit stdio replacement) let the retained merge restore it. Check removal before skipping overridden keys, so the edit is refused with the existing message instead of producing a registration that cannot be applied.
216 lines
7.4 KiB
JavaScript
216 lines
7.4 KiB
JavaScript
import { mkdir, readFile, readdir, rm, stat } from "node:fs/promises";
|
|
import { dirname, join } from "node:path";
|
|
|
|
import { ensureGeneratedFile } from "./generated-file.mjs";
|
|
|
|
// Identity fields follow the shared plugin manifest checked for local Cursor
|
|
// publication (name, release version, repository, skill, and icon). The
|
|
// Marketplace checkout has no dist/, so the server is the pinned npm command
|
|
// instead of the bundled launcher.
|
|
const CURSOR_PLUGIN_MANIFEST = ".cursor-plugin/plugin.json";
|
|
const CURSOR_PLUGIN_MCP = "mcp.json";
|
|
const AUTHORED_SKILL_DIRECTORY = ".agents/skills/reverse-engineer-anything";
|
|
const CURSOR_PLUGIN_SKILLS = ".cursor-plugin/skills";
|
|
const CURSOR_PLUGIN_SKILL = "reverse-engineer-anything";
|
|
const CURSOR_PLUGIN_LOGO = "assets/rea-plugin.png";
|
|
const CURSOR_PLUGIN_REPOSITORY = "https://github.com/morluto/rea";
|
|
const GENERATE_COMMAND = "node scripts/generate-cursor-plugin-skill.mjs";
|
|
const INSTALL_LINK_MARKERS = ["install-mcp", "deeplink/mcp", "mcp-install"];
|
|
|
|
const failure = (code, detail) => {
|
|
const error = new Error(`${code}: ${detail}`);
|
|
error.code = code;
|
|
return error;
|
|
};
|
|
|
|
const cursorServerArgs = (version) => ["-y", `rea-agents@${version}`, "mcp"];
|
|
|
|
/** Relative file inventory for one skill directory, in stable order. */
|
|
const cursorPluginSkillPaths = async (directory, prefix = "") => {
|
|
const paths = [];
|
|
let entries;
|
|
try {
|
|
entries = await readdir(directory, { withFileTypes: true });
|
|
} catch (cause) {
|
|
if (cause?.code === "ENOENT") return null;
|
|
throw cause;
|
|
}
|
|
for (const entry of entries.sort((left, right) =>
|
|
left.name < right.name ? -1 : left.name > right.name ? 1 : 0,
|
|
)) {
|
|
const relativePath = prefix === "" ? entry.name : `${prefix}/${entry.name}`;
|
|
if (entry.isDirectory())
|
|
paths.push(
|
|
...(await cursorPluginSkillPaths(
|
|
join(directory, entry.name),
|
|
relativePath,
|
|
)),
|
|
);
|
|
else if (entry.isFile()) paths.push(relativePath);
|
|
else
|
|
throw failure(
|
|
"cursor_plugin_skill_inventory",
|
|
`Skill bundle requires regular files or directories: ${relativePath}`,
|
|
);
|
|
}
|
|
return paths;
|
|
};
|
|
|
|
const skillFrontmatter = (content) => {
|
|
const normalized = content.replaceAll("\r\n", "\n");
|
|
if (!normalized.startsWith("---\n")) return null;
|
|
const closing = normalized.indexOf("\n---\n", 4);
|
|
if (closing === -1) return null;
|
|
const fields = {};
|
|
for (const line of normalized.slice(4, closing).split("\n")) {
|
|
const separator = line.indexOf(":");
|
|
if (separator === -1) continue;
|
|
const key = line.slice(0, separator).trim();
|
|
const value = line.slice(separator + 1).trim();
|
|
if (key !== "" && fields[key] === undefined) fields[key] = value;
|
|
}
|
|
return fields;
|
|
};
|
|
|
|
/**
|
|
* Structured differences between the Cursor plugin declaration and the
|
|
* package version it must launch. Empty means the manifest, server pin,
|
|
* logo, and skill frontmatter agree.
|
|
*/
|
|
export const cursorPluginBundleIssues = ({
|
|
manifest,
|
|
mcp,
|
|
packageVersion,
|
|
logoExists,
|
|
skillNames,
|
|
skillFrontmatter: frontmatter,
|
|
}) => {
|
|
const issues = [];
|
|
const add = (field) => issues.push({ field });
|
|
if (manifest?.name !== "rea") add("name");
|
|
if (manifest?.version !== packageVersion) add("version");
|
|
if (typeof manifest?.description !== "string" || manifest.description === "")
|
|
add("description");
|
|
if (typeof manifest?.author?.name !== "string" || manifest.author.name === "")
|
|
add("author.name");
|
|
if (manifest?.repository !== CURSOR_PLUGIN_REPOSITORY) add("repository");
|
|
if (typeof manifest?.license !== "string" || manifest.license === "")
|
|
add("license");
|
|
if (
|
|
!Array.isArray(manifest?.keywords) ||
|
|
manifest.keywords.length === 0 ||
|
|
manifest.keywords.some((keyword) => typeof keyword !== "string")
|
|
)
|
|
add("keywords");
|
|
if (manifest?.skills !== CURSOR_PLUGIN_SKILLS) add("skills");
|
|
if (manifest?.logo !== CURSOR_PLUGIN_LOGO) add("logo");
|
|
if (Object.hasOwn(manifest ?? {}, "mcpServers")) add("mcpServers");
|
|
if (logoExists !== true) add("logo.file");
|
|
const server = mcp?.mcpServers?.rea;
|
|
if (
|
|
server?.command !== "npx" ||
|
|
JSON.stringify(server?.args) !==
|
|
JSON.stringify(cursorServerArgs(packageVersion))
|
|
)
|
|
add("mcp.args");
|
|
if (
|
|
!Array.isArray(skillNames) ||
|
|
skillNames.length !== 1 ||
|
|
skillNames[0] !== CURSOR_PLUGIN_SKILL
|
|
)
|
|
add("skills.entries");
|
|
if (frontmatter?.name !== CURSOR_PLUGIN_SKILL) add("skill.name");
|
|
if (
|
|
typeof frontmatter?.description !== "string" ||
|
|
frontmatter.description === ""
|
|
)
|
|
add("skill.description");
|
|
return issues;
|
|
};
|
|
|
|
/** Copy the authored skill into the Marketplace plugin tree, or fail when it drifted. */
|
|
export const syncCursorPluginSkill = async ({ root, check }) => {
|
|
const sourceRoot = join(root, AUTHORED_SKILL_DIRECTORY);
|
|
const outputRoot = join(root, CURSOR_PLUGIN_SKILLS, CURSOR_PLUGIN_SKILL);
|
|
const sourcePaths = await cursorPluginSkillPaths(sourceRoot);
|
|
if (sourcePaths === null)
|
|
throw failure(
|
|
"cursor_plugin_skill_inventory",
|
|
`Authored skill is missing: ${AUTHORED_SKILL_DIRECTORY}`,
|
|
);
|
|
if (!check) await rm(outputRoot, { recursive: true, force: true });
|
|
for (const relativePath of sourcePaths) {
|
|
const source = (
|
|
await readFile(join(sourceRoot, relativePath), "utf8")
|
|
).replaceAll("\r\n", "\n");
|
|
if (!check)
|
|
await mkdir(dirname(join(outputRoot, relativePath)), { recursive: true });
|
|
try {
|
|
await ensureGeneratedFile({
|
|
path: join(outputRoot, relativePath),
|
|
source,
|
|
check,
|
|
generateCommand: GENERATE_COMMAND,
|
|
});
|
|
} catch (cause) {
|
|
throw failure(
|
|
"cursor_plugin_skill_stale",
|
|
cause instanceof Error ? cause.message : String(cause),
|
|
);
|
|
}
|
|
}
|
|
const outputPaths = await cursorPluginSkillPaths(outputRoot);
|
|
if (
|
|
outputPaths === null ||
|
|
JSON.stringify(outputPaths) !== JSON.stringify(sourcePaths)
|
|
)
|
|
throw failure(
|
|
"cursor_plugin_skill_inventory",
|
|
"Cursor plugin skill inventory drifted; run node scripts/generate-cursor-plugin-skill.mjs",
|
|
);
|
|
};
|
|
|
|
/** Read the committed plugin and report structured contract issues. */
|
|
export const inspectCursorPluginBundle = async (root) => {
|
|
const manifest = JSON.parse(
|
|
await readFile(join(root, CURSOR_PLUGIN_MANIFEST), "utf8"),
|
|
);
|
|
const mcp = JSON.parse(await readFile(join(root, CURSOR_PLUGIN_MCP), "utf8"));
|
|
const packageJson = JSON.parse(
|
|
await readFile(join(root, "package.json"), "utf8"),
|
|
);
|
|
const logoExists = await stat(join(root, CURSOR_PLUGIN_LOGO))
|
|
.then((metadata) => metadata.isFile())
|
|
.catch((cause) => {
|
|
if (cause?.code === "ENOENT") return false;
|
|
throw cause;
|
|
});
|
|
const skillDirectory = join(root, CURSOR_PLUGIN_SKILLS);
|
|
const skillNames = await readdir(skillDirectory);
|
|
const skillContent = await readFile(
|
|
join(skillDirectory, CURSOR_PLUGIN_SKILL, "SKILL.md"),
|
|
"utf8",
|
|
);
|
|
return {
|
|
manifest,
|
|
mcp,
|
|
packageVersion: packageJson.version,
|
|
issues: cursorPluginBundleIssues({
|
|
manifest,
|
|
mcp,
|
|
packageVersion: packageJson.version,
|
|
logoExists,
|
|
skillNames,
|
|
skillFrontmatter: skillFrontmatter(skillContent),
|
|
}),
|
|
};
|
|
};
|
|
|
|
/** MCP-only install links omit the skill, so Marketplace docs must not carry them. */
|
|
export const cursorMarketplaceInstallLinkIssues = (documents) =>
|
|
documents.flatMap(({ path, text }) =>
|
|
INSTALL_LINK_MARKERS.filter((marker) => text.includes(marker)).map(
|
|
(marker) => ({ path, marker }),
|
|
),
|
|
);
|