@hviana/sema 0.4.0 → 0.4.2

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 (154) hide show
  1. package/CONTRIBUTING.md +92 -10
  2. package/LICENSE.md +2 -2
  3. package/package.json +1 -1
  4. package/src/ingest-cache.ts +4 -0
  5. package/src/meter.ts +5 -0
  6. package/src/mind/attention.ts +18 -1
  7. package/src/mind/bridge.ts +292 -54
  8. package/src/mind/junction.ts +21 -7
  9. package/src/mind/match.ts +92 -1
  10. package/src/mind/mechanisms/cast.ts +12 -0
  11. package/src/mind/mechanisms/confluence.ts +30 -1
  12. package/src/mind/mechanisms/cover.ts +36 -4
  13. package/src/mind/mechanisms/recall.ts +21 -44
  14. package/src/mind/mind.ts +39 -2
  15. package/src/mind/pipeline-mechanism.ts +86 -4
  16. package/src/mind/pipeline.ts +1 -1
  17. package/src/mind/reasoning.ts +15 -8
  18. package/src/mind/recognition.ts +40 -0
  19. package/src/mind/resonance.ts +0 -0
  20. package/src/mind/traverse.ts +17 -15
  21. package/src/mind/types.ts +10 -0
  22. package/test/49-natural-units-synonym-bridge.test.mjs +56 -15
  23. package/dist/example/demo.d.ts +0 -1
  24. package/dist/example/demo.js +0 -39
  25. package/dist/example/train_base.d.ts +0 -87
  26. package/dist/example/train_base.js +0 -2252
  27. package/dist/src/alphabet.d.ts +0 -7
  28. package/dist/src/alphabet.js +0 -33
  29. package/dist/src/alu/src/alu.d.ts +0 -185
  30. package/dist/src/alu/src/alu.js +0 -440
  31. package/dist/src/alu/src/expr.d.ts +0 -61
  32. package/dist/src/alu/src/expr.js +0 -318
  33. package/dist/src/alu/src/index.d.ts +0 -11
  34. package/dist/src/alu/src/index.js +0 -19
  35. package/dist/src/alu/src/kernel-arith.d.ts +0 -16
  36. package/dist/src/alu/src/kernel-arith.js +0 -264
  37. package/dist/src/alu/src/kernel-bits.d.ts +0 -19
  38. package/dist/src/alu/src/kernel-bits.js +0 -152
  39. package/dist/src/alu/src/kernel-logic.d.ts +0 -4
  40. package/dist/src/alu/src/kernel-logic.js +0 -60
  41. package/dist/src/alu/src/kernel-nd.d.ts +0 -3
  42. package/dist/src/alu/src/kernel-nd.js +0 -208
  43. package/dist/src/alu/src/kernel-numeric.d.ts +0 -54
  44. package/dist/src/alu/src/kernel-numeric.js +0 -366
  45. package/dist/src/alu/src/operation.d.ts +0 -168
  46. package/dist/src/alu/src/operation.js +0 -189
  47. package/dist/src/alu/src/parser.d.ts +0 -221
  48. package/dist/src/alu/src/parser.js +0 -577
  49. package/dist/src/alu/src/resonance.d.ts +0 -55
  50. package/dist/src/alu/src/resonance.js +0 -126
  51. package/dist/src/alu/src/text.d.ts +0 -31
  52. package/dist/src/alu/src/text.js +0 -73
  53. package/dist/src/alu/src/value.d.ts +0 -109
  54. package/dist/src/alu/src/value.js +0 -300
  55. package/dist/src/alu/test/alu.test.d.ts +0 -1
  56. package/dist/src/alu/test/alu.test.js +0 -764
  57. package/dist/src/bytes.d.ts +0 -14
  58. package/dist/src/bytes.js +0 -59
  59. package/dist/src/canon.d.ts +0 -26
  60. package/dist/src/canon.js +0 -57
  61. package/dist/src/config.d.ts +0 -111
  62. package/dist/src/config.js +0 -91
  63. package/dist/src/derive/src/deduction.d.ts +0 -136
  64. package/dist/src/derive/src/deduction.js +0 -159
  65. package/dist/src/derive/src/index.d.ts +0 -8
  66. package/dist/src/derive/src/index.js +0 -11
  67. package/dist/src/derive/src/priority-queue.d.ts +0 -20
  68. package/dist/src/derive/src/priority-queue.js +0 -73
  69. package/dist/src/derive/src/rewrite.d.ts +0 -56
  70. package/dist/src/derive/src/rewrite.js +0 -100
  71. package/dist/src/derive/src/trie.d.ts +0 -90
  72. package/dist/src/derive/src/trie.js +0 -217
  73. package/dist/src/derive/test/derive.test.d.ts +0 -1
  74. package/dist/src/derive/test/derive.test.js +0 -122
  75. package/dist/src/extension.d.ts +0 -37
  76. package/dist/src/extension.js +0 -7
  77. package/dist/src/geometry.d.ts +0 -175
  78. package/dist/src/geometry.js +0 -823
  79. package/dist/src/index.d.ts +0 -17
  80. package/dist/src/index.js +0 -19
  81. package/dist/src/ingest-cache.d.ts +0 -41
  82. package/dist/src/ingest-cache.js +0 -161
  83. package/dist/src/meter.d.ts +0 -171
  84. package/dist/src/meter.js +0 -269
  85. package/dist/src/mind/articulation.d.ts +0 -6
  86. package/dist/src/mind/articulation.js +0 -99
  87. package/dist/src/mind/attention.d.ts +0 -414
  88. package/dist/src/mind/attention.js +0 -2065
  89. package/dist/src/mind/bridge.d.ts +0 -39
  90. package/dist/src/mind/bridge.js +0 -738
  91. package/dist/src/mind/canonical.d.ts +0 -34
  92. package/dist/src/mind/canonical.js +0 -93
  93. package/dist/src/mind/graph-search.d.ts +0 -294
  94. package/dist/src/mind/graph-search.js +0 -996
  95. package/dist/src/mind/index.d.ts +0 -9
  96. package/dist/src/mind/index.js +0 -5
  97. package/dist/src/mind/junction.d.ts +0 -134
  98. package/dist/src/mind/junction.js +0 -331
  99. package/dist/src/mind/learning.d.ts +0 -75
  100. package/dist/src/mind/learning.js +0 -270
  101. package/dist/src/mind/match.d.ts +0 -166
  102. package/dist/src/mind/match.js +0 -565
  103. package/dist/src/mind/mechanisms/alu.d.ts +0 -4
  104. package/dist/src/mind/mechanisms/alu.js +0 -36
  105. package/dist/src/mind/mechanisms/cast.d.ts +0 -89
  106. package/dist/src/mind/mechanisms/cast.js +0 -773
  107. package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
  108. package/dist/src/mind/mechanisms/confluence.js +0 -225
  109. package/dist/src/mind/mechanisms/cover.d.ts +0 -6
  110. package/dist/src/mind/mechanisms/cover.js +0 -203
  111. package/dist/src/mind/mechanisms/extraction.d.ts +0 -33
  112. package/dist/src/mind/mechanisms/extraction.js +0 -300
  113. package/dist/src/mind/mechanisms/recall.d.ts +0 -16
  114. package/dist/src/mind/mechanisms/recall.js +0 -388
  115. package/dist/src/mind/mind.d.ts +0 -330
  116. package/dist/src/mind/mind.js +0 -594
  117. package/dist/src/mind/pipeline-mechanism.d.ts +0 -172
  118. package/dist/src/mind/pipeline-mechanism.js +0 -382
  119. package/dist/src/mind/pipeline.d.ts +0 -49
  120. package/dist/src/mind/pipeline.js +0 -275
  121. package/dist/src/mind/primitives.d.ts +0 -66
  122. package/dist/src/mind/primitives.js +0 -306
  123. package/dist/src/mind/rationale.d.ts +0 -139
  124. package/dist/src/mind/rationale.js +0 -163
  125. package/dist/src/mind/reasoning.d.ts +0 -40
  126. package/dist/src/mind/reasoning.js +0 -272
  127. package/dist/src/mind/recognition.d.ts +0 -20
  128. package/dist/src/mind/recognition.js +0 -463
  129. package/dist/src/mind/resonance.d.ts +0 -23
  130. package/dist/src/mind/resonance.js +0 -0
  131. package/dist/src/mind/trace.d.ts +0 -15
  132. package/dist/src/mind/trace.js +0 -73
  133. package/dist/src/mind/traverse.d.ts +0 -124
  134. package/dist/src/mind/traverse.js +0 -649
  135. package/dist/src/mind/types.d.ts +0 -323
  136. package/dist/src/mind/types.js +0 -130
  137. package/dist/src/rabitq-ivf/src/database.d.ts +0 -113
  138. package/dist/src/rabitq-ivf/src/database.js +0 -201
  139. package/dist/src/rabitq-ivf/src/index.d.ts +0 -7
  140. package/dist/src/rabitq-ivf/src/index.js +0 -4
  141. package/dist/src/rabitq-ivf/src/ivf.d.ts +0 -200
  142. package/dist/src/rabitq-ivf/src/ivf.js +0 -1165
  143. package/dist/src/rabitq-ivf/src/prng.d.ts +0 -19
  144. package/dist/src/rabitq-ivf/src/prng.js +0 -36
  145. package/dist/src/rabitq-ivf/src/rabitq.d.ts +0 -95
  146. package/dist/src/rabitq-ivf/src/rabitq.js +0 -283
  147. package/dist/src/sema.d.ts +0 -31
  148. package/dist/src/sema.js +0 -63
  149. package/dist/src/store-sqlite.d.ts +0 -184
  150. package/dist/src/store-sqlite.js +0 -942
  151. package/dist/src/store.d.ts +0 -678
  152. package/dist/src/store.js +0 -1703
  153. package/dist/src/vec.d.ts +0 -31
  154. package/dist/src/vec.js +0 -109
@@ -1,330 +0,0 @@
1
- import { Vec } from "../vec.js";
2
- import { Sema, Space } from "../sema.js";
3
- import { Alphabet } from "../alphabet.js";
4
- import { Grid } from "../geometry.js";
5
- import { BoundedMap, type Store } from "../store.js";
6
- import { type MindConfig } from "../config.js";
7
- import { type Canon } from "../canon.js";
8
- import { GraphSearch, type Leaf, type Site } from "./graph-search.js";
9
- import type { ComputedSpan, ExtensionHost } from "../extension.js";
10
- export type { ComputedSpan, ExtensionHost };
11
- import { type InspectRationale, Rationale } from "./rationale.js";
12
- export type { InspectRationale, RationaleItem, RationaleStep, } from "./rationale.js";
13
- export type Input = string | Uint8Array | Grid | Grid[];
14
- export interface Response {
15
- v: Vec | null;
16
- bytes: Uint8Array;
17
- /** How the answer was grounded (see {@link Provenance}). `"recall-echo"`
18
- * marks the last-resort fallback that returned the nearest stored form's
19
- * own bytes verbatim — an echo, NOT a grounded fact. Absent when there is
20
- * no answer. */
21
- provenance?: import("./pipeline.js").Provenance;
22
- }
23
- /** Serializable state of a conversation — can be saved and restored across
24
- * sessions. The Mind never interprets the bytes; it only tracks their
25
- * cumulative lengths so the caller can reconstruct turn boundaries later
26
- * without inspecting content. */
27
- export interface ConversationState {
28
- /** The accumulated context bytes — raw concatenation of every turn's
29
- * bytes in order. No separator is inserted; the boundary offsets
30
- * ({@link boundaries}) tell the caller where each turn ends. */
31
- context: Uint8Array;
32
- /** Cumulative byte length after each completed turn. Sorted, strictly
33
- * increasing, each {@code < context.length}. The first turn's length
34
- * is `boundaries[0]`; the second turn starts at that offset, and so
35
- * on. Empty for a single-turn or new conversation. */
36
- boundaries: number[];
37
- }
38
- /** An active conversation handle. Opaque — interact through the Mind's
39
- * conversation methods ({@link Mind.beginConversation},
40
- * {@link Mind.respondTurn}, {@link Mind.endConversation}). */
41
- export interface Conversation {
42
- readonly id: number;
43
- }
44
- import type { AttentionRead, MindContext, Recognition } from "./types.js";
45
- export type { AnchorRejectionReason, ClimbConsensusData, ConsensusAnchorTrace, ConsensusReachTrace, ConsensusRegionTrace, CrossRegionTier, JunctionVoteTrace, RegionOutcome, } from "./attention.js";
46
- export type { AncestorReach, SaturationReason, SaturationStop, } from "./types.js";
47
- import { type CostReport, Meter } from "../meter.js";
48
- export interface MindOptions {
49
- seed?: number;
50
- recallQueryK?: number;
51
- haloQueryK?: number;
52
- normalizeEpsilon?: number;
53
- cosineEpsilon?: number;
54
- geometry?: Partial<import("../config.js").GeometryConfig>;
55
- alphabet?: Partial<import("../config.js").AlphabetConfig>;
56
- storeConfig?: Partial<import("../config.js").StoreConfig>;
57
- store?: Store;
58
- /** Additional grounding mechanisms (appended after the built-in defaults). */
59
- mechanisms?: import("./pipeline-mechanism.js").PipelineMechanism[];
60
- /** Factories that receive the {@link ExtensionHost} and return mechanisms. */
61
- mechanismFactories?: ((host: import("../extension.js").ExtensionHost) => import("./pipeline-mechanism.js").PipelineMechanism)[];
62
- /** Measure the computational usage of every inference call — see
63
- * src/meter.ts. Off by default and free when off (one null check per
64
- * store read); on, each `respond`/`respondTurn` leaves a {@link
65
- * Mind.lastCost} report behind. Counters are deterministic, so two runs
66
- * of the same query on the same store are diffable; the millisecond
67
- * fields are not. Profiling NEVER changes an answer — but note that
68
- * attaching a RATIONALE does (traced responses bypass the ctx memos,
69
- * AGENTS §2.11), so profile without a trace. */
70
- profile?: boolean;
71
- /** Content canonicalizer applied to EVERY response (any modality) for
72
- * equivalence-class resolution — see src/canon.ts. Text entry points
73
- * ({@link Mind.respondText}, {@link Mind.respondTurnText}) inject the
74
- * Unicode text canonicalizer automatically when this is unset; pass
75
- * `false` to disable canonical resolution everywhere. */
76
- canon?: Canon | false;
77
- }
78
- export declare class Mind implements MindContext {
79
- readonly space: Space;
80
- readonly alphabet: Alphabet;
81
- readonly store: Store;
82
- readonly cfg: MindConfig;
83
- /** The lightest-derivation engine over the Sema graph. */
84
- readonly search: GraphSearch;
85
- /** The grounding mechanisms iterated by {@link think}. */
86
- readonly mechanisms: import("./pipeline-mechanism.js").PipelineMechanism[];
87
- /** The live rationale tracer for the inference currently in flight, or null. */
88
- trace: Rationale | null;
89
- /** The content canonicalizer for the response in flight — see
90
- * {@link MindContext.canon}. Injected per response by the modality entry
91
- * point; null when the response carries no equivalence. */
92
- canon: Canon | null;
93
- /** Per-response canonical-resolution memo — see {@link MindContext.canonMemo}. */
94
- canonMemo: Map<string, number | null> | null;
95
- /** The Mind-level canon option: a canonicalizer to use for EVERY response,
96
- * `false` to disable canonical resolution, or null to let each entry
97
- * point decide (text entry points inject {@link textCanon}). */
98
- private _canonOpt;
99
- /** The work accumulator for the inference call in flight — see
100
- * {@link MindContext.meter}. Non-null only between beginResponse and
101
- * endResponse, and only when the Mind was constructed with
102
- * `{ profile: true }`. */
103
- meter: Meter | null;
104
- /** Whether {@link MindOptions.profile} was set. */
105
- private _profile;
106
- /** The computational-usage report of the LAST completed inference call, or
107
- * null when profiling is off (or nothing has been asked yet). Overwritten
108
- * by every `respond`/`respondTurn`; copy it if you are aggregating. See
109
- * {@link import("../meter.js").CostReport} and `sumReports`/`formatReport`
110
- * for battery-level aggregation. */
111
- lastCost: CostReport | null;
112
- /** Memo of the consensus climb — content-keyed. See {@link MindContext.climbMemo}. */
113
- climbMemo: Map<string, Map<string, AttentionRead>> | null;
114
- /** Memo of recognise() — content-keyed. See {@link MindContext.recogniseMemo}. */
115
- recogniseMemo: Map<string, Recognition> | null;
116
- /** Memo of perceive() — content-keyed. See {@link MindContext.perceiveMemo}. */
117
- perceiveMemo: Map<string, import("../sema.js").Sema> | null;
118
- /** Subtree-resolution cache. See {@link MindContext._resolvedSubtrees}. */
119
- _resolvedSubtrees: WeakMap<import("../sema.js").Sema, {
120
- id: number;
121
- len: number;
122
- }> | null;
123
- /** The perceived gist of the query currently being answered. Set by `think`
124
- * before the graph search runs; `chooseNext` consults it as a gate (a null
125
- * guide means no query is in flight, so structural walkers keep plain
126
- * first-edge behaviour) and the reverse projection uses it for
127
- * reverse-recall disambiguation via `chooseAmong`. */
128
- _edgeGuide: Vec | null;
129
- /** Per-response memo of {@link chooseNext} picks — ensures every mechanism
130
- * of a single response follows the SAME continuation for each ambiguous
131
- * context node. */
132
- _edgeChoice: Map<number, number>;
133
- /** Previous deposit's seen node ids for incremental change detection. */
134
- _prevSeen: Set<number> | null;
135
- /** Session cache of node-id → perceived gist for candidate scoring — see
136
- * {@link MindContext._gistCache}. 32 MB ≈ 8K gists at D=1024; hub
137
- * candidate sets (√N at most) fit comfortably and recur across queries. */
138
- _gistCache: BoundedMap<number, Vec>;
139
- _depositTrees: BoundedMap<string, import("./types.js").DepositCacheEntry>;
140
- _depositLens: Set<number>;
141
- _internIds: WeakMap<Sema, number>;
142
- private _nextConvId;
143
- private _conversations;
144
- /** Canonical node id of a byte span. Required by GraphSearchHost & MindContext. */
145
- resolve(bytes: Uint8Array): number | null;
146
- recogniseSpan(bytes: Uint8Array): {
147
- sites: ReadonlyArray<Site>;
148
- leaves: ReadonlyArray<Leaf>;
149
- splits: ReadonlySet<number>;
150
- starts: ReadonlySet<number>;
151
- };
152
- /** Disambiguate among multiple learnt continuations of the same context node.
153
- * Required by {@link GraphSearchHost} — the graph search calls this through the
154
- * host interface when a recognised form has more than one outgoing edge.
155
- * Delegates to the standalone {@link chooseNext} which picks the candidate
156
- * with the most distributional evidence (highest `prevOf` count — the
157
- * structural manifestation of its halo). When evidence is equal the
158
- * first-inserted edge wins. */
159
- chooseNext(node: number): number | undefined;
160
- constructor(opts?: MindOptions);
161
- constructor(cfg: MindConfig, store: Store, _fromStore: true);
162
- /** Exposed for tests: the consensus climb over query sub-regions. */
163
- climbAttention(query: Uint8Array, k: number, mode?: import("./types.js").DFMode): Promise<import("./types.js").Attention[]>;
164
- /** Exposed for tests: climb the structural DAG from a node to its
165
- * edge-bearing ancestor contexts. */
166
- edgeAncestors(id: number, contextCount: number): import("./types.js").AncestorReach;
167
- /** Exposed for tests: find the natural break point in a sorted vote list. */
168
- naturalBreak(votes: number[]): number;
169
- /** Perceive input into a content-defined tree. Deterministic — identical
170
- * bytes always produce an identical tree. Public for ingest-cache. */
171
- perceive(input: Input, leafAt?: (i: number) => number | null, lookup?: (ids: number[]) => number | null): Sema;
172
- /** Open one response's transient state — the tracer, the per-response
173
- * memos, the work meter. The ONE place this state is created, and it
174
- * serves BOTH entry points: `respond` takes fresh per-response memos,
175
- * `respondTurn` passes its conversation, whose memos persist across turns
176
- * (content-keyed, so the previous turn's results are found by this turn's
177
- * sub-span calls) and whose `resolvedSubtrees` makes foldTree O(suffix)
178
- * instead of O(context). respondTurn used to inline its own copy of this
179
- * and of {@link endResponse}; the two drifted (a memo added to one was
180
- * silently absent from the other), so there is exactly one pair now. */
181
- private beginResponse;
182
- /** Open (or leave closed) the response's work accumulator. Separate from
183
- * {@link beginResponse} because {@link respondTurn} keeps its own
184
- * conversation-scoped lifecycle and must not create fresh per-response
185
- * memos — but it DOES meter, through this same pair. */
186
- private _beginMeter;
187
- /** Close the accumulator and publish its report. Detaching from the store
188
- * matters: a Mind that shares a store with another Mind must not keep
189
- * charging that store's reads to a finished response. */
190
- private _endMeter;
191
- /** The canonicalizer a response should carry: the Mind-level option when
192
- * set (or none when explicitly disabled), else the entry point's own
193
- * default — text entry points pass {@link textCanon}, binary ones null. */
194
- private _canonFor;
195
- /** Close one response's transient state — every per-response field, incl.
196
- * the edge guide/choices `think` sets mid-flight, and the meter's report.
197
- *
198
- * A conversation's memo MAPS were mutated in place, so `data.*` still
199
- * points at them and there is nothing to save back. Clearing the Mind's
200
- * references is what matters: a concurrently-started `respond()` swaps its
201
- * own fresh maps into these pointers, and copying back from them here
202
- * would inject a foreign response's memos into the conversation. */
203
- private endResponse;
204
- /** Shared response core — the one path from bytes to voiced answer.
205
- * `respond` calls this directly; `respondTurn` has its own path
206
- * with conversation-persistent memos and incremental perception. */
207
- private _respondImpl;
208
- /** The ONE path from query bytes to a voiced answer: ground (think), then
209
- * re-voice in the asker's words (articulate). Both entry points run
210
- * exactly this — they differ only in the LIFECYCLE around it (fresh
211
- * per-response memos vs. a conversation's persistent ones) and in what
212
- * they do with the answer afterwards. It must be called between
213
- * {@link beginResponse} and {@link endResponse}. */
214
- private _groundAndVoice;
215
- respond(input: Input, inspectRationale?: InspectRationale): Promise<Response>;
216
- /** Text view of {@link respond}. NUL bytes (0x00) are stripped before
217
- * decoding — they are structural padding in text answers. LOSSY for a
218
- * binary answer that legitimately contains NULs: use {@link respond} and
219
- * read `bytes` directly for binary/grid modalities.
220
- *
221
- * Injects the TEXT canonicalizer (src/canon.ts) so resolution treats
222
- * every character variation of the same text — case, width, whitespace —
223
- * as one form, provided the store's canon index is built
224
- * ({@link buildCanonIndex}). */
225
- respondText(input: string, inspectRationale?: InspectRationale): Promise<string>;
226
- /** Begin a new conversation, optionally restoring from a previously-saved
227
- * {@link ConversationState}. The returned handle is required for
228
- * {@link respondTurn} and {@link endConversation}.
229
- *
230
- * Conversations are independent — a Mind can manage several concurrently.
231
- * Each tracks the fold pyramid (accumulated internal processing) and
232
- * turn-boundary offsets; the geometry never inspects content to guess
233
- * where one turn ends and the next begins. */
234
- beginConversation(state?: ConversationState): Conversation;
235
- /** End a conversation, releasing its internal resources (accumulated
236
- * context, boundary offsets, and the fold-pyramid cache). Idempotent. */
237
- endConversation(conv: Conversation): void;
238
- /** The current serialisable state of an active conversation. Save this
239
- * to resume the conversation later via {@link beginConversation}. */
240
- conversationState(conv: Conversation): ConversationState | null;
241
- /** Append a turn to a conversation's accumulated context WITHOUT
242
- * responding — raw byte append plus a boundary offset, never a
243
- * separator; the fold pyramid advances by O(turn).
244
- *
245
- * This is the primitive for turns the Mind should hear but not answer:
246
- * replaying a transcript, feeding the OTHER speaker's line in a
247
- * prediction harness, or restoring context piecewise. {@link
248
- * respondTurn} = addTurn + think + its own reply appended the same way. */
249
- addTurn(conv: Conversation, turn: Input): ConversationState;
250
- /** Grow a conversation's accumulated context by one turn's bytes — raw
251
- * append plus a boundary offset, pyramid advanced by O(turn), the grown
252
- * context's tree seeded into the conversation's perceive memo. The ONE
253
- * place a context grows ({@link addTurn} and {@link respondTurn} both
254
- * come through here), so the append semantics cannot drift. */
255
- private _growContext;
256
- /** Process one turn of a conversation.
257
- *
258
- * `turn` is the raw input for the latest turn — its bytes are appended
259
- * to the accumulated context directly (raw concatenation). The Mind
260
- * tracks the byte offset where each turn ends; no separator is ever
261
- * inserted or inspected.
262
- *
263
- * Returns the response AND the updated {@link ConversationState} so the
264
- * caller can persist it. The conversation handle's internal state is
265
- * updated in place — the returned state is a snapshot for storage.
266
- *
267
- * SINGLE FLIGHT: at most one respondTurn may be in flight per Mind. The
268
- * conversation's memo caches are swapped into the Mind-level per-response
269
- * pointers for the duration of the turn, so a concurrently-running
270
- * respond()/respondTurn() on the SAME Mind would interleave state.
271
- * Different Minds (or sequential awaits, as in every test) are safe. */
272
- respondTurn(conv: Conversation, turn: Input, inspectRationale?: InspectRationale): Promise<{
273
- response: Response;
274
- state: ConversationState;
275
- }>;
276
- /** Text view of {@link respondTurn}. See {@link respondText} for the
277
- * NUL-stripping caveat. For binary or grid turns use {@link respondTurn}
278
- * directly — this is a text-only convenience, like {@link respondText}. */
279
- respondTurnText(conv: Conversation, turn: string, inspectRationale?: InspectRationale): Promise<{
280
- response: string;
281
- state: ConversationState;
282
- }>;
283
- embedding(input: Input): Promise<Vec | null>;
284
- /** Kinship note: the vector arm below is a miniature of recall's tier 3
285
- * (resonate → reach gate → read out the nearest form's bytes) — the
286
- * read-out direction of the same operation, without recall's grounding
287
- * ladder. If either side's acceptance rule changes, revisit the other. */
288
- express(idOrV: number | Vec): Promise<Uint8Array>;
289
- /** See {@link import("./learning.js").ingest} — `onDeposit`, when given,
290
- * reports each ingested item's deposited root node ids
291
- * ({@link DepositReport}); purely observational. */
292
- ingest(input: Input | (Input | [Input, Input])[], second?: Input, onDeposit?: (report: import("./learning.js").DepositReport) => void): Promise<(Sema & {
293
- id: number;
294
- }) | undefined>;
295
- private extensionHost;
296
- private groundedContinuation;
297
- /** Re-index structurally-important nodes whose gists were evicted from the
298
- * pending cache before they reached the content index. See {@link
299
- * Store.repairContentIndex} for the contract; this method wires the
300
- * Mind's perception into the store's repair walk.
301
- *
302
- * Run this after training or at checkpoints to restore recall reach for
303
- * nodes that bridge experiences but were never indexed. A pure interior
304
- * node (no edges, no halo) is deliberately skipped — it is scaffolding,
305
- * not an experience root or bridge, and regenerating its gist would waste
306
- * I/O and index space for no recall benefit.
307
- *
308
- * @param minParents only repair nodes with ≥ this many structural parents
309
- * (default 2 — structural bridges)
310
- * @returns number of nodes added to the content index */
311
- repairContentIndex(minParents?: number): Promise<number>;
312
- /** Build (or incrementally refresh) the store's canonical-form index: for
313
- * every content-bearing node, record the hash of its CANONICAL key so
314
- * resolution can find stored forms across surface variation (case, width,
315
- * whitespace — whatever `canon` equates; see src/canon.ts).
316
- *
317
- * Incremental and idempotent: the last indexed node id is remembered in
318
- * store meta (`canon.upto`), so a refresh after further training scans
319
- * only the new rows. Run once after training, and again after ingests —
320
- * the same operational shape as {@link repairContentIndex}.
321
- *
322
- * @param canon the canonicalizer to index under — MUST be the same one
323
- * queries will carry (text queries carry {@link textCanon}
324
- * unless the Mind was constructed with its own)
325
- * @returns number of index rows added */
326
- buildCanonIndex(canon?: Canon): Promise<number>;
327
- save(): Promise<Uint8Array>;
328
- static load(snapshot: Uint8Array, store: Store): Promise<Mind>;
329
- static loadFromStore(store: Store): Promise<Mind>;
330
- }