{"version":3,"file":"mcp-evidence.d.ts","sourceRoot":"","sources":["../../../src/core/mcp-foundation/mcp-evidence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEnF,wEAAwE;AACxE,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE5E;AAWD,MAAM,WAAW,qBAAqB;IACrC,MAAM,EAAE,aAAa,CAAC;IACtB,sEAAsE;IACtE,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,yEAAyE;IACzE,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC9C;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,WAAW,CAoC1E;AAED;;;;GAIG;AACH,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAMxG","sourcesContent":["/**\n * MCP Client Foundation — evidence integration (2.13.0).\n *\n * MCP tool invocations become first-class Jensen evidence through the existing\n * L3 Evidence Archive (`EvidenceArchive`). The durable payload is an\n * `McpEvidence` JSON document stored under kind `tool-result` with a\n * deterministic, content-addressed id — so `retrieve_evidence` can rehydrate\n * \"I queried the real external system and this is what it reported.\"\n *\n * Secret hygiene: environment contents are never embedded; the archive's\n * conservative redaction additionally scrubs credential-shaped values before\n * persistence.\n */\n\nimport type { EvidenceArchive } from \"../context-runtime/evidence-archive.js\";\nimport type { McpEvidence, McpServerSession, McpToolResult } from \"./mcp-types.js\";\n\n/** Deterministic evidence source identity for a (server, tool) pair. */\nexport function mcpEvidenceSource(serverId: string, toolName: string): string {\n\treturn `mcp:${serverId}:${toolName}`;\n}\n\nconst TEXT_PREVIEW_MAX_CHARS = 2_000;\n\nfunction firstText(result: McpToolResult): string | undefined {\n\tfor (const item of result.content) {\n\t\tif (item.type === \"text\" && typeof item.text === \"string\") return item.text;\n\t}\n\treturn undefined;\n}\n\nexport interface BuildMcpEvidenceInput {\n\tresult: McpToolResult;\n\t/** argv identity for diagnostics; env contents are never included. */\n\tserverCommand: string;\n\tsession: McpServerSession;\n\t/** Safe argument representation (redacted at archive time if needed). */\n\targuments?: Readonly<Record<string, unknown>>;\n}\n\n/**\n * Build the durable MCP evidence payload. On failure paths this deliberately\n * carries failure metadata (never a success claim); on success it carries a\n * bounded result summary rather than unbounded raw content.\n */\nexport function buildMcpEvidence(input: BuildMcpEvidenceInput): McpEvidence {\n\tconst { result, serverCommand, session, arguments: args } = input;\n\tconst successLike = result.status === \"success\" || result.status === \"tool-error\";\n\n\tconst evidence: McpEvidence = {\n\t\tkind: \"mcp-tool-call\",\n\t\tversion: 1,\n\t\tserverId: result.serverId,\n\t\tserverCommand,\n\t\tsessionId: result.sessionId,\n\t\ttoolName: result.toolName,\n\t\tstatus: result.status,\n\t\tinvokedAtMs: result.invokedAtMs,\n\t\tcompletedAtMs: result.completedAtMs,\n\t\targuments: args,\n\t\tprotocolVersion: session.protocolVersion,\n\t\tprotocolEra: session.protocolEra,\n\t};\n\n\tif (successLike) {\n\t\tconst text = firstText(result);\n\t\tevidence.resultSummary = {\n\t\t\tcontentTypes: result.content.map((item) => item.type),\n\t\t\ttextPreview: text ? text.slice(0, TEXT_PREVIEW_MAX_CHARS) : undefined,\n\t\t\thasStructuredContent: result.structuredContent !== undefined,\n\t\t};\n\t}\n\n\tif (result.status !== \"success\") {\n\t\tevidence.failure = {\n\t\t\tcode: result.errorCode ?? \"MCP_TOOL_CALL_FAILED\",\n\t\t\tmessage: result.errorMessage ?? result.status,\n\t\t};\n\t}\n\n\treturn evidence;\n}\n\n/**\n * Persist MCP evidence into the existing Evidence Archive and return its\n * deterministic evidence id. The archive redacts and hashes the payload, so the\n * same invocation always resolves to the same reference.\n */\nexport async function recordMcpEvidence(archive: EvidenceArchive, evidence: McpEvidence): Promise<string> {\n\treturn archive.store({\n\t\tkind: \"tool-result\",\n\t\tsource: mcpEvidenceSource(evidence.serverId, evidence.toolName),\n\t\tcontent: JSON.stringify(evidence),\n\t});\n}\n"]}