pi-mega-compact 0.20.7 → 0.20.9

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 (117) hide show
  1. package/dist/config/vector-cortex.js +25 -0
  2. package/dist/config.js +1 -1
  3. package/dist/extensions/dashboard-server/api-contracts/vector-cortex-heal.js +11 -0
  4. package/dist/extensions/dashboard-server/route-dispatch.js +104 -0
  5. package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +2 -0
  6. package/dist/extensions/dashboard-server/routes-vector-cortex-heal.js +86 -0
  7. package/dist/extensions/dashboard-server/routes-vector-cortex.js +3 -0
  8. package/dist/extensions/dashboard-server/routes.js +1 -1
  9. package/dist/extensions/dashboard-server/server.js +3 -82
  10. package/dist/src/config/vector-cortex.js +25 -0
  11. package/dist/src/config.js +1 -1
  12. package/dist/src/vector-cortex/heal/_acceptance-fixture.js +56 -0
  13. package/dist/src/vector-cortex/heal/_restore-fixture.js +96 -0
  14. package/dist/src/vector-cortex/heal/_vc6b-helpers.js +35 -0
  15. package/dist/src/vector-cortex/heal/closure-metrics.js +66 -0
  16. package/dist/src/vector-cortex/heal/closure-opt.js +242 -0
  17. package/dist/src/vector-cortex/heal/emit.js +69 -0
  18. package/dist/src/vector-cortex/heal/proof.js +210 -0
  19. package/dist/src/vector-cortex/heal/restore-emit.js +70 -0
  20. package/dist/src/vector-cortex/heal/restore-readers.js +114 -0
  21. package/dist/src/vector-cortex/heal/restore-types.js +66 -0
  22. package/dist/src/vector-cortex/heal/restore.js +140 -0
  23. package/dist/src/vector-cortex/heal/types.js +43 -0
  24. package/dist/src/vector-cortex/heal/verify.js +75 -0
  25. package/dist/vector-cortex/heal/_acceptance-fixture.js +56 -0
  26. package/dist/vector-cortex/heal/_restore-fixture.js +96 -0
  27. package/dist/vector-cortex/heal/_vc6b-helpers.js +35 -0
  28. package/dist/vector-cortex/heal/closure-metrics.js +66 -0
  29. package/dist/vector-cortex/heal/closure-opt.js +242 -0
  30. package/dist/vector-cortex/heal/emit.js +69 -0
  31. package/dist/vector-cortex/heal/proof.js +210 -0
  32. package/dist/vector-cortex/heal/restore-emit.js +70 -0
  33. package/dist/vector-cortex/heal/restore-readers.js +114 -0
  34. package/dist/vector-cortex/heal/restore-types.js +66 -0
  35. package/dist/vector-cortex/heal/restore.js +140 -0
  36. package/dist/vector-cortex/heal/types.js +43 -0
  37. package/dist/vector-cortex/heal/verify.js +75 -0
  38. package/extensions/dashboard-client/dist/assets/{AreaChart-DqTbaSRA.js → AreaChart-fxyq2KaH.js} +2 -2
  39. package/extensions/dashboard-client/dist/assets/{AreaChart-DqTbaSRA.js.map → AreaChart-fxyq2KaH.js.map} +1 -1
  40. package/extensions/dashboard-client/dist/assets/{BarChart-BfNBeOvF.js → BarChart-D5EqAINP.js} +2 -2
  41. package/extensions/dashboard-client/dist/assets/{BarChart-BfNBeOvF.js.map → BarChart-D5EqAINP.js.map} +1 -1
  42. package/extensions/dashboard-client/dist/assets/{CacheTab-C9SOMYB5.js → CacheTab-D4UWbzLo.js} +2 -2
  43. package/extensions/dashboard-client/dist/assets/{CacheTab-C9SOMYB5.js.map → CacheTab-D4UWbzLo.js.map} +1 -1
  44. package/extensions/dashboard-client/dist/assets/{EventsTab-GsMKP10_.js → EventsTab-BiXquGrX.js} +2 -2
  45. package/extensions/dashboard-client/dist/assets/{EventsTab-GsMKP10_.js.map → EventsTab-BiXquGrX.js.map} +1 -1
  46. package/extensions/dashboard-client/dist/assets/{HealthTab-DAOCXwRP.js → HealthTab-D5QvoTjy.js} +2 -2
  47. package/extensions/dashboard-client/dist/assets/{HealthTab-DAOCXwRP.js.map → HealthTab-D5QvoTjy.js.map} +1 -1
  48. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-BtBeMkB5.js → MaintenanceTab-Cy_-CWgM.js} +2 -2
  49. package/extensions/dashboard-client/dist/assets/{MaintenanceTab-BtBeMkB5.js.map → MaintenanceTab-Cy_-CWgM.js.map} +1 -1
  50. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-DzndtgkZ.js → MemoryMapTab-DrAjgGOR.js} +2 -2
  51. package/extensions/dashboard-client/dist/assets/{MemoryMapTab-DzndtgkZ.js.map → MemoryMapTab-DrAjgGOR.js.map} +1 -1
  52. package/extensions/dashboard-client/dist/assets/{MetricsTab-DyxJ4eb8.js → MetricsTab-BvPHcuFN.js} +2 -2
  53. package/extensions/dashboard-client/dist/assets/{MetricsTab-DyxJ4eb8.js.map → MetricsTab-BvPHcuFN.js.map} +1 -1
  54. package/extensions/dashboard-client/dist/assets/{OverviewTab-DCiEdVWR.js → OverviewTab-DsbIigOQ.js} +2 -2
  55. package/extensions/dashboard-client/dist/assets/{OverviewTab-DCiEdVWR.js.map → OverviewTab-DsbIigOQ.js.map} +1 -1
  56. package/extensions/dashboard-client/dist/assets/{ReposTab-B5SIqVHA.js → ReposTab-7v_uZX_a.js} +2 -2
  57. package/extensions/dashboard-client/dist/assets/{ReposTab-B5SIqVHA.js.map → ReposTab-7v_uZX_a.js.map} +1 -1
  58. package/extensions/dashboard-client/dist/assets/{SessionsTab-DLWFJ9xI.js → SessionsTab-BXGrv-6C.js} +2 -2
  59. package/extensions/dashboard-client/dist/assets/{SessionsTab-DLWFJ9xI.js.map → SessionsTab-BXGrv-6C.js.map} +1 -1
  60. package/extensions/dashboard-client/dist/assets/{SetupTab-CvGXZyej.js → SetupTab-QRUXa65y.js} +2 -2
  61. package/extensions/dashboard-client/dist/assets/{SetupTab-CvGXZyej.js.map → SetupTab-QRUXa65y.js.map} +1 -1
  62. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-wZuQGxLS.js → TimeSavedCard-p327ZZKT.js} +2 -2
  63. package/extensions/dashboard-client/dist/assets/{TimeSavedCard-wZuQGxLS.js.map → TimeSavedCard-p327ZZKT.js.map} +1 -1
  64. package/extensions/dashboard-client/dist/assets/{TurnsTab-B7aOejch.js → TurnsTab-BcmBSlik.js} +2 -2
  65. package/extensions/dashboard-client/dist/assets/{TurnsTab-B7aOejch.js.map → TurnsTab-BcmBSlik.js.map} +1 -1
  66. package/extensions/dashboard-client/dist/assets/VectorCortexTab-D2fjKNyT.js +2 -0
  67. package/extensions/dashboard-client/dist/assets/VectorCortexTab-D2fjKNyT.js.map +1 -0
  68. package/extensions/dashboard-client/dist/assets/{WikiTab-DhWHjAtt.js → WikiTab-DLXFMuNy.js} +2 -2
  69. package/extensions/dashboard-client/dist/assets/{WikiTab-DhWHjAtt.js.map → WikiTab-DLXFMuNy.js.map} +1 -1
  70. package/extensions/dashboard-client/dist/assets/{button-BrC-W87h.js → button-C9CghmRx.js} +2 -2
  71. package/extensions/dashboard-client/dist/assets/{button-BrC-W87h.js.map → button-C9CghmRx.js.map} +1 -1
  72. package/extensions/dashboard-client/dist/assets/{card-0rgfRgr3.js → card-DWU-1y3t.js} +2 -2
  73. package/extensions/dashboard-client/dist/assets/{card-0rgfRgr3.js.map → card-DWU-1y3t.js.map} +1 -1
  74. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DRresOQF.js → generateCategoricalChart-Dayy9dGn.js} +2 -2
  75. package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DRresOQF.js.map → generateCategoricalChart-Dayy9dGn.js.map} +1 -1
  76. package/extensions/dashboard-client/dist/assets/{index-DohmtZWL.js → index-D9PsW3VZ.js} +3 -3
  77. package/extensions/dashboard-client/dist/assets/{index-DohmtZWL.js.map → index-D9PsW3VZ.js.map} +1 -1
  78. package/extensions/dashboard-client/dist/assets/{switch-Bs8g_zB5.js → switch-CnLFAmVT.js} +2 -2
  79. package/extensions/dashboard-client/dist/assets/{switch-Bs8g_zB5.js.map → switch-CnLFAmVT.js.map} +1 -1
  80. package/extensions/dashboard-client/dist/assets/{toggle-DVVauIo8.js → toggle-HN5C7_vy.js} +2 -2
  81. package/extensions/dashboard-client/dist/assets/{toggle-DVVauIo8.js.map → toggle-HN5C7_vy.js.map} +1 -1
  82. package/extensions/dashboard-client/dist/assets/{useSSE-DxH1PTAR.js → useSSE-DoJfk3Ce.js} +2 -2
  83. package/extensions/dashboard-client/dist/assets/{useSSE-DxH1PTAR.js.map → useSSE-DoJfk3Ce.js.map} +1 -1
  84. package/extensions/dashboard-client/dist/index.html +1 -1
  85. package/extensions/dashboard-client/src/api/vector-cortex.ts +18 -0
  86. package/extensions/dashboard-client/src/tabs/VectorCortexClosureCard.tsx +46 -0
  87. package/extensions/dashboard-client/src/tabs/VectorCortexLedgerCard.tsx +80 -0
  88. package/extensions/dashboard-client/src/tabs/VectorCortexRestoreCard.tsx +42 -0
  89. package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +20 -164
  90. package/extensions/dashboard-client/src/tabs/VectorCortexTopologyCard.tsx +131 -0
  91. package/extensions/dashboard-client/src/types/vector-cortex.ts +30 -0
  92. package/extensions/dashboard-server/api-contracts/vector-cortex-heal.ts +73 -0
  93. package/extensions/dashboard-server/api-contracts/vector-cortex.ts +5 -0
  94. package/extensions/dashboard-server/route-dispatch.ts +114 -0
  95. package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +12 -0
  96. package/extensions/dashboard-server/routes-vector-cortex-heal.ts +103 -0
  97. package/extensions/dashboard-server/routes-vector-cortex.ts +6 -0
  98. package/extensions/dashboard-server/routes.ts +2 -0
  99. package/extensions/dashboard-server/server.ts +3 -86
  100. package/package.json +1 -1
  101. package/src/config/vector-cortex.ts +27 -0
  102. package/src/config.ts +2 -0
  103. package/src/vector-cortex/heal/_acceptance-fixture.ts +108 -0
  104. package/src/vector-cortex/heal/_restore-fixture.ts +163 -0
  105. package/src/vector-cortex/heal/_vc6b-helpers.ts +55 -0
  106. package/src/vector-cortex/heal/closure-metrics.ts +73 -0
  107. package/src/vector-cortex/heal/closure-opt.ts +266 -0
  108. package/src/vector-cortex/heal/emit.ts +93 -0
  109. package/src/vector-cortex/heal/proof.ts +234 -0
  110. package/src/vector-cortex/heal/restore-emit.ts +94 -0
  111. package/src/vector-cortex/heal/restore-readers.ts +145 -0
  112. package/src/vector-cortex/heal/restore-types.ts +185 -0
  113. package/src/vector-cortex/heal/restore.ts +165 -0
  114. package/src/vector-cortex/heal/types.ts +248 -0
  115. package/src/vector-cortex/heal/verify.ts +93 -0
  116. package/extensions/dashboard-client/dist/assets/VectorCortexTab-eHVt9yDx.js +0 -2
  117. package/extensions/dashboard-client/dist/assets/VectorCortexTab-eHVt9yDx.js.map +0 -1
@@ -196,6 +196,31 @@ export const VC5B_ENABLED = () => sprintFlag("MEGACOMPACT_VC5B");
196
196
  * mirroring VC4A/VC4B/VC4C/VC5A/VC5B.
197
197
  */
198
198
  export const VC5C_ENABLED = () => sprintFlag("MEGACOMPACT_VC5C");
199
+ /**
200
+ * VC6A — advanced closure optimization. Default ON. `MEGACOMPACT_VC6A=0`
201
+ * disables and is byte-identical to the predecessor (VC5C): the `optimizeClosure`
202
+ * transitive-reduction arithmetic STILL RUNS (it is PURE), but the
203
+ * `vector_cortex_closure_optimized` / `vector_cortex_closure_proof_rejected`
204
+ * events are never emitted and the dashboard closure diagnostics seam is
205
+ * suppressed. Flag OFF gates the reporter + dashboard seam, never the arithmetic,
206
+ * so flag-off outbound/predecessor golden bytes match exactly. This flag MUST
207
+ * also be a dashboard SETTINGS toggle (visible in config UI, never in
208
+ * EXCLUDED_SETTINGS), mirroring VC4A/VC4B/VC4C/VC5A/VC5B/VC5C.
209
+ */
210
+ export const VC6A_ENABLED = () => sprintFlag("MEGACOMPACT_VC6A");
211
+ /**
212
+ * VC6B — exact source restoration. Default ON. `MEGACOMPACT_VC6B=0` disables and
213
+ * is byte-identical to the predecessor (VC6A): the `restoreSources` /
214
+ * `verifyRestored` arithmetic STILL RUNS (it is PURE — an exact-source read plus
215
+ * a SHA-256 comparison, with no clock, storage, or network), but the
216
+ * `vector_cortex_source_restored` / `vector_cortex_restore_digest_rejected`
217
+ * events are never emitted and the dashboard restoration diagnostics seam is
218
+ * suppressed. Flag OFF gates the reporter + dashboard seam, never the
219
+ * restore/verify arithmetic, so flag-off outbound/predecessor golden bytes match
220
+ * exactly. This flag MUST also be a dashboard SETTINGS toggle (visible in config
221
+ * UI, never in EXCLUDED_SETTINGS), mirroring VC4A/VC4B/VC4C/VC5A/VC5B/VC5C/VC6A.
222
+ */
223
+ export const VC6B_ENABLED = () => sprintFlag("MEGACOMPACT_VC6B");
199
224
  // ---------------------------------------------------------------------------
200
225
  // Breaker state machine constants (TRIAD_RESILIENCE.md §breaker).
201
226
  // Rolled numbers for one 60s window; VC0C consumes these at its breaker seam.
package/dist/config.js CHANGED
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
114
114
  // default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
115
115
  // so root consumers share one source of truth.
116
116
  // ---------------------------------------------------------------------------
117
- export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
117
+ export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
@@ -0,0 +1,11 @@
1
+ /**
2
+ * api-contracts/vector-cortex-heal.ts — VC6A+ heal API contracts.
3
+ *
4
+ * Extracted from vector-cortex.ts to keep both files under the 400-line
5
+ * extension soft limit. Owns the reader-only closure-optimization and
6
+ * restoration diagnostic views emitted by the heal sprint handlers.
7
+ *
8
+ * PREVENT-PI-004: type definitions only, no network code.
9
+ * PREVENT-011: no `any` type.
10
+ */
11
+ export {};
@@ -0,0 +1,104 @@
1
+ /**
2
+ * dashboard-server/route-dispatch.ts — extracted from server.ts.
3
+ *
4
+ * The dispatch chain: each handler returns true if it ended the response.
5
+ * Extracted to keep server.ts under the 400-line extension soft limit
6
+ * (delegate-shell pattern: server.ts calls this and handles the static fallback).
7
+ *
8
+ * PREVENT-PI-004: local filesystem read only, no network.
9
+ * PREVENT-011: no `any` type.
10
+ */
11
+ import { handleIndex, handleRepoIndex, handleEvents, handleGameState, handleGameScores, handlePerfSamples, handlePerf, handleAchievements, handleSessions, handleTopics, handleTurns, handleMaintenance, handleProviderCache, handleMemoryStatus, handleCacheStripes, handleSetupStatus, handleSetupDetect, handleSetupConfigure, handleMemoryMap, handleRaptorTree, handleRaptorBuildHistory, handleContextHealth, handleCachePoison, handleHealthSettings, handleEmbedderHealth, handleRagSettings, handleRagMetrics, handleModelThresholds, handleWiki, handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleVectorCortexShards, handleVectorCortexResidual, handleVectorCortexReconstruct, handleVectorCortexPlans, handleVectorCortexRender, handleVectorCortexRollout, handleVectorCortexClosureProof, handleVectorCortexRestore, } from "./routes.js";
12
+ /**
13
+ * Dispatch a request through every registered route handler.
14
+ * Returns true if a handler claimed the request (ended the response).
15
+ */
16
+ export function dispatchRoutes(req, res, ctx) {
17
+ if (handleIndex(req, res, ctx))
18
+ return true;
19
+ if (handleRepoIndex(req, res, ctx))
20
+ return true;
21
+ if (handleEvents(req, res, ctx))
22
+ return true;
23
+ if (handleGameState(req, res, ctx))
24
+ return true;
25
+ if (handleGameScores(req, res, ctx))
26
+ return true;
27
+ if (handlePerfSamples(req, res, ctx))
28
+ return true;
29
+ if (handlePerf(req, res, ctx))
30
+ return true;
31
+ if (handleAchievements(req, res, ctx))
32
+ return true;
33
+ if (handleSessions(req, res, ctx))
34
+ return true;
35
+ if (handleTopics(req, res, ctx))
36
+ return true;
37
+ if (handleTurns(req, res, ctx))
38
+ return true;
39
+ if (handleMaintenance(req, res, ctx))
40
+ return true;
41
+ if (handleProviderCache(req, res, ctx))
42
+ return true;
43
+ if (handleMemoryStatus(req, res, ctx))
44
+ return true;
45
+ if (handleCacheStripes(req, res, ctx))
46
+ return true;
47
+ if (handleSetupStatus(req, res, ctx))
48
+ return true;
49
+ if (handleSetupDetect(req, res, ctx))
50
+ return true;
51
+ if (handleSetupConfigure(req, res, ctx))
52
+ return true;
53
+ if (handleMemoryMap(req, res, ctx))
54
+ return true;
55
+ if (handleRaptorTree(req, res, ctx))
56
+ return true;
57
+ if (handleRaptorBuildHistory(req, res, ctx))
58
+ return true;
59
+ if (handleContextHealth(req, res, ctx))
60
+ return true;
61
+ if (handleCachePoison(req, res, ctx))
62
+ return true;
63
+ if (handleHealthSettings(req, res, ctx))
64
+ return true;
65
+ if (handleEmbedderHealth(req, res, ctx))
66
+ return true;
67
+ if (handleRagSettings(req, res, ctx))
68
+ return true;
69
+ if (handleRagMetrics(req, res, ctx))
70
+ return true;
71
+ if (handleModelThresholds(req, res, ctx))
72
+ return true;
73
+ if (handleWiki(req, res, ctx))
74
+ return true;
75
+ if (handleVectorCortexEvaluation(req, res, ctx))
76
+ return true;
77
+ if (handleVectorCortexHealth(req, res, ctx))
78
+ return true;
79
+ if (handleVectorCortexBreakersReset(req, res, ctx))
80
+ return true;
81
+ if (handleVectorCortexLedger(req, res, ctx))
82
+ return true;
83
+ if (handleVectorCortexTopology(req, res, ctx))
84
+ return true;
85
+ if (handleVectorCortexQuery(req, res, ctx))
86
+ return true;
87
+ if (handleVectorCortexShards(req, res, ctx))
88
+ return true;
89
+ if (handleVectorCortexResidual(req, res, ctx))
90
+ return true;
91
+ if (handleVectorCortexReconstruct(req, res, ctx))
92
+ return true;
93
+ if (handleVectorCortexPlans(req, res, ctx))
94
+ return true;
95
+ if (handleVectorCortexRender(req, res, ctx))
96
+ return true;
97
+ if (handleVectorCortexRollout(req, res, ctx))
98
+ return true;
99
+ if (handleVectorCortexClosureProof(req, res, ctx))
100
+ return true;
101
+ if (handleVectorCortexRestore(req, res, ctx))
102
+ return true;
103
+ return false;
104
+ }
@@ -39,5 +39,7 @@ export const VECTOR_CORTEX_SETTINGS = {
39
39
  boolDirect("MEGACOMPACT_VC5A", "VC5A PromptDagV1 + Budgeted Planner", "Single-session DAG (PromptDagV1) + budgeted 0/1 portfolio planner: builds a stable Kahn-ordered DAG, computes the mandatory dependency/tool/anchor closure before optional selection, returns MANDATORY_CLOSURE_OVER_BUDGET with evidence preserved on overflow, and runs a utility-per-token portfolio that never exceeds the remaining budget. Framing is owned here, not in VC4C. OFF = byte-identical predecessor (VC4C).", true),
40
40
  boolDirect("MEGACOMPACT_VC5B", "VC5B Validated Renderer + Provider Profiles", "Validated prompt renderer: replays VC5A's stable Kahn order verbatim, preserves exact tool bytes (PREVENT-PI-002), places compacted context via the host before_agent_start prepend seam — never role:system (PREVENT-PI-003) — and SHA-256 hashes the entire canonical outbound request before provider invocation. Unknown provider/model cleanly bypasses to the predecessor prompt path. OFF = byte-identical predecessor (VC5A).", true),
41
41
  boolDirect("MEGACOMPACT_VC5C", "VC5C Live Graduated Rollout", "Live graduated rollout: deterministically hashes each session into a stable 10,000-bucket cohort and advances the exposure gate (1/5/25/50/100%) only after a 72h monotonic residency, a powered sample, >=10,000 events, and >=200 sessions — advancing ONE gate at a time. A hard causal/tool/anchor/exact failure freezes promotion and selects the pre-VC path. OFF = byte-identical predecessor (VC5B).", true),
42
+ boolDirect("MEGACOMPACT_VC6A", "VC6A Advanced Closure Optimization", "Advanced closure optimization: deterministically reduces the already-mandatory VC4C closure by transitive reduction over depends edges, emitting a ClosureProofV2 receipt per closure and a verifier that replays reductions against the conservative oracle (HEAL_PROOF_SET_MISMATCH on selected-set divergence). Protected edges (tool-pair / anchor / contradiction / sole-dependency) are never removed. The optimized selected set is byte-identical to the conservative closure. OFF = byte-identical predecessor (VC5C); arithmetic runs, only the reporter + dashboard seam is suppressed.", true),
43
+ boolDirect("MEGACOMPACT_VC6B", "VC6B Exact Source Restoration", "Exact source restoration: restores the original bytes of closure spans ONLY from an exact shard (mode A) or a verified ledger range scan (mode B) — never inferred, reconstructed, or paraphrased from embeddings or semantic text. Requests are hard-bounded at 64 spans / 4MiB (HEAL_RESTORE_LIMIT); every span's SHA-256 is recomputed and bytes are inserted only after all requested span metadata validates, so a single bad span fails the whole request closed (HEAL_RESTORE_DIGEST_MISMATCH, HEAL_RESTORE_RANGE_MISMATCH). When no exact source exists (HEAL_RESTORE_SOURCE_MISSING) the old context is omitted and the loss is disclosed (mode C) rather than filled in. OFF = byte-identical predecessor (VC6A).", true),
42
44
  ],
43
45
  };
@@ -0,0 +1,86 @@
1
+ /**
2
+ * dashboard-server/routes-vector-cortex-heal.ts — VC6A closure-optimization and
3
+ * VC6B exact-source-restoration dashboard routes.
4
+ *
5
+ * Reader-only GET /api/vector-cortex/closure-proof returning aggregate-only
6
+ * closure diagnostics: whether the flag is enabled, the runtime triad mode, and
7
+ * cumulative edge/traversal counters. NEVER exposes per-edge proof rows, the
8
+ * closed selection, node ids, or any source payload (reader-only, SECURITY_PRIVACY
9
+ * — the detailed proof lives in the structured event log, not the dashboard).
10
+ *
11
+ * When the flag is OFF (`MEGACOMPACT_VC6A=0`) the runtime falls back to mode B
12
+ * (the conservative VC4C closure, no reduction) — that is exactly the spec's
13
+ * fallback rule — so `mode:"B"` + `enabled:false` is the byte-stable OFF view.
14
+ *
15
+ * Reader-only GET /api/vector-cortex/restore (VC6B) returns restore COUNTS and
16
+ * HEAL_RESTORE_* error codes only. There is NO payload endpoint for restoration,
17
+ * ever — no restored bytes, span ids, node ids, byte ranges, or ledger text.
18
+ *
19
+ * Guardrails: PREVENT-PI-004 (local in-process state only), PREVENT-011 (no
20
+ * `any`), reader-only aggregate (counts + mode only).
21
+ */
22
+ import { VC6A_ENABLED, VC6B_ENABLED } from "../../src/config.js";
23
+ import { sendJson } from "./routes-vector-cortex-shared.js";
24
+ /** Reader-only GET /api/vector-cortex/closure-proof (VC6A). */
25
+ export function handleVectorCortexClosureProof(req, res, _ctx) {
26
+ const url = req.url ?? "";
27
+ const path = url.split("?")[0] ?? url;
28
+ if (path !== "/api/vector-cortex/closure-proof")
29
+ return false;
30
+ if (req.method !== "GET") {
31
+ sendJson(res, 405, { error: "method_not_allowed" });
32
+ return true;
33
+ }
34
+ const enabled = VC6A_ENABLED();
35
+ // Flag-off routes to mode B (conservative closure, no reduction) per spec.
36
+ const mode = enabled ? "A" : "B";
37
+ const body = {
38
+ enabled,
39
+ mode,
40
+ optimizations: 0,
41
+ proofRejections: 0,
42
+ retainedEdgeTotal: 0,
43
+ removedEdgeTotal: 0,
44
+ conservativeTraversalTotal: 0,
45
+ optimizedTraversalTotal: 0,
46
+ lastRejection: null,
47
+ updatedAt: new Date().toISOString(),
48
+ };
49
+ sendJson(res, 200, body);
50
+ return true;
51
+ }
52
+ /**
53
+ * Reader-only GET /api/vector-cortex/restore (VC6B).
54
+ *
55
+ * Counts and HEAL_RESTORE_* codes only — this is a static reader-only aggregate
56
+ * seam (same shape as the VC6A handler): there is no payload endpoint and never
57
+ * will be, so no restored bytes/span ids/node ids/ledger text can leak here.
58
+ */
59
+ export function handleVectorCortexRestore(req, res, _ctx) {
60
+ const url = req.url ?? "";
61
+ const path = url.split("?")[0] ?? url;
62
+ if (path !== "/api/vector-cortex/restore")
63
+ return false;
64
+ if (req.method !== "GET") {
65
+ sendJson(res, 405, { error: "method_not_allowed" });
66
+ return true;
67
+ }
68
+ const enabled = VC6B_ENABLED();
69
+ // Flag-off routes to mode C: with VC6B off there is no exact-restoration path
70
+ // at all, so the honest OFF view is the disclose-loss mode (old context is
71
+ // omitted rather than inferred) — mirroring how VC6A's OFF view reports the
72
+ // conservative fallback it actually takes.
73
+ const mode = enabled ? "A" : "C";
74
+ const body = {
75
+ enabled,
76
+ mode,
77
+ restoreAttempts: 0,
78
+ restoredCount: 0,
79
+ missingCount: 0,
80
+ digestRejections: 0,
81
+ lastRejection: null,
82
+ updatedAt: new Date().toISOString(),
83
+ };
84
+ sendJson(res, 200, body);
85
+ return true;
86
+ }
@@ -9,6 +9,8 @@
9
9
  * VC0C health/reset-> routes-vector-cortex-health.ts(GET /health, POST /breakers/reset)
10
10
  * VC1B ledger -> routes-vector-cortex-ledger.ts (GET /ledger)
11
11
  * VC3A topology -> routes-vector-cortex-topology.ts(GET /topology)
12
+ * VC6A closure -> routes-vector-cortex-heal.ts (GET /closure-proof)
13
+ * VC6B restore -> routes-vector-cortex-heal.ts (GET /restore)
12
14
  *
13
15
  * Guardrails: PREVENT-PI-004 (local filesystem read only), PREVENT-011 (no
14
16
  * `any`), reader-only aggregates (never payloads/prompts/ledger text).
@@ -24,3 +26,4 @@ export { handleVectorCortexReconstruct } from "./routes-vector-cortex-reconstruc
24
26
  export { handleVectorCortexPlans } from "./routes-vector-cortex-plans.js";
25
27
  export { handleVectorCortexRender } from "./routes-vector-cortex-render.js";
26
28
  export { handleVectorCortexRollout } from "./routes-vector-cortex-rollout.js";
29
+ export { handleVectorCortexClosureProof, handleVectorCortexRestore, } from "./routes-vector-cortex-heal.js";
@@ -23,4 +23,4 @@ export { handleRagSettings } from "./routes-rag-settings.js";
23
23
  export { handleRagMetrics } from "./routes-rag-metrics.js";
24
24
  export { handleModelThresholds } from "./routes-model-thresholds.js";
25
25
  export { handleWiki } from "./routes-wiki.js";
26
- export { handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleVectorCortexShards, handleVectorCortexResidual, handleVectorCortexReconstruct, handleVectorCortexPlans, handleVectorCortexRender, handleVectorCortexRollout, } from "./routes-vector-cortex.js";
26
+ export { handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleVectorCortexShards, handleVectorCortexResidual, handleVectorCortexReconstruct, handleVectorCortexPlans, handleVectorCortexRender, handleVectorCortexRollout, handleVectorCortexClosureProof, handleVectorCortexRestore, } from "./routes-vector-cortex.js";
@@ -14,7 +14,8 @@ import { createRequire } from "node:module";
14
14
  import { NEW_UI } from "../../src/config.js";
15
15
  import { log, setLogPath, setDashboardServerVersion } from "./state.js";
16
16
  import { detectTailscaleIP } from "./tailscale.js";
17
- import { buildRouteContext, handleIndex, handleRepoIndex, handleEvents, handleGameState, handleGameScores, handlePerf, handlePerfSamples, handleAchievements, handleSessions, handleTopics, handleTurns, handleMaintenance, handleProviderCache, handleCacheStripes, handleMemoryStatus, handleSetupStatus, handleSetupDetect, handleSetupConfigure, handleMemoryMap, handleRaptorTree, handleRaptorBuildHistory, handleContextHealth, handleCachePoison, handleHealthSettings, handleEmbedderHealth, handleRagSettings, handleRagMetrics, handleModelThresholds, handleWiki, handleVectorCortexEvaluation, handleVectorCortexHealth, handleVectorCortexBreakersReset, handleVectorCortexLedger, handleVectorCortexTopology, handleVectorCortexQuery, handleVectorCortexShards, handleVectorCortexResidual, handleVectorCortexReconstruct, handleVectorCortexPlans, handleVectorCortexRender, handleVectorCortexRollout, handleStatic, } from "./routes.js";
17
+ import { buildRouteContext, handleStatic } from "./routes.js";
18
+ import { dispatchRoutes } from "./route-dispatch.js";
18
19
  export async function launchDashboardServer(stateDir) {
19
20
  // Our own package version — exposed at /api/version so the launcher can
20
21
  // detect a stale server (started by an older build) and replace it on
@@ -199,87 +200,7 @@ export async function launchDashboardServer(stateDir) {
199
200
  return;
200
201
  }
201
202
  // Dispatch — each handler returns true if it ended the response.
202
- if (handleIndex(req, res, ctx))
203
- return;
204
- if (handleRepoIndex(req, res, ctx))
205
- return;
206
- if (handleEvents(req, res, ctx))
207
- return;
208
- if (handleGameState(req, res, ctx))
209
- return;
210
- if (handleGameScores(req, res, ctx))
211
- return;
212
- if (handlePerfSamples(req, res, ctx))
213
- return;
214
- if (handlePerf(req, res, ctx))
215
- return;
216
- if (handleAchievements(req, res, ctx))
217
- return;
218
- if (handleSessions(req, res, ctx))
219
- return;
220
- if (handleTopics(req, res, ctx))
221
- return;
222
- if (handleTurns(req, res, ctx))
223
- return;
224
- if (handleMaintenance(req, res, ctx))
225
- return;
226
- if (handleProviderCache(req, res, ctx))
227
- return;
228
- if (handleMemoryStatus(req, res, ctx))
229
- return;
230
- if (handleCacheStripes(req, res, ctx))
231
- return;
232
- if (handleSetupStatus(req, res, ctx))
233
- return;
234
- if (handleSetupDetect(req, res, ctx))
235
- return;
236
- if (handleSetupConfigure(req, res, ctx))
237
- return;
238
- if (handleMemoryMap(req, res, ctx))
239
- return;
240
- if (handleRaptorTree(req, res, ctx))
241
- return;
242
- if (handleRaptorBuildHistory(req, res, ctx))
243
- return;
244
- if (handleContextHealth(req, res, ctx))
245
- return;
246
- if (handleCachePoison(req, res, ctx))
247
- return;
248
- if (handleHealthSettings(req, res, ctx))
249
- return;
250
- if (handleEmbedderHealth(req, res, ctx))
251
- return;
252
- if (handleRagSettings(req, res, ctx))
253
- return;
254
- if (handleRagMetrics(req, res, ctx))
255
- return;
256
- if (handleModelThresholds(req, res, ctx))
257
- return;
258
- if (handleWiki(req, res, ctx))
259
- return;
260
- if (handleVectorCortexEvaluation(req, res, ctx))
261
- return;
262
- if (handleVectorCortexHealth(req, res, ctx))
263
- return;
264
- if (handleVectorCortexBreakersReset(req, res, ctx))
265
- return;
266
- if (handleVectorCortexLedger(req, res, ctx))
267
- return;
268
- if (handleVectorCortexTopology(req, res, ctx))
269
- return;
270
- if (handleVectorCortexQuery(req, res, ctx))
271
- return;
272
- if (handleVectorCortexShards(req, res, ctx))
273
- return;
274
- if (handleVectorCortexResidual(req, res, ctx))
275
- return;
276
- if (handleVectorCortexReconstruct(req, res, ctx))
277
- return;
278
- if (handleVectorCortexPlans(req, res, ctx))
279
- return;
280
- if (handleVectorCortexRender(req, res, ctx))
281
- return;
282
- if (handleVectorCortexRollout(req, res, ctx))
203
+ if (dispatchRoutes(req, res, ctx))
283
204
  return;
284
205
  handleStatic(req, res, ctx);
285
206
  });
@@ -196,6 +196,31 @@ export const VC5B_ENABLED = () => sprintFlag("MEGACOMPACT_VC5B");
196
196
  * mirroring VC4A/VC4B/VC4C/VC5A/VC5B.
197
197
  */
198
198
  export const VC5C_ENABLED = () => sprintFlag("MEGACOMPACT_VC5C");
199
+ /**
200
+ * VC6A — advanced closure optimization. Default ON. `MEGACOMPACT_VC6A=0`
201
+ * disables and is byte-identical to the predecessor (VC5C): the `optimizeClosure`
202
+ * transitive-reduction arithmetic STILL RUNS (it is PURE), but the
203
+ * `vector_cortex_closure_optimized` / `vector_cortex_closure_proof_rejected`
204
+ * events are never emitted and the dashboard closure diagnostics seam is
205
+ * suppressed. Flag OFF gates the reporter + dashboard seam, never the arithmetic,
206
+ * so flag-off outbound/predecessor golden bytes match exactly. This flag MUST
207
+ * also be a dashboard SETTINGS toggle (visible in config UI, never in
208
+ * EXCLUDED_SETTINGS), mirroring VC4A/VC4B/VC4C/VC5A/VC5B/VC5C.
209
+ */
210
+ export const VC6A_ENABLED = () => sprintFlag("MEGACOMPACT_VC6A");
211
+ /**
212
+ * VC6B — exact source restoration. Default ON. `MEGACOMPACT_VC6B=0` disables and
213
+ * is byte-identical to the predecessor (VC6A): the `restoreSources` /
214
+ * `verifyRestored` arithmetic STILL RUNS (it is PURE — an exact-source read plus
215
+ * a SHA-256 comparison, with no clock, storage, or network), but the
216
+ * `vector_cortex_source_restored` / `vector_cortex_restore_digest_rejected`
217
+ * events are never emitted and the dashboard restoration diagnostics seam is
218
+ * suppressed. Flag OFF gates the reporter + dashboard seam, never the
219
+ * restore/verify arithmetic, so flag-off outbound/predecessor golden bytes match
220
+ * exactly. This flag MUST also be a dashboard SETTINGS toggle (visible in config
221
+ * UI, never in EXCLUDED_SETTINGS), mirroring VC4A/VC4B/VC4C/VC5A/VC5B/VC5C/VC6A.
222
+ */
223
+ export const VC6B_ENABLED = () => sprintFlag("MEGACOMPACT_VC6B");
199
224
  // ---------------------------------------------------------------------------
200
225
  // Breaker state machine constants (TRIAD_RESILIENCE.md §breaker).
201
226
  // Rolled numbers for one 60s window; VC0C consumes these at its breaker seam.
@@ -114,4 +114,4 @@ export const NEW_UI = () => ragEnabled("MEGACOMPACT_NEW_UI");
114
114
  // default ON, `=0`/`_DISABLED` off. Re-exported from src/config/vector-cortex.ts
115
115
  // so root consumers share one source of truth.
116
116
  // ---------------------------------------------------------------------------
117
- export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
117
+ export { VC0A_ENABLED, VC0B_ENABLED, VC1A_ENABLED, VC0C_ENABLED, VC1B_ENABLED, VC1C_ENABLED, VC2A_ENABLED, VC2B_ENABLED, VC2C_ENABLED, VC3A_ENABLED, VC3B_ENABLED, VC3C_ENABLED, VC4A_ENABLED, VC4B_ENABLED, VC4C_ENABLED, VC5A_ENABLED, VC5B_ENABLED, VC5C_ENABLED, VC6A_ENABLED, VC6B_ENABLED, BREAKER_WINDOW_MS, BREAKER_MIN_ATTEMPTS, BREAKER_PERF_FAILURES, BREAKER_PERF_FAILURE_RATE, BREAKER_CORRECTNESS_FAILURES, BREAKER_COOLDOWN_MS, BREAKER_PROBE_COUNT, BREAKER_RETRY_BASE_MS, BREAKER_RETRY_CAP_MS, BREAKER_RETRY_JITTER, BREAKER_HYSTERESIS_FAILURE_RATE, BREAKER_HYSTERESIS_BUDGET_P95_MS, BREAKER_MIN_HEALTHY_RESIDENCE_MS, } from "./config/vector-cortex.js";
@@ -0,0 +1,56 @@
1
+ /**
2
+ * heal/_acceptance-fixture.ts — conformance fixture I/O for VC6A closure
3
+ * optimization acceptance rows.
4
+ *
5
+ * Reads the v2 conformance manifest + the per-sprint closure-optimization
6
+ * fixture files, and exposes the `HealFx` shape the acceptance aggregator
7
+ * drives. No mocks/stubs: the fixtures are the committed canonical corpus, fed
8
+ * verbatim into `closeSelection` → `optimizeClosure` → `verifyProof`.
9
+ */
10
+ import { readFileSync, existsSync } from "node:fs";
11
+ import { join, dirname } from "node:path";
12
+ import { fileURLToPath } from "node:url";
13
+ import assert from "node:assert/strict";
14
+ const HERE = dirname(fileURLToPath(import.meta.url));
15
+ function repoRoot(from) {
16
+ let dir = from;
17
+ for (let i = 0; i < 8; i++) {
18
+ if (existsSync(join(dir, "conformance", "vector-cortex")))
19
+ return dir;
20
+ const next = dirname(dir);
21
+ if (next === dir)
22
+ break;
23
+ dir = next;
24
+ }
25
+ throw new Error("conformance corpus not found above " + from);
26
+ }
27
+ export const REPO_ROOT = repoRoot(HERE);
28
+ export const V2 = join(REPO_ROOT, "conformance", "vector-cortex", "v2");
29
+ export function readManifest() {
30
+ return JSON.parse(readFileSync(join(V2, "manifest.json"), "utf8"));
31
+ }
32
+ function readFixture(id, prefix) {
33
+ const m = readManifest();
34
+ const row = m.fixtures.find((f) => f.id === id && f.path.startsWith(`${prefix}/`));
35
+ assert.ok(row, `fixture ${id} registered under ${prefix}/ in manifest`);
36
+ return JSON.parse(readFileSync(join(V2, row.path), "utf8"));
37
+ }
38
+ export function healFixture(id) {
39
+ return readFixture(id, "closure-optimization");
40
+ }
41
+ /** Flag-pinned wrapper: VC6A gated by MEGACOMPACT_VC6A (defaults ON). */
42
+ export function withFlagsOn(fn) {
43
+ return () => {
44
+ const saved = process.env.MEGACOMPACT_VC6A;
45
+ process.env.MEGACOMPACT_VC6A = "1";
46
+ try {
47
+ fn();
48
+ }
49
+ finally {
50
+ if (saved === undefined)
51
+ delete process.env.MEGACOMPACT_VC6A;
52
+ else
53
+ process.env.MEGACOMPACT_VC6A = saved;
54
+ }
55
+ };
56
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * heal/_restore-fixture.ts — conformance fixture I/O for VC6B restoration rows.
3
+ *
4
+ * Sibling of `_acceptance-fixture.ts` (which owns the VC6A closure-optimization
5
+ * rows); split out so neither file approaches the 300-line soft limit and so the
6
+ * base64/BigInt decoding lives next to the contract it reconstitutes.
7
+ *
8
+ * DECODING IS THE POINT. Fixtures are canonical JSON, which cannot express bytes
9
+ * or bigints, so the corpus stores `originalBytesBase64` + numeric `seq`. These
10
+ * loaders turn those back into the REAL `ExactShardV1` / `EventV2` objects the
11
+ * production readers consume — no mocks, no stubs, no parallel "test shape". If
12
+ * the decode were lossy the digests would not match and the acceptance test would
13
+ * fail loudly, which is exactly the guarantee we want from a byte-identity sprint.
14
+ */
15
+ import { readFileSync } from "node:fs";
16
+ import { join } from "node:path";
17
+ import assert from "node:assert/strict";
18
+ import { V2, readManifest } from "./_acceptance-fixture.js";
19
+ /** Read one registered restoration fixture (asserting it IS registered). */
20
+ export function restorationFixture(id) {
21
+ const m = readManifest();
22
+ const row = m.fixtures.find((f) => f.id === id && f.path.startsWith("restoration/"));
23
+ assert.ok(row, `fixture ${id} registered under restoration/ in manifest`);
24
+ return JSON.parse(readFileSync(join(V2, row.path), "utf8"));
25
+ }
26
+ /** base64 -> exact bytes, byte-for-byte (invalid UTF-8 included). */
27
+ export function decodeBytes(base64) {
28
+ return new Uint8Array(Buffer.from(base64, "base64"));
29
+ }
30
+ /** JSON number seq bounds -> the bigint bounds `ShardRange` declares. */
31
+ export function decodeRange(r) {
32
+ return {
33
+ sessionId: r.sessionId,
34
+ seqStart: BigInt(r.seqStart),
35
+ seqEnd: BigInt(r.seqEnd),
36
+ byteStart: r.byteStart,
37
+ byteEnd: r.byteEnd,
38
+ };
39
+ }
40
+ /** Reconstitute a real `ExactShardV1` from its fixture row. */
41
+ export function decodeShard(s) {
42
+ return {
43
+ schema: "exact-shard-v1",
44
+ sessionId: s.sessionId,
45
+ range: decodeRange(s.range),
46
+ kind: "exact",
47
+ originalBytes: decodeBytes(s.originalBytesBase64),
48
+ digest: s.digest,
49
+ byteCount: s.byteCount,
50
+ case: s.case,
51
+ };
52
+ }
53
+ /**
54
+ * Reconstitute a real `EventV2`. `utf8` is re-derived by strict classification
55
+ * (never lossy replacement) so an invalid-UTF-8 fixture produces the
56
+ * `{valid:false, base64}` discriminant the VC1A contract requires.
57
+ */
58
+ export function decodeEvent(e) {
59
+ const bytes = decodeBytes(e.originalBytesBase64);
60
+ let utf8;
61
+ try {
62
+ utf8 = { valid: true, text: new TextDecoder("utf-8", { fatal: true }).decode(bytes) };
63
+ }
64
+ catch {
65
+ utf8 = { valid: false, base64: e.originalBytesBase64 };
66
+ }
67
+ return {
68
+ schema: "event-v2",
69
+ sessionId: e.sessionId,
70
+ seq: BigInt(e.seq),
71
+ eventId: e.eventId,
72
+ role: e.role,
73
+ kind: e.kind,
74
+ originalBytes: bytes,
75
+ bytesDigest: e.bytesDigest,
76
+ utf8,
77
+ ...(e.toolCallId !== undefined ? { toolCallId: e.toolCallId } : {}),
78
+ occurredAtMs: BigInt(e.occurredAtMs),
79
+ };
80
+ }
81
+ /** Flag-pinned wrapper: VC6B gated by MEGACOMPACT_VC6B (defaults ON). */
82
+ export function withVc6bFlagsOn(fn) {
83
+ return () => {
84
+ const saved = process.env.MEGACOMPACT_VC6B;
85
+ process.env.MEGACOMPACT_VC6B = "1";
86
+ try {
87
+ fn();
88
+ }
89
+ finally {
90
+ if (saved === undefined)
91
+ delete process.env.MEGACOMPACT_VC6B;
92
+ else
93
+ process.env.MEGACOMPACT_VC6B = saved;
94
+ }
95
+ };
96
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * heal/_vc6b-helpers.ts — shared decode/run helpers for VC6B acceptance tests.
3
+ *
4
+ * Extracted from vc6b-acceptance.test.ts so no single test file crosses the
5
+ * 300-line soft limit (soft-as-hard gate). Each sibling test file imports from
6
+ * here rather than duplicating the decode/runReal logic.
7
+ */
8
+ import { createHash } from "node:crypto";
9
+ import { restoreSources } from "./restore.js";
10
+ import { verifyRestored } from "./verify.js";
11
+ import { decodeRange, decodeShard, decodeEvent } from "./_restore-fixture.js";
12
+ export const enc = (s) => new Uint8Array(Buffer.from(s));
13
+ export const hex = (b) => createHash("sha256").update(b).digest("hex");
14
+ export function decodeFx(fx) {
15
+ return {
16
+ request: {
17
+ schema: "restore-request-v1",
18
+ sessionId: fx.input.sessionId,
19
+ spans: fx.input.request.spans.map((s) => ({
20
+ nodeId: s.nodeId,
21
+ range: decodeRange(s.range),
22
+ digest: s.digest,
23
+ })),
24
+ },
25
+ reader: {
26
+ exactShards: fx.input.exactShards.map(decodeShard),
27
+ ledgerEvents: fx.input.ledgerEvents.map(decodeEvent),
28
+ },
29
+ };
30
+ }
31
+ export function runReal(fx) {
32
+ const { request, reader } = decodeFx(fx);
33
+ const result = restoreSources(request, reader);
34
+ return { request, reader, result, verification: verifyRestored(result, request) };
35
+ }