@hviana/sema 0.5.2 → 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 (157) hide show
  1. package/AGENTS.md +115 -53
  2. package/HOW_IT_WORKS.md +291 -184
  3. package/jsr.json +6 -0
  4. package/package.json +1 -1
  5. package/src/mind/bridge.ts +10 -104
  6. package/src/mind/match.ts +497 -7
  7. package/src/mind/{prefix-completion.ts → mechanisms/prefix-completion.ts} +66 -92
  8. package/src/mind/mechanisms/recall.ts +38 -129
  9. package/src/mind/mechanisms/reference.ts +343 -0
  10. package/src/mind/mind.ts +12 -8
  11. package/src/mind/pipeline-mechanism.ts +120 -3
  12. package/src/mind/pipeline.ts +16 -2
  13. package/src/mind/traverse.ts +92 -1
  14. package/src/store.ts +13 -4
  15. package/test/33-multi-candidate.test.mjs +21 -11
  16. package/test/70-prefix-completion.test.mjs +1 -1
  17. package/test/72-prefix-candidate-supply.test.mjs +7 -9
  18. package/test/74-prefix-trap-not-sprung-early.test.mjs +1 -1
  19. package/test/76-reference-binding.test.mjs +543 -0
  20. package/dist/example/demo.d.ts +0 -1
  21. package/dist/example/demo.js +0 -39
  22. package/dist/example/train_base.d.ts +0 -93
  23. package/dist/example/train_base.js +0 -2269
  24. package/dist/src/alphabet.d.ts +0 -7
  25. package/dist/src/alphabet.js +0 -33
  26. package/dist/src/alu/src/alu.d.ts +0 -185
  27. package/dist/src/alu/src/alu.js +0 -440
  28. package/dist/src/alu/src/expr.d.ts +0 -61
  29. package/dist/src/alu/src/expr.js +0 -318
  30. package/dist/src/alu/src/index.d.ts +0 -11
  31. package/dist/src/alu/src/index.js +0 -19
  32. package/dist/src/alu/src/kernel-arith.d.ts +0 -16
  33. package/dist/src/alu/src/kernel-arith.js +0 -264
  34. package/dist/src/alu/src/kernel-bits.d.ts +0 -19
  35. package/dist/src/alu/src/kernel-bits.js +0 -152
  36. package/dist/src/alu/src/kernel-logic.d.ts +0 -4
  37. package/dist/src/alu/src/kernel-logic.js +0 -60
  38. package/dist/src/alu/src/kernel-nd.d.ts +0 -3
  39. package/dist/src/alu/src/kernel-nd.js +0 -208
  40. package/dist/src/alu/src/kernel-numeric.d.ts +0 -54
  41. package/dist/src/alu/src/kernel-numeric.js +0 -366
  42. package/dist/src/alu/src/operation.d.ts +0 -168
  43. package/dist/src/alu/src/operation.js +0 -189
  44. package/dist/src/alu/src/parser.d.ts +0 -221
  45. package/dist/src/alu/src/parser.js +0 -577
  46. package/dist/src/alu/src/resonance.d.ts +0 -55
  47. package/dist/src/alu/src/resonance.js +0 -126
  48. package/dist/src/alu/src/text.d.ts +0 -31
  49. package/dist/src/alu/src/text.js +0 -73
  50. package/dist/src/alu/src/value.d.ts +0 -109
  51. package/dist/src/alu/src/value.js +0 -300
  52. package/dist/src/alu/test/alu.test.d.ts +0 -1
  53. package/dist/src/alu/test/alu.test.js +0 -764
  54. package/dist/src/bytes.d.ts +0 -14
  55. package/dist/src/bytes.js +0 -59
  56. package/dist/src/canon.d.ts +0 -45
  57. package/dist/src/canon.js +0 -85
  58. package/dist/src/config.d.ts +0 -111
  59. package/dist/src/config.js +0 -91
  60. package/dist/src/derive/src/deduction.d.ts +0 -136
  61. package/dist/src/derive/src/deduction.js +0 -159
  62. package/dist/src/derive/src/index.d.ts +0 -8
  63. package/dist/src/derive/src/index.js +0 -11
  64. package/dist/src/derive/src/priority-queue.d.ts +0 -20
  65. package/dist/src/derive/src/priority-queue.js +0 -73
  66. package/dist/src/derive/src/rewrite.d.ts +0 -56
  67. package/dist/src/derive/src/rewrite.js +0 -100
  68. package/dist/src/derive/src/trie.d.ts +0 -90
  69. package/dist/src/derive/src/trie.js +0 -217
  70. package/dist/src/derive/test/derive.test.d.ts +0 -1
  71. package/dist/src/derive/test/derive.test.js +0 -122
  72. package/dist/src/extension.d.ts +0 -37
  73. package/dist/src/extension.js +0 -7
  74. package/dist/src/geometry.d.ts +0 -233
  75. package/dist/src/geometry.js +0 -1089
  76. package/dist/src/index.d.ts +0 -17
  77. package/dist/src/index.js +0 -19
  78. package/dist/src/ingest-cache.d.ts +0 -41
  79. package/dist/src/ingest-cache.js +0 -165
  80. package/dist/src/meter.d.ts +0 -176
  81. package/dist/src/meter.js +0 -274
  82. package/dist/src/mind/articulation.d.ts +0 -6
  83. package/dist/src/mind/articulation.js +0 -99
  84. package/dist/src/mind/attention.d.ts +0 -430
  85. package/dist/src/mind/attention.js +0 -2418
  86. package/dist/src/mind/bridge.d.ts +0 -39
  87. package/dist/src/mind/bridge.js +0 -998
  88. package/dist/src/mind/canonical.d.ts +0 -34
  89. package/dist/src/mind/canonical.js +0 -93
  90. package/dist/src/mind/frame-filler.d.ts +0 -15
  91. package/dist/src/mind/frame-filler.js +0 -535
  92. package/dist/src/mind/graph-search.d.ts +0 -294
  93. package/dist/src/mind/graph-search.js +0 -996
  94. package/dist/src/mind/index.d.ts +0 -9
  95. package/dist/src/mind/index.js +0 -5
  96. package/dist/src/mind/junction.d.ts +0 -137
  97. package/dist/src/mind/junction.js +0 -358
  98. package/dist/src/mind/learning.d.ts +0 -75
  99. package/dist/src/mind/learning.js +0 -265
  100. package/dist/src/mind/match.d.ts +0 -192
  101. package/dist/src/mind/match.js +0 -666
  102. package/dist/src/mind/mechanisms/alu.d.ts +0 -4
  103. package/dist/src/mind/mechanisms/alu.js +0 -36
  104. package/dist/src/mind/mechanisms/cast.d.ts +0 -89
  105. package/dist/src/mind/mechanisms/cast.js +0 -1186
  106. package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
  107. package/dist/src/mind/mechanisms/confluence.js +0 -271
  108. package/dist/src/mind/mechanisms/cover.d.ts +0 -6
  109. package/dist/src/mind/mechanisms/cover.js +0 -232
  110. package/dist/src/mind/mechanisms/extraction.d.ts +0 -33
  111. package/dist/src/mind/mechanisms/extraction.js +0 -327
  112. package/dist/src/mind/mechanisms/recall.d.ts +0 -16
  113. package/dist/src/mind/mechanisms/recall.js +0 -558
  114. package/dist/src/mind/mind.d.ts +0 -386
  115. package/dist/src/mind/mind.js +0 -754
  116. package/dist/src/mind/pipeline-mechanism.d.ts +0 -183
  117. package/dist/src/mind/pipeline-mechanism.js +0 -521
  118. package/dist/src/mind/pipeline.d.ts +0 -49
  119. package/dist/src/mind/pipeline.js +0 -331
  120. package/dist/src/mind/prefix-completion.d.ts +0 -59
  121. package/dist/src/mind/prefix-completion.js +0 -270
  122. package/dist/src/mind/primitives.d.ts +0 -85
  123. package/dist/src/mind/primitives.js +0 -333
  124. package/dist/src/mind/rationale.d.ts +0 -139
  125. package/dist/src/mind/rationale.js +0 -163
  126. package/dist/src/mind/reasoning.d.ts +0 -42
  127. package/dist/src/mind/reasoning.js +0 -305
  128. package/dist/src/mind/recognition.d.ts +0 -20
  129. package/dist/src/mind/recognition.js +0 -696
  130. package/dist/src/mind/resonance.d.ts +0 -35
  131. package/dist/src/mind/resonance.js +0 -365
  132. package/dist/src/mind/trace.d.ts +0 -15
  133. package/dist/src/mind/trace.js +0 -73
  134. package/dist/src/mind/traverse.d.ts +0 -158
  135. package/dist/src/mind/traverse.js +0 -716
  136. package/dist/src/mind/types.d.ts +0 -418
  137. package/dist/src/mind/types.js +0 -179
  138. package/dist/src/rabitq-ivf/src/database.d.ts +0 -113
  139. package/dist/src/rabitq-ivf/src/database.js +0 -201
  140. package/dist/src/rabitq-ivf/src/index.d.ts +0 -7
  141. package/dist/src/rabitq-ivf/src/index.js +0 -4
  142. package/dist/src/rabitq-ivf/src/ivf.d.ts +0 -200
  143. package/dist/src/rabitq-ivf/src/ivf.js +0 -1165
  144. package/dist/src/rabitq-ivf/src/prng.d.ts +0 -19
  145. package/dist/src/rabitq-ivf/src/prng.js +0 -36
  146. package/dist/src/rabitq-ivf/src/rabitq.d.ts +0 -95
  147. package/dist/src/rabitq-ivf/src/rabitq.js +0 -313
  148. package/dist/src/sema.d.ts +0 -41
  149. package/dist/src/sema.js +0 -77
  150. package/dist/src/store-sqlite.d.ts +0 -184
  151. package/dist/src/store-sqlite.js +0 -942
  152. package/dist/src/store.d.ts +0 -762
  153. package/dist/src/store.js +0 -1823
  154. package/dist/src/vec.d.ts +0 -31
  155. package/dist/src/vec.js +0 -109
  156. package/src/mind/frame-filler.ts +0 -604
  157. package/test/69-frame-filler.test.mjs +0 -115
@@ -1,183 +0,0 @@
1
- import type { AncestorReach, MindContext, Recognition } from "./types.js";
2
- import type { AttentionRead } from "./types.js";
3
- import type { ComputedSpan } from "../extension.js";
4
- import type { Vec } from "../vec.js";
5
- import { type GradedRun } from "./match.js";
6
- export declare class Precomputed {
7
- readonly ctx: MindContext;
8
- readonly query: Uint8Array;
9
- /** Recognition result (structural + canonical). */
10
- readonly rec: Recognition;
11
- /** Computed spans from mechanisms that implement `parse()` (e.g. ALU). */
12
- readonly computed: ComputedSpan[];
13
- /** The query's gist — the response-wide disambiguation guide. */
14
- readonly guide: Vec;
15
- /** The response's evidence-breadth constant: how many ranked candidates the
16
- * resonance probes, the weave alignment, and the climb all consider.
17
- * Derived once from config; every consumer reads it here. */
18
- readonly k: number;
19
- constructor(ctx: MindContext, query: Uint8Array,
20
- /** Recognition result (structural + canonical). */
21
- rec: Recognition,
22
- /** Computed spans from mechanisms that implement `parse()` (e.g. ALU). */
23
- computed: ComputedSpan[],
24
- /** The query's gist — the response-wide disambiguation guide. */
25
- guide: Vec);
26
- private _windows?;
27
- /** Content-addressed W-window identities for every position in the query
28
- * (offset → node id). O(|query|) probes. */
29
- get queryWindows(): Map<number, number>;
30
- private _resolved?;
31
- /** The node id of the query itself, or null when it is not a stored form.
32
- * O(|query|) probes. */
33
- get queryResolved(): number | null;
34
- private _anchorWindows;
35
- /** Content-addressed W-window identities of one anchor's own bytes
36
- * (offset → node id), memoised per anchor. Confluence intersects these;
37
- * any future identity-based mechanism reads the same cache. */
38
- windowsOf(anchor: number): Map<number, number>;
39
- /** Shared memo for {@link reachOf} (structural-IDF reads): a window's
40
- * ancestor reach is a pure function of the read-only store, so one memo
41
- * serves every mechanism that prices commonality — AND the consensus
42
- * climb, which is the largest consumer and used to build its own. The
43
- * ONE definition of its lifetime lives in traverse.ts
44
- * ({@link sharedReachMemo}): session-scoped between writes and always cold
45
- * under a trace. */
46
- private _reach?;
47
- get reachMemo(): Map<number, AncestorReach>;
48
- /** Charge a lazily-shared analysis to its OWN phase rather than to the
49
- * mechanism that happened to first-touch it. Without this the profile
50
- * reads as "cast.floor costs 2 s" when what actually cost 2 s is the
51
- * consensus climb — which cast merely paid for on everyone's behalf, and
52
- * which every later consumer then got free. Attribution must follow the
53
- * work, not the caller. */
54
- private shared;
55
- private _attention?;
56
- /** The full consensus climb (roots + ranked anchors) — the query-level
57
- * evidence CAST, confluence, extraction, recall's scaffolding tier, and
58
- * fusion all share. Computed on first access; a query no mechanism
59
- * climbs for (e.g. one an extension decided outright) never pays for it. */
60
- attention(): Promise<AttentionRead>;
61
- private _weave?;
62
- /** Result of {@link alignGraded} for the first k ranked anchors —
63
- * O(k · |query| · |ctx|). Consumed by CAST; reusable by any future
64
- * mechanism doing analogical transfer. */
65
- weave(): Promise<WeaveInfo>;
66
- /** Span-shaped classification of one ranked anchor, memoised per anchor id
67
- * so repeated calls (extraction's own early-exit scan, any future
68
- * template-based mechanism) never redo the work. Deliberately NOT an
69
- * eager all-anchors map: `skillExemplar` is the expensive part of
70
- * extraction (capped fan-out reads plus an O(|ctx|) scan), and most
71
- * queries are answered by the FIRST ranked anchor that qualifies — paying
72
- * for every ranked anchor regardless of where the scan stops would turn
73
- * an early-exit lookup into full O(k) work on every query. */
74
- private _spanShaped;
75
- spanShapedOf(anchor: number): Promise<SkillInfo | null>;
76
- /** Every ranked anchor's classification at once, sharing the same
77
- * per-anchor cache as {@link spanShapedOf} — for a mechanism that
78
- * genuinely needs the full picture (not an early-exit scan). Mixing
79
- * access patterns across mechanisms never duplicates work: whichever
80
- * anchors an early-exit consumer already asked for are reused here, and
81
- * whichever this computes first are reused by a later early-exit scan. */
82
- spanShapedAll(): Promise<Map<number, SkillInfo | null>>;
83
- }
84
- /** The weave-local structural alignment, computed once and consumed by CAST
85
- * (and any future mechanism doing analogical transfer). */
86
- export interface WeaveInfo {
87
- /** Per-anchor alignment: context bytes, vote weight, and graded runs. */
88
- points: Array<{
89
- anchor: number;
90
- vote: number;
91
- ctx: Uint8Array;
92
- runs: GradedRun[];
93
- /** The query span the CLIMB elected this anchor from — its evidence,
94
- * independent of any literal run alignment (see Attention.start/end). */
95
- start: number;
96
- end: number;
97
- }>;
98
- /** Weighted depth at each query byte — sum of alignment weights.
99
- * `depth[i]` is the total evidence that byte i is shared among the
100
- * aligned structures. */
101
- depth: Float64Array;
102
- }
103
- /** Span-shaped classification of one anchor — the structural information
104
- * extraction uses to decide whether a learned fact can serve as a template
105
- * for reading an analogous span out of the query. */
106
- export interface SkillInfo {
107
- contextBytes: Uint8Array;
108
- answerBytes: Uint8Array;
109
- }
110
- /** Raw result from a mechanism's `run()`. The pipeline computes the weight
111
- * from `moves` + `PASS * unaccounted(accounted)` — the mechanism does not
112
- * know about the cost ladder.
113
- *
114
- * When `weight` is present, the pipeline uses it directly instead of
115
- * computing `weigh(accounted, moves)`. This is for mechanisms whose cost
116
- * is derived externally (e.g. cover: the A*LD derivation's g-value). */
117
- export interface MechanismResult {
118
- bytes: Uint8Array;
119
- accounted: Array<[number, number]>;
120
- moves: number;
121
- used?: ReadonlySet<number>;
122
- unexplained: string;
123
- /** Explicit weight override. When absent, weight = moves + PASS·unaccounted. */
124
- weight?: number;
125
- /** Bytes of `bytes` that came from spans nothing recognised — the asker's
126
- * own words carried through verbatim rather than derived (see
127
- * {@link liftedScaffolding}). Reported, not priced: the ladder prices what
128
- * a candidate leaves UNACCOUNTED, and this orders candidates that tie on
129
- * exactly that. Omit when a mechanism composes its answer entirely from
130
- * recognised material, which is the usual case. */
131
- scaffolding?: number;
132
- /** Override the mechanism's default provenance for this result.
133
- * When absent, the pipeline uses `mech.provenance`. */
134
- provenance?: string;
135
- /** This grounding is a COMPLETE trained answer — post-grounding must not
136
- * extend it. Declared by the mechanism about its own result, exactly like
137
- * `accounted`/`used`/`unexplained`; the decider honours the property and
138
- * never asks which mechanism set it, so the market stays uniform.
139
- *
140
- * Set it only when the answer is a stored form's OWN continuation reached
141
- * through an identity claim about the query — i.e. the query IS some
142
- * trained context, so its continuation is the whole read-out and a further
143
- * multi-hop pivot would chain PAST the fact that produced the answer.
144
- * That is the same reasoning `reason`'s echo guard already applies to a
145
- * query that resolves exactly (see reasoning.ts); this carries the claim
146
- * for the mechanisms that establish the identity by another route.
147
- *
148
- * Observed without it: the correct "What is the process of
149
- * photosynthesis?" grounding was pivoted forward four times, out of the
150
- * fact that answered it and into an unrelated "Hello! How can I assist you
151
- * today?" conversational turn. */
152
- complete?: boolean;
153
- }
154
- export interface PipelineMechanism {
155
- /** Stable identifier for trace/debug. */
156
- readonly name: string;
157
- /** Which provenance tag the pipeline attaches to this mechanism's answers. */
158
- readonly provenance: string;
159
- /** Parse authoritative spans BEFORE the grounding loop.
160
- * Only needed by computational mechanisms (e.g. ALU). Results from ALL
161
- * mechanisms that implement this are collected into `Precomputed.computed`
162
- * before any `floor()` or `run()` is called. */
163
- parse?(query: Uint8Array): Promise<ComputedSpan[]>;
164
- /** Admissible lower bound on this mechanism's weight.
165
- * Returns `null` when the mechanism structurally cannot fire.
166
- *
167
- * `worthRunning(cheapFloor)` reports whether the CURRENT incumbent
168
- * (established by mechanisms that already ran this response, cover being
169
- * first — see `defaultMechanisms`) could still be beaten by a floor no
170
- * tighter than `cheapFloor`. THE INVESTMENT DISCIPLINE: before
171
- * first-touching an expensive shared analysis (`pre.attention()`,
172
- * `pre.weave()`, …), check `worthRunning(bound)` with this mechanism's
173
- * cheapest possible bound — and when it fails, RETURN THE BOUND rather
174
- * than null. The bound is still admissible (it never overstates cost),
175
- * the pipeline's own check then prunes `run()` and records the truthful
176
- * "cannot beat incumbent" trace note, and no analysis was computed just
177
- * to be discarded. This is uniform: no mechanism asks what produced the
178
- * incumbent — a computed extension result and an ordinary cheap cover
179
- * prune the same way. */
180
- floor(ctx: MindContext, query: Uint8Array, pre: Precomputed, worthRunning: (floor: number) => boolean): Promise<number | null>;
181
- /** Produce candidate answers. */
182
- run(ctx: MindContext, query: Uint8Array, pre: Precomputed): Promise<MechanismResult[]>;
183
- }