@polycode-projects/the-mechanical-code-talker 5.0.27 → 5.0.29

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/corpus/worlds/index.json.gz +0 -0
  2. package/corpus/worlds/manifest.json +27 -17
  3. package/corpus/worlds/shards/river-crossing.jsonl.gz +0 -0
  4. package/corpus/worlds/shards/town-square-chapel.jsonl.gz +0 -0
  5. package/corpus/worlds/shards/town-square-market.jsonl.gz +0 -0
  6. package/corpus/worlds/shards/town-square.jsonl.gz +0 -0
  7. package/corpus/worlds/src/river-crossing.jsonl +29 -0
  8. package/corpus/worlds/src/town-square-chapel.jsonl +12 -8
  9. package/corpus/worlds/src/town-square-market.jsonl +12 -8
  10. package/corpus/worlds/src/town-square.jsonl +12 -8
  11. package/package.json +2 -2
  12. package/src/adapters/memory/inspect.mjs +37 -0
  13. package/src/domain/agent-belief.mjs +33 -11
  14. package/src/domain/agent-traits.mjs +282 -0
  15. package/src/domain/choice-question.mjs +259 -6
  16. package/src/domain/el-classify.mjs +55 -7
  17. package/src/domain/fact-phrase.mjs +7 -4
  18. package/src/domain/grammar/ace.mjs +66 -3
  19. package/src/domain/interpret/normalize.mjs +58 -2
  20. package/src/domain/tableau.mjs +101 -14
  21. package/src/domain/town-square-world.mjs +44 -19
  22. package/src/services/adventure.mjs +5 -16
  23. package/src/services/agent-editor.mjs +216 -0
  24. package/src/services/chat-session.mjs +26 -5
  25. package/src/services/chat.mjs +118 -58
  26. package/src/services/mudiii-scene.mjs +32 -5
  27. package/src/services/mudiii-turn.mjs +120 -5
  28. package/src/services/mudiii-viz.mjs +299 -1
  29. package/src/services/predator-prey.mjs +234 -57
  30. package/src/surfaces/web/chat-browser-entry.mjs +69 -3
  31. package/src/surfaces/web/memory-ask-browser.bundle.js +155 -155
  32. package/src/surfaces/web/mudiii-browser-entry.mjs +48 -2
  33. package/src/surfaces/web/planner-instances.mjs +64 -3
  34. package/src/surfaces/web/turn-session.mjs +13 -9
@@ -19,7 +19,11 @@ import {
19
19
  import { findActionPath } from "../../domain/planning.mjs";
20
20
  import { DEFAULT_GAME_CONFIG } from "../../domain/game-config.mjs";
21
21
  import { parseMudEditorText, planMudEditorSync, gridWorldEditorState } from "../../services/mud-editor.mjs";
22
- import { pillsForMudiii } from "../../services/mudiii-turn.mjs";
22
+ import {
23
+ parseAgentEditorText, planAgentEditorSync, renderAgentEditorText, renderAgentClassText,
24
+ } from "../../services/agent-editor.mjs";
25
+ import { agentTraitsOf } from "../../domain/agent-traits.mjs";
26
+ import { pillsForMudiii, agentOutlook } from "../../services/mudiii-turn.mjs";
23
27
  import { relatedForTerm } from "../../domain/skos-view.mjs";
24
28
  import { classAncestorChain } from "../../domain/sprite-map.mjs";
25
29
  import { createTurnSession } from "./turn-session.mjs";
@@ -147,7 +151,8 @@ export function routeBetweenCells(factRows, fromCell, toCell) {
147
151
  * (`runTownSquareTick`) and its conversation is a single shared dock.
148
152
  *
149
153
  * Returns `{ memoryDir, codeGraph, graph, refreshGraph, turn, tick, board,
150
- * snapshot, applyEdit, placeFood, driveAgent, recast }`.
154
+ * snapshot, outlook, applyEdit, applyAgentEdit, placeFood, driveAgent,
155
+ * recast }`.
151
156
  *
152
157
  * `getTeachEnabled` is read fresh on every turn, so a visitor can tick the
153
158
  * page's teach box mid-session and have the very next line read as a fact to
@@ -277,6 +282,15 @@ export async function createMudiiiSession(
277
282
  return { rows, state: foldTownSquareState(rows) };
278
283
  }
279
284
 
285
+ /** The belief and plan panels' own read path: every live agent's current
286
+ * belief map and plan, computed from the store as it stands, with no turn
287
+ * spent and no write — see agentOutlook (mudiii-turn.mjs). The page calls
288
+ * this on boot and after every edit, world or actor, so both panels
289
+ * recompute live without a tick ever running. */
290
+ async function outlook() {
291
+ return agentOutlook(memoryDir, { layout });
292
+ }
293
+
280
294
  /** The world editor's own store sync, reusing mud-editor.mjs UNCHANGED —
281
295
  * it already round-trips `mgx:model`/`mgx:rotation` (a concurrent track
282
296
  * added those), so nothing here is town-square-specific beyond the
@@ -305,6 +319,29 @@ export async function createMudiiiSession(
305
319
  return engPlaceFood(memoryDir, { layout, ...opts });
306
320
  }
307
321
 
322
+ /** The actor card's own store sync — agent-editor.mjs's closed table,
323
+ * disjoint from `applyEdit`'s world table. `subject` is whichever id the
324
+ * card is scoped to when this is called: an instance id on the "this
325
+ * goblin" tab, the class name itself on the "all goblins" tab — either
326
+ * way `planAgentEditorSync` only ever reads and writes rows whose own
327
+ * subject is that one id, so an actor edit can reach no instance, no
328
+ * class and no placement it was not asked to touch. Never calls
329
+ * `recast`: a trait is not where anything stands. */
330
+ async function applyAgentEdit(subject, text) {
331
+ const rows = readFactRows(await loadMemory(memoryDir));
332
+ const { triples, unrecognized } = parseAgentEditorText(text);
333
+ const { toAppend, toRemoveIds } = planAgentEditorSync(rows, subject, triples);
334
+ if (toAppend.length) {
335
+ await appendFacts(memoryDir, toAppend.map((f) => ({
336
+ subject: f.subject, predicate: f.predicate, object: f.object, provenance: `actor-edit:${subject}`,
337
+ })));
338
+ }
339
+ const removed = unrecognized.length === 0 && toRemoveIds.length
340
+ ? (await removeFacts(memoryDir, toRemoveIds)).removed.length
341
+ : 0;
342
+ return { unrecognized, added: toAppend.length, removed };
343
+ }
344
+
308
345
  return {
309
346
  memoryDir,
310
347
  codeGraph,
@@ -316,7 +353,9 @@ export async function createMudiiiSession(
316
353
  recast,
317
354
  board,
318
355
  snapshot,
356
+ outlook,
319
357
  applyEdit,
358
+ applyAgentEdit,
320
359
  placeFood,
321
360
  };
322
361
  }
@@ -340,5 +379,12 @@ publishTmctSurface({
340
379
  // cursor: the lateral SKOS neighbourhood and the vertical is-a chain.
341
380
  relatedForTerm, classAncestorChain,
342
381
  routeBetweenCells,
382
+ // What the page's scene boot reads to resolve each agent's stated
383
+ // display name and model off the rows, class chain included.
384
+ agentTraitsOf,
385
+ // The actor card's own render half — agent-editor.mjs leans on
386
+ // agent-traits.mjs's class-chain walk, so (like agentTraitsOf) it
387
+ // reaches the page through this bag rather than a `.toString()` splice.
388
+ renderAgentEditorText, renderAgentClassText,
343
389
  },
344
390
  });
@@ -1,4 +1,4 @@
1
- // planner-instances.mjs — the three taught puzzles claim-planner.mjs measures,
1
+ // planner-instances.mjs — the four taught puzzles claim-planner.mjs measures,
2
2
  // and the one per-instance solve function every caller (that rig, and
3
3
  // claims-browser-entry.mjs's own "run it on this device" button) drives
4
4
  // through. Lives under surfaces/web because solvePlannerInstance itself
@@ -16,7 +16,9 @@
16
16
  // data/games/hanoi-3.txt and data/games/river.txt already exercise (the
17
17
  // action-signature, clearing-precondition, and action-effect sentences), so
18
18
  // nothing here is a new grammar shape — only new vocabulary and a new
19
- // instance shape.
19
+ // instance shape. river reuses the same frames again, plus the
20
+ // action-constraint one data/games/river.txt teaches for the wolf/goat/
21
+ // cabbage pairing.
20
22
  //
21
23
  // blocksworld drops hanoi's "smaller than" comparative precondition: real
22
24
  // Blocksworld blocks are uniform, so any clear block may stack on any other
@@ -25,6 +27,14 @@
25
27
  // constraints only ever ADDS legal moves at each search step, which is why
26
28
  // both grow harder than hanoi at the same instance size — the search radius
27
29
  // shrinks. claim-planner.mjs measures how much.
30
+ //
31
+ // river scales the opposite way: growing its chain never makes the search
32
+ // slower, it makes the puzzle itself unsolvable. A chain longer than three
33
+ // has no first move that leaves every remaining neighbouring pair guarded,
34
+ // so movesFromRules returns no legal moves at all from the opening state and
35
+ // solvePlannerInstance reports a fast, correct miss rather than a slow
36
+ // search — the honest-miss constitution applied to a domain's own shape,
37
+ // not just to a search that ran out of budget.
28
38
 
29
39
  import { hanoiLessonSentences } from "../../domain/hanoi-lesson.mjs";
30
40
  import { createInMemoryStore } from "../../adapters/memory/core.mjs";
@@ -103,7 +113,57 @@ export function gripperInstanceSentences(ballCount = 3) {
103
113
  return sentences;
104
114
  }
105
115
 
106
- /** The three envelope columns claim-planner.mjs measures, and the
116
+ /** The river-crossing domain's rule scaffolding alone: one farmer and a
117
+ * chain of `passengerCount` classes, each with exactly one instance, where
118
+ * every neighbouring pair in the chain may not be left together without
119
+ * the farmer — the shipped wolf/goat/cabbage constraint
120
+ * (data/games/river.txt) generalised past its fixed three. Every class
121
+ * needs exactly one instance because the "may not be with … without"
122
+ * constraint frame (src/services/chat.mjs's ACTION_CONSTRAINT_TEACH_RE)
123
+ * binds each of its three trailing words to that class's sole member. Only
124
+ * the chain's middle link can ever be ferried first without leaving two
125
+ * neighbours together unguarded, which is why this family stops being
126
+ * solvable once the chain outgrows three: `solvePlannerInstance` still
127
+ * reports that honestly, as a fast miss rather than a shortened plan. */
128
+ export function riverRuleSentences(passengerCount = 3) {
129
+ const n = Math.max(1, Math.floor(Number(passengerCount) || 1));
130
+ const chain = Array.from({ length: n }, (_, i) => `beast-${i + 1}`);
131
+ const sentences = [];
132
+ sentences.push("a passenger is a kind of game piece.");
133
+ sentences.push("a bank is a kind of place.");
134
+ for (const cls of chain) {
135
+ sentences.push(`${cls}-1 is a ${cls}.`);
136
+ sentences.push(`${cls}-1 is a passenger.`);
137
+ }
138
+ sentences.push("farmer-1 is a farmer.");
139
+ sentences.push("bank-east is a bank.");
140
+ sentences.push("bank-west is a bank.");
141
+ sentences.push("you can ferry a passenger onto a bank.");
142
+ sentences.push("you can ferry a farmer onto a bank.");
143
+ sentences.push("ferrying a passenger onto a bank makes the passenger stand on the target.");
144
+ sentences.push("ferrying a passenger onto a bank makes the farmer stand on the target.");
145
+ for (let i = 0; i < n - 1; i += 1) {
146
+ sentences.push(`to ferry a passenger onto a bank, the ${chain[i]} may not be with the ${chain[i + 1]} without the farmer.`);
147
+ }
148
+ return sentences;
149
+ }
150
+
151
+ /** riverRuleSentences(passengerCount) plus one solvable instance: every
152
+ * chain member and the farmer start on bank-east, and the goal ferries
153
+ * every passenger to bank-west — the same opening data/games/river.txt
154
+ * teaches interactively, generalised to `passengerCount` members. */
155
+ export function riverInstanceSentences(passengerCount = 3) {
156
+ const n = Math.max(1, Math.floor(Number(passengerCount) || 1));
157
+ const chain = Array.from({ length: n }, (_, i) => `beast-${i + 1}`);
158
+ const sentences = riverRuleSentences(n);
159
+ for (const cls of chain) sentences.push(`${cls}-1 stands on bank-east.`);
160
+ sentences.push("farmer-1 stands on bank-east.");
161
+ sentences.push("the goal is that every passenger stands on bank-west.");
162
+ sentences.push("solve it.");
163
+ return sentences;
164
+ }
165
+
166
+ /** The four envelope columns claim-planner.mjs measures, and the
107
167
  * benchmark-this-device button offers a visitor. `unit` names what `size`
108
168
  * counts; `instanceSentences(size)` is the full taught sequence a fresh
109
169
  * session runs to solve one instance. */
@@ -111,6 +171,7 @@ export const PLANNER_DOMAINS = {
111
171
  hanoi: { unit: "disks", instanceSentences: hanoiLessonSentences },
112
172
  blocksworld: { unit: "blocks", instanceSentences: blocksworldInstanceSentences },
113
173
  gripper: { unit: "balls", instanceSentences: gripperInstanceSentences },
174
+ river: { unit: "passengers", instanceSentences: riverInstanceSentences },
114
175
  };
115
176
 
116
177
  /** Teach one fresh in-memory session domain's instance at `size` and solve
@@ -3,7 +3,7 @@
3
3
  // entry.mjs, ledger-browser-entry.mjs, adventure-browser-entry.mjs, spider-
4
4
  // fly-browser-entry.mjs, plan-browser-entry.mjs, research-browser-entry.mjs,
5
5
  // mud-browser-entry.mjs, sprites-browser-entry.mjs): a closure over
6
- // focus/last/planState/researchState, a `try { runTurn(...) } catch` that
6
+ // focus/last/planState/researchState/newsState, a `try { runTurn(...) } catch` that
7
7
  // turns a throw into a safe answer instead of ending the session (the page
8
8
  // has no other chance to show that turn's reply), the post-call state
9
9
  // capture, and a return shape covering every field one caller or another
@@ -19,7 +19,7 @@
19
19
  // The nine differ in what they hand `runTurn` beyond the common core
20
20
  // (`synthesisBudget`, `gameConfig`, `researchConfig`,
21
21
  // `actingSubject`, a per-character `sessionId`...) and in what they do with a
22
- // turn's result besides the standard focus/last/planState/researchState fold
22
+ // turn's result besides the standard focus/last/planState/researchState/newsState fold
23
23
  // (sync an externally-held plan holder, grow a visited-rooms set, bump a
24
24
  // per-character turn tally). `buildExtraOptions`/`captureExtraState` below
25
25
  // are exactly those two seams — everything else is common enough to live
@@ -40,7 +40,7 @@ function turnErrorFallback(message) {
40
40
  * `createTurnSession({ memoryDir, graph, lexicon, sessionId, vocabHint,
41
41
  * buildExtraOptions, captureExtraState })` — a live turn-dispatch session
42
42
  * over the real engine (`runTurn`), threading focus/last/planState/
43
- * researchState across calls the way every browser chat dock does.
43
+ * researchState/newsState across calls the way every browser chat dock does.
44
44
  *
45
45
  * `vocabHint` is the session-lifetime hint every caller computes once at
46
46
  * creation (a fixed string, or `vocabExampleHint(vocabSeeded)`'s result) —
@@ -51,19 +51,19 @@ function turnErrorFallback(message) {
51
51
  * (`synthesisBudget`, `gameConfig`, `researchConfig`,
52
52
  * a per-character `actingSubject`/`sessionId`, or a `planState` read from an
53
53
  * external holder instead of this closure's own). `state` is
54
- * `{ focus, last, planState, researchState }` as this turn is about to run;
54
+ * `{ focus, last, planState, researchState, newsState }` as this turn is about to run;
55
55
  * `callArgs` is whatever extra argument `turn(line, callArgs)` was given
56
56
  * (plan-browser-entry.mjs's own per-call `{ maxDepth }` override, for one).
57
57
  *
58
58
  * `captureExtraState(result, state, callArgs)` (optional, may be async) runs
59
59
  * once after a SUCCESSFUL turn, with `state` already folded forward
60
- * (focus/last/planState/researchState updated) — the caller's own chance to
60
+ * (focus/last/planState/researchState/newsState updated) — the caller's own chance to
61
61
  * do further bookkeeping (sync an external plan holder, reload memory to
62
62
  * grow a visited-rooms set, bump a turn tally). Never runs on a throw: none
63
63
  * of the nine originals touch their own state when `runTurn` itself failed.
64
64
  *
65
65
  * Returns `{ memoryDir, sessionId, graph, turn, focus, last, planState,
66
- * setPlanState, researchState, setResearchState }`. `graph` is the one this
66
+ * setPlanState, researchState, setResearchState, newsState, setNewsState }`. `graph` is the one this
67
67
  * session was built over, exposed so a caller can put a question to the same
68
68
  * graph its turns run against (engine-surface.mjs's `graphAsk`) without
69
69
  * holding a second reference to it. `turn(line, callArgs)`
@@ -87,15 +87,16 @@ export function createTurnSession({
87
87
  let last = null;
88
88
  let planState = null;
89
89
  let researchState = null;
90
+ let newsState = null;
90
91
 
91
92
  async function turn(line, callArgs) {
92
- const before = { focus, last, planState, researchState };
93
+ const before = { focus, last, planState, researchState, newsState };
93
94
  const extra = buildExtraOptions(before, callArgs) || {};
94
95
  let result;
95
96
  try {
96
97
  result = await runTurn(line, {
97
98
  config: null, source: null, graph, focus, last, memoryDir, sessionId,
98
- env: {}, lexicon, vocabHint, planState, researchState, uiContext: "browser",
99
+ env: {}, lexicon, vocabHint, planState, researchState, newsState, uiContext: "browser",
99
100
  ...extra,
100
101
  });
101
102
  } catch (e) {
@@ -106,7 +107,8 @@ export function createTurnSession({
106
107
  last = result.last;
107
108
  if ("planState" in result) planState = result.planState;
108
109
  if ("researchState" in result) researchState = result.researchState;
109
- await captureExtraState(result, { focus, last, planState, researchState }, callArgs);
110
+ if ("newsState" in result) newsState = result.newsState;
111
+ await captureExtraState(result, { focus, last, planState, researchState, newsState }, callArgs);
110
112
  return {
111
113
  answer: result.answer,
112
114
  end: Boolean(result.end),
@@ -126,6 +128,8 @@ export function createTurnSession({
126
128
  setPlanState(next) { planState = next; },
127
129
  get researchState() { return researchState; },
128
130
  setResearchState(next) { researchState = next; },
131
+ get newsState() { return newsState; },
132
+ setNewsState(next) { newsState = next; },
129
133
  turn,
130
134
  };
131
135
  }