@remnic/core 9.67.0 → 9.68.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/dist/access-admin-ops-surface.d.ts +1 -1
  2. package/dist/access-admin-ops-surface.js +26 -26
  3. package/dist/access-audit.js +2 -2
  4. package/dist/access-authorization-probe.d.ts +1 -1
  5. package/dist/access-authorization-probe.js +27 -27
  6. package/dist/access-boundary.d.ts +1 -1
  7. package/dist/access-boundary.js +26 -26
  8. package/dist/access-cli.js +87 -87
  9. package/dist/access-extraction-force-flush.d.ts +1 -1
  10. package/dist/access-extraction-force-flush.js +26 -26
  11. package/dist/access-http-lcm-compaction.d.ts +1 -1
  12. package/dist/access-http-lifecycle-flush.d.ts +1 -1
  13. package/dist/access-http-offline-stream.d.ts +1 -1
  14. package/dist/access-http-query.js +28 -28
  15. package/dist/access-http.d.ts +2 -2
  16. package/dist/access-http.js +44 -44
  17. package/dist/access-identity-continuity-surface.js +26 -26
  18. package/dist/access-lcm-surface.d.ts +1 -1
  19. package/dist/access-lcm-surface.js +26 -26
  20. package/dist/access-mcp.d.ts +1 -1
  21. package/dist/access-mcp.js +34 -34
  22. package/dist/access-namespace-preflight.js +26 -26
  23. package/dist/access-observe-write-surface.d.ts +1 -1
  24. package/dist/access-observe-write-surface.js +26 -26
  25. package/dist/access-operations-batch.js +28 -28
  26. package/dist/access-operations.d.ts +6 -6
  27. package/dist/access-operations.js +33 -33
  28. package/dist/access-recall-concurrency.d.ts +1 -1
  29. package/dist/access-recall-concurrency.js +26 -26
  30. package/dist/access-recall-response.d.ts +1 -1
  31. package/dist/access-recall-response.js +26 -26
  32. package/dist/access-recall-surface.d.ts +1 -1
  33. package/dist/access-recall-surface.js +26 -26
  34. package/dist/access-schema.d.ts +89 -89
  35. package/dist/access-schema.js +3 -3
  36. package/dist/access-service-helpers.d.ts +1 -1
  37. package/dist/access-service.d.ts +1 -1
  38. package/dist/access-service.js +26 -26
  39. package/dist/access-surface-catalog.d.ts +1 -1
  40. package/dist/access-surface-catalog.js +28 -28
  41. package/dist/adapters/index.js +7 -7
  42. package/dist/adapters/registry.js +3 -3
  43. package/dist/briefing.js +11 -11
  44. package/dist/{capsule-crypto-GWVG7LGC.js → capsule-crypto-7FJQINUR.js} +2 -2
  45. package/dist/causal-consolidation.js +12 -12
  46. package/dist/{chunk-LEPOP46W.js → chunk-227UFSEQ.js} +4 -4
  47. package/dist/{chunk-FJP6MVRK.js → chunk-25P3LW6U.js} +2 -2
  48. package/dist/{chunk-JKXPFIPC.js → chunk-2MHMHF76.js} +2 -2
  49. package/dist/{chunk-OWHERGF2.js → chunk-2NLLXCJG.js} +2 -2
  50. package/dist/{chunk-QMIKXIAM.js → chunk-327JMA2N.js} +2 -2
  51. package/dist/{chunk-H6VYVOVP.js → chunk-363VZTVH.js} +2 -2
  52. package/dist/{chunk-PKRYQ222.js → chunk-3IRH5MYM.js} +6 -6
  53. package/dist/{chunk-GEHEBLVY.js → chunk-4PEZMGZD.js} +2 -2
  54. package/dist/{chunk-EU5PDHU2.js → chunk-4PMPOZK3.js} +2 -2
  55. package/dist/{chunk-6SRUPUTY.js → chunk-52GQNSLC.js} +5 -5
  56. package/dist/{chunk-SV3MDTJI.js → chunk-5UI7WQA6.js} +2 -2
  57. package/dist/{chunk-JGXMA6HL.js → chunk-6FUMA6AA.js} +2 -2
  58. package/dist/{chunk-TVVEYCNW.js → chunk-7K5Q6COX.js} +4 -4
  59. package/dist/{chunk-WGVAEVT7.js → chunk-7KG5V4VV.js} +2 -2
  60. package/dist/{chunk-A6HVSRGM.js → chunk-A7NMS5II.js} +3 -3
  61. package/dist/{chunk-M3BFW3VX.js → chunk-ABPCF4MW.js} +1 -1
  62. package/dist/{chunk-NNBZS3DY.js → chunk-AG46P24C.js} +4 -4
  63. package/dist/{chunk-I7FVQMAA.js → chunk-BGD3T743.js} +2 -2
  64. package/dist/{chunk-QRHKJT7F.js → chunk-BHH736UQ.js} +4 -4
  65. package/dist/{chunk-4L7OKRGP.js → chunk-BS5BD3DF.js} +2 -2
  66. package/dist/{chunk-BT7AQZQX.js → chunk-BTRY6UH3.js} +2 -2
  67. package/dist/{chunk-BE4Y6GK6.js → chunk-D35XLYQ7.js} +11 -11
  68. package/dist/{chunk-CJTZO5MW.js → chunk-D6Q5EPOV.js} +2 -2
  69. package/dist/{chunk-6KGBI54C.js → chunk-DJ7TZLGU.js} +2 -2
  70. package/dist/{chunk-IDPFBRPJ.js → chunk-ERKFG4RV.js} +38 -38
  71. package/dist/{chunk-K7VTD5AZ.js → chunk-F25CL3IQ.js} +2 -2
  72. package/dist/{chunk-QZPSIQRB.js → chunk-FOT5GP2U.js} +2 -2
  73. package/dist/{chunk-OMA2B7GY.js → chunk-HACVBEAP.js} +2 -2
  74. package/dist/{chunk-IEZ6CGTW.js → chunk-HCM7ZYJD.js} +2 -2
  75. package/dist/{chunk-46XRYYOJ.js → chunk-HDQQRRCZ.js} +3 -3
  76. package/dist/{chunk-QXDICB4J.js → chunk-I6T4SYFW.js} +3 -3
  77. package/dist/{chunk-HQJM3BKH.js → chunk-J2R275FN.js} +2 -2
  78. package/dist/{chunk-STUPJFG7.js → chunk-KAY2C6VX.js} +2 -2
  79. package/dist/{chunk-I3X5NWDU.js → chunk-KJUH3QIQ.js} +2 -2
  80. package/dist/{chunk-BUKK5SWA.js → chunk-KQAFEZQX.js} +2 -2
  81. package/dist/{chunk-KZAN4JXY.js → chunk-KRNFJKMH.js} +2 -2
  82. package/dist/{chunk-SBUQ4KIE.js → chunk-L7MJJAG2.js} +2 -2
  83. package/dist/{chunk-IVKIODHO.js → chunk-MB6GLPRY.js} +4 -4
  84. package/dist/{chunk-NROLO2HY.js → chunk-ND6NL2YR.js} +2 -2
  85. package/dist/{chunk-O2HDDAUM.js → chunk-NFITGYMQ.js} +3 -3
  86. package/dist/{chunk-GRZYF6KK.js → chunk-NYQHD7H4.js} +12 -12
  87. package/dist/{chunk-REJCULWA.js → chunk-P342D5BP.js} +2 -2
  88. package/dist/{chunk-HGRRJDUH.js → chunk-PIBQIYF2.js} +2 -2
  89. package/dist/{chunk-UUGU26P2.js → chunk-QOE3EM5Z.js} +2 -2
  90. package/dist/{chunk-N37X5RU7.js → chunk-RACZB5HT.js} +4 -4
  91. package/dist/{chunk-AU7Q3LSC.js → chunk-RKNJBZ55.js} +7 -7
  92. package/dist/{chunk-F3H7VNM4.js → chunk-USQAH6PN.js} +2 -2
  93. package/dist/{chunk-ZFE7NXB7.js → chunk-VLSUKXCJ.js} +4 -4
  94. package/dist/{chunk-QJLTAH5X.js → chunk-WFFGUFFN.js} +152 -43
  95. package/dist/chunk-WFFGUFFN.js.map +1 -0
  96. package/dist/{chunk-YWD5UIWY.js → chunk-WQCET3N3.js} +2 -2
  97. package/dist/{chunk-MUYJQ273.js → chunk-WSYACIKD.js} +2 -2
  98. package/dist/{chunk-UVYI6VIX.js → chunk-X7Y7WX73.js} +1 -1
  99. package/dist/{chunk-AWMS3IFB.js → chunk-XPDWNWH6.js} +3 -3
  100. package/dist/{chunk-K5JFIA44.js → chunk-XW3G4BJI.js} +7 -7
  101. package/dist/{chunk-GIC6BASP.js → chunk-XZBXINXZ.js} +4 -4
  102. package/dist/{chunk-KDCPIXIY.js → chunk-YFK64FYK.js} +2 -2
  103. package/dist/{chunk-DDAHG5ZD.js → chunk-YYAWJRGL.js} +2 -2
  104. package/dist/{chunk-IYFL3534.js → chunk-Z2FXSE5P.js} +2 -2
  105. package/dist/{chunk-CR73YTWC.js → chunk-ZDJMCXC7.js} +11 -11
  106. package/dist/{chunk-OQT34EVH.js → chunk-ZVW724ZK.js} +2 -2
  107. package/dist/{cli-CFpMhqz5.d.ts → cli-Bvy4jdBu.d.ts} +1 -1
  108. package/dist/cli.d.ts +2 -2
  109. package/dist/cli.js +63 -63
  110. package/dist/coding/export-okf-codegraph.js +11 -11
  111. package/dist/compounding/engine.js +11 -11
  112. package/dist/connectors/codex-materialize-runner.js +11 -11
  113. package/dist/connectors/index.js +11 -11
  114. package/dist/convergence-refresh.js +13 -13
  115. package/dist/conversation-index/backend.js +2 -2
  116. package/dist/corpus-watermark.js +13 -13
  117. package/dist/entity-retrieval.js +11 -11
  118. package/dist/external-wiki-access.d.ts +1 -1
  119. package/dist/external-wiki-access.js +27 -27
  120. package/dist/external-wiki-mcp-tools.d.ts +1 -1
  121. package/dist/extraction-span-gate.d.ts +31 -0
  122. package/dist/extraction-span-gate.js +37 -0
  123. package/dist/extraction-span-gate.js.map +1 -0
  124. package/dist/extraction.js +14 -14
  125. package/dist/harmonic-retrieval.js +1 -1
  126. package/dist/index.d.ts +727 -681
  127. package/dist/index.js +106 -100
  128. package/dist/lcm/index.js +3 -3
  129. package/dist/local-llm.js +2 -2
  130. package/dist/location/index.js +13 -13
  131. package/dist/maintenance/memory-governance.js +11 -11
  132. package/dist/maintenance/rebuild-memory-lifecycle-ledger.js +11 -11
  133. package/dist/maintenance/rebuild-memory-projection.js +12 -12
  134. package/dist/mcp-memory-inspector-app.d.ts +1 -1
  135. package/dist/memory-subject-cli.d.ts +1 -1
  136. package/dist/memory-subject.d.ts +1 -1
  137. package/dist/namespaces/migrate.js +12 -12
  138. package/dist/namespaces/search.js +9 -9
  139. package/dist/namespaces/storage.js +11 -11
  140. package/dist/operator-doctor-corpus.js +14 -14
  141. package/dist/operator-toolkit.js +19 -19
  142. package/dist/orchestration/maintenance.js +19 -19
  143. package/dist/orchestrator.js +87 -87
  144. package/dist/{public-http-C9-CHc40.d.ts → public-http-2MyshWxl.d.ts} +1 -1
  145. package/dist/recall-navigate-window.d.ts +26 -0
  146. package/dist/recall-navigate-window.js +32 -0
  147. package/dist/recall-navigate-window.js.map +1 -0
  148. package/dist/schemas.d.ts +176 -176
  149. package/dist/search/factory.js +8 -8
  150. package/dist/search/index.js +13 -13
  151. package/dist/search/lancedb-backend.js +2 -2
  152. package/dist/search/meilisearch-backend.js +2 -2
  153. package/dist/search/orama-backend.js +2 -2
  154. package/dist/semantic-consolidation.js +12 -12
  155. package/dist/semantic-rule-promotion.js +11 -11
  156. package/dist/semantic-rule-verifier.js +11 -11
  157. package/dist/shared-context/manager.d.ts +6 -6
  158. package/dist/source-agent-qualifier.js +11 -11
  159. package/dist/standup/build.js +11 -11
  160. package/dist/storage.js +10 -10
  161. package/dist/summarizer.js +3 -3
  162. package/dist/support-passport/index.d.ts +4 -4
  163. package/dist/support-passport/index.js +29 -29
  164. package/dist/transfer/backup.js +2 -2
  165. package/dist/transfer/capsule-export.js +2 -2
  166. package/dist/transfer/capsule-import.js +2 -2
  167. package/dist/transfer/export-okf.js +12 -12
  168. package/dist/transfer/types.d.ts +78 -78
  169. package/dist/verified-recall.js +11 -11
  170. package/dist/who-knows-cli.d.ts +1 -1
  171. package/dist/who-knows-cli.js +12 -12
  172. package/dist/who-knows.d.ts +1 -1
  173. package/dist/who-knows.js +11 -11
  174. package/package.json +2 -2
  175. package/src/activity/index.ts +1 -0
  176. package/src/activity/privacy-delete-plan.test.ts +215 -0
  177. package/src/activity/privacy-delete-plan.ts +116 -0
  178. package/src/activity/timeline/index.ts +1 -0
  179. package/src/activity/timeline/recap-merge-edits.test.ts +181 -0
  180. package/src/activity/timeline/recap-merge-edits.ts +70 -0
  181. package/src/extraction-span-gate.test.ts +202 -0
  182. package/src/extraction-span-gate.ts +58 -0
  183. package/src/recall-navigate-window.test.ts +104 -0
  184. package/src/recall-navigate-window.ts +48 -0
  185. package/src/shared-context/supersession-chain.test.ts +158 -0
  186. package/src/shared-context/supersession-chain.ts +95 -0
  187. package/dist/chunk-QJLTAH5X.js.map +0 -1
  188. package/dist/{access-service-DcfM0Vf0.d.ts → access-service-LbwWl05g.d.ts} +64 -64
  189. /package/dist/{capsule-crypto-GWVG7LGC.js.map → capsule-crypto-7FJQINUR.js.map} +0 -0
  190. /package/dist/{chunk-LEPOP46W.js.map → chunk-227UFSEQ.js.map} +0 -0
  191. /package/dist/{chunk-FJP6MVRK.js.map → chunk-25P3LW6U.js.map} +0 -0
  192. /package/dist/{chunk-JKXPFIPC.js.map → chunk-2MHMHF76.js.map} +0 -0
  193. /package/dist/{chunk-OWHERGF2.js.map → chunk-2NLLXCJG.js.map} +0 -0
  194. /package/dist/{chunk-QMIKXIAM.js.map → chunk-327JMA2N.js.map} +0 -0
  195. /package/dist/{chunk-H6VYVOVP.js.map → chunk-363VZTVH.js.map} +0 -0
  196. /package/dist/{chunk-PKRYQ222.js.map → chunk-3IRH5MYM.js.map} +0 -0
  197. /package/dist/{chunk-GEHEBLVY.js.map → chunk-4PEZMGZD.js.map} +0 -0
  198. /package/dist/{chunk-EU5PDHU2.js.map → chunk-4PMPOZK3.js.map} +0 -0
  199. /package/dist/{chunk-6SRUPUTY.js.map → chunk-52GQNSLC.js.map} +0 -0
  200. /package/dist/{chunk-SV3MDTJI.js.map → chunk-5UI7WQA6.js.map} +0 -0
  201. /package/dist/{chunk-JGXMA6HL.js.map → chunk-6FUMA6AA.js.map} +0 -0
  202. /package/dist/{chunk-TVVEYCNW.js.map → chunk-7K5Q6COX.js.map} +0 -0
  203. /package/dist/{chunk-WGVAEVT7.js.map → chunk-7KG5V4VV.js.map} +0 -0
  204. /package/dist/{chunk-A6HVSRGM.js.map → chunk-A7NMS5II.js.map} +0 -0
  205. /package/dist/{chunk-M3BFW3VX.js.map → chunk-ABPCF4MW.js.map} +0 -0
  206. /package/dist/{chunk-NNBZS3DY.js.map → chunk-AG46P24C.js.map} +0 -0
  207. /package/dist/{chunk-I7FVQMAA.js.map → chunk-BGD3T743.js.map} +0 -0
  208. /package/dist/{chunk-QRHKJT7F.js.map → chunk-BHH736UQ.js.map} +0 -0
  209. /package/dist/{chunk-4L7OKRGP.js.map → chunk-BS5BD3DF.js.map} +0 -0
  210. /package/dist/{chunk-BT7AQZQX.js.map → chunk-BTRY6UH3.js.map} +0 -0
  211. /package/dist/{chunk-BE4Y6GK6.js.map → chunk-D35XLYQ7.js.map} +0 -0
  212. /package/dist/{chunk-CJTZO5MW.js.map → chunk-D6Q5EPOV.js.map} +0 -0
  213. /package/dist/{chunk-6KGBI54C.js.map → chunk-DJ7TZLGU.js.map} +0 -0
  214. /package/dist/{chunk-IDPFBRPJ.js.map → chunk-ERKFG4RV.js.map} +0 -0
  215. /package/dist/{chunk-K7VTD5AZ.js.map → chunk-F25CL3IQ.js.map} +0 -0
  216. /package/dist/{chunk-QZPSIQRB.js.map → chunk-FOT5GP2U.js.map} +0 -0
  217. /package/dist/{chunk-OMA2B7GY.js.map → chunk-HACVBEAP.js.map} +0 -0
  218. /package/dist/{chunk-IEZ6CGTW.js.map → chunk-HCM7ZYJD.js.map} +0 -0
  219. /package/dist/{chunk-46XRYYOJ.js.map → chunk-HDQQRRCZ.js.map} +0 -0
  220. /package/dist/{chunk-QXDICB4J.js.map → chunk-I6T4SYFW.js.map} +0 -0
  221. /package/dist/{chunk-HQJM3BKH.js.map → chunk-J2R275FN.js.map} +0 -0
  222. /package/dist/{chunk-STUPJFG7.js.map → chunk-KAY2C6VX.js.map} +0 -0
  223. /package/dist/{chunk-I3X5NWDU.js.map → chunk-KJUH3QIQ.js.map} +0 -0
  224. /package/dist/{chunk-BUKK5SWA.js.map → chunk-KQAFEZQX.js.map} +0 -0
  225. /package/dist/{chunk-KZAN4JXY.js.map → chunk-KRNFJKMH.js.map} +0 -0
  226. /package/dist/{chunk-SBUQ4KIE.js.map → chunk-L7MJJAG2.js.map} +0 -0
  227. /package/dist/{chunk-IVKIODHO.js.map → chunk-MB6GLPRY.js.map} +0 -0
  228. /package/dist/{chunk-NROLO2HY.js.map → chunk-ND6NL2YR.js.map} +0 -0
  229. /package/dist/{chunk-O2HDDAUM.js.map → chunk-NFITGYMQ.js.map} +0 -0
  230. /package/dist/{chunk-GRZYF6KK.js.map → chunk-NYQHD7H4.js.map} +0 -0
  231. /package/dist/{chunk-REJCULWA.js.map → chunk-P342D5BP.js.map} +0 -0
  232. /package/dist/{chunk-HGRRJDUH.js.map → chunk-PIBQIYF2.js.map} +0 -0
  233. /package/dist/{chunk-UUGU26P2.js.map → chunk-QOE3EM5Z.js.map} +0 -0
  234. /package/dist/{chunk-N37X5RU7.js.map → chunk-RACZB5HT.js.map} +0 -0
  235. /package/dist/{chunk-AU7Q3LSC.js.map → chunk-RKNJBZ55.js.map} +0 -0
  236. /package/dist/{chunk-F3H7VNM4.js.map → chunk-USQAH6PN.js.map} +0 -0
  237. /package/dist/{chunk-ZFE7NXB7.js.map → chunk-VLSUKXCJ.js.map} +0 -0
  238. /package/dist/{chunk-YWD5UIWY.js.map → chunk-WQCET3N3.js.map} +0 -0
  239. /package/dist/{chunk-MUYJQ273.js.map → chunk-WSYACIKD.js.map} +0 -0
  240. /package/dist/{chunk-UVYI6VIX.js.map → chunk-X7Y7WX73.js.map} +0 -0
  241. /package/dist/{chunk-AWMS3IFB.js.map → chunk-XPDWNWH6.js.map} +0 -0
  242. /package/dist/{chunk-K5JFIA44.js.map → chunk-XW3G4BJI.js.map} +0 -0
  243. /package/dist/{chunk-GIC6BASP.js.map → chunk-XZBXINXZ.js.map} +0 -0
  244. /package/dist/{chunk-KDCPIXIY.js.map → chunk-YFK64FYK.js.map} +0 -0
  245. /package/dist/{chunk-DDAHG5ZD.js.map → chunk-YYAWJRGL.js.map} +0 -0
  246. /package/dist/{chunk-IYFL3534.js.map → chunk-Z2FXSE5P.js.map} +0 -0
  247. /package/dist/{chunk-CR73YTWC.js.map → chunk-ZDJMCXC7.js.map} +0 -0
  248. /package/dist/{chunk-OQT34EVH.js.map → chunk-ZVW724ZK.js.map} +0 -0
@@ -0,0 +1,202 @@
1
+ import assert from "node:assert/strict";
2
+ import { describe, it } from "node:test";
3
+
4
+ import {
5
+ evaluateSpanPhaseGate,
6
+ SPAN_GATE_MAX_FALLBACK_RATE_PCT,
7
+ SPAN_GATE_MAX_JUDGE_DROP_POINTS,
8
+ SPAN_GATE_MIN_WALLCLOCK_REDUCTION_PCT,
9
+ } from "./extraction-span-gate.js";
10
+
11
+ function assertRangeError(fn: () => unknown, field: string): void {
12
+ assert.throws(fn, (err: unknown) => {
13
+ assert.ok(err instanceof RangeError, `expected RangeError, got ${String(err)}`);
14
+ assert.match((err as RangeError).message, new RegExp(field));
15
+ return true;
16
+ });
17
+ }
18
+
19
+ describe("evaluateSpanPhaseGate", () => {
20
+ it("passes the Phase A bench numbers from the issue", () => {
21
+ const verdict = evaluateSpanPhaseGate({
22
+ wallClockReductionPct: 45,
23
+ judgeScoreDropPoints: 0.3,
24
+ fallbackRatePct: 4,
25
+ });
26
+ assert.deepEqual(verdict, {
27
+ pass: true,
28
+ conditions: { wallClockReduction: true, judgeQuality: true, fallbackRate: true },
29
+ failed: [],
30
+ });
31
+ });
32
+
33
+ it("treats the wall-clock boundary 20.0 as a pass (>= 20)", () => {
34
+ const verdict = evaluateSpanPhaseGate({
35
+ wallClockReductionPct: SPAN_GATE_MIN_WALLCLOCK_REDUCTION_PCT,
36
+ judgeScoreDropPoints: 0,
37
+ fallbackRatePct: 0,
38
+ });
39
+ assert.equal(verdict.conditions.wallClockReduction, true);
40
+ });
41
+
42
+ it("treats a judge drop of exactly 2.0 as a failure (< 2)", () => {
43
+ const verdict = evaluateSpanPhaseGate({
44
+ wallClockReductionPct: 45,
45
+ judgeScoreDropPoints: SPAN_GATE_MAX_JUDGE_DROP_POINTS,
46
+ fallbackRatePct: 4,
47
+ });
48
+ assert.equal(verdict.pass, false);
49
+ assert.deepEqual(verdict.failed, ["judgeQuality"]);
50
+ });
51
+
52
+ it("treats a fallback rate of exactly 15.0 as a failure (< 15)", () => {
53
+ const verdict = evaluateSpanPhaseGate({
54
+ wallClockReductionPct: 45,
55
+ judgeScoreDropPoints: 0.3,
56
+ fallbackRatePct: SPAN_GATE_MAX_FALLBACK_RATE_PCT,
57
+ });
58
+ assert.equal(verdict.pass, false);
59
+ assert.deepEqual(verdict.failed, ["fallbackRate"]);
60
+ });
61
+
62
+ it("fails on wall-clock reduction alone", () => {
63
+ const verdict = evaluateSpanPhaseGate({
64
+ wallClockReductionPct: 19.9,
65
+ judgeScoreDropPoints: 0.3,
66
+ fallbackRatePct: 4,
67
+ });
68
+ assert.equal(verdict.pass, false);
69
+ assert.deepEqual(verdict.failed, ["wallClockReduction"]);
70
+ });
71
+
72
+ it("fails on judge quality alone", () => {
73
+ const verdict = evaluateSpanPhaseGate({
74
+ wallClockReductionPct: 45,
75
+ judgeScoreDropPoints: 2.5,
76
+ fallbackRatePct: 4,
77
+ });
78
+ assert.equal(verdict.pass, false);
79
+ assert.deepEqual(verdict.failed, ["judgeQuality"]);
80
+ });
81
+
82
+ it("fails on fallback rate alone", () => {
83
+ const verdict = evaluateSpanPhaseGate({
84
+ wallClockReductionPct: 45,
85
+ judgeScoreDropPoints: 0.3,
86
+ fallbackRatePct: 15.1,
87
+ });
88
+ assert.equal(verdict.pass, false);
89
+ assert.deepEqual(verdict.failed, ["fallbackRate"]);
90
+ });
91
+
92
+ it("lists all three failures in declaration order", () => {
93
+ const verdict = evaluateSpanPhaseGate({
94
+ wallClockReductionPct: 10,
95
+ judgeScoreDropPoints: 3,
96
+ fallbackRatePct: 20,
97
+ });
98
+ assert.equal(verdict.pass, false);
99
+ assert.deepEqual(verdict.conditions, {
100
+ wallClockReduction: false,
101
+ judgeQuality: false,
102
+ fallbackRate: false,
103
+ });
104
+ assert.deepEqual(verdict.failed, ["wallClockReduction", "judgeQuality", "fallbackRate"]);
105
+ });
106
+
107
+ it("fails a negative wall-clock reduction without throwing", () => {
108
+ const verdict = evaluateSpanPhaseGate({
109
+ wallClockReductionPct: -5,
110
+ judgeScoreDropPoints: 0.3,
111
+ fallbackRatePct: 4,
112
+ });
113
+ assert.equal(verdict.pass, false);
114
+ assert.deepEqual(verdict.failed, ["wallClockReduction"]);
115
+ });
116
+
117
+ it("passes a negative judge drop (quality improved)", () => {
118
+ const verdict = evaluateSpanPhaseGate({
119
+ wallClockReductionPct: 45,
120
+ judgeScoreDropPoints: -0.5,
121
+ fallbackRatePct: 4,
122
+ });
123
+ assert.equal(verdict.conditions.judgeQuality, true);
124
+ assert.equal(verdict.pass, true);
125
+ });
126
+
127
+ it("throws RangeError naming the field on non-finite wall-clock reduction", () => {
128
+ assertRangeError(
129
+ () =>
130
+ evaluateSpanPhaseGate({
131
+ wallClockReductionPct: Number.NaN,
132
+ judgeScoreDropPoints: 0.3,
133
+ fallbackRatePct: 4,
134
+ }),
135
+ "wallClockReductionPct",
136
+ );
137
+ });
138
+
139
+ it("throws RangeError naming the field on non-finite judge drop", () => {
140
+ assertRangeError(
141
+ () =>
142
+ evaluateSpanPhaseGate({
143
+ wallClockReductionPct: 45,
144
+ judgeScoreDropPoints: Number.POSITIVE_INFINITY,
145
+ fallbackRatePct: 4,
146
+ }),
147
+ "judgeScoreDropPoints",
148
+ );
149
+ });
150
+
151
+ it("throws RangeError naming the field on non-finite fallback rate", () => {
152
+ assertRangeError(
153
+ () =>
154
+ evaluateSpanPhaseGate({
155
+ wallClockReductionPct: 45,
156
+ judgeScoreDropPoints: 0.3,
157
+ fallbackRatePct: Number.NEGATIVE_INFINITY,
158
+ }),
159
+ "fallbackRatePct",
160
+ );
161
+ });
162
+
163
+ it("throws RangeError on a fallback rate of 101", () => {
164
+ assertRangeError(
165
+ () =>
166
+ evaluateSpanPhaseGate({
167
+ wallClockReductionPct: 45,
168
+ judgeScoreDropPoints: 0.3,
169
+ fallbackRatePct: 101,
170
+ }),
171
+ "fallbackRatePct",
172
+ );
173
+ });
174
+
175
+ it("throws RangeError on a fallback rate of -1", () => {
176
+ assertRangeError(
177
+ () =>
178
+ evaluateSpanPhaseGate({
179
+ wallClockReductionPct: 45,
180
+ judgeScoreDropPoints: 0.3,
181
+ fallbackRatePct: -1,
182
+ }),
183
+ "fallbackRatePct",
184
+ );
185
+ });
186
+
187
+ it("accepts the fallback-rate endpoints 0 and 100 as measurements", () => {
188
+ assert.doesNotThrow(() =>
189
+ evaluateSpanPhaseGate({
190
+ wallClockReductionPct: 45,
191
+ judgeScoreDropPoints: 0.3,
192
+ fallbackRatePct: 0,
193
+ }),
194
+ );
195
+ const verdict = evaluateSpanPhaseGate({
196
+ wallClockReductionPct: 45,
197
+ judgeScoreDropPoints: 0.3,
198
+ fallbackRatePct: 100,
199
+ });
200
+ assert.deepEqual(verdict.failed, ["fallbackRate"]);
201
+ });
202
+ });
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Span-mode Phase B gate (issue #2333).
3
+ *
4
+ * Phase A must earn >= 20% extraction wall-clock reduction, keep the LLM-judge
5
+ * score drop under 2 points, and keep the span fallback rate under 15% before
6
+ * Phase B wiring starts. A failed gate is reported, never rounded into a pass.
7
+ *
8
+ * Pure. No I/O, no clock, no randomness.
9
+ */
10
+
11
+ export const SPAN_GATE_MIN_WALLCLOCK_REDUCTION_PCT = 20;
12
+ export const SPAN_GATE_MAX_JUDGE_DROP_POINTS = 2;
13
+ export const SPAN_GATE_MAX_FALLBACK_RATE_PCT = 15;
14
+
15
+ export interface SpanGateConditions {
16
+ wallClockReduction: boolean;
17
+ judgeQuality: boolean;
18
+ fallbackRate: boolean;
19
+ }
20
+
21
+ export interface SpanGateVerdict {
22
+ /** True only when every condition passes. */
23
+ pass: boolean;
24
+ conditions: SpanGateConditions;
25
+ /** Condition names that failed, in declaration order. Empty when pass. */
26
+ failed: string[];
27
+ }
28
+
29
+ function requireFinite(value: number, field: string): void {
30
+ if (typeof value !== "number" || !Number.isFinite(value)) {
31
+ throw new RangeError(`span gate input ${field} must be a finite number, got ${value}`);
32
+ }
33
+ }
34
+
35
+ export function evaluateSpanPhaseGate(input: {
36
+ wallClockReductionPct: number;
37
+ judgeScoreDropPoints: number;
38
+ fallbackRatePct: number;
39
+ }): SpanGateVerdict {
40
+ requireFinite(input.wallClockReductionPct, "wallClockReductionPct");
41
+ requireFinite(input.judgeScoreDropPoints, "judgeScoreDropPoints");
42
+ requireFinite(input.fallbackRatePct, "fallbackRatePct");
43
+ if (input.fallbackRatePct < 0 || input.fallbackRatePct > 100) {
44
+ throw new RangeError(
45
+ `span gate input fallbackRatePct must be within [0, 100], got ${input.fallbackRatePct}`,
46
+ );
47
+ }
48
+
49
+ const conditions: SpanGateConditions = {
50
+ wallClockReduction: input.wallClockReductionPct >= SPAN_GATE_MIN_WALLCLOCK_REDUCTION_PCT,
51
+ judgeQuality: input.judgeScoreDropPoints < SPAN_GATE_MAX_JUDGE_DROP_POINTS,
52
+ fallbackRate: input.fallbackRatePct < SPAN_GATE_MAX_FALLBACK_RATE_PCT,
53
+ };
54
+ const failed = (Object.keys(conditions) as (keyof SpanGateConditions)[]).filter(
55
+ (name) => !conditions[name],
56
+ );
57
+ return { pass: failed.length === 0, conditions, failed };
58
+ }
@@ -0,0 +1,104 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+
4
+ import {
5
+ DEFAULT_NAVIGATION_WINDOW_SNAPSHOTS,
6
+ assertIdInNavigationWindow,
7
+ type NavigationSnapshot,
8
+ } from "./recall-navigate-window.js";
9
+
10
+ const snap = (...servedIds: string[]): NavigationSnapshot => ({ servedIds });
11
+ const malformed = (value: unknown): NavigationSnapshot => value as NavigationSnapshot;
12
+
13
+ test("default window is 3 snapshots", () => {
14
+ assert.equal(DEFAULT_NAVIGATION_WINDOW_SNAPSHOTS, 3);
15
+ });
16
+
17
+ test("id in the newest snapshot is ok", () => {
18
+ assert.deepEqual(
19
+ assertIdInNavigationWindow({ snapshots: [snap("fact-1"), snap("fact-2")], memoryId: "fact-1" }),
20
+ { ok: true, memoryId: "fact-1" },
21
+ );
22
+ });
23
+
24
+ test("id in the 3rd snapshot is ok at the default window", () => {
25
+ const snapshots = [snap("fact-a"), snap("fact-b"), snap("fact-c"), snap("fact-d")];
26
+ assert.deepEqual(assertIdInNavigationWindow({ snapshots, memoryId: "fact-c" }), {
27
+ ok: true,
28
+ memoryId: "fact-c",
29
+ });
30
+ });
31
+
32
+ test("id only in a 4th snapshot is not_served", () => {
33
+ const snapshots = [snap("fact-a"), snap("fact-b"), snap("fact-c"), snap("fact-d")];
34
+ assert.deepEqual(assertIdInNavigationWindow({ snapshots, memoryId: "fact-d" }), {
35
+ ok: false,
36
+ error: "not_served",
37
+ });
38
+ });
39
+
40
+ test("windowSnapshots 1 rejects an id from the 2nd snapshot", () => {
41
+ const snapshots = [snap("fact-a"), snap("fact-b")];
42
+ assert.deepEqual(
43
+ assertIdInNavigationWindow({ snapshots, memoryId: "fact-b", windowSnapshots: 1 }),
44
+ { ok: false, error: "not_served" },
45
+ );
46
+ });
47
+
48
+ test("windowSnapshots 0, negative, fractional, NaN, Infinity throw", () => {
49
+ const snapshots = [snap("fact-a")];
50
+ for (const windowSnapshots of [0, -1, 1.5, Number.NaN, Number.POSITIVE_INFINITY]) {
51
+ assert.throws(
52
+ () => assertIdInNavigationWindow({ snapshots, memoryId: "fact-a", windowSnapshots }),
53
+ { name: "RangeError", message: /windowSnapshots/ },
54
+ );
55
+ }
56
+ });
57
+
58
+ test("non-string and whitespace ids are empty_id, never not_served", () => {
59
+ const snapshots = [snap("fact-a")];
60
+ for (const memoryId of [null, undefined, 42, {}, "", " ", "\t\n"]) {
61
+ assert.deepEqual(assertIdInNavigationWindow({ snapshots, memoryId }), {
62
+ ok: false,
63
+ error: "empty_id",
64
+ });
65
+ }
66
+ });
67
+
68
+ test("padded id matches after trim", () => {
69
+ const snapshots = [snap("fact-1")];
70
+ assert.deepEqual(assertIdInNavigationWindow({ snapshots, memoryId: " fact-1 \t" }), {
71
+ ok: true,
72
+ memoryId: "fact-1",
73
+ });
74
+ });
75
+
76
+ test("case-different id is not_served", () => {
77
+ const snapshots = [snap("Fact-1")];
78
+ assert.deepEqual(assertIdInNavigationWindow({ snapshots, memoryId: "fact-1" }), {
79
+ ok: false,
80
+ error: "not_served",
81
+ });
82
+ });
83
+
84
+ test("empty snapshots list is not_served", () => {
85
+ assert.deepEqual(assertIdInNavigationWindow({ snapshots: [], memoryId: "fact-1" }), {
86
+ ok: false,
87
+ error: "not_served",
88
+ });
89
+ });
90
+
91
+ test("malformed snapshot consumes its window slot without throwing", () => {
92
+ // Missing servedIds on the newest snapshot: it still burns the only
93
+ // window slot, so the id served by the 2nd snapshot stays not_served.
94
+ assert.doesNotThrow(() => {
95
+ assert.deepEqual(
96
+ assertIdInNavigationWindow({
97
+ snapshots: [malformed({}), malformed({ servedIds: "fact-1" })],
98
+ memoryId: "fact-1",
99
+ windowSnapshots: 1,
100
+ }),
101
+ { ok: false, error: "not_served" },
102
+ );
103
+ });
104
+ });
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Recall navigation window authority (issue #1956).
3
+ *
4
+ * Pure. An expandable id must have been served by one of the session's
5
+ * last `windowSnapshots` recall snapshots, ordered newest first. Unknown
6
+ * or foreign ids are rejected, not reinterpreted (pattern 39).
7
+ */
8
+
9
+ export const DEFAULT_NAVIGATION_WINDOW_SNAPSHOTS = 3;
10
+
11
+ /** Ids served by one recall snapshot, newest snapshot first when passed in. */
12
+ export interface NavigationSnapshot {
13
+ servedIds: readonly string[];
14
+ }
15
+
16
+ export type NavigationAuthorityResult =
17
+ | { ok: true; memoryId: string }
18
+ | { ok: false; error: "empty_id" | "not_served" };
19
+
20
+ export function assertIdInNavigationWindow(input: {
21
+ snapshots: readonly NavigationSnapshot[];
22
+ memoryId: unknown;
23
+ windowSnapshots?: number;
24
+ }): NavigationAuthorityResult {
25
+ const windowSnapshots = input.windowSnapshots ?? DEFAULT_NAVIGATION_WINDOW_SNAPSHOTS;
26
+ if (!Number.isInteger(windowSnapshots) || windowSnapshots < 1) {
27
+ throw new RangeError(
28
+ `windowSnapshots must be a positive integer; got ${JSON.stringify(windowSnapshots)}`,
29
+ );
30
+ }
31
+ if (typeof input.memoryId !== "string" || input.memoryId.trim() === "") {
32
+ return { ok: false, error: "empty_id" };
33
+ }
34
+ const wanted = input.memoryId.trim();
35
+ for (const snapshot of input.snapshots.slice(0, windowSnapshots)) {
36
+ // A malformed entry (missing or non-array servedIds) was still a real
37
+ // recall turn: it consumes a window slot but contributes no ids.
38
+ if (!snapshot || !Array.isArray(snapshot.servedIds)) {
39
+ continue;
40
+ }
41
+ for (const served of snapshot.servedIds) {
42
+ if (typeof served === "string" && served.trim() === wanted) {
43
+ return { ok: true, memoryId: wanted };
44
+ }
45
+ }
46
+ }
47
+ return { ok: false, error: "not_served" };
48
+ }
@@ -0,0 +1,158 @@
1
+ import { test } from "node:test";
2
+ import assert from "node:assert/strict";
3
+
4
+ import {
5
+ MAX_SUPERSESSION_DEPTH,
6
+ resolveSupersessionHead,
7
+ type SupersessionItem,
8
+ } from "./supersession-chain.js";
9
+
10
+ const link = (id: string, supersedes?: string): SupersessionItem =>
11
+ supersedes === undefined ? { id } : { id, supersedes };
12
+
13
+ test("single item resolves to itself", () => {
14
+ assert.deepEqual(resolveSupersessionHead({ items: [link("a")], startId: "a" }), {
15
+ ok: true,
16
+ headId: "a",
17
+ chain: ["a"],
18
+ });
19
+ });
20
+
21
+ test("3-link chain resolves to the newest head with the full chain", () => {
22
+ const items = [link("a"), link("b", "a"), link("c", "b")];
23
+ assert.deepEqual(resolveSupersessionHead({ items, startId: "a" }), {
24
+ ok: true,
25
+ headId: "c",
26
+ chain: ["a", "b", "c"],
27
+ });
28
+ });
29
+
30
+ test("2-cycle returns cycle_detected without hanging", () => {
31
+ const items = [link("a", "b"), link("b", "a")];
32
+ assert.deepEqual(resolveSupersessionHead({ items, startId: "a" }), {
33
+ ok: false,
34
+ error: "cycle_detected",
35
+ chain: ["a", "b"],
36
+ });
37
+ });
38
+
39
+ test("longer cycle is also detected", () => {
40
+ // b supersedes a, c supersedes b, a supersedes c.
41
+ const items = [link("a", "c"), link("b", "a"), link("c", "b")];
42
+ assert.deepEqual(resolveSupersessionHead({ items, startId: "a" }), {
43
+ ok: false,
44
+ error: "cycle_detected",
45
+ chain: ["a", "b", "c"],
46
+ });
47
+ });
48
+
49
+ test("depth_exceeded with a small maxDepth", () => {
50
+ const items = [link("a"), link("b", "a"), link("c", "b"), link("d", "c")];
51
+ assert.deepEqual(resolveSupersessionHead({ items, startId: "a", maxDepth: 2 }), {
52
+ ok: false,
53
+ error: "depth_exceeded",
54
+ chain: ["a", "b"],
55
+ });
56
+ assert.deepEqual(resolveSupersessionHead({ items, startId: "a", maxDepth: 1 }), {
57
+ ok: false,
58
+ error: "depth_exceeded",
59
+ chain: ["a"],
60
+ });
61
+ // A chain exactly maxDepth ids long still resolves.
62
+ assert.deepEqual(resolveSupersessionHead({ items, startId: "b", maxDepth: 3 }), {
63
+ ok: true,
64
+ headId: "d",
65
+ chain: ["b", "c", "d"],
66
+ });
67
+ });
68
+
69
+ test("default depth is MAX_SUPERSESSION_DEPTH", () => {
70
+ assert.equal(MAX_SUPERSESSION_DEPTH, 32);
71
+ const items: SupersessionItem[] = [link("i0")];
72
+ for (let i = 1; i <= 60; i++) items.push(link(`i${i}`, `i${i - 1}`));
73
+ assert.deepEqual(resolveSupersessionHead({ items, startId: "i0" }), {
74
+ ok: false,
75
+ error: "depth_exceeded",
76
+ chain: Array.from({ length: MAX_SUPERSESSION_DEPTH }, (_, i) => `i${i}`),
77
+ });
78
+ });
79
+
80
+ test("unknown startId returns unknown_id with an empty chain", () => {
81
+ assert.deepEqual(resolveSupersessionHead({ items: [link("a")], startId: "zzz" }), {
82
+ ok: false,
83
+ error: "unknown_id",
84
+ chain: [],
85
+ });
86
+ });
87
+
88
+ test("empty and whitespace-only startId return unknown_id", () => {
89
+ const items = [link("a")];
90
+ for (const startId of ["", " "]) {
91
+ assert.deepEqual(resolveSupersessionHead({ items, startId }), {
92
+ ok: false,
93
+ error: "unknown_id",
94
+ chain: [],
95
+ });
96
+ }
97
+ });
98
+
99
+ test("startId is trimmed on the happy path", () => {
100
+ const items = [link("a"), link("b", "a")];
101
+ assert.deepEqual(resolveSupersessionHead({ items, startId: " a " }), {
102
+ ok: true,
103
+ headId: "b",
104
+ chain: ["a", "b"],
105
+ });
106
+ });
107
+
108
+ test("maxDepth 0, negative, and float throw RangeError naming maxDepth", () => {
109
+ const items = [link("a")];
110
+ for (const bad of [0, -1, -32, 2.5, Number.NaN]) {
111
+ assert.throws(
112
+ () => resolveSupersessionHead({ items, startId: "a", maxDepth: bad }),
113
+ (err: unknown) =>
114
+ err instanceof RangeError && /maxDepth/.test(String(err.message)),
115
+ );
116
+ }
117
+ });
118
+
119
+ test("fork resolves to the smallest successor id, stable across shuffles", () => {
120
+ // Both b and c supersede a; b < c, so b wins even though c appears first.
121
+ const ordered = [link("a"), link("c", "a"), link("b", "a"), link("d", "b")];
122
+ const shuffled = [link("d", "b"), link("b", "a"), link("a"), link("c", "a")];
123
+ const expected = { ok: true, headId: "d", chain: ["a", "b", "d"] };
124
+ assert.deepEqual(resolveSupersessionHead({ items: ordered, startId: "a" }), expected);
125
+ assert.deepEqual(resolveSupersessionHead({ items: shuffled, startId: "a" }), expected);
126
+ // Same shuffled input twice: identical results.
127
+ assert.deepEqual(resolveSupersessionHead({ items: shuffled, startId: "a" }), expected);
128
+ });
129
+
130
+ test("blank-id items are ignored", () => {
131
+ const items: SupersessionItem[] = [
132
+ link("a"),
133
+ link("b", "a"),
134
+ { id: "", supersedes: "b" },
135
+ { id: " ", supersedes: "b" },
136
+ { supersedes: "b" } as unknown as SupersessionItem,
137
+ link("z", " "),
138
+ ];
139
+ // The blank-id items must not make themselves successors of b.
140
+ assert.deepEqual(resolveSupersessionHead({ items, startId: "a" }), {
141
+ ok: true,
142
+ headId: "b",
143
+ chain: ["a", "b"],
144
+ });
145
+ // z has a blank supersedes pointer: it supersedes nothing.
146
+ assert.deepEqual(resolveSupersessionHead({ items, startId: "z" }), {
147
+ ok: true,
148
+ headId: "z",
149
+ chain: ["z"],
150
+ });
151
+ });
152
+
153
+ test("input is not mutated", () => {
154
+ const items = [link("c", "b"), link("a"), link("b", "a")];
155
+ const snapshot = structuredClone(items);
156
+ resolveSupersessionHead({ items, startId: "a" });
157
+ assert.deepEqual(items, snapshot);
158
+ });
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Supersession chain resolution for shared-context curation (issue #1957).
3
+ *
4
+ * A shared item may supersede another item, which may itself be superseded.
5
+ * Curation needs the live head of that chain. This module resolves the head
6
+ * deterministically and survives malformed input: cycles, forks, and depth
7
+ * blowups return errors instead of throwing or looping.
8
+ */
9
+
10
+ export interface SupersessionItem {
11
+ id: string;
12
+ /** Id of the item this one replaces, when any. */
13
+ supersedes?: string;
14
+ }
15
+
16
+ export type SupersessionChainResult =
17
+ | { ok: true; headId: string; chain: string[] }
18
+ | {
19
+ ok: false;
20
+ error: "unknown_id" | "cycle_detected" | "depth_exceeded";
21
+ chain: string[];
22
+ };
23
+
24
+ export const MAX_SUPERSESSION_DEPTH = 32;
25
+
26
+ /**
27
+ * Resolve the live head of the supersession chain that starts at `startId`.
28
+ *
29
+ * Direction: forward. The successor of id X is the item whose `supersedes`
30
+ * points at X. The head is the item that nothing supersedes.
31
+ *
32
+ * Fork policy: when two items supersede the same id, the lexicographically
33
+ * smallest successor id wins. This keeps the result dependent only on the
34
+ * item set, never on array order.
35
+ *
36
+ * Pure: reads the input, mutates nothing, performs no I/O.
37
+ */
38
+ export function resolveSupersessionHead(input: {
39
+ items: readonly SupersessionItem[];
40
+ startId: string;
41
+ maxDepth?: number;
42
+ }): SupersessionChainResult {
43
+ const { items, maxDepth } = input;
44
+ if (maxDepth !== undefined && (!Number.isInteger(maxDepth) || maxDepth < 1)) {
45
+ throw new RangeError(`maxDepth must be a positive integer, got ${maxDepth}`);
46
+ }
47
+ const depth = maxDepth ?? MAX_SUPERSESSION_DEPTH;
48
+
49
+ const start = input.startId.trim();
50
+ if (start === "") {
51
+ return { ok: false, error: "unknown_id", chain: [] };
52
+ }
53
+
54
+ // Build the id set and the successor map. Blank ids cannot participate,
55
+ // and a blank `supersedes` value cannot point at anything.
56
+ const ids = new Set<string>();
57
+ const successorOf = new Map<string, string>();
58
+ for (const item of items) {
59
+ if (typeof item?.id !== "string") continue;
60
+ const id = item.id.trim();
61
+ if (id === "") continue;
62
+ ids.add(id);
63
+ const target =
64
+ typeof item.supersedes === "string" ? item.supersedes.trim() : "";
65
+ if (target === "") continue;
66
+ // Fork resolution: keep the smallest successor id for determinism.
67
+ const best = successorOf.get(target);
68
+ if (best === undefined || id < best) {
69
+ successorOf.set(target, id);
70
+ }
71
+ }
72
+
73
+ if (!ids.has(start)) {
74
+ return { ok: false, error: "unknown_id", chain: [] };
75
+ }
76
+
77
+ const chain = [start];
78
+ const visited = new Set<string>([start]);
79
+ let current = start;
80
+ for (;;) {
81
+ const next = successorOf.get(current);
82
+ if (next === undefined) {
83
+ return { ok: true, headId: current, chain };
84
+ }
85
+ if (visited.has(next)) {
86
+ return { ok: false, error: "cycle_detected", chain };
87
+ }
88
+ if (chain.length + 1 > depth) {
89
+ return { ok: false, error: "depth_exceeded", chain };
90
+ }
91
+ chain.push(next);
92
+ visited.add(next);
93
+ current = next;
94
+ }
95
+ }