feat(skill): rename skill to reverse-engineer-anything
This commit is contained in:
@@ -3,6 +3,7 @@ import type {
|
||||
SetupClient,
|
||||
SetupProviderEnvironment,
|
||||
} from "./Setup.js";
|
||||
import { PRODUCT_IDENTITY } from "../identity.js";
|
||||
|
||||
/** Build the complete setup mutation plan before approval. */
|
||||
export const setupPlan = (
|
||||
@@ -42,8 +43,9 @@ export const setupPlan = (
|
||||
? [
|
||||
{
|
||||
kind: "install_skill" as const,
|
||||
target: "~/.agents/skills/rea-analysis/SKILL.md",
|
||||
detail: "Install or update the bundled REA analysis skill.",
|
||||
target: `~/.agents/skills/${PRODUCT_IDENTITY.skillName}/SKILL.md`,
|
||||
detail:
|
||||
"Install or update the bundled REA reverse-engineering skill.",
|
||||
external: false,
|
||||
},
|
||||
]
|
||||
|
||||
@@ -1,18 +1,26 @@
|
||||
import { mkdir, readFile, rm } from "node:fs/promises";
|
||||
import { lstat, mkdir, readFile, rm } from "node:fs/promises";
|
||||
import { dirname, join } from "node:path";
|
||||
import writeFileAtomic from "write-file-atomic";
|
||||
|
||||
import { PRODUCT_IDENTITY } from "../identity.js";
|
||||
|
||||
const skillDestination = (home: string, name: string): string =>
|
||||
join(home, ".agents/skills", name, "SKILL.md");
|
||||
|
||||
const readOptionalText = async (path: string): Promise<string | undefined> => {
|
||||
try {
|
||||
return await readFile(path, "utf8");
|
||||
} catch (cause: unknown) {
|
||||
if (cause instanceof Error && "code" in cause && cause.code === "ENOENT")
|
||||
return undefined;
|
||||
throw cause;
|
||||
}
|
||||
};
|
||||
|
||||
const canonicalSkillFiles = async (
|
||||
home: string,
|
||||
): Promise<{ readonly content: string; readonly destination: string }> => ({
|
||||
destination: join(
|
||||
home,
|
||||
".agents/skills",
|
||||
PRODUCT_IDENTITY.skillName,
|
||||
"SKILL.md",
|
||||
),
|
||||
destination: skillDestination(home, PRODUCT_IDENTITY.skillName),
|
||||
content: await readFile(
|
||||
new URL(
|
||||
`../../skills/${PRODUCT_IDENTITY.skillName}/SKILL.md`,
|
||||
@@ -28,7 +36,11 @@ export const canonicalSkillNeedsInstall = async (
|
||||
): Promise<boolean> => {
|
||||
try {
|
||||
const { content, destination } = await canonicalSkillFiles(home);
|
||||
return (await readFile(destination, "utf8")) !== content;
|
||||
if ((await readOptionalText(destination)) !== content) return true;
|
||||
for (const name of PRODUCT_IDENTITY.legacySkillNames)
|
||||
if ((await readOptionalText(skillDestination(home, name))) !== undefined)
|
||||
return true;
|
||||
return false;
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
@@ -38,45 +50,80 @@ export const canonicalSkillNeedsInstall = async (
|
||||
export const installCanonicalSkill = async (
|
||||
home: string,
|
||||
): Promise<"installed" | "unchanged" | "failed"> => {
|
||||
let destination = join(
|
||||
home,
|
||||
".agents/skills",
|
||||
PRODUCT_IDENTITY.skillName,
|
||||
"SKILL.md",
|
||||
);
|
||||
let destination = skillDestination(home, PRODUCT_IDENTITY.skillName);
|
||||
let backup = `${destination}.rea.backup`;
|
||||
let original: string | undefined;
|
||||
let canonicalChanged = false;
|
||||
const removedLegacy: Array<{
|
||||
readonly content: string;
|
||||
readonly destination: string;
|
||||
}> = [];
|
||||
try {
|
||||
const canonical = await canonicalSkillFiles(home);
|
||||
destination = canonical.destination;
|
||||
backup = `${destination}.rea.backup`;
|
||||
const { content } = canonical;
|
||||
original = await readFile(destination, "utf8").catch(() => undefined);
|
||||
if (original === content) return "unchanged";
|
||||
original = await readOptionalText(destination);
|
||||
const legacy: Array<{
|
||||
readonly content: string;
|
||||
readonly destination: string;
|
||||
}> = [];
|
||||
for (const name of PRODUCT_IDENTITY.legacySkillNames) {
|
||||
const legacyDestination = skillDestination(home, name);
|
||||
const legacyContent = await readOptionalText(legacyDestination);
|
||||
if (legacyContent !== undefined) {
|
||||
if ((await lstat(dirname(legacyDestination))).isSymbolicLink())
|
||||
throw new Error("legacy skill directory is a symbolic link");
|
||||
legacy.push({ content: legacyContent, destination: legacyDestination });
|
||||
}
|
||||
}
|
||||
if (original === content && legacy.length === 0) return "unchanged";
|
||||
await mkdir(dirname(destination), { recursive: true });
|
||||
if (original !== undefined)
|
||||
if (original !== undefined && original !== content)
|
||||
await writeFileAtomic(backup, original, {
|
||||
encoding: "utf8",
|
||||
mode: 0o600,
|
||||
});
|
||||
await writeFileAtomic(destination, content, {
|
||||
encoding: "utf8",
|
||||
mode: 0o600,
|
||||
});
|
||||
canonicalChanged = original !== content;
|
||||
if (canonicalChanged)
|
||||
await writeFileAtomic(destination, content, {
|
||||
encoding: "utf8",
|
||||
mode: 0o600,
|
||||
});
|
||||
if ((await readFile(destination, "utf8")) !== content)
|
||||
throw new Error("skill readback mismatch");
|
||||
for (const legacySkill of legacy) {
|
||||
await writeFileAtomic(
|
||||
`${legacySkill.destination}.rea.backup`,
|
||||
legacySkill.content,
|
||||
{ encoding: "utf8", mode: 0o600 },
|
||||
);
|
||||
await rm(legacySkill.destination, { force: true });
|
||||
removedLegacy.push(legacySkill);
|
||||
}
|
||||
return "installed";
|
||||
} catch {
|
||||
try {
|
||||
if (original === undefined) await rm(destination, { force: true });
|
||||
else
|
||||
if (canonicalChanged && original === undefined)
|
||||
await rm(destination, { force: true });
|
||||
else if (canonicalChanged && original !== undefined)
|
||||
await writeFileAtomic(destination, original, {
|
||||
encoding: "utf8",
|
||||
mode: 0o600,
|
||||
});
|
||||
} catch {
|
||||
// The backup remains beside the skill for explicit operator recovery.
|
||||
// The canonical backup remains beside the skill for operator recovery.
|
||||
}
|
||||
for (const legacySkill of removedLegacy)
|
||||
try {
|
||||
await mkdir(dirname(legacySkill.destination), { recursive: true });
|
||||
await writeFileAtomic(legacySkill.destination, legacySkill.content, {
|
||||
encoding: "utf8",
|
||||
mode: 0o600,
|
||||
});
|
||||
} catch {
|
||||
// The legacy backup remains beside the skill for operator recovery.
|
||||
}
|
||||
return "failed";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -87,12 +87,7 @@ export const systemUninstallHost = (
|
||||
): UninstallHost => ({
|
||||
clients: () => Promise.resolve(supportedClients(home)),
|
||||
removeClient: (client) => removeClient(client, fileSystem),
|
||||
removeSkill: () =>
|
||||
removeManagedPath(
|
||||
join(home, ".agents/skills", PRODUCT_IDENTITY.skillName),
|
||||
"skill",
|
||||
fileSystem,
|
||||
),
|
||||
removeSkill: () => removeManagedSkills(home, fileSystem),
|
||||
purgeData: async () => [
|
||||
await removeManagedPath(join(home, ".rea/cache"), "cache", fileSystem),
|
||||
await removeManagedPath(join(home, ".rea/state"), "state", fileSystem),
|
||||
@@ -262,6 +257,36 @@ const removeManagedPath = async (
|
||||
}
|
||||
};
|
||||
|
||||
const removeManagedSkills = async (
|
||||
home: string,
|
||||
fileSystem: UninstallFileSystem,
|
||||
): Promise<UninstallItem> => {
|
||||
const results: UninstallItem[] = [];
|
||||
for (const name of [
|
||||
PRODUCT_IDENTITY.skillName,
|
||||
...PRODUCT_IDENTITY.legacySkillNames,
|
||||
])
|
||||
results.push(
|
||||
await removeManagedPath(
|
||||
join(home, ".agents/skills", name),
|
||||
"skill",
|
||||
fileSystem,
|
||||
),
|
||||
);
|
||||
const failed = results.find(({ status }) => status === "failed");
|
||||
if (failed !== undefined) return failed;
|
||||
const retained = results.find(({ status }) => status === "retained");
|
||||
if (retained !== undefined) return retained;
|
||||
const removed = results.filter(({ status }) => status === "removed");
|
||||
if (removed.length > 0)
|
||||
return item(
|
||||
"skill",
|
||||
"removed",
|
||||
removed.map(({ detail }) => detail).join(" "),
|
||||
);
|
||||
return item("skill", "skipped", "No managed REA skill installation exists.");
|
||||
};
|
||||
|
||||
const item = (
|
||||
name: string,
|
||||
status: UninstallItem["status"],
|
||||
|
||||
Reference in New Issue
Block a user