@polycode-projects/the-mechanical-code-talker 5.0.16 → 5.0.18
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 +1 -0
- package/bin/tmct.mjs +36 -3
- package/package.json +3 -2
- package/src/adapters/corpus/research-source.mjs +17 -0
- package/src/adapters/corpus/wikipedia-live.mjs +32 -9
- package/src/domain/cli-verbs.mjs +2 -0
- package/src/services/chat-page-viz.mjs +12 -6
- package/src/services/chat-session.mjs +18 -3
- package/src/services/chat.mjs +39 -9
- package/src/services/init.mjs +21 -1
- package/src/services/research.mjs +36 -14
- package/src/surfaces/web/memory-ask-browser.bundle.js +98 -98
|
@@ -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");
|