diff --git a/docs/native-investigation.md b/docs/native-investigation.md index f3d5191b8c..8c710d51e5 100644 --- a/docs/native-investigation.md +++ b/docs/native-investigation.md @@ -236,6 +236,11 @@ the index retains the complete selected names, addresses, provider facts and caveats. Failure details retain at most 32 rows within 2,048 JSON-encoded UTF-8 bytes; names may be omitted to keep complete addresses and reasons. The index retains every failure and its complete observed name. +The manifest reports the procedure-inventory limitations of the current call in +`inventory_limitations`. `decompile-index.json`'s `latest_run` records that +call's filters, selected and excluded counts, and inventory limitations; older +runs remain represented only by their retained function records, so a later +inventory warning is not presented as the history of every file. Each function's `decompile-index.json` record, whatever its status, keeps the complete limitations of the observations it used. When available, `provider_source` records the source of that attempt's diff --git a/src/application/decompileDirectory/decompileAll.test.ts b/src/application/decompileDirectory/decompileAll.test.ts index f7d6de44e2..c4623c57d7 100644 --- a/src/application/decompileDirectory/decompileAll.test.ts +++ b/src/application/decompileDirectory/decompileAll.test.ts @@ -138,6 +138,7 @@ const harness = (options?: { Record >; readonly info?: "ok" | "unavailable" | "error"; + readonly listLimitations?: readonly string[]; readonly listProfile?: typeof profile; readonly subject?: boolean; readonly mismatch?: string; @@ -173,6 +174,9 @@ const harness = (options?: { { analysisProfile: options?.listProfile ?? profile, ...(options?.subject === false ? {} : { subject }), + ...(options?.listLimitations === undefined + ? {} + : { limitations: options.listLimitations }), }, ), ), @@ -379,6 +383,89 @@ describe("decompile_all manifest", () => { }); }); +describe("decompile_all inventory limitations", () => { + const directory = useOutputDirectory(); + + const readIndex = async (root: string) => + decompileDirectoryIndexSchema.parse( + JSON.parse( + await readFile(join(root, DECOMPILE_DIRECTORY_INDEX_NAME), "utf8"), + ), + ); + + it("keeps the latest selection's limitations without attaching them to historical files", async () => { + const created = await run( + harness({ listLimitations: ["first inventory limitation"] }).tools, + directory(), + { name: "Foo::", limit: 1 }, + ); + expect(created.ok).toBe(true); + if (!created.ok) throw created.error; + expect(created.value).toMatchObject({ + inventory_limitations: ["first inventory limitation"], + counts: { selected: 2, excluded: 1, requested: 1, remaining: 1 }, + }); + const firstIndex = await readIndex(directory()); + expect(firstIndex.latest_run).toEqual({ + resume: false, + selected: 2, + excluded: 1, + selection: { + name: "Foo::", + namespace: null, + address_start: null, + address_end: null, + limit: 1, + }, + inventory_limitations: ["first inventory limitation"], + }); + expect(firstIndex.limitations).toEqual([]); + expect(firstIndex.functions).toHaveLength(1); + expect(firstIndex.functions[0]?.limitations).toContain( + "terminal call may cut the body", + ); + expect(firstIndex.functions[0]?.limitations).not.toContain( + "first inventory limitation", + ); + + const resumed = await run( + harness({ listLimitations: ["second inventory limitation"] }).tools, + directory(), + { resume: true, name: "Bar::" }, + ); + expect(resumed.ok).toBe(true); + if (!resumed.ok) throw resumed.error; + expect(resumed.value).toMatchObject({ + inventory_limitations: ["second inventory limitation"], + counts: { selected: 1, excluded: 2, requested: 1, remaining: 0 }, + }); + const resumedIndex = await readIndex(directory()); + expect(resumedIndex.latest_run).toMatchObject({ + resume: true, + selected: 1, + excluded: 2, + selection: { name: "Bar::" }, + inventory_limitations: ["second inventory limitation"], + }); + expect( + resumedIndex.functions.map((record) => record.address).sort(), + ).toEqual(["0x1000", "0x3000"]); + expect( + resumedIndex.functions.every((record) => + record.limitations?.includes("terminal call may cut the body"), + ), + ).toBe(true); + expect( + resumedIndex.functions.every( + (record) => + !record.limitations?.includes("first inventory limitation") && + !record.limitations?.includes("second inventory limitation"), + ), + ).toBe(true); + expect(resumedIndex.limitations).toEqual([]); + }); +}); + describe("decompile_all external functions", () => { const directory = useOutputDirectory(); diff --git a/src/application/decompileDirectory/decompileAll.ts b/src/application/decompileDirectory/decompileAll.ts index 7b8b24fd52..cdf5f57857 100644 --- a/src/application/decompileDirectory/decompileAll.ts +++ b/src/application/decompileDirectory/decompileAll.ts @@ -119,6 +119,7 @@ export const decompileAll = async ( input, bounds.value, ); + const inventoryLimitations = loaded.value.limitations; const opened = await DecompileExport.open({ placement: placement.value, identity: loaded.value.identity, @@ -164,6 +165,19 @@ export const decompileAll = async ( indexed = await session.writeIndex({ layoutStatus: layoutStatus(input.layout), limitations, + latestRun: { + resume: input.resume, + selected: selection.procedures.length, + excluded: selection.excluded, + selection: { + name: input.name ?? null, + namespace: input.namespace ?? null, + address_start: input.address_start ?? null, + address_end: input.address_end ?? null, + limit: input.limit ?? null, + }, + inventoryLimitations, + }, }); } finally { closed = await session.close(); @@ -220,6 +234,7 @@ export const decompileAll = async ( excluded: selection.excluded, state, limitations, + inventoryLimitations, }), ); return manifest.success @@ -258,6 +273,7 @@ const loadProcedures = async ( readonly procedures: readonly SelectedProcedure[]; readonly identity: ExportIdentity; readonly unaddressed: number; + readonly limitations: readonly string[]; }, AnalysisError > @@ -287,6 +303,7 @@ const loadProcedures = async ( })), identity: identity.value, unaddressed: parsed.data.length - addressed.length, + limitations: observed.value.limitations, }); }; @@ -999,6 +1016,7 @@ const manifestOf = (input: { readonly excluded: number; readonly state: PublishState; readonly limitations: readonly string[]; + readonly inventoryLimitations: readonly string[]; }) => { const requested = input.state.written + input.state.failed + input.state.external; @@ -1026,6 +1044,7 @@ const manifestOf = (input: { provider: input.identity.provider, analysis_profile_digest: input.identity.analysisProfileDigest, target_sha256: input.identity.targetSha256, + inventory_limitations: [...input.inventoryLimitations], limitations: [...input.limitations], resume: input.input.resume, }; diff --git a/src/application/decompileDirectory/exportTree.ts b/src/application/decompileDirectory/exportTree.ts index 3954fd2ce2..4be8ea0a9a 100644 --- a/src/application/decompileDirectory/exportTree.ts +++ b/src/application/decompileDirectory/exportTree.ts @@ -205,6 +205,19 @@ export class DecompileExport { async writeIndex(input: { readonly layoutStatus: "address" | "debug_layout_unavailable"; readonly limitations: readonly string[]; + readonly latestRun: { + readonly resume: boolean; + readonly selected: number; + readonly excluded: number; + readonly selection: { + readonly name: string | null; + readonly namespace: string | null; + readonly address_start: string | null; + readonly address_end: string | null; + readonly limit: number | null; + }; + readonly inventoryLimitations: readonly string[]; + }; }): Promise> { // Appends update this owner only after journal sync; resume parses once. // Reuse those committed facts instead of re-reading and reinterpreting them. @@ -215,6 +228,13 @@ export class DecompileExport { analysis_profile_digest: this.identity.analysisProfileDigest, layout: this.identity.layout, layout_status: input.layoutStatus, + latest_run: { + resume: input.latestRun.resume, + selected: input.latestRun.selected, + excluded: input.latestRun.excluded, + selection: input.latestRun.selection, + inventory_limitations: [...input.latestRun.inventoryLimitations], + }, limitations: [...input.limitations], functions: [...this.records.values()].sort((left, right) => compareProcedureAddresses(left.address, right.address), diff --git a/src/contracts/decompileDirectory.ts b/src/contracts/decompileDirectory.ts index 38dd2b7dfc..f65d644ba1 100644 --- a/src/contracts/decompileDirectory.ts +++ b/src/contracts/decompileDirectory.ts @@ -201,6 +201,11 @@ export const decompileDirectoryManifestSchema = z .describe( "SHA-256 of the analyzed target, or null when the observation has no file subject.", ), + inventory_limitations: z + .array(z.string()) + .describe( + "Limitations reported by this call's procedure inventory. They describe the selection that produced this run, not every historical function record in the directory.", + ), limitations: z .array(z.string()) .describe("Limits of this export. Pseudocode is not included."), @@ -318,6 +323,28 @@ export const decompileJournalLineSchema = z.discriminatedUnion("kind", [ decompileJournalFunctionSchema, ]); +/** One caller selection, retained to distinguish the latest run from older records. */ +const decompileSelectionSchema = z.strictObject({ + name: z.string().nullable(), + namespace: z.string().nullable(), + address_start: z.string().nullable(), + address_end: z.string().nullable(), + limit: z.number().int().min(1).nullable(), +}); + +/** + * Facts owned by the run that last rewrote this index. Inventory limitations + * and filters describe that run; older runs remain represented only by their + * retained function records. + */ +const decompileLatestRunSchema = z.strictObject({ + resume: z.boolean(), + selected: countSchema("Functions matching this run's filter."), + excluded: countSchema("Inventory functions excluded by this run's filter."), + selection: decompileSelectionSchema, + inventory_limitations: z.array(z.string()), +}); + /** Index rewritten from the journal at the end of a call. */ export const decompileDirectoryIndexSchema = z.strictObject({ version: z.literal(DECOMPILE_DIRECTORY_VERSION), @@ -326,6 +353,11 @@ export const decompileDirectoryIndexSchema = z.strictObject({ analysis_profile_digest: digestSchema.nullable(), layout: layoutSchema, layout_status: z.enum(["address", "debug_layout_unavailable"]), + latest_run: decompileLatestRunSchema + .optional() + .describe( + "Selection and inventory limitations owned by the run that last rewrote this index. Absent in indexes written before this field existed.", + ), limitations: z.array(z.string()), functions: z.array(decompileDirectoryFunctionSchema), }); diff --git a/tests/boundary/filesystem/decompileExportCreate.test.ts b/tests/boundary/filesystem/decompileExportCreate.test.ts index 732e5a24fc..238a279e7e 100644 --- a/tests/boundary/filesystem/decompileExportCreate.test.ts +++ b/tests/boundary/filesystem/decompileExportCreate.test.ts @@ -277,6 +277,19 @@ describe("decompile journal ownership", () => { await opened.value.writeIndex({ layoutStatus: "address", limitations: [], + latestRun: { + resume: false, + selected: 1, + excluded: 0, + selection: { + name: null, + namespace: null, + address_start: null, + address_end: null, + limit: null, + }, + inventoryLimitations: [], + }, }) ).ok, ).toBe(true);