Skip to content

Commit dc8a19c

Browse files
committed
feat(artifacts): project typed retained inventory views
Keep complete inspection output and historical Evidence input parsing intact. Add exact path selection and graph pages with source completeness, distinct view IDs and parent provenance. Verify SDK-converted schemas, portable CLI input and session export/close/import behavior.
1 parent 16338af commit dc8a19c

13 files changed

Lines changed: 746 additions & 93 deletions

‎.agents/skills/reverse-engineer-anything/references/evidence-workflows.md‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ returned inline. When complete `inspect_binary_layout` or
1111
`inspect_analysis_view` for a summary, one section/symbol/module, or a stable
1212
page instead of repeating the producer.
1313

14+
Completed `inspect_artifact` inventory also supports a summary and
15+
`view: {kind: "inventory", collection: "occurrences", logical_paths: ["package.json", "main.js"]}`.
16+
Omit `logical_paths` to page all available occurrences; `[]` selects none.
17+
Other inventory collections are `nodes`, `edges` and
18+
`integrity_contradictions`. Keep `source_complete` separate from page exhaustion:
19+
a missing match in partial source Evidence does not establish absence. Use the
20+
returned parent Evidence ID for subsequent views and export before closing the
21+
session when the source must survive it.
22+
1423
Use `record_unknown` to track unresolved questions in the user's investigation
1524
and name the authority or environment still required. Supply supporting and
1625
contradicting evidence IDs. It updates the session registry directly.

‎docs/mcp-contracts.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,20 @@ application and semantic coverage. The result carries a digest of the selected
437437
facts. Actual serialized size determines MCP transport admission: reduce the
438438
page size or export retained Evidence if the view is too large.
439439

440+
Completed `inspect_artifact` and atomic `inventory_artifact` Evidence also
441+
support summary and inventory views. A summary reports the manifest's expected
442+
counts separately from available record counts, observed entry kinds, inventory
443+
Evidence IDs and inspection coverage. An inventory view selects `nodes`,
444+
`occurrences`, `edges`, or `integrity_contradictions`, with `offset` and `limit`
445+
defaulting to 0 and 64. For occurrences, optional `logical_paths` matches exact
446+
recorded strings: omission selects all available records; `[]` selects none.
447+
These selectors do not reopen the artifact or resolve filesystem paths.
448+
`source_complete` records whether the available inventory passes the complete
449+
graph checks. Exhausting a page from a partial source does not establish that
450+
unreturned paths are absent. Views carry their own Evidence IDs and preserve
451+
links to the original parent; complete producer output and historical inline
452+
Evidence input parsing retain their existing shapes.
453+
440454
`trace_application_feature`, `trace_javascript_semantics`,
441455
`compare_application_versions`, `compare_source_to_bundle`, and
442456
`compare_javascript_export_shapes` accept complete inline application Evidence

‎src/contracts/analysisViewToolContracts.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,33 @@ import { evidenceResultOf } from "./toolOutputSchemaPrimitives.js";
88

99
const RETAINED_EXAMPLE_ID = `ev_${"a".repeat(64)}`;
1010

11-
/** Selected views of already completed layout, JavaScript and native function Evidence. */
11+
/** Selected views of completed layout, JavaScript, native and inventory Evidence. */
1212
export const ANALYSIS_VIEW_TOOL_CONTRACTS = [
1313
{
1414
name: "inspect_analysis_view",
1515
...toolContractMetadata("inspect_analysis_view"),
1616
kind: "application",
1717
description:
18-
"Inspect selected views of completed binary-layout, JavaScript application or native analyze_function Evidence without repeating analysis. Use an exact same-session retained evidence_id or portable inline Evidence. Select a summary, layout mitigations/linkage facet, one section/symbol/module, or a stable page. Module pages include assets, bundled and source modules; use node_id for ambiguous or unavailable paths. Native views select procedure, pseudocode, assembly, basic blocks, comments, callers/callees, references, unresolved calls, referenced strings/names, native API and high-pcode. Use nonnegative offset and a positive caller-selected limit (defaults 0 and 64); pseudocode uses UTF-16 code units, other native pages use rows. Returns artifact identity, parent Evidence ID, a distinct view digest, coverage, limitations and unknowns. Actual serialized size determines MCP transport admission; choose a smaller page or export the complete retained Evidence if needed.",
18+
"Inspect selected views of completed binary-layout, JavaScript application, native analyze_function, inspect_artifact or inventory_artifact Evidence without repeating analysis. Use an exact same-session retained evidence_id or portable inline Evidence. Select a summary, layout mitigations/linkage facet, one section/symbol/module, or a stable page. Module pages include assets, bundled and source modules; use node_id for ambiguous or unavailable paths. Inventory views page nodes, occurrences, edges or integrity contradictions; occurrence logical_paths matches exact recorded strings (omitted means all available, [] means none). source_complete distinguishes complete inventories from partial source records; page exhaustion does not prove absence in a partial source. Native views select procedure, pseudocode, assembly, basic blocks, comments, callers/callees, references, unresolved calls, referenced strings/names, native API and high-pcode. Use nonnegative offset and a positive caller-selected limit (defaults 0 and 64); pseudocode uses UTF-16 code units, other native pages use rows. Returns artifact identity, parent Evidence ID, a distinct view digest, coverage, limitations and unknowns. Actual serialized size determines MCP transport admission; choose a smaller page or export the complete retained Evidence if needed.",
1919
inputSchema: inspectAnalysisViewInputSchema,
2020
outputSchema: evidenceResultOf(analysisViewResultSchema),
2121
examples: [
22+
{
23+
title: "Read exact inventory paths from retained inspection Evidence",
24+
input: {
25+
source: {
26+
kind: "retained-evidence",
27+
evidence_id: RETAINED_EXAMPLE_ID,
28+
},
29+
view: {
30+
kind: "inventory",
31+
collection: "occurrences",
32+
logical_paths: ["package.json", "main.js"],
33+
offset: 0,
34+
limit: 32,
35+
},
36+
},
37+
},
2238
{
2339
title: "Summarize retained JavaScript application Evidence",
2440
input: {

‎src/contracts/toolOutputSchemaGroups.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import {
3737
listArchitecturesSchema,
3838
} from "../domain/native/nativeInspection.js";
3939
import { artifactExtractionResultSchema } from "../domain/artifactGraph.js";
40-
import { artifactInspectionResultSchema } from "../domain/artifactInspection.js";
40+
import { artifactInspectionOutputSchema } from "../domain/artifactInspection.js";
4141
import { interfaceBuilderAnalysisSchema } from "../domain/apple/interfaceBuilderGraph.js";
4242
import { dylibResolutionResultSchema } from "../domain/apple/dylibResolution.js";
4343
import { keyedArchiveResultSchema } from "../domain/apple/keyedArchive.js";
@@ -385,7 +385,7 @@ export const nativeOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
385385

386386
/** Exact Evidence schemas for provider-neutral artifact graph operations. */
387387
export const artifactOutputSchemas: Readonly<Record<string, z.ZodObject>> = {
388-
inspect_artifact: evidenceResultOf(artifactInspectionResultSchema),
388+
inspect_artifact: evidenceResultOf(artifactInspectionOutputSchema),
389389
extract_artifact: evidenceResultOf(artifactExtractionResultSchema),
390390
decode_interface_builder: evidenceResultOf(interfaceBuilderAnalysisSchema),
391391
inspect_keyed_archive: evidenceResultOf(keyedArchiveResultSchema),

‎src/domain/analysisView/analysisView.ts‎

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ import { err, ok, type Result } from "../result.js";
1414
import type { AnalysisError } from "../analysisErrorBase.js";
1515
import { binaryLayoutSchema } from "../native/binaryLayout.js";
1616
import { functionDossierSchema } from "../hopperValues.js";
17+
import {
18+
artifactGraphManifestSchema,
19+
artifactNodeSchema,
20+
artifactOccurrenceSchema,
21+
artifactEdgeSchema,
22+
integrityContradictionSchema,
23+
} from "../artifactGraph.js";
24+
import { artifactInspectionResultSchema } from "../artifactInspection.js";
1725
import {
1826
parseOwnedJavaScriptApplicationAnalysisSteps,
1927
type JavaScriptApplicationAnalysisResult,
@@ -22,6 +30,7 @@ import { analysisInputErrorFromIssues } from "../inputIssueProjection.js";
2230
import { projectBinaryLayoutView } from "./binaryLayoutView.js";
2331
import { projectJavaScriptApplicationView } from "./javascriptApplicationView.js";
2432
import { projectNativeFunctionView } from "./nativeFunctionView.js";
33+
import { projectArtifactInventoryView } from "./artifactInventoryView.js";
2534

2635
/** Public name of the selected-view workflow. */
2736
export const INSPECT_ANALYSIS_VIEW_OPERATION = "inspect_analysis_view" as const;
@@ -102,13 +111,36 @@ const nativeViewSchema = z.strictObject({
102111
limit: z.number().int().positive().default(64),
103112
});
104113

114+
/** Original inventory records in stable order, optionally matching exact paths. */
115+
const inventoryViewSchema = z.discriminatedUnion("collection", [
116+
z.strictObject({
117+
kind: z.literal("inventory"),
118+
collection: z.literal("occurrences"),
119+
logical_paths: z
120+
.array(z.string())
121+
.optional()
122+
.describe(
123+
"Exact recorded logical paths. Omitted selects all available occurrences; an empty array selects none. This does not resolve filesystem paths.",
124+
),
125+
offset: z.number().int().nonnegative().default(0),
126+
limit: z.number().int().positive().default(64),
127+
}),
128+
z.strictObject({
129+
kind: z.literal("inventory"),
130+
collection: z.enum(["nodes", "edges", "integrity_contradictions"]),
131+
offset: z.number().int().nonnegative().default(0),
132+
limit: z.number().int().positive().default(64),
133+
}),
134+
]);
135+
105136
/** Caller-selected projection of already completed analysis Evidence. */
106137
export const analysisViewRequestSchema = z.discriminatedUnion("kind", [
107138
summaryViewSchema,
108139
facetViewSchema,
109140
itemViewSchema,
110141
pageViewSchema,
111142
nativeViewSchema,
143+
inventoryViewSchema,
112144
]);
113145

114146
/** Inline Evidence or an exact same-session retained reference. */
@@ -178,12 +210,40 @@ const javascriptSummarySchema = z.strictObject({
178210
limitation_count: z.number().int().nonnegative(),
179211
});
180212

213+
const inventorySummarySchema = z.strictObject({
214+
manifest: artifactGraphManifestSchema,
215+
available_counts: z.strictObject({
216+
nodes: z.number().int().nonnegative(),
217+
occurrences: z.number().int().nonnegative(),
218+
edges: z.number().int().nonnegative(),
219+
integrity_contradictions: z.number().int().nonnegative(),
220+
}),
221+
observed_entry_kind_counts: z.strictObject({
222+
file: z.number().int().nonnegative(),
223+
directory: z.number().int().nonnegative(),
224+
symlink: z.number().int().nonnegative(),
225+
slice: z.number().int().nonnegative(),
226+
}),
227+
source_complete: z.boolean(),
228+
inventory_evidence_ids: z.array(prefixedDigestSchema("ev")).min(1),
229+
inspection: z
230+
.strictObject({
231+
coverage: artifactInspectionResultSchema.shape.coverage,
232+
unexplored_branches:
233+
artifactInspectionResultSchema.shape.unexplored_branches,
234+
})
235+
.nullable(),
236+
limitation_count: z.number().int().nonnegative(),
237+
});
238+
181239
const viewResultBase = {
182240
parent_evidence_id: prefixedDigestSchema("ev"),
183241
parent_operation: z.enum([
184242
"inspect_binary_layout",
185243
"analyze_javascript_application",
186244
"analyze_function",
245+
"inspect_artifact",
246+
"inventory_artifact",
187247
]),
188248
parent_digest: digestSchema,
189249
view_digest: digestSchema,
@@ -198,7 +258,11 @@ export const analysisViewResultSchema = z.discriminatedUnion("kind", [
198258
z.strictObject({
199259
kind: z.literal("summary"),
200260
view: summaryViewSchema,
201-
summary: z.union([layoutSummarySchema, javascriptSummarySchema]),
261+
summary: z.union([
262+
layoutSummarySchema,
263+
javascriptSummarySchema,
264+
inventorySummarySchema,
265+
]),
202266
...viewResultBase,
203267
}),
204268
z.strictObject({
@@ -226,6 +290,22 @@ export const analysisViewResultSchema = z.discriminatedUnion("kind", [
226290
item: jsonValueSchema,
227291
...viewResultBase,
228292
}),
293+
z.strictObject({
294+
kind: z.literal("inventory"),
295+
view: inventoryViewSchema,
296+
manifest: artifactGraphManifestSchema,
297+
inventory_evidence_ids: z.array(prefixedDigestSchema("ev")).min(1),
298+
source_complete: z.boolean(),
299+
items: z.array(
300+
z.union([
301+
artifactNodeSchema,
302+
artifactOccurrenceSchema,
303+
artifactEdgeSchema,
304+
integrityContradictionSchema,
305+
]),
306+
),
307+
...viewResultBase,
308+
}),
229309
]);
230310

231311
export type AnalysisViewRequest = z.output<typeof analysisViewRequestSchema>;
@@ -262,6 +342,10 @@ export type UnsignedAnalysisView =
262342
| Omit<
263343
Extract<AnalysisViewResult, { readonly kind: "native" }>,
264344
"view_digest"
345+
>
346+
| Omit<
347+
Extract<AnalysisViewResult, { readonly kind: "inventory" }>,
348+
"view_digest"
265349
>;
266350

267351
/** Attach the content digest that must change when projected bytes change. */
@@ -307,7 +391,7 @@ const unsupportedParent = (
307391
new AnalysisUnsupportedTargetError(
308392
INSPECT_ANALYSIS_VIEW_OPERATION,
309393
parentArtifactPath(parent),
310-
`Parent Evidence operation ${JSON.stringify(parent.operation)} is not inspect_binary_layout, analyze_javascript_application or analyze_function.`,
394+
`Parent Evidence operation ${JSON.stringify(parent.operation)} does not support analysis views. Use completed binary layout, JavaScript application, native function, or artifact inventory/inspection Evidence.`,
311395
);
312396

313397
const parentArtifactPath = (parent: AnalysisViewParent): string => {
@@ -390,5 +474,12 @@ export const projectAnalysisView = (
390474
const projected = projectNativeFunctionView(parent, native.data, view);
391475
return projected.ok ? ok(sealAnalysisView(projected.value)) : projected;
392476
}
477+
if (
478+
parent.operation === "inspect_artifact" ||
479+
parent.operation === "inventory_artifact"
480+
) {
481+
const projected = projectArtifactInventoryView(parent, view);
482+
return projected.ok ? ok(sealAnalysisView(projected.value)) : projected;
483+
}
393484
return err(unsupportedParent(parent));
394485
};

0 commit comments

Comments
 (0)