@remnic/core 1.0.2 → 1.1.0
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/abort-error.d.ts +32 -0
- package/dist/abort-error.js +11 -0
- package/dist/access-cli.d.ts +13 -3
- package/dist/access-cli.js +96 -80
- package/dist/access-cli.js.map +1 -1
- package/dist/access-http.d.ts +12 -4
- package/dist/access-http.js +25 -18
- package/dist/access-mcp.d.ts +32 -4
- package/dist/access-mcp.js +16 -1
- package/dist/access-schema.d.ts +28 -28
- package/dist/access-schema.js +1 -1
- package/dist/access-service-HmO1Trrx.d.ts +732 -0
- package/dist/access-service.d.ts +15 -601
- package/dist/access-service.js +21 -15
- package/dist/active-memory-bridge.d.ts +66 -0
- package/dist/active-memory-bridge.js +11 -0
- package/dist/active-memory-bridge.js.map +1 -0
- package/dist/active-recall.d.ts +96 -0
- package/dist/active-recall.js +308 -0
- package/dist/active-recall.js.map +1 -0
- package/dist/behavior-learner.js +1 -1
- package/dist/bootstrap.d.ts +6 -3
- package/dist/bootstrap.js +2 -2
- package/dist/boxes.js +2 -2
- package/dist/briefing.d.ts +169 -0
- package/dist/briefing.js +52 -0
- package/dist/briefing.js.map +1 -0
- package/dist/buffer.d.ts +19 -5
- package/dist/buffer.js +2 -2
- package/dist/calibration.js +6 -6
- package/dist/causal-behavior.js +5 -5
- package/dist/causal-chain.js +3 -3
- package/dist/causal-consolidation.d.ts +22 -2
- package/dist/causal-consolidation.js +36 -9
- package/dist/causal-consolidation.js.map +1 -1
- package/dist/causal-retrieval.js +6 -6
- package/dist/causal-trajectory-graph.js +1 -1
- package/dist/causal-trajectory.d.ts +14 -1
- package/dist/causal-trajectory.js +5 -1
- package/dist/{chunk-KWBU5S5U.js → chunk-2ODBA7MQ.js} +9 -3
- package/dist/chunk-2ODBA7MQ.js.map +1 -0
- package/dist/{chunk-ZJLY4QSU.js → chunk-37UIFYWO.js} +130 -6
- package/dist/chunk-37UIFYWO.js.map +1 -0
- package/dist/chunk-3PG3H5TD.js +7 -0
- package/dist/chunk-3PG3H5TD.js.map +1 -0
- package/dist/{chunk-NTTLPF7F.js → chunk-3QFQGRHO.js} +5 -5
- package/dist/{chunk-QDOSNLB4.js → chunk-3QHL5ABG.js} +17 -15
- package/dist/chunk-3QHL5ABG.js.map +1 -0
- package/dist/{chunk-6UJQNRIO.js → chunk-3SV6CQHO.js} +92 -33
- package/dist/chunk-3SV6CQHO.js.map +1 -0
- package/dist/{chunk-U4PV25RD.js → chunk-3WHVNEN7.js} +1 -1
- package/dist/chunk-3WHVNEN7.js.map +1 -0
- package/dist/{chunk-XUHI52HK.js → chunk-44ICJRF3.js} +98 -10
- package/dist/chunk-44ICJRF3.js.map +1 -0
- package/dist/{chunk-HG2NKWR2.js → chunk-47UU5PU2.js} +49 -10
- package/dist/chunk-47UU5PU2.js.map +1 -0
- package/dist/chunk-4DJQYKMN.js +187 -0
- package/dist/chunk-4DJQYKMN.js.map +1 -0
- package/dist/chunk-4KAN3GZ3.js +225 -0
- package/dist/chunk-4KAN3GZ3.js.map +1 -0
- package/dist/chunk-4LACOVZX.js +813 -0
- package/dist/chunk-4LACOVZX.js.map +1 -0
- package/dist/{chunk-ORZMT74A.js → chunk-4NRAJUDS.js} +11 -1
- package/dist/chunk-4NRAJUDS.js.map +1 -0
- package/dist/{chunk-B7LOFDVE.js → chunk-4WMCPJWX.js} +8 -3
- package/dist/chunk-4WMCPJWX.js.map +1 -0
- package/dist/{chunk-G3AG3KZN.js → chunk-5IZL4DCV.js} +2 -2
- package/dist/{chunk-BRK4ODMI.js → chunk-5NPGSAVB.js} +2 -2
- package/dist/{chunk-QANCTXQF.js → chunk-6LX5ORAS.js} +3 -3
- package/dist/chunk-6MKAMLQL.js +16 -0
- package/dist/chunk-6MKAMLQL.js.map +1 -0
- package/dist/{chunk-ESSMF2FR.js → chunk-6PFRXT4K.js} +15 -6
- package/dist/chunk-6PFRXT4K.js.map +1 -0
- package/dist/{chunk-UIYZ5T3I.js → chunk-6UJ47TVX.js} +8 -8
- package/dist/chunk-6ZH4TU6I.js +245 -0
- package/dist/chunk-6ZH4TU6I.js.map +1 -0
- package/dist/{chunk-L5RPWGFK.js → chunk-7DHTMOND.js} +2 -2
- package/dist/{chunk-L7WO3MZ4.js → chunk-7ECD5ATE.js} +2 -2
- package/dist/{chunk-Q6FETXJA.js → chunk-7SEAZFFB.js} +2 -2
- package/dist/{chunk-V4YC4LUK.js → chunk-7WQ6SLIE.js} +175 -63
- package/dist/chunk-7WQ6SLIE.js.map +1 -0
- package/dist/chunk-ALXMCZEU.js +332 -0
- package/dist/chunk-ALXMCZEU.js.map +1 -0
- package/dist/{chunk-TVVVQQAK.js → chunk-BLKTA7MM.js} +58 -24
- package/dist/chunk-BLKTA7MM.js.map +1 -0
- package/dist/{chunk-SCHEKPYH.js → chunk-C2EFFULQ.js} +1 -1
- package/dist/{chunk-GJR6D6KC.js → chunk-D654IBA6.js} +2 -2
- package/dist/{chunk-OTFNI3OO.js → chunk-DEPL3635.js} +1828 -401
- package/dist/chunk-DEPL3635.js.map +1 -0
- package/dist/{chunk-UYSKNO6E.js → chunk-DHHP2Z4X.js} +15 -4
- package/dist/chunk-DHHP2Z4X.js.map +1 -0
- package/dist/{chunk-UV2FO7J4.js → chunk-E6K4NIEU.js} +2 -2
- package/dist/{chunk-T4WRIV2C.js → chunk-EABGC2TL.js} +2 -2
- package/dist/chunk-EJI5XIBB.js +232 -0
- package/dist/chunk-EJI5XIBB.js.map +1 -0
- package/dist/{chunk-ONRU4L2N.js → chunk-FEMOX5AD.js} +2 -2
- package/dist/{chunk-IFFFR3MR.js → chunk-FSFEQI74.js} +3 -3
- package/dist/chunk-G4SK7DSQ.js +121 -0
- package/dist/chunk-G4SK7DSQ.js.map +1 -0
- package/dist/{chunk-WWIQTB2Y.js → chunk-GGD5W7TB.js} +9 -2
- package/dist/chunk-GGD5W7TB.js.map +1 -0
- package/dist/{chunk-QWUUMMIK.js → chunk-GV6NLQ4X.js} +1355 -80
- package/dist/chunk-GV6NLQ4X.js.map +1 -0
- package/dist/{chunk-2PO5ZRKV.js → chunk-GZCUW5IC.js} +16 -3
- package/dist/chunk-GZCUW5IC.js.map +1 -0
- package/dist/{chunk-AAI7JARD.js → chunk-HMDCOMYU.js} +8 -11
- package/dist/chunk-HMDCOMYU.js.map +1 -0
- package/dist/chunk-IQT3XTKW.js +121 -0
- package/dist/chunk-IQT3XTKW.js.map +1 -0
- package/dist/{chunk-J3BT33K7.js → chunk-ITRLGI2T.js} +5 -5
- package/dist/{chunk-BDFZXRSO.js → chunk-J4IYOZZ5.js} +15 -2
- package/dist/chunk-J4IYOZZ5.js.map +1 -0
- package/dist/{chunk-J47FNDR7.js → chunk-JIU55F3X.js} +7 -7
- package/dist/{chunk-MDDAA2AO.js → chunk-JL2PU6AI.js} +17 -6
- package/dist/chunk-JL2PU6AI.js.map +1 -0
- package/dist/{chunk-ZKYI7UVO.js → chunk-JR4ZC3G4.js} +2 -2
- package/dist/{chunk-UCYSTFZR.js → chunk-JRNQ3RNA.js} +2 -2
- package/dist/{chunk-GPGBSNKM.js → chunk-K4FLSOR5.js} +2 -2
- package/dist/chunk-KVE7R4CG.js +320 -0
- package/dist/chunk-KVE7R4CG.js.map +1 -0
- package/dist/chunk-LAYN4LDC.js +267 -0
- package/dist/chunk-LAYN4LDC.js.map +1 -0
- package/dist/{chunk-ISY75RLM.js → chunk-MBJHSA7F.js} +344 -7
- package/dist/chunk-MBJHSA7F.js.map +1 -0
- package/dist/{chunk-PGK3VUHN.js → chunk-MTLYEMJB.js} +3 -2
- package/dist/chunk-MTLYEMJB.js.map +1 -0
- package/dist/{chunk-QY2BHY5O.js → chunk-MVTHXUBX.js} +297 -34
- package/dist/chunk-MVTHXUBX.js.map +1 -0
- package/dist/{chunk-LP47L3ZX.js → chunk-N42IWANG.js} +5 -5
- package/dist/{chunk-YNI4S5WT.js → chunk-N53K2EXC.js} +2 -2
- package/dist/{chunk-763GUIOU.js → chunk-NBNN5GOB.js} +2 -2
- package/dist/{chunk-CXWFUJR2.js → chunk-NQEVYWX6.js} +195 -5
- package/dist/chunk-NQEVYWX6.js.map +1 -0
- package/dist/{chunk-KL4CP4SB.js → chunk-O5ETUNBT.js} +17 -5
- package/dist/chunk-O5ETUNBT.js.map +1 -0
- package/dist/{chunk-OOSWAUYB.js → chunk-ODWDQNRE.js} +2 -2
- package/dist/chunk-OIT5QGG4.js +80 -0
- package/dist/chunk-OIT5QGG4.js.map +1 -0
- package/dist/{chunk-HLBYLYRD.js → chunk-PAORGQRI.js} +70 -13
- package/dist/chunk-PAORGQRI.js.map +1 -0
- package/dist/chunk-PVGDJXVK.js +21 -0
- package/dist/chunk-PVGDJXVK.js.map +1 -0
- package/dist/{chunk-OTAVQCSF.js → chunk-PYXS46O7.js} +2 -2
- package/dist/chunk-QDW3E4RD.js +108 -0
- package/dist/chunk-QDW3E4RD.js.map +1 -0
- package/dist/{chunk-YNCQ7E4M.js → chunk-QDYXG4CS.js} +4 -3
- package/dist/chunk-QDYXG4CS.js.map +1 -0
- package/dist/{chunk-HLXVTBF3.js → chunk-QNJMBKFK.js} +3 -2
- package/dist/chunk-QNJMBKFK.js.map +1 -0
- package/dist/{chunk-4A24LIM2.js → chunk-S75M5ZRK.js} +2 -2
- package/dist/chunk-SYUK3VLY.js +789 -0
- package/dist/chunk-SYUK3VLY.js.map +1 -0
- package/dist/{chunk-QCCCQT3O.js → chunk-TBBDFYXW.js} +2 -2
- package/dist/chunk-TBBDFYXW.js.map +1 -0
- package/dist/chunk-U66YHYC7.js +31 -0
- package/dist/chunk-U66YHYC7.js.map +1 -0
- package/dist/{chunk-MWGVGUIS.js → chunk-UEYA6UC7.js} +36 -4
- package/dist/chunk-UEYA6UC7.js.map +1 -0
- package/dist/{chunk-M5KEYE5E.js → chunk-URB2WSKZ.js} +2 -2
- package/dist/chunk-UVJFDP7P.js +202 -0
- package/dist/chunk-UVJFDP7P.js.map +1 -0
- package/dist/chunk-W6SL7OFG.js +180 -0
- package/dist/chunk-W6SL7OFG.js.map +1 -0
- package/dist/chunk-WBSAYXVI.js +7945 -0
- package/dist/chunk-WBSAYXVI.js.map +1 -0
- package/dist/{chunk-M5ZBBBJI.js → chunk-XZ2TIKGC.js} +39 -9
- package/dist/chunk-XZ2TIKGC.js.map +1 -0
- package/dist/chunk-Y4FHOFJ2.js +140 -0
- package/dist/chunk-Y4FHOFJ2.js.map +1 -0
- package/dist/chunk-YDBIWGNI.js +298 -0
- package/dist/chunk-YDBIWGNI.js.map +1 -0
- package/dist/chunk-YNB73F22.js +137 -0
- package/dist/chunk-YNB73F22.js.map +1 -0
- package/dist/{chunk-IZME7KW2.js → chunk-ZVBB3T7V.js} +31 -12
- package/dist/chunk-ZVBB3T7V.js.map +1 -0
- package/dist/chunking.js +1 -1
- package/dist/citations.d.ts +67 -0
- package/dist/citations.js +13 -0
- package/dist/citations.js.map +1 -0
- package/dist/cli-BneVIEvh.d.ts +1240 -0
- package/dist/cli.d.ts +32 -1147
- package/dist/cli.js +150 -7092
- package/dist/cli.js.map +1 -1
- package/dist/codex-materialize-CQlLTzke.d.ts +139 -0
- package/dist/codex-thread-key.d.ts +3 -0
- package/dist/codex-thread-key.js +7 -0
- package/dist/codex-thread-key.js.map +1 -0
- package/dist/config.js +3 -2
- package/dist/connectors/codex/instructions.md +160 -0
- package/dist/connectors/codex/resources/namespace-cheatsheet.md +48 -0
- package/dist/contradiction-review-WIUBAR52.js +21 -0
- package/dist/contradiction-review-WIUBAR52.js.map +1 -0
- package/dist/contradiction-scan-GR33PONM.js +376 -0
- package/dist/contradiction-scan-GR33PONM.js.map +1 -0
- package/dist/day-summary.d.ts +7 -2
- package/dist/day-summary.js +5 -2
- package/dist/direct-answer-wiring.d.ts +77 -0
- package/dist/direct-answer-wiring.js +75 -0
- package/dist/direct-answer-wiring.js.map +1 -0
- package/dist/direct-answer.d.ts +106 -0
- package/dist/direct-answer.js +10 -0
- package/dist/direct-answer.js.map +1 -0
- package/dist/embedding-fallback.d.ts +96 -2
- package/dist/embedding-fallback.js +6 -4
- package/dist/{engine-2A6J4XEX.js → engine-5TIQBYZR.js} +10 -7
- package/dist/engine-5TIQBYZR.js.map +1 -0
- package/dist/entity-retrieval.d.ts +3 -2
- package/dist/entity-retrieval.js +10 -7
- package/dist/entity-schema.d.ts +11 -0
- package/dist/entity-schema.js +19 -0
- package/dist/entity-schema.js.map +1 -0
- package/dist/explicit-capture.d.ts +6 -3
- package/dist/explicit-capture.js +2 -2
- package/dist/extraction-judge.d.ts +66 -0
- package/dist/extraction-judge.js +18 -0
- package/dist/extraction-judge.js.map +1 -0
- package/dist/extraction.d.ts +1 -0
- package/dist/extraction.js +12 -10
- package/dist/fallback-llm.d.ts +11 -2
- package/dist/fallback-llm.js +4 -4
- package/dist/graph.js +1 -1
- package/dist/harmonic-retrieval.js +2 -1
- package/dist/importance.d.ts +11 -1
- package/dist/importance.js +3 -1
- package/dist/index.d.ts +1027 -9
- package/dist/index.js +3303 -349
- package/dist/index.js.map +1 -1
- package/dist/intent.d.ts +2 -1
- package/dist/intent.js +3 -1
- package/dist/lifecycle.js +1 -1
- package/dist/local-llm.d.ts +10 -3
- package/dist/local-llm.js +2 -2
- package/dist/logger.d.ts +1 -1
- package/dist/logger.js +1 -1
- package/dist/memory-cache.d.ts +2 -2
- package/dist/memory-cache.js +1 -1
- package/dist/{memory-projection-store-NxMkbocT.d.ts → memory-projection-store-DeSXPh1j.d.ts} +1 -1
- package/dist/memory-projection-store.d.ts +1 -1
- package/dist/model-registry.js +2 -2
- package/dist/models-json.js +2 -2
- package/dist/native-knowledge.js +2 -2
- package/dist/negative.js +2 -2
- package/dist/operator-toolkit.js +20 -15
- package/dist/{orchestrator-zTa-Qo-1.d.ts → orchestrator-DRYA6_lW.d.ts} +273 -9
- package/dist/orchestrator.d.ts +6 -3
- package/dist/orchestrator.js +76 -63
- package/dist/page-versioning.d.ts +77 -0
- package/dist/page-versioning.js +15 -0
- package/dist/page-versioning.js.map +1 -0
- package/dist/plugin-id.d.ts +37 -0
- package/dist/plugin-id.js +11 -0
- package/dist/plugin-id.js.map +1 -0
- package/dist/policy-runtime.js +2 -2
- package/dist/profiling.js +2 -2
- package/dist/qmd.d.ts +5 -2
- package/dist/qmd.js +4 -3
- package/dist/recall-audit.d.ts +20 -0
- package/dist/recall-audit.js +50 -0
- package/dist/recall-audit.js.map +1 -0
- package/dist/recall-mmr.d.ts +152 -0
- package/dist/recall-mmr.js +17 -0
- package/dist/recall-mmr.js.map +1 -0
- package/dist/recall-qos.js +2 -2
- package/dist/recall-state.d.ts +28 -1
- package/dist/recall-state.js +2 -2
- package/dist/relevance.js +2 -2
- package/dist/resolution-QBTDHTG7.js +100 -0
- package/dist/resolution-QBTDHTG7.js.map +1 -0
- package/dist/resolve-provider-secret.d.ts +24 -1
- package/dist/resolve-provider-secret.js +4 -2
- package/dist/resume-bundles.js +6 -5
- package/dist/retrieval-agents.js +2 -2
- package/dist/retrieval.js +2 -2
- package/dist/schemas.d.ts +412 -54
- package/dist/schemas.js +3 -1
- package/dist/sdk-compat.d.ts +2 -0
- package/dist/sdk-compat.js +6 -3
- package/dist/sdk-compat.js.map +1 -1
- package/dist/semantic-chunking.d.ts +87 -0
- package/dist/semantic-chunking.js +20 -0
- package/dist/semantic-chunking.js.map +1 -0
- package/dist/semantic-consolidation-DrvSYRdB.d.ts +119 -0
- package/dist/semantic-consolidation.d.ts +4 -42
- package/dist/semantic-consolidation.js +23 -2
- package/dist/semantic-rule-promotion.js +9 -6
- package/dist/semantic-rule-verifier.js +10 -7
- package/dist/session-observer-state.js +2 -2
- package/dist/session-toggles.d.ts +22 -0
- package/dist/session-toggles.js +116 -0
- package/dist/session-toggles.js.map +1 -0
- package/dist/skills-registry.d.ts +47 -0
- package/dist/skills-registry.js +48 -0
- package/dist/skills-registry.js.map +1 -0
- package/dist/source-attribution.d.ts +169 -0
- package/dist/source-attribution.js +27 -0
- package/dist/source-attribution.js.map +1 -0
- package/dist/storage.d.ts +171 -10
- package/dist/storage.js +16 -5
- package/dist/summarizer.js +7 -7
- package/dist/temporal-supersession.d.ts +127 -0
- package/dist/temporal-supersession.js +20 -0
- package/dist/temporal-supersession.js.map +1 -0
- package/dist/threading.js +2 -2
- package/dist/tier-migration.d.ts +2 -1
- package/dist/tier-routing.js +2 -2
- package/dist/tokens.d.ts +21 -1
- package/dist/tokens.js +5 -1
- package/dist/transcript.js +2 -2
- package/dist/types-DJhqDJUV.d.ts +50 -0
- package/dist/types.d.ts +529 -3
- package/dist/types.js +1 -1
- package/dist/utility-learner.js +2 -2
- package/dist/utility-runtime.js +3 -3
- package/dist/verified-recall.js +11 -8
- package/dist/whitespace.d.ts +4 -0
- package/dist/whitespace.js +9 -0
- package/dist/whitespace.js.map +1 -0
- package/package.json +14 -8
- package/dist/chunk-2CJCWDMR.js +0 -87
- package/dist/chunk-2CJCWDMR.js.map +0 -1
- package/dist/chunk-2PO5ZRKV.js.map +0 -1
- package/dist/chunk-6UJQNRIO.js.map +0 -1
- package/dist/chunk-AAI7JARD.js.map +0 -1
- package/dist/chunk-B7LOFDVE.js.map +0 -1
- package/dist/chunk-BDFZXRSO.js.map +0 -1
- package/dist/chunk-CXWFUJR2.js.map +0 -1
- package/dist/chunk-DORBM6OB.js +0 -81
- package/dist/chunk-DORBM6OB.js.map +0 -1
- package/dist/chunk-ESSMF2FR.js.map +0 -1
- package/dist/chunk-HG2NKWR2.js.map +0 -1
- package/dist/chunk-HLBYLYRD.js.map +0 -1
- package/dist/chunk-HLXVTBF3.js.map +0 -1
- package/dist/chunk-ISY75RLM.js.map +0 -1
- package/dist/chunk-IZME7KW2.js.map +0 -1
- package/dist/chunk-KL4CP4SB.js.map +0 -1
- package/dist/chunk-KWBU5S5U.js.map +0 -1
- package/dist/chunk-M5ZBBBJI.js.map +0 -1
- package/dist/chunk-MDDAA2AO.js.map +0 -1
- package/dist/chunk-MWGVGUIS.js.map +0 -1
- package/dist/chunk-ORZMT74A.js.map +0 -1
- package/dist/chunk-OTFNI3OO.js.map +0 -1
- package/dist/chunk-PGK3VUHN.js.map +0 -1
- package/dist/chunk-QCCCQT3O.js.map +0 -1
- package/dist/chunk-QDOSNLB4.js.map +0 -1
- package/dist/chunk-QPKFPHOO.js +0 -178
- package/dist/chunk-QPKFPHOO.js.map +0 -1
- package/dist/chunk-QWUUMMIK.js.map +0 -1
- package/dist/chunk-QY2BHY5O.js.map +0 -1
- package/dist/chunk-TVVVQQAK.js.map +0 -1
- package/dist/chunk-U4PV25RD.js.map +0 -1
- package/dist/chunk-UYSKNO6E.js.map +0 -1
- package/dist/chunk-V4YC4LUK.js.map +0 -1
- package/dist/chunk-WWIQTB2Y.js.map +0 -1
- package/dist/chunk-XUHI52HK.js.map +0 -1
- package/dist/chunk-YNCQ7E4M.js.map +0 -1
- package/dist/chunk-ZJLY4QSU.js.map +0 -1
- /package/dist/{engine-2A6J4XEX.js.map → abort-error.js.map} +0 -0
- /package/dist/{chunk-NTTLPF7F.js.map → chunk-3QFQGRHO.js.map} +0 -0
- /package/dist/{chunk-G3AG3KZN.js.map → chunk-5IZL4DCV.js.map} +0 -0
- /package/dist/{chunk-BRK4ODMI.js.map → chunk-5NPGSAVB.js.map} +0 -0
- /package/dist/{chunk-QANCTXQF.js.map → chunk-6LX5ORAS.js.map} +0 -0
- /package/dist/{chunk-UIYZ5T3I.js.map → chunk-6UJ47TVX.js.map} +0 -0
- /package/dist/{chunk-L5RPWGFK.js.map → chunk-7DHTMOND.js.map} +0 -0
- /package/dist/{chunk-L7WO3MZ4.js.map → chunk-7ECD5ATE.js.map} +0 -0
- /package/dist/{chunk-Q6FETXJA.js.map → chunk-7SEAZFFB.js.map} +0 -0
- /package/dist/{chunk-SCHEKPYH.js.map → chunk-C2EFFULQ.js.map} +0 -0
- /package/dist/{chunk-GJR6D6KC.js.map → chunk-D654IBA6.js.map} +0 -0
- /package/dist/{chunk-UV2FO7J4.js.map → chunk-E6K4NIEU.js.map} +0 -0
- /package/dist/{chunk-T4WRIV2C.js.map → chunk-EABGC2TL.js.map} +0 -0
- /package/dist/{chunk-ONRU4L2N.js.map → chunk-FEMOX5AD.js.map} +0 -0
- /package/dist/{chunk-IFFFR3MR.js.map → chunk-FSFEQI74.js.map} +0 -0
- /package/dist/{chunk-J3BT33K7.js.map → chunk-ITRLGI2T.js.map} +0 -0
- /package/dist/{chunk-J47FNDR7.js.map → chunk-JIU55F3X.js.map} +0 -0
- /package/dist/{chunk-ZKYI7UVO.js.map → chunk-JR4ZC3G4.js.map} +0 -0
- /package/dist/{chunk-UCYSTFZR.js.map → chunk-JRNQ3RNA.js.map} +0 -0
- /package/dist/{chunk-GPGBSNKM.js.map → chunk-K4FLSOR5.js.map} +0 -0
- /package/dist/{chunk-LP47L3ZX.js.map → chunk-N42IWANG.js.map} +0 -0
- /package/dist/{chunk-YNI4S5WT.js.map → chunk-N53K2EXC.js.map} +0 -0
- /package/dist/{chunk-763GUIOU.js.map → chunk-NBNN5GOB.js.map} +0 -0
- /package/dist/{chunk-OOSWAUYB.js.map → chunk-ODWDQNRE.js.map} +0 -0
- /package/dist/{chunk-OTAVQCSF.js.map → chunk-PYXS46O7.js.map} +0 -0
- /package/dist/{chunk-4A24LIM2.js.map → chunk-S75M5ZRK.js.map} +0 -0
- /package/dist/{chunk-M5KEYE5E.js.map → chunk-URB2WSKZ.js.map} +0 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// src/taxonomy/resolver.ts
|
|
2
|
+
var DEFAULT_CATEGORY_ID = "facts";
|
|
3
|
+
function resolveCategory(content, memoryCategory, taxonomy) {
|
|
4
|
+
const contentLower = content.toLowerCase();
|
|
5
|
+
const matches = taxonomy.categories.filter(
|
|
6
|
+
(cat) => cat.memoryCategories.includes(memoryCategory)
|
|
7
|
+
);
|
|
8
|
+
if (matches.length === 0) {
|
|
9
|
+
const fallback = taxonomy.categories.find((c) => c.id === DEFAULT_CATEGORY_ID) ?? taxonomy.categories[0];
|
|
10
|
+
if (!fallback) {
|
|
11
|
+
return {
|
|
12
|
+
categoryId: DEFAULT_CATEGORY_ID,
|
|
13
|
+
confidence: 0,
|
|
14
|
+
reason: "Taxonomy is empty; using default category",
|
|
15
|
+
alternatives: []
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const alternatives2 = taxonomy.categories.filter((c) => c.id !== fallback.id).map((c) => ({
|
|
19
|
+
categoryId: c.id,
|
|
20
|
+
reason: c.description
|
|
21
|
+
}));
|
|
22
|
+
return {
|
|
23
|
+
categoryId: fallback.id,
|
|
24
|
+
confidence: 0.3,
|
|
25
|
+
reason: `No taxonomy category maps to MemoryCategory "${memoryCategory}"; falling back to "${fallback.name}"`,
|
|
26
|
+
alternatives: alternatives2
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (matches.length === 1) {
|
|
30
|
+
const match = matches[0];
|
|
31
|
+
const alternatives2 = taxonomy.categories.filter((c) => c.id !== match.id).map((c) => ({
|
|
32
|
+
categoryId: c.id,
|
|
33
|
+
reason: c.description
|
|
34
|
+
}));
|
|
35
|
+
return {
|
|
36
|
+
categoryId: match.id,
|
|
37
|
+
confidence: 1,
|
|
38
|
+
reason: `Unique match: MemoryCategory "${memoryCategory}" maps to "${match.name}"`,
|
|
39
|
+
alternatives: alternatives2
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
const scored = matches.map((cat) => ({
|
|
43
|
+
cat,
|
|
44
|
+
keywordScore: computeKeywordScore(contentLower, cat)
|
|
45
|
+
}));
|
|
46
|
+
scored.sort((a, b) => {
|
|
47
|
+
if (b.keywordScore !== a.keywordScore) return b.keywordScore - a.keywordScore;
|
|
48
|
+
return a.cat.priority - b.cat.priority;
|
|
49
|
+
});
|
|
50
|
+
const best = scored[0];
|
|
51
|
+
const runnerUp = scored[1];
|
|
52
|
+
const confidence = best.keywordScore > 0 && (!runnerUp || best.keywordScore > runnerUp.keywordScore) ? 0.9 : 0.7;
|
|
53
|
+
const alternatives = taxonomy.categories.filter((c) => c.id !== best.cat.id).map((c) => ({
|
|
54
|
+
categoryId: c.id,
|
|
55
|
+
reason: c.description
|
|
56
|
+
}));
|
|
57
|
+
const reason = best.keywordScore > 0 ? `Filing rules for "${best.cat.name}" matched content keywords (priority ${best.cat.priority})` : `Priority tie-break: "${best.cat.name}" has lowest priority number (${best.cat.priority})`;
|
|
58
|
+
return {
|
|
59
|
+
categoryId: best.cat.id,
|
|
60
|
+
confidence,
|
|
61
|
+
reason,
|
|
62
|
+
alternatives
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function computeKeywordScore(contentLower, cat) {
|
|
66
|
+
let score = 0;
|
|
67
|
+
const ruleText = [...cat.filingRules, cat.description].join(" ").toLowerCase();
|
|
68
|
+
const keywords = ruleText.split(/[^a-z0-9]+/).filter((w) => w.length >= 3);
|
|
69
|
+
for (const kw of keywords) {
|
|
70
|
+
if (contentLower.includes(kw)) {
|
|
71
|
+
score += 1;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return score;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
resolveCategory
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=chunk-OIT5QGG4.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/taxonomy/resolver.ts"],"sourcesContent":["/**\n * Resolver decision tree for the MECE taxonomy.\n *\n * Given extracted content and its MemoryCategory, determines which\n * taxonomy category the knowledge should be filed under.\n */\n\nimport type { MemoryCategory } from \"../types.js\";\nimport type { ResolverDecision, Taxonomy, TaxonomyCategory } from \"./types.js\";\n\nconst DEFAULT_CATEGORY_ID = \"facts\";\n\n/**\n * Resolve a piece of content to a taxonomy category.\n *\n * Algorithm:\n * 1. Find all taxonomy categories whose `memoryCategories` include\n * the given `memoryCategory`.\n * 2. If exactly one match, return it with confidence 1.0.\n * 3. If multiple matches, pick the one with the lowest priority\n * number (highest precedence). Apply keyword heuristics from\n * filing rules as a secondary signal.\n * 4. If no match, fall back to the \"facts\" category (or first\n * category if \"facts\" is absent) with low confidence.\n * 5. Always populate `alternatives` with other plausible categories.\n */\nexport function resolveCategory(\n content: string,\n memoryCategory: MemoryCategory,\n taxonomy: Taxonomy,\n): ResolverDecision {\n const contentLower = content.toLowerCase();\n\n // Step 1: find matching categories\n const matches = taxonomy.categories.filter((cat) =>\n cat.memoryCategories.includes(memoryCategory),\n );\n\n if (matches.length === 0) {\n // No taxonomy category accepts this MemoryCategory — fall back\n const fallback =\n taxonomy.categories.find((c) => c.id === DEFAULT_CATEGORY_ID) ??\n taxonomy.categories[0];\n if (!fallback) {\n return {\n categoryId: DEFAULT_CATEGORY_ID,\n confidence: 0,\n reason: \"Taxonomy is empty; using default category\",\n alternatives: [],\n };\n }\n const alternatives = taxonomy.categories\n .filter((c) => c.id !== fallback.id)\n .map((c) => ({\n categoryId: c.id,\n reason: c.description,\n }));\n return {\n categoryId: fallback.id,\n confidence: 0.3,\n reason: `No taxonomy category maps to MemoryCategory \"${memoryCategory}\"; falling back to \"${fallback.name}\"`,\n alternatives,\n };\n }\n\n if (matches.length === 1) {\n const match = matches[0]!;\n const alternatives = taxonomy.categories\n .filter((c) => c.id !== match.id)\n .map((c) => ({\n categoryId: c.id,\n reason: c.description,\n }));\n return {\n categoryId: match.id,\n confidence: 1.0,\n reason: `Unique match: MemoryCategory \"${memoryCategory}\" maps to \"${match.name}\"`,\n alternatives,\n };\n }\n\n // Multiple matches — use filing rule keyword heuristics + priority\n const scored = matches.map((cat) => ({\n cat,\n keywordScore: computeKeywordScore(contentLower, cat),\n }));\n\n // Sort by keyword score descending, then priority ascending (lower wins)\n scored.sort((a, b) => {\n if (b.keywordScore !== a.keywordScore) return b.keywordScore - a.keywordScore;\n return a.cat.priority - b.cat.priority;\n });\n\n const best = scored[0]!;\n const runnerUp = scored[1];\n\n // Confidence is higher when keyword match clearly differentiates\n const confidence =\n best.keywordScore > 0 && (!runnerUp || best.keywordScore > runnerUp.keywordScore)\n ? 0.9\n : 0.7;\n\n const alternatives = taxonomy.categories\n .filter((c) => c.id !== best.cat.id)\n .map((c) => ({\n categoryId: c.id,\n reason: c.description,\n }));\n\n const reason =\n best.keywordScore > 0\n ? `Filing rules for \"${best.cat.name}\" matched content keywords (priority ${best.cat.priority})`\n : `Priority tie-break: \"${best.cat.name}\" has lowest priority number (${best.cat.priority})`;\n\n return {\n categoryId: best.cat.id,\n confidence,\n reason,\n alternatives,\n };\n}\n\n/**\n * Compute a simple keyword overlap score between content and\n * a category's filing rules + description.\n */\nfunction computeKeywordScore(contentLower: string, cat: TaxonomyCategory): number {\n let score = 0;\n const ruleText = [...cat.filingRules, cat.description]\n .join(\" \")\n .toLowerCase();\n\n // Extract meaningful words (3+ chars) from the rule text\n const keywords = ruleText\n .split(/[^a-z0-9]+/)\n .filter((w) => w.length >= 3);\n\n for (const kw of keywords) {\n if (contentLower.includes(kw)) {\n score += 1;\n }\n }\n return score;\n}\n"],"mappings":";AAUA,IAAM,sBAAsB;AAgBrB,SAAS,gBACd,SACA,gBACA,UACkB;AAClB,QAAM,eAAe,QAAQ,YAAY;AAGzC,QAAM,UAAU,SAAS,WAAW;AAAA,IAAO,CAAC,QAC1C,IAAI,iBAAiB,SAAS,cAAc;AAAA,EAC9C;AAEA,MAAI,QAAQ,WAAW,GAAG;AAExB,UAAM,WACJ,SAAS,WAAW,KAAK,CAAC,MAAM,EAAE,OAAO,mBAAmB,KAC5D,SAAS,WAAW,CAAC;AACvB,QAAI,CAAC,UAAU;AACb,aAAO;AAAA,QACL,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,QAAQ;AAAA,QACR,cAAc,CAAC;AAAA,MACjB;AAAA,IACF;AACA,UAAMA,gBAAe,SAAS,WAC3B,OAAO,CAAC,MAAM,EAAE,OAAO,SAAS,EAAE,EAClC,IAAI,CAAC,OAAO;AAAA,MACX,YAAY,EAAE;AAAA,MACd,QAAQ,EAAE;AAAA,IACZ,EAAE;AACJ,WAAO;AAAA,MACL,YAAY,SAAS;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;AAAA,IACL,YAAY,KAAK,IAAI;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAMA,SAAS,oBAAoB,cAAsB,KAA+B;AAChF,MAAI,QAAQ;AACZ,QAAM,WAAW,CAAC,GAAG,IAAI,aAAa,IAAI,WAAW,EAClD,KAAK,GAAG,EACR,YAAY;AAGf,QAAM,WAAW,SACd,MAAM,YAAY,EAClB,OAAO,CAAC,MAAM,EAAE,UAAU,CAAC;AAE9B,aAAW,MAAM,UAAU;AACzB,QAAI,aAAa,SAAS,EAAE,GAAG;AAC7B,eAAS;AAAA,IACX;AAAA,EACF;AACA,SAAO;AACT;","names":["alternatives"]}
|
|
@@ -1,18 +1,79 @@
|
|
|
1
1
|
import {
|
|
2
2
|
validateRouteTarget
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QNJMBKFK.js";
|
|
4
4
|
import {
|
|
5
5
|
log
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-2ODBA7MQ.js";
|
|
7
|
+
|
|
8
|
+
// src/utils/iso-timestamp.ts
|
|
9
|
+
var ISO_UTC_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/;
|
|
10
|
+
var ISO_OFFSET_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
11
|
+
function validateDateComponents(isoString) {
|
|
12
|
+
const match = isoString.match(
|
|
13
|
+
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/
|
|
14
|
+
);
|
|
15
|
+
if (!match) return false;
|
|
16
|
+
const [, yStr, mStr, dStr, hStr, minStr, sStr] = match;
|
|
17
|
+
const y = Number(yStr);
|
|
18
|
+
const m = Number(mStr);
|
|
19
|
+
const d = Number(dStr);
|
|
20
|
+
const h = Number(hStr);
|
|
21
|
+
const min = Number(minStr);
|
|
22
|
+
const s = Number(sStr);
|
|
23
|
+
if (m < 1 || m > 12) return false;
|
|
24
|
+
if (d < 1 || d > 31) return false;
|
|
25
|
+
if (h > 23 || min > 59 || s > 59) return false;
|
|
26
|
+
const daysInMonth = new Date(y, m, 0).getDate();
|
|
27
|
+
if (d > daysInMonth) return false;
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
function validateOffset(isoString) {
|
|
31
|
+
const offsetMatch = isoString.match(/([+-])(\d{2}):(\d{2})$/);
|
|
32
|
+
if (!offsetMatch) return true;
|
|
33
|
+
const oh = Number(offsetMatch[2]);
|
|
34
|
+
const om = Number(offsetMatch[3]);
|
|
35
|
+
if (oh > 14 || om > 59) return false;
|
|
36
|
+
if (oh === 14 && om > 0) return false;
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
function normalizeUtcForComparison(value) {
|
|
40
|
+
const fracMatch = value.match(/\.(\d+)Z$/);
|
|
41
|
+
if (fracMatch) {
|
|
42
|
+
const ms = (fracMatch[1] + "000").slice(0, 3);
|
|
43
|
+
return value.replace(/\.\d+Z$/, `.${ms}Z`);
|
|
44
|
+
}
|
|
45
|
+
return value.replace(/Z$/, ".000Z");
|
|
46
|
+
}
|
|
47
|
+
function parseIsoUtcTimestamp(value) {
|
|
48
|
+
if (typeof value !== "string" || !ISO_UTC_TIMESTAMP_RE.test(value)) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const ts = Date.parse(value);
|
|
52
|
+
if (!Number.isFinite(ts)) return null;
|
|
53
|
+
if (!validateDateComponents(value)) return null;
|
|
54
|
+
const roundTrip = new Date(ts).toISOString();
|
|
55
|
+
if (roundTrip !== normalizeUtcForComparison(value)) return null;
|
|
56
|
+
return ts;
|
|
57
|
+
}
|
|
58
|
+
function parseIsoOffsetTimestamp(value) {
|
|
59
|
+
if (typeof value !== "string" || !ISO_OFFSET_TIMESTAMP_RE.test(value)) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const ts = Date.parse(value);
|
|
63
|
+
if (!Number.isFinite(ts)) return null;
|
|
64
|
+
if (!validateDateComponents(value)) return null;
|
|
65
|
+
if (!validateOffset(value)) return null;
|
|
66
|
+
if (value.endsWith("Z")) {
|
|
67
|
+
const roundTrip = new Date(ts).toISOString();
|
|
68
|
+
if (roundTrip !== normalizeUtcForComparison(value)) return null;
|
|
69
|
+
}
|
|
70
|
+
return ts;
|
|
71
|
+
}
|
|
7
72
|
|
|
8
73
|
// src/replay/types.ts
|
|
9
74
|
var VALID_SOURCES = /* @__PURE__ */ new Set(["openclaw", "claude", "chatgpt"]);
|
|
10
75
|
var VALID_ROLES = /* @__PURE__ */ new Set(["user", "assistant"]);
|
|
11
|
-
var ISO_UTC_TIMESTAMP_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?Z$/;
|
|
12
76
|
var REPLAY_UNKNOWN_SESSION_KEY = "replay:unknown";
|
|
13
|
-
function normalizeIsoForComparison(value) {
|
|
14
|
-
return value.includes(".") ? value : value.replace("Z", ".000Z");
|
|
15
|
-
}
|
|
16
77
|
function isReplaySource(value) {
|
|
17
78
|
return typeof value === "string" && VALID_SOURCES.has(value);
|
|
18
79
|
}
|
|
@@ -25,12 +86,7 @@ function normalizeReplaySessionKey(value) {
|
|
|
25
86
|
return trimmed.length > 0 ? trimmed : REPLAY_UNKNOWN_SESSION_KEY;
|
|
26
87
|
}
|
|
27
88
|
function parseIsoTimestamp(value) {
|
|
28
|
-
|
|
29
|
-
const ts = Date.parse(value);
|
|
30
|
-
if (!Number.isFinite(ts)) return null;
|
|
31
|
-
const roundTrip = new Date(ts).toISOString();
|
|
32
|
-
if (roundTrip !== normalizeIsoForComparison(value)) return null;
|
|
33
|
-
return ts;
|
|
89
|
+
return parseIsoUtcTimestamp(value);
|
|
34
90
|
}
|
|
35
91
|
function validateReplayTurn(turn, index) {
|
|
36
92
|
const issues = [];
|
|
@@ -336,6 +392,7 @@ var RoutingRulesStore = class {
|
|
|
336
392
|
};
|
|
337
393
|
|
|
338
394
|
export {
|
|
395
|
+
parseIsoOffsetTimestamp,
|
|
339
396
|
isReplaySource,
|
|
340
397
|
isReplayRole,
|
|
341
398
|
normalizeReplaySessionKey,
|
|
@@ -343,4 +400,4 @@ export {
|
|
|
343
400
|
validateReplayTurn,
|
|
344
401
|
RoutingRulesStore
|
|
345
402
|
};
|
|
346
|
-
//# sourceMappingURL=chunk-
|
|
403
|
+
//# sourceMappingURL=chunk-PAORGQRI.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/iso-timestamp.ts","../src/replay/types.ts","../src/routing/store.ts"],"sourcesContent":["// ---------------------------------------------------------------------------\n// Shared ISO-8601 / RFC 3339 timestamp validation helpers.\n//\n// Two public entry points — a strict UTC-only parser used by the replay\n// pipeline, and a more permissive parser used by bulk-import adapters that\n// need to preserve source timezone offsets. Both share date-component,\n// offset-range, and round-trip validation so they cannot silently diverge.\n// ---------------------------------------------------------------------------\n\n// UTC-only: `...Z`, 0 or 3 fractional digits (replay canonical form).\nconst ISO_UTC_TIMESTAMP_RE =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d{3})?Z$/;\n\n// Lenient: variable-precision fractional seconds and `Z` or `[+-]HH:MM` offset.\nconst ISO_OFFSET_TIMESTAMP_RE =\n /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.\\d+)?(?:Z|[+-]\\d{2}:\\d{2})$/;\n\n/**\n * Validate the date/time components of an ISO timestamp string.\n * Catches overflowed dates like Feb 31 that `Date.parse` silently normalizes.\n */\nfunction validateDateComponents(isoString: string): boolean {\n const match = isoString.match(\n /^(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})/,\n );\n if (!match) return false;\n const [, yStr, mStr, dStr, hStr, minStr, sStr] = match;\n const y = Number(yStr);\n const m = Number(mStr);\n const d = Number(dStr);\n const h = Number(hStr);\n const min = Number(minStr);\n const s = Number(sStr);\n if (m < 1 || m > 12) return false;\n if (d < 1 || d > 31) return false;\n if (h > 23 || min > 59 || s > 59) return false;\n // Validate day for the specific month (using Date(y, m, 0) to get days).\n const daysInMonth = new Date(y, m, 0).getDate();\n if (d > daysInMonth) return false;\n return true;\n}\n\n/**\n * Validate the timezone offset range if present.\n * Max offset is +/-14:00 per ISO 8601; minute part must be 0-59.\n */\nfunction validateOffset(isoString: string): boolean {\n const offsetMatch = isoString.match(/([+-])(\\d{2}):(\\d{2})$/);\n if (!offsetMatch) return true; // `Z` form, no offset to validate.\n const oh = Number(offsetMatch[2]);\n const om = Number(offsetMatch[3]);\n if (oh > 14 || om > 59) return false;\n // +14:00 is max; offsets like +14:30 are invalid.\n if (oh === 14 && om > 0) return false;\n return true;\n}\n\n/**\n * Normalize a `Z`-suffixed ISO timestamp to exactly three fractional digits so\n * the round-trip comparison against `Date.prototype.toISOString()` succeeds\n * regardless of input precision (or absence of a fractional part).\n */\nfunction normalizeUtcForComparison(value: string): string {\n const fracMatch = value.match(/\\.(\\d+)Z$/);\n if (fracMatch) {\n const ms = (fracMatch[1] + \"000\").slice(0, 3);\n return value.replace(/\\.\\d+Z$/, `.${ms}Z`);\n }\n return value.replace(/Z$/, \".000Z\");\n}\n\n/**\n * Strict UTC-only parser — accepts `YYYY-MM-DDTHH:MM:SS[.sss]Z`.\n * Returns milliseconds since epoch, or `null` if invalid.\n */\nexport function parseIsoUtcTimestamp(value: string): number | null {\n if (typeof value !== \"string\" || !ISO_UTC_TIMESTAMP_RE.test(value)) {\n return null;\n }\n const ts = Date.parse(value);\n if (!Number.isFinite(ts)) return null;\n if (!validateDateComponents(value)) return null;\n const roundTrip = new Date(ts).toISOString();\n if (roundTrip !== normalizeUtcForComparison(value)) return null;\n return ts;\n}\n\n/**\n * Lenient parser — accepts variable-precision fractional seconds and either\n * a `Z` suffix or a `[+-]HH:MM` offset. Returns milliseconds since epoch, or\n * `null` if the string is not a well-formed RFC 3339 timestamp.\n */\nexport function parseIsoOffsetTimestamp(value: string): number | null {\n if (typeof value !== \"string\" || !ISO_OFFSET_TIMESTAMP_RE.test(value)) {\n return null;\n }\n const ts = Date.parse(value);\n if (!Number.isFinite(ts)) return null;\n if (!validateDateComponents(value)) return null;\n if (!validateOffset(value)) return null;\n // For UTC timestamps (ending in `Z`), verify with a round-trip so that\n // overflowed UTC calendar dates cannot slip through.\n if (value.endsWith(\"Z\")) {\n const roundTrip = new Date(ts).toISOString();\n if (roundTrip !== normalizeUtcForComparison(value)) return null;\n }\n return ts;\n}\n","import { parseIsoUtcTimestamp } from \"../utils/iso-timestamp.js\";\n\nexport type ReplaySource = \"openclaw\" | \"claude\" | \"chatgpt\";\nexport type ReplayRole = \"user\" | \"assistant\";\n\nexport interface ReplayTurn {\n source: ReplaySource;\n sessionKey: string;\n role: ReplayRole;\n content: string;\n timestamp: string;\n externalId?: string;\n metadata?: Record<string, unknown>;\n}\n\nexport interface ReplayWarning {\n code: string;\n message: string;\n index?: number;\n}\n\nexport interface ReplayValidationIssue {\n code: string;\n message: string;\n index?: number;\n}\n\nexport interface ReplayParseOptions {\n from?: string;\n to?: string;\n defaultSessionKey?: string;\n strict?: boolean;\n}\n\nexport interface ReplayParseResult {\n turns: ReplayTurn[];\n warnings: ReplayWarning[];\n}\n\nexport interface ReplayNormalizer {\n source: ReplaySource;\n parse(input: unknown, options?: ReplayParseOptions): Promise<ReplayParseResult> | ReplayParseResult;\n}\n\nconst VALID_SOURCES: ReadonlySet<string> = new Set([\"openclaw\", \"claude\", \"chatgpt\"]);\nconst VALID_ROLES: ReadonlySet<string> = new Set([\"user\", \"assistant\"]);\nexport const REPLAY_UNKNOWN_SESSION_KEY = \"replay:unknown\";\n\nexport function isReplaySource(value: unknown): value is ReplaySource {\n return typeof value === \"string\" && VALID_SOURCES.has(value);\n}\n\nexport function isReplayRole(value: unknown): value is ReplayRole {\n return typeof value === \"string\" && VALID_ROLES.has(value);\n}\n\nexport function normalizeReplaySessionKey(value: unknown): string {\n if (typeof value !== \"string\") return REPLAY_UNKNOWN_SESSION_KEY;\n const trimmed = value.trim();\n return trimmed.length > 0 ? trimmed : REPLAY_UNKNOWN_SESSION_KEY;\n}\n\n/**\n * Strict UTC-only ISO-8601 parser used by the replay pipeline.\n *\n * Delegates to the shared parser in `utils/iso-timestamp.ts` — do not\n * reimplement locally; extend that helper instead. Replay intentionally\n * rejects timezone-offset timestamps to keep canonical form consistent\n * across recorded transcripts.\n */\nexport function parseIsoTimestamp(value: string): number | null {\n return parseIsoUtcTimestamp(value);\n}\n\nexport function validateReplayTurn(turn: ReplayTurn, index?: number): ReplayValidationIssue[] {\n const issues: ReplayValidationIssue[] = [];\n if (!turn || typeof turn !== \"object\") {\n issues.push({\n code: \"turn.invalid\",\n message: \"Replay turn must be an object.\",\n index,\n });\n return issues;\n }\n\n if (!isReplayRole(turn.role)) {\n issues.push({\n code: \"turn.role.invalid\",\n message: `Replay role must be 'user' or 'assistant', received '${String(turn.role)}'.`,\n index,\n });\n }\n\n if (!isReplaySource(turn.source)) {\n issues.push({\n code: \"turn.source.invalid\",\n message: `Replay source must be 'openclaw', 'claude', or 'chatgpt', received '${String(turn.source)}'.`,\n index,\n });\n }\n\n if (!turn.sessionKey || typeof turn.sessionKey !== \"string\" || turn.sessionKey.trim().length === 0) {\n issues.push({\n code: \"turn.sessionKey.invalid\",\n message: \"Replay sessionKey is required.\",\n index,\n });\n }\n\n if (!turn.content || typeof turn.content !== \"string\" || turn.content.trim().length === 0) {\n issues.push({\n code: \"turn.content.invalid\",\n message: \"Replay content must be a non-empty string.\",\n index,\n });\n }\n\n if (!turn.timestamp || typeof turn.timestamp !== \"string\" || parseIsoTimestamp(turn.timestamp) === null) {\n issues.push({\n code: \"turn.timestamp.invalid\",\n message: `Replay timestamp must be a valid ISO timestamp, received '${String(turn.timestamp)}'.`,\n index,\n });\n }\n\n return issues;\n}\n","import { lstat, mkdir, readFile, realpath, rename, rm, stat, writeFile } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { createHash } from \"node:crypto\";\nimport { log } from \"../logger.js\";\nimport { validateRouteTarget, type RouteRule, type RoutingEngineOptions } from \"./engine.js\";\n\ntype RoutingRulesState = {\n version: 1;\n updatedAt: string;\n rules: RouteRule[];\n};\n\nfunction defaultState(): RoutingRulesState {\n return {\n version: 1,\n updatedAt: new Date(0).toISOString(),\n rules: [],\n };\n}\n\nfunction stableRuleId(rule: Pick<RouteRule, \"patternType\" | \"pattern\" | \"priority\" | \"target\">): string {\n const seed = JSON.stringify({\n patternType: rule.patternType,\n pattern: rule.pattern.trim(),\n priority: rule.priority,\n target: rule.target,\n });\n return `route-${createHash(\"sha256\").update(seed).digest(\"hex\").slice(0, 12)}`;\n}\n\nfunction resolveStatePath(memoryDir: string, stateFile: string): string {\n const root = path.resolve(memoryDir);\n const defaultPath = path.join(root, \"state\", \"routing-rules.json\");\n if (path.isAbsolute(stateFile)) {\n const absolute = path.resolve(stateFile);\n return absolute.startsWith(root + path.sep) ? absolute : defaultPath;\n }\n const resolved = path.resolve(root, stateFile);\n return resolved.startsWith(root + path.sep) ? resolved : defaultPath;\n}\n\nfunction normalizeRule(rule: RouteRule, options?: RoutingEngineOptions): RouteRule | null {\n if (!rule || typeof rule !== \"object\") return null;\n if (rule.enabled === false) return null;\n if (rule.patternType !== \"keyword\" && rule.patternType !== \"regex\") return null;\n if (typeof rule.pattern !== \"string\" || rule.pattern.trim().length === 0) return null;\n if (typeof rule.priority !== \"number\" || !Number.isFinite(rule.priority)) return null;\n\n const targetValidation = validateRouteTarget(rule.target, options);\n if (!targetValidation.ok || !targetValidation.target) return null;\n\n const normalizedPriority = Math.trunc(rule.priority);\n const normalizedTarget = targetValidation.target;\n const id = typeof rule.id === \"string\" && rule.id.trim().length > 0\n ? rule.id.trim()\n : stableRuleId({\n patternType: rule.patternType,\n pattern: rule.pattern.trim(),\n priority: normalizedPriority,\n target: normalizedTarget,\n });\n return {\n id,\n patternType: rule.patternType,\n pattern: rule.pattern.trim(),\n priority: normalizedPriority,\n target: normalizedTarget,\n enabled: true,\n };\n}\n\nexport class RoutingRulesStore {\n private readonly memoryRoot: string;\n private readonly statePath: string;\n private readonly lockPath: string;\n private writeQueue: Promise<void> = Promise.resolve();\n\n constructor(memoryDir: string, stateFile = \"state/routing-rules.json\") {\n this.memoryRoot = path.resolve(memoryDir);\n this.statePath = resolveStatePath(memoryDir, stateFile);\n this.lockPath = `${this.statePath}.lock`;\n }\n\n async read(options?: RoutingEngineOptions): Promise<RouteRule[]> {\n try {\n const persisted = await this.readPersistedRules();\n return persisted\n .map((rule) => normalizeRule(rule, options))\n .filter((rule): rule is RouteRule => rule !== null);\n } catch {\n return [];\n }\n }\n\n async write(rules: RouteRule[], options?: RoutingEngineOptions): Promise<RouteRule[]> {\n return this.withWriteLock(async () => this.writeNormalized(rules, options));\n }\n\n async upsert(rule: RouteRule, options?: RoutingEngineOptions): Promise<RouteRule[]> {\n return this.withWriteLock(async () => {\n const existing = await this.readPersistedRules();\n const normalized = normalizeRule(rule, options);\n if (!normalized) return existing;\n\n const next = existing.filter((entry) => entry.id !== normalized.id);\n next.push(normalized);\n return this.writeNormalized(next);\n });\n }\n\n async removeByPattern(pattern: string): Promise<RouteRule[]> {\n return this.withWriteLock(async () => {\n const trimmed = pattern.trim();\n const existing = await this.readPersistedRules();\n const next = existing.filter((entry) => entry.pattern !== trimmed);\n if (next.length === existing.length) return existing;\n return this.writeNormalized(next);\n });\n }\n\n async reset(): Promise<void> {\n await this.withWriteLock(async () => {\n const payload = defaultState();\n await this.assertStatePathScoped();\n await writeFile(this.statePath, JSON.stringify(payload, null, 2), \"utf-8\");\n });\n }\n\n private dedupeById(rules: RouteRule[]): RouteRule[] {\n const byId = new Map<string, RouteRule>();\n for (const rule of rules) {\n byId.set(rule.id, rule);\n }\n return Array.from(byId.values());\n }\n\n private async readPersistedRules(): Promise<RouteRule[]> {\n try {\n await this.assertStatePathScoped();\n const raw = await readFile(this.statePath, \"utf-8\");\n const parsed = JSON.parse(raw) as Partial<RoutingRulesState>;\n if (!parsed || typeof parsed !== \"object\" || !Array.isArray(parsed.rules)) return [];\n const normalized = parsed.rules\n .map((rule) => normalizeRule(rule))\n .filter((rule): rule is RouteRule => rule !== null);\n return this.dedupeById(normalized);\n } catch {\n return [];\n }\n }\n\n private async writeNormalized(rules: RouteRule[], options?: RoutingEngineOptions): Promise<RouteRule[]> {\n const normalized = this.dedupeById(\n rules\n .map((rule) => normalizeRule(rule, options))\n .filter((rule): rule is RouteRule => rule !== null),\n );\n\n const payload: RoutingRulesState = {\n version: 1,\n updatedAt: new Date().toISOString(),\n rules: normalized,\n };\n\n const tmpPath = `${this.statePath}.tmp-${process.pid}-${Date.now()}`;\n try {\n await this.assertStatePathScoped();\n await writeFile(tmpPath, JSON.stringify(payload, null, 2), \"utf-8\");\n await rename(tmpPath, this.statePath);\n } catch (err) {\n log.debug(`routing rules write failed: ${err}`);\n throw err;\n } finally {\n await rm(tmpPath, { force: true }).catch(() => {});\n }\n\n return normalized;\n }\n\n private async withWriteLock<T>(op: () => Promise<T>): Promise<T> {\n const previous = this.writeQueue;\n let release: () => void = () => {};\n this.writeQueue = new Promise<void>((resolve) => {\n release = resolve;\n });\n await previous;\n let unlock: (() => Promise<void>) | null = null;\n try {\n unlock = await this.acquireFileLock();\n return await op();\n } finally {\n if (unlock) await unlock();\n release();\n }\n }\n\n private async acquireFileLock(): Promise<() => Promise<void>> {\n const start = Date.now();\n const staleMs = 30_000;\n const timeoutMs = 5_000;\n let unexpectedLockError: unknown = null;\n await this.assertStatePathScoped();\n await mkdir(path.dirname(this.lockPath), { recursive: true });\n\n while (Date.now() - start < timeoutMs) {\n try {\n await mkdir(this.lockPath);\n return async () => {\n try {\n await rm(this.lockPath, { recursive: true, force: true });\n } catch {\n // Fail-open: lock cleanup should not fail writes.\n }\n };\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code !== \"EEXIST\") {\n unexpectedLockError = err;\n break;\n }\n try {\n const lockStat = await stat(this.lockPath);\n if (Date.now() - lockStat.mtimeMs > staleMs) {\n await rm(this.lockPath, { recursive: true, force: true });\n continue;\n }\n } catch {\n // Lock may have been released between stat/rm attempts.\n }\n await new Promise((resolve) => setTimeout(resolve, 25));\n }\n }\n\n if (unexpectedLockError) {\n throw unexpectedLockError;\n }\n throw new Error(`routing rules lock acquisition timed out after ${timeoutMs}ms`);\n }\n\n private async assertStatePathScoped(): Promise<void> {\n await mkdir(this.memoryRoot, { recursive: true });\n const canonicalRoot = await realpath(this.memoryRoot);\n const canonicalParent = await this.canonicalizePathWithoutCreating(path.dirname(this.statePath));\n const canonicalStatePath = path.join(canonicalParent, path.basename(this.statePath));\n if (!this.isPathInside(canonicalRoot, canonicalStatePath)) {\n throw new Error(`routing rules state path escaped memoryDir: ${canonicalStatePath}`);\n }\n await mkdir(path.dirname(this.statePath), { recursive: true });\n try {\n const stateStats = await lstat(this.statePath);\n if (stateStats.isSymbolicLink()) {\n const canonicalFile = await realpath(this.statePath);\n if (!this.isPathInside(canonicalRoot, canonicalFile)) {\n throw new Error(`routing rules state symlink escaped memoryDir: ${canonicalFile}`);\n }\n }\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code !== \"ENOENT\") {\n throw err;\n }\n }\n }\n\n private isPathInside(root: string, candidate: string): boolean {\n const normalizedRoot = path.resolve(root);\n const normalizedCandidate = path.resolve(candidate);\n if (normalizedCandidate === normalizedRoot) return true;\n if (normalizedRoot === path.parse(normalizedRoot).root) {\n return normalizedCandidate.startsWith(normalizedRoot);\n }\n return normalizedCandidate.startsWith(`${normalizedRoot}${path.sep}`);\n }\n\n private async canonicalizePathWithoutCreating(targetPath: string): Promise<string> {\n const absoluteTarget = path.resolve(targetPath);\n let probe = absoluteTarget;\n while (true) {\n try {\n const canonicalProbe = await realpath(probe);\n const remainder = path.relative(probe, absoluteTarget);\n return path.resolve(canonicalProbe, remainder);\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code !== \"ENOENT\") {\n throw err;\n }\n const parent = path.dirname(probe);\n if (parent === probe) {\n return absoluteTarget;\n }\n probe = parent;\n }\n }\n }\n}\n"],"mappings":";;;;;;;;AAUA,IAAM,uBACJ;AAGF,IAAM,0BACJ;AAMF,SAAS,uBAAuB,WAA4B;AAC1D,QAAM,QAAQ,UAAU;AAAA,IACtB;AAAA,EACF;AACA,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,CAAC,EAAE,MAAM,MAAM,MAAM,MAAM,QAAQ,IAAI,IAAI;AACjD,QAAM,IAAI,OAAO,IAAI;AACrB,QAAM,IAAI,OAAO,IAAI;AACrB,QAAM,IAAI,OAAO,IAAI;AACrB,QAAM,IAAI,OAAO,IAAI;AACrB,QAAM,MAAM,OAAO,MAAM;AACzB,QAAM,IAAI,OAAO,IAAI;AACrB,MAAI,IAAI,KAAK,IAAI,GAAI,QAAO;AAC5B,MAAI,IAAI,KAAK,IAAI,GAAI,QAAO;AAC5B,MAAI,IAAI,MAAM,MAAM,MAAM,IAAI,GAAI,QAAO;AAEzC,QAAM,cAAc,IAAI,KAAK,GAAG,GAAG,CAAC,EAAE,QAAQ;AAC9C,MAAI,IAAI,YAAa,QAAO;AAC5B,SAAO;AACT;AAMA,SAAS,eAAe,WAA4B;AAClD,QAAM,cAAc,UAAU,MAAM,wBAAwB;AAC5D,MAAI,CAAC,YAAa,QAAO;AACzB,QAAM,KAAK,OAAO,YAAY,CAAC,CAAC;AAChC,QAAM,KAAK,OAAO,YAAY,CAAC,CAAC;AAChC,MAAI,KAAK,MAAM,KAAK,GAAI,QAAO;AAE/B,MAAI,OAAO,MAAM,KAAK,EAAG,QAAO;AAChC,SAAO;AACT;AAOA,SAAS,0BAA0B,OAAuB;AACxD,QAAM,YAAY,MAAM,MAAM,WAAW;AACzC,MAAI,WAAW;AACb,UAAM,MAAM,UAAU,CAAC,IAAI,OAAO,MAAM,GAAG,CAAC;AAC5C,WAAO,MAAM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;AACrB,gBAAM;AAAA,QACR;AACA,cAAM,SAAS,KAAK,QAAQ,KAAK;AACjC,YAAI,WAAW,OAAO;AACpB,iBAAO;AAAA,QACT;AACA,gBAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/abort-error.ts
|
|
2
|
+
function abortError(message) {
|
|
3
|
+
const err = new Error(message);
|
|
4
|
+
Object.defineProperty(err, "name", { value: "AbortError" });
|
|
5
|
+
return err;
|
|
6
|
+
}
|
|
7
|
+
function isAbortError(err) {
|
|
8
|
+
return err instanceof Error && err.name === "AbortError";
|
|
9
|
+
}
|
|
10
|
+
function throwIfAborted(signal, message = "operation aborted") {
|
|
11
|
+
if (signal?.aborted) {
|
|
12
|
+
throw abortError(message);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
abortError,
|
|
18
|
+
isAbortError,
|
|
19
|
+
throwIfAborted
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-PVGDJXVK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/abort-error.ts"],"sourcesContent":["/**\n * Shared abort-error helpers.\n *\n * Consolidates the `throwIfAborted` / `abortError` / `isAbortError`\n * patterns that were independently implemented across\n * `direct-answer-wiring.ts`, `harmonic-retrieval.ts`, and `qmd.ts`\n * (plus a private pair in `orchestrator.ts`). A single helper\n * means future changes to the abort-error convention are applied\n * consistently across the codebase.\n *\n * The convention (matching Web / Node): throw a standard `Error`\n * with `name === \"AbortError\"`. Callers dispatch on name rather\n * than a specific class so error propagation across async\n * boundaries continues to classify correctly.\n */\n\n/**\n * Build an Error whose `name` is `\"AbortError\"`. Uses\n * `Object.defineProperty` so the name is non-enumerable and\n * mirrors the shape of `DOMException(\"AbortError\")` where that\n * is available.\n */\nexport function abortError(message: string): Error {\n const err = new Error(message);\n Object.defineProperty(err, \"name\", { value: \"AbortError\" });\n return err;\n}\n\n/** Return true iff `err` is an Error whose `name` is `\"AbortError\"`. */\nexport function isAbortError(err: unknown): boolean {\n return err instanceof Error && err.name === \"AbortError\";\n}\n\n/**\n * Throw an AbortError when the given signal has fired. No-op\n * when the signal is absent or not yet aborted. The default\n * message matches the prior in-module implementations.\n */\nexport function throwIfAborted(\n signal?: AbortSignal,\n message = \"operation aborted\",\n): void {\n if (signal?.aborted) {\n throw abortError(message);\n }\n}\n"],"mappings":";AAsBO,SAAS,WAAW,SAAwB;AACjD,QAAM,MAAM,IAAI,MAAM,OAAO;AAC7B,SAAO,eAAe,KAAK,QAAQ,EAAE,OAAO,aAAa,CAAC;AAC1D,SAAO;AACT;AAGO,SAAS,aAAa,KAAuB;AAClD,SAAO,eAAe,SAAS,IAAI,SAAS;AAC9C;AAOO,SAAS,eACd,QACA,UAAU,qBACJ;AACN,MAAI,QAAQ,SAAS;AACnB,UAAM,WAAW,OAAO;AAAA,EAC1B;AACF;","names":[]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-3QKK7QOS.js";
|
|
5
5
|
import {
|
|
6
6
|
clamp01
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-TBBDFYXW.js";
|
|
8
8
|
|
|
9
9
|
// src/utility-learner.ts
|
|
10
10
|
import path from "path";
|
|
@@ -265,4 +265,4 @@ export {
|
|
|
265
265
|
learnUtilityPromotionWeights,
|
|
266
266
|
getUtilityLearningStatus
|
|
267
267
|
};
|
|
268
|
-
//# sourceMappingURL=chunk-
|
|
268
|
+
//# sourceMappingURL=chunk-PYXS46O7.js.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// src/procedural/procedure-types.ts
|
|
2
|
+
function normalizeProcedureSteps(raw) {
|
|
3
|
+
if (!Array.isArray(raw)) return [];
|
|
4
|
+
const out = [];
|
|
5
|
+
for (let i = 0; i < raw.length; i++) {
|
|
6
|
+
const s = raw[i];
|
|
7
|
+
if (!s || typeof s !== "object") continue;
|
|
8
|
+
const o = s;
|
|
9
|
+
const intent = typeof o.intent === "string" ? o.intent.trim() : "";
|
|
10
|
+
if (!intent) continue;
|
|
11
|
+
const orderRaw = o.order;
|
|
12
|
+
const order = typeof orderRaw === "number" && Number.isFinite(orderRaw) ? Math.max(1, Math.floor(orderRaw)) : i + 1;
|
|
13
|
+
let toolCall;
|
|
14
|
+
const tc = o.toolCall;
|
|
15
|
+
if (tc && typeof tc === "object" && !Array.isArray(tc)) {
|
|
16
|
+
const t = tc;
|
|
17
|
+
const kind = typeof t.kind === "string" ? t.kind.trim() : "";
|
|
18
|
+
const signature = typeof t.signature === "string" ? t.signature.trim() : "";
|
|
19
|
+
if (kind && signature) {
|
|
20
|
+
toolCall = { kind, signature };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const expectedOutcome = typeof o.expectedOutcome === "string" && o.expectedOutcome.trim() ? o.expectedOutcome.trim() : void 0;
|
|
24
|
+
const optional = o.optional === true ? true : void 0;
|
|
25
|
+
out.push({ order, intent, toolCall, expectedOutcome, optional });
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
function buildProcedurePersistBody(title, procedureSteps) {
|
|
30
|
+
const head = typeof title === "string" ? title.trim() : "";
|
|
31
|
+
const steps = normalizeProcedureSteps(procedureSteps);
|
|
32
|
+
if (steps.length === 0) return head;
|
|
33
|
+
return `${head}
|
|
34
|
+
|
|
35
|
+
${buildProcedureMarkdownBody(steps)}`.trimEnd() + "\n";
|
|
36
|
+
}
|
|
37
|
+
function buildProcedureMarkdownBody(steps) {
|
|
38
|
+
const sorted = [...steps].sort((a, b) => a.order - b.order);
|
|
39
|
+
const lines = [];
|
|
40
|
+
for (const step of sorted) {
|
|
41
|
+
const n = Number.isFinite(step.order) ? Math.max(1, Math.floor(step.order)) : 1;
|
|
42
|
+
lines.push(`## Step ${n}`);
|
|
43
|
+
lines.push("");
|
|
44
|
+
lines.push(step.intent.trim());
|
|
45
|
+
if (step.toolCall?.kind && step.toolCall.signature) {
|
|
46
|
+
lines.push("");
|
|
47
|
+
lines.push(`- Tool: \`${step.toolCall.kind}\` \u2014 ${step.toolCall.signature}`);
|
|
48
|
+
}
|
|
49
|
+
if (step.expectedOutcome?.trim()) {
|
|
50
|
+
lines.push("");
|
|
51
|
+
lines.push(`- Expected: ${step.expectedOutcome.trim()}`);
|
|
52
|
+
}
|
|
53
|
+
if (step.optional === true) {
|
|
54
|
+
lines.push("");
|
|
55
|
+
lines.push("- Optional: true");
|
|
56
|
+
}
|
|
57
|
+
lines.push("");
|
|
58
|
+
}
|
|
59
|
+
return lines.join("\n").trimEnd() + "\n";
|
|
60
|
+
}
|
|
61
|
+
var STEP_HEADER_RE = /^##\s+Step\s+(\d+)\s*$/im;
|
|
62
|
+
function parseProcedureStepsFromBody(content) {
|
|
63
|
+
const text = content.replace(/\r\n/g, "\n").trim();
|
|
64
|
+
if (!text) return null;
|
|
65
|
+
const matches = [...text.matchAll(new RegExp(STEP_HEADER_RE.source, "gim"))];
|
|
66
|
+
if (matches.length === 0) return null;
|
|
67
|
+
const steps = [];
|
|
68
|
+
for (let i = 0; i < matches.length; i++) {
|
|
69
|
+
const m = matches[i];
|
|
70
|
+
const order = Number.parseInt(m[1] ?? "1", 10);
|
|
71
|
+
const start = (m.index ?? 0) + m[0].length;
|
|
72
|
+
const end = i + 1 < matches.length ? matches[i + 1].index ?? text.length : text.length;
|
|
73
|
+
const block = text.slice(start, end).trim();
|
|
74
|
+
const lines = block.split("\n").map((l) => l.trim());
|
|
75
|
+
const intentLines = lines.filter(
|
|
76
|
+
(l) => l.length > 0 && !l.startsWith("- Tool:") && !l.startsWith("- Expected:") && !l.startsWith("- Optional:")
|
|
77
|
+
);
|
|
78
|
+
const intent = intentLines.join(" ").trim() || "(unspecified)";
|
|
79
|
+
let toolCall;
|
|
80
|
+
const toolLine = lines.find((l) => l.startsWith("- Tool:"));
|
|
81
|
+
if (toolLine) {
|
|
82
|
+
const inner = toolLine.replace(/^- Tool:\s*/i, "").trim();
|
|
83
|
+
const tick = inner.match(/^`([^`]+)`\s*[—-]\s*(.+)$/);
|
|
84
|
+
if (tick) {
|
|
85
|
+
toolCall = { kind: tick[1].trim(), signature: tick[2].trim() };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const expectedLine = lines.find((l) => l.startsWith("- Expected:"));
|
|
89
|
+
const expectedOutcome = expectedLine?.replace(/^- Expected:\s*/i, "").trim();
|
|
90
|
+
const optional = /^- Optional:\s*true$/i.test(lines.find((l) => l.startsWith("- Optional:")) ?? "");
|
|
91
|
+
steps.push({
|
|
92
|
+
order: Number.isFinite(order) ? order : i + 1,
|
|
93
|
+
intent,
|
|
94
|
+
toolCall,
|
|
95
|
+
expectedOutcome: expectedOutcome?.length ? expectedOutcome : void 0,
|
|
96
|
+
optional: optional || void 0
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return steps.length > 0 ? steps : null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export {
|
|
103
|
+
normalizeProcedureSteps,
|
|
104
|
+
buildProcedurePersistBody,
|
|
105
|
+
buildProcedureMarkdownBody,
|
|
106
|
+
parseProcedureStepsFromBody
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=chunk-QDW3E4RD.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/procedural/procedure-types.ts"],"sourcesContent":["/**\n * Procedural memory types (issue #519).\n * Bodies use ordered \"## Step N\" sections; machine fields live in frontmatter / structuredAttributes.\n */\n\nexport interface ProcedureStep {\n order: number;\n intent: string;\n toolCall?: {\n kind: string;\n signature: string;\n };\n expectedOutcome?: string;\n optional?: boolean;\n}\n\n/** Normalize loose extraction JSON into ProcedureStep records. */\nexport function normalizeProcedureSteps(raw: unknown): ProcedureStep[] {\n if (!Array.isArray(raw)) return [];\n const out: ProcedureStep[] = [];\n for (let i = 0; i < raw.length; i++) {\n const s = raw[i];\n if (!s || typeof s !== \"object\") continue;\n const o = s as Record<string, unknown>;\n const intent = typeof o.intent === \"string\" ? o.intent.trim() : \"\";\n if (!intent) continue;\n const orderRaw = o.order;\n const order =\n typeof orderRaw === \"number\" && Number.isFinite(orderRaw)\n ? Math.max(1, Math.floor(orderRaw))\n : i + 1;\n let toolCall: ProcedureStep[\"toolCall\"];\n const tc = o.toolCall;\n if (tc && typeof tc === \"object\" && !Array.isArray(tc)) {\n const t = tc as Record<string, unknown>;\n const kind = typeof t.kind === \"string\" ? t.kind.trim() : \"\";\n const signature = typeof t.signature === \"string\" ? t.signature.trim() : \"\";\n if (kind && signature) {\n toolCall = { kind, signature };\n }\n }\n const expectedOutcome =\n typeof o.expectedOutcome === \"string\" && o.expectedOutcome.trim()\n ? o.expectedOutcome.trim()\n : undefined;\n const optional = o.optional === true ? true : undefined;\n out.push({ order, intent, toolCall, expectedOutcome, optional });\n }\n return out;\n}\n\n/** Title line plus serialized steps for storage.writeMemory body. */\nexport function buildProcedurePersistBody(title: string, procedureSteps: unknown): string {\n const head = typeof title === \"string\" ? title.trim() : \"\";\n const steps = normalizeProcedureSteps(procedureSteps);\n if (steps.length === 0) return head;\n return `${head}\\n\\n${buildProcedureMarkdownBody(steps)}`.trimEnd() + \"\\n\";\n}\n\n/** Serialize steps into markdown body (human-editable). */\nexport function buildProcedureMarkdownBody(steps: ProcedureStep[]): string {\n const sorted = [...steps].sort((a, b) => a.order - b.order);\n const lines: string[] = [];\n for (const step of sorted) {\n const n = Number.isFinite(step.order) ? Math.max(1, Math.floor(step.order)) : 1;\n lines.push(`## Step ${n}`);\n lines.push(\"\");\n lines.push(step.intent.trim());\n if (step.toolCall?.kind && step.toolCall.signature) {\n lines.push(\"\");\n lines.push(`- Tool: \\`${step.toolCall.kind}\\` — ${step.toolCall.signature}`);\n }\n if (step.expectedOutcome?.trim()) {\n lines.push(\"\");\n lines.push(`- Expected: ${step.expectedOutcome.trim()}`);\n }\n if (step.optional === true) {\n lines.push(\"\");\n lines.push(\"- Optional: true\");\n }\n lines.push(\"\");\n }\n return lines.join(\"\\n\").trimEnd() + \"\\n\";\n}\n\nconst STEP_HEADER_RE = /^##\\s+Step\\s+(\\d+)\\s*$/im;\n\n/**\n * Best-effort parse of \"## Step N\" blocks into ProcedureStep records.\n * Returns null when no step headers are found.\n */\nexport function parseProcedureStepsFromBody(content: string): ProcedureStep[] | null {\n const text = content.replace(/\\r\\n/g, \"\\n\").trim();\n if (!text) return null;\n const matches = [...text.matchAll(new RegExp(STEP_HEADER_RE.source, \"gim\"))];\n if (matches.length === 0) return null;\n\n const steps: ProcedureStep[] = [];\n for (let i = 0; i < matches.length; i++) {\n const m = matches[i];\n const order = Number.parseInt(m[1] ?? \"1\", 10);\n const start = (m.index ?? 0) + m[0].length;\n const end = i + 1 < matches.length ? (matches[i + 1].index ?? text.length) : text.length;\n const block = text.slice(start, end).trim();\n const lines = block.split(\"\\n\").map((l) => l.trim());\n const intentLines = lines.filter(\n (l) => l.length > 0 && !l.startsWith(\"- Tool:\") && !l.startsWith(\"- Expected:\") && !l.startsWith(\"- Optional:\"),\n );\n const intent = intentLines.join(\" \").trim() || \"(unspecified)\";\n let toolCall: ProcedureStep[\"toolCall\"];\n const toolLine = lines.find((l) => l.startsWith(\"- Tool:\"));\n if (toolLine) {\n const inner = toolLine.replace(/^- Tool:\\s*/i, \"\").trim();\n const tick = inner.match(/^`([^`]+)`\\s*[—-]\\s*(.+)$/);\n if (tick) {\n toolCall = { kind: tick[1].trim(), signature: tick[2].trim() };\n }\n }\n const expectedLine = lines.find((l) => l.startsWith(\"- Expected:\"));\n const expectedOutcome = expectedLine?.replace(/^- Expected:\\s*/i, \"\").trim();\n const optional = /^- Optional:\\s*true$/i.test(lines.find((l) => l.startsWith(\"- Optional:\")) ?? \"\");\n\n steps.push({\n order: Number.isFinite(order) ? order : i + 1,\n intent,\n toolCall,\n expectedOutcome: expectedOutcome?.length ? expectedOutcome : undefined,\n optional: optional || undefined,\n });\n }\n return steps.length > 0 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QAAQ,IAAI;AAAA,MAC5C;AAAA,MACA;AAAA,MACA,iBAAiB,iBAAiB,SAAS,kBAAkB;AAAA,MAC7D,UAAU,YAAY;AAAA,IACxB,CAAC;AAAA,EACH;AACA,SAAO,MAAM,SAAS,IAAI,QAAQ;AACpC;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isSafeRouteNamespace
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QNJMBKFK.js";
|
|
4
4
|
import {
|
|
5
5
|
sanitizeMemoryContent
|
|
6
6
|
} from "./chunk-M62O4P4T.js";
|
|
@@ -20,7 +20,8 @@ var INLINE_ALLOWED_CATEGORIES = /* @__PURE__ */ new Set([
|
|
|
20
20
|
"commitment",
|
|
21
21
|
"moment",
|
|
22
22
|
"skill",
|
|
23
|
-
"rule"
|
|
23
|
+
"rule",
|
|
24
|
+
"procedure"
|
|
24
25
|
]);
|
|
25
26
|
var SECRET_PATTERNS = [
|
|
26
27
|
/\bsk-[A-Za-z0-9]{16,}\b/,
|
|
@@ -385,4 +386,4 @@ export {
|
|
|
385
386
|
shouldSkipImplicitExtraction,
|
|
386
387
|
shouldProcessInlineExplicitCapture
|
|
387
388
|
};
|
|
388
|
-
//# sourceMappingURL=chunk-
|
|
389
|
+
//# sourceMappingURL=chunk-QDYXG4CS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/explicit-capture.ts"],"sourcesContent":["import { randomUUID } from \"node:crypto\";\nimport type { Orchestrator } from \"./orchestrator.js\";\nimport { isSafeRouteNamespace } from \"./routing/engine.js\";\nimport { sanitizeMemoryContent } from \"./sanitize.js\";\nimport { ContentHashIndex } from \"./storage.js\";\nimport type { CaptureMode, MemoryCategory, MemoryLifecycleEvent, PluginConfig } from \"./types.js\";\n\nexport type ExplicitCaptureInput = {\n content: string;\n category?: string;\n confidence?: number;\n namespace?: string;\n tags?: string[];\n entityRef?: string;\n ttl?: string;\n sourceReason?: string;\n};\n\nexport type ValidExplicitCapture = {\n content: string;\n category: MemoryCategory;\n confidence: number;\n namespace?: string;\n tags: string[];\n entityRef?: string;\n expiresAt?: string;\n sourceReason?: string;\n};\n\nexport type ExplicitCaptureSource = \"memory_store\" | \"memory_capture\" | \"suggestion_submit\" | \"inline\";\ntype ExplicitCaptureValidationMode = \"legacy_tool\" | \"strict_explicit\";\n\nconst INLINE_NOTE_RE = /<memory_note>\\s*([\\s\\S]*?)\\s*<\\/memory_note>/gi;\nconst INLINE_NOTE_MARKUP_RE = /<memory_note>\\s*[\\s\\S]*?\\s*<\\/memory_note>/i;\nconst INLINE_ALLOWED_CATEGORIES = new Set<MemoryCategory>([\n \"fact\",\n \"preference\",\n \"correction\",\n \"entity\",\n \"decision\",\n \"relationship\",\n \"principle\",\n \"commitment\",\n \"moment\",\n \"skill\",\n \"rule\",\n \"procedure\",\n]);\n\nconst SECRET_PATTERNS: RegExp[] = [\n /\\bsk-[A-Za-z0-9]{16,}\\b/,\n /\\bAKIA[0-9A-Z]{16}\\b/,\n /\\bBearer\\s+[A-Za-z0-9._-]{16,}\\b/i,\n /\\b(?:api[_-]?key|secret|token|password|passwd)\\s*[:=]\\s*[^\\s]{8,}\\b/i,\n /\\b(?:authorization)\\s*:\\s*[^\\s]{8,}\\b/i,\n];\nconst SECRET_REDACTION_PATTERNS: Array<{ pattern: RegExp; replacement: string }> = [\n { pattern: /\\bsk-[A-Za-z0-9]{16,}\\b/g, replacement: \"[redacted openai key]\" },\n { pattern: /\\bAKIA[0-9A-Z]{16}\\b/g, replacement: \"[redacted aws key]\" },\n { pattern: /\\bBearer\\s+[A-Za-z0-9._-]{16,}\\b/gi, replacement: \"Bearer [redacted token]\" },\n {\n pattern: /\\b(?:api[_-]?key|secret|token|password|passwd)\\s*[:=]\\s*[^\\s]{8,}\\b/gi,\n replacement: \"[redacted credential]\",\n },\n {\n pattern: /\\b(?:authorization)\\s*:\\s*[^\\s]{8,}\\b/gi,\n replacement: \"authorization: [redacted credential]\",\n },\n];\nconst EXPLICIT_CAPTURE_REVIEW_TAGS = [\"explicit-capture\", \"queued-review\"];\n\nfunction explicitCaptureActor(source: ExplicitCaptureSource): string {\n switch (source) {\n case \"inline\":\n return \"inline.memory_note\";\n case \"memory_store\":\n return \"tool.memory_store\";\n case \"suggestion_submit\":\n return \"tool.suggestion_submit\";\n default:\n return \"tool.memory_capture\";\n }\n}\n\nfunction asTrimmed(value: string | undefined): string | undefined {\n const trimmed = value?.trim();\n return trimmed && trimmed.length > 0 ? trimmed : undefined;\n}\n\nfunction normalizeCaptureContent(value: string): string {\n return value\n .toLowerCase()\n .replace(/\\s+/g, \" \")\n .trim();\n}\n\nfunction redactSecrets(value: string): string {\n let redacted = value;\n for (const { pattern, replacement } of SECRET_REDACTION_PATTERNS) {\n redacted = redacted.replace(pattern, replacement);\n }\n return redacted;\n}\n\nfunction normalizeExplicitCaptureError(error: unknown): string {\n if (error instanceof Error && error.message.trim().length > 0) return error.message.trim();\n const rendered = String(error).trim();\n return rendered.length > 0 ? rendered : \"explicit capture failed\";\n}\n\nfunction resolveExplicitCaptureReviewNamespace(\n orchestrator: Orchestrator,\n namespace: string | undefined,\n): string | undefined {\n const normalized = asTrimmed(namespace);\n if (!normalized) return undefined;\n return resolveExplicitCaptureNamespace(orchestrator, normalized);\n}\n\nfunction resolveExplicitCaptureNamespace(\n orchestrator: Orchestrator,\n namespace: string | undefined,\n): string | undefined {\n const normalized = asTrimmed(namespace);\n if (!normalized) return undefined;\n if (!orchestrator.config.namespacesEnabled) {\n if (normalized !== orchestrator.config.defaultNamespace) {\n throw new Error(`unsupported namespace: ${normalized}`);\n }\n return normalized;\n }\n const allowed = new Set([\n orchestrator.config.defaultNamespace,\n orchestrator.config.sharedNamespace,\n ...orchestrator.config.namespacePolicies.map((policy) => policy.name),\n ].map((value) => value.trim()).filter(Boolean));\n if (!allowed.has(normalized)) {\n throw new Error(`unsupported namespace: ${normalized}`);\n }\n return normalized;\n}\n\nfunction parseExplicitCaptureTtl(ttl: string | undefined): string | undefined {\n const raw = asTrimmed(ttl);\n if (!raw) return undefined;\n\n const absoluteMs = Date.parse(raw);\n if (Number.isFinite(absoluteMs)) {\n return new Date(absoluteMs).toISOString();\n }\n\n const relative = raw.match(/^(\\d+)\\s*([mhdw])$/i);\n if (!relative) {\n throw new Error(\"ttl must be an ISO-8601 timestamp or relative duration like 30m, 12h, 7d, or 2w\");\n }\n\n const amount = Number.parseInt(relative[1] ?? \"\", 10);\n const unit = (relative[2] ?? \"\").toLowerCase();\n if (!Number.isFinite(amount) || amount <= 0) {\n throw new Error(\"ttl duration must be a positive integer\");\n }\n\n const multiplier =\n unit === \"m\" ? 60_000\n : unit === \"h\" ? 60 * 60_000\n : unit === \"d\" ? 24 * 60 * 60_000\n : 7 * 24 * 60 * 60_000;\n return new Date(Date.now() + amount * multiplier).toISOString();\n}\n\nfunction parseInlineNote(block: string): ExplicitCaptureInput | null {\n const lines = block.replace(/\\r/g, \"\").split(\"\\n\");\n const note: Partial<ExplicitCaptureInput> = {};\n let idx = 0;\n\n while (idx < lines.length) {\n const rawLine = lines[idx] ?? \"\";\n const line = rawLine.trim();\n idx += 1;\n if (line.length === 0) continue;\n const colonIdx = line.indexOf(\":\");\n if (colonIdx < 0) continue;\n const key = line.slice(0, colonIdx).trim();\n const value = line.slice(colonIdx + 1).trim();\n\n if (key === \"content\" && value === \"|\") {\n const contentLines: string[] = [];\n while (idx < lines.length) {\n const next = lines[idx] ?? \"\";\n if (next.startsWith(\" \") || next.startsWith(\"\\t\")) {\n contentLines.push(next.replace(/^( |\\t)/, \"\"));\n idx += 1;\n continue;\n }\n if (next.trim().length === 0) {\n contentLines.push(\"\");\n idx += 1;\n continue;\n }\n break;\n }\n note.content = contentLines.join(\"\\n\").trim();\n continue;\n }\n\n switch (key) {\n case \"content\":\n note.content = value;\n break;\n case \"category\":\n note.category = value;\n break;\n case \"confidence\":\n note.confidence = Number.parseFloat(value);\n break;\n case \"namespace\":\n note.namespace = value;\n break;\n case \"tags\":\n note.tags = value\n .split(\",\")\n .map((entry) => entry.trim())\n .filter(Boolean);\n break;\n case \"entityRef\":\n note.entityRef = value;\n break;\n case \"ttl\":\n note.ttl = value;\n break;\n case \"sourceReason\":\n note.sourceReason = value;\n break;\n default:\n break;\n }\n }\n\n return asTrimmed(note.content) ? (note as ExplicitCaptureInput) : null;\n}\n\nexport function parseInlineExplicitCaptureNotes(text: string): ExplicitCaptureInput[] {\n const notes: ExplicitCaptureInput[] = [];\n for (const match of text.matchAll(INLINE_NOTE_RE)) {\n const parsed = parseInlineNote(match[1] ?? \"\");\n if (parsed) notes.push(parsed);\n }\n return notes;\n}\n\nexport function hasInlineExplicitCaptureMarkup(text: string): boolean {\n return INLINE_NOTE_MARKUP_RE.test(text);\n}\n\nexport function stripInlineExplicitCaptureNotes(text: string): string {\n return text.replace(INLINE_NOTE_RE, \"\").trim();\n}\n\nexport function validateExplicitCaptureInput(\n input: ExplicitCaptureInput,\n mode: ExplicitCaptureValidationMode = \"strict_explicit\",\n): ValidExplicitCapture {\n const content = asTrimmed(input.content);\n if (!content) throw new Error(\"content is required\");\n if (mode === \"strict_explicit\") {\n if (content.length < 10) throw new Error(\"content must be at least 10 characters\");\n if (content.length > 4000) throw new Error(\"content must be 4000 characters or fewer\");\n }\n if (/<memory_note>/i.test(content) || /<\\/memory_note>/i.test(content)) {\n throw new Error(\"nested memory_note blocks are not allowed\");\n }\n\n const category = (asTrimmed(input.category) ?? \"fact\") as MemoryCategory;\n if (!INLINE_ALLOWED_CATEGORIES.has(category)) {\n throw new Error(`unsupported category: ${input.category ?? category}`);\n }\n\n const sanitized = sanitizeMemoryContent(content);\n if (!sanitized.clean) {\n throw new Error(\"content failed memory sanitization\");\n }\n for (const pattern of SECRET_PATTERNS) {\n if (pattern.test(content)) {\n throw new Error(\"content appears to contain a secret or credential\");\n }\n }\n\n const confidence = Number.isFinite(input.confidence) ? Number(input.confidence) : 0.95;\n if (confidence < 0 || confidence > 1) {\n throw new Error(\"confidence must be between 0 and 1\");\n }\n const requestedNamespace = asTrimmed(input.namespace);\n if (requestedNamespace && !isSafeRouteNamespace(requestedNamespace)) {\n throw new Error(`unsafe namespace: ${requestedNamespace}`);\n }\n const expiresAt = parseExplicitCaptureTtl(input.ttl);\n\n return {\n content,\n category,\n confidence,\n namespace: asTrimmed(input.namespace),\n tags: Array.from(new Set((input.tags ?? []).map((tag) => tag.trim()).filter(Boolean))),\n entityRef: asTrimmed(input.entityRef),\n expiresAt,\n sourceReason: asTrimmed(input.sourceReason),\n };\n}\n\nasync function findDuplicateExplicitCapture(\n orchestrator: Orchestrator,\n resolvedNamespace: string | undefined,\n candidate: ValidExplicitCapture,\n): Promise<string | null> {\n const storage = await orchestrator.getStorage(resolvedNamespace);\n if (\n candidate.category === \"fact\"\n && typeof (storage as { hasFactContentHash?: (content: string) => Promise<boolean> }).hasFactContentHash === \"function\"\n ) {\n try {\n const hasHash = await (storage as { hasFactContentHash: (content: string) => Promise<boolean> }).hasFactContentHash(\n candidate.content,\n );\n if (!hasHash) {\n const authoritative =\n typeof (storage as { isFactContentHashAuthoritative?: () => Promise<boolean> | boolean }).isFactContentHashAuthoritative\n === \"function\"\n ? await (storage as { isFactContentHashAuthoritative: () => Promise<boolean> | boolean })\n .isFactContentHashAuthoritative()\n : false;\n if (authoritative) return null;\n }\n } catch (err) {\n // Fail open: hash index is only an optimization, so fall back to the full corpus scan.\n void err;\n }\n }\n const existing = await storage.readAllMemories();\n const normalizedCandidate = normalizeCaptureContent(candidate.content);\n const match = existing.find((memory) => {\n const status = memory.frontmatter.status ?? \"active\";\n if (status !== \"active\") return false;\n if (memory.frontmatter.category !== candidate.category) return false;\n return normalizeCaptureContent(memory.content) === normalizedCandidate;\n });\n return match?.frontmatter.id ?? null;\n}\n\nexport async function persistExplicitCapture(\n orchestrator: Orchestrator,\n candidate: ValidExplicitCapture,\n source: ExplicitCaptureSource,\n): Promise<{ id: string; duplicateOf?: string }> {\n const resolvedNamespace = resolveExplicitCaptureNamespace(orchestrator, candidate.namespace);\n const duplicateOf = await findDuplicateExplicitCapture(orchestrator, resolvedNamespace, candidate);\n if (duplicateOf) {\n return { id: duplicateOf, duplicateOf };\n }\n\n const storage = await orchestrator.getStorage(resolvedNamespace);\n const id = await storage.writeMemory(candidate.category, candidate.content, {\n confidence: candidate.confidence,\n tags: candidate.tags,\n entityRef: candidate.entityRef,\n expiresAt: candidate.expiresAt,\n source: source === \"inline\" ? \"explicit-inline\" : \"explicit\",\n });\n\n const created = new Date().toISOString();\n const event: MemoryLifecycleEvent = {\n eventId: `mle-${randomUUID()}`,\n memoryId: id,\n eventType: \"explicit_capture_accepted\",\n timestamp: created,\n actor: explicitCaptureActor(source),\n reasonCode: candidate.sourceReason,\n ruleVersion: \"explicit-capture.v1\",\n };\n await storage.appendMemoryLifecycleEvents([event]);\n\n return { id };\n}\n\nfunction buildExplicitCaptureReviewContent(input: ExplicitCaptureInput, reason: string): string {\n const requestedContent = asTrimmed(input.content);\n const sanitized = sanitizeMemoryContent(redactSecrets(requestedContent ?? \"[empty explicit capture]\"));\n const safeContent = sanitized.text.trim().length > 0 ? sanitized.text.trim() : \"[empty explicit capture]\";\n const lines = [\n \"Explicit capture queued for review.\",\n \"\",\n `Reason: ${reason}`,\n \"\",\n \"Submitted content:\",\n safeContent,\n ];\n const metadata = [\n input.category ? `Requested category: ${input.category}` : undefined,\n input.namespace ? `Requested namespace: ${input.namespace}` : undefined,\n input.entityRef ? `Requested entityRef: ${input.entityRef}` : undefined,\n input.ttl ? `Requested ttl: ${input.ttl}` : undefined,\n input.sourceReason ? `Requested sourceReason: ${input.sourceReason}` : undefined,\n input.tags && input.tags.length > 0 ? `Requested tags: ${input.tags.join(\", \")}` : undefined,\n ].filter((entry): entry is string => typeof entry === \"string\" && entry.length > 0);\n if (metadata.length > 0) {\n lines.push(\"\", ...metadata);\n }\n return lines.join(\"\\n\");\n}\n\nasync function findQueuedExplicitCaptureDuplicate(\n orchestrator: Orchestrator,\n namespace: string | undefined,\n content: string,\n): Promise<string | null> {\n const storage = await orchestrator.getStorage(namespace);\n const existing = await storage.readAllMemories();\n const normalized = normalizeCaptureContent(content);\n const match = existing.find((memory) => {\n const status = memory.frontmatter.status ?? \"active\";\n if (status !== \"pending_review\") return false;\n if (!(memory.frontmatter.tags ?? []).includes(\"queued-review\")) return false;\n return normalizeCaptureContent(memory.content) === normalized;\n });\n return match?.frontmatter.id ?? null;\n}\n\nexport async function queueExplicitCaptureForReview(\n orchestrator: Orchestrator,\n input: ExplicitCaptureInput,\n source: ExplicitCaptureSource,\n error: unknown,\n): Promise<{ id: string; duplicateOf?: string }> {\n const reason = normalizeExplicitCaptureError(error);\n const requestedNamespace = asTrimmed(input.namespace);\n const queueNamespace = resolveExplicitCaptureReviewNamespace(orchestrator, requestedNamespace);\n const content = buildExplicitCaptureReviewContent(input, reason);\n const duplicateOf = await findQueuedExplicitCaptureDuplicate(orchestrator, queueNamespace, content);\n if (duplicateOf) {\n return { id: duplicateOf, duplicateOf };\n }\n\n const requestedCategory = asTrimmed(input.category);\n const reviewCategory = requestedCategory && INLINE_ALLOWED_CATEGORIES.has(requestedCategory as MemoryCategory)\n ? requestedCategory as MemoryCategory\n : \"fact\";\n const requestedTags = Array.isArray(input.tags)\n ? input.tags.map((tag) => tag.trim()).filter(Boolean)\n : [];\n const storage = await orchestrator.getStorage(queueNamespace);\n const id = await storage.writeMemory(reviewCategory, content, {\n confidence: 0.2,\n tags: Array.from(new Set([...EXPLICIT_CAPTURE_REVIEW_TAGS, ...requestedTags])),\n entityRef: asTrimmed(input.entityRef),\n source: source === \"inline\" ? \"explicit-inline-review\" : \"explicit-review\",\n });\n const created = await storage.getMemoryById(id);\n if (created) {\n await storage.writeMemoryFrontmatter(created, {\n status: \"pending_review\",\n updated: new Date().toISOString(),\n }, {\n actor: explicitCaptureActor(source),\n reasonCode: reason,\n ruleVersion: \"explicit-capture.v1\",\n });\n }\n const event: MemoryLifecycleEvent = {\n eventId: `mle-${randomUUID()}`,\n memoryId: id,\n eventType: \"explicit_capture_queued\",\n timestamp: new Date().toISOString(),\n actor: explicitCaptureActor(source),\n reasonCode: reason,\n ruleVersion: \"explicit-capture.v1\",\n };\n await storage.appendMemoryLifecycleEvents([event]);\n return { id };\n}\n\nexport function shouldSkipImplicitExtraction(cfg: Pick<PluginConfig, \"captureMode\">): boolean {\n return cfg.captureMode === \"explicit\";\n}\n\nexport function shouldProcessInlineExplicitCapture(cfg: Pick<PluginConfig, \"captureMode\">): boolean {\n return cfg.captureMode !== \"implicit\";\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,kBAAkB;AAgC3B,IAAM,iBAAiB;AACvB,IAAM,wBAAwB;AAC9B,IAAM,4BAA4B,oBAAI,IAAoB;AAAA,EACxD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,kBAA4B;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,IAAM,4BAA6E;AAAA,EACjF,EAAE,SAAS,4BAA4B,aAAa,wBAAwB;AAAA,EAC5E,EAAE,SAAS,yBAAyB,aAAa,qBAAqB;AAAA,EACtE,EAAE,SAAS,sCAAsC,aAAa,0BAA0B;AAAA,EACxF;AAAA,IACE,SAAS;AAAA,IACT,aAAa;AAAA,EACf;AAAA,EACA;AAAA,IACE,SAAS;AAAA,IACT,aAAa;AAAA,EACf;AACF;AACA,IAAM,+BAA+B,CAAC,oBAAoB,eAAe;AAEzE,SAAS,qBAAqB,QAAuC;AACnE,UAAQ,QAAQ;AAAA,IACd,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAEA,SAAS,UAAU,OAA+C;AAChE,QAAM,UAAU,OAAO,KAAK;AAC5B,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MAAM,MAAM,KAAK,oBAAI,IAAI,CAAC,GAAG,8BAA8B,GAAG,aAAa,CAAC,CAAC;AAAA,IAC7E,WAAW,UAAU,MAAM,SAAS;AAAA,IACpC,QAAQ,WAAW,WAAW,2BAA2B;AAAA,EAC3D,CAAC;AACD,QAAM,UAAU,MAAM,QAAQ,cAAc,EAAE;AAC9C,MAAI,SAAS;AACX,UAAM,QAAQ,uBAAuB,SAAS;AAAA,MAC5C,QAAQ;AAAA,MACR,UAAS,oBAAI,KAAK,GAAE,YAAY;AAAA,IAClC,GAAG;AAAA,MACD,OAAO,qBAAqB,MAAM;AAAA,MAClC,YAAY;AAAA,MACZ,aAAa;AAAA,IACf,CAAC;AAAA,EACH;AACA,QAAM,QAA8B;AAAA,IAClC,SAAS,OAAO,WAAW,CAAC;AAAA,IAC5B,UAAU;AAAA,IACV,WAAW;AAAA,IACX,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,IAClC,OAAO,qBAAqB,MAAM;AAAA,IAClC,YAAY;AAAA,IACZ,aAAa;AAAA,EACf;AACA,QAAM,QAAQ,4BAA4B,CAAC,KAAK,CAAC;AACjD,SAAO,EAAE,GAAG;AACd;AAEO,SAAS,6BAA6B,KAAiD;AAC5F,SAAO,IAAI,gBAAgB;AAC7B;AAEO,SAAS,mCAAmC,KAAiD;AAClG,SAAO,IAAI,gBAAgB;AAC7B;","names":[]}
|
|
@@ -10,7 +10,8 @@ var DEFAULT_CATEGORIES = [
|
|
|
10
10
|
"commitment",
|
|
11
11
|
"moment",
|
|
12
12
|
"skill",
|
|
13
|
-
"rule"
|
|
13
|
+
"rule",
|
|
14
|
+
"procedure"
|
|
14
15
|
];
|
|
15
16
|
function normalizeNamespace(namespace) {
|
|
16
17
|
return namespace.trim();
|
|
@@ -106,4 +107,4 @@ export {
|
|
|
106
107
|
validateRouteTarget,
|
|
107
108
|
selectRouteRule
|
|
108
109
|
};
|
|
109
|
-
//# sourceMappingURL=chunk-
|
|
110
|
+
//# sourceMappingURL=chunk-QNJMBKFK.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/routing/engine.ts"],"sourcesContent":["import type { MemoryCategory } from \"../types.js\";\n\nexport type RoutePatternType = \"regex\" | \"keyword\";\n\nexport interface RouteTarget {\n category?: MemoryCategory;\n namespace?: string;\n}\n\nexport interface RouteRule {\n id: string;\n patternType: RoutePatternType;\n pattern: string;\n priority: number;\n target: RouteTarget;\n enabled?: boolean;\n}\n\nexport interface RoutingEngineOptions {\n allowedNamespaces?: string[];\n allowedCategories?: MemoryCategory[];\n}\n\nexport interface RouteSelection {\n rule: RouteRule;\n target: RouteTarget;\n}\n\nconst DEFAULT_CATEGORIES: readonly MemoryCategory[] = [\n \"fact\",\n \"preference\",\n \"correction\",\n \"entity\",\n \"decision\",\n \"relationship\",\n \"principle\",\n \"commitment\",\n \"moment\",\n \"skill\",\n \"rule\",\n \"procedure\",\n] as const;\n\nfunction normalizeNamespace(namespace: string): string {\n return namespace.trim();\n}\n\nexport function isLikelyUnsafeRegex(pattern: string): boolean {\n const value = pattern.trim();\n if (value.length === 0) return true;\n if (value.length > 120) return true;\n if (/\\\\[1-9]/.test(value)) return true; // backreferences\n if (/\\(\\?<?[=!]/.test(value)) return true; // lookaround assertions\n if (/\\((?:[^()\\\\]|\\\\.)*[+*](?:[^()\\\\]|\\\\.)*\\)[+*{]/.test(value)) return true; // nested quantifiers\n // Conservative fail-closed guardrail: grouped/alternation regexes are user-configurable and can be expensive.\n if (/(^|[^\\\\])[()|]/.test(value)) return true;\n // Multiple quantifiers in one user pattern are high risk for catastrophic backtracking on non-matches.\n const quantifierCount =\n (value.match(/(^|[^\\\\])[*+?]/g)?.length ?? 0) +\n (value.match(/(^|[^\\\\])\\{/g)?.length ?? 0);\n if (quantifierCount > 1) return true;\n return false;\n}\n\nexport function isSafeRouteNamespace(namespace: string): boolean {\n const value = normalizeNamespace(namespace);\n if (value.length === 0) return false;\n if (value === \".\") return false;\n if (value.includes(\"/\") || value.includes(\"\\\\\")) return false;\n if (value.includes(\"..\")) return false;\n return /^[A-Za-z0-9._-]{1,64}$/.test(value);\n}\n\nexport function validateRouteTarget(target: RouteTarget | null | undefined, options?: RoutingEngineOptions): {\n ok: boolean;\n error?: string;\n target?: RouteTarget;\n} {\n if (!target || typeof target !== \"object\") {\n return { ok: false, error: \"target must be an object\" };\n }\n\n const allowedCategories = new Set(options?.allowedCategories ?? DEFAULT_CATEGORIES);\n const allowedNamespaces = options?.allowedNamespaces\n ? new Set(options.allowedNamespaces.map((v) => v.trim()).filter((v) => v.length > 0))\n : null;\n\n const normalized: RouteTarget = {};\n\n if (typeof target.category === \"string\") {\n if (!allowedCategories.has(target.category)) {\n return { ok: false, error: `invalid category: ${target.category}` };\n }\n normalized.category = target.category;\n }\n\n if (typeof target.namespace === \"string\") {\n const namespace = normalizeNamespace(target.namespace);\n if (!isSafeRouteNamespace(namespace)) {\n return { ok: false, error: `invalid namespace: ${target.namespace}` };\n }\n if (allowedNamespaces && !allowedNamespaces.has(namespace)) {\n return { ok: false, error: `namespace not allowed: ${namespace}` };\n }\n normalized.namespace = namespace;\n }\n\n if (!normalized.category && !normalized.namespace) {\n return { ok: false, error: \"target must include category or namespace\" };\n }\n\n return { ok: true, target: normalized };\n}\n\nexport function doesRuleMatch(rule: RouteRule, text: string): boolean {\n if (!rule || typeof rule !== \"object\") return false;\n if (rule.enabled === false) return false;\n if (typeof rule.pattern !== \"string\") return false;\n const pattern = rule.pattern.trim();\n if (pattern.length === 0) return false;\n\n if (rule.patternType === \"keyword\") {\n return text.toLowerCase().includes(pattern.toLowerCase());\n }\n if (rule.patternType !== \"regex\") {\n return false;\n }\n\n if (isLikelyUnsafeRegex(pattern)) {\n return false;\n }\n\n try {\n return new RegExp(pattern, \"i\").test(text);\n } catch {\n return false;\n }\n}\n\nexport function selectRouteRule(text: string, rules: RouteRule[], options?: RoutingEngineOptions): RouteSelection | null {\n const ranked = rules\n .map((rule, index) => ({ rule, index }))\n .sort((a, b) => {\n if (b.rule.priority !== a.rule.priority) return b.rule.priority - a.rule.priority;\n return a.index - b.index;\n });\n\n for (const entry of ranked) {\n if (!doesRuleMatch(entry.rule, text)) continue;\n\n const validation = validateRouteTarget(entry.rule.target, options);\n if (!validation.ok || !validation.target) continue;\n\n return {\n rule: entry.rule,\n target: validation.target,\n };\n }\n\n return null;\n}\n"],"mappings":";AA4BA,IAAM,qBAAgD;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,SAAS,mBAAmB,WAA2B;AACrD,SAAO,UAAU,KAAK;AACxB;AAEO,SAAS,oBAAoB,SAA0B;AAC5D,QAAM,QAAQ,QAAQ,KAAK;AAC3B,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,MAAI,MAAM,SAAS,IAAK,QAAO;AAC/B,MAAI,UAAU,KAAK,KAAK,EAAG,QAAO;AAClC,MAAI,aAAa,KAAK,KAAK,EAAG,QAAO;AACrC,MAAI,gDAAgD,KAAK,KAAK,EAAG,QAAO;AAExE,MAAI,iBAAiB,KAAK,KAAK,EAAG,QAAO;AAEzC,QAAM,mBACH,MAAM,MAAM,iBAAiB,GAAG,UAAU,MAC1C,MAAM,MAAM,cAAc,GAAG,UAAU;AAC1C,MAAI,kBAAkB,EAAG,QAAO;AAChC,SAAO;AACT;AAEO,SAAS,qBAAqB,WAA4B;AAC/D,QAAM,QAAQ,mBAAmB,SAAS;AAC1C,MAAI,MAAM,WAAW,EAAG,QAAO;AAC/B,MAAI,UAAU,IAAK,QAAO;AAC1B,MAAI,MAAM,SAAS,GAAG,KAAK,MAAM,SAAS,IAAI,EAAG,QAAO;AACxD,MAAI,MAAM,SAAS,IAAI,EAAG,QAAO;AACjC,SAAO,yBAAyB,KAAK,KAAK;AAC5C;AAEO,SAAS,oBAAoB,QAAwC,SAI1E;AACA,MAAI,CAA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AAW,EAAG,QAAO;AAEjC,MAAI,KAAK,gBAAgB,WAAW;AAClC,WAAO,KAAK,YAAY,EAAE,SAAS,QAAQ,YAAY,CAAC;AAAA,EAC1D;AACA,MAAI,KAAK,gBAAgB,SAAS;AAChC,WAAO;AAAA,EACT;AAEA,MAAI,oBAAoB,OAAO,GAAG;AAChC,WAAO;AAAA,EACT;AAEA,MAAI;AACF,WAAO,IAAI,OAAO,SAAS,GAAG,EAAE,KAAK,IAAI;AAAA,EAC3C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,SAAS,gBAAgB,MAAc,OAAoB,SAAuD;AACvH,QAAM,SAAS,MACZ,IAAI,CAAC,MAAM,WAAW,EAAE,MAAM,MAAM,EAAE,EACtC,KAAK,CAAC,GAAG,MAAM;AACd,QAAI,EAAE,KAAK,aAAa,EAAE,KAAK,SAAU,QAAO,EAAE,KAAK,WAAW,EAAE,KAAK;AACzE,WAAO,EAAE,QAAQ,EAAE;AAAA,EACrB,CAAC;AAEH,aAAW,SAAS,QAAQ;AAC1B,QAAI,CAAC,cAAc,MAAM,MAAM,IAAI,EAAG;AAEtC,UAAM,aAAa,oBAAoB,MAAM,KAAK,QAAQ,OAAO;AACjE,QAAI,CAAC,WAAW,MAAM,CAAC,WAAW,OAAQ;AAE1C,WAAO;AAAA,MACL,MAAM,MAAM;AAAA,MACZ,QAAQ,WAAW;AAAA,IACrB;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
clamp01,
|
|
3
3
|
computeLifecycleValueInputs,
|
|
4
4
|
daysSince
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-TBBDFYXW.js";
|
|
6
6
|
|
|
7
7
|
// src/tier-routing.ts
|
|
8
8
|
function computeTierValueScore(memory, now, signals) {
|
|
@@ -65,4 +65,4 @@ export {
|
|
|
65
65
|
computeTierValueScore,
|
|
66
66
|
decideTierTransition
|
|
67
67
|
};
|
|
68
|
-
//# sourceMappingURL=chunk-
|
|
68
|
+
//# sourceMappingURL=chunk-S75M5ZRK.js.map
|