@hviana/sema 0.2.2 → 0.2.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/dist/src/mind/articulation.js +1 -1
- package/dist/src/mind/attention.d.ts +18 -2
- package/dist/src/mind/attention.js +88 -18
- package/dist/src/mind/bridge.d.ts +30 -0
- package/dist/src/mind/bridge.js +569 -0
- package/dist/src/mind/graph-search.d.ts +16 -1
- package/dist/src/mind/graph-search.js +34 -5
- package/dist/src/mind/match.d.ts +15 -2
- package/dist/src/mind/match.js +3 -8
- package/dist/src/mind/mechanisms/alu.js +8 -1
- package/dist/src/mind/mechanisms/cast.d.ts +54 -0
- package/dist/src/mind/mechanisms/cast.js +303 -48
- package/dist/src/mind/mechanisms/cover.js +24 -32
- package/dist/src/mind/mechanisms/extraction.js +75 -30
- package/dist/src/mind/mechanisms/recall.js +66 -0
- package/dist/src/mind/mind.d.ts +1 -0
- package/dist/src/mind/mind.js +6 -1
- package/dist/src/mind/pipeline.js +34 -2
- package/dist/src/mind/reasoning.d.ts +20 -1
- package/dist/src/mind/reasoning.js +84 -6
- package/dist/src/mind/recognition.js +157 -13
- package/dist/src/mind/traverse.js +16 -0
- package/dist/src/mind/types.d.ts +65 -2
- package/dist/src/mind/types.js +53 -7
- package/dist/src/store.d.ts +12 -3
- package/dist/src/store.js +9 -3
- package/package.json +1 -1
- package/src/mind/articulation.ts +1 -0
- package/src/mind/attention.ts +105 -17
- package/src/mind/bridge.ts +596 -0
- package/src/mind/graph-search.ts +59 -2
- package/src/mind/match.ts +19 -5
- package/src/mind/mechanisms/alu.ts +8 -1
- package/src/mind/mechanisms/cast.ts +336 -46
- package/src/mind/mechanisms/cover.ts +31 -36
- package/src/mind/mechanisms/extraction.ts +101 -40
- package/src/mind/mechanisms/recall.ts +79 -0
- package/src/mind/mind.ts +7 -1
- package/src/mind/pipeline.ts +37 -2
- package/src/mind/reasoning.ts +97 -5
- package/src/mind/recognition.ts +160 -12
- package/src/mind/traverse.ts +17 -0
- package/src/mind/types.ts +110 -6
- package/src/store.ts +19 -5
- package/test/35-attention-confidence.test.mjs +139 -0
- package/test/36-already-answered-fusion.test.mjs +128 -0
- package/test/37-cluster-dispersion-fusion.test.mjs +190 -0
- package/test/38-reason-restate-guard.test.mjs +94 -0
- package/test/39-cast-restate-guard.test.mjs +102 -0
- package/test/40-choosenext-scale-guard.test.mjs +75 -0
- package/test/41-seatofnode-direction.test.mjs +85 -0
- package/test/42-recognise-trace-idempotence.test.mjs +106 -0
- package/test/43-cast-analog-seat.test.mjs +244 -0
- package/test/44-recognise-edge-whitespace.test.mjs +63 -0
- package/test/45-liftanswer-restated-trim.test.mjs +60 -0
- package/test/46-recognise-multibyte-edge.test.mjs +85 -0
- package/test/47-cast-comparison-coverage.test.mjs +134 -0
- package/test/48-recognise-turn-connective.test.mjs +125 -0
- package/test/49-natural-units-synonym-bridge.test.mjs +175 -0
- package/test/50-cast-analog-consensus-floor.test.mjs +179 -0
|
@@ -11,14 +11,16 @@
|
|
|
11
11
|
// gate = the frame gate below + analogyStrength, projection = insert / project /
|
|
12
12
|
// juxtapose.
|
|
13
13
|
import { read } from "../primitives.js";
|
|
14
|
-
import { argmaxBy, hubBound } from "../traverse.js";
|
|
14
|
+
import { argmaxBy, corpusN, hubBound } from "../traverse.js";
|
|
15
15
|
import { analogyStrength, follow, project, reverseContext, } from "../match.js";
|
|
16
16
|
import { joinWithBridge } from "../resonance.js";
|
|
17
|
+
import { restatesQuery } from "../reasoning.js";
|
|
17
18
|
import { CONCEPT, STEP } from "../graph-search.js";
|
|
18
19
|
import { concat2, indexOf } from "../../bytes.js";
|
|
19
|
-
import { dominates } from "../../geometry.js";
|
|
20
|
-
import { unexplainedLabel } from "../rationale.js";
|
|
20
|
+
import { consensusFloor, dominates } from "../../geometry.js";
|
|
21
|
+
import { unexplainedLabel, unexplainedSpans, } from "../rationale.js";
|
|
21
22
|
import { rItem, rNode } from "../trace.js";
|
|
23
|
+
import { dismissedKnownContent } from "../bridge.js";
|
|
22
24
|
// ── CAST gates ────────────────────────────────────────────────────────────
|
|
23
25
|
//
|
|
24
26
|
// The frame gate has TWO components, both derived from the weave itself:
|
|
@@ -52,6 +54,81 @@ import { rItem, rNode } from "../trace.js";
|
|
|
52
54
|
* minimum: `depth > MIN_WEAVE` means at least three structures agree on a
|
|
53
55
|
* byte, so no byte is frame when only the minimum pair exists. */
|
|
54
56
|
const MIN_WEAVE = 2;
|
|
57
|
+
/** The seat that establishes a node's role in an analogical comparison:
|
|
58
|
+
* the REVERSE context (what leads to it) when a predecessor genuinely
|
|
59
|
+
* ESTABLISHES id — introduces or describes it by name — else the FORWARD
|
|
60
|
+
* continuation (what it leads to), else `fallback`.
|
|
61
|
+
*
|
|
62
|
+
* An earlier version gated this purely on `prevCount(id) > 0`: any
|
|
63
|
+
* predecessor at all was treated as proof of a genuine named ENTITY
|
|
64
|
+
* (seat it by what established it), while no predecessor meant a bare
|
|
65
|
+
* learnt CONTEXT (seat it by what it leads to, since voicing it verbatim
|
|
66
|
+
* would answer a question with a question). That test measured the wrong
|
|
67
|
+
* thing — a broad sample of this store's own question-shaped nodes showed
|
|
68
|
+
* the large majority (≈71%) have at least one predecessor, most of them a
|
|
69
|
+
* handful of generic, high-fan-out sentences that recur as an INCIDENTAL
|
|
70
|
+
* neighbour to dozens of otherwise-unrelated destinations (a SmolSent-
|
|
71
|
+
* style sentence-adjacency artifact, never naming or describing what
|
|
72
|
+
* follows). Traced live: "What is the capital of France?" — whose own
|
|
73
|
+
* forward edge unambiguously resolves to "The capital of France is
|
|
74
|
+
* Paris." — has exactly one such incidental predecessor ("Create an
|
|
75
|
+
* example of a types of questions a GPT model can answer.?"), wrongly
|
|
76
|
+
* read as disqualifying proof of "genuine entity."
|
|
77
|
+
*
|
|
78
|
+
* A plain forward-first swap (matching {@link project}'s universal
|
|
79
|
+
* priority) over-corrected: test/29's C2/C3 pin that a genuine entity
|
|
80
|
+
* analog (e.g. "Leonardo da Vinci", established by "The Mona Lisa was
|
|
81
|
+
* painted by Leonardo da Vinci.") must be seated by that establishing
|
|
82
|
+
* sentence, NOT by its own biography fact — voicing the bio leaks exactly
|
|
83
|
+
* what a comparison must keep out, and loses the embedded "Mona Lisa"
|
|
84
|
+
* term C3 relies on for a further hop.
|
|
85
|
+
*
|
|
86
|
+
* The distinguishing signal is content-addressed, not a count: a genuine
|
|
87
|
+
* establishing predecessor's bytes CONTAIN id's own bytes — it names or
|
|
88
|
+
* describes id ("...painted by Leonardo da Vinci." contains "Leonardo da
|
|
89
|
+
* Vinci"). An incidental adjacency predecessor never does — it merely
|
|
90
|
+
* preceded id in some unrelated document without ever mentioning it. No
|
|
91
|
+
* new tuned constant: containment is the same primitive `restatesQuery`
|
|
92
|
+
* and `dominates`-style checks already use throughout this codebase.
|
|
93
|
+
*
|
|
94
|
+
* `allowForward` (default true) gates the FORWARD branch specifically —
|
|
95
|
+
* see the call sites below: the DOMINANT is what the query is actually
|
|
96
|
+
* ASKING, so completing it forward is the whole point; an ANALOG is only
|
|
97
|
+
* being CITED for comparison; the query never asked about IT, so chasing
|
|
98
|
+
* its own further continuation drifts onto whatever coincidentally
|
|
99
|
+
* follows it in the corpus. Traced live: the analog "What is the capital
|
|
100
|
+
* of Japan?\nTokyo is the capital of Japan." is ALREADY a complete,
|
|
101
|
+
* self-answering unit (prevCount 0, so no establishing predecessor
|
|
102
|
+
* either) — its sole forward edge is "And what is the capital of the
|
|
103
|
+
* Moon?", an unrelated quiz question sharing nothing but corpus
|
|
104
|
+
* adjacency. With forward disallowed, an analog like this falls through
|
|
105
|
+
* to `fallback` — its own bytes, exactly the complete fact that made it a
|
|
106
|
+
* genuine analog in the first place. See
|
|
107
|
+
* test/41-seatofnode-direction.test.mjs and
|
|
108
|
+
* test/43-cast-analog-seat.test.mjs. */
|
|
109
|
+
export async function seatOfNode(ctx, id, guide, fallback, allowForward = true) {
|
|
110
|
+
const rev = ctx.store.prevFirst(id, hubBound(ctx));
|
|
111
|
+
if (rev.length > 0) {
|
|
112
|
+
const own = read(ctx, id);
|
|
113
|
+
const establishing = rev.some((p) => indexOf(read(ctx, p), own, 0) >= 0);
|
|
114
|
+
if (establishing) {
|
|
115
|
+
const back = reverseContext(ctx, id, guide, rev);
|
|
116
|
+
if (back !== null)
|
|
117
|
+
return back;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
// The "last resort, non-establishing reverse" fallback below is itself a
|
|
121
|
+
// LESS CERTAIN projection (the same tier as forward) — an analog
|
|
122
|
+
// (allowForward: false) must stop at `fallback` (its own bytes) here
|
|
123
|
+
// rather than fall back to a predecessor that already failed the
|
|
124
|
+
// establishing check just above.
|
|
125
|
+
if (!allowForward)
|
|
126
|
+
return fallback;
|
|
127
|
+
const fwd = await follow(ctx, id, guide);
|
|
128
|
+
if (fwd !== null)
|
|
129
|
+
return fwd;
|
|
130
|
+
return reverseContext(ctx, id, guide, rev) ?? fallback;
|
|
131
|
+
}
|
|
55
132
|
/** CAST's own entry gates, checked once here and reused by
|
|
56
133
|
/** The main CAST entry point. Given a query and its pre-computed pre.rec.sites,
|
|
57
134
|
* determine whether the query weaves together multiple independent learnt
|
|
@@ -70,19 +147,37 @@ const MIN_WEAVE = 2;
|
|
|
70
147
|
*
|
|
71
148
|
* Returns the array of {@link CastResult}s that fired (possibly empty). */
|
|
72
149
|
export async function counterfactualTransfer(ctx, query, pre) {
|
|
150
|
+
// Opened unconditionally, at entry — the same convention recall.ts's
|
|
151
|
+
// recallByResonance and extraction.ts's extractBySkill use, so every exit
|
|
152
|
+
// path (five gates below, then the schemas themselves) closes through
|
|
153
|
+
// ONE scope and inspectRationale never hits a silent dead end. Only the
|
|
154
|
+
// first two gates duplicate floor()'s own admissible bound (query length,
|
|
155
|
+
// ranked anchor count) — required to stay in sync per this function's own
|
|
156
|
+
// doc comment above, and effectively dead through the ordinary pipeline
|
|
157
|
+
// (floor() returning null already stops run() from being called at all),
|
|
158
|
+
// but this function is also exported and callable directly, so they stay
|
|
159
|
+
// and get the same honest trace as everything past them.
|
|
160
|
+
const t = ctx.trace?.enter("counterfactual", [rItem(query, "query")]);
|
|
161
|
+
const fail = (note) => {
|
|
162
|
+
t?.done([], note);
|
|
163
|
+
return [];
|
|
164
|
+
};
|
|
73
165
|
const quantum = ctx.space.maxGroup;
|
|
74
166
|
if (query.length < 2 * quantum || ctx.store.edgeSourceCount() === 0) {
|
|
75
|
-
return
|
|
167
|
+
return fail("query below the two-quantum floor, or no edges learnt yet");
|
|
76
168
|
}
|
|
77
169
|
const { roots, ranked } = await pre.attention();
|
|
78
|
-
if (ranked.length < 2)
|
|
79
|
-
return
|
|
170
|
+
if (ranked.length < 2) {
|
|
171
|
+
return fail(`only ${ranked.length} ranked anchor(s) — CAST needs at least two`);
|
|
172
|
+
}
|
|
80
173
|
const weave = await pre.weave();
|
|
81
174
|
const points = weave.points;
|
|
82
175
|
const depth = weave.depth;
|
|
83
176
|
const aligned = points.length;
|
|
84
|
-
if (aligned < 2)
|
|
85
|
-
return
|
|
177
|
+
if (aligned < 2) {
|
|
178
|
+
return fail(`only ${aligned} structure(s) aligned across the query — CAST needs ` +
|
|
179
|
+
`at least two to transfer between`);
|
|
180
|
+
}
|
|
86
181
|
// ── Frame gate (half-dominance, weave-local) ─────────────────────────
|
|
87
182
|
// A byte is FRAME when more than MIN_WEAVE aligned structures cover it
|
|
88
183
|
// AND those structures are a majority of all aligned structures.
|
|
@@ -120,14 +215,20 @@ export async function counterfactualTransfer(ctx, query, pre) {
|
|
|
120
215
|
const isRoot = (id) => roots.some((r) => r.anchor === id);
|
|
121
216
|
// The weave must touch a COMMITTED point of attention: the dominant
|
|
122
217
|
// structure itself, or another aligned point the climb committed to.
|
|
123
|
-
if (!points.some((p) => isRoot(p.anchor)))
|
|
218
|
+
if (!points.some((p) => isRoot(p.anchor))) {
|
|
219
|
+
t?.done([
|
|
220
|
+
...points.map((p) => rNode(ctx, p.anchor, "aligned")),
|
|
221
|
+
...roots.map((r) => rNode(ctx, r.anchor, "committed-root")),
|
|
222
|
+
], `${points.length} aligned structure(s), but none is one of the climb's ` +
|
|
223
|
+
`${roots.length} committed root(s) — CAST refuses to transfer through ` +
|
|
224
|
+
`content the climb itself never settled on`);
|
|
124
225
|
return [];
|
|
226
|
+
}
|
|
125
227
|
const woven = points.some((p) => p.runs.some((r) => !pre.rec.sites.some((s) => r.qs >= s.start && r.qe <= s.end)));
|
|
126
|
-
if (!woven)
|
|
127
|
-
return
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
]);
|
|
228
|
+
if (!woven) {
|
|
229
|
+
return fail(`every aligned run restates a recognised query site — nothing was ` +
|
|
230
|
+
`actually WOVEN across structures, so there is nothing to transfer`);
|
|
231
|
+
}
|
|
131
232
|
// Each schema tried below RECORDS its candidate (when it fires) rather than
|
|
132
233
|
// returning immediately — every schema that succeeds contributes its own
|
|
133
234
|
// candidate, and the grounding decider's own weight comparison (not CAST's
|
|
@@ -198,7 +299,8 @@ export async function counterfactualTransfer(ctx, query, pre) {
|
|
|
198
299
|
const tail = proj.ctx.subarray(seat.cs);
|
|
199
300
|
let answer = await joinWithBridge(ctx, filler, tail);
|
|
200
301
|
const fwd = await follow(ctx, proj.anchor, qv);
|
|
201
|
-
if (fwd !== null && indexOf(answer, fwd, 0) < 0
|
|
302
|
+
if (fwd !== null && indexOf(answer, fwd, 0) < 0 &&
|
|
303
|
+
!restatesQuery(query, fwd)) {
|
|
202
304
|
answer = concat2(answer, fwd);
|
|
203
305
|
}
|
|
204
306
|
ctx.trace?.step("projectCounterfactual", [
|
|
@@ -254,30 +356,8 @@ export async function counterfactualTransfer(ctx, query, pre) {
|
|
|
254
356
|
// seed-dependent failure where the climb ranks an exemplar above a
|
|
255
357
|
// person node and the person node is excluded from points by run-
|
|
256
358
|
// overlap trimming.
|
|
257
|
-
// The seat that establishes a candidate's role
|
|
258
|
-
|
|
259
|
-
// candidate's own bytes when it follows nothing. DELIBERATE STRENGTHENING
|
|
260
|
-
// over the pre-refactor code: reverseContext also returns null when the
|
|
261
|
-
// picked context READS EMPTY (a dangling id degrades to zero bytes), so a
|
|
262
|
-
// corrupted-store read now falls back here instead of voicing a hollow
|
|
263
|
-
// seat into the comparison — the same "empty bytes are no grounding"
|
|
264
|
-
// invariant project() has always enforced.
|
|
265
|
-
// A node that only ever CONTINUES — an edge SOURCE with no predecessor —
|
|
266
|
-
// is a learnt CONTEXT (a stored question-shaped frame), not an entity.
|
|
267
|
-
// Voicing it verbatim answers a question with a question (the observed
|
|
268
|
-
// cast echo: two stored questions concatenated as an "answer"). The
|
|
269
|
-
// context's role is established by what it LEADS TO, so its seat is its
|
|
270
|
-
// own continuation — the fact — with the reverse projection and the raw
|
|
271
|
-
// bytes as the ordinary fallbacks for genuine entities.
|
|
272
|
-
const seatOfNode = async (id, fallback) => {
|
|
273
|
-
if (ctx.store.prevCount(id) === 0 && ctx.store.hasNext(id)) {
|
|
274
|
-
const fwd = await follow(ctx, id, qv);
|
|
275
|
-
if (fwd !== null)
|
|
276
|
-
return fwd;
|
|
277
|
-
}
|
|
278
|
-
return reverseContext(ctx, id, qv) ?? fallback;
|
|
279
|
-
};
|
|
280
|
-
const seatOf = (p) => seatOfNode(p.anchor, p.ctx);
|
|
359
|
+
// The seat that establishes a candidate's role — see {@link seatOfNode}.
|
|
360
|
+
const seatOf = (p, allowForward = true) => seatOfNode(ctx, p.anchor, qv, p.ctx, allowForward);
|
|
281
361
|
const analogs = [];
|
|
282
362
|
for (const p of points) {
|
|
283
363
|
if (p === dominant)
|
|
@@ -311,15 +391,49 @@ export async function counterfactualTransfer(ctx, query, pre) {
|
|
|
311
391
|
}
|
|
312
392
|
let bestAnalog = null;
|
|
313
393
|
let bestSim = 0;
|
|
394
|
+
let bestHalo = false;
|
|
395
|
+
// Whether the query itself NAMES a candidate. A directly aligned point
|
|
396
|
+
// is named by construction — its runs ARE query bytes. A hop-reached
|
|
397
|
+
// candidate is named when its own bytes contain the query text of an
|
|
398
|
+
// aligned run of the point whose continuation edge reached it (that
|
|
399
|
+
// alignment IS the query evidence the hop rests on — the same reading
|
|
400
|
+
// cmpAccounted already prices): "William Shakespeare", reached off
|
|
401
|
+
// "Macbeth was written by William Shakespeare.", contains the src's
|
|
402
|
+
// 12-byte aligned run " Shakespeare" — test/29 C2/C3. The run must span
|
|
403
|
+
// at least TWO perception windows (2·W, the same two-quantum floor
|
|
404
|
+
// CAST's own entry gate holds the whole query to): a single shared
|
|
405
|
+
// W-window is exactly the frame tier's own evidence quantum — the level
|
|
406
|
+
// "half the corpus" shares — and stopword scraps (" the ", "he b",
|
|
407
|
+
// 4–5 bytes) never reach two windows, while a genuinely named entity
|
|
408
|
+
// does. NOT the weave's usable()/frame filter: weave depth counts every
|
|
409
|
+
// ranked exemplar, so a query's own named entity recurring across
|
|
410
|
+
// exemplars ("Shakespeare" in Hamlet+Macbeth+…) is wrongly classified as
|
|
411
|
+
// frame — measured live, it silently disqualified C3's genuine analog.
|
|
412
|
+
const namedByQuery = (c) => {
|
|
413
|
+
if (c.point !== null)
|
|
414
|
+
return true;
|
|
415
|
+
const bytes = read(ctx, c.anchor);
|
|
416
|
+
return c.src.runs.some((r) => r.qe - r.qs >= 2 * quantum &&
|
|
417
|
+
indexOf(bytes, query.subarray(r.qs, r.qe), 0) >= 0);
|
|
418
|
+
};
|
|
419
|
+
// Whether any committed root's consensus vote clears the SAME trust bar
|
|
420
|
+
// recallByResonance applies before grounding through a climb root:
|
|
421
|
+
// consensusFloor(N) = ln(N) + 1/2. The climb's FIRST root is
|
|
422
|
+
// deliberately floor-free (attention.ts: "the dominant one always
|
|
423
|
+
// grounds") — fine for ORIENTING mechanisms, not for voicing learnt
|
|
424
|
+
// content the query never asked about. Computed once here; both the
|
|
425
|
+
// hub fallback below and the comparison gate consume it.
|
|
426
|
+
const rootTrusted = roots.some((r) => r.vote >= consensusFloor(corpusN(ctx)));
|
|
314
427
|
for (const c of analogs) {
|
|
315
|
-
const sim = await analogyStrength(ctx, dominant.anchor, c.anchor);
|
|
428
|
+
const { score: sim, halo } = await analogyStrength(ctx, dominant.anchor, c.anchor);
|
|
316
429
|
ctx.trace?.step("tryAnalog", [
|
|
317
430
|
rNode(ctx, dominant.anchor, "dominant"),
|
|
318
431
|
rNode(ctx, c.anchor, "candidate", sim),
|
|
319
|
-
], [], `analogy strength ${sim.toFixed(4)}`);
|
|
432
|
+
], [], `analogy strength ${sim.toFixed(4)}${halo ? " (halo tier)" : ""}`);
|
|
320
433
|
if (sim > bestSim) {
|
|
321
434
|
bestSim = sim;
|
|
322
435
|
bestAnalog = c;
|
|
436
|
+
bestHalo = halo;
|
|
323
437
|
}
|
|
324
438
|
}
|
|
325
439
|
// When every candidate fails the similarity gates (halo company — now
|
|
@@ -348,6 +462,18 @@ export async function counterfactualTransfer(ctx, query, pre) {
|
|
|
348
462
|
let hubMass = -1;
|
|
349
463
|
const fanClamp = hubBound(ctx) + 1;
|
|
350
464
|
for (const c of analogs) {
|
|
465
|
+
// A fallback comparison carries NO similarity evidence at all. Its
|
|
466
|
+
// honesty rests on the grounding decider discounting it against
|
|
467
|
+
// richer candidates (the design note below) — an assumption that
|
|
468
|
+
// holds only when the climb itself settled on this query with real
|
|
469
|
+
// evidence. Under a root the consensus floor does not trust, an
|
|
470
|
+
// unnamed, hop-reached hub is pure corpus adjacency: refusing it is
|
|
471
|
+
// what kept the live wrong echo silent. A hub the query itself
|
|
472
|
+
// NAMED stays eligible either way (test/29 C2/C3's "William
|
|
473
|
+
// Shakespeare"); an unnamed one under a TRUSTED root stays eligible
|
|
474
|
+
// too (test/33 1b's deliberately weak second candidate).
|
|
475
|
+
if (!rootTrusted && !namedByQuery(c))
|
|
476
|
+
continue;
|
|
351
477
|
// Evidence clamped at the hub bound: beyond √N + 1 the exact fan-out
|
|
352
478
|
// no longer discriminates (every mega-hub ties at the clamp), and
|
|
353
479
|
// counting it exactly would require the corpus-sized read.
|
|
@@ -388,17 +514,130 @@ export async function counterfactualTransfer(ctx, query, pre) {
|
|
|
388
514
|
// climb's own forest, never tuned; substitution/redirection stay
|
|
389
515
|
// unaffected — they orient around a displaced seat, not a whole-topic
|
|
390
516
|
// analogy.
|
|
517
|
+
//
|
|
518
|
+
// roots.length <= 1 is a PROXY for "the query is about one thing" — it is
|
|
519
|
+
// only as good as the climb's own root-commitment, which depends on
|
|
520
|
+
// recognise() having found something to commit a root TO. When the
|
|
521
|
+
// query's newest content genuinely isn't recognised (not boundary noise —
|
|
522
|
+
// real, uncommitted content; see the session's own investigation of the
|
|
523
|
+
// France→Spain live trace), the climb under-commits roots and this proxy
|
|
524
|
+
// is fooled: comparison looks licensed to treat the query as one topic
|
|
525
|
+
// when it is not.
|
|
526
|
+
//
|
|
527
|
+
// The direct check is the SAME accounted spans comparison is about to
|
|
528
|
+
// cite as its evidence: unexplainedSpans (rationale.ts, the same gap
|
|
529
|
+
// computation the trace's own `unexplained` diagnostic uses) names every
|
|
530
|
+
// stretch of the query NEITHER the dominant NOR the analog's evidence
|
|
531
|
+
// touches. A short comparison query ("How is ice like steel?") legitimately
|
|
532
|
+
// accounts for only its two short entity spans — the surrounding "How is
|
|
533
|
+
// ... like ...?" framing is real but SHORT, split into several small gaps,
|
|
534
|
+
// none of them the bulk of the query. The live bug's shape is different in
|
|
535
|
+
// kind, not degree: ONE contiguous, substantial gap — a whole second
|
|
536
|
+
// question the query added that comparison's two spans never touch at all.
|
|
537
|
+
//
|
|
538
|
+
// Two bars, both derived, neither tuned:
|
|
539
|
+
// • the largest gap must not DOMINATE the whole query (the same
|
|
540
|
+
// predicate CAST's own frame gate uses) — rules out a gap that is
|
|
541
|
+
// most of the query outright;
|
|
542
|
+
// • the largest gap must be SMALLER than the dominant's own established
|
|
543
|
+
// context. A gap can't be dismissed as mere connective framing once
|
|
544
|
+
// it is at least as large as the topic being compared FROM — at that
|
|
545
|
+
// scale it isn't glue between two named things, it's substantial
|
|
546
|
+
// enough to be a second topic in its own right. This is what
|
|
547
|
+
// actually separates the live bug (a 47-byte gap against a 30-byte
|
|
548
|
+
// dominant — the ignored content is bigger than the topic itself)
|
|
549
|
+
// from ordinary short comparisons (a 9-byte gap against an 11-byte
|
|
550
|
+
// dominant — the gap is smaller than what's being compared): the two
|
|
551
|
+
// cases land on the same side of "half the query" often enough
|
|
552
|
+
// (both can exceed or clear it) that the query-relative bar alone
|
|
553
|
+
// does not reliably separate them — the topic-relative scale does.
|
|
554
|
+
const cmpAccounted = bestAnalog !== null
|
|
555
|
+
? [...runSpans(dominant), ...runSpans(bestAnalog.point ?? bestAnalog.src)]
|
|
556
|
+
: [];
|
|
557
|
+
const cmpGaps = unexplainedSpans(query.length, cmpAccounted);
|
|
558
|
+
const cmpMaxGap = cmpGaps.reduce((n, [s, e]) => Math.max(n, e - s), 0);
|
|
559
|
+
// An analog that is not itself a directly ALIGNED point (point !== null —
|
|
560
|
+
// its own runs are query bytes, the query NAMED it) was only reached
|
|
561
|
+
// through a continuation hop or the structural-hub fallback. Voicing
|
|
562
|
+
// learnt content the query never named is the same act recallByResonance
|
|
563
|
+
// refuses to perform through a climb root whose consensus vote is below
|
|
564
|
+
// consensusFloor(N) = ln(N) + 1/2 (recall.ts's minVote), so comparison
|
|
565
|
+
// holds the climb to that SAME bar before citing a hop-reached analog:
|
|
566
|
+
// some committed root must clear the floor. The climb's FIRST root is
|
|
567
|
+
// deliberately floor-free (attention.ts: "the dominant one always
|
|
568
|
+
// grounds") — fine for ORIENTING mechanisms, not for transferring
|
|
569
|
+
// unnamed content through. The live bug this gates (real trained store,
|
|
570
|
+
// 325k edge sources, floor 13.2): the query's stopword scraps pooled a
|
|
571
|
+
// 1.92 vote that committed an unrelated haiku exemplar as the sole root,
|
|
572
|
+
// and comparison voiced that exemplar's continuation through a
|
|
573
|
+
// hop-reached analog while every other mechanism honestly refused. A
|
|
574
|
+
// directly aligned analog needs no floor — the query's own bytes are its
|
|
575
|
+
// evidence (test/29 C1's "Steel is hard" for "How is ice like steel?").
|
|
576
|
+
// See test/50-cast-analog-consensus-floor.
|
|
577
|
+
// A HALO-tier best analog needs neither: its similarity already cleared
|
|
578
|
+
// significanceBar-gated distributional company (analogyStrength's
|
|
579
|
+
// `halo`) — genuine evidence in its own right, the very case the halo
|
|
580
|
+
// gate exists for (test/33 1b's nickname-corroborated analog). Only a
|
|
581
|
+
// FRAME-tier or fallback analog — whose "similarity" is an unbarred
|
|
582
|
+
// coverage fraction or nothing — needs the query's naming or the climb's
|
|
583
|
+
// trust.
|
|
584
|
+
const analogNamed = bestAnalog !== null && namedByQuery(bestAnalog);
|
|
585
|
+
// NOTE — two further gates were tried here and empirically REFUTED,
|
|
586
|
+
// recorded so they are not re-tried:
|
|
587
|
+
// • dominant self-coverage (dominant's aligned runs must dominate its
|
|
588
|
+
// own ctx): legitimate dominants sit at the same coverage as junk
|
|
589
|
+
// ones ("The Mona Lisa was painted by…" 16/47 vs the live junk
|
|
590
|
+
// haiku ~10/54) — no separation.
|
|
591
|
+
// • denying the shared-frame similarity tier to hop-reached analogs:
|
|
592
|
+
// semantically right in isolation, but it merely promoted the next
|
|
593
|
+
// junk candidate — an ALIGNED scrap-matched point ("The affluence…",
|
|
594
|
+
// frame 0.157) — into bestAnalog on the live store, and the aligned
|
|
595
|
+
// configuration is byte-structurally IDENTICAL to test/29 C1's
|
|
596
|
+
// legitimate one ("Steel is hard", frame 0.364): every derived
|
|
597
|
+
// local separator measured (run length, site overlap, frame
|
|
598
|
+
// query-containment, weave-usable classification) falls on the same
|
|
599
|
+
// side for both. Only corpus-scale consensus separates them, which
|
|
600
|
+
// is exactly what `rootTrusted` prices.
|
|
601
|
+
// FRAME-tier evidence under an UNTRUSTED root is comparison's weakest
|
|
602
|
+
// licence (an unbarred coverage fraction, a climb the consensus floor
|
|
603
|
+
// does not trust). There it is additionally held to the IGNORED-KNOWN
|
|
604
|
+
// principle (dismissedKnownContent, bridge.ts): the two analogs' aligned
|
|
605
|
+
// runs must account for every STORED window of the query. This is the
|
|
606
|
+
// byte-structural separator the refuted-gates note below could not find
|
|
607
|
+
// locally: a legitimate small-corpus comparison ("How is ice like
|
|
608
|
+
// steel?") leaves only UNATTESTED spans ("How ", " like ") unexplained,
|
|
609
|
+
// while a scrap-matched junk pair leaves the query's own trained content
|
|
610
|
+
// ("…songs…times…", "…planet…sun.") dismissed as gaps. Halo-tier and
|
|
611
|
+
// trusted-root comparisons are exempt — their evidence already stands.
|
|
612
|
+
const cmpDismisses = !(bestHalo || rootTrusted) &&
|
|
613
|
+
dismissedKnownContent(ctx, query, cmpAccounted);
|
|
391
614
|
if (bestAnalog !== null &&
|
|
615
|
+
(bestHalo || analogNamed || rootTrusted) &&
|
|
616
|
+
!cmpDismisses &&
|
|
392
617
|
dominant.ctx.length <= query.length &&
|
|
393
|
-
roots.length <= 1
|
|
618
|
+
roots.length <= 1 &&
|
|
619
|
+
!dominates(cmpMaxGap, query.length) &&
|
|
620
|
+
cmpMaxGap < dominant.ctx.length) {
|
|
394
621
|
ctx.trace?.step("validateAnalogy", [
|
|
395
622
|
rNode(ctx, dominant.anchor, "analog", bestSim),
|
|
396
623
|
rNode(ctx, bestAnalog.anchor, "analog", bestSim),
|
|
397
624
|
], [], "the two structures keep distributional company beyond chance — genuine analogs");
|
|
398
625
|
const a = await seatOf(dominant);
|
|
626
|
+
// The analog is only being CITED for comparison — the query never asked
|
|
627
|
+
// about it — so its seat never chases a FORWARD continuation (see
|
|
628
|
+
// seatOfNode's `allowForward`): only reverse (if a predecessor genuinely
|
|
629
|
+
// establishes it) or its own bytes. A DIRECTLY aligned point
|
|
630
|
+
// (bestAnalog.point !== null) still goes through seatOfNode for that
|
|
631
|
+
// reverse check (a bare entity NAME like "Leonardo da Vinci" needs it —
|
|
632
|
+
// test/29's C2/C3). A nextOf DESCENDANT (point === null) was already
|
|
633
|
+
// reached by following ONE meaningful hop off another aligned point (the
|
|
634
|
+
// alignment loop above: "its nextOf is the hub... and the hub's own
|
|
635
|
+
// [...] context will be the seat") — its own bytes ARE that seat
|
|
636
|
+
// directly, with no predecessor to even check (it was found by a
|
|
637
|
+
// forward edge, not matched in the query).
|
|
399
638
|
const b = bestAnalog.point !== null
|
|
400
|
-
? await seatOf(bestAnalog.point)
|
|
401
|
-
:
|
|
639
|
+
? await seatOf(bestAnalog.point, false)
|
|
640
|
+
: read(ctx, bestAnalog.anchor);
|
|
402
641
|
const answer = await joinWithBridge(ctx, a, b);
|
|
403
642
|
record(answer, "analogical comparison — each analog voiced by the context that establishes its role", new Set([dominant.anchor, bestAnalog.anchor]),
|
|
404
643
|
// A halo-mediated act (the analogy gate) plus two seat projections.
|
|
@@ -408,10 +647,26 @@ export async function counterfactualTransfer(ctx, query, pre) {
|
|
|
408
647
|
// when it was an aligned point, else the source point whose
|
|
409
648
|
// continuation edge reached it (that alignment IS the query evidence
|
|
410
649
|
// the hop rests on).
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
650
|
+
cmpAccounted);
|
|
651
|
+
}
|
|
652
|
+
else if (bestAnalog !== null &&
|
|
653
|
+
dominant.ctx.length <= query.length &&
|
|
654
|
+
roots.length <= 1) {
|
|
655
|
+
ctx.trace?.step("validateAnalogy", [
|
|
656
|
+
rNode(ctx, dominant.anchor, "analog", bestSim),
|
|
657
|
+
rNode(ctx, bestAnalog.anchor, "analog", bestSim),
|
|
658
|
+
], [], !(bestHalo || analogNamed || rootTrusted)
|
|
659
|
+
? `the best analog carries no halo-tier company evidence, was never ` +
|
|
660
|
+
`named by the query, and no committed root's consensus vote ` +
|
|
661
|
+
`clears the floor, so comparison refuses to voice it`
|
|
662
|
+
: cmpDismisses
|
|
663
|
+
? `a frame-tier analog under an untrusted root dismisses stored ` +
|
|
664
|
+
`query content its alignment never accounted for — comparison ` +
|
|
665
|
+
`refuses to ignore what the store knows`
|
|
666
|
+
: `comparison's own accounted evidence leaves a ${cmpMaxGap}-byte gap in ` +
|
|
667
|
+
`a ${query.length}-byte query against a ${dominant.ctx.length}-byte ` +
|
|
668
|
+
`dominant — too large to be mere framing — so it refuses rather ` +
|
|
669
|
+
`than paper over it with an analog the query never asked about`);
|
|
415
670
|
}
|
|
416
671
|
t?.done(results.map((r) => rItem(r.bytes, "answer")), results.length > 0
|
|
417
672
|
? `${results.length} counterfactual schema(s) fired — the grounding decider weighs them`
|
|
@@ -8,12 +8,11 @@
|
|
|
8
8
|
// cover runs FIRST in defaultMechanisms: a computed-backed cover becomes a
|
|
9
9
|
// near-zero-cost incumbent that prunes the other mechanisms through the
|
|
10
10
|
// ordinary admissible-floor check, with no extension special-case anywhere.
|
|
11
|
-
import { bytesEqual, indexOf } from "../../bytes.js";
|
|
12
11
|
import { read, resolve } from "../primitives.js";
|
|
13
12
|
import { guidedFirst } from "../traverse.js";
|
|
14
13
|
import { conceptHop } from "../match.js";
|
|
15
14
|
import { bridge } from "../resonance.js";
|
|
16
|
-
import { liftAnswer } from "../types.js";
|
|
15
|
+
import { liftAnswer, segRestatesQuery } from "../types.js";
|
|
17
16
|
import { decodeText, unexplainedLabel } from "../rationale.js";
|
|
18
17
|
import { rItem, rNode, traceDerivation } from "../trace.js";
|
|
19
18
|
// ── Concept / connector pre-resolution ──────────────────────────────────────
|
|
@@ -122,11 +121,18 @@ export const coverMechanism = {
|
|
|
122
121
|
return [];
|
|
123
122
|
const connectors = await resolveConnectors(ctx, sites);
|
|
124
123
|
let splits = rec.splits;
|
|
124
|
+
let starts = rec.starts;
|
|
125
125
|
if (computed.length > 0) {
|
|
126
126
|
splits = new Set(rec.splits);
|
|
127
|
+
starts = new Set(rec.starts);
|
|
127
128
|
for (const u of computed) {
|
|
128
129
|
splits.add(u.i);
|
|
129
130
|
splits.add(u.j);
|
|
131
|
+
// A computation's own boundaries carry the same fold-level evidence
|
|
132
|
+
// a chunk boundary does — "computation always wins" (see the header
|
|
133
|
+
// comment) extends to being trusted ground for cross-leaf recovery.
|
|
134
|
+
starts.add(u.i);
|
|
135
|
+
starts.add(u.j);
|
|
130
136
|
}
|
|
131
137
|
}
|
|
132
138
|
const concepts = await resolveConcepts(ctx, sites);
|
|
@@ -150,7 +156,7 @@ export const coverMechanism = {
|
|
|
150
156
|
])),
|
|
151
157
|
...computedResults.map((u) => rItem(u.bytes, "computed")),
|
|
152
158
|
], coverDeps.length ? coverDeps : undefined);
|
|
153
|
-
const solved = ctx.search.cover(query.length, sites, concepts, rec.leaves, splits, undefined, connectors, computedResults, ctx.trace ? (steps) => traceDerivation(ctx, steps) : undefined);
|
|
159
|
+
const solved = ctx.search.cover(query.length, sites, concepts, rec.leaves, splits, starts, undefined, connectors, computedResults, ctx.trace ? (steps) => traceDerivation(ctx, steps) : undefined);
|
|
154
160
|
const segs = solved && solved.segs;
|
|
155
161
|
tCover?.done(segs === null
|
|
156
162
|
? []
|
|
@@ -159,46 +165,32 @@ export const coverMechanism = {
|
|
|
159
165
|
: "lightest derivation: the chosen spans, left to right");
|
|
160
166
|
if (segs === null)
|
|
161
167
|
return [];
|
|
168
|
+
const W = ctx.space.maxGroup;
|
|
162
169
|
// A chosen span's SUBSTITUTED bytes (an edge followed from a recognised
|
|
163
170
|
// site, not the site's own literal text read back) that equal a byte
|
|
164
171
|
// span the query ALREADY CONTAINS elsewhere restates part of the
|
|
165
|
-
// question — never an answer (
|
|
166
|
-
// apply to a whole-query projection: "a projection that is a proper
|
|
167
|
-
// byte-subspan of the query restates part of the question"). A
|
|
172
|
+
// question — never an answer (see {@link segRestatesQuery}). A
|
|
168
173
|
// recognised site that is itself an entire PRIOR TURN of a multi-turn
|
|
169
174
|
// query is exactly this shape: it carries a genuine learnt
|
|
170
175
|
// continuation, but that continuation is something the asker already
|
|
171
|
-
// said moments later in the SAME query
|
|
172
|
-
//
|
|
173
|
-
//
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
const literal = s.j - s.i === s.bytes.length &&
|
|
179
|
-
bytesEqual(s.bytes, query.subarray(s.i, s.j));
|
|
180
|
-
if (literal)
|
|
181
|
-
continue;
|
|
182
|
-
// A span shorter than one river window is exactly the "ice"/"c"
|
|
183
|
-
// case: a chain hop's short terminal coincidentally recurring as a
|
|
184
|
-
// substring of an unrelated longer word. Below the quantum, byte
|
|
185
|
-
// overlap is chance, not evidence — the same floor identityBar and
|
|
186
|
-
// reachThreshold hold every other structural-overlap claim to.
|
|
187
|
-
if (s.bytes.length >= W && s.bytes.length < query.length &&
|
|
188
|
-
indexOf(query, s.bytes, 0) >= 0) {
|
|
189
|
-
ctx.trace?.step("restatedSpan", [rItem(s.bytes, "substituted", s.node, [s.i, s.j])], [], "the chosen span's substitution already occurs elsewhere in the query — restates it, not an answer");
|
|
190
|
-
return [];
|
|
191
|
-
}
|
|
176
|
+
// said moments later in the SAME query. liftAnswer TRIMS such spans
|
|
177
|
+
// out of both the framing decision and the final concatenation — the
|
|
178
|
+
// OTHER spans a derivation chose are independent evidence and must not
|
|
179
|
+
// be discarded along with the stale one.
|
|
180
|
+
const restated = segs.filter((s) => segRestatesQuery(s, query, query.length, W));
|
|
181
|
+
if (restated.length > 0) {
|
|
182
|
+
ctx.trace?.step("restatedSpan", restated.map((s) => rItem(s.bytes, "substituted", s.node, [s.i, s.j])), [], "the chosen span's substitution already occurs elsewhere in the query — trimmed from the answer, not an answer itself");
|
|
192
183
|
}
|
|
193
|
-
const composed = liftAnswer(segs, query.length);
|
|
184
|
+
const composed = liftAnswer(segs, query.length, query, W);
|
|
194
185
|
if (composed === null)
|
|
195
186
|
return [];
|
|
196
187
|
ctx.trace?.step("liftAnswer", segs.map((s) => rItem(s.bytes, s.rec ? "chosen" : "scaffolding", s.node, [s.i, s.j])), [rItem(composed, "answer", resolve(ctx, composed) ?? undefined)], "lift the recognised region out of the asker's framing", tCover ? [tCover.index] : undefined);
|
|
197
|
-
// accounted = RECOGNISED cover spans only —
|
|
198
|
-
//
|
|
199
|
-
//
|
|
188
|
+
// accounted = RECOGNISED, non-restating cover spans only — a trimmed
|
|
189
|
+
// restated span contributes nothing to the composed answer, so it must
|
|
190
|
+
// not be priced as if it did (PASS-carried bytes are priced already;
|
|
191
|
+
// the diagnostic label reflects the same distinction).
|
|
200
192
|
const accounted = segs
|
|
201
|
-
.filter((s) => s.rec)
|
|
193
|
+
.filter((s) => s.rec && !segRestatesQuery(s, query, query.length, W))
|
|
202
194
|
.map((s) => [s.i, s.j]);
|
|
203
195
|
return [{
|
|
204
196
|
bytes: composed,
|