@remnic/core 10.0.110 → 10.0.112

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.
Files changed (199) hide show
  1. package/dist/access-admin-ops-surface.js +69 -67
  2. package/dist/access-cli.js +69 -67
  3. package/dist/access-cli.js.map +1 -1
  4. package/dist/access-extraction-force-flush.js +69 -67
  5. package/dist/access-http-briefing.js +69 -67
  6. package/dist/access-http-query.js +69 -67
  7. package/dist/access-http.js +69 -67
  8. package/dist/access-identity-continuity-surface.js +69 -67
  9. package/dist/access-lcm-surface.js +69 -67
  10. package/dist/access-mcp.js +69 -67
  11. package/dist/access-observe-write-category.js +5 -5
  12. package/dist/access-observe-write-surface.js +69 -67
  13. package/dist/access-operations-batch.js +69 -67
  14. package/dist/access-operations.js +69 -67
  15. package/dist/access-recall-concurrency.js +69 -67
  16. package/dist/access-recall-response.js +69 -67
  17. package/dist/access-recall-surface.js +69 -67
  18. package/dist/access-schema.js +4 -4
  19. package/dist/access-service.js +69 -67
  20. package/dist/active-recall.js +6 -6
  21. package/dist/adapters/index.js +4 -4
  22. package/dist/adapters/registry.js +2 -2
  23. package/dist/briefing.js +7 -7
  24. package/dist/{capsule-crypto-7FJQINUR.js → capsule-crypto-YO5QJ6L3.js} +2 -2
  25. package/dist/causal-consolidation.js +8 -8
  26. package/dist/{chunk-4TYIHHPW.js → chunk-4N7L2N54.js} +111 -98
  27. package/dist/{chunk-4TYIHHPW.js.map → chunk-4N7L2N54.js.map} +1 -1
  28. package/dist/{chunk-WQ4XKIOX.js → chunk-5RONA5FF.js} +70 -52
  29. package/dist/chunk-5RONA5FF.js.map +1 -0
  30. package/dist/{chunk-ZG4GNPRE.js → chunk-BNQJKWWZ.js} +8 -8
  31. package/dist/{chunk-2NLLXCJG.js → chunk-BXLOS5AJ.js} +2 -2
  32. package/dist/{chunk-7QIRIF3Z.js → chunk-C2KBLOKE.js} +2 -2
  33. package/dist/{chunk-AZYUG2HW.js → chunk-C6WVKVHZ.js} +2 -2
  34. package/dist/{chunk-JODSN3V5.js → chunk-CTQ2XD4R.js} +2 -2
  35. package/dist/{chunk-XNI3URDR.js → chunk-D5F3D7DA.js} +2 -2
  36. package/dist/{chunk-X7Y7WX73.js → chunk-DQEMWVMT.js} +1 -1
  37. package/dist/{chunk-LYR57GEF.js → chunk-EKWS6NCF.js} +3 -3
  38. package/dist/{chunk-XTN54NML.js → chunk-G3T6YMBO.js} +4 -4
  39. package/dist/{chunk-AOAREXFV.js → chunk-G6TDGYVC.js} +2 -2
  40. package/dist/chunk-GE5J2T67.js +100 -0
  41. package/dist/chunk-GE5J2T67.js.map +1 -0
  42. package/dist/{chunk-BUOP3DOK.js → chunk-GRS34Y7V.js} +2 -2
  43. package/dist/{chunk-FQACH7MC.js → chunk-HM62567O.js} +2 -2
  44. package/dist/{chunk-B3LGXOM5.js → chunk-IOLFR3JJ.js} +2 -2
  45. package/dist/{chunk-WCKLRFGF.js → chunk-J5MBTYDO.js} +2 -2
  46. package/dist/{chunk-HRMOKGQM.js → chunk-JCKN3E6Y.js} +2 -2
  47. package/dist/{chunk-UOIVXBNS.js → chunk-JTO63AXR.js} +2 -2
  48. package/dist/{chunk-AY535ZIM.js → chunk-KPFOFT4I.js} +2 -2
  49. package/dist/{chunk-S2HLHAZ4.js → chunk-L76BQSWB.js} +10 -2
  50. package/dist/chunk-L76BQSWB.js.map +1 -0
  51. package/dist/{chunk-FV2B6XE6.js → chunk-NRZJKDGO.js} +2 -2
  52. package/dist/{chunk-VLUWWPKO.js → chunk-O5DO5LXA.js} +13 -13
  53. package/dist/{chunk-5VWN3FJS.js → chunk-OSYHJCLK.js} +2 -2
  54. package/dist/chunk-PQVLF42S.js +87 -0
  55. package/dist/chunk-PQVLF42S.js.map +1 -0
  56. package/dist/{chunk-OLJYBMFW.js → chunk-Q7UY2CSW.js} +7 -7
  57. package/dist/{chunk-R2DOFBG4.js → chunk-QNTBJKTN.js} +2 -2
  58. package/dist/{chunk-7SW6EBEF.js → chunk-QYN6I3CG.js} +2 -2
  59. package/dist/{chunk-KQAFEZQX.js → chunk-R45L4TV6.js} +6 -6
  60. package/dist/{chunk-7HNQR5MV.js → chunk-R76L66OW.js} +3 -3
  61. package/dist/{chunk-QIGEWFXE.js → chunk-RJTHGVO3.js} +2 -2
  62. package/dist/{chunk-FVMEZ57K.js → chunk-RLXD2L3G.js} +7 -7
  63. package/dist/{chunk-25BUV3TU.js → chunk-S4G7WX7Q.js} +2 -2
  64. package/dist/{chunk-BP7LNNWG.js → chunk-SMAPUZYV.js} +2 -2
  65. package/dist/{chunk-GT2TH7FZ.js → chunk-T4FW43AG.js} +3 -3
  66. package/dist/{chunk-OIOKDTZU.js → chunk-T5DX6A7T.js} +17 -6
  67. package/dist/chunk-T5DX6A7T.js.map +1 -0
  68. package/dist/{chunk-EDVVW655.js → chunk-T6H5HNA6.js} +2 -2
  69. package/dist/{chunk-YD4D4EVO.js → chunk-TA6IK76H.js} +2 -2
  70. package/dist/{chunk-7ZEF43SR.js → chunk-TPAIKAT5.js} +3 -3
  71. package/dist/{chunk-IOGYSADY.js → chunk-TS34Y2T5.js} +2 -2
  72. package/dist/{chunk-OEVJH66T.js → chunk-VHWQGBXY.js} +3 -3
  73. package/dist/{chunk-63OWJXGW.js → chunk-VMEFUPOM.js} +2 -2
  74. package/dist/{chunk-E55J2NFL.js → chunk-WP25PXBB.js} +2 -2
  75. package/dist/{chunk-H4XPEXWA.js → chunk-XOCAG2LF.js} +2 -2
  76. package/dist/{chunk-K32VAS5B.js → chunk-YPDUSAPH.js} +2 -2
  77. package/dist/cli.js +69 -67
  78. package/dist/coding/export-okf-codegraph.js +6 -6
  79. package/dist/compounding/engine.js +8 -8
  80. package/dist/config.js +6 -6
  81. package/dist/connectors/codex-materialize-runner.js +7 -7
  82. package/dist/connectors/index.js +7 -7
  83. package/dist/convergence-refresh.js +9 -9
  84. package/dist/corpus-watermark.js +9 -9
  85. package/dist/deep-recall-http-glue.js +5 -5
  86. package/dist/entity-retrieval.js +7 -7
  87. package/dist/explicit-capture.js +69 -67
  88. package/dist/extraction.js +7 -7
  89. package/dist/harmonic-retrieval.js +7 -7
  90. package/dist/index.js +86 -84
  91. package/dist/lcm/engine.js +3 -3
  92. package/dist/lcm/index.js +9 -9
  93. package/dist/location/index.js +8 -8
  94. package/dist/maintenance/memory-governance.js +7 -7
  95. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +7 -7
  96. package/dist/maintenance/rebuild-memory-projection-runner.js +9 -9
  97. package/dist/maintenance/rebuild-memory-projection.js +8 -8
  98. package/dist/memory-snapshot.d.ts +7 -1
  99. package/dist/memory-snapshot.d.ts.map +1 -1
  100. package/dist/memory-snapshot.js +5 -3
  101. package/dist/namespaces/migrate.js +8 -8
  102. package/dist/namespaces/search.js +4 -4
  103. package/dist/namespaces/storage.js +7 -7
  104. package/dist/operator-doctor-corpus.js +10 -10
  105. package/dist/operator-toolkit.js +13 -13
  106. package/dist/orchestration/backlog-scheduler.js +70 -68
  107. package/dist/orchestration/backlog-scheduler.js.map +1 -1
  108. package/dist/orchestration/buffer-drain-runner.js +70 -68
  109. package/dist/orchestration/maintenance.js +15 -15
  110. package/dist/orchestration/recall-internal.d.ts.map +1 -1
  111. package/dist/orchestration/workspace-ops.d.ts.map +1 -1
  112. package/dist/orchestrator.js +69 -67
  113. package/dist/recall-navigation.js +69 -67
  114. package/dist/resume-bundles.js +10 -8
  115. package/dist/search/factory.js +3 -3
  116. package/dist/search/index.js +7 -7
  117. package/dist/semantic-consolidation.js +8 -8
  118. package/dist/semantic-rule-promotion.js +7 -7
  119. package/dist/semantic-rule-verifier.js +7 -7
  120. package/dist/source-agent-qualifier.js +7 -7
  121. package/dist/standup/build.js +7 -7
  122. package/dist/storage.d.ts +3 -0
  123. package/dist/storage.d.ts.map +1 -1
  124. package/dist/storage.js +6 -6
  125. package/dist/transcript-recent.d.ts +22 -0
  126. package/dist/transcript-recent.d.ts.map +1 -0
  127. package/dist/transcript-recent.js +15 -0
  128. package/dist/transcript-recent.js.map +1 -0
  129. package/dist/transcript-write-dir-memo.d.ts +43 -0
  130. package/dist/transcript-write-dir-memo.d.ts.map +1 -0
  131. package/dist/transcript-write-dir-memo.js +10 -0
  132. package/dist/transcript-write-dir-memo.js.map +1 -0
  133. package/dist/transcript.d.ts +15 -3
  134. package/dist/transcript.d.ts.map +1 -1
  135. package/dist/transcript.js +3 -1
  136. package/dist/transfer/autodetect.js +1 -1
  137. package/dist/transfer/backup.js +2 -2
  138. package/dist/transfer/capsule-export.js +3 -3
  139. package/dist/transfer/capsule-import.js +2 -2
  140. package/dist/transfer/export-okf.js +7 -7
  141. package/dist/verified-recall.js +7 -7
  142. package/dist/who-knows-cli.js +8 -8
  143. package/dist/who-knows.js +7 -7
  144. package/package.json +2 -2
  145. package/src/memory-snapshot.ts +14 -1
  146. package/src/orchestration/recall-internal.ts +1 -4
  147. package/src/orchestration/workspace-ops.test.ts +113 -0
  148. package/src/orchestration/workspace-ops.ts +38 -12
  149. package/src/storage-contract/lazy-memory-snapshot.test.ts +194 -0
  150. package/src/storage.ts +15 -4
  151. package/src/transcript-ownership-digest.test.ts +8 -0
  152. package/src/transcript-recent-tail.test.ts +355 -0
  153. package/src/transcript-recent.ts +129 -0
  154. package/src/transcript-write-dir-memo.test.ts +308 -0
  155. package/src/transcript-write-dir-memo.ts +104 -0
  156. package/src/transcript.ts +70 -63
  157. package/dist/chunk-OIOKDTZU.js.map +0 -1
  158. package/dist/chunk-S2HLHAZ4.js.map +0 -1
  159. package/dist/chunk-WQ4XKIOX.js.map +0 -1
  160. /package/dist/{capsule-crypto-7FJQINUR.js.map → capsule-crypto-YO5QJ6L3.js.map} +0 -0
  161. /package/dist/{chunk-ZG4GNPRE.js.map → chunk-BNQJKWWZ.js.map} +0 -0
  162. /package/dist/{chunk-2NLLXCJG.js.map → chunk-BXLOS5AJ.js.map} +0 -0
  163. /package/dist/{chunk-7QIRIF3Z.js.map → chunk-C2KBLOKE.js.map} +0 -0
  164. /package/dist/{chunk-AZYUG2HW.js.map → chunk-C6WVKVHZ.js.map} +0 -0
  165. /package/dist/{chunk-JODSN3V5.js.map → chunk-CTQ2XD4R.js.map} +0 -0
  166. /package/dist/{chunk-XNI3URDR.js.map → chunk-D5F3D7DA.js.map} +0 -0
  167. /package/dist/{chunk-X7Y7WX73.js.map → chunk-DQEMWVMT.js.map} +0 -0
  168. /package/dist/{chunk-LYR57GEF.js.map → chunk-EKWS6NCF.js.map} +0 -0
  169. /package/dist/{chunk-XTN54NML.js.map → chunk-G3T6YMBO.js.map} +0 -0
  170. /package/dist/{chunk-AOAREXFV.js.map → chunk-G6TDGYVC.js.map} +0 -0
  171. /package/dist/{chunk-BUOP3DOK.js.map → chunk-GRS34Y7V.js.map} +0 -0
  172. /package/dist/{chunk-FQACH7MC.js.map → chunk-HM62567O.js.map} +0 -0
  173. /package/dist/{chunk-B3LGXOM5.js.map → chunk-IOLFR3JJ.js.map} +0 -0
  174. /package/dist/{chunk-WCKLRFGF.js.map → chunk-J5MBTYDO.js.map} +0 -0
  175. /package/dist/{chunk-HRMOKGQM.js.map → chunk-JCKN3E6Y.js.map} +0 -0
  176. /package/dist/{chunk-UOIVXBNS.js.map → chunk-JTO63AXR.js.map} +0 -0
  177. /package/dist/{chunk-AY535ZIM.js.map → chunk-KPFOFT4I.js.map} +0 -0
  178. /package/dist/{chunk-FV2B6XE6.js.map → chunk-NRZJKDGO.js.map} +0 -0
  179. /package/dist/{chunk-VLUWWPKO.js.map → chunk-O5DO5LXA.js.map} +0 -0
  180. /package/dist/{chunk-5VWN3FJS.js.map → chunk-OSYHJCLK.js.map} +0 -0
  181. /package/dist/{chunk-OLJYBMFW.js.map → chunk-Q7UY2CSW.js.map} +0 -0
  182. /package/dist/{chunk-R2DOFBG4.js.map → chunk-QNTBJKTN.js.map} +0 -0
  183. /package/dist/{chunk-7SW6EBEF.js.map → chunk-QYN6I3CG.js.map} +0 -0
  184. /package/dist/{chunk-KQAFEZQX.js.map → chunk-R45L4TV6.js.map} +0 -0
  185. /package/dist/{chunk-7HNQR5MV.js.map → chunk-R76L66OW.js.map} +0 -0
  186. /package/dist/{chunk-QIGEWFXE.js.map → chunk-RJTHGVO3.js.map} +0 -0
  187. /package/dist/{chunk-FVMEZ57K.js.map → chunk-RLXD2L3G.js.map} +0 -0
  188. /package/dist/{chunk-25BUV3TU.js.map → chunk-S4G7WX7Q.js.map} +0 -0
  189. /package/dist/{chunk-BP7LNNWG.js.map → chunk-SMAPUZYV.js.map} +0 -0
  190. /package/dist/{chunk-GT2TH7FZ.js.map → chunk-T4FW43AG.js.map} +0 -0
  191. /package/dist/{chunk-EDVVW655.js.map → chunk-T6H5HNA6.js.map} +0 -0
  192. /package/dist/{chunk-YD4D4EVO.js.map → chunk-TA6IK76H.js.map} +0 -0
  193. /package/dist/{chunk-7ZEF43SR.js.map → chunk-TPAIKAT5.js.map} +0 -0
  194. /package/dist/{chunk-IOGYSADY.js.map → chunk-TS34Y2T5.js.map} +0 -0
  195. /package/dist/{chunk-OEVJH66T.js.map → chunk-VHWQGBXY.js.map} +0 -0
  196. /package/dist/{chunk-63OWJXGW.js.map → chunk-VMEFUPOM.js.map} +0 -0
  197. /package/dist/{chunk-E55J2NFL.js.map → chunk-WP25PXBB.js.map} +0 -0
  198. /package/dist/{chunk-H4XPEXWA.js.map → chunk-XOCAG2LF.js.map} +0 -0
  199. /package/dist/{chunk-K32VAS5B.js.map → chunk-YPDUSAPH.js.map} +0 -0
@@ -0,0 +1,100 @@
1
+ import {
2
+ log
3
+ } from "./chunk-3WCASNQZ.js";
4
+
5
+ // src/transcript-recent.ts
6
+ import { open, stat } from "fs/promises";
7
+ import path from "path";
8
+ var RECENT_TAIL_CHUNK_BYTES = 1 << 18;
9
+ var RECENT_SKEW_MS = 36e5;
10
+ var ISO_STAMP = /^\d{4}-\d\d-\d\dT/;
11
+ function firstLineBefore(chunk, cutoffMs) {
12
+ const from = chunk.indexOf(10) + 1;
13
+ const to = chunk.indexOf(10, from);
14
+ if (from === 0 || to < 0) return false;
15
+ try {
16
+ const stamp = JSON.parse(chunk.toString("utf-8", from, to)).timestamp;
17
+ return ISO_STAMP.test(stamp) && new Date(stamp).getTime() < cutoffMs;
18
+ } catch {
19
+ return false;
20
+ }
21
+ }
22
+ function countNewlines(chunk) {
23
+ let n = 0;
24
+ for (let i = chunk.indexOf(10); i >= 0; i = chunk.indexOf(10, i + 1)) n++;
25
+ return n;
26
+ }
27
+ var FS_CONCURRENCY = 48;
28
+ async function mapLimited(items, fn) {
29
+ const out = new Array(items.length);
30
+ let next = 0;
31
+ await Promise.all(Array.from({ length: Math.min(FS_CONCURRENCY, items.length) }, async () => {
32
+ while (next < items.length) {
33
+ const i = next++;
34
+ out[i] = await fn(items[i]);
35
+ }
36
+ }));
37
+ return out;
38
+ }
39
+ async function readLinesSince(filePath, cutoffMs, maxLines = Infinity) {
40
+ const { size, mtimeMs } = await stat(filePath);
41
+ if (mtimeMs < cutoffMs) return [];
42
+ const fh = await open(filePath, "r");
43
+ try {
44
+ const chunks = [];
45
+ let pos = size;
46
+ let newlines = 0;
47
+ while (pos > 0) {
48
+ const buf = Buffer.allocUnsafe(Math.min(RECENT_TAIL_CHUNK_BYTES, pos));
49
+ pos -= buf.length;
50
+ const { bytesRead } = await fh.read(buf, 0, buf.length, pos);
51
+ if (bytesRead !== buf.length) throw new Error(`short read on ${filePath}`);
52
+ chunks.unshift(buf);
53
+ newlines += countNewlines(chunks[0]);
54
+ if (pos > 0 && (newlines > maxLines || firstLineBefore(chunks[0], cutoffMs))) break;
55
+ }
56
+ let text = Buffer.concat(chunks).toString("utf-8");
57
+ if (pos > 0) text = text.slice(text.indexOf("\n") + 1);
58
+ return (text.endsWith("\n") ? text.slice(0, -1) : text).split("\n").slice(-maxLines);
59
+ } finally {
60
+ await fh.close();
61
+ }
62
+ }
63
+ async function readNewestFromFiles(transcriptsDir, files, start, end, limit) {
64
+ const startMs = start.getTime();
65
+ const stamped = await mapLimited(files, async (f) => {
66
+ const filePath = path.join(transcriptsDir, f);
67
+ return { filePath, mtimeMs: await stat(filePath).then((s) => s.mtimeMs, () => -Infinity) };
68
+ });
69
+ stamped.sort((a, b) => b.mtimeMs - a.mtimeMs);
70
+ let newest = [];
71
+ for (const { filePath, mtimeMs } of stamped) {
72
+ const floorMs = newest.length >= limit ? new Date(newest[0].timestamp).getTime() : startMs;
73
+ if (mtimeMs + RECENT_SKEW_MS < floorMs) break;
74
+ let found = [];
75
+ for (let cap = limit; ; cap *= 2) {
76
+ const lines = await readLinesSince(filePath, floorMs - RECENT_SKEW_MS, cap).catch(() => []);
77
+ found = [];
78
+ for (const line of lines) {
79
+ try {
80
+ const entry = JSON.parse(line);
81
+ const entryTime = new Date(entry.timestamp);
82
+ if (entryTime >= start && entryTime < end) found.push(entry);
83
+ } catch {
84
+ log.debug(`skipped malformed transcript line in ${filePath}`);
85
+ }
86
+ }
87
+ if (found.length >= limit || lines.length < cap) break;
88
+ }
89
+ newest = [...newest, ...found].sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()).slice(-limit);
90
+ }
91
+ return newest;
92
+ }
93
+
94
+ export {
95
+ RECENT_SKEW_MS,
96
+ mapLimited,
97
+ readLinesSince,
98
+ readNewestFromFiles
99
+ };
100
+ //# sourceMappingURL=chunk-GE5J2T67.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/transcript-recent.ts"],"sourcesContent":["/**\n * Tail reads of daily transcript files for the unscoped `readRecent` (COS-666c). Split out of\n * transcript.ts to keep that file under its size cap.\n */\n\nimport { open, stat } from \"node:fs/promises\";\nimport path from \"node:path\";\nimport { log } from \"./logger.js\";\nimport type { TranscriptEntry } from \"./types.js\";\n\nconst RECENT_TAIL_CHUNK_BYTES = 1 << 18;\nexport const RECENT_SKEW_MS = 3_600_000;\n\nconst ISO_STAMP = /^\\d{4}-\\d\\d-\\d\\dT/;\n\n/** True when the first complete line in `chunk` (which starts mid-line) is stamped before `cutoffMs`. */\nfunction firstLineBefore(chunk: Buffer, cutoffMs: number): boolean {\n const from = chunk.indexOf(0x0a) + 1;\n const to = chunk.indexOf(0x0a, from);\n if (from === 0 || to < 0) return false;\n try {\n // SAFETY: only `.timestamp` is read, and it is used only if it is an ISO string (the test coerces null, numbers\n // and other shapes to text that fails); new Date(null) is the epoch and would stop the scan early.\n const stamp = (JSON.parse(chunk.toString(\"utf-8\", from, to)) as TranscriptEntry).timestamp;\n return ISO_STAMP.test(stamp) && new Date(stamp).getTime() < cutoffMs;\n } catch {\n return false;\n }\n}\n\nfunction countNewlines(chunk: Buffer): number {\n let n = 0;\n for (let i = chunk.indexOf(0x0a); i >= 0; i = chunk.indexOf(0x0a, i + 1)) n++;\n return n;\n}\n\nconst FS_CONCURRENCY = 48;\n\n/** `items.map(fn)` with at most FS_CONCURRENCY in flight (the libuv pool is shared); results keep input order. */\nexport async function mapLimited<T, R>(items: T[], fn: (item: T) => Promise<R>): Promise<R[]> {\n const out = new Array<R>(items.length);\n let next = 0;\n await Promise.all(Array.from({ length: Math.min(FS_CONCURRENCY, items.length) }, async () => {\n while (next < items.length) {\n const i = next++;\n out[i] = await fn(items[i]);\n }\n }));\n return out;\n}\n\n/**\n * Lines of a daily transcript file that can be stamped at or after `cutoffMs`.\n * Files are appended in write order, so the recent window is the file's tail:\n * read 256 KiB chunks from the end and stop once the first complete line in hand is\n * older than the cutoff, or (with `maxLines`) once `maxLines` complete lines are in hand,\n * returning at most the last `maxLines`. A file not modified since the cutoff holds nothing in the window.\n * shortcut: assumes a file's timestamps never run backwards by more than the\n * RECENT_SKEW_MS the caller subtracts, and that its last `maxLines` lines hold its newest\n * `maxLines` entries (the newest-N path has no skew margin: a writer stamping entries late can change which N are returned); widen the margin if writers can lag further.\n */\nexport async function readLinesSince(filePath: string, cutoffMs: number, maxLines = Infinity): Promise<string[]> {\n const { size, mtimeMs } = await stat(filePath);\n if (mtimeMs < cutoffMs) return [];\n const fh = await open(filePath, \"r\");\n try {\n const chunks: Buffer[] = [];\n let pos = size;\n let newlines = 0;\n while (pos > 0) {\n const buf = Buffer.allocUnsafe(Math.min(RECENT_TAIL_CHUNK_BYTES, pos));\n pos -= buf.length;\n const { bytesRead } = await fh.read(buf, 0, buf.length, pos);\n if (bytesRead !== buf.length) throw new Error(`short read on ${filePath}`); // a gap would silently drop lines\n chunks.unshift(buf);\n newlines += countNewlines(chunks[0]);\n // One newline ends the partial first line; each further one ends a complete line.\n if (pos > 0 && (newlines > maxLines || firstLineBefore(chunks[0], cutoffMs))) break;\n }\n let text = Buffer.concat(chunks).toString(\"utf-8\");\n if (pos > 0) text = text.slice(text.indexOf(\"\\n\") + 1); // drop the partial first line\n // Blank lines stay (only the final terminator goes): they count toward `maxLines` like the chunk stop counts them, and a blank fails to parse like any bad line.\n return (text.endsWith(\"\\n\") ? text.slice(0, -1) : text).split(\"\\n\").slice(-maxLines);\n } finally {\n await fh.close();\n }\n}\n\n/** The newest `limit` entries in `[start, end)` from the given daily files (paths relative to `transcriptsDir`). */\nexport async function readNewestFromFiles(\n transcriptsDir: string,\n files: string[],\n start: Date,\n end: Date,\n limit: number,\n): Promise<TranscriptEntry[]> {\n const startMs = start.getTime();\n const stamped = await mapLimited(files, async (f) => {\n const filePath = path.join(transcriptsDir, f);\n return { filePath, mtimeMs: await stat(filePath).then((s) => s.mtimeMs, () => -Infinity) };\n });\n stamped.sort((a, b) => b.mtimeMs - a.mtimeMs);\n let newest: TranscriptEntry[] = []; // ascending by timestamp, at most `limit`\n for (const { filePath, mtimeMs } of stamped) {\n // The Nth-newest timestamp so far; a file modified more than the skew before it holds nothing newer.\n const floorMs = newest.length >= limit ? new Date(newest[0].timestamp).getTime() : startMs;\n if (mtimeMs + RECENT_SKEW_MS < floorMs) break;\n let found: TranscriptEntry[] = [];\n // A bad line (torn append, no timestamp, future-dated) takes a slot without yielding an entry:\n // widen the tail until `limit` entries are found or the file's window is exhausted.\n for (let cap = limit; ; cap *= 2) {\n const lines = await readLinesSince(filePath, floorMs - RECENT_SKEW_MS, cap).catch(() => []);\n found = [];\n for (const line of lines) {\n try {\n // SAFETY: the same cast the full-window read made here; `timestamp` is validated on the next line.\n const entry = JSON.parse(line) as TranscriptEntry;\n const entryTime = new Date(entry.timestamp);\n if (entryTime >= start && entryTime < end) found.push(entry);\n } catch {\n log.debug(`skipped malformed transcript line in ${filePath}`);\n }\n }\n if (found.length >= limit || lines.length < cap) break;\n }\n newest = [...newest, ...found].sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()).slice(-limit);\n }\n return newest;\n}\n"],"mappings":";;;;;AAKA,SAAS,MAAM,YAAY;AAC3B,OAAO,UAAU;AAIjB,IAAM,0BAA0B,KAAK;AAC9B,IAAM,iBAAiB;AAE9B,IAAM,YAAY;AAGlB,SAAS,gBAAgB,OAAe,UAA2B;AACjE,QAAM,OAAO,MAAM,QAAQ,EAAI,IAAI;AACnC,QAAM,KAAK,MAAM,QAAQ,IAAM,IAAI;AACnC,MAAI,SAAS,KAAK,KAAK,EAAG,QAAO;AACjC,MAAI;AAGF,UAAM,QAAS,KAAK,MAAM,MAAM,SAAS,SAAS,MAAM,EAAE,CAAC,EAAsB;AACjF,WAAO,UAAU,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,EAAE,QAAQ,IAAI;AAAA,EAC9D,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,cAAc,OAAuB;AAC5C,MAAI,IAAI;AACR,WAAS,IAAI,MAAM,QAAQ,EAAI,GAAG,KAAK,GAAG,IAAI,MAAM,QAAQ,IAAM,IAAI,CAAC,EAAG;AAC1E,SAAO;AACT;AAEA,IAAM,iBAAiB;AAGvB,eAAsB,WAAiB,OAAY,IAA2C;AAC5F,QAAM,MAAM,IAAI,MAAS,MAAM,MAAM;AACrC,MAAI,OAAO;AACX,QAAM,QAAQ,IAAI,MAAM,KAAK,EAAE,QAAQ,KAAK,IAAI,gBAAgB,MAAM,MAAM,EAAE,GAAG,YAAY;AAC3F,WAAO,OAAO,MAAM,QAAQ;AAC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radation
6
6
  } from "./chunk-NWA6IXR3.js";
@@ -572,4 +572,4 @@ export {
572
572
  normalizeQmdResultPath,
573
573
  resolveNamespaceResultPath
574
574
  };
575
- //# sourceMappingURL=chunk-BUOP3DOK.js.map
575
+ //# sourceMappingURL=chunk-GRS34Y7V.js.map
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-B2NXOVZN.js";
5
5
  import {
6
6
  TranscriptManager
7
- } from "./chunk-WQ4XKIOX.js";
7
+ } from "./chunk-5RONA5FF.js";
8
8
  import {
9
9
  resolveCommitmentLedgerDir,
10
10
  validateCommitmentLedgerEntry
@@ -268,4 +268,4 @@ export {
268
268
  recordResumeBundle,
269
269
  getResumeBundleStatus
270
270
  };
271
- //# sourceMappingURL=chunk-FQACH7MC.js.map
271
+ //# sourceMappingURL=chunk-HM62567O.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  StorageManager
3
- } from "./chunk-OIOKDTZU.js";
3
+ } from "./chunk-T5DX6A7T.js";
4
4
  import {
5
5
  countRecallTokenOverlap,
6
6
  normalizeRecallTokens
@@ -119,4 +119,4 @@ export {
119
119
  compareVerifiedSemanticRuleResults,
120
120
  searchVerifiedSemanticRules
121
121
  };
122
- //# sourceMappingURL=chunk-B3LGXOM5.js.map
122
+ //# sourceMappingURL=chunk-IOLFR3JJ.js.map
@@ -13,7 +13,7 @@ import {
13
13
  } from "./chunk-ZCUTSMR2.js";
14
14
  import {
15
15
  StorageManager
16
- } from "./chunk-OIOKDTZU.js";
16
+ } from "./chunk-T5DX6A7T.js";
17
17
  import {
18
18
  excludeSupportPassportPrivateMemories
19
19
  } from "./chunk-NS7U4ZYU.js";
@@ -134,4 +134,4 @@ export {
134
134
  runCodexMaterialize,
135
135
  runPostConsolidationMaterialize
136
136
  };
137
- //# sourceMappingURL=chunk-WCKLRFGF.js.map
137
+ //# sourceMappingURL=chunk-J5MBTYDO.js.map
@@ -19,7 +19,7 @@ import {
19
19
  import {
20
20
  decryptCapsuleFileInMemory,
21
21
  isEncryptedCapsuleFile
22
- } from "./chunk-X7Y7WX73.js";
22
+ } from "./chunk-DQEMWVMT.js";
23
23
  import {
24
24
  assertIsDirectoryNotSymlink,
25
25
  assertRealpathInsideRoot,
@@ -296,4 +296,4 @@ function mintForkId(capsuleId, originalId, now) {
296
296
  export {
297
297
  importCapsule
298
298
  };
299
- //# sourceMappingURL=chunk-HRMOKGQM.js.map
299
+ //# sourceMappingURL=chunk-JCKN3E6Y.js.map
@@ -14,7 +14,7 @@ import {
14
14
  } from "./chunk-3UXOZBHV.js";
15
15
  import {
16
16
  StorageManager
17
- } from "./chunk-OIOKDTZU.js";
17
+ } from "./chunk-T5DX6A7T.js";
18
18
  import {
19
19
  OKF_PROFILE_TYPE,
20
20
  okfTypeForMemory
@@ -272,4 +272,4 @@ export {
272
272
  exportOkfBundle,
273
273
  firstHeading
274
274
  };
275
- //# sourceMappingURL=chunk-UOIVXBNS.js.map
275
+ //# sourceMappingURL=chunk-JTO63AXR.js.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-KJTKLXTH.js";
4
4
  import {
5
5
  StorageManager
6
- } from "./chunk-OIOKDTZU.js";
6
+ } from "./chunk-T5DX6A7T.js";
7
7
  import {
8
8
  assertInjectedStorageRooted
9
9
  } from "./chunk-BNZAR6PO.js";
@@ -260,4 +260,4 @@ export {
260
260
  backupExistingLedger,
261
261
  rebuildMemoryLifecycleLedger
262
262
  };
263
- //# sourceMappingURL=chunk-AY535ZIM.js.map
263
+ //# sourceMappingURL=chunk-KPFOFT4I.js.map
@@ -9,8 +9,16 @@ function sortSnapshotObject(_key, candidate) {
9
9
  function createMemorySnapshot(memory) {
10
10
  return JSON.stringify([memory.frontmatter, memory.content], sortSnapshotObject);
11
11
  }
12
+ function loadTimeStamps(raw, parsed, loaded) {
13
+ const front = raw.slice(0, raw.indexOf("\n---", 3));
14
+ return {
15
+ created: /^[ \t]*created[ \t]*:/m.test(front) ? parsed.created : loaded.created,
16
+ updated: /^[ \t]*updated[ \t]*:/m.test(front) ? parsed.updated : loaded.updated
17
+ };
18
+ }
12
19
 
13
20
  export {
14
- createMemorySnapshot
21
+ createMemorySnapshot,
22
+ loadTimeStamps
15
23
  };
16
- //# sourceMappingURL=chunk-S2HLHAZ4.js.map
24
+ //# sourceMappingURL=chunk-L76BQSWB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/memory-snapshot.ts"],"sourcesContent":["import type { MemoryFile, MemoryFrontmatter } from \"./types.js\";\n\nfunction sortSnapshotObject(_key: string, candidate: unknown): unknown {\n if (candidate === null || typeof candidate !== \"object\" || Array.isArray(candidate)) return candidate;\n return Object.keys(candidate)\n .sort()\n .reduce<Record<string, unknown>>((sorted, key) => {\n sorted[key] = (candidate as Record<string, unknown>)[key];\n return sorted;\n }, {});\n}\n\nexport function createMemorySnapshot(memory: MemoryFile): string {\n return JSON.stringify([memory.frontmatter, memory.content], sortSnapshotObject);\n}\n\n/**\n * created/updated for a snapshot rebuilt from a file's text. parseFrontmatter stamps a missing key with \"now\", so take\n * the loaded memory's own stamp instead, as the old eager snapshot did: a file with no timestamps then never matches a\n * later read of itself (refused every time, not by clock tick). Key presence follows the parser, which trims the key.\n */\nexport function loadTimeStamps(raw: string, parsed: MemoryFrontmatter, loaded: MemoryFrontmatter): Pick<MemoryFrontmatter, \"created\" | \"updated\"> {\n const front = raw.slice(0, raw.indexOf(\"\\n---\", 3)); // the block parseFrontmatter reads, without a lazy regex\n return {\n created: /^[ \\t]*created[ \\t]*:/m.test(front) ? parsed.created : loaded.created,\n updated: /^[ \\t]*updated[ \\t]*:/m.test(front) ? parsed.updated : loaded.updated,\n };\n}\n"],"mappings":";AAEA,SAAS,mBAAmB,MAAc,WAA6B;AACrE,MAAI,cAAc,QAAQ,OAAO,cAAc,YAAY,MAAM,QAAQ,SAAS,EAAG,QAAO;AAC5F,SAAO,OAAO,KAAK,SAAS,EACzB,KAAK,EACL,OAAgC,CAAC,QAAQ,QAAQ;AAChD,WAAO,GAAG,IAAK,UAAsC,GAAG;AACxD,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACT;AAEO,SAAS,qBAAqB,QAA4B;AAC/D,SAAO,KAAK,UAAU,CAAC,OAAO,aAAa,OAAO,OAAO,GAAG,kBAAkB;AAChF;AAOO,SAAS,eAAe,KAAa,QAA2B,QAA2E;AAChJ,QAAM,QAAQ,IAAI,MAAM,GAAG,IAAI,QAAQ,SAAS,CAAC,CAAC;AAClD,SAAO;AAAA,IACL,SAAS,yBAAyB,KAAK,KAAK,IAAI,OAAO,UAAU,OAAO;AAAA,IACxE,SAAS,yBAAyB,KAAK,KAAK,IAAI,OAAO,UAAU,OAAO;AAAA,EAC1E;AACF;","names":[]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  StorageManager
3
- } from "./chunk-OIOKDTZU.js";
3
+ } from "./chunk-T5DX6A7T.js";
4
4
  import {
5
5
  isSafeRouteNamespace
6
6
  } from "./chunk-PCXDUHQH.js";
@@ -416,4 +416,4 @@ export {
416
416
  resolveNamespaceStorageRoot,
417
417
  NamespaceStorageRouter
418
418
  };
419
- //# sourceMappingURL=chunk-FV2B6XE6.js.map
419
+ //# sourceMappingURL=chunk-NRZJKDGO.js.map
@@ -1,12 +1,3 @@
1
- import {
2
- rebuildMemoryLifecycleLedger
3
- } from "./chunk-AY535ZIM.js";
4
- import {
5
- PROJECTION_REBUILD_RUNNER_FLAG
6
- } from "./chunk-63OWJXGW.js";
7
- import {
8
- startLocationAutoSync
9
- } from "./chunk-OEVJH66T.js";
10
1
  import {
11
2
  ensureContradictionScanCron,
12
3
  ensureDaySummaryCron,
@@ -16,19 +7,28 @@ import {
16
7
  ensureProceduralMiningCron,
17
8
  graphEdgeDecayCadenceToCronExpr
18
9
  } from "./chunk-666A3MOW.js";
10
+ import {
11
+ rebuildMemoryLifecycleLedger
12
+ } from "./chunk-KPFOFT4I.js";
13
+ import {
14
+ PROJECTION_REBUILD_RUNNER_FLAG
15
+ } from "./chunk-VMEFUPOM.js";
16
+ import {
17
+ startLocationAutoSync
18
+ } from "./chunk-VHWQGBXY.js";
19
19
  import {
20
20
  CompoundingEngine,
21
21
  isIsoWeekId,
22
22
  msUntilNextIsoWeek,
23
23
  previousIsoWeekId
24
- } from "./chunk-7HNQR5MV.js";
24
+ } from "./chunk-R76L66OW.js";
25
25
  import {
26
26
  planNamespaceMaintenance,
27
27
  runNamespaceMaintenanceBatchPlan
28
- } from "./chunk-AOAREXFV.js";
28
+ } from "./chunk-G6TDGYVC.js";
29
29
  import {
30
30
  rebuildMemoryProjection
31
- } from "./chunk-LYR57GEF.js";
31
+ } from "./chunk-EKWS6NCF.js";
32
32
  import {
33
33
  LocalLlmClient
34
34
  } from "./chunk-33C4BK7I.js";
@@ -2874,4 +2874,4 @@ export {
2874
2874
  ActivitySyncScheduler,
2875
2875
  MaintenanceScheduler
2876
2876
  };
2877
- //# sourceMappingURL=chunk-VLUWWPKO.js.map
2877
+ //# sourceMappingURL=chunk-O5DO5LXA.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseFrontmatter
3
- } from "./chunk-OIOKDTZU.js";
3
+ } from "./chunk-T5DX6A7T.js";
4
4
  import {
5
5
  activityDigestPath,
6
6
  isValidActivityDate
@@ -199,4 +199,4 @@ export {
199
199
  buildStandup,
200
200
  standupHelp
201
201
  };
202
- //# sourceMappingURL=chunk-5VWN3FJS.js.map
202
+ //# sourceMappingURL=chunk-OSYHJCLK.js.map
@@ -0,0 +1,87 @@
1
+ // src/transcript-write-dir-memo.ts
2
+ import { createHash } from "crypto";
3
+ var DEFAULT_WRITE_DIR_MEMO_ENTRIES = 4096;
4
+ var WriteDirMemo = class {
5
+ constructor(maxEntries = DEFAULT_WRITE_DIR_MEMO_ENTRIES) {
6
+ this.maxEntries = maxEntries;
7
+ if (!Number.isInteger(maxEntries) || maxEntries < 1) {
8
+ throw new RangeError("maxEntries must be a positive integer");
9
+ }
10
+ }
11
+ maxEntries;
12
+ entries = /* @__PURE__ */ new Map();
13
+ /** Bumped by every invalidation; a choice that was pending across one is not remembered. */
14
+ generation = 0;
15
+ /** Tail of the queue of memo-miss runs, per primary directory. */
16
+ lanes = /* @__PURE__ */ new Map();
17
+ /** Primary directories with a first append queued or running; empty when idle. */
18
+ get pendingLanes() {
19
+ return this.lanes.size;
20
+ }
21
+ /** The remembered choice for the session, else the result of `choose` (remembered when it resolves). */
22
+ async resolve(root, sessionKey, choose) {
23
+ const key = this.keyFor(root, sessionKey);
24
+ const hit = this.entries.get(key);
25
+ if (hit) {
26
+ this.entries.delete(key);
27
+ this.entries.set(key, hit);
28
+ return hit;
29
+ }
30
+ const generation = this.generation;
31
+ const chosen = await choose();
32
+ if (generation !== this.generation) return chosen;
33
+ this.entries.set(key, chosen);
34
+ if (this.entries.size > this.maxEntries) {
35
+ const oldest = this.entries.keys().next();
36
+ if (!oldest.done) this.entries.delete(oldest.value);
37
+ }
38
+ return chosen;
39
+ }
40
+ /**
41
+ * Run a session's append. A session whose directory is already remembered
42
+ * runs at once. Any other session's first append runs after the earlier
43
+ * first appends that share its primary directory: two sessions that map to
44
+ * one directory (two agents in one channel) must not both find it empty and
45
+ * both claim it, so the second check has to see the first session's row.
46
+ */
47
+ async run(root, sessionKey, primaryDir, fn) {
48
+ if (this.entries.has(this.keyFor(root, sessionKey))) return fn();
49
+ const lane = `${root}\0${primaryDir}`;
50
+ const result = (this.lanes.get(lane) ?? Promise.resolve()).then(fn);
51
+ const tail = result.then(
52
+ () => void 0,
53
+ () => void 0
54
+ );
55
+ this.lanes.set(lane, tail);
56
+ try {
57
+ return await result;
58
+ } finally {
59
+ if (this.lanes.get(lane) === tail) this.lanes.delete(lane);
60
+ }
61
+ }
62
+ /** Run a file removal, then drop every remembered directory: the removal may have emptied one that another session can now claim. */
63
+ async removing(remove) {
64
+ try {
65
+ return await remove();
66
+ } finally {
67
+ this.clear();
68
+ }
69
+ }
70
+ clear() {
71
+ this.generation++;
72
+ this.entries.clear();
73
+ }
74
+ forget(root, sessionKey) {
75
+ this.generation++;
76
+ this.entries.delete(this.keyFor(root, sessionKey));
77
+ }
78
+ keyFor(root, sessionKey) {
79
+ return `${root}\0${createHash("sha256").update(sessionKey).digest("hex")}`;
80
+ }
81
+ };
82
+
83
+ export {
84
+ DEFAULT_WRITE_DIR_MEMO_ENTRIES,
85
+ WriteDirMemo
86
+ };
87
+ //# sourceMappingURL=chunk-PQVLF42S.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/transcript-write-dir-memo.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\n\n/** One entry per session, ~200 B each. */\nexport const DEFAULT_WRITE_DIR_MEMO_ENTRIES = 4096;\n\nexport interface WriteDirChoice {\n dir: string;\n channelDir: string;\n}\n\n/**\n * Remembers which storage directory a session's appends were verified to own,\n * so only a session's first append in a process pays the directory ownership\n * check (a full read of every daily file). The key holds the session key as a\n * digest so caller-chosen keys cannot inflate memory; the map is an LRU.\n *\n * The remembered choice is not re-derived from the bytes. A file edited on\n * disk behind the process is noticed on the session's first append after a\n * restart or after an append error ({@link forget}), not on every append.\n */\nexport class WriteDirMemo {\n private readonly entries = new Map<string, WriteDirChoice>();\n /** Bumped by every invalidation; a choice that was pending across one is not remembered. */\n private generation = 0;\n /** Tail of the queue of memo-miss runs, per primary directory. */\n private readonly lanes = new Map<string, Promise<void>>();\n\n constructor(private readonly maxEntries: number = DEFAULT_WRITE_DIR_MEMO_ENTRIES) {\n if (!Number.isInteger(maxEntries) || maxEntries < 1) {\n throw new RangeError(\"maxEntries must be a positive integer\");\n }\n }\n\n /** Primary directories with a first append queued or running; empty when idle. */\n get pendingLanes(): number {\n return this.lanes.size;\n }\n\n /** The remembered choice for the session, else the result of `choose` (remembered when it resolves). */\n async resolve(root: string, sessionKey: string, choose: () => Promise<WriteDirChoice>): Promise<WriteDirChoice> {\n const key = this.keyFor(root, sessionKey);\n const hit = this.entries.get(key);\n if (hit) {\n this.entries.delete(key);\n this.entries.set(key, hit);\n return hit;\n }\n const generation = this.generation;\n const chosen = await choose();\n if (generation !== this.generation) return chosen;\n this.entries.set(key, chosen);\n if (this.entries.size > this.maxEntries) {\n const oldest = this.entries.keys().next();\n if (!oldest.done) this.entries.delete(oldest.value);\n }\n return chosen;\n }\n\n /**\n * Run a session's append. A session whose directory is already remembered\n * runs at once. Any other session's first append runs after the earlier\n * first appends that share its primary directory: two sessions that map to\n * one directory (two agents in one channel) must not both find it empty and\n * both claim it, so the second check has to see the first session's row.\n */\n async run<T>(root: string, sessionKey: string, primaryDir: string, fn: () => Promise<T>): Promise<T> {\n if (this.entries.has(this.keyFor(root, sessionKey))) return fn();\n const lane = `${root}\\0${primaryDir}`;\n const result = (this.lanes.get(lane) ?? Promise.resolve()).then(fn);\n const tail = result.then(\n () => undefined,\n () => undefined,\n );\n this.lanes.set(lane, tail);\n try {\n return await result;\n } finally {\n if (this.lanes.get(lane) === tail) this.lanes.delete(lane);\n }\n }\n\n /** Run a file removal, then drop every remembered directory: the removal may have emptied one that another session can now claim. */\n async removing<T>(remove: () => Promise<T>): Promise<T> {\n try {\n return await remove();\n } finally {\n this.clear();\n }\n }\n\n clear(): void {\n this.generation++;\n this.entries.clear();\n }\n\n forget(root: string, sessionKey: string): void {\n this.generation++;\n this.entries.delete(this.keyFor(root, sessionKey));\n }\n\n private keyFor(root: string, sessionKey: string): string {\n return `${root}\\0${createHash(\"sha256\").update(sessionKey).digest(\"hex\")}`;\n }\n}\n"],"mappings":";AAAA,SAAS,kBAAkB;AAGpB,IAAM,iCAAiC;AAiBvC,IAAM,eAAN,MAAmB;AAAA,EAOxB,YAA6B,aAAqB,gCAAgC;AAArD;AAC3B,QAAI,CAAC,OAAO,UAAU,UAAU,KAAK,aAAa,GAAG;AACnD,YAAM,IAAI,WAAW,uCAAuC;AAAA,IAC9D;AAAA,EACF;AAAA,EAJ6B;AAAA,EANZ,UAAU,oBAAI,IAA4B;AAAA;AAAA,EAEnD,aAAa;AAAA;AAAA,EAEJ,QAAQ,oBAAI,IAA2B;AAAA;AAA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AO;AAAA,IACtB,UAAE;AACA,WAAK,MAAM;AAAA,IACb;AAAA,EACF;AAAA,EAEA,QAAc;AACZ,SAAK;AACL,SAAK,QAAQ,MAAM;AAAA,EACrB;AAAA,EAEA,OAAO,MAAc,YAA0B;AAC7C,SAAK;AACL,SAAK,QAAQ,OAAO,KAAK,OAAO,MAAM,UAAU,CAAC;AAAA,EACnD;AAAA,EAEQ,OAAO,MAAc,YAA4B;AACvD,WAAO,GAAG,IAAI,KAAK,WAAW,QAAQ,EAAE,OAAO,UAAU,EAAE,OAAO,KAAK,CAAC;AAAA,EAC1E;AACF;","names":[]}
@@ -3,7 +3,7 @@ import {
3
3
  readNamespaceMaintenanceLastRanStatuses,
4
4
  readNamespaceMaintenanceStatuses,
5
5
  runNamespaceMaintenancePlan
6
- } from "./chunk-AOAREXFV.js";
6
+ } from "./chunk-G6TDGYVC.js";
7
7
  import {
8
8
  analyzeSessionIntegrity,
9
9
  applySessionRepair,
@@ -14,7 +14,7 @@ import {
14
14
  } from "./chunk-CMTINOFS.js";
15
15
  import {
16
16
  summarizeCorpusAndReplica
17
- } from "./chunk-BP7LNNWG.js";
17
+ } from "./chunk-SMAPUZYV.js";
18
18
  import {
19
19
  readJudgeVerdictStats
20
20
  } from "./chunk-OZKOPQCM.js";
@@ -27,14 +27,14 @@ import {
27
27
  } from "./chunk-JKMIGCK6.js";
28
28
  import {
29
29
  resolveCorpusNamespaceRoots
30
- } from "./chunk-7SW6EBEF.js";
30
+ } from "./chunk-QYN6I3CG.js";
31
31
  import {
32
32
  listNamespaces
33
- } from "./chunk-GT2TH7FZ.js";
33
+ } from "./chunk-T4FW43AG.js";
34
34
  import {
35
35
  listMemoryGovernanceRuns,
36
36
  readMemoryGovernanceRunArtifact
37
- } from "./chunk-H4XPEXWA.js";
37
+ } from "./chunk-XOCAG2LF.js";
38
38
  import {
39
39
  resolveCuratedIncludeFilesStatePath,
40
40
  resolveNativeKnowledgeStatePath,
@@ -57,7 +57,7 @@ import {
57
57
  } from "./chunk-AWD36R4D.js";
58
58
  import {
59
59
  StorageManager
60
- } from "./chunk-OIOKDTZU.js";
60
+ } from "./chunk-T5DX6A7T.js";
61
61
  import {
62
62
  lintWorkspaceFiles
63
63
  } from "./chunk-DM2T26WE.js";
@@ -1876,4 +1876,4 @@ export {
1876
1876
  runBenchmarkRecall,
1877
1877
  runOperatorRepair
1878
1878
  };
1879
- //# sourceMappingURL=chunk-OLJYBMFW.js.map
1879
+ //# sourceMappingURL=chunk-Q7UY2CSW.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  isValidCapsuleSince
3
- } from "./chunk-KQAFEZQX.js";
3
+ } from "./chunk-R45L4TV6.js";
4
4
  import {
5
5
  CAPSULE_ID_PATTERN
6
6
  } from "./chunk-WEHSQBFR.js";
@@ -580,4 +580,4 @@ export {
580
580
  actionConfidenceRequestSchema,
581
581
  validateRequest
582
582
  };
583
- //# sourceMappingURL=chunk-R2DOFBG4.js.map
583
+ //# sourceMappingURL=chunk-QNTBJKTN.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  listNamespaces
3
- } from "./chunk-GT2TH7FZ.js";
3
+ } from "./chunk-T4FW43AG.js";
4
4
  import {
5
5
  corpusScanWorker
6
6
  } from "./chunk-4LZ7SVKM.js";
@@ -292,4 +292,4 @@ export {
292
292
  computeServiceCorpusWatermarks,
293
293
  computeServiceCorpusCensus
294
294
  };
295
- //# sourceMappingURL=chunk-7SW6EBEF.js.map
295
+ //# sourceMappingURL=chunk-QYN6I3CG.js.map
@@ -1,3 +1,7 @@
1
+ import {
2
+ CAPSULE_SCHEMA_VERSION,
3
+ EXPORT_FORMAT
4
+ } from "./chunk-J4EB7DNW.js";
1
5
  import {
2
6
  CAPSULE_ID_PATTERN,
3
7
  CapsuleBlockSchema,
@@ -6,11 +10,7 @@ import {
6
10
  } from "./chunk-WEHSQBFR.js";
7
11
  import {
8
12
  encryptCapsuleFile
9
- } from "./chunk-X7Y7WX73.js";
10
- import {
11
- CAPSULE_SCHEMA_VERSION,
12
- EXPORT_FORMAT
13
- } from "./chunk-J4EB7DNW.js";
13
+ } from "./chunk-DQEMWVMT.js";
14
14
  import {
15
15
  DEFAULT_TRANSFER_EXCLUDE_DIRS,
16
16
  computeTransferOutputRel
@@ -261,4 +261,4 @@ export {
261
261
  exportCapsule,
262
262
  isValidCapsuleSince
263
263
  };
264
- //# sourceMappingURL=chunk-KQAFEZQX.js.map
264
+ //# sourceMappingURL=chunk-R45L4TV6.js.map
@@ -8,11 +8,11 @@ import {
8
8
  } from "./chunk-5CO5G4MN.js";
9
9
  import {
10
10
  resolveDefaultNamespaceRoot
11
- } from "./chunk-FV2B6XE6.js";
11
+ } from "./chunk-NRZJKDGO.js";
12
12
  import {
13
13
  StorageManager,
14
14
  readRawMemoryDocument
15
- } from "./chunk-OIOKDTZU.js";
15
+ } from "./chunk-T5DX6A7T.js";
16
16
  import {
17
17
  parseContinuityImprovementLoops
18
18
  } from "./chunk-LDXUBPMO.js";
@@ -1869,4 +1869,4 @@ export {
1869
1869
  defaultTierMigrationCycleBudget,
1870
1870
  CompoundingEngine
1871
1871
  };
1872
- //# sourceMappingURL=chunk-7HNQR5MV.js.map
1872
+ //# sourceMappingURL=chunk-R76L66OW.js.map
@@ -2,7 +2,7 @@ import {
2
2
  WHO_KNOWS_DEFAULT_LIMIT,
3
3
  WHO_KNOWS_MAX_LIMIT,
4
4
  validateWhoKnowsInput
5
- } from "./chunk-7QIRIF3Z.js";
5
+ } from "./chunk-C2KBLOKE.js";
6
6
 
7
7
  // src/who-knows-cli.ts
8
8
  function extractWhoKnowsRawArgs(rest) {
@@ -74,4 +74,4 @@ export {
74
74
  renderWhoKnowsText,
75
75
  renderWhoKnows
76
76
  };
77
- //# sourceMappingURL=chunk-QIGEWFXE.js.map
77
+ //# sourceMappingURL=chunk-RJTHGVO3.js.map
@@ -1,3 +1,9 @@
1
+ import {
2
+ RemoteSearchBackend
3
+ } from "./chunk-OVZIYLBZ.js";
4
+ import {
5
+ EmbedHelper
6
+ } from "./chunk-EXYT52NR.js";
1
7
  import {
2
8
  LanceDbBackend
3
9
  } from "./chunk-DOJBV6WR.js";
@@ -10,12 +16,6 @@ import {
10
16
  import {
11
17
  OramaBackend
12
18
  } from "./chunk-DLZGSZVC.js";
13
- import {
14
- RemoteSearchBackend
15
- } from "./chunk-OVZIYLBZ.js";
16
- import {
17
- EmbedHelper
18
- } from "./chunk-EXYT52NR.js";
19
19
  import {
20
20
  createConversationIndexBackend
21
21
  } from "./chunk-TFA6HPOA.js";
@@ -179,4 +179,4 @@ export {
179
179
  createConversationSearchBackend,
180
180
  createConversationIndexRuntime
181
181
  };
182
- //# sourceMappingURL=chunk-FVMEZ57K.js.map
182
+ //# sourceMappingURL=chunk-RLXD2L3G.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  canonicalCategoryForAlias,
3
3
  categoryAliasCoercion
4
- } from "./chunk-R2DOFBG4.js";
4
+ } from "./chunk-QNTBJKTN.js";
5
5
 
6
6
  // src/access-observe-write-category.ts
7
7
  function splitCanonicalWriteRequest(request) {
@@ -22,4 +22,4 @@ function splitCanonicalWriteRequest(request) {
22
22
  export {
23
23
  splitCanonicalWriteRequest
24
24
  };
25
- //# sourceMappingURL=chunk-25BUV3TU.js.map
25
+ //# sourceMappingURL=chunk-S4G7WX7Q.js.map
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  computeCorpusWatermarks,
6
6
  resolveCorpusNamespaceRoots
7
- } from "./chunk-7SW6EBEF.js";
7
+ } from "./chunk-QYN6I3CG.js";
8
8
 
9
9
  // src/operator-doctor-corpus.ts
10
10
  var DIGEST_PREFIX_LENGTH = 12;
@@ -78,4 +78,4 @@ export {
78
78
  corpusWatermarksFromCheck,
79
79
  summarizeCorpusAndReplica
80
80
  };
81
- //# sourceMappingURL=chunk-BP7LNNWG.js.map
81
+ //# sourceMappingURL=chunk-SMAPUZYV.js.map
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  NamespaceStorageRouter
3
- } from "./chunk-FV2B6XE6.js";
3
+ } from "./chunk-NRZJKDGO.js";
4
4
  import {
5
5
  namespaceCollectionName
6
- } from "./chunk-BUOP3DOK.js";
6
+ } from "./chunk-GRS34Y7V.js";
7
7
  import {
8
8
  isSafeRouteNamespace
9
9
  } from "./chunk-PCXDUHQH.js";
@@ -213,4 +213,4 @@ export {
213
213
  verifyNamespaces,
214
214
  runNamespaceMigration
215
215
  };
216
- //# sourceMappingURL=chunk-GT2TH7FZ.js.map
216
+ //# sourceMappingURL=chunk-T4FW43AG.js.map