@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.
- package/AGENTS.md +6 -6
- package/HOW_IT_WORKS.md +16 -0
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/mind/match.ts +81 -0
- package/src/mind/mechanisms/recall.ts +29 -3
- package/test/76-reference-binding.test.mjs +72 -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 -37
- package/dist/src/mind/bridge.js +0 -907
- package/dist/src/mind/canonical.d.ts +0 -34
- package/dist/src/mind/canonical.js +0 -93
- 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 -351
- package/dist/src/mind/match.js +0 -959
- 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/prefix-completion.d.ts +0 -22
- package/dist/src/mind/mechanisms/prefix-completion.js +0 -243
- package/dist/src/mind/mechanisms/recall.d.ts +0 -16
- package/dist/src/mind/mechanisms/recall.js +0 -460
- package/dist/src/mind/mechanisms/reference.d.ts +0 -6
- package/dist/src/mind/mechanisms/reference.js +0 -296
- 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 -238
- package/dist/src/mind/pipeline-mechanism.js +0 -622
- package/dist/src/mind/pipeline.d.ts +0 -49
- package/dist/src/mind/pipeline.js +0 -343
- 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 -196
- package/dist/src/mind/traverse.js +0 -806
- 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
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
// mechanisms/reference.ts — Reference: voice a slot with the context's own
|
|
2
|
-
// bytes (Grounding IV).
|
|
3
|
-
//
|
|
4
|
-
// This file is a CONFIGURATION of the shared frame reading in match.ts, not a
|
|
5
|
-
// pipeline of its own. The three parts it configures live where §2.5 puts
|
|
6
|
-
// them and are reachable by any mechanism:
|
|
7
|
-
//
|
|
8
|
-
// matcher Precomputed.frames() — the frame INVENTORY: which ranked
|
|
9
|
-
// candidates read as instances of the query's own frame, and
|
|
10
|
-
// where each leaves the query VARIABLE. Shared, election-free.
|
|
11
|
-
// projection follow() — each instance's own learnt continuation.
|
|
12
|
-
// gate carriesFillers() — the carriage licence.
|
|
13
|
-
//
|
|
14
|
-
// What this file adds is the reading and the price: elect one frame from the
|
|
15
|
-
// inventory, demand the licence of it, splice, and state the cost.
|
|
16
|
-
//
|
|
17
|
-
// WHAT KIND OF ACT THIS IS. bridge.ts refuses this shape and is right to:
|
|
18
|
-
// `attestedQ` demands the query-side span be corpus-attested, because a
|
|
19
|
-
// SUBSTITUTION asserts equivalence ("these two spans mean the same"), and
|
|
20
|
-
// nothing can corroborate an equivalence claim about bytes the corpus has
|
|
21
|
-
// never seen. A REFERENCE asserts no equivalence. It asserts POSITION —
|
|
22
|
-
// "this is the thing you named, where the corpus keeps one" — and the bytes
|
|
23
|
-
// come from the asker, so voicing them cannot fabricate corpus knowledge.
|
|
24
|
-
// What CAN be fabricated is the relation claimed about them, which is exactly
|
|
25
|
-
// what the licence withholds.
|
|
26
|
-
//
|
|
27
|
-
// The same reasoning is why the bridge is NOT rewired to consult the frame
|
|
28
|
-
// inventory, though it is now free to: the bridge grounds through its
|
|
29
|
-
// candidate's continuation UNSUBSTITUTED, so admitting a slot-gap there would
|
|
30
|
-
// voice the corpus's filler for the asker's referent — the misreference
|
|
31
|
-
// measured live on the trained store ("How do you say 'flurbish' in French?"
|
|
32
|
-
// answered "the way to say hello is \"Bonjour\""). Nor is CAST rewired: its
|
|
33
|
-
// frame gate is WEAVE-local while a slot is COHORT-local, and substituting one
|
|
34
|
-
// population for the other is the error §2.7 names. The notion is made
|
|
35
|
-
// AVAILABLE, never imposed.
|
|
36
|
-
import { carriesFillers, distinct, follow, substituteAll } from "../match.js";
|
|
37
|
-
import { dominates } from "../../geometry.js";
|
|
38
|
-
import { bytesEqual, indexOf } from "../../bytes.js";
|
|
39
|
-
import { unexplainedLabel } from "../rationale.js";
|
|
40
|
-
import { STEP } from "../graph-search.js";
|
|
41
|
-
import { rItem, rNode, traceFail } from "../trace.js";
|
|
42
|
-
/** The minimum number of instances that can establish a frame. One instance
|
|
43
|
-
* agrees with nothing, so no carriage is attested — the same "two or no
|
|
44
|
-
* constituent" reading frame-filler's contentRuns applies.
|
|
45
|
-
*
|
|
46
|
-
* THIS IS ALSO THE MECHANISM'S REACH. Evidence comes from the shared top-k
|
|
47
|
-
* resonance, so a frame the corpus instantiates only ONCE within k is not
|
|
48
|
-
* reachable here. Measured on the trained store: `How do you say 'flurbish'
|
|
49
|
-
* in French?` finds one instance of its frame in the top 24 — the rest are
|
|
50
|
-
* `How do you make …`, a different frame — so this abstains and recall's
|
|
51
|
-
* scaffolding-dominated tier answers with the CORPUS's filler. That
|
|
52
|
-
* misreference is recall's, and widening the supply is not the fix: the
|
|
53
|
-
* exhaustive √N list recall's refusal path builds costs hundreds of
|
|
54
|
-
* milliseconds and this runs before it. Abstaining on thin evidence is the
|
|
55
|
-
* honest reading (§2.13). */
|
|
56
|
-
const MIN_INSTANCES = 2;
|
|
57
|
-
/** THE VOICING GATES — this mechanism's own reading of a pairing, applied here
|
|
58
|
-
* and NOT in the shared matcher.
|
|
59
|
-
*
|
|
60
|
-
* Every one of these is a requirement for SUBSTITUTING AND SPEAKING, not for
|
|
61
|
-
* knowing where a pairing varies, so each belongs to the consumer that
|
|
62
|
-
* speaks. They lived in `frameSlots` first and made the shared reading
|
|
63
|
-
* reference-shaped: three of four real pairings were hidden from every other
|
|
64
|
-
* consumer, including a definite description standing where a noun stands —
|
|
65
|
-
* the shape the frame filler exists for. A shared layer with one usable
|
|
66
|
-
* consumer is private code at a public address.
|
|
67
|
-
*
|
|
68
|
-
* 1. EVERY slot must be a SUBSTITUTION. An insertion or deletion means the
|
|
69
|
-
* query says more or less than the frame does, and there is no occupant to
|
|
70
|
-
* carry. (A consumer that WANTS insertions — "what did the asker add?" —
|
|
71
|
-
* now sees them; this one cannot use them.)
|
|
72
|
-
* 2. EVERY slot must reach one river window on BOTH sides. Below one window
|
|
73
|
-
* byte overlap is chance, not evidence — the floor identityBar, the
|
|
74
|
-
* bridge's attestedQ and recognition's site test all draw.
|
|
75
|
-
* 3. The FRAME MUST DOMINATE the query, or this is a different sentence that
|
|
76
|
-
* happens to align somewhere. It is also what bounds the slot count
|
|
77
|
-
* without a constant: every slot costs at least a window, and the frame
|
|
78
|
-
* must still be more than half the query.
|
|
79
|
-
* 4. FILLERS PAIRWISE DISTINCT. Two slots holding the same bytes make the
|
|
80
|
-
* occurrence → referent mapping ambiguous, and no evidence resolves it. */
|
|
81
|
-
function voiceable(inst, W, queryLen) {
|
|
82
|
-
if (inst.slots.length === 0)
|
|
83
|
-
return false;
|
|
84
|
-
for (const slot of inst.slots) {
|
|
85
|
-
if (slot.kind !== "substitution")
|
|
86
|
-
return false;
|
|
87
|
-
if (slot.qe - slot.qs < W || slot.ce - slot.cs < W)
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
if (!dominates(inst.covered, queryLen))
|
|
91
|
-
return false;
|
|
92
|
-
return distinct(inst.slots.map((s) => s.filler));
|
|
93
|
-
}
|
|
94
|
-
/** Elect ONE frame from the inventory: the voiceable instances that place
|
|
95
|
-
* their slots in the same query spans.
|
|
96
|
-
*
|
|
97
|
-
* THE ELECTION IS THIS MECHANISM'S, not the inventory's (see
|
|
98
|
-
* Precomputed.frames). Demanding that everything which aligned agree would
|
|
99
|
-
* be the wrong population: the top-k is ranked by gist, not by frame, so it
|
|
100
|
-
* mixes them — measured, `How do you say 'flurbish' in French?` returns one
|
|
101
|
-
* instance of its own frame and a dozen of `How do you make …`, which align
|
|
102
|
-
* on the shared opening and put their slot somewhere else entirely. One
|
|
103
|
-
* dissenting frame would then veto every binding.
|
|
104
|
-
*
|
|
105
|
-
* Instances of ONE frame put their slots in ONE place, so grouping by the
|
|
106
|
-
* whole slot signature and keeping the modal group IS the frame. The
|
|
107
|
-
* signature is every slot, not one: two candidates agreeing about a file name
|
|
108
|
-
* but disagreeing about whether a second thing was named are instances of two
|
|
109
|
-
* different frames, and mixing them would let a one-slot instance vouch for a
|
|
110
|
-
* two-slot binding it says nothing about. */
|
|
111
|
-
function electFrame(inventory, W, queryLen) {
|
|
112
|
-
const bySignature = new Map();
|
|
113
|
-
for (const inst of inventory) {
|
|
114
|
-
if (!voiceable(inst, W, queryLen))
|
|
115
|
-
continue;
|
|
116
|
-
const key = inst.slots.map((s) => `${s.qs}:${s.qe}`).join(",");
|
|
117
|
-
const group = bySignature.get(key);
|
|
118
|
-
if (group === undefined)
|
|
119
|
-
bySignature.set(key, [inst]);
|
|
120
|
-
else
|
|
121
|
-
group.push(inst);
|
|
122
|
-
}
|
|
123
|
-
let best = [];
|
|
124
|
-
for (const group of bySignature.values()) {
|
|
125
|
-
// Ties keep the FIRST group in insertion order, which is resonance rank —
|
|
126
|
-
// corpus-determined, like every other tie-break here (§2.1).
|
|
127
|
-
if (group.length > best.length)
|
|
128
|
-
best = group;
|
|
129
|
-
}
|
|
130
|
-
return best;
|
|
131
|
-
}
|
|
132
|
-
/** Voice the query's referents through their frame's own attested carriage, or
|
|
133
|
-
* null when the corpus does not attest one. */
|
|
134
|
-
export async function bindReference(ctx, query, pre) {
|
|
135
|
-
const t = ctx.trace?.enter("bindReference", [rItem(query, "query")]);
|
|
136
|
-
const fail = traceFail(t);
|
|
137
|
-
const frame = electFrame(await pre.frames(), ctx.space.maxGroup, query.length);
|
|
138
|
-
if (frame.length < MIN_INSTANCES) {
|
|
139
|
-
return fail(`${frame.length} instance(s) of one frame — agreement needs ` +
|
|
140
|
-
`${MIN_INSTANCES}`);
|
|
141
|
-
}
|
|
142
|
-
const slots = frame[0].slots.map((s) => [s.qs, s.qe]);
|
|
143
|
-
const fillersOf = (inst) => inst.slots.map((s) => s.filler);
|
|
144
|
-
const referents = slots.map(([s, e]) => query.subarray(s, e));
|
|
145
|
-
// A referent must be the ASKER's, never the engine's own words. A completed
|
|
146
|
-
// reply stays available to recognition and the climb as context, but quoting
|
|
147
|
-
// it back as a referent launders the engine's own output into evidence — the
|
|
148
|
-
// same rule the weave applies when it aligns only the asker's stream. ANY
|
|
149
|
-
// slot falling inside one refuses the whole binding.
|
|
150
|
-
for (const [rs, re] of slots) {
|
|
151
|
-
for (const [as_, ae] of ctx.answeredSpans) {
|
|
152
|
-
if (rs < ae && as_ < re) {
|
|
153
|
-
return fail("a referent lies inside a completed reply — not the asker's");
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
// Two slots may not name the same bytes, for the same reason two fillers may
|
|
158
|
-
// not (frameSlots applies it to every instance): the mapping from occurrence
|
|
159
|
-
// to referent would be ambiguous.
|
|
160
|
-
if (!distinct(referents)) {
|
|
161
|
-
return fail("two slots name the same bytes — the binding is ambiguous");
|
|
162
|
-
}
|
|
163
|
-
// ── THE LICENCE ────────────────────────────────────────────────────────
|
|
164
|
-
// Every instance must agree, against the first, that its continuation is its
|
|
165
|
-
// own fillers carried through one fixed form. Unanimity, exactly as the
|
|
166
|
-
// bridge's `unanimous` demands of a frame before it will substitute.
|
|
167
|
-
//
|
|
168
|
-
// Continuations are followed ONE AT A TIME, inside the test, because the
|
|
169
|
-
// overwhelmingly common outcome is refusal and a refusal usually comes from
|
|
170
|
-
// the first comparison — a filler-dependent frame disagrees on instance 2 of
|
|
171
|
-
// 12. Reading all of them up front pays the whole cohort's projections to
|
|
172
|
-
// discard them. Each goes through the shared projection, so an ambiguous
|
|
173
|
-
// instance is disambiguated exactly as it would be anywhere else.
|
|
174
|
-
const leadsNowhere = "an instance of the frame leads nowhere";
|
|
175
|
-
const first = await follow(ctx, frame[0].id, pre.guide);
|
|
176
|
-
if (first === null || first.length === 0)
|
|
177
|
-
return fail(leadsNowhere);
|
|
178
|
-
for (let i = 1; i < frame.length; i++) {
|
|
179
|
-
const cont = await follow(ctx, frame[i].id, pre.guide);
|
|
180
|
-
if (cont === null || cont.length === 0)
|
|
181
|
-
return fail(leadsNowhere);
|
|
182
|
-
if (!carriesFillers(first, fillersOf(frame[0]), cont, fillersOf(frame[i]))) {
|
|
183
|
-
ctx.trace?.step("referenceLicence", [rItem(first, "instance"), rNode(ctx, frame[i].id, "against")], [rItem(cont, "attested")], "refused — the frame's answer carries content that depends on WHICH " +
|
|
184
|
-
"filler, so the corpus cannot supply it for a new one");
|
|
185
|
-
return fail("the frame's answer is not a carriage of its fillers");
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
// THE BINDING IS A BYTE CONSTRUCTION, NOT A SEARCH, and deliberately so.
|
|
189
|
-
// Articulation splices through ctx.search.cover because WHICH voicing wins is
|
|
190
|
-
// genuinely searched — several candidate substitutions compete. Here the
|
|
191
|
-
// licence has already determined the substitution byte-exactly; a search that
|
|
192
|
-
// can only confirm a determined result is ceremony, not composition. The
|
|
193
|
-
// precedent is frame-filler, which constructs its lookup key the same way.
|
|
194
|
-
const bytes = substituteAll(first, fillersOf(frame[0]).map((needle, s) => ({ needle, repl: referents[s] })));
|
|
195
|
-
if (bytes.length === 0)
|
|
196
|
-
return fail("the binding produced nothing");
|
|
197
|
-
// Answering with the question is not answering — the same restated-fragment
|
|
198
|
-
// guard every recall tier applies.
|
|
199
|
-
if (bytes.length < query.length && indexOf(query, bytes, 0) >= 0) {
|
|
200
|
-
return fail("the binding restates part of the question");
|
|
201
|
-
}
|
|
202
|
-
const carried = !bytesEqual(bytes, first);
|
|
203
|
-
ctx.trace?.step("bindReferent", [
|
|
204
|
-
...referents.map((r, s) => rItem(r, `referent ${s + 1}`, undefined, slots[s])),
|
|
205
|
-
...frame.map((inst) => rNode(ctx, inst.id, "instance")),
|
|
206
|
-
], [rItem(bytes, "bound")], carried
|
|
207
|
-
? `carry the asker's ${slots.length} referent(s) through the frame's own ` +
|
|
208
|
-
`answer — ${frame.length} instances attest the carriage byte-exactly`
|
|
209
|
-
: `the frame's answer does not depend on its filler(s) — ` +
|
|
210
|
-
`${frame.length} instances attest the same continuation`);
|
|
211
|
-
// WHAT THIS EXPLAINS: the frame it matched literally, AND every slot. A slot
|
|
212
|
-
// is not a hole in the explanation — it is an act this mechanism PAID for,
|
|
213
|
-
// one STEP each in `moves` below, and leaving it unaccounted charges the same
|
|
214
|
-
// act twice (once as a move, once at PASS per byte, which is far the larger).
|
|
215
|
-
// The bridge records the same reasoning for its own substitutions.
|
|
216
|
-
const accounted = [
|
|
217
|
-
...frame[0].matched.filter(([s, e]) => e > s),
|
|
218
|
-
...slots,
|
|
219
|
-
].sort((a, b) => a[0] - b[0]);
|
|
220
|
-
t?.done([rItem(bytes, "answer")], "reference — the asker's referent(s) voiced through a slot the corpus " +
|
|
221
|
-
"attests as a carriage");
|
|
222
|
-
return {
|
|
223
|
-
bytes,
|
|
224
|
-
accounted,
|
|
225
|
-
// The acts: one BINDING per slot plus one edge FOLLOW across the frame's
|
|
226
|
-
// own continuation — the same per-projection price CAST's substitution
|
|
227
|
-
// schema pays for the structurally analogous act. Not CONCEPT: the ladder
|
|
228
|
-
// reserves that for halo-mediated acts, and a reference is decided by byte
|
|
229
|
-
// identity, not distributional company. Per-slot matters: a two-slot
|
|
230
|
-
// binding claims strictly more than a one-slot binding, so where both are
|
|
231
|
-
// licensed the smaller claim wins.
|
|
232
|
-
moves: STEP * slots.length + STEP,
|
|
233
|
-
unexplained: unexplainedLabel(query, accounted),
|
|
234
|
-
// NOT scaffolding. That field counts answer bytes carried through BECAUSE
|
|
235
|
-
// NOTHING EXPLAINED THEM; a referent is carried because the frame's slot
|
|
236
|
-
// explains it, and it is accounted above. Reporting it would make every
|
|
237
|
-
// licensed binding lose its equal-grade tie-breaks by construction.
|
|
238
|
-
//
|
|
239
|
-
// COMPLETE — post-grounding must not extend a binding. The bound answer is
|
|
240
|
-
// a byte string this mechanism CONSTRUCTED; the corpus never said it, so
|
|
241
|
-
// pivoting through it treats the engine's own construction as a trained
|
|
242
|
-
// fact — the same laundering the answeredSpans guard above refuses in the
|
|
243
|
-
// other direction. Measured: with the frame "How do I compile X?" ->
|
|
244
|
-
// "Run gcc X" and a stored "Run gcc main.c" -> "then execute ./a.out", the
|
|
245
|
-
// binding produced "Run gcc main.c" and reason() pivoted straight past it,
|
|
246
|
-
// answering "then execute ./a.out" — the referent gone AND the question
|
|
247
|
-
// unanswered. This is what MechanismResult.complete documents: the query
|
|
248
|
-
// IS a trained context (here, an instance of a trained frame), so its
|
|
249
|
-
// continuation is the whole read-out. Fusion still runs; it is gated on
|
|
250
|
-
// the query REMAINDER, which a binding accounting frame plus slots leaves
|
|
251
|
-
// empty.
|
|
252
|
-
complete: true,
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
// ── Pipeline mechanism ──────────────────────────────────────────────────────
|
|
256
|
-
export const referenceMechanism = {
|
|
257
|
-
name: "reference",
|
|
258
|
-
provenance: "reference",
|
|
259
|
-
async floor(ctx, query, pre, worthRunning) {
|
|
260
|
-
// The floor is exactly one binding plus one follow — the cheapest shape a
|
|
261
|
-
// result can take. INVESTMENT DISCIPLINE: when that already cannot beat
|
|
262
|
-
// the incumbent, return it UNINVESTED rather than first-touching the shared
|
|
263
|
-
// inventory (cast.ts and extraction.ts are the reference implementations).
|
|
264
|
-
const bound = STEP + STEP;
|
|
265
|
-
if (!worthRunning(bound))
|
|
266
|
-
return bound;
|
|
267
|
-
// A frame needs a query long enough to hold one, and a slot needs at least
|
|
268
|
-
// one window of its own beside it.
|
|
269
|
-
if (query.length < 2 * ctx.space.maxGroup)
|
|
270
|
-
return null;
|
|
271
|
-
// A query the store holds outright is not a reference to anything — its own
|
|
272
|
-
// edges answer it, and binding would re-derive what recall reads directly.
|
|
273
|
-
// O(|query|) probes, already computed for this response.
|
|
274
|
-
if (pre.queryResolved !== null)
|
|
275
|
-
return null;
|
|
276
|
-
// NO SCAFFOLDING GATE HERE, DELIBERATELY. `allWindowsAreScaffolding` gates
|
|
277
|
-
// recall's scaffolding-dominated tier and looks like the obvious third
|
|
278
|
-
// gate, but it is calibrated for mechanisms grounding THROUGH the query's
|
|
279
|
-
// stored windows, where "every window is a hub" means the query says
|
|
280
|
-
// nothing the corpus can be held to. A reference query's discriminative
|
|
281
|
-
// content is the SLOT — exactly the part the corpus cannot attest — so the
|
|
282
|
-
// predicate reports "all scaffolding" for the purest references there are.
|
|
283
|
-
// Measured on the byte-modality fixture (test/76): the frame's windows sit
|
|
284
|
-
// in all three instances and the referents' in none, so the gate fired and
|
|
285
|
-
// the mechanism abstained on an answer it had already derived correctly.
|
|
286
|
-
//
|
|
287
|
-
// What holds this honest is not window rarity but the licence: instances
|
|
288
|
-
// agreeing on one slot signature, each leading somewhere, and unanimous
|
|
289
|
-
// BYTE-EXACT carriage across all of them.
|
|
290
|
-
return bound;
|
|
291
|
-
},
|
|
292
|
-
async run(ctx, query, pre) {
|
|
293
|
-
const bound = await bindReference(ctx, query, pre);
|
|
294
|
-
return bound === null ? [] : [bound];
|
|
295
|
-
},
|
|
296
|
-
};
|