{"version":3,"file":"retrieve-evidence.d.ts","sourceRoot":"","sources":["../../../src/core/tools/retrieve-evidence.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,KAAK,MAAM,EAAQ,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAQ9E,QAAA,MAAM,sBAAsB;;;;EAiB1B,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,OAAO,sBAAsB,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,eAAe,GAAG,SAAS,CAAC,OAAO,sBAAsB,CAAC,CA4E7G;AAED,2FAA2F;AAC3F,eAAO,MAAM,oBAAoB,EAAE,SAAS,CAAC,OAAO,sBAAsB,CAEzE,CAAC","sourcesContent":["import type { AgentTool } from \"@apholdings/jensen-agent-core\";\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport type { EvidenceArchive } from \"../context-runtime/evidence-archive.js\";\nimport { InMemoryEvidenceArchive } from \"../context-runtime/evidence-archive.js\";\nimport {\n\tDEFAULT_EVIDENCE_PAGE_CHARS,\n\tMAX_EVIDENCE_PAGE_CHARS,\n\tretrieveEvidencePage,\n} from \"../context-runtime/evidence-retrieval.js\";\n\nconst retrieveEvidenceSchema = Type.Object({\n\tevidenceId: Type.String({\n\t\tdescription:\n\t\t\t'Evidence ID of the archived artifact to retrieve (as shown in an <evidence ref=\"...\"/> or checkpoint evidence-refs entry)',\n\t}),\n\toffset: Type.Optional(\n\t\tType.Number({\n\t\t\tminimum: 0,\n\t\t\tdescription: \"0-based character offset to start reading from. Default 0.\",\n\t\t}),\n\t),\n\tlimit: Type.Optional(\n\t\tType.Number({\n\t\t\tminimum: 1,\n\t\t\tdescription: `Maximum characters to return. Default ${DEFAULT_EVIDENCE_PAGE_CHARS}, hard cap ${MAX_EVIDENCE_PAGE_CHARS}.`,\n\t\t}),\n\t),\n});\n\nexport type RetrieveEvidenceInput = Static<typeof retrieveEvidenceSchema>;\n\n/**\n * Model-facing capability to page an archived cold-evidence artifact back into\n * hot context. The returned content is ordinary untrusted DATA (it was already\n * redacted at archive time), never privileged instructions, and never completion\n * authority.\n */\nexport function createRetrieveEvidenceTool(archive: EvidenceArchive): AgentTool<typeof retrieveEvidenceSchema> {\n\treturn {\n\t\tname: \"retrieve_evidence\",\n\t\tlabel: \"retrieve_evidence\",\n\t\tdescription:\n\t\t\t\"Retrieve a bounded, integrity-verified page of an archived evidence artifact by its evidence ID. \" +\n\t\t\t'Use this when an <evidence ref=\"...\"/> or checkpoint evidence reference contains a fact you need that is no longer in the working context. ' +\n\t\t\t\"Returns exact archived content (secrets already redacted), a character range, and whether more content exists; use offset=end to page forward. \" +\n\t\t\t\"Retrieving evidence only reads data — it never certifies that a test passed or that work is complete.\",\n\t\tparameters: retrieveEvidenceSchema,\n\t\teffects: {\n\t\t\treadsWorkspace: false,\n\t\t\twritesWorkspace: false,\n\t\t\tcreatesFiles: false,\n\t\t\tdeletesFiles: false,\n\t\t\texecutesProcesses: false,\n\t\t\tstartsPersistentProcesses: false,\n\t\t\taccessesNetwork: false,\n\t\t\tmutatesGit: false,\n\t\t\tmutatesExternalState: false,\n\t\t\thandlesSecrets: false,\n\t\t\tpotentiallyDestructive: false,\n\t\t\trequiresExclusiveWorkspaceLease: false,\n\t\t\tparallelSafe: true,\n\t\t\tscopes: [{ kind: \"external\", resource: \"evidence-archive\" }],\n\t\t},\n\t\tisConcurrencySafe: () => true,\n\t\texecute: async (_toolCallId: string, input: RetrieveEvidenceInput) => {\n\t\t\tconst result = await retrieveEvidencePage(archive, input.evidenceId, {\n\t\t\t\toffset: input.offset,\n\t\t\t\tlimit: input.limit,\n\t\t\t});\n\n\t\t\tif (!result.ok) {\n\t\t\t\treturn {\n\t\t\t\t\tcontent: [{ type: \"text\", text: result.reason ?? `Retrieval failed (${result.status}).` }],\n\t\t\t\t\tdetails: {\n\t\t\t\t\t\tstatus: result.status,\n\t\t\t\t\t\tevidenceId: result.evidenceId,\n\t\t\t\t\t\tintegrity: \"unverified\",\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst meta = result.metadata!;\n\t\t\tconst envelope = [\n\t\t\t\t`[evidence ${meta.integrity}] ${meta.evidenceId}`,\n\t\t\t\t`range: chars ${meta.start}-${meta.end} of ${meta.totalChars} (${meta.totalBytes} bytes)`,\n\t\t\t\t`${meta.hasMore ? `hasMore: true (next offset ${meta.end})` : \"hasMore: false\"}`,\n\t\t\t\t\"\",\n\t\t\t\tresult.content!,\n\t\t\t].join(\"\\n\");\n\n\t\t\treturn {\n\t\t\t\tcontent: [{ type: \"text\", text: envelope }],\n\t\t\t\tdetails: {\n\t\t\t\t\tstatus: result.status,\n\t\t\t\t\tintegrity: meta.integrity,\n\t\t\t\t\tevidenceId: meta.evidenceId,\n\t\t\t\t\tkind: meta.kind,\n\t\t\t\t\tsource: meta.source,\n\t\t\t\t\tcontentHash: meta.contentHash,\n\t\t\t\t\tstart: meta.start,\n\t\t\t\t\tend: meta.end,\n\t\t\t\t\ttotalChars: meta.totalChars,\n\t\t\t\t\ttotalBytes: meta.totalBytes,\n\t\t\t\t\tretrievedChars: meta.retrievedChars,\n\t\t\t\t\thasMore: meta.hasMore,\n\t\t\t\t\tredaction: meta.redaction,\n\t\t\t\t\t// Marker used by the Context Governor to preserve archive identity\n\t\t\t\t\t// when this page is later virtualized again (no duplicate records).\n\t\t\t\t\t__evidenceSourceId: meta.evidenceId,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n\n/** Static name-resolution instance (the session binds its own archive in AgentSession). */\nexport const retrieveEvidenceTool: AgentTool<typeof retrieveEvidenceSchema> = createRetrieveEvidenceTool(\n\tnew InMemoryEvidenceArchive(),\n);\n"]}