@remnic/core 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access-audit.d.ts +56 -0
- package/dist/access-audit.js +9 -0
- package/dist/access-cli.js +62 -45
- package/dist/access-cli.js.map +1 -1
- package/dist/access-http.d.ts +16 -9
- package/dist/access-http.js +25 -17
- package/dist/access-mcp.d.ts +16 -9
- package/dist/access-mcp.js +29 -7
- package/dist/access-schema.d.ts +124 -33
- package/dist/access-schema.js +5 -1
- package/dist/{access-service-HmO1Trrx.d.ts → access-service-Br8ZydTK.d.ts} +158 -63
- package/dist/access-service.d.ts +13 -6
- package/dist/access-service.js +22 -14
- package/dist/bootstrap.d.ts +6 -3
- package/dist/briefing.d.ts +1 -0
- package/dist/briefing.js +7 -6
- package/dist/buffer-surprise-report.d.ts +70 -0
- package/dist/buffer-surprise-report.js +7 -0
- package/dist/buffer-surprise-report.js.map +1 -0
- package/dist/buffer-surprise.d.ts +98 -0
- package/dist/buffer-surprise.js +11 -0
- package/dist/buffer-surprise.js.map +1 -0
- package/dist/buffer.d.ts +100 -2
- package/dist/buffer.js +1 -1
- package/dist/calibration.js +5 -5
- package/dist/causal-behavior.js +4 -4
- package/dist/causal-chain.js +2 -2
- package/dist/causal-consolidation.js +17 -16
- package/dist/causal-consolidation.js.map +1 -1
- package/dist/causal-retrieval.js +4 -4
- package/dist/causal-trajectory.js +1 -1
- package/dist/{chunk-QNJMBKFK.js → chunk-2LGMW3DJ.js} +3 -2
- package/dist/chunk-2LGMW3DJ.js.map +1 -0
- package/dist/{chunk-QDYXG4CS.js → chunk-3FPTCC3Z.js} +4 -3
- package/dist/chunk-3FPTCC3Z.js.map +1 -0
- package/dist/chunk-3GPTTA4J.js +57 -0
- package/dist/chunk-3GPTTA4J.js.map +1 -0
- package/dist/{chunk-44ICJRF3.js → chunk-3GXCSUXR.js} +4 -4
- package/dist/{chunk-ITRLGI2T.js → chunk-3OGMS3PE.js} +2 -2
- package/dist/chunk-54V4BZWP.js +139 -0
- package/dist/chunk-54V4BZWP.js.map +1 -0
- package/dist/chunk-5JRF2PZA.js +67 -0
- package/dist/chunk-5JRF2PZA.js.map +1 -0
- package/dist/chunk-64NJRYU2.js +332 -0
- package/dist/chunk-64NJRYU2.js.map +1 -0
- package/dist/{chunk-OIT5QGG4.js → chunk-6AUUAZEX.js} +72 -2
- package/dist/chunk-6AUUAZEX.js.map +1 -0
- package/dist/{chunk-ZVBB3T7V.js → chunk-7I7FKFZH.js} +24 -22
- package/dist/chunk-7I7FKFZH.js.map +1 -0
- package/dist/chunk-AJU4PJGY.js +126 -0
- package/dist/chunk-AJU4PJGY.js.map +1 -0
- package/dist/chunk-ASAITVLA.js +64 -0
- package/dist/chunk-ASAITVLA.js.map +1 -0
- package/dist/{chunk-3QHL5ABG.js → chunk-B5WXLVDY.js} +187 -6
- package/dist/chunk-B5WXLVDY.js.map +1 -0
- package/dist/{chunk-SYUK3VLY.js → chunk-BGJGXLZ7.js} +111 -2
- package/dist/{chunk-SYUK3VLY.js.map → chunk-BGJGXLZ7.js.map} +1 -1
- package/dist/{chunk-MBJHSA7F.js → chunk-BK2EFTE2.js} +258 -13
- package/dist/chunk-BK2EFTE2.js.map +1 -0
- package/dist/chunk-C4SQJZAF.js +486 -0
- package/dist/chunk-C4SQJZAF.js.map +1 -0
- package/dist/{chunk-6UJ47TVX.js → chunk-CUPFXL3J.js} +2 -2
- package/dist/chunk-DF3RVK3X.js +119 -0
- package/dist/chunk-DF3RVK3X.js.map +1 -0
- package/dist/{chunk-37UIFYWO.js → chunk-DFTTJYSO.js} +108 -9
- package/dist/chunk-DFTTJYSO.js.map +1 -0
- package/dist/chunk-DGVM5SFL.js +69 -0
- package/dist/chunk-DGVM5SFL.js.map +1 -0
- package/dist/chunk-EIR5VLIH.js +90 -0
- package/dist/chunk-EIR5VLIH.js.map +1 -0
- package/dist/{chunk-PAORGQRI.js → chunk-EPQJM2GC.js} +37 -23
- package/dist/chunk-EPQJM2GC.js.map +1 -0
- package/dist/{chunk-GV6NLQ4X.js → chunk-F5VP6YCB.js} +374 -16
- package/dist/chunk-F5VP6YCB.js.map +1 -0
- package/dist/{chunk-6ZH4TU6I.js → chunk-FAAFWE4G.js} +2 -1
- package/dist/chunk-FAAFWE4G.js.map +1 -0
- package/dist/{chunk-7WQ6SLIE.js → chunk-FVA6TGI3.js} +2 -2
- package/dist/chunk-GDFS42HT.js +206 -0
- package/dist/chunk-GDFS42HT.js.map +1 -0
- package/dist/{chunk-MVTHXUBX.js → chunk-GKFXUTJ2.js} +479 -20
- package/dist/chunk-GKFXUTJ2.js.map +1 -0
- package/dist/{chunk-NQEVYWX6.js → chunk-HK3FGIEW.js} +209 -5
- package/dist/chunk-HK3FGIEW.js.map +1 -0
- package/dist/chunk-IISBCCWR.js +52 -0
- package/dist/chunk-IISBCCWR.js.map +1 -0
- package/dist/{chunk-WBSAYXVI.js → chunk-INXV5JBT.js} +198 -42
- package/dist/chunk-INXV5JBT.js.map +1 -0
- package/dist/chunk-JBMSGZEQ.js +441 -0
- package/dist/chunk-JBMSGZEQ.js.map +1 -0
- package/dist/{chunk-J4IYOZZ5.js → chunk-JXS5PDQ7.js} +3 -1
- package/dist/chunk-JXS5PDQ7.js.map +1 -0
- package/dist/{chunk-6LX5ORAS.js → chunk-KUB6JU6H.js} +4 -4
- package/dist/chunk-KVBLZUKV.js +173 -0
- package/dist/chunk-KVBLZUKV.js.map +1 -0
- package/dist/chunk-LBLXEFWK.js +51 -0
- package/dist/chunk-LBLXEFWK.js.map +1 -0
- package/dist/{chunk-3WHVNEN7.js → chunk-LTCGGW2D.js} +1 -1
- package/dist/chunk-LTCGGW2D.js.map +1 -0
- package/dist/{chunk-UEYA6UC7.js → chunk-NZLQTHS5.js} +25 -2
- package/dist/chunk-NZLQTHS5.js.map +1 -0
- package/dist/chunk-PVPWZSSI.js +37 -0
- package/dist/chunk-PVPWZSSI.js.map +1 -0
- package/dist/{chunk-4NRAJUDS.js → chunk-RBBWYEFJ.js} +1 -1
- package/dist/chunk-RFYAYKTD.js +146 -0
- package/dist/chunk-RFYAYKTD.js.map +1 -0
- package/dist/{chunk-DHHP2Z4X.js → chunk-RGLL5SPU.js} +2 -2
- package/dist/{chunk-3SV6CQHO.js → chunk-S3EEFKNY.js} +101 -65
- package/dist/chunk-S3EEFKNY.js.map +1 -0
- package/dist/chunk-SOBJ6NEY.js +18 -0
- package/dist/chunk-SOBJ6NEY.js.map +1 -0
- package/dist/{chunk-JIU55F3X.js → chunk-SPI27QT6.js} +2 -2
- package/dist/chunk-TVVEYCNW.js +65 -0
- package/dist/chunk-TVVEYCNW.js.map +1 -0
- package/dist/chunk-ULYOGL6R.js +322 -0
- package/dist/chunk-ULYOGL6R.js.map +1 -0
- package/dist/{chunk-47UU5PU2.js → chunk-VBVG2M5G.js} +18 -3
- package/dist/chunk-VBVG2M5G.js.map +1 -0
- package/dist/{chunk-7ECD5ATE.js → chunk-VDX363PS.js} +2 -2
- package/dist/{chunk-DEPL3635.js → chunk-VYM3VWOF.js} +1432 -188
- package/dist/chunk-VYM3VWOF.js.map +1 -0
- package/dist/{chunk-MTLYEMJB.js → chunk-WCLICCGB.js} +18 -3
- package/dist/chunk-WCLICCGB.js.map +1 -0
- package/dist/{chunk-4LACOVZX.js → chunk-WVVA7F5A.js} +2 -2
- package/dist/chunk-X6GF3FX2.js +26 -0
- package/dist/chunk-X6GF3FX2.js.map +1 -0
- package/dist/{chunk-3QFQGRHO.js → chunk-XMHBH5H6.js} +4 -4
- package/dist/{chunk-BLKTA7MM.js → chunk-YNQKWQT4.js} +50 -17
- package/dist/chunk-YNQKWQT4.js.map +1 -0
- package/dist/chunk-ZAIM4TUE.js +488 -0
- package/dist/chunk-ZAIM4TUE.js.map +1 -0
- package/dist/{chunk-N42IWANG.js → chunk-ZEM3OK2K.js} +2 -2
- package/dist/chunk-ZZTOURJI.js +91 -0
- package/dist/chunk-ZZTOURJI.js.map +1 -0
- package/dist/{cli-BneVIEvh.d.ts → cli-BkeRaYfk.d.ts} +2 -2
- package/dist/cli.d.ts +13 -6
- package/dist/cli.js +40 -29
- package/dist/config.js +1 -1
- package/dist/consolidation-operator.d.ts +41 -0
- package/dist/consolidation-operator.js +11 -0
- package/dist/consolidation-operator.js.map +1 -0
- package/dist/consolidation-provenance-check.d.ts +68 -0
- package/dist/consolidation-provenance-check.js +9 -0
- package/dist/consolidation-provenance-check.js.map +1 -0
- package/dist/consolidation-undo.d.ts +123 -0
- package/dist/consolidation-undo.js +426 -0
- package/dist/consolidation-undo.js.map +1 -0
- package/dist/{contradiction-scan-GR33PONM.js → contradiction-scan-E3GJTI4F.js} +43 -7
- package/dist/contradiction-scan-E3GJTI4F.js.map +1 -0
- package/dist/cross-namespace-budget.d.ts +133 -0
- package/dist/cross-namespace-budget.js +9 -0
- package/dist/cross-namespace-budget.js.map +1 -0
- package/dist/direct-answer-wiring.js +5 -70
- package/dist/direct-answer-wiring.js.map +1 -1
- package/dist/{engine-5TIQBYZR.js → engine-F3GOXGE5.js} +8 -7
- package/dist/engine-F3GOXGE5.js.map +1 -0
- package/dist/entity-retrieval.d.ts +1 -0
- package/dist/entity-retrieval.js +7 -6
- package/dist/explicit-capture.d.ts +6 -3
- package/dist/explicit-capture.js +2 -2
- package/dist/extraction-judge-telemetry.d.ts +113 -0
- package/dist/extraction-judge-telemetry.js +14 -0
- package/dist/extraction-judge-telemetry.js.map +1 -0
- package/dist/extraction-judge-training.d.ts +85 -0
- package/dist/extraction-judge-training.js +16 -0
- package/dist/extraction-judge-training.js.map +1 -0
- package/dist/extraction-judge.d.ts +124 -2
- package/dist/extraction-judge.js +11 -1
- package/dist/extraction.js +6 -5
- package/dist/fallback-llm.js +2 -2
- package/dist/graph-recall.d.ts +100 -0
- package/dist/graph-recall.js +8 -0
- package/dist/graph-recall.js.map +1 -0
- package/dist/graph-retrieval.d.ts +271 -0
- package/dist/graph-retrieval.js +21 -0
- package/dist/graph-retrieval.js.map +1 -0
- package/dist/importance.js +1 -1
- package/dist/index.d.ts +585 -20
- package/dist/index.js +503 -312
- package/dist/index.js.map +1 -1
- package/dist/memory-worth-bench.d.ts +51 -0
- package/dist/memory-worth-bench.js +131 -0
- package/dist/memory-worth-bench.js.map +1 -0
- package/dist/memory-worth-filter.d.ts +128 -0
- package/dist/memory-worth-filter.js +10 -0
- package/dist/memory-worth-filter.js.map +1 -0
- package/dist/memory-worth-outcomes.d.ts +118 -0
- package/dist/memory-worth-outcomes.js +9 -0
- package/dist/memory-worth-outcomes.js.map +1 -0
- package/dist/memory-worth.d.ts +102 -0
- package/dist/memory-worth.js +7 -0
- package/dist/memory-worth.js.map +1 -0
- package/dist/operator-toolkit.d.ts +40 -1
- package/dist/operator-toolkit.js +23 -14
- package/dist/{orchestrator-DRYA6_lW.d.ts → orchestrator-CmJ-NTdJ.d.ts} +233 -8
- package/dist/orchestrator.d.ts +6 -3
- package/dist/orchestrator.js +49 -39
- package/dist/page-versioning.d.ts +12 -1
- package/dist/page-versioning.js +5 -3
- package/dist/{port-C1GZFv8h.d.ts → port-BADbLZU5.d.ts} +2 -2
- package/dist/qmd-recall-cache.d.ts +1 -1
- package/dist/qmd.d.ts +5 -3
- package/dist/qmd.js +1 -1
- package/dist/reasoning-trace-recall.d.ts +90 -0
- package/dist/reasoning-trace-recall.js +13 -0
- package/dist/reasoning-trace-recall.js.map +1 -0
- package/dist/reasoning-trace-types.d.ts +54 -0
- package/dist/reasoning-trace-types.js +17 -0
- package/dist/reasoning-trace-types.js.map +1 -0
- package/dist/recall-audit-anomaly.d.ts +112 -0
- package/dist/recall-audit-anomaly.js +11 -0
- package/dist/recall-audit-anomaly.js.map +1 -0
- package/dist/recall-audit.js +5 -44
- package/dist/recall-audit.js.map +1 -1
- package/dist/recall-explain-renderer.d.ts +49 -0
- package/dist/recall-explain-renderer.js +18 -0
- package/dist/recall-explain-renderer.js.map +1 -0
- package/dist/recall-state.d.ts +12 -1
- package/dist/recall-state.js +1 -1
- package/dist/recall-xray-cli.d.ts +40 -0
- package/dist/recall-xray-cli.js +11 -0
- package/dist/recall-xray-cli.js.map +1 -0
- package/dist/recall-xray-renderer.d.ts +44 -0
- package/dist/recall-xray-renderer.js +18 -0
- package/dist/recall-xray-renderer.js.map +1 -0
- package/dist/recall-xray.d.ts +179 -0
- package/dist/recall-xray.js +13 -0
- package/dist/recall-xray.js.map +1 -0
- package/dist/resume-bundles.js +5 -5
- package/dist/retrieval-agents.d.ts +1 -1
- package/dist/retrieval-tiers.d.ts +17 -0
- package/dist/retrieval-tiers.js +9 -0
- package/dist/retrieval-tiers.js.map +1 -0
- package/dist/schemas.d.ts +287 -31
- package/dist/schemas.js +1 -1
- package/dist/{semantic-consolidation-DrvSYRdB.d.ts → semantic-consolidation-CxJU6MJk.d.ts} +62 -1
- package/dist/semantic-consolidation.d.ts +2 -1
- package/dist/semantic-consolidation.js +21 -7
- package/dist/semantic-rule-promotion.js +7 -6
- package/dist/semantic-rule-verifier.js +7 -6
- package/dist/storage.d.ts +82 -1
- package/dist/storage.js +6 -5
- package/dist/summarizer.js +3 -3
- package/dist/temporal-supersession.d.ts +1 -0
- package/dist/tier-migration.d.ts +2 -1
- package/dist/types.d.ts +276 -2
- package/dist/types.js +1 -1
- package/dist/verified-recall.js +7 -6
- package/package.json +1 -1
- package/dist/chunk-37UIFYWO.js.map +0 -1
- package/dist/chunk-3QHL5ABG.js.map +0 -1
- package/dist/chunk-3SV6CQHO.js.map +0 -1
- package/dist/chunk-3WHVNEN7.js.map +0 -1
- package/dist/chunk-47UU5PU2.js.map +0 -1
- package/dist/chunk-6ZH4TU6I.js.map +0 -1
- package/dist/chunk-BLKTA7MM.js.map +0 -1
- package/dist/chunk-DEPL3635.js.map +0 -1
- package/dist/chunk-GV6NLQ4X.js.map +0 -1
- package/dist/chunk-J4IYOZZ5.js.map +0 -1
- package/dist/chunk-LAYN4LDC.js +0 -267
- package/dist/chunk-LAYN4LDC.js.map +0 -1
- package/dist/chunk-MBJHSA7F.js.map +0 -1
- package/dist/chunk-MTLYEMJB.js.map +0 -1
- package/dist/chunk-MVTHXUBX.js.map +0 -1
- package/dist/chunk-NQEVYWX6.js.map +0 -1
- package/dist/chunk-OIT5QGG4.js.map +0 -1
- package/dist/chunk-PAORGQRI.js.map +0 -1
- package/dist/chunk-QDYXG4CS.js.map +0 -1
- package/dist/chunk-QNJMBKFK.js.map +0 -1
- package/dist/chunk-UEYA6UC7.js.map +0 -1
- package/dist/chunk-UVJFDP7P.js +0 -202
- package/dist/chunk-UVJFDP7P.js.map +0 -1
- package/dist/chunk-WBSAYXVI.js.map +0 -1
- package/dist/chunk-ZVBB3T7V.js.map +0 -1
- package/dist/contradiction-scan-GR33PONM.js.map +0 -1
- /package/dist/{engine-5TIQBYZR.js.map → access-audit.js.map} +0 -0
- /package/dist/{chunk-44ICJRF3.js.map → chunk-3GXCSUXR.js.map} +0 -0
- /package/dist/{chunk-ITRLGI2T.js.map → chunk-3OGMS3PE.js.map} +0 -0
- /package/dist/{chunk-6UJ47TVX.js.map → chunk-CUPFXL3J.js.map} +0 -0
- /package/dist/{chunk-7WQ6SLIE.js.map → chunk-FVA6TGI3.js.map} +0 -0
- /package/dist/{chunk-6LX5ORAS.js.map → chunk-KUB6JU6H.js.map} +0 -0
- /package/dist/{chunk-4NRAJUDS.js.map → chunk-RBBWYEFJ.js.map} +0 -0
- /package/dist/{chunk-DHHP2Z4X.js.map → chunk-RGLL5SPU.js.map} +0 -0
- /package/dist/{chunk-JIU55F3X.js.map → chunk-SPI27QT6.js.map} +0 -0
- /package/dist/{chunk-7ECD5ATE.js.map → chunk-VDX363PS.js.map} +0 -0
- /package/dist/{chunk-4LACOVZX.js.map → chunk-WVVA7F5A.js.map} +0 -0
- /package/dist/{chunk-3QFQGRHO.js.map → chunk-XMHBH5H6.js.map} +0 -0
- /package/dist/{chunk-N42IWANG.js.map → chunk-ZEM3OK2K.js.map} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/access-mcp.ts"],"sourcesContent":["import type { Readable, Writable } from \"node:stream\";\nimport { readFile } from \"node:fs/promises\";\nimport { randomUUID } from \"node:crypto\";\nimport type { EngramAccessService, EngramAccessRecallResponse } from \"./access-service.js\";\nimport { readEnvVar } from \"./runtime/env.js\";\nimport type { RecallPlanMode } from \"./types.js\";\nimport { validateBriefingFormat } from \"./briefing.js\";\nimport { buildCitationGuidance, type CitationMetadata } from \"./citations.js\";\n\ntype JsonRpcId = string | number | null;\n\ntype JsonRpcRequest = {\n jsonrpc?: string;\n id?: JsonRpcId;\n method?: string;\n params?: Record<string, unknown>;\n};\n\ntype McpTool = {\n name: string;\n description: string;\n inputSchema: Record<string, unknown>;\n};\n\nconst MCP_PROTOCOL_VERSION = \"2024-11-05\";\nconst LEGACY_MCP_PREFIX = \"engram.\";\nconst CANONICAL_MCP_PREFIX = \"remnic.\";\n\nfunction toCanonicalToolName(name: string): string {\n return name.startsWith(LEGACY_MCP_PREFIX)\n ? `${CANONICAL_MCP_PREFIX}${name.slice(LEGACY_MCP_PREFIX.length)}`\n : name;\n}\n\nfunction toLegacyToolName(name: string): string {\n return name.startsWith(CANONICAL_MCP_PREFIX)\n ? `${LEGACY_MCP_PREFIX}${name.slice(CANONICAL_MCP_PREFIX.length)}`\n : name;\n}\n\nfunction withToolAliases(tool: McpTool): McpTool[] {\n const canonicalName = toCanonicalToolName(tool.name);\n const canonicalTool = canonicalName === tool.name ? tool : { ...tool, name: canonicalName };\n if (canonicalName === tool.name) return [canonicalTool];\n return [canonicalTool, tool];\n}\n\nasync function getMcpServerVersion(): Promise<string> {\n const envVersion =\n readEnvVar(\"OPENCLAW_ENGRAM_VERSION\")?.trim() ||\n readEnvVar(\"npm_package_version\")?.trim();\n if (envVersion) return envVersion;\n try {\n const pkgPath = new URL(\"../package.json\", import.meta.url);\n const raw = await readFile(pkgPath, \"utf-8\");\n const parsed = JSON.parse(raw) as { version?: string };\n return parsed.version?.trim() || \"unknown\";\n } catch {\n return \"unknown\";\n }\n}\n\nexport class EngramMcpServer {\n private buffer = Buffer.alloc(0);\n private flushTask: Promise<void> | null = null;\n private readonly tools: McpTool[];\n private readonly authenticatedPrincipal?: string;\n /**\n * MCP client info keyed by server-assigned session ID. On each `initialize`\n * handshake the server generates a UUID, stores the client's clientInfo\n * against it, and returns the ID as `Mcp-Session-Id` in the response\n * metadata. Subsequent requests from the same client include this header,\n * allowing per-session clientInfo lookup without cross-session leaks.\n */\n private clientInfoBySession = new Map<string, { name: string; version?: string }>();\n /**\n * Session IDs generated during initialize, keyed by caller-supplied correlation\n * ID (unique per HTTP request) to avoid collisions when multiple clients send\n * initialize with the same JSON-RPC id concurrently.\n */\n private initSessionIds = new Map<string, string>();\n\n /** Whether oai-mem-citation guidance is explicitly enabled via config. */\n private readonly citationsEnabled: boolean;\n /** Whether to auto-enable citations for Codex adapter connections. */\n private readonly citationsAutoDetect: boolean;\n\n constructor(\n private readonly service: EngramAccessService,\n options: { principal?: string; citationsEnabled?: boolean; citationsAutoDetect?: boolean } = {},\n ) {\n this.citationsEnabled = options.citationsEnabled === true;\n this.citationsAutoDetect = options.citationsAutoDetect !== false;\n this.authenticatedPrincipal =\n options.principal?.trim() ||\n readEnvVar(\"OPENCLAW_ENGRAM_ACCESS_PRINCIPAL\")?.trim() ||\n undefined;\n this.tools = [\n {\n name: \"engram.recall\",\n description: \"Recall Engram context for a query.\",\n inputSchema: {\n type: \"object\",\n properties: {\n query: { type: \"string\" },\n sessionKey: { type: \"string\" },\n namespace: { type: \"string\" },\n topK: { type: \"number\" },\n mode: { type: \"string\", enum: [\"auto\", \"no_recall\", \"minimal\", \"full\", \"graph_mode\"] },\n includeDebug: { type: \"boolean\" },\n },\n required: [\"query\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.recall_explain\",\n description: \"Return the last recall snapshot for a session or the most recent one.\",\n inputSchema: {\n type: \"object\",\n properties: {\n sessionKey: { type: \"string\" },\n namespace: { type: \"string\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.day_summary\",\n description:\n \"Generate a structured end-of-day summary. When memories is omitted or empty, auto-gathers today's facts and hourly summaries from storage.\",\n inputSchema: {\n type: \"object\",\n properties: {\n memories: { type: \"string\" },\n sessionKey: { type: \"string\" },\n namespace: { type: \"string\" },\n },\n required: [],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_governance_run\",\n description: \"Run Remnic memory governance in a bounded shadow/apply pass.\",\n inputSchema: {\n type: \"object\",\n properties: {\n namespace: { type: \"string\" },\n mode: { type: \"string\", enum: [\"shadow\", \"apply\"] },\n recentDays: { type: \"number\" },\n maxMemories: { type: \"number\" },\n batchSize: { type: \"number\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.procedure_mining_run\",\n description:\n \"Run procedural memory mining from causal trajectories (issue #519). Respects procedural.enabled; writes under procedures/ when clusters qualify.\",\n inputSchema: {\n type: \"object\",\n properties: {\n namespace: { type: \"string\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_get\",\n description: \"Fetch one Remnic memory by id.\",\n inputSchema: {\n type: \"object\",\n properties: {\n memoryId: { type: \"string\" },\n namespace: { type: \"string\" },\n },\n required: [\"memoryId\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_timeline\",\n description: \"Fetch one Remnic memory timeline by id.\",\n inputSchema: {\n type: \"object\",\n properties: {\n memoryId: { type: \"string\" },\n namespace: { type: \"string\" },\n limit: { type: \"number\" },\n },\n required: [\"memoryId\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_store\",\n description: \"Store an explicit Remnic memory through the access layer.\",\n inputSchema: {\n type: \"object\",\n properties: {\n schemaVersion: { type: \"number\" },\n idempotencyKey: { type: \"string\" },\n dryRun: { type: \"boolean\" },\n sessionKey: { type: \"string\" },\n content: { type: \"string\" },\n category: { type: \"string\" },\n confidence: { type: \"number\" },\n namespace: { type: \"string\" },\n tags: { type: \"array\", items: { type: \"string\" } },\n entityRef: { type: \"string\" },\n ttl: { type: \"string\" },\n sourceReason: { type: \"string\" },\n },\n required: [\"content\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.suggestion_submit\",\n description: \"Queue a suggested Remnic memory for review.\",\n inputSchema: {\n type: \"object\",\n properties: {\n schemaVersion: { type: \"number\" },\n idempotencyKey: { type: \"string\" },\n dryRun: { type: \"boolean\" },\n sessionKey: { type: \"string\" },\n content: { type: \"string\" },\n category: { type: \"string\" },\n confidence: { type: \"number\" },\n namespace: { type: \"string\" },\n tags: { type: \"array\", items: { type: \"string\" } },\n entityRef: { type: \"string\" },\n ttl: { type: \"string\" },\n sourceReason: { type: \"string\" },\n },\n required: [\"content\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.entity_get\",\n description: \"Fetch one Engram entity by name.\",\n inputSchema: {\n type: \"object\",\n properties: {\n name: { type: \"string\" },\n namespace: { type: \"string\" },\n },\n required: [\"name\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.review_queue_list\",\n description: \"Fetch the latest Engram review queue artifact bundle.\",\n inputSchema: {\n type: \"object\",\n properties: {\n runId: { type: \"string\" },\n namespace: { type: \"string\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.observe\",\n description: \"Feed conversation messages into Engram's memory pipeline (LCM archive + extraction).\",\n inputSchema: {\n type: \"object\",\n properties: {\n sessionKey: { type: \"string\", description: \"Conversation session identifier\" },\n messages: {\n type: \"array\",\n items: {\n type: \"object\",\n properties: {\n role: { type: \"string\", enum: [\"user\", \"assistant\"] },\n content: { type: \"string\" },\n },\n required: [\"role\", \"content\"],\n },\n description: \"Conversation messages to observe\",\n },\n namespace: { type: \"string\" },\n skipExtraction: { type: \"boolean\" },\n },\n required: [\"sessionKey\", \"messages\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.lcm_search\",\n description: \"Search the LCM conversation archive for matching content.\",\n inputSchema: {\n type: \"object\",\n properties: {\n query: { type: \"string\", description: \"Search query\" },\n sessionKey: { type: \"string\", description: \"Optional session filter\" },\n namespace: { type: \"string\" },\n limit: { type: \"number\", description: \"Max results to return\" },\n },\n required: [\"query\"],\n additionalProperties: false,\n },\n },\n // ── Continuity / Identity tools ─────────────────────────────────────\n {\n name: \"engram.continuity_audit_generate\",\n description: \"Generate a deterministic identity continuity audit report (weekly/monthly).\",\n inputSchema: {\n type: \"object\",\n properties: {\n period: { type: \"string\", enum: [\"weekly\", \"monthly\"] },\n key: { type: \"string\", description: \"Period key (weekly: YYYY-Www, monthly: YYYY-MM). Defaults to current.\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.continuity_incident_open\",\n description: \"Create a new continuity incident record in append-only storage.\",\n inputSchema: {\n type: \"object\",\n properties: {\n symptom: { type: \"string\", description: \"Observed continuity failure symptom.\" },\n namespace: { type: \"string\" },\n triggerWindow: { type: \"string\", description: \"Time window when incident occurred.\" },\n suspectedCause: { type: \"string\" },\n },\n required: [\"symptom\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.continuity_incident_close\",\n description: \"Close an open continuity incident with verification details.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Incident ID to close.\" },\n namespace: { type: \"string\" },\n fixApplied: { type: \"string\", description: \"What fix was applied.\" },\n verificationResult: { type: \"string\", description: \"How closure was verified.\" },\n preventiveRule: { type: \"string\", description: \"Optional preventive follow-up rule.\" },\n },\n required: [\"id\", \"fixApplied\", \"verificationResult\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.continuity_incident_list\",\n description: \"List continuity incidents, optionally filtered by state.\",\n inputSchema: {\n type: \"object\",\n properties: {\n state: { type: \"string\", enum: [\"open\", \"closed\", \"all\"] },\n namespace: { type: \"string\" },\n limit: { type: \"number\", description: \"Max incidents (default 25, max 200).\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.continuity_loop_add_or_update\",\n description: \"Add or update a continuity improvement loop entry.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Stable loop identifier.\" },\n cadence: { type: \"string\", enum: [\"daily\", \"weekly\", \"monthly\", \"quarterly\"] },\n purpose: { type: \"string\", description: \"What this recurring loop improves.\" },\n status: { type: \"string\", enum: [\"active\", \"paused\", \"retired\"] },\n killCondition: { type: \"string\", description: \"Clear condition for retiring this loop.\" },\n namespace: { type: \"string\" },\n lastReviewed: { type: \"string\", description: \"ISO timestamp for last review.\" },\n notes: { type: \"string\" },\n },\n required: [\"id\", \"cadence\", \"purpose\", \"status\", \"killCondition\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.continuity_loop_review\",\n description: \"Update review metadata for an existing continuity improvement loop.\",\n inputSchema: {\n type: \"object\",\n properties: {\n id: { type: \"string\", description: \"Loop ID to review.\" },\n namespace: { type: \"string\" },\n status: { type: \"string\", enum: [\"active\", \"paused\", \"retired\"] },\n notes: { type: \"string\" },\n reviewedAt: { type: \"string\", description: \"ISO timestamp for review event.\" },\n },\n required: [\"id\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.identity_anchor_get\",\n description: \"Read the identity continuity anchor document (recovery-safe identity context).\",\n inputSchema: {\n type: \"object\",\n properties: {\n namespace: { type: \"string\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.identity_anchor_update\",\n description: \"Conservatively merge identity anchor sections without overwriting existing material.\",\n inputSchema: {\n type: \"object\",\n properties: {\n namespace: { type: \"string\" },\n identityTraits: { type: \"string\", description: \"Updates for 'Identity Traits' section.\" },\n communicationPreferences: { type: \"string\", description: \"Updates for 'Communication Preferences' section.\" },\n operatingPrinciples: { type: \"string\", description: \"Updates for 'Operating Principles' section.\" },\n continuityNotes: { type: \"string\", description: \"Updates for 'Continuity Notes' section.\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_identity\",\n description: \"Read the agent's identity reflections from the workspace IDENTITY.md file.\",\n inputSchema: {\n type: \"object\",\n properties: {\n namespace: { type: \"string\" },\n },\n additionalProperties: false,\n },\n },\n // ── Work Layer tools ─────────────────────────────────────────────────\n {\n name: \"engram.work_task\",\n description: \"Manage work-layer tasks (create, get, list, update, transition, delete). Excluded from memory extraction.\",\n inputSchema: {\n type: \"object\",\n properties: {\n action: { type: \"string\", enum: [\"create\", \"get\", \"list\", \"update\", \"transition\", \"delete\"] },\n id: { type: \"string\" },\n title: { type: \"string\" },\n description: { type: \"string\" },\n status: { type: \"string\", enum: [\"todo\", \"in_progress\", \"blocked\", \"done\", \"cancelled\"] },\n priority: { type: \"string\", enum: [\"low\", \"medium\", \"high\"] },\n owner: { type: \"string\" },\n assignee: { type: \"string\" },\n projectId: { type: \"string\" },\n tags: { type: \"array\", items: { type: \"string\" } },\n dueAt: { type: \"string\" },\n },\n required: [\"action\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.work_project\",\n description: \"Manage work-layer projects (create, get, list, update, delete, link_task). Excluded from memory extraction.\",\n inputSchema: {\n type: \"object\",\n properties: {\n action: { type: \"string\", enum: [\"create\", \"get\", \"list\", \"update\", \"delete\", \"link_task\"] },\n id: { type: \"string\" },\n name: { type: \"string\" },\n description: { type: \"string\" },\n status: { type: \"string\", enum: [\"active\", \"on_hold\", \"completed\", \"archived\"] },\n owner: { type: \"string\" },\n tags: { type: \"array\", items: { type: \"string\" } },\n taskId: { type: \"string\", description: \"Task ID for link_task.\" },\n projectId: { type: \"string\", description: \"Project ID for link_task.\" },\n },\n required: [\"action\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.work_board\",\n description: \"Export/import work-layer board snapshots and markdown.\",\n inputSchema: {\n type: \"object\",\n properties: {\n action: { type: \"string\", enum: [\"export_markdown\", \"export_snapshot\", \"import_snapshot\"] },\n projectId: { type: \"string\" },\n snapshotJson: { type: \"string\", description: \"Snapshot JSON for import_snapshot.\" },\n linkToMemory: { type: \"boolean\", description: \"If true, output can be retained as long-term memory.\" },\n },\n required: [\"action\"],\n additionalProperties: false,\n },\n },\n // ── Shared Context / Compounding tools ────────────────────────────\n {\n name: \"engram.shared_context_write_output\",\n description: \"Write agent work product into shared-context directory for cross-agent coordination.\",\n inputSchema: {\n type: \"object\",\n properties: {\n agentId: { type: \"string\", description: \"Agent ID producing this output.\" },\n title: { type: \"string\", description: \"Short title for the output.\" },\n content: { type: \"string\", description: \"Markdown content to write.\" },\n },\n required: [\"agentId\", \"title\", \"content\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.shared_feedback_record\",\n description: \"Append approval/rejection decision into shared-context feedback inbox for compounding learning.\",\n inputSchema: {\n type: \"object\",\n properties: {\n agent: { type: \"string\", description: \"Agent name that produced the output.\" },\n decision: { type: \"string\", enum: [\"approved\", \"approved_with_feedback\", \"rejected\"] },\n reason: { type: \"string\" },\n date: { type: \"string\", description: \"ISO timestamp. Defaults to now.\" },\n learning: { type: \"string\" },\n outcome: { type: \"string\" },\n severity: { type: \"string\", enum: [\"low\", \"medium\", \"high\"] },\n confidence: { type: \"number\", description: \"Confidence 0-1.\" },\n workflow: { type: \"string\" },\n tags: { type: \"array\", items: { type: \"string\" } },\n evidenceWindowStart: { type: \"string\" },\n evidenceWindowEnd: { type: \"string\" },\n refs: { type: \"array\", items: { type: \"string\" } },\n },\n required: [\"agent\", \"decision\", \"reason\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.shared_priorities_append\",\n description: \"Append priorities text into shared-context inbox for curator merge.\",\n inputSchema: {\n type: \"object\",\n properties: {\n agentId: { type: \"string\" },\n text: { type: \"string\", description: \"Priority notes (markdown).\" },\n },\n required: [\"agentId\", \"text\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.shared_context_cross_signals_run\",\n description: \"Generate cross-signal markdown + JSON artifacts from agent outputs and feedback.\",\n inputSchema: {\n type: \"object\",\n properties: {\n date: { type: \"string\", description: \"YYYY-MM-DD. Defaults to today.\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.shared_context_curate_daily\",\n description: \"Generate daily roundtable summary (deterministic baseline aggregation).\",\n inputSchema: {\n type: \"object\",\n properties: {\n date: { type: \"string\", description: \"YYYY-MM-DD. Defaults to today.\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.compounding_weekly_synthesize\",\n description: \"Generate weekly compounding outputs: reports, mistake registry, rubrics, and promotion candidates.\",\n inputSchema: {\n type: \"object\",\n properties: {\n weekId: { type: \"string\", description: \"ISO week ID (YYYY-Www). Defaults to current week.\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.compounding_promote_candidate\",\n description: \"Promote a compounding candidate from weekly report into durable rule/principle memory.\",\n inputSchema: {\n type: \"object\",\n properties: {\n weekId: { type: \"string\" },\n candidateId: { type: \"string\" },\n dryRun: { type: \"boolean\", description: \"Preview without writing.\" },\n },\n required: [\"weekId\", \"candidateId\"],\n additionalProperties: false,\n },\n },\n // ── Compression Guidelines tools ────────────────────────────────────\n {\n name: \"engram.compression_guidelines_optimize\",\n description: \"Run compression guideline optimizer, optionally persisting new guidelines.\",\n inputSchema: {\n type: \"object\",\n properties: {\n dryRun: { type: \"boolean\" },\n eventLimit: { type: \"number\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.compression_guidelines_activate\",\n description: \"Promote staged compression guideline draft to active (after review).\",\n inputSchema: {\n type: \"object\",\n properties: {\n expectedContentHash: { type: \"string\" },\n expectedGuidelineVersion: { type: \"number\" },\n },\n additionalProperties: false,\n },\n },\n // ── Memory search & debug tools ────────────────────────────────────\n {\n name: \"engram.memory_search\",\n description: \"Direct semantic search over memory files using the QMD index. Returns matching memories with relevance scores.\",\n inputSchema: {\n type: \"object\",\n properties: {\n query: { type: \"string\" },\n namespace: { type: \"string\" },\n maxResults: { type: \"number\" },\n collection: { type: \"string\", description: \"QMD collection (omit for memory, 'global' for all)\" },\n },\n required: [\"query\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_profile\",\n description: \"Read the user's behavioral profile — a living document of their preferences, habits, and personality.\",\n inputSchema: {\n type: \"object\",\n properties: { namespace: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_entities_list\",\n description: \"List all tracked entities (people, projects, tools, companies).\",\n inputSchema: {\n type: \"object\",\n properties: { namespace: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_questions\",\n description: \"List open questions the system is curious about from past conversations.\",\n inputSchema: {\n type: \"object\",\n properties: { namespace: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_last_recall\",\n description: \"Return the last recall snapshot for a session (debug introspection).\",\n inputSchema: {\n type: \"object\",\n properties: { sessionKey: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_intent_debug\",\n description: \"Return the last intent classification debug snapshot.\",\n inputSchema: {\n type: \"object\",\n properties: { namespace: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_qmd_debug\",\n description: \"Return QMD search index debug information from the last recall.\",\n inputSchema: {\n type: \"object\",\n properties: { namespace: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_graph_explain\",\n description: \"Explain the last entity graph recall — which entities were activated and why.\",\n inputSchema: {\n type: \"object\",\n properties: { namespace: { type: \"string\" } },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_feedback\",\n description: \"Record relevance feedback (thumbs up/down) for a specific memory.\",\n inputSchema: {\n type: \"object\",\n properties: {\n memoryId: { type: \"string\" },\n vote: { type: \"string\", enum: [\"up\", \"down\"] },\n note: { type: \"string\" },\n },\n required: [\"memoryId\", \"vote\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.memory_promote\",\n description: \"Promote a memory's lifecycle state (e.g. from draft to active).\",\n inputSchema: {\n type: \"object\",\n properties: {\n memoryId: { type: \"string\" },\n namespace: { type: \"string\" },\n sessionKey: { type: \"string\" },\n },\n required: [\"memoryId\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.context_checkpoint\",\n description: \"Save a structured context checkpoint for a session (preserves conversation state to disk).\",\n inputSchema: {\n type: \"object\",\n properties: {\n sessionKey: { type: \"string\" },\n context: { type: \"string\", description: \"Context content to checkpoint\" },\n namespace: { type: \"string\" },\n },\n required: [\"sessionKey\", \"context\"],\n additionalProperties: false,\n },\n },\n // ── Daily Context Briefing (#370) ───────────────────────────────────\n // Uses the legacy \"engram.*\" prefix like every other tool in this array;\n // withToolAliases (applied via .flatMap below) generates the canonical\n // \"remnic.briefing\" alias automatically.\n ...(service.briefingEnabled ? [{\n name: \"engram.briefing\",\n description: \"Generate a daily context briefing by cross-referencing active entities, recent facts, open commitments, and optional calendar events.\",\n inputSchema: {\n type: \"object\",\n properties: {\n since: { type: \"string\", description: \"Lookback window (e.g. 'yesterday', '3d', '1w', '24h').\" },\n focus: { type: \"string\", description: \"Optional focus filter (e.g. 'person:Jane Doe', 'project:remnic-core', 'topic:retrieval').\" },\n namespace: { type: \"string\" },\n format: { type: \"string\", enum: [\"markdown\", \"json\"] },\n maxFollowups: { type: \"number\", description: \"Maximum LLM-suggested follow-ups (0 disables that section).\" },\n },\n additionalProperties: false,\n },\n }] : []),\n // ── Contradiction Review (issue #520) ────────────────────────────────\n {\n name: \"engram.review_list\",\n description: \"List contradiction review items pending user resolution.\",\n inputSchema: {\n type: \"object\",\n properties: {\n filter: { type: \"string\", enum: [\"all\", \"unresolved\", \"contradicts\", \"independent\", \"duplicates\", \"needs-user\"], description: \"Filter by verdict type. Default: unresolved.\" },\n namespace: { type: \"string\" },\n limit: { type: \"number\", description: \"Max items to return (default 50).\" },\n },\n additionalProperties: false,\n },\n },\n {\n name: \"engram.review_resolve\",\n description: \"Resolve a contradiction pair with a chosen verb.\",\n inputSchema: {\n type: \"object\",\n properties: {\n pairId: { type: \"string\", description: \"The contradiction pair ID to resolve.\" },\n verb: { type: \"string\", enum: [\"keep-a\", \"keep-b\", \"merge\", \"both-valid\", \"needs-more-context\"], description: \"Resolution action.\" },\n },\n required: [\"pairId\", \"verb\"],\n additionalProperties: false,\n },\n },\n {\n name: \"engram.contradiction_scan_run\",\n description: \"Run an on-demand contradiction scan over the memory corpus.\",\n inputSchema: {\n type: \"object\",\n properties: {\n namespace: { type: \"string\" },\n },\n additionalProperties: false,\n },\n },\n ].flatMap((tool) => withToolAliases(tool));\n }\n\n /** Get clientInfo for a specific MCP session. Returns undefined for non-MCP requests. */\n getClientInfo(sessionId?: string): { name: string; version?: string } | undefined {\n if (sessionId) {\n return this.clientInfoBySession.get(sessionId);\n }\n return undefined;\n }\n\n /** Pop the session ID generated during an initialize handshake, keyed by correlation ID. */\n popInitSessionId(correlationId: string): string | undefined {\n const sid = this.initSessionIds.get(correlationId);\n if (sid !== undefined) this.initSessionIds.delete(correlationId);\n return sid;\n }\n\n async handleRequest(request: JsonRpcRequest, options?: { principalOverride?: string; sessionId?: string; correlationId?: string }): Promise<Record<string, unknown> | null> {\n const id = request.id ?? null;\n const method = request.method ?? \"\";\n\n if (method === \"notifications/initialized\") return null;\n if (method === \"ping\") {\n return { jsonrpc: \"2.0\", id, result: {} };\n }\n if (method === \"initialize\") {\n const params = request.params ?? {};\n const rawClientInfo = params.clientInfo as { name?: string; version?: string } | undefined;\n // Generate a server-side session ID for this MCP session.\n // The caller should send this back as Mcp-Session-Id on subsequent requests.\n const newSessionId = randomUUID();\n if (rawClientInfo && typeof rawClientInfo.name === \"string\") {\n const info = { name: rawClientInfo.name, version: rawClientInfo.version as string | undefined };\n this.clientInfoBySession.set(newSessionId, info);\n // Evict oldest sessions if map exceeds limit\n if (this.clientInfoBySession.size > 1000) {\n const firstKey = this.clientInfoBySession.keys().next().value;\n if (firstKey) this.clientInfoBySession.delete(firstKey);\n }\n }\n const version = await getMcpServerVersion();\n // Store session ID keyed by correlation ID (unique per HTTP request) so\n // concurrent initializes with the same JSON-RPC id don't collide.\n const corrId = options?.correlationId;\n if (corrId) this.initSessionIds.set(corrId, newSessionId);\n return {\n jsonrpc: \"2.0\",\n id,\n result: {\n protocolVersion: MCP_PROTOCOL_VERSION,\n capabilities: {\n tools: {},\n },\n serverInfo: {\n name: \"remnic\",\n version,\n },\n },\n };\n }\n if (method === \"tools/list\") {\n return {\n jsonrpc: \"2.0\",\n id,\n result: {\n tools: this.tools,\n },\n };\n }\n if (method === \"tools/call\") {\n const params = request.params ?? {};\n const name = typeof params.name === \"string\" ? params.name : \"\";\n const argumentsObject =\n params.arguments && typeof params.arguments === \"object\" && !Array.isArray(params.arguments)\n ? (params.arguments as Record<string, unknown>)\n : {};\n\n try {\n const effectivePrincipal = options?.principalOverride ?? this.authenticatedPrincipal;\n const result = await this.callTool(name, argumentsObject, effectivePrincipal, options?.sessionId);\n return {\n jsonrpc: \"2.0\",\n id,\n result: {\n content: [{ type: \"text\", text: JSON.stringify(result, null, 2) }],\n structuredContent: result,\n isError: false,\n },\n };\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n return {\n jsonrpc: \"2.0\",\n id,\n result: {\n content: [{ type: \"text\", text: message }],\n isError: true,\n },\n };\n }\n }\n\n return {\n jsonrpc: \"2.0\",\n id,\n error: {\n code: -32601,\n message: `Method not found: ${method}`,\n },\n };\n }\n\n async runStdio(input: Readable, output: Writable): Promise<void> {\n input.on(\"data\", (chunk) => {\n this.buffer = Buffer.concat([this.buffer, Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk)]);\n this.scheduleFlush(output);\n });\n await new Promise<void>((resolve, reject) => {\n input.on(\"end\", resolve);\n input.on(\"error\", reject);\n });\n while (this.flushTask) {\n await this.flushTask;\n }\n }\n\n private scheduleFlush(output: Writable): void {\n if (this.flushTask) return;\n const task = this.flushBuffer(output)\n .catch((err) => {\n this.writeMessage(output, {\n jsonrpc: \"2.0\",\n id: null,\n error: {\n code: -32700,\n message: err instanceof Error ? err.message : String(err),\n },\n });\n })\n .finally(() => {\n if (this.flushTask === task) {\n this.flushTask = null;\n }\n if (this.buffer.length > 0) {\n this.scheduleFlush(output);\n }\n });\n this.flushTask = task;\n }\n\n private async flushBuffer(output: Writable): Promise<void> {\n while (true) {\n const headerEnd = this.buffer.indexOf(\"\\r\\n\\r\\n\");\n if (headerEnd < 0) return;\n const headerText = this.buffer.slice(0, headerEnd).toString(\"utf-8\");\n const headers = headerText.split(\"\\r\\n\");\n const contentLengthHeader = headers.find((line) => line.toLowerCase().startsWith(\"content-length:\"));\n if (!contentLengthHeader) {\n this.buffer = Buffer.alloc(0);\n return;\n }\n const contentLength = parseInt(contentLengthHeader.split(\":\")[1]?.trim() ?? \"0\", 10);\n if (!Number.isFinite(contentLength) || contentLength < 0) {\n this.buffer = Buffer.alloc(0);\n return;\n }\n const messageStart = headerEnd + 4;\n const messageEnd = messageStart + contentLength;\n if (this.buffer.length < messageEnd) return;\n const body = this.buffer.slice(messageStart, messageEnd).toString(\"utf-8\");\n this.buffer = this.buffer.slice(messageEnd);\n\n let parsed: JsonRpcRequest;\n try {\n parsed = JSON.parse(body) as JsonRpcRequest;\n } catch {\n this.writeMessage(output, {\n jsonrpc: \"2.0\",\n id: null,\n error: {\n code: -32700,\n message: \"Parse error\",\n },\n });\n continue;\n }\n const response = await this.handleRequest(parsed);\n if (response) {\n this.writeMessage(output, response);\n }\n }\n }\n\n private writeMessage(output: Writable, payload: Record<string, unknown>): void {\n const body = JSON.stringify(payload);\n const message = `Content-Length: ${Buffer.byteLength(body, \"utf-8\")}\\r\\n\\r\\n${body}`;\n output.write(message);\n }\n\n /**\n * Determine whether oai-mem-citation guidance should be appended to recall.\n * Returns true when explicitly enabled via config OR when auto-detect is\n * active and the current MCP session belongs to a Codex adapter client.\n *\n * When no sessionId is provided (e.g., stdio transport where there are no\n * HTTP headers carrying mcp-session-id), fall back to checking if there is\n * exactly one known session whose clientInfo matches the Codex pattern.\n * This covers the common stdio case where a single client connection exists.\n */\n private shouldEmitCitations(mcpSessionId?: string): boolean {\n if (this.citationsEnabled) return true;\n if (!this.citationsAutoDetect) return false;\n\n // Direct session lookup (HTTP transport with mcp-session-id header).\n if (mcpSessionId) {\n const info = this.clientInfoBySession.get(mcpSessionId);\n if (!info) return false;\n return this.isCodexClient(info);\n }\n\n // Stdio fallback: no session ID available. If there is exactly one session\n // registered (the typical stdio pattern), check that session's clientInfo.\n if (this.clientInfoBySession.size === 1) {\n const [info] = [...this.clientInfoBySession.values()];\n if (info) return this.isCodexClient(info);\n }\n\n return false;\n }\n\n /** Check whether a clientInfo record identifies a Codex adapter client. */\n private isCodexClient(info: { name: string; version?: string }): boolean {\n const lowerName = info.name.toLowerCase();\n return lowerName === \"codex-mcp-client\" || lowerName.includes(\"codex\");\n }\n\n /**\n * Build citation metadata for each recall result that has a path.\n * Line range defaults to 1-1 when not determinable from the summary.\n */\n private buildRecallCitations(response: EngramAccessRecallResponse): CitationMetadata[] {\n return response.results\n .filter((r) => r.path && r.path.length > 0)\n .map((r) => ({\n memoryId: r.id,\n path: r.path,\n lineStart: 1,\n lineEnd: 1,\n noteDefault: r.preview?.slice(0, 60) || r.id,\n }));\n }\n\n private async callTool(name: string, args: Record<string, unknown>, effectivePrincipal?: string, mcpSessionId?: string): Promise<unknown> {\n switch (toLegacyToolName(name)) {\n case \"engram.recall\": {\n const response = await this.service.recall({\n query: typeof args.query === \"string\" ? args.query : \"\",\n sessionKey: typeof args.sessionKey === \"string\" ? args.sessionKey : undefined,\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n topK: typeof args.topK === \"number\" && Number.isFinite(args.topK) ? args.topK : undefined,\n mode: typeof args.mode === \"string\" ? args.mode as RecallPlanMode | \"auto\" : undefined,\n includeDebug: args.includeDebug === true,\n });\n\n if (this.shouldEmitCitations(mcpSessionId)) {\n const citations = this.buildRecallCitations(response);\n const guidance = buildCitationGuidance(citations);\n if (guidance.length > 0) {\n return {\n ...response,\n context: response.context + guidance,\n citations,\n };\n }\n }\n return response;\n }\n case \"engram.recall_explain\":\n return this.service.recallExplain({\n sessionKey: typeof args.sessionKey === \"string\" ? args.sessionKey : undefined,\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n });\n case \"engram.day_summary\":\n return this.service.daySummary({\n memories: typeof args.memories === \"string\" ? args.memories : \"\",\n sessionKey: typeof args.sessionKey === \"string\" ? args.sessionKey : undefined,\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n });\n case \"engram.memory_governance_run\":\n return this.service.governanceRun({\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n mode: args.mode === \"apply\" ? \"apply\" : \"shadow\",\n recentDays: typeof args.recentDays === \"number\" && Number.isFinite(args.recentDays) ? args.recentDays : undefined,\n maxMemories: typeof args.maxMemories === \"number\" && Number.isFinite(args.maxMemories) ? args.maxMemories : undefined,\n batchSize: typeof args.batchSize === \"number\" && Number.isFinite(args.batchSize) ? args.batchSize : undefined,\n authenticatedPrincipal: effectivePrincipal,\n }, effectivePrincipal);\n case \"engram.procedure_mining_run\":\n return this.service.procedureMiningRun(\n {\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n authenticatedPrincipal: effectivePrincipal,\n },\n effectivePrincipal,\n );\n case \"engram.memory_get\":\n return this.service.memoryGet(\n typeof args.memoryId === \"string\" ? args.memoryId : \"\",\n typeof args.namespace === \"string\" ? args.namespace : undefined,\n effectivePrincipal,\n );\n case \"engram.memory_timeline\": {\n const limit = typeof args.limit === \"number\" && Number.isFinite(args.limit) ? args.limit : 200;\n return this.service.memoryTimeline(\n typeof args.memoryId === \"string\" ? args.memoryId : \"\",\n typeof args.namespace === \"string\" ? args.namespace : undefined,\n limit,\n effectivePrincipal,\n );\n }\n case \"engram.memory_store\":\n return this.service.memoryStore({\n schemaVersion: typeof args.schemaVersion === \"number\" ? args.schemaVersion : undefined,\n idempotencyKey: typeof args.idempotencyKey === \"string\" ? args.idempotencyKey : undefined,\n dryRun: args.dryRun === true,\n sessionKey: typeof args.sessionKey === \"string\" ? args.sessionKey : undefined,\n authenticatedPrincipal: effectivePrincipal,\n content: typeof args.content === \"string\" ? args.content : \"\",\n category: typeof args.category === \"string\" ? args.category : undefined,\n confidence: typeof args.confidence === \"number\" ? args.confidence : undefined,\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n tags: Array.isArray(args.tags) ? args.tags.filter((tag): tag is string => typeof tag === \"string\") : undefined,\n entityRef: typeof args.entityRef === \"string\" ? args.entityRef : undefined,\n ttl: typeof args.ttl === \"string\" ? args.ttl : undefined,\n sourceReason: typeof args.sourceReason === \"string\" ? args.sourceReason : undefined,\n });\n case \"engram.suggestion_submit\":\n return this.service.suggestionSubmit({\n schemaVersion: typeof args.schemaVersion === \"number\" ? args.schemaVersion : undefined,\n idempotencyKey: typeof args.idempotencyKey === \"string\" ? args.idempotencyKey : undefined,\n dryRun: args.dryRun === true,\n sessionKey: typeof args.sessionKey === \"string\" ? args.sessionKey : undefined,\n authenticatedPrincipal: effectivePrincipal,\n content: typeof args.content === \"string\" ? args.content : \"\",\n category: typeof args.category === \"string\" ? args.category : undefined,\n confidence: typeof args.confidence === \"number\" ? args.confidence : undefined,\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n tags: Array.isArray(args.tags) ? args.tags.filter((tag): tag is string => typeof tag === \"string\") : undefined,\n entityRef: typeof args.entityRef === \"string\" ? args.entityRef : undefined,\n ttl: typeof args.ttl === \"string\" ? args.ttl : undefined,\n sourceReason: typeof args.sourceReason === \"string\" ? args.sourceReason : undefined,\n });\n case \"engram.entity_get\":\n return this.service.entityGet(\n typeof args.name === \"string\" ? args.name : \"\",\n typeof args.namespace === \"string\" ? args.namespace : undefined,\n );\n case \"engram.review_queue_list\":\n return this.service.reviewQueue(\n typeof args.runId === \"string\" ? args.runId : undefined,\n typeof args.namespace === \"string\" ? args.namespace : undefined,\n effectivePrincipal,\n );\n case \"engram.observe\":\n return this.service.observe({\n sessionKey: typeof args.sessionKey === \"string\" ? args.sessionKey : \"\",\n messages: Array.isArray(args.messages) ? args.messages : [],\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n authenticatedPrincipal: effectivePrincipal,\n skipExtraction: args.skipExtraction === true,\n });\n case \"engram.lcm_search\":\n return this.service.lcmSearch({\n query: typeof args.query === \"string\" ? args.query : \"\",\n sessionKey: typeof args.sessionKey === \"string\" ? args.sessionKey : undefined,\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n limit: typeof args.limit === \"number\" && Number.isFinite(args.limit) ? args.limit : undefined,\n authenticatedPrincipal: effectivePrincipal,\n });\n // ── Continuity / Identity tools ───────────────────────────────────\n case \"engram.continuity_audit_generate\":\n return this.service.continuityAuditGenerate({\n period: args.period === \"monthly\" ? \"monthly\" : args.period === \"weekly\" ? \"weekly\" : undefined,\n key: typeof args.key === \"string\" ? args.key : undefined,\n });\n case \"engram.continuity_incident_open\":\n return this.service.continuityIncidentOpen({\n symptom: typeof args.symptom === \"string\" ? args.symptom : \"\",\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n principal: effectivePrincipal,\n triggerWindow: typeof args.triggerWindow === \"string\" ? args.triggerWindow : undefined,\n suspectedCause: typeof args.suspectedCause === \"string\" ? args.suspectedCause : undefined,\n });\n case \"engram.continuity_incident_close\":\n return this.service.continuityIncidentClose({\n id: typeof args.id === \"string\" ? args.id : \"\",\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n principal: effectivePrincipal,\n fixApplied: typeof args.fixApplied === \"string\" ? args.fixApplied : \"\",\n verificationResult: typeof args.verificationResult === \"string\" ? args.verificationResult : \"\",\n preventiveRule: typeof args.preventiveRule === \"string\" ? args.preventiveRule : undefined,\n });\n case \"engram.continuity_incident_list\":\n return this.service.continuityIncidentList({\n state: args.state === \"closed\" ? \"closed\" : args.state === \"all\" ? \"all\" : args.state === \"open\" ? \"open\" : undefined,\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n principal: effectivePrincipal,\n limit: typeof args.limit === \"number\" ? args.limit : undefined,\n });\n case \"engram.continuity_loop_add_or_update\":\n return this.service.continuityLoopAddOrUpdate({\n id: typeof args.id === \"string\" ? args.id : \"\",\n cadence: (args.cadence as \"daily\" | \"weekly\" | \"monthly\" | \"quarterly\") ?? \"weekly\",\n purpose: typeof args.purpose === \"string\" ? args.purpose : \"\",\n status: (args.status as \"active\" | \"paused\" | \"retired\") ?? \"active\",\n killCondition: typeof args.killCondition === \"string\" ? args.killCondition : \"\",\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n principal: effectivePrincipal,\n lastReviewed: typeof args.lastReviewed === \"string\" ? args.lastReviewed : undefined,\n notes: typeof args.notes === \"string\" ? args.notes : undefined,\n });\n case \"engram.continuity_loop_review\":\n return this.service.continuityLoopReview({\n id: typeof args.id === \"string\" ? args.id : \"\",\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n principal: effectivePrincipal,\n status: args.status === \"active\" || args.status === \"paused\" || args.status === \"retired\" ? args.status : undefined,\n notes: typeof args.notes === \"string\" ? args.notes : undefined,\n reviewedAt: typeof args.reviewedAt === \"string\" ? args.reviewedAt : undefined,\n });\n case \"engram.identity_anchor_get\":\n return this.service.identityAnchorGet({\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n principal: effectivePrincipal,\n });\n case \"engram.identity_anchor_update\":\n return this.service.identityAnchorUpdate({\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n principal: effectivePrincipal,\n identityTraits: typeof args.identityTraits === \"string\" ? args.identityTraits : undefined,\n communicationPreferences: typeof args.communicationPreferences === \"string\" ? args.communicationPreferences : undefined,\n operatingPrinciples: typeof args.operatingPrinciples === \"string\" ? args.operatingPrinciples : undefined,\n continuityNotes: typeof args.continuityNotes === \"string\" ? args.continuityNotes : undefined,\n });\n case \"engram.memory_identity\":\n return this.service.memoryIdentity({\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n principal: effectivePrincipal,\n });\n // ── Work Layer tools ──────────────────────────────────────────────\n case \"engram.work_task\":\n return this.service.workTask({\n action: (args.action as any) ?? \"list\",\n id: typeof args.id === \"string\" ? args.id : undefined,\n title: typeof args.title === \"string\" ? args.title : undefined,\n description: typeof args.description === \"string\" ? args.description : undefined,\n status: typeof args.status === \"string\" ? args.status : undefined,\n priority: typeof args.priority === \"string\" ? args.priority : undefined,\n owner: typeof args.owner === \"string\" ? args.owner : undefined,\n assignee: typeof args.assignee === \"string\" ? args.assignee : undefined,\n projectId: typeof args.projectId === \"string\" ? args.projectId : undefined,\n tags: Array.isArray(args.tags) ? args.tags.filter((x: unknown): x is string => typeof x === \"string\") : undefined,\n dueAt: typeof args.dueAt === \"string\" ? args.dueAt : undefined,\n });\n case \"engram.work_project\":\n return this.service.workProject({\n action: (args.action as any) ?? \"list\",\n id: typeof args.id === \"string\" ? args.id : undefined,\n name: typeof args.name === \"string\" ? args.name : undefined,\n description: typeof args.description === \"string\" ? args.description : undefined,\n status: typeof args.status === \"string\" ? args.status : undefined,\n owner: typeof args.owner === \"string\" ? args.owner : undefined,\n tags: Array.isArray(args.tags) ? args.tags.filter((x: unknown): x is string => typeof x === \"string\") : undefined,\n taskId: typeof args.taskId === \"string\" ? args.taskId : undefined,\n projectId: typeof args.projectId === \"string\" ? args.projectId : undefined,\n });\n case \"engram.work_board\":\n return this.service.workBoard({\n action: (args.action as any) ?? \"export_markdown\",\n projectId: typeof args.projectId === \"string\" ? args.projectId : undefined,\n snapshotJson: typeof args.snapshotJson === \"string\" ? args.snapshotJson : undefined,\n linkToMemory: args.linkToMemory === true,\n });\n // ── Shared Context / Compounding tools ─────────────────────────\n case \"engram.shared_context_write_output\":\n return this.service.sharedContextWriteOutput({\n agentId: typeof args.agentId === \"string\" ? args.agentId : \"\",\n title: typeof args.title === \"string\" ? args.title : \"\",\n content: typeof args.content === \"string\" ? args.content : \"\",\n });\n case \"engram.shared_feedback_record\":\n return this.service.sharedFeedbackRecord({\n agent: typeof args.agent === \"string\" ? args.agent : \"\",\n decision: (args.decision as any) ?? \"approved\",\n reason: typeof args.reason === \"string\" ? args.reason : \"\",\n date: typeof args.date === \"string\" ? args.date : undefined,\n learning: typeof args.learning === \"string\" ? args.learning : undefined,\n outcome: typeof args.outcome === \"string\" ? args.outcome : undefined,\n severity: args.severity === \"low\" || args.severity === \"medium\" || args.severity === \"high\" ? args.severity : undefined,\n confidence: typeof args.confidence === \"number\" ? args.confidence : undefined,\n workflow: typeof args.workflow === \"string\" ? args.workflow : undefined,\n tags: Array.isArray(args.tags) ? args.tags.filter((x: unknown): x is string => typeof x === \"string\") : undefined,\n evidenceWindowStart: typeof args.evidenceWindowStart === \"string\" ? args.evidenceWindowStart : undefined,\n evidenceWindowEnd: typeof args.evidenceWindowEnd === \"string\" ? args.evidenceWindowEnd : undefined,\n refs: Array.isArray(args.refs) ? args.refs.filter((x: unknown): x is string => typeof x === \"string\") : undefined,\n });\n case \"engram.shared_priorities_append\":\n return this.service.sharedPrioritiesAppend({\n agentId: typeof args.agentId === \"string\" ? args.agentId : \"\",\n text: typeof args.text === \"string\" ? args.text : \"\",\n });\n case \"engram.shared_context_cross_signals_run\":\n return this.service.sharedContextCrossSignalsRun({\n date: typeof args.date === \"string\" ? args.date : undefined,\n });\n case \"engram.shared_context_curate_daily\":\n return this.service.sharedContextCurateDaily({\n date: typeof args.date === \"string\" ? args.date : undefined,\n });\n case \"engram.compounding_weekly_synthesize\":\n return this.service.compoundingWeeklySynthesize({\n weekId: typeof args.weekId === \"string\" ? args.weekId : undefined,\n });\n case \"engram.compounding_promote_candidate\":\n return this.service.compoundingPromoteCandidate({\n weekId: typeof args.weekId === \"string\" ? args.weekId : \"\",\n candidateId: typeof args.candidateId === \"string\" ? args.candidateId : \"\",\n dryRun: args.dryRun === true,\n });\n // ── Compression Guidelines tools ───────────────────────────────────\n case \"engram.compression_guidelines_optimize\":\n return this.service.compressionGuidelinesOptimize({\n dryRun: args.dryRun === true,\n eventLimit: typeof args.eventLimit === \"number\" ? args.eventLimit : undefined,\n });\n case \"engram.compression_guidelines_activate\":\n return this.service.compressionGuidelinesActivate({\n expectedContentHash: typeof args.expectedContentHash === \"string\" ? args.expectedContentHash : undefined,\n expectedGuidelineVersion: typeof args.expectedGuidelineVersion === \"number\" ? args.expectedGuidelineVersion : undefined,\n });\n // ── Memory search & debug tools ──────────────────────────────────\n case \"engram.memory_search\":\n return this.service.memorySearch({\n query: typeof args.query === \"string\" ? args.query : \"\",\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n maxResults: typeof args.maxResults === \"number\" && Number.isFinite(args.maxResults) ? args.maxResults : undefined,\n collection: typeof args.collection === \"string\" ? args.collection : undefined,\n principal: effectivePrincipal,\n });\n case \"engram.memory_profile\":\n return this.service.memoryProfile(\n typeof args.namespace === \"string\" ? args.namespace : undefined,\n effectivePrincipal,\n );\n case \"engram.memory_entities_list\":\n return this.service.memoryEntitiesList(\n typeof args.namespace === \"string\" ? args.namespace : undefined,\n effectivePrincipal,\n );\n case \"engram.memory_questions\":\n return this.service.memoryQuestions(\n typeof args.namespace === \"string\" ? args.namespace : undefined,\n effectivePrincipal,\n );\n case \"engram.memory_last_recall\":\n return this.service.lastRecallSnapshot(\n typeof args.sessionKey === \"string\" ? args.sessionKey : undefined,\n );\n case \"engram.memory_intent_debug\":\n return this.service.intentDebug(\n typeof args.namespace === \"string\" ? args.namespace : undefined,\n );\n case \"engram.memory_qmd_debug\":\n return this.service.qmdDebug(\n typeof args.namespace === \"string\" ? args.namespace : undefined,\n );\n case \"engram.memory_graph_explain\":\n return this.service.graphExplainLastRecall(\n typeof args.namespace === \"string\" ? args.namespace : undefined,\n );\n case \"engram.memory_feedback\":\n return this.service.memoryFeedback({\n memoryId: typeof args.memoryId === \"string\" ? args.memoryId : \"\",\n vote: args.vote === \"down\" ? \"down\" : \"up\",\n note: typeof args.note === \"string\" ? args.note : undefined,\n });\n case \"engram.memory_promote\":\n return this.service.memoryPromote({\n memoryId: typeof args.memoryId === \"string\" ? args.memoryId : \"\",\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n principal: effectivePrincipal,\n sessionKey: typeof args.sessionKey === \"string\" ? args.sessionKey : undefined,\n });\n case \"engram.context_checkpoint\":\n return this.service.contextCheckpoint({\n sessionKey: typeof args.sessionKey === \"string\" ? args.sessionKey : \"\",\n context: typeof args.context === \"string\" ? args.context : \"\",\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n principal: effectivePrincipal,\n });\n // ── Daily Context Briefing (#370) ───────────────────────────────────\n case \"engram.briefing\": {\n // Validate the format value upfront — unsupported values (e.g. \"xml\")\n // must be rejected with a descriptive error rather than silently\n // falling back to the default format.\n const rawFormat = typeof args.format === \"string\" ? args.format : undefined;\n const formatErr = validateBriefingFormat(rawFormat);\n if (formatErr) throw new Error(formatErr);\n return this.service.briefing({\n since: typeof args.since === \"string\" ? args.since : undefined,\n focus: typeof args.focus === \"string\" ? args.focus : undefined,\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n format: rawFormat as \"json\" | \"markdown\" | undefined,\n maxFollowups:\n typeof args.maxFollowups === \"number\" ? args.maxFollowups : undefined,\n principal: effectivePrincipal,\n });\n }\n // ── Contradiction Review (issue #520) ──────────────────────────────────\n case \"engram.review_list\":\n case \"remnic.review_list\": {\n const { listPairs } = await import(\"./contradiction/contradiction-review.js\");\n const filter = typeof args.filter === \"string\" ? args.filter as \"all\" | \"unresolved\" | \"contradicts\" | \"independent\" | \"duplicates\" | \"needs-user\" : \"unresolved\";\n const ns = typeof args.namespace === \"string\" ? args.namespace : undefined;\n const limit = typeof args.limit === \"number\" ? args.limit : 50;\n return listPairs(this.service.memoryDir, { filter, namespace: ns, limit });\n }\n case \"engram.review_resolve\":\n case \"remnic.review_resolve\": {\n const pairId = typeof args.pairId === \"string\" ? args.pairId : \"\";\n const verb = typeof args.verb === \"string\" ? args.verb : \"\";\n if (!pairId) throw new Error(\"pairId is required\");\n if (!verb) throw new Error(\"verb is required\");\n const { isValidResolutionVerb } = await import(\"./contradiction/resolution.js\");\n if (!isValidResolutionVerb(verb)) throw new Error(`Invalid verb: ${verb}. Must be one of: keep-a, keep-b, merge, both-valid, needs-more-context`);\n const { executeResolution } = await import(\"./contradiction/resolution.js\");\n return executeResolution(this.service.memoryDir, this.service.storageRef, pairId, verb);\n }\n case \"engram.contradiction_scan_run\":\n case \"remnic.contradiction_scan_run\": {\n const { runContradictionScan } = await import(\"./contradiction/contradiction-scan.js\");\n return runContradictionScan({\n storage: this.service.storageRef,\n config: this.service.configRef,\n memoryDir: this.service.memoryDir,\n embeddingLookup: this.service.embeddingLookupRef,\n localLlm: this.service.localLlmRef,\n fallbackLlm: this.service.fallbackLlmRef,\n namespace: typeof args.namespace === \"string\" ? args.namespace : undefined,\n });\n }\n default:\n throw new Error(`unknown tool: ${name}`);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AACA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAsB3B,IAAM,uBAAuB;AAC7B,IAAM,oBAAoB;AAC1B,IAAM,uBAAuB;AAE7B,SAAS,oBAAoB,MAAsB;AACjD,SAAO,KAAK,WAAW,iBAAiB,IACpC,GAAG,oBAAoB,GAAG,KAAK,MAAM,kBAAkB,MAAM,CAAC,KAC9D;AACN;AAEA,SAAS,iBAAiB,MAAsB;AAC9C,SAAO,KAAK,WAAW,oBAAoB,IACvC,GAAG,iBAAiB,GAAG,KAAK,MAAM,qBAAqB,MAAM,CAAC,KAC9D;AACN;AAEA,SAAS,gBAAgB,MAA0B;AACjD,QAAM,gBAAgB,oBAAoB,KAAK,IAAI;AACnD,QAAM,gBAAgB,kBAAkB,KAAK,OAAO,OAAO,EAAE,GAAG,MAAM,MAAM,cAAc;AAC1F,MAAI,kBAAkB,KAAK,KAAM,QAAO,CAAC,aAAa;AACtD,SAAO,CAAC,eAAe,IAAI;AAC7B;AAEA,eAAe,sBAAuC;AACpD,QAAM,aACJ,WAAW,yBAAyB,GAAG,KAAK,KAC5C,WAAW,qBAAqB,GAAG,KAAK;AAC1C,MAAI,WAAY,QAAO;AACvB,MAAI;AACF,UAAM,UAAU,IAAI,IAAI,mBAAmB,YAAY,GAAG;AAC1D,UAAM,MAAM,MAAM,SAAS,SAAS,OAAO;AAC3C,UAAM,SAAS,KAAK,MAAM,GAAG;AAC7B,WAAO,OAAO,SAAS,KAAK,KAAK;AAAA,EACnC,QAAQ;AACN,WAAO;AAAA,EAC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AAkB,IAAI,MAAM,OAAO,0BAA+B;AAC1E,eAAO,kBAAkB,KAAK,QAAQ,WAAW,KAAK,QAAQ,YAAY,QAAQ,IAAI;AAAA,MACxF;AAAA,MACA,KAAK;AAAA,MACL,KAAK,iCAAiC;AACpC,cAAM,EAAE,qBAAqB,IAAI,MAAM,OAAO,kCAAuC;AACrF,eAAO,qBAAqB;AAAA,UAC1B,SAAS,KAAK,QAAQ;AAAA,UACtB,QAAQ,KAAK,QAAQ;AAAA,UACrB,WAAW,KAAK,QAAQ;AAAA,UACxB,iBAAiB,KAAK,QAAQ;AAAA,UAC9B,UAAU,KAAK,QAAQ;AAAA,UACvB,aAAa,KAAK,QAAQ;AAAA,UAC1B,WAAW,OAAO,KAAK,cAAc,WAAW,KAAK,YAAY;AAAA,QACnE,CAAC;AAAA,MACH;AAAA,MACA;AACE,cAAM,IAAI,MAAM,iBAAiB,IAAI,EAAE;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/taxonomy/resolver.ts"],"sourcesContent":["/**\n * Resolver decision tree for the MECE taxonomy.\n *\n * Given extracted content and its MemoryCategory, determines which\n * taxonomy category the knowledge should be filed under.\n */\n\nimport type { MemoryCategory } from \"../types.js\";\nimport type { ResolverDecision, Taxonomy, TaxonomyCategory } from \"./types.js\";\n\nconst DEFAULT_CATEGORY_ID = \"facts\";\n\n/**\n * Resolve a piece of content to a taxonomy category.\n *\n * Algorithm:\n * 1. Find all taxonomy categories whose `memoryCategories` include\n * the given `memoryCategory`.\n * 2. If exactly one match, return it with confidence 1.0.\n * 3. If multiple matches, pick the one with the lowest priority\n * number (highest precedence). Apply keyword heuristics from\n * filing rules as a secondary signal.\n * 4. If no match, fall back to the \"facts\" category (or first\n * category if \"facts\" is absent) with low confidence.\n * 5. Always populate `alternatives` with other plausible categories.\n */\nexport function resolveCategory(\n content: string,\n memoryCategory: MemoryCategory,\n taxonomy: Taxonomy,\n): ResolverDecision {\n const contentLower = content.toLowerCase();\n\n // Step 1: find matching categories\n const matches = taxonomy.categories.filter((cat) =>\n cat.memoryCategories.includes(memoryCategory),\n );\n\n if (matches.length === 0) {\n // No taxonomy category accepts this MemoryCategory — fall back\n const fallback =\n taxonomy.categories.find((c) => c.id === DEFAULT_CATEGORY_ID) ??\n taxonomy.categories[0];\n if (!fallback) {\n return {\n categoryId: DEFAULT_CATEGORY_ID,\n confidence: 0,\n reason: \"Taxonomy is empty; using default category\",\n alternatives: [],\n };\n }\n const alternatives = taxonomy.categories\n .filter((c) => c.id !== fallback.id)\n .map((c) => ({\n categoryId: c.id,\n reason: c.description,\n }));\n return {\n categoryId: fallback.id,\n confidence: 0.3,\n reason: `No taxonomy category maps to MemoryCategory \"${memoryCategory}\"; falling back to \"${fallback.name}\"`,\n alternatives,\n };\n }\n\n if (matches.length === 1) {\n const match = matches[0]!;\n const alternatives = taxonomy.categories\n .filter((c) => c.id !== match.id)\n .map((c) => ({\n categoryId: c.id,\n reason: c.description,\n }));\n return {\n categoryId: match.id,\n confidence: 1.0,\n reason: `Unique match: MemoryCategory \"${memoryCategory}\" maps to \"${match.name}\"`,\n alternatives,\n };\n }\n\n // Multiple matches — use filing rule keyword heuristics + priority\n const scored = matches.map((cat) => ({\n cat,\n keywordScore: computeKeywordScore(contentLower, cat),\n }));\n\n // Sort by keyword score descending, then priority ascending (lower wins)\n scored.sort((a, b) => {\n if (b.keywordScore !== a.keywordScore) return b.keywordScore - a.keywordScore;\n return a.cat.priority - b.cat.priority;\n });\n\n const best = scored[0]!;\n const runnerUp = scored[1];\n\n // Confidence is higher when keyword match clearly differentiates\n const confidence =\n best.keywordScore > 0 && (!runnerUp || best.keywordScore > runnerUp.keywordScore)\n ? 0.9\n : 0.7;\n\n const alternatives = taxonomy.categories\n .filter((c) => c.id !== best.cat.id)\n .map((c) => ({\n categoryId: c.id,\n reason: c.description,\n }));\n\n const reason =\n best.keywordScore > 0\n ? `Filing rules for \"${best.cat.name}\" matched content keywords (priority ${best.cat.priority})`\n : `Priority tie-break: \"${best.cat.name}\" has lowest priority number (${best.cat.priority})`;\n\n return {\n categoryId: best.cat.id,\n confidence,\n reason,\n alternatives,\n };\n}\n\n/**\n * Compute a simple keyword overlap score between content and\n * a category's filing rules + description.\n */\nfunction computeKeywordScore(contentLower: string, cat: TaxonomyCategory): number {\n let score = 0;\n const ruleText = [...cat.filingRules, cat.description]\n .join(\" \")\n .toLowerCase();\n\n // Extract meaningful words (3+ chars) from the rule text\n const keywords = ruleText\n .split(/[^a-z0-9]+/)\n .filter((w) => w.length >= 3);\n\n for (const kw of keywords) {\n if (contentLower.includes(kw)) {\n score += 1;\n }\n }\n return score;\n}\n"],"mappings":";AAUA,IAAM,sBAAsB;AAgBrB,SAAS,gBACd,SACA,gBACA,UACkB;AAClB,QAAM,eAAe,QAAQ,YAAY;AAGzC,QAAM,UAAU,SAAS,WAAW;AAAA,IAAO,CAAC,QAC1C,IAAI,iBAAiB,SAAS,cAAc;AAAA,EAC9C;AAEA,MAAI,QAAQ,WAAW,GAAG;AAExB,UAAM,WACJ,SAAS,WAAW,KAAK,CAAC,MAAM,EAAE,OAAO,mBAAmB,KAC5D,SAAS,WAAW,CAAC;AACvB,QAAI,CAAC,UAAU;AACb,aAAO;AAAA,QACL,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,QAAQ;AAAA,QACR,cAAc,CAAC;AAAA,MACjB;AAAA,IACF;AACA,UAAMA,gBAAe,SAAS,WAC3B,OAAO,CAAC,MAAM,EAAE,OAAO,SAAS,EAAE,EAClC,IAAI,CAAC,OAAO;AAAA,MACX,YAAY,EAAE;AAAA,MACd,QAAQ,EAAE;AAAA,IACZ,EAAE;AACJ,WAAO;AAAA,MACL,YAAY,SAAS;AAAA,MACrB,YAAY;AAAA,MACZ,QAAQ,gDAAgD,cAAc,uBAAuB,SAAS,IAAI;AAAA,MAC1G,cAAAA;AAAA,IACF;AAAA,EACF;AAEA,MAAI,QAAQ,WAAW,GA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AM,WAAW,CAAC,GAAG,IAAI,aAAa,IAAI,WAAW,EAClD,KAAK,GAAG,EACR,YAAY;AAGf,QAAM,WAAW,SACd,MAAM,YAAY,EAClB,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC;AAE9B,aAAW,MAAM,UAAU;AACzB,QAAI,aAAa,SAAS,EAAE,GAAG;AAC7B,eAAS;AAAA,IACX;AAAA,EACF;AACA,SAAO;AACT;","names":["alternatives"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/iso-timestamp.ts","../src/replay/types.ts","../src/routing/store.ts"],"sourcesContent":["// ---------------------------------------------------------------------------\n// Shared ISO-8601 / RFC 3339 timestamp validation helpers.\n//\n// Two public entry points — a strict UTC-only parser used by the replay\n// pipeline, and a more permissive parser used by bulk-import adapters that\n// need to preserve source timezone offsets. Both share date-component,\n// offset-range, and round-trip validation so they cannot silently diverge.\n// ---------------------------------------------------------------------------\n\n// UTC-only: `...Z`, 0 or 3 fractional digits (replay canonical form).\nconst ISO_UTC_TIMESTAMP_RE =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{3})?Z$/;\n\n// Lenient: variable-precision fractional seconds and `Z` or `[+-]HH:MM` offset.\nconst ISO_OFFSET_TIMESTAMP_RE =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$/;\n\n/**\n * Validate the date/time components of an ISO timestamp string.\n * Catches overflowed dates like Feb 31 that `Date.parse` silently normalizes.\n */\nfunction validateDateComponents(isoString: string): boolean {\n const match = isoString.match(\n /^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})/,\n );\n if (!match) return false;\n const [, yStr, mStr, dStr, hStr, minStr, sStr] = match;\n const y = Number(yStr);\n const m = Number(mStr);\n const d = Number(dStr);\n const h = Number(hStr);\n const min = Number(minStr);\n const s = Number(sStr);\n if (m < 1 || m > 12) return false;\n if (d < 1 || d > 31) return false;\n if (h > 23 || min > 59 || s > 59) return false;\n // Validate day for the specific month (using Date(y, m, 0) to get days).\n const daysInMonth = new Date(y, m, 0).getDate();\n if (d > daysInMonth) return false;\n return true;\n}\n\n/**\n * Validate the timezone offset range if present.\n * Max offset is +/-14:00 per ISO 8601; minute part must be 0-59.\n */\nfunction validateOffset(isoString: string): boolean {\n const offsetMatch = isoString.match(/([+-])(\\d{2}):(\\d{2})$/);\n if (!offsetMatch) return true; // `Z` form, no offset to validate.\n const oh = Number(offsetMatch[2]);\n const om = Number(offsetMatch[3]);\n if (oh > 14 || om > 59) return false;\n // +14:00 is max; offsets like +14:30 are invalid.\n if (oh === 14 && om > 0) return false;\n return true;\n}\n\n/**\n * Normalize a `Z`-suffixed ISO timestamp to exactly three fractional digits so\n * the round-trip comparison against `Date.prototype.toISOString()` succeeds\n * regardless of input precision (or absence of a fractional part).\n */\nfunction normalizeUtcForComparison(value: string): string {\n const fracMatch = value.match(/\\.(\\d+)Z$/);\n if (fracMatch) {\n const ms = (fracMatch[1] + \"000\").slice(0, 3);\n return value.replace(/\\.\\d+Z$/, `.${ms}Z`);\n }\n return value.replace(/Z$/, \".000Z\");\n}\n\n/**\n * Strict UTC-only parser — accepts `YYYY-MM-DDTHH:MM:SS[.sss]Z`.\n * Returns milliseconds since epoch, or `null` if invalid.\n */\nexport function parseIsoUtcTimestamp(value: string): number | null {\n if (typeof value !== \"string\" || !ISO_UTC_TIMESTAMP_RE.test(value)) {\n return null;\n }\n const ts = Date.parse(value);\n if (!Number.isFinite(ts)) return null;\n if (!validateDateComponents(value)) return null;\n const roundTrip = new Date(ts).toISOString();\n if (roundTrip !== normalizeUtcForComparison(value)) return null;\n return ts;\n}\n\n/**\n * Lenient parser — accepts variable-precision fractional seconds and either\n * a `Z` suffix or a `[+-]HH:MM` offset. Returns milliseconds since epoch, or\n * `null` if the string is not a well-formed RFC 3339 timestamp.\n */\nexport function parseIsoOffsetTimestamp(value: string): number | null {\n if (typeof value !== \"string\" || !ISO_OFFSET_TIMESTAMP_RE.test(value)) {\n return null;\n }\n const ts = Date.parse(value);\n if (!Number.isFinite(ts)) return null;\n if (!validateDateComponents(value)) return null;\n if (!validateOffset(value)) return null;\n // For UTC timestamps (ending in `Z`), verify with a round-trip so that\n // overflowed UTC calendar dates cannot slip through.\n if (value.endsWith(\"Z\")) {\n const roundTrip = new Date(ts).toISOString();\n if (roundTrip !== normalizeUtcForComparison(value)) return null;\n }\n return ts;\n}\n","import { parseIsoUtcTimestamp } from \"../utils/iso-timestamp.js\";\n\nexport type ReplaySource = \"openclaw\" | \"claude\" | \"chatgpt\";\nexport type ReplayRole = \"user\" | \"assistant\";\n\nexport interface ReplayTurn {\n source: ReplaySource;\n sessionKey: string;\n role: ReplayRole;\n content: string;\n timestamp: string;\n externalId?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface ReplayWarning {\n code: string;\n message: string;\n index?: number;\n}\n\nexport interface ReplayValidationIssue {\n code: string;\n message: string;\n index?: number;\n}\n\nexport interface ReplayParseOptions {\n from?: string;\n to?: string;\n defaultSessionKey?: string;\n strict?: boolean;\n}\n\nexport interface ReplayParseResult {\n turns: ReplayTurn[];\n warnings: ReplayWarning[];\n}\n\nexport interface ReplayNormalizer {\n source: ReplaySource;\n parse(input: unknown, options?: ReplayParseOptions): Promise<ReplayParseResult> | ReplayParseResult;\n}\n\nconst VALID_SOURCES: ReadonlySet<string> = new Set([\"openclaw\", \"claude\", \"chatgpt\"]);\nconst VALID_ROLES: ReadonlySet<string> = new Set([\"user\", \"assistant\"]);\nexport const REPLAY_UNKNOWN_SESSION_KEY = \"replay:unknown\";\n\nexport function isReplaySource(value: unknown): value is ReplaySource {\n return typeof value === \"string\" && VALID_SOURCES.has(value);\n}\n\nexport function isReplayRole(value: unknown): value is ReplayRole {\n return typeof value === \"string\" && VALID_ROLES.has(value);\n}\n\nexport function normalizeReplaySessionKey(value: unknown): string {\n if (typeof value !== \"string\") return REPLAY_UNKNOWN_SESSION_KEY;\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : REPLAY_UNKNOWN_SESSION_KEY;\n}\n\n/**\n * Strict UTC-only ISO-8601 parser used by the replay pipeline.\n *\n * Delegates to the shared parser in `utils/iso-timestamp.ts` — do not\n * reimplement locally; extend that helper instead. Replay intentionally\n * rejects timezone-offset timestamps to keep canonical form consistent\n * across recorded transcripts.\n */\nexport function parseIsoTimestamp(value: string): number | null {\n return parseIsoUtcTimestamp(value);\n}\n\nexport function validateReplayTurn(turn: ReplayTurn, index?: number): ReplayValidationIssue[] {\n const issues: ReplayValidationIssue[] = [];\n if (!turn || typeof turn !== \"object\") {\n issues.push({\n code: \"turn.invalid\",\n message: \"Replay turn must be an object.\",\n index,\n });\n return issues;\n }\n\n if (!isReplayRole(turn.role)) {\n issues.push({\n code: \"turn.role.invalid\",\n message: `Replay role must be 'user' or 'assistant', received '${String(turn.role)}'.`,\n index,\n });\n }\n\n if (!isReplaySource(turn.source)) {\n issues.push({\n code: \"turn.source.invalid\",\n message: `Replay source must be 'openclaw', 'claude', or 'chatgpt', received '${String(turn.source)}'.`,\n index,\n });\n }\n\n if (!turn.sessionKey || typeof turn.sessionKey !== \"string\" || turn.sessionKey.trim().length === 0) {\n issues.push({\n code: \"turn.sessionKey.invalid\",\n message: \"Replay sessionKey is required.\",\n index,\n });\n }\n\n if (!turn.content || typeof turn.content !== \"string\" || turn.content.trim().length === 0) {\n issues.push({\n code: \"turn.content.invalid\",\n message: \"Replay content must be a non-empty string.\",\n index,\n });\n }\n\n if (!turn.timestamp || typeof turn.timestamp !== \"string\" || parseIsoTimestamp(turn.timestamp) === null) {\n issues.push({\n code: \"turn.timestamp.invalid\",\n message: `Replay timestamp must be a valid ISO timestamp, received '${String(turn.timestamp)}'.`,\n index,\n });\n }\n\n return issues;\n}\n","import { lstat, mkdir, readFile, realpath, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createHash } from \"node:crypto\";\nimport { log } from \"../logger.js\";\nimport { validateRouteTarget, type RouteRule, type RoutingEngineOptions } from \"./engine.js\";\n\ntype RoutingRulesState = {\n version: 1;\n updatedAt: string;\n rules: RouteRule[];\n};\n\nfunction defaultState(): RoutingRulesState {\n return {\n version: 1,\n updatedAt: new Date(0).toISOString(),\n rules: [],\n };\n}\n\nfunction stableRuleId(rule: Pick<RouteRule, \"patternType\" | \"pattern\" | \"priority\" | \"target\">): string {\n const seed = JSON.stringify({\n patternType: rule.patternType,\n pattern: rule.pattern.trim(),\n priority: rule.priority,\n target: rule.target,\n });\n return `route-${createHash(\"sha256\").update(seed).digest(\"hex\").slice(0, 12)}`;\n}\n\nfunction resolveStatePath(memoryDir: string, stateFile: string): string {\n const root = path.resolve(memoryDir);\n const defaultPath = path.join(root, \"state\", \"routing-rules.json\");\n if (path.isAbsolute(stateFile)) {\n const absolute = path.resolve(stateFile);\n return absolute.startsWith(root + path.sep) ? absolute : defaultPath;\n }\n const resolved = path.resolve(root, stateFile);\n return resolved.startsWith(root + path.sep) ? resolved : defaultPath;\n}\n\nfunction normalizeRule(rule: RouteRule, options?: RoutingEngineOptions): RouteRule | null {\n if (!rule || typeof rule !== \"object\") return null;\n if (rule.enabled === false) return null;\n if (rule.patternType !== \"keyword\" && rule.patternType !== \"regex\") return null;\n if (typeof rule.pattern !== \"string\" || rule.pattern.trim().length === 0) return null;\n if (typeof rule.priority !== \"number\" || !Number.isFinite(rule.priority)) return null;\n\n const targetValidation = validateRouteTarget(rule.target, options);\n if (!targetValidation.ok || !targetValidation.target) return null;\n\n const normalizedPriority = Math.trunc(rule.priority);\n const normalizedTarget = targetValidation.target;\n const id = typeof rule.id === \"string\" && rule.id.trim().length > 0\n ? rule.id.trim()\n : stableRuleId({\n patternType: rule.patternType,\n pattern: rule.pattern.trim(),\n priority: normalizedPriority,\n target: normalizedTarget,\n });\n return {\n id,\n patternType: rule.patternType,\n pattern: rule.pattern.trim(),\n priority: normalizedPriority,\n target: normalizedTarget,\n enabled: true,\n };\n}\n\nexport class RoutingRulesStore {\n private readonly memoryRoot: string;\n private readonly statePath: string;\n private readonly lockPath: string;\n private writeQueue: Promise<void> = Promise.resolve();\n\n constructor(memoryDir: string, stateFile = \"state/routing-rules.json\") {\n this.memoryRoot = path.resolve(memoryDir);\n this.statePath = resolveStatePath(memoryDir, stateFile);\n this.lockPath = `${this.statePath}.lock`;\n }\n\n async read(options?: RoutingEngineOptions): Promise<RouteRule[]> {\n try {\n const persisted = await this.readPersistedRules();\n return persisted\n .map((rule) => normalizeRule(rule, options))\n .filter((rule): rule is RouteRule => rule !== null);\n } catch {\n return [];\n }\n }\n\n async write(rules: RouteRule[], options?: RoutingEngineOptions): Promise<RouteRule[]> {\n return this.withWriteLock(async () => this.writeNormalized(rules, options));\n }\n\n async upsert(rule: RouteRule, options?: RoutingEngineOptions): Promise<RouteRule[]> {\n return this.withWriteLock(async () => {\n const existing = await this.readPersistedRules();\n const normalized = normalizeRule(rule, options);\n if (!normalized) return existing;\n\n const next = existing.filter((entry) => entry.id !== normalized.id);\n next.push(normalized);\n return this.writeNormalized(next);\n });\n }\n\n async removeByPattern(pattern: string): Promise<RouteRule[]> {\n return this.withWriteLock(async () => {\n const trimmed = pattern.trim();\n const existing = await this.readPersistedRules();\n const next = existing.filter((entry) => entry.pattern !== trimmed);\n if (next.length === existing.length) return existing;\n return this.writeNormalized(next);\n });\n }\n\n async reset(): Promise<void> {\n await this.withWriteLock(async () => {\n const payload = defaultState();\n await this.assertStatePathScoped();\n await writeFile(this.statePath, JSON.stringify(payload, null, 2), \"utf-8\");\n });\n }\n\n private dedupeById(rules: RouteRule[]): RouteRule[] {\n const byId = new Map<string, RouteRule>();\n for (const rule of rules) {\n byId.set(rule.id, rule);\n }\n return Array.from(byId.values());\n }\n\n private async readPersistedRules(): Promise<RouteRule[]> {\n try {\n await this.assertStatePathScoped();\n const raw = await readFile(this.statePath, \"utf-8\");\n const parsed = JSON.parse(raw) as Partial<RoutingRulesState>;\n if (!parsed || typeof parsed !== \"object\" || !Array.isArray(parsed.rules)) return [];\n const normalized = parsed.rules\n .map((rule) => normalizeRule(rule))\n .filter((rule): rule is RouteRule => rule !== null);\n return this.dedupeById(normalized);\n } catch {\n return [];\n }\n }\n\n private async writeNormalized(rules: RouteRule[], options?: RoutingEngineOptions): Promise<RouteRule[]> {\n const normalized = this.dedupeById(\n rules\n .map((rule) => normalizeRule(rule, options))\n .filter((rule): rule is RouteRule => rule !== null),\n );\n\n const payload: RoutingRulesState = {\n version: 1,\n updatedAt: new Date().toISOString(),\n rules: normalized,\n };\n\n const tmpPath = `${this.statePath}.tmp-${process.pid}-${Date.now()}`;\n try {\n await this.assertStatePathScoped();\n await writeFile(tmpPath, JSON.stringify(payload, null, 2), \"utf-8\");\n await rename(tmpPath, this.statePath);\n } catch (err) {\n log.debug(`routing rules write failed: ${err}`);\n throw err;\n } finally {\n await rm(tmpPath, { force: true }).catch(() => {});\n }\n\n return normalized;\n }\n\n private async withWriteLock<T>(op: () => Promise<T>): Promise<T> {\n const previous = this.writeQueue;\n let release: () => void = () => {};\n this.writeQueue = new Promise<void>((resolve) => {\n release = resolve;\n });\n await previous;\n let unlock: (() => Promise<void>) | null = null;\n try {\n unlock = await this.acquireFileLock();\n return await op();\n } finally {\n if (unlock) await unlock();\n release();\n }\n }\n\n private async acquireFileLock(): Promise<() => Promise<void>> {\n const start = Date.now();\n const staleMs = 30_000;\n const timeoutMs = 5_000;\n let unexpectedLockError: unknown = null;\n await this.assertStatePathScoped();\n await mkdir(path.dirname(this.lockPath), { recursive: true });\n\n while (Date.now() - start < timeoutMs) {\n try {\n await mkdir(this.lockPath);\n return async () => {\n try {\n await rm(this.lockPath, { recursive: true, force: true });\n } catch {\n // Fail-open: lock cleanup should not fail writes.\n }\n };\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code !== \"EEXIST\") {\n unexpectedLockError = err;\n break;\n }\n try {\n const lockStat = await stat(this.lockPath);\n if (Date.now() - lockStat.mtimeMs > staleMs) {\n await rm(this.lockPath, { recursive: true, force: true });\n continue;\n }\n } catch {\n // Lock may have been released between stat/rm attempts.\n }\n await new Promise((resolve) => setTimeout(resolve, 25));\n }\n }\n\n if (unexpectedLockError) {\n throw unexpectedLockError;\n }\n throw new Error(`routing rules lock acquisition timed out after ${timeoutMs}ms`);\n }\n\n private async assertStatePathScoped(): Promise<void> {\n await mkdir(this.memoryRoot, { recursive: true });\n const canonicalRoot = await realpath(this.memoryRoot);\n const canonicalParent = await this.canonicalizePathWithoutCreating(path.dirname(this.statePath));\n const canonicalStatePath = path.join(canonicalParent, path.basename(this.statePath));\n if (!this.isPathInside(canonicalRoot, canonicalStatePath)) {\n throw new Error(`routing rules state path escaped memoryDir: ${canonicalStatePath}`);\n }\n await mkdir(path.dirname(this.statePath), { recursive: true });\n try {\n const stateStats = await lstat(this.statePath);\n if (stateStats.isSymbolicLink()) {\n const canonicalFile = await realpath(this.statePath);\n if (!this.isPathInside(canonicalRoot, canonicalFile)) {\n throw new Error(`routing rules state symlink escaped memoryDir: ${canonicalFile}`);\n }\n }\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code !== \"ENOENT\") {\n throw err;\n }\n }\n }\n\n private isPathInside(root: string, candidate: string): boolean {\n const normalizedRoot = path.resolve(root);\n const normalizedCandidate = path.resolve(candidate);\n if (normalizedCandidate === normalizedRoot) return true;\n if (normalizedRoot === path.parse(normalizedRoot).root) {\n return normalizedCandidate.startsWith(normalizedRoot);\n }\n return normalizedCandidate.startsWith(`${normalizedRoot}${path.sep}`);\n }\n\n private async canonicalizePathWithoutCreating(targetPath: string): Promise<string> {\n const absoluteTarget = path.resolve(targetPath);\n let probe = absoluteTarget;\n while (true) {\n try {\n const canonicalProbe = await realpath(probe);\n const remainder = path.relative(probe, absoluteTarget);\n return path.resolve(canonicalProbe, remainder);\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code !== \"ENOENT\") {\n throw err;\n }\n const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AK;AACjC,YAAI,WAAW,OAAO;AACpB,iBAAO;AAAA,QACT;AACA,gBAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/explicit-capture.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { Orchestrator } from \"./orchestrator.js\";\nimport { isSafeRouteNamespace } from \"./routing/engine.js\";\nimport { sanitizeMemoryContent } from \"./sanitize.js\";\nimport { ContentHashIndex } from \"./storage.js\";\nimport type { CaptureMode, MemoryCategory, MemoryLifecycleEvent, PluginConfig } from \"./types.js\";\n\nexport type ExplicitCaptureInput = {\n content: string;\n category?: string;\n confidence?: number;\n namespace?: string;\n tags?: string[];\n entityRef?: string;\n ttl?: string;\n sourceReason?: string;\n};\n\nexport type ValidExplicitCapture = {\n content: string;\n category: MemoryCategory;\n confidence: number;\n namespace?: string;\n tags: string[];\n entityRef?: string;\n expiresAt?: string;\n sourceReason?: string;\n};\n\nexport type ExplicitCaptureSource = \"memory_store\" | \"memory_capture\" | \"suggestion_submit\" | \"inline\";\ntype ExplicitCaptureValidationMode = \"legacy_tool\" | \"strict_explicit\";\n\nconst INLINE_NOTE_RE = /<memory_note>\\s*([\\s\\S]*?)\\s*<\\/memory_note>/gi;\nconst INLINE_NOTE_MARKUP_RE = /<memory_note>\\s*[\\s\\S]*?\\s*<\\/memory_note>/i;\nconst INLINE_ALLOWED_CATEGORIES = new Set<MemoryCategory>([\n \"fact\",\n \"preference\",\n \"correction\",\n \"entity\",\n \"decision\",\n \"relationship\",\n \"principle\",\n \"commitment\",\n \"moment\",\n \"skill\",\n \"rule\",\n \"procedure\",\n]);\n\nconst SECRET_PATTERNS: RegExp[] = [\n /\\bsk-[A-Za-z0-9]{16,}\\b/,\n /\\bAKIA[0-9A-Z]{16}\\b/,\n /\\bBearer\\s+[A-Za-z0-9._-]{16,}\\b/i,\n /\\b(?:api[_-]?key|secret|token|password|passwd)\\s*[:=]\\s*[^\\s]{8,}\\b/i,\n /\\b(?:authorization)\\s*:\\s*[^\\s]{8,}\\b/i,\n];\nconst SECRET_REDACTION_PATTERNS: Array<{ pattern: RegExp; replacement: string }> = [\n { pattern: /\\bsk-[A-Za-z0-9]{16,}\\b/g, replacement: \"[redacted openai key]\" },\n { pattern: /\\bAKIA[0-9A-Z]{16}\\b/g, replacement: \"[redacted aws key]\" },\n { pattern: /\\bBearer\\s+[A-Za-z0-9._-]{16,}\\b/gi, replacement: \"Bearer [redacted token]\" },\n {\n pattern: /\\b(?:api[_-]?key|secret|token|password|passwd)\\s*[:=]\\s*[^\\s]{8,}\\b/gi,\n replacement: \"[redacted credential]\",\n },\n {\n pattern: /\\b(?:authorization)\\s*:\\s*[^\\s]{8,}\\b/gi,\n replacement: \"authorization: [redacted credential]\",\n },\n];\nconst EXPLICIT_CAPTURE_REVIEW_TAGS = [\"explicit-capture\", \"queued-review\"];\n\nfunction explicitCaptureActor(source: ExplicitCaptureSource): string {\n switch (source) {\n case \"inline\":\n return \"inline.memory_note\";\n case \"memory_store\":\n return \"tool.memory_store\";\n case \"suggestion_submit\":\n return \"tool.suggestion_submit\";\n default:\n return \"tool.memory_capture\";\n }\n}\n\nfunction asTrimmed(value: string | undefined): string | undefined {\n const trimmed = value?.trim();\n return trimmed && trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction normalizeCaptureContent(value: string): string {\n return value\n .toLowerCase()\n .replace(/\\s+/g, \" \")\n .trim();\n}\n\nfunction redactSecrets(value: string): string {\n let redacted = value;\n for (const { pattern, replacement } of SECRET_REDACTION_PATTERNS) {\n redacted = redacted.replace(pattern, replacement);\n }\n return redacted;\n}\n\nfunction normalizeExplicitCaptureError(error: unknown): string {\n if (error instanceof Error && error.message.trim().length > 0) return error.message.trim();\n const rendered = String(error).trim();\n return rendered.length > 0 ? rendered : \"explicit capture failed\";\n}\n\nfunction resolveExplicitCaptureReviewNamespace(\n orchestrator: Orchestrator,\n namespace: string | undefined,\n): string | undefined {\n const normalized = asTrimmed(namespace);\n if (!normalized) return undefined;\n return resolveExplicitCaptureNamespace(orchestrator, normalized);\n}\n\nfunction resolveExplicitCaptureNamespace(\n orchestrator: Orchestrator,\n namespace: string | undefined,\n): string | undefined {\n const normalized = asTrimmed(namespace);\n if (!normalized) return undefined;\n if (!orchestrator.config.namespacesEnabled) {\n if (normalized !== orchestrator.config.defaultNamespace) {\n throw new Error(`unsupported namespace: ${normalized}`);\n }\n return normalized;\n }\n const allowed = new Set([\n orchestrator.config.defaultNamespace,\n orchestrator.config.sharedNamespace,\n ...orchestrator.config.namespacePolicies.map((policy) => policy.name),\n ].map((value) => value.trim()).filter(Boolean));\n if (!allowed.has(normalized)) {\n throw new Error(`unsupported namespace: ${normalized}`);\n }\n return normalized;\n}\n\nfunction parseExplicitCaptureTtl(ttl: string | undefined): string | undefined {\n const raw = asTrimmed(ttl);\n if (!raw) return undefined;\n\n const absoluteMs = Date.parse(raw);\n if (Number.isFinite(absoluteMs)) {\n return new Date(absoluteMs).toISOString();\n }\n\n const relative = raw.match(/^(\\d+)\\s*([mhdw])$/i);\n if (!relative) {\n throw new Error(\"ttl must be an ISO-8601 timestamp or relative duration like 30m, 12h, 7d, or 2w\");\n }\n\n const amount = Number.parseInt(relative[1] ?? \"\", 10);\n const unit = (relative[2] ?? \"\").toLowerCase();\n if (!Number.isFinite(amount) || amount <= 0) {\n throw new Error(\"ttl duration must be a positive integer\");\n }\n\n const multiplier =\n unit === \"m\" ? 60_000\n : unit === \"h\" ? 60 * 60_000\n : unit === \"d\" ? 24 * 60 * 60_000\n : 7 * 24 * 60 * 60_000;\n return new Date(Date.now() + amount * multiplier).toISOString();\n}\n\nfunction parseInlineNote(block: string): ExplicitCaptureInput | null {\n const lines = block.replace(/\\r/g, \"\").split(\"\\n\");\n const note: Partial<ExplicitCaptureInput> = {};\n let idx = 0;\n\n while (idx < lines.length) {\n const rawLine = lines[idx] ?? \"\";\n const line = rawLine.trim();\n idx += 1;\n if (line.length === 0) continue;\n const colonIdx = line.indexOf(\":\");\n if (colonIdx < 0) continue;\n const key = line.slice(0, colonIdx).trim();\n const value = line.slice(colonIdx + 1).trim();\n\n if (key === \"content\" && value === \"|\") {\n const contentLines: string[] = [];\n while (idx < lines.length) {\n const next = lines[idx] ?? \"\";\n if (next.startsWith(\" \") || next.startsWith(\"\\t\")) {\n contentLines.push(next.replace(/^( |\\t)/, \"\"));\n idx += 1;\n continue;\n }\n if (next.trim().length === 0) {\n contentLines.push(\"\");\n idx += 1;\n continue;\n }\n break;\n }\n note.content = contentLines.join(\"\\n\").trim();\n continue;\n }\n\n switch (key) {\n case \"content\":\n note.content = value;\n break;\n case \"category\":\n note.category = value;\n break;\n case \"confidence\":\n note.confidence = Number.parseFloat(value);\n break;\n case \"namespace\":\n note.namespace = value;\n break;\n case \"tags\":\n note.tags = value\n .split(\",\")\n .map((entry) => entry.trim())\n .filter(Boolean);\n break;\n case \"entityRef\":\n note.entityRef = value;\n break;\n case \"ttl\":\n note.ttl = value;\n break;\n case \"sourceReason\":\n note.sourceReason = value;\n break;\n default:\n break;\n }\n }\n\n return asTrimmed(note.content) ? (note as ExplicitCaptureInput) : null;\n}\n\nexport function parseInlineExplicitCaptureNotes(text: string): ExplicitCaptureInput[] {\n const notes: ExplicitCaptureInput[] = [];\n for (const match of text.matchAll(INLINE_NOTE_RE)) {\n const parsed = parseInlineNote(match[1] ?? \"\");\n if (parsed) notes.push(parsed);\n }\n return notes;\n}\n\nexport function hasInlineExplicitCaptureMarkup(text: string): boolean {\n return INLINE_NOTE_MARKUP_RE.test(text);\n}\n\nexport function stripInlineExplicitCaptureNotes(text: string): string {\n return text.replace(INLINE_NOTE_RE, \"\").trim();\n}\n\nexport function validateExplicitCaptureInput(\n input: ExplicitCaptureInput,\n mode: ExplicitCaptureValidationMode = \"strict_explicit\",\n): ValidExplicitCapture {\n const content = asTrimmed(input.content);\n if (!content) throw new Error(\"content is required\");\n if (mode === \"strict_explicit\") {\n if (content.length < 10) throw new Error(\"content must be at least 10 characters\");\n if (content.length > 4000) throw new Error(\"content must be 4000 characters or fewer\");\n }\n if (/<memory_note>/i.test(content) || /<\\/memory_note>/i.test(content)) {\n throw new Error(\"nested memory_note blocks are not allowed\");\n }\n\n const category = (asTrimmed(input.category) ?? \"fact\") as MemoryCategory;\n if (!INLINE_ALLOWED_CATEGORIES.has(category)) {\n throw new Error(`unsupported category: ${input.category ?? category}`);\n }\n\n const sanitized = sanitizeMemoryContent(content);\n if (!sanitized.clean) {\n throw new Error(\"content failed memory sanitization\");\n }\n for (const pattern of SECRET_PATTERNS) {\n if (pattern.test(content)) {\n throw new Error(\"content appears to contain a secret or credential\");\n }\n }\n\n const confidence = Number.isFinite(input.confidence) ? Number(input.confidence) : 0.95;\n if (confidence < 0 || confidence > 1) {\n throw new Error(\"confidence must be between 0 and 1\");\n }\n const requestedNamespace = asTrimmed(input.namespace);\n if (requestedNamespace && !isSafeRouteNamespace(requestedNamespace)) {\n throw new Error(`unsafe namespace: ${requestedNamespace}`);\n }\n const expiresAt = parseExplicitCaptureTtl(input.ttl);\n\n return {\n content,\n category,\n confidence,\n namespace: asTrimmed(input.namespace),\n tags: Array.from(new Set((input.tags ?? []).map((tag) => tag.trim()).filter(Boolean))),\n entityRef: asTrimmed(input.entityRef),\n expiresAt,\n sourceReason: asTrimmed(input.sourceReason),\n };\n}\n\nasync function findDuplicateExplicitCapture(\n orchestrator: Orchestrator,\n resolvedNamespace: string | undefined,\n candidate: ValidExplicitCapture,\n): Promise<string | null> {\n const storage = await orchestrator.getStorage(resolvedNamespace);\n if (\n candidate.category === \"fact\"\n && typeof (storage as { hasFactContentHash?: (content: string) => Promise<boolean> }).hasFactContentHash === \"function\"\n ) {\n try {\n const hasHash = await (storage as { hasFactContentHash: (content: string) => Promise<boolean> }).hasFactContentHash(\n candidate.content,\n );\n if (!hasHash) {\n const authoritative =\n typeof (storage as { isFactContentHashAuthoritative?: () => Promise<boolean> | boolean }).isFactContentHashAuthoritative\n === \"function\"\n ? await (storage as { isFactContentHashAuthoritative: () => Promise<boolean> | boolean })\n .isFactContentHashAuthoritative()\n : false;\n if (authoritative) return null;\n }\n } catch (err) {\n // Fail open: hash index is only an optimization, so fall back to the full corpus scan.\n void err;\n }\n }\n const existing = await storage.readAllMemories();\n const normalizedCandidate = normalizeCaptureContent(candidate.content);\n const match = existing.find((memory) => {\n const status = memory.frontmatter.status ?? \"active\";\n if (status !== \"active\") return false;\n if (memory.frontmatter.category !== candidate.category) return false;\n return normalizeCaptureContent(memory.content) === normalizedCandidate;\n });\n return match?.frontmatter.id ?? null;\n}\n\nexport async function persistExplicitCapture(\n orchestrator: Orchestrator,\n candidate: ValidExplicitCapture,\n source: ExplicitCaptureSource,\n): Promise<{ id: string; duplicateOf?: string }> {\n const resolvedNamespace = resolveExplicitCaptureNamespace(orchestrator, candidate.namespace);\n const duplicateOf = await findDuplicateExplicitCapture(orchestrator, resolvedNamespace, candidate);\n if (duplicateOf) {\n return { id: duplicateOf, duplicateOf };\n }\n\n const storage = await orchestrator.getStorage(resolvedNamespace);\n const id = await storage.writeMemory(candidate.category, candidate.content, {\n confidence: candidate.confidence,\n tags: candidate.tags,\n entityRef: candidate.entityRef,\n expiresAt: candidate.expiresAt,\n source: source === \"inline\" ? \"explicit-inline\" : \"explicit\",\n });\n\n const created = new Date().toISOString();\n const event: MemoryLifecycleEvent = {\n eventId: `mle-${randomUUID()}`,\n memoryId: id,\n eventType: \"explicit_capture_accepted\",\n timestamp: created,\n actor: explicitCaptureActor(source),\n reasonCode: candidate.sourceReason,\n ruleVersion: \"explicit-capture.v1\",\n };\n await storage.appendMemoryLifecycleEvents([event]);\n\n return { id };\n}\n\nfunction buildExplicitCaptureReviewContent(input: ExplicitCaptureInput, reason: string): string {\n const requestedContent = asTrimmed(input.content);\n const sanitized = sanitizeMemoryContent(redactSecrets(requestedContent ?? \"[empty explicit capture]\"));\n const safeContent = sanitized.text.trim().length > 0 ? sanitized.text.trim() : \"[empty explicit capture]\";\n const lines = [\n \"Explicit capture queued for review.\",\n \"\",\n `Reason: ${reason}`,\n \"\",\n \"Submitted content:\",\n safeContent,\n ];\n const metadata = [\n input.category ? `Requested category: ${input.category}` : undefined,\n input.namespace ? `Requested namespace: ${input.namespace}` : undefined,\n input.entityRef ? `Requested entityRef: ${input.entityRef}` : undefined,\n input.ttl ? `Requested ttl: ${input.ttl}` : undefined,\n input.sourceReason ? `Requested sourceReason: ${input.sourceReason}` : undefined,\n input.tags && input.tags.length > 0 ? `Requested tags: ${input.tags.join(\", \")}` : undefined,\n ].filter((entry): entry is string => typeof entry === \"string\" && entry.length > 0);\n if (metadata.length > 0) {\n lines.push(\"\", ...metadata);\n }\n return lines.join(\"\\n\");\n}\n\nasync function findQueuedExplicitCaptureDuplicate(\n orchestrator: Orchestrator,\n namespace: string | undefined,\n content: string,\n): Promise<string | null> {\n const storage = await orchestrator.getStorage(namespace);\n const existing = await storage.readAllMemories();\n const normalized = normalizeCaptureContent(content);\n const match = existing.find((memory) => {\n const status = memory.frontmatter.status ?? \"active\";\n if (status !== \"pending_review\") return false;\n if (!(memory.frontmatter.tags ?? []).includes(\"queued-review\")) return false;\n return normalizeCaptureContent(memory.content) === normalized;\n });\n return match?.frontmatter.id ?? null;\n}\n\nexport async function queueExplicitCaptureForReview(\n orchestrator: Orchestrator,\n input: ExplicitCaptureInput,\n source: ExplicitCaptureSource,\n error: unknown,\n): Promise<{ id: string; duplicateOf?: string }> {\n const reason = normalizeExplicitCaptureError(error);\n const requestedNamespace = asTrimmed(input.namespace);\n const queueNamespace = resolveExplicitCaptureReviewNamespace(orchestrator, requestedNamespace);\n const content = buildExplicitCaptureReviewContent(input, reason);\n const duplicateOf = await findQueuedExplicitCaptureDuplicate(orchestrator, queueNamespace, content);\n if (duplicateOf) {\n return { id: duplicateOf, duplicateOf };\n }\n\n const requestedCategory = asTrimmed(input.category);\n const reviewCategory = requestedCategory && INLINE_ALLOWED_CATEGORIES.has(requestedCategory as MemoryCategory)\n ? requestedCategory as MemoryCategory\n : \"fact\";\n const requestedTags = Array.isArray(input.tags)\n ? input.tags.map((tag) => tag.trim()).filter(Boolean)\n : [];\n const storage = await orchestrator.getStorage(queueNamespace);\n const id = await storage.writeMemory(reviewCategory, content, {\n confidence: 0.2,\n tags: Array.from(new Set([...EXPLICIT_CAPTURE_REVIEW_TAGS, ...requestedTags])),\n entityRef: asTrimmed(input.entityRef),\n source: source === \"inline\" ? \"explicit-inline-review\" : \"explicit-review\",\n });\n const created = await storage.getMemoryById(id);\n if (created) {\n await storage.writeMemoryFrontmatter(created, {\n status: \"pending_review\",\n updated: new Date().toISOString(),\n }, {\n actor: explicitCaptureActor(source),\n reasonCode: reason,\n ruleVersion: \"explicit-capture.v1\",\n });\n }\n const event: MemoryLifecycleEvent = {\n eventId: `mle-${randomUUID()}`,\n memoryId: id,\n eventType: \"explicit_capture_queued\",\n timestamp: new Date().toISOString(),\n actor: explicitCaptureActor(source),\n reasonCode: reason,\n ruleVersion: \"explicit-capture.v1\",\n };\n await storage.appendMemoryLifecycleEvents([event]);\n return { id };\n}\n\nexport function shouldSkipImplicitExtraction(cfg: Pick<PluginConfig, \"captureMode\">): boolean {\n return cfg.captureMode === \"explicit\";\n}\n\nexport function shouldProcessInlineExplicitCapture(cfg: Pick<PluginConfig, \"captureMode\">): boolean {\n return cfg.captureMode !== \"implicit\";\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,kBAAkB;AAgC3B,IAAM,iBAAiB;AACvB,IAAM,wBAAwB;AAC9B,IAAM,4BAA4B,oBAAI,IAAoB;AAAA,EACxD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,kBAA4B;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,IAAM,4BAA6E;AAAA,EACjF,EAAE,SAAS,4BAA4B,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AAS,6BAA6B,KAAiD;AAC5F,SAAO,IAAI,gBAAgB;AAC7B;AAEO,SAAS,mCAAmC,KAAiD;AAClG,SAAO,IAAI,gBAAgB;AAC7B;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/routing/engine.ts"],"sourcesContent":["import type { MemoryCategory } from \"../types.js\";\n\nexport type RoutePatternType = \"regex\" | \"keyword\";\n\nexport interface RouteTarget {\n category?: MemoryCategory;\n namespace?: string;\n}\n\nexport interface RouteRule {\n id: string;\n patternType: RoutePatternType;\n pattern: string;\n priority: number;\n target: RouteTarget;\n enabled?: boolean;\n}\n\nexport interface RoutingEngineOptions {\n allowedNamespaces?: string[];\n allowedCategories?: MemoryCategory[];\n}\n\nexport interface RouteSelection {\n rule: RouteRule;\n target: RouteTarget;\n}\n\nconst DEFAULT_CATEGORIES: readonly MemoryCategory[] = [\n \"fact\",\n \"preference\",\n \"correction\",\n \"entity\",\n \"decision\",\n \"relationship\",\n \"principle\",\n \"commitment\",\n \"moment\",\n \"skill\",\n \"rule\",\n \"procedure\",\n] as const;\n\nfunction normalizeNamespace(namespace: string): string {\n return namespace.trim();\n}\n\nexport function isLikelyUnsafeRegex(pattern: string): boolean {\n const value = pattern.trim();\n if (value.length === 0) return true;\n if (value.length > 120) return true;\n if (/\\\\[1-9]/.test(value)) return true; // backreferences\n if (/\\(\\?<?[=!]/.test(value)) return true; // lookaround assertions\n if (/\\((?:[^()\\\\]|\\\\.)*[+*](?:[^()\\\\]|\\\\.)*\\)[+*{]/.test(value)) return true; // nested quantifiers\n // Conservative fail-closed guardrail: grouped/alternation regexes are user-configurable and can be expensive.\n if (/(^|[^\\\\])[()|]/.test(value)) return true;\n // Multiple quantifiers in one user pattern are high risk for catastrophic backtracking on non-matches.\n const quantifierCount =\n (value.match(/(^|[^\\\\])[*+?]/g)?.length ?? 0) +\n (value.match(/(^|[^\\\\])\\{/g)?.length ?? 0);\n if (quantifierCount > 1) return true;\n return false;\n}\n\nexport function isSafeRouteNamespace(namespace: string): boolean {\n const value = normalizeNamespace(namespace);\n if (value.length === 0) return false;\n if (value === \".\") return false;\n if (value.includes(\"/\") || value.includes(\"\\\\\")) return false;\n if (value.includes(\"..\")) return false;\n return /^[A-Za-z0-9._-]{1,64}$/.test(value);\n}\n\nexport function validateRouteTarget(target: RouteTarget | null | undefined, options?: RoutingEngineOptions): {\n ok: boolean;\n error?: string;\n target?: RouteTarget;\n} {\n if (!target || typeof target !== \"object\") {\n return { ok: false, error: \"target must be an object\" };\n }\n\n const allowedCategories = new Set(options?.allowedCategories ?? DEFAULT_CATEGORIES);\n const allowedNamespaces = options?.allowedNamespaces\n ? new Set(options.allowedNamespaces.map((v) => v.trim()).filter((v) => v.length > 0))\n : null;\n\n const normalized: RouteTarget = {};\n\n if (typeof target.category === \"string\") {\n if (!allowedCategories.has(target.category)) {\n return { ok: false, error: `invalid category: ${target.category}` };\n }\n normalized.category = target.category;\n }\n\n if (typeof target.namespace === \"string\") {\n const namespace = normalizeNamespace(target.namespace);\n if (!isSafeRouteNamespace(namespace)) {\n return { ok: false, error: `invalid namespace: ${target.namespace}` };\n }\n if (allowedNamespaces && !allowedNamespaces.has(namespace)) {\n return { ok: false, error: `namespace not allowed: ${namespace}` };\n }\n normalized.namespace = namespace;\n }\n\n if (!normalized.category && !normalized.namespace) {\n return { ok: false, error: \"target must include category or namespace\" };\n }\n\n return { ok: true, target: normalized };\n}\n\nexport function doesRuleMatch(rule: RouteRule, text: string): boolean {\n if (!rule || typeof rule !== \"object\") return false;\n if (rule.enabled === false) return false;\n if (typeof rule.pattern !== \"string\") return false;\n const pattern = rule.pattern.trim();\n if (pattern.length === 0) return false;\n\n if (rule.patternType === \"keyword\") {\n return text.toLowerCase().includes(pattern.toLowerCase());\n }\n if (rule.patternType !== \"regex\") {\n return false;\n }\n\n if (isLikelyUnsafeRegex(pattern)) {\n return false;\n }\n\n try {\n return new RegExp(pattern, \"i\").test(text);\n } catch {\n return false;\n }\n}\n\nexport function selectRouteRule(text: string, rules: RouteRule[], options?: RoutingEngineOptions): RouteSelection | null {\n const ranked = rules\n .map((rule, index) => ({ rule, index }))\n .sort((a, b) => {\n if (b.rule.priority !== a.rule.priority) return b.rule.priority - a.rule.priority;\n return a.index - b.index;\n });\n\n for (const entry of ranked) {\n if (!doesRuleMatch(entry.rule, text)) continue;\n\n const validation = validateRouteTarget(entry.rule.target, options);\n if (!validation.ok || !validation.target) continue;\n\n return {\n rule: entry.rule,\n target: validation.target,\n };\n }\n\n return null;\n}\n"],"mappings":";AA4BA,IAAM,qBAAgD;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,mBAAmB,WAA2B;AACrD,SAAO,UAAU,KAAK;AACxB;AAEO,SAAS,oBAAoB,SAA0B;AAC5D,QAAM,QAAQ,QAAQ,KAAK;AAC3B,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,MAAI,MAAM,SAAS,IAAK,QAAO;AAC/B,MAAI,UAAU,KAAK,KAAK,EAAG,QAAO;AAClC,MAAI,aAAa,KAAK,KAAK,EAAG,QAAO;AACrC,MAAI,gDAAgD,KAAK,KAAK,EAAG,QAAO;AAExE,MAAI,iBAAiB,KAAK,KAAK,EAAG,QAAO;AAEzC,QAAM,mBACH,MAAM,MAAM,iBAAiB,GAAG,UAAU,MAC1C,MAAM,MAAM,cAAc,GAAG,UAAU;AAC1C,MAAI,kBAAkB,EAAG,QAAO;AAChC,SAAO;AACT;AAEO,SAAS,qBAAqB,WAA4B;AAC/D,QAAM,QAAQ,mBAAmB,SAAS;AAC1C,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,MAAI,UAAU,IAAK,QAAO;AAC1B,MAAI,MAAM,SAAS,GAAG,KAAK,MAAM,SAAS,IAAI,EAAG,QAAO;AACxD,MAAI,MAAM,SAAS,IAA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O;AACnC,MAAI,OAAO,KAAK,YAAY,SAAU,QAAO;AAC7C,QAAM,UAAU,KAAK,QAAQ,KAAK;AAClC,MAAI,QAAQ,WAAW,EAAG,QAAO;AAEjC,MAAI,KAAK,gBAAgB,WAAW;AAClC,WAAO,KAAK,YAAY,EAAE,SAAS,QAAQ,YAAY,CAAC;AAAA,EAC1D;AACA,MAAI,KAAK,gBAAgB,SAAS;AAChC,WAAO;AAAA,EACT;AAEA,MAAI,oBAAoB,OAAO,GAAG;AAChC,WAAO;AAAA,EACT;AAEA,MAAI;AACF,WAAO,IAAI,OAAO,SAAS,GAAG,EAAE,KAAK,IAAI;AAAA,EAC3C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,gBAAgB,MAAc,OAAoB,SAAuD;AACvH,QAAM,SAAS,MACZ,IAAI,CAAC,MAAM,WAAW,EAAE,MAAM,MAAM,EAAE,EACtC,KAAK,CAAC,GAAG,MAAM;AACd,QAAI,EAAE,KAAK,aAAa,EAAE,KAAK,SAAU,QAAO,EAAE,KAAK,WAAW,EAAE,KAAK;AACzE,WAAO,EAAE,QAAQ,EAAE;AAAA,EACrB,CAAC;AAEH,aAAW,SAAS,QAAQ;AAC1B,QAAI,CAAC,cAAc,MAAM,MAAM,IAAI,EAAG;AAEtC,UAAM,aAAa,oBAAoB,MAAM,KAAK,QAAQ,OAAO;AACjE,QAAI,CAAC,WAAW,MAAM,CAAC,WAAW,OAAQ;AAE1C,WAAO;AAAA,MACL,MAAM,MAAM;AAAA,MACZ,QAAQ,WAAW;AAAA,IACrB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schemas.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const MemoryActionTypeSchema = z.enum([\n \"store_episode\",\n \"store_note\",\n \"update_note\",\n \"create_artifact\",\n \"summarize_node\",\n \"discard\",\n \"link_graph\",\n]);\n\nexport const MemoryActionEligibilityContextSchema = z\n .object({\n confidence: z.number().min(0).max(1),\n lifecycleState: z.enum([\"active\", \"validated\", \"candidate\", \"stale\", \"archived\"]),\n importance: z.number().min(0).max(1),\n source: z.enum([\"extraction\", \"consolidation\", \"replay\", \"manual\", \"unknown\"]),\n })\n .strict();\n\nexport function parseMemoryActionType(value: unknown): z.infer<typeof MemoryActionTypeSchema> {\n const parsed = MemoryActionTypeSchema.safeParse(value);\n return parsed.success ? parsed.data : \"discard\";\n}\n\nexport function parseMemoryActionEligibilityContext(\n value: unknown,\n): z.infer<typeof MemoryActionEligibilityContextSchema> {\n const parsed = MemoryActionEligibilityContextSchema.safeParse(value);\n if (parsed.success) return parsed.data;\n return {\n confidence: 0,\n lifecycleState: \"candidate\",\n importance: 0,\n source: \"unknown\",\n };\n}\n\nexport const ProcedureStepExtractSchema = z.object({\n order: z.number(),\n intent: z.string(),\n toolCall: z\n .object({\n kind: z.string(),\n signature: z.string(),\n })\n .optional()\n .nullable(),\n expectedOutcome: z.string().optional().nullable(),\n optional: z.boolean().optional().nullable(),\n});\n\nexport const ExtractedFactSchema = z.object({\n category: z.enum([\n \"fact\",\n \"preference\",\n \"correction\",\n \"entity\",\n \"decision\",\n \"relationship\",\n \"principle\",\n \"commitment\",\n \"moment\",\n \"skill\",\n \"rule\",\n \"procedure\",\n ]),\n content: z\n .string()\n .describe(\"The memory content — a clear, standalone statement\"),\n confidence: z\n .number()\n .min(0)\n .max(1)\n .describe(\"How confident are you this is correct (0-1)\"),\n tags: z.array(z.string()).describe(\"Relevant tags for categorization\"),\n entityRef: z\n .string()\n .optional()\n .nullable()\n .describe(\"If about an entity, its normalized name (e.g. person-jane-doe)\"),\n promptedByQuestion: z\n .string()\n .optional()\n .nullable()\n .describe(\"Optional proactive follow-up question that surfaced this fact.\"),\n structuredAttributes: z\n .record(z.string(), z.string())\n .optional()\n .nullable()\n .describe(\"Structured key-value attributes when the fact contains measurable or categorical data (e.g., {\\\"price\\\": \\\"29.99\\\", \\\"color\\\": \\\"blue\\\", \\\"date\\\": \\\"2024-03-15\\\"}).\"),\n procedureSteps: z\n .array(ProcedureStepExtractSchema)\n .optional()\n .nullable()\n .describe(\n 'For category \"procedure\" only: ordered steps (intent per step). At least two steps; include explicit trigger phrasing in content (e.g. \"When you deploy…\").',\n ),\n});\n\nexport const EntityMentionSchema = z.object({\n name: z\n .string()\n .describe(\"Normalized entity name (e.g. jane-doe, acme-corp, my-project)\"),\n type: z.enum([\"person\", \"project\", \"tool\", \"company\", \"place\", \"other\"]),\n facts: z\n .array(z.string())\n .describe(\"New facts learned about this entity in this conversation\"),\n promptedByQuestion: z\n .string()\n .optional()\n .nullable()\n .describe(\"Optional proactive follow-up question that surfaced this entity.\"),\n structuredSections: z\n .array(z.object({\n key: z.string(),\n title: z.string(),\n facts: z.array(z.string()),\n }))\n .optional()\n .nullable()\n .describe(\"Optional named sections for entity-specific facts. Use when facts clearly belong under a durable heading such as Beliefs or Building / Working On.\"),\n});\n\nexport const ExtractedQuestionSchema = z.object({\n question: z.string().describe(\"A genuine question the AI is curious about based on this conversation\"),\n context: z.string().describe(\"Why this question matters or what prompted it\"),\n priority: z.number().min(0).max(1).describe(\"How important/urgent this question is (0-1)\"),\n});\n\nexport const ProactiveQuestionsResultSchema = z.object({\n questions: z\n .array(ExtractedQuestionSchema)\n .describe(\"Additional follow-up questions discovered in a proactive second-pass extraction.\"),\n});\n\nexport const ExtractedRelationshipSchema = z.object({\n source: z.string().describe(\"Source entity name (normalized, e.g. person-jane-doe)\"),\n target: z.string().describe(\"Target entity name (normalized, e.g. company-acme-corp)\"),\n label: z.string().describe(\"Relationship label (e.g. 'works at', 'created', 'manages')\"),\n promptedByQuestion: z\n .string()\n .optional()\n .nullable()\n .describe(\"Optional proactive follow-up question that surfaced this relationship.\"),\n});\n\nexport const ProactiveExtractionResultSchema = z.object({\n facts: z\n .array(ExtractedFactSchema)\n .describe(\n \"Additional high-confidence memories recovered only after answering proactive follow-up questions from the same buffered conversation.\",\n ),\n profileUpdates: z\n .array(z.string())\n .describe(\n \"Additional profile updates directly supported by the buffered conversation. Omit anything speculative.\",\n ),\n entities: z\n .array(EntityMentionSchema)\n .describe(\n \"Additional entities or entity facts surfaced by the proactive follow-up pass.\",\n ),\n relationships: z\n .array(ExtractedRelationshipSchema)\n .optional()\n .nullable()\n .describe(\n \"Additional relationships surfaced by the proactive follow-up pass.\",\n ),\n});\n\nexport const ExtractionResultSchema = z.object({\n facts: z\n .array(ExtractedFactSchema)\n .describe(\n \"Extracted memories from the conversation. Include facts, preferences, corrections, and decisions. Only extract genuinely new, durable information — skip transient task state.\",\n ),\n profileUpdates: z\n .array(z.string())\n .describe(\n \"Updates to the user's behavioral profile. Each string is a standalone statement about the user's preferences, habits, or personality. Only include genuinely new insights.\",\n ),\n entities: z\n .array(EntityMentionSchema)\n .describe(\n \"Entities mentioned in the conversation with new facts about them.\",\n ),\n questions: z\n .array(ExtractedQuestionSchema)\n .describe(\n \"1-3 genuine questions you're curious about from this conversation. These should be things you'd actually want to know the answer to in future sessions.\",\n ),\n identityReflection: z\n .string()\n .optional()\n .nullable()\n .describe(\n \"A brief reflection on what you learned about yourself as an agent in this interaction — patterns in your behavior, growth, things you did well or could improve.\",\n ),\n relationships: z\n .array(ExtractedRelationshipSchema)\n .optional()\n .nullable()\n .describe(\n \"Relationships between entities discovered in this conversation. Max 5 per extraction. Format: {source, target, label}.\",\n ),\n});\n\nexport const ConsolidationItemSchema = z.object({\n existingId: z\n .string()\n .describe(\"The ID of the existing memory being evaluated\"),\n action: z.enum([\"ADD\", \"MERGE\", \"UPDATE\", \"INVALIDATE\", \"SKIP\"]),\n mergeWith: z\n .string()\n .optional()\n .nullable()\n .describe(\"If MERGE, the ID of the memory to merge with\"),\n updatedContent: z\n .string()\n .optional()\n .nullable()\n .describe(\"If UPDATE or MERGE, the new content\"),\n reason: z.string().describe(\"Brief reason for this decision\"),\n});\n\nexport const ConsolidationResultSchema = z.object({\n items: z\n .array(ConsolidationItemSchema)\n .describe(\n \"Decisions for each existing memory: ADD (keep as-is), MERGE (combine with another), UPDATE (revise content), INVALIDATE (mark as outdated/wrong), SKIP (no action needed)\",\n ),\n profileUpdates: z\n .array(z.string())\n .describe(\"New profile statements to add or update\"),\n entityUpdates: z\n .array(EntityMentionSchema)\n .describe(\"Entity updates from consolidation analysis\"),\n});\n\nexport function buildProfileConsolidationResultSchema(targetLines: number) {\n return z.object({\n consolidatedProfile: z\n .string()\n .describe(\n `The full consolidated profile as markdown. Preserve all ## section headers. Merge duplicate or near-duplicate bullets into single clear statements. Remove stale or superseded information. Keep the most important and durable observations. Target roughly ${targetLines} lines.`,\n ),\n removedCount: z\n .number()\n .describe(\"Number of bullets removed or merged during consolidation\"),\n summary: z\n .string()\n .describe(\"Brief summary of what was consolidated\"),\n });\n}\n\nexport const ProfileConsolidationResultSchema = buildProfileConsolidationResultSchema(50);\n\nexport const IdentityConsolidationResultSchema = z.object({\n learnedPatterns: z\n .array(z.string())\n .describe(\n \"Consolidated behavioral patterns and lessons learned, each a concise standalone statement\",\n ),\n summary: z\n .string()\n .describe(\n \"A brief paragraph summarizing the agent's core identity insights\",\n ),\n});\n\nexport type IdentityConsolidationResultParsed = z.infer<\n typeof IdentityConsolidationResultSchema\n>;\n\n// Contradiction Verification (Phase 2B)\nexport const ContradictionVerificationSchema = z.object({\n isContradiction: z\n .boolean()\n .describe(\"Whether the two memories truly contradict each other\"),\n confidence: z\n .number()\n .min(0)\n .max(1)\n .describe(\"How confident are you in this assessment (0-1)\"),\n reasoning: z\n .string()\n .describe(\"Explanation of why these are or are not contradictory\"),\n whichIsNewer: z\n .enum([\"first\", \"second\", \"unclear\"])\n .describe(\"Which memory represents the more recent/current state\"),\n});\n\nexport type ContradictionVerificationResult = z.infer<\n typeof ContradictionVerificationSchema\n>;\n\n// Memory Linking (Phase 3A)\nexport const MemoryLinkSchema = z.object({\n targetId: z\n .string()\n .describe(\"The ID of the memory this links to\"),\n linkType: z\n .enum([\"follows\", \"references\", \"contradicts\", \"supports\", \"related\"])\n .describe(\"The type of relationship\"),\n strength: z\n .number()\n .min(0)\n .max(1)\n .describe(\"How strong is this relationship (0-1)\"),\n reason: z\n .string()\n .optional()\n .nullable()\n .describe(\"Why this link exists\"),\n});\n\nexport const SuggestedLinksSchema = z.object({\n links: z\n .array(MemoryLinkSchema)\n .describe(\"Suggested links between memories based on semantic analysis\"),\n});\n\nexport type MemoryLink = z.infer<typeof MemoryLinkSchema>;\nexport type SuggestedLinks = z.infer<typeof SuggestedLinksSchema>;\n\n// Memory Summarization (Phase 4A)\nexport const MemorySummarySchema = z.object({\n summaryText: z\n .string()\n .describe(\"A concise summary of the batch of memories\"),\n keyFacts: z\n .array(z.string())\n .describe(\"The most important facts extracted from these memories\"),\n keyEntities: z\n .array(z.string())\n .describe(\"Key entities mentioned across these memories\"),\n});\n\nexport type MemorySummaryResult = z.infer<typeof MemorySummarySchema>;\n\nexport const DaySummaryResultSchema = z.object({\n summary: z.string().min(1).describe(\"A concise end-of-day summary paragraph.\"),\n bullets: z.array(z.string()).default([]).describe(\"The most important moments from the day.\"),\n next_actions: z.array(z.string()).default([]).describe(\"Concrete next actions for tomorrow.\"),\n risks_or_open_loops: z.array(z.string()).default([]).describe(\"Open loops, blockers, or fragile assumptions still needing attention.\"),\n});\n\n// v8.15 behavior-loop auto-tuning state contracts\nexport const BehaviorLoopAdjustmentSchema = z.object({\n parameter: z.string().min(1),\n previousValue: z.number(),\n nextValue: z.number(),\n delta: z.number(),\n evidenceCount: z.number().int().min(0),\n confidence: z.number().min(0).max(1),\n reason: z.string(),\n appliedAt: z.string(),\n});\n\nexport const BehaviorLoopPolicyStateSchema = z.object({\n version: z.number().int().min(0),\n windowDays: z.number().int().min(0),\n minSignalCount: z.number().int().min(0),\n maxDeltaPerCycle: z.number().min(0).max(1),\n protectedParams: z.array(z.string()),\n adjustments: z.array(BehaviorLoopAdjustmentSchema),\n updatedAt: z.string(),\n});\n\nexport type BehaviorLoopAdjustmentParsed = z.infer<typeof BehaviorLoopAdjustmentSchema>;\nexport type BehaviorLoopPolicyStateParsed = z.infer<typeof BehaviorLoopPolicyStateSchema>;\n\nexport type MemoryActionTypeParsed = z.infer<typeof MemoryActionTypeSchema>;\nexport type MemoryActionEligibilityContextParsed = z.infer<typeof MemoryActionEligibilityContextSchema>;\nexport type ExtractedFactParsed = z.infer<typeof ExtractedFactSchema>;\nexport type EntityMentionParsed = z.infer<typeof EntityMentionSchema>;\nexport type ExtractedQuestionParsed = z.infer<typeof ExtractedQuestionSchema>;\nexport type ProactiveQuestionsResultParsed = z.infer<typeof ProactiveQuestionsResultSchema>;\nexport type ExtractionResultParsed = z.infer<typeof ExtractionResultSchema>;\nexport type ConsolidationItemParsed = z.infer<typeof ConsolidationItemSchema>;\nexport type ConsolidationResultParsed = z.infer<\n typeof ConsolidationResultSchema\n>;\n\n"],"mappings":";AAAA,SAAS,SAAS;AAEX,IAAM,yBAAyB,EAAE,KAAK;AAAA,EAC3C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,uCAAuC,EACjD,OAAO;AAAA,EACN,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC;AAAA,EACnC,gBAAgB,EAAE,KAAK,CAAC,UAAU,aAAa,aAAa,SAAS,UAAU,CAAC;AAAA,EAChF,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC;AAAA,EACnC,QAAQ,EAAE,KAAK,CAAC,cAAc,iBAAiB,UAAU,UAAU,SAAS,CAAC;AAC/E,CAAC,EACA,OAAO;AAEH,SAAS,sBAAsB,OAAwD;AAC5F,QAAM,SAAS,uBAAuB,UAAU,KAAK;AACrD,SAAO,OAAO,UAAU,OAAO,OAAO;AACxC;AAEO,SAAS,oCACd,OACsD;AACtD,QAAM,SAAS,qCAAqC,UAAU,KAAK;AACnE,MAAI,OAAO,QAAS,QAAO,OAAO;AAClC,SAAO;AAAA,IACL,Y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