@polycode-projects/the-mechanical-code-talker 2.5.0 → 2.5.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 (94) hide show
  1. package/README.md +15 -11
  2. package/bin/tmct.mjs +8 -5
  3. package/corpus/LICENSES.json +7 -0
  4. package/corpus/README.md +3 -3
  5. package/corpus/reference/LICENSE-NOTICE +36 -0
  6. package/corpus/reference/README.md +19 -0
  7. package/corpus/reference/index.json.gz +0 -0
  8. package/corpus/reference/manifest.json +367 -0
  9. package/corpus/reference/shards/ref-00.jsonl.gz +0 -0
  10. package/corpus/reference/shards/ref-01.jsonl.gz +0 -0
  11. package/corpus/reference/shards/ref-02.jsonl.gz +0 -0
  12. package/corpus/reference/shards/ref-03.jsonl.gz +0 -0
  13. package/corpus/reference/shards/ref-04.jsonl.gz +0 -0
  14. package/corpus/reference/shards/ref-05.jsonl.gz +0 -0
  15. package/corpus/reference/shards/ref-06.jsonl.gz +0 -0
  16. package/corpus/reference/shards/ref-07.jsonl.gz +0 -0
  17. package/corpus/reference/shards/ref-08.jsonl.gz +0 -0
  18. package/corpus/reference/shards/ref-09.jsonl.gz +0 -0
  19. package/corpus/reference/shards/ref-0a.jsonl.gz +0 -0
  20. package/corpus/reference/shards/ref-0b.jsonl.gz +0 -0
  21. package/corpus/reference/shards/ref-0c.jsonl.gz +0 -0
  22. package/corpus/reference/shards/ref-0d.jsonl.gz +0 -0
  23. package/corpus/reference/shards/ref-0e.jsonl.gz +0 -0
  24. package/corpus/reference/shards/ref-0f.jsonl.gz +0 -0
  25. package/corpus/reference/shards/ref-10.jsonl.gz +0 -0
  26. package/corpus/reference/shards/ref-11.jsonl.gz +0 -0
  27. package/corpus/reference/shards/ref-12.jsonl.gz +0 -0
  28. package/corpus/reference/shards/ref-13.jsonl.gz +0 -0
  29. package/corpus/reference/shards/ref-14.jsonl.gz +0 -0
  30. package/corpus/reference/shards/ref-15.jsonl.gz +0 -0
  31. package/corpus/reference/shards/ref-16.jsonl.gz +0 -0
  32. package/corpus/reference/shards/ref-17.jsonl.gz +0 -0
  33. package/corpus/reference/shards/ref-18.jsonl.gz +0 -0
  34. package/corpus/reference/shards/ref-19.jsonl.gz +0 -0
  35. package/corpus/reference/shards/ref-1a.jsonl.gz +0 -0
  36. package/corpus/reference/shards/ref-1b.jsonl.gz +0 -0
  37. package/corpus/reference/shards/ref-1c.jsonl.gz +0 -0
  38. package/corpus/reference/shards/ref-1d.jsonl.gz +0 -0
  39. package/corpus/reference/shards/ref-1e.jsonl.gz +0 -0
  40. package/corpus/reference/shards/ref-1f.jsonl.gz +0 -0
  41. package/corpus/reference/shards/ref-20.jsonl.gz +0 -0
  42. package/corpus/reference/shards/ref-21.jsonl.gz +0 -0
  43. package/corpus/reference/shards/ref-22.jsonl.gz +0 -0
  44. package/corpus/reference/shards/ref-23.jsonl.gz +0 -0
  45. package/corpus/reference/shards/ref-24.jsonl.gz +0 -0
  46. package/corpus/reference/shards/ref-25.jsonl.gz +0 -0
  47. package/corpus/reference/shards/ref-26.jsonl.gz +0 -0
  48. package/corpus/reference/shards/ref-27.jsonl.gz +0 -0
  49. package/corpus/reference/shards/ref-28.jsonl.gz +0 -0
  50. package/corpus/reference/shards/ref-29.jsonl.gz +0 -0
  51. package/corpus/reference/shards/ref-2a.jsonl.gz +0 -0
  52. package/corpus/reference/shards/ref-2b.jsonl.gz +0 -0
  53. package/corpus/reference/shards/ref-2c.jsonl.gz +0 -0
  54. package/corpus/reference/shards/ref-2d.jsonl.gz +0 -0
  55. package/corpus/reference/shards/ref-2e.jsonl.gz +0 -0
  56. package/corpus/reference/shards/ref-2f.jsonl.gz +0 -0
  57. package/corpus/reference/shards/ref-30.jsonl.gz +0 -0
  58. package/corpus/reference/shards/ref-31.jsonl.gz +0 -0
  59. package/corpus/reference/shards/ref-32.jsonl.gz +0 -0
  60. package/corpus/reference/shards/ref-33.jsonl.gz +0 -0
  61. package/corpus/reference/shards/ref-34.jsonl.gz +0 -0
  62. package/corpus/reference/shards/ref-35.jsonl.gz +0 -0
  63. package/corpus/reference/shards/ref-36.jsonl.gz +0 -0
  64. package/corpus/reference/shards/ref-37.jsonl.gz +0 -0
  65. package/corpus/reference/shards/ref-38.jsonl.gz +0 -0
  66. package/corpus/reference/shards/ref-39.jsonl.gz +0 -0
  67. package/corpus/reference/shards/ref-3a.jsonl.gz +0 -0
  68. package/corpus/reference/shards/ref-3b.jsonl.gz +0 -0
  69. package/corpus/reference/shards/ref-3c.jsonl.gz +0 -0
  70. package/corpus/reference/shards/ref-3d.jsonl.gz +0 -0
  71. package/corpus/reference/shards/ref-3e.jsonl.gz +0 -0
  72. package/corpus/reference/shards/ref-3f.jsonl.gz +0 -0
  73. package/package.json +8 -4
  74. package/src/adapters/corpus/reference-pack.mjs +107 -0
  75. package/src/adapters/memory/core.mjs +104 -10
  76. package/src/domain/ask.mjs +66 -9
  77. package/src/domain/cli-verbs.mjs +3 -3
  78. package/src/domain/codegraph.mjs +6 -0
  79. package/src/domain/dialogue-acts.mjs +155 -0
  80. package/src/domain/grammar/lexicon-core.json +1 -1
  81. package/src/domain/interpret/normalize.mjs +14 -2
  82. package/src/domain/interpret/strategies/keywords.mjs +10 -1
  83. package/src/domain/memory/trust.mjs +12 -0
  84. package/src/domain/reference-pack.mjs +72 -0
  85. package/src/domain/skos-view.mjs +111 -0
  86. package/src/domain/syllogise.mjs +647 -56
  87. package/src/services/chat.mjs +499 -123
  88. package/src/services/init.mjs +2 -2
  89. package/src/surfaces/web/chat-browser-entry.mjs +87 -0
  90. package/src/surfaces/web/memory-ask-browser.bundle.js +865 -74
  91. package/src/tools/definitions.mjs +13 -0
  92. package/src/tools/handlers/index.mjs +2 -0
  93. package/src/tools/handlers/tmct-related.mjs +30 -0
  94. package/ROADMAP.md +0 -130
@@ -85,7 +85,7 @@ export function renderTomlConfig(config = defaultConfig()) {
85
85
  const base = `# tmct.toml — the mechanical code talker, project configuration.
86
86
  # Written by \`tmct init\`. An ABSENT file means shipped defaults (this file
87
87
  # just makes them explicit and editable). Documented in the repository-interface
88
- # onboarding surface (ROADMAP Phase 8, "Distribution: tmct init").
88
+ # onboarding surface.
89
89
 
90
90
  # Where the code-graph JSON artifact lives, relative to this file. The
91
91
  # TMCT_GRAPH_FILE environment variable overrides it at runtime.
@@ -99,7 +99,7 @@ ${Array.isArray(c.graphFiles) && c.graphFiles.length ? `
99
99
  graph_files = ${JSON.stringify(c.graphFiles)}
100
100
  ` : ""}
101
101
  [corpus]
102
- # Corpus-tiering policy (ROADMAP Phase 4). The $0-offline default is inviolable;
102
+ # Corpus-tiering policy. The $0-offline default is inviolable;
103
103
  # higher tiers are ADDITIVE and never required to answer.
104
104
  # "tier1" — committed slice only. Offline, $0. The default.
105
105
  # "tier2" — also fetch growable corpora at seed time (network, once, cached).
@@ -0,0 +1,87 @@
1
+ // chat-browser-entry.mjs — the esbuild entry for the home page's embedded
2
+ // chat (public/chat-ui.mjs, built by scripts/build-chat-bundle.mjs).
3
+ //
4
+ // Unlike memory-ask-browser-entry.mjs (factAnswer/factReadBack only), this
5
+ // exposes the FULL turn engine: createChatSession wraps chat.mjs's runTurn
6
+ // with a session-shaped closure — the focus/last/planState threading
7
+ // src/services/chat-session.mjs's createSession.turn does, minus every
8
+ // filesystem side effect (no transcript log, no sidecar, no graph upsert).
9
+ // Memory is an in-memory Backend-B handle, optionally pre-loaded with a
10
+ // built seed payload (scripts/build-chat-seed.mjs), so teach turns, recall,
11
+ // proof chains and the honest miss all run client-side with zero I/O.
12
+ //
13
+ // Two browser traps this file owns so no caller can fall into them:
14
+ // - runTurn defaults `env` to process.env, and a browser has no `process`
15
+ // global — every turn here passes `env: {}` explicitly;
16
+ // - the uuid adapter needs node:crypto — the session id comes from the
17
+ // Web Crypto API instead, with a Date.now fallback for contexts
18
+ // without it.
19
+ import { runTurn, vocabExampleHint } from "../../services/chat.mjs";
20
+ import { createInMemoryStore, normFactTerm } from "../../adapters/memory/core.mjs";
21
+ import { parseEntities } from "../../domain/codegraph.mjs";
22
+ import { loadLexicon } from "../../domain/grammar/lexicon.mjs";
23
+ import { registerWinkModel } from "../../adapters/wink-model.mjs";
24
+ // The reference-pack provider seam: the page registers a fetch-backed
25
+ // provider over public/reference-pack/ so the engine's pack lookups work
26
+ // where the gzipped fs layout cannot (the module's own fs loader degrades to
27
+ // null in the browser — build-chat-bundle stubs node:zlib as a thrower its
28
+ // try/catch absorbs).
29
+ import { registerReferencePackProvider } from "../../adapters/corpus/reference-pack.mjs";
30
+
31
+ /**
32
+ * A browser chat session over the real turn engine.
33
+ *
34
+ * `seedPayload` (optional) is a serialized memory graph (loadMemory's shape,
35
+ * built by scripts/build-chat-seed.mjs) assigned onto a fresh Backend-B
36
+ * handle. `vocabSeeded` tells the session's vocabulary hint whether that
37
+ * payload carries the starter vocabulary, so an unseeded session offers the
38
+ * teach pointer instead of an example it cannot answer.
39
+ *
40
+ * Returns { memoryDir, sessionId, turn }. `turn(line)` resolves to
41
+ * { answer, end, record, plan } and threads focus/last/planState between
42
+ * calls exactly as the CLI session does.
43
+ */
44
+ export function createChatSession({ seedPayload = null, vocabSeeded = false } = {}) {
45
+ const memoryDir = createInMemoryStore();
46
+ // Spread onto the store's own empty payload so a partial seed (individuals
47
+ // and objectProperties only) still carries the classes/prefixes scaffolding
48
+ // the write path recounts — teach turns must work on any seed.
49
+ if (seedPayload) memoryDir.payload = { ...memoryDir.payload, ...seedPayload };
50
+
51
+ // A known-empty code graph: code-structure questions get the same honest
52
+ // no-code-graph answer an un-pointed CLI session gives, never a crash.
53
+ const graph = parseEntities({ individuals: [], objectProperties: [] });
54
+ const lexicon = loadLexicon();
55
+ const vocabHint = vocabExampleHint(vocabSeeded);
56
+ const sessionId = globalThis.crypto?.randomUUID?.() ?? String(Date.now());
57
+
58
+ let focus = null;
59
+ let last = null;
60
+ let planState = null;
61
+
62
+ return {
63
+ memoryDir,
64
+ sessionId,
65
+
66
+ /** One dispatched turn. A throwing runTurn must never kill the session —
67
+ * the page has no other chance to show this turn's answer. */
68
+ async turn(line) {
69
+ let result;
70
+ try {
71
+ result = await runTurn(line, {
72
+ config: null, source: null, graph, focus, last, memoryDir, sessionId,
73
+ env: {}, lexicon, vocabHint, planState,
74
+ });
75
+ } catch (e) {
76
+ const message = e instanceof Error ? e.message : String(e);
77
+ return { answer: `Something went wrong answering that (${message}). Try rephrasing, or /help.`, end: false, record: null, plan: null };
78
+ }
79
+ focus = result.focus;
80
+ last = result.last;
81
+ if ("planState" in result) planState = result.planState;
82
+ return { answer: result.answer, end: Boolean(result.end), record: result.record ?? null, plan: result.plan ?? null };
83
+ },
84
+ };
85
+ }
86
+
87
+ globalThis.tmctChat = { createChatSession, registerWinkModel, registerReferencePackProvider, normFactTerm, vocabExampleHint };