@hviana/sema 0.1.8 → 0.1.9

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 (131) hide show
  1. package/package.json +1 -1
  2. package/src/geometry.ts +14 -30
  3. package/src/mind/mechanisms/cast.ts +12 -7
  4. package/dist/example/demo.d.ts +0 -1
  5. package/dist/example/demo.js +0 -39
  6. package/dist/example/train_base.d.ts +0 -87
  7. package/dist/example/train_base.js +0 -2252
  8. package/dist/src/alphabet.d.ts +0 -7
  9. package/dist/src/alphabet.js +0 -33
  10. package/dist/src/alu/src/alu.d.ts +0 -185
  11. package/dist/src/alu/src/alu.js +0 -440
  12. package/dist/src/alu/src/expr.d.ts +0 -61
  13. package/dist/src/alu/src/expr.js +0 -318
  14. package/dist/src/alu/src/index.d.ts +0 -11
  15. package/dist/src/alu/src/index.js +0 -19
  16. package/dist/src/alu/src/kernel-arith.d.ts +0 -16
  17. package/dist/src/alu/src/kernel-arith.js +0 -264
  18. package/dist/src/alu/src/kernel-bits.d.ts +0 -19
  19. package/dist/src/alu/src/kernel-bits.js +0 -152
  20. package/dist/src/alu/src/kernel-logic.d.ts +0 -4
  21. package/dist/src/alu/src/kernel-logic.js +0 -60
  22. package/dist/src/alu/src/kernel-nd.d.ts +0 -3
  23. package/dist/src/alu/src/kernel-nd.js +0 -208
  24. package/dist/src/alu/src/kernel-numeric.d.ts +0 -54
  25. package/dist/src/alu/src/kernel-numeric.js +0 -366
  26. package/dist/src/alu/src/operation.d.ts +0 -168
  27. package/dist/src/alu/src/operation.js +0 -189
  28. package/dist/src/alu/src/parser.d.ts +0 -221
  29. package/dist/src/alu/src/parser.js +0 -577
  30. package/dist/src/alu/src/resonance.d.ts +0 -55
  31. package/dist/src/alu/src/resonance.js +0 -126
  32. package/dist/src/alu/src/text.d.ts +0 -31
  33. package/dist/src/alu/src/text.js +0 -73
  34. package/dist/src/alu/src/value.d.ts +0 -109
  35. package/dist/src/alu/src/value.js +0 -300
  36. package/dist/src/alu/test/alu.test.d.ts +0 -1
  37. package/dist/src/alu/test/alu.test.js +0 -764
  38. package/dist/src/bytes.d.ts +0 -14
  39. package/dist/src/bytes.js +0 -59
  40. package/dist/src/canon.d.ts +0 -26
  41. package/dist/src/canon.js +0 -57
  42. package/dist/src/config.d.ts +0 -111
  43. package/dist/src/config.js +0 -91
  44. package/dist/src/derive/src/deduction.d.ts +0 -125
  45. package/dist/src/derive/src/deduction.js +0 -155
  46. package/dist/src/derive/src/index.d.ts +0 -7
  47. package/dist/src/derive/src/index.js +0 -11
  48. package/dist/src/derive/src/priority-queue.d.ts +0 -20
  49. package/dist/src/derive/src/priority-queue.js +0 -73
  50. package/dist/src/derive/src/rewrite.d.ts +0 -56
  51. package/dist/src/derive/src/rewrite.js +0 -100
  52. package/dist/src/derive/src/trie.d.ts +0 -90
  53. package/dist/src/derive/src/trie.js +0 -217
  54. package/dist/src/derive/test/derive.test.d.ts +0 -1
  55. package/dist/src/derive/test/derive.test.js +0 -122
  56. package/dist/src/extension.d.ts +0 -37
  57. package/dist/src/extension.js +0 -7
  58. package/dist/src/geometry.d.ts +0 -148
  59. package/dist/src/geometry.js +0 -529
  60. package/dist/src/index.d.ts +0 -16
  61. package/dist/src/index.js +0 -18
  62. package/dist/src/ingest-cache.d.ts +0 -41
  63. package/dist/src/ingest-cache.js +0 -161
  64. package/dist/src/mind/articulation.d.ts +0 -6
  65. package/dist/src/mind/articulation.js +0 -99
  66. package/dist/src/mind/attention.d.ts +0 -72
  67. package/dist/src/mind/attention.js +0 -898
  68. package/dist/src/mind/canonical.d.ts +0 -29
  69. package/dist/src/mind/canonical.js +0 -88
  70. package/dist/src/mind/graph-search.d.ts +0 -270
  71. package/dist/src/mind/graph-search.js +0 -847
  72. package/dist/src/mind/index.d.ts +0 -5
  73. package/dist/src/mind/index.js +0 -5
  74. package/dist/src/mind/junction.d.ts +0 -95
  75. package/dist/src/mind/junction.js +0 -262
  76. package/dist/src/mind/learning.d.ts +0 -47
  77. package/dist/src/mind/learning.js +0 -233
  78. package/dist/src/mind/match.d.ts +0 -113
  79. package/dist/src/mind/match.js +0 -446
  80. package/dist/src/mind/mechanisms/alu.d.ts +0 -4
  81. package/dist/src/mind/mechanisms/alu.js +0 -29
  82. package/dist/src/mind/mechanisms/cast.d.ts +0 -35
  83. package/dist/src/mind/mechanisms/cast.js +0 -461
  84. package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
  85. package/dist/src/mind/mechanisms/confluence.js +0 -225
  86. package/dist/src/mind/mechanisms/cover.d.ts +0 -6
  87. package/dist/src/mind/mechanisms/cover.js +0 -179
  88. package/dist/src/mind/mechanisms/extraction.d.ts +0 -67
  89. package/dist/src/mind/mechanisms/extraction.js +0 -342
  90. package/dist/src/mind/mechanisms/recall.d.ts +0 -13
  91. package/dist/src/mind/mechanisms/recall.js +0 -235
  92. package/dist/src/mind/mind.d.ts +0 -273
  93. package/dist/src/mind/mind.js +0 -562
  94. package/dist/src/mind/pipeline-mechanism.d.ts +0 -142
  95. package/dist/src/mind/pipeline-mechanism.js +0 -213
  96. package/dist/src/mind/pipeline.d.ts +0 -20
  97. package/dist/src/mind/pipeline.js +0 -185
  98. package/dist/src/mind/primitives.d.ts +0 -63
  99. package/dist/src/mind/primitives.js +0 -251
  100. package/dist/src/mind/rationale.d.ts +0 -134
  101. package/dist/src/mind/rationale.js +0 -162
  102. package/dist/src/mind/reasoning.d.ts +0 -15
  103. package/dist/src/mind/reasoning.js +0 -162
  104. package/dist/src/mind/recognition.d.ts +0 -20
  105. package/dist/src/mind/recognition.js +0 -246
  106. package/dist/src/mind/resonance.d.ts +0 -23
  107. package/dist/src/mind/resonance.js +0 -0
  108. package/dist/src/mind/trace.d.ts +0 -15
  109. package/dist/src/mind/trace.js +0 -73
  110. package/dist/src/mind/traverse.d.ts +0 -113
  111. package/dist/src/mind/traverse.js +0 -488
  112. package/dist/src/mind/types.d.ts +0 -186
  113. package/dist/src/mind/types.js +0 -84
  114. package/dist/src/rabitq-ivf/src/database.d.ts +0 -113
  115. package/dist/src/rabitq-ivf/src/database.js +0 -201
  116. package/dist/src/rabitq-ivf/src/index.d.ts +0 -7
  117. package/dist/src/rabitq-ivf/src/index.js +0 -4
  118. package/dist/src/rabitq-ivf/src/ivf.d.ts +0 -200
  119. package/dist/src/rabitq-ivf/src/ivf.js +0 -1165
  120. package/dist/src/rabitq-ivf/src/prng.d.ts +0 -19
  121. package/dist/src/rabitq-ivf/src/prng.js +0 -36
  122. package/dist/src/rabitq-ivf/src/rabitq.d.ts +0 -95
  123. package/dist/src/rabitq-ivf/src/rabitq.js +0 -283
  124. package/dist/src/sema.d.ts +0 -31
  125. package/dist/src/sema.js +0 -63
  126. package/dist/src/store-sqlite.d.ts +0 -184
  127. package/dist/src/store-sqlite.js +0 -942
  128. package/dist/src/store.d.ts +0 -654
  129. package/dist/src/store.js +0 -1612
  130. package/dist/src/vec.d.ts +0 -31
  131. package/dist/src/vec.js +0 -109
@@ -1,29 +0,0 @@
1
- import type { MindContext } from "./types.js";
2
- /** The two sliding-window lengths the WRITE side interns over a stream's leaf
3
- * ids: W−1 and W (the river's grouping quantum and its off-by-one neighbour,
4
- * so a form straddling a group boundary is reachable from either cut). */
5
- export declare function canonicalWindows(W: number): [number, number];
6
- /** The READ side's chain reach: how many leaf ids a canonical chain may grow
7
- * to from one position — W², the deepest two-level composite the write side's
8
- * windows can spell. */
9
- export declare function chainReach(W: number): number;
10
- /** The id of the single-byte leaf at position `p`, or null when that byte was
11
- * never interned. */
12
- export declare function leafIdAt(ctx: MindContext, bytes: Uint8Array, p: number): number | null;
13
- /** The leaf ids of the window `[from, to)`, or null the moment ANY byte in it
14
- * is unknown — the all-or-nothing read {@link canonicalChunkId} anchors on. */
15
- export declare function leafIdRun(ctx: MindContext, bytes: Uint8Array, from: number, to: number): number[] | null;
16
- /** The leaf ids of the LONGEST KNOWN PREFIX of `bytes` — stops at the first
17
- * unknown byte and returns what it has (possibly empty). The caller decides
18
- * what a partial prefix means (deposit only interns the whole-stream flat
19
- * branch when the prefix covers everything). */
20
- export declare function leafIdPrefix(ctx: MindContext, bytes: Uint8Array): number[];
21
- /** The canonical W-window node ids of a byte stream, offset → id — the
22
- * CONTENT-ADDRESSED IDENTITY of every W-sized slice, under which any content
23
- * two deposits share IS the same node (hash-consing paid the comparison at
24
- * write time). The read side of the {@link canonicalWindows} contract asked
25
- * at every offset: a window over unknown bytes, or one never interned as a
26
- * flat branch, has no identity and is skipped. Confluence's meet and CAST's
27
- * frame detection both read shared/common content through this — never
28
- * through a byte scan. */
29
- export declare function windowIds(ctx: MindContext, bytes: Uint8Array): Map<number, number>;
@@ -1,88 +0,0 @@
1
- // canonical.ts — THE canonical-segmentation convention, defined once.
2
- //
3
- // The store's canonical reading of a byte stream — "the id of each single-byte
4
- // leaf, chained into flat branches" — is a WRITE/READ CONTRACT split across
5
- // four consumers that previously each re-implemented the chaining loop:
6
- //
7
- // WRITE side (training):
8
- // • learning.indexSubSpans — interns sliding windows of the two
9
- // {@link canonicalWindows} lengths over the stream's leaf ids;
10
- // • learning.deposit — interns the WHOLE stream as one flat branch
11
- // (via {@link leafIdPrefix}) so every deposit has a byte-level identity.
12
- // READ side (inference):
13
- // • recognition's canonical pass — chains leaf ids from every position and
14
- // probes each growing prefix as a flat branch, up to {@link chainReach};
15
- // • attention.canonicalChunkId — reads a chunk's window of leaf ids
16
- // (via {@link leafIdRun}) and probes its prefixes for the best anchor.
17
- // (geometry.knownPrefixLength is the same convention below the store layer,
18
- // expressed through injected `leafAt`/`lookup` capabilities — it cannot
19
- // import this module without inverting the dependency spine, so its header
20
- // cross-references this file instead.)
21
- //
22
- // If the write side's windows or the read side's reach ever change, they must
23
- // change HERE — a drift between them silently makes recognition stop finding
24
- // what training indexed, which no type checker catches.
25
- /** The two sliding-window lengths the WRITE side interns over a stream's leaf
26
- * ids: W−1 and W (the river's grouping quantum and its off-by-one neighbour,
27
- * so a form straddling a group boundary is reachable from either cut). */
28
- export function canonicalWindows(W) {
29
- return [W - 1, W];
30
- }
31
- /** The READ side's chain reach: how many leaf ids a canonical chain may grow
32
- * to from one position — W², the deepest two-level composite the write side's
33
- * windows can spell. */
34
- export function chainReach(W) {
35
- return W * W;
36
- }
37
- /** The id of the single-byte leaf at position `p`, or null when that byte was
38
- * never interned. */
39
- export function leafIdAt(ctx, bytes, p) {
40
- return ctx.store.findLeaf(bytes.subarray(p, p + 1));
41
- }
42
- /** The leaf ids of the window `[from, to)`, or null the moment ANY byte in it
43
- * is unknown — the all-or-nothing read {@link canonicalChunkId} anchors on. */
44
- export function leafIdRun(ctx, bytes, from, to) {
45
- const ids = [];
46
- for (let i = from; i < to; i++) {
47
- const lid = leafIdAt(ctx, bytes, i);
48
- if (lid === null)
49
- return null;
50
- ids.push(lid);
51
- }
52
- return ids;
53
- }
54
- /** The leaf ids of the LONGEST KNOWN PREFIX of `bytes` — stops at the first
55
- * unknown byte and returns what it has (possibly empty). The caller decides
56
- * what a partial prefix means (deposit only interns the whole-stream flat
57
- * branch when the prefix covers everything). */
58
- export function leafIdPrefix(ctx, bytes) {
59
- const ids = [];
60
- for (let i = 0; i < bytes.length; i++) {
61
- const lid = leafIdAt(ctx, bytes, i);
62
- if (lid === null)
63
- break;
64
- ids.push(lid);
65
- }
66
- return ids;
67
- }
68
- /** The canonical W-window node ids of a byte stream, offset → id — the
69
- * CONTENT-ADDRESSED IDENTITY of every W-sized slice, under which any content
70
- * two deposits share IS the same node (hash-consing paid the comparison at
71
- * write time). The read side of the {@link canonicalWindows} contract asked
72
- * at every offset: a window over unknown bytes, or one never interned as a
73
- * flat branch, has no identity and is skipped. Confluence's meet and CAST's
74
- * frame detection both read shared/common content through this — never
75
- * through a byte scan. */
76
- export function windowIds(ctx, bytes) {
77
- const W = ctx.space.maxGroup;
78
- const out = new Map();
79
- for (let off = 0; off + W <= bytes.length; off++) {
80
- const ids = leafIdRun(ctx, bytes, off, off + W);
81
- if (ids === null)
82
- continue;
83
- const wid = ctx.store.findBranch(ids);
84
- if (wid !== null)
85
- out.set(off, wid);
86
- }
87
- return out;
88
- }
@@ -1,270 +0,0 @@
1
- import type { Store } from "../store.js";
2
- import type { GraphSearchHost } from "./types.js";
3
- /** A recognised form: a span of the query that names a node already in the
4
- * store. `payload` is that node id. */
5
- export interface Site {
6
- start: number;
7
- end: number;
8
- payload: number;
9
- }
10
- /** A perceived leaf of the query tree, carrying the node id it resolves to. */
11
- export interface Leaf {
12
- start: number;
13
- end: number;
14
- bytes: Uint8Array;
15
- node: number | null;
16
- }
17
- /** A COMPUTED span: the result of applying a manual rule (an extension's
18
- * operation — e.g. the `alu` extension's arithmetic) to a recognised stretch
19
- * of the query. Every
20
- * bit of the intelligence — recognising the operator (literally or by
21
- * resonance), parsing the operands, evaluating the operation — is done by the
22
- * caller (src/mind/pipeline.ts), which hands the search the finished result span; the search
23
- * treats it exactly like any other recognised completion (a learned fact that
24
- * happens to be computed rather than stored). `node` is the canonical id of
25
- * the result bytes when the store already holds them, else undefined. */
26
- export interface ComputedResult {
27
- i: number;
28
- j: number;
29
- bytes: Uint8Array;
30
- node?: number;
31
- }
32
- export type GItem = {
33
- kind: "cover";
34
- p: number;
35
- } | {
36
- kind: "form";
37
- i: number;
38
- j: number;
39
- node: number;
40
- via: boolean;
41
- /** Set when this form was born by RECOMPOSING rewritten parts into a deeper
42
- * learned whole (the fuse of ≥2 recognised completions that names an
43
- * edge-bearing node). Its onward continuation is charged at MICRO, not
44
- * STEP: once parts are recomposed into a learned form, following that form
45
- * to its grounded answer is the recomposition completing — so the
46
- * consolidated, more-explanatory reading wins over leaving the parts split.
47
- * See {@link GraphSearch.fuse} and {@link GraphSearch.formRules}. */
48
- rcmp?: boolean;
49
- } | {
50
- kind: "out";
51
- i: number;
52
- j: number;
53
- bytes: Uint8Array;
54
- cover: boolean;
55
- rec: boolean;
56
- node?: number;
57
- };
58
- export declare const STEP = 1;
59
- export declare const CONCEPT = 10;
60
- export declare const PASS = 1000;
61
- /** The cheapest local cost in the ladder: a recognised completion bridging into
62
- * the cover. Far below STEP, so connecting two recognised spans never disturbs
63
- * the ordering — and, being the minimum per-position cost, it is the per-byte
64
- * unit of the admissible search heuristic (see {@link GraphSearch.buildSearch}). */
65
- export declare const MICRO = 0.001;
66
- /** One chosen span of the cover, left to right. `node` is the graph node the
67
- * span resolved to (when known) — for a recognised completion it is the chain's
68
- * terminal node, the foothold the bridge walks edges from. */
69
- export interface Seg {
70
- i: number;
71
- j: number;
72
- bytes: Uint8Array;
73
- rec: boolean;
74
- node?: number;
75
- }
76
- /** One rule application inside the cover's lightest derivation — the FINEST
77
- * grain of Sema's core reasoning, one node of the adapted A*LD proof tree. `move`
78
- * names which deduction rule fired (the reasoning act); `premises` and
79
- * `conclusion` are the items it consumed and produced, each rendered as a
80
- * positioned, possibly-node-bearing span; `cost` is the rule's local weight
81
- * (STEP for a learned edge, CONCEPT for a synonym hop, 0 for a free fuse, …);
82
- * `order` is its post-order position so a tracer can replay the proof in the
83
- * order it was built (premises before conclusion). */
84
- export interface DerivationStep {
85
- order: number;
86
- move: DerivationMove;
87
- premises: DerivationItem[];
88
- conclusion: DerivationItem;
89
- cost: number;
90
- /** The `order`s of the steps that produced this one's premises — the EXACT
91
- * data-flow edges of the proof tree (a `bridge` names the `ground` whose
92
- * `out` it crossed and the earlier `cover` it extended). A premise that is
93
- * an axiom (a seed leaf/form/computed result, never a rule conclusion) has no
94
- * producer and contributes no edge, so this lists only the derived premises —
95
- * the finest dependency structure the inference holds. */
96
- producers: number[];
97
- }
98
- /** A premise or conclusion of a {@link DerivationStep}, flattened from a {@link
99
- * GItem} into the fields a rationale cares about. */
100
- export interface DerivationItem {
101
- kind: "cover" | "form" | "out";
102
- /** `[i, j)` span for a form/out; for a cover item, `[p, p]`. */
103
- span: [number, number];
104
- /** The bytes an `out` carries (the only item kind that holds output bytes). */
105
- bytes?: Uint8Array;
106
- /** The graph node a form/out resolves to, when known. */
107
- node?: number;
108
- }
109
- /** The reasoning act a derivation rule performs — the human name for which of
110
- * {@link GraphSearch}'s rules fired, recovered from the rule's premise/
111
- * conclusion shape (the rules carry no label, so this classifies by structure,
112
- * the single place that maps rule geometry to a name). */
113
- export type DerivationMove = "axiom" | "follow-edge" | "concept-hop" | "voice" | "ground" | "splice-connector" | "split" | "fuse" | "recompose" | "bridge" | "pool-vote" | "step";
114
- /** The lightest-derivation search over the Sema graph. One instance binds the
115
- * store, `maxGroup` (the fusible span ceiling), and the canonical
116
- * {@link resolve} callback; {@link cover} then solves one query. */
117
- export declare class GraphSearch {
118
- private readonly store;
119
- private readonly maxGroup;
120
- /** The host whose capabilities the search consults: resolve (canonical node
121
- * id of a byte span), recogniseSpan (content-addressed graph lookup for
122
- * recursive completion), and chooseNext (distributional-evidence edge
123
- * disambiguation when a recognised form has multiple continuations). */
124
- private readonly host;
125
- constructor(store: Store, maxGroup: number,
126
- /** The host whose capabilities the search consults: resolve (canonical node
127
- * id of a byte span), recogniseSpan (content-addressed graph lookup for
128
- * recursive completion), and chooseNext (distributional-evidence edge
129
- * disambiguation when a recognised form has multiple continuations). */
130
- host: GraphSearchHost);
131
- /** Explore the Sema graph for the lightest cover of the query and return its
132
- * chosen spans left-to-right — WITH the derivation's total weight (the g
133
- * value of the goal item, in the exported cost ladder), which think's
134
- * grounding decider compares against the other mechanisms' candidates —
135
- * or null if the query cannot be covered.
136
- *
137
- * The search runs on the query's tree leaves, not flat bytes — leaf-level
138
- * cover axioms, recognised forms as graph entry points — and discovers
139
- * cross-leaf forms by fusing adjacent fragments on demand (the only
140
- * byte-processing it does, and only where a derivation needs it). When
141
- * `substitutions` is given, recognised forms emit substitute bytes directly
142
- * (cost 0) — articulation splicing the asker's wording in.
143
- *
144
- * Any learnt connector between two rewrites is spliced IN by the in-search
145
- * connector rule (see {@link outRules}), so the returned spans already carry
146
- * it — there is no post-pass. */
147
- cover(queryLen: number, sites: ReadonlyArray<Site>, conceptTarget: ReadonlyMap<number, number>, leaves: ReadonlyArray<Leaf>, splits: ReadonlySet<number>, substitutions?: ReadonlyMap<number, Uint8Array>, connectors?: ReadonlyMap<string, Uint8Array>, computedResults?: ReadonlyArray<ComputedResult>,
148
- /** When given, receives the lightest derivation's rule applications — the
149
- * full adapted A*LD proof tree as classified {@link DerivationStep}s — for the TOP
150
- * cover only (a recursive recompletion solves its own sub-cover and is not
151
- * reported here, to keep the trace one layer per think). Off by default,
152
- * so the search pays nothing when no one inspects. */
153
- onDerivation?: (steps: DerivationStep[]) => void): {
154
- segs: Seg[];
155
- cost: number;
156
- } | null;
157
- /** Build the deduction system for one span and return its lightest cover's
158
- * chosen spans — the SINGLE routine the query and every produced composite
159
- * run through. `recognition` carries the span's recognised forms; the query
160
- * brings its own (with pre-resolved concepts/connectors), a recursive
161
- * completion re-recognises the produced bytes (edge/fuse only).
162
- *
163
- * No depth limit governs nesting — convergence is INTRINSIC, exactly as in the
164
- * adapted A*LD chart and {@link completeForward}: a completion only recurses into a
165
- * node it has not already entered ({@link recompleteNode}'s cycle guard), and
166
- * the node ids are finite, so the recursion must terminate on its own. A
167
- * decomposition may therefore run as deep as the graph licenses — three
168
- * decomposes, two recomposes, any mix — and stops only when it reaches a node
169
- * that leads nowhere new, never at an arbitrary count. */
170
- private solve;
171
- /** The weighted deduction system the graph exploration solves (the four
172
- * reductions of adapted A*LD live in {@link lightestDerivation}; this only states the
173
- * items, axioms, goal, and rules — see {@link GItem} for the item kinds).
174
- *
175
- * Forms that span across leaves are discovered BY the rules, which fuse
176
- * adjacent fragments toward a known leaf (findLeaf) or branch (findBranch);
177
- * a completion fused with its neighbour may spell a deeper learned form the
178
- * flat probes can't name, recovered canonically by {@link resolve}. */
179
- private buildSearch;
180
- /** cover(p): the BRIDGE rule — extend the cover across any coverable out that
181
- * begins at p, stepping the frontier from p to that out's end.
182
- *
183
- * This is what links the rewritten parts of a multi-form answer. An out is
184
- * either a recognised completion (`rec`, free) or a literal span the query
185
- * carried between known forms — the connective: a space, comma, period,
186
- * newline, or any run of bytes that was never recognised. Bridging a literal
187
- * costs PASS per byte (so the search still prefers to recognise), but it is
188
- * the cheapest — indeed only — way to cross a gap that has no learned form,
189
- * and it KEEPS that connective in the cover chain, so the asker's own linking
190
- * material reappears when it still coheres ("ice, fire" → "cold, hot", not
191
- * "coldhot"). A recognised completion bridges for a tiny ε (1e-3, far below
192
- * STEP), so a single connected span beats two separate ones on coherence
193
- * without disturbing the cost ladder's ordering.
194
- *
195
- * Marks p finalised so the symmetric out-side bridge ({@link outRules}) can
196
- * fire for outs that arrive after their start position is covered. */
197
- private coverRules;
198
- /** The BRIDGE rule, built once for its two arrival orders (cover-first in
199
- * {@link coverRules}, out-first in {@link outRules}): ε for a recognised
200
- * completion; PASS per byte for a literal connective — kept in the cover
201
- * so the asker's own connector survives where it fits. ONE definition of
202
- * the cost expression, so the ladder's application cannot drift between
203
- * the two sides. */
204
- private bridgeRule;
205
- /** The connector-SPLICE rule for an oriented (l, r) pair, or null when the
206
- * pair does not qualify — the ONE body behind {@link outRules}' two
207
- * mirror loops (this-as-left over resolved right partners, this-as-right
208
- * over resolved left partners). Fires only when both sides are
209
- * recognised, r starts at or after l ends, and the gap between them is
210
- * empty or wholly recognised — never across the asker's own literal
211
- * separator. */
212
- private trySplice;
213
- /** form(i,j,node,via): follow the graph out of `node`, or (in articulation)
214
- * emit its substitute voice directly. */
215
- private formRules;
216
- /** Complete a node that an edge produced but that bears no further whole-edge,
217
- * by COVERING ITS OWN BYTES — the very same operation the top query runs.
218
- * Completion is not a special pass: a produced composite ("p1 p2") is just
219
- * another span to cover, and covering it re-applies recognition, edge-follow,
220
- * fusion and recomposition to discover that its parts continue (p1→R1, p2→R2)
221
- * and recompose into a deeper learnt form (→ FINAL). This is why a single
222
- * edge-target needs no bespoke logic — it routes back through {@link solve}.
223
- *
224
- * Re-recognition (not the node's tree children) is what surfaces the learnt
225
- * parts: content-defined chunking may cut "p1 p2" as "p1 p"|"2", so only
226
- * recognising the bytes recovers p1 and p2 as the forms the graph knows.
227
- *
228
- * The recovered answer is accepted only when it MOVED and names a LEARNT node
229
- * ({@link resolve}) — the graph itself gates against re-expanding a contained
230
- * form ("ice is cold" ⊅→ "ice is cold is cold").
231
- *
232
- * Termination is INTRINSIC, not a depth limit: a node already on the
233
- * completion stack ({@link recompleteOpen}) is not re-entered — a self-
234
- * referential recomposition is a cycle that can yield nothing new, so it
235
- * stops there, exactly as {@link completeForward} stops on a revisited edge.
236
- * Distinct node ids are finite and each finished completion is memoised, so a
237
- * legitimate chain runs as deep as the graph licenses and no further. */
238
- private recompleteNode;
239
- /** Per-cover memo of each produced node's completion (so the many terminal
240
- * outs of a long query re-cover each distinct node at most once); reset at the
241
- * top of {@link cover}. */
242
- private recompleteMemo;
243
- /** The nodes currently being re-completed — the recursion stack. A node in
244
- * this set is not re-entered, so a cyclic recomposition terminates naturally
245
- * (the same cycle guard {@link completeForward} uses), with no depth cap. */
246
- private recompleteOpen;
247
- /** out(i,j,bytes,…): index it for the binary rules, then offer splicing a
248
- * learnt connector (the in-search bridge), splitting (at a sub-leaf form
249
- * boundary), bridging (cover(i) ∧ this → cover(j)), and fusing with an
250
- * adjacent finalised out. */
251
- private outRules;
252
- /** Whether the query span [from, to) is wholly covered by RECOGNISED outs —
253
- * the test that lets a connector jump across INTERIOR answers (an N-ary whole)
254
- * but never across the asker's own unrecognised framing (a space or comma the
255
- * asker wrote between parts). Empty span (from === to, the adjacent case) is
256
- * trivially recognised. Otherwise step right-to-left: from `to`, find a
257
- * recognised out ending there and continue from its start, until reaching
258
- * `from`. Greedy-longest is sufficient here — the spans in play are the few
259
- * recognised answers of one query, not a general interval cover. */
260
- private gapRecognised;
261
- /** Fuse two adjacent finalised outs — the search's own discovery of forms
262
- * that cross leaf boundaries. The concatenation may be a known leaf
263
- * (findLeaf, when short enough), or — when both sides resolved — their pair a
264
- * known branch (findBranch); a completion fused with its neighbour may spell
265
- * a deeper learned form, recovered canonically by {@link resolve} (gated on a
266
- * completion being present, so it only runs along chains). The fused span
267
- * lives on as an intermediate out while it could still grow into a form, and
268
- * enters the graph as a form the moment it names a node. */
269
- private fuse;
270
- }