@hviana/sema 0.1.5 → 0.1.7

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 (170) hide show
  1. package/AGENTS.md +6 -5
  2. package/CITATION.cff +49 -0
  3. package/HOW_IT_WORKS.md +11 -12
  4. package/README.md +7 -5
  5. package/dist/example/demo.js +25 -25
  6. package/dist/example/train_base.d.ts +19 -21
  7. package/dist/example/train_base.js +1700 -1952
  8. package/dist/src/alphabet.d.ts +3 -3
  9. package/dist/src/alphabet.js +24 -27
  10. package/dist/src/alu/src/alu.d.ts +169 -194
  11. package/dist/src/alu/src/alu.js +374 -414
  12. package/dist/src/alu/src/expr.d.ts +36 -43
  13. package/dist/src/alu/src/expr.js +252 -278
  14. package/dist/src/alu/src/index.d.ts +9 -98
  15. package/dist/src/alu/src/index.js +10 -64
  16. package/dist/src/alu/src/kernel-arith.d.ts +1 -5
  17. package/dist/src/alu/src/kernel-arith.js +195 -285
  18. package/dist/src/alu/src/kernel-bits.d.ts +1 -5
  19. package/dist/src/alu/src/kernel-bits.js +81 -115
  20. package/dist/src/alu/src/kernel-logic.js +33 -63
  21. package/dist/src/alu/src/kernel-nd.js +155 -195
  22. package/dist/src/alu/src/kernel-numeric.d.ts +16 -80
  23. package/dist/src/alu/src/kernel-numeric.js +259 -331
  24. package/dist/src/alu/src/operation.d.ts +112 -132
  25. package/dist/src/alu/src/operation.js +149 -163
  26. package/dist/src/alu/src/parser.d.ts +168 -175
  27. package/dist/src/alu/src/parser.js +382 -421
  28. package/dist/src/alu/src/resonance.d.ts +16 -25
  29. package/dist/src/alu/src/resonance.js +49 -56
  30. package/dist/src/alu/src/text.d.ts +3 -7
  31. package/dist/src/alu/src/text.js +31 -37
  32. package/dist/src/alu/src/value.d.ts +14 -14
  33. package/dist/src/alu/src/value.js +150 -160
  34. package/dist/src/alu/test/alu.test.js +543 -656
  35. package/dist/src/bytes.d.ts +1 -5
  36. package/dist/src/bytes.js +33 -40
  37. package/dist/src/config.d.ts +99 -102
  38. package/dist/src/config.js +78 -83
  39. package/dist/src/derive/src/deduction.d.ts +60 -62
  40. package/dist/src/derive/src/deduction.js +103 -109
  41. package/dist/src/derive/src/index.d.ts +1 -7
  42. package/dist/src/derive/src/priority-queue.d.ts +8 -8
  43. package/dist/src/derive/src/priority-queue.js +57 -61
  44. package/dist/src/derive/src/rewrite.d.ts +15 -18
  45. package/dist/src/derive/src/rewrite.js +59 -67
  46. package/dist/src/derive/src/trie.d.ts +56 -56
  47. package/dist/src/derive/src/trie.js +175 -179
  48. package/dist/src/derive/test/derive.test.js +96 -100
  49. package/dist/src/extension.d.ts +13 -16
  50. package/dist/src/geometry.d.ts +29 -43
  51. package/dist/src/geometry.js +324 -268
  52. package/dist/src/index.d.ts +2 -17
  53. package/dist/src/index.js +2 -12
  54. package/dist/src/ingest-cache.d.ts +25 -30
  55. package/dist/src/ingest-cache.js +108 -127
  56. package/dist/src/mind/articulation.d.ts +1 -5
  57. package/dist/src/mind/articulation.js +77 -112
  58. package/dist/src/mind/attention.d.ts +40 -108
  59. package/dist/src/mind/attention.js +754 -872
  60. package/dist/src/mind/canonical.d.ts +4 -19
  61. package/dist/src/mind/canonical.js +27 -31
  62. package/dist/src/mind/graph-search.d.ts +201 -225
  63. package/dist/src/mind/graph-search.js +742 -821
  64. package/dist/src/mind/index.d.ts +2 -10
  65. package/dist/src/mind/junction.d.ts +31 -58
  66. package/dist/src/mind/junction.js +172 -237
  67. package/dist/src/mind/learning.d.ts +16 -52
  68. package/dist/src/mind/learning.js +143 -165
  69. package/dist/src/mind/match.d.ts +20 -69
  70. package/dist/src/mind/match.js +259 -318
  71. package/dist/src/mind/mechanisms/alu.js +16 -16
  72. package/dist/src/mind/mechanisms/cast.d.ts +9 -13
  73. package/dist/src/mind/mechanisms/cast.js +363 -456
  74. package/dist/src/mind/mechanisms/confluence.d.ts +8 -12
  75. package/dist/src/mind/mechanisms/confluence.js +152 -183
  76. package/dist/src/mind/mechanisms/cover.d.ts +2 -8
  77. package/dist/src/mind/mechanisms/cover.js +148 -210
  78. package/dist/src/mind/mechanisms/extraction.d.ts +8 -34
  79. package/dist/src/mind/mechanisms/extraction.js +234 -288
  80. package/dist/src/mind/mechanisms/recall.d.ts +6 -10
  81. package/dist/src/mind/mechanisms/recall.js +141 -185
  82. package/dist/src/mind/mind.d.ts +194 -155
  83. package/dist/src/mind/mind.js +392 -289
  84. package/dist/src/mind/pipeline-mechanism.d.ts +112 -124
  85. package/dist/src/mind/pipeline-mechanism.js +161 -172
  86. package/dist/src/mind/pipeline.d.ts +4 -14
  87. package/dist/src/mind/pipeline.js +125 -189
  88. package/dist/src/mind/primitives.d.ts +20 -33
  89. package/dist/src/mind/primitives.js +124 -120
  90. package/dist/src/mind/rationale.d.ts +86 -98
  91. package/dist/src/mind/rationale.js +113 -121
  92. package/dist/src/mind/reasoning.d.ts +2 -13
  93. package/dist/src/mind/reasoning.js +129 -166
  94. package/dist/src/mind/recognition.d.ts +1 -4
  95. package/dist/src/mind/recognition.js +198 -210
  96. package/dist/src/mind/resonance.d.ts +5 -22
  97. package/dist/src/mind/resonance.js +0 -0
  98. package/dist/src/mind/trace.d.ts +6 -25
  99. package/dist/src/mind/trace.js +50 -58
  100. package/dist/src/mind/traverse.d.ts +29 -58
  101. package/dist/src/mind/traverse.js +344 -356
  102. package/dist/src/mind/types.d.ts +122 -127
  103. package/dist/src/mind/types.js +60 -69
  104. package/dist/src/rabitq-ivf/src/database.d.ts +113 -0
  105. package/dist/src/rabitq-ivf/src/database.js +201 -0
  106. package/dist/src/rabitq-ivf/src/index.d.ts +7 -0
  107. package/dist/src/{rabitq-hnsw → rabitq-ivf}/src/index.js +1 -3
  108. package/dist/src/rabitq-ivf/src/ivf.d.ts +200 -0
  109. package/dist/src/rabitq-ivf/src/ivf.js +1165 -0
  110. package/dist/src/rabitq-ivf/src/prng.d.ts +19 -0
  111. package/dist/src/rabitq-ivf/src/prng.js +36 -0
  112. package/dist/src/rabitq-ivf/src/rabitq.d.ts +95 -0
  113. package/dist/src/rabitq-ivf/src/rabitq.js +283 -0
  114. package/dist/src/sema.d.ts +9 -13
  115. package/dist/src/sema.js +26 -40
  116. package/dist/src/store-sqlite.d.ts +171 -166
  117. package/dist/src/store-sqlite.js +768 -662
  118. package/dist/src/store.d.ts +597 -630
  119. package/dist/src/store.js +1434 -1581
  120. package/dist/src/vec.d.ts +5 -9
  121. package/dist/src/vec.js +61 -73
  122. package/example/train_base.ts +33 -15
  123. package/index.html +65 -0
  124. package/package.json +1 -1
  125. package/src/alu/README.md +1 -1
  126. package/src/alu/src/index.ts +1 -1
  127. package/src/config.ts +19 -27
  128. package/src/geometry.ts +93 -1
  129. package/src/index.ts +6 -11
  130. package/src/mind/attention.ts +11 -6
  131. package/src/mind/mechanisms/recall.ts +29 -13
  132. package/src/mind/mind.ts +250 -19
  133. package/src/mind/primitives.ts +43 -6
  134. package/src/mind/recognition.ts +26 -8
  135. package/src/mind/traverse.ts +47 -0
  136. package/src/mind/types.ts +20 -21
  137. package/src/rabitq-ivf/README.md +56 -0
  138. package/src/rabitq-ivf/src/database.ts +276 -0
  139. package/src/{rabitq-hnsw → rabitq-ivf}/src/index.ts +2 -5
  140. package/src/rabitq-ivf/src/ivf.ts +1330 -0
  141. package/src/{rabitq-hnsw → rabitq-ivf}/src/prng.ts +1 -1
  142. package/src/store-sqlite.ts +204 -9
  143. package/src/store.ts +27 -34
  144. package/test/08-storage.test.mjs +3 -3
  145. package/test/13-conversation.test.mjs +190 -20
  146. package/test/14-scaling.test.mjs +2 -2
  147. package/test/35-ivf.test.mjs +263 -0
  148. package/test/36-bloom.test.mjs +123 -0
  149. package/dist/src/rabitq-hnsw/src/database.d.ts +0 -202
  150. package/dist/src/rabitq-hnsw/src/database.js +0 -405
  151. package/dist/src/rabitq-hnsw/src/heap.d.ts +0 -22
  152. package/dist/src/rabitq-hnsw/src/heap.js +0 -94
  153. package/dist/src/rabitq-hnsw/src/hnsw.d.ts +0 -125
  154. package/dist/src/rabitq-hnsw/src/hnsw.js +0 -500
  155. package/dist/src/rabitq-hnsw/src/index.d.ts +0 -15
  156. package/dist/src/rabitq-hnsw/src/prng.d.ts +0 -19
  157. package/dist/src/rabitq-hnsw/src/prng.js +0 -38
  158. package/dist/src/rabitq-hnsw/src/rabitq.d.ts +0 -95
  159. package/dist/src/rabitq-hnsw/src/rabitq.js +0 -299
  160. package/dist/src/rabitq-hnsw/src/store.d.ts +0 -162
  161. package/dist/src/rabitq-hnsw/src/store.js +0 -916
  162. package/dist/src/rabitq-hnsw/test/hnsw.test.d.ts +0 -1
  163. package/dist/src/rabitq-hnsw/test/hnsw.test.js +0 -1197
  164. package/src/rabitq-hnsw/README.md +0 -303
  165. package/src/rabitq-hnsw/src/database.ts +0 -492
  166. package/src/rabitq-hnsw/src/heap.ts +0 -90
  167. package/src/rabitq-hnsw/src/hnsw.ts +0 -514
  168. package/src/rabitq-hnsw/src/store.ts +0 -994
  169. package/src/rabitq-hnsw/test/hnsw.test.ts +0 -1213
  170. /package/src/{rabitq-hnsw → rabitq-ivf}/src/rabitq.ts +0 -0
@@ -3,124 +3,120 @@
3
3
  // and the optimal cover. Uses node:test; no dependency on sema.
4
4
  import { test } from "node:test";
5
5
  import assert from "node:assert/strict";
6
- import { coverSequence, lightestDerivation, Trie } from "../src/index.js";
6
+ import { coverSequence, lightestDerivation, Trie, } from "../src/index.js";
7
7
  // ── trie: on-demand matching, no length bound ──────────────────────────────
8
8
  test("trie matchesAt reports forms beginning exactly at a position", () => {
9
- const t = new Trie();
10
- t.insert([1, 2], "ab");
11
- t.insert([1, 2, 3], "abc");
12
- t.insert([2, 3], "bc");
13
- const at0 = t.matchesAt([1, 2, 3, 4], 0).map((m) => m.payload);
14
- assert.deepEqual(at0, ["ab", "abc"]); // both forms starting at 0, shortest first
15
- const at1 = t.matchesAt([1, 2, 3, 4], 1).map((m) => m.payload);
16
- assert.deepEqual(at1, ["bc"]);
17
- const at3 = t.matchesAt([1, 2, 3, 4], 3).map((m) => m.payload);
18
- assert.deepEqual(at3, []); // nothing learned here → dead-ends immediately
9
+ const t = new Trie();
10
+ t.insert([1, 2], "ab");
11
+ t.insert([1, 2, 3], "abc");
12
+ t.insert([2, 3], "bc");
13
+ const at0 = t.matchesAt([1, 2, 3, 4], 0).map((m) => m.payload);
14
+ assert.deepEqual(at0, ["ab", "abc"]); // both forms starting at 0, shortest first
15
+ const at1 = t.matchesAt([1, 2, 3, 4], 1).map((m) => m.payload);
16
+ assert.deepEqual(at1, ["bc"]);
17
+ const at3 = t.matchesAt([1, 2, 3, 4], 3).map((m) => m.payload);
18
+ assert.deepEqual(at3, []); // nothing learned here → dead-ends immediately
19
19
  });
20
20
  test("trie scan finds every occurrence; duplicate inserts share an id", () => {
21
- const t = new Trie();
22
- const id1 = t.insert([7, 7], 1);
23
- const id2 = t.insert([7, 7], 2); // same content
24
- assert.equal(id1, id2);
25
- assert.equal(t.size, 1);
26
- const hits = t.scan([7, 7, 7]);
27
- assert.equal(hits.length, 2); // [0,2) and [1,3)
21
+ const t = new Trie();
22
+ const id1 = t.insert([7, 7], 1);
23
+ const id2 = t.insert([7, 7], 2); // same content
24
+ assert.equal(id1, id2);
25
+ assert.equal(t.size, 1);
26
+ const hits = t.scan([7, 7, 7]);
27
+ assert.equal(hits.length, 2); // [0,2) and [1,3)
28
28
  });
29
29
  // ── engine: Dijkstra/Knuth core with a bridge (multi-premise) rule ─────────
30
30
  test("lightestDerivation solves a hypergraph with a bridge premise", () => {
31
- // Items: "A", "B", "AB". Axioms A (3) and B (4). A binary bridge A ∧ B → AB
32
- // at cost 1. The only derivation of AB costs 3 + 4 + 1 = 8.
33
- const A = "A", B = "B", AB = "AB";
34
- const system = {
35
- key: (s) => s,
36
- axioms: () => [{ item: A, cost: 3 }, { item: B, cost: 4 }],
37
- isGoal: (s) => s === AB,
38
- *rules(item) {
39
- // Bridge fires from either premise; the engine waits until both are known.
40
- if (item === A) {
41
- yield { premises: [A, B], conclusion: AB, cost: 1 };
42
- }
43
- if (item === B) {
44
- yield { premises: [A, B], conclusion: AB, cost: 1 };
45
- }
46
- },
47
- };
48
- const d = lightestDerivation(system);
49
- assert.ok(d);
50
- assert.equal(d.item, AB);
51
- assert.equal(d.cost, 8);
52
- assert.equal(d.premises.length, 2); // it really used the bridge
31
+ // Items: "A", "B", "AB". Axioms A (3) and B (4). A binary bridge A ∧ B → AB
32
+ // at cost 1. The only derivation of AB costs 3 + 4 + 1 = 8.
33
+ const A = "A", B = "B", AB = "AB";
34
+ const system = {
35
+ key: (s) => s,
36
+ axioms: () => [{ item: A, cost: 3 }, { item: B, cost: 4 }],
37
+ isGoal: (s) => s === AB,
38
+ *rules(item) {
39
+ // Bridge fires from either premise; the engine waits until both are known.
40
+ if (item === A)
41
+ yield { premises: [A, B], conclusion: AB, cost: 1 };
42
+ if (item === B)
43
+ yield { premises: [A, B], conclusion: AB, cost: 1 };
44
+ },
45
+ };
46
+ const d = lightestDerivation(system);
47
+ assert.ok(d);
48
+ assert.equal(d.item, AB);
49
+ assert.equal(d.cost, 8);
50
+ assert.equal(d.premises.length, 2); // it really used the bridge
53
51
  });
54
52
  test("lightestDerivation picks the cheaper of competing derivations", () => {
55
- // Two ways to reach the goal G from axiom S: S→G cost 10, or S→M→G cost 3+3.
56
- const system = {
57
- key: (s) => s,
58
- axioms: () => [{ item: "S", cost: 0 }],
59
- isGoal: (s) => s === "G",
60
- *rules(item) {
61
- if (item === "S") {
62
- yield { premises: ["S"], conclusion: "G", cost: 10 };
63
- yield { premises: ["S"], conclusion: "M", cost: 3 };
64
- }
65
- if (item === "M") {
66
- yield { premises: ["M"], conclusion: "G", cost: 3 };
67
- }
68
- },
69
- };
70
- const d = lightestDerivation(system);
71
- assert.ok(d);
72
- assert.equal(d.cost, 6); // via M, not the direct 10
73
- assert.equal(d.rule?.premises[0], "M");
53
+ // Two ways to reach the goal G from axiom S: S→G cost 10, or S→M→G cost 3+3.
54
+ const system = {
55
+ key: (s) => s,
56
+ axioms: () => [{ item: "S", cost: 0 }],
57
+ isGoal: (s) => s === "G",
58
+ *rules(item) {
59
+ if (item === "S") {
60
+ yield { premises: ["S"], conclusion: "G", cost: 10 };
61
+ yield { premises: ["S"], conclusion: "M", cost: 3 };
62
+ }
63
+ if (item === "M")
64
+ yield { premises: ["M"], conclusion: "G", cost: 3 };
65
+ },
66
+ };
67
+ const d = lightestDerivation(system);
68
+ assert.ok(d);
69
+ assert.equal(d.cost, 6); // via M, not the direct 10
70
+ assert.equal(d.rule?.premises[0], "M");
74
71
  });
75
72
  test("lightestDerivation returns null when the goal is unreachable", () => {
76
- const system = {
77
- key: (n) => "" + n,
78
- axioms: () => [{ item: 0, cost: 0 }],
79
- isGoal: (n) => n === 99,
80
- *rules(n) {
81
- if (n < 3) {
82
- yield { premises: [n], conclusion: n + 1, cost: 1 };
83
- }
84
- },
85
- };
86
- assert.equal(lightestDerivation(system), null);
73
+ const system = {
74
+ key: (n) => "" + n,
75
+ axioms: () => [{ item: 0, cost: 0 }],
76
+ isGoal: (n) => n === 99,
77
+ *rules(n) {
78
+ if (n < 3)
79
+ yield { premises: [n], conclusion: n + 1, cost: 1 };
80
+ },
81
+ };
82
+ assert.equal(lightestDerivation(system), null);
87
83
  });
88
84
  // ── cover: optimal, not greedy ─────────────────────────────────────────────
89
85
  test("coverSequence maximises coverage, beating greedy longest-match", () => {
90
- // Over [0,4): one long span [1,4) (len 3) vs two short [0,2),[2,4) (cover 4).
91
- // Greedy-longest takes [1,4) and covers 3; the optimal cover takes the pair.
92
- const cover = coverSequence(4, [
93
- { start: 1, end: 4, payload: "long" },
94
- { start: 0, end: 2, payload: "left" },
95
- { start: 2, end: 4, payload: "right" },
96
- ]);
97
- assert.equal(cover.covered, 4);
98
- assert.equal(cover.uncovered, 0);
99
- assert.deepEqual(cover.spans.map((s) => s.payload), ["left", "right"]);
86
+ // Over [0,4): one long span [1,4) (len 3) vs two short [0,2),[2,4) (cover 4).
87
+ // Greedy-longest takes [1,4) and covers 3; the optimal cover takes the pair.
88
+ const cover = coverSequence(4, [
89
+ { start: 1, end: 4, payload: "long" },
90
+ { start: 0, end: 2, payload: "left" },
91
+ { start: 2, end: 4, payload: "right" },
92
+ ]);
93
+ assert.equal(cover.covered, 4);
94
+ assert.equal(cover.uncovered, 0);
95
+ assert.deepEqual(cover.spans.map((s) => s.payload), ["left", "right"]);
100
96
  });
101
97
  test("coverSequence prefers fewer, longer spans on ties (unit weight)", () => {
102
- // [0,3) covers the same as [0,1)+[1,3) but in one span → preferred.
103
- const cover = coverSequence(3, [
104
- { start: 0, end: 3, payload: "whole" },
105
- { start: 0, end: 1, payload: "a" },
106
- { start: 1, end: 3, payload: "b" },
107
- ]);
108
- assert.deepEqual(cover.spans.map((s) => s.payload), ["whole"]);
98
+ // [0,3) covers the same as [0,1)+[1,3) but in one span → preferred.
99
+ const cover = coverSequence(3, [
100
+ { start: 0, end: 3, payload: "whole" },
101
+ { start: 0, end: 1, payload: "a" },
102
+ { start: 1, end: 3, payload: "b" },
103
+ ]);
104
+ assert.deepEqual(cover.spans.map((s) => s.payload), ["whole"]);
109
105
  });
110
106
  test("coverSequence leaves genuinely uncovered gaps uncovered", () => {
111
- const cover = coverSequence(10, [
112
- { start: 0, end: 3, payload: "x" },
113
- { start: 6, end: 9, payload: "y" },
114
- ]);
115
- assert.equal(cover.covered, 6);
116
- assert.equal(cover.uncovered, 4);
117
- assert.deepEqual(cover.spans.map((s) => s.payload), ["x", "y"]);
107
+ const cover = coverSequence(10, [
108
+ { start: 0, end: 3, payload: "x" },
109
+ { start: 6, end: 9, payload: "y" },
110
+ ]);
111
+ assert.equal(cover.covered, 6);
112
+ assert.equal(cover.uncovered, 4);
113
+ assert.deepEqual(cover.spans.map((s) => s.payload), ["x", "y"]);
118
114
  });
119
115
  test("coverSequence honours weights when coverage ties", () => {
120
- // Both single-span covers cover all 2 symbols; the lighter weight wins.
121
- const cover = coverSequence(2, [
122
- { start: 0, end: 2, weight: 5, payload: "heavy" },
123
- { start: 0, end: 2, weight: 1, payload: "light" },
124
- ]);
125
- assert.deepEqual(cover.spans.map((s) => s.payload), ["light"]);
116
+ // Both single-span covers cover all 2 symbols; the lighter weight wins.
117
+ const cover = coverSequence(2, [
118
+ { start: 0, end: 2, weight: 5, payload: "heavy" },
119
+ { start: 0, end: 2, weight: 1, payload: "light" },
120
+ ]);
121
+ assert.deepEqual(cover.spans.map((s) => s.payload), ["light"]);
126
122
  });
@@ -1,9 +1,9 @@
1
1
  /** A half-open byte span of a query an extension computed, and the canonical
2
2
  * result bytes it is authoritative for. */
3
3
  export interface ComputedSpan {
4
- i: number;
5
- j: number;
6
- bytes: Uint8Array;
4
+ i: number;
5
+ j: number;
6
+ bytes: Uint8Array;
7
7
  }
8
8
  /** The generic capabilities the mind lends every extension — nothing here
9
9
  * names any particular extension, and every member is machinery the mind
@@ -24,17 +24,14 @@ export interface ComputedSpan {
24
24
  * • reach — the river's grouping capacity (maxGroup), bounding how far apart
25
25
  * two spans may sit and still be read as one construction. */
26
26
  export interface ExtensionHost {
27
- meaningOf(
28
- bytes: Uint8Array,
29
- anchors: ReadonlyArray<{
30
- name: string;
31
- form: Uint8Array;
32
- }>,
33
- ): Promise<string | null>;
34
- continuation(bytes: Uint8Array): Promise<Uint8Array | null>;
35
- segment(bytes: Uint8Array): Array<{
36
- i: number;
37
- j: number;
38
- }>;
39
- reach: number;
27
+ meaningOf(bytes: Uint8Array, anchors: ReadonlyArray<{
28
+ name: string;
29
+ form: Uint8Array;
30
+ }>): Promise<string | null>;
31
+ continuation(bytes: Uint8Array): Promise<Uint8Array | null>;
32
+ segment(bytes: Uint8Array): Array<{
33
+ i: number;
34
+ j: number;
35
+ }>;
36
+ reach: number;
40
37
  }
@@ -21,11 +21,7 @@ export declare function mergeThreshold(D: number): number;
21
21
  * fraction, the span's MAGNITUDE (√len, the linear fold's own norm) converts
22
22
  * the tolerated fraction into tolerated bytes. Derived from W, D and the
23
23
  * span; never tuned. */
24
- export declare function identityBar(
25
- D: number,
26
- maxGroup: number,
27
- len: number,
28
- ): number;
24
+ export declare function identityBar(D: number, maxGroup: number, len: number): number;
29
25
  /** The reach bar: half a river quantum, derived from the fold's own geometry.
30
26
  * A branch folds up to `maxGroup` children, so two forms that differ in ONE
31
27
  * whole child — the smallest distinction perception can mean — sit at cosine
@@ -95,30 +91,31 @@ export declare function consensusFloor(N: number): number;
95
91
  * structurally-isolated entries. Derived, never tuned. */
96
92
  export declare function coverageBar(_maxGroup: number, D: number): number;
97
93
  export interface Grid {
98
- width: number;
99
- height: number;
100
- channels: number;
101
- data: Uint8Array;
102
- dims?: number[];
94
+ width: number;
95
+ height: number;
96
+ channels: number;
97
+ data: Uint8Array;
98
+ dims?: number[];
103
99
  }
104
100
  /** Find the longest prefix of `bytes` whose leaf-id signature matches a
105
101
  * known branch via `lookup`. Returns the byte-length of that prefix, or 0. */
106
- export declare function knownPrefixLength(
107
- bytes: Uint8Array,
108
- leafAt: (i: number) => number | null,
109
- lookup: (leafIds: number[]) => number | null,
110
- ): number;
102
+ export declare function knownPrefixLength(bytes: Uint8Array, leafAt: (i: number) => number | null, lookup: (leafIds: number[]) => number | null): number;
111
103
  /** Bytes → Sema tree. `leafAt` and `lookup` are store capabilities for
112
104
  * detecting previously-stored prefixes so the river can split at the
113
105
  * correct boundary. Pass them through from `perceive`; the geometry
114
- * computes the stable prefix internally. */
115
- export declare function bytesToTree(
116
- space: Space,
117
- alphabet: Alphabet,
118
- bytes: Uint8Array,
119
- leafAt?: (i: number) => number | null,
120
- lookup?: (leafIds: number[]) => number | null,
121
- ): Sema;
106
+ * computes the stable prefix internally.
107
+ *
108
+ * `boundaries` is the CALLER-computed stable-prefix boundary set (§10.3):
109
+ * strictly-increasing proper byte offsets, each the length of a prefix that
110
+ * is already a stored whole-stream form. When given, the fold splits into
111
+ * the segments between consecutive boundaries each folded independently,
112
+ * exactly as it folded when it was learned — and the segment roots join
113
+ * LEFT-NESTED (((s₀·s₁)·s₂)…), so every learnt cumulative-context root
114
+ * reappears as an identical subtree (and, by hash-consing, the very same
115
+ * node) inside the grown stream. This is what lets a conversation's next
116
+ * turn extend perception instead of refolding it: identical prefixes
117
+ * produce identical subtrees regardless of what follows them. */
118
+ export declare function bytesToTree(space: Space, alphabet: Alphabet, bytes: Uint8Array, leafAt?: (i: number) => number | null, lookup?: (leafIds: number[]) => number | null, boundaries?: readonly number[]): Sema;
122
119
  /** The PLAIN fold's full level pyramid — every level's item list, bottom
123
120
  * (leaves) to top (root). Left-grouped folding is RADIX-ALIGNED: the item
124
121
  * at level L, index i, covers exactly bytes [i·mg^L, (i+1)·mg^L) whenever
@@ -132,31 +129,20 @@ export declare function bytesToTree(
132
129
  * never mutated). Purely an implementation cache: structure and numerics
133
130
  * never depend on whether a pyramid was available. */
134
131
  export interface FoldPyramid {
135
- levels: Array<
136
- Array<{
137
- tree: Sema;
138
- len: number;
139
- }>
140
- >;
141
- bytes: number;
132
+ levels: Array<Array<{
133
+ tree: Sema;
134
+ len: number;
135
+ }>>;
136
+ bytes: number;
142
137
  }
143
138
  /** Plain bytes→tree (identical to capability-less {@link bytesToTree}) that
144
139
  * also RETURNS its pyramid, reusing `prev` — the pyramid of a PROPER
145
140
  * prefix of `bytes` (caller guarantees content match and
146
141
  * prev.bytes < bytes.length). */
147
- export declare function bytesToTreePyramid(
148
- space: Space,
149
- alphabet: Alphabet,
150
- bytes: Uint8Array,
151
- prev?: FoldPyramid,
152
- ): {
153
- tree: Sema;
154
- pyramid: FoldPyramid;
142
+ export declare function bytesToTreePyramid(space: Space, alphabet: Alphabet, bytes: Uint8Array, prev?: FoldPyramid): {
143
+ tree: Sema;
144
+ pyramid: FoldPyramid;
155
145
  };
156
146
  export declare function hilbertBytes(grid: Grid): Uint8Array;
157
- export declare function gridToTree(
158
- space: Space,
159
- alphabet: Alphabet,
160
- grid: Grid,
161
- ): Sema;
147
+ export declare function gridToTree(space: Space, alphabet: Alphabet, grid: Grid): Sema;
162
148
  export declare function stackGrids(frames: Grid[]): Grid;