@hviana/sema 0.1.3 → 0.1.5

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 (123) hide show
  1. package/dist/example/demo.js +25 -25
  2. package/dist/example/train_base.d.ts +21 -19
  3. package/dist/example/train_base.js +1952 -1684
  4. package/dist/src/alphabet.d.ts +3 -3
  5. package/dist/src/alphabet.js +27 -24
  6. package/dist/src/alu/src/alu.d.ts +194 -169
  7. package/dist/src/alu/src/alu.js +414 -374
  8. package/dist/src/alu/src/expr.d.ts +43 -36
  9. package/dist/src/alu/src/expr.js +278 -252
  10. package/dist/src/alu/src/index.d.ts +98 -9
  11. package/dist/src/alu/src/index.js +63 -9
  12. package/dist/src/alu/src/kernel-arith.d.ts +5 -1
  13. package/dist/src/alu/src/kernel-arith.js +285 -195
  14. package/dist/src/alu/src/kernel-bits.d.ts +5 -1
  15. package/dist/src/alu/src/kernel-bits.js +115 -81
  16. package/dist/src/alu/src/kernel-logic.js +63 -33
  17. package/dist/src/alu/src/kernel-nd.js +195 -155
  18. package/dist/src/alu/src/kernel-numeric.d.ts +80 -16
  19. package/dist/src/alu/src/kernel-numeric.js +331 -259
  20. package/dist/src/alu/src/operation.d.ts +132 -112
  21. package/dist/src/alu/src/operation.js +163 -149
  22. package/dist/src/alu/src/parser.d.ts +175 -168
  23. package/dist/src/alu/src/parser.js +421 -382
  24. package/dist/src/alu/src/resonance.d.ts +25 -16
  25. package/dist/src/alu/src/resonance.js +56 -49
  26. package/dist/src/alu/src/text.d.ts +7 -3
  27. package/dist/src/alu/src/text.js +37 -31
  28. package/dist/src/alu/src/value.d.ts +14 -14
  29. package/dist/src/alu/src/value.js +160 -150
  30. package/dist/src/alu/test/alu.test.js +656 -543
  31. package/dist/src/bytes.d.ts +5 -1
  32. package/dist/src/bytes.js +40 -33
  33. package/dist/src/config.d.ts +102 -102
  34. package/dist/src/config.js +83 -83
  35. package/dist/src/derive/src/deduction.d.ts +62 -60
  36. package/dist/src/derive/src/deduction.js +109 -103
  37. package/dist/src/derive/src/index.d.ts +7 -1
  38. package/dist/src/derive/src/priority-queue.d.ts +8 -8
  39. package/dist/src/derive/src/priority-queue.js +61 -57
  40. package/dist/src/derive/src/rewrite.d.ts +18 -15
  41. package/dist/src/derive/src/rewrite.js +67 -59
  42. package/dist/src/derive/src/trie.d.ts +56 -56
  43. package/dist/src/derive/src/trie.js +179 -175
  44. package/dist/src/derive/test/derive.test.js +100 -96
  45. package/dist/src/extension.d.ts +16 -13
  46. package/dist/src/geometry.d.ts +42 -17
  47. package/dist/src/geometry.js +266 -235
  48. package/dist/src/index.d.ts +17 -2
  49. package/dist/src/index.js +7 -1
  50. package/dist/src/ingest-cache.d.ts +30 -25
  51. package/dist/src/ingest-cache.js +127 -108
  52. package/dist/src/mind/articulation.d.ts +5 -1
  53. package/dist/src/mind/articulation.js +112 -77
  54. package/dist/src/mind/attention.d.ts +108 -40
  55. package/dist/src/mind/attention.js +871 -749
  56. package/dist/src/mind/canonical.d.ts +19 -4
  57. package/dist/src/mind/canonical.js +31 -27
  58. package/dist/src/mind/graph-search.d.ts +225 -201
  59. package/dist/src/mind/graph-search.js +821 -742
  60. package/dist/src/mind/index.d.ts +10 -2
  61. package/dist/src/mind/junction.d.ts +58 -31
  62. package/dist/src/mind/junction.js +237 -172
  63. package/dist/src/mind/learning.d.ts +52 -16
  64. package/dist/src/mind/learning.js +165 -143
  65. package/dist/src/mind/match.d.ts +69 -20
  66. package/dist/src/mind/match.js +318 -259
  67. package/dist/src/mind/mechanisms/alu.js +16 -16
  68. package/dist/src/mind/mechanisms/cast.d.ts +13 -9
  69. package/dist/src/mind/mechanisms/cast.js +456 -363
  70. package/dist/src/mind/mechanisms/confluence.d.ts +12 -8
  71. package/dist/src/mind/mechanisms/confluence.js +183 -152
  72. package/dist/src/mind/mechanisms/cover.d.ts +8 -2
  73. package/dist/src/mind/mechanisms/cover.js +210 -148
  74. package/dist/src/mind/mechanisms/extraction.d.ts +34 -8
  75. package/dist/src/mind/mechanisms/extraction.js +288 -234
  76. package/dist/src/mind/mechanisms/recall.d.ts +10 -6
  77. package/dist/src/mind/mechanisms/recall.js +185 -126
  78. package/dist/src/mind/mind.d.ts +154 -129
  79. package/dist/src/mind/mind.js +288 -258
  80. package/dist/src/mind/pipeline-mechanism.d.ts +124 -112
  81. package/dist/src/mind/pipeline-mechanism.js +172 -161
  82. package/dist/src/mind/pipeline.d.ts +14 -4
  83. package/dist/src/mind/pipeline.js +189 -125
  84. package/dist/src/mind/primitives.d.ts +32 -8
  85. package/dist/src/mind/primitives.js +117 -99
  86. package/dist/src/mind/rationale.d.ts +98 -86
  87. package/dist/src/mind/rationale.js +121 -113
  88. package/dist/src/mind/reasoning.d.ts +13 -2
  89. package/dist/src/mind/reasoning.js +166 -129
  90. package/dist/src/mind/recognition.d.ts +4 -1
  91. package/dist/src/mind/recognition.js +208 -183
  92. package/dist/src/mind/resonance.d.ts +22 -5
  93. package/dist/src/mind/resonance.js +0 -0
  94. package/dist/src/mind/trace.d.ts +25 -6
  95. package/dist/src/mind/trace.js +58 -50
  96. package/dist/src/mind/traverse.d.ts +58 -16
  97. package/dist/src/mind/traverse.js +357 -304
  98. package/dist/src/mind/types.d.ts +127 -120
  99. package/dist/src/mind/types.js +69 -60
  100. package/dist/src/rabitq-hnsw/src/database.d.ts +179 -177
  101. package/dist/src/rabitq-hnsw/src/database.js +359 -342
  102. package/dist/src/rabitq-hnsw/src/heap.d.ts +12 -12
  103. package/dist/src/rabitq-hnsw/src/heap.js +80 -75
  104. package/dist/src/rabitq-hnsw/src/hnsw.d.ts +103 -103
  105. package/dist/src/rabitq-hnsw/src/hnsw.js +454 -428
  106. package/dist/src/rabitq-hnsw/src/index.d.ts +6 -1
  107. package/dist/src/rabitq-hnsw/src/prng.d.ts +10 -10
  108. package/dist/src/rabitq-hnsw/src/prng.js +27 -25
  109. package/dist/src/rabitq-hnsw/src/rabitq.d.ts +69 -69
  110. package/dist/src/rabitq-hnsw/src/rabitq.js +262 -246
  111. package/dist/src/rabitq-hnsw/src/store.d.ts +132 -132
  112. package/dist/src/rabitq-hnsw/src/store.js +843 -752
  113. package/dist/src/rabitq-hnsw/test/hnsw.test.js +1054 -805
  114. package/dist/src/sema.d.ts +35 -0
  115. package/dist/src/sema.js +77 -0
  116. package/dist/src/store-sqlite.d.ts +166 -144
  117. package/dist/src/store-sqlite.js +660 -578
  118. package/dist/src/store.d.ts +630 -593
  119. package/dist/src/store.js +1581 -1440
  120. package/dist/src/vec.d.ts +9 -5
  121. package/dist/src/vec.js +73 -61
  122. package/package.json +2 -2
  123. package/src/sema.ts +102 -0
@@ -3,10 +3,16 @@ import { type PipelineMechanism } from "./pipeline-mechanism.js";
3
3
  export { resolveConcepts, resolveConnectors } from "./mechanisms/cover.js";
4
4
  export { aluToMechanism } from "./mechanisms/alu.js";
5
5
  export declare const defaultMechanisms: PipelineMechanism[];
6
- export type Provenance = "cast" | "join" | "cover" | "extract" | "recall" | "recall-echo";
6
+ export type Provenance =
7
+ | "cast"
8
+ | "join"
9
+ | "cover"
10
+ | "extract"
11
+ | "recall"
12
+ | "recall-echo";
7
13
  export interface Thought {
8
- bytes: Uint8Array;
9
- provenance: Provenance;
14
+ bytes: Uint8Array;
15
+ provenance: Provenance;
10
16
  }
11
17
  /** Think: a single lightest-derivation exploration of the Sema graph.
12
18
  *
@@ -17,4 +23,8 @@ export interface Thought {
17
23
  * cost ladder; the lightest grounding derivation wins.
18
24
  * 3. Post-grounding — diagnostics (narrowDecision, thinGrounding),
19
25
  * reasoning (multi-hop), fusion (multi-topic). */
20
- export declare function think(ctx: MindContext, query: Uint8Array, mechs?: readonly PipelineMechanism[]): Promise<Thought | null>;
26
+ export declare function think(
27
+ ctx: MindContext,
28
+ query: Uint8Array,
29
+ mechs?: readonly PipelineMechanism[],
30
+ ): Promise<Thought | null>;
@@ -26,12 +26,13 @@ export { resolveConcepts, resolveConnectors } from "./mechanisms/cover.js";
26
26
  export { aluToMechanism } from "./mechanisms/alu.js";
27
27
  // ── Extension dispatch (pre-loop parse) ─────────────────────────────────────
28
28
  async function collectComputed(mechanisms, query) {
29
- const out = [];
30
- for (const m of mechanisms) {
31
- if (m.parse)
32
- out.push(...await m.parse(query));
29
+ const out = [];
30
+ for (const m of mechanisms) {
31
+ if (m.parse) {
32
+ out.push(...await m.parse(query));
33
33
  }
34
- return out;
34
+ }
35
+ return out;
35
36
  }
36
37
  // ── Built-in mechanisms ─────────────────────────────────────────────────────
37
38
  // ORDER MATTERS, but only through the uniform floor/worthRunning pruning —
@@ -45,11 +46,11 @@ async function collectComputed(mechanisms, query) {
45
46
  // order is also the tie-break priority: cover, cast, confluence, extraction,
46
47
  // recall.
47
48
  export const defaultMechanisms = [
48
- coverMechanism,
49
- castMechanism,
50
- confluenceMechanism,
51
- extractionMechanism,
52
- recallMechanism,
49
+ coverMechanism,
50
+ castMechanism,
51
+ confluenceMechanism,
52
+ extractionMechanism,
53
+ recallMechanism,
53
54
  ];
54
55
  /** Think: a single lightest-derivation exploration of the Sema graph.
55
56
  *
@@ -61,125 +62,188 @@ export const defaultMechanisms = [
61
62
  * 3. Post-grounding — diagnostics (narrowDecision, thinGrounding),
62
63
  * reasoning (multi-hop), fusion (multi-topic). */
63
64
  export async function think(ctx, query, mechs) {
64
- if (query.length === 0)
65
- return null;
66
- ctx._edgeGuide = gistOf(ctx, query);
67
- ctx._edgeChoice.clear();
68
- const t = ctx.trace?.enter("think", [rItem(query, "query")]);
69
- const done = (answer, note) => {
70
- t?.done(answer
71
- ? [rItem(answer, "answer", resolve(ctx, answer) ?? undefined)]
72
- : [], note);
73
- return answer;
74
- };
75
- // ── Pre-computation ──────────────────────────────────────────────────
76
- const mechanisms = mechs ?? defaultMechanisms;
77
- const rec = recognise(ctx, query);
78
- // Phase 1: collect computed spans from mechanisms that implement parse()
79
- const computed = await collectComputed(mechanisms, query);
80
- if (computed.length > 0) {
81
- ctx.trace?.step("computeExtensions", [rItem(query, "query")], computed.map((u) => rItem(query.subarray(u.i, u.j), "operand", undefined, [u.i, u.j])), `extensions recognised and evaluated ${computed.length} computation(s)`);
82
- for (const u of computed) {
83
- ctx.trace?.step("evalComputation", [rItem(query.subarray(u.i, u.j), "expression", undefined, [u.i, u.j])], [rItem(u.bytes, "result", resolve(ctx, u.bytes) ?? undefined)], "evaluate the recognised operation to its authoritative result");
84
- }
65
+ if (query.length === 0) {
66
+ return null;
67
+ }
68
+ ctx._edgeGuide = gistOf(ctx, query);
69
+ ctx._edgeChoice.clear();
70
+ const t = ctx.trace?.enter("think", [rItem(query, "query")]);
71
+ const done = (answer, note) => {
72
+ t?.done(
73
+ answer
74
+ ? [rItem(answer, "answer", resolve(ctx, answer) ?? undefined)]
75
+ : [],
76
+ note,
77
+ );
78
+ return answer;
79
+ };
80
+ // ── Pre-computation ──────────────────────────────────────────────────
81
+ const mechanisms = mechs ?? defaultMechanisms;
82
+ const rec = recognise(ctx, query);
83
+ // Phase 1: collect computed spans from mechanisms that implement parse()
84
+ const computed = await collectComputed(mechanisms, query);
85
+ if (computed.length > 0) {
86
+ ctx.trace?.step(
87
+ "computeExtensions",
88
+ [rItem(query, "query")],
89
+ computed.map((u) =>
90
+ rItem(query.subarray(u.i, u.j), "operand", undefined, [u.i, u.j])
91
+ ),
92
+ `extensions recognised and evaluated ${computed.length} computation(s)`,
93
+ );
94
+ for (const u of computed) {
95
+ ctx.trace?.step(
96
+ "evalComputation",
97
+ [rItem(query.subarray(u.i, u.j), "expression", undefined, [u.i, u.j])],
98
+ [rItem(u.bytes, "result", resolve(ctx, u.bytes) ?? undefined)],
99
+ "evaluate the recognised operation to its authoritative result",
100
+ );
85
101
  }
86
- // Phase 2: the shared pre-computation container. Eager fields only
87
- // (recognition, computed spans, guide) every expensive analysis
88
- // (consensus climb, weave, span-shape classification) is a lazily-cached
89
- // method on Precomputed, first-touched by whichever mechanism's floor
90
- // survives its cheap gates and the worthRunning check. A query no
91
- // mechanism climbs for (e.g. one an extension decided) never climbs.
92
- const pre = new Precomputed(ctx, query, rec, computed, ctx._edgeGuide);
93
- const grade = (w) => Math.floor(w / STEP);
94
- const unaccounted = (spans) => unexplainedSpans(query.length, spans)
95
- .reduce((sum, [s, e]) => sum + (e - s), 0);
96
- const weigh = (accounted, moves) => moves + PASS * unaccounted(accounted);
97
- const candidates = [];
98
- let best = null;
99
- const consider = (c) => {
100
- if (c.bytes.length === 0)
101
- return;
102
- candidates.push(c);
103
- if (best === null || grade(c.weight) < grade(best.weight))
104
- best = c;
105
- };
106
- const worthRunning = (floor) => best === null || grade(floor) < grade(best.weight);
107
- // Phase 3: grounding loop
108
- for (const mech of mechanisms) {
109
- const floor = await mech.floor(ctx, query, pre, worthRunning);
110
- if (floor === null) {
111
- ctx.trace?.step("skipMechanism", [], [], `${mech.name} skipped — structural precondition failed`);
112
- continue;
113
- }
114
- if (!worthRunning(floor)) {
115
- ctx.trace?.step("skipMechanism", [], [], `${mech.name} skipped — floor ${floor} cannot beat incumbent (grade ${grade(best.weight)})`);
116
- continue;
117
- }
118
- const results = await mech.run(ctx, query, pre);
119
- for (const r of results) {
120
- const weight = r.weight ?? weigh(r.accounted, r.moves);
121
- consider({
122
- bytes: r.bytes,
123
- provenance: r.provenance ?? mech.provenance,
124
- weight,
125
- used: r.used,
126
- accounted: r.accounted,
127
- unexplained: r.unexplained,
128
- });
129
- }
102
+ }
103
+ // Phase 2: the shared pre-computation container. Eager fields only
104
+ // (recognition, computed spans, guide) every expensive analysis
105
+ // (consensus climb, weave, span-shape classification) is a lazily-cached
106
+ // method on Precomputed, first-touched by whichever mechanism's floor
107
+ // survives its cheap gates and the worthRunning check. A query no
108
+ // mechanism climbs for (e.g. one an extension decided) never climbs.
109
+ const pre = new Precomputed(ctx, query, rec, computed, ctx._edgeGuide);
110
+ const grade = (w) => Math.floor(w / STEP);
111
+ const unaccounted = (spans) =>
112
+ unexplainedSpans(query.length, spans)
113
+ .reduce((sum, [s, e]) => sum + (e - s), 0);
114
+ const weigh = (accounted, moves) => moves + PASS * unaccounted(accounted);
115
+ const candidates = [];
116
+ let best = null;
117
+ const consider = (c) => {
118
+ if (c.bytes.length === 0) {
119
+ return;
130
120
  }
131
- // (TS cannot see the closure assignments into `best` and narrows it to its
132
- // initial null, so the read-back needs the assertion.)
133
- const decided = best;
134
- if (candidates.length > 1) {
135
- ctx.trace?.step("decideGrounding", candidates.map((c) => rItem(c.bytes, `${c.provenance} (weight ${c.weight.toFixed(3)}${c.unexplained ? `, unexplained: "${c.unexplained}"` : ""})`)), decided ? [rItem(decided.bytes, decided.provenance)] : [], "the lightest grounding derivation wins — every mechanism weighed in the one cost ladder");
136
- if (decided !== null) {
137
- let runnerUp = null;
138
- for (const c of candidates) {
139
- if (c === decided)
140
- continue;
141
- if (runnerUp === null || grade(c.weight) < grade(runnerUp.weight)) {
142
- runnerUp = c;
143
- }
144
- }
145
- if (runnerUp !== null) {
146
- const margin = grade(runnerUp.weight) - grade(decided.weight);
147
- if (margin <= 1) {
148
- ctx.trace?.step("narrowDecision", [
149
- rItem(decided.bytes, `${decided.provenance} (weight ${decided.weight.toFixed(3)})`),
150
- ], [
151
- rItem(runnerUp.bytes, `${runnerUp.provenance} (weight ${runnerUp.weight.toFixed(3)})`),
152
- ], `margin ${margin} grade-unit(s) — the decision could change with one more training fact`);
153
- }
154
- }
155
- }
121
+ candidates.push(c);
122
+ if (best === null || grade(c.weight) < grade(best.weight)) {
123
+ best = c;
156
124
  }
157
- if (decided === null) {
158
- done(null, "no mechanism grounded an answer");
159
- return null;
125
+ };
126
+ const worthRunning = (floor) =>
127
+ best === null || grade(floor) < grade(best.weight);
128
+ // Phase 3: grounding loop
129
+ for (const mech of mechanisms) {
130
+ const floor = await mech.floor(ctx, query, pre, worthRunning);
131
+ if (floor === null) {
132
+ ctx.trace?.step(
133
+ "skipMechanism",
134
+ [],
135
+ [],
136
+ `${mech.name} skipped — structural precondition failed`,
137
+ );
138
+ continue;
160
139
  }
161
- // Honesty density
162
- {
163
- const covered = query.length - unaccounted(decided.accounted);
164
- const density = query.length > 0 ? covered / query.length : 1;
165
- const thinBar = 1 / ctx.space.maxGroup;
166
- if (density < thinBar) {
167
- ctx.trace?.step("thinGrounding", [rItem(decided.bytes, decided.provenance)], [], `grounded but thin — density ${density.toFixed(3)} is below 1/W (${thinBar.toFixed(3)})`);
140
+ if (!worthRunning(floor)) {
141
+ ctx.trace?.step(
142
+ "skipMechanism",
143
+ [],
144
+ [],
145
+ `${mech.name} skipped floor ${floor} cannot beat incumbent (grade ${
146
+ grade(best.weight)
147
+ })`,
148
+ );
149
+ continue;
150
+ }
151
+ const results = await mech.run(ctx, query, pre);
152
+ for (const r of results) {
153
+ const weight = r.weight ?? weigh(r.accounted, r.moves);
154
+ consider({
155
+ bytes: r.bytes,
156
+ provenance: r.provenance ?? mech.provenance,
157
+ weight,
158
+ used: r.used,
159
+ accounted: r.accounted,
160
+ unexplained: r.unexplained,
161
+ });
162
+ }
163
+ }
164
+ // (TS cannot see the closure assignments into `best` and narrows it to its
165
+ // initial null, so the read-back needs the assertion.)
166
+ const decided = best;
167
+ if (candidates.length > 1) {
168
+ ctx.trace?.step(
169
+ "decideGrounding",
170
+ candidates.map((c) =>
171
+ rItem(
172
+ c.bytes,
173
+ `${c.provenance} (weight ${c.weight.toFixed(3)}${
174
+ c.unexplained ? `, unexplained: "${c.unexplained}"` : ""
175
+ })`,
176
+ )
177
+ ),
178
+ decided ? [rItem(decided.bytes, decided.provenance)] : [],
179
+ "the lightest grounding derivation wins — every mechanism weighed in the one cost ladder",
180
+ );
181
+ if (decided !== null) {
182
+ let runnerUp = null;
183
+ for (const c of candidates) {
184
+ if (c === decided) {
185
+ continue;
186
+ }
187
+ if (runnerUp === null || grade(c.weight) < grade(runnerUp.weight)) {
188
+ runnerUp = c;
168
189
  }
190
+ }
191
+ if (runnerUp !== null) {
192
+ const margin = grade(runnerUp.weight) - grade(decided.weight);
193
+ if (margin <= 1) {
194
+ ctx.trace?.step(
195
+ "narrowDecision",
196
+ [
197
+ rItem(
198
+ decided.bytes,
199
+ `${decided.provenance} (weight ${decided.weight.toFixed(3)})`,
200
+ ),
201
+ ],
202
+ [
203
+ rItem(
204
+ runnerUp.bytes,
205
+ `${runnerUp.provenance} (weight ${runnerUp.weight.toFixed(3)})`,
206
+ ),
207
+ ],
208
+ `margin ${margin} grade-unit(s) — the decision could change with one more training fact`,
209
+ );
210
+ }
211
+ }
212
+ }
213
+ }
214
+ if (decided === null) {
215
+ done(null, "no mechanism grounded an answer");
216
+ return null;
217
+ }
218
+ // Honesty density
219
+ {
220
+ const covered = query.length - unaccounted(decided.accounted);
221
+ const density = query.length > 0 ? covered / query.length : 1;
222
+ const thinBar = 1 / ctx.space.maxGroup;
223
+ if (density < thinBar) {
224
+ ctx.trace?.step(
225
+ "thinGrounding",
226
+ [rItem(decided.bytes, decided.provenance)],
227
+ [],
228
+ `grounded but thin — density ${density.toFixed(3)} is below 1/W (${
229
+ thinBar.toFixed(3)
230
+ })`,
231
+ );
169
232
  }
170
- const answer = decided.bytes;
171
- const provenance = decided.provenance;
172
- const castUsed = decided.used ?? new Set();
173
- // ── Post-grounding, gated by provenance ──────────────────────────────
174
- const preConsumed = provenance === "cast" || provenance === "join"
175
- ? castUsed
176
- : provenance === "recall" || provenance === "recall-echo"
177
- ? new Set()
178
- : new Set(recognise(ctx, answer).sites.map((s) => s.payload));
179
- const reasoned = await reason(ctx, query, answer, preConsumed, pre);
180
- const fused = provenance === "recall" || provenance === "recall-echo"
181
- ? await fuseAttention(ctx, query, reasoned, pre)
182
- : reasoned;
183
- done(fused, "grounded, reasoned forward, fused across points of attention");
184
- return { bytes: fused, provenance };
233
+ }
234
+ const answer = decided.bytes;
235
+ const provenance = decided.provenance;
236
+ const castUsed = decided.used ?? new Set();
237
+ // ── Post-grounding, gated by provenance ──────────────────────────────
238
+ const preConsumed = provenance === "cast" || provenance === "join"
239
+ ? castUsed
240
+ : provenance === "recall" || provenance === "recall-echo"
241
+ ? new Set()
242
+ : new Set(recognise(ctx, answer).sites.map((s) => s.payload));
243
+ const reasoned = await reason(ctx, query, answer, preConsumed, pre);
244
+ const fused = provenance === "recall" || provenance === "recall-echo"
245
+ ? await fuseAttention(ctx, query, reasoned, pre)
246
+ : reasoned;
247
+ done(fused, "grounded, reasoned forward, fused across points of attention");
248
+ return { bytes: fused, provenance };
185
249
  }
@@ -3,7 +3,12 @@ import { Sema } from "../sema.js";
3
3
  import type { Input, MindContext } from "./types.js";
4
4
  /** Perceive input into a content-defined tree (the river fold).
5
5
  * Deterministic — identical bytes always produce an identical tree. */
6
- export declare function perceive(ctx: MindContext, input: Input, leafAt?: (i: number) => number | null, lookup?: (ids: number[]) => number | null): Sema;
6
+ export declare function perceive(
7
+ ctx: MindContext,
8
+ input: Input,
9
+ leafAt?: (i: number) => number | null,
10
+ lookup?: (ids: number[]) => number | null,
11
+ ): Sema;
7
12
  /** The DEPOSIT-shaped perceive: the PLAIN fold (bit-identical to inference
8
13
  * perception — that structural train/inference agreement is load-bearing
9
14
  * for exact recall), computed INCREMENTALLY via the fold's level pyramid
@@ -12,7 +17,10 @@ export declare function perceive(ctx: MindContext, input: Input, leafAt?: (i: nu
12
17
  * (ctx._depositTrees), and this deposit refolds only the right edge of
13
18
  * each level — O(turn) instead of O(context) per turn. Purely a cache:
14
19
  * the produced tree never depends on cache state. */
15
- export declare function perceiveDeposit(ctx: MindContext, bytes: Uint8Array): Sema;
20
+ export declare function perceiveDeposit(
21
+ ctx: MindContext,
22
+ bytes: Uint8Array,
23
+ ): Sema;
16
24
  /** The raw bytes of an input — modality-neutral conversion. */
17
25
  export declare function inputBytes(ctx: MindContext, input: Input): Uint8Array;
18
26
  /** Convenience: the gist vector of a byte span. */
@@ -22,14 +30,22 @@ export declare function gistOf(ctx: MindContext, bytes: Uint8Array): Vec;
22
30
  * ids (null the moment any child is unknown). `visit`, when given, sees each
23
31
  * node with its byte span and resolved id. Returns the node's byte end and
24
32
  * resolved id. */
25
- export declare function foldTree(ctx: MindContext, n: Sema, start: number, visit?: (n: Sema, start: number, end: number, node: number | null) => void): {
26
- end: number;
27
- node: number | null;
33
+ export declare function foldTree(
34
+ ctx: MindContext,
35
+ n: Sema,
36
+ start: number,
37
+ visit?: (n: Sema, start: number, end: number, node: number | null) => void,
38
+ ): {
39
+ end: number;
40
+ node: number | null;
28
41
  };
29
42
  /** The canonical node id of a byte span: perceive it in isolation — the way
30
43
  * training did — and recover its root bottom-up. Returns null if any part is
31
44
  * unknown. */
32
- export declare function resolve(ctx: MindContext, bytes: Uint8Array): number | null;
45
+ export declare function resolve(
46
+ ctx: MindContext,
47
+ bytes: Uint8Array,
48
+ ): number | null;
33
49
  /** Walk a perceived tree in POST-ORDER with byte offsets — children before
34
50
  * their parent, `visit(node, start, end)` for every node including leaves.
35
51
  * Returns the byte end. The one shared traversal the offset-carrying tree
@@ -38,6 +54,14 @@ export declare function resolve(ctx: MindContext, bytes: Uint8Array): number | n
38
54
  * re-derive the offset bookkeeping. (recognition.segment keeps its own
39
55
  * walk: its flush semantics need PRE-order decisions at leaf-parents, which
40
56
  * a post-order visitor cannot express.) */
41
- export declare function walkTree(n: Sema, start: number, visit: (node: Sema, start: number, end: number) => void): number;
57
+ export declare function walkTree(
58
+ n: Sema,
59
+ start: number,
60
+ visit: (node: Sema, start: number, end: number) => void,
61
+ ): number;
42
62
  /** Reconstruct a node's byte content from the DAG, up to `maxLen` bytes. */
43
- export declare function read(ctx: MindContext, id: number, maxLen?: number): Uint8Array;
63
+ export declare function read(
64
+ ctx: MindContext,
65
+ id: number,
66
+ maxLen?: number,
67
+ ): Uint8Array;