@remnic/core 10.0.126 → 10.0.128

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 (178) hide show
  1. package/dist/access-admin-ops-surface.js +38 -38
  2. package/dist/access-cli.js +38 -38
  3. package/dist/access-extraction-force-flush.js +38 -38
  4. package/dist/access-http-briefing.js +38 -38
  5. package/dist/access-http-query.js +38 -38
  6. package/dist/access-http.js +38 -38
  7. package/dist/access-identity-continuity-surface.js +38 -38
  8. package/dist/access-lcm-surface.js +38 -38
  9. package/dist/access-mcp.js +38 -38
  10. package/dist/access-observe-write-surface.js +38 -38
  11. package/dist/access-operations-batch.js +38 -38
  12. package/dist/access-operations.js +38 -38
  13. package/dist/access-recall-concurrency.js +38 -38
  14. package/dist/access-recall-response.js +38 -38
  15. package/dist/access-recall-surface.js +38 -38
  16. package/dist/access-service.d.ts.map +1 -1
  17. package/dist/access-service.js +38 -38
  18. package/dist/active-recall.js +6 -6
  19. package/dist/briefing.js +4 -4
  20. package/dist/buffer-turn-helpers.d.ts +7 -0
  21. package/dist/buffer-turn-helpers.d.ts.map +1 -1
  22. package/dist/buffer-turn-helpers.js +3 -1
  23. package/dist/buffer-turn.d.ts +10 -0
  24. package/dist/buffer-turn.d.ts.map +1 -1
  25. package/dist/buffer.js +3 -3
  26. package/dist/causal-consolidation.js +5 -5
  27. package/dist/{chunk-BNRKSJMO.js → chunk-2BBCM2PX.js} +2 -2
  28. package/dist/{chunk-2GSPNTOU.js → chunk-2G72JBQB.js} +2 -2
  29. package/dist/{chunk-IDCZEKK6.js → chunk-34YQ7CVE.js} +3 -3
  30. package/dist/{chunk-AYWW6JEH.js → chunk-3OLHDECL.js} +115 -41
  31. package/dist/chunk-3OLHDECL.js.map +1 -0
  32. package/dist/{chunk-4VWZ4HPL.js → chunk-4DJSDH2M.js} +6 -6
  33. package/dist/{chunk-YJEOQ72B.js → chunk-6FPJPSQK.js} +2 -2
  34. package/dist/{chunk-YKUW2EZF.js → chunk-7T7I5D3F.js} +2 -2
  35. package/dist/{chunk-ERR7ZFPJ.js → chunk-7TC2PWKH.js} +2 -2
  36. package/dist/{chunk-DH2CDGAE.js → chunk-ALLI23GW.js} +2 -2
  37. package/dist/{chunk-RTIHO7AJ.js → chunk-AYBRQJXP.js} +2 -2
  38. package/dist/{chunk-UXXK523X.js → chunk-BR7CZVMO.js} +20 -16
  39. package/dist/chunk-BR7CZVMO.js.map +1 -0
  40. package/dist/{chunk-AWD36R4D.js → chunk-DURQZFVJ.js} +36 -6
  41. package/dist/chunk-DURQZFVJ.js.map +1 -0
  42. package/dist/{chunk-C7BTGSCY.js → chunk-FPBFDQZZ.js} +9 -9
  43. package/dist/{chunk-5DCCVEKT.js → chunk-GWFL6LUU.js} +2 -2
  44. package/dist/{chunk-JTY3NA3I.js → chunk-HJ7M322C.js} +2 -2
  45. package/dist/{chunk-HURBXNNB.js → chunk-JCPEXUNP.js} +2 -2
  46. package/dist/{chunk-LKGTTX74.js → chunk-JK2IVISS.js} +2 -2
  47. package/dist/{chunk-7XG7KMIW.js → chunk-LNQQEFKH.js} +2 -2
  48. package/dist/{chunk-IB4TDPCC.js → chunk-LR2X3FJM.js} +2 -2
  49. package/dist/{chunk-6IRJWKR5.js → chunk-LU2GQ4Q4.js} +2 -2
  50. package/dist/{chunk-4VCASS3Q.js → chunk-MCTGYIYN.js} +2 -2
  51. package/dist/{chunk-XN43HAIV.js → chunk-MGCV3VGC.js} +2 -2
  52. package/dist/{chunk-KWVGRNKL.js → chunk-NYZ6ZNFO.js} +2 -2
  53. package/dist/{chunk-6VAN7VZR.js → chunk-ORMJT23N.js} +7 -7
  54. package/dist/{chunk-DL7K5PMQ.js → chunk-PPPY2PCU.js} +2 -2
  55. package/dist/{chunk-5DP4GVKR.js → chunk-PXZLVFNC.js} +2 -2
  56. package/dist/{chunk-GSCIRMPR.js → chunk-QKYOMKRG.js} +2 -2
  57. package/dist/{chunk-QF64W4YM.js → chunk-QRZNVNNS.js} +2 -2
  58. package/dist/{chunk-CQMH65IP.js → chunk-TJJPT2OV.js} +2 -2
  59. package/dist/{chunk-2AVPRUML.js → chunk-TJY6AKWV.js} +2 -2
  60. package/dist/{chunk-RRHLI6VU.js → chunk-TQ5NOVMT.js} +2 -2
  61. package/dist/{chunk-KNT3BZZH.js → chunk-UWU6KEZU.js} +185 -59
  62. package/dist/chunk-UWU6KEZU.js.map +1 -0
  63. package/dist/{chunk-PUKLCFCU.js → chunk-VY3DHUL7.js} +2 -2
  64. package/dist/chunk-VY3DHUL7.js.map +1 -0
  65. package/dist/{chunk-47W3ALIS.js → chunk-XMKUABIG.js} +3 -3
  66. package/dist/{chunk-UGCLNASV.js → chunk-XUWDB53W.js} +3 -3
  67. package/dist/{chunk-XLHLZALR.js → chunk-YCJRYM3Q.js} +3 -3
  68. package/dist/{chunk-DB4THCGN.js → chunk-YFUHFPV6.js} +2 -2
  69. package/dist/{chunk-42JE2CF4.js → chunk-YPE3O5VH.js} +2 -2
  70. package/dist/{chunk-7TJMXZPO.js → chunk-ZO377APE.js} +2 -2
  71. package/dist/cli.js +38 -38
  72. package/dist/coding/export-okf-codegraph.js +3 -3
  73. package/dist/compounding/engine.js +5 -5
  74. package/dist/config.js +6 -6
  75. package/dist/connectors/codex-materialize-runner.js +4 -4
  76. package/dist/connectors/index.js +4 -4
  77. package/dist/convergence-refresh.js +6 -6
  78. package/dist/corpus-watermark.js +6 -6
  79. package/dist/entity-retrieval.js +4 -4
  80. package/dist/explicit-capture.js +38 -38
  81. package/dist/extraction-liveness.d.ts +54 -5
  82. package/dist/extraction-liveness.d.ts.map +1 -1
  83. package/dist/extraction-liveness.js +1 -1
  84. package/dist/extraction-span-config.js +2 -2
  85. package/dist/extraction.js +7 -7
  86. package/dist/harmonic-retrieval.js +4 -4
  87. package/dist/index.js +38 -38
  88. package/dist/location/index.js +5 -5
  89. package/dist/maintenance/memory-governance.js +4 -4
  90. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +4 -4
  91. package/dist/maintenance/rebuild-memory-projection-runner.js +6 -6
  92. package/dist/maintenance/rebuild-memory-projection.js +5 -5
  93. package/dist/namespaces/migrate.js +5 -5
  94. package/dist/namespaces/storage.js +4 -4
  95. package/dist/operator-doctor-corpus.js +7 -7
  96. package/dist/operator-toolkit.js +13 -13
  97. package/dist/orchestration/backlog-scheduler.js +39 -39
  98. package/dist/orchestration/buffer-drain-runner.js +39 -39
  99. package/dist/orchestration/extraction-dedupe.d.ts +46 -0
  100. package/dist/orchestration/extraction-dedupe.d.ts.map +1 -0
  101. package/dist/orchestration/extraction-drain.d.ts +12 -1
  102. package/dist/orchestration/extraction-drain.d.ts.map +1 -1
  103. package/dist/orchestration/extraction-run.d.ts.map +1 -1
  104. package/dist/orchestration/maintenance.js +12 -12
  105. package/dist/orchestrator.js +38 -38
  106. package/dist/recall-navigation.js +38 -38
  107. package/dist/resume-bundles.js +7 -7
  108. package/dist/semantic-consolidation.js +5 -5
  109. package/dist/semantic-rule-promotion.js +4 -4
  110. package/dist/semantic-rule-verifier.js +4 -4
  111. package/dist/source-agent-qualifier.js +6 -6
  112. package/dist/standup/build.js +4 -4
  113. package/dist/storage/buffer-drain-claims.d.ts +19 -4
  114. package/dist/storage/buffer-drain-claims.d.ts.map +1 -1
  115. package/dist/storage/buffer-drain-claims.js +2 -2
  116. package/dist/storage/buffer-session-files.js +2 -2
  117. package/dist/storage/drain-claim-totals.d.ts +54 -0
  118. package/dist/storage/drain-claim-totals.d.ts.map +1 -0
  119. package/dist/storage.js +3 -3
  120. package/dist/transfer/export-okf.js +4 -4
  121. package/dist/verified-recall.js +4 -4
  122. package/dist/who-knows-cli.js +5 -5
  123. package/dist/who-knows.js +4 -4
  124. package/package.json +2 -2
  125. package/src/access-service-health.test.ts +102 -1
  126. package/src/access-service.ts +10 -1
  127. package/src/buffer-turn-helpers.ts +25 -15
  128. package/src/buffer-turn.ts +10 -0
  129. package/src/extraction-liveness.test.ts +229 -0
  130. package/src/extraction-liveness.ts +89 -6
  131. package/src/orchestration/extraction-dedupe.test.ts +101 -0
  132. package/src/orchestration/extraction-dedupe.ts +80 -0
  133. package/src/orchestration/extraction-drain-dedupe.test.ts +477 -0
  134. package/src/orchestration/extraction-drain.ts +69 -9
  135. package/src/orchestration/extraction-run.ts +2 -0
  136. package/src/storage/buffer-drain-claims.test.ts +66 -0
  137. package/src/storage/buffer-drain-claims.ts +49 -4
  138. package/src/storage/drain-claim-totals.test.ts +356 -0
  139. package/src/storage/drain-claim-totals.ts +175 -0
  140. package/dist/chunk-AWD36R4D.js.map +0 -1
  141. package/dist/chunk-AYWW6JEH.js.map +0 -1
  142. package/dist/chunk-KNT3BZZH.js.map +0 -1
  143. package/dist/chunk-PUKLCFCU.js.map +0 -1
  144. package/dist/chunk-UXXK523X.js.map +0 -1
  145. /package/dist/{chunk-BNRKSJMO.js.map → chunk-2BBCM2PX.js.map} +0 -0
  146. /package/dist/{chunk-2GSPNTOU.js.map → chunk-2G72JBQB.js.map} +0 -0
  147. /package/dist/{chunk-IDCZEKK6.js.map → chunk-34YQ7CVE.js.map} +0 -0
  148. /package/dist/{chunk-4VWZ4HPL.js.map → chunk-4DJSDH2M.js.map} +0 -0
  149. /package/dist/{chunk-YJEOQ72B.js.map → chunk-6FPJPSQK.js.map} +0 -0
  150. /package/dist/{chunk-YKUW2EZF.js.map → chunk-7T7I5D3F.js.map} +0 -0
  151. /package/dist/{chunk-ERR7ZFPJ.js.map → chunk-7TC2PWKH.js.map} +0 -0
  152. /package/dist/{chunk-DH2CDGAE.js.map → chunk-ALLI23GW.js.map} +0 -0
  153. /package/dist/{chunk-RTIHO7AJ.js.map → chunk-AYBRQJXP.js.map} +0 -0
  154. /package/dist/{chunk-C7BTGSCY.js.map → chunk-FPBFDQZZ.js.map} +0 -0
  155. /package/dist/{chunk-5DCCVEKT.js.map → chunk-GWFL6LUU.js.map} +0 -0
  156. /package/dist/{chunk-JTY3NA3I.js.map → chunk-HJ7M322C.js.map} +0 -0
  157. /package/dist/{chunk-HURBXNNB.js.map → chunk-JCPEXUNP.js.map} +0 -0
  158. /package/dist/{chunk-LKGTTX74.js.map → chunk-JK2IVISS.js.map} +0 -0
  159. /package/dist/{chunk-7XG7KMIW.js.map → chunk-LNQQEFKH.js.map} +0 -0
  160. /package/dist/{chunk-IB4TDPCC.js.map → chunk-LR2X3FJM.js.map} +0 -0
  161. /package/dist/{chunk-6IRJWKR5.js.map → chunk-LU2GQ4Q4.js.map} +0 -0
  162. /package/dist/{chunk-4VCASS3Q.js.map → chunk-MCTGYIYN.js.map} +0 -0
  163. /package/dist/{chunk-XN43HAIV.js.map → chunk-MGCV3VGC.js.map} +0 -0
  164. /package/dist/{chunk-KWVGRNKL.js.map → chunk-NYZ6ZNFO.js.map} +0 -0
  165. /package/dist/{chunk-6VAN7VZR.js.map → chunk-ORMJT23N.js.map} +0 -0
  166. /package/dist/{chunk-DL7K5PMQ.js.map → chunk-PPPY2PCU.js.map} +0 -0
  167. /package/dist/{chunk-5DP4GVKR.js.map → chunk-PXZLVFNC.js.map} +0 -0
  168. /package/dist/{chunk-GSCIRMPR.js.map → chunk-QKYOMKRG.js.map} +0 -0
  169. /package/dist/{chunk-QF64W4YM.js.map → chunk-QRZNVNNS.js.map} +0 -0
  170. /package/dist/{chunk-CQMH65IP.js.map → chunk-TJJPT2OV.js.map} +0 -0
  171. /package/dist/{chunk-2AVPRUML.js.map → chunk-TJY6AKWV.js.map} +0 -0
  172. /package/dist/{chunk-RRHLI6VU.js.map → chunk-TQ5NOVMT.js.map} +0 -0
  173. /package/dist/{chunk-47W3ALIS.js.map → chunk-XMKUABIG.js.map} +0 -0
  174. /package/dist/{chunk-UGCLNASV.js.map → chunk-XUWDB53W.js.map} +0 -0
  175. /package/dist/{chunk-XLHLZALR.js.map → chunk-YCJRYM3Q.js.map} +0 -0
  176. /package/dist/{chunk-DB4THCGN.js.map → chunk-YFUHFPV6.js.map} +0 -0
  177. /package/dist/{chunk-42JE2CF4.js.map → chunk-YPE3O5VH.js.map} +0 -0
  178. /package/dist/{chunk-7TJMXZPO.js.map → chunk-ZO377APE.js.map} +0 -0
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-TBBDFYXW.js";
4
4
  import {
5
5
  StorageManager
6
- } from "./chunk-IB4TDPCC.js";
6
+ } from "./chunk-LR2X3FJM.js";
7
7
  import {
8
8
  requestEntityCanonicalIdReconcile
9
9
  } from "./chunk-O3GZPLVY.js";
@@ -769,4 +769,4 @@ export {
769
769
  listMemoryGovernanceRuns,
770
770
  readMemoryGovernanceRunArtifact
771
771
  };
772
- //# sourceMappingURL=chunk-DL7K5PMQ.js.map
772
+ //# sourceMappingURL=chunk-PPPY2PCU.js.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-B7RWBZXW.js";
4
4
  import {
5
5
  StorageManager
6
- } from "./chunk-IB4TDPCC.js";
6
+ } from "./chunk-LR2X3FJM.js";
7
7
  import {
8
8
  countRecallTokenOverlap,
9
9
  normalizeRecallTokens
@@ -109,4 +109,4 @@ export {
109
109
  compareVerifiedEpisodeResults,
110
110
  searchVerifiedEpisodes
111
111
  };
112
- //# sourceMappingURL=chunk-5DP4GVKR.js.map
112
+ //# sourceMappingURL=chunk-PXZLVFNC.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  runPostConsolidationMaterialize
3
- } from "./chunk-6IRJWKR5.js";
3
+ } from "./chunk-LU2GQ4Q4.js";
4
4
  import {
5
5
  discoverMemoryExtensions,
6
6
  renderExtensionsBlock,
@@ -220,4 +220,4 @@ export {
220
220
  buildExtensionsBlockForConsolidation,
221
221
  materializeAfterSemanticConsolidation
222
222
  };
223
- //# sourceMappingURL=chunk-GSCIRMPR.js.map
223
+ //# sourceMappingURL=chunk-QKYOMKRG.js.map
@@ -8,7 +8,7 @@ import {
8
8
  } from "./chunk-D3ZKHLN2.js";
9
9
  import {
10
10
  deriveSourceConnector
11
- } from "./chunk-PUKLCFCU.js";
11
+ } from "./chunk-VY3DHUL7.js";
12
12
  import {
13
13
  resolvePipelineProcessingCapabilities
14
14
  } from "./chunk-C5LWPYS3.js";
@@ -130,4 +130,4 @@ export {
130
130
  renderExtractionConversation,
131
131
  applyGroundingWithConnector
132
132
  };
133
- //# sourceMappingURL=chunk-QF64W4YM.js.map
133
+ //# sourceMappingURL=chunk-QRZNVNNS.js.map
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-FL3O34XF.js";
12
12
  import {
13
13
  StorageManager
14
- } from "./chunk-IB4TDPCC.js";
14
+ } from "./chunk-LR2X3FJM.js";
15
15
  import {
16
16
  isValidityExpiredNow
17
17
  } from "./chunk-6CIAGZ6X.js";
@@ -552,4 +552,4 @@ export {
552
552
  readProjectedHarmonicGraph,
553
553
  searchHarmonicRetrieval
554
554
  };
555
- //# sourceMappingURL=chunk-CQMH65IP.js.map
555
+ //# sourceMappingURL=chunk-TJJPT2OV.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-JTY3NA3I.js";
5
+ } from "./chunk-HJ7M322C.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-2AVPRUML.js.map
77
+ //# sourceMappingURL=chunk-TJY6AKWV.js.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  parseFrontmatter
3
- } from "./chunk-IB4TDPCC.js";
3
+ } from "./chunk-LR2X3FJM.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-RRHLI6VU.js.map
202
+ //# sourceMappingURL=chunk-TQ5NOVMT.js.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  bufferTurnIdentityKey,
3
3
  subtractBufferTurns
4
- } from "./chunk-UXXK523X.js";
4
+ } from "./chunk-BR7CZVMO.js";
5
5
  import {
6
6
  withHeldFileLock
7
7
  } from "./chunk-EBV6VXKF.js";
@@ -19,10 +19,10 @@ import {
19
19
  // src/storage/buffer-drain-claims.ts
20
20
  import { randomUUID } from "crypto";
21
21
  import { hostname } from "os";
22
- import { z } from "zod";
22
+ import { z as z2 } from "zod";
23
23
  import { existsSync } from "fs";
24
- import { mkdir, readdir as readdir2, readFile, rename, stat, unlink as unlink2, writeFile } from "fs/promises";
25
- import path2 from "path";
24
+ import { mkdir, readdir as readdir3, readFile as readFile2, rename, stat as stat2, unlink as unlink2, writeFile } from "fs/promises";
25
+ import path3 from "path";
26
26
 
27
27
  // src/storage/buffer-session-files.ts
28
28
  import { createHash } from "crypto";
@@ -93,16 +93,16 @@ var BufferSessionFiles = class {
93
93
  */
94
94
  async assertDirSafe() {
95
95
  if (this.dirVerified) return;
96
- let stat2 = null;
96
+ let stat3 = null;
97
97
  try {
98
- stat2 = await lstat(this.dir);
98
+ stat3 = await lstat(this.dir);
99
99
  } catch (err) {
100
100
  if (!(err instanceof Error) || !isMissing(asFsError(err))) throw err;
101
101
  }
102
- if (stat2 && (stat2.isSymbolicLink() || !stat2.isDirectory())) {
102
+ if (stat3 && (stat3.isSymbolicLink() || !stat3.isDirectory())) {
103
103
  throw new Error(`buffer session directory must be a real directory, not a symlink or file: ${this.dir}`);
104
104
  }
105
- this.dirVerified = stat2 !== null;
105
+ this.dirVerified = stat3 !== null;
106
106
  }
107
107
  /** Persist ONE session atomically. Compact JSON: machine-read state, and
108
108
  * pretty-printing a large buffer costs CPU and bytes on every observe.
@@ -304,6 +304,102 @@ var HandInMemo = class {
304
304
  }
305
305
  };
306
306
 
307
+ // src/storage/drain-claim-totals.ts
308
+ import { readdir as readdir2, readFile, stat } from "fs/promises";
309
+ import path2 from "path";
310
+ import { z } from "zod";
311
+ var DEFAULT_MAX_CLAIMS = 4096;
312
+ var CLAIM_BODY_PATTERN = /^s-[0-9a-f]{64}\.json$/;
313
+ var sidecarSchema = z.object({
314
+ size: z.number(),
315
+ mtimeMs: z.number(),
316
+ pending: z.number().nonnegative(),
317
+ oldestTurnAt: z.string().optional()
318
+ });
319
+ function verifiedSidecar(raw, identity) {
320
+ let parsed;
321
+ try {
322
+ parsed = sidecarSchema.parse(JSON.parse(raw));
323
+ } catch {
324
+ return null;
325
+ }
326
+ if (parsed.size !== identity.size || parsed.mtimeMs !== identity.mtimeMs) return null;
327
+ return { pending: parsed.pending, oldestTurnAt: parsed.oldestTurnAt };
328
+ }
329
+ async function readDrainClaimTotals(claimsDir, opts = {}) {
330
+ const totals = {
331
+ claimedSessions: 0,
332
+ claimedPendingTurns: 0,
333
+ oldestClaimedTurnAt: null,
334
+ oldestClaimedAgeBasis: null,
335
+ verifiedSidecars: 0,
336
+ unverifiedClaims: 0,
337
+ claimsPendingInbox: 0,
338
+ truncated: false
339
+ };
340
+ let oldest = null;
341
+ let bodies;
342
+ try {
343
+ bodies = (await readdir2(claimsDir)).filter((name) => CLAIM_BODY_PATTERN.test(name)).sort();
344
+ } catch {
345
+ return totals;
346
+ }
347
+ totals.claimedSessions = bodies.length;
348
+ const maxClaims = opts.maxClaims ?? DEFAULT_MAX_CLAIMS;
349
+ if (bodies.length > maxClaims) {
350
+ totals.truncated = true;
351
+ bodies = bodies.slice(0, maxClaims);
352
+ }
353
+ for (const name of bodies) {
354
+ const bodyPath = path2.join(claimsDir, name);
355
+ let identity;
356
+ try {
357
+ identity = await stat(bodyPath);
358
+ } catch {
359
+ totals.unverifiedClaims += 1;
360
+ continue;
361
+ }
362
+ let raw;
363
+ try {
364
+ raw = await readFile(`${bodyPath}.count`, "utf8");
365
+ } catch {
366
+ totals.unverifiedClaims += 1;
367
+ continue;
368
+ }
369
+ const sidecar = verifiedSidecar(raw, { size: identity.size, mtimeMs: identity.mtimeMs });
370
+ if (sidecar === null) {
371
+ totals.unverifiedClaims += 1;
372
+ continue;
373
+ }
374
+ totals.verifiedSidecars += 1;
375
+ totals.claimedPendingTurns += sidecar.pending;
376
+ const inboxStat = await stat(`${bodyPath}.inbox.jsonl`).catch(() => null);
377
+ const inboxPending = inboxStat !== null && inboxStat.size > 0;
378
+ if (inboxPending) totals.claimsPendingInbox += 1;
379
+ if (sidecar.pending > 0 || inboxPending) {
380
+ const candidates = [];
381
+ if (sidecar.pending > 0) {
382
+ const turnIso = sidecar.oldestTurnAt;
383
+ if (turnIso !== void 0) {
384
+ const turnMs = Date.parse(turnIso);
385
+ if (Number.isFinite(turnMs)) candidates.push({ ms: turnMs, iso: turnIso, basis: "turn" });
386
+ else candidates.push({ ms: identity.mtimeMs, iso: new Date(identity.mtimeMs).toISOString(), basis: "claim-mtime-lower-bound" });
387
+ } else {
388
+ candidates.push({ ms: identity.mtimeMs, iso: new Date(identity.mtimeMs).toISOString(), basis: "claim-mtime-lower-bound" });
389
+ }
390
+ }
391
+ if (inboxPending && inboxStat !== null) {
392
+ candidates.push({ ms: inboxStat.mtimeMs, iso: new Date(inboxStat.mtimeMs).toISOString(), basis: "claim-mtime-lower-bound" });
393
+ }
394
+ const claimOldest = candidates.sort((a, b) => a.ms - b.ms)[0];
395
+ if (claimOldest !== void 0 && (oldest === null || claimOldest.ms < oldest.ms)) oldest = claimOldest;
396
+ }
397
+ }
398
+ totals.oldestClaimedTurnAt = oldest?.iso ?? null;
399
+ totals.oldestClaimedAgeBasis = oldest?.basis ?? null;
400
+ return totals;
401
+ }
402
+
307
403
  // src/storage/buffer-drain-claims.ts
308
404
  var CLAIM_LOCK_STALE_MS = 12e4;
309
405
  var CLAIM_LOCK_MAX_WAIT_MS = 12e4;
@@ -397,23 +493,23 @@ function isLeaseExpired(lease, now = Date.now()) {
397
493
  const heartbeat = Date.parse(lease.heartbeatAt);
398
494
  return !Number.isFinite(heartbeat) || now - heartbeat > lease.leaseMs;
399
495
  }
400
- var claimBodySchema = z.object({
401
- key: z.string().min(1),
402
- entry: z.object({
403
- turns: z.array(z.unknown()),
404
- retainedTurns: z.array(z.unknown()).optional(),
405
- lastExtractionAt: z.string().nullable().optional(),
406
- extractionCount: z.number().optional()
496
+ var claimBodySchema = z2.object({
497
+ key: z2.string().min(1),
498
+ entry: z2.object({
499
+ turns: z2.array(z2.unknown()),
500
+ retainedTurns: z2.array(z2.unknown()).optional(),
501
+ lastExtractionAt: z2.string().nullable().optional(),
502
+ extractionCount: z2.number().optional()
407
503
  }).optional(),
408
- turns: z.array(z.unknown()).optional(),
409
- retainedTurns: z.array(z.unknown()).optional(),
410
- lastExtractionAt: z.string().nullable().optional(),
411
- extractionCount: z.number().optional(),
412
- claimedAt: z.string().optional(),
413
- drained: z.array(z.unknown()).optional(),
414
- drainedRetained: z.array(z.unknown()).optional(),
415
- movedTurns: z.array(z.unknown()).optional(),
416
- foldedRecords: z.array(z.string()).optional()
504
+ turns: z2.array(z2.unknown()).optional(),
505
+ retainedTurns: z2.array(z2.unknown()).optional(),
506
+ lastExtractionAt: z2.string().nullable().optional(),
507
+ extractionCount: z2.number().optional(),
508
+ claimedAt: z2.string().optional(),
509
+ drained: z2.array(z2.unknown()).optional(),
510
+ drainedRetained: z2.array(z2.unknown()).optional(),
511
+ movedTurns: z2.array(z2.unknown()).optional(),
512
+ foldedRecords: z2.array(z2.string()).optional()
417
513
  });
418
514
  function parseBody(raw) {
419
515
  let body;
@@ -448,12 +544,12 @@ function parseBody(raw) {
448
544
  if (body.foldedRecords) claim.foldedRecords = body.foldedRecords;
449
545
  return claim;
450
546
  }
451
- var inboxRecordSchema = z.object({
452
- id: z.string().min(1),
453
- turns: z.array(z.unknown()),
454
- retainedTurns: z.array(z.unknown()).optional(),
455
- lastExtractionAt: z.string().nullable().optional(),
456
- extractionCount: z.number().optional()
547
+ var inboxRecordSchema = z2.object({
548
+ id: z2.string().min(1),
549
+ turns: z2.array(z2.unknown()),
550
+ retainedTurns: z2.array(z2.unknown()).optional(),
551
+ lastExtractionAt: z2.string().nullable().optional(),
552
+ extractionCount: z2.number().optional()
457
553
  });
458
554
  function parseInbox(raw) {
459
555
  const records = [];
@@ -481,20 +577,32 @@ function parseInbox(raw) {
481
577
  function pendingTurns(entry) {
482
578
  return entry.turns.length + (entry.retainedTurns?.length ?? 0);
483
579
  }
484
- var summarySchema = z.object({
485
- key: z.string().min(1),
486
- size: z.number(),
487
- mtimeMs: z.number(),
488
- pending: z.number(),
489
- drained: z.number()
580
+ function oldestTurnTimestamp(turns) {
581
+ let oldest;
582
+ let oldestMs = Number.POSITIVE_INFINITY;
583
+ for (const turn of turns) {
584
+ const parsed = Date.parse(turn.timestamp);
585
+ if (!Number.isFinite(parsed) || parsed >= oldestMs) continue;
586
+ oldestMs = parsed;
587
+ oldest = turn.timestamp;
588
+ }
589
+ return oldest;
590
+ }
591
+ var summarySchema = z2.object({
592
+ key: z2.string().min(1),
593
+ size: z2.number(),
594
+ mtimeMs: z2.number(),
595
+ pending: z2.number(),
596
+ drained: z2.number(),
597
+ oldestTurnAt: z2.string().optional()
490
598
  });
491
- var leaseSchema = z.object({
492
- ownerId: z.string().min(1),
493
- pid: z.number().optional(),
494
- host: z.string().optional(),
495
- acquiredAt: z.string().optional(),
496
- heartbeatAt: z.string(),
497
- leaseMs: z.number()
599
+ var leaseSchema = z2.object({
600
+ ownerId: z2.string().min(1),
601
+ pid: z2.number().optional(),
602
+ host: z2.string().optional(),
603
+ acquiredAt: z2.string().optional(),
604
+ heartbeatAt: z2.string(),
605
+ leaseMs: z2.number()
498
606
  });
499
607
  function parseLease(raw) {
500
608
  let lease;
@@ -520,6 +628,7 @@ var COUNT_SUFFIX = ".count";
520
628
  var INBOX_LISTING_PARSE_LIMIT = 1048576;
521
629
  var INBOX_UNREADABLE_BYTES = 536870888;
522
630
  var LIST_PAGE_SCAN_FACTOR = 8;
631
+ var CLAIM_TOTALS_TTL_MS = 3e4;
523
632
  var BufferDrainClaims = class {
524
633
  constructor(stateDir, io) {
525
634
  this.stateDir = stateDir;
@@ -528,11 +637,27 @@ var BufferDrainClaims = class {
528
637
  stateDir;
529
638
  io;
530
639
  handIns = new HandInMemo();
640
+ /** Last `claimTotals` scan; the /health path polls per request (#3442). */
641
+ totalsCache = null;
642
+ /**
643
+ * Claimed-backlog totals for liveness surfaces (#3442): sidecars only, no
644
+ * claim-body parse, bounded scan, cached for `ttlMs` (default 30s) so a
645
+ * health poll per request cannot turn into a directory storm. `ttlMs: 0`
646
+ * forces a rescan; `nowMs`/`maxClaims` are test/bounds seams.
647
+ */
648
+ async claimTotals(opts = {}) {
649
+ const nowMs = opts.nowMs ?? Date.now();
650
+ const cached = this.totalsCache;
651
+ if (cached !== null && nowMs - cached.atMs < (opts.ttlMs ?? CLAIM_TOTALS_TTL_MS)) return cached.totals;
652
+ const totals = await readDrainClaimTotals(this.dir, { maxClaims: opts.maxClaims });
653
+ this.totalsCache = { atMs: nowMs, totals };
654
+ return totals;
655
+ }
531
656
  get dir() {
532
- return path2.join(this.stateDir, "buffer", "drain");
657
+ return path3.join(this.stateDir, "buffer", "drain");
533
658
  }
534
659
  fileFor(key) {
535
- return path2.join(this.dir, bufferSessionFileName(key));
660
+ return path3.join(this.dir, bufferSessionFileName(key));
536
661
  }
537
662
  leaseFileFor(key) {
538
663
  return `${this.fileFor(key)}.lease.json`;
@@ -601,7 +726,7 @@ var BufferDrainClaims = class {
601
726
  const bodyPath = this.fileFor(key);
602
727
  const foldedRecords = consumed.length > 0 ? [...consumed] : void 0;
603
728
  await this.io.write(bodyPath, JSON.stringify({ ...claim, key, foldedRecords }));
604
- await stat(bodyPath).then((identity) => this.writeSummary(bodyPath, claim, identity), () => {
729
+ await stat2(bodyPath).then((identity) => this.writeSummary(bodyPath, claim, identity), () => {
605
730
  });
606
731
  await unlink2(this.inboxFor(key)).catch(() => {
607
732
  });
@@ -618,7 +743,8 @@ var BufferDrainClaims = class {
618
743
  size: identity.size,
619
744
  mtimeMs: identity.mtimeMs,
620
745
  pending: pendingTurns(claim.entry),
621
- drained: (claim.drained?.length ?? 0) + (claim.drainedRetained?.length ?? 0)
746
+ drained: (claim.drained?.length ?? 0) + (claim.drainedRetained?.length ?? 0),
747
+ oldestTurnAt: oldestTurnTimestamp([...claim.entry.turns, ...claim.entry.retainedTurns ?? []])
622
748
  };
623
749
  try {
624
750
  await writeFile(`${bodyPath}${COUNT_SUFFIX}`, JSON.stringify(summary));
@@ -636,12 +762,12 @@ var BufferDrainClaims = class {
636
762
  async readSummary(bodyPath) {
637
763
  let identity;
638
764
  try {
639
- identity = await stat(bodyPath);
765
+ identity = await stat2(bodyPath);
640
766
  } catch {
641
767
  return null;
642
768
  }
643
769
  try {
644
- const cached = summarySchema.parse(JSON.parse(await readFile(`${bodyPath}${COUNT_SUFFIX}`, "utf8")));
770
+ const cached = summarySchema.parse(JSON.parse(await readFile2(`${bodyPath}${COUNT_SUFFIX}`, "utf8")));
645
771
  if (cached.size === identity.size && cached.mtimeMs === identity.mtimeMs) return cached;
646
772
  } catch {
647
773
  }
@@ -649,7 +775,7 @@ var BufferDrainClaims = class {
649
775
  try {
650
776
  claim = parseBody(await this.io.read(bodyPath));
651
777
  } catch (err) {
652
- log.debug(`buffer drain: skipping unreadable claim file ${path2.basename(bodyPath)}: ${err instanceof Error ? err.message : String(err)}`);
778
+ log.debug(`buffer drain: skipping unreadable claim file ${path3.basename(bodyPath)}: ${err instanceof Error ? err.message : String(err)}`);
653
779
  return null;
654
780
  }
655
781
  return claim ? await this.writeSummary(bodyPath, claim, identity) : null;
@@ -677,7 +803,7 @@ var BufferDrainClaims = class {
677
803
  */
678
804
  async claimFromSessionFile(key, lease) {
679
805
  await mkdir(this.dir, { recursive: true });
680
- const sessionPath = path2.join(this.stateDir, "buffer", bufferSessionFileName(key));
806
+ const sessionPath = path3.join(this.stateDir, "buffer", bufferSessionFileName(key));
681
807
  if (existsSync(sessionPath)) {
682
808
  try {
683
809
  const seeded = parseBody(await this.io.read(sessionPath));
@@ -710,7 +836,7 @@ var BufferDrainClaims = class {
710
836
  });
711
837
  return "empty";
712
838
  }
713
- await stat(this.fileFor(key)).then((identity) => this.writeSummary(this.fileFor(key), claim, identity), () => {
839
+ await stat2(this.fileFor(key)).then((identity) => this.writeSummary(this.fileFor(key), claim, identity), () => {
714
840
  });
715
841
  await this.writeLease(key, lease);
716
842
  return "claimed";
@@ -757,7 +883,7 @@ var BufferDrainClaims = class {
757
883
  /** The inbox as this process last left it (identity, size, mtime); "absent" when there is none, null when unknown. */
758
884
  async handInStamp(key) {
759
885
  try {
760
- const inbox = await stat(this.inboxFor(key));
886
+ const inbox = await stat2(this.inboxFor(key));
761
887
  return `${inbox.ino}:${inbox.size}:${inbox.mtimeMs}`;
762
888
  } catch (err) {
763
889
  return isErrnoCode(err, "ENOENT") ? "absent" : null;
@@ -986,7 +1112,7 @@ ${JSON.stringify({ id: randomUUID(), key, ...plan.record })}`);
986
1112
  /** Claim body file names in the drain directory (no leases, inboxes, summaries or locks). */
987
1113
  async claimNames() {
988
1114
  try {
989
- return (await readdir2(this.dir)).filter((name) => name.endsWith(".json") && !name.endsWith(".lease.json")).sort();
1115
+ return (await readdir3(this.dir)).filter((name) => name.endsWith(".json") && !name.endsWith(".lease.json")).sort();
990
1116
  } catch (err) {
991
1117
  if (err?.code === "ENOENT") return null;
992
1118
  throw err;
@@ -1000,11 +1126,11 @@ ${JSON.stringify({ id: randomUUID(), key, ...plan.record })}`);
1000
1126
  * inbox, so an over-count costs one cheap drain run, never a lost turn.
1001
1127
  */
1002
1128
  async describeClaim(name) {
1003
- const summary = await this.readSummary(path2.join(this.dir, name));
1129
+ const summary = await this.readSummary(path3.join(this.dir, name));
1004
1130
  if (!summary) return null;
1005
1131
  let inboxTurns = 0;
1006
1132
  try {
1007
- const inboxBytes = (await stat(this.inboxFor(summary.key)).catch(() => null))?.size ?? 0;
1133
+ const inboxBytes = (await stat2(this.inboxFor(summary.key)).catch(() => null))?.size ?? 0;
1008
1134
  if (inboxBytes > INBOX_UNREADABLE_BYTES) throw new Error(`inbox is ${inboxBytes} bytes, too long to read`);
1009
1135
  if (inboxBytes <= INBOX_LISTING_PARSE_LIMIT) {
1010
1136
  for (const record of await this.readInbox(summary.key)) inboxTurns += pendingTurns(record.entry);
@@ -1071,7 +1197,7 @@ ${JSON.stringify({ id: randomUUID(), key, ...plan.record })}`);
1071
1197
  async foldAllInboxes() {
1072
1198
  let names;
1073
1199
  try {
1074
- names = (await readdir2(this.dir)).filter((name) => name.endsWith(INBOX_SUFFIX));
1200
+ names = (await readdir3(this.dir)).filter((name) => name.endsWith(INBOX_SUFFIX));
1075
1201
  } catch (err) {
1076
1202
  if (isErrnoCode(err, "ENOENT")) return 0;
1077
1203
  throw err;
@@ -1101,7 +1227,7 @@ ${JSON.stringify({ id: randomUUID(), key, ...plan.record })}`);
1101
1227
  }
1102
1228
  async readClaimBodyByName(name) {
1103
1229
  try {
1104
- return parseBody(await this.io.read(path2.join(this.dir, name)));
1230
+ return parseBody(await this.io.read(path3.join(this.dir, name)));
1105
1231
  } catch (err) {
1106
1232
  log.debug(`buffer drain: skipping unreadable claim file ${name}: ${err instanceof Error ? err.message : String(err)}`);
1107
1233
  return null;
@@ -1115,4 +1241,4 @@ export {
1115
1241
  legacyStateToEntries,
1116
1242
  BufferSessionFiles
1117
1243
  };
1118
- //# sourceMappingURL=chunk-KNT3BZZH.js.map
1244
+ //# sourceMappingURL=chunk-UWU6KEZU.js.map