@polycode-projects/the-mechanical-code-talker 5.0.45 → 5.0.46

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.
@@ -22,13 +22,16 @@ import { dispatchTool, dispatchToolStructured, loadGraph, TOOLS } from "../tools
22
22
  import { ToolError } from "../adapters/config.mjs";
23
23
  import { parseEntities, edgesOfKind, moduleCountOf, packageCounts, modulesOf, renderAuthorCard, renderAuthorTouches, renderCommitAuthor, resolveSymbol, renderCompare } from "../domain/codegraph.mjs";
24
24
  import { classDisplayName, DYNAMIC_TAIL_OK_RE } from "../domain/ask.mjs";
25
- // How a stored fact predicate reads in English — one phrase per predicate the
26
- // two writers (the ACE grammar, the ConceptNet map) actually emit, shared
27
- // with the news feed's own paraphrase renderer (src/domain/news-feed.mjs)
28
- // instead of growing a twin. An unknown predicate renders verbatim rather
29
- // than being guessed around (see this file's own predicatePhrase, below,
30
- // which layers polarity/comparative/mechanical-fallback handling on top).
31
- import { FACT_PREDICATE_PHRASES } from "../domain/fact-phrase.mjs";
25
+ // How a stored fact predicate reads in English — the curated table, the
26
+ // reader over it, and the verb-surface folds the teach lane and the read-back
27
+ // share. One implementation, in one place: the news feed's paraphrase
28
+ // renderer, the news page's inline script and this file's answer path all
29
+ // render a fact through the same function, so no two surfaces can disagree
30
+ // about what a predicate says.
31
+ import {
32
+ FACT_PREDICATE_PHRASES, TEACH_PARTICIPLE_SRC, predicatePhrase,
33
+ thirdPersonSingularSurface, baseVerbSurface, gerundVerbSurface,
34
+ } from "../domain/fact-phrase.mjs";
32
35
  import { emptyRecord as emptyDiscourseRecord, advanceTurn as advanceDiscourseTurn, register as registerReferent, bind as bindDiscourseForm } from "../domain/discourse.mjs";
33
36
  import { uuidv7 } from "../adapters/uuid.mjs";
34
37
  import * as defaultSource from "../adapters/source.mjs";
@@ -37,7 +40,7 @@ import { rankByBiasThenTrust } from "../domain/memory/bias.mjs";
37
40
  import { HAS_A_PREDICATE, loadMemory as loadMemoryStore, normFactPredicate, normFactTerm as normFactTermStatic, readFactRows as readStoredFactRows, readRuleRows as readStoredRuleRows } from "../adapters/memory/core.mjs";
38
41
  import {
39
42
  CAPABILITY_REPORT_CAP, NEG_CAPABLE_OF_PREDICATE, NEG_SUBCLASS_PREDICATE, capabilityBaseRate,
40
- capabilityExtension, isNegatedPredicate, negatedPredicate, positivePredicate,
43
+ capabilityExtension, isNegatedPredicate, negatedPredicate,
41
44
  resolveCapabilityPolarity,
42
45
  } from "../domain/memory/capability.mjs";
43
46
  import { finish, beginsWithVowelSound, grammarRules } from "./finish.mjs";
@@ -64,6 +67,9 @@ import { getLiveReferenceProvider, getResearchProvider } from "../adapters/corpu
64
67
  // Imported for its research-source registration side effect only, so
65
68
  // getResearchProvider({ source: "wikidata" }) can find an entry to build.
66
69
  import "../adapters/corpus/wikidata-live.mjs";
70
+ // Same side-effect-only import, for getResearchProvider({ source:
71
+ // "simple-wikipedia-pack" }) — the offline pack-backed research source.
72
+ import "../adapters/corpus/simple-wikipedia-pack.mjs";
67
73
  import { researchTurn, researchSnapshot, resolveResearchConfig, RESEARCH_DEFAULTS, parseResearchRequest, researchSourceLabel } from "./research.mjs";
68
74
  import { loadResearchQueue, saveResearchQueue } from "../adapters/research-queue-store.mjs";
69
75
  import { newsTurn, resolveNewsConfig, NEWS_DEFAULTS, createNewsState } from "./news.mjs";
@@ -147,6 +153,33 @@ const goalNoun = (entityType) => (entityType ? `${String(entityType).toLowerCase
147
153
  * runAsk's fact-lane goal revision and withDeducedGoal's fact-reader field. */
148
154
  const TAUGHT_FACT_LOOKUP_GOAL = "look up a taught fact about a subject/verb/object";
149
155
 
156
+ /** The narration's name for the store a turn read from. The memory token is a
157
+ * backend HANDLE, not a path, so interpolating it renders "[object Object]"
158
+ * in a trace a host may show its own users. The backend kind is the part
159
+ * that stays true across machines and runs. */
160
+ function memoryBackendLabel(memoryDir) {
161
+ if (!memoryDir) return "none";
162
+ if (typeof memoryDir === "string") return "files";
163
+ return typeof memoryDir.backend === "string" ? memoryDir.backend : "unknown";
164
+ }
165
+
166
+ /**
167
+ * A fact lane answered a turn the grammar declined. Two lines written before
168
+ * any lane ran describe the PARSE attempt — "no parse stood", and a goal
169
+ * deduced from a parse that is null — so a trace that leaves them alone reads
170
+ * as though nothing resolved the turn, while its own decision and lane lines
171
+ * say a remembered fact did. Restate both.
172
+ *
173
+ * Trace only: `deduced` itself is left alone, because it also drives the
174
+ * answer's own "Goal (inferred)" line, and which turns carry that line is a
175
+ * product decision each lane makes for itself.
176
+ */
177
+ function noteFactLaneTookTheTurn(trace, { parsed, deduced, goal = TAUGHT_FACT_LOOKUP_GOAL }) {
178
+ if (parsed) return;
179
+ note(trace, "pattern: the grammar declined, and the fact layer claimed the turn from the remembered store (revised — the earlier line reports the parse attempt, not what answered)");
180
+ if (!deduced) note(trace, `goal: ${goal} (revised — no parse stood, so the goal the turn served is the fact lookup that answered)`);
181
+ }
182
+
150
183
  /** Deduce a one-line goal statement from the ask engine's parsed AST — either
151
184
  * the plain-clause form ({shape,kind,entityType,object[,subject]}) or the
152
185
  * compositional form ({node:...}, ask.mjs's §compositional grammar). Returns
@@ -4477,12 +4510,7 @@ function splitTeachNegation(payload) {
4477
4510
  return { payload: `${m[1]} ${canFamily ? "can " : ""}${m[3]}`.trim(), negated: true };
4478
4511
  }
4479
4512
  const GENERAL_VERB_TEACH_RE = new RegExp(`^([\\w'-]+)\\s+${TEACH_ADVERB_SKIP_SRC}([a-z]+)\\s+(.+?)[.!?]*$`, "i");
4480
- /** The closed participle set the relational teach frames read as "X is
4481
- * <participle> <prep> Y" — a past participle whose own form is the word, so it
4482
- * reads back with no morphology. Closed by list (templates over general
4483
- * grammar), so the frame can never widen onto an arbitrary "-ed" adjective. */
4484
- const TEACH_PARTICIPLE_SRC = "connected|related|associated|linked|based|derived|composed|made|used|known|located|found|involved|concerned";
4485
- /** The prepositions those participles take. A closed set, folded into the
4513
+ /** The prepositions TEACH_PARTICIPLE_SRC's participles take. A closed set, folded into the
4486
4514
  * minted predicate (mgx:<participle>-<prep>) the same way PREP_SRC folds into
4487
4515
  * the general-verb frame's. */
4488
4516
  const TEACH_PARTICIPLE_PREP_SRC = "with|to|from|by|of|in|on|for|as|about|into";
@@ -8000,89 +8028,6 @@ const WORLD_PLACEMENT_PREDICATES = new Set([
8000
8028
  "mgx:currently-in", "mgx:located-in", "mgx:fixed-in", "mgx:stands-locked-in", "mgx:works-in",
8001
8029
  ]);
8002
8030
 
8003
- /** The MECHANICAL fallback for a predicate this table has no curated entry
8004
- * for — specifically generalVerbTeach's minted "mgx:<lemma>" predicates
8005
- * ("mgx:eat", "mgx:drive", …) — the mechanical INVERSE of singularizeSurface's
8006
- * own naive -s/-es/-ies fold used elsewhere in this file, same accepted-
8007
- * limitation trade (no real morphology; a handful of doubly-irregular verbs
8008
- * render slightly off but never wrong-MEANING). "has"/"have" never reach
8009
- * this fallback — generalVerbPredicate special-cases them onto the CURATED
8010
- * mgx:hasA entry above before a predicate is ever minted. Any OTHER unknown
8011
- * predicate (not the "mgx:<lemma>" shape — e.g. a stray/foreign CURIE) still
8012
- * renders verbatim. */
8013
- function thirdPersonSingularSurface(lemma) {
8014
- const w = String(lemma || "");
8015
- // "have" should never reach this naive fallback at all
8016
- // (generalVerbPredicate special-cases it onto mgx:hasA before a predicate is
8017
- // ever minted), but if some OTHER path ever reaches here with it as typed —
8018
- // e.g. wink-nlp unavailable so lemma degrades to the raw verb — the naive
8019
- // "+s" rule would produce the wrong-MEANING "haves" instead of the correct
8020
- // irregular "has".
8021
- if (/^have$/i.test(w)) return "has";
8022
- if (/[a-z]y$/i.test(w) && !/[aeiou]y$/i.test(w)) return `${w.slice(0, -1)}ies`;
8023
- if (/(?:s|x|z|ch|sh|o)$/i.test(w)) return `${w}es`;
8024
- return `${w}s`;
8025
- }
8026
- /** The INVERSE of thirdPersonSingularSurface — "eats" -> "eat", "flies" ->
8027
- * "fly", "has" -> "have". Do-support wants the bare infinitive after it
8028
- * ("does not EAT", never "does not eats"), and so does every derived
8029
- * forward yes/no reader ("does X cause Y"), so both fold through this one
8030
- * function and can never drift apart on a verb. */
8031
- function baseVerbSurface(verb) {
8032
- const w = String(verb || "");
8033
- if (/^has$/i.test(w)) return "have";
8034
- if (/[a-z]ies$/i.test(w) && !/[aeiou]ies$/i.test(w)) return `${w.slice(0, -3)}y`;
8035
- if (/(?:s|x|z|ch|sh|o)es$/i.test(w)) return w.slice(0, -2);
8036
- return w.replace(/s$/i, "");
8037
- }
8038
- /** The gerund surface of a 3sg-minted role predicate — "contains" -> "containing",
8039
- * "touches" -> "touching" — the naive INVERSE of the "-ing"-stripping fold
8040
- * verbPredicateFromSurface (ace.mjs) already accepts alongside a 3sg surface
8041
- * when parsing patterns 16, 17 and 19. Same accepted naive-morphology trade
8042
- * thirdPersonSingularSurface/baseVerbSurface already make. */
8043
- function gerundVerbSurface(verb) {
8044
- const base = baseVerbSurface(verb);
8045
- return /[^aeiou]e$/i.test(base) && base.length > 2 ? `${base.slice(0, -1)}ing` : `${base}ing`;
8046
- }
8047
- function predicatePhrase(predicate) {
8048
- if (FACT_PREDICATE_PHRASES[predicate]) return FACT_PREDICATE_PHRASES[predicate];
8049
- const p = String(predicate || "");
8050
- // NEGATIVE polarity renders as its own positive phrase, negated — ONE branch
8051
- // for every predicate that can carry a polarity, curated or minted. The
8052
- // negative twins are deliberately absent from FACT_PREDICATE_PHRASES: the
8053
- // TRAILING_PREDICATE_MARKERS / REVERSE_PREDICATE_MARKERS /
8054
- // FORWARD_YESNO_MARKERS families all derive their vocabulary from that table,
8055
- // so an entry there would auto-mint readers for "what cannot X" and
8056
- // "does X cannot Y" that nobody wrote and nothing pins.
8057
- // The three surface shapes split exactly as FORWARD_YESNO_MARKERS splits
8058
- // them, for the same reason: a modal, a copula and a plain verb take
8059
- // different negations, and nothing else does.
8060
- const positive = positivePredicate(p);
8061
- if (positive) {
8062
- const phrase = predicatePhrase(positive);
8063
- if (phrase === "can") return "cannot";
8064
- if (phrase === "can be") return "cannot be";
8065
- if (phrase === "is" || phrase.startsWith("is ")) return `is not${phrase.slice(2)}`;
8066
- const [head, ...tail] = phrase.split(" ");
8067
- return ["does not", baseVerbSurface(head), ...tail].join(" ");
8068
- }
8069
- // a comparative renders as its copula surface: mgx:smaller-than ->
8070
- // "is smaller than" (never a 3sg fold — "smallers" isn't a word)
8071
- const comp = /^mgx:([a-z]+(?:-[a-z]+)*)-than$/i.exec(p);
8072
- if (comp) return `is ${comp[1].replace(/-/g, " ")} than`;
8073
- // a participle + preposition renders as its copula surface: mgx:connected-with
8074
- // -> "is connected with" (the participle is already a participle, so no 3sg
8075
- // fold — "connecteds" isn't a word)
8076
- const part = new RegExp(`^mgx:(${TEACH_PARTICIPLE_SRC})-([a-z]+)$`, "i").exec(p);
8077
- if (part) return `is ${part[1].toLowerCase()} ${part[2].toLowerCase()}`;
8078
- // a shared-attribute predicate: mgx:same-goal-as -> "has the same goal as"
8079
- const same = /^mgx:same-([a-z]+)-as$/i.exec(p);
8080
- if (same) return `has the same ${same[1].toLowerCase()} as`;
8081
- const m = /^mgx:([a-z]+)(?:-([a-z]+))?$/i.exec(p);
8082
- if (!m) return predicate;
8083
- // a folded preposition renders back naturally: mgx:rest-on -> "rests on"
8084
- return `${thirdPersonSingularSurface(m[1])}${m[2] ? ` ${m[2]}` : ""}`;
8085
- }
8086
8031
  const factPhrase = (f) => `${f.subject} ${predicatePhrase(f.predicate)} ${f.object}`;
8087
8032
 
8088
8033
  /** The mechanical INVERSE of generalVerbPredicate: recovers the bare role/verb
@@ -15584,6 +15529,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
15584
15529
  note(trace, "lane: (0) WHAT ELSE — \"what else is/about X\" recognized off the raw query, before the relaxation cascade could quietly drop \"else\" and reduce it to a plain \"what is X\"");
15585
15530
  note(trace, "source: .tmct/memory Facts (see /memory for provenance per line)");
15586
15531
  note(trace, `goal: ${deduced} (revised — the raw \"what else\" phrasing was recognized directly, not the relaxed/reparsed envelope)`);
15532
+ if (!recordMiss) noteFactLaneTookTheTurn(trace, { parsed: envelope?.parsed, deduced });
15587
15533
  }
15588
15534
  }
15589
15535
  // (0a) ARCHITECTURE OVERVIEW — see ARCH_OVERVIEW_PHRASES. Answered here,
@@ -15980,6 +15926,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
15980
15926
  note(trace, "lane: (2b) BARE META FACT — \"what is X\" (no article) / \"is X <adjective>\" resolved to a remembered fact before the conversational catch-all could claim it");
15981
15927
  note(trace, "source: .tmct/memory Facts (see /memory for provenance per line)");
15982
15928
  }
15929
+ if (via === "fact") noteFactLaneTookTheTurn(trace, { parsed: envelope?.parsed, deduced });
15983
15930
  } else if (isConversationalCandidate && habitualGroundingHint) {
15984
15931
  // A bare habitual teach ("penguins swim") naming a subject grounded
15985
15932
  // nowhere: an honest, actionable grounding hint beats the orientation
@@ -16116,7 +16063,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
16116
16063
  }
16117
16064
  if (fact.pending) factPending = fact.pending; // a truncated fact list → paginable remainder
16118
16065
  if (typeof fact.trust === "number") entailedTrust = fact.trust; // live-chase trust (see the `entailedTrust` declaration above)
16119
- note(trace, `lane: (3) memory facts — factAnswer/factReadBack matched (memoryDir=${memoryDir})`);
16066
+ note(trace, `lane: (3) memory facts — factAnswer/factReadBack matched (memory backend=${memoryBackendLabel(memoryDir)})`);
16120
16067
  note(trace, "source: .tmct/memory Facts (see /memory for provenance per line)");
16121
16068
  // Mirrors the TEACH lane's own goal revision below: `deduced` was
16122
16069
  // computed off envelope.parsed alone, but a general-verb direct
@@ -16136,6 +16083,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
16136
16083
  deduced = deduceGoalFromParsed({ shape: "meta", object: definedTerm });
16137
16084
  note(trace, `goal: ${deduced} (revised — "define X" answered from the vocabulary store, not the code index)`);
16138
16085
  }
16086
+ if (via === "fact") noteFactLaneTookTheTurn(trace, { parsed: envelope?.parsed, deduced });
16139
16087
  } else if (miss) {
16140
16088
  // W2: after the honest miss is composed, consult the folded-session memory. A
16141
16089
  // relevant enough block ANSWERS — recalled Q/A framed + cited first, with the
@@ -16238,6 +16186,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
16238
16186
  if (syn.pending) factPending = syn.pending;
16239
16187
  note(trace, "lane: (3b) ONTOLOGY SYNONYM EXPANSION — a last-resort synonym of the term had direct facts");
16240
16188
  note(trace, "source: .tmct/memory Facts, reached via a known synonym (cited in the answer itself)");
16189
+ noteFactLaneTookTheTurn(trace, { parsed: envelope?.parsed, deduced });
16241
16190
  }
16242
16191
  }
16243
16192
  // (4) #2 TEACH lane — a teach-shaped would-miss nothing above answered: route to
@@ -16451,6 +16400,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
16451
16400
  if (fact.pending) factPending = fact.pending;
16452
16401
  note(trace, "lane: (4h) CHILD PACK — a clean miss on a lexicon term pulled the term's triples from the shipped child pack into memory, and the question was re-answered from the store");
16453
16402
  note(trace, `source: child pack ${CHILD_PACK_NAME} — ${learned.count} fact(s) appended as ${childProvenanceTag(key)}, answer served from .tmct/memory Facts`);
16403
+ noteFactLaneTookTheTurn(trace, { parsed: envelope?.parsed, deduced });
16454
16404
  }
16455
16405
  }
16456
16406
  if (miss && recordMiss && via === "composed" && key) {
@@ -16569,6 +16519,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
16569
16519
  via = "fact";
16570
16520
  recordMiss = false;
16571
16521
  note(trace, "lane: (4x) ADJECTIVE-QUALIFIED HEAD NOUN — the full phrase grounded nothing, so the answer is the head noun's, with the phrase named as unheld");
16522
+ noteFactLaneTookTheTurn(trace, { parsed: envelope?.parsed, deduced });
16572
16523
  } else {
16573
16524
  teachOffer = unknownVocabTermOffer(cleanTerm);
16574
16525
  }
@@ -51,6 +51,8 @@ export { foldSessionLogs } from "./fold.mjs";
51
51
  // (docs/adapter-contract.md): registerProvider() plugs a producer in;
52
52
  // fetchEntities() is the one read path.
53
53
  export { fetchEntities, registerProvider } from "../adapters/source.mjs";
54
+ export { registerResearchProvider } from "../adapters/corpus/wikipedia-live.mjs";
55
+ export { registerResearchSource } from "../adapters/corpus/research-source.mjs";
54
56
 
55
57
  // `tmct init` onboarding.
56
58
  // init.mjs and toml-config.mjs each export a same-named `CONFIG_FILE`
@@ -154,6 +154,7 @@ backend = ${JSON.stringify(config.memory.backend)}
154
154
  # this file > "wikipedia" (the built-in default).
155
155
  # "wikipedia" — Simple English Wikipedia prose articles, CC BY-SA 4.0.
156
156
  # "wikidata" — Wikidata's structured claims, CC0 1.0.
157
+ # "simple-wikipedia-pack" — the shipped reference pack, offline, no network.
157
158
  source = ${JSON.stringify(config.research.source)}
158
159
  `;
159
160
  }
@@ -230,7 +231,7 @@ function seedRequested({ optSeed, configEnabled, env }) {
230
231
  * @param {string} [opts.memoryBackend] "default" | "memory" | "sqlite" — merged into a
231
232
  * FRESH config's `[memory] backend`, and selects which backend the corpus seed writes
232
233
  * into (via src/adapters/memory/core.mjs's openMemoryBackend).
233
- * @param {string} [opts.researchSource] "wikipedia" | "wikidata" — merged into a
234
+ * @param {string} [opts.researchSource] "wikipedia" | "wikidata" | "simple-wikipedia-pack" — merged into a
234
235
  * FRESH config's `[research] source`, the tmct.toml tier of the research lane's
235
236
  * source precedence (src/services/chat-session.mjs createSession).
236
237
  * @returns {Promise<{
@@ -24,7 +24,7 @@ import {
24
24
  THEME_TOKENS_CSS, MONO_STACK, escapeHtml, embedJson, demoEyebrowHtml, EYEBROW_LINKS_CSS,
25
25
  } from "./viz-theme.mjs";
26
26
  import { loadSeedPayload, fetchWithProgress, factTripleParts } from "./memory-panel-viz.mjs";
27
- import { predicatePhrase, factSentence, FACT_PREDICATE_PHRASES } from "../domain/fact-phrase.mjs";
27
+ import { phraseRendererSource, FACT_PREDICATE_PHRASES } from "../domain/fact-phrase.mjs";
28
28
  import { NEWS_SOURCE_RECORDS } from "../adapters/corpus/news-sources.mjs";
29
29
 
30
30
  const DEFAULT_TITLE = "tmct news — a dashboard over the graph, fed on your say-so";
@@ -287,8 +287,7 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
287
287
  const el = (id) => document.getElementById(id);
288
288
  const esc = ${escapeHtml.toString()};
289
289
  const FACT_PREDICATE_PHRASES = ${factPhrasesJson};
290
- const predicatePhrase = ${predicatePhrase.toString()};
291
- const factSentence = ${factSentence.toString()};
290
+ ${phraseRendererSource()}
292
291
  const factTripleParts = ${factTripleParts.toString()};
293
292
  const fetchWithProgress = ${fetchWithProgress.toString()};
294
293
  const loadSeedPayload = ${loadSeedPayload.toString()};