@polycode-projects/the-mechanical-code-talker 5.0.45 → 6.0.0
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/bin/tmct.mjs +11 -10
- package/package.json +15 -2
- package/src/adapters/corpus/research-source.mjs +4 -2
- package/src/adapters/corpus/simple-wikipedia-pack.mjs +138 -0
- package/src/adapters/memory/backends-exports.mjs +8 -0
- package/src/adapters/memory/core.mjs +291 -30
- package/src/adapters/memory/row-backend-dynamo.mjs +315 -0
- package/src/adapters/memory/row-backend-memory.mjs +85 -0
- package/src/adapters/memory/row-backend.mjs +162 -0
- package/src/adapters/memory/rows.mjs +328 -0
- package/src/adapters/memory/shacl.mjs +24 -0
- package/src/adapters/research-queue-store.mjs +215 -32
- package/src/domain/cli-verbs.mjs +2 -2
- package/src/domain/fact-phrase.mjs +170 -13
- package/src/domain/memory/capability.mjs +1 -1
- package/src/domain/phrase-exports.mjs +33 -0
- package/src/domain/reference-pack.mjs +46 -0
- package/src/domain/retrieval-plan.mjs +224 -0
- package/src/services/chat-session.mjs +23 -7
- package/src/services/chat.mjs +49 -98
- package/src/services/extract-facts.mjs +244 -33
- package/src/services/index.mjs +2 -0
- package/src/services/init.mjs +17 -6
- package/src/services/news-viz.mjs +2 -3
- package/src/services/news.mjs +4 -2
- package/src/services/subgraph-retrieval.mjs +361 -0
- package/src/surfaces/web/memory-ask-browser.bundle.js +127 -126
- package/src/surfaces/web/news-browser-entry.mjs +6 -2
- package/src/tools/handlers/tmct-ingest.mjs +3 -1
- package/src/tools/memory-backend-conformance.mjs +238 -0
package/src/services/chat.mjs
CHANGED
|
@@ -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 —
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
import {
|
|
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,
|
|
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
|
|
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 (
|
|
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
|
}
|