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.
- package/dist/config/vector-cortex.js +25 -0
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/api-contracts/vector-cortex-heal.js +11 -0
- package/dist/extensions/dashboard-server/route-dispatch.js +104 -0
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +2 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex-heal.js +86 -0
- package/dist/extensions/dashboard-server/routes-vector-cortex.js +3 -0
- package/dist/extensions/dashboard-server/routes.js +1 -1
- package/dist/extensions/dashboard-server/server.js +3 -82
- package/dist/src/config/vector-cortex.js +25 -0
- package/dist/src/config.js +1 -1
- package/dist/src/vector-cortex/heal/_acceptance-fixture.js +56 -0
- package/dist/src/vector-cortex/heal/_restore-fixture.js +96 -0
- package/dist/src/vector-cortex/heal/_vc6b-helpers.js +35 -0
- package/dist/src/vector-cortex/heal/closure-metrics.js +66 -0
- package/dist/src/vector-cortex/heal/closure-opt.js +242 -0
- package/dist/src/vector-cortex/heal/emit.js +69 -0
- package/dist/src/vector-cortex/heal/proof.js +210 -0
- package/dist/src/vector-cortex/heal/restore-emit.js +70 -0
- package/dist/src/vector-cortex/heal/restore-readers.js +114 -0
- package/dist/src/vector-cortex/heal/restore-types.js +66 -0
- package/dist/src/vector-cortex/heal/restore.js +140 -0
- package/dist/src/vector-cortex/heal/types.js +43 -0
- package/dist/src/vector-cortex/heal/verify.js +75 -0
- package/dist/vector-cortex/heal/_acceptance-fixture.js +56 -0
- package/dist/vector-cortex/heal/_restore-fixture.js +96 -0
- package/dist/vector-cortex/heal/_vc6b-helpers.js +35 -0
- package/dist/vector-cortex/heal/closure-metrics.js +66 -0
- package/dist/vector-cortex/heal/closure-opt.js +242 -0
- package/dist/vector-cortex/heal/emit.js +69 -0
- package/dist/vector-cortex/heal/proof.js +210 -0
- package/dist/vector-cortex/heal/restore-emit.js +70 -0
- package/dist/vector-cortex/heal/restore-readers.js +114 -0
- package/dist/vector-cortex/heal/restore-types.js +66 -0
- package/dist/vector-cortex/heal/restore.js +140 -0
- package/dist/vector-cortex/heal/types.js +43 -0
- package/dist/vector-cortex/heal/verify.js +75 -0
- package/extensions/dashboard-client/dist/assets/{AreaChart-DqTbaSRA.js → AreaChart-fxyq2KaH.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{AreaChart-DqTbaSRA.js.map → AreaChart-fxyq2KaH.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{BarChart-BfNBeOvF.js → BarChart-D5EqAINP.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{BarChart-BfNBeOvF.js.map → BarChart-D5EqAINP.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{CacheTab-C9SOMYB5.js → CacheTab-D4UWbzLo.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{CacheTab-C9SOMYB5.js.map → CacheTab-D4UWbzLo.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{EventsTab-GsMKP10_.js → EventsTab-BiXquGrX.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{EventsTab-GsMKP10_.js.map → EventsTab-BiXquGrX.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{HealthTab-DAOCXwRP.js → HealthTab-D5QvoTjy.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{HealthTab-DAOCXwRP.js.map → HealthTab-D5QvoTjy.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-BtBeMkB5.js → MaintenanceTab-Cy_-CWgM.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MaintenanceTab-BtBeMkB5.js.map → MaintenanceTab-Cy_-CWgM.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-DzndtgkZ.js → MemoryMapTab-DrAjgGOR.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MemoryMapTab-DzndtgkZ.js.map → MemoryMapTab-DrAjgGOR.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{MetricsTab-DyxJ4eb8.js → MetricsTab-BvPHcuFN.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{MetricsTab-DyxJ4eb8.js.map → MetricsTab-BvPHcuFN.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{OverviewTab-DCiEdVWR.js → OverviewTab-DsbIigOQ.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{OverviewTab-DCiEdVWR.js.map → OverviewTab-DsbIigOQ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{ReposTab-B5SIqVHA.js → ReposTab-7v_uZX_a.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{ReposTab-B5SIqVHA.js.map → ReposTab-7v_uZX_a.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SessionsTab-DLWFJ9xI.js → SessionsTab-BXGrv-6C.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SessionsTab-DLWFJ9xI.js.map → SessionsTab-BXGrv-6C.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{SetupTab-CvGXZyej.js → SetupTab-QRUXa65y.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{SetupTab-CvGXZyej.js.map → SetupTab-QRUXa65y.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-wZuQGxLS.js → TimeSavedCard-p327ZZKT.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TimeSavedCard-wZuQGxLS.js.map → TimeSavedCard-p327ZZKT.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{TurnsTab-B7aOejch.js → TurnsTab-BcmBSlik.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{TurnsTab-B7aOejch.js.map → TurnsTab-BcmBSlik.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-D2fjKNyT.js +2 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-D2fjKNyT.js.map +1 -0
- package/extensions/dashboard-client/dist/assets/{WikiTab-DhWHjAtt.js → WikiTab-DLXFMuNy.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{WikiTab-DhWHjAtt.js.map → WikiTab-DLXFMuNy.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{button-BrC-W87h.js → button-C9CghmRx.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{button-BrC-W87h.js.map → button-C9CghmRx.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{card-0rgfRgr3.js → card-DWU-1y3t.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{card-0rgfRgr3.js.map → card-DWU-1y3t.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DRresOQF.js → generateCategoricalChart-Dayy9dGn.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{generateCategoricalChart-DRresOQF.js.map → generateCategoricalChart-Dayy9dGn.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{index-DohmtZWL.js → index-D9PsW3VZ.js} +3 -3
- package/extensions/dashboard-client/dist/assets/{index-DohmtZWL.js.map → index-D9PsW3VZ.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{switch-Bs8g_zB5.js → switch-CnLFAmVT.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{switch-Bs8g_zB5.js.map → switch-CnLFAmVT.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{toggle-DVVauIo8.js → toggle-HN5C7_vy.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{toggle-DVVauIo8.js.map → toggle-HN5C7_vy.js.map} +1 -1
- package/extensions/dashboard-client/dist/assets/{useSSE-DxH1PTAR.js → useSSE-DoJfk3Ce.js} +2 -2
- package/extensions/dashboard-client/dist/assets/{useSSE-DxH1PTAR.js.map → useSSE-DoJfk3Ce.js.map} +1 -1
- package/extensions/dashboard-client/dist/index.html +1 -1
- package/extensions/dashboard-client/src/api/vector-cortex.ts +18 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexClosureCard.tsx +46 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexLedgerCard.tsx +80 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexRestoreCard.tsx +42 -0
- package/extensions/dashboard-client/src/tabs/VectorCortexTab.tsx +20 -164
- package/extensions/dashboard-client/src/tabs/VectorCortexTopologyCard.tsx +131 -0
- package/extensions/dashboard-client/src/types/vector-cortex.ts +30 -0
- package/extensions/dashboard-server/api-contracts/vector-cortex-heal.ts +73 -0
- package/extensions/dashboard-server/api-contracts/vector-cortex.ts +5 -0
- package/extensions/dashboard-server/route-dispatch.ts +114 -0
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +12 -0
- package/extensions/dashboard-server/routes-vector-cortex-heal.ts +103 -0
- package/extensions/dashboard-server/routes-vector-cortex.ts +6 -0
- package/extensions/dashboard-server/routes.ts +2 -0
- package/extensions/dashboard-server/server.ts +3 -86
- package/package.json +1 -1
- package/src/config/vector-cortex.ts +27 -0
- package/src/config.ts +2 -0
- package/src/vector-cortex/heal/_acceptance-fixture.ts +108 -0
- package/src/vector-cortex/heal/_restore-fixture.ts +163 -0
- package/src/vector-cortex/heal/_vc6b-helpers.ts +55 -0
- package/src/vector-cortex/heal/closure-metrics.ts +73 -0
- package/src/vector-cortex/heal/closure-opt.ts +266 -0
- package/src/vector-cortex/heal/emit.ts +93 -0
- package/src/vector-cortex/heal/proof.ts +234 -0
- package/src/vector-cortex/heal/restore-emit.ts +94 -0
- package/src/vector-cortex/heal/restore-readers.ts +145 -0
- package/src/vector-cortex/heal/restore-types.ts +185 -0
- package/src/vector-cortex/heal/restore.ts +165 -0
- package/src/vector-cortex/heal/types.ts +248 -0
- package/src/vector-cortex/heal/verify.ts +93 -0
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-eHVt9yDx.js +0 -2
- package/extensions/dashboard-client/dist/assets/VectorCortexTab-eHVt9yDx.js.map +0 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/heal/restore-readers.ts — the two EXACT source readers (VC6B).
|
|
3
|
+
*
|
|
4
|
+
* Split out of `restore.ts` so the orchestrator stays a short, readable policy
|
|
5
|
+
* file and each reader can be reasoned about on its own (PRACTICES: split at the
|
|
6
|
+
* 300-line soft limit, delegate-shell + impl).
|
|
7
|
+
*
|
|
8
|
+
* Both readers share one discipline: they return bytes ONLY after recomputing
|
|
9
|
+
* SHA-256 over the bytes they actually hold and comparing it to the digest the
|
|
10
|
+
* REQUEST pinned. Neither reader trusts the digest recorded alongside its own
|
|
11
|
+
* source — an `ExactShardV1.digest` is metadata that lives in the same file as
|
|
12
|
+
* the bytes, so a swapped file carries a matching (wrong) pair. Only the
|
|
13
|
+
* caller-supplied digest is authoritative, and only a fresh hash of the fetched
|
|
14
|
+
* bytes can be checked against it.
|
|
15
|
+
*
|
|
16
|
+
* Pure/deterministic/local: `node:crypto` only (a Node built-in, not a network
|
|
17
|
+
* call), no storage, no console (PREVENT-PI-004 / PREVENT-011).
|
|
18
|
+
*/
|
|
19
|
+
import { createHash } from "node:crypto";
|
|
20
|
+
/**
|
|
21
|
+
* SHA-256 over bytes as LOWERCASE HEX with NO `sha256:` prefix — the
|
|
22
|
+
* `ExactShardV1.digest` / `ReconstructionSpan.digest` / `RestoreSpanRequest`
|
|
23
|
+
* convention. `EventV2.bytesDigest` prefixes this same value with `sha256:`.
|
|
24
|
+
*/
|
|
25
|
+
export function sha256Hex(bytes) {
|
|
26
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Strip the `sha256:` prefix from an `EventV2.bytesDigest` so it can be compared
|
|
30
|
+
* against a bare hex digest. A value that does not carry the prefix is returned
|
|
31
|
+
* unchanged rather than mangled — the comparison then simply fails, which is the
|
|
32
|
+
* correct outcome for a malformed record.
|
|
33
|
+
*/
|
|
34
|
+
export function bareHex(digest) {
|
|
35
|
+
return digest.startsWith("sha256:") ? digest.slice("sha256:".length) : digest;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Structural range equality. All five components must match: two spans over the
|
|
39
|
+
* same seq window but different byte offsets are DIFFERENT spans (a re-encoded
|
|
40
|
+
* or re-offset stream is not the stream that was requested).
|
|
41
|
+
*/
|
|
42
|
+
export function rangeEquals(a, b) {
|
|
43
|
+
return (a.sessionId === b.sessionId &&
|
|
44
|
+
a.seqStart === b.seqStart &&
|
|
45
|
+
a.seqEnd === b.seqEnd &&
|
|
46
|
+
a.byteStart === b.byteStart &&
|
|
47
|
+
a.byteEnd === b.byteEnd);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Mode A — indexed exact-shard read.
|
|
51
|
+
*
|
|
52
|
+
* Selection is by RANGE identity plus the shard's own recorded digest, which
|
|
53
|
+
* narrows the candidate set the way a real index lookup would. The accepted
|
|
54
|
+
* candidate is then re-hashed from its `originalBytes`: this second check is
|
|
55
|
+
* what catches a shard whose bytes were swapped AFTER the index lookup resolved
|
|
56
|
+
* (the sprint's unique failure injection). A candidate that matches by range but
|
|
57
|
+
* fails either digest check reports `digest-mismatch` — it does NOT silently fall
|
|
58
|
+
* through to the ledger, because a corrupt exact shard is a fact worth surfacing.
|
|
59
|
+
*/
|
|
60
|
+
export function readExactShard(shards, range, digest) {
|
|
61
|
+
const byRange = shards.filter((s) => rangeEquals(s.range, range));
|
|
62
|
+
if (byRange.length === 0)
|
|
63
|
+
return { kind: "absent" };
|
|
64
|
+
const candidate = byRange.find((s) => s.digest === digest);
|
|
65
|
+
if (candidate === undefined)
|
|
66
|
+
return { kind: "digest-mismatch" };
|
|
67
|
+
// Defense in depth: the shard's recorded digest is metadata, the bytes are the
|
|
68
|
+
// authority. Re-hash what we actually hold.
|
|
69
|
+
const bytes = candidate.originalBytes;
|
|
70
|
+
if (sha256Hex(bytes) !== digest)
|
|
71
|
+
return { kind: "digest-mismatch" };
|
|
72
|
+
return { kind: "bytes", bytes };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Mode B — ledger range scan.
|
|
76
|
+
*
|
|
77
|
+
* An INDEPENDENT path from mode A: no shard index is consulted. The occurrence
|
|
78
|
+
* records covering `[seqStart..seqEnd]` are selected, sorted ascending by seq
|
|
79
|
+
* (the caller's array order is untrusted — a scan that concatenated records in
|
|
80
|
+
* arrival order would produce plausible-looking but wrong bytes), each record's
|
|
81
|
+
* own `bytesDigest` is verified, and the concatenation is hashed against the
|
|
82
|
+
* span digest.
|
|
83
|
+
*
|
|
84
|
+
* Both checks matter. Per-record verification localizes corruption to a single
|
|
85
|
+
* occurrence; the span-level hash catches a scan that is individually valid but
|
|
86
|
+
* collectively wrong — a missing record in the middle of the range, or a range
|
|
87
|
+
* that covers different content than the requester believed.
|
|
88
|
+
*/
|
|
89
|
+
export function readLedgerSpan(events, range, digest) {
|
|
90
|
+
const covering = events
|
|
91
|
+
.filter((e) => e.sessionId === range.sessionId &&
|
|
92
|
+
e.seq >= range.seqStart &&
|
|
93
|
+
e.seq <= range.seqEnd)
|
|
94
|
+
.sort((a, b) => (a.seq < b.seq ? -1 : a.seq > b.seq ? 1 : 0));
|
|
95
|
+
if (covering.length === 0)
|
|
96
|
+
return { kind: "absent" };
|
|
97
|
+
// Per-record byte authority (VC1A): a record whose own digest disagrees with
|
|
98
|
+
// its bytes is corrupt, and a corrupt record can never contribute to a restore.
|
|
99
|
+
for (const e of covering) {
|
|
100
|
+
if (sha256Hex(e.originalBytes) !== bareHex(e.bytesDigest)) {
|
|
101
|
+
return { kind: "digest-mismatch" };
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const total = covering.reduce((sum, e) => sum + e.originalBytes.length, 0);
|
|
105
|
+
const bytes = new Uint8Array(total);
|
|
106
|
+
let offset = 0;
|
|
107
|
+
for (const e of covering) {
|
|
108
|
+
bytes.set(e.originalBytes, offset);
|
|
109
|
+
offset += e.originalBytes.length;
|
|
110
|
+
}
|
|
111
|
+
if (sha256Hex(bytes) !== digest)
|
|
112
|
+
return { kind: "digest-mismatch" };
|
|
113
|
+
return { kind: "bytes", bytes };
|
|
114
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/heal/restore-types.ts — VC6B exact source restoration contract.
|
|
3
|
+
*
|
|
4
|
+
* VC6A optimized WHICH EDGES the closure plan walks. VC6B answers the next
|
|
5
|
+
* question: when the plan needs a node whose bytes are no longer in the live
|
|
6
|
+
* window, WHERE do those bytes come from? The answer is deliberately narrow —
|
|
7
|
+
* an EXACT source, or nothing.
|
|
8
|
+
*
|
|
9
|
+
* THE CARDINAL RULE. Restored bytes are ONLY ever read from an exact source:
|
|
10
|
+
* 1. an `ExactShardV1` whose range and digest both match the request, or
|
|
11
|
+
* 2. a scan of the `EventV2` occurrence ledger over the requested seq range.
|
|
12
|
+
* Bytes are NEVER inferred from an embedding, a semantic shard, a RAPTOR
|
|
13
|
+
* summary, or any other derived/lossy representation. A semantic tier can tell
|
|
14
|
+
* you what a span was ABOUT; it cannot tell you what the span WAS. Attempting to
|
|
15
|
+
* "restore" from a derived source would silently fabricate transcript history,
|
|
16
|
+
* so VC6B has no code path that can do it: `RestoreReader` exposes exactly the
|
|
17
|
+
* two exact sources and nothing else.
|
|
18
|
+
*
|
|
19
|
+
* THE VERIFICATION RULE. Every restored span must hash to the SHA-256 digest the
|
|
20
|
+
* REQUEST pinned, checked immediately before insertion. A source that matches by
|
|
21
|
+
* range but not by hash is rejected (`HEAL_RESTORE_DIGEST_MISMATCH`) — never
|
|
22
|
+
* "close enough". This is what makes a swapped shard file, a truncated read, or a
|
|
23
|
+
* corrupted ledger record fail loudly instead of poisoning the reconstruction.
|
|
24
|
+
*
|
|
25
|
+
* DIGEST PINNING (three fields exist; do not confuse them).
|
|
26
|
+
* - `ReconstructionSpan.digest` and `ExactShardV1.digest` are SHA-256 in
|
|
27
|
+
* LOWERCASE HEX with NO prefix.
|
|
28
|
+
* - `EventV2.bytesDigest` is `sha256:<hex>`, WITH the prefix.
|
|
29
|
+
* `RestoreSpanRequest.digest` works at SPAN level and uses the FORMER: bare
|
|
30
|
+
* lowercase hex, matching `ExactShardV1.digest` / `ReconstructionSpan.digest`.
|
|
31
|
+
* The prefixed `EventV2.bytesDigest` is used ONLY for per-event verification
|
|
32
|
+
* inside the ledger-scan path and is never the request-level digest. Mixing the
|
|
33
|
+
* two would make every ledger restoration fail (or, worse, make a prefix-stripped
|
|
34
|
+
* comparison accidentally succeed against the wrong granularity).
|
|
35
|
+
*
|
|
36
|
+
* BOUNDS. A restore request is attacker-shaped input: it names spans and byte
|
|
37
|
+
* ranges. `RESTORE_LIMIT_SPANS` / `RESTORE_LIMIT_BYTES` bound it BEFORE any
|
|
38
|
+
* reader is consulted, so an oversized request cannot be used to make the
|
|
39
|
+
* restorer walk the whole ledger (HEAL-LIMIT-002).
|
|
40
|
+
*
|
|
41
|
+
* Pure types + registered conformance IDs: no storage, no console, no network
|
|
42
|
+
* (PREVENT-PI-004 / PREVENT-011).
|
|
43
|
+
*/
|
|
44
|
+
/**
|
|
45
|
+
* Maximum spans in one request. A request naming more spans than this is
|
|
46
|
+
* rejected outright — the bound exists so a single call cannot be turned into an
|
|
47
|
+
* unbounded traversal of the ledger.
|
|
48
|
+
*/
|
|
49
|
+
export const RESTORE_LIMIT_SPANS = 64;
|
|
50
|
+
/**
|
|
51
|
+
* Maximum aggregate requested bytes (4 MiB), summed from the REQUEST's ranges
|
|
52
|
+
* (`byteEnd - byteStart`) so the bound is enforceable without reading anything.
|
|
53
|
+
*/
|
|
54
|
+
export const RESTORE_LIMIT_BYTES = 4 * 1024 * 1024;
|
|
55
|
+
/**
|
|
56
|
+
* Registered VC6B conformance ID range (HEAL-016..030), continuing VC6A's
|
|
57
|
+
* HEAL-001..015. The acceptance test reads these rows from the v2 manifest and
|
|
58
|
+
* asserts each returns its manifest `ok`/`code`.
|
|
59
|
+
*/
|
|
60
|
+
export const RESTORE_IDS = Array.from({ length: 15 }, (_v, i) => `HEAL-${String(i + 16).padStart(3, "0")}`);
|
|
61
|
+
/** Named VC6B conformance assertions (the sprint's headline rows). */
|
|
62
|
+
export const RESTORE_NAMED_IDS = [
|
|
63
|
+
"HEAL-SPAN-001",
|
|
64
|
+
"HEAL-LIMIT-002",
|
|
65
|
+
"HEAL-DIGEST-003",
|
|
66
|
+
];
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/heal/restore.ts — VC6B exact source restoration orchestrator.
|
|
3
|
+
*
|
|
4
|
+
* Turns a `RestoreRequestV1` into a `RestoreResultV1` by consulting, per span,
|
|
5
|
+
* the two EXACT sources in `restore-readers.ts` — an indexed exact shard first,
|
|
6
|
+
* then a ledger range scan — and inserting bytes only after they hash to the
|
|
7
|
+
* digest the request pinned.
|
|
8
|
+
*
|
|
9
|
+
* ORDER OF OPERATIONS IS THE CONTRACT.
|
|
10
|
+
*
|
|
11
|
+
* 1. BOUNDS, BEFORE ANY READER TOUCH. The span count and the aggregate
|
|
12
|
+
* requested byte span are computed PURELY FROM THE REQUEST (`byteEnd -
|
|
13
|
+
* byteStart`, which needs no source at all) and checked first. On breach we
|
|
14
|
+
* return immediately, having never read `reader.exactShards` or
|
|
15
|
+
* `reader.ledgerEvents`. This is HEAL-LIMIT-002: an oversized request must
|
|
16
|
+
* not be able to make the restorer walk the ledger even once, so the check
|
|
17
|
+
* cannot be "inside the loop, before the read" — it must be before the loop
|
|
18
|
+
* exists. The acceptance corpus proves it by passing EMPTY readers with an
|
|
19
|
+
* over-limit request: a reader-touching implementation would still return
|
|
20
|
+
* "missing" rather than "limit".
|
|
21
|
+
*
|
|
22
|
+
* 2. EXACT SHARD, then LEDGER, then MISSING. Sources are tried strongest-first.
|
|
23
|
+
* A digest mismatch anywhere is recorded and the span is NOT restored — the
|
|
24
|
+
* restorer never downgrades to "closest available bytes".
|
|
25
|
+
*
|
|
26
|
+
* 3. MODE from what actually happened, not from what was attempted. A = every
|
|
27
|
+
* span came from a shard; B = all restored, at least one via ledger scan;
|
|
28
|
+
* C = something is missing, and mode C STATES its semantic loss rather than
|
|
29
|
+
* hiding an incomplete restoration behind a successful-looking result.
|
|
30
|
+
*
|
|
31
|
+
* PURE. No storage, no console, no clock, no network — `node:crypto` (a Node
|
|
32
|
+
* built-in) is the only dependency beyond types (PREVENT-PI-004 / PREVENT-011).
|
|
33
|
+
* The reporter seam in `restore-emit.ts` is flag-gated; THIS arithmetic is not,
|
|
34
|
+
* so flag-off is byte-identical.
|
|
35
|
+
*/
|
|
36
|
+
import { RESTORE_LIMIT_BYTES, RESTORE_LIMIT_SPANS } from "./restore-types.js";
|
|
37
|
+
import { readExactShard, readLedgerSpan } from "./restore-readers.js";
|
|
38
|
+
/**
|
|
39
|
+
* Fixed code ordering so a result's `codes` array is deterministic regardless of
|
|
40
|
+
* which span failed first. Deterministic output is what lets the conformance
|
|
41
|
+
* corpus pin an exact expected value.
|
|
42
|
+
*/
|
|
43
|
+
const CODE_ORDER = [
|
|
44
|
+
"HEAL_RESTORE_LIMIT",
|
|
45
|
+
"HEAL_RESTORE_DIGEST_MISMATCH",
|
|
46
|
+
"HEAL_RESTORE_SOURCE_MISSING",
|
|
47
|
+
"HEAL_RESTORE_RANGE_MISMATCH",
|
|
48
|
+
];
|
|
49
|
+
/** Deduplicate + sort codes into the fixed priority order. */
|
|
50
|
+
export function orderCodes(codes) {
|
|
51
|
+
const seen = new Set(codes);
|
|
52
|
+
return CODE_ORDER.filter((c) => seen.has(c));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Total bytes the request ASKS for, derived from the ranges alone. Negative or
|
|
56
|
+
* inverted ranges contribute 0 rather than reducing the total — an inverted span
|
|
57
|
+
* must never be usable to smuggle a large request under the bound.
|
|
58
|
+
*/
|
|
59
|
+
function requestedBytes(spans) {
|
|
60
|
+
let total = 0;
|
|
61
|
+
for (const s of spans) {
|
|
62
|
+
const len = s.range.byteEnd - s.range.byteStart;
|
|
63
|
+
total += len > 0 ? len : 0;
|
|
64
|
+
}
|
|
65
|
+
return total;
|
|
66
|
+
}
|
|
67
|
+
/** The immediate over-limit result: nothing read, everything missing. */
|
|
68
|
+
function limitExceeded(request) {
|
|
69
|
+
return {
|
|
70
|
+
schema: "restore-result-v1",
|
|
71
|
+
sessionId: request.sessionId,
|
|
72
|
+
mode: "C",
|
|
73
|
+
restored: [],
|
|
74
|
+
missing: request.spans.map((s) => s.nodeId),
|
|
75
|
+
semanticLossStated: true,
|
|
76
|
+
codes: ["HEAL_RESTORE_LIMIT"],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Restore the exact original bytes for every requested span.
|
|
81
|
+
*
|
|
82
|
+
* Never throws: a request naming spans no source covers yields a mode-C result
|
|
83
|
+
* that discloses the loss, not an exception (PRACTICES: non-fatal — a failed
|
|
84
|
+
* restoration must degrade the prompt, never break the agent loop).
|
|
85
|
+
*/
|
|
86
|
+
export function restoreSources(request, reader) {
|
|
87
|
+
// (1) Bounds first — computed from the request only. `reader` is not touched
|
|
88
|
+
// on this path, which is exactly what HEAL-LIMIT-002 asserts.
|
|
89
|
+
if (request.spans.length > RESTORE_LIMIT_SPANS ||
|
|
90
|
+
requestedBytes(request.spans) > RESTORE_LIMIT_BYTES) {
|
|
91
|
+
return limitExceeded(request);
|
|
92
|
+
}
|
|
93
|
+
const restored = [];
|
|
94
|
+
const missing = [];
|
|
95
|
+
const codes = [];
|
|
96
|
+
let usedLedger = false;
|
|
97
|
+
// (2) Per span, strongest source first, in request order.
|
|
98
|
+
for (const span of request.spans) {
|
|
99
|
+
const exact = readExactShard(reader.exactShards, span.range, span.digest);
|
|
100
|
+
if (exact.kind === "bytes") {
|
|
101
|
+
restored.push({
|
|
102
|
+
nodeId: span.nodeId,
|
|
103
|
+
source: "exact-shard",
|
|
104
|
+
bytes: exact.bytes,
|
|
105
|
+
digest: span.digest,
|
|
106
|
+
});
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (exact.kind === "digest-mismatch")
|
|
110
|
+
codes.push("HEAL_RESTORE_DIGEST_MISMATCH");
|
|
111
|
+
const ledger = readLedgerSpan(reader.ledgerEvents, span.range, span.digest);
|
|
112
|
+
if (ledger.kind === "bytes") {
|
|
113
|
+
usedLedger = true;
|
|
114
|
+
restored.push({
|
|
115
|
+
nodeId: span.nodeId,
|
|
116
|
+
source: "ledger-scan",
|
|
117
|
+
bytes: ledger.bytes,
|
|
118
|
+
digest: span.digest,
|
|
119
|
+
});
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
if (ledger.kind === "digest-mismatch")
|
|
123
|
+
codes.push("HEAL_RESTORE_DIGEST_MISMATCH");
|
|
124
|
+
// (3) Neither exact source answered. Identity only — never bytes.
|
|
125
|
+
missing.push(span.nodeId);
|
|
126
|
+
codes.push("HEAL_RESTORE_SOURCE_MISSING");
|
|
127
|
+
}
|
|
128
|
+
const complete = missing.length === 0 && restored.length === request.spans.length;
|
|
129
|
+
const mode = !complete ? "C" : usedLedger ? "B" : "A";
|
|
130
|
+
return {
|
|
131
|
+
schema: "restore-result-v1",
|
|
132
|
+
sessionId: request.sessionId,
|
|
133
|
+
mode,
|
|
134
|
+
restored,
|
|
135
|
+
missing,
|
|
136
|
+
// Mode C omits spans, so it MUST disclose that the old context is gone.
|
|
137
|
+
semanticLossStated: mode === "C",
|
|
138
|
+
codes: orderCodes(codes),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/heal/types.ts — VC6A closure-optimization contract.
|
|
3
|
+
*
|
|
4
|
+
* Owns `ClosureProofV2` and `RestoreHintV1`.
|
|
5
|
+
*
|
|
6
|
+
* VC4C already performs the MANDATORY conservative closure (CONTRACTS §plan and
|
|
7
|
+
* closure): it recursively adds every `depends`/tool-pair predecessor to a fixed
|
|
8
|
+
* point, resolves contradictions, and preserves the anchor floor. VC6A does NOT
|
|
9
|
+
* re-close and does NOT change WHICH NODES ARE SELECTED — "VC6 only optimizes
|
|
10
|
+
* restoration/self-healing". It optimizes the PROOF EDGES of that already-closed
|
|
11
|
+
* graph by transitive reduction: an edge `a -> c` whose requirement is already
|
|
12
|
+
* carried by a path `a -> b -> c` is redundant and can be dropped from the
|
|
13
|
+
* traversal plan without changing the closed set.
|
|
14
|
+
*
|
|
15
|
+
* The optimization is therefore a claim, and a claim needs a receipt:
|
|
16
|
+
* `ClosureProofV2` records EVERY considered edge — retained or removed — with
|
|
17
|
+
* the reason. `proof.ts` replays those rows against the conservative VC4C oracle
|
|
18
|
+
* and rejects the optimization if the selected set diverges
|
|
19
|
+
* (`HEAL_PROOF_SET_MISMATCH`) or if a considered edge has no proof row
|
|
20
|
+
* (`HEAL_PROOF_INCOMPLETE`).
|
|
21
|
+
*
|
|
22
|
+
* PROTECTED EDGES ARE NEVER REMOVED. A tool-pair edge (PREVENT-PI-002), an edge
|
|
23
|
+
* touching an anchor node (PREVENT-PI-001's anchor floor), a
|
|
24
|
+
* contradiction-resolution edge, and a SOLE dependency edge (the only edge that
|
|
25
|
+
* pulls its prerequisite in) are all retained unconditionally, even when an
|
|
26
|
+
* alternate path exists. Only a redundant `depends` edge may go.
|
|
27
|
+
*
|
|
28
|
+
* Pure types + registered conformance IDs: no storage, no console, no network
|
|
29
|
+
* (PREVENT-PI-004 / PREVENT-011).
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Registered HEAL conformance ID range (HEAL-001..015). The acceptance test
|
|
33
|
+
* reads these rows from the v2 manifest and asserts each returns its manifest
|
|
34
|
+
* `ok`/`code`.
|
|
35
|
+
*/
|
|
36
|
+
export const HEAL_IDS = Array.from({ length: 15 }, (_v, i) => `HEAL-${String(i + 1).padStart(3, "0")}`);
|
|
37
|
+
/** Named VC6A conformance assertions (the sprint's headline rows). */
|
|
38
|
+
export const HEAL_NAMED_IDS = [
|
|
39
|
+
"HEAL-REDUCE-001",
|
|
40
|
+
"HEAL-PROTECT-002",
|
|
41
|
+
"HEAL-PROOF-003",
|
|
42
|
+
];
|
|
43
|
+
export { RESTORE_IDS, RESTORE_NAMED_IDS, RESTORE_LIMIT_SPANS, RESTORE_LIMIT_BYTES, } from "./restore-types.js";
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vector-cortex/heal/verify.ts — VC6B pre-insertion verification (task 3).
|
|
3
|
+
*
|
|
4
|
+
* `restoreSources` already hashes every span before it puts it in the result, so
|
|
5
|
+
* why hash again here?
|
|
6
|
+
*
|
|
7
|
+
* Because the result is a VALUE that travels. Between restoration and insertion
|
|
8
|
+
* it is passed across module boundaries, possibly cached, possibly assembled from
|
|
9
|
+
* more than one restore call, possibly reordered. `verifyRestored` is the gate
|
|
10
|
+
* immediately before bytes enter the reconstruction, and it re-derives its facts
|
|
11
|
+
* from scratch: it hashes the bytes the result ACTUALLY CARRIES and cross-checks
|
|
12
|
+
* them against the digest THE REQUEST asked for. A result object mutated after
|
|
13
|
+
* `restoreSources` returned — the classic "verified then swapped" injection —
|
|
14
|
+
* fails here.
|
|
15
|
+
*
|
|
16
|
+
* TWO DISTINCT INVARIANTS, TWO DISTINCT CODES.
|
|
17
|
+
* - `HEAL_RESTORE_DIGEST_MISMATCH` — the bytes do not hash to their OWN stated
|
|
18
|
+
* digest. The span is internally inconsistent (tampering or truncation).
|
|
19
|
+
* - `HEAL_RESTORE_RANGE_MISMATCH` — the bytes are internally consistent but do
|
|
20
|
+
* not answer the question that was asked: the nodeId was never requested, or
|
|
21
|
+
* the digest disagrees with the digest the request pinned for that nodeId.
|
|
22
|
+
* This is the "right bytes, wrong span" failure — substituting one real,
|
|
23
|
+
* correctly-hashed span for another would otherwise pass a naive check.
|
|
24
|
+
*
|
|
25
|
+
* WHOLESALE, NOT PER-SPAN. `insertable` returns the restored spans only when the
|
|
26
|
+
* entire result verifies. Inserting the good half of a result whose other half
|
|
27
|
+
* failed verification would splice a partially-corrupt transcript into the
|
|
28
|
+
* reconstruction without the caller ever seeing a mode-C disclosure.
|
|
29
|
+
*
|
|
30
|
+
* Pure: `node:crypto` only, no storage/console/network (PREVENT-PI-004 /
|
|
31
|
+
* PREVENT-011).
|
|
32
|
+
*/
|
|
33
|
+
import { sha256Hex } from "./restore-readers.js";
|
|
34
|
+
import { orderCodes } from "./restore.js";
|
|
35
|
+
/**
|
|
36
|
+
* Re-verify every restored span against the request that asked for it.
|
|
37
|
+
*
|
|
38
|
+
* Returns `{ok:true}` only when EVERY restored span hashes to its own digest AND
|
|
39
|
+
* that digest is the one the request pinned for that node.
|
|
40
|
+
*/
|
|
41
|
+
export function verifyRestored(result, request) {
|
|
42
|
+
const requestedDigests = new Map();
|
|
43
|
+
for (const span of request.spans)
|
|
44
|
+
requestedDigests.set(span.nodeId, span.digest);
|
|
45
|
+
const codes = [];
|
|
46
|
+
for (const span of result.restored) {
|
|
47
|
+
// (1) Internal consistency: do these bytes hash to the digest they claim?
|
|
48
|
+
if (sha256Hex(span.bytes) !== span.digest) {
|
|
49
|
+
codes.push("HEAL_RESTORE_DIGEST_MISMATCH");
|
|
50
|
+
// A span that fails its own digest cannot meaningfully be checked against
|
|
51
|
+
// the request's digest as well; one code per real defect keeps the verdict
|
|
52
|
+
// readable.
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
// (2) Provenance: was this node requested, and with THIS digest? An
|
|
56
|
+
// unrequested node or a digest swap is a range mismatch, not a hash failure.
|
|
57
|
+
const wanted = requestedDigests.get(span.nodeId);
|
|
58
|
+
if (wanted === undefined || wanted !== span.digest) {
|
|
59
|
+
codes.push("HEAL_RESTORE_RANGE_MISMATCH");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (codes.length === 0)
|
|
63
|
+
return { ok: true };
|
|
64
|
+
return { ok: false, codes: orderCodes(codes) };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The spans that may be inserted: all of them, or none.
|
|
68
|
+
*
|
|
69
|
+
* A caller should never need to decide which half of a partially-verified result
|
|
70
|
+
* is safe — that decision is the whole point of the digest contract, so it is
|
|
71
|
+
* made here, once, in the strict direction.
|
|
72
|
+
*/
|
|
73
|
+
export function insertable(result, request) {
|
|
74
|
+
return verifyRestored(result, request).ok ? result.restored : [];
|
|
75
|
+
}
|
|
@@ -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
|
+
}
|