@hviana/sema 0.8.9 → 0.9.1
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 +7 -7
- package/dist/src/alu/src/index.d.ts +1 -1
- package/dist/src/alu/src/index.js +1 -1
- package/dist/src/alu/src/parser.js +2 -6
- package/dist/src/alu/src/resonance.d.ts +13 -0
- package/dist/src/alu/src/resonance.js +41 -0
- package/dist/src/alu/test/alu.test.js +39 -0
- package/dist/src/bytes.d.ts +6 -2
- package/dist/src/bytes.js +10 -4
- package/dist/src/canon.js +44 -0
- package/dist/src/geometry.d.ts +19 -1
- package/dist/src/geometry.js +125 -141
- package/dist/src/meter.d.ts +27 -0
- package/dist/src/meter.js +28 -1
- package/dist/src/mind/articulation.js +14 -1
- package/dist/src/mind/attention.d.ts +12 -0
- package/dist/src/mind/attention.js +44 -16
- package/dist/src/mind/bridge.js +3 -3
- package/dist/src/mind/derivation.d.ts +40 -0
- package/dist/src/mind/derivation.js +34 -0
- package/dist/src/mind/graph-search.d.ts +89 -15
- package/dist/src/mind/graph-search.js +345 -174
- package/dist/src/mind/learning.js +1 -1
- package/dist/src/mind/mechanisms/cover.d.ts +19 -3
- package/dist/src/mind/mechanisms/cover.js +101 -58
- package/dist/src/mind/mechanisms/recall.js +0 -1
- package/dist/src/mind/mind.js +2 -2
- package/dist/src/mind/pipeline.d.ts +5 -1
- package/dist/src/mind/pipeline.js +175 -87
- package/dist/src/mind/primitives.d.ts +25 -5
- package/dist/src/mind/primitives.js +107 -44
- package/dist/src/mind/reasoning.d.ts +18 -4
- package/dist/src/mind/reasoning.js +445 -321
- package/dist/src/mind/recognition.js +55 -73
- package/dist/src/mind/resonance.js +1 -11
- package/dist/src/mind/traverse.d.ts +3 -3
- package/dist/src/mind/traverse.js +3 -3
- package/dist/src/mind/types.d.ts +7 -1
- package/dist/src/store-sqlite.d.ts +25 -0
- package/dist/src/store-sqlite.js +89 -1
- package/dist/src/store.d.ts +48 -4
- package/dist/src/store.js +86 -6
- package/docs/INDEX.md +18 -18
- package/docs/INVARIANTS.md +16 -16
- package/docs/architecture/bounded-reads.md +1 -1
- package/docs/architecture/caches.md +5 -4
- package/docs/architecture/closure.md +45 -5
- package/docs/architecture/cost-model.md +16 -0
- package/docs/architecture/factored-machinery.md +14 -13
- package/docs/architecture/fold-contract.md +51 -1
- package/docs/architecture/mechanism-market.md +21 -0
- package/docs/architecture/memoization.md +3 -3
- package/docs/architecture/meter.md +2 -1
- package/docs/architecture/saturation.md +12 -0
- package/docs/architecture/store.md +25 -2
- package/docs/failures/tempting-but-wrong.md +13 -2
- package/docs/harness/gates.md +12 -10
- package/docs/mechanisms/cover.md +23 -6
- package/jsr.json +1 -1
- package/package.json +1 -1
- package/src/alu/README.md +10 -2
- package/src/alu/src/index.ts +1 -0
- package/src/alu/src/parser.ts +6 -6
- package/src/alu/src/resonance.ts +42 -0
- package/src/alu/test/alu.test.ts +40 -0
- package/src/bytes.ts +13 -3
- package/src/canon.ts +40 -0
- package/src/geometry.ts +183 -154
- package/src/meter.ts +28 -1
- package/src/mind/articulation.ts +14 -2
- package/src/mind/attention.ts +47 -25
- package/src/mind/bridge.ts +3 -3
- package/src/mind/derivation.ts +77 -0
- package/src/mind/graph-search.ts +449 -221
- package/src/mind/learning.ts +1 -7
- package/src/mind/match.ts +1 -2
- package/src/mind/mechanisms/cast.ts +1 -2
- package/src/mind/mechanisms/cover.ts +149 -84
- package/src/mind/mechanisms/extraction.ts +1 -2
- package/src/mind/mechanisms/prefix-completion.ts +1 -1
- package/src/mind/mechanisms/recall.ts +1 -3
- package/src/mind/mechanisms/reference.ts +1 -1
- package/src/mind/mind.ts +5 -30
- package/src/mind/pipeline.ts +206 -102
- package/src/mind/primitives.ts +119 -43
- package/src/mind/reasoning.ts +558 -413
- package/src/mind/recognition.ts +49 -65
- package/src/mind/resonance.ts +2 -16
- package/src/mind/trace.ts +1 -1
- package/src/mind/traverse.ts +3 -3
- package/src/mind/types.ts +9 -11
- package/src/store-sqlite.ts +92 -1
- package/src/store.ts +113 -7
- package/test/105-derive-through-reports-its-refusal.test.mjs +8 -5
- package/test/106-the-join-fires.test.mjs +21 -0
- package/test/111-the-cover-assembly-is-counted.test.mjs +8 -5
- package/test/128-the-leads-somewhere-pair-agrees.test.mjs +18 -12
- package/test/136-the-two-named-limits.test.mjs +3 -2
- package/test/137-the-law-lives-once-and-below.test.mjs +21 -0
- package/test/148-exact-shortcuts-agree.test.mjs +188 -0
- package/test/149-the-closure-engine.test.mjs +138 -0
- package/test/150-the-join-is-output-sensitive.test.mjs +66 -0
- package/test/151-the-cover-pays-for-what-it-reaches.test.mjs +142 -0
- package/test/152-the-read-side-names-as-the-write-side.test.mjs +146 -0
- package/test/153-a-cheaper-bound-is-looked-at-first.test.mjs +155 -0
- package/test/24-generalization.test.mjs +32 -0
- package/test/36-bloom.test.mjs +53 -0
- package/test/37-cluster-dispersion-fusion.test.mjs +75 -0
- package/test/48-recognise-turn-connective.test.mjs +3 -2
- package/test/55-cost-meter.test.mjs +4 -4
- package/test/90-connector-read-cap.test.mjs +7 -7
package/src/mind/learning.ts
CHANGED
|
@@ -7,13 +7,7 @@ import { addInto, normalize, Vec, zeros } from "../vec.js";
|
|
|
7
7
|
import { bindSeat, companySignature, isChunk, Sema } from "../sema.js";
|
|
8
8
|
import type { Input, MindContext } from "./types.js";
|
|
9
9
|
import { changedNodes } from "./types.js";
|
|
10
|
-
import {
|
|
11
|
-
inputBytes,
|
|
12
|
-
latin1Key,
|
|
13
|
-
perceive,
|
|
14
|
-
perceiveDeposit,
|
|
15
|
-
resolve,
|
|
16
|
-
} from "./primitives.js";
|
|
10
|
+
import { inputBytes, perceiveDeposit, resolve } from "./primitives.js";
|
|
17
11
|
import { canonicalWindows, leafIdPrefix } from "./canonical.js";
|
|
18
12
|
import { rItem, rNode } from "./trace.js";
|
|
19
13
|
import { hubBound } from "./traverse.js";
|
package/src/mind/match.ts
CHANGED
|
@@ -40,7 +40,7 @@ import {
|
|
|
40
40
|
} from "../geometry.js";
|
|
41
41
|
import { bytesEqual, indexOf, latin1 } from "../bytes.js";
|
|
42
42
|
import type { MindContext } from "./types.js";
|
|
43
|
-
import {
|
|
43
|
+
import { leafIdRun } from "./canonical.js";
|
|
44
44
|
import { foldTree, gistOf, perceive, read, resolve } from "./primitives.js";
|
|
45
45
|
import {
|
|
46
46
|
argmaxCosine,
|
|
@@ -54,7 +54,6 @@ import {
|
|
|
54
54
|
sharedReachMemo,
|
|
55
55
|
} from "./traverse.js";
|
|
56
56
|
import { recognise, segment } from "./recognition.js";
|
|
57
|
-
import { rItem } from "./trace.js";
|
|
58
57
|
import type { Site } from "./graph-search.js";
|
|
59
58
|
|
|
60
59
|
// ═══════════════════════════════════════════════════════════════════════════
|
|
@@ -31,9 +31,8 @@ import {
|
|
|
31
31
|
} from "../match.js";
|
|
32
32
|
import { joinWithBridge } from "../resonance.js";
|
|
33
33
|
import { CONCEPT, STEP } from "../graph-search.js";
|
|
34
|
-
import {
|
|
34
|
+
import { indexOf } from "../../bytes.js";
|
|
35
35
|
import { consensusFloor, dominates } from "../../geometry.js";
|
|
36
|
-
import { decodeText } from "../rationale.js";
|
|
37
36
|
import { restates, unexplainedSpans } from "../derivation.js";
|
|
38
37
|
import { rItem, rNode } from "../trace.js";
|
|
39
38
|
import { dismissedKnownContent } from "../bridge.js";
|
|
@@ -10,7 +10,13 @@
|
|
|
10
10
|
// ordinary admissible-floor check, with no extension special-case anywhere.
|
|
11
11
|
|
|
12
12
|
import type { MindContext } from "../types.js";
|
|
13
|
-
import type {
|
|
13
|
+
import type {
|
|
14
|
+
ComputedResult,
|
|
15
|
+
ConceptLicence,
|
|
16
|
+
ConnectorLicence,
|
|
17
|
+
DerivationStep,
|
|
18
|
+
Site,
|
|
19
|
+
} from "../graph-search.js";
|
|
14
20
|
import { read, resolve } from "../primitives.js";
|
|
15
21
|
import { guidedFirst, hubBound } from "../traverse.js";
|
|
16
22
|
import { conceptHop } from "../match.js";
|
|
@@ -18,47 +24,72 @@ import { bridge } from "../resonance.js";
|
|
|
18
24
|
import { liftAnswer, liftedScaffolding, segRestatesQuery } from "../types.js";
|
|
19
25
|
import { decodeText } from "../rationale.js";
|
|
20
26
|
import { insideAnsweredTurn, restates } from "../derivation.js";
|
|
21
|
-
import { indexOf } from "../../bytes.js";
|
|
22
27
|
import type { RationaleItem } from "../rationale.js";
|
|
23
28
|
import { rItem, rNode, traceDerivation } from "../trace.js";
|
|
24
29
|
import type { PipelineMechanism } from "../pipeline-mechanism.js";
|
|
25
30
|
|
|
26
31
|
// ── Concept / connector pre-resolution ──────────────────────────────────────
|
|
27
32
|
|
|
28
|
-
|
|
33
|
+
/** The concept hops the cover may take, OFFERED up front and looked up only
|
|
34
|
+
* when the search asks (see {@link Licence}): every recognised form with no
|
|
35
|
+
* continuation of its own may borrow a halo sibling's. */
|
|
36
|
+
export interface CoverConcepts extends ConceptLicence {
|
|
37
|
+
/** Look up the asked forms' concept targets not yet granted. */
|
|
38
|
+
grant(nodes: Iterable<number>): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function offerConcepts(
|
|
29
42
|
ctx: MindContext,
|
|
30
|
-
sites: Site
|
|
31
|
-
):
|
|
32
|
-
const
|
|
33
|
-
const visited = new Set<number>();
|
|
43
|
+
sites: ReadonlyArray<Site>,
|
|
44
|
+
): CoverConcepts {
|
|
45
|
+
const offered = new Set<number>();
|
|
34
46
|
for (const { payload: n } of sites) {
|
|
35
|
-
if (
|
|
36
|
-
visited.add(n);
|
|
37
|
-
if (ctx.store.hasNext(n)) continue;
|
|
38
|
-
const hop = await conceptHop(ctx, n);
|
|
39
|
-
if (hop !== null) target.set(n, hop);
|
|
47
|
+
if (!offered.has(n) && !ctx.store.hasNext(n)) offered.add(n);
|
|
40
48
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
const granted = new Map<number, number | null>();
|
|
50
|
+
return {
|
|
51
|
+
offered,
|
|
52
|
+
granted,
|
|
53
|
+
asked: new Set(),
|
|
54
|
+
async grant(nodes) {
|
|
55
|
+
const found: Array<[number, number]> = [];
|
|
56
|
+
for (const n of nodes) {
|
|
57
|
+
if (granted.has(n)) continue;
|
|
58
|
+
const hop = await conceptHop(ctx, n);
|
|
59
|
+
granted.set(n, hop);
|
|
60
|
+
if (hop !== null) found.push([n, hop]);
|
|
61
|
+
}
|
|
62
|
+
if (found.length > 0) {
|
|
63
|
+
ctx.trace?.step(
|
|
64
|
+
"resolveConcepts",
|
|
65
|
+
found.map(([n]) => rNode(ctx, n, "edgeless-form")),
|
|
66
|
+
found.map(([, h]) => rNode(ctx, h, "concept-sibling")),
|
|
67
|
+
"borrow a synonym's continuation edge for each edge-less form the search reached (a concept/halo hop)",
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The connectors the cover may splice, OFFERED up front and BRIDGED only when
|
|
75
|
+
* the search asks (see {@link ConnectorLicence}): every pair a learnt whole
|
|
76
|
+
* could run together — two touching sites, each side as itself or as its
|
|
77
|
+
* answer, in both orders — and, when three or more answers are recognised, the
|
|
78
|
+
* first answer to each later one (the N-ary whole). */
|
|
79
|
+
export interface CoverConnectors extends ConnectorLicence {
|
|
80
|
+
/** Bridge the asked pairs not yet granted. */
|
|
81
|
+
grant(keys: Iterable<string>): Promise<void>;
|
|
50
82
|
}
|
|
51
83
|
|
|
52
|
-
export
|
|
84
|
+
export function offerConnectors(
|
|
53
85
|
ctx: MindContext,
|
|
54
86
|
sites: ReadonlyArray<Site>,
|
|
55
87
|
query?: Uint8Array,
|
|
56
|
-
):
|
|
57
|
-
const links = new Map<string, Uint8Array>();
|
|
88
|
+
): CoverConnectors {
|
|
58
89
|
const answerOf = (n: number) => guidedFirst(ctx, n) ?? n;
|
|
59
90
|
// A site's continuation already present elsewhere in the query is stale
|
|
60
91
|
// transcript evidence: cover still needs the site for structural context,
|
|
61
|
-
// but liftAnswer will trim that continuation as already answered.
|
|
92
|
+
// but liftAnswer will trim that continuation as already answered. Offering
|
|
62
93
|
// pairwise/n-ary bridges for it can only create connectors that are later
|
|
63
94
|
// discarded — a semantically neutral gate (it removes work whose product
|
|
64
95
|
// liftAnswer throws away), and a cumulative (multi-turn) query is exactly
|
|
@@ -98,20 +129,16 @@ export async function resolveConnectors(
|
|
|
98
129
|
return restates(query, bytes, 0);
|
|
99
130
|
});
|
|
100
131
|
});
|
|
101
|
-
const
|
|
102
|
-
if (l === r || links.has(l + "," + r)) return;
|
|
103
|
-
if (ctx.meter) ctx.meter.coverBridges++;
|
|
104
|
-
const link = await bridge(ctx, read(ctx, l), read(ctx, r));
|
|
105
|
-
if (link !== null) links.set(l + "," + r, link);
|
|
106
|
-
};
|
|
132
|
+
const pairwise = new Set<string>();
|
|
107
133
|
for (let i = 0; i + 1 < ordered.length; i++) {
|
|
108
134
|
if (ordered[i].end !== ordered[i + 1].start) continue;
|
|
109
135
|
const lefts = [ordered[i].payload, answerOf(ordered[i].payload)];
|
|
110
136
|
const rights = [ordered[i + 1].payload, answerOf(ordered[i + 1].payload)];
|
|
111
137
|
for (const l of new Set(lefts)) {
|
|
112
138
|
for (const r of new Set(rights)) {
|
|
113
|
-
|
|
114
|
-
|
|
139
|
+
if (l === r) continue;
|
|
140
|
+
pairwise.add(l + "," + r);
|
|
141
|
+
pairwise.add(r + "," + l);
|
|
115
142
|
}
|
|
116
143
|
}
|
|
117
144
|
}
|
|
@@ -123,46 +150,70 @@ export async function resolveConnectors(
|
|
|
123
150
|
seenN.add(node);
|
|
124
151
|
orderedNodes.push({ node, bytes: read(ctx, node) });
|
|
125
152
|
}
|
|
153
|
+
const nary = new Map<
|
|
154
|
+
string,
|
|
155
|
+
{ left: Uint8Array; right: Uint8Array; allowance: number }
|
|
156
|
+
>();
|
|
126
157
|
if (orderedNodes.length >= 3) {
|
|
127
158
|
const first = orderedNodes[0];
|
|
128
159
|
const W = ctx.space.maxGroup;
|
|
129
160
|
let middleBytes = 0; // Σ bytes of the answers BETWEEN first and m-th
|
|
130
161
|
for (let m = 1; m < orderedNodes.length; m++) {
|
|
131
|
-
const key = first.node + "," + orderedNodes[m].node;
|
|
132
|
-
if (links.has(key)) {
|
|
133
|
-
middleBytes += orderedNodes[m].bytes.length;
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
162
|
// The N-ary interior legitimately holds every intermediate answer
|
|
137
163
|
// plus one W-quantum of glue per joint — pass that allowance so the
|
|
138
|
-
// bridge's phrase-scale cap admits the whole learnt run.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
ctx,
|
|
146
|
-
first.bytes,
|
|
147
|
-
orderedNodes[m].bytes,
|
|
148
|
-
allowance,
|
|
149
|
-
);
|
|
150
|
-
if (interior !== null) links.set(key, interior);
|
|
164
|
+
// bridge's phrase-scale cap admits the whole learnt run. Asked only
|
|
165
|
+
// when the pairwise bridge of the same key (if offered) found nothing.
|
|
166
|
+
nary.set(first.node + "," + orderedNodes[m].node, {
|
|
167
|
+
left: first.bytes,
|
|
168
|
+
right: orderedNodes[m].bytes,
|
|
169
|
+
allowance: middleBytes + (m + 1) * W,
|
|
170
|
+
});
|
|
151
171
|
middleBytes += orderedNodes[m].bytes.length;
|
|
152
172
|
}
|
|
153
173
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
174
|
+
const granted = new Map<string, Uint8Array | null>();
|
|
175
|
+
return {
|
|
176
|
+
offered: new Set([...pairwise, ...nary.keys()]),
|
|
177
|
+
granted,
|
|
178
|
+
asked: new Set(),
|
|
179
|
+
async grant(keys) {
|
|
180
|
+
const found: Array<[string, Uint8Array]> = [];
|
|
181
|
+
for (const key of keys) {
|
|
182
|
+
if (granted.has(key)) continue;
|
|
183
|
+
let link: Uint8Array | null = null;
|
|
184
|
+
if (pairwise.has(key)) {
|
|
185
|
+
const comma = key.indexOf(",");
|
|
186
|
+
if (ctx.meter) ctx.meter.coverBridges++;
|
|
187
|
+
link = await bridge(
|
|
188
|
+
ctx,
|
|
189
|
+
read(ctx, Number(key.slice(0, comma))),
|
|
190
|
+
read(ctx, Number(key.slice(comma + 1))),
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
const whole = nary.get(key);
|
|
194
|
+
if (link === null && whole !== undefined) {
|
|
195
|
+
if (ctx.meter) {
|
|
196
|
+
ctx.meter.coverBridges++;
|
|
197
|
+
ctx.meter.coverAllowanceBytes += whole.allowance;
|
|
198
|
+
}
|
|
199
|
+
link = await bridge(ctx, whole.left, whole.right, whole.allowance);
|
|
200
|
+
}
|
|
201
|
+
granted.set(key, link);
|
|
202
|
+
if (link !== null) found.push([key, link]);
|
|
203
|
+
}
|
|
204
|
+
if (found.length > 0) {
|
|
205
|
+
ctx.trace?.step(
|
|
206
|
+
"resolveConnectors",
|
|
207
|
+
ordered.map((s) => rItem(read(ctx, s.payload), "answer", s.payload)),
|
|
208
|
+
found.map(([pair, bytes]) => ({
|
|
209
|
+
text: `${pair}: "${decodeText(bytes)}"`,
|
|
210
|
+
role: "connector",
|
|
211
|
+
} as RationaleItem)),
|
|
212
|
+
"the bytes the graph splices between adjacent answers the search reached (asked of the gist space)",
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
};
|
|
166
217
|
}
|
|
167
218
|
|
|
168
219
|
// ── Pipeline mechanism ──────────────────────────────────────────────────────
|
|
@@ -206,11 +257,11 @@ export const coverMechanism: PipelineMechanism = {
|
|
|
206
257
|
if (sites.length === 0 && computed.length === 0) return [];
|
|
207
258
|
|
|
208
259
|
const connectors = ctx.meter
|
|
209
|
-
?
|
|
210
|
-
"cover.
|
|
211
|
-
() =>
|
|
260
|
+
? ctx.meter.timeSync(
|
|
261
|
+
"cover.offerConnectors",
|
|
262
|
+
() => offerConnectors(ctx, sites, query),
|
|
212
263
|
)
|
|
213
|
-
:
|
|
264
|
+
: offerConnectors(ctx, sites, query);
|
|
214
265
|
let splits = rec.splits;
|
|
215
266
|
if (computed.length > 0) {
|
|
216
267
|
splits = new Set(rec.splits);
|
|
@@ -220,17 +271,15 @@ export const coverMechanism: PipelineMechanism = {
|
|
|
220
271
|
}
|
|
221
272
|
}
|
|
222
273
|
const concepts = ctx.meter
|
|
223
|
-
?
|
|
224
|
-
"cover.
|
|
225
|
-
() =>
|
|
274
|
+
? ctx.meter.timeSync(
|
|
275
|
+
"cover.offerConcepts",
|
|
276
|
+
() => offerConcepts(ctx, sites),
|
|
226
277
|
)
|
|
227
|
-
:
|
|
278
|
+
: offerConcepts(ctx, sites);
|
|
228
279
|
|
|
229
280
|
const coverDeps = [
|
|
230
281
|
ctx.trace?.lastIndex("recognise"),
|
|
231
282
|
ctx.trace?.lastIndex("computeExtensions"),
|
|
232
|
-
ctx.trace?.lastIndex("resolveConcepts"),
|
|
233
|
-
ctx.trace?.lastIndex("resolveConnectors"),
|
|
234
283
|
].filter((x): x is number => x !== undefined);
|
|
235
284
|
|
|
236
285
|
// Convert ComputedSpan[] to ComputedResult[] for the graph search.
|
|
@@ -251,17 +300,33 @@ export const coverMechanism: PipelineMechanism = {
|
|
|
251
300
|
...computedResults.map((u) => rItem(u.bytes, "computed")),
|
|
252
301
|
], coverDeps.length ? coverDeps : undefined);
|
|
253
302
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
303
|
+
// COVER, GRANT WHAT IT ASKED, COVER AGAIN — until a cover asks for nothing
|
|
304
|
+
// (see Licence in graph-search.ts). Only the final cover's derivations reach the
|
|
305
|
+
// rationale; a provisional one is superseded, not part of the answer.
|
|
306
|
+
let derivations: DerivationStep[][] = [];
|
|
307
|
+
let solved: ReturnType<typeof ctx.search.cover>;
|
|
308
|
+
for (;;) {
|
|
309
|
+
derivations = [];
|
|
310
|
+
solved = ctx.search.cover(
|
|
311
|
+
query.length,
|
|
312
|
+
sites,
|
|
313
|
+
concepts,
|
|
314
|
+
rec.leaves,
|
|
315
|
+
splits,
|
|
316
|
+
undefined,
|
|
317
|
+
connectors,
|
|
318
|
+
computedResults,
|
|
319
|
+
ctx.trace ? (steps) => derivations.push(steps) : undefined,
|
|
320
|
+
);
|
|
321
|
+
if (concepts.asked.size === 0 && connectors.asked.size === 0) break;
|
|
322
|
+
const grant = async () => {
|
|
323
|
+
await concepts.grant([...concepts.asked]);
|
|
324
|
+
await connectors.grant([...connectors.asked]);
|
|
325
|
+
};
|
|
326
|
+
if (ctx.meter) await ctx.meter.time("cover.grant", grant);
|
|
327
|
+
else await grant();
|
|
328
|
+
}
|
|
329
|
+
for (const steps of derivations) traceDerivation(ctx, steps);
|
|
265
330
|
const segs = solved && solved.segs;
|
|
266
331
|
tCover?.done(
|
|
267
332
|
segs === null
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
// that contains it.
|
|
9
9
|
|
|
10
10
|
import type { MindContext } from "../types.js";
|
|
11
|
-
import {
|
|
12
|
-
import { follow, isSpanShaped, locate, skillExemplar } from "../match.js";
|
|
11
|
+
import { locate } from "../match.js";
|
|
13
12
|
import { concatBytes, indexOf } from "../../bytes.js";
|
|
14
13
|
import { decodeText } from "../rationale.js";
|
|
15
14
|
import type {
|
|
@@ -103,7 +103,7 @@ import { bytesEqual } from "../../bytes.js";
|
|
|
103
103
|
import { rItem } from "../trace.js";
|
|
104
104
|
import { formsOpenedBy } from "../traverse.js";
|
|
105
105
|
import { STEP } from "../graph-search.js";
|
|
106
|
-
import type { PipelineMechanism
|
|
106
|
+
import type { PipelineMechanism } from "../pipeline-mechanism.js";
|
|
107
107
|
|
|
108
108
|
/** A trained form the query opens, and the bytes by which it continues. */
|
|
109
109
|
export interface PrefixCompletion {
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
import { cosine } from "../../vec.js";
|
|
8
8
|
import {
|
|
9
|
-
conceptThreshold,
|
|
10
9
|
consensusFloor,
|
|
11
10
|
dominates,
|
|
12
11
|
identityBar,
|
|
@@ -15,7 +14,7 @@ import {
|
|
|
15
14
|
} from "../../geometry.js";
|
|
16
15
|
import type { MindContext } from "../types.js";
|
|
17
16
|
import { gistOf, read, resolve } from "../primitives.js";
|
|
18
|
-
import {
|
|
17
|
+
import { indexOf } from "../../bytes.js";
|
|
19
18
|
import { allWindowsAreScaffolding, corpusN, hubBound } from "../traverse.js";
|
|
20
19
|
import {
|
|
21
20
|
follow,
|
|
@@ -73,7 +72,6 @@ export async function recallByResonance(
|
|
|
73
72
|
...(complete ? { complete } : {}),
|
|
74
73
|
};
|
|
75
74
|
};
|
|
76
|
-
const k = pre.k;
|
|
77
75
|
const queryGist = pre.guide;
|
|
78
76
|
|
|
79
77
|
// 0. Exact self-match — content-addressed, deterministic.
|
|
@@ -38,7 +38,7 @@ import type { MindContext } from "../types.js";
|
|
|
38
38
|
import type { FrameInstance } from "../match.js";
|
|
39
39
|
import { carriesFillers, distinct, follow, substituteAll } from "../match.js";
|
|
40
40
|
import { dominates } from "../../geometry.js";
|
|
41
|
-
import { bytesEqual
|
|
41
|
+
import { bytesEqual } from "../../bytes.js";
|
|
42
42
|
import { restates } from "../derivation.js";
|
|
43
43
|
import { STEP } from "../graph-search.js";
|
|
44
44
|
import type {
|
package/src/mind/mind.ts
CHANGED
|
@@ -9,41 +9,20 @@
|
|
|
9
9
|
// Architecture: 4 primitives × 2 patterns = all inference.
|
|
10
10
|
// Implementation split across src/mind/*.ts — this file assembles the Mind class.
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { makeKeyring, rng, setVecConfig, Vec } from "../vec.js";
|
|
13
|
+
import { Sema, Space } from "../sema.js";
|
|
14
14
|
import { sampleCorpus, searchCorpus } from "./corpus.js";
|
|
15
15
|
import type { CorpusPair, CorpusResult } from "./corpus.js";
|
|
16
16
|
import { Alphabet } from "../alphabet.js";
|
|
17
|
-
import {
|
|
18
|
-
bytesToTree,
|
|
19
|
-
contentFoldIncremental,
|
|
20
|
-
Grid,
|
|
21
|
-
gridToTree,
|
|
22
|
-
hilbertBytes,
|
|
23
|
-
reachThreshold,
|
|
24
|
-
stackGrids,
|
|
25
|
-
} from "../geometry.js";
|
|
17
|
+
import { contentFoldIncremental, Grid, reachThreshold } from "../geometry.js";
|
|
26
18
|
import { keyEnds } from "./canonical.js";
|
|
27
19
|
import type { ContentFold } from "../geometry.js";
|
|
28
20
|
import { BoundedMap, type Store } from "../store.js";
|
|
29
21
|
import { SQliteStore } from "../store-sqlite.js";
|
|
30
22
|
import { type MindConfig, resolveConfig } from "../config.js";
|
|
31
23
|
import { type Canon, canonHash, textCanon, textEdgeTrim } from "../canon.js";
|
|
32
|
-
import {
|
|
33
|
-
|
|
34
|
-
coverSequence,
|
|
35
|
-
lightestDerivation,
|
|
36
|
-
} from "../derive/src/index.js";
|
|
37
|
-
import { bytesEqual, concat2, concatBytes, indexOf } from "../bytes.js";
|
|
38
|
-
import {
|
|
39
|
-
type ComputedResult,
|
|
40
|
-
type DerivationItem,
|
|
41
|
-
type DerivationStep,
|
|
42
|
-
GraphSearch,
|
|
43
|
-
type Leaf,
|
|
44
|
-
type Seg,
|
|
45
|
-
type Site,
|
|
46
|
-
} from "./graph-search.js";
|
|
24
|
+
import { bytesEqual, concat2 } from "../bytes.js";
|
|
25
|
+
import { GraphSearch, type Leaf, type Site } from "./graph-search.js";
|
|
47
26
|
import { Alu } from "../alu/src/index.js";
|
|
48
27
|
import type { ComputedSpan, ExtensionHost } from "../extension.js";
|
|
49
28
|
|
|
@@ -147,16 +126,12 @@ interface ConversationData {
|
|
|
147
126
|
|
|
148
127
|
// Mind module imports
|
|
149
128
|
import type { AttentionRead, MindContext, Recognition } from "./types.js";
|
|
150
|
-
import { changedNodes, liftAnswer, spliceAll } from "./types.js";
|
|
151
129
|
import {
|
|
152
130
|
canonResolve as canonResolveImpl,
|
|
153
|
-
foldTree,
|
|
154
131
|
gistOf,
|
|
155
132
|
inputBytes,
|
|
156
|
-
latin1Key,
|
|
157
133
|
perceive as perceiveImpl,
|
|
158
134
|
perceiveKey,
|
|
159
|
-
read,
|
|
160
135
|
resolve as resolveImpl,
|
|
161
136
|
} from "./primitives.js";
|
|
162
137
|
import {
|