@polycode-projects/the-mechanical-code-talker 5.0.35 → 5.0.37

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.
@@ -20,7 +20,9 @@
20
20
  // `.setCamera(...)` on every camera-mode change, agent-select change and
21
21
  // `nextCameraSelection` fallback (see `callScene`, below) — every call
22
22
  // guarded, because a failed three.js vendor load (~800 KB) must never take
23
- // the map panel, the HUD, the deck or the chat down with it.
23
+ // the map panel, the HUD, the deck or the chat down with it. A puzzle
24
+ // scenario swaps those first two calls for `.bootRiver(...)` once and
25
+ // `.applyRiver(...)` per crossing; the same stage draws the river.
24
26
  //
25
27
  // Deliberately absent, all P2P (mud.html's #statePill, share/join buttons,
26
28
  // the share overlay, the wave button): this is the 1-player page. A later
@@ -114,6 +116,35 @@ export function roleOfAgentId(id) {
114
116
  return String(id).replace(/-\d+$/, "");
115
117
  }
116
118
 
119
+ /** Which scenario a page URL asks for. `?scenario=river` on a page whose
120
+ * fourth entry is the river crossing returns 3. The asked-for value and each
121
+ * scenario's own world name and label are all reduced to the same hyphenated
122
+ * slug before they are compared, so "River", "river" and "river-crossing" all
123
+ * reach the same scenario; a whole hyphen-separated word of a name or a label
124
+ * counts, which is what lets a short "river" reach "river crossing (fox,
125
+ * goat, cabbage and a farmer)". An exact name or label wins over a word of
126
+ * one. A value the page carries no scenario for falls back to 0 — the
127
+ * scenario the page would have opened on anyway, with no error and no empty
128
+ * stage. Pure, self-contained. */
129
+ export function scenarioIndexFromQuery(search, scenarios) {
130
+ const slugOf = (text) => String(text == null ? "" : text)
131
+ .toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
132
+ const wanted = slugOf(new URLSearchParams(String(search || "")).get("scenario"));
133
+ if (!wanted) return 0;
134
+ const list = scenarios || [];
135
+ const namesOf = (s) => [slugOf(s && s.label), slugOf(s && s.worldPayload && s.worldPayload.name)];
136
+ for (let i = 0; i < list.length; i += 1) {
137
+ if (namesOf(list[i]).indexOf(wanted) !== -1) return i;
138
+ }
139
+ for (let i = 0; i < list.length; i += 1) {
140
+ const names = namesOf(list[i]);
141
+ for (let n = 0; n < names.length; n += 1) {
142
+ if (names[n] && names[n].split("-").indexOf(wanted) !== -1) return i;
143
+ }
144
+ }
145
+ return 0;
146
+ }
147
+
117
148
  /** A manifest row's `destPath` as a URL the page can actually fetch.
118
149
  * `data/mudiii-assets.json` records paths from the repository root
119
150
  * ("public/models/props/well.glb"), because that is where the checker and
@@ -553,7 +584,7 @@ export function agentCardMarkup(slot) {
553
584
  * dropdown, the same rule mud-viz.mjs's own renderMudHtml follows. `puzzle`
554
585
  * is true for a scenario with no town-square layout of its own (the
555
586
  * 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
587
+ * 3D stage draws the river instead of a square and the deck's play/step/reset
557
588
  * controls walk the plan the search found rather than driving a simulation
558
589
  * (see this file's own pageScript, `data-hide-when-puzzle` and
559
590
  * `data-show-when-puzzle`). `assetManifest` is
@@ -702,7 +733,7 @@ ${openingAgents.map((a) => ` <option value="${escapeHtml(a.id)}">
702
733
  </div>
703
734
  </section>
704
735
  </div>
705
- <section class="scene-stage" id="sceneStage" aria-label="the town square, in three dimensions" data-hide-when-puzzle>
736
+ <section class="scene-stage" id="sceneStage" aria-label="the world, in three dimensions">
706
737
  <canvas id="sceneCanvas"></canvas>
707
738
  <div class="dir-ring" id="driveRing" role="group" aria-label="walk the agent the camera follows" hidden>
708
739
  ${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")}
@@ -714,7 +745,7 @@ ${RING_POINTS.map((point) => ` <span class="dir-slot dir-${point}"><button
714
745
  <span class="river-title">the crossing</span>
715
746
  <span class="mono river-progress" id="riverProgress"></span>
716
747
  </div>
717
- <div class="river-board" id="riverBoard">
748
+ <div class="river-board" id="riverBoard" aria-label="the crossing, as a flat board">
718
749
  <section class="river-bank" id="riverBankLeft" aria-label="the near bank">
719
750
  <h3 class="river-bank-name" id="riverBankLeftName"></h3>
720
751
  <div class="river-chips" id="riverChipsLeft"></div>
@@ -1060,10 +1091,12 @@ const MUDIII_STYLE = `
1060
1091
  .outlook-belief-table td { padding: .12rem .4rem .12rem 0; vertical-align: top; }
1061
1092
  .outlook-plan { margin: 0; font-family: ${MONO_STACK}; font-size: .68rem; white-space: pre-wrap; color: var(--square-ink); }
1062
1093
 
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. */
1094
+ /* The crossing's own strip under the 3D stage: its title, how far through
1095
+ the plan it is, and the move it just played. The flat board below them is
1096
+ the same crossing in CSS, shown only when the 3D stage could not start —
1097
+ two banks with the water between them, the boat absolutely placed inside
1098
+ the water so one CSS transition carries it, and everyone aboard it, from
1099
+ bank to bank. */
1067
1100
  .river-stage {
1068
1101
  display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem;
1069
1102
  background: var(--parchment); border: 1px solid var(--square-stone-dark); border-radius: 4px;
@@ -1075,6 +1108,7 @@ const MUDIII_STYLE = `
1075
1108
  .river-title { font-family: ${DISPLAY_STACK}; font-size: 1rem; }
1076
1109
  .river-progress { font-size: .68rem; color: var(--square-stone-dark); }
1077
1110
  .river-board { display: grid; grid-template-columns: minmax(0, 1fr) minmax(90px, 1.1fr) minmax(0, 1fr); gap: .5rem; align-items: stretch; }
1111
+ .river-board[hidden] { display: none; }
1078
1112
  .river-bank {
1079
1113
  background: rgba(124,154,91,.32); border: 1px solid var(--square-stone-dark); border-radius: 3px;
1080
1114
  padding: .4rem .45rem; display: flex; flex-direction: column; gap: .35rem; min-width: 0; min-height: 7rem;
@@ -1252,6 +1286,7 @@ function pageScript() {
1252
1286
  const matchPills = ${matchPills.toString()};
1253
1287
  const createPillComplete = ${createPillComplete.toString()};
1254
1288
  const roleOfAgentId = ${roleOfAgentId.toString()};
1289
+ const scenarioIndexFromQuery = ${scenarioIndexFromQuery.toString()};
1255
1290
  const cellToWorld = ${cellToWorld.toString()};
1256
1291
  const cellFromGroundPoint = ${cellFromGroundPoint.toString()};
1257
1292
  const propPlacementsFrom = ${propPlacementsFrom.toString()};
@@ -1270,7 +1305,9 @@ function pageScript() {
1270
1305
 
1271
1306
  const el = (id) => document.getElementById(id);
1272
1307
  const SEED_COMMANDS = ["tick", "what does the fox see", "where is the goblin", "what can I do"];
1273
- let scenarioIndex = 0;
1308
+ // A link can open the page straight on one scenario (mudiii.html?scenario=river),
1309
+ // so the dropdown is a second way in rather than the only one.
1310
+ let scenarioIndex = scenarioIndexFromQuery(window.location.search, DATA.scenarios);
1274
1311
  const scenario = function () { return DATA.scenarios[scenarioIndex]; };
1275
1312
  const gridSizeOf = function () { return scenario().gridSize || DATA.gridSize; };
1276
1313
  // A puzzle scenario (the river crossing) carries no town-square layout —
@@ -1322,6 +1359,11 @@ function pageScript() {
1322
1359
  // moored. Only ever set between two positions the plan already contains.
1323
1360
  let riverAfloat = null;
1324
1361
  let riverPlanKey = "";
1362
+ // Whether the 3D stage is drawing the crossing. False when three.js could
1363
+ // not be vendored at all, and then the flat board below the stage is shown
1364
+ // instead. Both are drawn from the same riverPlaces position either way, so
1365
+ // the two can never disagree about where anyone is.
1366
+ let riverStage3d = false;
1325
1367
 
1326
1368
  /** Take on whatever crossing the planner currently finds. Returns true when
1327
1369
  * that is a DIFFERENT crossing from the one being played — an edit to a
@@ -1399,8 +1441,22 @@ function pageScript() {
1399
1441
  + '<span class="river-chip-name mono">' + esc(id) + "</span></span>";
1400
1442
  }
1401
1443
 
1444
+ /** Hand the 3D stage the same position the flat board below it is drawing:
1445
+ * who stands on which bank, who is aboard, and where the boat is going. */
1446
+ function pushRiverToScene() {
1447
+ if (!riverStage3d) return;
1448
+ callScene("applyRiver", {
1449
+ banks: riverBanks,
1450
+ position: riverPositionNow(),
1451
+ aboard: riverAfloat ? riverAfloat.travellers : [],
1452
+ boatPlace: riverAfloat ? riverAfloat.to : riverBoatPlace(),
1453
+ crossingMs: RIVER_CROSSING_MS,
1454
+ });
1455
+ }
1456
+
1402
1457
  function renderRiverBoard() {
1403
1458
  if (!isPuzzle()) return;
1459
+ pushRiverToScene();
1404
1460
  const position = riverPositionNow();
1405
1461
  const aboard = {};
1406
1462
  (riverAfloat ? riverAfloat.travellers : []).forEach(function (id) { aboard[id] = true; });
@@ -2022,6 +2078,7 @@ function pageScript() {
2022
2078
  el("resetBtn").addEventListener("click", function () { resetBoard(); });
2023
2079
  const scenarioSelect = el("scenarioSelect");
2024
2080
  if (scenarioSelect) {
2081
+ scenarioSelect.value = String(scenarioIndex);
2025
2082
  scenarioSelect.addEventListener("change", function () {
2026
2083
  const picked = Number(scenarioSelect.value);
2027
2084
  if (!DATA.scenarios[picked] || picked === scenarioIndex) return;
@@ -2551,7 +2608,9 @@ function pageScript() {
2551
2608
  // straight off its own facts (puzzleActorIdsFrom), the actor card and the
2552
2609
  // outlook panel work exactly as they do for a chase board's followed
2553
2610
  // agent, and the plan panel is the whole point — refreshOutlook() below
2554
- // computes it the same way it always does.
2611
+ // computes it the same way it always does. The 3D stage stays where it is
2612
+ // and draws the river instead of a town square; the flat crossing board
2613
+ // under it is shown only when the stage could not start at all.
2555
2614
  async function bootPuzzle(seq, s) {
2556
2615
  cast = [];
2557
2616
  props = [];
@@ -2566,11 +2625,13 @@ function pageScript() {
2566
2625
  agentsById = {};
2567
2626
  itemsById = {};
2568
2627
  el("chatInput").disabled = false;
2569
- await callScene("boot", {
2570
- propPlacements: [], assetManifest: DATA.assetManifest, gridSize: gridSizeOf(), cellSize: 1,
2571
- agentPresentation: {},
2628
+ const stage = await callScene("bootRiver", {
2629
+ passengers: puzzleActorIds, assetManifest: DATA.assetManifest,
2630
+ agentPresentation: agentPresentationFrom((s.worldPayload && s.worldPayload.facts) || []),
2572
2631
  });
2573
2632
  if (seq !== bootSeq) return;
2633
+ riverStage3d = stage === true;
2634
+ el("riverBoard").hidden = riverStage3d;
2574
2635
  camera.selectedId = puzzleActorIds[0] || null;
2575
2636
  renderAll();
2576
2637
  await refreshStoreRows();
@@ -2595,6 +2656,7 @@ function pageScript() {
2595
2656
  expandedAgents.clear();
2596
2657
  const s = scenario();
2597
2658
  applyPuzzleVisibility();
2659
+ riverStage3d = false;
2598
2660
  if (s.puzzle) return bootPuzzle(seq, s);
2599
2661
  const foxes = mintRoster(rosterPrefixFor(s, "predator"), chosenFoxCount());
2600
2662
  const goblins = mintRoster(rosterPrefixFor(s, "prey"), chosenGoblinCount());
@@ -50,14 +50,8 @@ function barPanelHtml(label, id) {
50
50
  </div>`;
51
51
  }
52
52
 
53
- /** The one fenced region carrying every third-party URL this page ever
54
- * names: the source registry's own homepage links (a plain reference list,
55
- * not a fetch) and the embedded registry JSON the source-toggle script
56
- * reads to build its checkbox list and its fetch targets. Nothing fetches
57
- * merely because this markup rendered — the toggles arm what start() is
58
- * allowed to poll, they never poll themselves. */
59
- function sourcesConfigBlockHtml() {
60
- const rows = NEWS_SOURCE_RECORDS.map((r) => {
53
+ function sourceRowsHtml(kind) {
54
+ return NEWS_SOURCE_RECORDS.filter((r) => (kind === "kb" ? r.kind === "kb" : r.kind !== "kb")).map((r) => {
61
55
  const cls = r.kind === "kb" ? "kb" : "contemporary";
62
56
  return `<label class="sourcerow ${cls}" data-source-id="${escapeHtml(r.id)}">
63
57
  <input type="checkbox" data-source-toggle value="${escapeHtml(r.id)}" ${r.enabledByDefault ? "checked" : ""}>
@@ -66,9 +60,24 @@ function sourcesConfigBlockHtml() {
66
60
  <span class="sourcestatus" data-source-status>not yet polled</span>
67
61
  </label>`;
68
62
  }).join("");
63
+ }
64
+
65
+ /** The one fenced region carrying every third-party URL this page ever
66
+ * names, in two groups the visitor can tell apart: the news feeds a poll
67
+ * fetches, and the reference works enrichment looks unknown terms up in. A
68
+ * reference work is never polled — ticking it arms the lookup, nothing
69
+ * else. Nothing fetches merely because this markup rendered. */
70
+ function sourcesConfigBlockHtml() {
69
71
  return `<!-- sources:start -->
70
72
  <div class="sources" id="sourcesConfig" aria-label="News sources">
71
- ${rows}
73
+ <h2 class="tile-label" id="pollRosterLabel">news feeds — polled when you press start or poll once</h2>
74
+ <div class="sourcegroup" id="pollRoster" aria-labelledby="pollRosterLabel">
75
+ ${sourceRowsHtml("contemporary")}
76
+ </div>
77
+ <h2 class="tile-label" id="lookupRosterLabel">reference works — looked up to explain a term, never polled</h2>
78
+ <div class="sourcegroup" id="lookupRoster" aria-labelledby="lookupRosterLabel">
79
+ ${sourceRowsHtml("kb")}
80
+ </div>
72
81
  </div>
73
82
  <script type="application/json" id="newsSourceRecordsJson">${embedJson(NEWS_SOURCE_RECORDS)}</script>
74
83
  <!-- sources:end -->`;
@@ -112,15 +121,17 @@ ${THEME_TOKENS_CSS}
112
121
  select, .urlinput { font-family: ${MONO_STACK}; font-size: .72rem; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: .3rem .55rem; }
113
122
  .urlinput { flex: 1 1 12rem; min-width: 8rem; }
114
123
  .sources { display: flex; flex-direction: column; gap: .3rem; margin: .6rem 0; }
124
+ .sources h2 { margin: .6rem 0 .1rem; }
125
+ .sourcegroup { display: flex; flex-direction: column; gap: .3rem; }
115
126
  .sourcerow { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; font-size: .78rem; padding: .25rem .1rem; min-width: 0; }
116
127
  .sourcerow.kb { opacity: .85; }
117
128
  .sourcename { min-width: 12rem; }
118
129
  @media (max-width: 480px) { .sourcename { min-width: 0; } .sourcestatus { flex-basis: 100%; } }
119
130
  .sourcehome { font-family: ${MONO_STACK}; font-size: .66rem; color: var(--corpus); }
120
131
  .sourcestatus { margin-left: auto; font-family: ${MONO_STACK}; font-size: .66rem; color: var(--muted); }
121
- .reqlog { margin-bottom: 1rem; }
122
- .reqlog table { width: 100%; border-collapse: collapse; font-family: ${MONO_STACK}; font-size: .7rem; }
123
- .reqlog th, .reqlog td { text-align: left; padding: .2rem .4rem; border-bottom: 1px solid var(--line); }
132
+ .reqlog { margin-bottom: 1rem; max-width: 100%; overflow-x: auto; }
133
+ .reqlog table { width: 100%; table-layout: fixed; border-collapse: collapse; font-family: ${MONO_STACK}; font-size: .7rem; }
134
+ .reqlog th, .reqlog td { text-align: left; padding: .2rem .4rem; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
124
135
  .reqlog tbody:empty::after { content: "no requests yet — nothing has fetched before you press start"; }
125
136
  .feedwrap { margin-bottom: 1.2rem; }
126
137
  .feedbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .45rem; }
@@ -196,6 +207,8 @@ ${NEWS_STYLE}
196
207
 
197
208
  <div class="controls" id="controls">
198
209
  <button type="button" class="btn primary" id="newsStart">start polling live sources</button>
210
+ <button type="button" class="btn" id="pollOnce">poll once</button>
211
+ <button type="button" class="btn" id="stopPolling" disabled>stop polling</button>
199
212
  <label class="mono" for="pollInterval">poll every</label>
200
213
  <select id="pollInterval">
201
214
  <option value="0">off</option>
@@ -234,7 +247,7 @@ ${NEWS_STYLE}
234
247
  </div>
235
248
  <div class="pills" id="feedPills" aria-label="Filter the feed by key term"></div>
236
249
  <div class="feed" id="feed" tabindex="0">
237
- <div class="empty" id="feedEmpty">no news items yet — the seed graph builds the first ones once it finishes loading.</div>
250
+ <div class="empty" id="feedEmpty">no news yet — the feed only shows named people, places and events from polled sources. press poll once to fetch some.</div>
238
251
  </div>
239
252
  </section>
240
253
 
@@ -358,6 +371,13 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
358
371
  let feedItems = [];
359
372
  const cardsByItemId = new Map();
360
373
  const activePillTerms = new Set();
374
+ // What an empty feed says: this line before a poll, or after one that
375
+ // reported nothing newsworthy; the purge line once "stop & forget" has
376
+ // emptied the graph of articles, until the next poll (start or poll once)
377
+ // puts content back and reverts it — the same "next action that puts
378
+ // content back" rule the session's own forgotten flag follows.
379
+ const DEFAULT_EMPTY_FEED_TEXT = "no news yet — the feed only shows named people, places and events from polled sources. press poll once to fetch some.";
380
+ let emptyFeedText = DEFAULT_EMPTY_FEED_TEXT;
361
381
 
362
382
  const MAX_PILLS = 12;
363
383
 
@@ -413,7 +433,7 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
413
433
  if (!shown.length) {
414
434
  emptyEl.textContent = feedItems.length
415
435
  ? "no article matches the terms you picked — unpick a pill to see the rest."
416
- : "no news items yet — the seed graph builds the first ones once it finishes loading.";
436
+ : emptyFeedText;
417
437
  }
418
438
  el("feedCount").textContent = shown.length === feedItems.length
419
439
  ? (feedItems.length + " article" + (feedItems.length === 1 ? "" : "s"))
@@ -542,46 +562,97 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
542
562
  button.disabled = false;
543
563
  button.removeAttribute("aria-busy");
544
564
  }
565
+ // "stop polling" is live whenever there is something to stop: a press
566
+ // still in flight, a cycle running, or a timer armed for the next one.
567
+ // The press counter leads the session's own busy flag — a click must be
568
+ // able to stop the cycle it just started, from the same tick.
569
+ let pressesInFlight = 0;
570
+ function syncStopPolling() {
571
+ const session = window.tmct.session;
572
+ el("stopPolling").disabled = !(pressesInFlight > 0 || (session && (session.busy || session.nextPollAt)));
573
+ }
545
574
  function followPhase(label) {
546
575
  el("controlsStatus").textContent = label;
547
- const id = setInterval(function () { el("controlsStatus").textContent = window.tmct.session.phase + "…"; }, 400);
548
- return function () { clearInterval(id); el("controlsStatus").textContent = ""; };
576
+ const id = setInterval(function () {
577
+ el("controlsStatus").textContent = window.tmct.session.phase + "…";
578
+ syncStopPolling();
579
+ }, 400);
580
+ return function () { clearInterval(id); el("controlsStatus").textContent = ""; syncStopPolling(); };
549
581
  }
550
582
 
551
- startBtn.addEventListener("click", async function () {
552
- markBusy(startBtn, "polling…");
553
- const stopFollowing = followPhase("polling…");
583
+ /** One press that fetches: the button reads back busy at once, the
584
+ * status line follows the phase, and everything re-renders after. */
585
+ async function runFetchingPress(button, busyLabel, idleLabel, work) {
586
+ markBusy(button, busyLabel);
587
+ pressesInFlight += 1;
588
+ syncStopPolling();
589
+ const stopFollowing = followPhase(busyLabel);
554
590
  try {
555
- await window.tmct.session.start();
591
+ await work();
556
592
  } finally {
593
+ pressesInFlight -= 1;
557
594
  stopFollowing();
558
- markIdle(startBtn, "poll now");
595
+ markIdle(button, idleLabel);
596
+ syncStopPolling();
559
597
  }
560
598
  await renderAll();
599
+ }
600
+
601
+ startBtn.addEventListener("click", function () {
602
+ emptyFeedText = DEFAULT_EMPTY_FEED_TEXT;
603
+ return runFetchingPress(startBtn, "polling…", "poll now", function () { return window.tmct.session.start(); });
604
+ });
605
+
606
+ el("pollOnce").addEventListener("click", function () {
607
+ emptyFeedText = DEFAULT_EMPTY_FEED_TEXT;
608
+ const pollOnceBtn = el("pollOnce");
609
+ return runFetchingPress(pollOnceBtn, "polling…", "poll once", function () { return window.tmct.session.pollOnce(); });
561
610
  });
562
611
 
563
- el("stopForget").addEventListener("click", function () {
564
- window.tmct.session.revokeConsent();
565
- startBtn.textContent = "start polling live sources";
566
- appendLog("stopped and forgot the start preference — this page reads as first-visit next load");
612
+ el("stopPolling").addEventListener("click", function () {
613
+ const result = window.tmct.session.stopPolling();
614
+ el("controlsStatus").textContent = result.wasRunning ? "stopping…" : "polling stopped";
615
+ appendLog(result.wasRunning
616
+ ? "stopping — the running cycle finishes the article it is on and stops there"
617
+ : "polling stopped — no cycle was running, the next scheduled poll is cancelled");
618
+ syncStopPolling();
619
+ renderSourcesPanel();
620
+ });
621
+
622
+ // The button stays busy until the purge is finished on screen as well as
623
+ // in the store, so "enabled again" really does mean "the articles are
624
+ // gone" rather than "the store call returned".
625
+ el("stopForget").addEventListener("click", async function () {
626
+ const stopForgetBtn = el("stopForget");
627
+ markBusy(stopForgetBtn, "forgetting…");
628
+ try {
629
+ const result = await window.tmct.session.revokeConsent();
630
+ const removed = (result && result.factsRemoved) || 0;
631
+ startBtn.textContent = "start polling live sources";
632
+ feedItems = [];
633
+ cardsByItemId.clear();
634
+ activePillTerms.clear();
635
+ el("feed").querySelectorAll(".item").forEach(function (n) { n.remove(); });
636
+ emptyFeedText = "the articles are gone — press start or poll once to gather news again.";
637
+ renderPills();
638
+ paintFeed();
639
+ appendLog("stopped and forgot: " + removed + " fact(s) from news dropped, articles cleared, this page reads as first-visit next load");
640
+ await renderAll();
641
+ } finally {
642
+ markIdle(stopForgetBtn, "stop & forget");
643
+ syncStopPolling();
644
+ }
567
645
  });
568
646
 
569
647
  el("pollInterval").addEventListener("change", function (ev) {
570
648
  const minutes = window.tmct.session.setInterval(Number(ev.target.value));
571
649
  ev.target.value = String(minutes);
650
+ syncStopPolling();
572
651
  });
573
652
 
574
- el("enrichNow").addEventListener("click", async function () {
653
+ el("enrichNow").addEventListener("click", function () {
575
654
  const enrichBtn = el("enrichNow");
576
- markBusy(enrichBtn, "enriching…");
577
- const stopFollowing = followPhase("enriching…");
578
- try {
579
- await window.tmct.session.enrich();
580
- } finally {
581
- stopFollowing();
582
- markIdle(enrichBtn);
583
- }
584
- await renderAll();
655
+ return runFetchingPress(enrichBtn, "enriching…", "enrich now", function () { return window.tmct.session.enrich(); });
585
656
  });
586
657
 
587
658
  document.querySelectorAll("[data-source-toggle]").forEach(function (box) {
@@ -639,9 +710,11 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
639
710
  window.tmct.news.phase = "seeded";
640
711
  appendLog("phase: seeded");
641
712
  await renderAll();
713
+ syncStopPolling();
642
714
  if (returningVisit) {
643
715
  await window.tmct.session.start();
644
716
  await renderAll();
717
+ syncStopPolling();
645
718
  }
646
719
  el("teachIngest").addEventListener("click", async function () {
647
720
  const text = el("teachText").value;