@remnic/core 9.65.1 → 9.65.2
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-admin-ops-surface.d.ts +11 -11
- package/dist/access-admin-ops-surface.js +35 -34
- package/dist/access-authorization-probe.d.ts +12 -13
- package/dist/access-authorization-probe.js +36 -35
- package/dist/access-boundary.d.ts +12 -156
- package/dist/access-boundary.js +35 -34
- package/dist/access-cli.js +107 -104
- package/dist/access-cli.js.map +1 -1
- package/dist/access-coding-context-resolution.d.ts +1 -1
- package/dist/access-extraction-force-flush.d.ts +11 -11
- package/dist/access-extraction-force-flush.js +35 -34
- package/dist/access-health-types.d.ts +1 -1
- package/dist/access-http-lcm-compaction.d.ts +11 -11
- package/dist/access-http-lifecycle-flush.d.ts +12 -13
- package/dist/access-http-offline-stream.d.ts +11 -11
- package/dist/access-http-query.d.ts +2 -2
- package/dist/access-http-query.js +37 -36
- package/dist/access-http.d.ts +12 -12
- package/dist/access-http.js +54 -53
- package/dist/access-identity-continuity-surface.d.ts +9 -9
- package/dist/access-identity-continuity-surface.js +35 -34
- package/dist/access-lcm-surface.d.ts +11 -11
- package/dist/access-lcm-surface.js +35 -34
- package/dist/access-mcp-admin-tools.js +1 -1
- package/dist/access-mcp-output-schemas.js +1 -1
- package/dist/access-mcp.d.ts +11 -11
- package/dist/access-mcp.js +47 -44
- package/dist/access-memory-search-fanout.d.ts +2 -2
- package/dist/{access-namespace-preflight-BKUnKsBv.d.ts → access-namespace-preflight-Dhvcl-T0.d.ts} +1 -1
- package/dist/access-namespace-preflight.d.ts +3 -3
- package/dist/access-namespace-preflight.js +35 -34
- package/dist/access-observe-write-surface.d.ts +11 -11
- package/dist/access-observe-write-surface.js +35 -34
- package/dist/access-offline-manifest.d.ts +9 -9
- package/dist/access-offline-manifest.js +5 -5
- package/dist/access-operations-batch.js +38 -37
- package/dist/access-operations.d.ts +18 -19
- package/dist/access-operations.js +41 -40
- package/dist/access-recall-concurrency.d.ts +11 -11
- package/dist/access-recall-concurrency.js +35 -34
- package/dist/access-recall-response.d.ts +11 -11
- package/dist/access-recall-response.js +35 -34
- package/dist/access-recall-surface.d.ts +11 -11
- package/dist/access-recall-surface.js +35 -34
- package/dist/access-schema.d.ts +118 -118
- package/dist/access-schema.js +3 -3
- package/dist/{access-service-B1Lbb-nQ.d.ts → access-service-Bke1alZO.d.ts} +478 -74
- package/dist/access-service-helpers.d.ts +11 -11
- package/dist/access-service.d.ts +11 -11
- package/dist/access-service.js +35 -34
- package/dist/access-surface-catalog.d.ts +12 -13
- package/dist/access-surface-catalog.js +39 -36
- package/dist/access-surface-catalog.js.map +1 -1
- package/dist/access-wearables-meetings-surface.d.ts +3 -3
- package/dist/action-confidence.d.ts +1 -1
- package/dist/active-memory-bridge.d.ts +1 -1
- package/dist/active-recall.d.ts +1 -1
- package/dist/active-recall.js +6 -1
- package/dist/active-recall.js.map +1 -1
- package/dist/adapters/index.js +4 -4
- package/dist/adapters/registry.js +2 -2
- package/dist/ambient-provenance.d.ts +1 -1
- package/dist/artifact-search.d.ts +1 -1
- package/dist/{auto-sync-5L7EUZ27.js → auto-sync-H64ZCNIR.js} +13 -5
- package/dist/{auto-sync-5L7EUZ27.js.map → auto-sync-H64ZCNIR.js.map} +1 -1
- package/dist/behavior-learner.d.ts +1 -1
- package/dist/behavior-signals.d.ts +1 -1
- package/dist/bootstrap.d.ts +9 -9
- package/dist/briefing-window.d.ts +2 -2
- package/dist/briefing.d.ts +2 -2
- package/dist/briefing.js +16 -15
- package/dist/buffer-surprise-report.d.ts +1 -1
- package/dist/buffer-turn-helpers.d.ts +1 -1
- package/dist/buffer.d.ts +2 -2
- package/dist/buffer.js +4 -4
- package/dist/bulk-import/index.d.ts +3 -3
- package/dist/calibration.d.ts +1 -1
- package/dist/calibration.js +1 -1
- package/dist/capabilities.d.ts +1 -1
- package/dist/{capsule-crypto-7FJQINUR.js → capsule-crypto-YO5QJ6L3.js} +2 -2
- package/dist/{catalog-DjVhJoRM.d.ts → catalog-DV6qnbr7.d.ts} +1 -1
- package/dist/causal-behavior.d.ts +1 -1
- package/dist/causal-consolidation.d.ts +1 -1
- package/dist/causal-consolidation.js +17 -16
- package/dist/causal-consolidation.js.map +1 -1
- package/dist/causal-trajectory-graph.d.ts +1 -1
- package/dist/{chunk-LYIZXQYY.js → chunk-2E36UXVW.js} +2 -2
- package/dist/{chunk-7QFBLYFP.js → chunk-2XDWWPTN.js} +3 -3
- package/dist/{chunk-CFRBTATE.js → chunk-2YI72KM3.js} +3 -3
- package/dist/{chunk-3YTTAGPB.js → chunk-3DVBKTSO.js} +2 -2
- package/dist/{chunk-VPGRXEAB.js → chunk-3I7ASZN3.js} +2 -2
- package/dist/{chunk-EIR5VLIH.js → chunk-4K7IW3F7.js} +2 -2
- package/dist/chunk-4K7IW3F7.js.map +1 -0
- package/dist/{chunk-WTOE7CW4.js → chunk-4KYOLI6M.js} +13 -13
- package/dist/chunk-573TEZCD.js +88 -0
- package/dist/chunk-573TEZCD.js.map +1 -0
- package/dist/{chunk-ESCQ6LY7.js → chunk-5NM4OH4P.js} +3 -3
- package/dist/{chunk-Y23B2QXP.js → chunk-5YQ63T4B.js} +2 -2
- package/dist/{chunk-PMVPCZJZ.js → chunk-6433HV72.js} +2 -2
- package/dist/{chunk-4NZHHGVL.js → chunk-7BDZTALN.js} +4 -1
- package/dist/chunk-7BDZTALN.js.map +1 -0
- package/dist/{chunk-NS5ETDYD.js → chunk-7BEPVIH3.js} +3 -3
- package/dist/{chunk-JG22O53B.js → chunk-7CBKAQIG.js} +2 -1
- package/dist/chunk-7CBKAQIG.js.map +1 -0
- package/dist/{chunk-W6TSGWYS.js → chunk-7YQ4IYS2.js} +2 -2
- package/dist/chunk-AAXJNINV.js +55 -0
- package/dist/chunk-AAXJNINV.js.map +1 -0
- package/dist/{chunk-YQ3CBLL4.js → chunk-BWLRUMOG.js} +78 -8
- package/dist/chunk-BWLRUMOG.js.map +1 -0
- package/dist/{chunk-2NLLXCJG.js → chunk-BXLOS5AJ.js} +2 -2
- package/dist/{chunk-CEH2AFXG.js → chunk-C24UZSFW.js} +6 -6
- package/dist/{chunk-ZPN7W3OP.js → chunk-CDUUDBWJ.js} +3 -3
- package/dist/{chunk-5UYSCYR7.js → chunk-CT56C22C.js} +4 -4
- package/dist/{chunk-HJQZQUPC.js → chunk-DJZWNKFO.js} +5 -5
- package/dist/{chunk-X7Y7WX73.js → chunk-DQEMWVMT.js} +1 -1
- package/dist/{chunk-CCTVAVTT.js → chunk-DZUJ46DO.js} +2 -2
- package/dist/{chunk-N6TRHP72.js → chunk-EILZG5VC.js} +2 -2
- package/dist/{chunk-GXWDWOWP.js → chunk-GDFVPUJ5.js} +2 -2
- package/dist/{chunk-7PWWGYGO.js → chunk-GNCCUR6K.js} +2 -2
- package/dist/{chunk-KPBLJCCV.js → chunk-IID2CMUU.js} +2 -2
- package/dist/{chunk-DEFI2QBT.js → chunk-J275IYMG.js} +25 -22
- package/dist/chunk-J275IYMG.js.map +1 -0
- package/dist/{chunk-UYCIS6V5.js → chunk-JCWY73FK.js} +2 -2
- package/dist/{chunk-SYJ6EKKE.js → chunk-JYYBA7TF.js} +2 -2
- package/dist/{chunk-T42L3S6A.js → chunk-LBWQ65SX.js} +4 -4
- package/dist/{chunk-MSTNSVXI.js → chunk-LDBFXD4F.js} +2 -1
- package/dist/chunk-LDBFXD4F.js.map +1 -0
- package/dist/{chunk-LWVO2QZV.js → chunk-LGO6A7GJ.js} +50 -50
- package/dist/{chunk-CEQF6L5K.js → chunk-LUNJ3WFO.js} +9 -7
- package/dist/chunk-LUNJ3WFO.js.map +1 -0
- package/dist/{chunk-2572MRP2.js → chunk-LZH5FR2W.js} +2 -2
- package/dist/{chunk-256FBCVX.js → chunk-M4AHBM72.js} +7 -7
- package/dist/{chunk-YEQEGSJA.js → chunk-MN4KB2A4.js} +3 -3
- package/dist/{chunk-AGKIG3YA.js → chunk-NKKD4ZAU.js} +2 -2
- package/dist/{chunk-3TMYV3LP.js → chunk-NTWN6HB2.js} +5 -5
- package/dist/{chunk-63FHSH7E.js → chunk-OCZIYAE5.js} +4 -4
- package/dist/{chunk-I2HTKOOP.js → chunk-ODZG724P.js} +2 -2
- package/dist/{chunk-HQSBYI5X.js → chunk-OTHZWLUD.js} +2 -2
- package/dist/{chunk-4W6INNXO.js → chunk-PE255F4T.js} +2 -2
- package/dist/{chunk-6L27N6YI.js → chunk-QOS5LBZN.js} +2 -2
- package/dist/{chunk-G72IPMR7.js → chunk-R4OCGPSH.js} +2 -2
- package/dist/{chunk-MIBKEW7A.js → chunk-R7JAM2XF.js} +3 -3
- package/dist/{chunk-LCU5R6TQ.js → chunk-RAIUTAZZ.js} +22 -3
- package/dist/chunk-RAIUTAZZ.js.map +1 -0
- package/dist/chunk-RIAM7DND.js +167 -0
- package/dist/chunk-RIAM7DND.js.map +1 -0
- package/dist/{chunk-JBPKEARU.js → chunk-RKNJBZ55.js} +4 -4
- package/dist/{chunk-HUNSEO5U.js → chunk-S2DPMJXH.js} +2 -2
- package/dist/{chunk-3PXVYJMC.js → chunk-SB7D4BT7.js} +536 -114
- package/dist/chunk-SB7D4BT7.js.map +1 -0
- package/dist/{chunk-JFJ3MHGV.js → chunk-SBDCZ2AX.js} +1 -1
- package/dist/chunk-SBDCZ2AX.js.map +1 -0
- package/dist/{chunk-HQSPXTQO.js → chunk-SIHSCCUQ.js} +1 -1
- package/dist/{chunk-R3AAOKR2.js → chunk-SPUJNJJC.js} +2 -2
- package/dist/{chunk-IAY7YBXS.js → chunk-SQI57UCJ.js} +2 -2
- package/dist/{chunk-CTQRPANJ.js → chunk-SVSRPG6M.js} +2 -2
- package/dist/{chunk-56BSXSHC.js → chunk-TBOJ76ER.js} +14 -1
- package/dist/{chunk-56BSXSHC.js.map → chunk-TBOJ76ER.js.map} +1 -1
- package/dist/{chunk-Z54TXZ2F.js → chunk-TF77C7SV.js} +14 -7
- package/dist/chunk-TF77C7SV.js.map +1 -0
- package/dist/{chunk-S2VBSTTA.js → chunk-THG4GYIE.js} +2 -2
- package/dist/{chunk-IXRC7EQG.js → chunk-TR7DGXGI.js} +2 -2
- package/dist/{chunk-GEULB2VI.js → chunk-TZNQUNKL.js} +7 -1
- package/dist/chunk-TZNQUNKL.js.map +1 -0
- package/dist/{chunk-BC4QD3FM.js → chunk-UIN2BWDD.js} +2 -2
- package/dist/{chunk-JTSVMJHV.js → chunk-UXO5IMBK.js} +3 -3
- package/dist/{chunk-DBXZZIDU.js → chunk-V3MXUL3D.js} +138 -73
- package/dist/chunk-V3MXUL3D.js.map +1 -0
- package/dist/{chunk-KQAFEZQX.js → chunk-VDX2J7OX.js} +2 -2
- package/dist/{chunk-MUJ4QFUQ.js → chunk-W4BMEGQA.js} +4 -4
- package/dist/{chunk-5HK3CJAR.js → chunk-W675UJCZ.js} +2 -2
- package/dist/{chunk-MDVBCPOS.js → chunk-XCTXS7VY.js} +2 -2
- package/dist/{chunk-53ENM6F6.js → chunk-XRYZRW54.js} +2 -2
- package/dist/{chunk-VJ6ECBIP.js → chunk-Y7DK7HHJ.js} +2 -2
- package/dist/{chunk-3MADV4YC.js → chunk-YB42WZCY.js} +2 -2
- package/dist/{chunk-X5SDZMO7.js → chunk-YHCBJULX.js} +2 -2
- package/dist/{chunk-3RHFGGI5.js → chunk-YLDXWCZP.js} +20 -5
- package/dist/chunk-YLDXWCZP.js.map +1 -0
- package/dist/{chunk-6JJT5AKI.js → chunk-Z7PBQPJ4.js} +2 -2
- package/dist/{chunk-ALCJRQ72.js → chunk-ZO6AXLEH.js} +2 -2
- package/dist/{chunk-VZVP2W4O.js → chunk-ZQHI2BZB.js} +2 -2
- package/dist/{chunk-CUS6S7PN.js → chunk-ZWXJBFZU.js} +9 -9
- package/dist/chunk-ZWXJBFZU.js.map +1 -0
- package/dist/{cli-Pulnz-qm.d.ts → cli-cShQ13XG.d.ts} +5 -5
- package/dist/cli.d.ts +13 -13
- package/dist/cli.js +77 -75
- package/dist/coding/pre-action-gate.d.ts +1 -1
- package/dist/compounding/engine.d.ts +2 -2
- package/dist/compounding/engine.js +17 -16
- package/dist/compounding/preference-consolidator.d.ts +1 -1
- package/dist/compression-optimizer.d.ts +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.js +6 -1
- package/dist/connectors/codex-materialize-runner.d.ts +1 -1
- package/dist/connectors/codex-materialize-runner.js +16 -15
- package/dist/connectors/codex-materialize.d.ts +1 -1
- package/dist/connectors/index.d.ts +1 -1
- package/dist/connectors/index.js +16 -15
- package/dist/consolidation-provenance-check.d.ts +2 -2
- package/dist/consolidation-undo.d.ts +2 -2
- package/dist/contradiction/index.d.ts +2 -2
- package/dist/contradiction/index.js +10 -2
- package/dist/converge-config.d.ts +1 -1
- package/dist/convergence-refresh.d.ts +2 -2
- package/dist/convergence-refresh.js +18 -17
- package/dist/conversation-index/backend.d.ts +1 -1
- package/dist/conversation-index/chunker.d.ts +1 -1
- package/dist/conversation-index/faiss-adapter.d.ts +1 -1
- package/dist/conversation-index/indexer.d.ts +1 -1
- package/dist/conversation-index/search.d.ts +1 -1
- package/dist/corpus-watermark.d.ts +1 -1
- package/dist/corpus-watermark.js +18 -17
- package/dist/cross-lingual-recall.d.ts +1 -1
- package/dist/day-summary.d.ts +1 -1
- package/dist/delinearize.d.ts +1 -1
- package/dist/dependency-propagation-config.d.ts +1 -1
- package/dist/{dependency-propagation-delivery-Co17gxYb.d.ts → dependency-propagation-delivery-CsGg-VwS.d.ts} +1 -1
- package/dist/direct-answer-wiring.d.ts +1 -1
- package/dist/direct-answer.d.ts +1 -1
- package/dist/embedding-fallback.d.ts +1 -1
- package/dist/enrichment/index.d.ts +1 -1
- package/dist/entity-origin-fields.d.ts +1 -1
- package/dist/entity-retrieval.d.ts +2 -2
- package/dist/entity-retrieval.js +16 -15
- package/dist/entity-schema.d.ts +1 -1
- package/dist/episodic-context.d.ts +1 -1
- package/dist/explicit-capture.d.ts +9 -9
- package/dist/explicit-capture.js +7 -6
- package/dist/external-wiki-access.d.ts +12 -13
- package/dist/external-wiki-access.js +36 -35
- package/dist/external-wiki-collection-registration.d.ts +1 -1
- package/dist/external-wiki-collection.d.ts +1 -1
- package/dist/external-wiki-mcp-tools.d.ts +11 -11
- package/dist/extraction-error-classification.d.ts +1 -1
- package/dist/extraction-faithfulness.d.ts +1 -1
- package/dist/extraction-judge-telemetry.d.ts +1 -1
- package/dist/extraction-judge-training.d.ts +1 -1
- package/dist/extraction-judge.d.ts +1 -1
- package/dist/extraction-judge.js +2 -2
- package/dist/extraction-liveness.d.ts +1 -1
- package/dist/extraction-normalization.d.ts +1 -1
- package/dist/extraction-normalization.js +2 -2
- package/dist/extraction-prompt.d.ts +2 -2
- package/dist/extraction-prompt.js +1 -1
- package/dist/extraction-source-grounding-rules.d.ts +1 -1
- package/dist/extraction-source-grounding.d.ts +1 -1
- package/dist/extraction.d.ts +1 -1
- package/dist/extraction.js +22 -21
- package/dist/fallback-llm.d.ts +1 -1
- package/dist/graph-dashboard-diff.d.ts +1 -1
- package/dist/graph-dashboard-key.d.ts +1 -1
- package/dist/graph-dashboard-parser.d.ts +1 -1
- package/dist/graph-edge-reinforcement.d.ts +1 -1
- package/dist/graph-path-reconstruction.d.ts +1 -1
- package/dist/graph-path-scoring.d.ts +1 -1
- package/dist/graph-snapshot.d.ts +1 -1
- package/dist/graph.d.ts +1 -1
- package/dist/harmonic-retrieval.js +1 -1
- package/dist/importance.d.ts +1 -1
- package/dist/importers/index.d.ts +1 -1
- package/dist/in-flight-reads.d.ts +1 -1
- package/dist/index.d.ts +716 -699
- package/dist/index.js +173 -125
- package/dist/intent.d.ts +1 -1
- package/dist/lcm/engine.d.ts +1 -1
- package/dist/lcm/engine.js +3 -3
- package/dist/lcm/index.d.ts +1 -1
- package/dist/lcm/index.js +6 -6
- package/dist/lcm/tools.d.ts +1 -1
- package/dist/lifecycle.d.ts +1 -1
- package/dist/live-connectors-runner.d.ts +1 -1
- package/dist/local-llm.d.ts +1 -1
- package/dist/local-model-endpoint.d.ts +1 -1
- package/dist/maintenance/memory-governance.d.ts +1 -1
- package/dist/maintenance/memory-governance.js +16 -15
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.d.ts +2 -2
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +16 -15
- package/dist/maintenance/rebuild-memory-projection.d.ts +2 -2
- package/dist/maintenance/rebuild-memory-projection.js +17 -16
- package/dist/{maintenance-DiSLtVN7.d.ts → maintenance-jhMpeGne.d.ts} +3 -3
- package/dist/mcp-memory-inspector-app.d.ts +11 -11
- package/dist/mcp-read-only-tools.js +1 -1
- package/dist/memory-action-policy.d.ts +1 -1
- package/dist/memory-cache.d.ts +1 -1
- package/dist/memory-lifecycle-ledger-utils.d.ts +1 -1
- package/dist/memory-projection-store.d.ts +1 -1
- package/dist/memory-provenance.d.ts +1 -1
- package/dist/memory-snapshot.d.ts +1 -1
- package/dist/memory-subject-cli.d.ts +177 -0
- package/dist/memory-subject-cli.js +16 -0
- package/dist/memory-subject.d.ts +128 -0
- package/dist/memory-subject.js +44 -0
- package/dist/memory-subject.js.map +1 -0
- package/dist/memory-worth-outcomes.d.ts +5 -4
- package/dist/memory-worth-outcomes.js +1 -1
- package/dist/models-json.d.ts +1 -1
- package/dist/namespaces/migrate.d.ts +3 -3
- package/dist/namespaces/migrate.js +17 -16
- package/dist/namespaces/principal.d.ts +1 -1
- package/dist/namespaces/search.d.ts +1 -1
- package/dist/namespaces/search.js +6 -6
- package/dist/namespaces/storage.d.ts +3 -3
- package/dist/namespaces/storage.js +16 -15
- package/dist/native-knowledge.d.ts +1 -1
- package/dist/offline-sync-impression-drain.d.ts +1 -1
- package/dist/operator-doctor-corpus.d.ts +1 -1
- package/dist/operator-doctor-corpus.js +19 -18
- package/dist/operator-doctor-replica.d.ts +1 -1
- package/dist/operator-toolkit.d.ts +3 -3
- package/dist/operator-toolkit.js +26 -24
- package/dist/orchestration/compression-guideline-coordinator.d.ts +2 -2
- package/dist/orchestration/maintenance.d.ts +4 -4
- package/dist/orchestration/maintenance.js +22 -21
- package/dist/{orchestrator-DzCaxNS4.d.ts → orchestrator-DyGUC7re.d.ts} +8 -8
- package/dist/orchestrator.d.ts +9 -9
- package/dist/orchestrator.js +108 -105
- package/dist/patterns-cli.d.ts +1 -1
- package/dist/{pipeline-HJ8DKbFl.d.ts → pipeline-C25Oxtp1.d.ts} +1 -1
- package/dist/policy-runtime.d.ts +1 -1
- package/dist/proactive-contention.d.ts +1 -1
- package/dist/provenance.d.ts +1 -1
- package/dist/{public-http-DwXauTX3.d.ts → public-http-CMe7NQzj.d.ts} +1 -1
- package/dist/{qmd-BzxluoLt.d.ts → qmd-DkDVCbgF.d.ts} +1 -1
- package/dist/qmd-preflight.d.ts +2 -2
- package/dist/qmd-recall-cache.d.ts +1 -1
- package/dist/qmd.d.ts +2 -2
- package/dist/qmd.js +4 -4
- package/dist/recall-concurrency-config.d.ts +1 -1
- package/dist/recall-disclosure-escalation.d.ts +1 -1
- package/dist/recall-explain-renderer.d.ts +1 -1
- package/dist/recall-explain-renderer.js +3 -3
- package/dist/recall-memory-map.d.ts +1 -1
- package/dist/recall-planner-llm.d.ts +1 -1
- package/dist/recall-state.d.ts +1 -1
- package/dist/recall-tag-filter.d.ts +1 -1
- package/dist/recall-timings.d.ts +1 -1
- package/dist/recall-xray-cli.d.ts +1 -1
- package/dist/recall-xray-cli.js +4 -4
- package/dist/recall-xray-renderer.d.ts +1 -1
- package/dist/recall-xray-renderer.js +3 -3
- package/dist/recall-xray.d.ts +1 -1
- package/dist/recall-xray.js +2 -2
- package/dist/reconcile/cursor.d.ts +1 -1
- package/dist/reconcile/manifest.d.ts +1 -1
- package/dist/reconcile/manifest.js +3 -3
- package/dist/reconcile/plan.d.ts +1 -1
- package/dist/replay/normalizers/chatgpt.d.ts +1 -1
- package/dist/replay/normalizers/claude.d.ts +1 -1
- package/dist/replay/normalizers/openclaw.d.ts +1 -1
- package/dist/replay/normalizers/shared.d.ts +1 -1
- package/dist/replay/runner.d.ts +1 -1
- package/dist/replay/types.d.ts +1 -1
- package/dist/replica-divergence.d.ts +1 -1
- package/dist/replica-peers-config.d.ts +1 -1
- package/dist/{resolution-DKMBPXHI.js → resolution-MFY72STR.js} +11 -3
- package/dist/resolution-MFY72STR.js.map +1 -0
- package/dist/resolve-auth-token.d.ts +1 -1
- package/dist/resume-bundles.js +7 -2
- package/dist/retrieval-agents.d.ts +2 -2
- package/dist/retrieval-tiers.d.ts +1 -1
- package/dist/routing/engine.d.ts +1 -1
- package/dist/routing/store.d.ts +1 -1
- package/dist/salvage-envelope.d.ts +1 -1
- package/dist/salvage-envelope.js +10 -2
- package/dist/schemas.d.ts +104 -90
- package/dist/schemas.js +1 -1
- package/dist/{scope-profiles-CEMZz0t5.d.ts → scope-profiles-B9xMoFO-.d.ts} +1 -1
- package/dist/search/embed-helper.d.ts +1 -1
- package/dist/search/factory.d.ts +1 -1
- package/dist/search/factory.js +5 -5
- package/dist/search/index.d.ts +1 -1
- package/dist/search/index.js +9 -9
- package/dist/search/lancedb-backend.d.ts +1 -1
- package/dist/search/meilisearch-backend.d.ts +1 -1
- package/dist/search/noop-backend.d.ts +1 -1
- package/dist/search/orama-backend.d.ts +1 -1
- package/dist/search/port.d.ts +1 -1
- package/dist/search/remote-backend.d.ts +1 -1
- package/dist/{semantic-consolidation-D9dYj6vu.d.ts → semantic-consolidation-C4uykW84.d.ts} +1 -1
- package/dist/semantic-consolidation.d.ts +2 -2
- package/dist/semantic-consolidation.js +17 -16
- package/dist/semantic-rule-promotion.js +16 -15
- package/dist/semantic-rule-verifier.d.ts +1 -1
- package/dist/semantic-rule-verifier.js +16 -15
- package/dist/{service-_qgST_0y.d.ts → service-DCZDZNcV.d.ts} +2 -2
- package/dist/session-observer-bands.d.ts +1 -1
- package/dist/session-observer-state.d.ts +1 -1
- package/dist/shared-context/manager.d.ts +11 -11
- package/dist/signal.d.ts +1 -1
- package/dist/source-agent-qualifier.d.ts +1 -1
- package/dist/source-agent-qualifier.js +18 -17
- package/dist/{storage-B9lbNTYE.d.ts → storage-CcKmEjL8.d.ts} +3 -2
- package/dist/storage.d.ts +2 -2
- package/dist/storage.js +18 -17
- package/dist/subject-config.d.ts +38 -0
- package/dist/subject-config.js +20 -0
- package/dist/subject-config.js.map +1 -0
- package/dist/summarizer.d.ts +1 -1
- package/dist/summary-snapshot.d.ts +1 -1
- package/dist/support-passport/index.d.ts +14 -14
- package/dist/support-passport/index.js +38 -37
- package/dist/temporal-supersession.d.ts +2 -2
- package/dist/temporal-timeline-recall.d.ts +1 -1
- package/dist/temporal-validity.d.ts +1 -1
- package/dist/threading.d.ts +1 -1
- package/dist/tier-migration.d.ts +2 -2
- package/dist/tier-routing.d.ts +1 -1
- package/dist/topics.d.ts +1 -1
- package/dist/transcript.d.ts +1 -1
- package/dist/transfer/backup.js +2 -2
- package/dist/transfer/capsule-export.js +2 -2
- package/dist/transfer/capsule-import.js +2 -2
- package/dist/transfer/types.d.ts +66 -66
- package/dist/trust-score-stage.d.ts +1 -1
- package/dist/trust-score.d.ts +1 -1
- package/dist/{types-BrEzuxPA.d.ts → types-Pi0lfaEt.d.ts} +38 -29
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/utility-runtime.d.ts +1 -1
- package/dist/verified-recall.js +16 -15
- package/dist/who-knows-cli.d.ts +11 -11
- package/dist/who-knows-cli.js +17 -16
- package/dist/who-knows.d.ts +11 -11
- package/dist/who-knows.js +16 -15
- package/dist/write-envelope.d.ts +5 -2
- package/dist/write-envelope.js +10 -1
- package/package.json +2 -2
- package/scripts/build-with-heap.mjs +1 -1
- package/src/access-boundary.ts +2 -0
- package/src/access-mcp-admin-tools.ts +14 -0
- package/src/access-mcp-output-schemas.ts +6 -0
- package/src/access-mcp.ts +6 -6
- package/src/access-operations-batch.ts +8 -0
- package/src/access-service.ts +85 -0
- package/src/access-surface-catalog.ts +2 -0
- package/src/config.ts +10 -17
- package/src/extraction-prompt.ts +1 -0
- package/src/extraction.ts +4 -1
- package/src/index.ts +5 -6
- package/src/mcp-read-only-tools.ts +1 -0
- package/src/memory-subject-cli.ts +135 -0
- package/src/memory-subject.test.ts +48 -0
- package/src/memory-subject.ts +314 -0
- package/src/memory-worth-outcomes.test.ts +6 -2
- package/src/memory-worth-outcomes.ts +11 -7
- package/src/operator-toolkit.ts +1 -1
- package/src/orchestration/extraction-persist.ts +48 -48
- package/src/orchestration/recall-internal.ts +6 -5
- package/src/procedural/library-maintenance.test.ts +582 -0
- package/src/procedural/library-maintenance.ts +546 -0
- package/src/procedural/maintenance-config.ts +78 -0
- package/src/procedural/procedure-recall.ts +29 -1
- package/src/procedural/procedure-stats.ts +20 -0
- package/src/schemas.ts +7 -0
- package/src/spaces/index.ts +38 -2
- package/src/storage.ts +6 -2
- package/src/subject-config.ts +80 -0
- package/src/types.ts +26 -29
- package/src/write-envelope.test.ts +14 -0
- package/src/write-envelope.ts +24 -3
- package/dist/chunk-3PXVYJMC.js.map +0 -1
- package/dist/chunk-3RHFGGI5.js.map +0 -1
- package/dist/chunk-4NZHHGVL.js.map +0 -1
- package/dist/chunk-CEQF6L5K.js.map +0 -1
- package/dist/chunk-CUS6S7PN.js.map +0 -1
- package/dist/chunk-DBXZZIDU.js.map +0 -1
- package/dist/chunk-DEFI2QBT.js.map +0 -1
- package/dist/chunk-EIR5VLIH.js.map +0 -1
- package/dist/chunk-GEULB2VI.js.map +0 -1
- package/dist/chunk-JFJ3MHGV.js.map +0 -1
- package/dist/chunk-JG22O53B.js.map +0 -1
- package/dist/chunk-LCU5R6TQ.js.map +0 -1
- package/dist/chunk-MSTNSVXI.js.map +0 -1
- package/dist/chunk-YQ3CBLL4.js.map +0 -1
- package/dist/chunk-Z54TXZ2F.js.map +0 -1
- /package/dist/{capsule-crypto-7FJQINUR.js.map → capsule-crypto-YO5QJ6L3.js.map} +0 -0
- /package/dist/{chunk-LYIZXQYY.js.map → chunk-2E36UXVW.js.map} +0 -0
- /package/dist/{chunk-7QFBLYFP.js.map → chunk-2XDWWPTN.js.map} +0 -0
- /package/dist/{chunk-CFRBTATE.js.map → chunk-2YI72KM3.js.map} +0 -0
- /package/dist/{chunk-3YTTAGPB.js.map → chunk-3DVBKTSO.js.map} +0 -0
- /package/dist/{chunk-VPGRXEAB.js.map → chunk-3I7ASZN3.js.map} +0 -0
- /package/dist/{chunk-WTOE7CW4.js.map → chunk-4KYOLI6M.js.map} +0 -0
- /package/dist/{chunk-ESCQ6LY7.js.map → chunk-5NM4OH4P.js.map} +0 -0
- /package/dist/{chunk-Y23B2QXP.js.map → chunk-5YQ63T4B.js.map} +0 -0
- /package/dist/{chunk-PMVPCZJZ.js.map → chunk-6433HV72.js.map} +0 -0
- /package/dist/{chunk-NS5ETDYD.js.map → chunk-7BEPVIH3.js.map} +0 -0
- /package/dist/{chunk-W6TSGWYS.js.map → chunk-7YQ4IYS2.js.map} +0 -0
- /package/dist/{chunk-2NLLXCJG.js.map → chunk-BXLOS5AJ.js.map} +0 -0
- /package/dist/{chunk-CEH2AFXG.js.map → chunk-C24UZSFW.js.map} +0 -0
- /package/dist/{chunk-ZPN7W3OP.js.map → chunk-CDUUDBWJ.js.map} +0 -0
- /package/dist/{chunk-5UYSCYR7.js.map → chunk-CT56C22C.js.map} +0 -0
- /package/dist/{chunk-HJQZQUPC.js.map → chunk-DJZWNKFO.js.map} +0 -0
- /package/dist/{chunk-X7Y7WX73.js.map → chunk-DQEMWVMT.js.map} +0 -0
- /package/dist/{chunk-CCTVAVTT.js.map → chunk-DZUJ46DO.js.map} +0 -0
- /package/dist/{chunk-N6TRHP72.js.map → chunk-EILZG5VC.js.map} +0 -0
- /package/dist/{chunk-GXWDWOWP.js.map → chunk-GDFVPUJ5.js.map} +0 -0
- /package/dist/{chunk-7PWWGYGO.js.map → chunk-GNCCUR6K.js.map} +0 -0
- /package/dist/{chunk-KPBLJCCV.js.map → chunk-IID2CMUU.js.map} +0 -0
- /package/dist/{chunk-UYCIS6V5.js.map → chunk-JCWY73FK.js.map} +0 -0
- /package/dist/{chunk-SYJ6EKKE.js.map → chunk-JYYBA7TF.js.map} +0 -0
- /package/dist/{chunk-T42L3S6A.js.map → chunk-LBWQ65SX.js.map} +0 -0
- /package/dist/{chunk-LWVO2QZV.js.map → chunk-LGO6A7GJ.js.map} +0 -0
- /package/dist/{chunk-2572MRP2.js.map → chunk-LZH5FR2W.js.map} +0 -0
- /package/dist/{chunk-256FBCVX.js.map → chunk-M4AHBM72.js.map} +0 -0
- /package/dist/{chunk-YEQEGSJA.js.map → chunk-MN4KB2A4.js.map} +0 -0
- /package/dist/{chunk-AGKIG3YA.js.map → chunk-NKKD4ZAU.js.map} +0 -0
- /package/dist/{chunk-3TMYV3LP.js.map → chunk-NTWN6HB2.js.map} +0 -0
- /package/dist/{chunk-63FHSH7E.js.map → chunk-OCZIYAE5.js.map} +0 -0
- /package/dist/{chunk-I2HTKOOP.js.map → chunk-ODZG724P.js.map} +0 -0
- /package/dist/{chunk-HQSBYI5X.js.map → chunk-OTHZWLUD.js.map} +0 -0
- /package/dist/{chunk-4W6INNXO.js.map → chunk-PE255F4T.js.map} +0 -0
- /package/dist/{chunk-6L27N6YI.js.map → chunk-QOS5LBZN.js.map} +0 -0
- /package/dist/{chunk-G72IPMR7.js.map → chunk-R4OCGPSH.js.map} +0 -0
- /package/dist/{chunk-MIBKEW7A.js.map → chunk-R7JAM2XF.js.map} +0 -0
- /package/dist/{chunk-JBPKEARU.js.map → chunk-RKNJBZ55.js.map} +0 -0
- /package/dist/{chunk-HUNSEO5U.js.map → chunk-S2DPMJXH.js.map} +0 -0
- /package/dist/{chunk-HQSPXTQO.js.map → chunk-SIHSCCUQ.js.map} +0 -0
- /package/dist/{chunk-R3AAOKR2.js.map → chunk-SPUJNJJC.js.map} +0 -0
- /package/dist/{chunk-IAY7YBXS.js.map → chunk-SQI57UCJ.js.map} +0 -0
- /package/dist/{chunk-CTQRPANJ.js.map → chunk-SVSRPG6M.js.map} +0 -0
- /package/dist/{chunk-S2VBSTTA.js.map → chunk-THG4GYIE.js.map} +0 -0
- /package/dist/{chunk-IXRC7EQG.js.map → chunk-TR7DGXGI.js.map} +0 -0
- /package/dist/{chunk-BC4QD3FM.js.map → chunk-UIN2BWDD.js.map} +0 -0
- /package/dist/{chunk-JTSVMJHV.js.map → chunk-UXO5IMBK.js.map} +0 -0
- /package/dist/{chunk-KQAFEZQX.js.map → chunk-VDX2J7OX.js.map} +0 -0
- /package/dist/{chunk-MUJ4QFUQ.js.map → chunk-W4BMEGQA.js.map} +0 -0
- /package/dist/{chunk-5HK3CJAR.js.map → chunk-W675UJCZ.js.map} +0 -0
- /package/dist/{chunk-MDVBCPOS.js.map → chunk-XCTXS7VY.js.map} +0 -0
- /package/dist/{chunk-53ENM6F6.js.map → chunk-XRYZRW54.js.map} +0 -0
- /package/dist/{chunk-VJ6ECBIP.js.map → chunk-Y7DK7HHJ.js.map} +0 -0
- /package/dist/{chunk-3MADV4YC.js.map → chunk-YB42WZCY.js.map} +0 -0
- /package/dist/{chunk-X5SDZMO7.js.map → chunk-YHCBJULX.js.map} +0 -0
- /package/dist/{chunk-6JJT5AKI.js.map → chunk-Z7PBQPJ4.js.map} +0 -0
- /package/dist/{chunk-ALCJRQ72.js.map → chunk-ZO6AXLEH.js.map} +0 -0
- /package/dist/{chunk-VZVP2W4O.js.map → chunk-ZQHI2BZB.js.map} +0 -0
- /package/dist/{resolution-DKMBPXHI.js.map → memory-subject-cli.js.map} +0 -0
package/dist/briefing.js
CHANGED
|
@@ -18,27 +18,27 @@ import {
|
|
|
18
18
|
renderBriefingMarkdown,
|
|
19
19
|
resolveBriefingSaveDir,
|
|
20
20
|
validateBriefingFormat
|
|
21
|
-
} from "./chunk-
|
|
22
|
-
import "./chunk-
|
|
23
|
-
import "./chunk-46WM6JX2.js";
|
|
21
|
+
} from "./chunk-NTWN6HB2.js";
|
|
22
|
+
import "./chunk-J275IYMG.js";
|
|
24
23
|
import "./chunk-UHVXE24Y.js";
|
|
24
|
+
import "./chunk-46WM6JX2.js";
|
|
25
25
|
import "./chunk-SXIMQLGV.js";
|
|
26
|
-
import "./chunk-
|
|
27
|
-
import "./chunk-
|
|
26
|
+
import "./chunk-YHCBJULX.js";
|
|
27
|
+
import "./chunk-DJZWNKFO.js";
|
|
28
|
+
import "./chunk-N37X5RU7.js";
|
|
28
29
|
import "./chunk-NNBZS3DY.js";
|
|
29
30
|
import "./chunk-CYEPCZN5.js";
|
|
30
31
|
import "./chunk-GIC6BASP.js";
|
|
31
32
|
import "./chunk-YQNNHLCG.js";
|
|
32
|
-
import "./chunk-6KTXE6A3.js";
|
|
33
|
-
import "./chunk-N37X5RU7.js";
|
|
34
33
|
import "./chunk-W7IGLX4G.js";
|
|
34
|
+
import "./chunk-6KTXE6A3.js";
|
|
35
35
|
import "./chunk-GUMZC2BO.js";
|
|
36
36
|
import "./chunk-227UFSEQ.js";
|
|
37
37
|
import "./chunk-ET356KSB.js";
|
|
38
38
|
import "./chunk-72A4L5JJ.js";
|
|
39
39
|
import "./chunk-A7Q43EUZ.js";
|
|
40
40
|
import "./chunk-S2V7RUCL.js";
|
|
41
|
-
import "./chunk-
|
|
41
|
+
import "./chunk-SBDCZ2AX.js";
|
|
42
42
|
import "./chunk-SCU65EZI.js";
|
|
43
43
|
import "./chunk-PO7NXBG2.js";
|
|
44
44
|
import "./chunk-S2HLHAZ4.js";
|
|
@@ -46,8 +46,8 @@ import "./chunk-DM2T26WE.js";
|
|
|
46
46
|
import "./chunk-LDXUBPMO.js";
|
|
47
47
|
import "./chunk-UG6VXIOK.js";
|
|
48
48
|
import "./chunk-AAD2ZS6P.js";
|
|
49
|
-
import "./chunk-
|
|
50
|
-
import "./chunk-
|
|
49
|
+
import "./chunk-W4BMEGQA.js";
|
|
50
|
+
import "./chunk-RAIUTAZZ.js";
|
|
51
51
|
import "./chunk-BT7NVCML.js";
|
|
52
52
|
import "./chunk-3ONXXHQO.js";
|
|
53
53
|
import "./chunk-YXZG5TVN.js";
|
|
@@ -60,10 +60,10 @@ import "./chunk-ZVPVTPGI.js";
|
|
|
60
60
|
import "./chunk-5WITETWU.js";
|
|
61
61
|
import "./chunk-6CIAGZ6X.js";
|
|
62
62
|
import "./chunk-G7D6GZ5J.js";
|
|
63
|
-
import "./chunk-
|
|
63
|
+
import "./chunk-C24UZSFW.js";
|
|
64
64
|
import "./chunk-JXN77SGO.js";
|
|
65
|
-
import "./chunk-IUM3VSHI.js";
|
|
66
65
|
import "./chunk-ZLQ37WJX.js";
|
|
66
|
+
import "./chunk-IUM3VSHI.js";
|
|
67
67
|
import "./chunk-C64XATK7.js";
|
|
68
68
|
import "./chunk-42JKGUFJ.js";
|
|
69
69
|
import "./chunk-UW5NPZJ2.js";
|
|
@@ -74,6 +74,7 @@ import "./chunk-RGMVMVMF.js";
|
|
|
74
74
|
import "./chunk-N7RWREIQ.js";
|
|
75
75
|
import "./chunk-UBCBDJOB.js";
|
|
76
76
|
import "./chunk-NXH34IPL.js";
|
|
77
|
+
import "./chunk-RIAM7DND.js";
|
|
77
78
|
import "./chunk-ZIKENA2C.js";
|
|
78
79
|
import "./chunk-PQVCH2AE.js";
|
|
79
80
|
import "./chunk-6Q3ZTEF6.js";
|
|
@@ -90,13 +91,13 @@ import "./chunk-DVYRD4HY.js";
|
|
|
90
91
|
import "./chunk-ZA53AZND.js";
|
|
91
92
|
import "./chunk-GCASGYIO.js";
|
|
92
93
|
import "./chunk-7RJUVTVF.js";
|
|
93
|
-
import "./chunk-JOEJG4SD.js";
|
|
94
94
|
import "./chunk-2LWQSV6A.js";
|
|
95
95
|
import "./chunk-RL6NEVXT.js";
|
|
96
|
-
import "./chunk-5FVVY2EB.js";
|
|
97
|
-
import "./chunk-FFAZ2XFU.js";
|
|
98
96
|
import "./chunk-XDL5CYZN.js";
|
|
99
97
|
import "./chunk-JDSVLVCG.js";
|
|
98
|
+
import "./chunk-JOEJG4SD.js";
|
|
99
|
+
import "./chunk-5FVVY2EB.js";
|
|
100
|
+
import "./chunk-FFAZ2XFU.js";
|
|
100
101
|
import "./chunk-5GKPFL3S.js";
|
|
101
102
|
import "./chunk-JAKIDQB2.js";
|
|
102
103
|
import "./chunk-P7FMDTKL.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { ck as AmbientCaptureProvenance, cl as BufferTurnOwner, cm as ProbeTimeoutError, cn as bufferTurnArrayIsSuffixOfSnapshot, co as bufferTurnArraysEqual, cp as bufferTurnsEqual, cq as copyBufferTurn, cr as describeError, cs as liveTurnsFromExtractionSnapshot, ct as matchingQueuedExtractionPrefixLength, cu as probeWithTimeout } from './types-Pi0lfaEt.js';
|
|
2
2
|
import './message-parts/index.js';
|
|
3
3
|
import './bounded-jsonl-state.js';
|
|
4
4
|
import './types-CM86alG1.js';
|
package/dist/buffer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as StorageManager } from './storage-
|
|
2
|
-
import { P as PluginConfig, k as BufferTurn, l as ExtractionBufferSnapshot } from './types-
|
|
1
|
+
import { S as StorageManager } from './storage-CcKmEjL8.js';
|
|
2
|
+
import { P as PluginConfig, k as BufferTurn, l as ExtractionBufferSnapshot } from './types-Pi0lfaEt.js';
|
|
3
3
|
import './corpus-read-cancellation.js';
|
|
4
4
|
import './artifact-search.js';
|
|
5
5
|
import './entity-id-normalization.js';
|
package/dist/buffer.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SmartBuffer
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TR7DGXGI.js";
|
|
4
4
|
import "./chunk-H3FZVNRN.js";
|
|
5
5
|
import "./chunk-2AD5SXO4.js";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-THG4GYIE.js";
|
|
7
7
|
import "./chunk-CSAKJVXW.js";
|
|
8
8
|
import "./chunk-K2XUWZBM.js";
|
|
9
9
|
import "./chunk-OD4FM2U7.js";
|
|
10
|
-
import "./chunk-
|
|
10
|
+
import "./chunk-C24UZSFW.js";
|
|
11
11
|
import "./chunk-JXN77SGO.js";
|
|
12
|
-
import "./chunk-IUM3VSHI.js";
|
|
13
12
|
import "./chunk-ZLQ37WJX.js";
|
|
13
|
+
import "./chunk-IUM3VSHI.js";
|
|
14
14
|
import "./chunk-C64XATK7.js";
|
|
15
15
|
import "./chunk-42JKGUFJ.js";
|
|
16
16
|
import "./chunk-6Q3ZTEF6.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
export { a as ProcessBatchContext, P as ProcessBatchFn, b as ProcessBatchResult, f as formatBatchTranscript, r as resolveBulkImportContext, c as runBulkImportPipeline, v as validateBatchSize } from '../pipeline-
|
|
1
|
+
import { bG as BulkImportSourceAdapter } from '../types-Pi0lfaEt.js';
|
|
2
|
+
export { bF as BulkImportError, ab as BulkImportOptions, ad as BulkImportResult, ac as BulkImportSource, bO as ImportSourceRole, aa as ImportTurn, bP as ImportTurnValidationIssue, c0 as isImportRole, c2 as parseIsoTimestamp, c3 as validateImportTurn } from '../types-Pi0lfaEt.js';
|
|
3
|
+
export { a as ProcessBatchContext, P as ProcessBatchFn, b as ProcessBatchResult, f as formatBatchTranscript, r as resolveBulkImportContext, c as runBulkImportPipeline, v as validateBatchSize } from '../pipeline-C25Oxtp1.js';
|
|
4
4
|
import '../message-parts/index.js';
|
|
5
5
|
import '../bounded-jsonl-state.js';
|
|
6
6
|
import '../types-CM86alG1.js';
|
package/dist/calibration.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FallbackLlmClient } from './fallback-llm.js';
|
|
2
|
-
import { G as GatewayConfig, A as AgentPersonaModelConfig } from './types-
|
|
2
|
+
import { G as GatewayConfig, A as AgentPersonaModelConfig } from './types-Pi0lfaEt.js';
|
|
3
3
|
import './resolve-provider-secret.js';
|
|
4
4
|
import './message-parts/index.js';
|
|
5
5
|
import './bounded-jsonl-state.js';
|
package/dist/calibration.js
CHANGED
package/dist/capabilities.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
decryptCapsuleFileInMemory,
|
|
4
4
|
encryptCapsuleFile,
|
|
5
5
|
isEncryptedCapsuleFile
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-DQEMWVMT.js";
|
|
7
7
|
import "./chunk-BJMBJZ2Y.js";
|
|
8
8
|
import "./chunk-UKJAGEXH.js";
|
|
9
9
|
import "./chunk-FP2373TW.js";
|
|
@@ -15,4 +15,4 @@ export {
|
|
|
15
15
|
encryptCapsuleFile,
|
|
16
16
|
isEncryptedCapsuleFile
|
|
17
17
|
};
|
|
18
|
-
//# sourceMappingURL=capsule-crypto-
|
|
18
|
+
//# sourceMappingURL=capsule-crypto-YO5QJ6L3.js.map
|
|
@@ -2,7 +2,7 @@ import { CausalChainIndex } from './causal-chain.js';
|
|
|
2
2
|
import { ConsolidatedPreference } from './compounding/preference-consolidator.js';
|
|
3
3
|
import './causal-trajectory.js';
|
|
4
4
|
import './objective-state.js';
|
|
5
|
-
import './types-
|
|
5
|
+
import './types-Pi0lfaEt.js';
|
|
6
6
|
import './message-parts/index.js';
|
|
7
7
|
import './bounded-jsonl-state.js';
|
|
8
8
|
import './types-CM86alG1.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as GatewayConfig, A as AgentPersonaModelConfig, P as PluginConfig, M as MemoryFile } from './types-
|
|
1
|
+
import { G as GatewayConfig, A as AgentPersonaModelConfig, P as PluginConfig, M as MemoryFile } from './types-Pi0lfaEt.js';
|
|
2
2
|
import { RolloutSummaryInput, MaterializeResult } from './connectors/codex-materialize.js';
|
|
3
3
|
import './message-parts/index.js';
|
|
4
4
|
import './bounded-jsonl-state.js';
|
|
@@ -4,36 +4,36 @@ import {
|
|
|
4
4
|
} from "./chunk-NZPFCP5A.js";
|
|
5
5
|
import {
|
|
6
6
|
buildExtensionsBlockForConsolidation
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-ZQHI2BZB.js";
|
|
8
8
|
import "./chunk-5JMAGU26.js";
|
|
9
9
|
import "./chunk-B7RWBZXW.js";
|
|
10
10
|
import {
|
|
11
11
|
runPostConsolidationMaterialize
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-QOS5LBZN.js";
|
|
13
13
|
import "./chunk-RDFF2NAU.js";
|
|
14
14
|
import {
|
|
15
15
|
resolveCausalTrajectoryStoreDir
|
|
16
16
|
} from "./chunk-PP7R754B.js";
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-46WM6JX2.js";
|
|
17
|
+
import "./chunk-J275IYMG.js";
|
|
19
18
|
import "./chunk-UHVXE24Y.js";
|
|
19
|
+
import "./chunk-46WM6JX2.js";
|
|
20
20
|
import "./chunk-SXIMQLGV.js";
|
|
21
|
-
import "./chunk-
|
|
22
|
-
import "./chunk-
|
|
21
|
+
import "./chunk-YHCBJULX.js";
|
|
22
|
+
import "./chunk-DJZWNKFO.js";
|
|
23
|
+
import "./chunk-N37X5RU7.js";
|
|
23
24
|
import "./chunk-NNBZS3DY.js";
|
|
24
25
|
import "./chunk-CYEPCZN5.js";
|
|
25
26
|
import "./chunk-GIC6BASP.js";
|
|
26
27
|
import "./chunk-YQNNHLCG.js";
|
|
27
|
-
import "./chunk-6KTXE6A3.js";
|
|
28
|
-
import "./chunk-N37X5RU7.js";
|
|
29
28
|
import "./chunk-W7IGLX4G.js";
|
|
29
|
+
import "./chunk-6KTXE6A3.js";
|
|
30
30
|
import "./chunk-GUMZC2BO.js";
|
|
31
31
|
import "./chunk-227UFSEQ.js";
|
|
32
32
|
import "./chunk-ET356KSB.js";
|
|
33
33
|
import "./chunk-72A4L5JJ.js";
|
|
34
34
|
import "./chunk-A7Q43EUZ.js";
|
|
35
35
|
import "./chunk-S2V7RUCL.js";
|
|
36
|
-
import "./chunk-
|
|
36
|
+
import "./chunk-SBDCZ2AX.js";
|
|
37
37
|
import "./chunk-SCU65EZI.js";
|
|
38
38
|
import "./chunk-PO7NXBG2.js";
|
|
39
39
|
import "./chunk-S2HLHAZ4.js";
|
|
@@ -41,8 +41,8 @@ import "./chunk-DM2T26WE.js";
|
|
|
41
41
|
import "./chunk-LDXUBPMO.js";
|
|
42
42
|
import "./chunk-UG6VXIOK.js";
|
|
43
43
|
import "./chunk-AAD2ZS6P.js";
|
|
44
|
-
import "./chunk-
|
|
45
|
-
import "./chunk-
|
|
44
|
+
import "./chunk-W4BMEGQA.js";
|
|
45
|
+
import "./chunk-RAIUTAZZ.js";
|
|
46
46
|
import "./chunk-BT7NVCML.js";
|
|
47
47
|
import "./chunk-3ONXXHQO.js";
|
|
48
48
|
import "./chunk-YXZG5TVN.js";
|
|
@@ -55,10 +55,10 @@ import "./chunk-ZVPVTPGI.js";
|
|
|
55
55
|
import "./chunk-5WITETWU.js";
|
|
56
56
|
import "./chunk-6CIAGZ6X.js";
|
|
57
57
|
import "./chunk-G7D6GZ5J.js";
|
|
58
|
-
import "./chunk-
|
|
58
|
+
import "./chunk-C24UZSFW.js";
|
|
59
59
|
import "./chunk-JXN77SGO.js";
|
|
60
|
-
import "./chunk-IUM3VSHI.js";
|
|
61
60
|
import "./chunk-ZLQ37WJX.js";
|
|
61
|
+
import "./chunk-IUM3VSHI.js";
|
|
62
62
|
import "./chunk-C64XATK7.js";
|
|
63
63
|
import "./chunk-42JKGUFJ.js";
|
|
64
64
|
import {
|
|
@@ -72,6 +72,7 @@ import "./chunk-RGMVMVMF.js";
|
|
|
72
72
|
import "./chunk-N7RWREIQ.js";
|
|
73
73
|
import "./chunk-TOTT6S2V.js";
|
|
74
74
|
import "./chunk-NXH34IPL.js";
|
|
75
|
+
import "./chunk-RIAM7DND.js";
|
|
75
76
|
import "./chunk-ZIKENA2C.js";
|
|
76
77
|
import "./chunk-PQVCH2AE.js";
|
|
77
78
|
import "./chunk-6Q3ZTEF6.js";
|
|
@@ -88,13 +89,13 @@ import "./chunk-DVYRD4HY.js";
|
|
|
88
89
|
import "./chunk-ZA53AZND.js";
|
|
89
90
|
import "./chunk-GCASGYIO.js";
|
|
90
91
|
import "./chunk-7RJUVTVF.js";
|
|
91
|
-
import "./chunk-JOEJG4SD.js";
|
|
92
92
|
import "./chunk-2LWQSV6A.js";
|
|
93
93
|
import "./chunk-RL6NEVXT.js";
|
|
94
|
-
import "./chunk-5FVVY2EB.js";
|
|
95
|
-
import "./chunk-FFAZ2XFU.js";
|
|
96
94
|
import "./chunk-XDL5CYZN.js";
|
|
97
95
|
import "./chunk-JDSVLVCG.js";
|
|
96
|
+
import "./chunk-JOEJG4SD.js";
|
|
97
|
+
import "./chunk-5FVVY2EB.js";
|
|
98
|
+
import "./chunk-FFAZ2XFU.js";
|
|
98
99
|
import "./chunk-5GKPFL3S.js";
|
|
99
100
|
import "./chunk-JAKIDQB2.js";
|
|
100
101
|
import "./chunk-P7FMDTKL.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/causal-consolidation.ts"],"sourcesContent":["/**\n * causal-consolidation.ts — CMC Phase 2: LLM-Assisted Causal Consolidation\n *\n * Uses an LLM to analyze causal trajectory patterns across sessions.\n * The LLM receives the causal chain graph as context — connected trajectories\n * from different sessions — and identifies recurring behavioral patterns,\n * preference signals, and actionable rules.\n *\n * This is the core CMC innovation: the LLM gets cross-session causal context\n * that no other memory system provides. It can see that a user investigated\n * a bug in session 1, attempted a fix in session 2, and succeeded in session 3 —\n * and synthesize a rule or preference from that chain.\n */\n\nimport { createHash } from \"node:crypto\";\nimport { resolveCausalTrajectoryStoreDir, type CausalTrajectoryRecord } from \"./causal-trajectory.js\";\nimport { readChainIndex, resolveChainsDir, type CausalChainIndex, type CausalEdge } from \"./causal-chain.js\";\nimport { listJsonFiles, readJsonFile } from \"./json-store.js\";\nimport { isRecord } from \"./store-contract.js\";\nimport { FallbackLlmClient, fallbackLlmRuntimeContextFromConfig } from \"./fallback-llm.js\";\nimport type { AgentPersonaModelConfig, GatewayConfig, MemoryFile, PluginConfig } from \"./types.js\";\nimport path from \"node:path\";\nimport { log } from \"./logger.js\";\nimport { runPostConsolidationMaterialize } from \"./connectors/codex-materialize-runner.js\";\nimport type { MaterializeResult, RolloutSummaryInput } from \"./connectors/codex-materialize.js\";\nimport { buildExtensionsBlockForConsolidation } from \"./semantic-consolidation.js\";\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\nexport interface CausalPatternCandidate {\n id: string;\n sourceType: \"causal-pattern\";\n subject: string;\n category: \"principle\" | \"rule\" | \"preference\";\n content: string;\n score: number;\n rationale: string;\n outcome: null;\n provenance: string[];\n agent: string | null;\n workflow: string | null;\n}\n\nexport interface ConsolidationConfig {\n minRecurrence: number;\n minSessions: number;\n successThreshold: number;\n}\n\nexport interface LlmConsolidationResult {\n rules: Array<{\n content: string;\n category: \"rule\" | \"principle\" | \"preference\";\n confidence: number;\n evidence: string[];\n }>;\n preferences: Array<{\n statement: string;\n confidence: number;\n evidence: string[];\n }>;\n}\n\nconst CAUSAL_RULE_CATEGORIES = new Set([\"rule\", \"principle\", \"preference\"]);\n\ninterface ConsolidationLlmClient {\n isAvailable(options?: { agentId?: string; modelChain?: AgentPersonaModelConfig }): boolean;\n chatCompletion(\n messages: Array<{ role: \"system\" | \"user\" | \"assistant\"; content: string }>,\n options?: { temperature?: number; maxTokens?: number; agentId?: string; modelChain?: AgentPersonaModelConfig },\n ): Promise<{ content: string } | null>;\n}\n\n// ─── Trajectory Reading ──────────────────────────────────────────────────────\n\nasync function readAllTrajectories(\n memoryDir: string,\n causalTrajectoryStoreDir?: string,\n): Promise<CausalTrajectoryRecord[]> {\n const root = resolveCausalTrajectoryStoreDir(memoryDir, causalTrajectoryStoreDir);\n const trajectoriesDir = path.join(root, \"trajectories\");\n\n const files = await listJsonFiles(trajectoriesDir).catch(() => [] as string[]);\n const results: CausalTrajectoryRecord[] = [];\n\n for (const filePath of files) {\n try {\n const raw = await readJsonFile(filePath);\n if (isRecord(raw) && typeof raw.trajectoryId === \"string\") {\n results.push(raw as unknown as CausalTrajectoryRecord);\n }\n } catch {\n // skip invalid\n }\n }\n\n return results;\n}\n\n// ─── Context Formatting ──────────────────────────────────────────────────────\n\n/**\n * Format trajectories and their causal connections as a readable context\n * for the LLM. Groups by session and shows chain connections.\n */\nfunction formatCausalContext(\n trajectories: CausalTrajectoryRecord[],\n chainIndex: CausalChainIndex,\n maxChars: number = 8000,\n): string {\n // Group trajectories by session\n const bySession = new Map<string, CausalTrajectoryRecord[]>();\n for (const t of trajectories) {\n const list = bySession.get(t.sessionKey) ?? [];\n list.push(t);\n bySession.set(t.sessionKey, list);\n }\n\n const lines: string[] = [];\n lines.push(`## Causal Trajectories (${trajectories.length} across ${bySession.size} sessions)`);\n lines.push(\"\");\n\n // Format each session's trajectories\n for (const [sessionKey, sessionTrajs] of bySession) {\n lines.push(`### Session: ${sessionKey}`);\n for (const t of sessionTrajs.slice(0, 5)) {\n const outcome = t.outcomeKind === \"success\" ? \"+\" : t.outcomeKind === \"failure\" ? \"-\" : \"~\";\n lines.push(`[${outcome}] Goal: ${t.goal}`);\n lines.push(` Action: ${t.actionSummary}`);\n lines.push(` Outcome: ${t.outcomeSummary}`);\n if (t.followUpSummary) lines.push(` Follow-up: ${t.followUpSummary}`);\n if (t.entityRefs?.length) lines.push(` Entities: ${t.entityRefs.join(\", \")}`);\n }\n lines.push(\"\");\n }\n\n // Format causal chain connections\n const edgeCount = Object.keys(chainIndex.edges).length;\n if (edgeCount > 0) {\n lines.push(`## Cross-Session Causal Chains (${edgeCount} connections)`);\n lines.push(\"\");\n\n const trajectoryMap = new Map(trajectories.map((t) => [t.trajectoryId, t]));\n const shown = new Set<string>();\n\n for (const [edgeId, edge] of Object.entries(chainIndex.edges)) {\n if (shown.size >= 10) break; // limit output size\n const from = trajectoryMap.get(edge.fromTrajectoryId);\n const to = trajectoryMap.get(edge.toTrajectoryId);\n if (!from || !to) continue;\n\n lines.push(`${edge.edgeType}: \"${from.goal}\" (${from.sessionKey}) → \"${to.goal}\" (${to.sessionKey})`);\n shown.add(edgeId);\n }\n lines.push(\"\");\n }\n\n const result = lines.join(\"\\n\");\n return result.length > maxChars ? result.slice(0, maxChars) + \"\\n[truncated]\" : result;\n}\n\n// ─── LLM Consolidation ──────────────────────────────────────────────────────\n\nconst CONSOLIDATION_PROMPT = `You are analyzing a user's causal trajectory history across multiple sessions. Trajectories record what the user tried to do (goal), what they did (action), and what happened (outcome).\n\nYour job is to identify:\n1. BEHAVIORAL RULES: Recurring patterns where the same approach consistently succeeds or fails. These should be actionable guidance for future sessions.\n2. PREFERENCES: What the user cares about, prefers, or consistently chooses — even if never explicitly stated. Infer preferences from what they repeatedly do, retry until successful, or always include in their workflow.\n\nIMPORTANT:\n- Look for CROSS-SESSION patterns — things that repeat across different sessions are more significant than within-session patterns.\n- A user who retries the same goal across sessions has a strong implicit preference for that outcome.\n- Consistent action choices reveal preferences even when the user never says \"I prefer X.\"\n- Frame preferences as \"The user would prefer responses that...\" when applicable.\n\nOutput valid JSON only:\n{\n \"rules\": [\n {\"content\": \"actionable rule text\", \"category\": \"rule|principle\", \"confidence\": 0.0-1.0, \"evidence\": [\"trajectory IDs\"]}\n ],\n \"preferences\": [\n {\"statement\": \"The user would prefer...\", \"confidence\": 0.0-1.0, \"evidence\": [\"trajectory IDs\"]}\n ]\n}\n\nIf no clear patterns exist, return {\"rules\": [], \"preferences\": []}.`;\n\nasync function consolidateWithLlm(\n context: string,\n llm: ConsolidationLlmClient,\n options: { agentId?: string; modelChain?: AgentPersonaModelConfig } = {},\n): Promise<LlmConsolidationResult> {\n const response = await llm.chatCompletion(\n [\n { role: \"system\", content: CONSOLIDATION_PROMPT },\n { role: \"user\", content: context },\n ],\n { temperature: 0.2, maxTokens: 2000, agentId: options.agentId, modelChain: options.modelChain },\n );\n\n if (!response?.content) {\n return { rules: [], preferences: [] };\n }\n\n try {\n // Extract JSON from response (may have markdown code fences)\n let jsonStr = response.content.trim();\n const fenceMatch = jsonStr.match(/```(?:json)?\\s*\\n?([\\s\\S]*?)\\n?\\s*```/);\n if (fenceMatch) jsonStr = fenceMatch[1];\n\n const parsed = JSON.parse(jsonStr);\n const rawRules: unknown[] = Array.isArray(parsed.rules) ? parsed.rules : [];\n const rawPreferences: unknown[] = Array.isArray(parsed.preferences) ? parsed.preferences : [];\n return {\n rules: rawRules\n .map(parseLlmRule)\n .filter((rule): rule is LlmConsolidationResult[\"rules\"][number] => !!rule),\n preferences: rawPreferences\n .map(parseLlmPreference)\n .filter((pref): pref is LlmConsolidationResult[\"preferences\"][number] => !!pref),\n };\n } catch {\n log.warn(\"[cmc] failed to parse LLM consolidation response\");\n return { rules: [], preferences: [] };\n }\n}\n\n// ─── Candidate Generation ────────────────────────────────────────────────────\n\nfunction stablePatternId(content: string): string {\n const digest = createHash(\"sha256\")\n .update(`causal-pattern\\0${content}`)\n .digest(\"hex\")\n .slice(0, 16);\n return `causal-pattern:${digest}`;\n}\n\nfunction parseConfidence(value: unknown): number | undefined {\n if (typeof value !== \"number\" || !Number.isFinite(value)) return undefined;\n return Math.max(0, Math.min(1, value));\n}\n\nfunction parseEvidence(value: unknown): string[] {\n if (!Array.isArray(value)) return [];\n return value.filter((item): item is string => typeof item === \"string\" && item.trim().length > 0);\n}\n\nfunction parseLlmRule(raw: unknown): LlmConsolidationResult[\"rules\"][number] | undefined {\n if (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n const r = raw as Record<string, unknown>;\n const content = typeof r.content === \"string\" ? r.content.trim() : \"\";\n const category = typeof r.category === \"string\" ? r.category : \"\";\n const confidence = parseConfidence(r.confidence);\n if (content.length <= 5 || !CAUSAL_RULE_CATEGORIES.has(category) || confidence === undefined) {\n return undefined;\n }\n return {\n content,\n category: category as \"rule\" | \"principle\" | \"preference\",\n confidence,\n evidence: parseEvidence(r.evidence),\n };\n}\n\nfunction parseLlmPreference(raw: unknown): LlmConsolidationResult[\"preferences\"][number] | undefined {\n if (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n const p = raw as Record<string, unknown>;\n const statement = typeof p.statement === \"string\" ? p.statement.trim() : \"\";\n const confidence = parseConfidence(p.confidence);\n if (statement.length <= 5 || confidence === undefined) return undefined;\n return {\n statement,\n confidence,\n evidence: parseEvidence(p.evidence),\n };\n}\n\nfunction llmResultToCandidates(result: LlmConsolidationResult): CausalPatternCandidate[] {\n const candidates: CausalPatternCandidate[] = [];\n\n for (const rule of result.rules) {\n const category =\n rule.category === \"principle\" || rule.category === \"preference\"\n ? rule.category\n : \"rule\";\n candidates.push({\n id: stablePatternId(rule.content),\n sourceType: \"causal-pattern\",\n subject: rule.content.slice(0, 80),\n category,\n content: rule.content,\n score: Math.min(1, rule.confidence ?? 0.7),\n rationale: \"LLM-identified causal pattern from cross-session trajectory analysis\",\n outcome: null,\n provenance: (rule.evidence ?? []).slice(0, 5),\n agent: null,\n workflow: null,\n });\n }\n\n for (const preference of result.preferences) {\n candidates.push({\n id: stablePatternId(preference.statement),\n sourceType: \"causal-pattern\",\n subject: preference.statement.slice(0, 80),\n category: \"preference\",\n content: preference.statement,\n score: Math.min(1, preference.confidence ?? 0.7),\n rationale: \"LLM-identified preference from cross-session trajectory analysis\",\n outcome: null,\n provenance: (preference.evidence ?? []).slice(0, 5),\n agent: null,\n workflow: null,\n });\n }\n\n return candidates;\n}\n\nfunction normalizePositiveInteger(value: number, fallback: number): number {\n return Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;\n}\n\nfunction normalizeSuccessThreshold(value: number): number {\n if (!Number.isFinite(value) || value <= 0) return 0;\n return Math.min(1, value);\n}\n\nfunction trajectorySuccessScore(trajectory: CausalTrajectoryRecord): number {\n if (trajectory.outcomeKind === \"success\") return 1;\n if (trajectory.outcomeKind === \"partial\") return 0.5;\n return 0;\n}\n\nfunction averageSuccessScore(trajectories: CausalTrajectoryRecord[]): number {\n if (trajectories.length === 0) return 0;\n const total = trajectories.reduce((sum, trajectory) => sum + trajectorySuccessScore(trajectory), 0);\n return total / trajectories.length;\n}\n\nfunction passesConsolidationGates(\n trajectories: CausalTrajectoryRecord[],\n config: ConsolidationConfig,\n): boolean {\n const minRecurrence = normalizePositiveInteger(config.minRecurrence, 1);\n if (trajectories.length < minRecurrence) return false;\n\n const minSessions = normalizePositiveInteger(config.minSessions, 1);\n const sessionCount = new Set(trajectories.map((trajectory) => trajectory.sessionKey)).size;\n if (sessionCount < minSessions) return false;\n\n const successThreshold = normalizeSuccessThreshold(config.successThreshold);\n if (successThreshold > 0 && averageSuccessScore(trajectories) < successThreshold) {\n return false;\n }\n\n return true;\n}\n\n// ─── Public API ──────────────────────────────────────────────────────────────\n\n/**\n * Run LLM-assisted consolidation: read trajectories, format causal context,\n * ask LLM to identify patterns and preferences.\n */\nexport async function deriveCausalPromotionCandidates(options: {\n memoryDir: string;\n causalTrajectoryStoreDir?: string;\n config: ConsolidationConfig;\n gatewayConfig?: GatewayConfig;\n gatewayAgentId?: string;\n modelChain?: AgentPersonaModelConfig;\n workspaceDir?: string;\n pluginConfig?: PluginConfig;\n llmClient?: ConsolidationLlmClient;\n}): Promise<CausalPatternCandidate[]> {\n try {\n const trajectories = await readAllTrajectories(options.memoryDir, options.causalTrajectoryStoreDir);\n if (!passesConsolidationGates(trajectories, options.config)) return [];\n\n const chainsDir = resolveChainsDir(options.memoryDir, options.causalTrajectoryStoreDir);\n const chainIndex = await readChainIndex(chainsDir);\n\n // Format the causal context for the LLM\n let context = formatCausalContext(trajectories, chainIndex);\n\n // Append memory extensions block if available (#382)\n if (options.pluginConfig) {\n const extBlock = await buildExtensionsBlockForConsolidation(options.pluginConfig);\n if (extBlock.length > 0) {\n context += \"\\n\\n\" + extBlock;\n }\n }\n\n // If no LLM available, fall back to empty (no deterministic fallback)\n const llm = options.llmClient ?? new FallbackLlmClient(\n options.gatewayConfig,\n options.pluginConfig\n ? fallbackLlmRuntimeContextFromConfig(options.pluginConfig, {\n workspaceDir: options.workspaceDir ?? options.pluginConfig.workspaceDir,\n })\n : { workspaceDir: options.workspaceDir },\n );\n const llmOptions = { agentId: options.gatewayAgentId, modelChain: options.modelChain };\n if (!llm.isAvailable(llmOptions)) {\n log.debug(\"[cmc] no LLM available for consolidation — skipping\");\n return [];\n }\n\n // Call LLM for pattern analysis\n const result = await consolidateWithLlm(context, llm, llmOptions);\n const candidates = llmResultToCandidates(result);\n\n log.debug(`[cmc] LLM consolidation produced ${candidates.length} rule(s) and ${result.preferences.length} preference(s)`);\n return candidates;\n } catch (error) {\n log.warn(`[cmc] consolidation failed (non-fatal): ${error instanceof Error ? error.message : String(error)}`);\n return [];\n }\n}\n\n/**\n * Get LLM-synthesized preferences from causal trajectory analysis.\n * Returns formatted preference statements for recall injection.\n */\nexport async function synthesizeCausalPreferencesViaLlm(options: {\n memoryDir: string;\n causalTrajectoryStoreDir?: string;\n gatewayConfig?: GatewayConfig;\n gatewayAgentId?: string;\n modelChain?: AgentPersonaModelConfig;\n workspaceDir?: string;\n minTrajectories?: number;\n}): Promise<string | null> {\n try {\n const trajectories = await readAllTrajectories(options.memoryDir, options.causalTrajectoryStoreDir);\n if (trajectories.length < (options.minTrajectories ?? 2)) return null;\n\n const chainsDir = resolveChainsDir(options.memoryDir, options.causalTrajectoryStoreDir);\n const chainIndex = await readChainIndex(chainsDir);\n const context = formatCausalContext(trajectories, chainIndex);\n\n const llm = new FallbackLlmClient(options.gatewayConfig, {\n workspaceDir: options.workspaceDir,\n });\n const llmOptions = { agentId: options.gatewayAgentId, modelChain: options.modelChain };\n if (!llm.isAvailable(llmOptions)) return null;\n\n const result = await consolidateWithLlm(context, llm, llmOptions);\n if (result.preferences.length === 0 && result.rules.length === 0) return null;\n\n const lines: string[] = [\"## Behavioral Insights (from Causal Chain Analysis)\", \"\"];\n\n for (const pref of result.preferences) {\n lines.push(`- ${pref.statement}`);\n }\n\n for (const rule of result.rules) {\n lines.push(`- ${rule.content}`);\n }\n\n lines.push(\"\");\n return lines.join(\"\\n\");\n } catch (error) {\n log.warn(`[cmc] preference synthesis failed (non-fatal): ${error instanceof Error ? error.message : String(error)}`);\n return null;\n }\n}\n\n/**\n * Optional post-consolidation hook — materializes Codex-native memory artifacts\n * after a causal consolidation run. Guarded by `codexMaterializeMemories` and\n * `codexMaterializeOnConsolidation`. Returns `null` when disabled or when the\n * sentinel is missing (honors user hand-edits).\n *\n * Split from the orchestrator-owned flow so #378 avoids touching\n * orchestrator.ts while Wave 1 edits are in flight.\n */\nexport async function materializeAfterCausalConsolidation(options: {\n config: PluginConfig;\n namespace?: string;\n memories?: MemoryFile[];\n memoryDir?: string;\n codexHome?: string;\n rolloutSummaries?: RolloutSummaryInput[];\n now?: Date;\n}): Promise<MaterializeResult | null> {\n // Delegates to the shared post-consolidation helper — see\n // runPostConsolidationMaterialize in codex-materialize-runner.ts.\n return runPostConsolidationMaterialize(\"[cmc]\", options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,SAAS,kBAAkB;AAO3B,OAAO,UAAU;AA0CjB,IAAM,yBAAyB,oBAAI,IAAI,CAAC,QAAQ,aAAa,YAAY,CAAC;AAY1E,eAAe,oBACb,WACA,0BACmC;AACnC,QAAM,OAAO,gCAAgC,WAAW,wBAAwB;AAChF,QAAM,kBAAkB,KAAK,KAAK,MAAM,cAAc;AAEtD,QAAM,QAAQ,MAAM,cAAc,eAAe,EAAE,MAAM,MAAM,CAAC,CAAa;AAC7E,QAAM,UAAoC,CAAC;AAE3C,aAAW,YAAY,OAAO;AAC5B,QAAI;AACF,YAAM,MAAM,MAAM,aAAa,QAAQ;AACvC,UAAI,SAAS,GAAG,KAAK,OAAO,IAAI,iBAAiB,UAAU;AACzD,gBAAQ,KAAK,GAAwC;AAAA,MACvD;AAAA,IACF,QAAQ;AAAA,IAER;AAAA,EACF;AAEA,SAAO;AACT;AAQA,SAAS,oBACP,cACA,YACA,WAAmB,KACX;AAER,QAAM,YAAY,oBAAI,IAAsC;AAC5D,aAAW,KAAK,cAAc;AAC5B,U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cAAc,QAAQ;AAAA,IACxB,CAAC;AACD,UAAM,aAAa,EAAE,SAAS,QAAQ,gBAAgB,YAAY,QAAQ,WAAW;AACrF,QAAI,CAAC,IAAI,YAAY,UAAU,EAAG,QAAO;AAEzC,UAAM,SAAS,MAAM,mBAAmB,SAAS,KAAK,UAAU;AAChE,QAAI,OAAO,YAAY,WAAW,KAAK,OAAO,MAAM,WAAW,EAAG,QAAO;AAEzE,UAAM,QAAkB,CAAC,uDAAuD,EAAE;AAElF,eAAW,QAAQ,OAAO,aAAa;AACrC,YAAM,KAAK,KAAK,KAAK,SAAS,EAAE;AAAA,IAClC;AAEA,eAAW,QAAQ,OAAO,OAAO;AAC/B,YAAM,KAAK,KAAK,KAAK,OAAO,EAAE;AAAA,IAChC;AAEA,UAAM,KAAK,EAAE;AACb,WAAO,MAAM,KAAK,IAAI;AAAA,EACxB,SAAS,OAAO;AACd,QAAI,KAAK,kDAAkD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AACnH,WAAO;AAAA,EACT;AACF;AAWA,eAAsB,oCAAoC,SAQpB;AAGpC,SAAO,gCAAgC,SAAS,OAAO;AACzD;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/causal-consolidation.ts"],"sourcesContent":["/**\n * causal-consolidation.ts — CMC Phase 2: LLM-Assisted Causal Consolidation\n *\n * Uses an LLM to analyze causal trajectory patterns across sessions.\n * The LLM receives the causal chain graph as context — connected trajectories\n * from different sessions — and identifies recurring behavioral patterns,\n * preference signals, and actionable rules.\n *\n * This is the core CMC innovation: the LLM gets cross-session causal context\n * that no other memory system provides. It can see that a user investigated\n * a bug in session 1, attempted a fix in session 2, and succeeded in session 3 —\n * and synthesize a rule or preference from that chain.\n */\n\nimport { createHash } from \"node:crypto\";\nimport { resolveCausalTrajectoryStoreDir, type CausalTrajectoryRecord } from \"./causal-trajectory.js\";\nimport { readChainIndex, resolveChainsDir, type CausalChainIndex, type CausalEdge } from \"./causal-chain.js\";\nimport { listJsonFiles, readJsonFile } from \"./json-store.js\";\nimport { isRecord } from \"./store-contract.js\";\nimport { FallbackLlmClient, fallbackLlmRuntimeContextFromConfig } from \"./fallback-llm.js\";\nimport type { AgentPersonaModelConfig, GatewayConfig, MemoryFile, PluginConfig } from \"./types.js\";\nimport path from \"node:path\";\nimport { log } from \"./logger.js\";\nimport { runPostConsolidationMaterialize } from \"./connectors/codex-materialize-runner.js\";\nimport type { MaterializeResult, RolloutSummaryInput } from \"./connectors/codex-materialize.js\";\nimport { buildExtensionsBlockForConsolidation } from \"./semantic-consolidation.js\";\n\n// ─── Types ───────────────────────────────────────────────────────────────────\n\nexport interface CausalPatternCandidate {\n id: string;\n sourceType: \"causal-pattern\";\n subject: string;\n category: \"principle\" | \"rule\" | \"preference\";\n content: string;\n score: number;\n rationale: string;\n outcome: null;\n provenance: string[];\n agent: string | null;\n workflow: string | null;\n}\n\nexport interface ConsolidationConfig {\n minRecurrence: number;\n minSessions: number;\n successThreshold: number;\n}\n\nexport interface LlmConsolidationResult {\n rules: Array<{\n content: string;\n category: \"rule\" | \"principle\" | \"preference\";\n confidence: number;\n evidence: string[];\n }>;\n preferences: Array<{\n statement: string;\n confidence: number;\n evidence: string[];\n }>;\n}\n\nconst CAUSAL_RULE_CATEGORIES = new Set([\"rule\", \"principle\", \"preference\"]);\n\ninterface ConsolidationLlmClient {\n isAvailable(options?: { agentId?: string; modelChain?: AgentPersonaModelConfig }): boolean;\n chatCompletion(\n messages: Array<{ role: \"system\" | \"user\" | \"assistant\"; content: string }>,\n options?: { temperature?: number; maxTokens?: number; agentId?: string; modelChain?: AgentPersonaModelConfig },\n ): Promise<{ content: string } | null>;\n}\n\n// ─── Trajectory Reading ──────────────────────────────────────────────────────\n\nasync function readAllTrajectories(\n memoryDir: string,\n causalTrajectoryStoreDir?: string,\n): Promise<CausalTrajectoryRecord[]> {\n const root = resolveCausalTrajectoryStoreDir(memoryDir, causalTrajectoryStoreDir);\n const trajectoriesDir = path.join(root, \"trajectories\");\n\n const files = await listJsonFiles(trajectoriesDir).catch(() => [] as string[]);\n const results: CausalTrajectoryRecord[] = [];\n\n for (const filePath of files) {\n try {\n const raw = await readJsonFile(filePath);\n if (isRecord(raw) && typeof raw.trajectoryId === \"string\") {\n results.push(raw as unknown as CausalTrajectoryRecord);\n }\n } catch {\n // skip invalid\n }\n }\n\n return results;\n}\n\n// ─── Context Formatting ──────────────────────────────────────────────────────\n\n/**\n * Format trajectories and their causal connections as a readable context\n * for the LLM. Groups by session and shows chain connections.\n */\nfunction formatCausalContext(\n trajectories: CausalTrajectoryRecord[],\n chainIndex: CausalChainIndex,\n maxChars: number = 8000,\n): string {\n // Group trajectories by session\n const bySession = new Map<string, CausalTrajectoryRecord[]>();\n for (const t of trajectories) {\n const list = bySession.get(t.sessionKey) ?? [];\n list.push(t);\n bySession.set(t.sessionKey, list);\n }\n\n const lines: string[] = [];\n lines.push(`## Causal Trajectories (${trajectories.length} across ${bySession.size} sessions)`);\n lines.push(\"\");\n\n // Format each session's trajectories\n for (const [sessionKey, sessionTrajs] of bySession) {\n lines.push(`### Session: ${sessionKey}`);\n for (const t of sessionTrajs.slice(0, 5)) {\n const outcome = t.outcomeKind === \"success\" ? \"+\" : t.outcomeKind === \"failure\" ? \"-\" : \"~\";\n lines.push(`[${outcome}] Goal: ${t.goal}`);\n lines.push(` Action: ${t.actionSummary}`);\n lines.push(` Outcome: ${t.outcomeSummary}`);\n if (t.followUpSummary) lines.push(` Follow-up: ${t.followUpSummary}`);\n if (t.entityRefs?.length) lines.push(` Entities: ${t.entityRefs.join(\", \")}`);\n }\n lines.push(\"\");\n }\n\n // Format causal chain connections\n const edgeCount = Object.keys(chainIndex.edges).length;\n if (edgeCount > 0) {\n lines.push(`## Cross-Session Causal Chains (${edgeCount} connections)`);\n lines.push(\"\");\n\n const trajectoryMap = new Map(trajectories.map((t) => [t.trajectoryId, t]));\n const shown = new Set<string>();\n\n for (const [edgeId, edge] of Object.entries(chainIndex.edges)) {\n if (shown.size >= 10) break; // limit output size\n const from = trajectoryMap.get(edge.fromTrajectoryId);\n const to = trajectoryMap.get(edge.toTrajectoryId);\n if (!from || !to) continue;\n\n lines.push(`${edge.edgeType}: \"${from.goal}\" (${from.sessionKey}) → \"${to.goal}\" (${to.sessionKey})`);\n shown.add(edgeId);\n }\n lines.push(\"\");\n }\n\n const result = lines.join(\"\\n\");\n return result.length > maxChars ? result.slice(0, maxChars) + \"\\n[truncated]\" : result;\n}\n\n// ─── LLM Consolidation ──────────────────────────────────────────────────────\n\nconst CONSOLIDATION_PROMPT = `You are analyzing a user's causal trajectory history across multiple sessions. Trajectories record what the user tried to do (goal), what they did (action), and what happened (outcome).\n\nYour job is to identify:\n1. BEHAVIORAL RULES: Recurring patterns where the same approach consistently succeeds or fails. These should be actionable guidance for future sessions.\n2. PREFERENCES: What the user cares about, prefers, or consistently chooses — even if never explicitly stated. Infer preferences from what they repeatedly do, retry until successful, or always include in their workflow.\n\nIMPORTANT:\n- Look for CROSS-SESSION patterns — things that repeat across different sessions are more significant than within-session patterns.\n- A user who retries the same goal across sessions has a strong implicit preference for that outcome.\n- Consistent action choices reveal preferences even when the user never says \"I prefer X.\"\n- Frame preferences as \"The user would prefer responses that...\" when applicable.\n\nOutput valid JSON only:\n{\n \"rules\": [\n {\"content\": \"actionable rule text\", \"category\": \"rule|principle\", \"confidence\": 0.0-1.0, \"evidence\": [\"trajectory IDs\"]}\n ],\n \"preferences\": [\n {\"statement\": \"The user would prefer...\", \"confidence\": 0.0-1.0, \"evidence\": [\"trajectory IDs\"]}\n ]\n}\n\nIf no clear patterns exist, return {\"rules\": [], \"preferences\": []}.`;\n\nasync function consolidateWithLlm(\n context: string,\n llm: ConsolidationLlmClient,\n options: { agentId?: string; modelChain?: AgentPersonaModelConfig } = {},\n): Promise<LlmConsolidationResult> {\n const response = await llm.chatCompletion(\n [\n { role: \"system\", content: CONSOLIDATION_PROMPT },\n { role: \"user\", content: context },\n ],\n { temperature: 0.2, maxTokens: 2000, agentId: options.agentId, modelChain: options.modelChain },\n );\n\n if (!response?.content) {\n return { rules: [], preferences: [] };\n }\n\n try {\n // Extract JSON from response (may have markdown code fences)\n let jsonStr = response.content.trim();\n const fenceMatch = jsonStr.match(/```(?:json)?\\s*\\n?([\\s\\S]*?)\\n?\\s*```/);\n if (fenceMatch) jsonStr = fenceMatch[1];\n\n const parsed = JSON.parse(jsonStr);\n const rawRules: unknown[] = Array.isArray(parsed.rules) ? parsed.rules : [];\n const rawPreferences: unknown[] = Array.isArray(parsed.preferences) ? parsed.preferences : [];\n return {\n rules: rawRules\n .map(parseLlmRule)\n .filter((rule): rule is LlmConsolidationResult[\"rules\"][number] => !!rule),\n preferences: rawPreferences\n .map(parseLlmPreference)\n .filter((pref): pref is LlmConsolidationResult[\"preferences\"][number] => !!pref),\n };\n } catch {\n log.warn(\"[cmc] failed to parse LLM consolidation response\");\n return { rules: [], preferences: [] };\n }\n}\n\n// ─── Candidate Generation ────────────────────────────────────────────────────\n\nfunction stablePatternId(content: string): string {\n const digest = createHash(\"sha256\")\n .update(`causal-pattern\\0${content}`)\n .digest(\"hex\")\n .slice(0, 16);\n return `causal-pattern:${digest}`;\n}\n\nfunction parseConfidence(value: unknown): number | undefined {\n if (typeof value !== \"number\" || !Number.isFinite(value)) return undefined;\n return Math.max(0, Math.min(1, value));\n}\n\nfunction parseEvidence(value: unknown): string[] {\n if (!Array.isArray(value)) return [];\n return value.filter((item): item is string => typeof item === \"string\" && item.trim().length > 0);\n}\n\nfunction parseLlmRule(raw: unknown): LlmConsolidationResult[\"rules\"][number] | undefined {\n if (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n const r = raw as Record<string, unknown>;\n const content = typeof r.content === \"string\" ? r.content.trim() : \"\";\n const category = typeof r.category === \"string\" ? r.category : \"\";\n const confidence = parseConfidence(r.confidence);\n if (content.length <= 5 || !CAUSAL_RULE_CATEGORIES.has(category) || confidence === undefined) {\n return undefined;\n }\n return {\n content,\n category: category as \"rule\" | \"principle\" | \"preference\",\n confidence,\n evidence: parseEvidence(r.evidence),\n };\n}\n\nfunction parseLlmPreference(raw: unknown): LlmConsolidationResult[\"preferences\"][number] | undefined {\n if (!raw || typeof raw !== \"object\" || Array.isArray(raw)) return undefined;\n const p = raw as Record<string, unknown>;\n const statement = typeof p.statement === \"string\" ? p.statement.trim() : \"\";\n const confidence = parseConfidence(p.confidence);\n if (statement.length <= 5 || confidence === undefined) return undefined;\n return {\n statement,\n confidence,\n evidence: parseEvidence(p.evidence),\n };\n}\n\nfunction llmResultToCandidates(result: LlmConsolidationResult): CausalPatternCandidate[] {\n const candidates: CausalPatternCandidate[] = [];\n\n for (const rule of result.rules) {\n const category =\n rule.category === \"principle\" || rule.category === \"preference\"\n ? rule.category\n : \"rule\";\n candidates.push({\n id: stablePatternId(rule.content),\n sourceType: \"causal-pattern\",\n subject: rule.content.slice(0, 80),\n category,\n content: rule.content,\n score: Math.min(1, rule.confidence ?? 0.7),\n rationale: \"LLM-identified causal pattern from cross-session trajectory analysis\",\n outcome: null,\n provenance: (rule.evidence ?? []).slice(0, 5),\n agent: null,\n workflow: null,\n });\n }\n\n for (const preference of result.preferences) {\n candidates.push({\n id: stablePatternId(preference.statement),\n sourceType: \"causal-pattern\",\n subject: preference.statement.slice(0, 80),\n category: \"preference\",\n content: preference.statement,\n score: Math.min(1, preference.confidence ?? 0.7),\n rationale: \"LLM-identified preference from cross-session trajectory analysis\",\n outcome: null,\n provenance: (preference.evidence ?? []).slice(0, 5),\n agent: null,\n workflow: null,\n });\n }\n\n return candidates;\n}\n\nfunction normalizePositiveInteger(value: number, fallback: number): number {\n return Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;\n}\n\nfunction normalizeSuccessThreshold(value: number): number {\n if (!Number.isFinite(value) || value <= 0) return 0;\n return Math.min(1, value);\n}\n\nfunction trajectorySuccessScore(trajectory: CausalTrajectoryRecord): number {\n if (trajectory.outcomeKind === \"success\") return 1;\n if (trajectory.outcomeKind === \"partial\") return 0.5;\n return 0;\n}\n\nfunction averageSuccessScore(trajectories: CausalTrajectoryRecord[]): number {\n if (trajectories.length === 0) return 0;\n const total = trajectories.reduce((sum, trajectory) => sum + trajectorySuccessScore(trajectory), 0);\n return total / trajectories.length;\n}\n\nfunction passesConsolidationGates(\n trajectories: CausalTrajectoryRecord[],\n config: ConsolidationConfig,\n): boolean {\n const minRecurrence = normalizePositiveInteger(config.minRecurrence, 1);\n if (trajectories.length < minRecurrence) return false;\n\n const minSessions = normalizePositiveInteger(config.minSessions, 1);\n const sessionCount = new Set(trajectories.map((trajectory) => trajectory.sessionKey)).size;\n if (sessionCount < minSessions) return false;\n\n const successThreshold = normalizeSuccessThreshold(config.successThreshold);\n if (successThreshold > 0 && averageSuccessScore(trajectories) < successThreshold) {\n return false;\n }\n\n return true;\n}\n\n// ─── Public API ──────────────────────────────────────────────────────────────\n\n/**\n * Run LLM-assisted consolidation: read trajectories, format causal context,\n * ask LLM to identify patterns and preferences.\n */\nexport async function deriveCausalPromotionCandidates(options: {\n memoryDir: string;\n causalTrajectoryStoreDir?: string;\n config: ConsolidationConfig;\n gatewayConfig?: GatewayConfig;\n gatewayAgentId?: string;\n modelChain?: AgentPersonaModelConfig;\n workspaceDir?: string;\n pluginConfig?: PluginConfig;\n llmClient?: ConsolidationLlmClient;\n}): Promise<CausalPatternCandidate[]> {\n try {\n const trajectories = await readAllTrajectories(options.memoryDir, options.causalTrajectoryStoreDir);\n if (!passesConsolidationGates(trajectories, options.config)) return [];\n\n const chainsDir = resolveChainsDir(options.memoryDir, options.causalTrajectoryStoreDir);\n const chainIndex = await readChainIndex(chainsDir);\n\n // Format the causal context for the LLM\n let context = formatCausalContext(trajectories, chainIndex);\n\n // Append memory extensions block if available (#382)\n if (options.pluginConfig) {\n const extBlock = await buildExtensionsBlockForConsolidation(options.pluginConfig);\n if (extBlock.length > 0) {\n context += \"\\n\\n\" + extBlock;\n }\n }\n\n // If no LLM available, fall back to empty (no deterministic fallback)\n const llm = options.llmClient ?? new FallbackLlmClient(\n options.gatewayConfig,\n options.pluginConfig\n ? fallbackLlmRuntimeContextFromConfig(options.pluginConfig, {\n workspaceDir: options.workspaceDir ?? options.pluginConfig.workspaceDir,\n })\n : { workspaceDir: options.workspaceDir },\n );\n const llmOptions = { agentId: options.gatewayAgentId, modelChain: options.modelChain };\n if (!llm.isAvailable(llmOptions)) {\n log.debug(\"[cmc] no LLM available for consolidation — skipping\");\n return [];\n }\n\n // Call LLM for pattern analysis\n const result = await consolidateWithLlm(context, llm, llmOptions);\n const candidates = llmResultToCandidates(result);\n\n log.debug(`[cmc] LLM consolidation produced ${candidates.length} rule(s) and ${result.preferences.length} preference(s)`);\n return candidates;\n } catch (error) {\n log.warn(`[cmc] consolidation failed (non-fatal): ${error instanceof Error ? error.message : String(error)}`);\n return [];\n }\n}\n\n/**\n * Get LLM-synthesized preferences from causal trajectory analysis.\n * Returns formatted preference statements for recall injection.\n */\nexport async function synthesizeCausalPreferencesViaLlm(options: {\n memoryDir: string;\n causalTrajectoryStoreDir?: string;\n gatewayConfig?: GatewayConfig;\n gatewayAgentId?: string;\n modelChain?: AgentPersonaModelConfig;\n workspaceDir?: string;\n minTrajectories?: number;\n}): Promise<string | null> {\n try {\n const trajectories = await readAllTrajectories(options.memoryDir, options.causalTrajectoryStoreDir);\n if (trajectories.length < (options.minTrajectories ?? 2)) return null;\n\n const chainsDir = resolveChainsDir(options.memoryDir, options.causalTrajectoryStoreDir);\n const chainIndex = await readChainIndex(chainsDir);\n const context = formatCausalContext(trajectories, chainIndex);\n\n const llm = new FallbackLlmClient(options.gatewayConfig, {\n workspaceDir: options.workspaceDir,\n });\n const llmOptions = { agentId: options.gatewayAgentId, modelChain: options.modelChain };\n if (!llm.isAvailable(llmOptions)) return null;\n\n const result = await consolidateWithLlm(context, llm, llmOptions);\n if (result.preferences.length === 0 && result.rules.length === 0) return null;\n\n const lines: string[] = [\"## Behavioral Insights (from Causal Chain Analysis)\", \"\"];\n\n for (const pref of result.preferences) {\n lines.push(`- ${pref.statement}`);\n }\n\n for (const rule of result.rules) {\n lines.push(`- ${rule.content}`);\n }\n\n lines.push(\"\");\n return lines.join(\"\\n\");\n } catch (error) {\n log.warn(`[cmc] preference synthesis failed (non-fatal): ${error instanceof Error ? error.message : String(error)}`);\n return null;\n }\n}\n\n/**\n * Optional post-consolidation hook — materializes Codex-native memory artifacts\n * after a causal consolidation run. Guarded by `codexMaterializeMemories` and\n * `codexMaterializeOnConsolidation`. Returns `null` when disabled or when the\n * sentinel is missing (honors user hand-edits).\n *\n * Split from the orchestrator-owned flow so #378 avoids touching\n * orchestrator.ts while Wave 1 edits are in flight.\n */\nexport async function materializeAfterCausalConsolidation(options: {\n config: PluginConfig;\n namespace?: string;\n memories?: MemoryFile[];\n memoryDir?: string;\n codexHome?: string;\n rolloutSummaries?: RolloutSummaryInput[];\n now?: Date;\n}): Promise<MaterializeResult | null> {\n // Delegates to the shared post-consolidation helper — see\n // runPostConsolidationMaterialize in codex-materialize-runner.ts.\n return runPostConsolidationMaterialize(\"[cmc]\", options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,SAAS,kBAAkB;AAO3B,OAAO,UAAU;AA0CjB,IAAM,yBAAyB,oBAAI,IAAI,CAAC,QAAQ,aAAa,YAAY,CAAC;AAY1E,eAAe,oBACb,WACA,0BACmC;AACnC,QAAM,OAAO,gCAAgC,WAAW,wBAAwB;AAChF,QAAM,kBAAkB,KAAK,KAAK,MAAM,cAAc;AAEtD,QAAM,QAAQ,MAAM,cAAc,eAAe,EAAE,MAAM,MAAM,CAAC,CAAa;AAC7E,QAAM,UAAoC,CAAC;AAE3C,aAAW,YAAY,OAAO;AAC5B,QAAI;AACF,YAAM,MAAM,MAAM,aAAa,QAAQ;AACvC,UAAI,SAAS,GAAG,KAAK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AAa,UAAU,QAAQ,mBAAmB,GAAI,QAAO;AAEjE,UAAM,YAAY,iBAAiB,QAAQ,WAAW,QAAQ,wBAAwB;AACtF,UAAM,aAAa,MAAM,eAAe,SAAS;AACjD,UAAM,UAAU,oBAAoB,cAAc,UAAU;AAE5D,UAAM,MAAM,IAAI,kBAAkB,QAAQ,eAAe;AAAA,MACvD,cAAc,QAAQ;AAAA,IACxB,CAAC;AACD,UAAM,aAAa,EAAE,SAAS,QAAQ,gBAAgB,YAAY,QAAQ,WAAW;AACrF,QAAI,CAAC,IAAI,YAAY,UAAU,EAAG,QAAO;AAEzC,UAAM,SAAS,MAAM,mBAAmB,SAAS,KAAK,UAAU;AAChE,QAAI,OAAO,YAAY,WAAW,KAAK,OAAO,MAAM,WAAW,EAAG,QAAO;AAEzE,UAAM,QAAkB,CAAC,uDAAuD,EAAE;AAElF,eAAW,QAAQ,OAAO,aAAa;AACrC,YAAM,KAAK,KAAK,KAAK,SAAS,EAAE;AAAA,IAClC;AAEA,eAAW,QAAQ,OAAO,OAAO;AAC/B,YAAM,KAAK,KAAK,KAAK,OAAO,EAAE;AAAA,IAChC;AAEA,UAAM,KAAK,EAAE;AACb,WAAO,MAAM,KAAK,IAAI;AAAA,EACxB,SAAS,OAAO;AACd,QAAI,KAAK,kDAAkD,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC,EAAE;AACnH,WAAO;AAAA,EACT;AACF;AAWA,eAAsB,oCAAoC,SAQpB;AAGpC,SAAO,gCAAgC,SAAS,OAAO;AACzD;","names":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as GraphEdge } from './graph-444E-DrF.js';
|
|
2
2
|
import { CausalTrajectoryRecord } from './causal-trajectory.js';
|
|
3
3
|
import './capabilities.js';
|
|
4
|
-
import './types-
|
|
4
|
+
import './types-Pi0lfaEt.js';
|
|
5
5
|
import './message-parts/index.js';
|
|
6
6
|
import './bounded-jsonl-state.js';
|
|
7
7
|
import './types-CM86alG1.js';
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-B7RWBZXW.js";
|
|
4
4
|
import {
|
|
5
5
|
StorageManager
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-J275IYMG.js";
|
|
7
7
|
import {
|
|
8
8
|
getCachedEpisodeMap,
|
|
9
9
|
setCachedEpisodeMap
|
|
@@ -109,4 +109,4 @@ export {
|
|
|
109
109
|
compareVerifiedEpisodeResults,
|
|
110
110
|
searchVerifiedEpisodes
|
|
111
111
|
};
|
|
112
|
-
//# sourceMappingURL=chunk-
|
|
112
|
+
//# sourceMappingURL=chunk-2E36UXVW.js.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NamespaceStorageRouter
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LZH5FR2W.js";
|
|
4
4
|
import {
|
|
5
5
|
namespaceCollectionName
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-YHCBJULX.js";
|
|
7
7
|
import {
|
|
8
8
|
isSafeRouteNamespace
|
|
9
9
|
} from "./chunk-PCXDUHQH.js";
|
|
@@ -213,4 +213,4 @@ export {
|
|
|
213
213
|
verifyNamespaces,
|
|
214
214
|
runNamespaceMigration
|
|
215
215
|
};
|
|
216
|
-
//# sourceMappingURL=chunk-
|
|
216
|
+
//# sourceMappingURL=chunk-2XDWWPTN.js.map
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
} from "./chunk-VI637ILW.js";
|
|
5
5
|
import {
|
|
6
6
|
composeSalvagedEnvelope
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-JCWY73FK.js";
|
|
8
8
|
import {
|
|
9
9
|
StorageManager
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-J275IYMG.js";
|
|
11
11
|
import {
|
|
12
12
|
parseContinuityImprovementLoops
|
|
13
13
|
} from "./chunk-LDXUBPMO.js";
|
|
@@ -1283,4 +1283,4 @@ export {
|
|
|
1283
1283
|
defaultTierMigrationCycleBudget,
|
|
1284
1284
|
CompoundingEngine
|
|
1285
1285
|
};
|
|
1286
|
-
//# sourceMappingURL=chunk-
|
|
1286
|
+
//# sourceMappingURL=chunk-2YI72KM3.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OUTPUT_LANGUAGE_POLICY
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7CBKAQIG.js";
|
|
4
4
|
import {
|
|
5
5
|
normalizeProcedureSteps
|
|
6
6
|
} from "./chunk-QDW3E4RD.js";
|
|
@@ -491,4 +491,4 @@ export {
|
|
|
491
491
|
createVerdictCache,
|
|
492
492
|
createDeferCountMap
|
|
493
493
|
};
|
|
494
|
-
//# sourceMappingURL=chunk-
|
|
494
|
+
//# sourceMappingURL=chunk-3DVBKTSO.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isRecallDisclosure
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-SBDCZ2AX.js";
|
|
4
4
|
import {
|
|
5
5
|
estimateTokenCount
|
|
6
6
|
} from "./chunk-TOTT6S2V.js";
|
|
@@ -304,4 +304,4 @@ export {
|
|
|
304
304
|
RecallXrayBuilder,
|
|
305
305
|
summarizeDisclosureTokens
|
|
306
306
|
};
|
|
307
|
-
//# sourceMappingURL=chunk-
|
|
307
|
+
//# sourceMappingURL=chunk-3I7ASZN3.js.map
|
|
@@ -16,7 +16,7 @@ function runSerialized(key, task) {
|
|
|
16
16
|
});
|
|
17
17
|
return next;
|
|
18
18
|
}
|
|
19
|
-
var MEMORY_WORTH_OUTCOME_ELIGIBLE_CATEGORIES = /* @__PURE__ */ new Set(["fact"]);
|
|
19
|
+
var MEMORY_WORTH_OUTCOME_ELIGIBLE_CATEGORIES = /* @__PURE__ */ new Set(["fact", "procedure"]);
|
|
20
20
|
function memoryWorthOutcomeEligibleCategories() {
|
|
21
21
|
return new Set(MEMORY_WORTH_OUTCOME_ELIGIBLE_CATEGORIES);
|
|
22
22
|
}
|
|
@@ -87,4 +87,4 @@ export {
|
|
|
87
87
|
memoryWorthOutcomeEligibleCategories,
|
|
88
88
|
recordMemoryOutcome
|
|
89
89
|
};
|
|
90
|
-
//# sourceMappingURL=chunk-
|
|
90
|
+
//# sourceMappingURL=chunk-4K7IW3F7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/memory-worth-outcomes.ts"],"sourcesContent":["/**\n * Issue #560 PR 3 — Memory Worth outcome signal pipeline.\n *\n * PR 1 added `mw_success` / `mw_fail` fields to MemoryFrontmatter. PR 2 added\n * a pure scoring helper. This module adds the one piece tying the two\n * together: a way for callers to record a single outcome observation against\n * a memory, which increments the appropriate counter in frontmatter.\n *\n * The public entry point is `recordMemoryOutcome({ memoryPath, outcome, ... })`.\n * Callers pass the full path to the memory file (not just the ID) because in\n * the usual outcome source — the observation ledger — the memory path is\n * already captured in the event payload, and path-based lookup avoids a\n * full-corpus scan.\n *\n * Intentional properties:\n * - Works on a per-memory basis (no bulk API in this slice). Bulk update is\n * an easy layer on top of this once a second caller needs it.\n * - Reuses the existing `updateMemoryFrontmatter(id, patch)` write path so\n * unrelated fields (confidence, importance, lifecycle hooks, etc.) are\n * preserved. The PR 1 serializer rejects negative / non-integer counters,\n * so we rely on that for defensive validation rather than duplicating it.\n * - Only instruments categories in `MEMORY_WORTH_OUTCOME_ELIGIBLE_CATEGORIES`\n * (currently `fact` and `procedure` — procedures joined in issue #2370 —\n * matching `MEMORY_WORTH_ELIGIBLE_CATEGORIES` in operator-toolkit.ts for\n * the doctor audit). Non-eligible memories return\n * `{ ok: false, reason: \"ineligible_category\" }` rather than throwing so\n * the caller — typically a ledger consumer draining heterogeneous events\n * — doesn't need to pre-filter by category.\n * - Missing / unknown memory IDs return `{ ok: false, reason: \"not_found\" }`\n * rather than throwing, because outcome events may reference memories\n * that were archived/deleted between the session and the ledger drain.\n * That isn't an operator-actionable error.\n * - On success, returns the new counter values so observability surfaces\n * can report the increment without a second read.\n *\n * Out of scope (later PRs):\n * - Recall filter reading the counters (PR 4).\n * - Benchmark + default flip (PR 5).\n * - Automatic increments from extraction or summarization. Only the\n * explicit `MEM_OUTCOME` ledger tag or an MCP tool call drives writes.\n */\n\nimport path from \"node:path\";\n\nimport type { StorageManager } from \"./storage.js\";\nimport type { MemoryFrontmatter } from \"./types.js\";\n\n/**\n * Per-memory-ID serialization of the read-modify-write increment.\n *\n * Codex P1: without this, concurrent calls for the same memory race. Both\n * callers read the same `mw_*` values, each writes +1, and one increment\n * is lost — silently undercounting outcomes. We chain an async promise\n * per memory ID so read-then-write is atomic with respect to other calls\n * into this module.\n *\n * This serializes only THIS module. Direct writers (e.g. hand-rolled\n * frontmatter patches) still bypass the lock, but the documented surface\n * for Memory Worth increments is this function, and the bench only uses\n * this path.\n *\n * The lock map is WeakRef-free by design: the chain self-cleans once the\n * last pending write resolves (we delete the entry inside the `.finally`\n * of the tail), so memory use stays bounded even for long-running\n * processes that touch many different memory IDs.\n */\nconst outcomeLocks = new Map<string, Promise<unknown>>();\n\nfunction runSerialized<T>(key: string, task: () => Promise<T>): Promise<T> {\n const prev = outcomeLocks.get(key) ?? Promise.resolve();\n // Swallow upstream errors so a failed outcome for memory A doesn't\n // permanently poison the chain for memory A. We still propagate our own\n // result/errors to the caller.\n const next = prev.catch(() => undefined).then(task);\n outcomeLocks.set(key, next);\n // Chain the cleanup off `next` BUT attach a `.catch` so the cleanup\n // promise itself never surfaces as an unhandled rejection. The caller\n // gets `next` back and handles it their own way; this detached cleanup\n // chain has no observer, so without the .catch Node would crash the\n // process on a task rejection even when the caller awaited `next` and\n // handled the error correctly.\n next\n .then(\n () => {\n if (outcomeLocks.get(key) === next) outcomeLocks.delete(key);\n },\n () => {\n if (outcomeLocks.get(key) === next) outcomeLocks.delete(key);\n },\n )\n .catch(() => {\n // Defensive no-op in case a hook inside the cleanup branches throws.\n });\n return next;\n}\n\n/**\n * Categories currently instrumented for Memory Worth counters. `procedure`\n * joined in issue #2370 — the procedure library-health maintenance loop\n * retires on failure-dominant `mw_*` counters, so injected procedures must\n * be able to accrue outcomes. Must be kept in sync with\n * `MEMORY_WORTH_ELIGIBLE_CATEGORIES` in `operator-toolkit.ts`. Declared\n * here (not imported) to avoid a circular dep with operator-toolkit, which\n * imports from this file's peers. The two constants are validated by a\n * test to stay in lockstep.\n */\nconst MEMORY_WORTH_OUTCOME_ELIGIBLE_CATEGORIES: ReadonlySet<MemoryFrontmatter[\"category\"]> =\n new Set([\"fact\", \"procedure\"]);\n\n/**\n * Exported so downstream tests / operators can query the allowlist without\n * re-declaring it. Returned as a frozen copy so consumers cannot mutate the\n * module-internal set.\n */\nexport function memoryWorthOutcomeEligibleCategories(): ReadonlySet<MemoryFrontmatter[\"category\"]> {\n return new Set(MEMORY_WORTH_OUTCOME_ELIGIBLE_CATEGORIES);\n}\n\n/**\n * The direction of an outcome — whether the session that consumed this\n * memory succeeded or failed. Restricted to a string literal union so\n * callers in TypeScript land can't pass arbitrary tags.\n */\nexport type MemoryOutcomeKind = \"success\" | \"failure\";\n\n/**\n * Arguments to `recordMemoryOutcome`.\n *\n * `memoryPath` is the filesystem path to the memory; we derive the ID from\n * the basename, matching how the operator-toolkit and recall layers map\n * paths to IDs.\n */\nexport interface RecordMemoryOutcomeInput {\n /**\n * Absolute or repo-relative path to the memory file. Typically the value\n * of `MemoryFile.path` for a memory returned by `readAllMemories`.\n */\n memoryPath: string;\n /** Outcome direction — \"success\" bumps mw_success; \"failure\" bumps mw_fail. */\n outcome: MemoryOutcomeKind;\n /**\n * Optional observation timestamp for audit / telemetry. This PR doesn't\n * persist the timestamp (PR 4/5 will use `lastAccessed`, which already\n * covers the recency-decay requirement), but accepting it here keeps the\n * call shape stable so future ledger integrations don't need a breaking\n * change.\n */\n timestamp?: Date | string;\n}\n\n/**\n * Outcome of a `recordMemoryOutcome` call.\n *\n * `ok: true` means the counter was incremented and flushed. The returned\n * values reflect the post-increment state, so callers can log\n * `\"fact-xyz: 4/1 → 5/1\"` without re-reading.\n *\n * `ok: false` carries a short machine-readable `reason` so a ledger drainer\n * can aggregate metrics (\"how many events hit not_found this hour?\"). The\n * human-readable `message` is a friendlier version for logs.\n */\nexport type RecordMemoryOutcomeResult =\n | {\n ok: true;\n memoryId: string;\n /** New value of `mw_success` after the increment. */\n mw_success: number;\n /** New value of `mw_fail` after the increment. */\n mw_fail: number;\n }\n | {\n ok: false;\n reason:\n | \"not_found\"\n | \"ineligible_category\"\n | \"invalid_outcome\"\n | \"invalid_path\";\n message: string;\n };\n\n/**\n * Extract the memory ID from a file path. Memory files are stored as\n * `<id>.md`, matching the rest of the system (see `getMemoryById`, which\n * infers paths from IDs).\n *\n * Returns `null` for any path that does not end in `.md`. The check is\n * unconditional — `path.basename` strips directory components before the\n * suffix check, so previous conditional logic silently accepted\n * directory-prefixed paths like `/tmp/facts/2026-01-01/not-a-memory`\n * (the basename `not-a-memory` is not equal to the input, so the `.md`\n * guard was skipped). The new check looks at the raw input once.\n */\nfunction memoryIdFromPath(memoryPath: string): string | null {\n if (!memoryPath || typeof memoryPath !== \"string\") return null;\n if (!memoryPath.endsWith(\".md\")) return null;\n const basename = path.basename(memoryPath, \".md\");\n if (!basename) return null;\n return basename;\n}\n\n/**\n * Record a single outcome observation against a memory. Increments\n * `mw_success` or `mw_fail` on the memory's frontmatter (preserving all\n * other fields) via the existing `updateMemoryFrontmatter` write path.\n *\n * See the top-of-file doc comment for policy details (eligible categories,\n * error semantics, and what is intentionally out of scope).\n */\nexport async function recordMemoryOutcome(\n storage: StorageManager,\n input: RecordMemoryOutcomeInput,\n): Promise<RecordMemoryOutcomeResult> {\n if (input.outcome !== \"success\" && input.outcome !== \"failure\") {\n return {\n ok: false,\n reason: \"invalid_outcome\",\n message: `outcome must be \"success\" or \"failure\"; got ${JSON.stringify(input.outcome)}`,\n };\n }\n\n const memoryId = memoryIdFromPath(input.memoryPath);\n if (memoryId === null) {\n return {\n ok: false,\n reason: \"invalid_path\",\n message: `memoryPath must end in .md; got ${JSON.stringify(input.memoryPath)}`,\n };\n }\n\n // Serialize the read-modify-write per memory ID so concurrent callers\n // (parallel ledger drain, multiple MCP clients, etc.) can't each read\n // the same snapshot and race to write `+1`, losing an increment.\n return runSerialized(memoryId, async () => {\n const memory = await storage.getMemoryById(memoryId);\n if (!memory) {\n return {\n ok: false,\n reason: \"not_found\",\n message: `no memory with id ${memoryId}`,\n };\n }\n\n if (!MEMORY_WORTH_OUTCOME_ELIGIBLE_CATEGORIES.has(memory.frontmatter.category)) {\n return {\n ok: false,\n reason: \"ineligible_category\",\n message: `category ${memory.frontmatter.category} is not instrumented for Memory Worth`,\n };\n }\n\n // Absent counters are treated as 0 (matching the PR 1 semantics — legacy\n // memories implicitly have Beta(1,1) priors). Increments land on the\n // actual counter regardless of whether the field was previously set.\n const currentSuccess = memory.frontmatter.mw_success ?? 0;\n const currentFail = memory.frontmatter.mw_fail ?? 0;\n\n const nextSuccess = input.outcome === \"success\" ? currentSuccess + 1 : currentSuccess;\n const nextFail = input.outcome === \"failure\" ? currentFail + 1 : currentFail;\n\n // `updateMemoryFrontmatter` goes through `writeMemoryFrontmatter`, which\n // routes through the PR 1 serializer — so a stored corrupt value (e.g., a\n // pre-existing float) would be rejected here. That is intentional: we\n // refuse to layer a fresh increment on top of garbage. Operators should\n // use `remnic doctor` to find and fix those rows before PR 4 ships.\n //\n // `updateMemoryFrontmatter` returns `false` when the memory is no\n // longer present (archived / deleted between `getMemoryById` and the\n // write). Surface that as `not_found` so callers see an honest result\n // — silently returning `ok: true` with a counter that never landed\n // would skew downstream worth scoring.\n const updated = await storage.updateMemoryFrontmatter(memoryId, {\n mw_success: nextSuccess,\n mw_fail: nextFail,\n });\n if (!updated) {\n return {\n ok: false,\n reason: \"not_found\",\n message: `memory ${memoryId} disappeared between read and write`,\n };\n }\n\n return {\n ok: true,\n memoryId,\n mw_success: nextSuccess,\n mw_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