mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 14:01:00 +00:00
refactor(mcp): share first collection page defaults (#16538)
* refactor(mcp): share first collection page defaults * fix(mcp): preserve firmware continuation collections
This commit is contained in:
1 parent
fb56a26b0b
commit
103acfbbbb
2 files changed
+82
-66
No files matched your search
+51
-66
@@ -81,70 +81,55 @@ const retainedEvidenceContinuation = (
|
||||
);
|
||||
};
|
||||
|
||||
const firstPage = (kind: string, collection?: string): JsonValue => ({
|
||||
kind,
|
||||
...(collection === undefined ? {} : { collection }),
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
});
|
||||
|
||||
/** The first page an owner offers when its complete retained result does not fit. */
|
||||
const ownerFirstPage = (evidence: Evidence): JsonValue | undefined =>
|
||||
evidence.operation === "trace_web_source_location"
|
||||
? { kind: "source-location", collection: "matches", offset: 0 }
|
||||
: evidence.operation === "analyze_function" ||
|
||||
evidence.operation === "procedure_pseudo_code"
|
||||
? { kind: "native", facet: "pseudocode", offset: 0 }
|
||||
: evidence.operation === "inspect_native_instruction"
|
||||
? {
|
||||
kind: "native-instruction-references",
|
||||
collection: "incoming_references",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
}
|
||||
: evidence.operation === "trace_application_feature"
|
||||
? { kind: "feature-trace", collection: "paths", offset: 0, limit: 64 }
|
||||
: evidence.operation === "batch_decompile"
|
||||
? {
|
||||
kind: "batch-decompile",
|
||||
collection: "items",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
}
|
||||
: evidence.operation === "inspect_esp_nvs"
|
||||
? {
|
||||
kind: "esp-nvs",
|
||||
collection: "entries",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
}
|
||||
: evidence.operation === "inspect_firmware_mmio"
|
||||
? {
|
||||
kind: "firmware-mmio",
|
||||
collection: "accesses",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
}
|
||||
: evidence.operation === "inspect_firmware_vector_table"
|
||||
? {
|
||||
kind: "firmware-vector-table",
|
||||
collection: (() => {
|
||||
const arch = (
|
||||
evidence.normalized_result as {
|
||||
architecture?: unknown;
|
||||
} | null
|
||||
)?.architecture;
|
||||
if (arch === "riscv") return "riscv_slots";
|
||||
if (arch === "arm-a-r") return "arm_ar_slots";
|
||||
if (arch === "avr") return "avr_slots";
|
||||
if (arch === "m68k") return "m68k_entries";
|
||||
return "arm_entries";
|
||||
})(),
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
}
|
||||
: evidence.operation === "inspect_labview_artifact"
|
||||
? {
|
||||
kind: "labview-artifact",
|
||||
collection: "blocks",
|
||||
offset: 0,
|
||||
limit: 64,
|
||||
}
|
||||
: isNativeInventoryOperation(evidence.operation)
|
||||
? { kind: "native-inventory", offset: 0, limit: 64 }
|
||||
: isNativeObservationOperation(evidence.operation)
|
||||
? { kind: "native-observation", offset: 0, limit: 64 }
|
||||
: undefined;
|
||||
const ownerFirstPage = (evidence: Evidence): JsonValue | undefined => {
|
||||
switch (evidence.operation) {
|
||||
case "trace_web_source_location":
|
||||
return { kind: "source-location", collection: "matches", offset: 0 };
|
||||
case "analyze_function":
|
||||
case "procedure_pseudo_code":
|
||||
return { kind: "native", facet: "pseudocode", offset: 0 };
|
||||
case "inspect_native_instruction":
|
||||
return firstPage("native-instruction-references", "incoming_references");
|
||||
case "trace_application_feature":
|
||||
return firstPage("feature-trace", "paths");
|
||||
case "batch_decompile":
|
||||
return firstPage("batch-decompile", "items");
|
||||
case "inspect_esp_nvs":
|
||||
return firstPage("esp-nvs", "entries");
|
||||
case "inspect_firmware_mmio":
|
||||
return firstPage("firmware-mmio", "accesses");
|
||||
case "inspect_firmware_vector_table": {
|
||||
const { architecture } =
|
||||
(evidence.normalized_result as { architecture?: unknown } | null) ?? {};
|
||||
const kind = "firmware-vector-table";
|
||||
switch (architecture) {
|
||||
case "riscv":
|
||||
return firstPage(kind, "riscv_slots");
|
||||
case "arm-a-r":
|
||||
return firstPage(kind, "arm_ar_slots");
|
||||
case "avr":
|
||||
return firstPage(kind, "avr_slots");
|
||||
case "m68k":
|
||||
return firstPage(kind, "m68k_entries");
|
||||
default:
|
||||
return firstPage(kind, "arm_entries");
|
||||
}
|
||||
}
|
||||
case "inspect_labview_artifact":
|
||||
return firstPage("labview-artifact", "blocks");
|
||||
default:
|
||||
if (isNativeInventoryOperation(evidence.operation))
|
||||
return firstPage("native-inventory");
|
||||
if (isNativeObservationOperation(evidence.operation))
|
||||
return firstPage("native-observation");
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
@@ -329,6 +329,37 @@ describe("oversized Evidence MCP retention", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it.each([
|
||||
["accesses", "armv7-m"],
|
||||
["arm_entries", "armv7-m"],
|
||||
["riscv_slots", "riscv"],
|
||||
["arm_ar_slots", "arm-a-r"],
|
||||
["avr_slots", "avr"],
|
||||
["m68k_entries", "m68k"],
|
||||
])(
|
||||
"pages oversized firmware Evidence via %s (%s)",
|
||||
(collection, architecture) => {
|
||||
const mmio = collection === "accesses";
|
||||
const operation = mmio
|
||||
? "inspect_firmware_mmio"
|
||||
: "inspect_firmware_vector_table";
|
||||
const kind = mmio ? "firmware-mmio" : "firmware-vector-table";
|
||||
const evidence = createEvidence(unknownTarget("not-observed"), provider, {
|
||||
operation,
|
||||
parameters: {},
|
||||
result: { architecture, fixture: "x".repeat(MINIMUM_RESPONSE_BYTES) },
|
||||
});
|
||||
const retained = createToolResultDelivery(
|
||||
MINIMUM_RESPONSE_BYTES,
|
||||
).toEvidenceToolResult(evidence, toolContract(operation), ok("added"));
|
||||
expect(retained.isError).toBe(true);
|
||||
expect(retained.structuredContent).toHaveProperty(
|
||||
"error.details.reported_limits.continuation.arguments.view",
|
||||
{ kind, collection, limit: 64, offset: 0 },
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("does not claim retention without a recording acknowledgment", () => {
|
||||
const evidence = createEvidence(unknownTarget("not-observed"), provider, {
|
||||
operation: "procedure_pseudo_code",
|
||||
|
||||
Reference in new issue
Block a user