@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.
- package/AGENTS.md +115 -53
- package/HOW_IT_WORKS.md +291 -184
- package/jsr.json +6 -0
- package/package.json +1 -1
- package/src/mind/bridge.ts +10 -104
- package/src/mind/match.ts +497 -7
- package/src/mind/{prefix-completion.ts → mechanisms/prefix-completion.ts} +66 -92
- package/src/mind/mechanisms/recall.ts +38 -129
- package/src/mind/mechanisms/reference.ts +343 -0
- package/src/mind/mind.ts +12 -8
- package/src/mind/pipeline-mechanism.ts +120 -3
- package/src/mind/pipeline.ts +16 -2
- package/src/mind/traverse.ts +92 -1
- package/src/store.ts +13 -4
- package/test/33-multi-candidate.test.mjs +21 -11
- package/test/70-prefix-completion.test.mjs +1 -1
- package/test/72-prefix-candidate-supply.test.mjs +7 -9
- package/test/74-prefix-trap-not-sprung-early.test.mjs +1 -1
- package/test/76-reference-binding.test.mjs +543 -0
- package/dist/example/demo.d.ts +0 -1
- package/dist/example/demo.js +0 -39
- package/dist/example/train_base.d.ts +0 -93
- package/dist/example/train_base.js +0 -2269
- package/dist/src/alphabet.d.ts +0 -7
- package/dist/src/alphabet.js +0 -33
- package/dist/src/alu/src/alu.d.ts +0 -185
- package/dist/src/alu/src/alu.js +0 -440
- package/dist/src/alu/src/expr.d.ts +0 -61
- package/dist/src/alu/src/expr.js +0 -318
- package/dist/src/alu/src/index.d.ts +0 -11
- package/dist/src/alu/src/index.js +0 -19
- package/dist/src/alu/src/kernel-arith.d.ts +0 -16
- package/dist/src/alu/src/kernel-arith.js +0 -264
- package/dist/src/alu/src/kernel-bits.d.ts +0 -19
- package/dist/src/alu/src/kernel-bits.js +0 -152
- package/dist/src/alu/src/kernel-logic.d.ts +0 -4
- package/dist/src/alu/src/kernel-logic.js +0 -60
- package/dist/src/alu/src/kernel-nd.d.ts +0 -3
- package/dist/src/alu/src/kernel-nd.js +0 -208
- package/dist/src/alu/src/kernel-numeric.d.ts +0 -54
- package/dist/src/alu/src/kernel-numeric.js +0 -366
- package/dist/src/alu/src/operation.d.ts +0 -168
- package/dist/src/alu/src/operation.js +0 -189
- package/dist/src/alu/src/parser.d.ts +0 -221
- package/dist/src/alu/src/parser.js +0 -577
- package/dist/src/alu/src/resonance.d.ts +0 -55
- package/dist/src/alu/src/resonance.js +0 -126
- package/dist/src/alu/src/text.d.ts +0 -31
- package/dist/src/alu/src/text.js +0 -73
- package/dist/src/alu/src/value.d.ts +0 -109
- package/dist/src/alu/src/value.js +0 -300
- package/dist/src/alu/test/alu.test.d.ts +0 -1
- package/dist/src/alu/test/alu.test.js +0 -764
- package/dist/src/bytes.d.ts +0 -14
- package/dist/src/bytes.js +0 -59
- package/dist/src/canon.d.ts +0 -45
- package/dist/src/canon.js +0 -85
- package/dist/src/config.d.ts +0 -111
- package/dist/src/config.js +0 -91
- package/dist/src/derive/src/deduction.d.ts +0 -136
- package/dist/src/derive/src/deduction.js +0 -159
- package/dist/src/derive/src/index.d.ts +0 -8
- package/dist/src/derive/src/index.js +0 -11
- package/dist/src/derive/src/priority-queue.d.ts +0 -20
- package/dist/src/derive/src/priority-queue.js +0 -73
- package/dist/src/derive/src/rewrite.d.ts +0 -56
- package/dist/src/derive/src/rewrite.js +0 -100
- package/dist/src/derive/src/trie.d.ts +0 -90
- package/dist/src/derive/src/trie.js +0 -217
- package/dist/src/derive/test/derive.test.d.ts +0 -1
- package/dist/src/derive/test/derive.test.js +0 -122
- package/dist/src/extension.d.ts +0 -37
- package/dist/src/extension.js +0 -7
- package/dist/src/geometry.d.ts +0 -233
- package/dist/src/geometry.js +0 -1089
- package/dist/src/index.d.ts +0 -17
- package/dist/src/index.js +0 -19
- package/dist/src/ingest-cache.d.ts +0 -41
- package/dist/src/ingest-cache.js +0 -165
- package/dist/src/meter.d.ts +0 -176
- package/dist/src/meter.js +0 -274
- package/dist/src/mind/articulation.d.ts +0 -6
- package/dist/src/mind/articulation.js +0 -99
- package/dist/src/mind/attention.d.ts +0 -430
- package/dist/src/mind/attention.js +0 -2418
- package/dist/src/mind/bridge.d.ts +0 -39
- package/dist/src/mind/bridge.js +0 -998
- package/dist/src/mind/canonical.d.ts +0 -34
- package/dist/src/mind/canonical.js +0 -93
- package/dist/src/mind/frame-filler.d.ts +0 -15
- package/dist/src/mind/frame-filler.js +0 -535
- package/dist/src/mind/graph-search.d.ts +0 -294
- package/dist/src/mind/graph-search.js +0 -996
- package/dist/src/mind/index.d.ts +0 -9
- package/dist/src/mind/index.js +0 -5
- package/dist/src/mind/junction.d.ts +0 -137
- package/dist/src/mind/junction.js +0 -358
- package/dist/src/mind/learning.d.ts +0 -75
- package/dist/src/mind/learning.js +0 -265
- package/dist/src/mind/match.d.ts +0 -192
- package/dist/src/mind/match.js +0 -666
- package/dist/src/mind/mechanisms/alu.d.ts +0 -4
- package/dist/src/mind/mechanisms/alu.js +0 -36
- package/dist/src/mind/mechanisms/cast.d.ts +0 -89
- package/dist/src/mind/mechanisms/cast.js +0 -1186
- package/dist/src/mind/mechanisms/confluence.d.ts +0 -24
- package/dist/src/mind/mechanisms/confluence.js +0 -271
- package/dist/src/mind/mechanisms/cover.d.ts +0 -6
- package/dist/src/mind/mechanisms/cover.js +0 -232
- package/dist/src/mind/mechanisms/extraction.d.ts +0 -33
- package/dist/src/mind/mechanisms/extraction.js +0 -327
- package/dist/src/mind/mechanisms/recall.d.ts +0 -16
- package/dist/src/mind/mechanisms/recall.js +0 -558
- package/dist/src/mind/mind.d.ts +0 -386
- package/dist/src/mind/mind.js +0 -754
- package/dist/src/mind/pipeline-mechanism.d.ts +0 -183
- package/dist/src/mind/pipeline-mechanism.js +0 -521
- package/dist/src/mind/pipeline.d.ts +0 -49
- package/dist/src/mind/pipeline.js +0 -331
- package/dist/src/mind/prefix-completion.d.ts +0 -59
- package/dist/src/mind/prefix-completion.js +0 -270
- package/dist/src/mind/primitives.d.ts +0 -85
- package/dist/src/mind/primitives.js +0 -333
- package/dist/src/mind/rationale.d.ts +0 -139
- package/dist/src/mind/rationale.js +0 -163
- package/dist/src/mind/reasoning.d.ts +0 -42
- package/dist/src/mind/reasoning.js +0 -305
- package/dist/src/mind/recognition.d.ts +0 -20
- package/dist/src/mind/recognition.js +0 -696
- package/dist/src/mind/resonance.d.ts +0 -35
- package/dist/src/mind/resonance.js +0 -365
- package/dist/src/mind/trace.d.ts +0 -15
- package/dist/src/mind/trace.js +0 -73
- package/dist/src/mind/traverse.d.ts +0 -158
- package/dist/src/mind/traverse.js +0 -716
- package/dist/src/mind/types.d.ts +0 -418
- package/dist/src/mind/types.js +0 -179
- package/dist/src/rabitq-ivf/src/database.d.ts +0 -113
- package/dist/src/rabitq-ivf/src/database.js +0 -201
- package/dist/src/rabitq-ivf/src/index.d.ts +0 -7
- package/dist/src/rabitq-ivf/src/index.js +0 -4
- package/dist/src/rabitq-ivf/src/ivf.d.ts +0 -200
- package/dist/src/rabitq-ivf/src/ivf.js +0 -1165
- package/dist/src/rabitq-ivf/src/prng.d.ts +0 -19
- package/dist/src/rabitq-ivf/src/prng.js +0 -36
- package/dist/src/rabitq-ivf/src/rabitq.d.ts +0 -95
- package/dist/src/rabitq-ivf/src/rabitq.js +0 -313
- package/dist/src/sema.d.ts +0 -41
- package/dist/src/sema.js +0 -77
- package/dist/src/store-sqlite.d.ts +0 -184
- package/dist/src/store-sqlite.js +0 -942
- package/dist/src/store.d.ts +0 -762
- package/dist/src/store.js +0 -1823
- package/dist/src/vec.d.ts +0 -31
- package/dist/src/vec.js +0 -109
- package/src/mind/frame-filler.ts +0 -604
- 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
|
-
}
|