@remnic/core 1.0.3 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/abort-error.d.ts +32 -0
- package/dist/abort-error.js +11 -0
- package/dist/access-audit.d.ts +56 -0
- package/dist/access-audit.js +9 -0
- package/dist/access-audit.js.map +1 -0
- package/dist/access-cli.js +72 -54
- package/dist/access-cli.js.map +1 -1
- package/dist/access-http.d.ts +16 -8
- package/dist/access-http.js +25 -17
- package/dist/access-mcp.d.ts +16 -8
- package/dist/access-mcp.js +28 -6
- package/dist/access-schema.d.ts +130 -39
- package/dist/access-schema.js +5 -1
- package/dist/access-service-Br8ZydTK.d.ts +827 -0
- package/dist/access-service.d.ts +20 -660
- package/dist/access-service.js +22 -14
- package/dist/bootstrap.d.ts +6 -3
- package/dist/briefing.d.ts +1 -0
- package/dist/briefing.js +6 -5
- package/dist/buffer-surprise-report.d.ts +70 -0
- package/dist/buffer-surprise-report.js +7 -0
- package/dist/buffer-surprise-report.js.map +1 -0
- package/dist/buffer-surprise.d.ts +98 -0
- package/dist/buffer-surprise.js +11 -0
- package/dist/buffer-surprise.js.map +1 -0
- package/dist/buffer.d.ts +100 -2
- package/dist/buffer.js +1 -1
- package/dist/calibration.js +5 -5
- package/dist/causal-behavior.js +4 -4
- package/dist/causal-chain.js +2 -2
- package/dist/causal-consolidation.js +17 -16
- package/dist/causal-consolidation.js.map +1 -1
- package/dist/causal-retrieval.js +4 -4
- package/dist/causal-trajectory.js +1 -1
- package/dist/{chunk-QNJMBKFK.js → chunk-2LGMW3DJ.js} +3 -2
- package/dist/chunk-2LGMW3DJ.js.map +1 -0
- package/dist/{chunk-QDYXG4CS.js → chunk-3FPTCC3Z.js} +4 -3
- package/dist/chunk-3FPTCC3Z.js.map +1 -0
- package/dist/chunk-3GPTTA4J.js +57 -0
- package/dist/chunk-3GPTTA4J.js.map +1 -0
- package/dist/{chunk-QKAH5B6E.js → chunk-3GXCSUXR.js} +94 -6
- package/dist/chunk-3GXCSUXR.js.map +1 -0
- package/dist/{chunk-POBPGDWI.js → chunk-3OGMS3PE.js} +2 -2
- package/dist/chunk-54V4BZWP.js +139 -0
- package/dist/chunk-54V4BZWP.js.map +1 -0
- package/dist/chunk-5JRF2PZA.js +67 -0
- package/dist/chunk-5JRF2PZA.js.map +1 -0
- package/dist/chunk-64NJRYU2.js +332 -0
- package/dist/chunk-64NJRYU2.js.map +1 -0
- package/dist/chunk-6AUUAZEX.js +150 -0
- package/dist/chunk-6AUUAZEX.js.map +1 -0
- package/dist/{chunk-HITJFT7E.js → chunk-7I7FKFZH.js} +28 -21
- package/dist/chunk-7I7FKFZH.js.map +1 -0
- package/dist/chunk-AJU4PJGY.js +126 -0
- package/dist/chunk-AJU4PJGY.js.map +1 -0
- package/dist/chunk-ASAITVLA.js +64 -0
- package/dist/chunk-ASAITVLA.js.map +1 -0
- package/dist/{chunk-X4WESCKA.js → chunk-B5WXLVDY.js} +187 -6
- package/dist/chunk-B5WXLVDY.js.map +1 -0
- package/dist/{chunk-RCICHSHL.js → chunk-BGJGXLZ7.js} +111 -2
- package/dist/{chunk-RCICHSHL.js.map → chunk-BGJGXLZ7.js.map} +1 -1
- package/dist/{chunk-OJFGVJS6.js → chunk-BK2EFTE2.js} +319 -18
- package/dist/chunk-BK2EFTE2.js.map +1 -0
- package/dist/chunk-C4SQJZAF.js +486 -0
- package/dist/chunk-C4SQJZAF.js.map +1 -0
- package/dist/{chunk-GJQPH5G3.js → chunk-CUPFXL3J.js} +2 -2
- package/dist/chunk-DF3RVK3X.js +119 -0
- package/dist/chunk-DF3RVK3X.js.map +1 -0
- package/dist/{chunk-PMB3WGDL.js → chunk-DFTTJYSO.js} +167 -7
- package/dist/chunk-DFTTJYSO.js.map +1 -0
- package/dist/chunk-DGVM5SFL.js +69 -0
- package/dist/chunk-DGVM5SFL.js.map +1 -0
- package/dist/chunk-EIR5VLIH.js +90 -0
- package/dist/chunk-EIR5VLIH.js.map +1 -0
- package/dist/{chunk-PAORGQRI.js → chunk-EPQJM2GC.js} +37 -23
- package/dist/chunk-EPQJM2GC.js.map +1 -0
- package/dist/{chunk-POMSFKTB.js → chunk-F5VP6YCB.js} +368 -10
- package/dist/chunk-F5VP6YCB.js.map +1 -0
- package/dist/{chunk-6ZH4TU6I.js → chunk-FAAFWE4G.js} +2 -1
- package/dist/chunk-FAAFWE4G.js.map +1 -0
- package/dist/{chunk-74JR4N5J.js → chunk-FVA6TGI3.js} +2 -2
- package/dist/chunk-GDFS42HT.js +206 -0
- package/dist/chunk-GDFS42HT.js.map +1 -0
- package/dist/{chunk-BKQJBXXX.js → chunk-GGD5W7TB.js} +2 -2
- package/dist/chunk-GGD5W7TB.js.map +1 -0
- package/dist/{chunk-V7XCAHIB.js → chunk-GKFXUTJ2.js} +508 -26
- package/dist/chunk-GKFXUTJ2.js.map +1 -0
- package/dist/{chunk-NSB3WSYS.js → chunk-HK3FGIEW.js} +278 -3
- package/dist/chunk-HK3FGIEW.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-IISBCCWR.js +52 -0
- package/dist/chunk-IISBCCWR.js.map +1 -0
- package/dist/{chunk-YFYL2SIJ.js → chunk-INXV5JBT.js} +290 -46
- package/dist/chunk-INXV5JBT.js.map +1 -0
- package/dist/chunk-JBMSGZEQ.js +441 -0
- package/dist/chunk-JBMSGZEQ.js.map +1 -0
- package/dist/{chunk-UPMD5XND.js → chunk-JL2PU6AI.js} +16 -5
- package/dist/chunk-JL2PU6AI.js.map +1 -0
- package/dist/{chunk-J4IYOZZ5.js → chunk-JXS5PDQ7.js} +3 -1
- package/dist/chunk-JXS5PDQ7.js.map +1 -0
- package/dist/{chunk-AYPYCLR7.js → chunk-KUB6JU6H.js} +4 -4
- package/dist/chunk-KVBLZUKV.js +173 -0
- package/dist/chunk-KVBLZUKV.js.map +1 -0
- package/dist/chunk-LBLXEFWK.js +51 -0
- package/dist/chunk-LBLXEFWK.js.map +1 -0
- package/dist/{chunk-U2IQTSBY.js → chunk-LTCGGW2D.js} +1 -1
- package/dist/chunk-LTCGGW2D.js.map +1 -0
- package/dist/{chunk-UEYA6UC7.js → chunk-NZLQTHS5.js} +25 -2
- package/dist/chunk-NZLQTHS5.js.map +1 -0
- package/dist/chunk-PVGDJXVK.js +21 -0
- package/dist/chunk-PVGDJXVK.js.map +1 -0
- package/dist/chunk-PVPWZSSI.js +37 -0
- package/dist/chunk-PVPWZSSI.js.map +1 -0
- package/dist/{chunk-4NRAJUDS.js → chunk-RBBWYEFJ.js} +1 -1
- package/dist/chunk-RFYAYKTD.js +146 -0
- package/dist/chunk-RFYAYKTD.js.map +1 -0
- package/dist/{chunk-JROGC36Y.js → chunk-RGLL5SPU.js} +2 -2
- package/dist/{chunk-2VFW5K5U.js → chunk-S3EEFKNY.js} +103 -65
- package/dist/chunk-S3EEFKNY.js.map +1 -0
- package/dist/chunk-SOBJ6NEY.js +18 -0
- package/dist/chunk-SOBJ6NEY.js.map +1 -0
- package/dist/{chunk-MYQWXITD.js → chunk-SPI27QT6.js} +2 -2
- package/dist/chunk-TVVEYCNW.js +65 -0
- package/dist/chunk-TVVEYCNW.js.map +1 -0
- package/dist/chunk-ULYOGL6R.js +322 -0
- package/dist/chunk-ULYOGL6R.js.map +1 -0
- package/dist/{chunk-S4LX5EBI.js → chunk-VBVG2M5G.js} +64 -10
- package/dist/chunk-VBVG2M5G.js.map +1 -0
- package/dist/{chunk-KWP7T3DP.js → chunk-VDX363PS.js} +2 -2
- package/dist/{chunk-XMGSSBFX.js → chunk-VYM3VWOF.js} +1560 -244
- package/dist/chunk-VYM3VWOF.js.map +1 -0
- package/dist/{chunk-MTLYEMJB.js → chunk-WCLICCGB.js} +18 -3
- package/dist/chunk-WCLICCGB.js.map +1 -0
- package/dist/{chunk-ECKDIK5F.js → chunk-WVVA7F5A.js} +2 -2
- package/dist/chunk-X6GF3FX2.js +26 -0
- package/dist/chunk-X6GF3FX2.js.map +1 -0
- package/dist/{chunk-3QFQGRHO.js → chunk-XMHBH5H6.js} +4 -4
- package/dist/{chunk-KEG4GNGI.js → chunk-XZ2TIKGC.js} +38 -8
- 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-YNB73F22.js +137 -0
- package/dist/chunk-YNB73F22.js.map +1 -0
- package/dist/{chunk-7PA4OZEU.js → chunk-YNQKWQT4.js} +55 -30
- package/dist/chunk-YNQKWQT4.js.map +1 -0
- package/dist/chunk-ZAIM4TUE.js +488 -0
- package/dist/chunk-ZAIM4TUE.js.map +1 -0
- package/dist/{chunk-BTY5RRRF.js → chunk-ZEM3OK2K.js} +5 -5
- package/dist/chunk-ZZTOURJI.js +91 -0
- package/dist/chunk-ZZTOURJI.js.map +1 -0
- package/dist/{cli-DwIBnp2g.d.ts → cli-BkeRaYfk.d.ts} +2 -2
- package/dist/cli.d.ts +13 -5
- package/dist/cli.js +45 -33
- package/dist/config.js +1 -1
- package/dist/consolidation-operator.d.ts +41 -0
- package/dist/consolidation-operator.js +11 -0
- package/dist/consolidation-operator.js.map +1 -0
- package/dist/consolidation-provenance-check.d.ts +68 -0
- package/dist/consolidation-provenance-check.js +9 -0
- package/dist/consolidation-provenance-check.js.map +1 -0
- package/dist/consolidation-undo.d.ts +123 -0
- package/dist/consolidation-undo.js +426 -0
- package/dist/consolidation-undo.js.map +1 -0
- package/dist/contradiction-review-WIUBAR52.js +21 -0
- package/dist/contradiction-review-WIUBAR52.js.map +1 -0
- package/dist/contradiction-scan-E3GJTI4F.js +412 -0
- package/dist/contradiction-scan-E3GJTI4F.js.map +1 -0
- package/dist/cross-namespace-budget.d.ts +133 -0
- package/dist/cross-namespace-budget.js +9 -0
- package/dist/cross-namespace-budget.js.map +1 -0
- package/dist/direct-answer-wiring.d.ts +77 -0
- package/dist/direct-answer-wiring.js +10 -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/{engine-X7X3AAG3.js → engine-F3GOXGE5.js} +7 -6
- package/dist/engine-F3GOXGE5.js.map +1 -0
- package/dist/entity-retrieval.d.ts +1 -0
- package/dist/entity-retrieval.js +6 -5
- package/dist/explicit-capture.d.ts +6 -3
- package/dist/explicit-capture.js +2 -2
- package/dist/extraction-judge-telemetry.d.ts +113 -0
- package/dist/extraction-judge-telemetry.js +14 -0
- package/dist/extraction-judge-telemetry.js.map +1 -0
- package/dist/extraction-judge-training.d.ts +85 -0
- package/dist/extraction-judge-training.js +16 -0
- package/dist/extraction-judge-training.js.map +1 -0
- package/dist/extraction-judge.d.ts +124 -2
- package/dist/extraction-judge.js +11 -1
- package/dist/extraction.js +7 -6
- package/dist/fallback-llm.d.ts +11 -2
- package/dist/fallback-llm.js +2 -2
- package/dist/graph-recall.d.ts +100 -0
- package/dist/graph-recall.js +8 -0
- package/dist/graph-recall.js.map +1 -0
- package/dist/graph-retrieval.d.ts +271 -0
- package/dist/graph-retrieval.js +21 -0
- package/dist/graph-retrieval.js.map +1 -0
- package/dist/harmonic-retrieval.js +2 -1
- package/dist/importance.js +1 -1
- package/dist/index.d.ts +589 -138
- package/dist/index.js +531 -403
- package/dist/index.js.map +1 -1
- package/dist/intent.js +1 -1
- package/dist/local-llm.d.ts +10 -3
- package/dist/local-llm.js +1 -1
- package/dist/memory-worth-bench.d.ts +51 -0
- package/dist/memory-worth-bench.js +131 -0
- package/dist/memory-worth-bench.js.map +1 -0
- package/dist/memory-worth-filter.d.ts +128 -0
- package/dist/memory-worth-filter.js +10 -0
- package/dist/memory-worth-filter.js.map +1 -0
- package/dist/memory-worth-outcomes.d.ts +118 -0
- package/dist/memory-worth-outcomes.js +9 -0
- package/dist/memory-worth-outcomes.js.map +1 -0
- package/dist/memory-worth.d.ts +102 -0
- package/dist/memory-worth.js +7 -0
- package/dist/memory-worth.js.map +1 -0
- package/dist/operator-toolkit.d.ts +40 -1
- package/dist/operator-toolkit.js +24 -14
- package/dist/{orchestrator-B9kwlCep.d.ts → orchestrator-CmJ-NTdJ.d.ts} +254 -10
- package/dist/orchestrator.d.ts +6 -3
- package/dist/orchestrator.js +59 -48
- package/dist/page-versioning.d.ts +12 -1
- package/dist/page-versioning.js +5 -3
- package/dist/{port-C1GZFv8h.d.ts → port-BADbLZU5.d.ts} +2 -2
- package/dist/qmd-recall-cache.d.ts +1 -1
- package/dist/qmd.d.ts +5 -3
- package/dist/qmd.js +2 -1
- package/dist/reasoning-trace-recall.d.ts +90 -0
- package/dist/reasoning-trace-recall.js +13 -0
- package/dist/reasoning-trace-recall.js.map +1 -0
- package/dist/reasoning-trace-types.d.ts +54 -0
- package/dist/reasoning-trace-types.js +17 -0
- package/dist/reasoning-trace-types.js.map +1 -0
- package/dist/recall-audit-anomaly.d.ts +112 -0
- package/dist/recall-audit-anomaly.js +11 -0
- package/dist/recall-audit-anomaly.js.map +1 -0
- package/dist/recall-audit.js +5 -44
- package/dist/recall-audit.js.map +1 -1
- package/dist/recall-explain-renderer.d.ts +49 -0
- package/dist/recall-explain-renderer.js +18 -0
- package/dist/recall-explain-renderer.js.map +1 -0
- package/dist/recall-state.d.ts +39 -1
- package/dist/recall-state.js +1 -1
- package/dist/recall-xray-cli.d.ts +40 -0
- package/dist/recall-xray-cli.js +11 -0
- package/dist/recall-xray-cli.js.map +1 -0
- package/dist/recall-xray-renderer.d.ts +44 -0
- package/dist/recall-xray-renderer.js +18 -0
- package/dist/recall-xray-renderer.js.map +1 -0
- package/dist/recall-xray.d.ts +179 -0
- package/dist/recall-xray.js +13 -0
- package/dist/recall-xray.js.map +1 -0
- 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 +3 -1
- package/dist/resume-bundles.js +6 -6
- package/dist/retrieval-agents.d.ts +1 -1
- package/dist/retrieval-tiers.d.ts +17 -0
- package/dist/retrieval-tiers.js +9 -0
- package/dist/retrieval-tiers.js.map +1 -0
- package/dist/schemas.d.ts +301 -45
- package/dist/schemas.js +1 -1
- package/dist/{semantic-consolidation-DrvSYRdB.d.ts → semantic-consolidation-CxJU6MJk.d.ts} +62 -1
- package/dist/semantic-consolidation.d.ts +2 -1
- package/dist/semantic-consolidation.js +20 -6
- package/dist/semantic-rule-promotion.js +6 -5
- package/dist/semantic-rule-verifier.js +6 -5
- package/dist/storage.d.ts +82 -1
- package/dist/storage.js +5 -4
- package/dist/summarizer.js +4 -4
- package/dist/temporal-supersession.d.ts +1 -0
- package/dist/tier-migration.d.ts +2 -1
- package/dist/types-DJhqDJUV.d.ts +50 -0
- package/dist/types.d.ts +309 -3
- package/dist/types.js +1 -1
- package/dist/verified-recall.js +6 -5
- package/package.json +1 -1
- package/dist/chunk-2VFW5K5U.js.map +0 -1
- package/dist/chunk-6ZH4TU6I.js.map +0 -1
- package/dist/chunk-7PA4OZEU.js.map +0 -1
- package/dist/chunk-AAI7JARD.js.map +0 -1
- package/dist/chunk-BKQJBXXX.js.map +0 -1
- package/dist/chunk-HITJFT7E.js.map +0 -1
- package/dist/chunk-J4IYOZZ5.js.map +0 -1
- package/dist/chunk-KEG4GNGI.js.map +0 -1
- package/dist/chunk-LAYN4LDC.js +0 -267
- package/dist/chunk-LAYN4LDC.js.map +0 -1
- package/dist/chunk-MTLYEMJB.js.map +0 -1
- package/dist/chunk-NSB3WSYS.js.map +0 -1
- package/dist/chunk-OJFGVJS6.js.map +0 -1
- package/dist/chunk-PAORGQRI.js.map +0 -1
- package/dist/chunk-PMB3WGDL.js.map +0 -1
- package/dist/chunk-POMSFKTB.js.map +0 -1
- package/dist/chunk-QDYXG4CS.js.map +0 -1
- package/dist/chunk-QKAH5B6E.js.map +0 -1
- package/dist/chunk-QNJMBKFK.js.map +0 -1
- package/dist/chunk-S4LX5EBI.js.map +0 -1
- package/dist/chunk-U2IQTSBY.js.map +0 -1
- package/dist/chunk-UEYA6UC7.js.map +0 -1
- package/dist/chunk-UPMD5XND.js.map +0 -1
- package/dist/chunk-UVJFDP7P.js +0 -202
- package/dist/chunk-UVJFDP7P.js.map +0 -1
- package/dist/chunk-V7XCAHIB.js.map +0 -1
- package/dist/chunk-X4WESCKA.js.map +0 -1
- package/dist/chunk-XMGSSBFX.js.map +0 -1
- package/dist/chunk-YFYL2SIJ.js.map +0 -1
- /package/dist/{engine-X7X3AAG3.js.map → abort-error.js.map} +0 -0
- /package/dist/{chunk-POBPGDWI.js.map → chunk-3OGMS3PE.js.map} +0 -0
- /package/dist/{chunk-GJQPH5G3.js.map → chunk-CUPFXL3J.js.map} +0 -0
- /package/dist/{chunk-74JR4N5J.js.map → chunk-FVA6TGI3.js.map} +0 -0
- /package/dist/{chunk-AYPYCLR7.js.map → chunk-KUB6JU6H.js.map} +0 -0
- /package/dist/{chunk-4NRAJUDS.js.map → chunk-RBBWYEFJ.js.map} +0 -0
- /package/dist/{chunk-JROGC36Y.js.map → chunk-RGLL5SPU.js.map} +0 -0
- /package/dist/{chunk-MYQWXITD.js.map → chunk-SPI27QT6.js.map} +0 -0
- /package/dist/{chunk-KWP7T3DP.js.map → chunk-VDX363PS.js.map} +0 -0
- /package/dist/{chunk-ECKDIK5F.js.map → chunk-WVVA7F5A.js.map} +0 -0
- /package/dist/{chunk-3QFQGRHO.js.map → chunk-XMHBH5H6.js.map} +0 -0
- /package/dist/{chunk-BTY5RRRF.js.map → chunk-ZEM3OK2K.js.map} +0 -0
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SPECULATIVE_TTL_DAYS,
|
|
3
3
|
confidenceTier
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LTCGGW2D.js";
|
|
5
5
|
import {
|
|
6
6
|
DEFAULT_CITATION_FORMAT,
|
|
7
7
|
hasCitation,
|
|
8
8
|
stripCitationForTemplate
|
|
9
9
|
} from "./chunk-4KAN3GZ3.js";
|
|
10
|
-
import {
|
|
11
|
-
createVersion
|
|
12
|
-
} from "./chunk-6ZH4TU6I.js";
|
|
13
10
|
import {
|
|
14
11
|
getCachedEntities,
|
|
15
12
|
setCachedEntities
|
|
@@ -30,6 +27,9 @@ import {
|
|
|
30
27
|
readProjectedMemoryState,
|
|
31
28
|
readProjectedMemoryTimeline
|
|
32
29
|
} from "./chunk-BOUYNNYD.js";
|
|
30
|
+
import {
|
|
31
|
+
rotateMarkdownFileToArchive
|
|
32
|
+
} from "./chunk-DM2T26WE.js";
|
|
33
33
|
import {
|
|
34
34
|
closeContinuityIncidentRecord,
|
|
35
35
|
createContinuityIncidentRecord,
|
|
@@ -39,9 +39,6 @@ import {
|
|
|
39
39
|
serializeContinuityIncident,
|
|
40
40
|
upsertContinuityLoopInMarkdown
|
|
41
41
|
} from "./chunk-QSVPYQPG.js";
|
|
42
|
-
import {
|
|
43
|
-
rotateMarkdownFileToArchive
|
|
44
|
-
} from "./chunk-DM2T26WE.js";
|
|
45
42
|
import {
|
|
46
43
|
sanitizeMemoryContent
|
|
47
44
|
} from "./chunk-M62O4P4T.js";
|
|
@@ -50,6 +47,13 @@ import {
|
|
|
50
47
|
normalizeEntityStructuredSection,
|
|
51
48
|
sortStructuredSectionsBySchema
|
|
52
49
|
} from "./chunk-4DJQYKMN.js";
|
|
50
|
+
import {
|
|
51
|
+
isConsolidationOperator,
|
|
52
|
+
isValidDerivedFromEntry
|
|
53
|
+
} from "./chunk-X6GF3FX2.js";
|
|
54
|
+
import {
|
|
55
|
+
createVersion
|
|
56
|
+
} from "./chunk-FAAFWE4G.js";
|
|
53
57
|
import {
|
|
54
58
|
log
|
|
55
59
|
} from "./chunk-2ODBA7MQ.js";
|
|
@@ -91,6 +95,17 @@ var ARTIFACT_SEARCH_STOPWORDS = /* @__PURE__ */ new Set([
|
|
|
91
95
|
function tokenizeArtifactSearchText(input) {
|
|
92
96
|
return input.toLowerCase().split(/[^a-z0-9]+/i).map((t) => t.trim()).filter((t) => t.length >= 2).filter((t) => !ARTIFACT_SEARCH_STOPWORDS.has(t));
|
|
93
97
|
}
|
|
98
|
+
function assertMemoryWorthCounter(field, value) {
|
|
99
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
100
|
+
throw new Error(`${field} must be a finite number, got ${String(value)}`);
|
|
101
|
+
}
|
|
102
|
+
if (!Number.isInteger(value)) {
|
|
103
|
+
throw new Error(`${field} must be an integer, got ${value}`);
|
|
104
|
+
}
|
|
105
|
+
if (value < 0) {
|
|
106
|
+
throw new Error(`${field} must be >= 0, got ${value}`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
94
109
|
function serializeFrontmatter(fm) {
|
|
95
110
|
const lines = [
|
|
96
111
|
"---",
|
|
@@ -123,6 +138,14 @@ function serializeFrontmatter(fm) {
|
|
|
123
138
|
lines.push(`accessCount: ${fm.accessCount}`);
|
|
124
139
|
}
|
|
125
140
|
if (fm.lastAccessed) lines.push(`lastAccessed: ${fm.lastAccessed}`);
|
|
141
|
+
if (fm.mw_success !== void 0) {
|
|
142
|
+
assertMemoryWorthCounter("mw_success", fm.mw_success);
|
|
143
|
+
lines.push(`mw_success: ${fm.mw_success}`);
|
|
144
|
+
}
|
|
145
|
+
if (fm.mw_fail !== void 0) {
|
|
146
|
+
assertMemoryWorthCounter("mw_fail", fm.mw_fail);
|
|
147
|
+
lines.push(`mw_fail: ${fm.mw_fail}`);
|
|
148
|
+
}
|
|
126
149
|
if (fm.importance) {
|
|
127
150
|
lines.push(`importanceScore: ${fm.importance.score}`);
|
|
128
151
|
lines.push(`importanceLevel: ${fm.importance.level}`);
|
|
@@ -160,6 +183,33 @@ function serializeFrontmatter(fm) {
|
|
|
160
183
|
lines.push(`structuredAttributes: ${JSON.stringify(fm.structuredAttributes)}`);
|
|
161
184
|
}
|
|
162
185
|
if (fm.contentHash) lines.push(`contentHash: ${fm.contentHash}`);
|
|
186
|
+
if (fm.derived_from !== void 0) {
|
|
187
|
+
if (!Array.isArray(fm.derived_from)) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`serializeFrontmatter: derived_from must be an array of "<path>:<version>" strings`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
for (const entry of fm.derived_from) {
|
|
193
|
+
if (!isValidDerivedFromEntry(entry)) {
|
|
194
|
+
throw new Error(
|
|
195
|
+
`serializeFrontmatter: invalid derived_from entry ${JSON.stringify(entry)} \u2014 expected "<path>:<version>" with version >= 0`
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
if (fm.derived_from.length > 0) {
|
|
200
|
+
lines.push(
|
|
201
|
+
`derived_from: [${fm.derived_from.map((e) => `"${e.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`).join(", ")}]`
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (fm.derived_via !== void 0) {
|
|
206
|
+
if (!isConsolidationOperator(fm.derived_via)) {
|
|
207
|
+
throw new Error(
|
|
208
|
+
`serializeFrontmatter: invalid derived_via ${JSON.stringify(fm.derived_via)} \u2014 expected one of "split" | "merge" | "update"`
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
lines.push(`derived_via: ${fm.derived_via}`);
|
|
212
|
+
}
|
|
163
213
|
lines.push("---");
|
|
164
214
|
return lines.join("\n");
|
|
165
215
|
}
|
|
@@ -192,13 +242,54 @@ function parseLinkReasonValue(rawValue) {
|
|
|
192
242
|
return legacyValue;
|
|
193
243
|
}
|
|
194
244
|
}
|
|
245
|
+
function parseMemoryWorthCounterField(raw) {
|
|
246
|
+
if (raw === void 0) return void 0;
|
|
247
|
+
const trimmed = raw.trim();
|
|
248
|
+
if (trimmed.length === 0) return void 0;
|
|
249
|
+
const n = Number(trimmed);
|
|
250
|
+
if (!Number.isFinite(n) || !Number.isInteger(n) || n < 0) return void 0;
|
|
251
|
+
return n;
|
|
252
|
+
}
|
|
195
253
|
function parseFrontmatter(raw) {
|
|
196
254
|
const match = raw.match(/^---\n([\s\S]*?)\n---\n?([\s\S]*)$/);
|
|
197
255
|
if (!match) return null;
|
|
198
256
|
const fmBlock = match[1];
|
|
199
257
|
const content = match[2].trim();
|
|
200
258
|
const fm = {};
|
|
201
|
-
|
|
259
|
+
const rawLines = fmBlock.split("\n");
|
|
260
|
+
const lines = [];
|
|
261
|
+
let i = 0;
|
|
262
|
+
while (i < rawLines.length) {
|
|
263
|
+
const line = rawLines[i];
|
|
264
|
+
const colonIdx = line.indexOf(":");
|
|
265
|
+
if (colonIdx !== -1 && line.slice(colonIdx + 1).trim() === "") {
|
|
266
|
+
const baseIndent = line.match(/^\s*/)[0].length;
|
|
267
|
+
const items = [];
|
|
268
|
+
let j = i + 1;
|
|
269
|
+
while (j < rawLines.length) {
|
|
270
|
+
const next = rawLines[j];
|
|
271
|
+
const m = next.match(/^(\s+)- (.*)$/);
|
|
272
|
+
if (!m || m[1].length <= baseIndent) break;
|
|
273
|
+
let item = m[2].trim();
|
|
274
|
+
if (item.startsWith('"') && item.endsWith('"') && item.length >= 2) {
|
|
275
|
+
item = item.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, "\\");
|
|
276
|
+
} else if (item.startsWith("'") && item.endsWith("'") && item.length >= 2) {
|
|
277
|
+
item = item.slice(1, -1).replace(/''/g, "'");
|
|
278
|
+
}
|
|
279
|
+
items.push(item);
|
|
280
|
+
j++;
|
|
281
|
+
}
|
|
282
|
+
if (items.length > 0) {
|
|
283
|
+
const inline = items.map((v) => `"${v.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`).join(", ");
|
|
284
|
+
lines.push(`${line.slice(0, colonIdx + 1)} [${inline}]`);
|
|
285
|
+
i = j;
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
lines.push(line);
|
|
290
|
+
i++;
|
|
291
|
+
}
|
|
292
|
+
for (const line of lines) {
|
|
202
293
|
const colonIdx = line.indexOf(":");
|
|
203
294
|
if (colonIdx === -1) continue;
|
|
204
295
|
const key = line.slice(0, colonIdx).trim();
|
|
@@ -224,9 +315,84 @@ function parseFrontmatter(raw) {
|
|
|
224
315
|
if (lineageMatch) {
|
|
225
316
|
lineage = lineageMatch[1].split(",").map((l) => l.trim().replace(/^"|"$/g, "")).filter(Boolean);
|
|
226
317
|
}
|
|
318
|
+
let derived_from;
|
|
319
|
+
const derivedFromStr = (fm.derived_from ?? "").trim();
|
|
320
|
+
if (derivedFromStr.startsWith("[") && derivedFromStr.endsWith("]")) {
|
|
321
|
+
const inner = derivedFromStr.slice(1, -1);
|
|
322
|
+
const entries = [];
|
|
323
|
+
let i2 = 0;
|
|
324
|
+
while (i2 < inner.length) {
|
|
325
|
+
const ch = inner[i2];
|
|
326
|
+
if (ch === '"') {
|
|
327
|
+
let buf = "";
|
|
328
|
+
i2++;
|
|
329
|
+
while (i2 < inner.length) {
|
|
330
|
+
const c = inner[i2];
|
|
331
|
+
if (c === "\\" && i2 + 1 < inner.length) {
|
|
332
|
+
const next = inner[i2 + 1];
|
|
333
|
+
if (next === '"') {
|
|
334
|
+
buf += '"';
|
|
335
|
+
i2 += 2;
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
if (next === "\\") {
|
|
339
|
+
buf += "\\";
|
|
340
|
+
i2 += 2;
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
buf += c;
|
|
344
|
+
i2++;
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (c === '"') {
|
|
348
|
+
i2++;
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
buf += c;
|
|
352
|
+
i2++;
|
|
353
|
+
}
|
|
354
|
+
if (buf.length > 0) entries.push(buf);
|
|
355
|
+
} else if (ch === "'") {
|
|
356
|
+
let buf = "";
|
|
357
|
+
i2++;
|
|
358
|
+
while (i2 < inner.length) {
|
|
359
|
+
const c = inner[i2];
|
|
360
|
+
if (c === "'") {
|
|
361
|
+
if (i2 + 1 < inner.length && inner[i2 + 1] === "'") {
|
|
362
|
+
buf += "'";
|
|
363
|
+
i2 += 2;
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
i2++;
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
buf += c;
|
|
370
|
+
i2++;
|
|
371
|
+
}
|
|
372
|
+
if (buf.length > 0) entries.push(buf);
|
|
373
|
+
} else if (ch === "," || /\s/.test(ch)) {
|
|
374
|
+
i2++;
|
|
375
|
+
} else {
|
|
376
|
+
let buf = "";
|
|
377
|
+
while (i2 < inner.length) {
|
|
378
|
+
const c = inner[i2];
|
|
379
|
+
if (c === "," || /\s/.test(c)) break;
|
|
380
|
+
buf += c;
|
|
381
|
+
i2++;
|
|
382
|
+
}
|
|
383
|
+
if (buf.length > 0) entries.push(buf);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
if (entries.length > 0) derived_from = entries;
|
|
387
|
+
}
|
|
388
|
+
const derivedViaRaw = (fm.derived_via ?? "").trim();
|
|
389
|
+
const derivedViaUnquoted = derivedViaRaw.startsWith('"') && derivedViaRaw.endsWith('"') || derivedViaRaw.startsWith("'") && derivedViaRaw.endsWith("'") ? derivedViaRaw.slice(1, -1) : derivedViaRaw;
|
|
390
|
+
const derived_via = isConsolidationOperator(derivedViaUnquoted) ? derivedViaUnquoted : void 0;
|
|
227
391
|
const accessCount = fm.accessCount ? parseInt(fm.accessCount, 10) : void 0;
|
|
228
392
|
const decayScore = fm.decayScore !== void 0 ? parseFloat(fm.decayScore) : void 0;
|
|
229
393
|
const heatScore = fm.heatScore !== void 0 ? parseFloat(fm.heatScore) : void 0;
|
|
394
|
+
const mw_success = parseMemoryWorthCounterField(fm.mw_success);
|
|
395
|
+
const mw_fail = parseMemoryWorthCounterField(fm.mw_fail);
|
|
230
396
|
let importance;
|
|
231
397
|
if (fm.importanceScore) {
|
|
232
398
|
const score = parseFloat(fm.importanceScore);
|
|
@@ -278,6 +444,9 @@ function parseFrontmatter(raw) {
|
|
|
278
444
|
// Access tracking
|
|
279
445
|
accessCount: accessCount && accessCount > 0 ? accessCount : void 0,
|
|
280
446
|
lastAccessed: fm.lastAccessed || void 0,
|
|
447
|
+
// Memory Worth counters (issue #560)
|
|
448
|
+
mw_success,
|
|
449
|
+
mw_fail,
|
|
281
450
|
// Importance scoring
|
|
282
451
|
importance,
|
|
283
452
|
// Chunking
|
|
@@ -296,7 +465,11 @@ function parseFrontmatter(raw) {
|
|
|
296
465
|
// Structured attributes (JSON on a single line)
|
|
297
466
|
structuredAttributes: parseStructuredAttributes(fm.structuredAttributes),
|
|
298
467
|
// Raw-content dedup hash (format-agnostic archive/consolidation cleanup)
|
|
299
|
-
contentHash: fm.contentHash || void 0
|
|
468
|
+
contentHash: fm.contentHash || void 0,
|
|
469
|
+
// Consolidation provenance (issue #561) — read-through only in this
|
|
470
|
+
// PR; no code produces these fields yet.
|
|
471
|
+
derived_from,
|
|
472
|
+
derived_via
|
|
300
473
|
},
|
|
301
474
|
content
|
|
302
475
|
};
|
|
@@ -1271,6 +1444,27 @@ function buildEntitySchemaCacheKey(entitySchemas) {
|
|
|
1271
1444
|
]);
|
|
1272
1445
|
return JSON.stringify(normalized);
|
|
1273
1446
|
}
|
|
1447
|
+
function isValidBufferSurpriseEvent(value) {
|
|
1448
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
1449
|
+
const v = value;
|
|
1450
|
+
if (v.event !== "BUFFER_SURPRISE") return false;
|
|
1451
|
+
if (typeof v.timestamp !== "string" || v.timestamp.length === 0) return false;
|
|
1452
|
+
if (!Number.isFinite(Date.parse(v.timestamp))) return false;
|
|
1453
|
+
if (typeof v.bufferKey !== "string" || v.bufferKey.length === 0) return false;
|
|
1454
|
+
if (v.sessionKey !== null && typeof v.sessionKey !== "string") return false;
|
|
1455
|
+
if (v.turnRole !== "user" && v.turnRole !== "assistant") return false;
|
|
1456
|
+
if (typeof v.surpriseScore !== "number" || !Number.isFinite(v.surpriseScore)) {
|
|
1457
|
+
return false;
|
|
1458
|
+
}
|
|
1459
|
+
if (v.surpriseScore < 0 || v.surpriseScore > 1) return false;
|
|
1460
|
+
if (typeof v.threshold !== "number" || !Number.isFinite(v.threshold)) return false;
|
|
1461
|
+
if (v.threshold < 0 || v.threshold > 1) return false;
|
|
1462
|
+
if (typeof v.triggeredFlush !== "boolean") return false;
|
|
1463
|
+
if (typeof v.turnCountInWindow !== "number" || !Number.isFinite(v.turnCountInWindow)) {
|
|
1464
|
+
return false;
|
|
1465
|
+
}
|
|
1466
|
+
return true;
|
|
1467
|
+
}
|
|
1274
1468
|
var StorageManager = class _StorageManager {
|
|
1275
1469
|
constructor(baseDir, entitySchemas) {
|
|
1276
1470
|
this.baseDir = baseDir;
|
|
@@ -1353,6 +1547,47 @@ var StorageManager = class _StorageManager {
|
|
|
1353
1547
|
} catch {
|
|
1354
1548
|
}
|
|
1355
1549
|
}
|
|
1550
|
+
/**
|
|
1551
|
+
* Consolidation provenance helper (issue #561 PR 2).
|
|
1552
|
+
*
|
|
1553
|
+
* Captures the current on-disk content of a source memory as a
|
|
1554
|
+
* page-version snapshot so the downstream consolidated write can record a
|
|
1555
|
+
* `derived_from` pointer that actually resolves. Returns the
|
|
1556
|
+
* `"<relative-path>:<versionId>"` entry expected by the `derived_from`
|
|
1557
|
+
* frontmatter field.
|
|
1558
|
+
*
|
|
1559
|
+
* Returns `null` when versioning is disabled (snapshots would not be
|
|
1560
|
+
* created), when the file does not exist (nothing to snapshot), or when
|
|
1561
|
+
* the snapshot write itself fails (best-effort — callers skip the entry
|
|
1562
|
+
* rather than block the consolidation).
|
|
1563
|
+
*/
|
|
1564
|
+
async snapshotForProvenance(filePath) {
|
|
1565
|
+
if (!this._versioningConfig || !this._versioningConfig.enabled) return null;
|
|
1566
|
+
let existing;
|
|
1567
|
+
try {
|
|
1568
|
+
existing = await readFile(filePath, "utf-8");
|
|
1569
|
+
} catch {
|
|
1570
|
+
return null;
|
|
1571
|
+
}
|
|
1572
|
+
try {
|
|
1573
|
+
const version = await createVersion(
|
|
1574
|
+
filePath,
|
|
1575
|
+
existing,
|
|
1576
|
+
"consolidation",
|
|
1577
|
+
this._versioningConfig,
|
|
1578
|
+
log,
|
|
1579
|
+
void 0,
|
|
1580
|
+
this.baseDir
|
|
1581
|
+
);
|
|
1582
|
+
const rel = path.relative(this.baseDir, filePath).split(path.sep).join("/");
|
|
1583
|
+
return `${rel}:${version.versionId}`;
|
|
1584
|
+
} catch (err) {
|
|
1585
|
+
log.warn(
|
|
1586
|
+
`storage.snapshotForProvenance: failed to snapshot ${filePath}: ${err instanceof Error ? err.message : String(err)}`
|
|
1587
|
+
);
|
|
1588
|
+
return null;
|
|
1589
|
+
}
|
|
1590
|
+
}
|
|
1356
1591
|
/** The root directory of this storage instance. */
|
|
1357
1592
|
get dir() {
|
|
1358
1593
|
return this.baseDir;
|
|
@@ -1410,6 +1645,9 @@ var StorageManager = class _StorageManager {
|
|
|
1410
1645
|
get proceduresDir() {
|
|
1411
1646
|
return path.join(this.baseDir, "procedures");
|
|
1412
1647
|
}
|
|
1648
|
+
get reasoningTracesDir() {
|
|
1649
|
+
return path.join(this.baseDir, "reasoning-traces");
|
|
1650
|
+
}
|
|
1413
1651
|
get entitiesDir() {
|
|
1414
1652
|
return path.join(this.baseDir, "entities");
|
|
1415
1653
|
}
|
|
@@ -1545,6 +1783,19 @@ var StorageManager = class _StorageManager {
|
|
|
1545
1783
|
get behaviorSignalsPath() {
|
|
1546
1784
|
return path.join(this.stateDir, "behavior-signals.jsonl");
|
|
1547
1785
|
}
|
|
1786
|
+
/**
|
|
1787
|
+
* Buffer surprise telemetry ledger (issue #563 PR 3).
|
|
1788
|
+
*
|
|
1789
|
+
* Append-only JSONL of per-turn `BUFFER_SURPRISE` events emitted by
|
|
1790
|
+
* `SmartBuffer` when `bufferSurpriseTriggerEnabled` is on. Each row
|
|
1791
|
+
* captures the score, the threshold in force at the time, whether the
|
|
1792
|
+
* turn caused an extract_now upgrade, and the buffer size. Kept in
|
|
1793
|
+
* `state/` alongside the other append-only ledgers so cleanup and
|
|
1794
|
+
* governance sweeps can treat it uniformly.
|
|
1795
|
+
*/
|
|
1796
|
+
get bufferSurpriseLedgerPath() {
|
|
1797
|
+
return path.join(this.stateDir, "buffer-surprise-ledger.jsonl");
|
|
1798
|
+
}
|
|
1548
1799
|
/**
|
|
1549
1800
|
* Load user-defined entity aliases from config/aliases.json in the memory store.
|
|
1550
1801
|
* File format: { "variant": "canonical", "variant2": "canonical", ... }
|
|
@@ -1567,6 +1818,7 @@ var StorageManager = class _StorageManager {
|
|
|
1567
1818
|
const today = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
|
|
1568
1819
|
await mkdir(path.join(this.factsDir, today), { recursive: true });
|
|
1569
1820
|
await mkdir(path.join(this.proceduresDir, today), { recursive: true });
|
|
1821
|
+
await mkdir(path.join(this.reasoningTracesDir, today), { recursive: true });
|
|
1570
1822
|
await mkdir(this.correctionsDir, { recursive: true });
|
|
1571
1823
|
await mkdir(this.entitiesDir, { recursive: true });
|
|
1572
1824
|
await mkdir(this.stateDir, { recursive: true });
|
|
@@ -1619,6 +1871,12 @@ var StorageManager = class _StorageManager {
|
|
|
1619
1871
|
if (options.status !== void 0) {
|
|
1620
1872
|
fm.status = options.status;
|
|
1621
1873
|
}
|
|
1874
|
+
if (options.derivedFrom !== void 0 && options.derivedFrom.length > 0) {
|
|
1875
|
+
fm.derived_from = options.derivedFrom;
|
|
1876
|
+
}
|
|
1877
|
+
if (options.derivedVia !== void 0) {
|
|
1878
|
+
fm.derived_via = options.derivedVia;
|
|
1879
|
+
}
|
|
1622
1880
|
let enrichedContent = content;
|
|
1623
1881
|
if (options.structuredAttributes && Object.keys(options.structuredAttributes).length > 0) {
|
|
1624
1882
|
enrichedContent = `${content}
|
|
@@ -1642,6 +1900,9 @@ ${sanitized.text}
|
|
|
1642
1900
|
} else if (category === "procedure") {
|
|
1643
1901
|
await mkdir(path.join(this.proceduresDir, today), { recursive: true });
|
|
1644
1902
|
filePath = path.join(this.proceduresDir, today, `${id}.md`);
|
|
1903
|
+
} else if (category === "reasoning_trace") {
|
|
1904
|
+
await mkdir(path.join(this.reasoningTracesDir, today), { recursive: true });
|
|
1905
|
+
filePath = path.join(this.reasoningTracesDir, today, `${id}.md`);
|
|
1645
1906
|
} else {
|
|
1646
1907
|
filePath = path.join(this.factsDir, today, `${id}.md`);
|
|
1647
1908
|
}
|
|
@@ -2062,6 +2323,7 @@ ${sanitized.text}
|
|
|
2062
2323
|
};
|
|
2063
2324
|
await collectPaths(this.factsDir);
|
|
2064
2325
|
await collectPaths(this.proceduresDir);
|
|
2326
|
+
await collectPaths(this.reasoningTracesDir);
|
|
2065
2327
|
await collectPaths(this.correctionsDir);
|
|
2066
2328
|
return filePaths;
|
|
2067
2329
|
}
|
|
@@ -2372,6 +2634,9 @@ ${sanitized.text}
|
|
|
2372
2634
|
if (memory.frontmatter.category === "procedure") {
|
|
2373
2635
|
return path.join(root, "procedures", this.resolveMemoryDateDir(memory), `${memory.frontmatter.id}.md`);
|
|
2374
2636
|
}
|
|
2637
|
+
if (memory.frontmatter.category === "reasoning_trace") {
|
|
2638
|
+
return path.join(root, "reasoning-traces", this.resolveMemoryDateDir(memory), `${memory.frontmatter.id}.md`);
|
|
2639
|
+
}
|
|
2375
2640
|
return path.join(root, "facts", this.resolveMemoryDateDir(memory), `${memory.frontmatter.id}.md`);
|
|
2376
2641
|
}
|
|
2377
2642
|
async writeMemoryFileAtomic(targetPath, memory) {
|
|
@@ -2757,6 +3022,96 @@ ${memory.content}
|
|
|
2757
3022
|
await appendFile(this.memoryLifecycleLedgerPath, payload, "utf-8");
|
|
2758
3023
|
return events.length;
|
|
2759
3024
|
}
|
|
3025
|
+
/**
|
|
3026
|
+
* Append a batch of `BUFFER_SURPRISE` telemetry events (issue #563 PR 3).
|
|
3027
|
+
*
|
|
3028
|
+
* Each event records a single buffer flush decision driven by the
|
|
3029
|
+
* surprise gate. The ledger is consumed by
|
|
3030
|
+
* `reportBufferSurpriseDistribution` (Doctor report) and by downstream
|
|
3031
|
+
* benchmark analysis. This method is fire-and-forget by contract:
|
|
3032
|
+
* callers log but do not fail the hot path if the append throws.
|
|
3033
|
+
*/
|
|
3034
|
+
async appendBufferSurpriseEvents(events) {
|
|
3035
|
+
if (events.length === 0) return 0;
|
|
3036
|
+
await this.ensureDirectories();
|
|
3037
|
+
const nowIso = (/* @__PURE__ */ new Date()).toISOString();
|
|
3038
|
+
const payload = events.map((event) => {
|
|
3039
|
+
const normalized = {
|
|
3040
|
+
...event,
|
|
3041
|
+
event: "BUFFER_SURPRISE",
|
|
3042
|
+
timestamp: event.timestamp && event.timestamp.length > 0 ? event.timestamp : nowIso
|
|
3043
|
+
};
|
|
3044
|
+
return `${JSON.stringify(normalized)}
|
|
3045
|
+
`;
|
|
3046
|
+
}).join("");
|
|
3047
|
+
await appendFile(this.bufferSurpriseLedgerPath, payload, "utf-8");
|
|
3048
|
+
return events.length;
|
|
3049
|
+
}
|
|
3050
|
+
/**
|
|
3051
|
+
* Read the buffer-surprise ledger, most recent rows last.
|
|
3052
|
+
*
|
|
3053
|
+
* `limit` bounds the number of **valid rows** returned (not the
|
|
3054
|
+
* number of raw lines parsed). We parse every row, discard malformed
|
|
3055
|
+
* ones, then take the tail — so a partial/truncated trailing line
|
|
3056
|
+
* (the common failure mode after an interrupted append) cannot hide
|
|
3057
|
+
* otherwise-valid recent data above it.
|
|
3058
|
+
*
|
|
3059
|
+
* Non-positive / non-integer / non-finite limits return `[]` rather
|
|
3060
|
+
* than the entire file, matching the other ledger readers in this
|
|
3061
|
+
* class and protecting against `slice(-0.5)` → `slice(-0)` silently
|
|
3062
|
+
* devolving into an unbounded parse.
|
|
3063
|
+
*
|
|
3064
|
+
* # Performance note
|
|
3065
|
+
*
|
|
3066
|
+
* For very large ledgers (issue #563 follow-up), a tail-first reader
|
|
3067
|
+
* would avoid parsing the full file when only a recent window is
|
|
3068
|
+
* needed. We keep the full-scan implementation here because:
|
|
3069
|
+
*
|
|
3070
|
+
* - the ledger is opt-in (flag off by default), so early deployments
|
|
3071
|
+
* accumulate rows slowly;
|
|
3072
|
+
* - telemetry rows are small (~200 bytes), so even 100k rows parse
|
|
3073
|
+
* in well under a second;
|
|
3074
|
+
* - the governance archive/cleanup flow can trim the ledger when
|
|
3075
|
+
* size becomes a concern, reusing the existing maintenance hooks.
|
|
3076
|
+
*
|
|
3077
|
+
* Swap to a chunked tail-reader if production logs show this is a
|
|
3078
|
+
* hot path — leaving that work for a follow-up keeps this PR scoped
|
|
3079
|
+
* to correctness, not optimization.
|
|
3080
|
+
*/
|
|
3081
|
+
async readBufferSurpriseEvents(options = {}) {
|
|
3082
|
+
let raw;
|
|
3083
|
+
try {
|
|
3084
|
+
raw = await readFile(this.bufferSurpriseLedgerPath, "utf-8");
|
|
3085
|
+
} catch (err) {
|
|
3086
|
+
const code = err.code;
|
|
3087
|
+
if (code === "ENOENT") return [];
|
|
3088
|
+
throw err;
|
|
3089
|
+
}
|
|
3090
|
+
let effectiveLimit = null;
|
|
3091
|
+
if (options.limit !== void 0) {
|
|
3092
|
+
if (typeof options.limit !== "number" || !Number.isFinite(options.limit) || options.limit <= 0) {
|
|
3093
|
+
return [];
|
|
3094
|
+
}
|
|
3095
|
+
const floored = Math.floor(options.limit);
|
|
3096
|
+
if (floored <= 0) return [];
|
|
3097
|
+
effectiveLimit = floored;
|
|
3098
|
+
}
|
|
3099
|
+
const lines = raw.split("\n");
|
|
3100
|
+
const events = [];
|
|
3101
|
+
for (const line of lines) {
|
|
3102
|
+
const trimmed = line.trim();
|
|
3103
|
+
if (trimmed.length === 0) continue;
|
|
3104
|
+
try {
|
|
3105
|
+
const parsed = JSON.parse(trimmed);
|
|
3106
|
+
if (isValidBufferSurpriseEvent(parsed)) {
|
|
3107
|
+
events.push(parsed);
|
|
3108
|
+
}
|
|
3109
|
+
} catch {
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
if (effectiveLimit === null) return events;
|
|
3113
|
+
return events.slice(-effectiveLimit);
|
|
3114
|
+
}
|
|
2760
3115
|
async appendBehaviorSignals(events) {
|
|
2761
3116
|
if (events.length === 0) return 0;
|
|
2762
3117
|
await this.ensureDirectories();
|
|
@@ -4073,6 +4428,9 @@ ${sanitized.text}
|
|
|
4073
4428
|
} else if (category === "procedure") {
|
|
4074
4429
|
await mkdir(path.join(this.proceduresDir, today), { recursive: true });
|
|
4075
4430
|
filePath = path.join(this.proceduresDir, today, `${id}.md`);
|
|
4431
|
+
} else if (category === "reasoning_trace") {
|
|
4432
|
+
await mkdir(path.join(this.reasoningTracesDir, today), { recursive: true });
|
|
4433
|
+
filePath = path.join(this.reasoningTracesDir, today, `${id}.md`);
|
|
4076
4434
|
} else {
|
|
4077
4435
|
filePath = path.join(this.factsDir, today, `${id}.md`);
|
|
4078
4436
|
}
|
|
@@ -4317,4 +4675,4 @@ export {
|
|
|
4317
4675
|
serializeEntityFile,
|
|
4318
4676
|
StorageManager
|
|
4319
4677
|
};
|
|
4320
|
-
//# sourceMappingURL=chunk-
|
|
4678
|
+
//# sourceMappingURL=chunk-F5VP6YCB.js.map
|