@hviana/sema 0.9.0 → 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 +20 -0
- package/dist/src/meter.js +21 -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 +29 -13
- 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 +21 -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 +24 -9
- 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
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { addInto, normalize, zeros } from "../vec.js";
|
|
6
6
|
import { bindSeat, companySignature, isChunk } from "../sema.js";
|
|
7
7
|
import { changedNodes } from "./types.js";
|
|
8
|
-
import { inputBytes, perceiveDeposit, resolve
|
|
8
|
+
import { inputBytes, perceiveDeposit, resolve } from "./primitives.js";
|
|
9
9
|
import { canonicalWindows, leafIdPrefix } from "./canonical.js";
|
|
10
10
|
import { rItem, rNode } from "./trace.js";
|
|
11
11
|
import { hubBound } from "./traverse.js";
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import type { MindContext } from "../types.js";
|
|
2
|
-
import type { Site } from "../graph-search.js";
|
|
2
|
+
import type { ConceptLicence, ConnectorLicence, Site } from "../graph-search.js";
|
|
3
3
|
import type { PipelineMechanism } from "../pipeline-mechanism.js";
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/** The concept hops the cover may take, OFFERED up front and looked up only
|
|
5
|
+
* when the search asks (see {@link Licence}): every recognised form with no
|
|
6
|
+
* continuation of its own may borrow a halo sibling's. */
|
|
7
|
+
export interface CoverConcepts extends ConceptLicence {
|
|
8
|
+
/** Look up the asked forms' concept targets not yet granted. */
|
|
9
|
+
grant(nodes: Iterable<number>): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
export declare function offerConcepts(ctx: MindContext, sites: ReadonlyArray<Site>): CoverConcepts;
|
|
12
|
+
/** The connectors the cover may splice, OFFERED up front and BRIDGED only when
|
|
13
|
+
* the search asks (see {@link ConnectorLicence}): every pair a learnt whole
|
|
14
|
+
* could run together — two touching sites, each side as itself or as its
|
|
15
|
+
* answer, in both orders — and, when three or more answers are recognised, the
|
|
16
|
+
* first answer to each later one (the N-ary whole). */
|
|
17
|
+
export interface CoverConnectors extends ConnectorLicence {
|
|
18
|
+
/** Bridge the asked pairs not yet granted. */
|
|
19
|
+
grant(keys: Iterable<string>): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export declare function offerConnectors(ctx: MindContext, sites: ReadonlyArray<Site>, query?: Uint8Array): CoverConnectors;
|
|
6
22
|
export declare const coverMechanism: PipelineMechanism;
|
|
@@ -16,31 +16,38 @@ import { liftAnswer, liftedScaffolding, segRestatesQuery } from "../types.js";
|
|
|
16
16
|
import { decodeText } from "../rationale.js";
|
|
17
17
|
import { insideAnsweredTurn, restates } from "../derivation.js";
|
|
18
18
|
import { rItem, rNode, traceDerivation } from "../trace.js";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const target = new Map();
|
|
22
|
-
const visited = new Set();
|
|
19
|
+
export function offerConcepts(ctx, sites) {
|
|
20
|
+
const offered = new Set();
|
|
23
21
|
for (const { payload: n } of sites) {
|
|
24
|
-
if (
|
|
25
|
-
|
|
26
|
-
visited.add(n);
|
|
27
|
-
if (ctx.store.hasNext(n))
|
|
28
|
-
continue;
|
|
29
|
-
const hop = await conceptHop(ctx, n);
|
|
30
|
-
if (hop !== null)
|
|
31
|
-
target.set(n, hop);
|
|
22
|
+
if (!offered.has(n) && !ctx.store.hasNext(n))
|
|
23
|
+
offered.add(n);
|
|
32
24
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
const granted = new Map();
|
|
26
|
+
return {
|
|
27
|
+
offered,
|
|
28
|
+
granted,
|
|
29
|
+
asked: new Set(),
|
|
30
|
+
async grant(nodes) {
|
|
31
|
+
const found = [];
|
|
32
|
+
for (const n of nodes) {
|
|
33
|
+
if (granted.has(n))
|
|
34
|
+
continue;
|
|
35
|
+
const hop = await conceptHop(ctx, n);
|
|
36
|
+
granted.set(n, hop);
|
|
37
|
+
if (hop !== null)
|
|
38
|
+
found.push([n, hop]);
|
|
39
|
+
}
|
|
40
|
+
if (found.length > 0) {
|
|
41
|
+
ctx.trace?.step("resolveConcepts", found.map(([n]) => rNode(ctx, n, "edgeless-form")), found.map(([, h]) => rNode(ctx, h, "concept-sibling")), "borrow a synonym's continuation edge for each edge-less form the search reached (a concept/halo hop)");
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
|
37
45
|
}
|
|
38
|
-
export
|
|
39
|
-
const links = new Map();
|
|
46
|
+
export function offerConnectors(ctx, sites, query) {
|
|
40
47
|
const answerOf = (n) => guidedFirst(ctx, n) ?? n;
|
|
41
48
|
// A site's continuation already present elsewhere in the query is stale
|
|
42
49
|
// transcript evidence: cover still needs the site for structural context,
|
|
43
|
-
// but liftAnswer will trim that continuation as already answered.
|
|
50
|
+
// but liftAnswer will trim that continuation as already answered. Offering
|
|
44
51
|
// pairwise/n-ary bridges for it can only create connectors that are later
|
|
45
52
|
// discarded — a semantically neutral gate (it removes work whose product
|
|
46
53
|
// liftAnswer throws away), and a cumulative (multi-turn) query is exactly
|
|
@@ -81,15 +88,7 @@ export async function resolveConnectors(ctx, sites, query) {
|
|
|
81
88
|
return restates(query, bytes, 0);
|
|
82
89
|
});
|
|
83
90
|
});
|
|
84
|
-
const
|
|
85
|
-
if (l === r || links.has(l + "," + r))
|
|
86
|
-
return;
|
|
87
|
-
if (ctx.meter)
|
|
88
|
-
ctx.meter.coverBridges++;
|
|
89
|
-
const link = await bridge(ctx, read(ctx, l), read(ctx, r));
|
|
90
|
-
if (link !== null)
|
|
91
|
-
links.set(l + "," + r, link);
|
|
92
|
-
};
|
|
91
|
+
const pairwise = new Set();
|
|
93
92
|
for (let i = 0; i + 1 < ordered.length; i++) {
|
|
94
93
|
if (ordered[i].end !== ordered[i + 1].start)
|
|
95
94
|
continue;
|
|
@@ -97,8 +96,10 @@ export async function resolveConnectors(ctx, sites, query) {
|
|
|
97
96
|
const rights = [ordered[i + 1].payload, answerOf(ordered[i + 1].payload)];
|
|
98
97
|
for (const l of new Set(lefts)) {
|
|
99
98
|
for (const r of new Set(rights)) {
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
if (l === r)
|
|
100
|
+
continue;
|
|
101
|
+
pairwise.add(l + "," + r);
|
|
102
|
+
pairwise.add(r + "," + l);
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
}
|
|
@@ -111,37 +112,61 @@ export async function resolveConnectors(ctx, sites, query) {
|
|
|
111
112
|
seenN.add(node);
|
|
112
113
|
orderedNodes.push({ node, bytes: read(ctx, node) });
|
|
113
114
|
}
|
|
115
|
+
const nary = new Map();
|
|
114
116
|
if (orderedNodes.length >= 3) {
|
|
115
117
|
const first = orderedNodes[0];
|
|
116
118
|
const W = ctx.space.maxGroup;
|
|
117
119
|
let middleBytes = 0; // Σ bytes of the answers BETWEEN first and m-th
|
|
118
120
|
for (let m = 1; m < orderedNodes.length; m++) {
|
|
119
|
-
const key = first.node + "," + orderedNodes[m].node;
|
|
120
|
-
if (links.has(key)) {
|
|
121
|
-
middleBytes += orderedNodes[m].bytes.length;
|
|
122
|
-
continue;
|
|
123
|
-
}
|
|
124
121
|
// The N-ary interior legitimately holds every intermediate answer
|
|
125
122
|
// plus one W-quantum of glue per joint — pass that allowance so the
|
|
126
|
-
// bridge's phrase-scale cap admits the whole learnt run.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (interior !== null)
|
|
134
|
-
links.set(key, interior);
|
|
123
|
+
// bridge's phrase-scale cap admits the whole learnt run. Asked only
|
|
124
|
+
// when the pairwise bridge of the same key (if offered) found nothing.
|
|
125
|
+
nary.set(first.node + "," + orderedNodes[m].node, {
|
|
126
|
+
left: first.bytes,
|
|
127
|
+
right: orderedNodes[m].bytes,
|
|
128
|
+
allowance: middleBytes + (m + 1) * W,
|
|
129
|
+
});
|
|
135
130
|
middleBytes += orderedNodes[m].bytes.length;
|
|
136
131
|
}
|
|
137
132
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
133
|
+
const granted = new Map();
|
|
134
|
+
return {
|
|
135
|
+
offered: new Set([...pairwise, ...nary.keys()]),
|
|
136
|
+
granted,
|
|
137
|
+
asked: new Set(),
|
|
138
|
+
async grant(keys) {
|
|
139
|
+
const found = [];
|
|
140
|
+
for (const key of keys) {
|
|
141
|
+
if (granted.has(key))
|
|
142
|
+
continue;
|
|
143
|
+
let link = null;
|
|
144
|
+
if (pairwise.has(key)) {
|
|
145
|
+
const comma = key.indexOf(",");
|
|
146
|
+
if (ctx.meter)
|
|
147
|
+
ctx.meter.coverBridges++;
|
|
148
|
+
link = await bridge(ctx, read(ctx, Number(key.slice(0, comma))), read(ctx, Number(key.slice(comma + 1))));
|
|
149
|
+
}
|
|
150
|
+
const whole = nary.get(key);
|
|
151
|
+
if (link === null && whole !== undefined) {
|
|
152
|
+
if (ctx.meter) {
|
|
153
|
+
ctx.meter.coverBridges++;
|
|
154
|
+
ctx.meter.coverAllowanceBytes += whole.allowance;
|
|
155
|
+
}
|
|
156
|
+
link = await bridge(ctx, whole.left, whole.right, whole.allowance);
|
|
157
|
+
}
|
|
158
|
+
granted.set(key, link);
|
|
159
|
+
if (link !== null)
|
|
160
|
+
found.push([key, link]);
|
|
161
|
+
}
|
|
162
|
+
if (found.length > 0) {
|
|
163
|
+
ctx.trace?.step("resolveConnectors", ordered.map((s) => rItem(read(ctx, s.payload), "answer", s.payload)), found.map(([pair, bytes]) => ({
|
|
164
|
+
text: `${pair}: "${decodeText(bytes)}"`,
|
|
165
|
+
role: "connector",
|
|
166
|
+
})), "the bytes the graph splices between adjacent answers the search reached (asked of the gist space)");
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
};
|
|
145
170
|
}
|
|
146
171
|
// ── Pipeline mechanism ──────────────────────────────────────────────────────
|
|
147
172
|
export const coverMechanism = {
|
|
@@ -169,8 +194,8 @@ export const coverMechanism = {
|
|
|
169
194
|
if (sites.length === 0 && computed.length === 0)
|
|
170
195
|
return [];
|
|
171
196
|
const connectors = ctx.meter
|
|
172
|
-
?
|
|
173
|
-
:
|
|
197
|
+
? ctx.meter.timeSync("cover.offerConnectors", () => offerConnectors(ctx, sites, query))
|
|
198
|
+
: offerConnectors(ctx, sites, query);
|
|
174
199
|
let splits = rec.splits;
|
|
175
200
|
if (computed.length > 0) {
|
|
176
201
|
splits = new Set(rec.splits);
|
|
@@ -180,13 +205,11 @@ export const coverMechanism = {
|
|
|
180
205
|
}
|
|
181
206
|
}
|
|
182
207
|
const concepts = ctx.meter
|
|
183
|
-
?
|
|
184
|
-
:
|
|
208
|
+
? ctx.meter.timeSync("cover.offerConcepts", () => offerConcepts(ctx, sites))
|
|
209
|
+
: offerConcepts(ctx, sites);
|
|
185
210
|
const coverDeps = [
|
|
186
211
|
ctx.trace?.lastIndex("recognise"),
|
|
187
212
|
ctx.trace?.lastIndex("computeExtensions"),
|
|
188
|
-
ctx.trace?.lastIndex("resolveConcepts"),
|
|
189
|
-
ctx.trace?.lastIndex("resolveConnectors"),
|
|
190
213
|
].filter((x) => x !== undefined);
|
|
191
214
|
// Convert ComputedSpan[] to ComputedResult[] for the graph search.
|
|
192
215
|
const computedResults = computed.map((u) => ({
|
|
@@ -202,7 +225,27 @@ export const coverMechanism = {
|
|
|
202
225
|
])),
|
|
203
226
|
...computedResults.map((u) => rItem(u.bytes, "computed")),
|
|
204
227
|
], coverDeps.length ? coverDeps : undefined);
|
|
205
|
-
|
|
228
|
+
// COVER, GRANT WHAT IT ASKED, COVER AGAIN — until a cover asks for nothing
|
|
229
|
+
// (see Licence in graph-search.ts). Only the final cover's derivations reach the
|
|
230
|
+
// rationale; a provisional one is superseded, not part of the answer.
|
|
231
|
+
let derivations = [];
|
|
232
|
+
let solved;
|
|
233
|
+
for (;;) {
|
|
234
|
+
derivations = [];
|
|
235
|
+
solved = ctx.search.cover(query.length, sites, concepts, rec.leaves, splits, undefined, connectors, computedResults, ctx.trace ? (steps) => derivations.push(steps) : undefined);
|
|
236
|
+
if (concepts.asked.size === 0 && connectors.asked.size === 0)
|
|
237
|
+
break;
|
|
238
|
+
const grant = async () => {
|
|
239
|
+
await concepts.grant([...concepts.asked]);
|
|
240
|
+
await connectors.grant([...connectors.asked]);
|
|
241
|
+
};
|
|
242
|
+
if (ctx.meter)
|
|
243
|
+
await ctx.meter.time("cover.grant", grant);
|
|
244
|
+
else
|
|
245
|
+
await grant();
|
|
246
|
+
}
|
|
247
|
+
for (const steps of derivations)
|
|
248
|
+
traceDerivation(ctx, steps);
|
|
206
249
|
const segs = solved && solved.segs;
|
|
207
250
|
tCover?.done(segs === null
|
|
208
251
|
? []
|
package/dist/src/mind/mind.js
CHANGED
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
import { makeKeyring, rng, setVecConfig } from "../vec.js";
|
|
12
12
|
import { sampleCorpus, searchCorpus } from "./corpus.js";
|
|
13
13
|
import { Alphabet } from "../alphabet.js";
|
|
14
|
-
import { contentFoldIncremental, reachThreshold
|
|
14
|
+
import { contentFoldIncremental, reachThreshold } from "../geometry.js";
|
|
15
15
|
import { keyEnds } from "./canonical.js";
|
|
16
16
|
import { BoundedMap } from "../store.js";
|
|
17
17
|
import { SQliteStore } from "../store-sqlite.js";
|
|
18
18
|
import { resolveConfig } from "../config.js";
|
|
19
19
|
import { canonHash, textCanon, textEdgeTrim } from "../canon.js";
|
|
20
20
|
import { bytesEqual, concat2 } from "../bytes.js";
|
|
21
|
-
import { GraphSearch
|
|
21
|
+
import { GraphSearch } from "./graph-search.js";
|
|
22
22
|
import { Alu } from "../alu/src/index.js";
|
|
23
23
|
import { decodeText, Rationale, } from "./rationale.js";
|
|
24
24
|
import { canonResolve as canonResolveImpl, gistOf, inputBytes, perceive as perceiveImpl, perceiveKey, resolve as resolveImpl, } from "./primitives.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { MindContext } from "./types.js";
|
|
2
2
|
import { type PipelineMechanism } from "./pipeline-mechanism.js";
|
|
3
|
-
export {
|
|
3
|
+
export { offerConcepts, offerConnectors } from "./mechanisms/cover.js";
|
|
4
4
|
export { aluToMechanism } from "./mechanisms/alu.js";
|
|
5
5
|
export declare const defaultMechanisms: PipelineMechanism[];
|
|
6
6
|
export type Provenance = "cast" | "join" | "cover" | "extract" | "reference" | "recall" | "recall-echo" | "prefix";
|
|
@@ -60,6 +60,10 @@ export interface RegimePredictionData {
|
|
|
60
60
|
* CAST's floor) — the bar the incumbent must sit at or below for the
|
|
61
61
|
* consensus climb to be skipped. */
|
|
62
62
|
climbFloorGrade: number;
|
|
63
|
+
/** The lowest grade reached by a mechanism run AHEAD of a dearer one (see
|
|
64
|
+
* the grounding loop), when one ran and grounded: a bound below
|
|
65
|
+
* `climbFloorGrade` makes the regime retrieval whatever the incumbent. */
|
|
66
|
+
boundGrade?: number;
|
|
63
67
|
}
|
|
64
68
|
/** Think: a single lightest-derivation exploration of the Sema graph.
|
|
65
69
|
*
|