@polycode-projects/the-mechanical-code-talker 4.0.0 → 4.1.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.
Files changed (108) hide show
  1. package/README.md +178 -9
  2. package/corpus/reference/index.json.gz +0 -0
  3. package/corpus/reference/manifest.json +8 -8
  4. package/corpus/reference/shards/ref-00.jsonl.gz +0 -0
  5. package/corpus/sprites/src/sprite-facts.jsonl +401 -0
  6. package/corpus/worlds/index.json.gz +0 -0
  7. package/corpus/worlds/manifest.json +49 -9
  8. package/corpus/worlds/shards/greyvale-museum.jsonl.gz +0 -0
  9. package/corpus/worlds/shards/lantern-cottage.jsonl.gz +0 -0
  10. package/corpus/worlds/shards/mud-hollow.jsonl.gz +0 -0
  11. package/corpus/worlds/shards/mud-warren.jsonl.gz +0 -0
  12. package/corpus/worlds/shards/spider-fly.jsonl.gz +0 -0
  13. package/corpus/worlds/src/greyvale-museum.jsonl +136 -0
  14. package/corpus/worlds/src/lantern-cottage.jsonl +60 -0
  15. package/corpus/worlds/src/mud-hollow.jsonl +82 -0
  16. package/corpus/worlds/src/mud-warren.jsonl +124 -0
  17. package/corpus/worlds/src/spider-fly.jsonl +1 -1
  18. package/data/sprites/animal-icon.toml +11 -5
  19. package/data/sprites/book-icon.toml +9 -5
  20. package/data/sprites/cabinet-icon.toml +10 -5
  21. package/data/sprites/cellar-icon.toml +16 -6
  22. package/data/sprites/container-icon.toml +7 -3
  23. package/data/sprites/desk-icon.toml +8 -5
  24. package/data/sprites/dog-icon.toml +8 -5
  25. package/data/sprites/dog-with-colour-icon.toml +13 -12
  26. package/data/sprites/drawing-room-icon.toml +14 -5
  27. package/data/sprites/egg-icon.toml +6 -3
  28. package/data/sprites/fly-icon.toml +10 -5
  29. package/data/sprites/furniture-icon.toml +5 -3
  30. package/data/sprites/garden-icon.toml +10 -3
  31. package/data/sprites/key-icon.toml +3 -1
  32. package/data/sprites/kitchen-icon.toml +15 -6
  33. package/data/sprites/lamp-icon.toml +9 -4
  34. package/data/sprites/letter-icon.toml +7 -4
  35. package/data/sprites/library-icon.toml +14 -3
  36. package/data/sprites/pan-icon.toml +7 -3
  37. package/data/sprites/person-icon.toml +6 -2
  38. package/data/sprites/poodle-icon.toml +1 -1
  39. package/data/sprites/portable-icon.toml +6 -4
  40. package/data/sprites/portrait-icon.toml +7 -4
  41. package/data/sprites/room-icon.toml +11 -2
  42. package/data/sprites/spider-icon.toml +9 -3
  43. package/data/sprites/study-icon.toml +10 -2
  44. package/package.json +5 -4
  45. package/src/adapters/memory/core.mjs +20 -0
  46. package/src/domain/ask-vocab.mjs +71 -0
  47. package/src/domain/ask.mjs +168 -0
  48. package/src/domain/game-config.mjs +11 -0
  49. package/src/domain/grammar/ace.mjs +40 -4
  50. package/src/domain/grammar/lexicon-core.json +2 -1
  51. package/src/domain/grammar/lexicon.mjs +18 -0
  52. package/src/domain/mud-facts.mjs +15 -0
  53. package/src/domain/reference-pack.mjs +31 -7
  54. package/src/domain/router/drive.mjs +35 -9
  55. package/src/domain/router/registry.mjs +24 -4
  56. package/src/domain/router/resolver.mjs +102 -40
  57. package/src/domain/scene-compose.mjs +117 -0
  58. package/src/domain/spider-fly-world.mjs +37 -1
  59. package/src/domain/sprite-facts.mjs +0 -0
  60. package/src/domain/sprite-request.mjs +156 -0
  61. package/src/domain/sprite-templates.mjs +169 -20
  62. package/src/services/adventure-editor.mjs +8 -14
  63. package/src/services/adventure-viz.mjs +209 -157
  64. package/src/services/adventure.mjs +526 -391
  65. package/src/services/chat-page-viz.mjs +69 -25
  66. package/src/services/chat.mjs +200 -51
  67. package/src/services/code-explorer-viz.mjs +102 -62
  68. package/src/services/extract-facts.mjs +4 -7
  69. package/src/services/ingest-viz.mjs +68 -82
  70. package/src/services/ledger-viz.mjs +136 -67
  71. package/src/services/memory-panel-viz.mjs +62 -0
  72. package/src/services/mud-editor.mjs +10 -15
  73. package/src/services/mud-turn.mjs +6 -6
  74. package/src/services/mud-viz.mjs +1016 -208
  75. package/src/services/p2p-room.mjs +90 -23
  76. package/src/services/plan-pddl.mjs +3 -1
  77. package/src/services/plan-viz.mjs +123 -64
  78. package/src/services/research-viz.mjs +160 -108
  79. package/src/services/spider-fly-turn.mjs +15 -23
  80. package/src/services/spider-fly-viz.mjs +146 -161
  81. package/src/services/spider-fly.mjs +69 -11
  82. package/src/services/sprite-catalog-viz.mjs +414 -240
  83. package/src/services/viz-boot.mjs +71 -0
  84. package/src/services/viz-room-graph.mjs +203 -0
  85. package/src/services/viz-theme.mjs +90 -1
  86. package/src/services/viz-ticker.mjs +22 -0
  87. package/src/surfaces/web/adventure-browser-entry.mjs +49 -33
  88. package/src/surfaces/web/chat-browser-entry.mjs +30 -105
  89. package/src/surfaces/web/code-explorer-browser-entry.mjs +168 -24
  90. package/src/surfaces/web/ingest-browser-entry.mjs +3 -13
  91. package/src/surfaces/web/ledger-browser-entry.mjs +7 -47
  92. package/src/surfaces/web/memory-ask-browser.bundle.js +127 -124
  93. package/src/surfaces/web/memory-stats.mjs +11 -0
  94. package/src/surfaces/web/mud-browser-entry.mjs +71 -29
  95. package/src/surfaces/web/plan-browser-entry.mjs +22 -40
  96. package/src/surfaces/web/research-browser-entry.mjs +26 -41
  97. package/src/surfaces/web/spider-fly-browser-entry.mjs +45 -28
  98. package/src/surfaces/web/sprites-browser-entry.mjs +14 -27
  99. package/src/surfaces/web/turn-session.mjs +120 -0
  100. package/src/tools/definitions.mjs +30 -0
  101. package/src/tools/handlers/index.mjs +6 -3
  102. package/src/tools/handlers/kit.mjs +19 -2
  103. package/src/tools/handlers/tmct-ask.mjs +11 -6
  104. package/src/tools/handlers/tmct-ingest.mjs +5 -1
  105. package/src/tools/handlers/tmct-related.mjs +4 -4
  106. package/src/tools/handlers/tmct-sprite.mjs +147 -0
  107. package/src/tools/memory-fallthrough.mjs +9 -2
  108. package/src/tools/server.mjs +25 -1
@@ -17,6 +17,7 @@
17
17
 
18
18
  import {
19
19
  DIRECTION_DELTA, WORLD_NAME, cellId, parseCellId, inBounds, chebyshevDistance, oneStepDirectionBetween,
20
+ agentKindOf, liveIdsOfKind,
20
21
  } from "../domain/spider-fly-world.mjs";
21
22
  import { foldSpiderFlyState, runSpiderFlyTick, startSpiderFlyGame, beliefSnapshotFor } from "./spider-fly.mjs";
22
23
  import { worldProvenanceTag } from "../domain/worlds-pack.mjs";
@@ -73,7 +74,7 @@ const SPIDER_FLY_TOLD_RE = new RegExp(
73
74
  const SPIDER_FLY_SEE_RE = /^what (?:does|can) the (spider|fly)(?:-(\d+))?\s+see[.!?\s]*$/i;
74
75
 
75
76
  const WORLD_OPENING_FALLBACK =
76
- "a spider waits in its web; a fly drifts in from the edge of the board. Neither is yours to move — watch, or address one by name in chat.";
77
+ "a spider waits in its web; a fly drifts in from the edge of the board. Neither is yours to move. Watch, or address one by name in chat.";
77
78
 
78
79
  // ---- the opening turn: load the shipped board through the worlds pack -------
79
80
 
@@ -121,11 +122,6 @@ async function openSpiderFlyGame({ planHolder, memoryDir, env, cache, gameConfig
121
122
 
122
123
  // ---- resolving an addressed agent / belief target ----------------------------
123
124
 
124
- const liveIdsOfKind = (kind, state) => {
125
- const re = new RegExp(`^${kind}-\\d+$`);
126
- return [...state.placements.keys()].filter((id) => re.test(id) && !state.removed.has(id)).sort();
127
- };
128
-
129
125
  /** An exact "kind-num" reference, or (no number given) the first live
130
126
  * individual of that kind — null when nothing live matches. */
131
127
  function resolveAgentId(kind, num, state) {
@@ -133,7 +129,7 @@ function resolveAgentId(kind, num, state) {
133
129
  const id = `${kind}-${num}`;
134
130
  return state.placements.has(id) && !state.removed.has(id) ? id : null;
135
131
  }
136
- const live = liveIdsOfKind(kind, state);
132
+ const live = liveIdsOfKind(state.placements, kind, state.removed);
137
133
  return live[0] ?? null;
138
134
  }
139
135
 
@@ -143,7 +139,7 @@ function resolveAgentId(kind, num, state) {
143
139
  * than one spider or fly. */
144
140
  function resolveNearestAgentId(kind, num, state, nearCell) {
145
141
  if (num) return resolveAgentId(kind, num, state);
146
- const live = liveIdsOfKind(kind, state);
142
+ const live = liveIdsOfKind(state.placements, kind, state.removed);
147
143
  if (!live.length || !nearCell) return live[0] ?? null;
148
144
  let best = live[0];
149
145
  let bestDist = Infinity;
@@ -193,11 +189,6 @@ export { oneStepDirectionBetween };
193
189
  // claim, true or false alike. A pill's `truth` tag is for the human eye
194
190
  // only — it never rides along in the submitted text itself.
195
191
 
196
- const liveIdsOfKindFromAgents = (kind, agents) => {
197
- const re = new RegExp(`^${kind}-\\d+$`);
198
- return Object.keys(agents || {}).filter((id) => re.test(id)).sort();
199
- };
200
-
201
192
  /** "spider"/"fly" bare when exactly one individual of that kind is live
202
193
  * (nothing to disambiguate), else the individual's own numbered id — a
203
194
  * pill-set legibility choice, not a grammar restriction (the addressed
@@ -246,8 +237,8 @@ function reflectedCell(cell) {
246
237
  */
247
238
  export function pillsForSpiderFly(agents, explicitAddresseeId, opts = {}) {
248
239
  const { defaultKind = "spider" } = opts;
249
- const liveSpiders = liveIdsOfKindFromAgents("spider", agents);
250
- const liveFlies = liveIdsOfKindFromAgents("fly", agents);
240
+ const liveSpiders = liveIdsOfKind(agents, "spider");
241
+ const liveFlies = liveIdsOfKind(agents, "fly");
251
242
 
252
243
  const addressPills = [
253
244
  ...liveSpiders.map((id) => ({ id, kind: "spider", label: `@${agentPillLabel("spider", id, liveSpiders)}` })),
@@ -258,7 +249,7 @@ export function pillsForSpiderFly(agents, explicitAddresseeId, opts = {}) {
258
249
  const addresseeId = (explicitAddresseeId && agents[explicitAddresseeId]) ? explicitAddresseeId : fallbackAddresseeId;
259
250
  if (!addresseeId) return { addressPills, claimPills: [], addresseeId: null };
260
251
 
261
- const addresseeKind = /^spider-\d+$/.test(addresseeId) ? "spider" : "fly";
252
+ const addresseeKind = agentKindOf(addresseeId);
262
253
  const addresseeLabel = agentPillLabel(addresseeKind, addresseeId, addresseeKind === "spider" ? liveSpiders : liveFlies);
263
254
  const addresseeCell = parseCellId(agents[addresseeId].cell);
264
255
 
@@ -352,10 +343,11 @@ async function runTickAndRender({ planHolder, memoryDir, cache, toldFacts = [],
352
343
 
353
344
  /** One `[id, cellId | null]` belief entry as a sentence: `"spider-1 is at
354
345
  * cell-3-4."` when observed/told, `"fly-2 has not been observed."`
355
- * otherwise — the same wording spider-fly-viz.mjs's own click-expand panel
356
- * (observedFactsHtml) renders, so the chat phrasing and the browser panel
357
- * never disagree about what an agent can see. */
358
- function observedFactSentence(id, believedCell) {
346
+ * otherwise — exported so spider-fly-viz.mjs's own click-expand panel
347
+ * (observedFactsHtml) renders from the SAME function instead of a
348
+ * hand-typed copy, so the chat phrasing and the browser panel can never
349
+ * drift apart. Pure, self-contained, `.toString()`-splice safe. */
350
+ export function believedFactSentence(id, believedCell) {
359
351
  return believedCell ? `${id} is at ${believedCell}.` : `${id} has not been observed.`;
360
352
  }
361
353
 
@@ -374,14 +366,14 @@ async function spiderFlyBeliefAnswer(match, { memoryDir, gameConfig = DEFAULT_GA
374
366
  const observerId = resolveAgentId(kind, num, state);
375
367
  if (!observerId) return noSuchAgentAnswer(kind, "addressee");
376
368
  const observerCell = parseCellId(state.placements.get(observerId).cell);
377
- const candidateIds = [...liveIdsOfKind("spider", state), ...liveIdsOfKind("fly", state)];
369
+ const candidateIds = [...liveIdsOfKind(state.placements, "spider", state.removed), ...liveIdsOfKind(state.placements, "fly", state.removed)];
378
370
  const visionRadius = kind === "spider"
379
371
  ? gameConfig?.spiderFly?.spiderVisionRadius
380
372
  : gameConfig?.spiderFly?.flyVisionRadius;
381
373
  const belief = beliefSnapshotFor(observerId, observerCell, candidateIds, state, { visionRadius });
382
374
  const entries = Object.entries(belief);
383
375
  const text = entries.length
384
- ? `${observerId} sees: ${entries.map(([id, cell]) => observedFactSentence(id, cell)).join(" ")}`
376
+ ? `${observerId} sees: ${entries.map(([id, cell]) => believedFactSentence(id, cell)).join(" ")}`
385
377
  : `${observerId} is alone on the board — nothing else to see.`;
386
378
  return {
387
379
  text,
@@ -446,7 +438,7 @@ const SF_GOAL_RE = /^(?:what(?:'s|\s+is)\s+(?:the\s+|my\s+)?(?:goal|objective|po
446
438
  const WATCHER_STANCE = 'you have no piece here — both agents move on their own. Watch, say "tick" to advance, or address one, e.g. "@spider the fly is east".';
447
439
 
448
440
  const positionsOfKind = (kind, state) =>
449
- liveIdsOfKind(kind, state).map((id) => `${id} at ${state.placements.get(id).cell}`);
441
+ liveIdsOfKind(state.placements, kind, state.removed).map((id) => `${id} at ${state.placements.get(id).cell}`);
450
442
 
451
443
  async function spiderFlyContextAnswer(line, { memoryDir }) {
452
444
  const l = String(line).trim();