@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/bin/tmct.mjs
CHANGED
|
@@ -709,11 +709,11 @@ async function main() {
|
|
|
709
709
|
let researchSource;
|
|
710
710
|
try {
|
|
711
711
|
memoryBackend = enumFlag(rest, ["--memory-backend"], ["default", "memory", "sqlite"]);
|
|
712
|
-
// `--research-source <wikipedia|wikidata>`: the
|
|
713
|
-
// research lane's source precedence (below
|
|
714
|
-
// above tmct.toml's [research] source).
|
|
715
|
-
// lower tiers still apply unchanged.
|
|
716
|
-
researchSource = enumFlag(rest, ["--research-source"], ["wikipedia", "wikidata"]);
|
|
712
|
+
// `--research-source <wikipedia|wikidata|simple-wikipedia-pack>`: the
|
|
713
|
+
// CLI's flag tier of the research lane's source precedence (below
|
|
714
|
+
// /wikipedia|/wikidata in chat, above tmct.toml's [research] source).
|
|
715
|
+
// Omitted when absent so the lower tiers still apply unchanged.
|
|
716
|
+
researchSource = enumFlag(rest, ["--research-source"], ["wikipedia", "wikidata", "simple-wikipedia-pack"]);
|
|
717
717
|
} catch (e) {
|
|
718
718
|
process.stderr.write(`tmct: ${e?.message || e}\n`);
|
|
719
719
|
process.exit(2);
|
|
@@ -888,13 +888,14 @@ async function main() {
|
|
|
888
888
|
process.exit(2);
|
|
889
889
|
}
|
|
890
890
|
|
|
891
|
-
// `--research-source <wikipedia|wikidata>`: written
|
|
892
|
-
// `[research] source` (src/services/init.mjs's
|
|
893
|
-
// flag name `tmct chat` reads at its own
|
|
894
|
-
// once here needs no flag on a later
|
|
891
|
+
// `--research-source <wikipedia|wikidata|simple-wikipedia-pack>`: written
|
|
892
|
+
// into tmct.toml's `[research] source` (src/services/init.mjs's
|
|
893
|
+
// renderTomlConfig), the same flag name `tmct chat` reads at its own
|
|
894
|
+
// precedence tier — a repo set up once here needs no flag on a later
|
|
895
|
+
// `tmct chat` in it.
|
|
895
896
|
let researchSourceVal;
|
|
896
897
|
try {
|
|
897
|
-
researchSourceVal = enumFlag(rest, ["--research-source"], ["wikipedia", "wikidata"]);
|
|
898
|
+
researchSourceVal = enumFlag(rest, ["--research-source"], ["wikipedia", "wikidata", "simple-wikipedia-pack"]);
|
|
898
899
|
} catch (e) {
|
|
899
900
|
process.stderr.write(`tmct init: ${e?.message || e}\n`);
|
|
900
901
|
process.exit(2);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polycode-projects/the-mechanical-code-talker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "The Mechanical Code Talker (tmct) — a tolerant, offline, $0 chat surface that guides you toward precision queries about a software repository. ELIZA/PARRY-style but domain-obsessed with code. No model calls; indexes a repo on request (tmct index) or reads any producer's graph.",
|
|
@@ -52,7 +52,10 @@
|
|
|
52
52
|
"./conformance": "./src/tools/conformance.mjs",
|
|
53
53
|
"./ask-browser": "./src/surfaces/web/graph-ask-browser-entry.mjs",
|
|
54
54
|
"./news": "./src/services/news-exports.mjs",
|
|
55
|
-
"./
|
|
55
|
+
"./phrase": "./src/domain/phrase-exports.mjs",
|
|
56
|
+
"./envelope": "./test-benchmarks/agentbench/envelope-reader.mjs",
|
|
57
|
+
"./memory-backend-conformance": "./src/tools/memory-backend-conformance.mjs",
|
|
58
|
+
"./memory-backends": "./src/adapters/memory/backends-exports.mjs"
|
|
56
59
|
},
|
|
57
60
|
"files": [
|
|
58
61
|
"bin/",
|
|
@@ -88,6 +91,14 @@
|
|
|
88
91
|
"wink-eng-lite-web-model": "^1.8.1",
|
|
89
92
|
"wink-nlp": "^2.4.0"
|
|
90
93
|
},
|
|
94
|
+
"peerDependencies": {
|
|
95
|
+
"@aws-sdk/lib-dynamodb": ">=3"
|
|
96
|
+
},
|
|
97
|
+
"peerDependenciesMeta": {
|
|
98
|
+
"@aws-sdk/lib-dynamodb": {
|
|
99
|
+
"optional": true
|
|
100
|
+
}
|
|
101
|
+
},
|
|
91
102
|
"scripts": {
|
|
92
103
|
"help": "node --disable-warning=ExperimentalWarning bin/tmct.mjs --help",
|
|
93
104
|
"test": "node scripts/ensure-worlds-pack.mjs && node scripts/ensure-sprite-facts.mjs && node --disable-warning=ExperimentalWarning --test --test-concurrency=8 \"test/**/*.test.mjs\"",
|
|
@@ -172,6 +183,7 @@
|
|
|
172
183
|
"claim:news": "node scripts/news-rig.mjs",
|
|
173
184
|
"roll": "node scripts/roll.mjs",
|
|
174
185
|
"build:ask-bundle": "node scripts/build-ask-bundle.mjs",
|
|
186
|
+
"build:row-service": "esbuild server/row-service/handler.mjs --bundle --platform=node --target=node20 --external:@aws-sdk/lib-dynamodb --external:@aws-sdk/client-dynamodb --outfile=server/row-service/dist/handler.js",
|
|
175
187
|
"build:chat-bundle": "node scripts/build-chat-bundle.mjs",
|
|
176
188
|
"build:spider-fly-bundle": "node scripts/build-spider-fly-bundle.mjs",
|
|
177
189
|
"build:plan-bundle": "node scripts/build-plan-bundle.mjs",
|
|
@@ -205,6 +217,7 @@
|
|
|
205
217
|
"extract:facts": "node --disable-warning=ExperimentalWarning bin/tmct.mjs extract"
|
|
206
218
|
},
|
|
207
219
|
"devDependencies": {
|
|
220
|
+
"@aws-sdk/lib-dynamodb": "3.1106.0",
|
|
208
221
|
"esbuild": "0.28.1",
|
|
209
222
|
"ink-testing-library": "4.0.0",
|
|
210
223
|
"playwright": "1.61.1",
|
|
@@ -124,9 +124,10 @@ export function researchSources() {
|
|
|
124
124
|
* same registered source, "wikipedia" for backward compatibility with the
|
|
125
125
|
* original single-source config, "simple-wikipedia" so the news `kb_sources`
|
|
126
126
|
* list (news-sources.mjs) can name every source by the same id its own
|
|
127
|
-
* registry uses.
|
|
127
|
+
* registry uses. "simple-wikipedia-pack" names its offline sibling — the
|
|
128
|
+
* shipped reference pack read as a research source, no network at all. */
|
|
128
129
|
export const RESEARCH_SOURCE_CHOICES = Object.freeze([
|
|
129
|
-
"wikipedia", "wikidata", "simple-wikipedia", "wiktionary", "dbpedia",
|
|
130
|
+
"wikipedia", "wikidata", "simple-wikipedia", "simple-wikipedia-pack", "wiktionary", "dbpedia",
|
|
130
131
|
]);
|
|
131
132
|
export const DEFAULT_RESEARCH_SOURCE_CHOICE = "wikipedia";
|
|
132
133
|
|
|
@@ -134,6 +135,7 @@ const CHOICE_TO_SOURCE_NAME = Object.freeze({
|
|
|
134
135
|
wikipedia: "simple-wikipedia",
|
|
135
136
|
wikidata: "wikidata",
|
|
136
137
|
"simple-wikipedia": "simple-wikipedia",
|
|
138
|
+
"simple-wikipedia-pack": "simple-wikipedia-pack",
|
|
137
139
|
wiktionary: "wiktionary",
|
|
138
140
|
dbpedia: "dbpedia-lookup",
|
|
139
141
|
});
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// corpus/simple-wikipedia-pack.mjs — the offline research source: the SAME
|
|
2
|
+
// shipped reference pack the reference lane serves
|
|
3
|
+
// (src/domain/reference-pack.mjs's shape, src/adapters/corpus/
|
|
4
|
+
// reference-pack.mjs's lazy fs loader), read as a research-source.mjs
|
|
5
|
+
// adapter so "research <topic>" can ground a turn with no network at all.
|
|
6
|
+
//
|
|
7
|
+
// Registered under its own name, "simple-wikipedia-pack" — deliberately
|
|
8
|
+
// distinct from the live "simple-wikipedia" source, so a fact stamped
|
|
9
|
+
// through researchFacts() (the news lane, the contract tests) still tells
|
|
10
|
+
// the pack apart from a live fetch at the provenance-tag layer. The
|
|
11
|
+
// interactive "research <topic>" chat lane stamps its own source-agnostic
|
|
12
|
+
// research:<topic>@<depth> tag regardless of which source grounded the
|
|
13
|
+
// turn (src/services/research.mjs); that tag is unaffected by this module
|
|
14
|
+
// and stays exactly as it already is for every other research source.
|
|
15
|
+
//
|
|
16
|
+
// "Linked" topics: the pack carries no link graph, so linkedTitles reads the
|
|
17
|
+
// pack's OWN cross-references instead — other terms the pack's index
|
|
18
|
+
// already knows, found as whole words inside this article's text, in the
|
|
19
|
+
// order they first occur. It is the offline analogue of a live source's
|
|
20
|
+
// lead-section links, built entirely from data already on disk.
|
|
21
|
+
//
|
|
22
|
+
// No network, ever — every read goes through the pack's own lazy, cached fs
|
|
23
|
+
// loader. Node-only, unlike the browser-shipped live adapters: the pack's fs
|
|
24
|
+
// layout is not available in the browser bundle, so this module is not
|
|
25
|
+
// imported there.
|
|
26
|
+
|
|
27
|
+
import { normFactTerm } from "../../domain/hash.mjs";
|
|
28
|
+
import { loadLexicon, lookupNoun } from "../../domain/grammar/lexicon.mjs";
|
|
29
|
+
import { isContentToken } from "../../domain/prose.mjs";
|
|
30
|
+
import { isReferenceArticleRow } from "../../domain/reference-pack.mjs";
|
|
31
|
+
import { loadReferenceIndex, loadReferenceArticle, referencePackDir } from "./reference-pack.mjs";
|
|
32
|
+
import { registerResearchSource, researchSourceTag } from "./research-source.mjs";
|
|
33
|
+
|
|
34
|
+
export const SIMPLE_WIKIPEDIA_PACK_ORIGIN = "https://simple.wikipedia.org";
|
|
35
|
+
export const SIMPLE_WIKIPEDIA_PACK_SOURCE_NAME = "simple-wikipedia-pack";
|
|
36
|
+
|
|
37
|
+
const WORD_RE = /[A-Za-z][A-Za-z'-]*/g;
|
|
38
|
+
const MAX_LINKED_TITLES = 25;
|
|
39
|
+
|
|
40
|
+
/** A text word folded to the pack index's own key: the lexicon's lemma when
|
|
41
|
+
* the word is a known noun ("birds" -> "bird"), else its own normFactTerm
|
|
42
|
+
* fold — the same fallback reference-pack.mjs's isaOf extraction uses. */
|
|
43
|
+
function packIndexKey(word, lexicon) {
|
|
44
|
+
const entry = lookupNoun(lexicon, word);
|
|
45
|
+
return entry ? normFactTerm(entry.lemma) : normFactTerm(word);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const capitalize = (key) => key.charAt(0).toUpperCase() + key.slice(1);
|
|
49
|
+
|
|
50
|
+
/** Other pack terms this article's text mentions, in the order they first
|
|
51
|
+
* occur, excluding the article's own term. The pack's index keys an alias
|
|
52
|
+
* ("prey") on whatever article it redirects to ("predator"), and carries no
|
|
53
|
+
* reverse title index — so the WORD found in the text, not that article's
|
|
54
|
+
* own (possibly unrelated-looking) title, is what round-trips back through
|
|
55
|
+
* lookup()/pageByTitle() correctly; capitalized for display only, since
|
|
56
|
+
* normFactTerm folds case away on the way back in. Every candidate is
|
|
57
|
+
* confirmed against a real row before it queues, so a stale index entry
|
|
58
|
+
* never queues a fetch that would fail. */
|
|
59
|
+
function packLinkedTitles(dir, text, ownKey, index, lexicon, limit) {
|
|
60
|
+
if (!index || limit <= 0) return [];
|
|
61
|
+
const seen = new Set([ownKey]);
|
|
62
|
+
const out = [];
|
|
63
|
+
for (const match of String(text ?? "").matchAll(WORD_RE)) {
|
|
64
|
+
if (out.length >= limit) break;
|
|
65
|
+
const key = packIndexKey(match[0], lexicon);
|
|
66
|
+
if (!key || !isContentToken(key) || seen.has(key) || !index[key]) continue;
|
|
67
|
+
seen.add(key);
|
|
68
|
+
if (!loadReferenceArticle(dir, key)) continue;
|
|
69
|
+
out.push(capitalize(key));
|
|
70
|
+
}
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The offline pack-backed research source: { name, origin, lookup(term),
|
|
76
|
+
* pageByTitle(title), linkedTitles(title, {limit}), provenanceTag(term) } —
|
|
77
|
+
* the research-source.mjs contract, satisfied entirely from the shipped
|
|
78
|
+
* reference pack on disk.
|
|
79
|
+
*
|
|
80
|
+
* `dir` defaults to the pack's own resolution order (TMCT_REFERENCE_PACK_DIR
|
|
81
|
+
* env, else the package's shipped corpus/reference/ — referencePackDir()).
|
|
82
|
+
* `lexicon` defaults to the shared lexicon, lazily loaded and cached the same
|
|
83
|
+
* way every other reference/research reader does.
|
|
84
|
+
*/
|
|
85
|
+
export function createSimpleWikipediaPackSource({
|
|
86
|
+
dir,
|
|
87
|
+
lexicon = null,
|
|
88
|
+
sourceName = SIMPLE_WIKIPEDIA_PACK_SOURCE_NAME,
|
|
89
|
+
} = {}) {
|
|
90
|
+
const packDir = dir || referencePackDir();
|
|
91
|
+
let lex = lexicon;
|
|
92
|
+
function activeLexicon() {
|
|
93
|
+
if (lex) return lex;
|
|
94
|
+
try { lex = loadLexicon(); } catch { lex = null; }
|
|
95
|
+
return lex;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function rowFor(term) {
|
|
99
|
+
const key = normFactTerm(term ?? "");
|
|
100
|
+
if (!key) return null;
|
|
101
|
+
const article = loadReferenceArticle(packDir, key);
|
|
102
|
+
if (!article) return null;
|
|
103
|
+
const row = { ...article, term: key };
|
|
104
|
+
return isReferenceArticleRow(row) ? row : null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
name: sourceName,
|
|
109
|
+
origin: SIMPLE_WIKIPEDIA_PACK_ORIGIN,
|
|
110
|
+
|
|
111
|
+
provenanceTag(term) {
|
|
112
|
+
return researchSourceTag(sourceName, term);
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
async lookup(term) {
|
|
116
|
+
return rowFor(term);
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
/** The pack row for an exact title — the pack's own term index already
|
|
120
|
+
* resolves a title's canonical key in one lookup, so this is the same
|
|
121
|
+
* read `lookup` performs, no round trip either way. */
|
|
122
|
+
async pageByTitle(title) {
|
|
123
|
+
return rowFor(title);
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
async linkedTitles(title, { limit = MAX_LINKED_TITLES } = {}) {
|
|
127
|
+
const article = rowFor(title);
|
|
128
|
+
if (!article) return null;
|
|
129
|
+
const index = loadReferenceIndex(packDir);
|
|
130
|
+
return packLinkedTitles(packDir, article.text, article.term, index, activeLexicon(), Math.max(0, limit));
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
registerResearchSource({
|
|
136
|
+
name: SIMPLE_WIKIPEDIA_PACK_SOURCE_NAME,
|
|
137
|
+
create: createSimpleWikipediaPackSource,
|
|
138
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// backends-exports.mjs — the `./memory-backends` package export: every
|
|
2
|
+
// shipped memory row backend plus the contract's shared failure classes and
|
|
3
|
+
// its duck-type test, in one place for a consumer who wants storage without
|
|
4
|
+
// reaching into src/adapters directly. Follows the ./envelope, ./news, and
|
|
5
|
+
// ./memory-backend-conformance subpath precedents.
|
|
6
|
+
export { createRowMemoryBackend } from "./row-backend-memory.mjs";
|
|
7
|
+
export { createDynamoRowBackend } from "./row-backend-dynamo.mjs";
|
|
8
|
+
export { isRowBackend, BackendRejected, BackendUnavailable } from "./row-backend.mjs";
|