@mneme-ai/core 2.95.0 → 2.97.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/agent_manifest.d.ts.map +1 -1
  2. package/dist/agent_manifest.js +1 -0
  3. package/dist/agent_manifest.js.map +1 -1
  4. package/dist/hydra/analytic.d.ts +103 -0
  5. package/dist/hydra/analytic.d.ts.map +1 -0
  6. package/dist/hydra/analytic.js +161 -0
  7. package/dist/hydra/analytic.js.map +1 -0
  8. package/dist/hydra/attest.d.ts +60 -0
  9. package/dist/hydra/attest.d.ts.map +1 -0
  10. package/dist/hydra/attest.js +84 -0
  11. package/dist/hydra/attest.js.map +1 -0
  12. package/dist/hydra/engine.d.ts +84 -0
  13. package/dist/hydra/engine.d.ts.map +1 -0
  14. package/dist/hydra/engine.js +108 -0
  15. package/dist/hydra/engine.js.map +1 -0
  16. package/dist/hydra/guard.d.ts +75 -0
  17. package/dist/hydra/guard.d.ts.map +1 -0
  18. package/dist/hydra/guard.js +171 -0
  19. package/dist/hydra/guard.js.map +1 -0
  20. package/dist/hydra/guard.test.d.ts +2 -0
  21. package/dist/hydra/guard.test.d.ts.map +1 -0
  22. package/dist/hydra/guard.test.js +79 -0
  23. package/dist/hydra/guard.test.js.map +1 -0
  24. package/dist/hydra/hydra.test.d.ts +2 -0
  25. package/dist/hydra/hydra.test.d.ts.map +1 -0
  26. package/dist/hydra/hydra.test.js +90 -0
  27. package/dist/hydra/hydra.test.js.map +1 -0
  28. package/dist/hydra/index.d.ts +77 -0
  29. package/dist/hydra/index.d.ts.map +1 -0
  30. package/dist/hydra/index.js +62 -0
  31. package/dist/hydra/index.js.map +1 -0
  32. package/dist/hydra/mine.d.ts +42 -0
  33. package/dist/hydra/mine.d.ts.map +1 -0
  34. package/dist/hydra/mine.js +72 -0
  35. package/dist/hydra/mine.js.map +1 -0
  36. package/dist/index.d.ts +1 -0
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/index.js +1 -0
  39. package/dist/index.js.map +1 -1
  40. package/dist/truth_gate/probes.d.ts.map +1 -1
  41. package/dist/truth_gate/probes.js +58 -0
  42. package/dist/truth_gate/probes.js.map +1 -1
  43. 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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,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;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAsB,MAAM,sBAAsB,CAAC;AAEvF,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGxC,8EAA8E;AAC9E,MAAM,UAAU,oBAAoB,CAAC,EAAY;IAC/C,0EAA0E;IAC1E,6DAA6D;IAC7D,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IACzD,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,OAAO,EAAE,CAAC,CAAC;AACzG,CAAC;AAYD;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB,EAAE,EAAY,EAAE,CAAW,EAAE,EAAU;IAClF,MAAM,KAAK,GAA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ingua/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,EAAE,MAAM,CAAC;IACZ,uDAAuD;IACvD,MAAM,EAAE,MAAM,CAAC;IACf,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IAC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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"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AA0BzC;;qEAEqE;AACrE,MAAM,YAAY,GAA6C;IAC7D,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;CAC3D,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,CAAS;IACjC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC9D,CAAC;AA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QAC3B,IAAI,CAAC,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QACpC,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAaD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,EAAY;IACtD,MAAM,OAAO,GAAG,QAAQ,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,75 @@
1
+ /**
2
+ * v2.97.0 — HYDRA · GUARDED EXPANSION ("Time-To-Trust").
3
+ *
4
+ * The fusion gem: HYDRA codebook × the knowledge-atrophy clock × NOTARY.
5
+ * A normal expand() is byte-lossless. A GUARDED expand is lossless for
6
+ * TRUSTED content but provably REDACTS stale/quarantined content down to a
7
+ * signed abstract (sha256 + byte-count) — so an AI literally cannot
8
+ * hallucinate from expired memory, yet can still verify the redacted
9
+ * region's identity and request re-hydration.
10
+ *
11
+ * Prior-art research (v2.96) found no signed + lossless + TTL-guarded
12
+ * codebook anywhere. This is that unfilled lane, made measurable:
13
+ * - all-fresh ⟹ guarded output is BYTE-IDENTICAL to the original (boolean)
14
+ * - any stale entry ⟹ its raw phrase NEVER appears, its sha256 DOES,
15
+ * fresh entries stay byte-exact (boolean)
16
+ * - deterministic: same input → same bytes (boolean)
17
+ *
18
+ * STABILITY: every function is total — it never throws. Malformed input,
19
+ * a missing field, an unknown trust level → the SAFEST outcome (redact).
20
+ * The 108-error rule: when in doubt, guard, don't crash and don't leak.
21
+ */
22
+ import { type Codebook } from "./engine.js";
23
+ export type TrustLevel = "fresh" | "stale" | "quarantined";
24
+ /** A function (or map) that returns the trust level for a symbol. */
25
+ export type TrustResolver = (sym: string) => TrustLevel;
26
+ export declare function trustFromMap(map: Record<string, TrustLevel>): TrustResolver;
27
+ /**
28
+ * The deterministic redaction placeholder for a guarded entry. Carries the
29
+ * sha256 of the original phrase (identity-verifiable) + byte count + the
30
+ * reason — but NOT the content. Re-hydration replaces it with the real
31
+ * phrase once the symbol is re-verified.
32
+ */
33
+ export declare function guardedPlaceholder(phrase: string, level: TrustLevel): string;
34
+ /**
35
+ * GUARDED EXPAND. Fresh symbols expand to their phrase (byte-exact); stale
36
+ * or quarantined symbols expand to a signed abstract. Total: never throws;
37
+ * a bad entry is treated as quarantined (fail-closed, never leak).
38
+ */
39
+ export declare function expandGuarded(encoded: string, cb: Codebook, trustOf: TrustResolver): string;
40
+ /**
41
+ * RE-HYDRATE a guarded output: given the set of symbols whose access has
42
+ * been re-verified, replace their placeholders with the real phrase. Total:
43
+ * unknown symbols / malformed input are left untouched (no throw, no leak).
44
+ */
45
+ export declare function rehydrate(encoded: string, cb: Codebook, approvedSyms: Iterable<string>, trustOf: TrustResolver): string;
46
+ export interface GuardedGauntlet {
47
+ /** all-fresh ⟹ guarded output is byte-identical to the original. */
48
+ freshLossless: boolean;
49
+ /** every stale phrase is absent from guarded output AND its sha256 present. */
50
+ redactionSound: boolean;
51
+ /** fresh entries remain byte-exact even when others are redacted. */
52
+ freshPreserved: boolean;
53
+ /** deterministic — two guarded expands hash-identical. */
54
+ deterministic: boolean;
55
+ redactedCount: number;
56
+ freshCount: number;
57
+ /** 0–100. 100 ⟺ all four invariants hold. Cannot lie about a leak. */
58
+ score: number;
59
+ }
60
+ /**
61
+ * The guarded gauntlet — proves the four Time-To-Trust invariants over a
62
+ * concrete trust assignment. Total + deterministic. `compressFn` lets the
63
+ * caller pass the engine's compress to avoid an import cycle; if omitted we
64
+ * verify directly against the codebook entries.
65
+ */
66
+ export declare function guardedGauntlet(original: string, encoded: string, cb: Codebook, trustMap: Record<string, TrustLevel>): GuardedGauntlet;
67
+ /**
68
+ * Compose the ATROPHY clock: mark a codebook's entries stale when the
69
+ * caller's age map says their source region is older than the half-life.
70
+ * `ageMsOf` returns the age (ms) of the source behind a symbol, or
71
+ * undefined if unknown (unknown ⇒ fresh, the least-surprising default —
72
+ * we only redact what we can PROVE is stale). Total; never throws.
73
+ */
74
+ export declare function trustByAtrophy(cb: Codebook, ageMsOf: (sym: string) => number | undefined, halfLifeMs: number): Record<string, TrustLevel>;
75
+ //# sourceMappingURL=guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/hydra/guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,KAAK,QAAQ,EAAa,MAAM,aAAa,CAAC;AAEvD,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,aAAa,CAAC;AAE3D,qEAAqE;AACrE,MAAM,MAAM,aAAa,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,UAAU,CAAC;AAExD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,aAAa,CAE3E;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,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