@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
@@ -12,36 +12,72 @@ import type { Input, MindContext } from "./types.js";
12
12
  * O(new nodes) per deposit instead of O(context). Only the hit node
13
13
  * itself enters `ids`; descendants stay reachable via the memo (see
14
14
  * idOf in indexSubSpans and the changedNodes prune). */
15
- export declare function internTreeIds(ctx: MindContext, node: Sema, ids: Map<Sema, number>): Promise<number>;
15
+ export declare function internTreeIds(
16
+ ctx: MindContext,
17
+ node: Sema,
18
+ ids: Map<Sema, number>,
19
+ ): Promise<number>;
16
20
  /** Index flat branches for sub-spans of a deposit's byte stream, linked to
17
21
  * their structural chunks via durable CONTAINMENT edges. */
18
- export declare function indexSubSpans(ctx: MindContext, tree: Sema, ids: Map<Sema, number>): Promise<boolean>;
22
+ export declare function indexSubSpans(
23
+ ctx: MindContext,
24
+ tree: Sema,
25
+ ids: Map<Sema, number>,
26
+ ): Promise<boolean>;
19
27
  /** Perceive, intern, and index a single input. Returns the perceived tree,
20
28
  * root id, id map, and the changed (new) subtrees for halo reinforcement. */
21
- export declare function deposit(ctx: MindContext, input: Input, track: boolean): Promise<{
22
- tree: Sema;
23
- rootId: number;
24
- ids: Map<Sema, number>;
25
- changed: Sema[];
29
+ export declare function deposit(
30
+ ctx: MindContext,
31
+ input: Input,
32
+ track: boolean,
33
+ ): Promise<{
34
+ tree: Sema;
35
+ rootId: number;
36
+ ids: Map<Sema, number>;
37
+ changed: Sema[];
26
38
  }>;
27
39
  /** Ingest a single input (a bare experience, no continuation). */
28
- export declare function ingestOne(ctx: MindContext, input: Input): Promise<Sema & {
40
+ export declare function ingestOne(
41
+ ctx: MindContext,
42
+ input: Input,
43
+ ): Promise<
44
+ Sema & {
29
45
  id: number;
30
- }>;
46
+ }
47
+ >;
31
48
  /** Ingest a pair (context, continuation) — learn an edge and pour halos. */
32
- export declare function ingestPair(ctx: MindContext, ctxInput: Input, cont: Input): Promise<void>;
49
+ export declare function ingestPair(
50
+ ctx: MindContext,
51
+ ctxInput: Input,
52
+ cont: Input,
53
+ ): Promise<void>;
33
54
  /** Dispatch the public ingest input shapes onto one-input / pair handlers —
34
55
  * THE one reading of ingest's polymorphic surface (scalar, (context,
35
56
  * continuation) pair, or a list mixing bare inputs and pairs). Both ingest
36
57
  * paths — the direct one below and {@link CachedIngest} — route through
37
58
  * this, so the shape-detection can never drift between them again (the
38
59
  * ingest cache once re-implemented it and drifted). */
39
- export declare function dispatchIngest(input: Input | (Input | [Input, Input])[], second: Input | undefined, onOne: (input: Input) => Promise<Sema & {
40
- id: number;
41
- }>, onPair: (ctxInput: Input, cont: Input) => Promise<void>): Promise<(Sema & {
60
+ export declare function dispatchIngest(
61
+ input: Input | (Input | [Input, Input])[],
62
+ second: Input | undefined,
63
+ onOne: (input: Input) => Promise<
64
+ Sema & {
65
+ id: number;
66
+ }
67
+ >,
68
+ onPair: (ctxInput: Input, cont: Input) => Promise<void>,
69
+ ): Promise<
70
+ (Sema & {
42
71
  id: number;
43
- }) | undefined>;
72
+ }) | undefined
73
+ >;
44
74
  /** Ingest an input or array of inputs/pairs. The public ingest entry point. */
45
- export declare function ingest(ctx: MindContext, input: Input | (Input | [Input, Input])[], second?: Input): Promise<(Sema & {
75
+ export declare function ingest(
76
+ ctx: MindContext,
77
+ input: Input | (Input | [Input, Input])[],
78
+ second?: Input,
79
+ ): Promise<
80
+ (Sema & {
46
81
  id: number;
47
- }) | undefined>;
82
+ }) | undefined
83
+ >;
@@ -20,152 +20,166 @@ import { fold as foldVecs } from "../sema.js";
20
20
  * itself enters `ids`; descendants stay reachable via the memo (see
21
21
  * idOf in indexSubSpans and the changedNodes prune). */
22
22
  export async function internTreeIds(ctx, node, ids) {
23
- const known = ctx._internIds.get(node);
24
- if (known !== undefined) {
25
- ids.set(node, known);
26
- return known;
23
+ const known = ctx._internIds.get(node);
24
+ if (known !== undefined) {
25
+ ids.set(node, known);
26
+ return known;
27
+ }
28
+ let id;
29
+ if (node.kids === null) {
30
+ id = await ctx.store.putLeaf(node.leaf ?? new Uint8Array(0), node.v);
31
+ } else {
32
+ const kds = [];
33
+ for (const k of node.kids) {
34
+ kds.push(await internTreeIds(ctx, k, ids));
27
35
  }
28
- let id;
29
- if (node.kids === null) {
30
- id = await ctx.store.putLeaf(node.leaf ?? new Uint8Array(0), node.v);
31
- }
32
- else {
33
- const kds = [];
34
- for (const k of node.kids)
35
- kds.push(await internTreeIds(ctx, k, ids));
36
- id = await ctx.store.putBranch(kds, node.v);
37
- }
38
- ids.set(node, id);
39
- ctx._internIds.set(node, id);
40
- return id;
36
+ id = await ctx.store.putBranch(kds, node.v);
37
+ }
38
+ ids.set(node, id);
39
+ ctx._internIds.set(node, id);
40
+ return id;
41
41
  }
42
42
  /** Index flat branches for sub-spans of a deposit's byte stream, linked to
43
43
  * their structural chunks via durable CONTAINMENT edges. */
44
44
  export async function indexSubSpans(ctx, tree, ids) {
45
- const chunkOf = [];
46
- const streamIds = [];
47
- const streamVecs = [];
48
- const collect = (n) => {
49
- if (isChunk(n)) {
50
- // A chunk inside a memo-skipped shared subtree is absent from `ids`;
51
- // the intern memo still knows it (same object). A miss on both (the
52
- // WeakMap entry was collected) only forfeits the seenBefore skip.
53
- const chunkId = ids.get(n) ?? ctx._internIds.get(n);
54
- for (const k of n.kids) {
55
- const lid = k.leaf ? ctx.store.findLeaf(k.leaf) : null;
56
- if (lid === null)
57
- return false;
58
- streamIds.push(lid);
59
- streamVecs.push(k.v);
60
- chunkOf.push(chunkId);
61
- }
62
- return true;
45
+ const chunkOf = [];
46
+ const streamIds = [];
47
+ const streamVecs = [];
48
+ const collect = (n) => {
49
+ if (isChunk(n)) {
50
+ // A chunk inside a memo-skipped shared subtree is absent from `ids`;
51
+ // the intern memo still knows it (same object). A miss on both (the
52
+ // WeakMap entry was collected) only forfeits the seenBefore skip.
53
+ const chunkId = ids.get(n) ?? ctx._internIds.get(n);
54
+ for (const k of n.kids) {
55
+ const lid = k.leaf ? ctx.store.findLeaf(k.leaf) : null;
56
+ if (lid === null) {
57
+ return false;
63
58
  }
64
- if (n.kids) {
65
- for (const k of n.kids)
66
- if (!collect(k))
67
- return false;
59
+ streamIds.push(lid);
60
+ streamVecs.push(k.v);
61
+ chunkOf.push(chunkId);
62
+ }
63
+ return true;
64
+ }
65
+ if (n.kids) {
66
+ for (const k of n.kids) {
67
+ if (!collect(k)) {
68
+ return false;
68
69
  }
69
- return true;
70
- };
71
- if (!collect(tree))
70
+ }
71
+ }
72
+ return true;
73
+ };
74
+ if (!collect(tree)) {
75
+ return false;
76
+ }
77
+ const W = ctx.space.maxGroup; // write side of the canonical contract
78
+ const prev = ctx._prevSeen;
79
+ const seenBefore = (off, len) => {
80
+ if (!prev) {
81
+ return false;
82
+ }
83
+ for (let i = off; i < off + len; i++) {
84
+ const c = chunkOf[i];
85
+ if (c === undefined || !prev.has(c)) {
72
86
  return false;
73
- const W = ctx.space.maxGroup; // write side of the canonical contract
74
- const prev = ctx._prevSeen;
75
- const seenBefore = (off, len) => {
76
- if (!prev)
77
- return false;
78
- for (let i = off; i < off + len; i++) {
79
- const c = chunkOf[i];
80
- if (c === undefined || !prev.has(c))
81
- return false;
82
- }
83
- return true;
84
- };
85
- const lens = streamIds.length >= W ? canonicalWindows(W) : [streamIds.length];
86
- for (const len of lens) {
87
- if (len < 1)
88
- continue;
89
- for (let off = 0; off + len <= streamIds.length; off++) {
90
- if (seenBefore(off, len))
91
- continue;
92
- const winIds = streamIds.slice(off, off + len);
93
- const flatId = ctx.store.findBranch(winIds) ??
94
- await ctx.store.putBranch(winIds, foldVecs(ctx.space, streamVecs.slice(off, off + len)));
95
- for (let i = off; i < off + len; i++) {
96
- const c = chunkOf[i];
97
- if (c !== undefined)
98
- ctx.store.addContainer(flatId, c);
99
- }
100
- }
87
+ }
101
88
  }
102
89
  return true;
90
+ };
91
+ const lens = streamIds.length >= W ? canonicalWindows(W) : [streamIds.length];
92
+ for (const len of lens) {
93
+ if (len < 1) {
94
+ continue;
95
+ }
96
+ for (let off = 0; off + len <= streamIds.length; off++) {
97
+ if (seenBefore(off, len)) {
98
+ continue;
99
+ }
100
+ const winIds = streamIds.slice(off, off + len);
101
+ const flatId = ctx.store.findBranch(winIds) ??
102
+ await ctx.store.putBranch(
103
+ winIds,
104
+ foldVecs(ctx.space, streamVecs.slice(off, off + len)),
105
+ );
106
+ for (let i = off; i < off + len; i++) {
107
+ const c = chunkOf[i];
108
+ if (c !== undefined) {
109
+ ctx.store.addContainer(flatId, c);
110
+ }
111
+ }
112
+ }
113
+ }
114
+ return true;
103
115
  }
104
116
  /** Perceive, intern, and index a single input. Returns the perceived tree,
105
117
  * root id, id map, and the changed (new) subtrees for halo reinforcement. */
106
118
  export async function deposit(ctx, input, track) {
107
- const bytes = inputBytes(ctx, input);
108
- // Deposit-shaped perception: stable-prefix tree SEEDING (see
109
- // perceiveDeposit) — an accumulated context re-folds only its new suffix,
110
- // O(turn) instead of O(context) per conversation turn. Cache-only here
111
- // (no store-probe fallback): a knownPrefixLength scan on every novel fact
112
- // would cost O(n²) hashing, while conversation replays are always warm —
113
- // re-deposition replays from the first turn, rebuilding the cache as it
114
- // goes.
115
- const tree = perceiveDeposit(ctx, bytes);
116
- const ids = new Map();
117
- const rootId = await internTreeIds(ctx, tree, ids);
118
- const indexed = await indexSubSpans(ctx, tree, ids);
119
- const leafIds = leafIdPrefix(ctx, bytes);
120
- if (leafIds.length === bytes.length && leafIds.length >= 2) {
121
- await ctx.store.putBranch(leafIds, tree.v);
122
- }
123
- const changed = (track && ctx._prevSeen)
124
- ? changedNodes(tree, ids, ctx._prevSeen)
125
- : [tree];
126
- if (track)
127
- ctx._prevSeen = indexed ? new Set(ids.values()) : null;
128
- return { tree, rootId, ids, changed };
119
+ const bytes = inputBytes(ctx, input);
120
+ // Deposit-shaped perception: stable-prefix tree SEEDING (see
121
+ // perceiveDeposit) — an accumulated context re-folds only its new suffix,
122
+ // O(turn) instead of O(context) per conversation turn. Cache-only here
123
+ // (no store-probe fallback): a knownPrefixLength scan on every novel fact
124
+ // would cost O(n²) hashing, while conversation replays are always warm —
125
+ // re-deposition replays from the first turn, rebuilding the cache as it
126
+ // goes.
127
+ const tree = perceiveDeposit(ctx, bytes);
128
+ const ids = new Map();
129
+ const rootId = await internTreeIds(ctx, tree, ids);
130
+ const indexed = await indexSubSpans(ctx, tree, ids);
131
+ const leafIds = leafIdPrefix(ctx, bytes);
132
+ if (leafIds.length === bytes.length && leafIds.length >= 2) {
133
+ await ctx.store.putBranch(leafIds, tree.v);
134
+ }
135
+ const changed = (track && ctx._prevSeen)
136
+ ? changedNodes(tree, ids, ctx._prevSeen)
137
+ : [tree];
138
+ if (track) {
139
+ ctx._prevSeen = indexed ? new Set(ids.values()) : null;
140
+ }
141
+ return { tree, rootId, ids, changed };
129
142
  }
130
143
  /** Ingest a single input (a bare experience, no continuation). */
131
144
  export async function ingestOne(ctx, input) {
132
- const { tree, rootId, ids } = await deposit(ctx, input, true);
133
- ctx.store.indexTarget(rootId);
134
- const parts = tree.kids
135
- ? tree.kids.map((k) => ids.get(k))
136
- : [rootId];
137
- const stride = ctx.space.maxGroup;
138
- if (parts.length > stride) {
139
- for (let i = 0; i + stride < parts.length; i += stride) {
140
- await ctx.store.link(parts[i], parts[i + stride]);
141
- }
142
- if ((parts.length - 1) % stride !== 0) {
143
- const lastStart = Math.floor((parts.length - 1) / stride) * stride;
144
- if (lastStart < parts.length - 1) {
145
- await ctx.store.link(parts[lastStart], parts[parts.length - 1]);
146
- }
147
- }
145
+ const { tree, rootId, ids } = await deposit(ctx, input, true);
146
+ ctx.store.indexTarget(rootId);
147
+ const parts = tree.kids ? tree.kids.map((k) => ids.get(k)) : [rootId];
148
+ const stride = ctx.space.maxGroup;
149
+ if (parts.length > stride) {
150
+ for (let i = 0; i + stride < parts.length; i += stride) {
151
+ await ctx.store.link(parts[i], parts[i + stride]);
152
+ }
153
+ if ((parts.length - 1) % stride !== 0) {
154
+ const lastStart = Math.floor((parts.length - 1) / stride) * stride;
155
+ if (lastStart < parts.length - 1) {
156
+ await ctx.store.link(parts[lastStart], parts[parts.length - 1]);
157
+ }
148
158
  }
149
- else {
150
- for (const id of parts)
151
- ctx.store.indexTarget(id);
159
+ } else {
160
+ for (const id of parts) {
161
+ ctx.store.indexTarget(id);
152
162
  }
153
- return Object.assign(tree, { id: rootId });
163
+ }
164
+ return Object.assign(tree, { id: rootId });
154
165
  }
155
166
  /** Ingest a pair (context, continuation) — learn an edge and pour halos. */
156
167
  export async function ingestPair(ctx, ctxInput, cont) {
157
- const c = await deposit(ctx, ctxInput, true);
158
- const cont_ = await deposit(ctx, cont, false);
159
- const ctxId = c.rootId, contId = cont_.rootId;
160
- await ctx.store.link(ctxId, contId);
161
- // Halos pour company SIGNATURES (identity), not gists (content) — see
162
- // companySignature in sema.ts.
163
- const contSeat = bindSeat(ctx.space, companySignature(ctx.space, contId), 1);
164
- for (const part of c.changed) {
165
- const partId = c.ids.get(part);
166
- await ctx.store.pourHalo(partId, contSeat);
167
- await ctx.store.pourHalo(contId, bindSeat(ctx.space, companySignature(ctx.space, partId), 0));
168
- }
168
+ const c = await deposit(ctx, ctxInput, true);
169
+ const cont_ = await deposit(ctx, cont, false);
170
+ const ctxId = c.rootId, contId = cont_.rootId;
171
+ await ctx.store.link(ctxId, contId);
172
+ // Halos pour company SIGNATURES (identity), not gists (content) — see
173
+ // companySignature in sema.ts.
174
+ const contSeat = bindSeat(ctx.space, companySignature(ctx.space, contId), 1);
175
+ for (const part of c.changed) {
176
+ const partId = c.ids.get(part);
177
+ await ctx.store.pourHalo(partId, contSeat);
178
+ await ctx.store.pourHalo(
179
+ contId,
180
+ bindSeat(ctx.space, companySignature(ctx.space, partId), 0),
181
+ );
182
+ }
169
183
  }
170
184
  /** Dispatch the public ingest input shapes onto one-input / pair handlers —
171
185
  * THE one reading of ingest's polymorphic surface (scalar, (context,
@@ -174,28 +188,36 @@ export async function ingestPair(ctx, ctxInput, cont) {
174
188
  * this, so the shape-detection can never drift between them again (the
175
189
  * ingest cache once re-implemented it and drifted). */
176
190
  export async function dispatchIngest(input, second, onOne, onPair) {
177
- if (Array.isArray(input) && !(input instanceof Uint8Array) &&
178
- input.width === undefined) {
179
- const arr = input;
180
- if (arr.length === 2 && !Array.isArray(arr[0]) && !Array.isArray(arr[1])) {
181
- await onPair(arr[0], arr[1]);
182
- return undefined;
183
- }
184
- for (const item of arr) {
185
- if (Array.isArray(item) && item.length === 2) {
186
- await onPair(item[0], item[1]);
187
- }
188
- else
189
- await onOne(item);
190
- }
191
- return undefined;
191
+ if (
192
+ Array.isArray(input) && !(input instanceof Uint8Array) &&
193
+ input.width === undefined
194
+ ) {
195
+ const arr = input;
196
+ if (arr.length === 2 && !Array.isArray(arr[0]) && !Array.isArray(arr[1])) {
197
+ await onPair(arr[0], arr[1]);
198
+ return undefined;
199
+ }
200
+ for (const item of arr) {
201
+ if (Array.isArray(item) && item.length === 2) {
202
+ await onPair(item[0], item[1]);
203
+ } else {
204
+ await onOne(item);
205
+ }
192
206
  }
193
- if (second === undefined)
194
- return onOne(input);
195
- await onPair(input, second);
196
207
  return undefined;
208
+ }
209
+ if (second === undefined) {
210
+ return onOne(input);
211
+ }
212
+ await onPair(input, second);
213
+ return undefined;
197
214
  }
198
215
  /** Ingest an input or array of inputs/pairs. The public ingest entry point. */
199
216
  export async function ingest(ctx, input, second) {
200
- return dispatchIngest(input, second, (i) => ingestOne(ctx, i), (a, b) => ingestPair(ctx, a, b));
217
+ return dispatchIngest(
218
+ input,
219
+ second,
220
+ (i) => ingestOne(ctx, i),
221
+ (a, b) => ingestPair(ctx, a, b),
222
+ );
201
223
  }
@@ -14,17 +14,27 @@ import type { Site } from "./graph-search.js";
14
14
  * (gate: identityBar — scale-aware).
15
15
  *
16
16
  * Returns the absolute byte position, or −1. */
17
- export declare function locate(ctx: MindContext, haystack: Uint8Array, needle: Uint8Array, fromPos: number, sites?: ReadonlyArray<Site>): number;
17
+ export declare function locate(
18
+ ctx: MindContext,
19
+ haystack: Uint8Array,
20
+ needle: Uint8Array,
21
+ fromPos: number,
22
+ sites?: ReadonlyArray<Site>,
23
+ ): number;
18
24
  /** The ALIGNED matcher: maximal literal matching runs between `query` and
19
25
  * `ct` (a learned context's bytes), by seed-and-extend over
20
26
  * `space.maxGroup`-sized n-gram seeds. Where locate() finds ONE position of
21
27
  * a short frame, this finds EVERY run two whole structures share — the
22
28
  * matcher CAST detects a woven query with. Returns non-overlapping runs
23
29
  * sorted by query position. */
24
- export declare function alignRuns(ctx: MindContext, query: Uint8Array, ct: Uint8Array): Array<{
25
- qs: number;
26
- qe: number;
27
- cs: number;
30
+ export declare function alignRuns(
31
+ ctx: MindContext,
32
+ query: Uint8Array,
33
+ ct: Uint8Array,
34
+ ): Array<{
35
+ qs: number;
36
+ qe: number;
37
+ cs: number;
28
38
  }>;
29
39
  /** A run from {@link alignGraded} — the ALIGNED matcher extended with the
30
40
  * same graded-evidence ladder as {@link locate}. Literal runs carry
@@ -34,10 +44,10 @@ export declare function alignRuns(ctx: MindContext, query: Uint8Array, ct: Uint8
34
44
  * kind, so the substitution/redirection schemas work unchanged on conceptual
35
45
  * alignment. */
36
46
  export interface GradedRun {
37
- qs: number;
38
- qe: number;
39
- cs: number;
40
- weight: number;
47
+ qs: number;
48
+ qe: number;
49
+ cs: number;
50
+ weight: number;
41
51
  }
42
52
  /** The GRADED alignment matcher: extends literal W-gram alignment
43
53
  * ({@link alignRuns}) with halo-matched recognised sites in query regions
@@ -49,23 +59,42 @@ export interface GradedRun {
49
59
  * `querySites` are the pre-computed recognition sites for the query
50
60
  * (optional — when absent, only literal alignment fires and graded degrades
51
61
  * to the original behaviour). Context sites are recognised internally. */
52
- export declare function alignGraded(ctx: MindContext, query: Uint8Array, contextBytes: Uint8Array, querySites?: ReadonlyArray<Site>): GradedRun[];
62
+ export declare function alignGraded(
63
+ ctx: MindContext,
64
+ query: Uint8Array,
65
+ contextBytes: Uint8Array,
66
+ querySites?: ReadonlyArray<Site>,
67
+ ): GradedRun[];
53
68
  /** The IN-LIST halo matcher: the best halo-mate for `halo` among EXPLICIT
54
69
  * candidates, above the concept threshold — the list counterpart of
55
70
  * {@link haloSiblings}, which asks the halo INDEX for candidates instead.
56
71
  * Behind locate()'s halo step and articulation's voice matching; a third
57
72
  * "best halo among these" decision must come here, not inline. */
58
- export declare function bestHaloMate<T>(ctx: MindContext, halo: Vec, items: Iterable<T>, haloOf: (item: T) => Vec | null | undefined): {
59
- item: T;
60
- score: number;
73
+ export declare function bestHaloMate<T>(
74
+ ctx: MindContext,
75
+ halo: Vec,
76
+ items: Iterable<T>,
77
+ haloOf: (item: T) => Vec | null | undefined,
78
+ ): {
79
+ item: T;
80
+ score: number;
61
81
  } | null;
62
- export declare function haloSiblings(ctx: MindContext, id: number, halo?: Vec | null, bar?: number): Promise<Hit[]>;
82
+ export declare function haloSiblings(
83
+ ctx: MindContext,
84
+ id: number,
85
+ halo?: Vec | null,
86
+ bar?: number,
87
+ ): Promise<Hit[]>;
63
88
  /** The DISTRIBUTIONAL matcher between two nodes: mutual-nearest-neighbour
64
89
  * strength, not a pick. Returns the direct halo cosine, or failing that the
65
90
  * highest mutual-halo-sibling min-score (second-order analogy), or failing
66
91
  * that the SHARED-FRAME strength (below) — the gate CAST's comparison
67
92
  * schema validates genuine analogs with (bar: significanceBar). */
68
- export declare function analogyStrength(ctx: MindContext, a: number, b: number): Promise<number>;
93
+ export declare function analogyStrength(
94
+ ctx: MindContext,
95
+ a: number,
96
+ b: number,
97
+ ): Promise<number>;
69
98
  /** The STRUCTURAL analogy tier: two nodes are analogs when their byte
70
99
  * streams share a LEARNT frame — a content-addressed flat form of at least
71
100
  * one full river window (W bytes, the perception quantum) that occurs in
@@ -78,17 +107,28 @@ export declare function analogyStrength(ctx: MindContext, a: number, b: number):
78
107
  * a fraction, comparable to the cosine tiers above. Derived: the window
79
108
  * is maxGroup, the same quantum differsByOneWindow and canonicalChunkId
80
109
  * measure by; no tuned constants. */
81
- export declare function sharedFrameStrength(ctx: MindContext, a: number, b: number): number;
110
+ export declare function sharedFrameStrength(
111
+ ctx: MindContext,
112
+ a: number,
113
+ b: number,
114
+ ): number;
82
115
  /** FORWARD through a synonym: the continuation an edge-less node borrows from
83
116
  * a concept (halo) sibling — resonate the node's halo, take the first
84
117
  * sibling above the concept threshold that itself has a direct edge. */
85
- export declare function conceptHop(ctx: MindContext, id: number): Promise<number | null>;
118
+ export declare function conceptHop(
119
+ ctx: MindContext,
120
+ id: number,
121
+ ): Promise<number | null>;
86
122
  /** FORWARD projection: follow continuation edges from a node to its fixpoint.
87
123
  * The first hop may cross a concept (halo) link — a synonym. The rest
88
124
  * follow direct edges. Convergence is intrinsic: the seen set guards
89
125
  * against cycles. `guide` disambiguates multi-continuation nodes by
90
126
  * resonance. */
91
- export declare function follow(ctx: MindContext, id: number, guide?: Vec | null): Promise<Uint8Array | null>;
127
+ export declare function follow(
128
+ ctx: MindContext,
129
+ id: number,
130
+ guide?: Vec | null,
131
+ ): Promise<Uint8Array | null>;
92
132
  /** REVERSE projection: the context a learnt continuation follows, voiced as
93
133
  * bytes. A common continuation ("Yes.") follows MANY contexts; with a
94
134
  * `guide` the context whose gist resonates with the query wins (seat
@@ -103,9 +143,18 @@ export declare function follow(ctx: MindContext, id: number, guide?: Vec | null)
103
143
  * context reads empty (a zero-length context is no grounding: an empty
104
144
  * Uint8Array is truthy, and returning it would flow a hollow "answer"
105
145
  * onward). */
106
- export declare function reverseContext(ctx: MindContext, id: number, guide?: Vec | null, rev?: readonly number[]): Uint8Array | null;
146
+ export declare function reverseContext(
147
+ ctx: MindContext,
148
+ id: number,
149
+ guide?: Vec | null,
150
+ rev?: readonly number[],
151
+ ): Uint8Array | null;
107
152
  /** THE projection: ground a matched node to answer bytes — FORWARD to its
108
153
  * continuation fixpoint (which may cross a concept hop), else REVERSE to
109
154
  * the context it follows. This is the direction ladder every mechanism's
110
155
  * final grounding step reduces to. */
111
- export declare function project(ctx: MindContext, id: number, guide?: Vec | null): Promise<Uint8Array | null>;
156
+ export declare function project(
157
+ ctx: MindContext,
158
+ id: number,
159
+ guide?: Vec | null,
160
+ ): Promise<Uint8Array | null>;