@polycode-projects/the-mechanical-code-talker 5.0.15 → 5.0.17
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/README.md +12 -3
- package/bin/tmct.mjs +52 -3
- package/corpus/LICENSES.json +3 -3
- package/corpus/domains/code/LICENSE-NOTICE +43 -0
- package/corpus/{seon → domains/code}/README.md +22 -24
- package/corpus/domains/code/vocab.json +43 -0
- package/corpus/reference/manifest.json +126 -126
- package/corpus/reference/shards/ref-00.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-01.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-02.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-03.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-04.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-05.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-06.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-07.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-08.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-09.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0f.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-10.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-11.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-12.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-13.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-14.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-15.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-16.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-17.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-18.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-19.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1f.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-20.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-21.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-22.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-23.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-24.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-25.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-26.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-27.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-28.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-29.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2f.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-30.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-31.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-32.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-33.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-34.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-35.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-36.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-37.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-38.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-39.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3f.jsonl.gz +0 -0
- package/corpus/tier2/vocab-empty.json +6 -0
- package/data/templates/responses.jsonl +3 -0
- package/package.json +19 -1
- package/src/adapters/corpus/conceptnet.mjs +7 -3
- package/src/adapters/corpus/courtesy.mjs +129 -0
- package/src/adapters/corpus/research-source.mjs +137 -0
- package/src/adapters/corpus/wikidata-live.mjs +262 -0
- package/src/adapters/corpus/wikipedia-live.mjs +83 -116
- package/src/domain/cli-verbs.mjs +2 -0
- package/src/domain/codegraph.mjs +10 -2
- package/src/domain/grammar/lexicon-core.json +1 -0
- package/src/domain/reference-pack.mjs +61 -9
- package/src/services/chat-page-viz.mjs +9 -6
- package/src/services/chat-session.mjs +65 -9
- package/src/services/chat.mjs +395 -121
- package/src/services/extensions.mjs +203 -3
- package/src/services/init.mjs +27 -6
- package/src/services/lane-vocab-data.mjs +56 -0
- package/src/services/research.mjs +36 -14
- package/src/surfaces/web/claims-browser-entry.mjs +26 -0
- package/src/surfaces/web/memory-ask-browser.bundle.js +130 -128
- package/src/surfaces/web/planner-instances.mjs +152 -0
- package/src/tools/handlers/tmct-untested.mjs +2 -2
- package/src/tools/server.mjs +9 -4
- package/corpus/seon/LICENSE-NOTICE +0 -37
- /package/corpus/{seon → domains/code}/concepts.jsonl +0 -0
- /package/corpus/{seon → domains/code}/definitions.jsonl +0 -0
- /package/corpus/{seon → domains/code}/relations.jsonl +0 -0
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
import { isAbsolute, join, resolve, dirname } from "node:path";
|
|
21
21
|
import { readFile } from "node:fs/promises";
|
|
22
22
|
import { fileURLToPath } from "node:url";
|
|
23
|
+
import { CODE_VOCAB_DATA, EMPTY_VOCAB_DATA as TIER2_EMPTY_VOCAB_DATA } from "./lane-vocab-data.mjs";
|
|
23
24
|
import { loadTomlConfig } from "../adapters/toml-config.mjs";
|
|
24
25
|
import {
|
|
25
26
|
SEON_CONCEPTS_FILE,
|
|
@@ -35,6 +36,17 @@ import {
|
|
|
35
36
|
// corpus/namenet/generate.mjs's output — a single small top-up bundle.
|
|
36
37
|
const NAMENET_DIR = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "corpus", "namenet");
|
|
37
38
|
|
|
39
|
+
// The code domain pack's lane vocabulary — count nouns/class labels, help rows
|
|
40
|
+
// and the miss-recovery pointer today's code-graph surfaces render, moved out
|
|
41
|
+
// of chat.mjs so a bare install carries none of it (see mergedLaneVocab).
|
|
42
|
+
const CODE_VOCAB_FILE = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "corpus", "domains", "code", "vocab.json");
|
|
43
|
+
|
|
44
|
+
// Empty vocabulary file for tier2 packs: they are authored corpora with no
|
|
45
|
+
// extraction adapter, so they need no lane-specific vocabulary, help rows, or
|
|
46
|
+
// miss-recovery pointers. A pack entry can have an empty vocab (counts as having
|
|
47
|
+
// one declared, but contributes nothing to the merged lane vocabulary).
|
|
48
|
+
const TIER2_EMPTY_VOCAB_FILE = join(dirname(fileURLToPath(import.meta.url)), "..", "..", "corpus", "tier2", "vocab-empty.json");
|
|
49
|
+
|
|
38
50
|
export const EXTENSION_KINDS = Object.freeze(["corpus", "lexicon", "templates", "pack", "ontology"]);
|
|
39
51
|
|
|
40
52
|
// The definitional-band-first predicate order for the ConceptNet seed (re-declared,
|
|
@@ -52,6 +64,23 @@ function builtinExtensions() {
|
|
|
52
64
|
corpusPath: SEON_CONCEPTS_FILE,
|
|
53
65
|
provenancePrefix: "corpus:seon",
|
|
54
66
|
},
|
|
67
|
+
// The code DOMAIN PACK: the seon corpus plus the lane vocabulary (count
|
|
68
|
+
// nouns, help rows, the miss-recovery pointer) a code-graph session needs
|
|
69
|
+
// — see mergedLaneVocab. Keeps seon's own provenance prefix (the curated-
|
|
70
|
+
// definitions gate keys on "corpus:seon" rows regardless of which entry
|
|
71
|
+
// seeded them). Its grounding channel is an extraction adapter: `tmct
|
|
72
|
+
// index` (and the graphPaths provider seam) is the deterministic path
|
|
73
|
+
// from a repo's own source to the facts this pack's vocabulary describes.
|
|
74
|
+
code: {
|
|
75
|
+
kind: "pack",
|
|
76
|
+
active: false,
|
|
77
|
+
corpusPath: SEON_CONCEPTS_FILE,
|
|
78
|
+
provenancePrefix: "corpus:seon",
|
|
79
|
+
vocabPath: CODE_VOCAB_FILE,
|
|
80
|
+
vocabData: CODE_VOCAB_DATA,
|
|
81
|
+
groundingKind: "extraction",
|
|
82
|
+
groundingAdapter: "tmct index (the graphPaths provider seam)",
|
|
83
|
+
},
|
|
55
84
|
// Opt-in too: the committed slice is tech-domain-filtered, equally biased.
|
|
56
85
|
conceptnet: {
|
|
57
86
|
kind: "corpus",
|
|
@@ -83,23 +112,37 @@ function builtinExtensions() {
|
|
|
83
112
|
corpusPath: join(TIER2_DIR, "human-large.jsonl"),
|
|
84
113
|
provenancePrefix: "corpus:human-large",
|
|
85
114
|
},
|
|
115
|
+
// Tier2 packs: authored language-domain bundles (AWS, Python, Java) without
|
|
116
|
+
// extraction adapters (no tmct index for these domains yet). Each bundles
|
|
117
|
+
// its corpus unchanged and an empty lane vocabulary, so a bare install stays
|
|
118
|
+
// domain-neutral (no AWS/Python/Java vocabulary reaches banners or help text
|
|
119
|
+
// without explicit activation).
|
|
86
120
|
"tier2-aws": {
|
|
87
|
-
kind: "
|
|
121
|
+
kind: "pack",
|
|
88
122
|
active: false,
|
|
89
123
|
corpusPath: join(TIER2_DIR, "aws.jsonl"),
|
|
90
124
|
provenancePrefix: "corpus:tier2-aws",
|
|
125
|
+
vocabPath: TIER2_EMPTY_VOCAB_FILE,
|
|
126
|
+
vocabData: TIER2_EMPTY_VOCAB_DATA,
|
|
127
|
+
groundingKind: "taught-only",
|
|
91
128
|
},
|
|
92
129
|
"tier2-python": {
|
|
93
|
-
kind: "
|
|
130
|
+
kind: "pack",
|
|
94
131
|
active: false,
|
|
95
132
|
corpusPath: join(TIER2_DIR, "python.jsonl"),
|
|
96
133
|
provenancePrefix: "corpus:tier2-python",
|
|
134
|
+
vocabPath: TIER2_EMPTY_VOCAB_FILE,
|
|
135
|
+
vocabData: TIER2_EMPTY_VOCAB_DATA,
|
|
136
|
+
groundingKind: "taught-only",
|
|
97
137
|
},
|
|
98
138
|
"tier2-java": {
|
|
99
|
-
kind: "
|
|
139
|
+
kind: "pack",
|
|
100
140
|
active: false,
|
|
101
141
|
corpusPath: join(TIER2_DIR, "java.jsonl"),
|
|
102
142
|
provenancePrefix: "corpus:tier2-java",
|
|
143
|
+
vocabPath: TIER2_EMPTY_VOCAB_FILE,
|
|
144
|
+
vocabData: TIER2_EMPTY_VOCAB_DATA,
|
|
145
|
+
groundingKind: "taught-only",
|
|
103
146
|
},
|
|
104
147
|
"tier2-general": {
|
|
105
148
|
kind: "corpus",
|
|
@@ -193,6 +236,7 @@ function mergeExtensionEntry(name, builtin, override, repoRoot) {
|
|
|
193
236
|
["templates_path", "templatesPath"],
|
|
194
237
|
["phrasebook_path", "phrasebookPath"],
|
|
195
238
|
["map_path", "mapPath"],
|
|
239
|
+
["vocab_path", "vocabPath"],
|
|
196
240
|
];
|
|
197
241
|
for (const [rawKey, key] of paths) {
|
|
198
242
|
if (override[rawKey] !== undefined) entry[key] = resolvePathMaybe(repoRoot, override[rawKey]);
|
|
@@ -205,6 +249,13 @@ function mergeExtensionEntry(name, builtin, override, repoRoot) {
|
|
|
205
249
|
else if (builtin?.limit !== undefined) entry.limit = builtin.limit;
|
|
206
250
|
if (override.prefer !== undefined) entry.prefer = override.prefer;
|
|
207
251
|
else if (builtin?.prefer !== undefined) entry.prefer = builtin.prefer;
|
|
252
|
+
// The grounding-channel declaration (validateExtensionPack requires it on a
|
|
253
|
+
// "pack" candidate): "extraction" names an adapter (grounding_adapter);
|
|
254
|
+
// "taught-only" says the pack's facts grow solely through the teach lane.
|
|
255
|
+
if (override.grounding_kind !== undefined) entry.groundingKind = String(override.grounding_kind);
|
|
256
|
+
else if (builtin?.groundingKind !== undefined) entry.groundingKind = builtin.groundingKind;
|
|
257
|
+
if (override.grounding_adapter !== undefined) entry.groundingAdapter = String(override.grounding_adapter);
|
|
258
|
+
else if (builtin?.groundingAdapter !== undefined) entry.groundingAdapter = builtin.groundingAdapter;
|
|
208
259
|
return entry;
|
|
209
260
|
}
|
|
210
261
|
|
|
@@ -329,6 +380,117 @@ export async function mergedLexiconExtra(entries, biasByBundle = {}) {
|
|
|
329
380
|
return merged;
|
|
330
381
|
}
|
|
331
382
|
|
|
383
|
+
// ---- Part 3b: lane-vocabulary merge (vocab_path) -----------------------------
|
|
384
|
+
|
|
385
|
+
/** Merge every ACTIVE `pack`-kind entry's declared `vocab_path` file into one
|
|
386
|
+
* lane-vocabulary object: `countNouns`/`classLabels` (the count lane's noun
|
|
387
|
+
* table), `helpRows` (the command rows a code-domain pack contributes to
|
|
388
|
+
* `/help`) and `missRecoveryPointer` (the remedy line an empty session's
|
|
389
|
+
* banner offers). Bundles merge in ascending bias order, same rule as
|
|
390
|
+
* mergedLexiconExtra: a higher-bias bundle's same-key entry wins.
|
|
391
|
+
* `helpRows` and `countNouns`/`classLabels` are additive across bundles;
|
|
392
|
+
* `missRecoveryPointer` is single-valued, so the highest-bias bundle to
|
|
393
|
+
* declare one wins outright. No active pack with a vocab_path → every field
|
|
394
|
+
* comes back empty — a bare session carries no code-domain vocabulary. */
|
|
395
|
+
export async function mergedLaneVocab(entries, biasByBundle = {}) {
|
|
396
|
+
const candidates = [];
|
|
397
|
+
for (const [name, entry] of entries instanceof Map ? entries : new Map()) {
|
|
398
|
+
if (!entry.active) continue;
|
|
399
|
+
if (entry.kind !== "pack") continue;
|
|
400
|
+
if (!entry.vocabPath && !entry.vocabData) continue;
|
|
401
|
+
candidates.push({ name, path: entry.vocabPath, data: entry.vocabData, bias: biasByBundle[name] ?? 1 });
|
|
402
|
+
}
|
|
403
|
+
const merged = { countNouns: {}, classLabels: {}, helpRows: [], missRecoveryPointer: "" };
|
|
404
|
+
if (!candidates.length) return merged;
|
|
405
|
+
candidates.sort((a, b) => a.bias - b.bias);
|
|
406
|
+
for (const c of candidates) {
|
|
407
|
+
let raw;
|
|
408
|
+
if (c.data) {
|
|
409
|
+
raw = c.data;
|
|
410
|
+
} else {
|
|
411
|
+
try {
|
|
412
|
+
raw = JSON.parse(await readFile(c.path, "utf8"));
|
|
413
|
+
} catch (e) {
|
|
414
|
+
throw new Error(`extension "${c.name}": vocab file ${c.path} — ${e && e.message ? e.message : e}`);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
Object.assign(merged.countNouns, raw.countNouns || {});
|
|
418
|
+
Object.assign(merged.classLabels, raw.classLabels || {});
|
|
419
|
+
if (Array.isArray(raw.helpRows)) merged.helpRows.push(...raw.helpRows);
|
|
420
|
+
if (raw.missRecoveryPointer) merged.missRecoveryPointer = raw.missRecoveryPointer;
|
|
421
|
+
}
|
|
422
|
+
return merged;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
let cachedDefaultCodeLaneVocab = null;
|
|
426
|
+
/** The shipped code pack's OWN lane vocabulary, loaded unconditionally
|
|
427
|
+
* (memoized — the file never changes mid-process). The safety net a caller
|
|
428
|
+
* holding a real code graph falls back to when the `code` pack itself isn't
|
|
429
|
+
* formally active in tmct.toml — the same "a real graph is enough" rule
|
|
430
|
+
* chat.mjs's own codeDomainActive already applies to the domain-active
|
|
431
|
+
* predicate. Never consulted when the domain is inactive. */
|
|
432
|
+
export function defaultCodeLaneVocab() {
|
|
433
|
+
if (!cachedDefaultCodeLaneVocab) {
|
|
434
|
+
const code = { ...builtinExtensions().code, active: true };
|
|
435
|
+
cachedDefaultCodeLaneVocab = mergedLaneVocab(new Map([["code", code]]), {});
|
|
436
|
+
}
|
|
437
|
+
return cachedDefaultCodeLaneVocab;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/** Read one pack entry's own declaration into the shape a capability listing
|
|
441
|
+
* renders: the pack's name, the grounding channel it declares
|
|
442
|
+
* (grounding_kind/grounding_adapter) and how much its `vocab_path` file adds
|
|
443
|
+
* to the lane merge. A pack whose vocab file is missing or malformed still
|
|
444
|
+
* names itself and its grounding channel, with nothing counted — the listing
|
|
445
|
+
* reports what the pack declares, and never invents a contribution. */
|
|
446
|
+
async function declaredPackSummary(name, entry) {
|
|
447
|
+
const summary = {
|
|
448
|
+
name,
|
|
449
|
+
groundingKind: entry.groundingKind || "",
|
|
450
|
+
groundingAdapter: entry.groundingAdapter || "",
|
|
451
|
+
commandCount: 0,
|
|
452
|
+
countNounCount: 0,
|
|
453
|
+
};
|
|
454
|
+
if (!entry.vocabPath) return summary;
|
|
455
|
+
try {
|
|
456
|
+
const raw = JSON.parse(await readFile(entry.vocabPath, "utf8"));
|
|
457
|
+
summary.commandCount = Array.isArray(raw.helpRows) ? raw.helpRows.length : 0;
|
|
458
|
+
summary.countNounCount = Object.keys(raw.countNouns || {}).length;
|
|
459
|
+
} catch { /* an unreadable vocab file lists as a pack that adds nothing */ }
|
|
460
|
+
return summary;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/** Every ACTIVE `pack`-kind entry, summarized from its own declaration, in
|
|
464
|
+
* ascending bias order (name breaks a tie, so the listing is stable). The
|
|
465
|
+
* read-side companion to mergedLaneVocab: that merges what packs contribute,
|
|
466
|
+
* this says which packs contributed it. No active pack → an empty list, and
|
|
467
|
+
* a listing that names no domain at all. */
|
|
468
|
+
export async function activeDomainPacks(entries, biasByBundle = {}) {
|
|
469
|
+
const candidates = [];
|
|
470
|
+
for (const [name, entry] of entries instanceof Map ? entries : new Map()) {
|
|
471
|
+
if (!entry.active) continue;
|
|
472
|
+
if (entry.kind !== "pack") continue;
|
|
473
|
+
candidates.push({ name, entry, bias: biasByBundle[name] ?? 1 });
|
|
474
|
+
}
|
|
475
|
+
candidates.sort((a, b) => a.bias - b.bias || a.name.localeCompare(b.name));
|
|
476
|
+
const summaries = [];
|
|
477
|
+
for (const c of candidates) summaries.push(await declaredPackSummary(c.name, c.entry));
|
|
478
|
+
return summaries;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
let cachedDefaultCodeDomainPacks = null;
|
|
482
|
+
/** The shipped code pack's OWN declaration as a one-entry listing — the same
|
|
483
|
+
* "a real graph is enough" fallback defaultCodeLaneVocab serves, for the
|
|
484
|
+
* caller that holds a real code graph without the `code` pack formally
|
|
485
|
+
* active in tmct.toml. Never consulted when the domain is inactive. */
|
|
486
|
+
export function defaultCodeDomainPacks() {
|
|
487
|
+
if (!cachedDefaultCodeDomainPacks) {
|
|
488
|
+
const code = { ...builtinExtensions().code, active: true };
|
|
489
|
+
cachedDefaultCodeDomainPacks = activeDomainPacks(new Map([["code", code]]), {});
|
|
490
|
+
}
|
|
491
|
+
return cachedDefaultCodeDomainPacks;
|
|
492
|
+
}
|
|
493
|
+
|
|
332
494
|
// ---- Part 4: `tmct extend --validate <dir>` ---------------------------------
|
|
333
495
|
|
|
334
496
|
/** Validate one CANDIDATE extension pack entry against a directory, reusing the existing
|
|
@@ -381,5 +543,43 @@ export async function validateExtensionPack(dir, candidate) {
|
|
|
381
543
|
}
|
|
382
544
|
}
|
|
383
545
|
|
|
546
|
+
if (candidate.vocabPath) {
|
|
547
|
+
const path = abs(candidate.vocabPath);
|
|
548
|
+
try {
|
|
549
|
+
const raw = JSON.parse(await readFile(path, "utf8"));
|
|
550
|
+
const countNouns = raw.countNouns && typeof raw.countNouns === "object" ? Object.keys(raw.countNouns).length : 0;
|
|
551
|
+
const classLabels = raw.classLabels && typeof raw.classLabels === "object" ? Object.keys(raw.classLabels).length : 0;
|
|
552
|
+
const helpRows = Array.isArray(raw.helpRows) ? raw.helpRows.length : 0;
|
|
553
|
+
results.push({ kind: "vocab", path, ok: true, counts: { countNouns, classLabels, helpRows } });
|
|
554
|
+
} catch (e) {
|
|
555
|
+
results.push({ kind: "vocab", path, ok: false, error: e && e.message ? e.message : String(e) });
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// The grounding-channel declaration — required on a "pack" candidate only
|
|
560
|
+
// (a plain corpus/lexicon/templates/ontology entry declares no grounding):
|
|
561
|
+
// exactly one of an extraction adapter (named) or explicit taught-only
|
|
562
|
+
// mode. A pack declaring neither is symbols defined in symbols, with no
|
|
563
|
+
// route from a domain's own artifacts back to the facts it describes.
|
|
564
|
+
if (candidate.kind === "pack") {
|
|
565
|
+
const gk = candidate.groundingKind;
|
|
566
|
+
if (gk !== "extraction" && gk !== "taught-only") {
|
|
567
|
+
results.push({
|
|
568
|
+
kind: "grounding", path: "(pack manifest)", ok: false,
|
|
569
|
+
error: `a "pack" entry needs "grounding_kind" of "extraction" or "taught-only" (got ${JSON.stringify(gk ?? null)})`,
|
|
570
|
+
});
|
|
571
|
+
} else if (gk === "extraction" && !candidate.groundingAdapter) {
|
|
572
|
+
results.push({
|
|
573
|
+
kind: "grounding", path: "(pack manifest)", ok: false,
|
|
574
|
+
error: 'grounding_kind "extraction" needs "grounding_adapter" naming the adapter',
|
|
575
|
+
});
|
|
576
|
+
} else {
|
|
577
|
+
results.push({
|
|
578
|
+
kind: "grounding", path: "(pack manifest)", ok: true,
|
|
579
|
+
counts: gk === "extraction" ? { channel: gk, adapter: candidate.groundingAdapter } : { channel: gk },
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
384
584
|
return { ok: results.length > 0 && results.every((r) => r.ok), results };
|
|
385
585
|
}
|
package/src/services/init.mjs
CHANGED
|
@@ -52,11 +52,12 @@ export function defaultConfig() {
|
|
|
52
52
|
|
|
53
53
|
/** `tmct init --with-persona <name>` presets: a named bundle of `extensions`/`bias`
|
|
54
54
|
* overrides written into tmct.toml. `human` makes the implicit default explicit; `code`
|
|
55
|
-
*
|
|
56
|
-
*
|
|
55
|
+
* activates the `code` domain pack (the seon ontology plus its lane vocabulary — count
|
|
56
|
+
* nouns, help rows, the miss-recovery pointer) alongside `conceptnet`; `empty`
|
|
57
|
+
* deactivates `human`, leaving a repo genuinely empty of corpus facts. */
|
|
57
58
|
export const PERSONA_PRESETS = Object.freeze({
|
|
58
59
|
human: { extensions: {}, bias: { human: 1.0 } },
|
|
59
|
-
code: { extensions: {
|
|
60
|
+
code: { extensions: { code: { active: true }, conceptnet: { active: true } }, bias: { code: 1.0, conceptnet: 1.0 } },
|
|
60
61
|
empty: { extensions: { human: { active: false } }, bias: {} },
|
|
61
62
|
});
|
|
62
63
|
|
|
@@ -144,6 +145,19 @@ backend = ${JSON.stringify(config.memory.backend)}
|
|
|
144
145
|
`;
|
|
145
146
|
}
|
|
146
147
|
|
|
148
|
+
// [research] source — only emitted when a caller actually supplies it.
|
|
149
|
+
if (config.research && config.research.source !== undefined) {
|
|
150
|
+
out += `
|
|
151
|
+
[research]
|
|
152
|
+
# Which source "research <topic>" fetches from.
|
|
153
|
+
# Precedence: /wikipedia|/wikidata in chat > --research-source flag >
|
|
154
|
+
# this file > "wikipedia" (the built-in default).
|
|
155
|
+
# "wikipedia" — Simple English Wikipedia prose articles, CC BY-SA 4.0.
|
|
156
|
+
# "wikidata" — Wikidata's structured claims, CC0 1.0.
|
|
157
|
+
source = ${JSON.stringify(config.research.source)}
|
|
158
|
+
`;
|
|
159
|
+
}
|
|
160
|
+
|
|
147
161
|
// Extension-pack / bias sections — only emitted when a caller supplies them.
|
|
148
162
|
const extras = {};
|
|
149
163
|
if (config.extensions !== undefined) extras.extensions = config.extensions;
|
|
@@ -151,7 +165,7 @@ backend = ${JSON.stringify(config.memory.backend)}
|
|
|
151
165
|
if (!Object.keys(extras).length) return out;
|
|
152
166
|
return `${out}
|
|
153
167
|
# Extension packs + bias (src/services/extensions.mjs) — written by \`tmct init --with-persona\`
|
|
154
|
-
# or a manual edit. Recognized names (human, seon, conceptnet, tier2-aws,
|
|
168
|
+
# or a manual edit. Recognized names (human, seon, code, conceptnet, tier2-aws,
|
|
155
169
|
# tier2-python, tier2-java, tier2-general) override the shipped defaults; any
|
|
156
170
|
# other name declares a new host-supplied bundle (needs its own "kind").
|
|
157
171
|
# [bias] is a flat bundle-name -> weight table consumed by
|
|
@@ -183,13 +197,16 @@ function seedRequested({ optSeed, configEnabled, env }) {
|
|
|
183
197
|
* @param {string} [opts.memoryBackend] "default" | "memory" | "sqlite" — merged into a
|
|
184
198
|
* FRESH config's `[memory] backend`, and selects which backend the corpus seed writes
|
|
185
199
|
* into (via src/adapters/memory/core.mjs's openMemoryBackend).
|
|
200
|
+
* @param {string} [opts.researchSource] "wikipedia" | "wikidata" — merged into a
|
|
201
|
+
* FRESH config's `[research] source`, the tmct.toml tier of the research lane's
|
|
202
|
+
* source precedence (src/services/chat-session.mjs createSession).
|
|
186
203
|
* @returns {Promise<{
|
|
187
204
|
* created: string[], config: object, seeded: boolean,
|
|
188
205
|
* alreadyInitialized: boolean, seedResult: (object|null), message: string
|
|
189
206
|
* }>} `created` lists the absolute paths this call brought into being. Never throws on
|
|
190
207
|
* a benign re-init or a corpus failure.
|
|
191
208
|
*/
|
|
192
|
-
export async function initRepo(dir, { force = false, seed, env = process.env, persona = null, memoryBackend = null } = {}) {
|
|
209
|
+
export async function initRepo(dir, { force = false, seed, env = process.env, persona = null, memoryBackend = null, researchSource = null } = {}) {
|
|
193
210
|
const root = resolve(dir);
|
|
194
211
|
const created = [];
|
|
195
212
|
const paths = {
|
|
@@ -264,6 +281,7 @@ export async function initRepo(dir, { force = false, seed, env = process.env, pe
|
|
|
264
281
|
if (persona.bias && Object.keys(persona.bias).length) config.bias = persona.bias;
|
|
265
282
|
}
|
|
266
283
|
if (memoryBackend) config.memory = { ...(config.memory || {}), backend: memoryBackend };
|
|
284
|
+
if (researchSource) config.research = { ...(config.research || {}), source: researchSource };
|
|
267
285
|
const tomlPresent = await exists(paths.toml);
|
|
268
286
|
if (!tomlPresent || force) {
|
|
269
287
|
await writeFile(paths.toml, renderTomlConfig(config));
|
|
@@ -317,7 +335,7 @@ export async function initRepo(dir, { force = false, seed, env = process.env, pe
|
|
|
317
335
|
if (allFailed) throw new Error(perBundle[bundleNames[0]].error);
|
|
318
336
|
seedResult = {
|
|
319
337
|
appended, skipped, total, perBundle,
|
|
320
|
-
|
|
338
|
+
code: perBundle.code?.appended || 0,
|
|
321
339
|
conceptnet: perBundle.conceptnet?.appended || 0,
|
|
322
340
|
};
|
|
323
341
|
const markerNew = !(await exists(paths.marker));
|
|
@@ -390,6 +408,9 @@ async function readWrittenConfig(tomlPath, base) {
|
|
|
390
408
|
if (raw.memory && raw.memory.backend !== undefined) {
|
|
391
409
|
cfg.memory = { ...cfg.memory, backend: raw.memory.backend };
|
|
392
410
|
}
|
|
411
|
+
if (raw.research && raw.research.source !== undefined) {
|
|
412
|
+
cfg.research = { ...cfg.research, source: raw.research.source };
|
|
413
|
+
}
|
|
393
414
|
return cfg;
|
|
394
415
|
} catch {
|
|
395
416
|
return base;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// The built-in packs' lane vocabulary, carried as code so it travels inside
|
|
2
|
+
// browser bundles (no filesystem there). Third-party packs still load their
|
|
3
|
+
// vocab_path files through mergedLaneVocab's readFile path, which only runs in
|
|
4
|
+
// Node. Each object must stay deep-equal to its pack's on-disk vocab file —
|
|
5
|
+
// a test pins the sync in both directions.
|
|
6
|
+
|
|
7
|
+
export const CODE_VOCAB_DATA = Object.freeze({
|
|
8
|
+
countNouns: {
|
|
9
|
+
class: "Class", classes: "Class",
|
|
10
|
+
function: "Function", functions: "Function", func: "Function", funcs: "Function",
|
|
11
|
+
module: "Module", modules: "Module", file: "Module", files: "Module",
|
|
12
|
+
package: "Package", packages: "Package",
|
|
13
|
+
method: "Method", methods: "Method",
|
|
14
|
+
attribute: "Attribute", attributes: "Attribute",
|
|
15
|
+
variable: "GlobalVariable", variables: "GlobalVariable", global: "GlobalVariable", globals: "GlobalVariable",
|
|
16
|
+
commit: "Commit", commits: "Commit",
|
|
17
|
+
session: "Session", sessions: "Session",
|
|
18
|
+
},
|
|
19
|
+
classLabels: {
|
|
20
|
+
Class: ["class", "classes"],
|
|
21
|
+
Function: ["function", "functions"],
|
|
22
|
+
Module: ["module", "modules"],
|
|
23
|
+
Package: ["package", "packages"],
|
|
24
|
+
Method: ["method", "methods"],
|
|
25
|
+
Attribute: ["attribute", "attributes"],
|
|
26
|
+
GlobalVariable: ["variable", "variables"],
|
|
27
|
+
Commit: ["commit", "commits"],
|
|
28
|
+
Session: ["session", "sessions"],
|
|
29
|
+
},
|
|
30
|
+
helpRows: [
|
|
31
|
+
["/find <query>", "lexical search across the graph"],
|
|
32
|
+
["/search <query>", "alias of /find"],
|
|
33
|
+
["/context <symbol>", "the sized edit bundle for a symbol (start here to change code)"],
|
|
34
|
+
["/snippet <symbol>", "exact source of one function/class/method"],
|
|
35
|
+
["/describe <symbol>", "a symbol's definition, kind and relations"],
|
|
36
|
+
["/signature <symbol>", "a symbol's signature only"],
|
|
37
|
+
["/members <class>", "the methods/attributes of a class"],
|
|
38
|
+
["/subclasses <class>", "the subclasses of a class"],
|
|
39
|
+
["/impact <module>", "what a change to this module or symbol reaches (impact closure)"],
|
|
40
|
+
["/callers <symbol>", "functions that call this symbol"],
|
|
41
|
+
["/callees <symbol>", "functions this symbol calls"],
|
|
42
|
+
["/tests <symbol>", "the tests covering this symbol"],
|
|
43
|
+
["/untested", "symbols with no covering test"],
|
|
44
|
+
["/history <symbol>", "the commit history of this symbol"],
|
|
45
|
+
["/exports <module>", "a module's public exports"],
|
|
46
|
+
["/arch [package]", "the architecture overview (optional package filter)"],
|
|
47
|
+
],
|
|
48
|
+
missRecoveryPointer: "for code structure, index this repo with `tmct index`, or point me at a .tmct/graph.json with --repo <path> (or try `npm run example:mini`).",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export const EMPTY_VOCAB_DATA = Object.freeze({
|
|
52
|
+
countNouns: {},
|
|
53
|
+
classLabels: {},
|
|
54
|
+
helpRows: [],
|
|
55
|
+
missRecoveryPointer: "",
|
|
56
|
+
});
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
import { normFactTerm } from "../domain/hash.mjs";
|
|
27
27
|
import { loadLexicon, lookupNoun } from "../domain/grammar/lexicon.mjs";
|
|
28
28
|
import { defaultNlp } from "../domain/interpret/nlp-registry.mjs";
|
|
29
|
+
import { normalizeResearchChoice } from "../adapters/corpus/research-source.mjs";
|
|
29
30
|
|
|
30
31
|
/** The search key a topic folds to: normFactTerm, then the lexicon lemma
|
|
31
32
|
* when the noun is known ("owls" → "owl") — the same fold the live
|
|
@@ -63,17 +64,19 @@ export const RESEARCH_DEFAULTS = Object.freeze({
|
|
|
63
64
|
maxDepth: 1,
|
|
64
65
|
maxTopics: 12,
|
|
65
66
|
minIntervalMs: 2000,
|
|
67
|
+
source: "wikipedia",
|
|
66
68
|
});
|
|
67
69
|
|
|
68
70
|
const clampInt = (n, lo, hi) => Math.min(hi, Math.max(lo, Math.floor(n)));
|
|
69
71
|
|
|
70
|
-
/** A partial `{ fanoutLimit?, maxDepth?, maxTopics?, minIntervalMs? }`
|
|
71
|
-
* as the page and CLI supply it) folded onto the shipped defaults
|
|
72
|
-
* to the engineered ranges: fan-out at RESEARCH_FANOUT_MAX, depth
|
|
73
|
-
* RESEARCH_MAX_DEPTH, the node budget at [1, RESEARCH_MAX_TOPICS],
|
|
74
|
-
* polite interval only ever RAISED above its floor, never lowered
|
|
75
|
-
*
|
|
76
|
-
* the shipped
|
|
72
|
+
/** A partial `{ fanoutLimit?, maxDepth?, maxTopics?, minIntervalMs?, source? }`
|
|
73
|
+
* (camelCase, as the page and CLI supply it) folded onto the shipped defaults
|
|
74
|
+
* and clamped to the engineered ranges: fan-out at RESEARCH_FANOUT_MAX, depth
|
|
75
|
+
* at RESEARCH_MAX_DEPTH, the node budget at [1, RESEARCH_MAX_TOPICS], the
|
|
76
|
+
* polite interval only ever RAISED above its floor, never lowered, and
|
|
77
|
+
* `source` folded through normalizeResearchChoice — an unrecognized or
|
|
78
|
+
* corrupt value is the shipped default, never a crash. Every non-finite
|
|
79
|
+
* field falls back to its default too. */
|
|
77
80
|
export function clampResearchConfig(partial = {}) {
|
|
78
81
|
const cfg = { ...RESEARCH_DEFAULTS };
|
|
79
82
|
const fanout = Number(partial.fanoutLimit);
|
|
@@ -84,6 +87,7 @@ export function clampResearchConfig(partial = {}) {
|
|
|
84
87
|
if (Number.isFinite(topics)) cfg.maxTopics = clampInt(topics, 1, RESEARCH_MAX_TOPICS);
|
|
85
88
|
const interval = Number(partial.minIntervalMs);
|
|
86
89
|
if (Number.isFinite(interval)) cfg.minIntervalMs = Math.max(RESEARCH_DEFAULTS.minIntervalMs, interval);
|
|
90
|
+
cfg.source = normalizeResearchChoice(partial.source);
|
|
87
91
|
return cfg;
|
|
88
92
|
}
|
|
89
93
|
|
|
@@ -92,7 +96,10 @@ export function clampResearchConfig(partial = {}) {
|
|
|
92
96
|
* takes with `[games.*]`). `fanout_limit` caps at RESEARCH_FANOUT_MAX;
|
|
93
97
|
* `depth_limit`/`max_depth` set how deep the fan-out follows (0 means no
|
|
94
98
|
* fan-out); `max_topics` sets the total node budget; `min_interval_ms` may
|
|
95
|
-
* only RAISE the polite floor between round trips, never lower it
|
|
99
|
+
* only RAISE the polite floor between round trips, never lower it; `source`
|
|
100
|
+
* picks which research source the lane fetches from ("wikipedia" or
|
|
101
|
+
* "wikidata"), the flag/slash-command tiers above it in
|
|
102
|
+
* chat-session.mjs taking precedence over this one. */
|
|
96
103
|
export function resolveResearchConfig(toml = null) {
|
|
97
104
|
const raw = toml?.research || {};
|
|
98
105
|
return clampResearchConfig({
|
|
@@ -100,6 +107,7 @@ export function resolveResearchConfig(toml = null) {
|
|
|
100
107
|
maxDepth: raw.max_depth ?? raw.depth_limit,
|
|
101
108
|
maxTopics: raw.max_topics,
|
|
102
109
|
minIntervalMs: raw.min_interval_ms,
|
|
110
|
+
source: raw.source,
|
|
103
111
|
});
|
|
104
112
|
}
|
|
105
113
|
|
|
@@ -158,11 +166,25 @@ export function researchProvenanceTag(topicKey, depth) {
|
|
|
158
166
|
return `research:${topicKey}@${depth}`;
|
|
159
167
|
}
|
|
160
168
|
|
|
169
|
+
/** The human-facing name of the active research source, read off the resolved
|
|
170
|
+
* config's `source` choice — what a miss line or the lane's `goal` names. */
|
|
171
|
+
export function researchSourceLabel(source) {
|
|
172
|
+
return source === "wikidata" ? "Wikidata" : "Simple English Wikipedia";
|
|
173
|
+
}
|
|
174
|
+
|
|
161
175
|
/** The cited per-topic report — the same title/licence/revision-pinned-URL
|
|
162
|
-
* discipline renderLiveReferenceAnswer
|
|
176
|
+
* discipline renderLiveReferenceAnswer/renderReferenceAnswer hold, naming
|
|
177
|
+
* this lane's source. Reads the row's own `source`/`licence` when present
|
|
178
|
+
* (a Wikidata row carries "Wikidata"/"CC0 1.0"), falling back to the
|
|
179
|
+
* Wikipedia defaults otherwise — every wikipedia row renders byte-identically
|
|
180
|
+
* to before this existed. The revision-pinned `?oldid=` query is a Wikipedia
|
|
181
|
+
* convention alone, so a non-Wikipedia row's own `url` is shown bare. */
|
|
163
182
|
export function renderResearchAnswer(term, article) {
|
|
183
|
+
const source = article.source ?? "Simple English Wikipedia";
|
|
184
|
+
const licence = article.licence ?? "CC BY-SA 4.0";
|
|
185
|
+
const url = source === "Simple English Wikipedia" ? `${article.url}?oldid=${article.revid}` : article.url;
|
|
164
186
|
return `${term} — ${article.summary} (source: research article "${article.title}", `
|
|
165
|
-
+
|
|
187
|
+
+ `${source}, ${licence} — ${url})`;
|
|
166
188
|
}
|
|
167
189
|
|
|
168
190
|
/** The queue as plain data for a UI: pending titles, per-topic fact counts,
|
|
@@ -348,7 +370,7 @@ async function startRun({ topic, limit, depth }, { holder, provider, ingest, con
|
|
|
348
370
|
if (!article) {
|
|
349
371
|
holder.state = null;
|
|
350
372
|
return {
|
|
351
|
-
text: `I couldn't ground "${topic}" from
|
|
373
|
+
text: `I couldn't ground "${topic}" from ${researchSourceLabel(config.source)} just now — no matching article, or the network didn't answer. Nothing was stored.`,
|
|
352
374
|
miss: true,
|
|
353
375
|
};
|
|
354
376
|
}
|
|
@@ -377,7 +399,7 @@ async function startRun({ topic, limit, depth }, { holder, provider, ingest, con
|
|
|
377
399
|
};
|
|
378
400
|
}
|
|
379
401
|
|
|
380
|
-
async function stepRun({ holder, provider, ingest, notify }) {
|
|
402
|
+
async function stepRun({ holder, provider, ingest, notify, config }) {
|
|
381
403
|
const state = holder.state;
|
|
382
404
|
const title = state.pending[0];
|
|
383
405
|
const depth = pendingDepth(state, title);
|
|
@@ -389,7 +411,7 @@ async function stepRun({ holder, provider, ingest, notify }) {
|
|
|
389
411
|
if (!article) {
|
|
390
412
|
state.skipped = [...state.skipped, title];
|
|
391
413
|
return {
|
|
392
|
-
text: `I couldn't fetch "${title}" from
|
|
414
|
+
text: `I couldn't fetch "${title}" from ${researchSourceLabel(config.source)} — skipped, nothing stored. ${progressLine(state)}`,
|
|
393
415
|
miss: true,
|
|
394
416
|
};
|
|
395
417
|
}
|
|
@@ -423,7 +445,7 @@ export async function researchTurn(line, ctx) {
|
|
|
423
445
|
// A bare "next" belongs to an active plan first, then to paging — this
|
|
424
446
|
// lane only claims it when a research queue is the one thing running.
|
|
425
447
|
if (req.kind === "bareNext" && (!pendingRun || planActive || pagerActive)) return null;
|
|
426
|
-
const goal =
|
|
448
|
+
const goal = `research a topic on ${researchSourceLabel(ctx.config?.source)} and remember what it grounds`;
|
|
427
449
|
const wrap = (r, note) => ({ ...r, goal, note });
|
|
428
450
|
if (req.kind === "status") {
|
|
429
451
|
if (!holder.state) return wrap({ text: 'no research is running — "research <topic>" starts one.', miss: true }, "RESEARCH — status with no run standing");
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// claims-browser-entry.mjs — the esbuild entry for the claims page's
|
|
2
|
+
// "run it on this device" button (public/claims-browser.bundle.js, built by
|
|
3
|
+
// scripts/build-claims-bundle.mjs).
|
|
4
|
+
//
|
|
5
|
+
// solvePlannerInstance is planner-instances.mjs's own function (this same
|
|
6
|
+
// directory), the same per-instance solve entry point
|
|
7
|
+
// scripts/claims/claim-planner.mjs drives (via scripts/claims/planner-
|
|
8
|
+
// domains.mjs's re-export) to produce results/claims/planner.json. A
|
|
9
|
+
// visitor's click and the committed number come from the identical code
|
|
10
|
+
// path — teach one domain's rule sentences plus one instance's starting
|
|
11
|
+
// state through the real chat turn engine, then time the solve — so the
|
|
12
|
+
// page never carries a second, lighter "browser demo" implementation that
|
|
13
|
+
// could quietly diverge from what was actually measured.
|
|
14
|
+
//
|
|
15
|
+
// registerWinkModel is re-exported for the same reason plan-browser-entry.mjs
|
|
16
|
+
// re-exports it as tmct.page.registerWinkModel: the hanoi lesson's "moving a
|
|
17
|
+
// disk onto a target makes the disk rest on the target" sentence needs a
|
|
18
|
+
// real lemmatiser to reduce "moving" to "move", and the browser bundle keeps
|
|
19
|
+
// wink-nlp's ~1 MB model out of THIS bundle rather than duplicating it — the
|
|
20
|
+
// page's own script loads the site's one shared ./vendor/wink.js and
|
|
21
|
+
// registers it before the first solve, the identical bounded-race pattern
|
|
22
|
+
// plan-viz.mjs's tryLoadWink already uses.
|
|
23
|
+
import { solvePlannerInstance } from "./planner-instances.mjs";
|
|
24
|
+
import { registerWinkModel } from "../../adapters/wink-model.mjs";
|
|
25
|
+
|
|
26
|
+
globalThis.tmctClaims = { solvePlannerInstance, registerWinkModel };
|