@polycode-projects/the-mechanical-code-talker 5.0.32 → 5.0.34
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.
- package/package.json +2 -1
- package/src/domain/news-feed.mjs +10 -1
- package/src/services/chat.mjs +100 -15
- package/src/services/extract-facts.mjs +124 -15
- package/src/services/index.mjs +4 -2
- package/src/services/mudiii-turn.mjs +39 -7
- package/src/services/mudiii-viz.mjs +421 -24
- package/src/services/news-exports.mjs +44 -0
- package/src/services/news-viz.mjs +158 -19
- package/src/surfaces/web/memory-ask-browser.bundle.js +121 -121
- package/src/surfaces/web/mudiii-browser-entry.mjs +4 -3
- package/src/surfaces/web/news-browser-entry.mjs +24 -3
|
@@ -552,10 +552,11 @@ export function agentCardMarkup(slot) {
|
|
|
552
552
|
* puzzle }]` — a page given none is the one-square case and ships no
|
|
553
553
|
* dropdown, the same rule mud-viz.mjs's own renderMudHtml follows. `puzzle`
|
|
554
554
|
* is true for a scenario with no town-square layout of its own (the
|
|
555
|
-
* river-crossing puzzle): no roster is minted
|
|
556
|
-
*
|
|
557
|
-
* the
|
|
558
|
-
* `
|
|
555
|
+
* river-crossing puzzle): no roster is minted and no tick ever runs, so the
|
|
556
|
+
* crossing board takes the 3D stage's place and the deck's play/step/reset
|
|
557
|
+
* controls walk the plan the search found rather than driving a simulation
|
|
558
|
+
* (see this file's own pageScript, `data-hide-when-puzzle` and
|
|
559
|
+
* `data-show-when-puzzle`). `assetManifest` is
|
|
559
560
|
* data/mudiii-assets.json's own `assets` rows, embedded as page data and
|
|
560
561
|
* resolved client-side by `propPlacementsFrom` — this is the one parameter
|
|
561
562
|
* mud-viz.mjs's renderMudHtml has no equivalent of, because mud.html has no
|
|
@@ -618,10 +619,10 @@ ${PILL_COMPLETE_CSS}
|
|
|
618
619
|
<div class="deck-row">
|
|
619
620
|
<section class="deck" aria-label="simulation controls">
|
|
620
621
|
<div class="deck-controls">
|
|
621
|
-
<button type="button" class="deck-play" id="autoToggle" aria-pressed="false"
|
|
622
|
-
<button type="button" id="stepBtn"
|
|
622
|
+
<button type="button" class="deck-play" id="autoToggle" aria-pressed="false">▶ play</button>
|
|
623
|
+
<button type="button" id="stepBtn">step</button>
|
|
623
624
|
<span class="deck-hint" id="stepHint" hidden>pause to step</span>
|
|
624
|
-
<button type="button" id="resetBtn"
|
|
625
|
+
<button type="button" id="resetBtn">reset</button>
|
|
625
626
|
${scenarioList.length > 1 ? ` <select id="scenarioSelect" class="deck-select" aria-label="which town square to play">
|
|
626
627
|
${scenarioList.map((s, i) => ` <option value="${i}"${i === 0 ? " selected" : ""}>${escapeHtml(s.label || scenarioLabel(s.worldPayload?.name))}</option>`).join("\n")}
|
|
627
628
|
</select>` : ""}
|
|
@@ -629,7 +630,7 @@ ${scenarioList.map((s, i) => ` <option value="${i}"${i === 0 ? " select
|
|
|
629
630
|
<button type="button" class="deck-info-btn" id="deckInfoBtn" aria-expanded="false" aria-controls="deckInfoPopup" aria-label="about this demo">?</button>
|
|
630
631
|
<span class="mono deck-turns" id="globalTurnCount" data-hide-when-puzzle>turns: 0</span>
|
|
631
632
|
</div>
|
|
632
|
-
<p class="deck-hint mudiii-puzzle-note" id="puzzleNote" hidden>This scenario is a
|
|
633
|
+
<p class="deck-hint mudiii-puzzle-note" id="puzzleNote" data-show-when-puzzle hidden>This scenario is a puzzle the planner solves by search. Press play to watch it ferry the passengers one move at a time, pause to hold the boat where it is, and step to take a single crossing. Follow any passenger to read its own beliefs, plan and drives below.</p>
|
|
633
634
|
<div class="deck-body">
|
|
634
635
|
<div class="deck-panels">
|
|
635
636
|
<div class="deck-stack deck-stack-1">
|
|
@@ -701,13 +702,36 @@ ${openingAgents.map((a) => ` <option value="${escapeHtml(a.id)}">
|
|
|
701
702
|
</div>
|
|
702
703
|
</section>
|
|
703
704
|
</div>
|
|
704
|
-
<section class="scene-stage" id="sceneStage" aria-label="the town square, in three dimensions">
|
|
705
|
+
<section class="scene-stage" id="sceneStage" aria-label="the town square, in three dimensions" data-hide-when-puzzle>
|
|
705
706
|
<canvas id="sceneCanvas"></canvas>
|
|
706
707
|
<div class="dir-ring" id="driveRing" role="group" aria-label="walk the agent the camera follows" hidden>
|
|
707
708
|
${RING_POINTS.map((point) => ` <span class="dir-slot dir-${point}"><button type="button" class="dir-pill" data-drive="${point}" title="walk ${point}" aria-label="walk ${point}" aria-pressed="false">${escapeHtml(DIR_GLYPH[point])}</button></span>`).join("\n")}
|
|
708
709
|
</div>
|
|
709
710
|
<p class="scene-status" id="sceneStatus" role="status"></p>
|
|
710
711
|
</section>
|
|
712
|
+
<section class="river-stage" id="riverStage" aria-label="the crossing, as the plan plays it" data-show-when-puzzle hidden>
|
|
713
|
+
<div class="river-head">
|
|
714
|
+
<span class="river-title">the crossing</span>
|
|
715
|
+
<span class="mono river-progress" id="riverProgress"></span>
|
|
716
|
+
</div>
|
|
717
|
+
<div class="river-board" id="riverBoard">
|
|
718
|
+
<section class="river-bank" id="riverBankLeft" aria-label="the near bank">
|
|
719
|
+
<h3 class="river-bank-name" id="riverBankLeftName"></h3>
|
|
720
|
+
<div class="river-chips" id="riverChipsLeft"></div>
|
|
721
|
+
</section>
|
|
722
|
+
<div class="river-water">
|
|
723
|
+
<div class="river-boat" id="riverBoat" data-at="left" aria-label="the boat">
|
|
724
|
+
<span class="river-boat-label mono">boat</span>
|
|
725
|
+
<div class="river-chips" id="riverChipsBoat"></div>
|
|
726
|
+
</div>
|
|
727
|
+
</div>
|
|
728
|
+
<section class="river-bank" id="riverBankRight" aria-label="the far bank">
|
|
729
|
+
<h3 class="river-bank-name" id="riverBankRightName"></h3>
|
|
730
|
+
<div class="river-chips" id="riverChipsRight"></div>
|
|
731
|
+
</section>
|
|
732
|
+
</div>
|
|
733
|
+
<p class="river-move mono" id="riverMoveText" role="status"></p>
|
|
734
|
+
</section>
|
|
711
735
|
<div class="edit-stage" id="mudiiiEditStage" aria-label="the square's own facts, in plain sentences">
|
|
712
736
|
<section class="edit-text" aria-label="the world's facts as editable sentences">
|
|
713
737
|
<h2>the square, in plain sentences</h2>
|
|
@@ -761,6 +785,23 @@ ${RING_POINTS.map((point) => ` <span class="dir-slot dir-${point}"><button
|
|
|
761
785
|
</form>
|
|
762
786
|
</div>
|
|
763
787
|
</section>
|
|
788
|
+
<section class="focus-panel" id="mudiiiFocusPanel" aria-label="what the followed agent believes, plans and is driven by">
|
|
789
|
+
<h2>following <span class="mono" id="focusWho"></span></h2>
|
|
790
|
+
<div class="focus-cols">
|
|
791
|
+
<section class="focus-col">
|
|
792
|
+
<h3>beliefs</h3>
|
|
793
|
+
<div class="focus-body" id="focusBeliefs"></div>
|
|
794
|
+
</section>
|
|
795
|
+
<section class="focus-col">
|
|
796
|
+
<h3>plan</h3>
|
|
797
|
+
<pre class="focus-body mono" id="focusPlanText"></pre>
|
|
798
|
+
</section>
|
|
799
|
+
<section class="focus-col">
|
|
800
|
+
<h3>imperatives</h3>
|
|
801
|
+
<pre class="focus-body mono" id="focusImperatives"></pre>
|
|
802
|
+
</section>
|
|
803
|
+
</div>
|
|
804
|
+
</section>
|
|
764
805
|
<div class="hud-row" id="hudRow" aria-label="every agent's own status" data-hide-when-puzzle></div>
|
|
765
806
|
</main>
|
|
766
807
|
<script>
|
|
@@ -1019,6 +1060,81 @@ const MUDIII_STYLE = `
|
|
|
1019
1060
|
.outlook-belief-table td { padding: .12rem .4rem .12rem 0; vertical-align: top; }
|
|
1020
1061
|
.outlook-plan { margin: 0; font-family: ${MONO_STACK}; font-size: .68rem; white-space: pre-wrap; color: var(--square-ink); }
|
|
1021
1062
|
|
|
1063
|
+
/* The crossing board: two banks with the water between them, standing in
|
|
1064
|
+
for the 3D square on a scenario that has no grid to draw. The boat is
|
|
1065
|
+
absolutely placed inside the water so one CSS transition carries it —
|
|
1066
|
+
and everyone aboard it — from bank to bank. */
|
|
1067
|
+
.river-stage {
|
|
1068
|
+
display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem;
|
|
1069
|
+
background: var(--parchment); border: 1px solid var(--square-stone-dark); border-radius: 4px;
|
|
1070
|
+
box-shadow: 0 2px 0 rgba(0,0,0,.18); padding: .7rem .8rem; min-width: 0;
|
|
1071
|
+
}
|
|
1072
|
+
.river-stage[hidden] { display: none; }
|
|
1073
|
+
body.editing .river-stage { display: none; }
|
|
1074
|
+
.river-head { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
|
|
1075
|
+
.river-title { font-family: ${DISPLAY_STACK}; font-size: 1rem; }
|
|
1076
|
+
.river-progress { font-size: .68rem; color: var(--square-stone-dark); }
|
|
1077
|
+
.river-board { display: grid; grid-template-columns: minmax(0, 1fr) minmax(90px, 1.1fr) minmax(0, 1fr); gap: .5rem; align-items: stretch; }
|
|
1078
|
+
.river-bank {
|
|
1079
|
+
background: rgba(124,154,91,.32); border: 1px solid var(--square-stone-dark); border-radius: 3px;
|
|
1080
|
+
padding: .4rem .45rem; display: flex; flex-direction: column; gap: .35rem; min-width: 0; min-height: 7rem;
|
|
1081
|
+
}
|
|
1082
|
+
.river-bank-name { margin: 0; color: var(--square-stone-dark); }
|
|
1083
|
+
.river-water {
|
|
1084
|
+
position: relative; border: 1px solid var(--square-stone-dark); border-radius: 3px; min-height: 7rem;
|
|
1085
|
+
background: repeating-linear-gradient(180deg, rgba(94,140,178,.55) 0 6px, rgba(120,166,201,.55) 6px 12px);
|
|
1086
|
+
}
|
|
1087
|
+
.river-boat {
|
|
1088
|
+
position: absolute; top: 50%; left: 6%; transform: translate(-50%, -50%);
|
|
1089
|
+
display: flex; flex-direction: column; align-items: center; gap: .2rem;
|
|
1090
|
+
background: var(--square-thatch); border: 1px solid var(--square-stone-dark); border-radius: 3px;
|
|
1091
|
+
padding: .3rem .35rem; min-width: 3.4rem;
|
|
1092
|
+
transition: left .4s ease;
|
|
1093
|
+
}
|
|
1094
|
+
.river-boat[data-at="right"] { left: 94%; }
|
|
1095
|
+
.river-boat[data-at="crossing"] { left: 50%; }
|
|
1096
|
+
.river-boat-label { font-size: .5rem; text-transform: uppercase; letter-spacing: .1em; color: var(--parchment); }
|
|
1097
|
+
.river-chips { display: flex; flex-wrap: wrap; gap: .25rem; align-content: flex-start; }
|
|
1098
|
+
.river-chip {
|
|
1099
|
+
display: inline-flex; align-items: center; gap: .22rem;
|
|
1100
|
+
background: var(--parchment); border: 1px solid var(--square-stone-dark); border-radius: 99px;
|
|
1101
|
+
padding: .12rem .42rem .12rem .3rem;
|
|
1102
|
+
}
|
|
1103
|
+
.river-chip-glyph { font-style: normal; font-size: .85rem; line-height: 1; }
|
|
1104
|
+
.river-chip-name { font-size: .58rem; letter-spacing: .02em; }
|
|
1105
|
+
.river-chip-empty { font-size: .68rem; font-style: italic; color: var(--square-stone-dark); }
|
|
1106
|
+
.river-move { margin: 0; font-size: .68rem; color: var(--square-ink); min-height: 1.2em; }
|
|
1107
|
+
@media (prefers-reduced-motion: reduce) { .river-boat { transition: none; } }
|
|
1108
|
+
|
|
1109
|
+
/* What the followed agent believes, plans and is driven by, on the playing
|
|
1110
|
+
screen itself rather than only behind the edit button. */
|
|
1111
|
+
.focus-panel {
|
|
1112
|
+
display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem;
|
|
1113
|
+
background: var(--parchment); border: 1px solid var(--square-stone-dark); border-radius: 4px;
|
|
1114
|
+
box-shadow: 0 2px 0 rgba(0,0,0,.18); padding: .7rem .8rem; min-width: 0;
|
|
1115
|
+
}
|
|
1116
|
+
body.editing .focus-panel { display: none; }
|
|
1117
|
+
.focus-panel h2 { margin: 0; font-size: .8rem; }
|
|
1118
|
+
.focus-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .7rem; }
|
|
1119
|
+
.focus-col { min-width: 0; display: flex; flex-direction: column; gap: .25rem; }
|
|
1120
|
+
.focus-body {
|
|
1121
|
+
margin: 0; font-size: .66rem; line-height: 1.5; color: var(--square-ink);
|
|
1122
|
+
background: rgba(255,255,255,.5); border: 1px solid rgba(89,80,63,.35); border-radius: 3px;
|
|
1123
|
+
padding: .4rem .45rem; min-height: 4.5rem; max-height: 13rem; overflow: auto;
|
|
1124
|
+
white-space: pre-wrap; overflow-wrap: anywhere;
|
|
1125
|
+
}
|
|
1126
|
+
.focus-line { margin: 0 0 .12rem; }
|
|
1127
|
+
.focus-empty { font-style: italic; color: var(--square-stone-dark); }
|
|
1128
|
+
.focus-plan-done { color: var(--square-stone-dark); }
|
|
1129
|
+
.focus-plan-now { color: #9A5B12; font-weight: 600; }
|
|
1130
|
+
|
|
1131
|
+
/* An author display rule outranks the browser's own [hidden] { display:
|
|
1132
|
+
none }, so anything this page hides by attribute has to say so at a
|
|
1133
|
+
specificity of its own — a hidden map panel, HUD row, control stack or
|
|
1134
|
+
slider otherwise keeps its flex box and stays on screen. */
|
|
1135
|
+
.deck-stack[hidden], .deck-slider[hidden], .deck-teach[hidden], .camera-mode[hidden],
|
|
1136
|
+
.map-panel[hidden], .hud-row[hidden], .scene-stage[hidden] { display: none; }
|
|
1137
|
+
|
|
1022
1138
|
.mudiii-chat { background: var(--parchment); border: 1px solid var(--square-stone-dark); border-radius: 4px; box-shadow: 0 2px 0 rgba(0,0,0,.18); padding: .7rem .8rem; display: flex; flex-direction: column; gap: .5rem; }
|
|
1023
1139
|
.chatlog { min-height: 8rem; max-height: 16rem; overflow-y: auto; }
|
|
1024
1140
|
.chatlog > * { margin: 0 0 .32rem; }
|
|
@@ -1164,9 +1280,10 @@ function pageScript() {
|
|
|
1164
1280
|
const isPuzzle = function () { return scenario().puzzle === true; };
|
|
1165
1281
|
function applyPuzzleVisibility() {
|
|
1166
1282
|
const puzzle = isPuzzle();
|
|
1167
|
-
const
|
|
1168
|
-
for (let i = 0; i <
|
|
1169
|
-
|
|
1283
|
+
const hideWhenPuzzle = document.querySelectorAll("[data-hide-when-puzzle]");
|
|
1284
|
+
for (let i = 0; i < hideWhenPuzzle.length; i += 1) hideWhenPuzzle[i].hidden = puzzle;
|
|
1285
|
+
const showWhenPuzzle = document.querySelectorAll("[data-show-when-puzzle]");
|
|
1286
|
+
for (let i = 0; i < showWhenPuzzle.length; i += 1) showWhenPuzzle[i].hidden = !puzzle;
|
|
1170
1287
|
}
|
|
1171
1288
|
// Every numbered instance a puzzle world's own facts place — fox-1, goat-1,
|
|
1172
1289
|
// cabbage-1, farmer-1 for the river crossing — read straight off rdf:type
|
|
@@ -1182,6 +1299,171 @@ function pageScript() {
|
|
|
1182
1299
|
}
|
|
1183
1300
|
let puzzleActorIds = [];
|
|
1184
1301
|
|
|
1302
|
+
// ---- the crossing, played back move by move ------------------------------
|
|
1303
|
+
// The planner finds the whole crossing before anything moves (see
|
|
1304
|
+
// mudiii-turn.mjs's riverPuzzleOutlook, reached through session.outlook()),
|
|
1305
|
+
// and hands back one "who stands where" map per position it passes through.
|
|
1306
|
+
// Playback here only walks that list: play steps through it on a timer,
|
|
1307
|
+
// pause holds wherever it stopped, step takes a single crossing. Nothing
|
|
1308
|
+
// below decides a move — every move on the board is one the search found.
|
|
1309
|
+
const RIVER_GLYPHS = {
|
|
1310
|
+
farmer: "\\uD83E\\uDDD1\\u200D\\uD83C\\uDF3E", goat: "\\uD83D\\uDC10",
|
|
1311
|
+
fox: "\\uD83E\\uDD8A", cabbage: "\\uD83E\\uDD6C",
|
|
1312
|
+
};
|
|
1313
|
+
const RIVER_CROSSING_MS = 420;
|
|
1314
|
+
let riverPlan = [];
|
|
1315
|
+
let riverPlaces = [];
|
|
1316
|
+
let riverBanks = [];
|
|
1317
|
+
// How many moves of the plan have been played. The boat and every passenger
|
|
1318
|
+
// are drawn from riverPlaces[riverMove], so this one number is the whole
|
|
1319
|
+
// playback position.
|
|
1320
|
+
let riverMove = 0;
|
|
1321
|
+
// The crossing in flight: { to, travellers }, or null while the boat is
|
|
1322
|
+
// moored. Only ever set between two positions the plan already contains.
|
|
1323
|
+
let riverAfloat = null;
|
|
1324
|
+
let riverPlanKey = "";
|
|
1325
|
+
|
|
1326
|
+
/** Take on whatever crossing the planner currently finds. Returns true when
|
|
1327
|
+
* that is a DIFFERENT crossing from the one being played — an edit to a
|
|
1328
|
+
* drive redraws the plan, and playback has to go back to the opening
|
|
1329
|
+
* arrangement rather than carry a position from a plan that no longer
|
|
1330
|
+
* exists. */
|
|
1331
|
+
function adoptPuzzlePlan(puzzle) {
|
|
1332
|
+
const plan = (puzzle && puzzle.plan) || [];
|
|
1333
|
+
const key = plan.map(function (a) { return a.label; }).join("|") + "#" + ((puzzle && puzzle.miss) || "");
|
|
1334
|
+
if (key === riverPlanKey) return false;
|
|
1335
|
+
riverPlanKey = key;
|
|
1336
|
+
riverPlan = plan;
|
|
1337
|
+
riverPlaces = (puzzle && puzzle.places) || [];
|
|
1338
|
+
riverBanks = riverBanksFrom(riverPlaces, puzzle && puzzle.goalPlace);
|
|
1339
|
+
riverMove = 0;
|
|
1340
|
+
riverAfloat = null;
|
|
1341
|
+
return true;
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
/** The two shores, near one first: every place the passengers ever stand,
|
|
1345
|
+
* sorted, with the goal place moved to the far side so the crossing always
|
|
1346
|
+
* reads left to right. */
|
|
1347
|
+
function riverBanksFrom(places, goalPlace) {
|
|
1348
|
+
const seen = {};
|
|
1349
|
+
(places || []).forEach(function (position) {
|
|
1350
|
+
Object.keys(position).forEach(function (id) { seen[position[id]] = true; });
|
|
1351
|
+
});
|
|
1352
|
+
const all = Object.keys(seen).sort();
|
|
1353
|
+
if (goalPlace && all.indexOf(goalPlace) !== -1) {
|
|
1354
|
+
return all.filter(function (place) { return place !== goalPlace; }).concat([goalPlace]);
|
|
1355
|
+
}
|
|
1356
|
+
return all;
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
function riverPositionNow() { return riverPlaces[riverMove] || riverPlaces[0] || {}; }
|
|
1360
|
+
|
|
1361
|
+
/** Everyone whose place changes on move "step" (1-based) — the boat's own
|
|
1362
|
+
* passengers for that crossing, read off the two positions rather than
|
|
1363
|
+
* guessed from the action's subject, so a companion the rules carry along
|
|
1364
|
+
* is aboard too. */
|
|
1365
|
+
function riverTravellersFor(step) {
|
|
1366
|
+
const before = riverPlaces[step - 1] || {};
|
|
1367
|
+
const after = riverPlaces[step] || {};
|
|
1368
|
+
return Object.keys(after).filter(function (id) { return before[id] !== after[id]; }).sort();
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
/** Whoever crosses on every single move — the one rowing. Null when no
|
|
1372
|
+
* single passenger does, and then the boat simply follows the last move's
|
|
1373
|
+
* target instead. */
|
|
1374
|
+
function riverFerrymanId() {
|
|
1375
|
+
if (!riverPlan.length) return null;
|
|
1376
|
+
let common = riverTravellersFor(1);
|
|
1377
|
+
for (let step = 2; step <= riverPlan.length; step += 1) {
|
|
1378
|
+
const travellers = riverTravellersFor(step);
|
|
1379
|
+
common = common.filter(function (id) { return travellers.indexOf(id) !== -1; });
|
|
1380
|
+
}
|
|
1381
|
+
return common.length === 1 ? common[0] : null;
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
function riverBoatPlace() {
|
|
1385
|
+
const ferryman = riverFerrymanId();
|
|
1386
|
+
if (ferryman) return riverPositionNow()[ferryman] || riverBanks[0] || null;
|
|
1387
|
+
if (riverMove > 0) return riverPlan[riverMove - 1].target;
|
|
1388
|
+
return riverBanks[0] || null;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
function riverGlyphFor(id) {
|
|
1392
|
+
const kind = roleOfAgentId(id);
|
|
1393
|
+
return RIVER_GLYPHS[kind] || kind.slice(0, 1).toUpperCase();
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
function riverChipHtml(id, place) {
|
|
1397
|
+
return '<span class="river-chip" data-passenger="' + esc(id) + '" data-place="' + esc(place) + '">'
|
|
1398
|
+
+ '<i class="river-chip-glyph" aria-hidden="true">' + riverGlyphFor(id) + "</i>"
|
|
1399
|
+
+ '<span class="river-chip-name mono">' + esc(id) + "</span></span>";
|
|
1400
|
+
}
|
|
1401
|
+
|
|
1402
|
+
function renderRiverBoard() {
|
|
1403
|
+
if (!isPuzzle()) return;
|
|
1404
|
+
const position = riverPositionNow();
|
|
1405
|
+
const aboard = {};
|
|
1406
|
+
(riverAfloat ? riverAfloat.travellers : []).forEach(function (id) { aboard[id] = true; });
|
|
1407
|
+
const ids = Object.keys(position).sort();
|
|
1408
|
+
const nearBank = riverBanks[0] || null;
|
|
1409
|
+
const farBank = riverBanks[1] || null;
|
|
1410
|
+
const bankHtml = function (bank) {
|
|
1411
|
+
const html = ids.filter(function (id) { return position[id] === bank && !aboard[id]; })
|
|
1412
|
+
.map(function (id) { return riverChipHtml(id, bank); }).join("");
|
|
1413
|
+
return html || '<span class="river-chip-empty">empty</span>';
|
|
1414
|
+
};
|
|
1415
|
+
el("riverBankLeftName").textContent = nearBank || "near bank";
|
|
1416
|
+
el("riverBankRightName").textContent = farBank || "far bank";
|
|
1417
|
+
el("riverChipsLeft").innerHTML = nearBank ? bankHtml(nearBank) : "";
|
|
1418
|
+
el("riverChipsRight").innerHTML = farBank ? bankHtml(farBank) : "";
|
|
1419
|
+
el("riverChipsBoat").innerHTML = Object.keys(aboard).sort()
|
|
1420
|
+
.map(function (id) { return riverChipHtml(id, "boat"); }).join("");
|
|
1421
|
+
|
|
1422
|
+
const moored = riverAfloat ? "crossing" : (riverBoatPlace() === farBank ? "right" : "left");
|
|
1423
|
+
el("riverBoat").setAttribute("data-at", moored);
|
|
1424
|
+
|
|
1425
|
+
const total = riverPlan.length;
|
|
1426
|
+
el("riverProgress").textContent = total
|
|
1427
|
+
? "move " + riverMove + " of " + total
|
|
1428
|
+
: "no crossing found";
|
|
1429
|
+
if (riverAfloat) {
|
|
1430
|
+
el("riverMoveText").textContent = "crossing to " + riverAfloat.to + ": "
|
|
1431
|
+
+ riverAfloat.travellers.join(", ") + " aboard.";
|
|
1432
|
+
} else if (riverMove > 0) {
|
|
1433
|
+
el("riverMoveText").textContent = "last move: " + riverPlan[riverMove - 1].label
|
|
1434
|
+
+ (riverMove === total ? " \\u2014 everyone is across." : ".");
|
|
1435
|
+
} else {
|
|
1436
|
+
el("riverMoveText").textContent = total
|
|
1437
|
+
? "nobody has crossed yet. Press play."
|
|
1438
|
+
: "the planner found no crossing for these drives.";
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
/** One crossing: the travellers board, the boat carries them over, and the
|
|
1443
|
+
* position the plan already computed lands. Nothing is decided here. */
|
|
1444
|
+
async function playOneRiverMove() {
|
|
1445
|
+
if (riverMove >= riverPlan.length) return null;
|
|
1446
|
+
const step = riverMove + 1;
|
|
1447
|
+
riverAfloat = { to: riverPlan[step - 1].target, travellers: riverTravellersFor(step) };
|
|
1448
|
+
renderRiverBoard();
|
|
1449
|
+
if (!prefersReducedMotion()) await wait(RIVER_CROSSING_MS);
|
|
1450
|
+
riverAfloat = null;
|
|
1451
|
+
riverMove = step;
|
|
1452
|
+
renderRiverBoard();
|
|
1453
|
+
renderFocusPanel();
|
|
1454
|
+
return { move: riverMove };
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
function rewindRiverPlayback() {
|
|
1458
|
+
autoOn = false;
|
|
1459
|
+
if (ticker) { ticker.pause(); ticker = null; }
|
|
1460
|
+
riverMove = 0;
|
|
1461
|
+
riverAfloat = null;
|
|
1462
|
+
renderRiverBoard();
|
|
1463
|
+
renderFocusPanel();
|
|
1464
|
+
showStopped();
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1185
1467
|
// ---- roster minting -----------------------------------------------------
|
|
1186
1468
|
// The page asks for a COUNT and names the ids it is about to get back: the
|
|
1187
1469
|
// engine mints <prefix>-1..N at seeded cells, so a slider can call for more
|
|
@@ -1233,7 +1515,9 @@ function pageScript() {
|
|
|
1233
1515
|
let editing = false;
|
|
1234
1516
|
let ticker = null;
|
|
1235
1517
|
|
|
1236
|
-
|
|
1518
|
+
// A puzzle plays its plan out, so what is left to play is what is left of
|
|
1519
|
+
// the plan; a chase plays until the turn budget runs out.
|
|
1520
|
+
function hasNext() { return isPuzzle() ? riverMove < riverPlan.length : globalTurn < maxTurns; }
|
|
1237
1521
|
const wait = function (ms) { return new Promise(function (resolve) { setTimeout(resolve, ms); }); };
|
|
1238
1522
|
const liveWait = function () { return wait(delayMs); };
|
|
1239
1523
|
|
|
@@ -1298,6 +1582,7 @@ function pageScript() {
|
|
|
1298
1582
|
}
|
|
1299
1583
|
|
|
1300
1584
|
async function runOneTick() {
|
|
1585
|
+
if (isPuzzle()) return playOneRiverMove();
|
|
1301
1586
|
return serializeTick(async function () {
|
|
1302
1587
|
if (!session) return null;
|
|
1303
1588
|
const result = await session.tick();
|
|
@@ -1317,10 +1602,13 @@ function pageScript() {
|
|
|
1317
1602
|
playBtn.textContent = state.playing ? "\\u23F8 pause" : "\\u25B6 play";
|
|
1318
1603
|
// The follow control reads the ticker's own state, never a second
|
|
1319
1604
|
// "am I playing" the page keeps for itself, so the two can never
|
|
1320
|
-
// disagree. It closes while
|
|
1321
|
-
// on top of the open dropdown and loses the pick.
|
|
1322
|
-
|
|
1323
|
-
|
|
1605
|
+
// disagree. It closes while a chase board plays because a redraw
|
|
1606
|
+
// lands on top of the open dropdown and loses the pick. A puzzle
|
|
1607
|
+
// rebuilds no dropdown as it plays, so it stays open and the panel
|
|
1608
|
+
// below follows whoever is picked mid-crossing.
|
|
1609
|
+
const lockFollow = state.playing && !isPuzzle();
|
|
1610
|
+
el("agentSelect").disabled = lockFollow;
|
|
1611
|
+
el("agentSelectHint").hidden = !lockFollow;
|
|
1324
1612
|
// Step reads the same ticker state for the same reason: a hand-driven
|
|
1325
1613
|
// turn while the board plays itself lands in the middle of one.
|
|
1326
1614
|
el("stepBtn").disabled = state.playing || state.animating;
|
|
@@ -1349,6 +1637,10 @@ function pageScript() {
|
|
|
1349
1637
|
appendChat("a", res.answer);
|
|
1350
1638
|
applyTickResult(board);
|
|
1351
1639
|
renderAll();
|
|
1640
|
+
// A taught line can change a drive, and a drive is what the plan and the
|
|
1641
|
+
// imperatives are made of, so both are re-read after every turn.
|
|
1642
|
+
await refreshStoreRows();
|
|
1643
|
+
await refreshOutlook();
|
|
1352
1644
|
return res;
|
|
1353
1645
|
});
|
|
1354
1646
|
}
|
|
@@ -1654,7 +1946,7 @@ function pageScript() {
|
|
|
1654
1946
|
camera = { mode: mode, selectedId: id, status: null };
|
|
1655
1947
|
renderCameraButtons();
|
|
1656
1948
|
renderDriveRing();
|
|
1657
|
-
if (editing) { renderActorEditor(); renderOutlookPanel(); }
|
|
1949
|
+
if (editing) { renderActorEditor(); renderOutlookPanel(); } else renderFocusPanel();
|
|
1658
1950
|
sendCameraToScene(camera);
|
|
1659
1951
|
});
|
|
1660
1952
|
|
|
@@ -1693,7 +1985,19 @@ function pageScript() {
|
|
|
1693
1985
|
function wireDeck() {
|
|
1694
1986
|
el("autoToggle").addEventListener("click", function () {
|
|
1695
1987
|
if (!session) return;
|
|
1696
|
-
|
|
1988
|
+
// The control reads its own drawn state, which the ticker writes, so a
|
|
1989
|
+
// run that ended on its own (a crossing played to the last move) is
|
|
1990
|
+
// still read as stopped rather than as playing.
|
|
1991
|
+
const playing = el("autoToggle").getAttribute("aria-pressed") === "true";
|
|
1992
|
+
// Play on a finished crossing starts it again from the opening
|
|
1993
|
+
// arrangement instead of reading as a dead control.
|
|
1994
|
+
if (!playing && isPuzzle() && !hasNext()) {
|
|
1995
|
+
riverMove = 0;
|
|
1996
|
+
riverAfloat = null;
|
|
1997
|
+
renderRiverBoard();
|
|
1998
|
+
renderFocusPanel();
|
|
1999
|
+
}
|
|
2000
|
+
autoOn = !playing;
|
|
1697
2001
|
if (autoOn) ensureTicker().play(); else ensureTicker().pause();
|
|
1698
2002
|
});
|
|
1699
2003
|
el("delaySlider").addEventListener("input", function () {
|
|
@@ -1824,6 +2128,8 @@ function pageScript() {
|
|
|
1824
2128
|
document.body.classList.remove("editing");
|
|
1825
2129
|
el("editModeBtn").textContent = "edit";
|
|
1826
2130
|
el("editModeBtn").setAttribute("aria-pressed", "false");
|
|
2131
|
+
renderFocusPanel();
|
|
2132
|
+
renderRiverBoard();
|
|
1827
2133
|
}
|
|
1828
2134
|
|
|
1829
2135
|
// The lateral SKOS neighbourhood plus the vertical is-a chain for whatever
|
|
@@ -2077,7 +2383,15 @@ function pageScript() {
|
|
|
2077
2383
|
async function refreshOutlook() {
|
|
2078
2384
|
if (!session || !session.outlook) return;
|
|
2079
2385
|
lastOutlook = await session.outlook();
|
|
2386
|
+
if (isPuzzle()) {
|
|
2387
|
+
// An edit to a drive redraws the crossing, so playback goes back to the
|
|
2388
|
+
// opening arrangement rather than holding a position in a plan that no
|
|
2389
|
+
// longer exists.
|
|
2390
|
+
if (adoptPuzzlePlan(lastOutlook.puzzle)) rewindRiverPlayback();
|
|
2391
|
+
else renderRiverBoard();
|
|
2392
|
+
}
|
|
2080
2393
|
renderOutlookPanel();
|
|
2394
|
+
renderFocusPanel();
|
|
2081
2395
|
}
|
|
2082
2396
|
|
|
2083
2397
|
function beliefOriginText(cell, origin) {
|
|
@@ -2130,6 +2444,76 @@ function pageScript() {
|
|
|
2130
2444
|
}
|
|
2131
2445
|
}
|
|
2132
2446
|
|
|
2447
|
+
// ---- the followed agent, on the playing screen --------------------------
|
|
2448
|
+
// The same three readings the edit view carries — what it believes, what it
|
|
2449
|
+
// plans, and the drive sentences it is acting on — sitting under the chat so
|
|
2450
|
+
// a player can watch them move without leaving the game. Beliefs and plan
|
|
2451
|
+
// come off the live tick payload (agentsById), which already carries both,
|
|
2452
|
+
// so a chase board costs no extra engine call per turn; the imperatives are
|
|
2453
|
+
// the actor editor's own per-instance text, inherited class lines included.
|
|
2454
|
+
function renderFocusPanel() {
|
|
2455
|
+
const id = el("agentSelect").value;
|
|
2456
|
+
el("focusWho").textContent = id || "nobody yet";
|
|
2457
|
+
renderFocusBeliefs(id);
|
|
2458
|
+
renderFocusPlan(id);
|
|
2459
|
+
renderFocusImperatives(id);
|
|
2460
|
+
}
|
|
2461
|
+
|
|
2462
|
+
function renderFocusBeliefs(id) {
|
|
2463
|
+
const box = el("focusBeliefs");
|
|
2464
|
+
const entry = id ? agentsById[id] : null;
|
|
2465
|
+
if (!id) {
|
|
2466
|
+
box.innerHTML = '<span class="focus-empty">Follow an agent above.</span>';
|
|
2467
|
+
return;
|
|
2468
|
+
}
|
|
2469
|
+
if (!entry) {
|
|
2470
|
+
box.innerHTML = '<span class="focus-empty">this scenario keeps no belief map \\u2014 nothing here is seen or told.</span>';
|
|
2471
|
+
return;
|
|
2472
|
+
}
|
|
2473
|
+
const subjects = Object.keys(entry.belief || {}).sort();
|
|
2474
|
+
box.innerHTML = subjects.length
|
|
2475
|
+
? subjects.map(function (subject) {
|
|
2476
|
+
return '<div class="focus-line">' + esc(believedFactSentence(subject, entry.belief[subject])) + "</div>";
|
|
2477
|
+
}).join("")
|
|
2478
|
+
: '<span class="focus-empty">' + esc(id) + " is alone on the board \\u2014 nothing else to believe anything about.</span>";
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
function renderFocusPlan(id) {
|
|
2482
|
+
const box = el("focusPlanText");
|
|
2483
|
+
const puzzle = lastOutlook && lastOutlook.puzzle;
|
|
2484
|
+
if (puzzle) {
|
|
2485
|
+
if (!puzzle.plan) { box.textContent = puzzle.miss; return; }
|
|
2486
|
+
box.innerHTML = puzzle.plan.map(function (action, i) {
|
|
2487
|
+
const step = i + 1;
|
|
2488
|
+
const inFlight = riverAfloat && step === riverMove + 1;
|
|
2489
|
+
const cls = inFlight ? "focus-plan-now" : (step <= riverMove ? "focus-plan-done" : "");
|
|
2490
|
+
const mark = inFlight ? "\\u25B8" : (step <= riverMove ? "\\u2713" : "\\u00B7");
|
|
2491
|
+
return '<span class="' + cls + '">' + mark + " " + step + ". " + esc(action.label) + "</span>";
|
|
2492
|
+
}).join("\\n");
|
|
2493
|
+
return;
|
|
2494
|
+
}
|
|
2495
|
+
const entry = id ? agentsById[id] : null;
|
|
2496
|
+
if (!entry) { box.textContent = "nothing planned yet."; return; }
|
|
2497
|
+
const plan = (entry.plan && entry.plan.length) ? entry.plan.join(" \\u2192 ") : "holding";
|
|
2498
|
+
box.textContent = plan + "\\n" + (entry.goal || "");
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
function renderFocusImperatives(id) {
|
|
2502
|
+
const box = el("focusImperatives");
|
|
2503
|
+
const render = window.tmct && window.tmct.page && window.tmct.page.renderAgentEditorText;
|
|
2504
|
+
if (!id || !render || !allStoreRows.length) { box.textContent = ""; return; }
|
|
2505
|
+
box.textContent = render(allStoreRows, id);
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
// The imperatives read the whole store, which only edit mode used to load.
|
|
2509
|
+
// Refreshed on boot, on a follow change and after a chat turn — never per
|
|
2510
|
+
// tick, because a drive is not something a turn moves.
|
|
2511
|
+
async function refreshStoreRows() {
|
|
2512
|
+
if (!session || !session.snapshot) return;
|
|
2513
|
+
const snap = await session.snapshot();
|
|
2514
|
+
allStoreRows = snap.rows;
|
|
2515
|
+
}
|
|
2516
|
+
|
|
2133
2517
|
// ---- booting ---------------------------------------------------------
|
|
2134
2518
|
// The board opens playing: a square standing still reads as broken, and the
|
|
2135
2519
|
// first thing anyone does is press play anyway. A visitor who asked for
|
|
@@ -2189,9 +2573,13 @@ function pageScript() {
|
|
|
2189
2573
|
if (seq !== bootSeq) return;
|
|
2190
2574
|
camera.selectedId = puzzleActorIds[0] || null;
|
|
2191
2575
|
renderAll();
|
|
2576
|
+
await refreshStoreRows();
|
|
2577
|
+
if (seq !== bootSeq) return;
|
|
2192
2578
|
await refreshOutlook();
|
|
2579
|
+
if (seq !== bootSeq) return;
|
|
2580
|
+
renderFocusPanel();
|
|
2193
2581
|
showStopped();
|
|
2194
|
-
setSceneStatus("this scenario is a puzzle, not a chase \\u2014
|
|
2582
|
+
setSceneStatus("this scenario is a puzzle, not a chase \\u2014 press play to watch the planner ferry everyone across, and follow any passenger to read what drives it.");
|
|
2195
2583
|
}
|
|
2196
2584
|
|
|
2197
2585
|
let bootSeq = 0;
|
|
@@ -2239,7 +2627,11 @@ function pageScript() {
|
|
|
2239
2627
|
camera.selectedId = openingFollowId(opening.agents);
|
|
2240
2628
|
applyTickResult(opening);
|
|
2241
2629
|
renderAll();
|
|
2630
|
+
await refreshStoreRows();
|
|
2631
|
+
if (seq !== bootSeq) return;
|
|
2242
2632
|
await refreshOutlook();
|
|
2633
|
+
if (seq !== bootSeq) return;
|
|
2634
|
+
renderFocusPanel();
|
|
2243
2635
|
if (!prefersReducedMotion()) {
|
|
2244
2636
|
autoOn = true;
|
|
2245
2637
|
ensureTicker().play();
|
|
@@ -2261,10 +2653,14 @@ function pageScript() {
|
|
|
2261
2653
|
if (ticker) { ticker.pause(); ticker = null; }
|
|
2262
2654
|
expandedAgents.clear();
|
|
2263
2655
|
const s = scenario();
|
|
2264
|
-
//
|
|
2265
|
-
//
|
|
2266
|
-
//
|
|
2267
|
-
if (s.puzzle)
|
|
2656
|
+
// A puzzle has no cast to re-mint. Reset there means the opening
|
|
2657
|
+
// arrangement again: playback rewinds to before the first crossing and
|
|
2658
|
+
// the world's own facts, edits included, stand untouched.
|
|
2659
|
+
if (s.puzzle) {
|
|
2660
|
+
rewindRiverPlayback();
|
|
2661
|
+
setSceneStatus("back to the opening arrangement \\u2014 press play to watch the crossing again.");
|
|
2662
|
+
return;
|
|
2663
|
+
}
|
|
2268
2664
|
const foxes = mintRoster(rosterPrefixFor(s, "predator"), chosenFoxCount());
|
|
2269
2665
|
const goblins = mintRoster(rosterPrefixFor(s, "prey"), chosenGoblinCount());
|
|
2270
2666
|
cast = foxes.concat(goblins);
|
|
@@ -2287,6 +2683,7 @@ function pageScript() {
|
|
|
2287
2683
|
renderCameraButtons();
|
|
2288
2684
|
renderDriveRing();
|
|
2289
2685
|
renderChatPills();
|
|
2686
|
+
renderFocusPanel();
|
|
2290
2687
|
el("globalTurnCount").textContent = "turns: " + globalTurn;
|
|
2291
2688
|
}
|
|
2292
2689
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// news-exports.mjs — the package's `./news` export subpath: the news
|
|
2
|
+
// library contract (PLAN_NEWS_FEED.md section 10.2/6.7) reachable without
|
|
3
|
+
// pulling in the chat/grammar engine the "." entry also carries. Re-exports
|
|
4
|
+
// news.mjs's engine calls, state constructor and metrics, plus the built-in
|
|
5
|
+
// fetchers and courtesy gate as optional conveniences for a consumer that
|
|
6
|
+
// wants tmct's own source adapters rather than supplying its own.
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
NEWS_DEFAULTS,
|
|
10
|
+
clampNewsConfig,
|
|
11
|
+
resolveNewsConfig,
|
|
12
|
+
parseNewsRequest,
|
|
13
|
+
pollNewsSources,
|
|
14
|
+
ingestNewsSnapshot,
|
|
15
|
+
enrichTopTerms,
|
|
16
|
+
reprocessAfterGrounding,
|
|
17
|
+
isVocabGroundedTerm,
|
|
18
|
+
isFactGroundedTerm,
|
|
19
|
+
ingestUploadedFactRows,
|
|
20
|
+
buildFeed,
|
|
21
|
+
newsTurn,
|
|
22
|
+
cycleMetrics,
|
|
23
|
+
createNewsState,
|
|
24
|
+
NEWS_SOURCE_RECORDS,
|
|
25
|
+
DEFAULT_NEWS_SOURCE_IDS,
|
|
26
|
+
DEFAULT_NEWS_KB_IDS,
|
|
27
|
+
} from "./news.mjs";
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
createNewsFetcher,
|
|
31
|
+
preflightNewsUrl,
|
|
32
|
+
registerNewsSource,
|
|
33
|
+
newsSourceRecords,
|
|
34
|
+
normalizeNewsSourceIds,
|
|
35
|
+
NEWS_USER_AGENT,
|
|
36
|
+
} from "../adapters/corpus/news-sources.mjs";
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
createCourtesyGate,
|
|
40
|
+
DEFAULT_TIMEOUT_MS,
|
|
41
|
+
DEFAULT_MIN_INTERVAL_MS,
|
|
42
|
+
RETRY_AFTER_FLOOR_MS,
|
|
43
|
+
MAXLAG_SECONDS,
|
|
44
|
+
} from "../adapters/corpus/courtesy.mjs";
|