@polycode-projects/the-mechanical-code-talker 4.0.1 → 4.1.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 (65) hide show
  1. package/README.md +2 -1
  2. package/corpus/sprites/src/sprite-facts.jsonl +375 -8
  3. package/package.json +1 -1
  4. package/src/adapters/memory/core.mjs +20 -0
  5. package/src/domain/ask-vocab.mjs +71 -0
  6. package/src/domain/ask.mjs +168 -0
  7. package/src/domain/game-config.mjs +11 -0
  8. package/src/domain/mud-facts.mjs +15 -0
  9. package/src/domain/router/drive.mjs +35 -9
  10. package/src/domain/router/registry.mjs +24 -4
  11. package/src/domain/router/resolver.mjs +102 -40
  12. package/src/domain/scene-compose.mjs +117 -0
  13. package/src/domain/spider-fly-world.mjs +36 -0
  14. package/src/domain/sprite-facts.mjs +0 -0
  15. package/src/domain/sprite-request.mjs +156 -0
  16. package/src/domain/sprite-templates.mjs +161 -14
  17. package/src/services/adventure-editor.mjs +8 -14
  18. package/src/services/adventure-viz.mjs +119 -150
  19. package/src/services/adventure.mjs +97 -35
  20. package/src/services/chat-page-viz.mjs +64 -48
  21. package/src/services/chat.mjs +102 -34
  22. package/src/services/code-explorer-viz.mjs +52 -50
  23. package/src/services/ingest-viz.mjs +32 -74
  24. package/src/services/ledger-viz.mjs +87 -70
  25. package/src/services/memory-panel-viz.mjs +38 -0
  26. package/src/services/mud-editor.mjs +10 -15
  27. package/src/services/mud-turn.mjs +6 -6
  28. package/src/services/mud-viz.mjs +119 -225
  29. package/src/services/p2p-room.mjs +90 -23
  30. package/src/services/plan-pddl.mjs +3 -1
  31. package/src/services/plan-viz.mjs +13 -12
  32. package/src/services/research-viz.mjs +25 -67
  33. package/src/services/spider-fly-turn.mjs +14 -22
  34. package/src/services/spider-fly-viz.mjs +97 -136
  35. package/src/services/spider-fly.mjs +69 -11
  36. package/src/services/sprite-catalog-viz.mjs +274 -224
  37. package/src/services/viz-boot.mjs +71 -0
  38. package/src/services/viz-room-graph.mjs +203 -0
  39. package/src/services/viz-theme.mjs +75 -1
  40. package/src/services/viz-ticker.mjs +22 -0
  41. package/src/surfaces/web/adventure-browser-entry.mjs +62 -47
  42. package/src/surfaces/web/chat-browser-entry.mjs +51 -107
  43. package/src/surfaces/web/code-explorer-browser-entry.mjs +192 -35
  44. package/src/surfaces/web/engine-surface.mjs +82 -0
  45. package/src/surfaces/web/ingest-browser-entry.mjs +16 -17
  46. package/src/surfaces/web/ledger-browser-entry.mjs +24 -56
  47. package/src/surfaces/web/memory-ask-browser-entry.mjs +55 -13
  48. package/src/surfaces/web/memory-ask-browser.bundle.js +128 -125
  49. package/src/surfaces/web/memory-stats.mjs +11 -0
  50. package/src/surfaces/web/mud-browser-entry.mjs +70 -49
  51. package/src/surfaces/web/plan-browser-entry.mjs +39 -50
  52. package/src/surfaces/web/research-browser-entry.mjs +48 -46
  53. package/src/surfaces/web/spider-fly-browser-entry.mjs +76 -40
  54. package/src/surfaces/web/sprites-browser-entry.mjs +28 -32
  55. package/src/surfaces/web/tmct-surface.mjs +147 -0
  56. package/src/surfaces/web/turn-session.mjs +124 -0
  57. package/src/tools/definitions.mjs +30 -0
  58. package/src/tools/handlers/index.mjs +6 -3
  59. package/src/tools/handlers/kit.mjs +19 -2
  60. package/src/tools/handlers/tmct-ask.mjs +11 -6
  61. package/src/tools/handlers/tmct-ingest.mjs +5 -1
  62. package/src/tools/handlers/tmct-related.mjs +4 -4
  63. package/src/tools/handlers/tmct-sprite.mjs +147 -0
  64. package/src/tools/memory-fallthrough.mjs +9 -2
  65. package/src/tools/server.mjs +37 -6
@@ -16,9 +16,8 @@
16
16
  // class as chat/spider-fly/adventure/plan's own browser bundles) and is
17
17
  // never published — only the hosted demo site's public/ledger.html links to
18
18
  // it, as an optional sibling script the page degrades honestly without.
19
- import { runTurn, vocabExampleHint } from "../../services/chat.mjs";
20
- import { createInMemoryStore, normFactTerm, loadMemory } from "../../adapters/memory/core.mjs";
21
- import { serializeFactsJsonl } from "../../adapters/memory/export-jsonl.mjs";
19
+ import { vocabExampleHint } from "../../services/chat.mjs";
20
+ import { createInMemoryStore, normFactTerm, applySeedPayload } from "../../adapters/memory/core.mjs";
22
21
  import { splitSentencesPreservingPaths } from "../../services/sentences.mjs";
23
22
  import { parseEntities } from "../../domain/codegraph.mjs";
24
23
  import { loadLexicon } from "../../domain/grammar/lexicon.mjs";
@@ -26,6 +25,10 @@ import { registerWinkModel } from "../../adapters/wink-model.mjs";
26
25
  import { registerResearchProvider } from "../../adapters/corpus/wikipedia-live.mjs";
27
26
  import { computeLedgerDataFromPayload } from "../../services/ledger-viz.mjs";
28
27
  import { digestTermFromPayloadBrowser } from "./digest-client.mjs";
28
+ import { createTurnSession } from "./turn-session.mjs";
29
+ import { exportFactsJsonl } from "./memory-stats.mjs";
30
+ import { publishTmctSurface } from "./tmct-surface.mjs";
31
+ import { graphAsk, enginePlan } from "./engine-surface.mjs";
29
32
 
30
33
  /**
31
34
  * A browser ledger-dock session over the real turn engine — createChatSession's
@@ -34,7 +37,7 @@ import { digestTermFromPayloadBrowser } from "./digest-client.mjs";
34
37
  * a fact taught through the dock extends the SAME graph the page renders
35
38
  * from, never a disconnected one.
36
39
  *
37
- * Returns { memoryDir, sessionId, turn }, identical to createChatSession.
40
+ * Returns { memoryDir, sessionId, graph, turn }, identical to createChatSession.
38
41
  * ledger-viz.mjs's own inline script calls computeLedgerDataFromPayload
39
42
  * (re-exported below) on `memoryDir.payload` after a turn whose record shows
40
43
  * a successful write (`via: "assert"` or `via: "retract"`, `miss: false`) to
@@ -43,63 +46,28 @@ import { digestTermFromPayloadBrowser } from "./digest-client.mjs";
43
46
  */
44
47
  export function createLedgerSession({ seedPayload = null, vocabSeeded = false } = {}) {
45
48
  const memoryDir = createInMemoryStore();
46
- // Spread onto the store's own empty payload so a partial seed still
47
- // carries the classes/prefixes scaffolding the write path recounts —
48
- // teach turns must work regardless of what the seed payload carries.
49
- if (seedPayload) memoryDir.payload = { ...memoryDir.payload, ...seedPayload };
49
+ applySeedPayload(memoryDir, seedPayload);
50
50
 
51
51
  const graph = parseEntities({ individuals: [], objectProperties: [] });
52
52
  const lexicon = loadLexicon();
53
53
  const vocabHint = vocabExampleHint(vocabSeeded);
54
54
  const sessionId = globalThis.crypto?.randomUUID?.() ?? String(Date.now());
55
55
 
56
- let focus = null;
57
- let last = null;
58
- let planState = null;
59
- let researchState = null;
60
-
61
- return {
62
- memoryDir,
63
- sessionId,
64
-
65
- /** One dispatched turn. A throwing runTurn must never kill the session —
66
- * the page has no other chance to show this turn's answer. */
67
- async turn(line) {
68
- let result;
69
- try {
70
- result = await runTurn(line, {
71
- config: null, source: null, graph, focus, last, memoryDir, sessionId,
72
- env: {}, lexicon, vocabHint, planState, researchState,
73
- });
74
- } catch (e) {
75
- const message = e instanceof Error ? e.message : String(e);
76
- return { answer: `Something went wrong answering that (${message}). Try rephrasing, or /help.`, end: false, record: null, research: null };
77
- }
78
- focus = result.focus;
79
- last = result.last;
80
- if ("planState" in result) planState = result.planState;
81
- if ("researchState" in result) researchState = result.researchState;
82
- // `research` distinguishes a queue snapshot (research turn) from null
83
- // (a research turn that ended the run) from undefined (not a research
84
- // turn) — the dock's controls only react to the first two.
85
- return { answer: result.answer, end: Boolean(result.end), record: result.record ?? null, research: result.research };
86
- },
87
- };
88
- }
89
-
90
- /** The session's whole triple store as JSONL — the same
91
- * { subject, predicate, object, provenance } shape `tmct extract` and
92
- * `tmct memory --export` emit. The ledger dock's "export facts" control reads
93
- * this and offers it as a download. */
94
- export async function exportFactsJsonl(memoryDir) {
95
- return serializeFactsJsonl(await loadMemory(memoryDir));
56
+ const session = createTurnSession({ memoryDir, graph, lexicon, sessionId, vocabHint });
57
+ return { memoryDir, sessionId, graph, turn: session.turn };
96
58
  }
97
59
 
98
- // Re-exported so ledger-viz.mjs's own inline script never has to duplicate
99
- // the derivation logic that builds rows/terms/edges/contradictions/
100
- // worthALook/stats from a payload the same posture chat-browser-entry.mjs
101
- // takes re-exporting registerWinkModel for its own page's CDN wink load.
102
- // splitSentences + exportFactsJsonl carry the dock's paste-and-drop ingest and
103
- // its JSONL export across the bundle boundary, the same one-serializer posture
104
- // chat-browser-entry.mjs holds for its own page.
105
- globalThis.tmctLedger = { createLedgerSession, computeLedgerDataFromPayload, normFactTerm, registerWinkModel, registerResearchProvider, splitSentences: splitSentencesPreservingPaths, exportFactsJsonl, digestTermFromPayloadBrowser };
60
+ // `tmct.page` keeps what the page's own script renders with and the engine has
61
+ // no plain-English form for: the payload-to-rows/terms/edges/stats derivation
62
+ // the ledger view re-mounts from after a successful teach, the digest reader,
63
+ // the wink and research seams, and the two serializers behind the dock's
64
+ // paste-ingest and JSONL export.
65
+ publishTmctSurface({
66
+ open: createLedgerSession,
67
+ ask: graphAsk,
68
+ plan: enginePlan,
69
+ page: {
70
+ computeLedgerDataFromPayload, normFactTerm, registerWinkModel, registerResearchProvider,
71
+ splitSentences: splitSentencesPreservingPaths, exportFactsJsonl, digestTermFromPayloadBrowser,
72
+ },
73
+ });
@@ -1,20 +1,62 @@
1
1
  // memory-ask-browser-entry.mjs — the esbuild entry for the ledger page's
2
2
  // chat dock (`tmct viz`, src/services/ledger-viz.mjs).
3
3
  //
4
- // Re-exports `factAnswer` (src/services/chat.mjs) and `createInMemoryStore`
5
- // (src/adapters/memory/core.mjs), which lets the dock hand `factAnswer` the page's
6
- // already-embedded payload with zero fs I/O. Called with `envelope: null,
7
- // miss: true` to arm factAnswer's bare-question regex fallbacks directly,
8
- // bypassing the structural-graph parse pipeline this dock has no use for.
4
+ // The one COMMITTED browser bundle: `tmct viz` is a real CLI command run
5
+ // against a user's own local .tmct store, so this ships with the package. It
6
+ // deliberately carries the question lanes only (factAnswer/factReadBack) and
7
+ // not the full turn engine — see ledger-browser-entry.mjs's header for the
8
+ // contrast with the demo site's own 1.5MB dock.
9
+ //
10
+ // It publishes the SAME `globalThis.tmct` every other page does, through
11
+ // tmct-surface.mjs, which imports nothing — so this bundle gets the shared
12
+ // contract without the tool layer or the capability router coming with it.
13
+ // `tmct.turn` and `tmct.plan` are unwired here and say so: this dock asks
14
+ // questions, it does not hold a conversation or plan anything.
9
15
  import { factAnswer, factReadBack } from "../../services/chat.mjs";
10
16
  import { createInMemoryStore, normFactTerm } from "../../adapters/memory/core.mjs";
11
17
  import { digestTermFromPayloadBrowser } from "./digest-client.mjs";
18
+ import { publishTmctSurface } from "./tmct-surface.mjs";
19
+
20
+ /** A question-only session over a payload the page already embeds — no fs I/O,
21
+ * no turn engine. Returns `{ memoryDir }`. */
22
+ export function createMemoryAskSession({ payload = null } = {}) {
23
+ const memoryDir = createInMemoryStore();
24
+ if (payload) memoryDir.payload = payload;
25
+ return { memoryDir };
26
+ }
27
+
28
+ /**
29
+ * One question, answered from the page's own embedded store. Runs the same
30
+ * cascade `runAsk` runs — factAnswer first, then factReadBack, which is where
31
+ * the taught-relation chases live ("who is the grandfather of ishmael") that
32
+ * factAnswer's own lanes don't reach.
33
+ *
34
+ * Both are called with `envelope: null, miss: true`, which arms factAnswer's
35
+ * bare-question fallbacks directly and skips the structural-graph parse
36
+ * pipeline this dock has no use for.
37
+ *
38
+ * Returns `{ answer, data, miss }`. `data` is the reader's own result, so a
39
+ * caller still sees the inferred `goal` line it computed on the way.
40
+ */
41
+ export async function askMemory(request, options, session) {
42
+ let fact = null;
43
+ try { fact = await factAnswer(session.memoryDir, request, null, true, {}); } catch { fact = null; }
44
+ if (!(fact && fact.text)) {
45
+ try { fact = await factReadBack(session.memoryDir, request, null, true, null); } catch { fact = null; }
46
+ }
47
+ if (!(fact && fact.text)) return { answer: null, data: null, miss: true };
48
+ return { answer: fact.text, data: fact, miss: false };
49
+ }
12
50
 
13
- // normFactTerm is re-exported too, for the page's client-side term normalization.
14
- // factReadBack carries the taught-relation chases (grandfather-style questions)
15
- // that factAnswer's own lanes don't reach.
16
- // digestTermFromPayloadBrowser lets the CLI `tmct viz` page read a refocused
17
- // term back as a digest client-side, from the structure table the page embeds
18
- // the same narrative the demo ledger's live bundle produces, over the same
19
- // static store this page already carries.
20
- globalThis.tmctMemoryAsk = { factAnswer, factReadBack, createInMemoryStore, normFactTerm, digestTermFromPayloadBrowser };
51
+ // `tmct.page` keeps the term normalizer the dock refocuses the ledger with,
52
+ // and the client-side digest reader — the narrative the demo ledger's live
53
+ // bundle produces, over the static structure table this page embeds.
54
+ // `fallback`, because the demo ledger page carries this bundle AND the full
55
+ // turn engine at once: this one answers where it is alone, and steps aside
56
+ // wherever the live dock is loaded, whichever order the two arrive in.
57
+ publishTmctSurface({
58
+ open: createMemoryAskSession,
59
+ ask: askMemory,
60
+ page: { normFactTerm, digestTermFromPayloadBrowser },
61
+ fallback: true,
62
+ });