Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(setup): inspect installed skill identity for unqualified doctor
morlutoba33c706d26b
diff --git a/src/application/Doctor.ts b/src/application/Doctor.tsindex c1e465a5e..40b9cbadd 100644--- a/src/application/Doctor.ts+++ b/src/application/Doctor.ts@@ -108,8 +108,9 @@ export interface DoctorHost {/** Validated provider settings preserved by setup, independent of readiness. */providerRegistrationEnvironment?(): Readonly<Record<string, string>>;installationPaths?(): Promise<readonly string[]>;+ /** Undefined checks installed skill roots; explicit selections stay scoped. */installedSkillIdentity?(- clientIds: readonly string[],+ clientIds: readonly string[] | undefined,): Promise<InstalledSkillIdentity | undefined>;close?(): Promise<string | undefined>;clientRegistrations?(): Promise<readonly ClientRegistrationStatus[]>;@@ -292,9 +293,7 @@ const collectDoctorIdentity = async (const registrations = (await host.clientRegistrations?.()) ?? [];const skillClientIds =scope.skill_clients ??- (scope.mode === "audit-wide"- ? registrations.map(({ client }) => client)- : scope.clients);+ (scope.clients.length > 0 ? scope.clients : undefined);const installedSkillIdentity =await host.installedSkillIdentity?.(skillClientIds);const skillAligned = skillIdentityAligned(installedSkillIdentity);diff --git a/src/application/SetupSkill.ts b/src/application/SetupSkill.tsindex 7dd28dee0..eb7b4b138 100644--- a/src/application/SetupSkill.ts+++ b/src/application/SetupSkill.ts@@ -361,6 +361,7 @@ const canonicalSkillFiles = async (interface CanonicalSkillInspection {readonly canonical: boolean;readonly manifest: string | undefined;+ readonly installedDestination: boolean;}interface SkillInspectionFailure {@@ -372,7 +373,7 @@ interface SkillInspectionFailure {const inspectCanonicalSkill = async (home: string,- clientIds: readonly string[],+ clientIds: readonly string[] | undefined,environment: Readonly<NodeJS.ProcessEnv>,platform: NodeJS.Platform,resources?: ArtifactResourceScope,@@ -383,7 +384,10 @@ const inspectCanonicalSkill = async (environment,platform,);- const issues = [...(await skillDirectoryIssues(destinations))];+ const issues =+ clientIds === undefined+ ? []+ : [...(await skillDirectoryIssues(destinations))];if (issues.length > 0)return err({_tag: "SkillInspectionFailure",@@ -394,7 +398,21 @@ const inspectCanonicalSkill = async (let canonical = true;let manifest: string | undefined;let failureCause: unknown;- for (const { path: root } of destinations) {+ let installedDestination = false;+ for (const destination of destinations) {+ const { path: root } = destination;+ const pathIssues =+ clientIds === undefined ? await skillDirectoryIssues([destination]) : [];+ if (pathIssues.length > 0) {+ issues.push(...pathIssues);+ if (failureCause === undefined) failureCause = pathIssues;+ installedDestination = true;+ canonical = false;+ continue;+ }+ let rootCanonical = true;+ let rootHasFiles = false;+ const rootIssues: SkillPathIssue[] = [];for (const relativePath of MANAGED_SKILL_FILES) {const destination = join(root, relativePath);let original: SkillFileState | undefined;@@ -406,27 +424,34 @@ const inspectCanonicalSkill = async (cause instanceof ArtifactReaderFailure)throw cause;- issues.push({+ rootIssues.push({path: destination,kind: "unreadable",detail: causeReason(cause),});- if (issues.length === 1) failureCause = cause;- canonical = false;+ if (failureCause === undefined) failureCause = cause;+ rootCanonical = false;+ rootHasFiles = true;continue;}+ if (original !== undefined) rootHasFiles = true;if (relativePath === "SKILL.md" && manifest === undefined)manifest = original?.bytes.toString("utf8");// A mismatch settles freshness, but not coverage of later read failures.- if (original === undefined) canonical = false;- else if (canonical) {+ if (original === undefined) rootCanonical = false;+ else if (rootCanonical) {const content = await canonicalSkillContent(relativePath);- canonical = original.bytes.equals(Buffer.from(content, "utf8"));+ rootCanonical = original.bytes.equals(Buffer.from(content, "utf8"));}}+ if (clientIds !== undefined || rootHasFiles || rootIssues.length > 0) {+ installedDestination = true;+ canonical = canonical && rootCanonical;+ issues.push(...rootIssues);+ }}return issues.length === 0- ? ok({ canonical, manifest })+ ? ok({ canonical, manifest, installedDestination }): err({_tag: "SkillInspectionFailure",issues,@@ -604,7 +629,7 @@ export const installCanonicalSkill = async (/** Read installed skill metadata and compare every managed location. */export const readInstalledSkillIdentity = async (home: string,- clientIds: readonly string[],+ clientIds: readonly string[] | undefined,environment: Readonly<NodeJS.ProcessEnv> = {},platform: NodeJS.Platform = process.platform,resources?: ArtifactResourceScope,@@ -616,6 +641,7 @@ export const readInstalledSkillIdentity = async (platform,resources,);+ if (inspection.ok && !inspection.value.installedDestination) return undefined;const content = inspection.ok? inspection.value.manifest: inspection.error.manifest;diff --git a/tests/acceptance/setup/unqualifiedDoctorSkill.test.ts b/tests/acceptance/setup/unqualifiedDoctorSkill.test.tsnew file mode 100644index 000000000..014467dc3--- /dev/null+++ b/tests/acceptance/setup/unqualifiedDoctorSkill.test.ts@@ -0,0 +1,121 @@+import { mkdir, readFile, writeFile } from "node:fs/promises";+import { dirname, join } from "node:path";+import { expect } from "vitest";++import { PRODUCT_IDENTITY } from "../../../src/identity.js";+import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";+import { cliTest } from "../../support/cli/cliFixture.js";++cliTest(+ "unqualified doctor checks the installed managed skill and preserves its files",+ async ({ cli }) => {+ const home = await createTestTempDirectory("rea-unqualified-doctor-skill-");+ const skill = join(+ home,+ ".claude/skills/reverse-engineer-anything/SKILL.md",+ );+ const run = (arguments_: readonly string[]) =>+ cli.run({+ arguments: [...arguments_, "--json"],+ cwd: home,+ environment: { HOME: home, USERPROFILE: home },+ });++ const install = await run([+ "setup",+ "--skill-client",+ "claude_code",+ "--yes",+ ]);+ expect(install.exitCode, install.stdout).toBe(0);+ const original = await readFile(skill);++ const skillCheck = await run(["doctor", "--skill"]);+ expect(skillCheck.exitCode, skillCheck.stdout).toBe(0);+ expect(skillCheck.json).toMatchObject({+ healthy: true,+ identity: {+ skill: {+ state: "aligned",+ installed_version: PRODUCT_IDENTITY.skillVersion,+ installed_tool_count: expect.any(Number),+ },+ },+ });+ expect(await readFile(skill)).toEqual(original);++ const audit = await run(["doctor"]);+ expect(audit.json).toMatchObject({+ identity: {+ skill: {+ state: "aligned",+ installed_version: PRODUCT_IDENTITY.skillVersion,+ installed_tool_count: expect.any(Number),+ },+ },+ });+ expect(await readFile(skill)).toEqual(original);++ await mkdir(join(home, ".cursor"));+ const withMarker = await run(["doctor"]);+ expect(withMarker.json).toMatchObject({+ identity: {+ skill: {+ state: "aligned",+ installed_version: PRODUCT_IDENTITY.skillVersion,+ installed_tool_count: expect.any(Number),+ },+ },+ });+ expect(await readFile(skill)).toEqual(original);++ await writeFile(+ skill,+ Buffer.concat([original, Buffer.from("\nlocal edit\n")]),+ );+ const changed = await run(["doctor", "--skill"]);+ expect(changed.exitCode).toBe(1);+ expect(changed.json).toMatchObject({+ healthy: false,+ identity: { skill: { state: "stale" } },+ });++ const emptyHome = await createTestTempDirectory(+ "rea-unqualified-doctor-empty-",+ );+ const empty = await cli.run({+ arguments: ["doctor", "--skill", "--json"],+ cwd: emptyHome,+ environment: { HOME: emptyHome, USERPROFILE: emptyHome },+ });+ expect(empty.exitCode).toBe(1);+ expect(empty.json).toMatchObject({+ healthy: false,+ identity: { skill: { state: "missing" } },+ });++ const foreignHome = await createTestTempDirectory(+ "rea-unqualified-doctor-foreign-skill-",+ );+ const foreignSkill = join(+ foreignHome,+ ".claude/skills/reverse-engineer-anything/SKILL.md",+ );+ const foreignBytes = Buffer.from(+ "---\nname: another-skill\n---\nA caller-owned workflow.\n",+ );+ await mkdir(dirname(foreignSkill), { recursive: true });+ await writeFile(foreignSkill, foreignBytes);+ const foreign = await cli.run({+ arguments: ["doctor", "--skill", "--json"],+ cwd: foreignHome,+ environment: { HOME: foreignHome, USERPROFILE: foreignHome },+ });+ expect(foreign.exitCode).toBe(1);+ expect(foreign.json).toMatchObject({+ healthy: false,+ identity: { skill: { state: "stale", installed_version: null } },+ });+ expect(await readFile(foreignSkill)).toEqual(foreignBytes);+ },+);