@polycode-projects/the-mechanical-code-talker 2.8.13 → 2.9.3

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 (37) hide show
  1. package/README.md +50 -28
  2. package/bin/tmct.mjs +176 -31
  3. package/corpus/LICENSES.json +7 -0
  4. package/corpus/sprites/src/sprite-facts.jsonl +1033 -0
  5. package/corpus/worlds/manifest.json +9 -9
  6. package/corpus/worlds/shards/ashcombe-hall.jsonl.gz +0 -0
  7. package/corpus/worlds/shards/spider-fly.jsonl.gz +0 -0
  8. package/corpus/worlds/src/ashcombe-hall.jsonl +3 -0
  9. package/corpus/worlds/src/spider-fly.jsonl +17 -0
  10. package/package.json +37 -34
  11. package/src/adapters/corpus/wikipedia-live.mjs +145 -0
  12. package/src/adapters/memory/core.mjs +77 -12
  13. package/src/adapters/toml-config.mjs +6 -5
  14. package/src/domain/cli-verbs.mjs +4 -2
  15. package/src/domain/hanoi-lesson.mjs +10 -0
  16. package/src/domain/reference-pack.mjs +102 -0
  17. package/src/domain/spider-fly-world.mjs +54 -1
  18. package/src/domain/sprite-facts.mjs +0 -0
  19. package/src/services/adventure-viz.mjs +208 -66
  20. package/src/services/chat-page-viz.mjs +366 -37
  21. package/src/services/chat-session.mjs +38 -22
  22. package/src/services/chat.mjs +199 -20
  23. package/src/services/fold.mjs +28 -44
  24. package/src/services/import-file.mjs +7 -6
  25. package/src/services/init.mjs +10 -5
  26. package/src/services/ledger-viz.mjs +25 -34
  27. package/src/services/plan-viz.mjs +22 -26
  28. package/src/services/sessions.mjs +15 -3
  29. package/src/services/spider-fly-viz.mjs +52 -49
  30. package/src/services/sprite-catalog-viz.mjs +187 -3
  31. package/src/services/viz-theme.mjs +8 -0
  32. package/src/surfaces/web/adventure-browser-entry.mjs +23 -10
  33. package/src/surfaces/web/chat-browser-entry.mjs +17 -2
  34. package/src/surfaces/web/idb-persist.mjs +115 -0
  35. package/src/surfaces/web/memory-ask-browser.bundle.js +155 -25927
  36. package/src/surfaces/web/sprites-browser-entry.mjs +68 -0
  37. package/src/tools/memory-fallthrough.mjs +11 -4
@@ -0,0 +1,68 @@
1
+ // sprites-browser-entry.mjs — the esbuild entry for sprites.html's chat dock
2
+ // (public/sprites-browser.bundle.js, built by scripts/build-sprites-bundle.mjs).
3
+ //
4
+ // One session factory over the real engine, mirroring
5
+ // spider-fly-browser-entry.mjs's createSpiderFlySession minus the game: no
6
+ // board, no tick — just the FULL chat turn engine (chat.mjs's runTurn, the
7
+ // exact dispatch the CLI runs) over one in-memory store seeded with the
8
+ // sprite-facts corpus the page embeds at build time
9
+ // (src/domain/sprite-facts.mjs's rows). A question the engine can't ground in
10
+ // those rows gets the same refusal the CLI gives — never a guess.
11
+ //
12
+ // The page's own inline script answers the closed set of catalog-specific
13
+ // question shapes (sprite-catalog-viz.mjs's answerSpriteQuestion) BEFORE
14
+ // handing a line to this session, so this bundle carries no sprite-specific
15
+ // grammar of its own.
16
+ import { runTurn } from "../../services/chat.mjs";
17
+ import { createInMemoryStore, appendFacts, normFactTerm } from "../../adapters/memory/core.mjs";
18
+ import { parseEntities } from "../../domain/codegraph.mjs";
19
+ import { loadLexicon } from "../../domain/grammar/lexicon.mjs";
20
+ import { SPRITE_FACTS_PROVENANCE } from "../../domain/sprite-facts.mjs";
21
+ import { registerWinkModel } from "../../adapters/wink-model.mjs";
22
+
23
+ /** A live in-memory chat session seeded with the embedded sprite-facts rows.
24
+ * Returns { memoryDir, sessionId, factCount, turn }. */
25
+ export async function createSpriteCatalogSession({ factRows = [] } = {}) {
26
+ const memoryDir = createInMemoryStore();
27
+ await appendFacts(memoryDir, factRows.map((f) => ({
28
+ subject: f.subject, predicate: f.predicate, object: f.object, provenance: SPRITE_FACTS_PROVENANCE,
29
+ })));
30
+
31
+ const graph = parseEntities({ individuals: [], objectProperties: [] });
32
+ const lexicon = loadLexicon();
33
+ const sessionId = globalThis.crypto?.randomUUID?.() ?? String(Date.now());
34
+
35
+ let focus = null;
36
+ let last = null;
37
+
38
+ return {
39
+ memoryDir,
40
+ sessionId,
41
+ factCount: factRows.length,
42
+
43
+ /** One dispatched chat turn — the SAME runTurn the CLI runs, over this
44
+ * session's own memoryDir. A throwing runTurn must never kill the
45
+ * session — the page has no other chance to show this turn's answer. */
46
+ async turn(line) {
47
+ let result;
48
+ try {
49
+ result = await runTurn(line, {
50
+ config: null, source: null, graph, focus, last, memoryDir, sessionId,
51
+ env: {}, lexicon, vocabHint: "",
52
+ });
53
+ } catch (e) {
54
+ const message = e instanceof Error ? e.message : String(e);
55
+ return { answer: `Something went wrong answering that (${message}). Try rephrasing, or /help.`, end: false, record: null };
56
+ }
57
+ focus = result.focus;
58
+ last = result.last;
59
+ return { answer: result.answer, end: Boolean(result.end), record: result.record ?? null };
60
+ },
61
+ };
62
+ }
63
+
64
+ // registerWinkModel is re-exported so the page's own inline script can hand in
65
+ // the self-hosted wink pair (./vendor/wink.js) exactly the way chat.html/
66
+ // ledger.html/plan.html register theirs — the bundle itself never imports
67
+ // wink-nlp (wink-model.mjs's own header explains why).
68
+ globalThis.tmctSprites = { createSpriteCatalogSession, registerWinkModel, normFactTerm };
@@ -4,7 +4,7 @@
4
4
  // facts instead, always citing provenance.
5
5
 
6
6
  import { dirname } from "node:path";
7
- import { loadMemory, readFactRows, normFactTerm } from "../adapters/memory/core.mjs";
7
+ import { loadMemory, openConfiguredMemoryBackend, readFactRows, normFactTerm } from "../adapters/memory/core.mjs";
8
8
 
9
9
  // The reified isa-family predicates a memory Fact carries ("<subject> rdfs:subClassOf
10
10
  // <object>" / "rdf:type"): subject IS-A object. Subclasses of X = facts whose OBJECT is X;
@@ -14,11 +14,18 @@ const MEMORY_LIST_CAP = 40;
14
14
 
15
15
  /** Load the conversational-memory Facts as trust-bearing rows, failure-tolerant (no memory
16
16
  * store / unreadable → [], so the tool still returns its honest code-map miss). repoRoot is
17
- * the dir that CONTAINS .tmct/ (graphFile = <repo>/.tmct/graph.json), which is exactly the
18
- * `dir` loadMemory joins MEMORY_GRAPH_REL onto. */
17
+ * the dir that CONTAINS .tmct/ (graphFile = <repo>/.tmct/graph.json). The read goes through
18
+ * the repo's CONFIGURED memory backend — the same store chat's taught facts land in — opened
19
+ * fresh per call and closed before returning, never the retired flat-file store off a raw
20
+ * repo path. */
19
21
  export async function memoryFactRows(config) {
20
22
  try {
21
- return readFactRows(await loadMemory(dirname(dirname(config.graphFile))));
23
+ const { dir, close } = await openConfiguredMemoryBackend(dirname(dirname(config.graphFile)));
24
+ try {
25
+ return readFactRows(await loadMemory(dir));
26
+ } finally {
27
+ await close();
28
+ }
22
29
  } catch {
23
30
  return [];
24
31
  }