@remnic/core 1.1.2 → 1.1.4
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/abort-error.js +1 -0
- package/dist/abstraction-nodes.js +1 -0
- package/dist/access-audit.js +1 -0
- package/dist/access-cli.js +72 -47
- package/dist/access-cli.js.map +1 -1
- package/dist/access-http.d.ts +50 -5
- package/dist/access-http.js +39 -16
- package/dist/access-idempotency.js +1 -0
- package/dist/access-mcp.d.ts +10 -5
- package/dist/access-mcp.js +38 -14
- package/dist/access-schema.d.ts +133 -13
- package/dist/access-schema.js +20 -1
- package/dist/access-service-CtXFnprR.d.ts +2033 -0
- package/dist/access-service.d.ts +11 -6
- package/dist/access-service.js +40 -15
- package/dist/active-memory-bridge.js +1 -0
- package/dist/active-recall.js +1 -0
- package/dist/active-recall.js.map +1 -1
- package/dist/behavior-learner.js +1 -0
- package/dist/behavior-learner.js.map +1 -1
- package/dist/behavior-signals.js +1 -0
- package/dist/bootstrap.d.ts +6 -4
- package/dist/bootstrap.js +1 -0
- package/dist/boxes.js +1 -0
- package/dist/briefing.d.ts +9 -5
- package/dist/briefing.js +10 -7
- package/dist/buffer-surprise-report.js +1 -0
- package/dist/buffer-surprise.js +1 -0
- package/dist/buffer.d.ts +1 -1
- package/dist/buffer.js +1 -0
- package/dist/calibration.d.ts +8 -1
- package/dist/calibration.js +10 -2
- package/dist/calibration.js.map +1 -1
- package/dist/capsule-cli.d.ts +137 -0
- package/dist/capsule-cli.js +34 -0
- package/dist/capsule-crypto-5CYAGVC5.js +18 -0
- package/dist/capsule-export-NZQPOTQ4.js +17 -0
- package/dist/capsule-export-NZQPOTQ4.js.map +1 -0
- package/dist/capsule-import-SDCUXLEV.js +16 -0
- package/dist/capsule-import-SDCUXLEV.js.map +1 -0
- package/dist/capsule-merge-DI7PNQ2H.js +189 -0
- package/dist/capsule-merge-DI7PNQ2H.js.map +1 -0
- package/dist/causal-behavior.js +1 -0
- package/dist/causal-behavior.js.map +1 -1
- package/dist/causal-chain.js +1 -0
- package/dist/causal-consolidation.js +12 -9
- package/dist/causal-consolidation.js.map +1 -1
- package/dist/causal-retrieval.js +2 -1
- package/dist/causal-retrieval.js.map +1 -1
- package/dist/causal-trajectory-graph.js +4 -1
- package/dist/causal-trajectory-graph.js.map +1 -1
- package/dist/causal-trajectory.js +2 -1
- package/dist/chunk-2LSZVONP.js +67 -0
- package/dist/chunk-2LSZVONP.js.map +1 -0
- package/dist/chunk-32KD5IHZ.js +245 -0
- package/dist/chunk-32KD5IHZ.js.map +1 -0
- package/dist/chunk-3KIS4VGT.js +228 -0
- package/dist/chunk-3KIS4VGT.js.map +1 -0
- package/dist/chunk-3LCWFNVS.js +350 -0
- package/dist/chunk-3LCWFNVS.js.map +1 -0
- package/dist/chunk-43EKP2UK.js +26 -0
- package/dist/chunk-43EKP2UK.js.map +1 -0
- package/dist/chunk-457A4P3L.js +119 -0
- package/dist/chunk-457A4P3L.js.map +1 -0
- package/dist/{chunk-TMYO7B5P.js → chunk-47WOM4YW.js} +2 -2
- package/dist/{chunk-FVA6TGI3.js → chunk-52PDY6GD.js} +42 -2
- package/dist/chunk-52PDY6GD.js.map +1 -0
- package/dist/{chunk-ULYOGL6R.js → chunk-5HRY2WRF.js} +7 -3
- package/dist/chunk-5HRY2WRF.js.map +1 -0
- package/dist/{chunk-BOUYNNYD.js → chunk-67YLUWLG.js} +32 -13
- package/dist/{chunk-BOUYNNYD.js.map → chunk-67YLUWLG.js.map} +1 -1
- package/dist/chunk-6TBWYBJ3.js +236 -0
- package/dist/chunk-6TBWYBJ3.js.map +1 -0
- package/dist/chunk-74EMIVE4.js +329 -0
- package/dist/chunk-74EMIVE4.js.map +1 -0
- package/dist/chunk-74WWN7ZW.js +82 -0
- package/dist/chunk-74WWN7ZW.js.map +1 -0
- package/dist/chunk-A6XUJE5D.js +126 -0
- package/dist/chunk-A6XUJE5D.js.map +1 -0
- package/dist/{chunk-STGWEHYR.js → chunk-AEMBDV7M.js} +1187 -62
- package/dist/chunk-AEMBDV7M.js.map +1 -0
- package/dist/{chunk-PVICZTKG.js → chunk-AGZHRWPT.js} +5 -5
- package/dist/{chunk-PVICZTKG.js.map → chunk-AGZHRWPT.js.map} +1 -1
- package/dist/chunk-AJA46VX5.js +393 -0
- package/dist/chunk-AJA46VX5.js.map +1 -0
- package/dist/chunk-ASIQZXYO.js +277 -0
- package/dist/chunk-ASIQZXYO.js.map +1 -0
- package/dist/{chunk-DG6YMRDC.js → chunk-B2TL6GA2.js} +2 -2
- package/dist/chunk-BJMBJZ2Y.js +290 -0
- package/dist/chunk-BJMBJZ2Y.js.map +1 -0
- package/dist/chunk-BT7NVCML.js +79 -0
- package/dist/chunk-BT7NVCML.js.map +1 -0
- package/dist/chunk-CK5NTM2S.js +454 -0
- package/dist/chunk-CK5NTM2S.js.map +1 -0
- package/dist/{chunk-AYXIPSZO.js → chunk-CRU27Q4J.js} +2 -2
- package/dist/{chunk-UWB5LMWY.js → chunk-CUI2STX6.js} +526 -24
- package/dist/chunk-CUI2STX6.js.map +1 -0
- package/dist/{chunk-CUPFXL3J.js → chunk-EGEPUGN4.js} +4 -4
- package/dist/chunk-EGEPUGN4.js.map +1 -0
- package/dist/{chunk-3OGMS3PE.js → chunk-F5VQOQ2E.js} +3 -2
- package/dist/chunk-F5VQOQ2E.js.map +1 -0
- package/dist/chunk-FP2373TW.js +149 -0
- package/dist/chunk-FP2373TW.js.map +1 -0
- package/dist/{chunk-RBBWYEFJ.js → chunk-G2WADRQ3.js} +1 -1
- package/dist/chunk-G7D6GZ5J.js +48 -0
- package/dist/chunk-G7D6GZ5J.js.map +1 -0
- package/dist/chunk-H7XKCNR6.js +60 -0
- package/dist/chunk-H7XKCNR6.js.map +1 -0
- package/dist/{chunk-LOIMBRDE.js → chunk-HIRKCQGF.js} +1994 -412
- package/dist/chunk-HIRKCQGF.js.map +1 -0
- package/dist/chunk-IXEJRKCZ.js +18 -0
- package/dist/chunk-IXEJRKCZ.js.map +1 -0
- package/dist/chunk-IYY4MCPG.js +275 -0
- package/dist/chunk-IYY4MCPG.js.map +1 -0
- package/dist/{chunk-BECYBZLX.js → chunk-JWSENLQI.js} +502 -22
- package/dist/chunk-JWSENLQI.js.map +1 -0
- package/dist/chunk-KNKUID7G.js +183 -0
- package/dist/chunk-KNKUID7G.js.map +1 -0
- package/dist/chunk-L2IO2QPY.js +2036 -0
- package/dist/chunk-L2IO2QPY.js.map +1 -0
- package/dist/{chunk-ZAIM4TUE.js → chunk-LW2NMHDW.js} +46 -1
- package/dist/chunk-LW2NMHDW.js.map +1 -0
- package/dist/chunk-MDYG7VI7.js +48 -0
- package/dist/chunk-MDYG7VI7.js.map +1 -0
- package/dist/{chunk-VDX363PS.js → chunk-MUELDH4F.js} +10 -3
- package/dist/chunk-MUELDH4F.js.map +1 -0
- package/dist/chunk-MXC3AP5I.js +74 -0
- package/dist/chunk-MXC3AP5I.js.map +1 -0
- package/dist/chunk-NN3TS5BM.js +147 -0
- package/dist/chunk-NN3TS5BM.js.map +1 -0
- package/dist/{chunk-3YGHKTBF.js → chunk-NZS2BLTP.js} +963 -326
- package/dist/chunk-NZS2BLTP.js.map +1 -0
- package/dist/chunk-OA3L7BFR.js +183 -0
- package/dist/chunk-OA3L7BFR.js.map +1 -0
- package/dist/chunk-OZHRDTDX.js +240 -0
- package/dist/chunk-OZHRDTDX.js.map +1 -0
- package/dist/chunk-PCUKNJAZ.js +165 -0
- package/dist/chunk-PCUKNJAZ.js.map +1 -0
- package/dist/{chunk-6PFRXT4K.js → chunk-PFV5C235.js} +11 -6
- package/dist/chunk-PFV5C235.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/{chunk-Y7R2XJ5Q.js → chunk-Q7FJ5ZHM.js} +6 -2
- package/dist/chunk-Q7FJ5ZHM.js.map +1 -0
- package/dist/{chunk-WCLICCGB.js → chunk-RILIVK4O.js} +91 -4
- package/dist/chunk-RILIVK4O.js.map +1 -0
- package/dist/{chunk-C2EFFULQ.js → chunk-RK2Y4XOM.js} +163 -20
- package/dist/chunk-RK2Y4XOM.js.map +1 -0
- package/dist/{chunk-TP4FZJIZ.js → chunk-RULE4VG5.js} +5 -1
- package/dist/chunk-RULE4VG5.js.map +1 -0
- package/dist/{chunk-PVPWZSSI.js → chunk-SMA4IMHV.js} +19 -3
- package/dist/chunk-SMA4IMHV.js.map +1 -0
- package/dist/{chunk-6YJHX2DL.js → chunk-TIFRGAKO.js} +242 -22
- package/dist/chunk-TIFRGAKO.js.map +1 -0
- package/dist/chunk-TUFG6VXY.js +875 -0
- package/dist/chunk-TUFG6VXY.js.map +1 -0
- package/dist/chunk-TYEOAFH3.js +251 -0
- package/dist/chunk-TYEOAFH3.js.map +1 -0
- package/dist/chunk-UKJAGEXH.js +260 -0
- package/dist/chunk-UKJAGEXH.js.map +1 -0
- package/dist/{chunk-KVBLZUKV.js → chunk-USFPPRAF.js} +93 -3
- package/dist/chunk-USFPPRAF.js.map +1 -0
- package/dist/{chunk-NBVAS5MT.js → chunk-V7TEH5I2.js} +6 -6
- package/dist/{chunk-GA5P7RST.js → chunk-VTJVUHRK.js} +22 -36
- package/dist/chunk-VTJVUHRK.js.map +1 -0
- package/dist/{chunk-SPI27QT6.js → chunk-W7WWT4FJ.js} +9 -4
- package/dist/chunk-W7WWT4FJ.js.map +1 -0
- package/dist/chunk-WIICJPET.js +45 -0
- package/dist/chunk-WIICJPET.js.map +1 -0
- package/dist/{chunk-VBVG2M5G.js → chunk-WPGJYVUH.js} +6 -2
- package/dist/chunk-WPGJYVUH.js.map +1 -0
- package/dist/{chunk-4HQS2HPX.js → chunk-WSZIHQBK.js} +29 -9
- package/dist/{chunk-4HQS2HPX.js.map → chunk-WSZIHQBK.js.map} +1 -1
- package/dist/{chunk-NZLQTHS5.js → chunk-WW3QQF4H.js} +4 -1
- package/dist/chunk-WW3QQF4H.js.map +1 -0
- package/dist/{chunk-DIXB44VE.js → chunk-X6VBWOVZ.js} +28 -13
- package/dist/chunk-X6VBWOVZ.js.map +1 -0
- package/dist/{chunk-XXVWLXSG.js → chunk-XQ4EJLUD.js} +64 -92
- package/dist/chunk-XQ4EJLUD.js.map +1 -0
- package/dist/{chunk-OC5OXUQ4.js → chunk-XRCYKJ3V.js} +780 -17
- package/dist/chunk-XRCYKJ3V.js.map +1 -0
- package/dist/{chunk-F5VP6YCB.js → chunk-Y4A6M3B6.js} +573 -156
- package/dist/chunk-Y4A6M3B6.js.map +1 -0
- package/dist/chunk-YNJHCGDT.js +309 -0
- package/dist/chunk-YNJHCGDT.js.map +1 -0
- package/dist/{chunk-L7IXWRYE.js → chunk-ZIBOQULP.js} +22 -13
- package/dist/chunk-ZIBOQULP.js.map +1 -0
- package/dist/{chunk-W6SL7OFG.js → chunk-ZTSE2ZJ6.js} +12 -2
- package/dist/{chunk-W6SL7OFG.js.map → chunk-ZTSE2ZJ6.js.map} +1 -1
- package/dist/chunking.js +1 -0
- package/dist/cipher-GVE2GQ5H.js +28 -0
- package/dist/cipher-GVE2GQ5H.js.map +1 -0
- package/dist/citations.js +1 -0
- package/dist/{cli-BkeRaYfk.d.ts → cli-lMql2FCr.d.ts} +26 -7
- package/dist/cli.d.ts +11 -6
- package/dist/cli.js +69 -34
- package/dist/codex-thread-key.js +1 -0
- package/dist/commitment-ledger.js +1 -0
- package/dist/compression-optimizer.js +1 -0
- package/dist/config.d.ts +2 -1
- package/dist/config.js +4 -1
- package/dist/connectors-cli-DFGtY2DB.d.ts +257 -0
- package/dist/connectors-cli.d.ts +2 -0
- package/dist/connectors-cli.js +22 -0
- package/dist/connectors-cli.js.map +1 -0
- package/dist/consolidation-operator.d.ts +65 -5
- package/dist/consolidation-operator.js +6 -1
- package/dist/consolidation-provenance-check.d.ts +1 -1
- package/dist/consolidation-provenance-check.js +3 -2
- package/dist/consolidation-undo.d.ts +1 -1
- package/dist/consolidation-undo.js +1 -0
- package/dist/consolidation-undo.js.map +1 -1
- package/dist/{contradiction-review-WIUBAR52.js → contradiction-review-5LTTVDQV.js} +2 -1
- package/dist/contradiction-review-5LTTVDQV.js.map +1 -0
- package/dist/{contradiction-scan-E3GJTI4F.js → contradiction-scan-3Z6YW7YA.js} +2 -1
- package/dist/{contradiction-scan-E3GJTI4F.js.map → contradiction-scan-3Z6YW7YA.js.map} +1 -1
- package/dist/cross-namespace-budget.js +1 -0
- package/dist/cue-anchors.js +1 -0
- package/dist/dashboard-runtime.js +1 -0
- package/dist/day-summary.js +1 -0
- package/dist/delinearize.js +1 -0
- package/dist/direct-answer-wiring.js +1 -0
- package/dist/direct-answer.js +1 -0
- package/dist/dreams-ledger-LR2NBAZE.js +286 -0
- package/dist/dreams-ledger-LR2NBAZE.js.map +1 -0
- package/dist/embedding-fallback.js +1 -0
- package/dist/engine-O6YWKQM3.js +28 -0
- package/dist/engine-O6YWKQM3.js.map +1 -0
- package/dist/entity-retrieval.d.ts +1 -1
- package/dist/entity-retrieval.js +10 -7
- package/dist/entity-schema.js +1 -0
- package/dist/evals.js +1 -0
- package/dist/evidence-pack.d.ts +16 -0
- package/dist/evidence-pack.js +8 -0
- package/dist/evidence-pack.js.map +1 -0
- package/dist/explicit-capture.d.ts +6 -4
- package/dist/explicit-capture.js +1 -0
- package/dist/extraction-judge-telemetry.js +1 -0
- package/dist/extraction-judge-training.js +1 -0
- package/dist/extraction-judge.js +1 -0
- package/dist/extraction.js +8 -7
- package/dist/fallback-llm.js +3 -2
- package/dist/first-start-migration-4MHQEOSD.js +263 -0
- package/dist/first-start-migration-4MHQEOSD.js.map +1 -0
- package/dist/forget-PLR6J5DN.js +69 -0
- package/dist/forget-PLR6J5DN.js.map +1 -0
- package/dist/framework-CyHYDcri.d.ts +153 -0
- package/dist/fs-utils-IRVUFB6G.js +30 -0
- package/dist/fs-utils-IRVUFB6G.js.map +1 -0
- package/dist/graph-dashboard-diff.js +1 -0
- package/dist/graph-dashboard-key.js +1 -0
- package/dist/graph-dashboard-parser.js +1 -0
- package/dist/graph-edge-decay-PWB63GRE.js +207 -0
- package/dist/graph-edge-decay-PWB63GRE.js.map +1 -0
- package/dist/graph-edge-reinforcement.d.ts +81 -0
- package/dist/graph-edge-reinforcement.js +24 -0
- package/dist/graph-edge-reinforcement.js.map +1 -0
- package/dist/graph-events.d.ts +87 -0
- package/dist/graph-events.js +14 -0
- package/dist/graph-events.js.map +1 -0
- package/dist/graph-recall.js +1 -0
- package/dist/graph-retrieval.js +1 -0
- package/dist/graph-snapshot.d.ts +112 -0
- package/dist/graph-snapshot.js +19 -0
- package/dist/graph-snapshot.js.map +1 -0
- package/dist/graph.d.ts +105 -7
- package/dist/graph.js +20 -3
- package/dist/harmonic-retrieval.js +1 -0
- package/dist/himem.js +1 -0
- package/dist/hygiene.js +1 -0
- package/dist/identity-continuity.js +1 -0
- package/dist/importance.js +1 -0
- package/dist/index.d.ts +574 -13
- package/dist/index.js +337 -69
- package/dist/index.js.map +1 -1
- package/dist/intent.js +1 -0
- package/dist/json-extract.js +1 -0
- package/dist/json-store.js +1 -0
- package/dist/kdf-7S6RWKLZ.js +26 -0
- package/dist/kdf-7S6RWKLZ.js.map +1 -0
- package/dist/legacy-hook-compat.js +1 -0
- package/dist/legacy-hook-compat.js.map +1 -1
- package/dist/lifecycle.js +1 -0
- package/dist/live-connectors-runner.d.ts +48 -0
- package/dist/live-connectors-runner.js +17 -0
- package/dist/live-connectors-runner.js.map +1 -0
- package/dist/local-llm.js +1 -0
- package/dist/logger.js +1 -0
- package/dist/memory-action-policy.js +1 -0
- package/dist/memory-cache.d.ts +2 -1
- package/dist/memory-cache.js +4 -1
- package/dist/memory-governance-JZHZDOLN.js +37 -0
- package/dist/memory-governance-JZHZDOLN.js.map +1 -0
- package/dist/memory-lifecycle-ledger-utils.d.ts +2 -1
- package/dist/memory-lifecycle-ledger-utils.js +4 -1
- package/dist/memory-projection-format.js +1 -0
- package/dist/{memory-projection-store-DeSXPh1j.d.ts → memory-projection-store-CY8TU40w.d.ts} +2 -1
- package/dist/memory-projection-store.d.ts +1 -1
- package/dist/memory-projection-store.js +2 -1
- package/dist/memory-worth-bench.js +1 -0
- package/dist/memory-worth-bench.js.map +1 -1
- package/dist/memory-worth-filter.js +1 -0
- package/dist/memory-worth-outcomes.d.ts +1 -1
- package/dist/memory-worth-outcomes.js +1 -0
- package/dist/memory-worth.js +1 -0
- package/dist/metadata-FC3XPDRQ.js +21 -0
- package/dist/metadata-FC3XPDRQ.js.map +1 -0
- package/dist/migrate-from-identity-anchor-TTEDEJGX.js +8 -0
- package/dist/migrate-from-identity-anchor-TTEDEJGX.js.map +1 -0
- package/dist/model-registry.js +1 -0
- package/dist/models-json.js +1 -0
- package/dist/native-knowledge.js +1 -0
- package/dist/negative.js +1 -0
- package/dist/objective-state-writers.js +1 -0
- package/dist/objective-state-writers.js.map +1 -1
- package/dist/objective-state.js +1 -0
- package/dist/openai-chat-compat.js +1 -0
- package/dist/operator-toolkit.d.ts +46 -2
- package/dist/operator-toolkit.js +29 -17
- package/dist/opik-exporter.js +1 -0
- package/dist/opik-exporter.js.map +1 -1
- package/dist/{orchestrator-CmJ-NTdJ.d.ts → orchestrator-ChkesB8U.d.ts} +177 -13
- package/dist/orchestrator.d.ts +6 -4
- package/dist/orchestrator.js +57 -41
- package/dist/page-versioning.js +1 -0
- package/dist/path-RMTY5Y5A.js +9 -0
- package/dist/path-RMTY5Y5A.js.map +1 -0
- package/dist/patterns-cli.d.ts +160 -0
- package/dist/patterns-cli.js +29 -0
- package/dist/patterns-cli.js.map +1 -0
- package/dist/peers-6OSQ3NK6.js +44 -0
- package/dist/peers-6OSQ3NK6.js.map +1 -0
- package/dist/plugin-id.js +1 -0
- package/dist/policy-runtime.js +1 -0
- package/dist/{port-BADbLZU5.d.ts → port-hqGnoStS.d.ts} +6 -0
- package/dist/profiling.js +1 -0
- package/dist/purge-6ATBGT77.js +205 -0
- package/dist/purge-6ATBGT77.js.map +1 -0
- package/dist/qmd-recall-cache.d.ts +1 -1
- package/dist/qmd-recall-cache.js +1 -0
- package/dist/qmd.d.ts +2 -1
- package/dist/qmd.js +4 -3
- package/dist/reasoning-trace-recall.js +1 -0
- package/dist/reasoning-trace-types.js +1 -0
- package/dist/recall-audit-anomaly.js +1 -0
- package/dist/recall-audit.js +1 -0
- package/dist/recall-disclosure-escalation.d.ts +84 -0
- package/dist/recall-disclosure-escalation.js +14 -0
- package/dist/recall-disclosure-escalation.js.map +1 -0
- package/dist/recall-explain-renderer.js +4 -1
- package/dist/recall-mmr.js +1 -0
- package/dist/recall-qos.js +1 -0
- package/dist/recall-query-policy.js +1 -0
- package/dist/recall-state.d.ts +7 -0
- package/dist/recall-state.js +2 -1
- package/dist/recall-tag-filter.d.ts +56 -0
- package/dist/recall-tag-filter.js +14 -0
- package/dist/recall-tag-filter.js.map +1 -0
- package/dist/recall-tokenization.js +1 -0
- package/dist/recall-xray-cli.d.ts +9 -2
- package/dist/recall-xray-cli.js +9 -4
- package/dist/recall-xray-renderer.js +4 -1
- package/dist/recall-xray.d.ts +116 -2
- package/dist/recall-xray.js +9 -3
- package/dist/reconstruct.js +1 -0
- package/dist/release-changelog.js +2 -0
- package/dist/release-changelog.js.map +1 -1
- package/dist/relevance.js +1 -0
- package/dist/rerank.js +1 -0
- package/dist/{resolution-QBTDHTG7.js → resolution-YGIBORXI.js} +2 -1
- package/dist/{resolution-QBTDHTG7.js.map → resolution-YGIBORXI.js.map} +1 -1
- package/dist/resolve-auth-token.d.ts +51 -0
- package/dist/resolve-auth-token.js +12 -0
- package/dist/resolve-auth-token.js.map +1 -0
- package/dist/resolve-provider-secret.d.ts +9 -1
- package/dist/resolve-provider-secret.js +4 -1
- package/dist/resume-bundles.js +4 -3
- package/dist/retrieval-agents.d.ts +1 -1
- package/dist/retrieval-agents.js +1 -0
- package/dist/retrieval-tiers.js +1 -0
- package/dist/retrieval.js +1 -0
- package/dist/sanitize.js +1 -0
- package/dist/schemas.d.ts +15 -2
- package/dist/schemas.js +2 -1
- package/dist/sdk-compat.js +1 -0
- package/dist/sdk-compat.js.map +1 -1
- package/dist/secure-store-4R2GSO7S.js +156 -0
- package/dist/secure-store-4R2GSO7S.js.map +1 -0
- package/dist/semantic-chunking.js +1 -0
- package/dist/{semantic-consolidation-CxJU6MJk.d.ts → semantic-consolidation-ByBXb-sf.d.ts} +3 -3
- package/dist/semantic-consolidation.d.ts +2 -2
- package/dist/semantic-consolidation.js +12 -7
- package/dist/semantic-rule-promotion.d.ts +1 -1
- package/dist/semantic-rule-promotion.js +10 -7
- package/dist/semantic-rule-verifier.d.ts +1 -1
- package/dist/semantic-rule-verifier.js +10 -7
- package/dist/session-integrity.js +1 -0
- package/dist/session-observer-bands.js +1 -0
- package/dist/session-observer-state.js +1 -0
- package/dist/session-toggles.js +2 -0
- package/dist/session-toggles.js.map +1 -1
- package/dist/signal.js +1 -0
- package/dist/skills-registry.js +2 -0
- package/dist/skills-registry.js.map +1 -1
- package/dist/source-attribution.js +1 -0
- package/dist/state-NCHQ4TRG.js +8 -0
- package/dist/state-NCHQ4TRG.js.map +1 -0
- package/dist/state-store-3EH7HYIN.js +16 -0
- package/dist/state-store-3EH7HYIN.js.map +1 -0
- package/dist/storage.d.ts +76 -2
- package/dist/storage.js +9 -6
- package/dist/store-contract.js +1 -0
- package/dist/summarizer.js +5 -4
- package/dist/summary-snapshot.js +1 -0
- package/dist/temporal-index.js +1 -0
- package/dist/temporal-supersession.d.ts +1 -1
- package/dist/temporal-supersession.js +2 -1
- package/dist/temporal-validity.d.ts +52 -0
- package/dist/temporal-validity.js +14 -0
- package/dist/temporal-validity.js.map +1 -0
- package/dist/threading.js +1 -0
- package/dist/tier-migration.d.ts +2 -2
- package/dist/tier-migration.js +1 -0
- package/dist/tier-routing.js +1 -0
- package/dist/tier-stats-62ZVDFKS.js +152 -0
- package/dist/tier-stats-62ZVDFKS.js.map +1 -0
- package/dist/tmt.js +1 -0
- package/dist/tokens.js +1 -0
- package/dist/topics.js +1 -0
- package/dist/trace-C5ETWBEF.js +290 -0
- package/dist/trace-C5ETWBEF.js.map +1 -0
- package/dist/transcript.js +1 -0
- package/dist/trust-zones.js +1 -0
- package/dist/tui-RI7P6PBS.js +13 -0
- package/dist/tui-RI7P6PBS.js.map +1 -0
- package/dist/types-V3FJ26TF.js +30 -0
- package/dist/types-V3FJ26TF.js.map +1 -0
- package/dist/types.d.ts +634 -9
- package/dist/types.js +10 -3
- package/dist/utility-learner.js +1 -0
- package/dist/utility-runtime.js +1 -0
- package/dist/utility-telemetry.js +1 -0
- package/dist/verified-recall.js +10 -7
- package/dist/version-utils.js +1 -0
- package/dist/whitespace.js +1 -0
- package/dist/work-product-ledger.js +1 -0
- package/package.json +7 -3
- package/scripts/ensure-better-sqlite3.mjs +124 -0
- package/dist/access-service-Br8ZydTK.d.ts +0 -827
- package/dist/chunk-3OGMS3PE.js.map +0 -1
- package/dist/chunk-3YGHKTBF.js.map +0 -1
- package/dist/chunk-6PFRXT4K.js.map +0 -1
- package/dist/chunk-6YJHX2DL.js.map +0 -1
- package/dist/chunk-BECYBZLX.js.map +0 -1
- package/dist/chunk-C2EFFULQ.js.map +0 -1
- package/dist/chunk-CUPFXL3J.js.map +0 -1
- package/dist/chunk-DIXB44VE.js.map +0 -1
- package/dist/chunk-F5VP6YCB.js.map +0 -1
- package/dist/chunk-FVA6TGI3.js.map +0 -1
- package/dist/chunk-GA5P7RST.js.map +0 -1
- package/dist/chunk-KVBLZUKV.js.map +0 -1
- package/dist/chunk-L7IXWRYE.js.map +0 -1
- package/dist/chunk-LOIMBRDE.js.map +0 -1
- package/dist/chunk-LTCGGW2D.js +0 -14
- package/dist/chunk-LTCGGW2D.js.map +0 -1
- package/dist/chunk-NZLQTHS5.js.map +0 -1
- package/dist/chunk-OC5OXUQ4.js.map +0 -1
- package/dist/chunk-PVPWZSSI.js.map +0 -1
- package/dist/chunk-SPI27QT6.js.map +0 -1
- package/dist/chunk-STGWEHYR.js.map +0 -1
- package/dist/chunk-TP4FZJIZ.js.map +0 -1
- package/dist/chunk-ULYOGL6R.js.map +0 -1
- package/dist/chunk-UWB5LMWY.js.map +0 -1
- package/dist/chunk-VBVG2M5G.js.map +0 -1
- package/dist/chunk-VDX363PS.js.map +0 -1
- package/dist/chunk-WCLICCGB.js.map +0 -1
- package/dist/chunk-X6GF3FX2.js +0 -26
- package/dist/chunk-X6GF3FX2.js.map +0 -1
- package/dist/chunk-XXVWLXSG.js.map +0 -1
- package/dist/chunk-Y7R2XJ5Q.js.map +0 -1
- package/dist/chunk-ZAIM4TUE.js.map +0 -1
- package/dist/engine-72LSIWQP.js +0 -23
- /package/dist/{contradiction-review-WIUBAR52.js.map → capsule-cli.js.map} +0 -0
- /package/dist/{engine-72LSIWQP.js.map → capsule-crypto-5CYAGVC5.js.map} +0 -0
- /package/dist/{chunk-TMYO7B5P.js.map → chunk-47WOM4YW.js.map} +0 -0
- /package/dist/{chunk-DG6YMRDC.js.map → chunk-B2TL6GA2.js.map} +0 -0
- /package/dist/{chunk-AYXIPSZO.js.map → chunk-CRU27Q4J.js.map} +0 -0
- /package/dist/{chunk-RBBWYEFJ.js.map → chunk-G2WADRQ3.js.map} +0 -0
- /package/dist/{chunk-NBVAS5MT.js.map → chunk-V7TEH5I2.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/recall-explain-renderer.ts","../src/recall-xray-renderer.ts"],"sourcesContent":["/**\n * Renderers for RecallTierExplain (issue #518).\n *\n * Pure functions that format a `LastRecallSnapshot` and its\n * optional `tierExplain` field for human text and machine JSON\n * consumption. CLI / HTTP / MCP surfaces consume these — they do\n * not format explain output themselves, so rendering is tested in\n * one place.\n */\n\nimport type { LastRecallSnapshot } from \"./recall-state.js\";\nimport type { RecallTierExplain } from \"./types.js\";\nimport { isRetrievalTier } from \"./retrieval-tiers.js\";\nimport type {\n RecallXraySnapshot,\n RecallFilterTrace,\n RecallXrayResult,\n} from \"./recall-xray.js\";\nimport { renderXrayMarkdown } from \"./recall-xray-renderer.js\";\n\nfunction sanitizeString(v: unknown): string | null {\n return typeof v === \"string\" && v.length > 0 ? v : null;\n}\n\nfunction sanitizeFiniteNumber(v: unknown): number | null {\n return typeof v === \"number\" && Number.isFinite(v) ? v : null;\n}\n\n/**\n * `text` and `json` are the original formats (backwards-compatible\n * since issue #518). `markdown` was added in issue #570 PR 7 and\n * delegates to the shared X-ray renderer so the three observability\n * surfaces stay in lock-step (CLAUDE.md rule 22).\n */\nexport type RecallExplainFormat = \"text\" | \"json\" | \"markdown\";\n\nexport interface RecallExplainJsonPayload {\n hasExplain: boolean;\n snapshotFound: boolean;\n sessionKey: string | null;\n recordedAt: string | null;\n namespace: string | null;\n memoryIds: string[];\n source: string | null;\n sourcesUsed: string[] | null;\n latencyMs: number | null;\n tierExplain: RecallTierExplain | null;\n}\n\nfunction normalizeTierExplain(value: unknown): RecallTierExplain | null {\n if (!value || typeof value !== \"object\" || Array.isArray(value)) return null;\n const raw = value as Record<string, unknown>;\n const filteredBy = Array.isArray(raw.filteredBy)\n ? raw.filteredBy.filter((x): x is string => typeof x === \"string\")\n : [];\n const sourceAnchors = Array.isArray(raw.sourceAnchors)\n ? raw.sourceAnchors\n .filter(\n (a): a is { path: string; lineRange?: unknown } =>\n !!a && typeof a === \"object\" && typeof (a as { path?: unknown }).path === \"string\",\n )\n .map((a) => {\n const lr = (a as { lineRange?: unknown }).lineRange;\n const lineRange =\n Array.isArray(lr) &&\n lr.length === 2 &&\n Number.isFinite(lr[0]) &&\n Number.isFinite(lr[1])\n ? ([lr[0] as number, lr[1] as number] as [number, number])\n : undefined;\n return lineRange\n ? { path: (a as { path: string }).path, lineRange }\n : { path: (a as { path: string }).path };\n })\n : undefined;\n return {\n tier: isRetrievalTier(raw.tier) ? raw.tier : \"hybrid\",\n tierReason: typeof raw.tierReason === \"string\" ? raw.tierReason : \"\",\n filteredBy,\n candidatesConsidered: sanitizeFiniteNumber(raw.candidatesConsidered) ?? 0,\n latencyMs: sanitizeFiniteNumber(raw.latencyMs) ?? 0,\n ...(sourceAnchors !== undefined ? { sourceAnchors } : {}),\n };\n}\n\nexport function toRecallExplainJson(\n snapshot: LastRecallSnapshot | null,\n): RecallExplainJsonPayload {\n if (!snapshot) {\n return {\n hasExplain: false,\n snapshotFound: false,\n sessionKey: null,\n recordedAt: null,\n namespace: null,\n memoryIds: [],\n source: null,\n sourcesUsed: null,\n latencyMs: null,\n tierExplain: null,\n };\n }\n const normalizedExplain = normalizeTierExplain(snapshot.tierExplain);\n return {\n hasExplain: normalizedExplain !== null,\n snapshotFound: true,\n sessionKey: sanitizeString(snapshot.sessionKey),\n recordedAt: sanitizeString(snapshot.recordedAt),\n namespace: sanitizeString(snapshot.namespace),\n memoryIds: Array.isArray(snapshot.memoryIds)\n ? snapshot.memoryIds.filter((x): x is string => typeof x === \"string\")\n : [],\n source: sanitizeString(snapshot.source),\n sourcesUsed: Array.isArray(snapshot.sourcesUsed)\n ? snapshot.sourcesUsed.filter((x): x is string => typeof x === \"string\")\n : null,\n latencyMs: sanitizeFiniteNumber(snapshot.latencyMs),\n tierExplain: normalizedExplain,\n };\n}\n\n/**\n * Render the shared \"--- tier explain ---\" text block used by both the\n * recall-explain surface and the Recall X-ray surface. Callers provide\n * the normalized `RecallTierExplain` (or `null` for the\n * not-populated/disabled case) so the block stays character-for-character\n * identical across surfaces (CLAUDE.md rule 22). The returned strings do\n * NOT include leading blank lines or headers — callers own that framing.\n */\nexport function renderTierExplainTextLines(\n tierExplain: RecallTierExplain | null,\n): string[] {\n const lines: string[] = [];\n if (!tierExplain) {\n lines.push(\n \"(not populated — direct-answer tier disabled or did not fire)\",\n );\n return lines;\n }\n lines.push(`tier: ${tierExplain.tier}`);\n lines.push(`reason: ${tierExplain.tierReason}`);\n lines.push(`candidates-considered: ${tierExplain.candidatesConsidered}`);\n lines.push(`latency-ms: ${tierExplain.latencyMs}`);\n if (tierExplain.filteredBy.length > 0) {\n lines.push(`filtered-by: ${tierExplain.filteredBy.join(\", \")}`);\n } else {\n lines.push(\"filtered-by: (none)\");\n }\n if (tierExplain.sourceAnchors && tierExplain.sourceAnchors.length > 0) {\n lines.push(\"source-anchors:\");\n for (const anchor of tierExplain.sourceAnchors) {\n const range = anchor.lineRange\n ? `:${anchor.lineRange[0]}-${anchor.lineRange[1]}`\n : \"\";\n lines.push(` - ${anchor.path}${range}`);\n }\n }\n return lines;\n}\n\nexport function toRecallExplainText(\n snapshot: LastRecallSnapshot | null,\n): string {\n const lines: string[] = [\"=== Recall Explain ===\"];\n\n if (!snapshot) {\n lines.push(\"No recall snapshot recorded yet.\");\n return lines.join(\"\\n\");\n }\n\n const sessionKey = sanitizeString(snapshot.sessionKey);\n const recordedAt = sanitizeString(snapshot.recordedAt);\n const namespace = sanitizeString(snapshot.namespace);\n const source = sanitizeString(snapshot.source);\n lines.push(`session: ${sessionKey ?? \"(unknown)\"}`);\n lines.push(`recorded: ${recordedAt ?? \"(unknown)\"}`);\n if (namespace) lines.push(`namespace: ${namespace}`);\n if (source) lines.push(`source: ${source}`);\n const sourcesUsed = Array.isArray(snapshot.sourcesUsed)\n ? snapshot.sourcesUsed.filter((x): x is string => typeof x === \"string\")\n : [];\n if (sourcesUsed.length > 0) {\n lines.push(`sources-used: ${sourcesUsed.join(\", \")}`);\n }\n const latencyMs = sanitizeFiniteNumber(snapshot.latencyMs);\n if (latencyMs !== null) {\n lines.push(`latency-ms: ${latencyMs}`);\n }\n const memoryIds = Array.isArray(snapshot.memoryIds)\n ? snapshot.memoryIds.filter((x): x is string => typeof x === \"string\")\n : [];\n if (memoryIds.length > 0) {\n lines.push(`memories: ${memoryIds.join(\", \")}`);\n }\n\n const ex = normalizeTierExplain(snapshot.tierExplain);\n if (!ex) {\n lines.push(\"\");\n lines.push(\n \"tier-explain: (not populated — direct-answer tier disabled or did not fire)\",\n );\n return lines.join(\"\\n\");\n }\n\n lines.push(\"\");\n lines.push(\"--- tier explain ---\");\n for (const line of renderTierExplainTextLines(ex)) {\n lines.push(line);\n }\n return lines.join(\"\\n\");\n}\n\n/**\n * Adapter: convert a `LastRecallSnapshot` into a best-effort\n * `RecallXraySnapshot` so the markdown renderer can produce a\n * consistent, richly-formatted document for callers that have asked\n * for `markdown` format. The LastRecallSnapshot and the X-ray\n * snapshot share session/namespace/memoryIds; additional X-ray-only\n * fields (filters, score decomposition, graph path, audit id) are\n * left empty because the legacy snapshot doesn't carry them. The\n * renderer handles missing fields gracefully.\n */\n/**\n * Strip backticks, pipes, and newlines from a host-provided value so it\n * cannot escape its enclosing markdown code span, break the surrounding\n * table row, or inject extra rows when it lands in\n * `renderXrayMarkdown`. Applied at the adapter boundary because\n * `LastRecallSnapshot` is hydrated from on-disk JSON without schema\n * validation (codex P2 review on #605).\n *\n * Accepts `unknown` so non-string truthy values (numbers, objects,\n * booleans, arrays) coming from a corrupted snapshot are coerced to\n * the empty string rather than crashing on `.replace(...)`. Callers\n * should treat an empty return as \"drop this field.\"\n */\nfunction sanitizeForMarkdownInline(value: unknown): string {\n if (typeof value !== \"string\") return \"\";\n return value.replace(/[`|\\r\\n]/g, \" \").trim();\n}\n\n/**\n * Map the legacy `LastRecallSnapshot.source` field to the\n * `RecallXrayServedBy` union used by the unified x-ray renderer.\n * Mirrors the `mapRecallSourceToXrayServedBy` helper inside\n * `orchestrator.ts` (which is private). Keep the two in sync when a\n * new source lands — unknown values collapse to `\"hybrid\"` to preserve\n * backwards compatibility with older on-disk snapshots.\n */\nfunction mapLegacySourceToServedBy(\n source: unknown,\n): \"hybrid\" | \"recent-scan\" {\n if (source === \"recent_scan\") return \"recent-scan\";\n return \"hybrid\";\n}\n\nexport function toRecallXraySnapshotFromLegacy(\n snapshot: LastRecallSnapshot | null,\n): RecallXraySnapshot | null {\n if (!snapshot) return null;\n const capturedAt = (() => {\n if (typeof snapshot.recordedAt !== \"string\") return 0;\n const ms = Date.parse(snapshot.recordedAt);\n return Number.isFinite(ms) && ms >= 0 ? ms : 0;\n })();\n const memoryIds = Array.isArray(snapshot.memoryIds)\n ? snapshot.memoryIds.filter((x): x is string => typeof x === \"string\")\n : [];\n // Codex P2 + Cursor Medium on #605: every converted result used to\n // be stamped with `servedBy: \"hybrid\"`, misattributing legacy\n // snapshots that came from `recent_scan` (or any future source).\n // Propagate the recorded `source` so markdown `recall-explain`\n // output matches the `served-by=` string the native x-ray capture\n // would emit for the same recall.\n const servedBy = mapLegacySourceToServedBy(snapshot.source);\n const results: RecallXrayResult[] = memoryIds.map((memoryId) => ({\n memoryId,\n path: \"\",\n servedBy,\n scoreDecomposition: { final: 0 },\n admittedBy: [],\n }));\n const filters: RecallFilterTrace[] = [];\n return {\n schemaVersion: \"1\",\n // `LastRecallSnapshot` does not preserve the original query text;\n // synthesize a placeholder so the renderer has a non-empty\n // string to print. `queryHash` + `queryLen` stay in the JSON\n // payload via `toRecallExplainJson` for callers that need them.\n query:\n snapshot.queryHash\n ? `(legacy explain; queryHash=${snapshot.queryHash})`\n : \"(legacy explain)\",\n // `snapshotId` is synthesized here; `sessionKey` is already\n // sanitized before it reaches the ID because we re-use the\n // sanitized string below.\n snapshotId: `legacy-${sanitizeForMarkdownInline(snapshot.sessionKey ?? \"unknown\") || \"unknown\"}-${capturedAt}`,\n capturedAt,\n // Run the raw on-disk value through the same normalizer the text\n // and JSON paths use so the markdown adapter cannot render\n // unvalidated tier-explain payloads (cursor / codex review on\n // #605). A malformed tierExplain is dropped to null, matching the\n // behavior of the non-markdown surfaces.\n tierExplain: normalizeTierExplain(snapshot.tierExplain) ?? null,\n results,\n filters,\n budget: { chars: 0, used: 0 },\n // Sanitize legacy session metadata at the adapter boundary so a\n // malformed on-disk value (containing backticks, pipes, or\n // newlines) cannot break the enclosing markdown table when\n // `renderXrayMarkdown` prints it in a raw code-span cell (codex P2\n // review on #605).\n ...(snapshot.sessionKey\n ? (() => {\n const clean = sanitizeForMarkdownInline(snapshot.sessionKey);\n return clean ? { sessionKey: clean } : {};\n })()\n : {}),\n ...(snapshot.namespace\n ? (() => {\n const clean = sanitizeForMarkdownInline(snapshot.namespace);\n return clean ? { namespace: clean } : {};\n })()\n : {}),\n };\n}\n\nexport function renderRecallExplain(\n snapshot: LastRecallSnapshot | null,\n format: RecallExplainFormat,\n): string {\n if (format === \"json\") {\n return JSON.stringify(toRecallExplainJson(snapshot), null, 2);\n }\n if (format === \"markdown\") {\n // Delegate to the shared X-ray renderer so CLI / HTTP / MCP\n // markdown output all share one implementation (CLAUDE.md rule\n // 22). The JSON and text paths remain byte-for-byte\n // backwards-compatible with pre-#570 behavior.\n return renderXrayMarkdown(toRecallXraySnapshotFromLegacy(snapshot));\n }\n return toRecallExplainText(snapshot);\n}\n\nexport function parseRecallExplainFormat(value: unknown): RecallExplainFormat {\n if (value === undefined || value === null) return \"text\";\n if (typeof value !== \"string\") {\n throw new Error(\n `--format expects \"text\", \"json\", or \"markdown\", got ${typeof value}`,\n );\n }\n const v = value.trim().toLowerCase();\n if (v === \"text\" || v === \"json\" || v === \"markdown\") return v;\n throw new Error(\n `--format expects \"text\", \"json\", or \"markdown\", got ${JSON.stringify(value)}`,\n );\n}\n","/**\n * Unified Recall X-ray renderer (issue #570, PR 2).\n *\n * Pure functions that format a `RecallXraySnapshot` for human text,\n * GitHub-flavored markdown, and machine JSON consumption. CLI / HTTP\n * / MCP surfaces all call into this module — they do NOT format X-ray\n * output themselves, so rendering is tested in one place (CLAUDE.md\n * rule 22).\n *\n * Scope for PR 2 (this slice):\n * - Pure rendering. No IO, no transport, no capture.\n * - `renderXray(snapshot, format)` with format ∈\n * `{\"json\", \"text\", \"markdown\"}`.\n * - `parseXrayFormat(value)` — input validator that rejects unknown\n * formats with a listed-options error (CLAUDE.md rule 51).\n * - Golden-file-style tests in `recall-xray-renderer.test.ts`.\n */\n\nimport type {\n RecallFilterTrace,\n RecallXrayResult,\n RecallXraySnapshot,\n RecallXrayServedBy,\n} from \"./recall-xray.js\";\nimport { summarizeDisclosureTokens } from \"./recall-xray.js\";\nimport { renderTierExplainTextLines } from \"./recall-explain-renderer.js\";\n\nexport type RecallXrayFormat = \"json\" | \"text\" | \"markdown\";\n\nexport const RECALL_XRAY_FORMATS: readonly RecallXrayFormat[] = [\n \"json\",\n \"text\",\n \"markdown\",\n] as const;\n\n/**\n * Validate and coerce a user-provided `--format` / `format` argument to\n * `RecallXrayFormat`. Unknown values throw an error listing valid\n * options (CLAUDE.md rule 51). `undefined`/`null` defaults to `\"text\"`.\n */\nexport function parseXrayFormat(value: unknown): RecallXrayFormat {\n if (value === undefined || value === null) return \"text\";\n if (typeof value !== \"string\") {\n throw new Error(\n `--format expects one of ${RECALL_XRAY_FORMATS.join(\", \")}; got ${typeof value}`,\n );\n }\n const v = value.trim().toLowerCase();\n if (v === \"json\" || v === \"text\" || v === \"markdown\") return v;\n throw new Error(\n `--format expects one of ${RECALL_XRAY_FORMATS.join(\", \")}; got ${JSON.stringify(value)}`,\n );\n}\n\n/**\n * Top-level dispatcher. CLI / HTTP / MCP callers should always route\n * through this function so the three formats stay in lock-step.\n */\nexport function renderXray(\n snapshot: RecallXraySnapshot | null,\n format: RecallXrayFormat,\n): string {\n if (format === \"json\") return renderXrayJson(snapshot);\n if (format === \"markdown\") return renderXrayMarkdown(snapshot);\n return renderXrayText(snapshot);\n}\n\n// ─── JSON ─────────────────────────────────────────────────────────────────\n\n/**\n * Deterministic JSON encoding of an X-ray snapshot. Returns a stable\n * v1 envelope when the snapshot is absent so consumers can pattern-match\n * on `snapshotFound` rather than distinguishing `null` vs `{}`.\n */\nexport function renderXrayJson(snapshot: RecallXraySnapshot | null): string {\n if (!snapshot) {\n return JSON.stringify(\n { schemaVersion: \"1\", snapshotFound: false },\n null,\n 2,\n );\n }\n // `snapshotFound` is injected *before* the rest so downstream JSON\n // consumers see it near the top of the document.\n return JSON.stringify(\n { snapshotFound: true, ...snapshot },\n null,\n 2,\n );\n}\n\n// ─── Text ─────────────────────────────────────────────────────────────────\n\nexport function renderXrayText(snapshot: RecallXraySnapshot | null): string {\n const lines: string[] = [\"=== Recall X-ray ===\"];\n if (!snapshot) {\n lines.push(\"No X-ray snapshot captured.\");\n return lines.join(\"\\n\");\n }\n\n lines.push(`query: ${snapshot.query}`);\n lines.push(`snapshot-id: ${snapshot.snapshotId}`);\n lines.push(`captured-at: ${formatCapturedAt(snapshot.capturedAt)}`);\n if (snapshot.sessionKey) lines.push(`session: ${snapshot.sessionKey}`);\n if (snapshot.namespace) lines.push(`namespace: ${snapshot.namespace}`);\n if (snapshot.traceId) lines.push(`trace-id: ${snapshot.traceId}`);\n lines.push(\n `budget: ${snapshot.budget.used} / ${snapshot.budget.chars} chars`,\n );\n\n lines.push(\"\");\n lines.push(\"--- filters ---\");\n if (snapshot.filters.length === 0) {\n lines.push(\"(no filter traces recorded)\");\n } else {\n for (const f of snapshot.filters) {\n lines.push(renderFilterTextLine(f));\n }\n }\n\n lines.push(\"\");\n lines.push(\"--- results ---\");\n if (snapshot.results.length === 0) {\n lines.push(\"(no results admitted)\");\n } else {\n snapshot.results.forEach((result, idx) => {\n for (const line of renderResultTextLines(result, idx + 1)) {\n lines.push(line);\n }\n });\n }\n\n lines.push(\"\");\n lines.push(\"--- tier explain ---\");\n for (const line of renderTierExplainTextLines(snapshot.tierExplain ?? null)) {\n lines.push(line);\n }\n\n return lines.join(\"\\n\");\n}\n\nfunction renderFilterTextLine(f: RecallFilterTrace): string {\n const base = `- ${f.name}: ${f.admitted}/${f.considered} admitted`;\n return f.reason ? `${base} (${f.reason})` : base;\n}\n\nfunction renderResultTextLines(\n result: RecallXrayResult,\n rank: number,\n): string[] {\n const lines: string[] = [];\n lines.push(`[${rank}] ${result.memoryId} — ${servedByLabel(result.servedBy)}`);\n if (result.path) lines.push(` path: ${result.path}`);\n lines.push(` score: ${renderScoreDecomposition(result)}`);\n if (result.admittedBy.length > 0) {\n lines.push(` admitted-by: ${result.admittedBy.join(\", \")}`);\n }\n if (result.rejectedBy) {\n lines.push(` rejected-by: ${result.rejectedBy}`);\n }\n if (result.graphPath && result.graphPath.length > 0) {\n lines.push(` graph-path: ${result.graphPath.join(\" -> \")}`);\n // Issue #681 PR 3/3 — surface per-edge confidence inline so\n // operators can attribute floor-pruning / PageRank ranking\n // decisions to specific edges. Skipped when no confidences were\n // recorded (legacy snapshot or single-node path).\n if (\n result.graphEdgeConfidences &&\n result.graphEdgeConfidences.length > 0\n ) {\n lines.push(\n ` edge-confidences: ${result.graphEdgeConfidences\n .map((c) => c.toFixed(2))\n .join(\", \")}`,\n );\n }\n }\n if (result.auditEntryId) {\n lines.push(` audit-entry: ${result.auditEntryId}`);\n }\n return lines;\n}\n\n// ─── Markdown ─────────────────────────────────────────────────────────────\n\nexport function renderXrayMarkdown(\n snapshot: RecallXraySnapshot | null,\n): string {\n const lines: string[] = [\"# Recall X-ray\"];\n if (!snapshot) {\n lines.push(\"\");\n lines.push(\"_No X-ray snapshot captured._\");\n return lines.join(\"\\n\");\n }\n\n lines.push(\"\");\n lines.push(`**Query:** ${mdInlineCode(snapshot.query)}`);\n lines.push(\"\");\n lines.push(\"| Field | Value |\");\n lines.push(\"| --- | --- |\");\n lines.push(`| Snapshot ID | \\`${snapshot.snapshotId}\\` |`);\n lines.push(`| Captured at | ${formatCapturedAt(snapshot.capturedAt)} |`);\n if (snapshot.sessionKey) {\n lines.push(`| Session | \\`${snapshot.sessionKey}\\` |`);\n }\n if (snapshot.namespace) {\n lines.push(`| Namespace | \\`${snapshot.namespace}\\` |`);\n }\n if (snapshot.traceId) {\n lines.push(`| Trace ID | \\`${snapshot.traceId}\\` |`);\n }\n lines.push(\n `| Budget | ${snapshot.budget.used} / ${snapshot.budget.chars} chars |`,\n );\n\n lines.push(\"\");\n lines.push(\"## Filters\");\n if (snapshot.filters.length === 0) {\n lines.push(\"\");\n lines.push(\"_No filter traces recorded._\");\n } else {\n lines.push(\"\");\n lines.push(\"| Filter | Considered | Admitted | Reason |\");\n lines.push(\"| --- | ---: | ---: | --- |\");\n for (const f of snapshot.filters) {\n const reason = f.reason ? mdEscape(f.reason) : \"\";\n lines.push(`| ${mdEscape(f.name)} | ${f.considered} | ${f.admitted} | ${reason} |`);\n }\n }\n\n lines.push(\"\");\n lines.push(\"## Results\");\n if (snapshot.results.length === 0) {\n lines.push(\"\");\n lines.push(\"_No results admitted._\");\n } else {\n snapshot.results.forEach((result, idx) => {\n for (const line of renderResultMarkdownLines(result, idx + 1)) {\n lines.push(line);\n }\n });\n\n // Per-disclosure token-spend summary (issue #677 PR 3/4). Only\n // emitted when at least one result carries a disclosure level so\n // we don't pollute the snapshot for callers who haven't wired the\n // depth knob through. Counts and tokens default to 0 for buckets\n // with no contributions.\n const summary = summarizeDisclosureTokens(snapshot.results);\n const hasAnyDisclosure =\n summary.chunk.count + summary.section.count + summary.raw.count > 0;\n if (hasAnyDisclosure) {\n lines.push(\"\");\n lines.push(\"### Token spend by disclosure\");\n lines.push(\"\");\n lines.push(\"| Disclosure | Results | Estimated tokens |\");\n lines.push(\"| --- | ---: | ---: |\");\n lines.push(\n `| chunk | ${summary.chunk.count} | ${summary.chunk.estimatedTokens} |`,\n );\n lines.push(\n `| section | ${summary.section.count} | ${summary.section.estimatedTokens} |`,\n );\n lines.push(\n `| raw | ${summary.raw.count} | ${summary.raw.estimatedTokens} |`,\n );\n if (summary.unspecified.count > 0) {\n lines.push(\n `| _(unspecified)_ | ${summary.unspecified.count} | ${summary.unspecified.estimatedTokens} |`,\n );\n }\n }\n }\n\n lines.push(\"\");\n lines.push(\"## Tier Explain\");\n if (!snapshot.tierExplain) {\n lines.push(\"\");\n lines.push(\n \"_Not populated — direct-answer tier disabled or did not fire._\",\n );\n } else {\n const te = snapshot.tierExplain;\n lines.push(\"\");\n lines.push(\"| Field | Value |\");\n lines.push(\"| --- | --- |\");\n lines.push(`| Tier | \\`${te.tier}\\` |`);\n lines.push(`| Reason | ${mdEscape(te.tierReason)} |`);\n lines.push(`| Candidates considered | ${te.candidatesConsidered} |`);\n lines.push(`| Latency (ms) | ${te.latencyMs} |`);\n lines.push(\n `| Filtered by | ${\n te.filteredBy.length > 0\n ? te.filteredBy.map(mdInlineCode).join(\", \")\n : \"_(none)_\"\n } |`,\n );\n if (te.sourceAnchors && te.sourceAnchors.length > 0) {\n lines.push(\"\");\n lines.push(\"**Source anchors:**\");\n for (const anchor of te.sourceAnchors) {\n const range = anchor.lineRange\n ? `:${anchor.lineRange[0]}-${anchor.lineRange[1]}`\n : \"\";\n lines.push(`- \\`${anchor.path}${range}\\``);\n }\n }\n }\n\n return lines.join(\"\\n\");\n}\n\nfunction renderResultMarkdownLines(\n result: RecallXrayResult,\n rank: number,\n): string[] {\n const lines: string[] = [];\n lines.push(\"\");\n lines.push(\n `### ${rank}. \\`${result.memoryId}\\` — ${servedByLabel(result.servedBy)}`,\n );\n if (result.path) {\n lines.push(\"\");\n lines.push(`- **Path:** \\`${result.path}\\``);\n } else {\n lines.push(\"\");\n }\n lines.push(`- **Score:** ${renderScoreDecomposition(result)}`);\n if (result.admittedBy.length > 0) {\n lines.push(\n `- **Admitted by:** ${result.admittedBy.map(mdInlineCode).join(\", \")}`,\n );\n }\n if (result.rejectedBy) {\n lines.push(`- **Rejected by:** ${mdInlineCode(result.rejectedBy)}`);\n }\n if (result.graphPath && result.graphPath.length > 0) {\n lines.push(\n `- **Graph path:** ${result.graphPath\n .map(mdInlineCode)\n .join(\" → \")}`,\n );\n // Issue #681 PR 3/3 — render per-edge confidences as a parallel\n // markdown line so operators can correlate them with the path\n // arrows above. Skipped when no confidences were recorded.\n if (\n result.graphEdgeConfidences &&\n result.graphEdgeConfidences.length > 0\n ) {\n lines.push(\n `- **Edge confidences:** ${result.graphEdgeConfidences\n .map((c) => mdInlineCode(c.toFixed(2)))\n .join(\", \")}`,\n );\n }\n }\n if (result.auditEntryId) {\n lines.push(`- **Audit entry:** \\`${result.auditEntryId}\\``);\n }\n if (result.disclosure !== undefined) {\n const tokenLine =\n typeof result.estimatedTokens === \"number\"\n ? ` (~${result.estimatedTokens} tokens)`\n : \"\";\n lines.push(`- **Disclosure:** \\`${result.disclosure}\\`${tokenLine}`);\n } else if (typeof result.estimatedTokens === \"number\") {\n // Disclosure unspecified but tokens recorded — still surface the\n // budget so the operator can attribute spend.\n lines.push(`- **Estimated tokens:** ${result.estimatedTokens}`);\n }\n return lines;\n}\n\n// ─── Shared helpers ───────────────────────────────────────────────────────\n\nfunction servedByLabel(servedBy: RecallXrayServedBy): string {\n return `served-by=${servedBy}`;\n}\n\nfunction renderScoreDecomposition(result: RecallXrayResult): string {\n const parts: string[] = [`final=${formatScore(result.scoreDecomposition.final)}`];\n const s = result.scoreDecomposition;\n if (s.vector !== undefined) parts.push(`vector=${formatScore(s.vector)}`);\n if (s.bm25 !== undefined) parts.push(`bm25=${formatScore(s.bm25)}`);\n if (s.importance !== undefined) {\n parts.push(`importance=${formatScore(s.importance)}`);\n }\n if (s.mmrPenalty !== undefined) {\n parts.push(`mmr_penalty=${formatScore(s.mmrPenalty)}`);\n }\n if (s.tierPrior !== undefined) {\n parts.push(`tier_prior=${formatScore(s.tierPrior)}`);\n }\n if (s.reinforcementBoost !== undefined && s.reinforcementBoost > 0) {\n parts.push(`reinforcement_boost=${formatScore(s.reinforcementBoost)}`);\n }\n return parts.join(\" \");\n}\n\nfunction formatScore(value: number): string {\n // Deterministic 4-decimal formatting keeps golden files stable\n // without printing spurious trailing zeros via toString().\n if (!Number.isFinite(value)) return \"0.0000\";\n return value.toFixed(4);\n}\n\nfunction formatCapturedAt(ts: number): string {\n if (!Number.isFinite(ts) || ts < 0) return \"(unknown)\";\n // `new Date(n).toISOString()` throws a RangeError for finite numbers\n // outside the valid Date range (roughly |n| > 8.64e15). That case\n // can surface when snapshots are corrupted or captured with a\n // custom clock, so coerce it to the same \"(unknown)\" fallback\n // rather than crashing the renderer.\n try {\n return new Date(ts).toISOString();\n } catch {\n return \"(unknown)\";\n }\n}\n\nfunction mdEscape(value: string): string {\n // Pipe is the only character that breaks GFM table rendering; escape\n // backslash first so we do not re-escape the escape character.\n return value.replace(/\\\\/g, \"\\\\\\\\\").replace(/\\|/g, \"\\\\|\");\n}\n\nfunction mdInlineCode(value: string): string {\n if (value.length === 0) return \"``\";\n // Use exactly enough backticks to unambiguously wrap content that\n // itself contains backticks (GFM rule).\n const longestRun = /`+/g;\n let maxLen = 0;\n for (const match of value.matchAll(longestRun)) {\n if (match[0].length > maxLen) maxLen = match[0].length;\n }\n const fence = \"`\".repeat(maxLen + 1);\n const pad = value.startsWith(\"`\") || value.endsWith(\"`\") ? \" \" : \"\";\n return `${fence}${pad}${value}${pad}${fence}`;\n}\n"],"mappings":";;;;;;;;AAoBA,SAAS,eAAe,GAA2B;AACjD,SAAO,OAAO,MAAM,YAAY,EAAE,SAAS,IAAI,IAAI;AACrD;AAEA,SAAS,qBAAqB,GAA2B;AACvD,SAAO,OAAO,MAAM,YAAY,OAAO,SAAS,CAAC,IAAI,IAAI;AAC3D;AAuBA,SAAS,qBAAqB,OAA0C;AACtE,MAAI,CAAC,SAAS,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,EAAG,QAAO;AACxE,QAAM,MAAM;AACZ,QAAM,aAAa,MAAM,QAAQ,IAAI,UAAU,IAC3C,IAAI,WAAW,OAAO,CAAC,MAAmB,OAAO,MAAM,QAAQ,IAC/D,CAAC;AACL,QAAM,gBAAgB,MAAM,QAAQ,IAAI,aAAa,IACjD,IAAI,cACD;AAAA,IACC,CAAC,MACC,CAAC,CAAC,KAAK,OAAO,MAAM,YAAY,OAAQ,EAAyB,SAAS;AAAA,EAC9E,EACC,IAAI,CAAC,MAAM;AACV,UAAM,KAAM,EAA8B;AAC1C,UAAM,YACJ,MAAM,QAAQ,EAAE,KAChB,GAAG,WAAW,KACd,OAAO,SAAS,GAAG,CAAC,CAAC,KACrB,OAAO,SAAS,GAAG,CAAC,CAAC,IAChB,CAAC,GAAG,CAAC,GAAa,GAAG,CAAC,CAAW,IAClC;AACN,WAAO,YACH,EAAE,MAAO,EAAuB,MAAM,UAAU,IAChD,EAAE,MAAO,EAAuB,KAAK;AAAA,EAC3C,CAAC,IACH;AACJ,SAAO;AAAA,IACL,MAAM,gBAAgB,IAAI,IAAI,IAAI,IAAI,OAAO;AA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AAC,OAAO,SAAS,KAAK,EAAG,QAAO;AACpC,SAAO,MAAM,QAAQ,CAAC;AACxB;AAEA,SAAS,iBAAiB,IAAoB;AAC5C,MAAI,CAAC,OAAO,SAAS,EAAE,KAAK,KAAK,EAAG,QAAO;AAM3C,MAAI;AACF,WAAO,IAAI,KAAK,EAAE,EAAE,YAAY;AAAA,EAClC,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,SAAS,OAAuB;AAGvC,SAAO,MAAM,QAAQ,OAAO,MAAM,EAAE,QAAQ,OAAO,KAAK;AAC1D;AAEA,SAAS,aAAa,OAAuB;AAC3C,MAAI,MAAM,WAAW,EAAG,QAAO;AAG/B,QAAM,aAAa;AACnB,MAAI,SAAS;AACb,aAAW,SAAS,MAAM,SAAS,UAAU,GAAG;AAC9C,QAAI,MAAM,CAAC,EAAE,SAAS,OAAQ,UAAS,MAAM,CAAC,EAAE;AAAA,EAClD;AACA,QAAM,QAAQ,IAAI,OAAO,SAAS,CAAC;AACnC,QAAM,MAAM,MAAM,WAAW,GAAG,KAAK,MAAM,SAAS,GAAG,IAAI,MAAM;AACjE,SAAO,GAAG,KAAK,GAAG,GAAG,GAAG,KAAK,GAAG,GAAG,GAAG,KAAK;AAC7C;","names":[]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// src/temporal-validity.ts
|
|
2
|
+
function effectiveValidAt(fm) {
|
|
3
|
+
const explicit = fm.valid_at?.trim();
|
|
4
|
+
if (explicit && explicit.length > 0) return explicit;
|
|
5
|
+
return fm.created;
|
|
6
|
+
}
|
|
7
|
+
function effectiveInvalidAt(fm) {
|
|
8
|
+
const explicit = fm.invalid_at?.trim();
|
|
9
|
+
if (explicit && explicit.length > 0) return explicit;
|
|
10
|
+
if (fm.status === "superseded") {
|
|
11
|
+
const legacy = fm.supersededAt?.trim();
|
|
12
|
+
if (legacy && legacy.length > 0) return legacy;
|
|
13
|
+
}
|
|
14
|
+
return void 0;
|
|
15
|
+
}
|
|
16
|
+
function isValidAsOf(fm, asOfMs) {
|
|
17
|
+
if (!Number.isFinite(asOfMs)) return true;
|
|
18
|
+
const validAtMs = Date.parse(effectiveValidAt(fm));
|
|
19
|
+
if (!Number.isFinite(validAtMs)) return false;
|
|
20
|
+
if (validAtMs > asOfMs) return false;
|
|
21
|
+
const invalidAt = effectiveInvalidAt(fm);
|
|
22
|
+
if (invalidAt === void 0) return true;
|
|
23
|
+
const invalidAtMs = Date.parse(invalidAt);
|
|
24
|
+
if (!Number.isFinite(invalidAtMs)) return true;
|
|
25
|
+
return invalidAtMs > asOfMs;
|
|
26
|
+
}
|
|
27
|
+
function parseAsOfTimestamp(raw) {
|
|
28
|
+
if (typeof raw !== "string" || raw.trim().length === 0) {
|
|
29
|
+
throw new RangeError(
|
|
30
|
+
`as_of must be a non-empty ISO 8601 timestamp string (got: ${typeof raw === "string" ? `"${raw}"` : typeof raw})`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
const ms = Date.parse(raw);
|
|
34
|
+
if (!Number.isFinite(ms)) {
|
|
35
|
+
throw new RangeError(
|
|
36
|
+
`as_of must be a parseable ISO 8601 timestamp (got: "${raw}")`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return ms;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
effectiveValidAt,
|
|
44
|
+
effectiveInvalidAt,
|
|
45
|
+
isValidAsOf,
|
|
46
|
+
parseAsOfTimestamp
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=chunk-MDYG7VI7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/temporal-validity.ts"],"sourcesContent":["/**\n * Temporal validity helpers (issue #680).\n *\n * `valid_at` / `invalid_at` are explicit ISO 8601 timestamps that mark when a\n * fact begins and ends being authoritative. These helpers centralize the\n * read-time defaulting rules so every call site (recall filter, supersession\n * write, tests) agrees on the canonical semantics:\n *\n * - `effectiveValidAt(fm)` — the moment this fact starts being true.\n * Falls back to `created` when `valid_at` is absent so legacy memories\n * written before #680 still participate in `as_of` filtering without\n * a backfill migration.\n * - `effectiveInvalidAt(fm)` — the moment this fact stops being true.\n * Returns `undefined` when no `invalid_at` is set; supersession logic\n * populates it on the older fact when a newer one replaces it.\n * - `isValidAsOf(fm, asOfMs)` — true when the fact was authoritative at\n * `asOfMs` (a numeric timestamp in ms). Half-open interval semantics:\n * `valid_at <= asOf < invalid_at`. Strings are parsed via\n * `Date.parse()` so timezone-suffixed ISO strings compare correctly\n * (CLAUDE.md gotcha — never compare ISO strings lexicographically).\n *\n * Boundary case: when `invalid_at === asOf`, the fact is treated as NOT\n * valid (the upper bound is exclusive), which matches the supersession\n * model — at the instant a successor's `valid_at` fires, the predecessor\n * is no longer authoritative.\n */\nimport type { MemoryFrontmatter } from \"./types.js\";\n\nexport function effectiveValidAt(fm: Pick<MemoryFrontmatter, \"valid_at\" | \"created\">): string {\n // `created` is required on every memory (see types.ts), so the fallback\n // chain always terminates. Trimming guards against whitespace-only\n // overrides written by legacy tooling.\n const explicit = fm.valid_at?.trim();\n if (explicit && explicit.length > 0) return explicit;\n return fm.created;\n}\n\nexport function effectiveInvalidAt(\n fm: Pick<MemoryFrontmatter, \"invalid_at\" | \"supersededAt\" | \"status\">,\n): string | undefined {\n const explicit = fm.invalid_at?.trim();\n if (explicit && explicit.length > 0) return explicit;\n // Cursor Medium rounds 1+2 on PR #713: legacy data written before\n // #680 has `status: superseded` and `supersededAt` populated, but\n // no `invalid_at`. With the new `as_of` filter bypassing the\n // supersession status check, those legacy predecessors would\n // otherwise be treated as \"always valid\" and surface alongside\n // their successors at every historical pin. Fall back to\n // `supersededAt` so the half-open `[valid_at, invalid_at)`\n // interval still terminates for legacy supersedes without\n // requiring a backfill migration.\n //\n // BOUNDARY APPROXIMATION: `supersededAt` is when the supersession\n // write fired, which may post-date the successor's true\n // `valid_at` (consolidation runs on its own cadence). So the\n // legacy predecessor stays visible from `valid_at` through\n // `supersededAt` rather than the tighter `valid_at` through\n // successor-`valid_at` window. We accept this intentionally: the\n // alternative — successor-aware coordination — would require\n // threading the successor through every call site, and \"show the\n // legacy fact a bit too long\" is a clear win over \"drop legacy\n // facts entirely from `as_of`\". New data (post-#680) writes\n // `invalid_at` directly and is unaffected.\n if (fm.status === \"superseded\") {\n const legacy = fm.supersededAt?.trim();\n if (legacy && legacy.length > 0) return legacy;\n }\n return undefined;\n}\n\n/**\n * Returns true when the fact was authoritative at `asOfMs` (parsed\n * milliseconds since epoch). Half-open semantics: a fact is valid in\n * `[valid_at, invalid_at)`.\n *\n * If `valid_at` cannot be parsed, the fact is conservatively treated as\n * NOT valid at the requested point — we never silently default a corrupt\n * timestamp to \"always true\" because that would let bad data leak past\n * the historical filter (CLAUDE.md gotcha #34: distinguish empty from\n * malformed).\n */\nexport function isValidAsOf(\n fm: Pick<\n MemoryFrontmatter,\n \"valid_at\" | \"invalid_at\" | \"created\" | \"supersededAt\" | \"status\"\n >,\n asOfMs: number,\n): boolean {\n if (!Number.isFinite(asOfMs)) return true;\n const validAtMs = Date.parse(effectiveValidAt(fm));\n if (!Number.isFinite(validAtMs)) return false;\n if (validAtMs > asOfMs) return false;\n const invalidAt = effectiveInvalidAt(fm);\n if (invalidAt === undefined) return true;\n const invalidAtMs = Date.parse(invalidAt);\n // Unparseable invalid_at — conservatively keep the fact (we can read\n // valid_at, so we know the fact was at some point true; corrupt\n // invalid_at is not a reason to hide it).\n if (!Number.isFinite(invalidAtMs)) return true;\n // Half-open: at exactly invalid_at, the fact is no longer valid.\n return invalidAtMs > asOfMs;\n}\n\n/**\n * Parse and validate an `as_of` value supplied at an input boundary\n * (CLI flag, HTTP query param, MCP field). Returns parsed milliseconds\n * on success; throws a `RangeError` with a helpful message on malformed\n * input. CLAUDE.md rule 51 — never silently default invalid input.\n */\nexport function parseAsOfTimestamp(raw: unknown): number {\n if (typeof raw !== \"string\" || raw.trim().length === 0) {\n throw new RangeError(\n `as_of must be a non-empty ISO 8601 timestamp string (got: ${typeof raw === \"string\" ? `\"${raw}\"` : typeof raw})`,\n );\n }\n const ms = Date.parse(raw);\n if (!Number.isFinite(ms)) {\n throw new RangeError(\n `as_of must be a parseable ISO 8601 timestamp (got: \"${raw}\")`,\n );\n }\n return ms;\n}\n"],"mappings":";AA4BO,SAAS,iBAAiB,IAA6D;AAI5F,QAAM,WAAW,GAAG,UAAU,KAAK;AACnC,MAAI,YAAY,SAAS,SAAS,EAAG,QAAO;AAC5C,SAAO,GAAG;AACZ;AAEO,SAAS,mBACd,IACoB;AACpB,QAAM,WAAW,GAAG,YAAY,KAAK;AACrC,MAAI,YAAY,SAAS,SAAS,EAAG,QAAO;AAsB5C,MAAI,GAAG,WAAW,cAAc;AAC9B,UAAM,SAAS,GAAG,cAAc,KAAK;AACrC,QAAI,UAAU,OAAO,SAAS,EAAG,QAAO;AAAA,EAC1C;AACA,SAAO;AACT;AAaO,SAAS,YACd,IAIA,QACS;AACT,MAAI,CAAC,OAAO,SAAS,MAAM,EAAG,QAAO;AACrC,QAAM,YAAY,KAAK,MAAM,iBAAiB,EAAE,CAAC;AACjD,MAAI,CAAC,OAAO,SAAS,SAAS,EAAG,QAAO;AACxC,MAAI,YAAY,OAAQ,QAAO;AAC/B,QAAM,YAAY,mBAAmB,EAAE;AACvC,MAAI,cAAc,OAAW,QAAO;AACpC,QAAM,cAAc,KAAK,MAAM,SAAS;AAIxC,MAAI,CAAC,OAAO,SAAS,WAAW,EAAG,QAAO;AAE1C,SAAO,cAAc;AACvB;AAQO,SAAS,mBAAmB,KAAsB;AACvD,MAAI,OAAO,QAAQ,YAAY,IAAI,KAAK,EAAE,WAAW,GAAG;AACtD,UAAM,IAAI;AAAA,MACR,6DAA6D,OAAO,QAAQ,WAAW,IAAI,GAAG,MAAM,OAAO,GAAG;AAAA,IAChH;AAAA,EACF;AACA,QAAM,KAAK,KAAK,MAAM,GAAG;AACzB,MAAI,CAAC,OAAO,SAAS,EAAE,GAAG;AACxB,UAAM,IAAI;AAAA,MACR,uDAAuD,GAAG;AAAA,IAC5D;AAAA,EACF;AACA,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StorageManager
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Y4A6M3B6.js";
|
|
4
4
|
|
|
5
5
|
// src/semantic-rule-promotion.ts
|
|
6
6
|
function normalizeRuleWhitespace(value) {
|
|
@@ -63,6 +63,13 @@ async function promoteSemanticRuleFromMemory(options) {
|
|
|
63
63
|
});
|
|
64
64
|
return report;
|
|
65
65
|
}
|
|
66
|
+
if (sourceMemory.frontmatter.status === "forgotten") {
|
|
67
|
+
report.skipped.push({
|
|
68
|
+
sourceMemoryId: options.sourceMemoryId,
|
|
69
|
+
reason: "source-memory-forgotten"
|
|
70
|
+
});
|
|
71
|
+
return report;
|
|
72
|
+
}
|
|
66
73
|
if (sourceMemory.frontmatter.status === "archived" || sourceMemory.frontmatter.memoryKind !== "episode") {
|
|
67
74
|
report.skipped.push({
|
|
68
75
|
sourceMemoryId: options.sourceMemoryId,
|
|
@@ -80,7 +87,7 @@ async function promoteSemanticRuleFromMemory(options) {
|
|
|
80
87
|
}
|
|
81
88
|
const ruleKey = canonicalizeRuleKey(content);
|
|
82
89
|
const existingRule = (await storage.readAllMemories()).find(
|
|
83
|
-
(memory) => memory.frontmatter.category === "rule" && memory.frontmatter.status !== "archived" && canonicalizeRuleKey(memory.content) === ruleKey
|
|
90
|
+
(memory) => memory.frontmatter.category === "rule" && memory.frontmatter.status !== "archived" && memory.frontmatter.status !== "forgotten" && canonicalizeRuleKey(memory.content) === ruleKey
|
|
84
91
|
);
|
|
85
92
|
if (existingRule) {
|
|
86
93
|
report.skipped.push({
|
|
@@ -125,4 +132,4 @@ async function promoteSemanticRuleFromMemory(options) {
|
|
|
125
132
|
export {
|
|
126
133
|
promoteSemanticRuleFromMemory
|
|
127
134
|
};
|
|
128
|
-
//# sourceMappingURL=chunk-
|
|
135
|
+
//# sourceMappingURL=chunk-MUELDH4F.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/semantic-rule-promotion.ts"],"sourcesContent":["import { StorageManager } from \"./storage.js\";\nimport type { MemoryFile, MemoryLink } from \"./types.js\";\n\nexport interface SemanticRulePromotionCandidate {\n id: string;\n sourceMemoryId: string;\n content: string;\n confidence: number;\n tags: string[];\n memoryKind: \"note\";\n lineage: string[];\n}\n\nexport interface SemanticRulePromotionSkip {\n sourceMemoryId: string;\n reason:\n | \"disabled\"\n | \"source-memory-missing\"\n | \"source-memory-forgotten\"\n | \"source-memory-not-episode\"\n | \"no-explicit-rule\"\n | \"duplicate-rule\";\n existingRuleId?: string;\n}\n\nexport interface SemanticRulePromotionReport {\n enabled: boolean;\n dryRun: boolean;\n promoted: SemanticRulePromotionCandidate[];\n skipped: SemanticRulePromotionSkip[];\n}\n\nfunction normalizeRuleWhitespace(value: string): string {\n return value.replace(/\\s+/g, \" \").trim();\n}\n\nfunction stripTrailingClausePunctuation(value: string): string {\n return value.replace(/[,:;]+$/g, \"\").trim();\n}\n\nfunction canonicalizeRuleContent(value: string): string {\n return extractExplicitIfThenRule(value) ?? normalizeRuleWhitespace(value);\n}\n\nfunction canonicalizeRuleKey(value: string): string {\n return canonicalizeRuleContent(value).toLowerCase();\n}\n\nfunction extractExplicitIfThenRule(content: string): string | null {\n const match = content.match(/\\bif\\b([\\s\\S]+?)\\bthen\\b([\\s\\S]+?)(?:[.!?](?:\\s|$)|$)/i);\n if (!match) return null;\n const condition = stripTrailingClausePunctuation(normalizeRuleWhitespace(match[1] ?? \"\"));\n const outcome = stripTrailingClausePunctuation(normalizeRuleWhitespace(match[2] ?? \"\"));\n if (condition.length === 0 || outcome.length === 0) return null;\n return `IF ${condition} THEN ${outcome}.`;\n}\n\nfunction promotionConfidence(memory: MemoryFile): number {\n const base = Number.isFinite(memory.frontmatter.confidence) ? memory.frontmatter.confidence : 0.8;\n return Math.max(0.6, Math.min(0.98, base));\n}\n\nfunction promotionTags(memory: MemoryFile): string[] {\n return Array.from(new Set([...(memory.frontmatter.tags ?? []), \"semantic-rule\", \"promoted-rule\"]));\n}\n\nfunction buildSupportLinks(sourceMemoryId: string, confidence: number): MemoryLink[] {\n return [\n {\n targetId: sourceMemoryId,\n linkType: \"supports\",\n strength: confidence,\n reason: \"Promoted from verified episodic memory\",\n },\n ];\n}\n\nexport async function promoteSemanticRuleFromMemory(options: {\n memoryDir: string;\n enabled: boolean;\n sourceMemoryId: string;\n dryRun?: boolean;\n}): Promise<SemanticRulePromotionReport> {\n const report: SemanticRulePromotionReport = {\n enabled: options.enabled,\n dryRun: options.dryRun === true,\n promoted: [],\n skipped: [],\n };\n if (!options.enabled) {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"disabled\",\n });\n return report;\n }\n\n const storage = new StorageManager(options.memoryDir);\n const sourceMemory = await storage.getMemoryById(options.sourceMemoryId);\n if (!sourceMemory) {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"source-memory-missing\",\n });\n return report;\n }\n if (sourceMemory.frontmatter.status === \"forgotten\") {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"source-memory-forgotten\",\n });\n return report;\n }\n if (\n sourceMemory.frontmatter.status === \"archived\" ||\n sourceMemory.frontmatter.memoryKind !== \"episode\"\n ) {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"source-memory-not-episode\",\n });\n return report;\n }\n\n const content = extractExplicitIfThenRule(sourceMemory.content);\n if (!content) {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"no-explicit-rule\",\n });\n return report;\n }\n\n const ruleKey = canonicalizeRuleKey(content);\n const existingRule = (await storage.readAllMemories()).find(\n (memory) =>\n memory.frontmatter.category === \"rule\" &&\n memory.frontmatter.status !== \"archived\" &&\n memory.frontmatter.status !== \"forgotten\" &&\n canonicalizeRuleKey(memory.content) === ruleKey,\n );\n if (existingRule) {\n report.skipped.push({\n sourceMemoryId: options.sourceMemoryId,\n reason: \"duplicate-rule\",\n existingRuleId: existingRule.frontmatter.id,\n });\n return report;\n }\n\n const confidence = promotionConfidence(sourceMemory);\n const candidateBase = {\n sourceMemoryId: options.sourceMemoryId,\n content,\n confidence,\n tags: promotionTags(sourceMemory),\n memoryKind: \"note\" as const,\n lineage: [options.sourceMemoryId],\n };\n\n if (options.dryRun === true) {\n report.promoted.push({\n id: `dry-run:${options.sourceMemoryId}`,\n ...candidateBase,\n });\n return report;\n }\n\n const id = await storage.writeMemory(\"rule\", content, {\n confidence,\n tags: candidateBase.tags,\n source: \"semantic-rule-promotion\",\n lineage: candidateBase.lineage,\n sourceMemoryId: options.sourceMemoryId,\n memoryKind: \"note\",\n links: buildSupportLinks(options.sourceMemoryId, confidence),\n });\n report.promoted.push({\n id,\n ...candidateBase,\n });\n return report;\n}\n"],"mappings":";;;;;AAgCA,SAAS,wBAAwB,OAAuB;AACtD,SAAO,MAAM,QAAQ,QAAQ,GAAG,EAAE,KAAK;AACzC;AAEA,SAAS,+BAA+B,OAAuB;AAC7D,SAAO,MAAM,QAAQ,YAAY,EAAE,EAAE,KAAK;AAC5C;AAEA,SAAS,wBAAwB,OAAuB;AACtD,SAAO,0BAA0B,KAAK,KAAK,wBAAwB,KAAK;AAC1E;AAEA,SAAS,oBAAoB,OAAuB;AAClD,SAAO,wBAAwB,KAAK,EAAE,YAAY;AACpD;AAEA,SAAS,0BAA0B,SAAgC;AACjE,QAAM,QAAQ,QAAQ,MAAM,wDAAwD;AACpF,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,YAAY,+BAA+B,wBAAwB,MAAM,CAAC,KAAK,EAAE,CAAC;AACxF,QAAM,UAAU,+BAA+B,wBAAwB,MAAM,CAAC,KAAK,EAAE,CAAC;AACtF,MAAI,UAAU,WAAW,KAAK,QAAQ,WAAW,EAAG,QAAO;AAC3D,SAAO,MAAM,SAAS,SAAS,OAAO;AACxC;AAEA,SA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AAK;AAAA,IACnB;AAAA,IACA,GAAG;AAAA,EACL,CAAC;AACD,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/resolve-auth-token.ts
|
|
2
|
+
var resolvedCache = /* @__PURE__ */ new Map();
|
|
3
|
+
function cacheKeyForSecretRef(ref) {
|
|
4
|
+
const sortedKeys = Object.keys(ref).sort();
|
|
5
|
+
const stable = {};
|
|
6
|
+
for (const key of sortedKeys) {
|
|
7
|
+
stable[key] = ref[key];
|
|
8
|
+
}
|
|
9
|
+
return JSON.stringify(stable);
|
|
10
|
+
}
|
|
11
|
+
function isPlainObject(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
async function resolveAgentAccessAuthToken(value, options = {}) {
|
|
15
|
+
if (value === void 0 || value === null) return void 0;
|
|
16
|
+
if (typeof value === "string") {
|
|
17
|
+
const trimmed = value.trim();
|
|
18
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
19
|
+
}
|
|
20
|
+
if (!isPlainObject(value)) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
"unsupported SecretRef shape for agentAccessHttp.authToken \u2014 expected a string or an object with a `source` field (see https://github.com/joshuaswarren/remnic/issues/757)"
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
const ref = value;
|
|
26
|
+
if (typeof ref.source !== "string" || ref.source.trim().length === 0) {
|
|
27
|
+
throw new Error(
|
|
28
|
+
"unsupported SecretRef shape for agentAccessHttp.authToken \u2014 missing required `source` field (see https://github.com/joshuaswarren/remnic/issues/757)"
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
const cacheKey = cacheKeyForSecretRef(ref);
|
|
32
|
+
const cached = resolvedCache.get(cacheKey);
|
|
33
|
+
if (cached !== void 0) return cached;
|
|
34
|
+
const resolver = options.resolveSecretRef ?? null;
|
|
35
|
+
if (!resolver) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`cannot resolve agentAccessHttp.authToken SecretRef (source="${ref.source}") \u2014 a SecretRef resolver was not provided. Use a literal string or \${ENV_VAR} expansion in standalone Remnic, or have the host adapter resolve SecretRef objects through its native secret resolver (see https://github.com/joshuaswarren/remnic/issues/757).`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
let resolved;
|
|
41
|
+
try {
|
|
42
|
+
const out = await resolver(ref);
|
|
43
|
+
if (typeof out === "string") {
|
|
44
|
+
const trimmed = out.trim();
|
|
45
|
+
if (trimmed.length > 0) resolved = trimmed;
|
|
46
|
+
}
|
|
47
|
+
} catch (err) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`failed to resolve agentAccessHttp.authToken SecretRef (source="${ref.source}"): ${err instanceof Error ? err.message : String(err)}`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (!resolved) {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`agentAccessHttp.authToken SecretRef resolved to empty value (source="${ref.source}", provider="${ref.provider ?? ""}") \u2014 refusing to start the HTTP bridge with an empty bearer token.`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
resolvedCache.set(cacheKey, resolved);
|
|
58
|
+
return resolved;
|
|
59
|
+
}
|
|
60
|
+
function isAgentAccessSecretRef(value) {
|
|
61
|
+
if (!isPlainObject(value)) return false;
|
|
62
|
+
const ref = value;
|
|
63
|
+
return typeof ref.source === "string" && ref.source.trim().length > 0;
|
|
64
|
+
}
|
|
65
|
+
function clearAuthTokenSecretCache() {
|
|
66
|
+
resolvedCache.clear();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
resolveAgentAccessAuthToken,
|
|
71
|
+
isAgentAccessSecretRef,
|
|
72
|
+
clearAuthTokenSecretCache
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=chunk-MXC3AP5I.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/resolve-auth-token.ts"],"sourcesContent":["import type { AgentAccessAuthToken, SecretRef } from \"./types.js\";\n\n/**\n * Resolve `agentAccessHttp.authToken` (issue #757).\n *\n * Two shapes are accepted:\n *\n * 1. Plain string — returned unchanged. This is the only shape supported\n * in standalone Remnic; it preserves backward compatibility with every\n * pre-#757 config.\n *\n * 2. SecretRef-like object (`{source, provider?, id?, command?, ...}`) —\n * resolved only through a resolver supplied by the host adapter. Core\n * stays host-agnostic and never scans OpenClaw, Hermes, or any other\n * runtime directly.\n *\n * Resolution flow for SecretRef objects:\n *\n * - Plain strings short-circuit before any host work.\n * - Host adapters pass their native SecretRef resolver in `options`.\n * - If no resolver is provided, throw a clear, actionable error rather\n * than silently leaving the bridge open or starting with no auth.\n *\n * Lessons baked in from PRs #316–#319:\n *\n * - Successful resolutions are cached for the process lifetime; failures\n * are not cached so transient issues (Keychain unlocked late, agent\n * restarts) recover automatically.\n */\n\nexport type ResolveSecretRefFn = (\n ref: SecretRef,\n context?: unknown,\n) => Promise<string | undefined> | string | undefined;\n\ntype ResolveAgentAccessAuthTokenOptions = {\n resolveSecretRef?: ResolveSecretRefFn | null;\n};\n\nconst resolvedCache = new Map<string, string>();\n\n/**\n * SecretRef objects are stable per (source, provider, id, command) tuple.\n * Sort keys before serializing so semantically-identical refs hit the same\n * cache slot regardless of authoring order (Lesson 38 in CLAUDE.md).\n */\nfunction cacheKeyForSecretRef(ref: SecretRef): string {\n const sortedKeys = Object.keys(ref).sort();\n const stable: Record<string, unknown> = {};\n for (const key of sortedKeys) {\n stable[key] = ref[key];\n }\n return JSON.stringify(stable);\n}\n\nfunction isPlainObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\n/**\n * Resolve an `agentAccessHttp.authToken` value to a literal bearer string.\n *\n * @returns the resolved string, or `undefined` if input was undefined/empty.\n * @throws if the input is a SecretRef and no resolver is provided, if the\n * resolver returns no value, or if the input shape is malformed.\n */\nexport async function resolveAgentAccessAuthToken(\n value: AgentAccessAuthToken | undefined,\n options: ResolveAgentAccessAuthTokenOptions = {},\n): Promise<string | undefined> {\n if (value === undefined || value === null) return undefined;\n\n if (typeof value === \"string\") {\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : undefined;\n }\n\n if (!isPlainObject(value)) {\n throw new Error(\n \"unsupported SecretRef shape for agentAccessHttp.authToken — \" +\n \"expected a string or an object with a `source` field \" +\n \"(see https://github.com/joshuaswarren/remnic/issues/757)\",\n );\n }\n\n const ref = value as SecretRef;\n if (typeof ref.source !== \"string\" || ref.source.trim().length === 0) {\n throw new Error(\n \"unsupported SecretRef shape for agentAccessHttp.authToken — \" +\n \"missing required `source` field \" +\n \"(see https://github.com/joshuaswarren/remnic/issues/757)\",\n );\n }\n\n const cacheKey = cacheKeyForSecretRef(ref);\n const cached = resolvedCache.get(cacheKey);\n if (cached !== undefined) return cached;\n\n const resolver = options.resolveSecretRef ?? null;\n if (!resolver) {\n throw new Error(\n `cannot resolve agentAccessHttp.authToken SecretRef (source=\"${ref.source}\") — ` +\n \"a SecretRef resolver was not provided. Use a literal string or \" +\n \"${ENV_VAR} expansion in standalone Remnic, or have the host adapter \" +\n \"resolve SecretRef objects through its native secret resolver \" +\n \"(see https://github.com/joshuaswarren/remnic/issues/757).\",\n );\n }\n\n let resolved: string | undefined;\n try {\n const out = await resolver(ref);\n if (typeof out === \"string\") {\n const trimmed = out.trim();\n if (trimmed.length > 0) resolved = trimmed;\n }\n } catch (err) {\n throw new Error(\n `failed to resolve agentAccessHttp.authToken SecretRef (source=\"${ref.source}\"): ${\n err instanceof Error ? err.message : String(err)\n }`,\n );\n }\n\n if (!resolved) {\n throw new Error(\n `agentAccessHttp.authToken SecretRef resolved to empty value (source=\"${ref.source}\", provider=\"${\n ref.provider ?? \"\"\n }\") — refusing to start the HTTP bridge with an empty bearer token.`,\n );\n }\n\n resolvedCache.set(cacheKey, resolved);\n return resolved;\n}\n\n/**\n * Returns true if the value is a SecretRef object (issue #757). Useful for\n * surfaces (CLI flags, doctor checks) that want to render a redacted\n * placeholder instead of leaking the unresolved object shape.\n */\nexport function isAgentAccessSecretRef(value: unknown): value is SecretRef {\n if (!isPlainObject(value)) return false;\n const ref = value as Record<string, unknown>;\n return typeof ref.source === \"string\" && ref.source.trim().length > 0;\n}\n\n/** Test/operations hook: drop the cache and force resolver rediscovery. */\nexport function clearAuthTokenSecretCache(): void {\n resolvedCache.clear();\n}\n"],"mappings":";AAuCA,IAAM,gBAAgB,oBAAI,IAAoB;AAO9C,SAAS,qBAAqB,KAAwB;AACpD,QAAM,aAAa,OAAO,KAAK,GAAG,EAAE,KAAK;AACzC,QAAM,SAAkC,CAAC;AACzC,aAAW,OAAO,YAAY;AAC5B,WAAO,GAAG,IAAI,IAAI,GAAG;AAAA,EACvB;AACA,SAAO,KAAK,UAAU,MAAM;AAC9B;AAEA,SAAS,cAAc,OAAkD;AACvE,SAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;AASA,eAAsB,4BACpB,OACA,UAA8C,CAAC,GAClB;AAC7B,MAAI,UAAU,UAAa,UAAU,KAAM,QAAO;AAElD,MAAI,OAAO,UAAU,UAAU;AAC7B,UAAM,UAAU,MAAM,KAAK;AAC3B,WAAO,QAAQ,SAAS,IAAI,UAAU;AAAA,EACxC;AAEA,MAAI,CAAC,cAAc,KAAK,GAAG;AACzB,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AAEA,QAAM,MAAM;AACZ,MAAI,OAAO,IAAI,WAAW,YAAY,IAAI,OAAO,KAAK,EAAE,WAAW,GAAG;AACpE,UAAM,IAAI;AAAA,MACR;AAAA,IAGF;AAAA,EACF;AAEA,QAAM,WAAW,qBAAqB,GAAG;AACzC,QAAM,SAAS,cAAc,IAAI,QAAQ;AACzC,MAAI,WAAW,OAAW,QAAO;AAEjC,QAAM,WAAW,QAAQ,oBAAoB;AAC7C,MAAI,CAAC,UAAU;AACb,UAAM,IAAI;AAAA,MACR,+DAA+D,IAAI,MAAM;AAAA,IAK3E;AAAA,EACF;AAEA,MAAI;AACJ,MAAI;AACF,UAAM,MAAM,MAAM,SAAS,GAAG;AAC9B,QAAI,OAAO,QAAQ,UAAU;AAC3B,YAAM,UAAU,IAAI,KAAK;AACzB,UAAI,QAAQ,SAAS,EAAG,YAAW;AAAA,IACrC;AAAA,EACF,SAAS,KAAK;AACZ,UAAM,IAAI;AAAA,MACR,kEAAkE,IAAI,MAAM,OAC1E,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG,CACjD;AAAA,IACF;AAAA,EACF;AAEA,MAAI,CAAC,UAAU;AACb,UAAM,IAAI;AAAA,MACR,wEAAwE,IAAI,MAAM,gBAChF,IAAI,YAAY,EAClB;AAAA,IACF;AAAA,EACF;AAEA,gBAAc,IAAI,UAAU,QAAQ;AACpC,SAAO;AACT;AAOO,SAAS,uBAAuB,OAAoC;AACzE,MAAI,CAAC,cAAc,KAAK,EAAG,QAAO;AAClC,QAAM,MAAM;AACZ,SAAO,OAAO,IAAI,WAAW,YAAY,IAAI,OAAO,KAAK,EAAE,SAAS;AACtE;AAGO,SAAS,4BAAkC;AAChD,gBAAc,MAAM;AACtB;","names":[]}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import {
|
|
2
|
+
expandTildePath
|
|
3
|
+
} from "./chunk-IXEJRKCZ.js";
|
|
4
|
+
import {
|
|
5
|
+
launchProcessSync
|
|
6
|
+
} from "./chunk-OR64ZGRZ.js";
|
|
7
|
+
|
|
8
|
+
// src/coding/git-context.ts
|
|
9
|
+
import path from "path";
|
|
10
|
+
var DEFAULT_GIT_TIMEOUT_MS = 2e3;
|
|
11
|
+
function defaultGitInvoker() {
|
|
12
|
+
return (cwd, args) => {
|
|
13
|
+
const result = launchProcessSync("git", args, {
|
|
14
|
+
cwd,
|
|
15
|
+
encoding: "utf-8",
|
|
16
|
+
timeout: DEFAULT_GIT_TIMEOUT_MS,
|
|
17
|
+
shell: false
|
|
18
|
+
});
|
|
19
|
+
if (result.error) {
|
|
20
|
+
return { stdout: "", exitCode: 127 };
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
stdout: typeof result.stdout === "string" ? result.stdout : "",
|
|
24
|
+
exitCode: typeof result.status === "number" ? result.status : 1
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function stableHash(input) {
|
|
29
|
+
let hash = 2166136261;
|
|
30
|
+
for (let i = 0; i < input.length; i++) {
|
|
31
|
+
hash ^= input.charCodeAt(i);
|
|
32
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
33
|
+
}
|
|
34
|
+
return hash.toString(16).padStart(8, "0");
|
|
35
|
+
}
|
|
36
|
+
function normalizeOriginUrl(rawUrl) {
|
|
37
|
+
let url = rawUrl.trim();
|
|
38
|
+
if (!url) return "";
|
|
39
|
+
if (/\.git$/i.test(url)) url = url.slice(0, -4);
|
|
40
|
+
if (/^[A-Za-z]:[\\/]/.test(url)) {
|
|
41
|
+
return url.toLowerCase();
|
|
42
|
+
}
|
|
43
|
+
const protoMatch = /^[a-z][a-z0-9+.-]*:\/\/(?:[^@/]+@)?(\[[^\]]+\]|[^/:]*)(?::(\d+))?(\/.*)?$/i.exec(url);
|
|
44
|
+
if (protoMatch) {
|
|
45
|
+
let host = protoMatch[1] ?? "";
|
|
46
|
+
const wasBracketed = host.startsWith("[") && host.endsWith("]");
|
|
47
|
+
if (wasBracketed) host = host.slice(1, -1);
|
|
48
|
+
const port = protoMatch[2];
|
|
49
|
+
const repoPath = (protoMatch[3] ?? "").replace(/^\/+/, "");
|
|
50
|
+
const hostPort = port ? wasBracketed ? `[${host}]:${port}` : `${host}:${port}` : host;
|
|
51
|
+
const prefix = hostPort.length > 0 ? hostPort : "localhost";
|
|
52
|
+
return `${prefix}/${repoPath}`.toLowerCase();
|
|
53
|
+
}
|
|
54
|
+
const scpMatch = /^(?:([^@\s/]+)@)?(\[[^\]]+\]|[^:@\s/]+):(.+)$/.exec(url);
|
|
55
|
+
if (scpMatch) {
|
|
56
|
+
let host = scpMatch[2] ?? "";
|
|
57
|
+
if (host.startsWith("[") && host.endsWith("]")) host = host.slice(1, -1);
|
|
58
|
+
const repoPath = scpMatch[3] ?? "";
|
|
59
|
+
if (repoPath.startsWith("//")) {
|
|
60
|
+
return url.toLowerCase();
|
|
61
|
+
}
|
|
62
|
+
return `${host}/${repoPath.replace(/^\/+/, "")}`.toLowerCase();
|
|
63
|
+
}
|
|
64
|
+
return url.toLowerCase();
|
|
65
|
+
}
|
|
66
|
+
async function resolveGitContext(cwd, options = {}) {
|
|
67
|
+
try {
|
|
68
|
+
if (typeof cwd !== "string" || cwd.length === 0) return null;
|
|
69
|
+
const expanded = expandTildePath(cwd);
|
|
70
|
+
if (!path.isAbsolute(expanded)) return null;
|
|
71
|
+
const invoker = options.invoker ?? defaultGitInvoker();
|
|
72
|
+
const topLevel = invoker(expanded, ["rev-parse", "--show-toplevel"]);
|
|
73
|
+
if (topLevel.exitCode !== 0) return null;
|
|
74
|
+
const rootPath = topLevel.stdout.trim();
|
|
75
|
+
if (!rootPath) return null;
|
|
76
|
+
const branchResult = invoker(rootPath, ["rev-parse", "--abbrev-ref", "HEAD"]);
|
|
77
|
+
let branch = null;
|
|
78
|
+
if (branchResult.exitCode === 0) {
|
|
79
|
+
const raw = branchResult.stdout.trim();
|
|
80
|
+
branch = raw && raw !== "HEAD" ? raw : null;
|
|
81
|
+
} else {
|
|
82
|
+
const unbornRef = invoker(rootPath, ["symbolic-ref", "--quiet", "HEAD"]);
|
|
83
|
+
if (unbornRef.exitCode === 0) {
|
|
84
|
+
const raw = unbornRef.stdout.trim();
|
|
85
|
+
const prefix = "refs/heads/";
|
|
86
|
+
if (raw.startsWith(prefix)) {
|
|
87
|
+
const candidate = raw.slice(prefix.length);
|
|
88
|
+
if (candidate) branch = candidate;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const originResult = invoker(rootPath, ["remote", "get-url", "origin"]);
|
|
93
|
+
let projectId;
|
|
94
|
+
if (originResult.exitCode === 0) {
|
|
95
|
+
const normalized = normalizeOriginUrl(originResult.stdout);
|
|
96
|
+
projectId = normalized ? `origin:${stableHash(normalized)}` : `root:${stableHash(rootPath)}`;
|
|
97
|
+
} else {
|
|
98
|
+
projectId = `root:${stableHash(rootPath)}`;
|
|
99
|
+
}
|
|
100
|
+
const headRef = invoker(rootPath, ["symbolic-ref", "--quiet", "refs/remotes/origin/HEAD"]);
|
|
101
|
+
let defaultBranch = null;
|
|
102
|
+
if (headRef.exitCode === 0) {
|
|
103
|
+
const raw = headRef.stdout.trim();
|
|
104
|
+
const prefix = "refs/remotes/origin/";
|
|
105
|
+
if (raw.startsWith(prefix)) {
|
|
106
|
+
const candidate = raw.slice(prefix.length);
|
|
107
|
+
if (candidate) defaultBranch = candidate;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return {
|
|
111
|
+
projectId,
|
|
112
|
+
branch,
|
|
113
|
+
rootPath,
|
|
114
|
+
defaultBranch
|
|
115
|
+
};
|
|
116
|
+
} catch {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/procedural/reinforcement-core.ts
|
|
122
|
+
function clusterByKey(items, keyFn) {
|
|
123
|
+
const clusters = /* @__PURE__ */ new Map();
|
|
124
|
+
for (const item of items) {
|
|
125
|
+
const key = keyFn(item);
|
|
126
|
+
if (typeof key !== "string") {
|
|
127
|
+
throw new TypeError(
|
|
128
|
+
`clusterByKey: keyFn must return a string, got ${key === null ? "null" : typeof key}`
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
const existing = clusters.get(key);
|
|
132
|
+
if (existing) {
|
|
133
|
+
existing.push(item);
|
|
134
|
+
} else {
|
|
135
|
+
clusters.set(key, [item]);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return clusters;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export {
|
|
142
|
+
clusterByKey,
|
|
143
|
+
stableHash,
|
|
144
|
+
normalizeOriginUrl,
|
|
145
|
+
resolveGitContext
|
|
146
|
+
};
|
|
147
|
+
//# sourceMappingURL=chunk-NN3TS5BM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/coding/git-context.ts","../src/procedural/reinforcement-core.ts"],"sourcesContent":["/**\n * GitContextResolver — pure module for detecting the git project + branch\n * a session is operating in.\n *\n * Introduced by issue #569 (coding-agent project/branch-scoped namespaces).\n *\n * This module is deliberately pure:\n * - no orchestrator references\n * - no config side-effects\n * - no namespace wiring\n *\n * Downstream slices (PR 2+ of #569) wire `resolveGitContext` into the\n * `NamespaceResolver` / `Orchestrator` so that memories are scoped to a\n * detected project / branch without leaking across repos.\n *\n * CLAUDE.md rule 17 (expand `~`): the `rootPath` returned here is always an\n * absolute, tilde-expanded path. Callers must not re-expand.\n *\n * CLAUDE.md rule 51 (reject invalid input): `cwd` must be an absolute path\n * and must exist. `resolveGitContext` returns `null` — rather than throwing —\n * when the directory is not inside a git worktree, because being outside a\n * repo is a normal runtime state (e.g. agent opened in a scratch dir).\n */\nimport path from \"node:path\";\n\nimport { expandTildePath } from \"../utils/path.js\";\nimport { launchProcessSync } from \"../runtime/child-process.js\";\n\n// Re-export so existing callers / tests that imported `expandTildePath` from\n// this module keep working. CLAUDE.md #17 requires consistent `~` expansion\n// across every user-facing path input; the canonical implementation now\n// lives in `utils/path.ts`.\nexport { expandTildePath };\n\n// ──────────────────────────────────────────────────────────────────────────\n// Public types\n// ──────────────────────────────────────────────────────────────────────────\n\nexport interface GitContext {\n /**\n * Stable identifier for the project. Derived from `git remote get-url origin`\n * when an origin remote is configured, otherwise from the repo root path.\n *\n * Formatted as `origin:<hex>` or `root:<hex>` so that the source is visible\n * to operators (see `remnic doctor`, issue #569 acceptance criteria).\n */\n projectId: string;\n /**\n * Current branch, e.g. `main`, `feat/foo`. `null` only in detached-HEAD\n * state (e.g. rebase in progress). Callers should treat `null` as \"no\n * branch-scope overlay applies\" without erroring.\n */\n branch: string | null;\n /**\n * Absolute path to the repository root (the directory containing `.git`).\n * Tilde-expanded per CLAUDE.md #17.\n */\n rootPath: string;\n /**\n * Best-effort default branch (usually `main` or `master`). Derived from the\n * `refs/remotes/origin/HEAD` symbolic ref. `null` when not available (e.g.\n * fresh clone without a default branch symref, or no origin remote).\n */\n defaultBranch: string | null;\n}\n\n/**\n * Injectable git-invocation surface. Only the commands `resolveGitContext`\n * actually needs are exposed. Tests inject a mock implementation to avoid\n * spawning a real git process.\n */\nexport interface GitInvoker {\n /**\n * Run `git <args>` with `cwd` as the working directory. Must return\n * `{ stdout, exitCode }` with `stdout` trimmed by the caller as needed.\n * Implementations should NOT throw for non-zero exit codes — they should\n * return the exit code so the resolver can decide how to recover.\n */\n (cwd: string, args: string[]): { stdout: string; exitCode: number };\n}\n\n// ──────────────────────────────────────────────────────────────────────────\n// Default git invoker — spawns real `git` via the shared child-process helper\n// ──────────────────────────────────────────────────────────────────────────\n\nconst DEFAULT_GIT_TIMEOUT_MS = 2_000;\n\nexport function defaultGitInvoker(): GitInvoker {\n return (cwd: string, args: string[]) => {\n const result = launchProcessSync(\"git\", args, {\n cwd,\n encoding: \"utf-8\",\n timeout: DEFAULT_GIT_TIMEOUT_MS,\n shell: false,\n });\n if (result.error) {\n // Spawn failure (git not on PATH, timeout, etc.). Surface as non-zero.\n return { stdout: \"\", exitCode: 127 };\n }\n return {\n stdout: typeof result.stdout === \"string\" ? result.stdout : \"\",\n exitCode: typeof result.status === \"number\" ? result.status : 1,\n };\n };\n}\n\n// ──────────────────────────────────────────────────────────────────────────\n// Stable hashing\n// ──────────────────────────────────────────────────────────────────────────\n\n/**\n * Non-cryptographic stable hash. Used only to derive a deterministic\n * `projectId` from either the origin URL or the root path. The hash does not\n * need to be collision-resistant against adversarial input — it is purely a\n * namespace discriminator.\n *\n * Uses FNV-1a 32-bit so we don't pull in `node:crypto` for a simple bucket\n * key. Output is lowercase hex, zero-padded to 8 characters.\n */\nexport function stableHash(input: string): string {\n let hash = 0x811c9dc5;\n for (let i = 0; i < input.length; i++) {\n hash ^= input.charCodeAt(i);\n hash = Math.imul(hash, 0x01000193) >>> 0;\n }\n return hash.toString(16).padStart(8, \"0\");\n}\n\n// ──────────────────────────────────────────────────────────────────────────\n// Origin URL normalization\n// ──────────────────────────────────────────────────────────────────────────\n\n/**\n * Normalize a git remote URL so that equivalent SSH / HTTPS forms of the\n * same repo produce the same `projectId`. Handles:\n * - `git@github.com:foo/bar.git` → `github.com/foo/bar`\n * - `https://github.com/foo/bar` → `github.com/foo/bar`\n * - `https://github.com/foo/bar.git` → `github.com/foo/bar`\n * - `ssh://git@github.com/foo/bar` → `github.com/foo/bar`\n * - `ssh://git@github.com:2222/foo/bar` → `github.com/foo/bar` (port stripped)\n *\n * Case-insensitive (remote hostnames and most repo paths on major forges are\n * case-insensitive in practice).\n */\nexport function normalizeOriginUrl(rawUrl: string): string {\n let url = rawUrl.trim();\n if (!url) return \"\";\n\n // Strip trailing `.git` case-insensitively — the whole result is\n // lowercased at the end, so `.GIT` / `.Git` must be treated the same as\n // `.git`. Previously the `.endsWith(\".git\")` check let `.GIT` leak\n // through and appear in the output.\n if (/\\.git$/i.test(url)) url = url.slice(0, -4);\n\n // Windows drive-letter local path (e.g. `C:/repos/app`): detect here\n // so the scp matcher below can accept single-character SSH host aliases\n // (`h:foo/bar` from `.ssh/config`). A drive letter is exactly one ASCII\n // letter followed by `:/` or `:\\`; SSH aliases never have a slash\n // immediately after the colon.\n if (/^[A-Za-z]:[\\\\/]/.test(url)) {\n return url.toLowerCase();\n }\n\n // Protocol-prefixed: ssh://, https://, http://, git://, file://\n // Must be tried FIRST so that scp-style detection below doesn't\n // incorrectly swallow an ssh:// URL that happens to contain `:port/`.\n //\n // Matches:\n // 1: host — bracketed IPv6 `[2001:db8::1]`, plain host with no `:` / `/`,\n // OR empty (for `file:///path` which has no host component).\n // 2: port (optional) — preserved in the output so two repos on the same\n // host under different ports get distinct project namespaces.\n // Losing the port risked false-coalescing separate repos on custom\n // SSH mesh setups.\n // 3: path (optional)\n const protoMatch =\n /^[a-z][a-z0-9+.-]*:\\/\\/(?:[^@/]+@)?(\\[[^\\]]+\\]|[^/:]*)(?::(\\d+))?(\\/.*)?$/i.exec(url);\n if (protoMatch) {\n let host = protoMatch[1] ?? \"\";\n // Detect IPv6 via the bracketed input form BEFORE stripping brackets,\n // so that when we later re-attach a port we can preserve the\n // `[host]:port` boundary. Without the brackets, `host:2222` is\n // ambiguous with a longer bare IPv6 address like `2001:db8::1:2222`.\n const wasBracketed =\n host.startsWith(\"[\") && host.endsWith(\"]\");\n if (wasBracketed) host = host.slice(1, -1);\n const port = protoMatch[2];\n const repoPath = (protoMatch[3] ?? \"\").replace(/^\\/+/, \"\");\n const hostPort = port\n ? wasBracketed\n ? `[${host}]:${port}`\n : `${host}:${port}`\n : host;\n // For protocols without a host component (file:///path), fall back to\n // a stable prefix so distinct local paths don't collapse to \"/path\".\n const prefix = hostPort.length > 0 ? hostPort : \"localhost\";\n return `${prefix}/${repoPath}`.toLowerCase();\n }\n\n // scp-like syntax: [user@]host:path. Protocol-prefixed URLs (`scheme://`)\n // are handled above, so the scp branch below guards against them: a\n // matched `host` of `scheme` followed by a path starting with `//` is\n // a protocol URL that fell through and must NOT be parsed here.\n // `user@` is optional — git also accepts userless scp forms like\n // `host:org/repo`. Valid scp paths may start with digits (e.g.\n // `git@host:123/repo.git`), so no numeric guard is needed: port-bearing\n // URLs have the `://` prefix and match the protocol branch above before\n // reaching here.\n //\n // Windows drive letters were filtered above, so single-character SSH\n // host aliases (`h:foo/bar`) are accepted here.\n //\n // Bracketed IPv6 (`[2001:db8::1]`) is supported: the host alternative\n // matches the bracketed literal up to `]` without splitting on internal\n // `:`. Brackets are stripped in the normalised form so the scp and\n // `ssh://` forms of the same IPv6 remote produce identical projectIds.\n const scpMatch =\n /^(?:([^@\\s/]+)@)?(\\[[^\\]]+\\]|[^:@\\s/]+):(.+)$/.exec(url);\n if (scpMatch) {\n let host = scpMatch[2] ?? \"\";\n if (host.startsWith(\"[\") && host.endsWith(\"]\")) host = host.slice(1, -1);\n const repoPath = scpMatch[3] ?? \"\";\n // Reject protocol-like leftovers (e.g. `file:///path` where the scp\n // regex greedily matched `file` as host and `///path` as path).\n if (repoPath.startsWith(\"//\")) {\n return url.toLowerCase();\n }\n return `${host}/${repoPath.replace(/^\\/+/, \"\")}`.toLowerCase();\n }\n\n // Fallback: use raw lowercased\n return url.toLowerCase();\n}\n\n// ──────────────────────────────────────────────────────────────────────────\n// Resolver\n// ──────────────────────────────────────────────────────────────────────────\n\nexport interface ResolveGitContextOptions {\n /** Inject a git invoker (tests). Defaults to spawning real `git`. */\n invoker?: GitInvoker;\n}\n\n/**\n * Detect the git project + branch for `cwd`.\n *\n * Returns `null` when:\n * - `cwd` is not an absolute path (invalid input, CLAUDE.md #51)\n * - `cwd` is not inside a git worktree\n * - `git` is not available on PATH\n *\n * Never throws.\n */\nexport async function resolveGitContext(\n cwd: string,\n options: ResolveGitContextOptions = {},\n): Promise<GitContext | null> {\n // Wrap the whole body so the documented \"Never throws\" contract is\n // enforced. Possible throw sites include:\n // - `expandTildePath` → `resolveHomeDir()` → `os.homedir()` when HOME\n // is unset (e.g. minimal containers)\n // - a custom `options.invoker` that raises instead of returning a\n // non-zero exitCode\n // - any future helper added to this chain\n // All of those map to \"not in a repo\" / `null`.\n try {\n // Validate input: must be a non-empty string.\n if (typeof cwd !== \"string\" || cwd.length === 0) return null;\n\n // Expand `~` per CLAUDE.md #17, then require absolute path.\n const expanded = expandTildePath(cwd);\n if (!path.isAbsolute(expanded)) return null;\n\n const invoker = options.invoker ?? defaultGitInvoker();\n\n // 1. Locate the repo root.\n const topLevel = invoker(expanded, [\"rev-parse\", \"--show-toplevel\"]);\n if (topLevel.exitCode !== 0) return null;\n const rootPath = topLevel.stdout.trim();\n if (!rootPath) return null;\n\n // 2. Current branch. `--abbrev-ref HEAD` returns `HEAD` in detached\n // state, which we normalize to `null`. On a fresh `git init` the\n // HEAD ref is unborn and `--abbrev-ref HEAD` fails, but\n // `symbolic-ref HEAD` still returns the target branch. Fall back\n // so newly-initialized repos get a sensible branch name.\n const branchResult = invoker(rootPath, [\"rev-parse\", \"--abbrev-ref\", \"HEAD\"]);\n let branch: string | null = null;\n if (branchResult.exitCode === 0) {\n const raw = branchResult.stdout.trim();\n branch = raw && raw !== \"HEAD\" ? raw : null;\n } else {\n const unbornRef = invoker(rootPath, [\"symbolic-ref\", \"--quiet\", \"HEAD\"]);\n if (unbornRef.exitCode === 0) {\n const raw = unbornRef.stdout.trim();\n const prefix = \"refs/heads/\";\n if (raw.startsWith(prefix)) {\n const candidate = raw.slice(prefix.length);\n if (candidate) branch = candidate;\n }\n }\n }\n\n // 3. Origin URL — optional. Used to derive a stable `projectId`.\n const originResult = invoker(rootPath, [\"remote\", \"get-url\", \"origin\"]);\n let projectId: string;\n if (originResult.exitCode === 0) {\n const normalized = normalizeOriginUrl(originResult.stdout);\n projectId = normalized ? `origin:${stableHash(normalized)}` : `root:${stableHash(rootPath)}`;\n } else {\n projectId = `root:${stableHash(rootPath)}`;\n }\n\n // 4. Default branch — best effort.\n const headRef = invoker(rootPath, [\"symbolic-ref\", \"--quiet\", \"refs/remotes/origin/HEAD\"]);\n let defaultBranch: string | null = null;\n if (headRef.exitCode === 0) {\n const raw = headRef.stdout.trim();\n const prefix = \"refs/remotes/origin/\";\n if (raw.startsWith(prefix)) {\n const candidate = raw.slice(prefix.length);\n if (candidate) defaultBranch = candidate;\n }\n }\n\n return {\n projectId,\n branch,\n rootPath,\n defaultBranch,\n };\n } catch {\n // Never throws — any unexpected error falls back to \"not in a repo\".\n return null;\n }\n}\n","/**\n * Generic reinforcement-core primitives extracted from `procedure-miner.ts`\n * (issue #687 PR 1/4). Procedure-specific scoring (success rate, step\n * normalization) intentionally stays in the miner — this module only\n * exposes category-agnostic clustering and cluster summarization helpers\n * so future PRs can run reinforcement across non-procedural categories.\n *\n * Pure refactor — no behavior change.\n */\n\n/**\n * Group `items` into clusters keyed by `keyFn(item)`.\n *\n * - Preserves the original input order within each cluster's array.\n * - The returned `Map` insertion order matches first-seen key order, so\n * downstream iteration is deterministic for a given input.\n * - Throws `TypeError` if `keyFn` returns a non-string (e.g. `undefined`,\n * `null`, or a number). Callers must produce a stable string key.\n */\nexport function clusterByKey<T>(items: readonly T[], keyFn: (item: T) => string): Map<string, T[]> {\n const clusters = new Map<string, T[]>();\n for (const item of items) {\n const key = keyFn(item);\n if (typeof key !== \"string\") {\n throw new TypeError(\n `clusterByKey: keyFn must return a string, got ${key === null ? \"null\" : typeof key}`,\n );\n }\n const existing = clusters.get(key);\n if (existing) {\n existing.push(item);\n } else {\n clusters.set(key, [item]);\n }\n }\n return clusters;\n}\n\nexport interface ClusterSummary {\n /** Number of items in the cluster. */\n count: number;\n /** Earliest timestamp seen in the cluster (string min via `localeCompare`). */\n firstSeen: string;\n /** Latest timestamp seen in the cluster (string max via `localeCompare`). */\n lastSeen: string;\n}\n\n/**\n * Summarize a cluster by counting items and tracking earliest/latest\n * timestamps. Timestamp comparison uses `String#localeCompare`, which is\n * correct for ISO-8601 strings (lexicographic order matches chronological\n * order).\n *\n * - Throws `RangeError` on empty clusters — `firstSeen`/`lastSeen` are not\n * meaningful without at least one item.\n * - When all timestamps are equal, `firstSeen === lastSeen`.\n */\nexport function summarizeCluster<T>(\n cluster: readonly T[],\n extractTimestamp: (item: T) => string,\n): ClusterSummary {\n if (cluster.length === 0) {\n throw new RangeError(\"summarizeCluster: cluster must contain at least one item\");\n }\n let firstSeen = extractTimestamp(cluster[0]);\n let lastSeen = firstSeen;\n for (let i = 1; i < cluster.length; i += 1) {\n const ts = extractTimestamp(cluster[i]);\n if (ts.localeCompare(firstSeen) < 0) firstSeen = ts;\n if (ts.localeCompare(lastSeen) > 0) lastSeen = ts;\n }\n return { count: cluster.length, firstSeen, lastSeen };\n}\n"],"mappings":";;;;;;;;AAuBA,OAAO,UAAU;AA8DjB,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