@polycode-projects/the-mechanical-code-talker 5.0.28 → 5.0.30

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.
@@ -23,7 +23,7 @@ import {
23
23
  parseAgentEditorText, planAgentEditorSync, renderAgentEditorText, renderAgentClassText,
24
24
  } from "../../services/agent-editor.mjs";
25
25
  import { agentTraitsOf } from "../../domain/agent-traits.mjs";
26
- import { pillsForMudiii } from "../../services/mudiii-turn.mjs";
26
+ import { pillsForMudiii, agentOutlook } from "../../services/mudiii-turn.mjs";
27
27
  import { relatedForTerm } from "../../domain/skos-view.mjs";
28
28
  import { classAncestorChain } from "../../domain/sprite-map.mjs";
29
29
  import { createTurnSession } from "./turn-session.mjs";
@@ -151,7 +151,8 @@ export function routeBetweenCells(factRows, fromCell, toCell) {
151
151
  * (`runTownSquareTick`) and its conversation is a single shared dock.
152
152
  *
153
153
  * Returns `{ memoryDir, codeGraph, graph, refreshGraph, turn, tick, board,
154
- * snapshot, applyEdit, placeFood, driveAgent, recast }`.
154
+ * snapshot, outlook, applyEdit, applyAgentEdit, placeFood, driveAgent,
155
+ * recast }`.
155
156
  *
156
157
  * `getTeachEnabled` is read fresh on every turn, so a visitor can tick the
157
158
  * page's teach box mid-session and have the very next line read as a fact to
@@ -281,6 +282,15 @@ export async function createMudiiiSession(
281
282
  return { rows, state: foldTownSquareState(rows) };
282
283
  }
283
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
+
284
294
  /** The world editor's own store sync, reusing mud-editor.mjs UNCHANGED —
285
295
  * it already round-trips `mgx:model`/`mgx:rotation` (a concurrent track
286
296
  * added those), so nothing here is town-square-specific beyond the
@@ -343,6 +353,7 @@ export async function createMudiiiSession(
343
353
  recast,
344
354
  board,
345
355
  snapshot,
356
+ outlook,
346
357
  applyEdit,
347
358
  applyAgentEdit,
348
359
  placeFood,
@@ -136,7 +136,26 @@ export function createNewsSession({
136
136
  const memoryDir = createInMemoryStore();
137
137
  applySeedPayload(memoryDir, seedPayload);
138
138
 
139
- const store = { loadMemory, readFactRows, appendFacts, removeFacts };
139
+ // Folding the seeded store is seconds of main-thread work in a browser,
140
+ // and every session verb reads rows — uncached, a 30-item feed render
141
+ // folds the whole store once per item and freezes the page for minutes.
142
+ // One fold per write epoch keeps every read on the same rows.
143
+ let foldedRows = null;
144
+ const store = {
145
+ loadMemory,
146
+ readFactRows(memory) {
147
+ if (!foldedRows) foldedRows = readFactRows(memory);
148
+ return foldedRows;
149
+ },
150
+ async appendFacts(...args) {
151
+ foldedRows = null;
152
+ return appendFacts(...args);
153
+ },
154
+ async removeFacts(...args) {
155
+ foldedRows = null;
156
+ return removeFacts(...args);
157
+ },
158
+ };
140
159
  const cache = { rows: null };
141
160
  let lexicon = loadLexicon();
142
161
  let config = resolveNewsConfig();
@@ -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