@remnic/core 1.1.2 → 1.1.3
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 +70 -45
- package/dist/access-cli.js.map +1 -1
- package/dist/access-http.d.ts +50 -5
- package/dist/access-http.js +37 -15
- package/dist/access-idempotency.js +1 -0
- package/dist/access-mcp.d.ts +10 -5
- package/dist/access-mcp.js +36 -13
- package/dist/access-schema.d.ts +133 -13
- package/dist/access-schema.js +20 -1
- package/dist/access-service-_AEUMVyX.d.ts +1981 -0
- package/dist/access-service.d.ts +11 -6
- package/dist/access-service.js +38 -14
- 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 +9 -6
- 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 +11 -8
- 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-VDX363PS.js → chunk-34F3PLWZ.js} +10 -3
- package/dist/chunk-34F3PLWZ.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-OC5OXUQ4.js → chunk-4PLGJRBV.js} +653 -17
- package/dist/chunk-4PLGJRBV.js.map +1 -0
- package/dist/{chunk-PVICZTKG.js → chunk-55FXRRSJ.js} +5 -5
- package/dist/{chunk-PVICZTKG.js.map → chunk-55FXRRSJ.js.map} +1 -1
- package/dist/{chunk-ULYOGL6R.js → chunk-5HRY2WRF.js} +7 -3
- package/dist/chunk-5HRY2WRF.js.map +1 -0
- 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-6YJHX2DL.js → chunk-7GCMLT7J.js} +242 -22
- package/dist/chunk-7GCMLT7J.js.map +1 -0
- package/dist/chunk-A6XUJE5D.js +126 -0
- package/dist/chunk-A6XUJE5D.js.map +1 -0
- package/dist/chunk-AJA46VX5.js +393 -0
- package/dist/chunk-AJA46VX5.js.map +1 -0
- package/dist/{chunk-UWB5LMWY.js → chunk-AKUCB2OG.js} +525 -24
- package/dist/chunk-AKUCB2OG.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-F5VP6YCB.js → chunk-DCE6SQLA.js} +572 -155
- package/dist/chunk-DCE6SQLA.js.map +1 -0
- package/dist/{chunk-CUPFXL3J.js → chunk-DHRQHX36.js} +4 -4
- package/dist/chunk-DHRQHX36.js.map +1 -0
- package/dist/{chunk-STGWEHYR.js → chunk-DR7MCMPS.js} +981 -61
- package/dist/chunk-DR7MCMPS.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-3YGHKTBF.js → chunk-IM3JSE73.js} +953 -322
- package/dist/chunk-IM3JSE73.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-SPI27QT6.js → chunk-L5IIGA5V.js} +9 -4
- package/dist/chunk-L5IIGA5V.js.map +1 -0
- package/dist/{chunk-XXVWLXSG.js → chunk-LVYGDT5V.js} +56 -82
- package/dist/chunk-LVYGDT5V.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-3OGMS3PE.js → chunk-LZRYQK6L.js} +3 -2
- package/dist/chunk-LZRYQK6L.js.map +1 -0
- package/dist/chunk-MDYG7VI7.js +48 -0
- package/dist/chunk-MDYG7VI7.js.map +1 -0
- package/dist/chunk-MXC3AP5I.js +74 -0
- package/dist/chunk-MXC3AP5I.js.map +1 -0
- package/dist/{chunk-DIXB44VE.js → chunk-N7X62G74.js} +25 -10
- package/dist/chunk-N7X62G74.js.map +1 -0
- package/dist/chunk-NN3TS5BM.js +147 -0
- package/dist/chunk-NN3TS5BM.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-NBVAS5MT.js → chunk-R2L7SUX2.js} +6 -6
- 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-L7IXWRYE.js → chunk-SS253RXF.js} +22 -13
- package/dist/chunk-SS253RXF.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-GA5P7RST.js → chunk-VTJVUHRK.js} +22 -36
- package/dist/chunk-VTJVUHRK.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-FVA6TGI3.js → chunk-Y3WQ4ZWK.js} +42 -2
- package/dist/chunk-Y3WQ4ZWK.js.map +1 -0
- package/dist/chunk-YNJHCGDT.js +309 -0
- package/dist/chunk-YNJHCGDT.js.map +1 -0
- package/dist/{chunk-LOIMBRDE.js → chunk-ZGXSCMQN.js} +1993 -411
- package/dist/chunk-ZGXSCMQN.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-x2APT9a6.d.ts} +26 -7
- package/dist/cli.d.ts +11 -6
- package/dist/cli.js +67 -33
- 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-72LSIWQP.js → engine-ICC2DSQF.js} +10 -7
- package/dist/engine-ICC2DSQF.js.map +1 -0
- package/dist/entity-retrieval.d.ts +1 -1
- package/dist/entity-retrieval.js +9 -6
- 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 +7 -6
- 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 +562 -13
- package/dist/index.js +329 -67
- 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-KG52RITE.js +37 -0
- package/dist/memory-governance-KG52RITE.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-D3vBHS4J.d.ts} +1 -0
- package/dist/memory-projection-store.d.ts +1 -1
- package/dist/memory-projection-store.js +1 -0
- 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 +28 -16
- 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 +55 -39
- 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 +37 -24
- 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 +11 -6
- package/dist/semantic-rule-promotion.d.ts +1 -1
- package/dist/semantic-rule-promotion.js +9 -6
- package/dist/semantic-rule-verifier.d.ts +1 -1
- package/dist/semantic-rule-verifier.js +9 -6
- 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 +8 -5
- 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 +9 -6
- package/dist/version-utils.js +1 -0
- package/dist/whitespace.js +1 -0
- package/dist/work-product-ledger.js +1 -0
- package/package.json +2 -1
- 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/{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-R2L7SUX2.js.map} +0 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import {
|
|
2
|
+
gatherConsoleState
|
|
3
|
+
} from "./chunk-TYEOAFH3.js";
|
|
4
|
+
|
|
5
|
+
// src/console/tui.ts
|
|
6
|
+
var ANSI_CLEAR_HOME = "\x1B[2J\x1B[H";
|
|
7
|
+
var ANSI_HIDE_CURSOR = "\x1B[?25l";
|
|
8
|
+
var ANSI_SHOW_CURSOR = "\x1B[?25h";
|
|
9
|
+
var FRAME_INNER_WIDTH = 70;
|
|
10
|
+
var DEFAULT_REFRESH_INTERVAL_MS = 2e3;
|
|
11
|
+
function runConsoleTui(orchestrator, options = {}) {
|
|
12
|
+
const refreshIntervalMs = Math.max(
|
|
13
|
+
50,
|
|
14
|
+
options.refreshIntervalMs ?? DEFAULT_REFRESH_INTERVAL_MS
|
|
15
|
+
);
|
|
16
|
+
const output = options.output ?? process.stdout;
|
|
17
|
+
const now = options.now ?? (() => Date.now());
|
|
18
|
+
const installSigintHandler = options.installSigintHandler ?? true;
|
|
19
|
+
let stopped = false;
|
|
20
|
+
let inFlight = false;
|
|
21
|
+
let inFlightTickPromise = null;
|
|
22
|
+
let traceWritePending = false;
|
|
23
|
+
let traceFramesDropped = 0;
|
|
24
|
+
let resolveDone;
|
|
25
|
+
const done = new Promise((resolve) => {
|
|
26
|
+
resolveDone = resolve;
|
|
27
|
+
});
|
|
28
|
+
safeWrite(output, ANSI_HIDE_CURSOR);
|
|
29
|
+
const tick = async () => {
|
|
30
|
+
if (stopped || inFlight) return;
|
|
31
|
+
inFlight = true;
|
|
32
|
+
try {
|
|
33
|
+
let snapshot = null;
|
|
34
|
+
let renderError = null;
|
|
35
|
+
try {
|
|
36
|
+
snapshot = await gatherConsoleState(orchestrator);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
renderError = describeError(err);
|
|
39
|
+
}
|
|
40
|
+
if (stopped) return;
|
|
41
|
+
let frame;
|
|
42
|
+
try {
|
|
43
|
+
frame = renderFrame({ snapshot, renderError, now });
|
|
44
|
+
} catch (err) {
|
|
45
|
+
frame = `remnic console: render failed: ${describeError(err)}
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
safeWrite(output, ANSI_CLEAR_HOME);
|
|
49
|
+
safeWrite(output, frame);
|
|
50
|
+
if (snapshot && options.traceRecorder && !traceWritePending) {
|
|
51
|
+
traceWritePending = true;
|
|
52
|
+
void options.traceRecorder.append(snapshot).catch(() => {
|
|
53
|
+
}).finally(() => {
|
|
54
|
+
traceWritePending = false;
|
|
55
|
+
});
|
|
56
|
+
} else if (snapshot && options.traceRecorder) {
|
|
57
|
+
traceFramesDropped += 1;
|
|
58
|
+
}
|
|
59
|
+
} finally {
|
|
60
|
+
inFlight = false;
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const launchTick = () => {
|
|
64
|
+
const p = runTickSafely(tick);
|
|
65
|
+
inFlightTickPromise = p;
|
|
66
|
+
void p.then(() => {
|
|
67
|
+
if (inFlightTickPromise === p) {
|
|
68
|
+
inFlightTickPromise = null;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
launchTick();
|
|
73
|
+
const handle = setInterval(launchTick, refreshIntervalMs);
|
|
74
|
+
const sigintHandler = () => {
|
|
75
|
+
stop();
|
|
76
|
+
};
|
|
77
|
+
if (installSigintHandler) {
|
|
78
|
+
process.on("SIGINT", sigintHandler);
|
|
79
|
+
}
|
|
80
|
+
const stop = () => {
|
|
81
|
+
if (stopped) return;
|
|
82
|
+
stopped = true;
|
|
83
|
+
clearInterval(handle);
|
|
84
|
+
if (installSigintHandler) {
|
|
85
|
+
try {
|
|
86
|
+
process.removeListener("SIGINT", sigintHandler);
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
safeWrite(output, ANSI_SHOW_CURSOR);
|
|
91
|
+
void (async () => {
|
|
92
|
+
try {
|
|
93
|
+
const pendingTick = inFlightTickPromise;
|
|
94
|
+
if (pendingTick) {
|
|
95
|
+
await pendingTick;
|
|
96
|
+
}
|
|
97
|
+
} finally {
|
|
98
|
+
resolveDone();
|
|
99
|
+
}
|
|
100
|
+
})();
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
stop,
|
|
104
|
+
done,
|
|
105
|
+
getDroppedTraceFrames: () => traceFramesDropped
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function renderFrame(input) {
|
|
109
|
+
const ts = new Date(input.now()).toISOString();
|
|
110
|
+
const lines = [];
|
|
111
|
+
lines.push(renderHeader(ts));
|
|
112
|
+
for (const panel of renderPanels(input)) {
|
|
113
|
+
lines.push(panel);
|
|
114
|
+
}
|
|
115
|
+
lines.push(renderFooter());
|
|
116
|
+
return lines.join("\n") + "\n";
|
|
117
|
+
}
|
|
118
|
+
function renderHeader(ts) {
|
|
119
|
+
const title = " remnic console ";
|
|
120
|
+
const trailing = ` ${ts} `;
|
|
121
|
+
const fillerLen = Math.max(
|
|
122
|
+
1,
|
|
123
|
+
FRAME_INNER_WIDTH - title.length - trailing.length
|
|
124
|
+
);
|
|
125
|
+
const filler = "\u2550".repeat(fillerLen);
|
|
126
|
+
return `\u2554${title}${filler}${trailing}\u2557`;
|
|
127
|
+
}
|
|
128
|
+
function renderFooter() {
|
|
129
|
+
return `\u255A${"\u2550".repeat(FRAME_INNER_WIDTH)}\u255D`;
|
|
130
|
+
}
|
|
131
|
+
function renderPanels(input) {
|
|
132
|
+
const lines = [];
|
|
133
|
+
const snap = input.snapshot;
|
|
134
|
+
if (input.renderError !== null) {
|
|
135
|
+
lines.push(panelLine("Error", `refresh failed: ${input.renderError}`));
|
|
136
|
+
lines.push(panelLine("Buffer", "(unavailable)"));
|
|
137
|
+
lines.push(panelLine("Extraction", "(unavailable)"));
|
|
138
|
+
lines.push(panelLine("Dedup", "(unavailable)"));
|
|
139
|
+
lines.push(panelLine("Maintenance", "(unavailable)"));
|
|
140
|
+
lines.push(panelLine("QMD", "(unavailable)"));
|
|
141
|
+
return lines;
|
|
142
|
+
}
|
|
143
|
+
if (snap) {
|
|
144
|
+
lines.push(
|
|
145
|
+
panelLine(
|
|
146
|
+
"Buffer",
|
|
147
|
+
`turns=${snap.bufferState.turnsCount} bytes=${snap.bufferState.byteCount}`
|
|
148
|
+
)
|
|
149
|
+
);
|
|
150
|
+
const verdicts = snap.extractionQueue.recentVerdicts;
|
|
151
|
+
const accepts = verdicts.filter((v) => v.kind === "accept").length;
|
|
152
|
+
const rejects = verdicts.filter((v) => v.kind === "reject").length;
|
|
153
|
+
lines.push(
|
|
154
|
+
panelLine(
|
|
155
|
+
"Extraction",
|
|
156
|
+
`queue=${snap.extractionQueue.depth} recent verdicts: accept(${accepts})/reject(${rejects})`
|
|
157
|
+
)
|
|
158
|
+
);
|
|
159
|
+
const dedupSummary = formatDedupSummary(snap.dedupRecent, input.now);
|
|
160
|
+
lines.push(panelLine("Dedup", dedupSummary));
|
|
161
|
+
const maintSummary = formatMaintenanceTail(snap.maintenanceLedgerTail);
|
|
162
|
+
lines.push(panelLine("Maintenance", maintSummary));
|
|
163
|
+
lines.push(panelLine("QMD", formatQmdSummary(snap)));
|
|
164
|
+
}
|
|
165
|
+
if (snap && snap.errors.length > 0) {
|
|
166
|
+
const head = snap.errors[0];
|
|
167
|
+
lines.push(panelLine("Errors", head ?? ""));
|
|
168
|
+
}
|
|
169
|
+
return lines;
|
|
170
|
+
}
|
|
171
|
+
function formatDedupSummary(decisions, now) {
|
|
172
|
+
if (decisions.length === 0) return "no recent decisions";
|
|
173
|
+
const last = decisions[decisions.length - 1];
|
|
174
|
+
if (!last) return "no recent decisions";
|
|
175
|
+
const ageMs = ageMsFromIso(last.ts, now);
|
|
176
|
+
const ageStr = ageMs === null ? "T-?" : `T-${Math.round(ageMs / 1e3)}s`;
|
|
177
|
+
const fp = last.fingerprint ? `hash=${last.fingerprint}` : "hash=?";
|
|
178
|
+
return `recent: ${fp} decision=${last.decision} (${ageStr})`;
|
|
179
|
+
}
|
|
180
|
+
function formatMaintenanceTail(events) {
|
|
181
|
+
if (events.length === 0) return "no events";
|
|
182
|
+
const last = events[events.length - 1];
|
|
183
|
+
if (!last) return "no events";
|
|
184
|
+
return `n=${events.length} last: ${last.category} ${truncate(last.summary, 40)}`;
|
|
185
|
+
}
|
|
186
|
+
function formatQmdSummary(snap) {
|
|
187
|
+
const probe = snap.qmdProbe.available ? "ok" : "down";
|
|
188
|
+
const uptimeH = snap.daemon.uptimeMs / 36e5;
|
|
189
|
+
const uptimeStr = uptimeH < 1 ? `${Math.round(snap.daemon.uptimeMs / 1e3)}s` : `${uptimeH.toFixed(1)}h`;
|
|
190
|
+
const mode = snap.qmdProbe.daemonMode ? "daemon" : "cli";
|
|
191
|
+
return `probe=${probe} mode=${mode} uptime=${uptimeStr}`;
|
|
192
|
+
}
|
|
193
|
+
function panelLine(label, value) {
|
|
194
|
+
const LABEL_WIDTH = 13;
|
|
195
|
+
const labelCol = padRight(label, LABEL_WIDTH);
|
|
196
|
+
const remaining = FRAME_INNER_WIDTH - LABEL_WIDTH - 2;
|
|
197
|
+
const valueCol = padRight(truncate(value, remaining), remaining);
|
|
198
|
+
return `\u2551 ${labelCol}${valueCol} \u2551`;
|
|
199
|
+
}
|
|
200
|
+
function padRight(s, width) {
|
|
201
|
+
if (s.length >= width) return s;
|
|
202
|
+
return s + " ".repeat(width - s.length);
|
|
203
|
+
}
|
|
204
|
+
function truncate(s, max) {
|
|
205
|
+
if (max <= 0) return "";
|
|
206
|
+
if (s.length <= max) return s;
|
|
207
|
+
if (max <= 1) return s.slice(0, max);
|
|
208
|
+
return s.slice(0, max - 1) + "\u2026";
|
|
209
|
+
}
|
|
210
|
+
function ageMsFromIso(iso, now) {
|
|
211
|
+
const ms = Date.parse(iso);
|
|
212
|
+
if (!Number.isFinite(ms)) return null;
|
|
213
|
+
const delta = now() - ms;
|
|
214
|
+
return delta < 0 ? 0 : delta;
|
|
215
|
+
}
|
|
216
|
+
async function runTickSafely(tick) {
|
|
217
|
+
try {
|
|
218
|
+
await tick();
|
|
219
|
+
} catch {
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
function safeWrite(output, chunk) {
|
|
223
|
+
try {
|
|
224
|
+
output.write(chunk);
|
|
225
|
+
} catch {
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function describeError(err) {
|
|
229
|
+
if (err instanceof Error) return err.message;
|
|
230
|
+
try {
|
|
231
|
+
return String(err);
|
|
232
|
+
} catch {
|
|
233
|
+
return "unknown error";
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function stripAnsi(s) {
|
|
237
|
+
return s.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, "");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export {
|
|
241
|
+
runConsoleTui,
|
|
242
|
+
renderFrame,
|
|
243
|
+
stripAnsi
|
|
244
|
+
};
|
|
245
|
+
//# sourceMappingURL=chunk-32KD5IHZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/console/tui.ts"],"sourcesContent":["/**\n * Operator console TUI for issue #688 (PR 2/3).\n *\n * Renders a five-panel one-screen layout that periodically polls\n * `gatherConsoleState` and repaints the terminal. Deliberately uses\n * the minimal-deps \"clear + repaint\" approach (no curses / blessed /\n * ink) — we just emit ANSI control sequences directly to the output\n * stream. This keeps the surface portable and dependency-free.\n *\n * PR 1/3 (#721) shipped `gatherConsoleState` plus the CLI's\n * `--state-only` flag (one-shot JSON snapshot). PR 2/3 wires the\n * interactive surface. Trace replay (`--trace <session-id>`) is\n * deferred to PR 3/3.\n *\n * Design contract:\n * - Read-only: never mutates orchestrator state.\n * - Resilient: a thrown error in one refresh cycle must NOT crash\n * the loop. Errors are surfaced inside the rendered frame.\n * - Cleanly stoppable: `runConsoleTui` returns a `stop()` that\n * clears the interval, restores the cursor, and resolves the\n * pending exit promise. SIGINT triggers the same cleanup.\n * - No external deps: only ANSI control sequences.\n */\n\nimport type { Writable } from \"node:stream\";\n\nimport {\n gatherConsoleState,\n type ConsoleStateOrchestratorLike,\n type ConsoleStateSnapshot,\n} from \"./state.js\";\n\n/** ANSI: clear screen + move cursor to home (top-left). */\nconst ANSI_CLEAR_HOME = \"\\x1b[2J\\x1b[H\";\n/** ANSI: hide / show the cursor (we hide during the loop, restore on exit). */\nconst ANSI_HIDE_CURSOR = \"\\x1b[?25l\";\nconst ANSI_SHOW_CURSOR = \"\\x1b[?25h\";\n\n/** Total inner width of the rendered frame (between the box borders). */\nconst FRAME_INNER_WIDTH = 70;\n\n/** Default refresh interval in milliseconds. Chosen to match the spec. */\nconst DEFAULT_REFRESH_INTERVAL_MS = 2000;\n\nexport interface RunConsoleTuiOptions {\n /** Polling interval in milliseconds. Defaults to 2000ms. */\n refreshIntervalMs?: number;\n /** Output stream. Defaults to `process.stdout`. */\n output?: Writable;\n /**\n * Optional clock injection — primarily for tests so the rendered\n * timestamp is deterministic. Defaults to `Date.now`.\n */\n now?: () => number;\n /**\n * If true, install a SIGINT handler that calls `stop()` and resolves\n * the returned promise. Defaults to true. Tests typically pass false.\n */\n installSigintHandler?: boolean;\n /**\n * Optional trace recorder. When provided, every successfully\n * gathered snapshot is appended to the recorder for later replay\n * via `replayTrace`. Failed appends are surfaced through the\n * recorder's `getLastError()` and never crash the loop (issue\n * #688 PR 3/3).\n */\n traceRecorder?: {\n append: (snapshot: ConsoleStateSnapshot) => Promise<void>;\n };\n}\n\nexport interface RunConsoleTuiHandle {\n /**\n * Stop the refresh loop and restore the cursor. Returns immediately;\n * callers should `await handle.done` to wait for any in-flight tick\n * (and its trace append) to finish. Codex P2 (#732 round 4): without\n * the in-flight await on the `done` path, a Ctrl-C that fires while\n * a tick is past its `stopped` check could still call\n * `traceRecorder.append` AFTER the CLI begins closing the recorder.\n */\n stop: () => void;\n /**\n * Resolves once `stop()` has been invoked, the interval is cleared,\n * AND any in-flight tick (including its fire-and-forget trace\n * append) has resolved. Callers that close a trace recorder after\n * the TUI exits MUST await this promise before initiating close,\n * otherwise the close path can race a still-running `append` call\n * and surface phantom \"post-close\" appends to the recorder. Codex\n * P2 (#732 round 4).\n */\n done: Promise<void>;\n /**\n * Number of trace frames that were dropped due to backpressure (i.e.\n * the previous `traceRecorder.append()` had not yet resolved when\n * the tick fired). Non-zero values indicate the trace recorder is\n * falling behind — typically caused by a slow or network-backed\n * filesystem. Codex P2 (PR #732 round 5): exposed so operators can\n * detect recording lag via `--state-only` snapshots or future\n * diagnostic surfaces.\n */\n getDroppedTraceFrames: () => number;\n}\n\n/**\n * Start the operator console TUI. Returns immediately with a handle\n * exposing `stop()` and a `done` promise that resolves once the loop\n * has been torn down. The caller can `await handle.done` to block\n * until the user (or a SIGINT) exits.\n */\nexport function runConsoleTui(\n orchestrator: ConsoleStateOrchestratorLike,\n options: RunConsoleTuiOptions = {},\n): RunConsoleTuiHandle {\n const refreshIntervalMs = Math.max(\n 50,\n options.refreshIntervalMs ?? DEFAULT_REFRESH_INTERVAL_MS,\n );\n const output: Writable = options.output ?? process.stdout;\n const now = options.now ?? (() => Date.now());\n const installSigintHandler = options.installSigintHandler ?? true;\n\n let stopped = false;\n let inFlight = false;\n // Codex P2 (PR #732 round 4): track the in-flight tick promise so\n // `stop()` can await it before resolving `done`. Without this, a\n // Ctrl-C that fires while a tick is past its `if (stopped) return`\n // check can still execute `traceRecorder.append(snapshot)` AFTER\n // `done` resolves and the CLI shutdown path begins closing the\n // recorder. By awaiting the tick body, we ensure\n // `recorder.append()` has at least been called (synchronously\n // enqueueing the line onto the recorder's internal writeChain)\n // before `done` resolves; the recorder's `close()` then drains\n // that writeChain. Without the await, `close()` can begin draining\n // while the tick is still about to call `append()`, producing a\n // post-close append.\n //\n // We deliberately do NOT also await the resulting fire-and-forget\n // trace promise. The append is fire-and-forget on purpose\n // (backpressure: see comment further below); a wedged disk that\n // stalls the append must not also stall shutdown. The recorder's\n // own `close()` path (combined with `flushWithTimeout` in the CLI)\n // is the right place to bound the disk-drain wait.\n let inFlightTickPromise: Promise<void> | null = null;\n // Codex P2 (PR #732): backpressure for trace recording. If the\n // previous fire-and-forget `append()` has not resolved yet, we drop\n // the current frame instead of enqueuing it onto the recorder's\n // internal writeChain. Without this guard, a wedged filesystem\n // would let memory grow unboundedly — every tick adds a JSON line\n // to a serialized chain that never drains. Dropping is preferable\n // to OOM; the operator can inspect `getLastError()` to learn that\n // tracing fell behind.\n let traceWritePending = false;\n let traceFramesDropped = 0;\n let resolveDone!: () => void;\n const done = new Promise<void>((resolve) => {\n resolveDone = resolve;\n });\n\n // Hide the cursor while the loop runs so the repaint doesn't flicker.\n safeWrite(output, ANSI_HIDE_CURSOR);\n\n const tick = async () => {\n if (stopped || inFlight) return;\n inFlight = true;\n // Cursor Low: wrap the entire body in try/finally so a thrown\n // `renderFrame` (or any other unexpected sync failure after the\n // gatherConsoleState try/catch) still releases the `inFlight`\n // latch. Without this guard, a single render-time exception\n // permanently freezes the loop because every subsequent tick\n // hits `if (inFlight) return`. Honors the file's design contract\n // (\"a thrown error in one refresh cycle must NOT crash the loop\").\n try {\n let snapshot: ConsoleStateSnapshot | null = null;\n let renderError: string | null = null;\n try {\n snapshot = await gatherConsoleState(orchestrator);\n } catch (err) {\n renderError = describeError(err);\n }\n if (stopped) return;\n let frame: string;\n try {\n frame = renderFrame({ snapshot, renderError, now });\n } catch (err) {\n // If the renderer itself throws (e.g. an invalid clock\n // injection produced `NaN`), fall back to a minimal error\n // frame instead of letting the exception escape and reject\n // the void-floated promise (which would also be unhandled).\n frame = `remnic console: render failed: ${describeError(err)}\\n`;\n }\n safeWrite(output, ANSI_CLEAR_HOME);\n safeWrite(output, frame);\n // Codex P2: do NOT await trace writes inside the render tick.\n // Awaiting holds `inFlight = true` for the duration of the disk\n // write; on a slow / network-backed filesystem that stretches\n // the visual refresh interval and skips ticks. Fire-and-forget\n // preserves the paint cadence; errors are captured via\n // `getLastError()`.\n //\n // Codex P2 (PR #732 follow-up): apply backpressure. If the\n // previous append is still pending (writeChain not yet\n // drained), drop this frame instead of queuing another line.\n // Without this gate, a wedged FS lets the chain grow\n // unboundedly — one JSON line per tick — until the process\n // OOMs. Dropping is preferable; the operator can inspect\n // `getLastError()` to see tracing fell behind.\n if (snapshot && options.traceRecorder && !traceWritePending) {\n traceWritePending = true;\n void options.traceRecorder\n .append(snapshot)\n .catch(() => {\n // already recorded in lastError; defense-in-depth.\n })\n .finally(() => {\n traceWritePending = false;\n });\n } else if (snapshot && options.traceRecorder) {\n traceFramesDropped += 1;\n }\n } finally {\n inFlight = false;\n }\n };\n\n // Kick off an immediate first paint, then schedule the interval.\n // Codex P1: do NOT call `handle.unref()`. The CLI path keeps the\n // process alive by `await`-ing `handle.done`, but a pending promise\n // alone is not enough to keep Node.js running — the interval timer\n // is the only ref'd handle that holds the event loop open between\n // ticks. Unref'ing it caused `remnic console` to render once and\n // exit immediately. Tests that don't want the process held open\n // can call `handle.stop()` directly when they're done.\n // Codex P2 (PR #732 round 4): wrap each tick launch so we hold a\n // reference to the in-flight tick promise. `stop()` awaits this\n // promise before resolving `done`, ensuring no late\n // `traceRecorder.append` call races the CLI shutdown path that\n // closes the recorder once `done` resolves.\n const launchTick = (): void => {\n const p = runTickSafely(tick);\n inFlightTickPromise = p;\n void p.then(() => {\n if (inFlightTickPromise === p) {\n inFlightTickPromise = null;\n }\n });\n };\n launchTick();\n const handle = setInterval(launchTick, refreshIntervalMs);\n\n const sigintHandler = () => {\n stop();\n };\n if (installSigintHandler) {\n process.on(\"SIGINT\", sigintHandler);\n }\n\n const stop = () => {\n if (stopped) return;\n stopped = true;\n clearInterval(handle);\n if (installSigintHandler) {\n try {\n process.removeListener(\"SIGINT\", sigintHandler);\n } catch {\n // ignore\n }\n }\n safeWrite(output, ANSI_SHOW_CURSOR);\n // Codex P2 (PR #732 round 4): wait for any in-flight tick before\n // resolving `done`. Without this, a Ctrl-C that fires while a\n // tick is past its `if (stopped) return` check can still execute\n // `traceRecorder.append(snapshot)` AFTER `done` resolves and the\n // CLI shutdown path begins closing the recorder, producing a\n // phantom post-close append. By awaiting the tick body, we\n // ensure `recorder.append()` has at least been *called*\n // (synchronously enqueueing the line onto the recorder's\n // writeChain) before `done` resolves; the recorder's `close()`\n // then drains that writeChain.\n //\n // We do NOT also await the fire-and-forget trace append promise\n // itself. A wedged disk that stalls the append must not also\n // stall shutdown — the recorder's `close()` path (bounded by\n // `flushWithTimeout` in the CLI) is the right place to bound\n // the disk-drain wait.\n void (async () => {\n try {\n const pendingTick = inFlightTickPromise;\n if (pendingTick) {\n await pendingTick;\n }\n } finally {\n resolveDone();\n }\n })();\n };\n\n return {\n stop,\n done,\n getDroppedTraceFrames: () => traceFramesDropped,\n };\n}\n\ninterface RenderFrameInput {\n snapshot: ConsoleStateSnapshot | null;\n renderError: string | null;\n now: () => number;\n}\n\n/**\n * Build the full rendered frame as a single string. Pure — exposed\n * for testing.\n */\nexport function renderFrame(input: RenderFrameInput): string {\n const ts = new Date(input.now()).toISOString();\n const lines: string[] = [];\n lines.push(renderHeader(ts));\n for (const panel of renderPanels(input)) {\n lines.push(panel);\n }\n lines.push(renderFooter());\n return lines.join(\"\\n\") + \"\\n\";\n}\n\nfunction renderHeader(ts: string): string {\n // ╔═ remnic console ════════════════════════════════ <ts> ═╗\n const title = \" remnic console \";\n const trailing = ` ${ts} `;\n // 2 corner chars + title + ts + filler. Filler at minimum 1 char.\n const fillerLen = Math.max(\n 1,\n FRAME_INNER_WIDTH - title.length - trailing.length,\n );\n const filler = \"═\".repeat(fillerLen);\n return `╔${title}${filler}${trailing}╗`;\n}\n\nfunction renderFooter(): string {\n return `╚${\"═\".repeat(FRAME_INNER_WIDTH)}╝`;\n}\n\nfunction renderPanels(input: RenderFrameInput): string[] {\n const lines: string[] = [];\n const snap = input.snapshot;\n\n if (input.renderError !== null) {\n lines.push(panelLine(\"Error\", `refresh failed: ${input.renderError}`));\n // Even on error we still print the section headers so the layout\n // stays stable for the operator and tests can locate them.\n lines.push(panelLine(\"Buffer\", \"(unavailable)\"));\n lines.push(panelLine(\"Extraction\", \"(unavailable)\"));\n lines.push(panelLine(\"Dedup\", \"(unavailable)\"));\n lines.push(panelLine(\"Maintenance\", \"(unavailable)\"));\n lines.push(panelLine(\"QMD\", \"(unavailable)\"));\n return lines;\n }\n\n // Buffer panel.\n if (snap) {\n lines.push(\n panelLine(\n \"Buffer\",\n `turns=${snap.bufferState.turnsCount} bytes=${snap.bufferState.byteCount}`,\n ),\n );\n\n // Extraction panel.\n const verdicts = snap.extractionQueue.recentVerdicts;\n const accepts = verdicts.filter((v) => v.kind === \"accept\").length;\n const rejects = verdicts.filter((v) => v.kind === \"reject\").length;\n lines.push(\n panelLine(\n \"Extraction\",\n `queue=${snap.extractionQueue.depth} recent verdicts: accept(${accepts})/reject(${rejects})`,\n ),\n );\n\n // Dedup panel.\n const dedupSummary = formatDedupSummary(snap.dedupRecent, input.now);\n lines.push(panelLine(\"Dedup\", dedupSummary));\n\n // Maintenance panel.\n const maintSummary = formatMaintenanceTail(snap.maintenanceLedgerTail);\n lines.push(panelLine(\"Maintenance\", maintSummary));\n\n // QMD panel.\n lines.push(panelLine(\"QMD\", formatQmdSummary(snap)));\n }\n\n // Surface aggregator-level read errors (e.g. ledger I/O failures)\n // without crashing the loop. These are not fatal — the snapshot is\n // still partially usable.\n if (snap && snap.errors.length > 0) {\n const head = snap.errors[0];\n lines.push(panelLine(\"Errors\", head ?? \"\"));\n }\n\n return lines;\n}\n\nfunction formatDedupSummary(\n decisions: ConsoleStateSnapshot[\"dedupRecent\"],\n now: () => number,\n): string {\n if (decisions.length === 0) return \"no recent decisions\";\n const last = decisions[decisions.length - 1];\n if (!last) return \"no recent decisions\";\n const ageMs = ageMsFromIso(last.ts, now);\n const ageStr = ageMs === null ? \"T-?\" : `T-${Math.round(ageMs / 1000)}s`;\n const fp = last.fingerprint ? `hash=${last.fingerprint}` : \"hash=?\";\n return `recent: ${fp} decision=${last.decision} (${ageStr})`;\n}\n\nfunction formatMaintenanceTail(\n events: ConsoleStateSnapshot[\"maintenanceLedgerTail\"],\n): string {\n if (events.length === 0) return \"no events\";\n const last = events[events.length - 1];\n if (!last) return \"no events\";\n // Show count + most-recent event line.\n return `n=${events.length} last: ${last.category} ${truncate(last.summary, 40)}`;\n}\n\nfunction formatQmdSummary(snap: ConsoleStateSnapshot): string {\n const probe = snap.qmdProbe.available ? \"ok\" : \"down\";\n const uptimeH = snap.daemon.uptimeMs / 3_600_000;\n const uptimeStr = uptimeH < 1\n ? `${Math.round(snap.daemon.uptimeMs / 1000)}s`\n : `${uptimeH.toFixed(1)}h`;\n const mode = snap.qmdProbe.daemonMode ? \"daemon\" : \"cli\";\n return `probe=${probe} mode=${mode} uptime=${uptimeStr}`;\n}\n\nfunction panelLine(label: string, value: string): string {\n // Layout: ║<space><label padded to LABEL_WIDTH><value padded to fill><space>║\n // Cursor Medium: the closing ║ must be preceded by a trailing space\n // so the rendered line width matches the header/footer borders.\n // Without it, every panel line was 71 chars while the borders were\n // 72, misaligning the right-hand box edge.\n const LABEL_WIDTH = 13;\n const labelCol = padRight(label, LABEL_WIDTH);\n // Two spaces (leading + trailing) inside the box, consuming 2 cols.\n const remaining = FRAME_INNER_WIDTH - LABEL_WIDTH - 2;\n const valueCol = padRight(truncate(value, remaining), remaining);\n return `║ ${labelCol}${valueCol} ║`;\n}\n\nfunction padRight(s: string, width: number): string {\n if (s.length >= width) return s;\n return s + \" \".repeat(width - s.length);\n}\n\nfunction truncate(s: string, max: number): string {\n if (max <= 0) return \"\";\n if (s.length <= max) return s;\n if (max <= 1) return s.slice(0, max);\n return s.slice(0, max - 1) + \"…\";\n}\n\nfunction ageMsFromIso(iso: string, now: () => number): number | null {\n const ms = Date.parse(iso);\n if (!Number.isFinite(ms)) return null;\n const delta = now() - ms;\n return delta < 0 ? 0 : delta;\n}\n\n/**\n * Run an async tick function and swallow any rejection so the floated\n * `void runTickSafely(tick)` call never produces an unhandled-rejection\n * crash (which Node ≥15 escalates to a process exit). The tick body\n * itself already wraps everything in try/finally, but this is the\n * outermost belt-and-suspenders guard.\n */\nasync function runTickSafely(tick: () => Promise<void>): Promise<void> {\n try {\n await tick();\n } catch {\n // Any error has already been (or will be) surfaced inside the\n // rendered frame; never let it escape the timer callback.\n }\n}\n\nfunction safeWrite(output: Writable, chunk: string): void {\n try {\n output.write(chunk);\n } catch {\n // Writing to a closed / broken stream is non-fatal for the TUI;\n // the next tick will retry.\n }\n}\n\nfunction describeError(err: unknown): string {\n if (err instanceof Error) return err.message;\n try {\n return String(err);\n } catch {\n return \"unknown error\";\n }\n}\n\n/**\n * Strip ANSI escape sequences from a string. Exposed for tests so the\n * rendered frame can be asserted against plain text.\n */\nexport function stripAnsi(s: string): string {\n // eslint-disable-next-line no-control-regex\n return s.replace(/\\x1b\\[[0-9;?]*[A-Za-z]/g, \"\");\n}\n"],"mappings":";;;;;AAiCA,IAAM,kBAAkB;AAExB,IAAM,mBAAmB;AACzB,IAAM,mBAAmB;AAGzB,IAAM,oBAAoB;AAG1B,IAAM,8BAA8B;AAmE7B,SAAS,cACd,cACA,UAAgC,CAAC,GACZ;AACrB,QAAM,oBAAoB,KAAK;AAAA,I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S,GAAW,OAAuB;AAClD,MAAI,EAAE,UAAU,MAAO,QAAO;AAC9B,SAAO,IAAI,IAAI,OAAO,QAAQ,EAAE,MAAM;AACxC;AAEA,SAAS,SAAS,GAAW,KAAqB;AAChD,MAAI,OAAO,EAAG,QAAO;AACrB,MAAI,EAAE,UAAU,IAAK,QAAO;AAC5B,MAAI,OAAO,EAAG,QAAO,EAAE,MAAM,GAAG,GAAG;AACnC,SAAO,EAAE,MAAM,GAAG,MAAM,CAAC,IAAI;AAC/B;AAEA,SAAS,aAAa,KAAa,KAAkC;AACnE,QAAM,KAAK,KAAK,MAAM,GAAG;AACzB,MAAI,CAAC,OAAO,SAAS,EAAE,EAAG,QAAO;AACjC,QAAM,QAAQ,IAAI,IAAI;AACtB,SAAO,QAAQ,IAAI,IAAI;AACzB;AASA,eAAe,cAAc,MAA0C;AACrE,MAAI;AACF,UAAM,KAAK;AAAA,EACb,QAAQ;AAAA,EAGR;AACF;AAEA,SAAS,UAAU,QAAkB,OAAqB;AACxD,MAAI;AACF,WAAO,MAAM,KAAK;AAAA,EACpB,QAAQ;AAAA,EAGR;AACF;AAEA,SAAS,cAAc,KAAsB;AAC3C,MAAI,eAAe,MAAO,QAAO,IAAI;AACrC,MAAI;AACF,WAAO,OAAO,GAAG;AAAA,EACnB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAMO,SAAS,UAAU,GAAmB;AAE3C,SAAO,EAAE,QAAQ,2BAA2B,EAAE;AAChD;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
StorageManager
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-DCE6SQLA.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-34F3PLWZ.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,SAAS,oBAAoB,QAA4B;AACvD,QAAM,OAAO,OAAO,SAAS,OAAO,YAAY,UAAU,IAAI,OAAO,YAAY,aAAa;AAC9F,SAAO,KAAK,IAAI,KAAK,KAAK,IAAI,MAAM,IAAI,CAAC;AAC3C;AAEA,SAAS,cAAc,QAA8B;AACnD,SAAO,MAAM,KAAK,oBAAI,IAAI,CAAC,GAAI,OAAO,YAAY,QAAQ,CAAC,GAAI,iBAAiB,eAAe,CAAC,CAAC;AACnG;AAEA,SAAS,kBAAkB,gBAAwB,YAAkC;AACnF,SAAO;AAAA,IACL;AAAA,MACE,UAAU;AAAA,MACV,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AAW,cAC9B,OAAO,YAAY,WAAW,eAC9B,oBAAoB,OAAO,OAAO,MAAM;AAAA,EAC5C;AACA,MAAI,cAAc;AAChB,WAAO,QAAQ,KAAK;AAAA,MAClB,gBAAgB,QAAQ;AAAA,MACxB,QAAQ;AAAA,MACR,gBAAgB,aAAa,YAAY;AAAA,IAC3C,CAAC;AACD,WAAO;AAAA,EACT;AAEA,QAAM,aAAa,oBAAoB,YAAY;AACnD,QAAM,gBAAgB;AAAA,IACpB,gBAAgB,QAAQ;AAAA,IACxB;AAAA,IACA;AAAA,IACA,MAAM,cAAc,YAAY;AAAA,IAChC,YAAY;AAAA,IACZ,SAAS,CAAC,QAAQ,cAAc;AAAA,EAClC;AAEA,MAAI,QAAQ,WAAW,MAAM;AAC3B,WAAO,SAAS,KAAK;AAAA,MACnB,IAAI,WAAW,QAAQ,cAAc;AAAA,MACrC,GAAG;AAAA,IACL,CAAC;AACD,WAAO;AAAA,EACT;AAEA,QAAM,KAAK,MAAM,QAAQ,YAAY,QAAQ,SAAS;AAAA,IACpD;AAAA,IACA,MAAM,cAAc;AAAA,IACpB,QAAQ;AAAA,IACR,SAAS,cAAc;AAAA,IACvB,gBAAgB,QAAQ;AAAA,IACxB,YAAY;AAAA,IACZ,OAAO,kBAAkB,QAAQ,gBAAgB,UAAU;AAAA,EAC7D,CAAC;AACD,SAAO,SAAS,KAAK;AAAA,IACnB;AAAA,IACA,GAAG;AAAA,EACL,CAAC;AACD,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createVersion
|
|
3
|
+
} from "./chunk-FAAFWE4G.js";
|
|
4
|
+
import {
|
|
5
|
+
assertIsDirectoryNotSymlink,
|
|
6
|
+
assertRealpathInsideRoot,
|
|
7
|
+
fromPosixRelPath,
|
|
8
|
+
isPathInsideRoot,
|
|
9
|
+
sha256String
|
|
10
|
+
} from "./chunk-457A4P3L.js";
|
|
11
|
+
import {
|
|
12
|
+
parseExportBundle
|
|
13
|
+
} from "./chunk-OA3L7BFR.js";
|
|
14
|
+
import {
|
|
15
|
+
decryptCapsuleFileInMemory,
|
|
16
|
+
isEncryptedCapsuleFile
|
|
17
|
+
} from "./chunk-KNKUID7G.js";
|
|
18
|
+
|
|
19
|
+
// src/transfer/capsule-import.ts
|
|
20
|
+
import { lstat, mkdir, readFile, realpath, stat, writeFile } from "fs/promises";
|
|
21
|
+
import path from "path";
|
|
22
|
+
import { createHash, randomUUID } from "crypto";
|
|
23
|
+
import { gunzipSync } from "zlib";
|
|
24
|
+
async function importCapsule(opts) {
|
|
25
|
+
const archiveAbs = path.resolve(opts.archivePath);
|
|
26
|
+
const rootAbs = path.resolve(opts.root);
|
|
27
|
+
await assertIsDirectoryNotSymlink(rootAbs, "importCapsule", "root");
|
|
28
|
+
const mode = opts.mode ?? "skip";
|
|
29
|
+
if (mode !== "skip" && mode !== "overwrite" && mode !== "fork") {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`importCapsule: unknown mode ${JSON.stringify(mode)}; expected "skip", "overwrite", or "fork"`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
const encrypted = await isEncryptedCapsuleFile(archiveAbs);
|
|
35
|
+
let raw;
|
|
36
|
+
if (encrypted) {
|
|
37
|
+
if (!opts.memoryDir) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`importCapsule: archive is encrypted but 'memoryDir' was not provided. Pass the memory directory so the secure-store key can be retrieved, or run \`remnic secure-store unlock\` before importing.`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
raw = await decryptCapsuleFileInMemory(archiveAbs, opts.memoryDir);
|
|
43
|
+
} else {
|
|
44
|
+
raw = await readFile(archiveAbs);
|
|
45
|
+
}
|
|
46
|
+
const json = gunzipSync(raw).toString("utf-8");
|
|
47
|
+
let parsedJson;
|
|
48
|
+
try {
|
|
49
|
+
parsedJson = JSON.parse(json);
|
|
50
|
+
} catch (cause) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`importCapsule: archive is not valid JSON after gunzip: ${archiveAbs}`,
|
|
53
|
+
{ cause }
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
const parsed = parseExportBundle(parsedJson);
|
|
57
|
+
if (parsed.capsuleVersion !== 2) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
"importCapsule: archive is V1; only V2 capsule archives are supported"
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
const bundle = parsed.bundle;
|
|
63
|
+
const manifest = bundle.manifest;
|
|
64
|
+
const capsule = manifest.capsule;
|
|
65
|
+
const manifestIndex = /* @__PURE__ */ new Map();
|
|
66
|
+
for (const f of manifest.files) {
|
|
67
|
+
manifestIndex.set(f.path, f);
|
|
68
|
+
}
|
|
69
|
+
if (manifestIndex.size !== manifest.files.length) {
|
|
70
|
+
throw new Error(
|
|
71
|
+
"importCapsule: manifest contains duplicate file paths"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const recordPaths = /* @__PURE__ */ new Set();
|
|
75
|
+
for (const rec of bundle.records) {
|
|
76
|
+
if (recordPaths.has(rec.path)) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`importCapsule: bundle contains duplicate record path: ${rec.path}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
recordPaths.add(rec.path);
|
|
82
|
+
}
|
|
83
|
+
const rootReal = await realpath(rootAbs).catch(() => rootAbs);
|
|
84
|
+
const seenTargetPaths = /* @__PURE__ */ new Map();
|
|
85
|
+
for (const rec of bundle.records) {
|
|
86
|
+
const entry = manifestIndex.get(rec.path);
|
|
87
|
+
if (!entry) {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`importCapsule: archive checksum mismatch (record without manifest entry: ${rec.path})`
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
const { sha256, bytes } = sha256String(rec.content);
|
|
93
|
+
if (sha256 !== entry.sha256 || bytes !== entry.bytes) {
|
|
94
|
+
throw new Error(
|
|
95
|
+
`importCapsule: archive checksum mismatch for ${rec.path}: expected sha256=${entry.sha256} bytes=${entry.bytes}, got sha256=${sha256} bytes=${bytes}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
if (rec.path.includes("\\")) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`importCapsule: record path contains backslash separators (Windows-style paths are not allowed): ${rec.path}`
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
const posixNormalized = path.posix.normalize(rec.path);
|
|
104
|
+
if (rec.path.startsWith("/") || rec.path.split("/").some((seg) => seg === "..") || posixNormalized.startsWith("..") || posixNormalized.startsWith("/")) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`importCapsule: record path escapes target root: ${rec.path}`
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
const targetRel = computeTargetPath(rec.path, mode, capsule.id);
|
|
110
|
+
const targetAbs = path.join(rootReal, fromPosixRelPath(targetRel));
|
|
111
|
+
if (!isPathInsideRoot(rootReal, targetAbs)) {
|
|
112
|
+
throw new Error(
|
|
113
|
+
`importCapsule: record path escapes target root: ${rec.path}`
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
await assertRealpathInsideRoot(rootReal, targetAbs, rec.path, "importCapsule");
|
|
117
|
+
const targetLstat = await lstat(targetAbs).catch(() => null);
|
|
118
|
+
if (targetLstat !== null && targetLstat.isSymbolicLink()) {
|
|
119
|
+
throw new Error(
|
|
120
|
+
`importCapsule: record target is a symlink and cannot be written to safely: ${rec.path}`
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
const dedupKey = targetAbs.toLowerCase();
|
|
124
|
+
const firstSourcePath = seenTargetPaths.get(dedupKey);
|
|
125
|
+
if (firstSourcePath !== void 0) {
|
|
126
|
+
throw new Error(
|
|
127
|
+
`importCapsule: manifest contains two entries that resolve to the same target path: "${firstSourcePath}" and "${rec.path}" both map to "${targetRel}"`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
seenTargetPaths.set(dedupKey, rec.path);
|
|
131
|
+
}
|
|
132
|
+
for (const f of manifest.files) {
|
|
133
|
+
if (!recordPaths.has(f.path)) {
|
|
134
|
+
throw new Error(
|
|
135
|
+
`importCapsule: archive checksum mismatch (manifest entry without record: ${f.path})`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const imported = [];
|
|
140
|
+
const skipped = [];
|
|
141
|
+
const sortedRecords = [...bundle.records].sort(
|
|
142
|
+
(a, b) => a.path.localeCompare(b.path)
|
|
143
|
+
);
|
|
144
|
+
for (const rec of sortedRecords) {
|
|
145
|
+
const targetRel = computeTargetPath(rec.path, mode, capsule.id);
|
|
146
|
+
const targetAbs = path.join(rootReal, fromPosixRelPath(targetRel));
|
|
147
|
+
const exists = await fileExistsAt(targetAbs);
|
|
148
|
+
if ((mode === "skip" || mode === "fork") && exists) {
|
|
149
|
+
skipped.push({ path: rec.path, reason: "exists" });
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
let snapshotted = false;
|
|
153
|
+
if (mode === "overwrite" && exists) {
|
|
154
|
+
if (opts.versioning && opts.versioning.enabled) {
|
|
155
|
+
const prior = await readFile(targetAbs, "utf-8").catch(() => "");
|
|
156
|
+
await createVersion(
|
|
157
|
+
targetAbs,
|
|
158
|
+
prior,
|
|
159
|
+
"manual",
|
|
160
|
+
opts.versioning,
|
|
161
|
+
opts.log,
|
|
162
|
+
`capsule-import: ${capsule.id}`,
|
|
163
|
+
rootReal
|
|
164
|
+
);
|
|
165
|
+
snapshotted = true;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
let contentToWrite = rec.content;
|
|
169
|
+
let rewroteId = false;
|
|
170
|
+
if (mode === "fork") {
|
|
171
|
+
const forked = rewriteFrontmatterIdForFork(rec.content, capsule.id, opts.now);
|
|
172
|
+
contentToWrite = forked.content;
|
|
173
|
+
rewroteId = forked.rewrote;
|
|
174
|
+
}
|
|
175
|
+
await mkdir(path.dirname(targetAbs), { recursive: true });
|
|
176
|
+
await writeFile(targetAbs, contentToWrite, "utf-8");
|
|
177
|
+
imported.push({
|
|
178
|
+
sourcePath: rec.path,
|
|
179
|
+
targetPath: targetRel,
|
|
180
|
+
snapshotted,
|
|
181
|
+
rewroteId
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
skipped.sort((a, b) => a.path.localeCompare(b.path));
|
|
185
|
+
return { imported, skipped, manifest };
|
|
186
|
+
}
|
|
187
|
+
function computeTargetPath(sourcePosix, mode, capsuleId) {
|
|
188
|
+
if (mode === "fork") return `forks/${capsuleId}/${sourcePosix}`;
|
|
189
|
+
return sourcePosix;
|
|
190
|
+
}
|
|
191
|
+
async function fileExistsAt(absPath) {
|
|
192
|
+
const st = await stat(absPath).catch(() => null);
|
|
193
|
+
return st !== null && st.isFile();
|
|
194
|
+
}
|
|
195
|
+
function rewriteFrontmatterIdForFork(content, capsuleId, now) {
|
|
196
|
+
const crlfMatch = /^---(\r\n|\r|\n)/.exec(content);
|
|
197
|
+
const eol = crlfMatch ? crlfMatch[1] : "\n";
|
|
198
|
+
const fmMatch = /^---\r?\n([\s\S]*?)\r?\n---(\r?\n|$)/.exec(content);
|
|
199
|
+
if (!fmMatch) return { content, rewrote: false };
|
|
200
|
+
const fmBody = fmMatch[1];
|
|
201
|
+
const fmTrailer = fmMatch[2];
|
|
202
|
+
const fmStart = fmMatch.index;
|
|
203
|
+
const fmEnd = fmStart + fmMatch[0].length;
|
|
204
|
+
const idLineRe = /^id:[ \t]*([^\r\n]*)$/m;
|
|
205
|
+
const idMatch = idLineRe.exec(fmBody);
|
|
206
|
+
if (!idMatch) return { content, rewrote: false };
|
|
207
|
+
const newId = mintForkId(capsuleId, idMatch[1]?.trim() ?? "", now);
|
|
208
|
+
const replacedBody = fmBody.replace(idLineRe, `id: ${newId}`);
|
|
209
|
+
const prefix = content.slice(0, fmStart);
|
|
210
|
+
const tail = content.slice(fmEnd);
|
|
211
|
+
const rebuilt = `${prefix}---${eol}${replacedBody}${eol}---${fmTrailer}${tail}`;
|
|
212
|
+
return { content: rebuilt, rewrote: true };
|
|
213
|
+
}
|
|
214
|
+
function mintForkId(capsuleId, originalId, now) {
|
|
215
|
+
const base = originalId.length > 0 ? originalId : "fork";
|
|
216
|
+
if (now === void 0) {
|
|
217
|
+
const suffix2 = randomUUID().slice(0, 8);
|
|
218
|
+
return `${base}-fork-${capsuleId}-${suffix2}`;
|
|
219
|
+
}
|
|
220
|
+
const payload = JSON.stringify({ c: capsuleId, i: originalId, n: now });
|
|
221
|
+
const suffix = createHash("sha256").update(payload, "utf-8").digest("hex").slice(0, 8);
|
|
222
|
+
return `${base}-fork-${capsuleId}-${suffix}`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export {
|
|
226
|
+
importCapsule
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=chunk-3KIS4VGT.js.map
|