Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
perf(cli): defer unused catalog work during command startup (#920)
morluto9a1552529889
diff --git a/src/application/binary/AnalysisSnapshotCache.test.ts b/src/application/binary/AnalysisSnapshotCache.test.tsindex 101880148..79ccfaa73 100644--- a/src/application/binary/AnalysisSnapshotCache.test.ts+++ b/src/application/binary/AnalysisSnapshotCache.test.ts@@ -10,9 +10,63 @@ import { createEvidence } from "../../domain/evidence.js";import { createEvidenceBundle } from "../../domain/evidenceBundle.js";import { ok } from "../../domain/result.js";import { createAnalysisExecution } from "../AnalysisProvider.js";-import { AnalysisSnapshotCache } from "./AnalysisSnapshotCache.js";+import type {+ AnalysisOperation,+ CapabilityDescriptor,+} from "../AnalysisProvider.js";+import {+ AnalysisSnapshotCache,+ isSnapshotCacheable,+} from "./AnalysisSnapshotCache.js";describe("analysis snapshot cache partitioning", () => {+ it.each<{+ operation: Exclude<AnalysisOperation, "health">;+ parameters: Record<string, string>;+ cacheable: boolean;+ }>([+ { operation: "list_strings", parameters: {}, cacheable: false },+ {+ operation: "list_strings",+ parameters: { document: "fixture" },+ cacheable: true,+ },+ {+ operation: "address_name",+ parameters: { document: "fixture" },+ cacheable: false,+ },+ {+ operation: "address_name",+ parameters: { document: "fixture", address: "0x1000" },+ cacheable: true,+ },+ { operation: "binary_overview", parameters: {}, cacheable: true },+ ])(+ "retains explicit document and cursor requirements for $operation",+ ({ operation, parameters, cacheable }) => {+ const descriptor: CapabilityDescriptor = {+ operation,+ provider: ANALYSIS_SNAPSHOT_PROVIDER,+ available: true,+ reason: null,+ effects: {+ mutatesArtifact: false,+ launchesProcess: false,+ mayShowUi: false,+ mayAccessNetwork: false,+ mayWriteFilesystem: false,+ changesPermissions: false,+ requiresRoot: false,+ },+ limitations: [],+ };+ expect(isSnapshotCacheable(operation, descriptor, parameters)).toBe(+ cacheable,+ );+ },+ );+it("returns detached data only from the exact provider/profile partition", () => {const cache = new AnalysisSnapshotCache();const execution = createAnalysisExecution(diff --git a/src/application/binary/AnalysisSnapshotCache.ts b/src/application/binary/AnalysisSnapshotCache.tsindex 2cb6f705f..473434542 100644--- a/src/application/binary/AnalysisSnapshotCache.ts+++ b/src/application/binary/AnalysisSnapshotCache.ts@@ -24,7 +24,7 @@ import type {AnalysisOperation,CapabilityDescriptor,} from "../AnalysisProvider.js";-import { GENERATED_MCP_TOOL_CATALOG } from "../../generatedMcpToolCatalog.js";+import { OFFICIAL_TOOL_CONTRACTS } from "../../contracts/officialToolContracts.js";const STATEFUL_OPERATIONS: ReadonlySet<AnalysisOperation> = new Set(["health",@@ -46,14 +46,12 @@ const CURSOR_DEFAULT_OPERATIONS: ReadonlySet<AnalysisOperation> = new Set([]);const DOCUMENT_SCOPED_OPERATIONS: ReadonlySet<string> = new Set(- GENERATED_MCP_TOOL_CATALOG.filter(({ kind }) => kind === "official-proxy")- .map(({ name }) => name)- .filter(- (name) =>- name !== "current_document" &&- name !== "list_documents" &&- name !== "set_current_document",- ),+ OFFICIAL_TOOL_CONTRACTS.map(({ name }) => name).filter(+ (name) =>+ name !== "current_document" &&+ name !== "list_documents" &&+ name !== "set_current_document",+ ),);/** Whether an operation is immutable and independent of provider UI state. */diff --git a/src/catalogIdentity.ts b/src/catalogIdentity.tsindex f7789d6ea..b751c4394 100644--- a/src/catalogIdentity.ts+++ b/src/catalogIdentity.ts@@ -9,26 +9,31 @@ import { CLI_COMMAND_NAMES } from "./cliCommandNames.js";export { CLI_COMMAND_NAMES } from "./cliCommandNames.js";-const toolCatalog = TOOL_CONTRACTS.map((contract) => ({- name: contract.name,- title: contract.title,- surface: contract.kind,- description: contract.description,- effects: { ...contract.effects },- annotations: contract.annotations,- input_schema: {- type: "object",- ...z.toJSONSchema(contract.inputSchema, {- unrepresentable: "any",- }),- },- output_schema: {- type: "object",- ...z.toJSONSchema(contract.outputSchema, {- unrepresentable: "any",- }),- },-})).sort((left, right) => left.name.localeCompare(right.name));+const sortedToolContracts = [...TOOL_CONTRACTS].sort((left, right) =>+ left.name.localeCompare(right.name),+);++const createToolCatalog = () =>+ sortedToolContracts.map((contract) => ({+ name: contract.name,+ title: contract.title,+ surface: contract.kind,+ description: contract.description,+ effects: { ...contract.effects },+ annotations: contract.annotations,+ input_schema: {+ type: "object",+ ...z.toJSONSchema(contract.inputSchema, {+ unrepresentable: "any",+ }),+ },+ output_schema: {+ type: "object",+ ...z.toJSONSchema(contract.outputSchema, {+ unrepresentable: "any",+ }),+ },+ }));const promptCatalog = PROMPT_CONTRACTS.map((contract) => ({name: contract.name,@@ -45,26 +50,35 @@ const digest = (value: unknown): string => {return createHash("sha256").update(encoded).digest("hex");};-/** Stable, schema-sensitive identity for every public REA surface. */-export const CATALOG_IDENTITY = {- counts: {- cli_commands: CLI_COMMAND_NAMES.length,- mcp_tools: toolCatalog.length,- mcp_prompts: promptCatalog.length,- },- digests: {- tools_sha256: digest(toolCatalog),+const createCatalogDigests = () => {+ const tools = createToolCatalog();+ return {+ tools_sha256: digest(tools),prompts_sha256: digest(promptCatalog),combined_sha256: digest({cli: CLI_COMMAND_NAMES,- tools: toolCatalog,+ tools,prompts: promptCatalog,}),+ } as const;+};++let catalogDigests: ReturnType<typeof createCatalogDigests> | undefined;++/** Stable, schema-sensitive identity; schema digests are computed on first use. */+export const CATALOG_IDENTITY = {+ counts: {+ cli_commands: CLI_COMMAND_NAMES.length,+ mcp_tools: sortedToolContracts.length,+ mcp_prompts: promptCatalog.length,+ },+ get digests() {+ return (catalogDigests ??= createCatalogDigests());},- tools: toolCatalog.map(({ name, surface, effects, annotations }) => ({+ tools: sortedToolContracts.map(({ name, kind, effects, annotations }) => ({name,- surface,- effects,+ surface: kind,+ effects: { ...effects },annotations: {read_only: annotations.readOnlyHint ?? false,destructive: annotations.destructiveHint ?? false,diff --git a/tests/boundary/mcp/serverIdentity.test.ts b/tests/boundary/mcp/serverIdentity.test.tsindex 366e50efa..2305a346e 100644--- a/tests/boundary/mcp/serverIdentity.test.ts+++ b/tests/boundary/mcp/serverIdentity.test.ts@@ -77,6 +77,17 @@ const statusCapability = (});describe("server and catalog identity", () => {+ it("retains all catalog identity fields through transport serialization and detached clones", () => {+ const serialized = JSON.parse(JSON.stringify(CATALOG_IDENTITY));+ expect(structuredClone(CATALOG_IDENTITY)).toEqual(serialized);+ expect(serialized.digests).toEqual(CATALOG_IDENTITY.digests);+ expect(serialized.tools).toHaveLength(TOOL_CONTRACTS.length);+ const identity = createServerIdentity({+ startedAt: "2026-07-13T00:00:00.000Z",+ });+ expect(JSON.parse(JSON.stringify(identity)).catalog).toEqual(serialized);+ });+it("derives package and SDK versions from canonical package metadata", async () => {const packageJson = JSON.parse(await readFile("package.json", "utf8"));const packageLock = JSON.parse(await readFile("package-lock.json", "utf8"));