@mneme-ai/core 2.95.0 → 2.96.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.
- package/dist/agent_manifest.d.ts.map +1 -1
- package/dist/agent_manifest.js +1 -0
- package/dist/agent_manifest.js.map +1 -1
- package/dist/hydra/analytic.d.ts +103 -0
- package/dist/hydra/analytic.d.ts.map +1 -0
- package/dist/hydra/analytic.js +161 -0
- package/dist/hydra/analytic.js.map +1 -0
- package/dist/hydra/attest.d.ts +60 -0
- package/dist/hydra/attest.d.ts.map +1 -0
- package/dist/hydra/attest.js +84 -0
- package/dist/hydra/attest.js.map +1 -0
- package/dist/hydra/engine.d.ts +84 -0
- package/dist/hydra/engine.d.ts.map +1 -0
- package/dist/hydra/engine.js +108 -0
- package/dist/hydra/engine.js.map +1 -0
- package/dist/hydra/hydra.test.d.ts +2 -0
- package/dist/hydra/hydra.test.d.ts.map +1 -0
- package/dist/hydra/hydra.test.js +90 -0
- package/dist/hydra/hydra.test.js.map +1 -0
- package/dist/hydra/index.d.ts +76 -0
- package/dist/hydra/index.d.ts.map +1 -0
- package/dist/hydra/index.js +61 -0
- package/dist/hydra/index.js.map +1 -0
- package/dist/hydra/mine.d.ts +42 -0
- package/dist/hydra/mine.d.ts.map +1 -0
- package/dist/hydra/mine.js +72 -0
- package/dist/hydra/mine.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/truth_gate/probes.d.ts.map +1 -1
- package/dist/truth_gate/probes.js +25 -0
- package/dist/truth_gate/probes.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2.96.0 — HYDRA · the SUPER-BOT ANALYTIC ENGINE.
|
|
3
|
+
*
|
|
4
|
+
* A live, self-checking forge loop. It mines (L1), MDL-selects (L2), and
|
|
5
|
+
* GROWS the codebook one batch at a time — but every growth step is gated
|
|
6
|
+
* by the gauntlet (L4 lossless ∧ L7 zero-collision). It keeps improving
|
|
7
|
+
* (L9) until it can no longer add a byte of value, then STOPS. It never
|
|
8
|
+
* ships a codebook that loses a byte or holds two meanings for one symbol.
|
|
9
|
+
*
|
|
10
|
+
* "Continue improvement until it doesn't lie, 100%": the loop's exit
|
|
11
|
+
* condition is CONVERGENCE (no positive-MDL candidate survives the
|
|
12
|
+
* gauntlet) — not a guess. Each round strictly increases bytes-saved or
|
|
13
|
+
* the loop ends. Bounded by construction: the candidate pool is finite and
|
|
14
|
+
* each accepted phrase is removed from contention.
|
|
15
|
+
*
|
|
16
|
+
* Pure + deterministic. No crypto, no I/O, no Date — attestation (L5 sign,
|
|
17
|
+
* L8 energy cert) lives in attest.ts so this stays trivially testable.
|
|
18
|
+
*/
|
|
19
|
+
import { chooseMarkers, symbolFor, proveLossless, sha256Hex, compress, expand } from "./engine.js";
|
|
20
|
+
import { mineCandidates } from "./mine.js";
|
|
21
|
+
/** Order entries longest-phrase-first + (re)assign deterministic symbols. */
|
|
22
|
+
export function buildCodebook(open, close, phrases, corpus) {
|
|
23
|
+
const sorted = [...phrases].sort((a, b) => b.phrase.length - a.phrase.length || (a.phrase < b.phrase ? -1 : 1));
|
|
24
|
+
const entries = sorted.map((p, i) => ({ sym: symbolFor(open, close, i), phrase: p.phrase, hits: p.hits, gain: p.gain }));
|
|
25
|
+
return { v: 1, open, close, entries, corpusHash: sha256Hex(corpus) };
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* L7 — collision detection (the "can't hold two meanings" invariant, the
|
|
29
|
+
* same discipline as the axiom lattice). A codebook is collision-free iff:
|
|
30
|
+
* - every symbol is unique,
|
|
31
|
+
* - every phrase is unique,
|
|
32
|
+
* - no phrase contains a marker (would make expansion ambiguous).
|
|
33
|
+
*/
|
|
34
|
+
export function collisions(cb) {
|
|
35
|
+
const reasons = [];
|
|
36
|
+
const syms = new Set();
|
|
37
|
+
const phrases = new Set();
|
|
38
|
+
for (const e of cb.entries) {
|
|
39
|
+
if (syms.has(e.sym))
|
|
40
|
+
reasons.push(`duplicate symbol ${JSON.stringify(e.sym)}`);
|
|
41
|
+
if (phrases.has(e.phrase))
|
|
42
|
+
reasons.push(`duplicate phrase ${JSON.stringify(e.phrase.slice(0, 24))}`);
|
|
43
|
+
if (e.phrase.includes(cb.open) || e.phrase.includes(cb.close))
|
|
44
|
+
reasons.push(`phrase carries a marker`);
|
|
45
|
+
syms.add(e.sym);
|
|
46
|
+
phrases.add(e.phrase);
|
|
47
|
+
}
|
|
48
|
+
return { collisions: reasons.length, reasons: reasons.slice(0, 8) };
|
|
49
|
+
}
|
|
50
|
+
function codebookByteSize(cb) {
|
|
51
|
+
let n = 0;
|
|
52
|
+
for (const e of cb.entries)
|
|
53
|
+
n += Buffer.byteLength(e.phrase, "utf8") + Buffer.byteLength(e.sym, "utf8") + 4;
|
|
54
|
+
return n;
|
|
55
|
+
}
|
|
56
|
+
/** Run the full gauntlet (L4 ∧ L6 ∧ L7 + honest ratios) over a codebook. */
|
|
57
|
+
export function gauntlet(corpus, cb) {
|
|
58
|
+
const proof = proveLossless(corpus, cb);
|
|
59
|
+
const coll = collisions(cb);
|
|
60
|
+
// L6 portability: determinism — recompute the round-trip hash; it must
|
|
61
|
+
// equal the original (single recompute; proveLossless already did one).
|
|
62
|
+
const portable = sha256Hex(expand(compress(corpus, cb), cb)) === proof.originalHash;
|
|
63
|
+
const perfect = proof.lossless && coll.collisions === 0 && portable;
|
|
64
|
+
const codebookBytes = codebookByteSize(cb);
|
|
65
|
+
return {
|
|
66
|
+
lossless: proof.lossless,
|
|
67
|
+
collisions: coll.collisions,
|
|
68
|
+
portable,
|
|
69
|
+
bytesOriginal: proof.originalBytes,
|
|
70
|
+
bytesCompressed: proof.compressedBytes,
|
|
71
|
+
codebookBytes,
|
|
72
|
+
ratio: proof.ratio,
|
|
73
|
+
netRatio: (proof.compressedBytes + codebookBytes) === 0 ? 1 : proof.originalBytes / (proof.compressedBytes + codebookBytes),
|
|
74
|
+
entries: cb.entries.length,
|
|
75
|
+
score: perfect ? 100 : 0,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* L9 — forge the codebook by infinite-until-convergence self-improvement.
|
|
80
|
+
* Each round: mine candidates not already covered, promote the top batch,
|
|
81
|
+
* RE-PROVE the gauntlet; if a batch ever broke losslessness or introduced
|
|
82
|
+
* a collision (it shouldn't, by construction), it is rolled back and
|
|
83
|
+
* retried one-at-a-time. Stop when no positive-gain candidate survives.
|
|
84
|
+
*/
|
|
85
|
+
export function forgeCodebook(corpus, opts = {}) {
|
|
86
|
+
const maxRounds = opts.maxRounds ?? 500;
|
|
87
|
+
const batchPerRound = opts.batchPerRound ?? 16;
|
|
88
|
+
const maxEntries = opts.maxEntries ?? 512;
|
|
89
|
+
const auditEvery = opts.auditEvery ?? 16;
|
|
90
|
+
const dedupSubstrings = opts.dedupSubstrings ?? true;
|
|
91
|
+
const [open, close] = chooseMarkers(corpus, []);
|
|
92
|
+
// Mine the full candidate pool ONCE — the corpus is fixed, so the pool
|
|
93
|
+
// doesn't change. Pre-sorted by MDL gain (L2). Per-candidate admission is
|
|
94
|
+
// O(1)+dedup; the full lossless proof is the load-bearing L4 gate, run as
|
|
95
|
+
// a LIVE periodic audit and authoritatively at the end.
|
|
96
|
+
const pool = mineCandidates(corpus, { minHits: opts.minHits, windowSizes: opts.windowSizes });
|
|
97
|
+
const chosen = [];
|
|
98
|
+
const chosenPhrases = new Set();
|
|
99
|
+
const rounds = [];
|
|
100
|
+
// collision-free ⟹ lossless (distinct phrases + PUA markers absent from
|
|
101
|
+
// corpus ⇒ symbols are isolated, expansion is exact). Per-candidate we
|
|
102
|
+
// check the O(1) collision precondition + substring-dedup; the full proof
|
|
103
|
+
// audits it. Substring-dedup keeps the codebook LEAN (one high-gain phrase
|
|
104
|
+
// beats a dozen overlapping sub-phrases).
|
|
105
|
+
const admissible = (phrase) => {
|
|
106
|
+
if (chosenPhrases.has(phrase) || phrase.includes(open) || phrase.includes(close))
|
|
107
|
+
return false;
|
|
108
|
+
if (dedupSubstrings) {
|
|
109
|
+
for (const c of chosen)
|
|
110
|
+
if (c.phrase.includes(phrase))
|
|
111
|
+
return false; // redundant with a higher-gain pick
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
};
|
|
115
|
+
let cb = buildCodebook(open, close, chosen, corpus);
|
|
116
|
+
let cursor = 0;
|
|
117
|
+
for (let round = 0; round < maxRounds && cursor < pool.length; round++) {
|
|
118
|
+
const before = chosen.length;
|
|
119
|
+
let taken = 0;
|
|
120
|
+
while (cursor < pool.length && taken < batchPerRound && chosen.length < maxEntries) {
|
|
121
|
+
const c = pool[cursor++];
|
|
122
|
+
if (!c)
|
|
123
|
+
break;
|
|
124
|
+
if (!admissible(c.phrase))
|
|
125
|
+
continue;
|
|
126
|
+
chosen.push(c);
|
|
127
|
+
chosenPhrases.add(c.phrase);
|
|
128
|
+
taken++;
|
|
129
|
+
}
|
|
130
|
+
if (chosen.length === before) {
|
|
131
|
+
if (cursor >= pool.length || chosen.length >= maxEntries)
|
|
132
|
+
break; // converged
|
|
133
|
+
continue; // batch all redundant, keep scanning
|
|
134
|
+
}
|
|
135
|
+
const lastRound = cursor >= pool.length || chosen.length >= maxEntries;
|
|
136
|
+
const doAudit = lastRound || round % auditEvery === 0;
|
|
137
|
+
if (doAudit) {
|
|
138
|
+
cb = buildCodebook(open, close, chosen, corpus);
|
|
139
|
+
const g = gauntlet(corpus, cb); // LIVE full audit (L4∧L6∧L7)
|
|
140
|
+
if (g.score !== 100) { // must not happen by construction
|
|
141
|
+
const rolledBack = chosen.splice(before);
|
|
142
|
+
for (const p of rolledBack)
|
|
143
|
+
chosenPhrases.delete(p.phrase);
|
|
144
|
+
cb = buildCodebook(open, close, chosen, corpus);
|
|
145
|
+
const rg = gauntlet(corpus, cb);
|
|
146
|
+
rounds.push({ round, added: 0, entries: chosen.length, bytesSaved: rg.bytesOriginal - rg.bytesCompressed, gauntletScore: rg.score, lossless: rg.lossless, collisions: g.collisions });
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
rounds.push({ round, added: chosen.length - before, entries: chosen.length, bytesSaved: g.bytesOriginal - g.bytesCompressed, gauntletScore: g.score, lossless: g.lossless, collisions: g.collisions });
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
rounds.push({ round, added: chosen.length - before, entries: chosen.length, bytesSaved: -1, gauntletScore: -1, lossless: true, collisions: 0 });
|
|
153
|
+
}
|
|
154
|
+
if (lastRound)
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
cb = buildCodebook(open, close, chosen, corpus);
|
|
158
|
+
const finalG = gauntlet(corpus, cb);
|
|
159
|
+
return { codebook: cb, gauntlet: finalG, rounds, converged: finalG.score === 100 };
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=analytic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytic.js","sourceRoot":"","sources":["../../src/hydra/analytic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAqC,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACtI,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,6EAA6E;AAC7E,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,KAAa,EAAE,OAA8D,EAAE,MAAc;IACvI,MAAM,MAAM,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAA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CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;gBACtL,MAAM;YACR,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,eAAe,EAAE,aAAa,EAAE,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC;QACzM,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC,CAAC;QAClJ,CAAC;QACD,IAAI,SAAS;YAAE,MAAM;IACvB,CAAC;IAED,EAAE,GAAG,aAAa,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACpC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,CAAC,KAAK,KAAK,GAAG,EAAE,CAAC;AACrF,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2.96.0 — HYDRA · L5 signed codebook + L8 energy certificate.
|
|
3
|
+
*
|
|
4
|
+
* This is the gem's CUT — the facets prior-art research found UNFILLED:
|
|
5
|
+
* no prompt-compression system signs its codebook or attests the round
|
|
6
|
+
* trip. HYDRA reuses Mneme's existing NOTARY (Ed25519) spine so a third
|
|
7
|
+
* party can verify OFFLINE, with the public key alone, that:
|
|
8
|
+
* - this exact codebook was forged by this issuer (L5), and
|
|
9
|
+
* - it expands a corpus of this exact hash with a perfect gauntlet, and
|
|
10
|
+
* - the one-time mining energy buys perpetual ~0-energy recollection (L8,
|
|
11
|
+
* the ANAMNESIS thesis: compute once, recollect forever).
|
|
12
|
+
*
|
|
13
|
+
* No new crypto — diamonds compound on the NOTARY spine.
|
|
14
|
+
*/
|
|
15
|
+
import { type NotaryReceipt } from "../notary/receipt.js";
|
|
16
|
+
import type { Codebook } from "./engine.js";
|
|
17
|
+
import type { Gauntlet } from "./analytic.js";
|
|
18
|
+
/** Canonical, deterministic serialization of a codebook (for hashing/sig). */
|
|
19
|
+
export declare function canonicalizeCodebook(cb: Codebook): string;
|
|
20
|
+
export interface HydraCodebookProof {
|
|
21
|
+
codebookHash: string;
|
|
22
|
+
corpusHash: string;
|
|
23
|
+
entries: number;
|
|
24
|
+
gauntletScore: number;
|
|
25
|
+
ratio: number;
|
|
26
|
+
bytesOriginal: number;
|
|
27
|
+
bytesCompressed: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* L5 — sign the codebook + its gauntlet verdict into a portable NOTARY
|
|
31
|
+
* receipt. `at` is the issue timestamp (passed in for determinism/testing;
|
|
32
|
+
* the CLI supplies Date.now()).
|
|
33
|
+
*/
|
|
34
|
+
export declare function signCodebook(repoRoot: string, cb: Codebook, g: Gauntlet, at: number): NotaryReceipt;
|
|
35
|
+
export interface CodebookVerify {
|
|
36
|
+
valid: boolean;
|
|
37
|
+
reason: string;
|
|
38
|
+
/** True only when the signature is valid AND the receipt's codebookHash
|
|
39
|
+
* matches the codebook actually presented (no swap-after-sign). */
|
|
40
|
+
bound: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Verify a signed codebook OFFLINE: the Ed25519 signature must check out
|
|
44
|
+
* AND the receipt's embedded codebookHash must equal the hash of the
|
|
45
|
+
* codebook presented. Catches both forged receipts and codebook tampering.
|
|
46
|
+
*/
|
|
47
|
+
export declare function verifyCodebook(receipt: unknown, cb: Codebook): CodebookVerify;
|
|
48
|
+
export interface EnergyCert {
|
|
49
|
+
receipt: NotaryReceipt;
|
|
50
|
+
bytesSaved: number;
|
|
51
|
+
ratio: number;
|
|
52
|
+
/** Bytes saved per future expansion, paid for by a single mine. */
|
|
53
|
+
perpetualSavingPerUse: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* L8 — energy certificate: the one-time mine cost buys perpetual savings.
|
|
57
|
+
* Signed via NOTARY so the savings claim is itself verifiable, not boast.
|
|
58
|
+
*/
|
|
59
|
+
export declare function mintEnergyCert(repoRoot: string, cb: Codebook, g: Gauntlet, at: number): EnergyCert;
|
|
60
|
+
//# sourceMappingURL=attest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attest.d.ts","sourceRoot":"","sources":["../../src/hydra/attest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAA+B,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACvF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,8EAA8E;AAC9E,wBAAgB,oBAAoB,CAAC,EAAE,EAAE,QAAQ,GAAG,MAAM,CAKzD;AAED,MAAM,WAAW,kBAAkB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,EAAE,MAAM,CAAC;IACtB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,GAAG,aAAa,CAiBnG;AAED,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf;wEACoE;IACpE,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,GAAG,cAAc,CAe7E;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,aAAa,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,GAAG,UAAU,CAUlG"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2.96.0 — HYDRA · L5 signed codebook + L8 energy certificate.
|
|
3
|
+
*
|
|
4
|
+
* This is the gem's CUT — the facets prior-art research found UNFILLED:
|
|
5
|
+
* no prompt-compression system signs its codebook or attests the round
|
|
6
|
+
* trip. HYDRA reuses Mneme's existing NOTARY (Ed25519) spine so a third
|
|
7
|
+
* party can verify OFFLINE, with the public key alone, that:
|
|
8
|
+
* - this exact codebook was forged by this issuer (L5), and
|
|
9
|
+
* - it expands a corpus of this exact hash with a perfect gauntlet, and
|
|
10
|
+
* - the one-time mining energy buys perpetual ~0-energy recollection (L8,
|
|
11
|
+
* the ANAMNESIS thesis: compute once, recollect forever).
|
|
12
|
+
*
|
|
13
|
+
* No new crypto — diamonds compound on the NOTARY spine.
|
|
14
|
+
*/
|
|
15
|
+
import { issueReceipt, verifyReceipt } from "../notary/receipt.js";
|
|
16
|
+
import { sha256Hex } from "./engine.js";
|
|
17
|
+
/** Canonical, deterministic serialization of a codebook (for hashing/sig). */
|
|
18
|
+
export function canonicalizeCodebook(cb) {
|
|
19
|
+
// Entry order is already deterministic (longest-first); we serialize only
|
|
20
|
+
// the load-bearing fields so the hash is stable across runs.
|
|
21
|
+
const entries = cb.entries.map((e) => [e.sym, e.phrase]);
|
|
22
|
+
return JSON.stringify({ v: cb.v, open: cb.open, close: cb.close, corpusHash: cb.corpusHash, entries });
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* L5 — sign the codebook + its gauntlet verdict into a portable NOTARY
|
|
26
|
+
* receipt. `at` is the issue timestamp (passed in for determinism/testing;
|
|
27
|
+
* the CLI supplies Date.now()).
|
|
28
|
+
*/
|
|
29
|
+
export function signCodebook(repoRoot, cb, g, at) {
|
|
30
|
+
const proof = {
|
|
31
|
+
codebookHash: sha256Hex(canonicalizeCodebook(cb)),
|
|
32
|
+
corpusHash: cb.corpusHash,
|
|
33
|
+
entries: g.entries,
|
|
34
|
+
gauntletScore: g.score,
|
|
35
|
+
ratio: Number(g.ratio.toFixed(4)),
|
|
36
|
+
bytesOriginal: g.bytesOriginal,
|
|
37
|
+
bytesCompressed: g.bytesCompressed,
|
|
38
|
+
};
|
|
39
|
+
return issueReceipt(repoRoot, {
|
|
40
|
+
kind: "memory-capsule",
|
|
41
|
+
subject: `hydra-codebook:${cb.corpusHash.slice(0, 16)}`,
|
|
42
|
+
payload: proof,
|
|
43
|
+
includePayload: true,
|
|
44
|
+
issuedAt: at,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Verify a signed codebook OFFLINE: the Ed25519 signature must check out
|
|
49
|
+
* AND the receipt's embedded codebookHash must equal the hash of the
|
|
50
|
+
* codebook presented. Catches both forged receipts and codebook tampering.
|
|
51
|
+
*/
|
|
52
|
+
export function verifyCodebook(receipt, cb) {
|
|
53
|
+
const v = verifyReceipt(receipt);
|
|
54
|
+
if (!v.valid)
|
|
55
|
+
return { valid: false, reason: v.reason ?? "invalid signature", bound: false };
|
|
56
|
+
const payload = receipt.payload;
|
|
57
|
+
if (!payload || typeof payload.codebookHash !== "string") {
|
|
58
|
+
return { valid: true, reason: "signature valid but no codebookHash payload to bind", bound: false };
|
|
59
|
+
}
|
|
60
|
+
const actual = sha256Hex(canonicalizeCodebook(cb));
|
|
61
|
+
if (payload.codebookHash !== actual) {
|
|
62
|
+
return { valid: true, reason: "signature valid but codebook does NOT match receipt (tampered/swapped)", bound: false };
|
|
63
|
+
}
|
|
64
|
+
if (payload.corpusHash !== cb.corpusHash) {
|
|
65
|
+
return { valid: true, reason: "signature valid but corpusHash mismatch", bound: false };
|
|
66
|
+
}
|
|
67
|
+
return { valid: true, reason: "signature valid and codebook bound to receipt", bound: true };
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* L8 — energy certificate: the one-time mine cost buys perpetual savings.
|
|
71
|
+
* Signed via NOTARY so the savings claim is itself verifiable, not boast.
|
|
72
|
+
*/
|
|
73
|
+
export function mintEnergyCert(repoRoot, cb, g, at) {
|
|
74
|
+
const bytesSaved = g.bytesOriginal - g.bytesCompressed;
|
|
75
|
+
const receipt = issueReceipt(repoRoot, {
|
|
76
|
+
kind: "memory-capsule",
|
|
77
|
+
subject: `hydra-energy:${cb.corpusHash.slice(0, 16)}`,
|
|
78
|
+
payload: { corpusHash: cb.corpusHash, bytesSaved, ratio: Number(g.ratio.toFixed(4)), computedOnce: true },
|
|
79
|
+
includePayload: true,
|
|
80
|
+
issuedAt: at,
|
|
81
|
+
});
|
|
82
|
+
return { receipt, bytesSaved, ratio: g.ratio, perpetualSavingPerUse: bytesSaved };
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=attest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attest.js","sourceRoot":"","sources":["../../src/hydra/attest.ts"],"names":[],"mappings":"AAAA;;;;;;;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CAAC,aAAa,GAAG,CAAC,CAAC,eAAe,CAAC;IACvD,MAAM,OAAO,GAAG,YAAY,CAAC,QAAQ,EAAE;QACrC,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,gBAAgB,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE;QACrD,OAAO,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,IAAI,EAAE;QACzG,cAAc,EAAE,IAAI;QACpB,QAAQ,EAAE,EAAE;KACb,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2.96.0 — HYDRA · L3 deterministic expansion engine + L4 lossless proof.
|
|
3
|
+
*
|
|
4
|
+
* HYDRA is NOT a "compressor" (the world has those — LLMLingua/LoPace/AWS
|
|
5
|
+
* Meta-Tokens). HYDRA is a SIGNED, DETERMINISTIC, PROVABLY-LOSSLESS,
|
|
6
|
+
* VENDOR-NEUTRAL context codebook that Mneme mines from its OWN corpus.
|
|
7
|
+
* The defensible gem is the CUT, not the carbon: L5 signed codebook (NOTARY)
|
|
8
|
+
* × L6 vendor-neutral-by-construction × L7 axiom-lattice binding — a
|
|
9
|
+
* combination prior-art research found UNFILLED.
|
|
10
|
+
*
|
|
11
|
+
* This file is the bedrock every other layer stands on: a substitution
|
|
12
|
+
* codec whose round-trip is BYTE-IDENTICAL by construction, and a proof
|
|
13
|
+
* (SHA-256 round-trip) that is a boolean — never "downstream accuracy
|
|
14
|
+
* stayed similar", always lossless=1.000 or fail. No lies.
|
|
15
|
+
*
|
|
16
|
+
* KEY DESIGN (different thinking):
|
|
17
|
+
* - Symbols live in the Unicode Private-Use Area (U+E000…), which never
|
|
18
|
+
* occurs in real manifests/code/docs. The marker pair is VERIFIED
|
|
19
|
+
* absent from the corpus AND every phrase, with deterministic fallback
|
|
20
|
+
* to the next candidate pair → collision is impossible, not unlikely.
|
|
21
|
+
* - Expansion is a single deterministic pass: phrases (raw corpus
|
|
22
|
+
* substrings) cannot contain markers, so no cascade, no ambiguity.
|
|
23
|
+
* - Pure functions. Same input → same bytes on every OS/arch (that IS
|
|
24
|
+
* the L6 vendor-neutral proof: the LLM never sees the codebook).
|
|
25
|
+
*/
|
|
26
|
+
export interface CodebookEntry {
|
|
27
|
+
/** The private-use-area symbol that stands in for `phrase`. */
|
|
28
|
+
sym: string;
|
|
29
|
+
/** The raw corpus substring this symbol expands to. */
|
|
30
|
+
phrase: string;
|
|
31
|
+
/** Occurrences in the corpus at mining time (telemetry only). */
|
|
32
|
+
hits: number;
|
|
33
|
+
/** MDL gain in bytes this entry contributed (telemetry only). */
|
|
34
|
+
gain: number;
|
|
35
|
+
}
|
|
36
|
+
export interface Codebook {
|
|
37
|
+
v: 1;
|
|
38
|
+
/** Open marker (PUA char), verified absent from corpus + all phrases. */
|
|
39
|
+
open: string;
|
|
40
|
+
/** Close marker (PUA char), verified absent from corpus + all phrases. */
|
|
41
|
+
close: string;
|
|
42
|
+
/** Entries ordered LONGEST-phrase-first so greedy encode never splits a
|
|
43
|
+
* longer phrase by replacing a shorter sub-phrase first. */
|
|
44
|
+
entries: CodebookEntry[];
|
|
45
|
+
/** SHA-256 of the exact corpus this codebook was mined from. */
|
|
46
|
+
corpusHash: string;
|
|
47
|
+
}
|
|
48
|
+
export declare function sha256Hex(s: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Pick a marker pair guaranteed absent from `corpus` and every `phrase`.
|
|
51
|
+
* Deterministic: always returns the first clean candidate. Throws only if
|
|
52
|
+
* the (astronomically unlikely) corpus contains every PUA candidate.
|
|
53
|
+
*/
|
|
54
|
+
export declare function chooseMarkers(corpus: string, phrases: string[]): readonly [string, string];
|
|
55
|
+
/** The deterministic symbol for entry index `i`. */
|
|
56
|
+
export declare function symbolFor(open: string, close: string, i: number): string;
|
|
57
|
+
/**
|
|
58
|
+
* L3 — COMPRESS. Replace each codebook phrase with its symbol, longest
|
|
59
|
+
* phrase first (the entries are pre-sorted). Pure + deterministic.
|
|
60
|
+
*/
|
|
61
|
+
export declare function compress(text: string, cb: Codebook): string;
|
|
62
|
+
/**
|
|
63
|
+
* L3 — EXPAND (the Hydra head). Single deterministic pass: replace every
|
|
64
|
+
* symbol with its phrase. Because phrases are raw corpus substrings they
|
|
65
|
+
* cannot contain markers, so there is no cascade and the result is exact.
|
|
66
|
+
*/
|
|
67
|
+
export declare function expand(encoded: string, cb: Codebook): string;
|
|
68
|
+
export interface LosslessProof {
|
|
69
|
+
/** True iff expand(compress(text)) is byte-identical to text. */
|
|
70
|
+
lossless: boolean;
|
|
71
|
+
originalHash: string;
|
|
72
|
+
roundTripHash: string;
|
|
73
|
+
originalBytes: number;
|
|
74
|
+
compressedBytes: number;
|
|
75
|
+
/** original / compressed (1.0 = no gain). */
|
|
76
|
+
ratio: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* L4 — LOSSLESS PROOF. The boolean that cannot lie: a SHA-256 round-trip,
|
|
80
|
+
* not a similarity score. If `lossless` is ever false the codebook is
|
|
81
|
+
* REJECTED upstream — HYDRA never ships a codebook that loses a byte.
|
|
82
|
+
*/
|
|
83
|
+
export declare function proveLossless(text: string, cb: Codebook): LosslessProof;
|
|
84
|
+
//# sourceMappingURL=engine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/hydra/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,GAAG,EAA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,EAAE,QAAQ,GAAG,aAAa,CAevE"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v2.96.0 — HYDRA · L3 deterministic expansion engine + L4 lossless proof.
|
|
3
|
+
*
|
|
4
|
+
* HYDRA is NOT a "compressor" (the world has those — LLMLingua/LoPace/AWS
|
|
5
|
+
* Meta-Tokens). HYDRA is a SIGNED, DETERMINISTIC, PROVABLY-LOSSLESS,
|
|
6
|
+
* VENDOR-NEUTRAL context codebook that Mneme mines from its OWN corpus.
|
|
7
|
+
* The defensible gem is the CUT, not the carbon: L5 signed codebook (NOTARY)
|
|
8
|
+
* × L6 vendor-neutral-by-construction × L7 axiom-lattice binding — a
|
|
9
|
+
* combination prior-art research found UNFILLED.
|
|
10
|
+
*
|
|
11
|
+
* This file is the bedrock every other layer stands on: a substitution
|
|
12
|
+
* codec whose round-trip is BYTE-IDENTICAL by construction, and a proof
|
|
13
|
+
* (SHA-256 round-trip) that is a boolean — never "downstream accuracy
|
|
14
|
+
* stayed similar", always lossless=1.000 or fail. No lies.
|
|
15
|
+
*
|
|
16
|
+
* KEY DESIGN (different thinking):
|
|
17
|
+
* - Symbols live in the Unicode Private-Use Area (U+E000…), which never
|
|
18
|
+
* occurs in real manifests/code/docs. The marker pair is VERIFIED
|
|
19
|
+
* absent from the corpus AND every phrase, with deterministic fallback
|
|
20
|
+
* to the next candidate pair → collision is impossible, not unlikely.
|
|
21
|
+
* - Expansion is a single deterministic pass: phrases (raw corpus
|
|
22
|
+
* substrings) cannot contain markers, so no cascade, no ambiguity.
|
|
23
|
+
* - Pure functions. Same input → same bytes on every OS/arch (that IS
|
|
24
|
+
* the L6 vendor-neutral proof: the LLM never sees the codebook).
|
|
25
|
+
*/
|
|
26
|
+
import { createHash } from "node:crypto";
|
|
27
|
+
/** Candidate marker pairs, built from Private-Use-Area code points
|
|
28
|
+
* (U+E000…U+E00B) — these never occur in real manifests/code/docs.
|
|
29
|
+
* Built programmatically so the bytes are unambiguous in source. */
|
|
30
|
+
const MARKER_PAIRS = [
|
|
31
|
+
[String.fromCharCode(0xe000), String.fromCharCode(0xe001)],
|
|
32
|
+
[String.fromCharCode(0xe002), String.fromCharCode(0xe003)],
|
|
33
|
+
[String.fromCharCode(0xe004), String.fromCharCode(0xe005)],
|
|
34
|
+
[String.fromCharCode(0xe006), String.fromCharCode(0xe007)],
|
|
35
|
+
[String.fromCharCode(0xe008), String.fromCharCode(0xe009)],
|
|
36
|
+
[String.fromCharCode(0xe00a), String.fromCharCode(0xe00b)],
|
|
37
|
+
];
|
|
38
|
+
export function sha256Hex(s) {
|
|
39
|
+
return createHash("sha256").update(s, "utf8").digest("hex");
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Pick a marker pair guaranteed absent from `corpus` and every `phrase`.
|
|
43
|
+
* Deterministic: always returns the first clean candidate. Throws only if
|
|
44
|
+
* the (astronomically unlikely) corpus contains every PUA candidate.
|
|
45
|
+
*/
|
|
46
|
+
export function chooseMarkers(corpus, phrases) {
|
|
47
|
+
for (const [o, c] of MARKER_PAIRS) {
|
|
48
|
+
if (corpus.includes(o) || corpus.includes(c))
|
|
49
|
+
continue;
|
|
50
|
+
if (phrases.some((p) => p.includes(o) || p.includes(c)))
|
|
51
|
+
continue;
|
|
52
|
+
return [o, c];
|
|
53
|
+
}
|
|
54
|
+
throw new Error("HYDRA: corpus exhausts all PUA marker candidates (impossible for real text)");
|
|
55
|
+
}
|
|
56
|
+
/** The deterministic symbol for entry index `i`. */
|
|
57
|
+
export function symbolFor(open, close, i) {
|
|
58
|
+
return open + i.toString(36) + close;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* L3 — COMPRESS. Replace each codebook phrase with its symbol, longest
|
|
62
|
+
* phrase first (the entries are pre-sorted). Pure + deterministic.
|
|
63
|
+
*/
|
|
64
|
+
export function compress(text, cb) {
|
|
65
|
+
let out = text;
|
|
66
|
+
for (const e of cb.entries) {
|
|
67
|
+
if (e.phrase.length === 0)
|
|
68
|
+
continue;
|
|
69
|
+
out = out.split(e.phrase).join(e.sym);
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* L3 — EXPAND (the Hydra head). Single deterministic pass: replace every
|
|
75
|
+
* symbol with its phrase. Because phrases are raw corpus substrings they
|
|
76
|
+
* cannot contain markers, so there is no cascade and the result is exact.
|
|
77
|
+
*/
|
|
78
|
+
export function expand(encoded, cb) {
|
|
79
|
+
let out = encoded;
|
|
80
|
+
for (const e of cb.entries) {
|
|
81
|
+
if (e.phrase.length === 0)
|
|
82
|
+
continue;
|
|
83
|
+
out = out.split(e.sym).join(e.phrase);
|
|
84
|
+
}
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* L4 — LOSSLESS PROOF. The boolean that cannot lie: a SHA-256 round-trip,
|
|
89
|
+
* not a similarity score. If `lossless` is ever false the codebook is
|
|
90
|
+
* REJECTED upstream — HYDRA never ships a codebook that loses a byte.
|
|
91
|
+
*/
|
|
92
|
+
export function proveLossless(text, cb) {
|
|
93
|
+
const encoded = compress(text, cb);
|
|
94
|
+
const restored = expand(encoded, cb);
|
|
95
|
+
const originalHash = sha256Hex(text);
|
|
96
|
+
const roundTripHash = sha256Hex(restored);
|
|
97
|
+
const originalBytes = Buffer.byteLength(text, "utf8");
|
|
98
|
+
const compressedBytes = Buffer.byteLength(encoded, "utf8");
|
|
99
|
+
return {
|
|
100
|
+
lossless: originalHash === roundTripHash,
|
|
101
|
+
originalHash,
|
|
102
|
+
roundTripHash,
|
|
103
|
+
originalBytes,
|
|
104
|
+
compressedBytes,
|
|
105
|
+
ratio: compressedBytes === 0 ? 1 : originalBytes / compressedBytes,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=engine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"engine.js","sourceRoot":"","sources":["../../src/hydra/engine.ts"],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CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;IACnC,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IACrC,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,aAAa,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACtD,MAAM,eAAe,GAAG,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3D,OAAO;QACL,QAAQ,EAAE,YAAY,KAAK,aAAa;QACxC,YAAY;QACZ,aAAa;QACb,aAAa;QACb,eAAe;QACf,KAAK,EAAE,eAAe,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,GAAG,eAAe;KACnE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydra.test.d.ts","sourceRoot":"","sources":["../../src/hydra/hydra.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { forgeCodebook, collisions, compress, expand, proveLossless, chooseMarkers, sha256Hex, mineCandidates, hydraForge, verifyCodebook, } from "./index.js";
|
|
3
|
+
const CORPUS = [
|
|
4
|
+
"HMAC-chained ledger is tamper-evident. The HMAC-chained ledger signs each row.",
|
|
5
|
+
"Ed25519-signed receipt verifies offline. Another Ed25519-signed receipt chains.",
|
|
6
|
+
"HMAC-chained ledger plus Ed25519-signed receipt equals tamper-evident provenance.",
|
|
7
|
+
].join("\n").repeat(4);
|
|
8
|
+
describe("v2.96 HYDRA · L3+L4 lossless engine", () => {
|
|
9
|
+
it("round-trips byte-identical (lossless proof is true)", () => {
|
|
10
|
+
const { codebook } = forgeCodebook(CORPUS, { minHits: 2 });
|
|
11
|
+
const p = proveLossless(CORPUS, codebook);
|
|
12
|
+
expect(p.lossless).toBe(true);
|
|
13
|
+
expect(p.originalHash).toBe(p.roundTripHash);
|
|
14
|
+
expect(expand(compress(CORPUS, codebook), codebook)).toBe(CORPUS);
|
|
15
|
+
});
|
|
16
|
+
it("markers are PUA chars absent from the corpus", () => {
|
|
17
|
+
const [o, c] = chooseMarkers(CORPUS, []);
|
|
18
|
+
expect(CORPUS.includes(o)).toBe(false);
|
|
19
|
+
expect(CORPUS.includes(c)).toBe(false);
|
|
20
|
+
expect(o.charCodeAt(0)).toBeGreaterThanOrEqual(0xe000);
|
|
21
|
+
});
|
|
22
|
+
it("does NOT munge a corpus that already contains a candidate marker — falls back", () => {
|
|
23
|
+
const tricky = String.fromCharCode(0xe000) + " " + CORPUS; // corpus carries the first marker
|
|
24
|
+
const { codebook } = forgeCodebook(tricky, { minHits: 2 });
|
|
25
|
+
expect(proveLossless(tricky, codebook).lossless).toBe(true); // still lossless via fallback marker
|
|
26
|
+
expect(codebook.open).not.toBe(String.fromCharCode(0xe000));
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
describe("v2.96 HYDRA · L7 collision-free (can't hold two meanings)", () => {
|
|
30
|
+
it("a forged codebook has zero collisions", () => {
|
|
31
|
+
const { codebook } = forgeCodebook(CORPUS, { minHits: 2 });
|
|
32
|
+
expect(collisions(codebook).collisions).toBe(0);
|
|
33
|
+
});
|
|
34
|
+
it("detects an injected duplicate symbol / phrase", () => {
|
|
35
|
+
const { codebook } = forgeCodebook(CORPUS, { minHits: 2 });
|
|
36
|
+
const dup = { v: 1, open: codebook.open, close: codebook.close, corpusHash: codebook.corpusHash,
|
|
37
|
+
entries: [...codebook.entries, codebook.entries[0]] };
|
|
38
|
+
expect(collisions(dup).collisions).toBeGreaterThan(0);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe("v2.96 HYDRA · L9 self-refining forge converges + L6 portable", () => {
|
|
42
|
+
it("converges with a perfect gauntlet (score 100)", () => {
|
|
43
|
+
const r = forgeCodebook(CORPUS, { minHits: 2 });
|
|
44
|
+
expect(r.converged).toBe(true);
|
|
45
|
+
expect(r.gauntlet.score).toBe(100);
|
|
46
|
+
expect(r.gauntlet.lossless).toBe(true);
|
|
47
|
+
expect(r.gauntlet.collisions).toBe(0);
|
|
48
|
+
expect(r.gauntlet.portable).toBe(true);
|
|
49
|
+
});
|
|
50
|
+
it("is deterministic — same corpus → identical codebook hash", () => {
|
|
51
|
+
const a = forgeCodebook(CORPUS, { minHits: 2 });
|
|
52
|
+
const b = forgeCodebook(CORPUS, { minHits: 2 });
|
|
53
|
+
expect(sha256Hex(JSON.stringify(a.codebook.entries))).toBe(sha256Hex(JSON.stringify(b.codebook.entries)));
|
|
54
|
+
});
|
|
55
|
+
it("reports an HONEST net ratio (never claims single-shot magic)", () => {
|
|
56
|
+
const r = forgeCodebook(CORPUS, { minHits: 2 });
|
|
57
|
+
expect(r.gauntlet.netRatio).toBeGreaterThan(0);
|
|
58
|
+
expect(typeof r.gauntlet.codebookBytes).toBe("number");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
describe("v2.96 HYDRA · L5 signed + L8 energy (offline-verifiable)", () => {
|
|
62
|
+
it("signs the codebook and verifies offline; catches tampering", () => {
|
|
63
|
+
const f = hydraForge(process.cwd(), CORPUS, 1700000000000, { minHits: 2 });
|
|
64
|
+
expect(verifyCodebook(f.receipt, f.forge.codebook).bound).toBe(true);
|
|
65
|
+
const tampered = JSON.parse(JSON.stringify(f.forge.codebook));
|
|
66
|
+
tampered.entries[0].phrase += "X";
|
|
67
|
+
expect(verifyCodebook(f.receipt, tampered).bound).toBe(false); // swap-after-sign caught
|
|
68
|
+
});
|
|
69
|
+
it("mints an energy certificate and binds axioms (L7/L8)", () => {
|
|
70
|
+
const f = hydraForge(process.cwd(), CORPUS, 1700000000000, { minHits: 2 });
|
|
71
|
+
expect(f.energy.bytesSaved).toBeGreaterThanOrEqual(0);
|
|
72
|
+
expect(f.axioms.length).toBe(f.forge.codebook.entries.length);
|
|
73
|
+
expect(f.axioms[0]?.claim).toContain("expands to");
|
|
74
|
+
});
|
|
75
|
+
it("L6 portable artifact carries a self-describing grammar", () => {
|
|
76
|
+
const f = hydraForge(process.cwd(), CORPUS, 1700000000000, { minHits: 2 });
|
|
77
|
+
expect(f.portable.kind).toBe("hydra/portable-codebook");
|
|
78
|
+
expect(f.portable.grammar.rule).toContain("replace");
|
|
79
|
+
expect(f.portable.codebookHash).toHaveLength(64);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe("v2.96 HYDRA · L1/L2 mining is MDL-positive", () => {
|
|
83
|
+
it("only mines phrases that pay back more than they cost", () => {
|
|
84
|
+
const cands = mineCandidates(CORPUS, { minHits: 2 });
|
|
85
|
+
expect(cands.length).toBeGreaterThan(0);
|
|
86
|
+
for (const c of cands)
|
|
87
|
+
expect(c.gain).toBeGreaterThan(0);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
//# sourceMappingURL=hydra.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydra.test.js","sourceRoot":"","sources":["../../src/hydra/hydra.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EACL,aAAa,EAAY,UAAU,EACnC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EACzD,cAAc,EACd,UAAU,EAAE,cAAc,GAC3B,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,GAAG;IACb,gFAAgF;IAChF,iFAAiF;IACjF,mFAAmF;CACpF,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAEvB,QAAQ,CAAC,qCAAqC,EAAE,GAAG,EAAE;IACnD,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,MAAM,EAAE,Q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