@remnic/core 1.1.12 → 1.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access-cli.d.ts +2 -1
- package/dist/access-cli.js +263 -82
- package/dist/access-cli.js.map +1 -1
- package/dist/access-http.d.ts +26 -60
- package/dist/access-http.js +43 -29
- package/dist/access-mcp.d.ts +24 -6
- package/dist/access-mcp.js +35 -28
- package/dist/access-schema.d.ts +9 -6
- package/dist/access-schema.js +7 -5
- package/dist/access-service-DcCDmNYC.d.ts +1542 -0
- package/dist/access-service.d.ts +25 -7
- package/dist/access-service.js +33 -26
- package/dist/active-memory-bridge.js +2 -2
- package/dist/active-recall.js +11 -3
- package/dist/active-recall.js.map +1 -1
- package/dist/adapters/claude-code.d.ts +24 -0
- package/dist/adapters/claude-code.js +9 -0
- package/dist/adapters/codex.d.ts +25 -0
- package/dist/adapters/codex.js +9 -0
- package/dist/adapters/hermes.d.ts +35 -0
- package/dist/adapters/hermes.js +9 -0
- package/dist/adapters/index.d.ts +6 -0
- package/dist/adapters/index.js +26 -0
- package/dist/adapters/registry.d.ts +20 -0
- package/dist/adapters/registry.js +13 -0
- package/dist/adapters/replit.d.ts +28 -0
- package/dist/adapters/replit.js +9 -0
- package/dist/adapters/types.d.ts +43 -0
- package/dist/adapters/types.js +8 -0
- package/dist/bootstrap.d.ts +20 -5
- package/dist/boxes.d.ts +7 -0
- package/dist/boxes.js +1 -1
- package/dist/briefing.d.ts +5 -3
- package/dist/briefing.js +9 -6
- package/dist/buffer-surprise-report.js +1 -1
- package/dist/buffer.d.ts +18 -4
- package/dist/buffer.js +1 -1
- package/dist/calibration.js +4 -4
- package/dist/capsule-cli.d.ts +4 -4
- package/dist/capsule-cli.js +1 -1
- package/dist/capsule-crypto-5CYAGVC5.js +18 -0
- package/dist/capsule-merge-4MGKE7C5.js +189 -0
- package/dist/causal-behavior.d.ts +8 -28
- package/dist/causal-behavior.js +6 -3
- package/dist/causal-behavior.js.map +1 -1
- package/dist/causal-chain.js +3 -2
- package/dist/causal-consolidation.d.ts +1 -1
- package/dist/causal-consolidation.js +24 -13
- package/dist/causal-consolidation.js.map +1 -1
- package/dist/causal-retrieval.js +3 -3
- package/dist/causal-trajectory.js +1 -1
- package/dist/chunk-25MQ7IHJ.js +427 -0
- package/dist/chunk-25MQ7IHJ.js.map +1 -0
- package/dist/chunk-2F2W355T.js +256 -0
- package/dist/chunk-2F2W355T.js.map +1 -0
- package/dist/chunk-2KI4QFHU.js +228 -0
- package/dist/chunk-2KI4QFHU.js.map +1 -0
- package/dist/chunk-2PRQG7PV.js +86 -0
- package/dist/chunk-2PRQG7PV.js.map +1 -0
- package/dist/chunk-2QR3XXIC.js +2272 -0
- package/dist/chunk-2QR3XXIC.js.map +1 -0
- package/dist/chunk-2WWLHTZY.js +121 -0
- package/dist/chunk-326G7DJK.js +2185 -0
- package/dist/chunk-326G7DJK.js.map +1 -0
- package/dist/chunk-34DQE4KF.js +174 -0
- package/dist/chunk-34DQE4KF.js.map +1 -0
- package/dist/chunk-3APJ5EVB.js +601 -0
- package/dist/chunk-3APJ5EVB.js.map +1 -0
- package/dist/chunk-3HPAPHUK.js +51 -0
- package/dist/chunk-3HPAPHUK.js.map +1 -0
- package/dist/chunk-3JXBXXM2.js +69 -0
- package/dist/chunk-3JXBXXM2.js.map +1 -0
- package/dist/chunk-3KW65B36.js +681 -0
- package/dist/chunk-3KW65B36.js.map +1 -0
- package/dist/chunk-3UXOZBHV.js +20 -0
- package/dist/chunk-3UXOZBHV.js.map +1 -0
- package/dist/chunk-3VAL7ZL2.js +266 -0
- package/dist/chunk-3VAL7ZL2.js.map +1 -0
- package/dist/chunk-3Y4P7RXM.js +31 -0
- package/dist/chunk-3Y4P7RXM.js.map +1 -0
- package/dist/chunk-47VWKCAF.js +273 -0
- package/dist/chunk-47VWKCAF.js.map +1 -0
- package/dist/chunk-4CRG46BG.js +271 -0
- package/dist/chunk-5375UYTQ.js +914 -0
- package/dist/chunk-5375UYTQ.js.map +1 -0
- package/dist/chunk-56K5QLHX.js +506 -0
- package/dist/chunk-56K5QLHX.js.map +1 -0
- package/dist/chunk-5RGLBDQF.js +596 -0
- package/dist/chunk-5RGLBDQF.js.map +1 -0
- package/dist/chunk-5UZXUTVO.js +9 -0
- package/dist/chunk-5UZXUTVO.js.map +1 -0
- package/dist/chunk-65PG43EQ.js +105 -0
- package/dist/chunk-65PG43EQ.js.map +1 -0
- package/dist/chunk-66DHUKLO.js +57 -0
- package/dist/chunk-66DHUKLO.js.map +1 -0
- package/dist/chunk-6FC5EGNV.js +46 -0
- package/dist/chunk-6FC5EGNV.js.map +1 -0
- package/dist/chunk-6H2TESSP.js +62 -0
- package/dist/chunk-6H2TESSP.js.map +1 -0
- package/dist/chunk-6LVVDPJ4.js +32 -0
- package/dist/chunk-6LVVDPJ4.js.map +1 -0
- package/dist/chunk-6RVI47ZR.js +159 -0
- package/dist/chunk-6RVI47ZR.js.map +1 -0
- package/dist/chunk-7AAT6G4Q.js +5117 -0
- package/dist/chunk-7AAT6G4Q.js.map +1 -0
- package/dist/chunk-7DTASS5T.js +29 -0
- package/dist/chunk-7DTASS5T.js.map +1 -0
- package/dist/chunk-7IASACLB.js +596 -0
- package/dist/chunk-7MNMYOFP.js +32 -0
- package/dist/chunk-7MNMYOFP.js.map +1 -0
- package/dist/chunk-7N4KAIGN.js +133 -0
- package/dist/chunk-7N4KAIGN.js.map +1 -0
- package/dist/chunk-7OZ53EXP.js +101 -0
- package/dist/chunk-7OZ53EXP.js.map +1 -0
- package/dist/chunk-7XYTQGCC.js +134 -0
- package/dist/chunk-7XYTQGCC.js.map +1 -0
- package/dist/chunk-A2XUIMJ3.js +341 -0
- package/dist/chunk-A2XUIMJ3.js.map +1 -0
- package/dist/chunk-AGZQD76C.js +201 -0
- package/dist/chunk-AGZQD76C.js.map +1 -0
- package/dist/chunk-APO3DCMU.js +361 -0
- package/dist/chunk-APO3DCMU.js.map +1 -0
- package/dist/chunk-BFBF3XEF.js +283 -0
- package/dist/chunk-BFBF3XEF.js.map +1 -0
- package/dist/chunk-BJ3KMYTB.js +1974 -0
- package/dist/chunk-BJ3KMYTB.js.map +1 -0
- package/dist/chunk-CHEL3SKB.js +6758 -0
- package/dist/chunk-CHEL3SKB.js.map +1 -0
- package/dist/chunk-CQZRLNMV.js +1491 -0
- package/dist/chunk-CQZRLNMV.js.map +1 -0
- package/dist/chunk-D46YSIYX.js +892 -0
- package/dist/chunk-D46YSIYX.js.map +1 -0
- package/dist/chunk-DINWEURR.js +648 -0
- package/dist/chunk-DINWEURR.js.map +1 -0
- package/dist/chunk-DK5LDEQM.js +530 -0
- package/dist/chunk-DK5LDEQM.js.map +1 -0
- package/dist/chunk-DOM4GKSW.js +34 -0
- package/dist/chunk-DOM4GKSW.js.map +1 -0
- package/dist/chunk-EDTHC6UD.js +1075 -0
- package/dist/chunk-EFJ3MQ4V.js +721 -0
- package/dist/chunk-EHRTFRWW.js +89 -0
- package/dist/chunk-EHRTFRWW.js.map +1 -0
- package/dist/chunk-FAJ7FZYM.js +11 -0
- package/dist/chunk-FAJ7FZYM.js.map +1 -0
- package/dist/chunk-FBYESMQ2.js +570 -0
- package/dist/chunk-FDU6HUUL.js +147 -0
- package/dist/chunk-FF4KLI5W.js +99 -0
- package/dist/chunk-FF4KLI5W.js.map +1 -0
- package/dist/chunk-FIT6DMX6.js +310 -0
- package/dist/chunk-FIT6DMX6.js.map +1 -0
- package/dist/chunk-FJ43PRLT.js +272 -0
- package/dist/chunk-FJ43PRLT.js.map +1 -0
- package/dist/chunk-FKFMOY3N.js +32 -0
- package/dist/chunk-FKFMOY3N.js.map +1 -0
- package/dist/chunk-FLTNHQK6.js +262 -0
- package/dist/chunk-FLTNHQK6.js.map +1 -0
- package/dist/chunk-GA454ALV.js +12436 -0
- package/dist/chunk-GA454ALV.js.map +1 -0
- package/dist/chunk-GGKRUQOO.js +228 -0
- package/dist/chunk-GIF42EW3.js +63 -0
- package/dist/chunk-GIF42EW3.js.map +1 -0
- package/dist/chunk-GL6I6MEQ.js +647 -0
- package/dist/chunk-H3ME6L6D.js +709 -0
- package/dist/chunk-H3ME6L6D.js.map +1 -0
- package/dist/chunk-HHLLAQGZ.js +1 -0
- package/dist/chunk-HXXBL2KD.js +2040 -0
- package/dist/chunk-I5V2VDIW.js +219 -0
- package/dist/chunk-I5V2VDIW.js.map +1 -0
- package/dist/chunk-I6K5FBRQ.js +35 -0
- package/dist/chunk-I6K5FBRQ.js.map +1 -0
- package/dist/chunk-ICRIXAP2.js +121 -0
- package/dist/chunk-ICRIXAP2.js.map +1 -0
- package/dist/chunk-J4EB7DNW.js +11 -0
- package/dist/chunk-J4EB7DNW.js.map +1 -0
- package/dist/chunk-JLFA7DQG.js +62 -0
- package/dist/chunk-JLFA7DQG.js.map +1 -0
- package/dist/chunk-KJTKLXTH.js +9 -0
- package/dist/chunk-KJTKLXTH.js.map +1 -0
- package/dist/chunk-KLAO5DGL.js +917 -0
- package/dist/chunk-KLAO5DGL.js.map +1 -0
- package/dist/chunk-KNKUID7G.js +183 -0
- package/dist/chunk-KOSORCJG.js +624 -0
- package/dist/chunk-KOSORCJG.js.map +1 -0
- package/dist/chunk-KUJVMMZQ.js +1262 -0
- package/dist/chunk-KUJVMMZQ.js.map +1 -0
- package/dist/chunk-LCR46JY5.js +123 -0
- package/dist/chunk-LCR46JY5.js.map +1 -0
- package/dist/chunk-LLQ2LLWF.js +148 -0
- package/dist/chunk-LLQ2LLWF.js.map +1 -0
- package/dist/chunk-LPMVBPA3.js +236 -0
- package/dist/chunk-LT3NLYSI.js +50 -0
- package/dist/chunk-LT3NLYSI.js.map +1 -0
- package/dist/chunk-LUDTDZLK.js +287 -0
- package/dist/chunk-LUDTDZLK.js.map +1 -0
- package/dist/chunk-M23FSH32.js +3963 -0
- package/dist/chunk-M23FSH32.js.map +1 -0
- package/dist/chunk-MC26UJIM.js +118 -0
- package/dist/chunk-ME6ESPZU.js +119 -0
- package/dist/chunk-ME6ESPZU.js.map +1 -0
- package/dist/chunk-MGKYQQYF.js +272 -0
- package/dist/chunk-MJFNCJXV.js +66 -0
- package/dist/chunk-MJFNCJXV.js.map +1 -0
- package/dist/chunk-MSWG7JI6.js +237 -0
- package/dist/chunk-MSWG7JI6.js.map +1 -0
- package/dist/chunk-MT25YHYH.js +141 -0
- package/dist/chunk-MT25YHYH.js.map +1 -0
- package/dist/chunk-MT4HVDUZ.js +53 -0
- package/dist/chunk-MY6TPVXW.js +219 -0
- package/dist/chunk-N2D6GXBM.js +267 -0
- package/dist/chunk-N2D6GXBM.js.map +1 -0
- package/dist/chunk-NJ3MJQZX.js +46 -0
- package/dist/chunk-NJ3MJQZX.js.map +1 -0
- package/dist/chunk-NMZY542O.js +335 -0
- package/dist/chunk-NMZY542O.js.map +1 -0
- package/dist/chunk-NNVTUXEB.js +23 -0
- package/dist/chunk-NZL6GGQE.js +375 -0
- package/dist/chunk-NZL6GGQE.js.map +1 -0
- package/dist/chunk-P4NEIHUT.js +108 -0
- package/dist/chunk-P7FMDTKL.js +103 -0
- package/dist/chunk-P7FMDTKL.js.map +1 -0
- package/dist/chunk-PHK3HARR.js +32 -0
- package/dist/chunk-PHK3HARR.js.map +1 -0
- package/dist/chunk-PIRJPV5T.js +98 -0
- package/dist/chunk-PIRJPV5T.js.map +1 -0
- package/dist/chunk-PK7H5L6Y.js +159 -0
- package/dist/chunk-PK7H5L6Y.js.map +1 -0
- package/dist/chunk-PR5FBTFU.js +233 -0
- package/dist/chunk-PR5FBTFU.js.map +1 -0
- package/dist/chunk-PU63GXWS.js +174 -0
- package/dist/chunk-PU63GXWS.js.map +1 -0
- package/dist/chunk-PZIAX57I.js +124 -0
- package/dist/chunk-PZIAX57I.js.map +1 -0
- package/dist/chunk-Q7P4WJDP.js +26 -0
- package/dist/chunk-Q7P4WJDP.js.map +1 -0
- package/dist/chunk-QQUAB63I.js +63 -0
- package/dist/chunk-QQUAB63I.js.map +1 -0
- package/dist/chunk-QRNI5JBH.js +18 -0
- package/dist/chunk-RHY3HH7P.js +601 -0
- package/dist/chunk-RHY3HH7P.js.map +1 -0
- package/dist/chunk-RRF5UOBJ.js +91 -0
- package/dist/chunk-RXDLTSWT.js +124 -0
- package/dist/chunk-RXDLTSWT.js.map +1 -0
- package/dist/chunk-RYED3SPJ.js +42 -0
- package/dist/chunk-RYED3SPJ.js.map +1 -0
- package/dist/chunk-S7KDBTWT.js +106 -0
- package/dist/chunk-S7KDBTWT.js.map +1 -0
- package/dist/chunk-SEDEKFYQ.js +1 -0
- package/dist/chunk-TECVW3JP.js +36 -0
- package/dist/chunk-TECVW3JP.js.map +1 -0
- package/dist/chunk-TFO23QT4.js +88 -0
- package/dist/chunk-TFO23QT4.js.map +1 -0
- package/dist/chunk-TK4UEOSK.js +76 -0
- package/dist/chunk-TK4UEOSK.js.map +1 -0
- package/dist/chunk-TKWGAOLV.js +122 -0
- package/dist/chunk-TKWGAOLV.js.map +1 -0
- package/dist/chunk-TMM4S4IJ.js +597 -0
- package/dist/chunk-TMM4S4IJ.js.map +1 -0
- package/dist/chunk-TMQLARTH.js +188 -0
- package/dist/chunk-TMQLARTH.js.map +1 -0
- package/dist/chunk-TPDBFYEG.js +130 -0
- package/dist/chunk-TPDBFYEG.js.map +1 -0
- package/dist/chunk-TPMQ3G6Z.js +145 -0
- package/dist/chunk-TPMQ3G6Z.js.map +1 -0
- package/dist/chunk-TZOLIGIG.js +61 -0
- package/dist/chunk-TZOLIGIG.js.map +1 -0
- package/dist/chunk-U3PN77QT.js +113 -0
- package/dist/chunk-U3WSW6PZ.js +277 -0
- package/dist/chunk-U4SCL7B7.js +640 -0
- package/dist/chunk-U4SCL7B7.js.map +1 -0
- package/dist/chunk-UWK5OXUJ.js +156 -0
- package/dist/chunk-UWK5OXUJ.js.map +1 -0
- package/dist/chunk-UWVJF25J.js +74 -0
- package/dist/chunk-UXHQAFNA.js +1317 -0
- package/dist/chunk-UXHQAFNA.js.map +1 -0
- package/dist/chunk-V5OCT34X.js +1 -0
- package/dist/chunk-VLXA6PI2.js +304 -0
- package/dist/chunk-VLXA6PI2.js.map +1 -0
- package/dist/chunk-VNO6ZJ35.js +500 -0
- package/dist/chunk-VNO6ZJ35.js.map +1 -0
- package/dist/chunk-VW676BEI.js +827 -0
- package/dist/chunk-VW676BEI.js.map +1 -0
- package/dist/chunk-W3LR522O.js +2296 -0
- package/dist/chunk-W4L6CZKA.js +96 -0
- package/dist/chunk-W4L6CZKA.js.map +1 -0
- package/dist/chunk-W4RVMTHR.js +372 -0
- package/dist/chunk-W4RVMTHR.js.map +1 -0
- package/dist/chunk-WEHSQBFR.js +188 -0
- package/dist/chunk-WEHSQBFR.js.map +1 -0
- package/dist/chunk-WELDCG6C.js +380 -0
- package/dist/chunk-WELDCG6C.js.map +1 -0
- package/dist/chunk-WZYKANL3.js +2800 -0
- package/dist/chunk-WZYKANL3.js.map +1 -0
- package/dist/chunk-XIG5PDM7.js +48 -0
- package/dist/chunk-XJNBEDFE.js +193 -0
- package/dist/chunk-XJNBEDFE.js.map +1 -0
- package/dist/chunk-XVVIG67A.js +291 -0
- package/dist/chunk-XVVIG67A.js.map +1 -0
- package/dist/chunk-XVZ7B3HG.js +135 -0
- package/dist/chunk-YBPYIAA5.js +73 -0
- package/dist/chunk-YBPYIAA5.js.map +1 -0
- package/dist/chunk-Z734BLO3.js +21 -0
- package/dist/chunk-Z734BLO3.js.map +1 -0
- package/dist/chunk-ZKSK55RC.js +269 -0
- package/dist/chunk-ZKSK55RC.js.map +1 -0
- package/dist/chunk-ZTFCYYEZ.js +69 -0
- package/dist/chunk-ZTFCYYEZ.js.map +1 -0
- package/dist/chunk-ZY2MNJR6.js +329 -0
- package/dist/chunk-ZY2MNJR6.js.map +1 -0
- package/dist/cli-D3VpkVwB.d.ts +1136 -0
- package/dist/cli.d.ts +39 -10
- package/dist/cli.js +108 -49
- package/dist/commitment-ledger.js +1 -1
- package/dist/compat/checks.d.ts +5 -0
- package/dist/compat/checks.js +11 -0
- package/dist/compat/checks.js.map +1 -0
- package/dist/compat/types.d.ts +30 -0
- package/dist/compat/types.js +1 -0
- package/dist/compat/types.js.map +1 -0
- package/dist/compounding/engine.d.ts +221 -0
- package/dist/compounding/engine.js +32 -0
- package/dist/compounding/engine.js.map +1 -0
- package/dist/compounding/preference-consolidator.d.ts +92 -0
- package/dist/compounding/preference-consolidator.js +553 -0
- package/dist/compounding/preference-consolidator.js.map +1 -0
- package/dist/config.d.ts +4 -2
- package/dist/config.js +9 -4
- package/dist/conflict-policy-DyJ2wd-h.d.ts +4 -0
- package/dist/connectors/codex-materialize-runner.d.ts +64 -0
- package/dist/connectors/codex-materialize-runner.js +33 -0
- package/dist/connectors/codex-materialize-runner.js.map +1 -0
- package/dist/connectors/codex-materialize.d.ts +195 -0
- package/dist/connectors/codex-materialize.js +38 -0
- package/dist/connectors/codex-materialize.js.map +1 -0
- package/dist/connectors/index.d.ts +444 -0
- package/dist/connectors/index.js +115 -0
- package/dist/connectors/index.js.map +1 -0
- package/dist/connectors-cli-CwbyjGR7.d.ts +257 -0
- package/dist/connectors-cli.d.ts +1 -1
- package/dist/consolidation-provenance-check.d.ts +3 -1
- package/dist/consolidation-undo.d.ts +3 -1
- package/dist/contradiction/index.d.ts +258 -0
- package/dist/contradiction/index.js +43 -0
- package/dist/contradiction/index.js.map +1 -0
- package/dist/contradiction-review-ATP4S6IC.js +30 -0
- package/dist/contradiction-review-ATP4S6IC.js.map +1 -0
- package/dist/contradiction-scan-5A4IDZV5.js +13 -0
- package/dist/contradiction-scan-5A4IDZV5.js.map +1 -0
- package/dist/conversation-index/backend.d.ts +97 -0
- package/dist/conversation-index/backend.js +13 -0
- package/dist/conversation-index/backend.js.map +1 -0
- package/dist/conversation-index/chunker.d.ts +16 -0
- package/dist/conversation-index/chunker.js +8 -0
- package/dist/conversation-index/chunker.js.map +1 -0
- package/dist/conversation-index/cleanup.d.ts +11 -0
- package/dist/conversation-index/cleanup.js +9 -0
- package/dist/conversation-index/cleanup.js.map +1 -0
- package/dist/conversation-index/faiss-adapter.d.ts +6 -0
- package/dist/conversation-index/faiss-adapter.js +16 -0
- package/dist/conversation-index/faiss-adapter.js.map +1 -0
- package/dist/conversation-index/indexer.d.ts +23 -0
- package/dist/conversation-index/indexer.js +15 -0
- package/dist/conversation-index/indexer.js.map +1 -0
- package/dist/conversation-index/search.d.ts +6 -0
- package/dist/conversation-index/search.js +11 -0
- package/dist/conversation-index/search.js.map +1 -0
- package/dist/embedding-fallback.js +2 -2
- package/dist/enrichment/index.d.ts +163 -0
- package/dist/enrichment/index.js +18 -0
- package/dist/enrichment/index.js.map +1 -0
- package/dist/entity-retrieval.d.ts +4 -2
- package/dist/entity-retrieval.js +8 -5
- package/dist/evals.js +1 -1
- package/dist/explicit-capture.d.ts +20 -5
- package/dist/explicit-capture.js +2 -2
- package/dist/extraction-judge-training.js +1 -1
- package/dist/extraction.js +8 -8
- package/dist/faiss-adapter-CzPghc4C.d.ts +70 -0
- package/dist/fallback-llm.d.ts +2 -0
- package/dist/fallback-llm.js +4 -4
- package/dist/graph-edge-decay-5DI5GUNL.js +207 -0
- package/dist/index.d.ts +66 -711
- package/dist/index.js +556 -2680
- package/dist/index.js.map +1 -1
- package/dist/lcm/archive.d.ts +89 -0
- package/dist/lcm/archive.js +12 -0
- package/dist/lcm/archive.js.map +1 -0
- package/dist/lcm/dag.d.ts +48 -0
- package/dist/lcm/dag.js +8 -0
- package/dist/lcm/dag.js.map +1 -0
- package/dist/lcm/engine.d.ts +116 -0
- package/dist/lcm/engine.js +20 -0
- package/dist/lcm/engine.js.map +1 -0
- package/dist/lcm/index.d.ts +12 -0
- package/dist/lcm/index.js +44 -0
- package/dist/lcm/index.js.map +1 -0
- package/dist/lcm/queue.d.ts +62 -0
- package/dist/lcm/queue.js +8 -0
- package/dist/lcm/queue.js.map +1 -0
- package/dist/lcm/recall.d.ts +20 -0
- package/dist/lcm/recall.js +8 -0
- package/dist/lcm/recall.js.map +1 -0
- package/dist/lcm/schema.d.ts +16 -0
- package/dist/lcm/schema.js +14 -0
- package/dist/lcm/schema.js.map +1 -0
- package/dist/lcm/summarizer.d.ts +38 -0
- package/dist/lcm/summarizer.js +12 -0
- package/dist/lcm/summarizer.js.map +1 -0
- package/dist/lcm/tools.d.ts +29 -0
- package/dist/lcm/tools.js +8 -0
- package/dist/lcm/tools.js.map +1 -0
- package/dist/live-connectors-runner.js +5 -5
- package/dist/local-llm.js +3 -3
- package/dist/maintenance/archive-observations.d.ts +18 -0
- package/dist/maintenance/archive-observations.js +8 -0
- package/dist/maintenance/archive-observations.js.map +1 -0
- package/dist/maintenance/backup-stamp.d.ts +3 -0
- package/dist/maintenance/backup-stamp.js +8 -0
- package/dist/maintenance/backup-stamp.js.map +1 -0
- package/dist/maintenance/memory-governance-cron.d.ts +85 -0
- package/dist/maintenance/memory-governance-cron.js +22 -0
- package/dist/maintenance/memory-governance-cron.js.map +1 -0
- package/dist/maintenance/memory-governance.d.ts +137 -0
- package/dist/maintenance/memory-governance.js +40 -0
- package/dist/maintenance/memory-governance.js.map +1 -0
- package/dist/maintenance/migrate-observations.d.ts +18 -0
- package/dist/maintenance/migrate-observations.js +9 -0
- package/dist/maintenance/migrate-observations.js.map +1 -0
- package/dist/maintenance/observation-ledger-utils.d.ts +10 -0
- package/dist/maintenance/observation-ledger-utils.js +10 -0
- package/dist/maintenance/observation-ledger-utils.js.map +1 -0
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.d.ts +15 -0
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +28 -0
- package/dist/maintenance/rebuild-memory-lifecycle-ledger.js.map +1 -0
- package/dist/maintenance/rebuild-memory-projection.d.ts +77 -0
- package/dist/maintenance/rebuild-memory-projection.js +35 -0
- package/dist/maintenance/rebuild-memory-projection.js.map +1 -0
- package/dist/maintenance/rebuild-observations.d.ts +17 -0
- package/dist/maintenance/rebuild-observations.js +9 -0
- package/dist/maintenance/rebuild-observations.js.map +1 -0
- package/dist/mcp-memory-inspector-app.d.ts +24 -6
- package/dist/memory-projection-store.d.ts +108 -3
- package/dist/memory-projection-store.js +2 -1
- package/dist/memory-worth-outcomes.d.ts +4 -2
- package/dist/migrate/from-engram.d.ts +24 -0
- package/dist/migrate/from-engram.js +12 -0
- package/dist/migrate/from-engram.js.map +1 -0
- package/dist/namespaces/migrate.d.ts +50 -0
- package/dist/namespaces/migrate.js +50 -0
- package/dist/namespaces/migrate.js.map +1 -0
- package/dist/namespaces/principal.d.ts +17 -0
- package/dist/namespaces/principal.js +16 -0
- package/dist/namespaces/principal.js.map +1 -0
- package/dist/namespaces/search.d.ts +46 -0
- package/dist/namespaces/search.js +28 -0
- package/dist/namespaces/search.js.map +1 -0
- package/dist/namespaces/storage.d.ts +32 -0
- package/dist/namespaces/storage.js +28 -0
- package/dist/namespaces/storage.js.map +1 -0
- package/dist/network/tailscale.d.ts +41 -0
- package/dist/network/tailscale.js +9 -0
- package/dist/network/tailscale.js.map +1 -0
- package/dist/network/webdav.d.ts +39 -0
- package/dist/network/webdav.js +10 -0
- package/dist/network/webdav.js.map +1 -0
- package/dist/objective-state-writers.js +2 -2
- package/dist/operator-toolkit.d.ts +4 -2
- package/dist/operator-toolkit.js +32 -14
- package/dist/opik-exporter.js +2 -2
- package/dist/opik-exporter.js.map +1 -1
- package/dist/orchestrator-DuWl9Hwx.d.ts +1244 -0
- package/dist/orchestrator.d.ts +22 -7
- package/dist/orchestrator.js +79 -44
- package/dist/path-MR5JPYOP.js +9 -0
- package/dist/path-MR5JPYOP.js.map +1 -0
- package/dist/qmd-recall-cache.d.ts +1 -1
- package/dist/qmd.d.ts +102 -3
- package/dist/qmd.js +23 -5
- package/dist/recall-explain-renderer.js +3 -3
- package/dist/recall-xray-cli.js +4 -4
- package/dist/recall-xray-renderer.js +3 -3
- package/dist/recall-xray.js +2 -2
- package/dist/replay/normalizers/chatgpt.d.ts +6 -0
- package/dist/replay/normalizers/chatgpt.js +11 -0
- package/dist/replay/normalizers/chatgpt.js.map +1 -0
- package/dist/replay/normalizers/claude.d.ts +6 -0
- package/dist/replay/normalizers/claude.js +11 -0
- package/dist/replay/normalizers/claude.js.map +1 -0
- package/dist/replay/normalizers/openclaw.d.ts +6 -0
- package/dist/replay/normalizers/openclaw.js +11 -0
- package/dist/replay/normalizers/openclaw.js.map +1 -0
- package/dist/replay/normalizers/shared.d.ts +16 -0
- package/dist/replay/normalizers/shared.js +14 -0
- package/dist/replay/normalizers/shared.js.map +1 -0
- package/dist/replay/runner.d.ts +35 -0
- package/dist/replay/runner.js +16 -0
- package/dist/replay/runner.js.map +1 -0
- package/dist/replay/types.d.ts +57 -0
- package/dist/replay/types.js +19 -0
- package/dist/replay/types.js.map +1 -0
- package/dist/resolution-B7FNQSSP.js +12 -0
- package/dist/resolution-B7FNQSSP.js.map +1 -0
- package/dist/resolve-provider-secret.js +2 -2
- package/dist/resume-bundles.js +8 -6
- package/dist/retrieval-agents.d.ts +1 -1
- package/dist/routing/engine.d.ts +35 -0
- package/dist/routing/engine.js +16 -0
- package/dist/routing/engine.js.map +1 -0
- package/dist/routing/store.d.ts +27 -0
- package/dist/routing/store.js +10 -0
- package/dist/routing/store.js.map +1 -0
- package/dist/runtime/better-sqlite.d.ts +8 -0
- package/dist/runtime/better-sqlite.js +10 -0
- package/dist/runtime/better-sqlite.js.map +1 -0
- package/dist/runtime/child-process.d.ts +32 -0
- package/dist/runtime/child-process.js +10 -0
- package/dist/runtime/child-process.js.map +1 -0
- package/dist/runtime/env.d.ts +5 -0
- package/dist/runtime/env.js +12 -0
- package/dist/runtime/env.js.map +1 -0
- package/dist/schemas.d.ts +22 -22
- package/dist/sdk-compat.js +1 -1
- package/dist/search/document-scanner.d.ts +22 -0
- package/dist/search/document-scanner.js +8 -0
- package/dist/search/document-scanner.js.map +1 -0
- package/dist/search/embed-helper.d.ts +35 -0
- package/dist/search/embed-helper.js +9 -0
- package/dist/search/embed-helper.js.map +1 -0
- package/dist/search/factory.d.ts +32 -0
- package/dist/search/factory.js +29 -0
- package/dist/search/factory.js.map +1 -0
- package/dist/search/index.d.ts +15 -0
- package/dist/search/index.js +50 -0
- package/dist/search/index.js.map +1 -0
- package/dist/search/lancedb-backend.d.ts +51 -0
- package/dist/search/lancedb-backend.js +10 -0
- package/dist/search/lancedb-backend.js.map +1 -0
- package/dist/search/meilisearch-backend.d.ts +48 -0
- package/dist/search/meilisearch-backend.js +10 -0
- package/dist/search/meilisearch-backend.js.map +1 -0
- package/dist/search/noop-backend.d.ts +26 -0
- package/dist/search/noop-backend.js +8 -0
- package/dist/search/noop-backend.js.map +1 -0
- package/dist/search/orama-backend.d.ts +53 -0
- package/dist/search/orama-backend.js +10 -0
- package/dist/search/orama-backend.js.map +1 -0
- package/dist/search/port.d.ts +61 -0
- package/dist/search/port.js +1 -0
- package/dist/search/port.js.map +1 -0
- package/dist/search/remote-backend.d.ts +39 -0
- package/dist/search/remote-backend.js +9 -0
- package/dist/search/remote-backend.js.map +1 -0
- package/dist/secure-store/index.d.ts +890 -0
- package/dist/secure-store/index.js +156 -0
- package/dist/secure-store/index.js.map +1 -0
- package/dist/semantic-VwGI14Ok.d.ts +69 -0
- package/dist/semantic-consolidation-4HkHWgeI.d.ts +180 -0
- package/dist/semantic-consolidation.d.ts +2 -2
- package/dist/semantic-consolidation.js +13 -6
- package/dist/semantic-rule-promotion.js +8 -5
- package/dist/semantic-rule-verifier.js +8 -5
- package/dist/shared-context/manager.d.ts +131 -0
- package/dist/shared-context/manager.js +15 -0
- package/dist/shared-context/manager.js.map +1 -0
- package/dist/skills-registry.js +13 -1
- package/dist/skills-registry.js.map +1 -1
- package/dist/state-store-VZU2IA53.js +16 -0
- package/dist/state-store-VZU2IA53.js.map +1 -0
- package/dist/storage-paths.d.ts +9 -0
- package/dist/storage-paths.js +20 -0
- package/dist/storage-paths.js.map +1 -0
- package/dist/storage.d.ts +3 -1
- package/dist/storage.js +7 -4
- package/dist/summarizer.d.ts +5 -0
- package/dist/summarizer.js +9 -8
- package/dist/summary-snapshot.js +2 -1
- package/dist/surfaces/dreams.d.ts +16 -0
- package/dist/surfaces/dreams.js +282 -0
- package/dist/surfaces/dreams.js.map +1 -0
- package/dist/surfaces/heartbeat.d.ts +17 -0
- package/dist/surfaces/heartbeat.js +265 -0
- package/dist/surfaces/heartbeat.js.map +1 -0
- package/dist/temporal-supersession.d.ts +3 -1
- package/dist/threading.d.ts +5 -0
- package/dist/threading.js +2 -1
- package/dist/tier-migration.d.ts +4 -2
- package/dist/tokens.js +2 -2
- package/dist/transcript.d.ts +15 -1
- package/dist/transcript.js +2 -1
- package/dist/transfer/autodetect.d.ts +4 -0
- package/dist/transfer/autodetect.js +15 -0
- package/dist/transfer/autodetect.js.map +1 -0
- package/dist/transfer/backup.d.ts +21 -0
- package/dist/transfer/backup.js +17 -0
- package/dist/transfer/backup.js.map +1 -0
- package/dist/transfer/capsule-export.d.ts +113 -0
- package/dist/transfer/capsule-export.js +19 -0
- package/dist/transfer/capsule-export.js.map +1 -0
- package/dist/transfer/capsule-import.d.ts +124 -0
- package/dist/transfer/capsule-import.js +16 -0
- package/dist/transfer/capsule-import.js.map +1 -0
- package/dist/transfer/constants.d.ts +13 -0
- package/dist/transfer/constants.js +12 -0
- package/dist/transfer/constants.js.map +1 -0
- package/dist/transfer/export-json.d.ts +11 -0
- package/dist/transfer/export-json.js +11 -0
- package/dist/transfer/export-json.js.map +1 -0
- package/dist/transfer/export-md.d.ts +10 -0
- package/dist/transfer/export-md.js +13 -0
- package/dist/transfer/export-md.js.map +1 -0
- package/dist/transfer/export-sqlite.d.ts +9 -0
- package/dist/transfer/export-sqlite.js +12 -0
- package/dist/transfer/export-sqlite.js.map +1 -0
- package/dist/transfer/fs-utils.d.ts +61 -0
- package/dist/transfer/fs-utils.js +40 -0
- package/dist/transfer/fs-utils.js.map +1 -0
- package/dist/transfer/import-json.d.ts +16 -0
- package/dist/transfer/import-json.js +13 -0
- package/dist/transfer/import-json.js.map +1 -0
- package/dist/transfer/import-md.d.ts +14 -0
- package/dist/transfer/import-md.js +11 -0
- package/dist/transfer/import-md.js.map +1 -0
- package/dist/transfer/import-sqlite.d.ts +14 -0
- package/dist/transfer/import-sqlite.js +12 -0
- package/dist/transfer/import-sqlite.js.map +1 -0
- package/dist/transfer/sqlite-schema.d.ts +4 -0
- package/dist/transfer/sqlite-schema.js +10 -0
- package/dist/transfer/sqlite-schema.js.map +1 -0
- package/dist/transfer/types.d.ts +916 -0
- package/dist/transfer/types.js +30 -0
- package/dist/transfer/types.js.map +1 -0
- package/dist/types.d.ts +28 -1
- package/dist/types.js +1 -1
- package/dist/verified-recall.js +9 -6
- package/dist/work/board.d.ts +43 -0
- package/dist/work/board.js +14 -0
- package/dist/work/board.js.map +1 -0
- package/dist/work/boundary.d.ts +8 -0
- package/dist/work/boundary.js +14 -0
- package/dist/work/boundary.js.map +1 -0
- package/dist/work/storage.d.ts +39 -0
- package/dist/work/storage.js +11 -0
- package/dist/work/storage.js.map +1 -0
- package/dist/work/types.d.ts +75 -0
- package/dist/work/types.js +1 -0
- package/dist/work/types.js.map +1 -0
- package/package.json +2767 -6
- package/scripts/faiss_index.py +816 -0
- package/scripts/faiss_requirements.txt +3 -0
- package/skills/remnic-entities/SKILL.md +51 -0
- package/skills/remnic-memory-workflow/SKILL.md +61 -0
- package/skills/remnic-recall/SKILL.md +51 -0
- package/skills/remnic-remember/SKILL.md +56 -0
- package/skills/remnic-search/SKILL.md +51 -0
- package/skills/remnic-status/SKILL.md +51 -0
- package/src/abort-error.test.ts +49 -0
- package/src/abort-error.ts +46 -0
- package/src/abstraction-nodes.ts +162 -0
- package/src/access-audit.test.ts +178 -0
- package/src/access-audit.ts +125 -0
- package/src/access-cli.test.ts +439 -0
- package/src/access-cli.ts +438 -0
- package/src/access-http.test.ts +225 -0
- package/src/access-http.ts +1899 -0
- package/src/access-idempotency.ts +232 -0
- package/src/access-mcp.test.ts +568 -0
- package/src/access-mcp.ts +3056 -0
- package/src/access-schema-pi.test.ts +60 -0
- package/src/access-schema.ts +522 -0
- package/src/access-service-namespace.test.ts +123 -0
- package/src/access-service.ts +5629 -0
- package/src/action-confidence.test.ts +206 -0
- package/src/action-confidence.ts +466 -0
- package/src/active-memory-bridge.test.ts +285 -0
- package/src/active-memory-bridge.ts +217 -0
- package/src/active-recall.test.ts +484 -0
- package/src/active-recall.ts +459 -0
- package/src/adapters/claude-code.ts +56 -0
- package/src/adapters/codex.ts +57 -0
- package/src/adapters/hermes.ts +64 -0
- package/src/adapters/index.ts +6 -0
- package/src/adapters/registry.ts +41 -0
- package/src/adapters/replit.ts +55 -0
- package/src/adapters/types.ts +51 -0
- package/src/behavior-learner.ts +144 -0
- package/src/behavior-signals.ts +73 -0
- package/src/binary-lifecycle/backend.ts +117 -0
- package/src/binary-lifecycle/index.ts +35 -0
- package/src/binary-lifecycle/manifest.ts +79 -0
- package/src/binary-lifecycle/pipeline.ts +352 -0
- package/src/binary-lifecycle/scanner.ts +89 -0
- package/src/binary-lifecycle/types.ts +89 -0
- package/src/bootstrap.ts +178 -0
- package/src/boxes.ts +521 -0
- package/src/briefing.test.ts +1535 -0
- package/src/briefing.ts +1382 -0
- package/src/buffer-session.test.ts +443 -0
- package/src/buffer-surprise-report.ts +176 -0
- package/src/buffer-surprise-telemetry.test.ts +606 -0
- package/src/buffer-surprise-trigger.test.ts +766 -0
- package/src/buffer-surprise.test.ts +339 -0
- package/src/buffer-surprise.ts +203 -0
- package/src/buffer.ts +900 -0
- package/src/bulk-import/cli-command.test.ts +204 -0
- package/src/bulk-import/index.ts +34 -0
- package/src/bulk-import/pipeline.test.ts +445 -0
- package/src/bulk-import/pipeline.ts +178 -0
- package/src/bulk-import/registry.test.ts +151 -0
- package/src/bulk-import/registry.ts +72 -0
- package/src/bulk-import/types.test.ts +272 -0
- package/src/bulk-import/types.ts +145 -0
- package/src/calibration.ts +394 -0
- package/src/capsule-cli.test.ts +398 -0
- package/src/capsule-cli.ts +565 -0
- package/src/causal-behavior.ts +308 -0
- package/src/causal-chain.ts +419 -0
- package/src/causal-consolidation.ts +370 -0
- package/src/causal-retrieval.ts +286 -0
- package/src/causal-trajectory-graph.ts +60 -0
- package/src/causal-trajectory.ts +303 -0
- package/src/chunking.ts +220 -0
- package/src/citations.ts +232 -0
- package/src/cli.ts +9403 -0
- package/src/codex-cli-fallback.ts +162 -0
- package/src/codex-thread-key.ts +1 -0
- package/src/coding/access-coding-context.test.ts +197 -0
- package/src/coding/coding-branch-scope.test.ts +281 -0
- package/src/coding/coding-namespace.test.ts +360 -0
- package/src/coding/coding-namespace.ts +412 -0
- package/src/coding/coding-orchestrator.test.ts +249 -0
- package/src/coding/git-context.test.ts +507 -0
- package/src/coding/git-context.ts +336 -0
- package/src/coding/mcp-set-coding-context.test.ts +174 -0
- package/src/coding/review-context.test.ts +316 -0
- package/src/coding/review-context.ts +349 -0
- package/src/coding/wire-coding-context.test.ts +468 -0
- package/src/commitment-ledger.test.ts +78 -0
- package/src/commitment-ledger.ts +337 -0
- package/src/compat/checks.test.ts +206 -0
- package/src/compat/checks.ts +716 -0
- package/src/compat/types.ts +33 -0
- package/src/compounding/engine.ts +1686 -0
- package/src/compounding/preference-consolidator.ts +778 -0
- package/src/compression-optimizer.ts +312 -0
- package/src/config.test.ts +930 -0
- package/src/config.ts +3807 -0
- package/src/connectors/codex/instructions.md +160 -0
- package/src/connectors/codex/resources/namespace-cheatsheet.md +48 -0
- package/src/connectors/codex-marketplace.ts +500 -0
- package/src/connectors/codex-materialize-runner.ts +212 -0
- package/src/connectors/codex-materialize.ts +983 -0
- package/src/connectors/coerce.ts +62 -0
- package/src/connectors/index.test.ts +1570 -0
- package/src/connectors/index.ts +3222 -0
- package/src/connectors/live/framework.ts +164 -0
- package/src/connectors/live/github.test.ts +1218 -0
- package/src/connectors/live/github.ts +1068 -0
- package/src/connectors/live/gmail.test.ts +1706 -0
- package/src/connectors/live/gmail.ts +1293 -0
- package/src/connectors/live/google-drive.test.ts +696 -0
- package/src/connectors/live/google-drive.ts +724 -0
- package/src/connectors/live/index.ts +101 -0
- package/src/connectors/live/live-connectors.test.ts +689 -0
- package/src/connectors/live/notion.test.ts +1109 -0
- package/src/connectors/live/notion.ts +978 -0
- package/src/connectors/live/registry.ts +103 -0
- package/src/connectors/live/state-store.ts +399 -0
- package/src/connectors/live/transient-errors.ts +150 -0
- package/src/connectors/weclone-installer.test.ts +850 -0
- package/src/connectors-cli.ts +513 -0
- package/src/console/state.test.ts +224 -0
- package/src/console/state.ts +514 -0
- package/src/console/trace.test.ts +813 -0
- package/src/console/trace.ts +603 -0
- package/src/console/tui.test.ts +582 -0
- package/src/console/tui.ts +508 -0
- package/src/consolidation-operator.ts +182 -0
- package/src/consolidation-provenance-check.ts +551 -0
- package/src/consolidation-undo.ts +718 -0
- package/src/contradiction/contradiction-judge.test.ts +189 -0
- package/src/contradiction/contradiction-judge.ts +333 -0
- package/src/contradiction/contradiction-review.ts +574 -0
- package/src/contradiction/contradiction-scan.ts +504 -0
- package/src/contradiction/contradiction.test.ts +2230 -0
- package/src/contradiction/index.ts +37 -0
- package/src/contradiction/resolution.ts +383 -0
- package/src/conversation-index/backend.ts +323 -0
- package/src/conversation-index/chunker.ts +47 -0
- package/src/conversation-index/cleanup.ts +53 -0
- package/src/conversation-index/faiss-adapter.ts +384 -0
- package/src/conversation-index/indexer.test.ts +164 -0
- package/src/conversation-index/indexer.ts +192 -0
- package/src/conversation-index/search.ts +37 -0
- package/src/cross-namespace-budget.test.ts +275 -0
- package/src/cross-namespace-budget.ts +365 -0
- package/src/cue-anchors.ts +163 -0
- package/src/curation/index.ts +544 -0
- package/src/dashboard-runtime.ts +337 -0
- package/src/day-summary.ts +122 -0
- package/src/dedup/index.ts +330 -0
- package/src/dedup/semantic.test.ts +1577 -0
- package/src/dedup/semantic.ts +148 -0
- package/src/delinearize.ts +193 -0
- package/src/direct-answer-wiring.test.ts +473 -0
- package/src/direct-answer-wiring.ts +180 -0
- package/src/direct-answer.test.ts +484 -0
- package/src/direct-answer.ts +273 -0
- package/src/embedding-fallback.ts +565 -0
- package/src/enrichment/audit.ts +89 -0
- package/src/enrichment/index.ts +27 -0
- package/src/enrichment/pipeline.ts +197 -0
- package/src/enrichment/provider-registry.ts +85 -0
- package/src/enrichment/types.ts +100 -0
- package/src/enrichment/web-search-provider.ts +63 -0
- package/src/entity-retrieval.ts +774 -0
- package/src/entity-schema.ts +239 -0
- package/src/evals.ts +1312 -0
- package/src/event-order-recall.test.ts +4164 -0
- package/src/event-order-recall.ts +2802 -0
- package/src/evidence-pack.test.ts +89 -0
- package/src/evidence-pack.ts +388 -0
- package/src/explicit-capture.ts +530 -0
- package/src/explicit-cue-recall.test.ts +3019 -0
- package/src/explicit-cue-recall.ts +5545 -0
- package/src/extraction-judge-telemetry.ts +234 -0
- package/src/extraction-judge-training.ts +221 -0
- package/src/extraction-judge.ts +846 -0
- package/src/extraction-timeout.test.ts +265 -0
- package/src/extraction.ts +2719 -0
- package/src/fallback-llm.test.ts +1060 -0
- package/src/fallback-llm.ts +918 -0
- package/src/focused-list-recall.test.ts +734 -0
- package/src/focused-list-recall.ts +1160 -0
- package/src/graph-dashboard-diff.ts +35 -0
- package/src/graph-dashboard-key.ts +5 -0
- package/src/graph-dashboard-parser.ts +104 -0
- package/src/graph-edge-reinforcement.ts +192 -0
- package/src/graph-events.ts +151 -0
- package/src/graph-recall.test.ts +164 -0
- package/src/graph-recall.ts +189 -0
- package/src/graph-retrieval.test.ts +809 -0
- package/src/graph-retrieval.ts +823 -0
- package/src/graph-snapshot.ts +329 -0
- package/src/graph.ts +813 -0
- package/src/harmonic-retrieval.ts +223 -0
- package/src/himem.ts +154 -0
- package/src/hygiene.ts +87 -0
- package/src/identity-continuity.ts +333 -0
- package/src/importance.ts +328 -0
- package/src/importers/base.test.ts +294 -0
- package/src/importers/base.ts +436 -0
- package/src/importers/index.ts +21 -0
- package/src/index.ts +1204 -0
- package/src/intent.ts +154 -0
- package/src/json-extract.ts +85 -0
- package/src/json-store.ts +42 -0
- package/src/lcm/archive.ts +617 -0
- package/src/lcm/dag.ts +199 -0
- package/src/lcm/engine.ts +645 -0
- package/src/lcm/index.ts +7 -0
- package/src/lcm/queue.test.ts +178 -0
- package/src/lcm/queue.ts +200 -0
- package/src/lcm/recall.ts +117 -0
- package/src/lcm/schema.ts +154 -0
- package/src/lcm/summarizer.ts +235 -0
- package/src/lcm/tools.ts +191 -0
- package/src/lcm-engine.test.ts +660 -0
- package/src/legacy-hook-compat.test.ts +20 -0
- package/src/legacy-hook-compat.ts +45 -0
- package/src/lifecycle.ts +289 -0
- package/src/live-connectors-runner.ts +385 -0
- package/src/local-llm-qos.test.ts +303 -0
- package/src/local-llm-thinking.test.ts +292 -0
- package/src/local-llm.ts +1464 -0
- package/src/logger.ts +49 -0
- package/src/maintenance/archive-observations.ts +147 -0
- package/src/maintenance/backup-stamp.ts +3 -0
- package/src/maintenance/dreams-ledger.ts +516 -0
- package/src/maintenance/first-start-migration.ts +362 -0
- package/src/maintenance/forget.test.ts +206 -0
- package/src/maintenance/forget.ts +126 -0
- package/src/maintenance/graph-edge-decay.test.ts +409 -0
- package/src/maintenance/graph-edge-decay.ts +394 -0
- package/src/maintenance/memory-governance-cron.ts +447 -0
- package/src/maintenance/memory-governance.ts +1039 -0
- package/src/maintenance/migrate-observations.ts +216 -0
- package/src/maintenance/observation-ledger-utils.ts +54 -0
- package/src/maintenance/pattern-reinforcement.test.ts +875 -0
- package/src/maintenance/pattern-reinforcement.ts +369 -0
- package/src/maintenance/purge.ts +334 -0
- package/src/maintenance/rebuild-memory-lifecycle-ledger.ts +78 -0
- package/src/maintenance/rebuild-memory-projection.ts +1234 -0
- package/src/maintenance/rebuild-observations.ts +178 -0
- package/src/maintenance/tier-stats.test.ts +378 -0
- package/src/maintenance/tier-stats.ts +222 -0
- package/src/mcp-memory-inspector-app.ts +421 -0
- package/src/memory-action-policy.ts +80 -0
- package/src/memory-cache.ts +208 -0
- package/src/memory-extension/claude-code-publisher.ts +51 -0
- package/src/memory-extension/codex-publisher.ts +149 -0
- package/src/memory-extension/hermes-publisher.ts +51 -0
- package/src/memory-extension/index.ts +100 -0
- package/src/memory-extension/shared-instructions.ts +133 -0
- package/src/memory-extension/types.ts +86 -0
- package/src/memory-extension-host/host-discovery.ts +276 -0
- package/src/memory-extension-host/index.ts +14 -0
- package/src/memory-extension-host/render-extensions-block.ts +73 -0
- package/src/memory-extension-host/types.ts +21 -0
- package/src/memory-lifecycle-ledger-utils.ts +116 -0
- package/src/memory-projection-format.ts +11 -0
- package/src/memory-projection-store.ts +951 -0
- package/src/memory-provenance.test.ts +196 -0
- package/src/memory-provenance.ts +484 -0
- package/src/memory-worth-bench.test.ts +71 -0
- package/src/memory-worth-bench.ts +265 -0
- package/src/memory-worth-filter.test.ts +209 -0
- package/src/memory-worth-filter.ts +204 -0
- package/src/memory-worth-frontmatter.test.ts +311 -0
- package/src/memory-worth-outcomes.test.ts +316 -0
- package/src/memory-worth-outcomes.ts +286 -0
- package/src/memory-worth.test.ts +317 -0
- package/src/memory-worth.ts +215 -0
- package/src/message-parts/index.ts +806 -0
- package/src/message-parts/message-parts.test.ts +421 -0
- package/src/migrate/from-engram.ts +789 -0
- package/src/model-registry.ts +313 -0
- package/src/models-json.ts +76 -0
- package/src/namespaces/migrate.ts +187 -0
- package/src/namespaces/path.ts +25 -0
- package/src/namespaces/principal.test.ts +195 -0
- package/src/namespaces/principal.ts +86 -0
- package/src/namespaces/search.test.ts +105 -0
- package/src/namespaces/search.ts +233 -0
- package/src/namespaces/storage.ts +74 -0
- package/src/native-knowledge.ts +1823 -0
- package/src/negative.ts +72 -0
- package/src/network/tailscale.ts +179 -0
- package/src/network/webdav.ts +385 -0
- package/src/objective-state-writers.ts +951 -0
- package/src/objective-state.ts +320 -0
- package/src/onboarding/index.ts +529 -0
- package/src/openai-chat-compat.ts +56 -0
- package/src/operator-toolkit.ts +2132 -0
- package/src/opik-exporter.test.ts +72 -0
- package/src/opik-exporter.ts +587 -0
- package/src/orchestrator-extraction-queue.test.ts +197 -0
- package/src/orchestrator-flush.test.ts +1171 -0
- package/src/orchestrator-pattern-reinforcement.test.ts +128 -0
- package/src/orchestrator-source-attribution.test.ts +701 -0
- package/src/orchestrator.ts +16368 -0
- package/src/page-versioning.ts +450 -0
- package/src/patterns-cli.ts +574 -0
- package/src/peers/index.ts +54 -0
- package/src/peers/migrate-from-identity-anchor.test.ts +291 -0
- package/src/peers/migrate-from-identity-anchor.ts +350 -0
- package/src/peers/peers.test.ts +419 -0
- package/src/peers/profile-reasoner.ts +694 -0
- package/src/peers/storage.ts +1350 -0
- package/src/peers/types.ts +138 -0
- package/src/plugin-id.ts +84 -0
- package/src/policy-runtime.ts +209 -0
- package/src/procedural/procedure-miner.ts +150 -0
- package/src/procedural/procedure-recall.ts +93 -0
- package/src/procedural/procedure-stats.ts +213 -0
- package/src/procedural/procedure-types.ts +132 -0
- package/src/procedural/reinforcement-core.test.ts +132 -0
- package/src/procedural/reinforcement-core.ts +73 -0
- package/src/profiling.test.ts +263 -0
- package/src/profiling.ts +435 -0
- package/src/projection/index.ts +398 -0
- package/src/qmd-recall-cache.test.ts +138 -0
- package/src/qmd-recall-cache.ts +111 -0
- package/src/qmd.test.ts +257 -0
- package/src/qmd.ts +2614 -0
- package/src/reasoning-trace-recall.ts +201 -0
- package/src/reasoning-trace-types.ts +235 -0
- package/src/recall-audit-anomaly.test.ts +246 -0
- package/src/recall-audit-anomaly.ts +297 -0
- package/src/recall-audit.test.ts +51 -0
- package/src/recall-audit.ts +72 -0
- package/src/recall-budget-config.test.ts +87 -0
- package/src/recall-disclosure-escalation.test.ts +196 -0
- package/src/recall-disclosure-escalation.ts +158 -0
- package/src/recall-disclosure-shaping.test.ts +146 -0
- package/src/recall-disclosure.test.ts +214 -0
- package/src/recall-explain-renderer.test.ts +140 -0
- package/src/recall-explain-renderer.ts +356 -0
- package/src/recall-mmr.test.ts +808 -0
- package/src/recall-mmr.ts +607 -0
- package/src/recall-qos.test.ts +85 -0
- package/src/recall-qos.ts +82 -0
- package/src/recall-query-policy.ts +221 -0
- package/src/recall-state.test.ts +233 -0
- package/src/recall-state.ts +456 -0
- package/src/recall-tag-filter.ts +143 -0
- package/src/recall-tokenization.ts +35 -0
- package/src/recall-xray-cli.test.ts +118 -0
- package/src/recall-xray-cli.ts +100 -0
- package/src/recall-xray-disclosure-telemetry.test.ts +183 -0
- package/src/recall-xray-renderer.test.ts +539 -0
- package/src/recall-xray-renderer.ts +487 -0
- package/src/recall-xray.test.ts +503 -0
- package/src/recall-xray.ts +621 -0
- package/src/reconstruct.ts +41 -0
- package/src/release-changelog.ts +35 -0
- package/src/relevance.ts +67 -0
- package/src/replay/normalizers/chatgpt.ts +133 -0
- package/src/replay/normalizers/claude.ts +102 -0
- package/src/replay/normalizers/openclaw.ts +119 -0
- package/src/replay/normalizers/shared.ts +69 -0
- package/src/replay/runner.ts +197 -0
- package/src/replay/types.ts +143 -0
- package/src/rerank.test.ts +48 -0
- package/src/rerank.ts +176 -0
- package/src/resolve-auth-token.test.ts +226 -0
- package/src/resolve-auth-token.ts +151 -0
- package/src/resolve-provider-secret.test.ts +187 -0
- package/src/resolve-provider-secret.ts +410 -0
- package/src/response-guidance-recall.test.ts +3952 -0
- package/src/response-guidance-recall.ts +4431 -0
- package/src/resume-bundles.ts +415 -0
- package/src/retrieval-agents.ts +623 -0
- package/src/retrieval-tiers.ts +25 -0
- package/src/retrieval.ts +104 -0
- package/src/review/index.test.ts +201 -0
- package/src/review/index.ts +536 -0
- package/src/routing/engine.ts +162 -0
- package/src/routing/store.ts +321 -0
- package/src/runtime/better-sqlite.test.ts +32 -0
- package/src/runtime/better-sqlite.ts +76 -0
- package/src/runtime/child-process.ts +67 -0
- package/src/runtime/env.ts +48 -0
- package/src/sanitize.ts +58 -0
- package/src/schemas.ts +449 -0
- package/src/sdk-compat.ts +87 -0
- package/src/search/document-scanner.ts +96 -0
- package/src/search/embed-helper.ts +142 -0
- package/src/search/factory.ts +189 -0
- package/src/search/index.ts +10 -0
- package/src/search/lancedb-backend.ts +342 -0
- package/src/search/meilisearch-backend.ts +232 -0
- package/src/search/noop-backend.ts +57 -0
- package/src/search/orama-backend.ts +358 -0
- package/src/search/port.ts +86 -0
- package/src/search/remote-backend.ts +124 -0
- package/src/secure-store/cipher.ts +271 -0
- package/src/secure-store/cli-handlers.ts +355 -0
- package/src/secure-store/cli-renderer.ts +131 -0
- package/src/secure-store/header.ts +373 -0
- package/src/secure-store/index.ts +137 -0
- package/src/secure-store/kdf.ts +263 -0
- package/src/secure-store/keyring.ts +106 -0
- package/src/secure-store/metadata.ts +394 -0
- package/src/secure-store/passphrase-reader.ts +252 -0
- package/src/secure-store/secure-fs.ts +571 -0
- package/src/secure-store/secure-store.test.ts +755 -0
- package/src/semantic-chunking.ts +545 -0
- package/src/semantic-consolidation.test.ts +182 -0
- package/src/semantic-consolidation.ts +432 -0
- package/src/semantic-rule-promotion.ts +183 -0
- package/src/semantic-rule-verifier.ts +160 -0
- package/src/session-integrity.ts +569 -0
- package/src/session-observer-bands.ts +11 -0
- package/src/session-observer-state.ts +346 -0
- package/src/session-toggles.test.ts +96 -0
- package/src/session-toggles.ts +159 -0
- package/src/shared-context/manager.ts +810 -0
- package/src/signal.ts +84 -0
- package/src/skills-registry.test.ts +277 -0
- package/src/skills-registry.ts +120 -0
- package/src/source-attribution-roundtrip.test.ts +215 -0
- package/src/source-attribution.test.ts +1425 -0
- package/src/source-attribution.ts +639 -0
- package/src/spaces/index.ts +627 -0
- package/src/storage-paths.ts +117 -0
- package/src/storage.ts +6657 -0
- package/src/store-contract.ts +55 -0
- package/src/summarizer.ts +844 -0
- package/src/summary-snapshot.test.ts +681 -0
- package/src/summary-snapshot.ts +238 -0
- package/src/surfaces/dreams.test.ts +394 -0
- package/src/surfaces/dreams.ts +346 -0
- package/src/surfaces/heartbeat.test.ts +415 -0
- package/src/surfaces/heartbeat.ts +325 -0
- package/src/sync/index.ts +308 -0
- package/src/targeted-fact-recall.test.ts +1694 -0
- package/src/targeted-fact-recall.ts +2905 -0
- package/src/taxonomy/default-taxonomy.ts +87 -0
- package/src/taxonomy/index.ts +26 -0
- package/src/taxonomy/resolver-doc-generator.ts +57 -0
- package/src/taxonomy/resolver.ts +184 -0
- package/src/taxonomy/taxonomy-loader.ts +186 -0
- package/src/taxonomy/types.ts +48 -0
- package/src/telemetry-transcript.ts +70 -0
- package/src/temporal-index.ts +890 -0
- package/src/temporal-supersession.test.ts +2703 -0
- package/src/temporal-supersession.ts +493 -0
- package/src/temporal-validity.test.ts +448 -0
- package/src/temporal-validity.ts +123 -0
- package/src/threading.ts +395 -0
- package/src/tier-migration.ts +124 -0
- package/src/tier-routing.ts +102 -0
- package/src/tmt.ts +462 -0
- package/src/tokens.test.ts +178 -0
- package/src/tokens.ts +279 -0
- package/src/topics.ts +147 -0
- package/src/training-export/cli-date-validation.test.ts +258 -0
- package/src/training-export/converter.test.ts +452 -0
- package/src/training-export/converter.ts +319 -0
- package/src/training-export/date-parse.ts +117 -0
- package/src/training-export/index.ts +26 -0
- package/src/training-export/registry.test.ts +85 -0
- package/src/training-export/registry.ts +57 -0
- package/src/training-export/types.ts +31 -0
- package/src/transcript.ts +1179 -0
- package/src/transfer/autodetect.ts +30 -0
- package/src/transfer/backup.ts +138 -0
- package/src/transfer/capsule-crypto.ts +485 -0
- package/src/transfer/capsule-encrypt.test.ts +690 -0
- package/src/transfer/capsule-export.ts +543 -0
- package/src/transfer/capsule-fork.ts +375 -0
- package/src/transfer/capsule-import.ts +564 -0
- package/src/transfer/capsule-merge.ts +433 -0
- package/src/transfer/conflict-policy.ts +16 -0
- package/src/transfer/constants.ts +13 -0
- package/src/transfer/exclusions.ts +37 -0
- package/src/transfer/export-json.ts +65 -0
- package/src/transfer/export-md.ts +59 -0
- package/src/transfer/export-sqlite.ts +52 -0
- package/src/transfer/fs-utils.ts +269 -0
- package/src/transfer/import-json.ts +108 -0
- package/src/transfer/import-md.ts +84 -0
- package/src/transfer/import-sqlite.ts +100 -0
- package/src/transfer/integrity.ts +71 -0
- package/src/transfer/sqlite-schema.ts +16 -0
- package/src/transfer/types.ts +297 -0
- package/src/trust-zones.ts +1186 -0
- package/src/types.ts +3074 -0
- package/src/user-model.test.ts +124 -0
- package/src/user-model.ts +162 -0
- package/src/utility-learner.ts +353 -0
- package/src/utility-runtime.ts +88 -0
- package/src/utility-telemetry.ts +215 -0
- package/src/utils/category-dir.ts +44 -0
- package/src/utils/errno.ts +6 -0
- package/src/utils/iso-timestamp.test.ts +37 -0
- package/src/utils/iso-timestamp.ts +164 -0
- package/src/utils/path.ts +26 -0
- package/src/verified-recall.ts +138 -0
- package/src/version-utils.test.ts +10 -0
- package/src/version-utils.ts +9 -0
- package/src/whitespace.ts +10 -0
- package/src/work/board.ts +359 -0
- package/src/work/boundary.ts +107 -0
- package/src/work/storage.ts +436 -0
- package/src/work/types.ts +82 -0
- package/src/work-product-ledger.ts +265 -0
- package/dist/access-service-DDjzFALq.d.ts +0 -2088
- package/dist/capsule-crypto-SJS5VVAP.js +0 -18
- package/dist/capsule-export-7QNCBZOQ.js +0 -17
- package/dist/capsule-import-EPBHD2EN.js +0 -16
- package/dist/capsule-merge-DI7PNQ2H.js +0 -189
- package/dist/chunk-23ZZK64Y.js +0 -26
- package/dist/chunk-23ZZK64Y.js.map +0 -1
- package/dist/chunk-242S3I2A.js +0 -647
- package/dist/chunk-2LGMW3DJ.js +0 -111
- package/dist/chunk-3B6KIRBH.js +0 -5213
- package/dist/chunk-3B6KIRBH.js.map +0 -1
- package/dist/chunk-457A4P3L.js +0 -119
- package/dist/chunk-457A4P3L.js.map +0 -1
- package/dist/chunk-4IS4SXIQ.js +0 -2040
- package/dist/chunk-4YM32CRU.js +0 -721
- package/dist/chunk-6TBWYBJ3.js +0 -236
- package/dist/chunk-74EMIVE4.js +0 -329
- package/dist/chunk-74EMIVE4.js.map +0 -1
- package/dist/chunk-767ODGE6.js +0 -183
- package/dist/chunk-7V22HTMD.js +0 -623
- package/dist/chunk-7V22HTMD.js.map +0 -1
- package/dist/chunk-7ZM3BFKK.js +0 -9705
- package/dist/chunk-7ZM3BFKK.js.map +0 -1
- package/dist/chunk-AQJNPMOA.js +0 -643
- package/dist/chunk-AQJNPMOA.js.map +0 -1
- package/dist/chunk-ASAITVLA.js +0 -64
- package/dist/chunk-ASAITVLA.js.map +0 -1
- package/dist/chunk-BBE34QBJ.js +0 -275
- package/dist/chunk-BBE34QBJ.js.map +0 -1
- package/dist/chunk-BZSQEPRW.js +0 -14710
- package/dist/chunk-BZSQEPRW.js.map +0 -1
- package/dist/chunk-CPKTBRS2.js +0 -891
- package/dist/chunk-CPKTBRS2.js.map +0 -1
- package/dist/chunk-D4GAOFF6.js +0 -562
- package/dist/chunk-D4GAOFF6.js.map +0 -1
- package/dist/chunk-D54LZC5L.js +0 -147
- package/dist/chunk-DF3RVK3X.js +0 -119
- package/dist/chunk-DF3RVK3X.js.map +0 -1
- package/dist/chunk-DZZPC36E.js +0 -1451
- package/dist/chunk-DZZPC36E.js.map +0 -1
- package/dist/chunk-E2UCDP5S.js +0 -570
- package/dist/chunk-E6K4NIEU.js +0 -747
- package/dist/chunk-E6K4NIEU.js.map +0 -1
- package/dist/chunk-EEQLFRUM.js +0 -89
- package/dist/chunk-ETOW6ACV.js +0 -158
- package/dist/chunk-ETOW6ACV.js.map +0 -1
- package/dist/chunk-FMEBPEAO.js +0 -347
- package/dist/chunk-FMEBPEAO.js.map +0 -1
- package/dist/chunk-FQDPCE3I.js +0 -1837
- package/dist/chunk-FQDPCE3I.js.map +0 -1
- package/dist/chunk-FYIYMQ5N.js +0 -221
- package/dist/chunk-FYIYMQ5N.js.map +0 -1
- package/dist/chunk-G2WADRQ3.js +0 -219
- package/dist/chunk-G4SK7DSQ.js +0 -121
- package/dist/chunk-GVPWB7EY.js +0 -390
- package/dist/chunk-GVPWB7EY.js.map +0 -1
- package/dist/chunk-HELQZFZO.js +0 -1075
- package/dist/chunk-HL5LRPNA.js +0 -1914
- package/dist/chunk-HL5LRPNA.js.map +0 -1
- package/dist/chunk-HQZVVSVB.js +0 -147
- package/dist/chunk-HQZVVSVB.js.map +0 -1
- package/dist/chunk-HY3L4WKC.js +0 -2195
- package/dist/chunk-HY3L4WKC.js.map +0 -1
- package/dist/chunk-IB3BFHGN.js +0 -228
- package/dist/chunk-IXEJRKCZ.js +0 -18
- package/dist/chunk-JBMSGZEQ.js +0 -441
- package/dist/chunk-JBMSGZEQ.js.map +0 -1
- package/dist/chunk-JESOB2HO.js +0 -108
- package/dist/chunk-JKDVIE52.js +0 -272
- package/dist/chunk-JRNQ3RNA.js +0 -284
- package/dist/chunk-JRNQ3RNA.js.map +0 -1
- package/dist/chunk-K6WK37A6.js +0 -865
- package/dist/chunk-K6WK37A6.js.map +0 -1
- package/dist/chunk-MARWOCVP.js +0 -48
- package/dist/chunk-MNU6ZBWT.js +0 -4454
- package/dist/chunk-MNU6ZBWT.js.map +0 -1
- package/dist/chunk-N5AKDXAI.js +0 -74
- package/dist/chunk-OA3L7BFR.js +0 -183
- package/dist/chunk-OA3L7BFR.js.map +0 -1
- package/dist/chunk-OR64ZGRZ.js +0 -23
- package/dist/chunk-P77UEOU2.js +0 -1521
- package/dist/chunk-P77UEOU2.js.map +0 -1
- package/dist/chunk-PH4C2U43.js +0 -239
- package/dist/chunk-PH4C2U43.js.map +0 -1
- package/dist/chunk-RVPLBATS.js +0 -1586
- package/dist/chunk-RVPLBATS.js.map +0 -1
- package/dist/chunk-U5JMRGKX.js +0 -340
- package/dist/chunk-U5JMRGKX.js.map +0 -1
- package/dist/chunk-URB2WSKZ.js +0 -350
- package/dist/chunk-URB2WSKZ.js.map +0 -1
- package/dist/chunk-UVMUAWVT.js +0 -596
- package/dist/chunk-WEJG4TB5.js +0 -118
- package/dist/chunk-X7HPGUVG.js +0 -271
- package/dist/chunk-XAMBKFQS.js +0 -2777
- package/dist/chunk-XAMBKFQS.js.map +0 -1
- package/dist/chunk-XJKFSSDW.js +0 -726
- package/dist/chunk-XJKFSSDW.js.map +0 -1
- package/dist/chunk-XMHBH5H6.js +0 -283
- package/dist/chunk-XMHBH5H6.js.map +0 -1
- package/dist/chunk-XMVFHBHT.js +0 -277
- package/dist/chunk-Y3VMVTYX.js +0 -53
- package/dist/chunk-YNB73F22.js +0 -137
- package/dist/chunk-YNB73F22.js.map +0 -1
- package/dist/chunk-Z2E7VW55.js +0 -335
- package/dist/chunk-Z2E7VW55.js.map +0 -1
- package/dist/chunk-ZG7PTKBK.js +0 -2296
- package/dist/chunk-ZNQN6ZTA.js +0 -135
- package/dist/chunk-ZVTKDVVM.js +0 -827
- package/dist/chunk-ZVTKDVVM.js.map +0 -1
- package/dist/cli-BR8KpIU0.d.ts +0 -1259
- package/dist/codex-materialize-CQlLTzke.d.ts +0 -139
- package/dist/connectors-cli-DFGtY2DB.d.ts +0 -257
- package/dist/contradiction-review-5LTTVDQV.js +0 -22
- package/dist/contradiction-scan-QTXAMBUA.js +0 -414
- package/dist/contradiction-scan-QTXAMBUA.js.map +0 -1
- package/dist/engine-35M5BKQ7.js +0 -28
- package/dist/fs-utils-IRVUFB6G.js +0 -30
- package/dist/graph-edge-decay-PWB63GRE.js +0 -207
- package/dist/memory-governance-IMPQZXFC.js +0 -37
- package/dist/memory-projection-store-CY8TU40w.d.ts +0 -222
- package/dist/orchestrator-DDMPqU6R.d.ts +0 -1792
- package/dist/path-RMTY5Y5A.js +0 -9
- package/dist/port-B6VEDIkC.d.ts +0 -53
- package/dist/resolution-YGIBORXI.js +0 -101
- package/dist/resolution-YGIBORXI.js.map +0 -1
- package/dist/secure-store-4R2GSO7S.js +0 -156
- package/dist/semantic-consolidation-ByBXb-sf.d.ts +0 -180
- package/dist/state-store-3EH7HYIN.js +0 -16
- package/dist/types-V3FJ26TF.js +0 -30
- /package/dist/{capsule-crypto-SJS5VVAP.js.map → adapters/claude-code.js.map} +0 -0
- /package/dist/{capsule-export-7QNCBZOQ.js.map → adapters/codex.js.map} +0 -0
- /package/dist/{capsule-import-EPBHD2EN.js.map → adapters/hermes.js.map} +0 -0
- /package/dist/{contradiction-review-5LTTVDQV.js.map → adapters/index.js.map} +0 -0
- /package/dist/{engine-35M5BKQ7.js.map → adapters/registry.js.map} +0 -0
- /package/dist/{fs-utils-IRVUFB6G.js.map → adapters/replit.js.map} +0 -0
- /package/dist/{memory-governance-IMPQZXFC.js.map → adapters/types.js.map} +0 -0
- /package/dist/{path-RMTY5Y5A.js.map → capsule-crypto-5CYAGVC5.js.map} +0 -0
- /package/dist/{capsule-merge-DI7PNQ2H.js.map → capsule-merge-4MGKE7C5.js.map} +0 -0
- /package/dist/{chunk-G4SK7DSQ.js.map → chunk-2WWLHTZY.js.map} +0 -0
- /package/dist/{chunk-X7HPGUVG.js.map → chunk-4CRG46BG.js.map} +0 -0
- /package/dist/{chunk-UVMUAWVT.js.map → chunk-7IASACLB.js.map} +0 -0
- /package/dist/{chunk-HELQZFZO.js.map → chunk-EDTHC6UD.js.map} +0 -0
- /package/dist/{chunk-4YM32CRU.js.map → chunk-EFJ3MQ4V.js.map} +0 -0
- /package/dist/{chunk-E2UCDP5S.js.map → chunk-FBYESMQ2.js.map} +0 -0
- /package/dist/{chunk-D54LZC5L.js.map → chunk-FDU6HUUL.js.map} +0 -0
- /package/dist/{chunk-IB3BFHGN.js.map → chunk-GGKRUQOO.js.map} +0 -0
- /package/dist/{chunk-242S3I2A.js.map → chunk-GL6I6MEQ.js.map} +0 -0
- /package/dist/{secure-store-4R2GSO7S.js.map → chunk-HHLLAQGZ.js.map} +0 -0
- /package/dist/{chunk-4IS4SXIQ.js.map → chunk-HXXBL2KD.js.map} +0 -0
- /package/dist/{chunk-767ODGE6.js.map → chunk-KNKUID7G.js.map} +0 -0
- /package/dist/{chunk-6TBWYBJ3.js.map → chunk-LPMVBPA3.js.map} +0 -0
- /package/dist/{chunk-WEJG4TB5.js.map → chunk-MC26UJIM.js.map} +0 -0
- /package/dist/{chunk-JKDVIE52.js.map → chunk-MGKYQQYF.js.map} +0 -0
- /package/dist/{chunk-Y3VMVTYX.js.map → chunk-MT4HVDUZ.js.map} +0 -0
- /package/dist/{chunk-G2WADRQ3.js.map → chunk-MY6TPVXW.js.map} +0 -0
- /package/dist/{chunk-OR64ZGRZ.js.map → chunk-NNVTUXEB.js.map} +0 -0
- /package/dist/{chunk-JESOB2HO.js.map → chunk-P4NEIHUT.js.map} +0 -0
- /package/dist/{chunk-IXEJRKCZ.js.map → chunk-QRNI5JBH.js.map} +0 -0
- /package/dist/{chunk-EEQLFRUM.js.map → chunk-RRF5UOBJ.js.map} +0 -0
- /package/dist/{state-store-3EH7HYIN.js.map → chunk-SEDEKFYQ.js.map} +0 -0
- /package/dist/{chunk-2LGMW3DJ.js.map → chunk-U3PN77QT.js.map} +0 -0
- /package/dist/{chunk-XMVFHBHT.js.map → chunk-U3WSW6PZ.js.map} +0 -0
- /package/dist/{chunk-N5AKDXAI.js.map → chunk-UWVJF25J.js.map} +0 -0
- /package/dist/{types-V3FJ26TF.js.map → chunk-V5OCT34X.js.map} +0 -0
- /package/dist/{chunk-ZG7PTKBK.js.map → chunk-W3LR522O.js.map} +0 -0
- /package/dist/{chunk-MARWOCVP.js.map → chunk-XIG5PDM7.js.map} +0 -0
- /package/dist/{chunk-ZNQN6ZTA.js.map → chunk-XVZ7B3HG.js.map} +0 -0
- /package/dist/{graph-edge-decay-PWB63GRE.js.map → graph-edge-decay-5DI5GUNL.js.map} +0 -0
|
@@ -0,0 +1,1823 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { mkdir, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
4
|
+
import { log } from "./logger.js";
|
|
5
|
+
import type {
|
|
6
|
+
NativeKnowledgeConfig,
|
|
7
|
+
NativeKnowledgeObsidianVaultConfig,
|
|
8
|
+
} from "./types.js";
|
|
9
|
+
|
|
10
|
+
export type NativeKnowledgeChunk = {
|
|
11
|
+
chunkId: string;
|
|
12
|
+
sourcePath: string;
|
|
13
|
+
title: string;
|
|
14
|
+
sourceKind:
|
|
15
|
+
| "identity"
|
|
16
|
+
| "memory"
|
|
17
|
+
| "workspace_doc"
|
|
18
|
+
| "obsidian_note"
|
|
19
|
+
| "bootstrap_doc"
|
|
20
|
+
| "handoff"
|
|
21
|
+
| "daily_summary"
|
|
22
|
+
| "automation_note";
|
|
23
|
+
startLine: number;
|
|
24
|
+
endLine: number;
|
|
25
|
+
content: string;
|
|
26
|
+
vaultId?: string;
|
|
27
|
+
notePath?: string;
|
|
28
|
+
noteKey?: string;
|
|
29
|
+
derivedDate?: string;
|
|
30
|
+
tags?: string[];
|
|
31
|
+
aliases?: string[];
|
|
32
|
+
wikilinks?: string[];
|
|
33
|
+
backlinks?: string[];
|
|
34
|
+
namespace?: string;
|
|
35
|
+
privacyClass?: string;
|
|
36
|
+
sourceHash?: string;
|
|
37
|
+
mtimeMs?: number;
|
|
38
|
+
sessionKey?: string;
|
|
39
|
+
workflowKey?: string;
|
|
40
|
+
author?: string;
|
|
41
|
+
agent?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type NativeKnowledgeSearchResult = NativeKnowledgeChunk & {
|
|
45
|
+
score: number;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
interface ParsedFrontmatter {
|
|
49
|
+
body: string;
|
|
50
|
+
bodyStartLine: number;
|
|
51
|
+
data: Record<string, string | string[]>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface ObsidianNoteState {
|
|
55
|
+
noteKey: string;
|
|
56
|
+
notePath: string;
|
|
57
|
+
title: string;
|
|
58
|
+
derivedDate?: string;
|
|
59
|
+
tags: string[];
|
|
60
|
+
aliases: string[];
|
|
61
|
+
wikilinks: string[];
|
|
62
|
+
backlinks: string[];
|
|
63
|
+
namespace?: string;
|
|
64
|
+
privacyClass?: string;
|
|
65
|
+
sourceHash: string;
|
|
66
|
+
mtimeMs: number;
|
|
67
|
+
deleted: boolean;
|
|
68
|
+
deletedAt?: string;
|
|
69
|
+
chunks: NativeKnowledgeChunk[];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface ObsidianVaultState {
|
|
73
|
+
vaultId: string;
|
|
74
|
+
rootDir: string;
|
|
75
|
+
syncedAt: string;
|
|
76
|
+
notes: Record<string, ObsidianNoteState>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface ObsidianSyncState {
|
|
80
|
+
version: 1;
|
|
81
|
+
updatedAt: string;
|
|
82
|
+
vaults: Record<string, ObsidianVaultState>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
interface OpenClawWorkspaceFileState {
|
|
86
|
+
sourcePath: string;
|
|
87
|
+
sourceKind: Exclude<NativeKnowledgeChunk["sourceKind"], "obsidian_note">;
|
|
88
|
+
title: string;
|
|
89
|
+
namespace?: string;
|
|
90
|
+
privacyClass?: string;
|
|
91
|
+
derivedDate?: string;
|
|
92
|
+
sessionKey?: string;
|
|
93
|
+
workflowKey?: string;
|
|
94
|
+
author?: string;
|
|
95
|
+
agent?: string;
|
|
96
|
+
sourceHash: string;
|
|
97
|
+
syncConfigHash: string;
|
|
98
|
+
mtimeMs: number;
|
|
99
|
+
deleted: boolean;
|
|
100
|
+
deletedAt?: string;
|
|
101
|
+
chunks: NativeKnowledgeChunk[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
interface OpenClawWorkspaceSyncState {
|
|
105
|
+
version: 1;
|
|
106
|
+
updatedAt: string;
|
|
107
|
+
files: Record<string, OpenClawWorkspaceFileState>;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
interface CuratedIncludeFileState {
|
|
111
|
+
sourcePath: string;
|
|
112
|
+
sourceKind: Extract<NativeKnowledgeChunk["sourceKind"], "identity" | "memory" | "workspace_doc">;
|
|
113
|
+
title: string;
|
|
114
|
+
namespace?: string;
|
|
115
|
+
privacyClass?: string;
|
|
116
|
+
derivedDate?: string;
|
|
117
|
+
sourceHash: string;
|
|
118
|
+
syncConfigHash: string;
|
|
119
|
+
mtimeMs: number;
|
|
120
|
+
deleted: boolean;
|
|
121
|
+
deletedAt?: string;
|
|
122
|
+
chunks: NativeKnowledgeChunk[];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
interface CuratedIncludeFilesSyncState {
|
|
126
|
+
version: 1;
|
|
127
|
+
updatedAt: string;
|
|
128
|
+
files: Record<string, CuratedIncludeFileState>;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface NativeKnowledgeSyncResult {
|
|
132
|
+
statePath: string;
|
|
133
|
+
vaultCount: number;
|
|
134
|
+
touchedNotes: number;
|
|
135
|
+
deletedNotes: number;
|
|
136
|
+
chunkCount: number;
|
|
137
|
+
activeChunks: NativeKnowledgeChunk[];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const PERSISTED_NATIVE_KNOWLEDGE_STATE_FILES = new Set([
|
|
141
|
+
"obsidian-sync.json",
|
|
142
|
+
"curated-include-sync.json",
|
|
143
|
+
"openclaw-workspace-sync.json",
|
|
144
|
+
]);
|
|
145
|
+
|
|
146
|
+
function normalizeText(value: string): string {
|
|
147
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim();
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function tokenize(value: string): string[] {
|
|
151
|
+
return normalizeText(value).split(/\s+/).filter((token) => token.length >= 2);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function uniqueSorted(values: string[]): string[] {
|
|
155
|
+
return [...new Set(values.filter((value) => value.trim().length > 0).map((value) => value.trim()))].sort();
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function detectSourceKind(filePath: string): CuratedIncludeFileState["sourceKind"] {
|
|
159
|
+
const base = path.basename(filePath).toLowerCase();
|
|
160
|
+
if (base.startsWith("identity")) return "identity";
|
|
161
|
+
if (base === "memory.md") return "memory";
|
|
162
|
+
return "workspace_doc";
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function parseInlineArray(raw: string): string[] {
|
|
166
|
+
const trimmed = raw.trim();
|
|
167
|
+
if (!trimmed.startsWith("[") || !trimmed.endsWith("]")) return [];
|
|
168
|
+
return trimmed
|
|
169
|
+
.slice(1, -1)
|
|
170
|
+
.split(",")
|
|
171
|
+
.map((value) => value.trim().replace(/^['"]|['"]$/g, ""))
|
|
172
|
+
.filter(Boolean);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function parseFrontmatter(content: string): ParsedFrontmatter {
|
|
176
|
+
const normalized = content.replace(/\r\n/g, "\n");
|
|
177
|
+
if (!normalized.startsWith("---\n")) return { body: normalized, bodyStartLine: 1, data: {} };
|
|
178
|
+
const closing = normalized.indexOf("\n---\n", 4);
|
|
179
|
+
if (closing === -1) return { body: normalized, bodyStartLine: 1, data: {} };
|
|
180
|
+
|
|
181
|
+
const data: Record<string, string | string[]> = {};
|
|
182
|
+
const lines = normalized.slice(4, closing).split("\n");
|
|
183
|
+
let index = 0;
|
|
184
|
+
while (index < lines.length) {
|
|
185
|
+
const line = lines[index] ?? "";
|
|
186
|
+
const match = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(line);
|
|
187
|
+
if (!match) {
|
|
188
|
+
index += 1;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const [, key, rawValue] = match;
|
|
192
|
+
if (rawValue.trim().length > 0) {
|
|
193
|
+
const inlineArray = parseInlineArray(rawValue);
|
|
194
|
+
data[key] = inlineArray.length > 0 ? inlineArray : rawValue.trim().replace(/^['"]|['"]$/g, "");
|
|
195
|
+
index += 1;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const items: string[] = [];
|
|
200
|
+
let cursor = index + 1;
|
|
201
|
+
while (cursor < lines.length) {
|
|
202
|
+
const next = lines[cursor] ?? "";
|
|
203
|
+
const itemMatch = /^\s*-\s*(.+)$/.exec(next);
|
|
204
|
+
if (!itemMatch) break;
|
|
205
|
+
items.push(itemMatch[1]!.trim().replace(/^['"]|['"]$/g, ""));
|
|
206
|
+
cursor += 1;
|
|
207
|
+
}
|
|
208
|
+
data[key] = items;
|
|
209
|
+
index = cursor;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return {
|
|
213
|
+
body: normalized.slice(closing + 5),
|
|
214
|
+
bodyStartLine: normalized.slice(0, closing + 5).split("\n").length,
|
|
215
|
+
data,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
function firstStringValue(
|
|
220
|
+
data: Record<string, string | string[]>,
|
|
221
|
+
keys: string[],
|
|
222
|
+
): string | undefined {
|
|
223
|
+
for (const key of keys) {
|
|
224
|
+
const value = data[key];
|
|
225
|
+
if (typeof value === "string" && value.trim().length > 0) return value.trim();
|
|
226
|
+
}
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function normalizeIsoDate(value: string | undefined): string | undefined {
|
|
231
|
+
if (!value) return undefined;
|
|
232
|
+
const trimmed = value.trim();
|
|
233
|
+
const isoDateMatch = /^(\d{4}-\d{2}-\d{2})/.exec(trimmed);
|
|
234
|
+
if (isoDateMatch) return isoDateMatch[1];
|
|
235
|
+
const slashDateMatch = /^(\d{4})[\/_](\d{2})[\/_](\d{2})$/.exec(trimmed);
|
|
236
|
+
if (slashDateMatch) return `${slashDateMatch[1]}-${slashDateMatch[2]}-${slashDateMatch[3]}`;
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function deriveDateFromPath(filePath: string): string | undefined {
|
|
241
|
+
const normalized = filePath.replace(/\\/g, "/");
|
|
242
|
+
const hyphenated = /(\d{4}-\d{2}-\d{2})/.exec(normalized);
|
|
243
|
+
if (hyphenated) return hyphenated[1];
|
|
244
|
+
const split = /(^|\/)(\d{4})\/(\d{2})\/(\d{2})(?=\/|[^/\n]*\.md$)/.exec(normalized);
|
|
245
|
+
if (split) return `${split[2]}-${split[3]}-${split[4]}`;
|
|
246
|
+
return undefined;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function deriveArtifactDate(filePath: string, parsed: ParsedFrontmatter): string | undefined {
|
|
250
|
+
return (
|
|
251
|
+
normalizeIsoDate(firstStringValue(parsed.data, ["date", "recordedAt", "generatedAt", "summaryDate", "day"]))
|
|
252
|
+
?? deriveDateFromPath(filePath)
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function deriveNamespaceFromIncludePath(sourcePath: string): string | undefined {
|
|
257
|
+
const basename = path.basename(sourcePath);
|
|
258
|
+
const match = /^identity\.([^.\/]+)\.md$/i.exec(basename);
|
|
259
|
+
return match?.[1];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function compileDailyNotePattern(pattern: string): RegExp {
|
|
263
|
+
const escaped = pattern.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
264
|
+
const regex = escaped
|
|
265
|
+
.replace(/YYYY/g, "(?<year>\\d{4})")
|
|
266
|
+
.replace(/MM/g, "(?<month>\\d{2})")
|
|
267
|
+
.replace(/DD/g, "(?<day>\\d{2})");
|
|
268
|
+
return new RegExp(`^${regex}$`);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function deriveDailyNoteDate(notePath: string, patterns: string[]): string | undefined {
|
|
272
|
+
const withoutExt = notePath.replace(/\.md$/i, "");
|
|
273
|
+
for (const pattern of patterns) {
|
|
274
|
+
const match = compileDailyNotePattern(pattern).exec(withoutExt);
|
|
275
|
+
if (!match?.groups) continue;
|
|
276
|
+
const { year, month, day } = match.groups;
|
|
277
|
+
if (!year || !month || !day) continue;
|
|
278
|
+
return `${year}-${month}-${day}`;
|
|
279
|
+
}
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function extractInlineTags(content: string): string[] {
|
|
284
|
+
const matches = [...content.matchAll(/(^|\s)#([a-z0-9/_-]+)/gi)];
|
|
285
|
+
return uniqueSorted(matches.map((match) => match[2] ?? ""));
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function extractWikilinks(content: string): { targets: string[]; aliases: string[] } {
|
|
289
|
+
const targets: string[] = [];
|
|
290
|
+
const aliases: string[] = [];
|
|
291
|
+
const regex = /\[\[([^\]|#]+)(?:#[^\]|]+)?(?:\|([^\]]+))?\]\]/g;
|
|
292
|
+
for (const match of content.matchAll(regex)) {
|
|
293
|
+
const target = (match[1] ?? "").trim();
|
|
294
|
+
const alias = (match[2] ?? "").trim();
|
|
295
|
+
if (target) targets.push(target);
|
|
296
|
+
if (alias) aliases.push(alias);
|
|
297
|
+
}
|
|
298
|
+
return {
|
|
299
|
+
targets: uniqueSorted(targets),
|
|
300
|
+
aliases: uniqueSorted(aliases),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function normalizePathPrefix(prefix: string): string {
|
|
305
|
+
const fwd = prefix.replace(/\\/g, "/");
|
|
306
|
+
let start = 0;
|
|
307
|
+
while (start < fwd.length && fwd[start] === "/") start++;
|
|
308
|
+
let end = fwd.length;
|
|
309
|
+
while (end > start && fwd[end - 1] === "/") end--;
|
|
310
|
+
return fwd.substring(start, end);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function classifyObsidianNote(
|
|
314
|
+
notePath: string,
|
|
315
|
+
vault: NativeKnowledgeObsidianVaultConfig,
|
|
316
|
+
): { namespace?: string; privacyClass?: string } {
|
|
317
|
+
let namespace = vault.namespace;
|
|
318
|
+
let privacyClass = vault.privacyClass;
|
|
319
|
+
const normalizedPath = notePath.replace(/\\/g, "/");
|
|
320
|
+
const rules = [...vault.folderRules].sort(
|
|
321
|
+
(a, b) => normalizePathPrefix(b.pathPrefix).length - normalizePathPrefix(a.pathPrefix).length,
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
for (const rule of rules) {
|
|
325
|
+
const prefix = normalizePathPrefix(rule.pathPrefix);
|
|
326
|
+
if (!prefix) continue;
|
|
327
|
+
if (normalizedPath === prefix || normalizedPath.startsWith(`${prefix}/`)) {
|
|
328
|
+
namespace = rule.namespace ?? namespace;
|
|
329
|
+
privacyClass = rule.privacyClass ?? privacyClass;
|
|
330
|
+
break;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return { namespace, privacyClass };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function chunkHeadingAware(options: {
|
|
338
|
+
sourcePath: string;
|
|
339
|
+
content: string;
|
|
340
|
+
maxChunkChars: number;
|
|
341
|
+
startLineOffset?: number;
|
|
342
|
+
createChunk: (args: {
|
|
343
|
+
title: string;
|
|
344
|
+
startLine: number;
|
|
345
|
+
endLine: number;
|
|
346
|
+
content: string;
|
|
347
|
+
}) => NativeKnowledgeChunk;
|
|
348
|
+
}): NativeKnowledgeChunk[] {
|
|
349
|
+
const lines = options.content.replace(/\r\n/g, "\n").split("\n");
|
|
350
|
+
const chunks: NativeKnowledgeChunk[] = [];
|
|
351
|
+
let currentTitle = path.basename(options.sourcePath);
|
|
352
|
+
let currentLines: string[] = [];
|
|
353
|
+
let startLine = 1 + (options.startLineOffset ?? 0);
|
|
354
|
+
|
|
355
|
+
const flush = () => {
|
|
356
|
+
const paragraphs: Array<{
|
|
357
|
+
content: string;
|
|
358
|
+
startLine: number;
|
|
359
|
+
endLine: number;
|
|
360
|
+
}> = [];
|
|
361
|
+
let paragraphLines: string[] = [];
|
|
362
|
+
let paragraphStartOffset: number | null = null;
|
|
363
|
+
|
|
364
|
+
const pushParagraph = (lineOffsetExclusive: number) => {
|
|
365
|
+
if (paragraphLines.length === 0 || paragraphStartOffset === null) return;
|
|
366
|
+
paragraphs.push({
|
|
367
|
+
content: paragraphLines.join("\n").trim(),
|
|
368
|
+
startLine: startLine + paragraphStartOffset,
|
|
369
|
+
endLine: startLine + lineOffsetExclusive - 1,
|
|
370
|
+
});
|
|
371
|
+
paragraphLines = [];
|
|
372
|
+
paragraphStartOffset = null;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
for (let index = 0; index < currentLines.length; index += 1) {
|
|
376
|
+
const line = currentLines[index] ?? "";
|
|
377
|
+
const isListLine = /^\s*(?:[-*+]|\d+\.)\s+/.test(line);
|
|
378
|
+
const previousLine = index > 0 ? (currentLines[index - 1] ?? "") : "";
|
|
379
|
+
const previousWasList = /^\s*(?:[-*+]|\d+\.)\s+/.test(previousLine);
|
|
380
|
+
if (line.trim().length === 0) {
|
|
381
|
+
pushParagraph(index);
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (isListLine && paragraphLines.length > 0 && !previousWasList) {
|
|
385
|
+
pushParagraph(index);
|
|
386
|
+
}
|
|
387
|
+
if (paragraphStartOffset === null) paragraphStartOffset = index;
|
|
388
|
+
paragraphLines.push(line);
|
|
389
|
+
}
|
|
390
|
+
pushParagraph(currentLines.length);
|
|
391
|
+
|
|
392
|
+
if (paragraphs.length === 0) return;
|
|
393
|
+
|
|
394
|
+
const body = paragraphs.map((paragraph) => paragraph.content).join("\n\n");
|
|
395
|
+
if (body.length <= options.maxChunkChars) {
|
|
396
|
+
chunks.push(options.createChunk({
|
|
397
|
+
title: currentTitle,
|
|
398
|
+
startLine: paragraphs[0]!.startLine,
|
|
399
|
+
endLine: paragraphs[paragraphs.length - 1]!.endLine,
|
|
400
|
+
content: body,
|
|
401
|
+
}));
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
let buffer = "";
|
|
406
|
+
let bufferStartLine = paragraphs[0]!.startLine;
|
|
407
|
+
let bufferEndLine = paragraphs[0]!.endLine;
|
|
408
|
+
|
|
409
|
+
for (const paragraph of paragraphs) {
|
|
410
|
+
const next = buffer.length > 0 ? `${buffer}\n\n${paragraph.content}` : paragraph.content;
|
|
411
|
+
if (next.length > options.maxChunkChars && buffer.length > 0) {
|
|
412
|
+
chunks.push(options.createChunk({
|
|
413
|
+
title: currentTitle,
|
|
414
|
+
startLine: bufferStartLine,
|
|
415
|
+
endLine: bufferEndLine,
|
|
416
|
+
content: buffer,
|
|
417
|
+
}));
|
|
418
|
+
buffer = paragraph.content;
|
|
419
|
+
bufferStartLine = paragraph.startLine;
|
|
420
|
+
bufferEndLine = paragraph.endLine;
|
|
421
|
+
} else {
|
|
422
|
+
buffer = next;
|
|
423
|
+
bufferEndLine = paragraph.endLine;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (buffer.length > 0) {
|
|
428
|
+
chunks.push(options.createChunk({
|
|
429
|
+
title: currentTitle,
|
|
430
|
+
startLine: bufferStartLine,
|
|
431
|
+
endLine: bufferEndLine,
|
|
432
|
+
content: buffer,
|
|
433
|
+
}));
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
438
|
+
const line = lines[index] ?? "";
|
|
439
|
+
if (/^#{1,6}\s+/.test(line) && currentLines.length > 0) {
|
|
440
|
+
flush();
|
|
441
|
+
currentLines = [];
|
|
442
|
+
currentTitle = line.replace(/^#{1,6}\s+/, "").trim() || currentTitle;
|
|
443
|
+
startLine = index + 2 + (options.startLineOffset ?? 0);
|
|
444
|
+
continue;
|
|
445
|
+
}
|
|
446
|
+
if (/^#{1,6}\s+/.test(line)) {
|
|
447
|
+
currentTitle = line.replace(/^#{1,6}\s+/, "").trim() || currentTitle;
|
|
448
|
+
startLine = index + 2 + (options.startLineOffset ?? 0);
|
|
449
|
+
continue;
|
|
450
|
+
}
|
|
451
|
+
currentLines.push(line);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
flush();
|
|
455
|
+
return chunks;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
async function readableFile(filePath: string): Promise<boolean> {
|
|
459
|
+
try {
|
|
460
|
+
const info = await stat(filePath);
|
|
461
|
+
return info.isFile();
|
|
462
|
+
} catch {
|
|
463
|
+
return false;
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
async function resolveCandidatePaths(options: {
|
|
468
|
+
workspaceDir: string;
|
|
469
|
+
includeFiles: string[];
|
|
470
|
+
recallNamespaces?: string[];
|
|
471
|
+
defaultNamespace: string;
|
|
472
|
+
identityVariantMode: "recall" | "disk";
|
|
473
|
+
}): Promise<string[]> {
|
|
474
|
+
const out = new Set<string>();
|
|
475
|
+
for (const rel of options.includeFiles) {
|
|
476
|
+
const trimmed = rel.trim();
|
|
477
|
+
if (!trimmed) continue;
|
|
478
|
+
const candidatePath = path.join(options.workspaceDir, trimmed);
|
|
479
|
+
out.add(candidatePath);
|
|
480
|
+
if (path.basename(trimmed).toLowerCase() !== "identity.md") continue;
|
|
481
|
+
|
|
482
|
+
const relativeDir = path.dirname(trimmed);
|
|
483
|
+
if (options.identityVariantMode === "recall") {
|
|
484
|
+
if (!Array.isArray(options.recallNamespaces)) continue;
|
|
485
|
+
for (const namespace of options.recallNamespaces) {
|
|
486
|
+
if (!namespace || namespace === options.defaultNamespace) continue;
|
|
487
|
+
out.add(path.join(options.workspaceDir, relativeDir, `IDENTITY.${namespace}.md`));
|
|
488
|
+
}
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
const absoluteDir = path.dirname(candidatePath);
|
|
493
|
+
let entries: string[] = [];
|
|
494
|
+
try {
|
|
495
|
+
entries = await readdir(absoluteDir);
|
|
496
|
+
} catch {
|
|
497
|
+
continue;
|
|
498
|
+
}
|
|
499
|
+
for (const entry of entries) {
|
|
500
|
+
if (!/^identity\.[^.\/]+\.md$/i.test(entry)) continue;
|
|
501
|
+
out.add(path.join(options.workspaceDir, relativeDir, entry));
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return Array.from(out);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function resolveNoteTitle(notePath: string, parsed: ParsedFrontmatter): string {
|
|
508
|
+
const rawTitle = parsed.data.title;
|
|
509
|
+
if (typeof rawTitle === "string" && rawTitle.trim().length > 0) return rawTitle.trim();
|
|
510
|
+
const heading = parsed.body.match(/^#{1,6}\s+(.+)$/m)?.[1]?.trim();
|
|
511
|
+
if (heading) return heading;
|
|
512
|
+
return path.basename(notePath, path.extname(notePath));
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function parseFrontmatterList(value: string | string[] | undefined): string[] {
|
|
516
|
+
if (Array.isArray(value)) return uniqueSorted(value);
|
|
517
|
+
if (typeof value === "string" && value.trim().length > 0) return [value.trim()];
|
|
518
|
+
return [];
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
function toPosixRelative(rootDir: string, filePath: string): string {
|
|
522
|
+
return path.relative(rootDir, filePath).split(path.sep).join("/");
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function globToRegExp(glob: string): RegExp {
|
|
526
|
+
let regex = "^";
|
|
527
|
+
for (let index = 0; index < glob.length; index += 1) {
|
|
528
|
+
const char = glob[index]!;
|
|
529
|
+
const next = glob[index + 1];
|
|
530
|
+
if (char === "*") {
|
|
531
|
+
if (next === "*") {
|
|
532
|
+
if (glob[index + 2] === "/") {
|
|
533
|
+
regex += "(?:.*/)?";
|
|
534
|
+
index += 2;
|
|
535
|
+
} else {
|
|
536
|
+
regex += ".*";
|
|
537
|
+
index += 1;
|
|
538
|
+
}
|
|
539
|
+
} else {
|
|
540
|
+
regex += "[^/]*";
|
|
541
|
+
}
|
|
542
|
+
continue;
|
|
543
|
+
}
|
|
544
|
+
if (char === "?") {
|
|
545
|
+
regex += ".";
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
if (char === "/") {
|
|
549
|
+
regex += "/";
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
regex += char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
553
|
+
}
|
|
554
|
+
regex += "$";
|
|
555
|
+
return new RegExp(regex);
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function compileGlobs(patterns: string[]): RegExp[] {
|
|
559
|
+
return patterns.map((pattern) => globToRegExp(pattern));
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
function matchesCompiledGlobs(notePath: string, patterns: RegExp[]): boolean {
|
|
563
|
+
if (patterns.length === 0) return false;
|
|
564
|
+
return patterns.some((pattern) => pattern.test(notePath));
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
async function listMarkdownFiles(rootDir: string): Promise<string[] | null> {
|
|
568
|
+
const results: string[] = [];
|
|
569
|
+
async function walk(currentDir: string): Promise<void> {
|
|
570
|
+
const entries = await readdir(currentDir, { withFileTypes: true }).catch(() => []);
|
|
571
|
+
for (const entry of entries) {
|
|
572
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
573
|
+
if (entry.isDirectory()) {
|
|
574
|
+
await walk(fullPath);
|
|
575
|
+
continue;
|
|
576
|
+
}
|
|
577
|
+
if (!entry.isFile() || !entry.name.toLowerCase().endsWith(".md")) continue;
|
|
578
|
+
results.push(toPosixRelative(rootDir, fullPath));
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
const rootInfo = await stat(rootDir).catch(() => null);
|
|
582
|
+
if (!rootInfo?.isDirectory()) return null;
|
|
583
|
+
await walk(rootDir);
|
|
584
|
+
return results.sort();
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function resolveFileCandidates(options: {
|
|
588
|
+
listedFiles: string[];
|
|
589
|
+
bootstrapFiles: string[];
|
|
590
|
+
handoffGlobs: string[];
|
|
591
|
+
dailySummaryGlobs: string[];
|
|
592
|
+
automationNoteGlobs: string[];
|
|
593
|
+
workspaceDocGlobs: string[];
|
|
594
|
+
excludeGlobs: string[];
|
|
595
|
+
}): Array<{
|
|
596
|
+
sourcePath: string;
|
|
597
|
+
sourceKind: "bootstrap_doc" | "handoff" | "daily_summary" | "automation_note" | "workspace_doc";
|
|
598
|
+
}> {
|
|
599
|
+
const out = new Map<string, "bootstrap_doc" | "handoff" | "daily_summary" | "automation_note" | "workspace_doc">();
|
|
600
|
+
const excludes = compileGlobs(options.excludeGlobs);
|
|
601
|
+
const handoff = compileGlobs(options.handoffGlobs);
|
|
602
|
+
const dailySummary = compileGlobs(options.dailySummaryGlobs);
|
|
603
|
+
const automation = compileGlobs(options.automationNoteGlobs);
|
|
604
|
+
const workspaceDocs = compileGlobs(options.workspaceDocGlobs);
|
|
605
|
+
const listedFiles = new Set(options.listedFiles.map((value) => value.replace(/\\/g, "/")));
|
|
606
|
+
|
|
607
|
+
for (const file of options.bootstrapFiles.map((value) => value.replace(/\\/g, "/"))) {
|
|
608
|
+
if (listedFiles.has(file) && !matchesCompiledGlobs(file, excludes)) out.set(file, "bootstrap_doc");
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
for (const sourcePath of listedFiles) {
|
|
612
|
+
if (matchesCompiledGlobs(sourcePath, excludes)) continue;
|
|
613
|
+
if (out.has(sourcePath)) continue;
|
|
614
|
+
if (matchesCompiledGlobs(sourcePath, handoff)) {
|
|
615
|
+
out.set(sourcePath, "handoff");
|
|
616
|
+
continue;
|
|
617
|
+
}
|
|
618
|
+
if (matchesCompiledGlobs(sourcePath, dailySummary)) {
|
|
619
|
+
out.set(sourcePath, "daily_summary");
|
|
620
|
+
continue;
|
|
621
|
+
}
|
|
622
|
+
if (matchesCompiledGlobs(sourcePath, automation)) {
|
|
623
|
+
out.set(sourcePath, "automation_note");
|
|
624
|
+
continue;
|
|
625
|
+
}
|
|
626
|
+
if (matchesCompiledGlobs(sourcePath, workspaceDocs)) {
|
|
627
|
+
out.set(sourcePath, "workspace_doc");
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
return [...out.entries()]
|
|
632
|
+
.map(([sourcePath, sourceKind]) => ({ sourcePath, sourceKind }))
|
|
633
|
+
.sort((left, right) => left.sourcePath.localeCompare(right.sourcePath));
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
export function resolveNativeKnowledgeStatePath(memoryDir: string, config: NativeKnowledgeConfig): string {
|
|
637
|
+
return path.join(memoryDir, config.stateDir, "obsidian-sync.json");
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
export function resolveCuratedIncludeFilesStatePath(memoryDir: string, config: NativeKnowledgeConfig): string {
|
|
641
|
+
return path.join(memoryDir, config.stateDir, "curated-include-sync.json");
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
export function resolveOpenClawWorkspaceStatePath(memoryDir: string, config: NativeKnowledgeConfig): string {
|
|
645
|
+
return path.join(memoryDir, config.stateDir, "openclaw-workspace-sync.json");
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
async function loadSyncState(memoryDir: string, config: NativeKnowledgeConfig): Promise<ObsidianSyncState> {
|
|
649
|
+
const statePath = resolveNativeKnowledgeStatePath(memoryDir, config);
|
|
650
|
+
try {
|
|
651
|
+
const raw = JSON.parse(await readFile(statePath, "utf-8")) as Partial<ObsidianSyncState>;
|
|
652
|
+
if (raw.version !== 1 || typeof raw.vaults !== "object" || !raw.vaults) {
|
|
653
|
+
throw new Error("invalid obsidian native knowledge state");
|
|
654
|
+
}
|
|
655
|
+
return {
|
|
656
|
+
version: 1,
|
|
657
|
+
updatedAt: typeof raw.updatedAt === "string" ? raw.updatedAt : new Date(0).toISOString(),
|
|
658
|
+
vaults: raw.vaults as Record<string, ObsidianVaultState>,
|
|
659
|
+
};
|
|
660
|
+
} catch {
|
|
661
|
+
return {
|
|
662
|
+
version: 1,
|
|
663
|
+
updatedAt: new Date(0).toISOString(),
|
|
664
|
+
vaults: {},
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
async function loadOpenClawWorkspaceState(
|
|
670
|
+
memoryDir: string,
|
|
671
|
+
config: NativeKnowledgeConfig,
|
|
672
|
+
): Promise<OpenClawWorkspaceSyncState> {
|
|
673
|
+
const statePath = resolveOpenClawWorkspaceStatePath(memoryDir, config);
|
|
674
|
+
try {
|
|
675
|
+
const raw = JSON.parse(await readFile(statePath, "utf-8")) as Partial<OpenClawWorkspaceSyncState>;
|
|
676
|
+
if (raw.version !== 1 || typeof raw.files !== "object" || !raw.files) {
|
|
677
|
+
throw new Error("invalid openclaw workspace native knowledge state");
|
|
678
|
+
}
|
|
679
|
+
return {
|
|
680
|
+
version: 1,
|
|
681
|
+
updatedAt: typeof raw.updatedAt === "string" ? raw.updatedAt : new Date(0).toISOString(),
|
|
682
|
+
files: raw.files as Record<string, OpenClawWorkspaceFileState>,
|
|
683
|
+
};
|
|
684
|
+
} catch {
|
|
685
|
+
return {
|
|
686
|
+
version: 1,
|
|
687
|
+
updatedAt: new Date(0).toISOString(),
|
|
688
|
+
files: {},
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
async function loadCuratedIncludeFilesState(
|
|
694
|
+
memoryDir: string,
|
|
695
|
+
config: NativeKnowledgeConfig,
|
|
696
|
+
): Promise<CuratedIncludeFilesSyncState> {
|
|
697
|
+
const statePath = resolveCuratedIncludeFilesStatePath(memoryDir, config);
|
|
698
|
+
try {
|
|
699
|
+
const raw = JSON.parse(await readFile(statePath, "utf-8")) as Partial<CuratedIncludeFilesSyncState>;
|
|
700
|
+
if (raw.version !== 1 || typeof raw.files !== "object" || !raw.files) {
|
|
701
|
+
throw new Error("invalid curated include native knowledge state");
|
|
702
|
+
}
|
|
703
|
+
return {
|
|
704
|
+
version: 1,
|
|
705
|
+
updatedAt: typeof raw.updatedAt === "string" ? raw.updatedAt : new Date(0).toISOString(),
|
|
706
|
+
files: raw.files as Record<string, CuratedIncludeFileState>,
|
|
707
|
+
};
|
|
708
|
+
} catch {
|
|
709
|
+
return {
|
|
710
|
+
version: 1,
|
|
711
|
+
updatedAt: new Date(0).toISOString(),
|
|
712
|
+
files: {},
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
function deriveOpenClawArtifactMetadata(options: {
|
|
718
|
+
sourcePath: string;
|
|
719
|
+
parsed: ParsedFrontmatter;
|
|
720
|
+
sharedSafeGlobs: string[];
|
|
721
|
+
}): Pick<NativeKnowledgeChunk, "derivedDate" | "sessionKey" | "workflowKey" | "author" | "agent" | "namespace" | "privacyClass"> {
|
|
722
|
+
const sharedSafe = compileGlobs(options.sharedSafeGlobs);
|
|
723
|
+
return {
|
|
724
|
+
derivedDate: deriveArtifactDate(options.sourcePath, options.parsed),
|
|
725
|
+
sessionKey: firstStringValue(options.parsed.data, ["sessionKey", "session"]),
|
|
726
|
+
workflowKey: firstStringValue(options.parsed.data, ["workflowKey", "workflow"]),
|
|
727
|
+
author: firstStringValue(options.parsed.data, ["author"]),
|
|
728
|
+
agent: firstStringValue(options.parsed.data, ["agent"]),
|
|
729
|
+
namespace: firstStringValue(options.parsed.data, ["namespace"]),
|
|
730
|
+
privacyClass:
|
|
731
|
+
firstStringValue(options.parsed.data, ["privacyClass", "privacy"])
|
|
732
|
+
?? (matchesCompiledGlobs(options.sourcePath, sharedSafe) ? "shared_safe" : undefined),
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
function buildOpenClawWorkspaceChunks(options: {
|
|
737
|
+
sourcePath: string;
|
|
738
|
+
sourceKind: "bootstrap_doc" | "handoff" | "daily_summary" | "automation_note" | "workspace_doc";
|
|
739
|
+
body: string;
|
|
740
|
+
bodyStartLine: number;
|
|
741
|
+
maxChunkChars: number;
|
|
742
|
+
sourceHash: string;
|
|
743
|
+
mtimeMs: number;
|
|
744
|
+
metadata: Pick<NativeKnowledgeChunk, "derivedDate" | "sessionKey" | "workflowKey" | "author" | "agent" | "namespace" | "privacyClass">;
|
|
745
|
+
}): NativeKnowledgeChunk[] {
|
|
746
|
+
return chunkHeadingAware({
|
|
747
|
+
sourcePath: options.sourcePath,
|
|
748
|
+
content: options.body,
|
|
749
|
+
maxChunkChars: options.maxChunkChars,
|
|
750
|
+
startLineOffset: options.bodyStartLine - 1,
|
|
751
|
+
createChunk: ({ title, startLine, endLine, content }) => ({
|
|
752
|
+
chunkId: `${options.sourceKind}:${options.sourcePath}:${startLine}-${endLine}`,
|
|
753
|
+
sourcePath: options.sourcePath,
|
|
754
|
+
title,
|
|
755
|
+
sourceKind: options.sourceKind,
|
|
756
|
+
startLine,
|
|
757
|
+
endLine,
|
|
758
|
+
content,
|
|
759
|
+
derivedDate: options.metadata.derivedDate,
|
|
760
|
+
sessionKey: options.metadata.sessionKey,
|
|
761
|
+
workflowKey: options.metadata.workflowKey,
|
|
762
|
+
author: options.metadata.author,
|
|
763
|
+
agent: options.metadata.agent,
|
|
764
|
+
namespace: options.metadata.namespace,
|
|
765
|
+
privacyClass: options.metadata.privacyClass,
|
|
766
|
+
sourceHash: options.sourceHash,
|
|
767
|
+
mtimeMs: options.mtimeMs,
|
|
768
|
+
}),
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
function buildObsidianChunks(options: {
|
|
773
|
+
vault: NativeKnowledgeObsidianVaultConfig;
|
|
774
|
+
notePath: string;
|
|
775
|
+
title: string;
|
|
776
|
+
content: string;
|
|
777
|
+
startLineOffset: number;
|
|
778
|
+
derivedDate?: string;
|
|
779
|
+
tags: string[];
|
|
780
|
+
aliases: string[];
|
|
781
|
+
wikilinks: string[];
|
|
782
|
+
backlinks?: string[];
|
|
783
|
+
namespace?: string;
|
|
784
|
+
privacyClass?: string;
|
|
785
|
+
sourceHash: string;
|
|
786
|
+
mtimeMs: number;
|
|
787
|
+
maxChunkChars: number;
|
|
788
|
+
}): NativeKnowledgeChunk[] {
|
|
789
|
+
const noteKey = `${options.vault.id}:${options.notePath}`;
|
|
790
|
+
return chunkHeadingAware({
|
|
791
|
+
sourcePath: options.notePath,
|
|
792
|
+
content: options.content,
|
|
793
|
+
maxChunkChars: options.maxChunkChars,
|
|
794
|
+
startLineOffset: options.startLineOffset,
|
|
795
|
+
createChunk: ({ title, startLine, endLine, content }) => ({
|
|
796
|
+
chunkId: `${noteKey}:${startLine}-${endLine}`,
|
|
797
|
+
sourcePath: `${options.vault.id}/${options.notePath}`,
|
|
798
|
+
title,
|
|
799
|
+
sourceKind: "obsidian_note",
|
|
800
|
+
startLine,
|
|
801
|
+
endLine,
|
|
802
|
+
content,
|
|
803
|
+
vaultId: options.vault.id,
|
|
804
|
+
notePath: options.notePath,
|
|
805
|
+
noteKey,
|
|
806
|
+
derivedDate: options.derivedDate,
|
|
807
|
+
tags: options.tags,
|
|
808
|
+
aliases: options.aliases,
|
|
809
|
+
wikilinks: options.wikilinks,
|
|
810
|
+
backlinks: options.backlinks ?? [],
|
|
811
|
+
namespace: options.namespace,
|
|
812
|
+
privacyClass: options.privacyClass,
|
|
813
|
+
sourceHash: options.sourceHash,
|
|
814
|
+
mtimeMs: options.mtimeMs,
|
|
815
|
+
}),
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
function buildAliasIndex(notes: Record<string, ObsidianNoteState>): Map<string, string[]> {
|
|
820
|
+
const index = new Map<string, string[]>();
|
|
821
|
+
for (const note of Object.values(notes)) {
|
|
822
|
+
if (note.deleted) continue;
|
|
823
|
+
const candidates = [
|
|
824
|
+
note.title,
|
|
825
|
+
path.basename(note.notePath, path.extname(note.notePath)),
|
|
826
|
+
note.notePath.replace(/\.md$/i, ""),
|
|
827
|
+
...note.aliases,
|
|
828
|
+
];
|
|
829
|
+
for (const candidate of candidates) {
|
|
830
|
+
const key = normalizeText(candidate);
|
|
831
|
+
if (!key) continue;
|
|
832
|
+
const existing = index.get(key) ?? [];
|
|
833
|
+
existing.push(note.noteKey);
|
|
834
|
+
index.set(key, uniqueSorted(existing));
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
return index;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
function materializeBacklinks(notes: Record<string, ObsidianNoteState>): Record<string, string[]> {
|
|
841
|
+
const backlinks = new Map<string, Set<string>>();
|
|
842
|
+
const aliasIndex = buildAliasIndex(notes);
|
|
843
|
+
for (const note of Object.values(notes)) {
|
|
844
|
+
if (note.deleted) continue;
|
|
845
|
+
for (const target of note.wikilinks) {
|
|
846
|
+
const matches = aliasIndex.get(normalizeText(target)) ?? [];
|
|
847
|
+
for (const match of matches) {
|
|
848
|
+
if (match === note.noteKey) continue;
|
|
849
|
+
const bucket = backlinks.get(match) ?? new Set<string>();
|
|
850
|
+
bucket.add(note.notePath);
|
|
851
|
+
backlinks.set(match, bucket);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
return Object.fromEntries(
|
|
856
|
+
[...backlinks.entries()].map(([noteKey, refs]) => [noteKey, [...refs].sort()]),
|
|
857
|
+
);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
export async function syncObsidianVaults(options: {
|
|
861
|
+
memoryDir: string;
|
|
862
|
+
config: NativeKnowledgeConfig;
|
|
863
|
+
}): Promise<NativeKnowledgeSyncResult> {
|
|
864
|
+
if (options.config.obsidianVaults.length === 0) {
|
|
865
|
+
return {
|
|
866
|
+
statePath: resolveNativeKnowledgeStatePath(options.memoryDir, options.config),
|
|
867
|
+
vaultCount: 0,
|
|
868
|
+
touchedNotes: 0,
|
|
869
|
+
deletedNotes: 0,
|
|
870
|
+
chunkCount: 0,
|
|
871
|
+
activeChunks: [],
|
|
872
|
+
};
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
const state = await loadSyncState(options.memoryDir, options.config);
|
|
876
|
+
const nextVaults: Record<string, ObsidianVaultState> = {};
|
|
877
|
+
let touchedNotes = 0;
|
|
878
|
+
let deletedNotes = 0;
|
|
879
|
+
let chunkCount = 0;
|
|
880
|
+
|
|
881
|
+
for (const vault of options.config.obsidianVaults) {
|
|
882
|
+
const previousVault = state.vaults[vault.id];
|
|
883
|
+
const previousNotes = previousVault?.notes ?? {};
|
|
884
|
+
const notePaths = await listMarkdownFiles(vault.rootDir);
|
|
885
|
+
if (notePaths === null) {
|
|
886
|
+
nextVaults[vault.id] = previousVault ?? {
|
|
887
|
+
vaultId: vault.id,
|
|
888
|
+
rootDir: vault.rootDir,
|
|
889
|
+
syncedAt: new Date().toISOString(),
|
|
890
|
+
notes: previousNotes,
|
|
891
|
+
};
|
|
892
|
+
chunkCount += Object.values(previousNotes)
|
|
893
|
+
.filter((note) => !note.deleted)
|
|
894
|
+
.reduce((total, note) => total + note.chunks.length, 0);
|
|
895
|
+
continue;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
const includePatterns = compileGlobs(vault.includeGlobs);
|
|
899
|
+
const excludePatterns = compileGlobs(vault.excludeGlobs);
|
|
900
|
+
const includedNotePaths = notePaths.filter((notePath) => {
|
|
901
|
+
if (!matchesCompiledGlobs(notePath, includePatterns)) return false;
|
|
902
|
+
if (matchesCompiledGlobs(notePath, excludePatterns)) return false;
|
|
903
|
+
return true;
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
const nextNotes: Record<string, ObsidianNoteState> = {};
|
|
907
|
+
const seenNoteKeys = new Set<string>();
|
|
908
|
+
|
|
909
|
+
for (const notePath of includedNotePaths) {
|
|
910
|
+
const absPath = path.join(vault.rootDir, notePath);
|
|
911
|
+
const content = await readFile(absPath, "utf-8").catch(() => null);
|
|
912
|
+
if (content === null) continue;
|
|
913
|
+
const info = await stat(absPath).catch(() => null);
|
|
914
|
+
if (!info?.isFile()) continue;
|
|
915
|
+
|
|
916
|
+
const sourceHash = createHash("sha256").update(content).digest("hex");
|
|
917
|
+
const noteKey = `${vault.id}:${notePath}`;
|
|
918
|
+
seenNoteKeys.add(noteKey);
|
|
919
|
+
const previous = previousNotes[noteKey];
|
|
920
|
+
if (previous && previous.deleted !== true && previous.sourceHash === sourceHash && previous.mtimeMs === info.mtimeMs) {
|
|
921
|
+
nextNotes[noteKey] = {
|
|
922
|
+
...previous,
|
|
923
|
+
deleted: false,
|
|
924
|
+
deletedAt: undefined,
|
|
925
|
+
};
|
|
926
|
+
chunkCount += previous.chunks.length;
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
const parsed = parseFrontmatter(content);
|
|
931
|
+
const { targets } = extractWikilinks(parsed.body);
|
|
932
|
+
const tags = uniqueSorted([
|
|
933
|
+
...parseFrontmatterList(parsed.data.tags),
|
|
934
|
+
...extractInlineTags(parsed.body),
|
|
935
|
+
]);
|
|
936
|
+
const aliases = parseFrontmatterList(parsed.data.aliases);
|
|
937
|
+
const { namespace, privacyClass } = classifyObsidianNote(notePath, vault);
|
|
938
|
+
const title = resolveNoteTitle(notePath, parsed);
|
|
939
|
+
const derivedDate = deriveDailyNoteDate(notePath, vault.dailyNotePatterns);
|
|
940
|
+
const chunks = buildObsidianChunks({
|
|
941
|
+
vault,
|
|
942
|
+
notePath,
|
|
943
|
+
title,
|
|
944
|
+
content: parsed.body,
|
|
945
|
+
startLineOffset: parsed.bodyStartLine - 1,
|
|
946
|
+
derivedDate,
|
|
947
|
+
tags,
|
|
948
|
+
aliases,
|
|
949
|
+
wikilinks: targets,
|
|
950
|
+
namespace,
|
|
951
|
+
privacyClass,
|
|
952
|
+
sourceHash,
|
|
953
|
+
mtimeMs: info.mtimeMs,
|
|
954
|
+
maxChunkChars: options.config.maxChunkChars,
|
|
955
|
+
});
|
|
956
|
+
|
|
957
|
+
nextNotes[noteKey] = {
|
|
958
|
+
noteKey,
|
|
959
|
+
notePath,
|
|
960
|
+
title,
|
|
961
|
+
derivedDate,
|
|
962
|
+
tags,
|
|
963
|
+
aliases,
|
|
964
|
+
wikilinks: targets,
|
|
965
|
+
backlinks: [],
|
|
966
|
+
namespace,
|
|
967
|
+
privacyClass,
|
|
968
|
+
sourceHash,
|
|
969
|
+
mtimeMs: info.mtimeMs,
|
|
970
|
+
deleted: false,
|
|
971
|
+
chunks,
|
|
972
|
+
};
|
|
973
|
+
touchedNotes += 1;
|
|
974
|
+
chunkCount += chunks.length;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
for (const [noteKey, previous] of Object.entries(previousNotes)) {
|
|
978
|
+
if (seenNoteKeys.has(noteKey)) continue;
|
|
979
|
+
nextNotes[noteKey] = {
|
|
980
|
+
...previous,
|
|
981
|
+
deleted: true,
|
|
982
|
+
deletedAt: new Date().toISOString(),
|
|
983
|
+
chunks: [],
|
|
984
|
+
};
|
|
985
|
+
deletedNotes += 1;
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
if (vault.materializeBacklinks) {
|
|
989
|
+
const backlinks = materializeBacklinks(nextNotes);
|
|
990
|
+
for (const note of Object.values(nextNotes)) {
|
|
991
|
+
if (note.deleted) continue;
|
|
992
|
+
note.backlinks = backlinks[note.noteKey] ?? [];
|
|
993
|
+
note.chunks = note.chunks.map((chunk) => ({
|
|
994
|
+
...chunk,
|
|
995
|
+
backlinks: note.backlinks,
|
|
996
|
+
}));
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
nextVaults[vault.id] = {
|
|
1001
|
+
vaultId: vault.id,
|
|
1002
|
+
rootDir: vault.rootDir,
|
|
1003
|
+
syncedAt: new Date().toISOString(),
|
|
1004
|
+
notes: nextNotes,
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
const nextState: ObsidianSyncState = {
|
|
1009
|
+
version: 1,
|
|
1010
|
+
updatedAt: new Date().toISOString(),
|
|
1011
|
+
vaults: nextVaults,
|
|
1012
|
+
};
|
|
1013
|
+
const activeChunks = loadActiveObsidianChunks({
|
|
1014
|
+
state: nextState,
|
|
1015
|
+
defaultNamespace: "default",
|
|
1016
|
+
});
|
|
1017
|
+
const statePath = resolveNativeKnowledgeStatePath(options.memoryDir, options.config);
|
|
1018
|
+
try {
|
|
1019
|
+
await mkdir(path.dirname(statePath), { recursive: true });
|
|
1020
|
+
await writeFile(statePath, `${JSON.stringify(nextState, null, 2)}\n`, "utf-8");
|
|
1021
|
+
} catch (error) {
|
|
1022
|
+
log.warn(`native knowledge: failed to persist obsidian sync state (fail-open): ${String(error)}`);
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
return {
|
|
1026
|
+
statePath,
|
|
1027
|
+
vaultCount: options.config.obsidianVaults.length,
|
|
1028
|
+
touchedNotes,
|
|
1029
|
+
deletedNotes,
|
|
1030
|
+
chunkCount,
|
|
1031
|
+
activeChunks,
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
function loadActiveObsidianChunks(options: {
|
|
1036
|
+
state: ObsidianSyncState;
|
|
1037
|
+
recallNamespaces?: string[];
|
|
1038
|
+
defaultNamespace: string;
|
|
1039
|
+
}): NativeKnowledgeChunk[] {
|
|
1040
|
+
const out: NativeKnowledgeChunk[] = [];
|
|
1041
|
+
for (const vault of Object.values(options.state.vaults)) {
|
|
1042
|
+
for (const note of Object.values(vault.notes)) {
|
|
1043
|
+
if (note.deleted) continue;
|
|
1044
|
+
if (!isChunkAllowedForRecall(note, options.recallNamespaces, options.defaultNamespace)) continue;
|
|
1045
|
+
out.push(...note.chunks);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
return out;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
function isChunkAllowedForRecall(
|
|
1052
|
+
chunk: Pick<NativeKnowledgeChunk, "namespace" | "privacyClass">,
|
|
1053
|
+
recallNamespaces: string[] | undefined,
|
|
1054
|
+
defaultNamespace: string,
|
|
1055
|
+
): boolean {
|
|
1056
|
+
const namespace = chunk.namespace?.trim() || defaultNamespace;
|
|
1057
|
+
if (
|
|
1058
|
+
Array.isArray(recallNamespaces) &&
|
|
1059
|
+
namespace !== defaultNamespace &&
|
|
1060
|
+
!recallNamespaces.includes(namespace)
|
|
1061
|
+
) {
|
|
1062
|
+
return false;
|
|
1063
|
+
}
|
|
1064
|
+
const privacyClass = chunk.privacyClass?.trim().toLowerCase();
|
|
1065
|
+
if (
|
|
1066
|
+
privacyClass === "private" &&
|
|
1067
|
+
Array.isArray(recallNamespaces) &&
|
|
1068
|
+
(namespace !== defaultNamespace || !recallNamespaces.includes(defaultNamespace))
|
|
1069
|
+
) {
|
|
1070
|
+
return false;
|
|
1071
|
+
}
|
|
1072
|
+
return true;
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
function loadActiveOpenClawWorkspaceChunks(options: {
|
|
1076
|
+
state: OpenClawWorkspaceSyncState;
|
|
1077
|
+
recallNamespaces?: string[];
|
|
1078
|
+
defaultNamespace: string;
|
|
1079
|
+
}): NativeKnowledgeChunk[] {
|
|
1080
|
+
const out: NativeKnowledgeChunk[] = [];
|
|
1081
|
+
for (const file of Object.values(options.state.files)) {
|
|
1082
|
+
if (file.deleted) continue;
|
|
1083
|
+
if (!isChunkAllowedForRecall(file, options.recallNamespaces, options.defaultNamespace)) continue;
|
|
1084
|
+
out.push(...file.chunks);
|
|
1085
|
+
}
|
|
1086
|
+
return out;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
function deriveCuratedFileMetadata(options: {
|
|
1090
|
+
sourcePath: string;
|
|
1091
|
+
parsed: ParsedFrontmatter;
|
|
1092
|
+
}): Pick<NativeKnowledgeChunk, "derivedDate" | "namespace" | "privacyClass"> {
|
|
1093
|
+
return {
|
|
1094
|
+
derivedDate: deriveArtifactDate(options.sourcePath, options.parsed),
|
|
1095
|
+
namespace: firstStringValue(options.parsed.data, ["namespace"]) ?? deriveNamespaceFromIncludePath(options.sourcePath),
|
|
1096
|
+
privacyClass: firstStringValue(options.parsed.data, ["privacyClass", "privacy"]),
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
function buildCuratedIncludeChunks(options: {
|
|
1101
|
+
sourcePath: string;
|
|
1102
|
+
body: string;
|
|
1103
|
+
bodyStartLine: number;
|
|
1104
|
+
maxChunkChars: number;
|
|
1105
|
+
sourceHash: string;
|
|
1106
|
+
mtimeMs: number;
|
|
1107
|
+
metadata: Pick<NativeKnowledgeChunk, "derivedDate" | "namespace" | "privacyClass">;
|
|
1108
|
+
}): NativeKnowledgeChunk[] {
|
|
1109
|
+
return chunkHeadingAware({
|
|
1110
|
+
sourcePath: options.sourcePath,
|
|
1111
|
+
content: options.body,
|
|
1112
|
+
maxChunkChars: options.maxChunkChars,
|
|
1113
|
+
startLineOffset: options.bodyStartLine - 1,
|
|
1114
|
+
createChunk: ({ title, startLine, endLine, content }) => ({
|
|
1115
|
+
chunkId: `${options.sourcePath}:${startLine}-${endLine}`,
|
|
1116
|
+
sourcePath: options.sourcePath,
|
|
1117
|
+
title,
|
|
1118
|
+
sourceKind: detectSourceKind(options.sourcePath),
|
|
1119
|
+
startLine,
|
|
1120
|
+
endLine,
|
|
1121
|
+
content,
|
|
1122
|
+
derivedDate: options.metadata.derivedDate,
|
|
1123
|
+
namespace: options.metadata.namespace,
|
|
1124
|
+
privacyClass: options.metadata.privacyClass,
|
|
1125
|
+
sourceHash: options.sourceHash,
|
|
1126
|
+
mtimeMs: options.mtimeMs,
|
|
1127
|
+
}),
|
|
1128
|
+
});
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
function loadActiveCuratedIncludeChunks(options: {
|
|
1132
|
+
state: CuratedIncludeFilesSyncState;
|
|
1133
|
+
recallNamespaces?: string[];
|
|
1134
|
+
defaultNamespace: string;
|
|
1135
|
+
}): NativeKnowledgeChunk[] {
|
|
1136
|
+
const out: NativeKnowledgeChunk[] = [];
|
|
1137
|
+
for (const file of Object.values(options.state.files)) {
|
|
1138
|
+
if (file.deleted) continue;
|
|
1139
|
+
if (!isChunkAllowedForRecall(file, options.recallNamespaces, options.defaultNamespace)) continue;
|
|
1140
|
+
out.push(...file.chunks);
|
|
1141
|
+
}
|
|
1142
|
+
return out;
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
function dedupeNativeKnowledgeChunks(chunks: NativeKnowledgeChunk[]): NativeKnowledgeChunk[] {
|
|
1146
|
+
const seen = new Set<string>();
|
|
1147
|
+
const priority = new Map<NativeKnowledgeChunk["sourceKind"], number>([
|
|
1148
|
+
["handoff", 1],
|
|
1149
|
+
["daily_summary", 2],
|
|
1150
|
+
["bootstrap_doc", 3],
|
|
1151
|
+
["automation_note", 4],
|
|
1152
|
+
["workspace_doc", 5],
|
|
1153
|
+
["identity", 6],
|
|
1154
|
+
["memory", 7],
|
|
1155
|
+
["obsidian_note", 8],
|
|
1156
|
+
]);
|
|
1157
|
+
return [...chunks]
|
|
1158
|
+
.sort((left, right) => {
|
|
1159
|
+
const leftPriority = priority.get(left.sourceKind) ?? 99;
|
|
1160
|
+
const rightPriority = priority.get(right.sourceKind) ?? 99;
|
|
1161
|
+
return (
|
|
1162
|
+
leftPriority - rightPriority
|
|
1163
|
+
|| left.sourcePath.localeCompare(right.sourcePath)
|
|
1164
|
+
|| left.startLine - right.startLine
|
|
1165
|
+
);
|
|
1166
|
+
})
|
|
1167
|
+
.filter((chunk) => {
|
|
1168
|
+
const key = [
|
|
1169
|
+
chunk.sourcePath,
|
|
1170
|
+
chunk.startLine,
|
|
1171
|
+
chunk.endLine,
|
|
1172
|
+
chunk.content,
|
|
1173
|
+
].join("::");
|
|
1174
|
+
if (seen.has(key)) return false;
|
|
1175
|
+
seen.add(key);
|
|
1176
|
+
return true;
|
|
1177
|
+
});
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
async function findPersistedNativeKnowledgeStateFiles(
|
|
1181
|
+
rootDir: string,
|
|
1182
|
+
maxDepth: number,
|
|
1183
|
+
currentDepth: number = 0,
|
|
1184
|
+
): Promise<string[]> {
|
|
1185
|
+
if (currentDepth > maxDepth) return [];
|
|
1186
|
+
const entries = await readdir(rootDir, { withFileTypes: true }).catch(() => []);
|
|
1187
|
+
const out: string[] = [];
|
|
1188
|
+
for (const entry of entries) {
|
|
1189
|
+
const fullPath = path.join(rootDir, entry.name);
|
|
1190
|
+
if (entry.isFile() && PERSISTED_NATIVE_KNOWLEDGE_STATE_FILES.has(entry.name)) {
|
|
1191
|
+
out.push(fullPath);
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
if (!entry.isDirectory()) continue;
|
|
1195
|
+
out.push(...await findPersistedNativeKnowledgeStateFiles(fullPath, maxDepth, currentDepth + 1));
|
|
1196
|
+
}
|
|
1197
|
+
return out;
|
|
1198
|
+
}
|
|
1199
|
+
|
|
1200
|
+
export async function loadPersistedNativeKnowledgeChunks(options: {
|
|
1201
|
+
memoryDir: string;
|
|
1202
|
+
recallNamespaces?: string[];
|
|
1203
|
+
defaultNamespace: string;
|
|
1204
|
+
}): Promise<NativeKnowledgeChunk[]> {
|
|
1205
|
+
const stateFiles = await findPersistedNativeKnowledgeStateFiles(options.memoryDir, 4);
|
|
1206
|
+
if (stateFiles.length === 0) return [];
|
|
1207
|
+
|
|
1208
|
+
const chunks: NativeKnowledgeChunk[] = [];
|
|
1209
|
+
for (const statePath of stateFiles.sort()) {
|
|
1210
|
+
const raw = await readFile(statePath, "utf-8").catch(() => "");
|
|
1211
|
+
if (!raw) continue;
|
|
1212
|
+
try {
|
|
1213
|
+
const parsed = JSON.parse(raw) as { vaults?: unknown; files?: unknown };
|
|
1214
|
+
if (typeof parsed.vaults === "object" && parsed.vaults) {
|
|
1215
|
+
const state: ObsidianSyncState = {
|
|
1216
|
+
version: 1,
|
|
1217
|
+
updatedAt: new Date(0).toISOString(),
|
|
1218
|
+
vaults: parsed.vaults as Record<string, ObsidianVaultState>,
|
|
1219
|
+
};
|
|
1220
|
+
chunks.push(...loadActiveObsidianChunks({
|
|
1221
|
+
state,
|
|
1222
|
+
recallNamespaces: options.recallNamespaces,
|
|
1223
|
+
defaultNamespace: options.defaultNamespace,
|
|
1224
|
+
}).map((chunk) => {
|
|
1225
|
+
const note = Object.values(state.vaults)
|
|
1226
|
+
.flatMap((vault) => Object.values(vault.notes))
|
|
1227
|
+
.find((entry) => entry.chunks.some((candidate) => candidate.chunkId === chunk.chunkId));
|
|
1228
|
+
if (!note) return chunk;
|
|
1229
|
+
return {
|
|
1230
|
+
...chunk,
|
|
1231
|
+
derivedDate: chunk.derivedDate ?? note.derivedDate,
|
|
1232
|
+
namespace: chunk.namespace ?? note.namespace,
|
|
1233
|
+
privacyClass: chunk.privacyClass ?? note.privacyClass,
|
|
1234
|
+
aliases: chunk.aliases ?? note.aliases,
|
|
1235
|
+
tags: chunk.tags ?? note.tags,
|
|
1236
|
+
wikilinks: chunk.wikilinks ?? note.wikilinks,
|
|
1237
|
+
backlinks: chunk.backlinks ?? note.backlinks,
|
|
1238
|
+
};
|
|
1239
|
+
}));
|
|
1240
|
+
continue;
|
|
1241
|
+
}
|
|
1242
|
+
if (typeof parsed.files === "object" && parsed.files) {
|
|
1243
|
+
if (path.basename(statePath) === "openclaw-workspace-sync.json") {
|
|
1244
|
+
const state: OpenClawWorkspaceSyncState = {
|
|
1245
|
+
version: 1,
|
|
1246
|
+
updatedAt: new Date(0).toISOString(),
|
|
1247
|
+
files: parsed.files as Record<string, OpenClawWorkspaceFileState>,
|
|
1248
|
+
};
|
|
1249
|
+
chunks.push(...loadActiveOpenClawWorkspaceChunks({
|
|
1250
|
+
state,
|
|
1251
|
+
recallNamespaces: options.recallNamespaces,
|
|
1252
|
+
defaultNamespace: options.defaultNamespace,
|
|
1253
|
+
}).map((chunk) => {
|
|
1254
|
+
const file = state.files[chunk.sourcePath];
|
|
1255
|
+
if (!file) return chunk;
|
|
1256
|
+
return {
|
|
1257
|
+
...chunk,
|
|
1258
|
+
derivedDate: chunk.derivedDate ?? file.derivedDate,
|
|
1259
|
+
namespace: chunk.namespace ?? file.namespace,
|
|
1260
|
+
privacyClass: chunk.privacyClass ?? file.privacyClass,
|
|
1261
|
+
sessionKey: chunk.sessionKey ?? file.sessionKey,
|
|
1262
|
+
workflowKey: chunk.workflowKey ?? file.workflowKey,
|
|
1263
|
+
author: chunk.author ?? file.author,
|
|
1264
|
+
agent: chunk.agent ?? file.agent,
|
|
1265
|
+
};
|
|
1266
|
+
}));
|
|
1267
|
+
continue;
|
|
1268
|
+
}
|
|
1269
|
+
const state: CuratedIncludeFilesSyncState = {
|
|
1270
|
+
version: 1,
|
|
1271
|
+
updatedAt: new Date(0).toISOString(),
|
|
1272
|
+
files: parsed.files as Record<string, CuratedIncludeFileState>,
|
|
1273
|
+
};
|
|
1274
|
+
chunks.push(...loadActiveCuratedIncludeChunks({
|
|
1275
|
+
state,
|
|
1276
|
+
recallNamespaces: options.recallNamespaces,
|
|
1277
|
+
defaultNamespace: options.defaultNamespace,
|
|
1278
|
+
}).map((chunk) => {
|
|
1279
|
+
const file = state.files[chunk.sourcePath];
|
|
1280
|
+
if (!file) return chunk;
|
|
1281
|
+
return {
|
|
1282
|
+
...chunk,
|
|
1283
|
+
derivedDate: chunk.derivedDate ?? file.derivedDate,
|
|
1284
|
+
namespace: chunk.namespace ?? file.namespace,
|
|
1285
|
+
privacyClass: chunk.privacyClass ?? file.privacyClass,
|
|
1286
|
+
};
|
|
1287
|
+
}));
|
|
1288
|
+
}
|
|
1289
|
+
} catch {
|
|
1290
|
+
continue;
|
|
1291
|
+
}
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
return dedupeNativeKnowledgeChunks(chunks);
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
export async function syncOpenClawWorkspaceArtifacts(options: {
|
|
1298
|
+
workspaceDir: string;
|
|
1299
|
+
memoryDir: string;
|
|
1300
|
+
config: NativeKnowledgeConfig;
|
|
1301
|
+
}): Promise<{
|
|
1302
|
+
statePath: string;
|
|
1303
|
+
touchedFiles: number;
|
|
1304
|
+
deletedFiles: number;
|
|
1305
|
+
chunkCount: number;
|
|
1306
|
+
activeChunks: NativeKnowledgeChunk[];
|
|
1307
|
+
}> {
|
|
1308
|
+
const adapter = options.config.openclawWorkspace;
|
|
1309
|
+
const statePath = resolveOpenClawWorkspaceStatePath(options.memoryDir, options.config);
|
|
1310
|
+
if (!adapter?.enabled) {
|
|
1311
|
+
return { statePath, touchedFiles: 0, deletedFiles: 0, chunkCount: 0, activeChunks: [] };
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
const previousState = await loadOpenClawWorkspaceState(options.memoryDir, options.config);
|
|
1315
|
+
const listedFiles = await listMarkdownFiles(options.workspaceDir);
|
|
1316
|
+
if (listedFiles === null) {
|
|
1317
|
+
return {
|
|
1318
|
+
statePath,
|
|
1319
|
+
touchedFiles: 0,
|
|
1320
|
+
deletedFiles: 0,
|
|
1321
|
+
chunkCount: Object.values(previousState.files)
|
|
1322
|
+
.filter((file) => !file.deleted)
|
|
1323
|
+
.reduce((total, file) => total + file.chunks.length, 0),
|
|
1324
|
+
activeChunks: loadActiveOpenClawWorkspaceChunks({
|
|
1325
|
+
state: previousState,
|
|
1326
|
+
defaultNamespace: "default",
|
|
1327
|
+
}),
|
|
1328
|
+
};
|
|
1329
|
+
}
|
|
1330
|
+
|
|
1331
|
+
const candidates = resolveFileCandidates({
|
|
1332
|
+
listedFiles,
|
|
1333
|
+
bootstrapFiles: adapter.bootstrapFiles,
|
|
1334
|
+
handoffGlobs: adapter.handoffGlobs,
|
|
1335
|
+
dailySummaryGlobs: adapter.dailySummaryGlobs,
|
|
1336
|
+
automationNoteGlobs: adapter.automationNoteGlobs,
|
|
1337
|
+
workspaceDocGlobs: adapter.workspaceDocGlobs,
|
|
1338
|
+
excludeGlobs: adapter.excludeGlobs,
|
|
1339
|
+
});
|
|
1340
|
+
const nextFiles: Record<string, OpenClawWorkspaceFileState> = {};
|
|
1341
|
+
const seen = new Set<string>();
|
|
1342
|
+
let touchedFiles = 0;
|
|
1343
|
+
let deletedFiles = 0;
|
|
1344
|
+
|
|
1345
|
+
for (const candidate of candidates) {
|
|
1346
|
+
const absPath = path.join(options.workspaceDir, candidate.sourcePath);
|
|
1347
|
+
const content = await readFile(absPath, "utf-8").catch(() => null);
|
|
1348
|
+
if (content === null) continue;
|
|
1349
|
+
const info = await stat(absPath).catch(() => null);
|
|
1350
|
+
if (!info?.isFile()) continue;
|
|
1351
|
+
|
|
1352
|
+
const sourceHash = createHash("sha256").update(content).digest("hex");
|
|
1353
|
+
const parsed = parseFrontmatter(content);
|
|
1354
|
+
const metadata = deriveOpenClawArtifactMetadata({
|
|
1355
|
+
sourcePath: candidate.sourcePath,
|
|
1356
|
+
parsed,
|
|
1357
|
+
sharedSafeGlobs: adapter.sharedSafeGlobs,
|
|
1358
|
+
});
|
|
1359
|
+
const title = resolveNoteTitle(candidate.sourcePath, parsed);
|
|
1360
|
+
const syncConfigHash = createHash("sha256")
|
|
1361
|
+
.update(JSON.stringify({
|
|
1362
|
+
sourceKind: candidate.sourceKind,
|
|
1363
|
+
maxChunkChars: options.config.maxChunkChars,
|
|
1364
|
+
metadata,
|
|
1365
|
+
}))
|
|
1366
|
+
.digest("hex");
|
|
1367
|
+
const previous = previousState.files[candidate.sourcePath];
|
|
1368
|
+
if (
|
|
1369
|
+
previous &&
|
|
1370
|
+
previous.deleted !== true &&
|
|
1371
|
+
previous.sourceHash === sourceHash &&
|
|
1372
|
+
previous.mtimeMs === info.mtimeMs &&
|
|
1373
|
+
previous.syncConfigHash === syncConfigHash
|
|
1374
|
+
) {
|
|
1375
|
+
nextFiles[candidate.sourcePath] = {
|
|
1376
|
+
...previous,
|
|
1377
|
+
deleted: false,
|
|
1378
|
+
deletedAt: undefined,
|
|
1379
|
+
};
|
|
1380
|
+
seen.add(candidate.sourcePath);
|
|
1381
|
+
continue;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
const chunks = buildOpenClawWorkspaceChunks({
|
|
1385
|
+
sourcePath: candidate.sourcePath,
|
|
1386
|
+
sourceKind: candidate.sourceKind,
|
|
1387
|
+
body: parsed.body,
|
|
1388
|
+
bodyStartLine: parsed.bodyStartLine,
|
|
1389
|
+
maxChunkChars: options.config.maxChunkChars,
|
|
1390
|
+
sourceHash,
|
|
1391
|
+
mtimeMs: info.mtimeMs,
|
|
1392
|
+
metadata,
|
|
1393
|
+
});
|
|
1394
|
+
|
|
1395
|
+
nextFiles[candidate.sourcePath] = {
|
|
1396
|
+
sourcePath: candidate.sourcePath,
|
|
1397
|
+
sourceKind: candidate.sourceKind,
|
|
1398
|
+
title,
|
|
1399
|
+
namespace: metadata.namespace,
|
|
1400
|
+
privacyClass: metadata.privacyClass,
|
|
1401
|
+
derivedDate: metadata.derivedDate,
|
|
1402
|
+
sessionKey: metadata.sessionKey,
|
|
1403
|
+
workflowKey: metadata.workflowKey,
|
|
1404
|
+
author: metadata.author,
|
|
1405
|
+
agent: metadata.agent,
|
|
1406
|
+
sourceHash,
|
|
1407
|
+
syncConfigHash,
|
|
1408
|
+
mtimeMs: info.mtimeMs,
|
|
1409
|
+
deleted: false,
|
|
1410
|
+
chunks,
|
|
1411
|
+
};
|
|
1412
|
+
touchedFiles += 1;
|
|
1413
|
+
seen.add(candidate.sourcePath);
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
for (const [sourcePath, previous] of Object.entries(previousState.files)) {
|
|
1417
|
+
if (seen.has(sourcePath)) continue;
|
|
1418
|
+
nextFiles[sourcePath] = {
|
|
1419
|
+
...previous,
|
|
1420
|
+
deleted: true,
|
|
1421
|
+
deletedAt: new Date().toISOString(),
|
|
1422
|
+
chunks: [],
|
|
1423
|
+
};
|
|
1424
|
+
deletedFiles += 1;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1427
|
+
const nextState: OpenClawWorkspaceSyncState = {
|
|
1428
|
+
version: 1,
|
|
1429
|
+
updatedAt: new Date().toISOString(),
|
|
1430
|
+
files: nextFiles,
|
|
1431
|
+
};
|
|
1432
|
+
const activeChunks = loadActiveOpenClawWorkspaceChunks({
|
|
1433
|
+
state: nextState,
|
|
1434
|
+
defaultNamespace: "default",
|
|
1435
|
+
});
|
|
1436
|
+
const chunkCount = activeChunks.length;
|
|
1437
|
+
try {
|
|
1438
|
+
await mkdir(path.dirname(statePath), { recursive: true });
|
|
1439
|
+
await writeFile(statePath, `${JSON.stringify(nextState, null, 2)}\n`, "utf-8");
|
|
1440
|
+
} catch (error) {
|
|
1441
|
+
log.warn(`native knowledge: failed to persist openclaw workspace sync state (fail-open): ${String(error)}`);
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
return {
|
|
1445
|
+
statePath,
|
|
1446
|
+
touchedFiles,
|
|
1447
|
+
deletedFiles,
|
|
1448
|
+
chunkCount,
|
|
1449
|
+
activeChunks,
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
export async function syncCuratedIncludeFiles(options: {
|
|
1454
|
+
workspaceDir: string;
|
|
1455
|
+
memoryDir: string;
|
|
1456
|
+
config: NativeKnowledgeConfig;
|
|
1457
|
+
recallNamespaces?: string[];
|
|
1458
|
+
defaultNamespace: string;
|
|
1459
|
+
skipSourcePaths?: string[];
|
|
1460
|
+
}): Promise<{
|
|
1461
|
+
statePath: string;
|
|
1462
|
+
touchedFiles: number;
|
|
1463
|
+
deletedFiles: number;
|
|
1464
|
+
chunkCount: number;
|
|
1465
|
+
activeChunks: NativeKnowledgeChunk[];
|
|
1466
|
+
}> {
|
|
1467
|
+
const statePath = resolveCuratedIncludeFilesStatePath(options.memoryDir, options.config);
|
|
1468
|
+
const previousState = await loadCuratedIncludeFilesState(options.memoryDir, options.config);
|
|
1469
|
+
const workspaceInfo = await stat(options.workspaceDir).catch(() => null);
|
|
1470
|
+
if (!workspaceInfo?.isDirectory()) {
|
|
1471
|
+
return {
|
|
1472
|
+
statePath,
|
|
1473
|
+
touchedFiles: 0,
|
|
1474
|
+
deletedFiles: 0,
|
|
1475
|
+
chunkCount: Object.values(previousState.files)
|
|
1476
|
+
.filter((file) => !file.deleted)
|
|
1477
|
+
.reduce((total, file) => total + file.chunks.length, 0),
|
|
1478
|
+
activeChunks: loadActiveCuratedIncludeChunks({
|
|
1479
|
+
state: previousState,
|
|
1480
|
+
recallNamespaces: options.recallNamespaces,
|
|
1481
|
+
defaultNamespace: options.defaultNamespace,
|
|
1482
|
+
}),
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
|
|
1486
|
+
const skipped = new Set((options.skipSourcePaths ?? []).map((value) => value.replace(/\\/g, "/")));
|
|
1487
|
+
const candidatePaths = await resolveCandidatePaths({
|
|
1488
|
+
workspaceDir: options.workspaceDir,
|
|
1489
|
+
includeFiles: options.config.includeFiles,
|
|
1490
|
+
defaultNamespace: options.defaultNamespace,
|
|
1491
|
+
identityVariantMode: "disk",
|
|
1492
|
+
});
|
|
1493
|
+
const nextFiles: Record<string, CuratedIncludeFileState> = {};
|
|
1494
|
+
const seen = new Set<string>();
|
|
1495
|
+
let touchedFiles = 0;
|
|
1496
|
+
let deletedFiles = 0;
|
|
1497
|
+
|
|
1498
|
+
for (const filePath of candidatePaths) {
|
|
1499
|
+
if (!(await readableFile(filePath))) continue;
|
|
1500
|
+
const content = await readFile(filePath, "utf-8").catch(() => null);
|
|
1501
|
+
if (content === null) continue;
|
|
1502
|
+
const info = await stat(filePath).catch(() => null);
|
|
1503
|
+
if (!info?.isFile()) continue;
|
|
1504
|
+
|
|
1505
|
+
const sourcePath = path.relative(options.workspaceDir, filePath).replace(/\\/g, "/");
|
|
1506
|
+
if (skipped.has(sourcePath)) continue;
|
|
1507
|
+
|
|
1508
|
+
const parsed = parseFrontmatter(content);
|
|
1509
|
+
const metadata = deriveCuratedFileMetadata({
|
|
1510
|
+
sourcePath,
|
|
1511
|
+
parsed,
|
|
1512
|
+
});
|
|
1513
|
+
const sourceKind = detectSourceKind(sourcePath);
|
|
1514
|
+
const sourceHash = createHash("sha256").update(content).digest("hex");
|
|
1515
|
+
const title = resolveNoteTitle(sourcePath, parsed);
|
|
1516
|
+
const syncConfigHash = createHash("sha256")
|
|
1517
|
+
.update(JSON.stringify({
|
|
1518
|
+
sourceKind,
|
|
1519
|
+
maxChunkChars: options.config.maxChunkChars,
|
|
1520
|
+
metadata,
|
|
1521
|
+
}))
|
|
1522
|
+
.digest("hex");
|
|
1523
|
+
const previous = previousState.files[sourcePath];
|
|
1524
|
+
if (
|
|
1525
|
+
previous &&
|
|
1526
|
+
previous.deleted !== true &&
|
|
1527
|
+
previous.sourceHash === sourceHash &&
|
|
1528
|
+
previous.mtimeMs === info.mtimeMs &&
|
|
1529
|
+
previous.syncConfigHash === syncConfigHash
|
|
1530
|
+
) {
|
|
1531
|
+
nextFiles[sourcePath] = {
|
|
1532
|
+
...previous,
|
|
1533
|
+
deleted: false,
|
|
1534
|
+
deletedAt: undefined,
|
|
1535
|
+
};
|
|
1536
|
+
seen.add(sourcePath);
|
|
1537
|
+
continue;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
const chunks = buildCuratedIncludeChunks({
|
|
1541
|
+
sourcePath,
|
|
1542
|
+
body: parsed.body,
|
|
1543
|
+
bodyStartLine: parsed.bodyStartLine,
|
|
1544
|
+
maxChunkChars: options.config.maxChunkChars,
|
|
1545
|
+
sourceHash,
|
|
1546
|
+
mtimeMs: info.mtimeMs,
|
|
1547
|
+
metadata,
|
|
1548
|
+
});
|
|
1549
|
+
nextFiles[sourcePath] = {
|
|
1550
|
+
sourcePath,
|
|
1551
|
+
sourceKind,
|
|
1552
|
+
title,
|
|
1553
|
+
namespace: metadata.namespace,
|
|
1554
|
+
privacyClass: metadata.privacyClass,
|
|
1555
|
+
derivedDate: metadata.derivedDate,
|
|
1556
|
+
sourceHash,
|
|
1557
|
+
syncConfigHash,
|
|
1558
|
+
mtimeMs: info.mtimeMs,
|
|
1559
|
+
deleted: false,
|
|
1560
|
+
chunks,
|
|
1561
|
+
};
|
|
1562
|
+
touchedFiles += 1;
|
|
1563
|
+
seen.add(sourcePath);
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
for (const [sourcePath, previous] of Object.entries(previousState.files)) {
|
|
1567
|
+
if (seen.has(sourcePath) || skipped.has(sourcePath)) continue;
|
|
1568
|
+
if (previous.deleted) {
|
|
1569
|
+
nextFiles[sourcePath] = previous;
|
|
1570
|
+
continue;
|
|
1571
|
+
}
|
|
1572
|
+
nextFiles[sourcePath] = {
|
|
1573
|
+
...previous,
|
|
1574
|
+
deleted: true,
|
|
1575
|
+
deletedAt: new Date().toISOString(),
|
|
1576
|
+
chunks: [],
|
|
1577
|
+
};
|
|
1578
|
+
deletedFiles += 1;
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
const nextState: CuratedIncludeFilesSyncState = {
|
|
1582
|
+
version: 1,
|
|
1583
|
+
updatedAt: new Date().toISOString(),
|
|
1584
|
+
files: nextFiles,
|
|
1585
|
+
};
|
|
1586
|
+
const activeChunks = loadActiveCuratedIncludeChunks({
|
|
1587
|
+
state: nextState,
|
|
1588
|
+
recallNamespaces: options.recallNamespaces,
|
|
1589
|
+
defaultNamespace: options.defaultNamespace,
|
|
1590
|
+
});
|
|
1591
|
+
const chunkCount = Object.values(nextFiles)
|
|
1592
|
+
.filter((file) => !file.deleted)
|
|
1593
|
+
.reduce((total, file) => total + file.chunks.length, 0);
|
|
1594
|
+
try {
|
|
1595
|
+
await mkdir(path.dirname(statePath), { recursive: true });
|
|
1596
|
+
await writeFile(statePath, `${JSON.stringify(nextState, null, 2)}\n`, "utf-8");
|
|
1597
|
+
} catch (error) {
|
|
1598
|
+
log.warn(`native knowledge: failed to persist curated include sync state (fail-open): ${String(error)}`);
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
return {
|
|
1602
|
+
statePath,
|
|
1603
|
+
touchedFiles,
|
|
1604
|
+
deletedFiles,
|
|
1605
|
+
chunkCount,
|
|
1606
|
+
activeChunks,
|
|
1607
|
+
};
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
export async function collectNativeKnowledgeChunks(options: {
|
|
1611
|
+
workspaceDir: string;
|
|
1612
|
+
memoryDir?: string;
|
|
1613
|
+
config: NativeKnowledgeConfig;
|
|
1614
|
+
recallNamespaces?: string[];
|
|
1615
|
+
defaultNamespace: string;
|
|
1616
|
+
abortSignal?: AbortSignal;
|
|
1617
|
+
}): Promise<NativeKnowledgeChunk[]> {
|
|
1618
|
+
throwIfNativeKnowledgeAborted(options.abortSignal);
|
|
1619
|
+
if (!options.config.enabled) return [];
|
|
1620
|
+
|
|
1621
|
+
const chunks: NativeKnowledgeChunk[] = [];
|
|
1622
|
+
const openclawBootstrapFiles = new Set(
|
|
1623
|
+
(options.memoryDir && options.config.openclawWorkspace?.enabled
|
|
1624
|
+
? options.config.openclawWorkspace.bootstrapFiles
|
|
1625
|
+
: []
|
|
1626
|
+
)
|
|
1627
|
+
.map((value) => value.replace(/\\/g, "/")),
|
|
1628
|
+
);
|
|
1629
|
+
if (options.memoryDir) {
|
|
1630
|
+
throwIfNativeKnowledgeAborted(options.abortSignal);
|
|
1631
|
+
const syncResult = await syncCuratedIncludeFiles({
|
|
1632
|
+
workspaceDir: options.workspaceDir,
|
|
1633
|
+
memoryDir: options.memoryDir,
|
|
1634
|
+
config: options.config,
|
|
1635
|
+
recallNamespaces: options.recallNamespaces,
|
|
1636
|
+
defaultNamespace: options.defaultNamespace,
|
|
1637
|
+
skipSourcePaths: [...openclawBootstrapFiles],
|
|
1638
|
+
});
|
|
1639
|
+
chunks.push(...syncResult.activeChunks);
|
|
1640
|
+
} else {
|
|
1641
|
+
throwIfNativeKnowledgeAborted(options.abortSignal);
|
|
1642
|
+
const candidatePaths = await resolveCandidatePaths({
|
|
1643
|
+
workspaceDir: options.workspaceDir,
|
|
1644
|
+
includeFiles: options.config.includeFiles,
|
|
1645
|
+
recallNamespaces: options.recallNamespaces,
|
|
1646
|
+
defaultNamespace: options.defaultNamespace,
|
|
1647
|
+
identityVariantMode: "recall",
|
|
1648
|
+
});
|
|
1649
|
+
for (const filePath of candidatePaths) {
|
|
1650
|
+
throwIfNativeKnowledgeAborted(options.abortSignal);
|
|
1651
|
+
if (!(await readableFile(filePath))) continue;
|
|
1652
|
+
const content = await readFile(filePath, "utf-8").catch(() => null);
|
|
1653
|
+
if (!content) continue;
|
|
1654
|
+
const sourcePath = path.relative(options.workspaceDir, filePath).replace(/\\/g, "/");
|
|
1655
|
+
if (openclawBootstrapFiles.has(sourcePath)) continue;
|
|
1656
|
+
const parsed = parseFrontmatter(content);
|
|
1657
|
+
const metadata = deriveCuratedFileMetadata({
|
|
1658
|
+
sourcePath,
|
|
1659
|
+
parsed,
|
|
1660
|
+
});
|
|
1661
|
+
const directChunks = buildCuratedIncludeChunks({
|
|
1662
|
+
sourcePath,
|
|
1663
|
+
body: parsed.body,
|
|
1664
|
+
bodyStartLine: parsed.bodyStartLine,
|
|
1665
|
+
maxChunkChars: options.config.maxChunkChars,
|
|
1666
|
+
sourceHash: createHash("sha256").update(content).digest("hex"),
|
|
1667
|
+
mtimeMs: 0,
|
|
1668
|
+
metadata,
|
|
1669
|
+
}).filter((chunk) => isChunkAllowedForRecall(chunk, options.recallNamespaces, options.defaultNamespace));
|
|
1670
|
+
chunks.push(...directChunks);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
if (options.memoryDir && options.config.openclawWorkspace?.enabled) {
|
|
1675
|
+
throwIfNativeKnowledgeAborted(options.abortSignal);
|
|
1676
|
+
const syncResult = await syncOpenClawWorkspaceArtifacts({
|
|
1677
|
+
workspaceDir: options.workspaceDir,
|
|
1678
|
+
memoryDir: options.memoryDir,
|
|
1679
|
+
config: options.config,
|
|
1680
|
+
});
|
|
1681
|
+
chunks.push(
|
|
1682
|
+
...syncResult.activeChunks.filter((chunk) =>
|
|
1683
|
+
isChunkAllowedForRecall(chunk, options.recallNamespaces, options.defaultNamespace),
|
|
1684
|
+
),
|
|
1685
|
+
);
|
|
1686
|
+
}
|
|
1687
|
+
|
|
1688
|
+
if (options.memoryDir && options.config.obsidianVaults.length > 0) {
|
|
1689
|
+
throwIfNativeKnowledgeAborted(options.abortSignal);
|
|
1690
|
+
const syncResult = await syncObsidianVaults({
|
|
1691
|
+
memoryDir: options.memoryDir,
|
|
1692
|
+
config: options.config,
|
|
1693
|
+
});
|
|
1694
|
+
chunks.push(
|
|
1695
|
+
...syncResult.activeChunks.filter((chunk) =>
|
|
1696
|
+
isChunkAllowedForRecall(chunk, options.recallNamespaces, options.defaultNamespace),
|
|
1697
|
+
),
|
|
1698
|
+
);
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
return dedupeNativeKnowledgeChunks(chunks);
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
function throwIfNativeKnowledgeAborted(signal?: AbortSignal): void {
|
|
1705
|
+
if (!signal?.aborted) return;
|
|
1706
|
+
const err = new Error("native knowledge collection aborted");
|
|
1707
|
+
Object.defineProperty(err, "name", { value: "AbortError" });
|
|
1708
|
+
throw err;
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
export function searchNativeKnowledge(options: {
|
|
1712
|
+
query: string;
|
|
1713
|
+
chunks: NativeKnowledgeChunk[];
|
|
1714
|
+
maxResults: number;
|
|
1715
|
+
}): NativeKnowledgeSearchResult[] {
|
|
1716
|
+
const normalizedQuery = normalizeText(options.query);
|
|
1717
|
+
const queryTokens = new Set(tokenize(options.query));
|
|
1718
|
+
if (!normalizedQuery || queryTokens.size === 0 || options.maxResults <= 0) return [];
|
|
1719
|
+
const temporalQuery = /\b(today|yesterday|recent|latest|current|next|handoff|summary)\b/i.test(options.query);
|
|
1720
|
+
const now = Date.now();
|
|
1721
|
+
|
|
1722
|
+
return options.chunks
|
|
1723
|
+
.map((chunk) => {
|
|
1724
|
+
const metadataText = [
|
|
1725
|
+
chunk.title,
|
|
1726
|
+
chunk.content,
|
|
1727
|
+
chunk.sourcePath,
|
|
1728
|
+
chunk.notePath,
|
|
1729
|
+
chunk.derivedDate,
|
|
1730
|
+
chunk.sessionKey,
|
|
1731
|
+
chunk.workflowKey,
|
|
1732
|
+
chunk.author,
|
|
1733
|
+
chunk.agent,
|
|
1734
|
+
...(chunk.tags ?? []),
|
|
1735
|
+
...(chunk.aliases ?? []),
|
|
1736
|
+
...(chunk.wikilinks ?? []),
|
|
1737
|
+
...(chunk.backlinks ?? []),
|
|
1738
|
+
]
|
|
1739
|
+
.filter((value): value is string => typeof value === "string" && value.length > 0)
|
|
1740
|
+
.join("\n");
|
|
1741
|
+
const normalizedContent = normalizeText(metadataText);
|
|
1742
|
+
const contentTokens = new Set(tokenize(normalizedContent));
|
|
1743
|
+
let overlap = 0;
|
|
1744
|
+
for (const token of queryTokens) {
|
|
1745
|
+
if (contentTokens.has(token)) overlap += 1;
|
|
1746
|
+
}
|
|
1747
|
+
if (overlap === 0 && !normalizedContent.includes(normalizedQuery)) return null;
|
|
1748
|
+
const kindBoost =
|
|
1749
|
+
chunk.sourceKind === "handoff"
|
|
1750
|
+
? 0.2
|
|
1751
|
+
: chunk.sourceKind === "daily_summary"
|
|
1752
|
+
? 0.16
|
|
1753
|
+
: chunk.sourceKind === "bootstrap_doc" || chunk.sourceKind === "identity"
|
|
1754
|
+
? 0.15
|
|
1755
|
+
: chunk.sourceKind === "memory"
|
|
1756
|
+
? 0.1
|
|
1757
|
+
: chunk.sourceKind === "obsidian_note"
|
|
1758
|
+
? 0.08
|
|
1759
|
+
: chunk.sourceKind === "automation_note"
|
|
1760
|
+
? 0.06
|
|
1761
|
+
: 0.05;
|
|
1762
|
+
const phraseBoost = normalizedContent.includes(normalizedQuery) ? 0.35 : 0;
|
|
1763
|
+
const metadataBoost =
|
|
1764
|
+
(chunk.aliases?.some((alias) => normalizeText(alias).includes(normalizedQuery)) ? 0.12 : 0) +
|
|
1765
|
+
(chunk.tags?.some((tag) => normalizeText(tag).includes(normalizedQuery)) ? 0.08 : 0) +
|
|
1766
|
+
(chunk.derivedDate && normalizeText(chunk.derivedDate).includes(normalizedQuery) ? 0.08 : 0) +
|
|
1767
|
+
(chunk.sessionKey && normalizeText(chunk.sessionKey).includes(normalizedQuery) ? 0.1 : 0) +
|
|
1768
|
+
(chunk.workflowKey && normalizeText(chunk.workflowKey).includes(normalizedQuery) ? 0.08 : 0) +
|
|
1769
|
+
(chunk.agent && normalizeText(chunk.agent).includes(normalizedQuery) ? 0.06 : 0) +
|
|
1770
|
+
(chunk.author && normalizeText(chunk.author).includes(normalizedQuery) ? 0.05 : 0);
|
|
1771
|
+
let temporalBoost = 0;
|
|
1772
|
+
if (chunk.derivedDate) {
|
|
1773
|
+
const parsed = Date.parse(`${chunk.derivedDate}T00:00:00Z`);
|
|
1774
|
+
if (Number.isFinite(parsed)) {
|
|
1775
|
+
const ageDays = Math.max(0, Math.floor((now - parsed) / (24 * 60 * 60 * 1000)));
|
|
1776
|
+
if (ageDays <= 1) temporalBoost += temporalQuery ? 0.12 : 0.04;
|
|
1777
|
+
else if (ageDays <= 7) temporalBoost += temporalQuery ? 0.08 : 0.02;
|
|
1778
|
+
else if (temporalQuery && ageDays >= 90) temporalBoost -= 0.08;
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
return {
|
|
1782
|
+
...chunk,
|
|
1783
|
+
score: overlap / Math.max(queryTokens.size, 1) + kindBoost + phraseBoost + metadataBoost + temporalBoost,
|
|
1784
|
+
};
|
|
1785
|
+
})
|
|
1786
|
+
.filter((chunk): chunk is NativeKnowledgeSearchResult => chunk !== null)
|
|
1787
|
+
.sort((a, b) => b.score - a.score || a.sourcePath.localeCompare(b.sourcePath) || a.startLine - b.startLine)
|
|
1788
|
+
.slice(0, options.maxResults);
|
|
1789
|
+
}
|
|
1790
|
+
|
|
1791
|
+
export function formatNativeKnowledgeSection(options: {
|
|
1792
|
+
results: NativeKnowledgeSearchResult[];
|
|
1793
|
+
maxChars: number;
|
|
1794
|
+
}): string | null {
|
|
1795
|
+
if (options.results.length === 0 || options.maxChars <= 0) return null;
|
|
1796
|
+
const lines = ["## Curated Workspace Knowledge", ""];
|
|
1797
|
+
let used = lines.join("\n").length;
|
|
1798
|
+
|
|
1799
|
+
for (const result of options.results) {
|
|
1800
|
+
const snippet = result.content.length > 500 ? `${result.content.slice(0, 497)}...` : result.content;
|
|
1801
|
+
const meta = [
|
|
1802
|
+
`kind=${result.sourceKind}`,
|
|
1803
|
+
result.derivedDate ? `date=${result.derivedDate}` : null,
|
|
1804
|
+
result.sessionKey ? `session=${result.sessionKey}` : null,
|
|
1805
|
+
result.workflowKey ? `workflow=${result.workflowKey}` : null,
|
|
1806
|
+
result.agent ? `agent=${result.agent}` : null,
|
|
1807
|
+
result.author ? `author=${result.author}` : null,
|
|
1808
|
+
result.tags && result.tags.length > 0 ? `tags=${result.tags.join(",")}` : null,
|
|
1809
|
+
result.vaultId ? `vault=${result.vaultId}` : null,
|
|
1810
|
+
]
|
|
1811
|
+
.filter((value): value is string => value !== null)
|
|
1812
|
+
.join(" ");
|
|
1813
|
+
const block =
|
|
1814
|
+
`- ${result.sourcePath}:${result.startLine}-${result.endLine} [${result.title}] ` +
|
|
1815
|
+
`(score: ${result.score.toFixed(3)}${meta ? `; ${meta}` : ""})\n ${snippet.replace(/\n/g, "\n ")}`;
|
|
1816
|
+
if (used + block.length > options.maxChars && lines.length > 2) break;
|
|
1817
|
+
if (used + block.length > options.maxChars) return null;
|
|
1818
|
+
lines.push(block);
|
|
1819
|
+
used += block.length + 1;
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
return lines.length > 2 ? lines.join("\n") : null;
|
|
1823
|
+
}
|