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

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.
Files changed (34) hide show
  1. package/README.md +27 -0
  2. package/bin/tmct.mjs +61 -0
  3. package/package.json +14 -2
  4. package/src/adapters/memory/backends-exports.mjs +8 -0
  5. package/src/adapters/memory/core.mjs +812 -175
  6. package/src/adapters/memory/corpus-bands.mjs +155 -0
  7. package/src/adapters/memory/dynamo-circuit-breaker.mjs +266 -0
  8. package/src/adapters/memory/row-backend-dynamo.mjs +315 -0
  9. package/src/adapters/memory/row-backend-memory.mjs +85 -0
  10. package/src/adapters/memory/row-backend.mjs +162 -0
  11. package/src/adapters/memory/rows.mjs +328 -0
  12. package/src/adapters/memory/shacl.mjs +24 -0
  13. package/src/adapters/memory/systemic-failure.mjs +28 -0
  14. package/src/adapters/research-queue-store.mjs +215 -32
  15. package/src/domain/ask.mjs +341 -75
  16. package/src/domain/cli-verbs.mjs +17 -0
  17. package/src/domain/fact-phrase.mjs +40 -0
  18. package/src/domain/news-feed.mjs +42 -4
  19. package/src/domain/phrase-exports.mjs +4 -0
  20. package/src/domain/retrieval-marker.mjs +120 -0
  21. package/src/domain/retrieval-modes.mjs +13 -0
  22. package/src/domain/retrieval-plan.mjs +224 -0
  23. package/src/services/chat-session.mjs +36 -9
  24. package/src/services/chat.mjs +73 -16
  25. package/src/services/corpus-loader.mjs +222 -0
  26. package/src/services/extract-facts.mjs +244 -33
  27. package/src/services/init.mjs +15 -5
  28. package/src/services/news.mjs +4 -2
  29. package/src/services/subgraph-retrieval.mjs +332 -0
  30. package/src/surfaces/web/http-row-backend.mjs +150 -0
  31. package/src/surfaces/web/memory-ask-browser.bundle.js +134 -131
  32. package/src/surfaces/web/news-browser-entry.mjs +6 -2
  33. package/src/tools/handlers/tmct-ingest.mjs +3 -1
  34. package/src/tools/memory-backend-conformance.mjs +238 -0
package/README.md CHANGED
@@ -981,6 +981,18 @@ package or a bare user gets a working install in one command.
981
981
  > Install-size note: tmct depends on wink-nlp's deterministic English language
982
982
  > model (~3.8 MB installed). That model is a lookup table, not an LLM.
983
983
 
984
+ ### Custom memory backends
985
+
986
+ Memory — the facts you teach tmct — lives behind a pluggable adapter seam. The CLI and library come with three backends: in-memory (ephemeral), SQLite (the CLI's default), and DynamoDB (for hosted deployments). You can inject a custom backend and tmct will read and write through it instead. The backend is a small async row store scoped to one session key — it needs eight methods (read, write, delete, and a couple of scalar sidecars). The published conformance suite validates that a custom backend meets the contract. See `docs/adapter-contract.md` for the full interface and `src/adapters/memory/row-backend-memory.mjs` for the reference implementation. Wire it into a session:
987
+
988
+ ```js skip=illustrative-import
989
+ import { createSession } from "@polycode-projects/the-mechanical-code-talker";
990
+ import { createMyBackend } from "./my-backend.mjs";
991
+
992
+ const backend = createMyBackend(sessionKey, config);
993
+ const session = await createSession({ memoryBackend: backend });
994
+ ```
995
+
984
996
  ### Full command reference (`tmct --help`)
985
997
 
986
998
  `tmct --help` always prints the real, current flags. What follows is that
@@ -1194,6 +1206,21 @@ kill $SERVE_PID
1194
1206
  [--graph <path>] the same thing. --graph names the graph file outright
1195
1207
  [--config <path>] (repeatable), --config an alternate tmct.toml
1196
1208
  tmct cli digest '{…}' architecture map + per-module context bundles
1209
+ ```
1210
+
1211
+ `tmct corpus` loads a shared, read-only corpus band into a DynamoDB
1212
+ row-backend table, or clears one; the deployed turn service reads the loaded
1213
+ bands per query:
1214
+
1215
+ ```output:help:corpus
1216
+ tmct corpus load <band> [--table <name>] [--source <path>] [--dry-run] load a shared, read-only corpus band (wikidata-slice, wordnet-complete,
1217
+ [--table <name>] conceptnet-full) into a DynamoDB row-backend table from a jsonl of
1218
+ wire-row-shaped facts (default table from TMCT_DYNAMO_TABLE); a
1219
+ source whose digest already matches the band's manifest is a no-op
1220
+ [--source <path>] the band's jsonl (a scripts/corpus-bands/ build output, or any jsonl
1221
+ in the same wire-row shape)
1222
+ [--dry-run] report the row count and source digest without writing anything
1223
+ tmct corpus clear <band> [--table <name>] physically delete every row and the manifest for one band
1197
1224
  tmct --help show this help
1198
1225
  ```
1199
1226
 
package/bin/tmct.mjs CHANGED
@@ -1821,6 +1821,67 @@ async function main() {
1821
1821
  return;
1822
1822
  }
1823
1823
 
1824
+ if (mode === "corpus") {
1825
+ // `tmct corpus load|clear <band>` — the credentialed operator verb pair
1826
+ // over the shared, read-only corpus bands (src/adapters/memory/corpus-bands.mjs,
1827
+ // src/services/corpus-loader.mjs). Ambient AWS credentials only (a
1828
+ // profile locally, OIDC in CI) — this dispatch never embeds any.
1829
+ const rest = process.argv.slice(3);
1830
+ const subcommand = rest[0];
1831
+ if (subcommand !== "load" && subcommand !== "clear") {
1832
+ process.stderr.write("tmct corpus — name an action: `tmct corpus load <band>` or `tmct corpus clear <band>`\n");
1833
+ process.exitCode = 1;
1834
+ return;
1835
+ }
1836
+ const band = rest.slice(1).find((a) => !a.startsWith("-"));
1837
+ if (!band) {
1838
+ process.stderr.write(`tmct corpus ${subcommand} — name a band: \`tmct corpus ${subcommand} <band>\`\n`);
1839
+ process.exitCode = 1;
1840
+ return;
1841
+ }
1842
+ const { strFlag } = await import("../src/services/cli-args.mjs");
1843
+ const tableName = strFlag(rest, "--table") || process.env.TMCT_DYNAMO_TABLE;
1844
+ if (!tableName) {
1845
+ process.stderr.write("tmct corpus — no table name given (--table <name> or TMCT_DYNAMO_TABLE)\n");
1846
+ process.exitCode = 1;
1847
+ return;
1848
+ }
1849
+
1850
+ let DynamoDBClient;
1851
+ let DynamoDBDocument;
1852
+ try {
1853
+ ({ DynamoDBClient } = await import("@aws-sdk/client-dynamodb"));
1854
+ ({ DynamoDBDocument } = await import("@aws-sdk/lib-dynamodb"));
1855
+ } catch (cause) {
1856
+ process.stderr.write(
1857
+ "tmct corpus needs \"@aws-sdk/lib-dynamodb\" (>=3) installed alongside tmct; "
1858
+ + `run \`npm install @aws-sdk/lib-dynamodb\` and retry (${cause.message})\n`,
1859
+ );
1860
+ process.exitCode = 1;
1861
+ return;
1862
+ }
1863
+ const client = DynamoDBDocument.from(new DynamoDBClient({}));
1864
+
1865
+ if (subcommand === "load") {
1866
+ const source = strFlag(rest, "--source");
1867
+ if (!source) {
1868
+ process.stderr.write("tmct corpus load — name a source: `tmct corpus load <band> --source <path>`\n");
1869
+ process.exitCode = 1;
1870
+ return;
1871
+ }
1872
+ const { loadBand } = await import("../src/services/corpus-loader.mjs");
1873
+ const result = await loadBand({ client, tableName, band, source, dryRun: rest.includes("--dry-run") });
1874
+ const verb = { unchanged: "unchanged", loaded: "loaded", "dry-run": "would load" }[result.status];
1875
+ process.stdout.write(`tmct corpus load ${band}: ${verb} (${result.rowCount} row(s), source digest ${result.sourceDigest})\n`);
1876
+ return;
1877
+ }
1878
+
1879
+ const { clearBand } = await import("../src/services/corpus-loader.mjs");
1880
+ const result = await clearBand({ client, tableName, band });
1881
+ process.stdout.write(`tmct corpus clear ${band}: deleted ${result.deleted} item(s)\n`);
1882
+ return;
1883
+ }
1884
+
1824
1885
  // An unknown mode gets the instructive usage line and exit 2. (A bare invocation
1825
1886
  // never lands here — the argv splice above rewrote it to `chat`.)
1826
1887
  process.stderr.write(unknownInvocationMessage(process.argv.slice(2).join(" ")));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polycode-projects/the-mechanical-code-talker",
3
- "version": "5.0.46",
3
+ "version": "6.0.1",
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.",
@@ -53,7 +53,9 @@
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"
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"
57
59
  },
58
60
  "files": [
59
61
  "bin/",
@@ -89,6 +91,14 @@
89
91
  "wink-eng-lite-web-model": "^1.8.1",
90
92
  "wink-nlp": "^2.4.0"
91
93
  },
94
+ "peerDependencies": {
95
+ "@aws-sdk/lib-dynamodb": ">=3"
96
+ },
97
+ "peerDependenciesMeta": {
98
+ "@aws-sdk/lib-dynamodb": {
99
+ "optional": true
100
+ }
101
+ },
92
102
  "scripts": {
93
103
  "help": "node --disable-warning=ExperimentalWarning bin/tmct.mjs --help",
94
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\"",
@@ -173,6 +183,7 @@
173
183
  "claim:news": "node scripts/news-rig.mjs",
174
184
  "roll": "node scripts/roll.mjs",
175
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",
176
187
  "build:chat-bundle": "node scripts/build-chat-bundle.mjs",
177
188
  "build:spider-fly-bundle": "node scripts/build-spider-fly-bundle.mjs",
178
189
  "build:plan-bundle": "node scripts/build-plan-bundle.mjs",
@@ -206,6 +217,7 @@
206
217
  "extract:facts": "node --disable-warning=ExperimentalWarning bin/tmct.mjs extract"
207
218
  },
208
219
  "devDependencies": {
220
+ "@aws-sdk/lib-dynamodb": "3.1106.0",
209
221
  "esbuild": "0.28.1",
210
222
  "ink-testing-library": "4.0.0",
211
223
  "playwright": "1.61.1",
@@ -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";