@hviana/sema 0.5.3 → 0.5.4

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 (143) hide show
  1. package/AGENTS.md +6 -6
  2. package/HOW_IT_WORKS.md +16 -0
  3. package/jsr.json +1 -1
  4. package/package.json +1 -1
  5. package/src/mind/match.ts +81 -0
  6. package/src/mind/mechanisms/recall.ts +29 -3
  7. package/test/76-reference-binding.test.mjs +72 -0
  8. package/dist/example/demo.d.ts +0 -1
  9. package/dist/example/demo.js +0 -39
  10. package/dist/example/train_base.d.ts +0 -93
  11. package/dist/example/train_base.js +0 -2269
  12. package/dist/src/alphabet.d.ts +0 -7
  13. package/dist/src/alphabet.js +0 -33
  14. package/dist/src/alu/src/alu.d.ts +0 -185
  15. package/dist/src/alu/src/alu.js +0 -440
  16. package/dist/src/alu/src/expr.d.ts +0 -61
  17. package/dist/src/alu/src/expr.js +0 -318
  18. package/dist/src/alu/src/index.d.ts +0 -11
  19. package/dist/src/alu/src/index.js +0 -19
  20. package/dist/src/alu/src/kernel-arith.d.ts +0 -16
  21. package/dist/src/alu/src/kernel-arith.js +0 -264
  22. package/dist/src/alu/src/kernel-bits.d.ts +0 -19
  23. package/dist/src/alu/src/kernel-bits.js +0 -152
  24. package/dist/src/alu/src/kernel-logic.d.ts +0 -4
  25. package/dist/src/alu/src/kernel-logic.js +0 -60
  26. package/dist/src/alu/src/kernel-nd.d.ts +0 -3
  27. package/dist/src/alu/src/kernel-nd.js +0 -208
  28. package/dist/src/alu/src/kernel-numeric.d.ts +0 -54
  29. package/dist/src/alu/src/kernel-numeric.js +0 -366
  30. package/dist/src/alu/src/operation.d.ts +0 -168
  31. package/dist/src/alu/src/operation.js +0 -189
  32. package/dist/src/alu/src/parser.d.ts +0 -221
  33. package/dist/src/alu/src/parser.js +0 -577
  34. package/dist/src/alu/src/resonance.d.ts +0 -55
  35. package/dist/src/alu/src/resonance.js +0 -126
  36. package/dist/src/alu/src/text.d.ts +0 -31
  37. package/dist/src/alu/src/text.js +0 -73
  38. package/dist/src/alu/src/value.d.ts +0 -109
  39. package/dist/src/alu/src/value.js +0 -300
  40. package/dist/src/alu/test/alu.test.d.ts +0 -1
  41. package/dist/src/alu/test/alu.test.js +0 -764
  42. package/dist/src/bytes.d.ts +0 -14
  43. package/dist/src/bytes.js +0 -59
  44. package/dist/src/canon.d.ts +0 -45
  45. package/dist/src/canon.js +0 -85
  46. package/dist/src/config.d.ts +0 -111
  47. package/dist/src/config.js +0 -91
  48. package/dist/src/derive/src/deduction.d.ts +0 -136
  49. package/dist/src/derive/src/deduction.js +0 -159
  50. package/dist/src/derive/src/index.d.ts +0 -8
  51. package/dist/src/derive/src/index.js +0 -11
  52. package/dist/src/derive/src/priority-queue.d.ts +0 -20
  53. package/dist/src/derive/src/priority-queue.js +0 -73
  54. package/dist/src/derive/src/rewrite.d.ts +0 -56
  55. package/dist/src/derive/src/rewrite.js +0 -100
  56. package/dist/src/derive/src/trie.d.ts +0 -90
  57. package/dist/src/derive/src/trie.js +0 -217
  58. package/dist/src/derive/test/derive.test.d.ts +0 -1
  59. package/dist/src/derive/test/derive.test.js +0 -122
  60. package/dist/src/extension.d.ts +0 -37
  61. package/dist/src/extension.js +0 -7
  62. package/dist/src/geometry.d.ts +0 -233
  63. package/dist/src/geometry.js +0 -1089
  64. package/dist/src/index.d.ts +0 -17
  65. package/dist/src/index.js +0 -19
  66. package/dist/src/ingest-cache.d.ts +0 -41
  67. package/dist/src/ingest-cache.js +0 -165
  68. package/dist/src/meter.d.ts +0 -176
  69. package/dist/src/meter.js +0 -274
  70. package/dist/src/mind/articulation.d.ts +0 -6
  71. package/dist/src/mind/articulation.js +0 -99
  72. package/dist/src/mind/attention.d.ts +0 -430
  73. package/dist/src/mind/attention.js +0 -2418
  74. package/dist/src/mind/bridge.d.ts +0 -37
  75. package/dist/src/mind/bridge.js +0 -907
  76. package/dist/src/mind/canonical.d.ts +0 -34
  77. package/dist/src/mind/canonical.js +0 -93
  78. package/dist/src/mind/graph-search.d.ts +0 -294
  79. package/dist/src/mind/graph-search.js +0 -996
  80. package/dist/src/mind/index.d.ts +0 -9
  81. package/dist/src/mind/index.js +0 -5
  82. package/dist/src/mind/junction.d.ts +0 -137
  83. package/dist/src/mind/junction.js +0 -358
  84. package/dist/src/mind/learning.d.ts +0 -75
  85. package/dist/src/mind/learning.js +0 -265
  86. package/dist/src/mind/match.d.ts +0 -351
  87. package/dist/src/mind/match.js +0 -959
  88. package/dist/src/mind/mechanisms/alu.d.ts +0 -4
  89. package/dist/src/mind/mechanisms/alu.js +0 -36
  90. package/dist/src/mind/mechanisms/cast.d.ts +0 -89
  91. package/dist/src/mind/mechanisms/cast.js +0 -1186
  92. package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
  93. package/dist/src/mind/mechanisms/confluence.js +0 -271
  94. package/dist/src/mind/mechanisms/cover.d.ts +0 -6
  95. package/dist/src/mind/mechanisms/cover.js +0 -232
  96. package/dist/src/mind/mechanisms/extraction.d.ts +0 -33
  97. package/dist/src/mind/mechanisms/extraction.js +0 -327
  98. package/dist/src/mind/mechanisms/prefix-completion.d.ts +0 -22
  99. package/dist/src/mind/mechanisms/prefix-completion.js +0 -243
  100. package/dist/src/mind/mechanisms/recall.d.ts +0 -16
  101. package/dist/src/mind/mechanisms/recall.js +0 -460
  102. package/dist/src/mind/mechanisms/reference.d.ts +0 -6
  103. package/dist/src/mind/mechanisms/reference.js +0 -296
  104. package/dist/src/mind/mind.d.ts +0 -386
  105. package/dist/src/mind/mind.js +0 -754
  106. package/dist/src/mind/pipeline-mechanism.d.ts +0 -238
  107. package/dist/src/mind/pipeline-mechanism.js +0 -622
  108. package/dist/src/mind/pipeline.d.ts +0 -49
  109. package/dist/src/mind/pipeline.js +0 -343
  110. package/dist/src/mind/primitives.d.ts +0 -85
  111. package/dist/src/mind/primitives.js +0 -333
  112. package/dist/src/mind/rationale.d.ts +0 -139
  113. package/dist/src/mind/rationale.js +0 -163
  114. package/dist/src/mind/reasoning.d.ts +0 -42
  115. package/dist/src/mind/reasoning.js +0 -305
  116. package/dist/src/mind/recognition.d.ts +0 -20
  117. package/dist/src/mind/recognition.js +0 -696
  118. package/dist/src/mind/resonance.d.ts +0 -35
  119. package/dist/src/mind/resonance.js +0 -365
  120. package/dist/src/mind/trace.d.ts +0 -15
  121. package/dist/src/mind/trace.js +0 -73
  122. package/dist/src/mind/traverse.d.ts +0 -196
  123. package/dist/src/mind/traverse.js +0 -806
  124. package/dist/src/mind/types.d.ts +0 -418
  125. package/dist/src/mind/types.js +0 -179
  126. package/dist/src/rabitq-ivf/src/database.d.ts +0 -113
  127. package/dist/src/rabitq-ivf/src/database.js +0 -201
  128. package/dist/src/rabitq-ivf/src/index.d.ts +0 -7
  129. package/dist/src/rabitq-ivf/src/index.js +0 -4
  130. package/dist/src/rabitq-ivf/src/ivf.d.ts +0 -200
  131. package/dist/src/rabitq-ivf/src/ivf.js +0 -1165
  132. package/dist/src/rabitq-ivf/src/prng.d.ts +0 -19
  133. package/dist/src/rabitq-ivf/src/prng.js +0 -36
  134. package/dist/src/rabitq-ivf/src/rabitq.d.ts +0 -95
  135. package/dist/src/rabitq-ivf/src/rabitq.js +0 -313
  136. package/dist/src/sema.d.ts +0 -41
  137. package/dist/src/sema.js +0 -77
  138. package/dist/src/store-sqlite.d.ts +0 -184
  139. package/dist/src/store-sqlite.js +0 -942
  140. package/dist/src/store.d.ts +0 -762
  141. package/dist/src/store.js +0 -1823
  142. package/dist/src/vec.d.ts +0 -31
  143. package/dist/src/vec.js +0 -109
@@ -1,196 +0,0 @@
1
- import { Vec } from "../vec.js";
2
- import type { AncestorReach, MindContext } from "./types.js";
3
- /** The reach memo this ask should use — see the note above.
4
- *
5
- * A TRACED response always gets a fresh, empty one. `AncestorReach`'s
6
- * `visited`/`maxDepth`/`saturation` fields are populated only when a trace
7
- * is attached, so an entry deposited by an untraced earlier turn would
8
- * silently black out the reach detail of a later traced one; and the trace's
9
- * reach payload is serialised by ITERATING this map, which must therefore
10
- * hold what THIS climb consulted, not the whole conversation's history.
11
- * Consistent with AGENTS §2.11: a traced response is a different machine —
12
- * never benchmark with a trace attached. */
13
- export declare function sharedReachMemo(ctx: MindContext): Map<number, AncestorReach>;
14
- /** Invalidate every session-lifetime structural read after a write. */
15
- export declare function invalidateStructuralCaches(ctx: MindContext): void;
16
- /** Climb the structural DAG from a node to its edge-bearing ancestor contexts.
17
- * Ascent stops at hub nodes (parents > √N) — their reach is non-discriminative.
18
- * When the start node has no structural parents, climbs from containment parents
19
- * (sub-span flat branches inheriting their chunks' context).
20
- *
21
- * `memo`, when given, caches whole climbs by start id for the duration of ONE
22
- * query (the store is read-only while a query is in flight, so a climb is a
23
- * pure function of the id). The consensus pipeline climbs the SAME anchors
24
- * repeatedly — regions sharing a chunk, and canonicalChunkId probing each
25
- * chunk's prefixes — so without the memo every repeat re-pays the full
26
- * fan-out reads. */
27
- export declare function edgeAncestors(ctx: MindContext, id: number, contextCount: number, memo?: Map<number, AncestorReach>): AncestorReach;
28
- /** Convenience: forward edges of a node. */
29
- export declare function nextOf(ctx: MindContext, id: number): number[];
30
- /** Convenience: reverse edges of a node. */
31
- export declare function prevOf(ctx: MindContext, id: number): number[];
32
- /** The uniform-expectation floor on a byte atom's corpus commonality: N
33
- * learnt contexts, each at least one perception chunk of up to W of the 256
34
- * possible byte values, contain a given atom in ≥ N·W/256 contexts on
35
- * average. An atom's TRUE containment is unmeasurable (atoms carry no
36
- * kid/contain links by construction), so this floor is the honest stand-in:
37
- * derived entirely from the corpus scale N, the perception window W, and
38
- * the alphabet size — never tuned. */
39
- export declare function atomReach(ctx: MindContext, contextCount: number): number;
40
- /** Whether a byte atom is a hub at this corpus scale — its commonality floor
41
- * {@link atomReach} exceeds the hub bound √N. Below it (small stores) an
42
- * atom votes and is recognised exactly as any stored form; above it the
43
- * alphabet is scaffolding everywhere and abstains. */
44
- export declare function atomIsHub(ctx: MindContext, contextCount: number): boolean;
45
- /** Whether a node LEADS SOMEWHERE — it bears a continuation edge or a halo.
46
- * The admission predicate recognition filters sites with (HOW_IT_WORKS
47
- * §15.3): a form that leads nowhere contributes nothing to any derivation.
48
- * Runs once per candidate span on the recognition hot path — `hasNext` is
49
- * cached per response (the same flat-branch ids are probed across prefix
50
- * variants by canonicalChunkId). `hasHalo` is not cached: it's a single
51
- * indexed point probe per candidate, and the candidates that reach this
52
- * check have already been filtered by hasNext above in edgeAncestors. */
53
- export declare function leadsSomewhere(ctx: MindContext, id: number): boolean;
54
- /** The structural IDF read of ONE node: how many distinct learnt contexts
55
- * its containment/edge climb reaches, or Infinity when it reaches none or
56
- * saturates (no usable identity evidence). The number every
57
- * discriminative-vs-scaffolding decision derives from — paired with the
58
- * half-dominance convention (geometry.dominates(reach, N)): content
59
- * reaching a corpus MINORITY of contexts discriminates (an entity, a
60
- * filler); content reaching a majority is frame scaffolding. */
61
- export declare function reachOf(ctx: MindContext, id: number, contextCount: number, memo?: Map<number, AncestorReach>): number;
62
- /** The corpus scale N — the count of DISTINCT learnt contexts, floored at 2
63
- * so its derived readings (ln N in the consensus floor, √N in the hub bound)
64
- * stay meaningful on a near-empty store. The one definition every consumer
65
- * of "how big is this corpus?" reads. */
66
- export declare function corpusN(ctx: MindContext): number;
67
- /** The hub bound √N itself (≥ 2 always, since N is floored at 2) — for
68
- * consumers that pass it to the store's LIMITed reads instead of capping a
69
- * materialised list. {@link hubCap} is the list-side reading of the same
70
- * convention. */
71
- export declare function hubBound(ctx: MindContext): number;
72
- /** Cap a candidate list at the hub bound √N (insertion order) — the ONE
73
- * fan-out convention every walk and disambiguation uses (see HOW_IT_WORKS
74
- * §8.6). A node connected to more than √N others is a hub whose individual
75
- * connections carry ~no discriminative information; materialising or scoring
76
- * them all would make single decisions scale with the corpus. */
77
- export declare function hubCap<T>(ctx: MindContext, ids: readonly T[]): readonly T[];
78
- /** Whether `descendant` lies within `ancestor`'s subtree — a structural DAG
79
- * relation read off the hash-consed `kids` lists, by a bounded explicit-stack
80
- * descent. Used by articulation to keep a voice from revoicing a fragment
81
- * OF that voice. */
82
- export declare function contains(ctx: MindContext, ancestor: number, descendant: number): boolean;
83
- /** The best-scoring item by cosine against `query`, among items scoring at
84
- * or above `threshold` — the shared arg-max every Pattern-A "which of these
85
- * resonates best" decision reduces to. `strict` picks the tie-break a
86
- * caller needs: `true` keeps the first-seen leader on a tie (`>`), the
87
- * default lets a later equal score take it (`>=`). */
88
- export declare function argmaxBy<T>(items: Iterable<T>, scoreOf: (item: T) => number, threshold: number, strict?: boolean): {
89
- item: T;
90
- score: number;
91
- } | null;
92
- export declare function argmaxCosine<T>(query: Vec, items: Iterable<T>, vecOf: (item: T) => Vec | null | undefined, threshold: number, strict?: boolean): {
93
- item: T;
94
- score: number;
95
- } | null;
96
- /** The guided-or-first continuation of a node, as answer-shaped bytes source:
97
- * chooseNext under the response guide, falling back to the FIRST-inserted
98
- * edge — the one no-guide convention chooseNext, project() and the search's
99
- * formRules all share. undefined when the node has no continuation. */
100
- export declare function guidedFirst(ctx: MindContext, id: number): number | undefined;
101
- export declare function guidedNext(ctx: MindContext, node: number): number | undefined;
102
- /** Disambiguate among a node's learnt continuations by distributional
103
- * support. NOTE the `guide` contract: its VALUE is deliberately unused —
104
- * only its PRESENCE gates disambiguation (a null guide means no query is in
105
- * flight, so structural walkers keep plain first-edge behaviour). The
106
- * gist-cosine of short answer candidates against a query guide is dominated
107
- * by accidental byte-pattern correlations, not semantic relatedness, so the
108
- * evidence consulted is structural: each candidate's reverse-edge support
109
- * count (see below). Contrast {@link chooseAmong}, the REVERSE-direction
110
- * disambiguator, whose candidates are whole learnt contexts — long enough
111
- * that their perceived gists ARE semantically meaningful — and which
112
- * therefore scores by guide cosine. The two directions consult different
113
- * halves of the evidence on purpose. */
114
- export declare function chooseNext(ctx: MindContext, id: number, guide?: Vec | null): number | undefined;
115
- /** The perceived gist of a candidate node, through the session gist cache.
116
- * Re-gisting a candidate is a full river fold of its bytes — the measured
117
- * recall bottleneck (a hub context offers up to √N continuations, EACH
118
- * re-perceived per pick). A node's bytes are immutable and perception is
119
- * pure, so the cached gist is valid for the store's lifetime. Exported for
120
- * every "score node ids against a guide" decision (chooseAmong here, the
121
- * bridge's junction pick) so they share ONE cache and one convention. */
122
- export declare function candidateGist(ctx: MindContext, c: number): Vec | null;
123
- export declare function chooseAmong(ctx: MindContext, candidates: readonly number[], guide: Vec): {
124
- id: number;
125
- score: number;
126
- };
127
- /** True when NO window of `query` discriminates anything — every stored
128
- * W-window it spells is contained by more places than the hub bound allows,
129
- * i.e. the whole query is corpus-global scaffolding.
130
- *
131
- * WHAT IT IS FOR. Several mechanisms ground a query through the literal
132
- * spans it did NOT explain, and those spans are the whole of their evidence.
133
- * When every one of them is a hub, the query says nothing the corpus can be
134
- * held to, and grounding it means picking one of thousands of continuations
135
- * it gives no evidence for — a fabrication whatever the answer happens to be.
136
- * Answering with silence there is the honest degradation contract (§2.13).
137
- *
138
- * MEASURED SEPARATION (trained store, hubBound 571) — this is categorical,
139
- * not marginal, and it is why the predicate lives here rather than being
140
- * spelled twice:
141
- * "What is the capital of" ALL saturated ("What":572) → fabricated
142
- * "What is the capital " ALL saturated ("What":572) → fabricated
143
- * "what is the capital of france" min "f fr":248 → correct
144
- * "What is the capitol of France?" min "f Fr":114 → correct
145
- * "WHAT IS THE CAPITAL OF FRANCE?" min "HE C":1 → correct
146
- * "What is the capital of France?" min "t i":4 → correct
147
- * "Who wrote Romeo and Juliet?" min "iet?":26 → correct
148
- * "What is the capital of Zamunda?" min "Zamu":3 → silent anyway
149
- * Note the last: the honest-silence probes are already refused on other
150
- * evidence and sit on the SAME side as the correct ones, so this predicate
151
- * is not what makes them silent and cannot be credited for them.
152
- *
153
- * NO NEW THRESHOLD (§2.2): `hubBound` is the √N reading of "hub" used
154
- * everywhere, and the containment read is clamped to it exactly as every
155
- * other fan-out read is (§2.8). A query with no stored window at all is NOT
156
- * scaffolding-only — it has no evidence either way, and its callers already
157
- * refuse it on their own terms. */
158
- export declare function allWindowsAreScaffolding(ctx: MindContext, query: Uint8Array): boolean;
159
- /** Trained forms the query may OPEN, proposed from the write side's own
160
- * leaf-id window index — the supply of last resort for prefix completion.
161
- *
162
- * WHY A SECOND SUPPLY EXISTS. The ranked list prefix completion normally reads
163
- * is a resonance list, and resonance cannot rank a proper prefix: measured on
164
- * the trained store, cos(prefix, form) falls from 0.9629 at a one-byte
165
- * truncation to 0.6206 at three bytes, against a reachThreshold of 0.8750.
166
- * Three bytes of truncation put the answer out of reach on GEOMETRY, not on a
167
- * bug, so no k and no re-ranking recovers it.
168
- *
169
- * WHY THIS ROUTE WORKS WHERE THE FOLD DOES NOT. A query's own fold is
170
- * useless here: content addressing is not phrase-position-invariant, so a
171
- * standalone prefix folds to a DIFFERENT node than the same bytes sitting
172
- * inside a longer deposit, and neither the prefix's own node nor its
173
- * ancestors lead to the deposit (measured: the 22-byte prefix of the
174
- * photosynthesis form resolves, is shared by 6 contexts, and does not have
175
- * the form among its ancestors). Leaf ids ARE position-invariant — they are
176
- * content-addressed on single bytes — and `indexSubSpans` already interns a
177
- * flat branch over every canonical WINDOW of a deposit's leaf-id stream, with
178
- * containment edges to the chunks that window spans. A query that is a
179
- * prefix therefore shares those window nodes exactly, and reaches the deposit
180
- * by climbing containment then parents. Nothing is added to the write side;
181
- * this reads an index training already built.
182
- *
183
- * BOUNDED (§2.8), AND WITH NO NEW THRESHOLD. The window whose containment is
184
- * SMALLEST carries the most evidence, and one saturated at `hubBound` carries
185
- * none — that is the same √N reading of "hub" the rest of the mind uses, not
186
- * a tuned knob. The upward walk spends a budget of `hubBound` nodes and
187
- * fans out by W, so a hub query enumerates nothing and the caller stays
188
- * silent rather than guessing (§2.13). Measured on the trained store: the
189
- * photosynthesis form at a one-byte truncation picks a window with 52
190
- * containers, visits 446 nodes, and yields exactly ONE candidate that
191
- * survives the caller's byte compare — the form itself.
192
- *
193
- * These are PROPOSALS only. Every candidate still faces the byte-exact
194
- * prefix compare and all three guards below, so a wrong proposal costs one
195
- * bounded read and can never be voiced (§2.3). */
196
- export declare function formsOpenedBy(ctx: MindContext, query: Uint8Array): number[];