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

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.
@@ -90,9 +90,9 @@ export function parseArgs(argv) {
90
90
  * — `recognized` true iff runTurn's own record called this a stored assertion,
91
91
  * `rows` the Fact rows it touched (possibly empty for a Rule-only write).
92
92
  */
93
- async function runSentence(sentence, { config, memoryDir }) {
93
+ async function runSentence(sentence, { config, memoryDir, env }) {
94
94
  const before = readFactRows(await loadMemory(memoryDir));
95
- const { record, answer } = await runTurn(sentence, { config, memoryDir, sessionId: uuidv7() });
95
+ const { record, answer } = await runTurn(sentence, { config, memoryDir, sessionId: uuidv7(), env });
96
96
  if (record?.via !== "assert" || record?.miss) return { recognized: false, rows: [], decline: String(answer || "") };
97
97
  const after = readFactRows(await loadMemory(memoryDir));
98
98
  return { recognized: true, rows: touchedFactRows(before, after) };
@@ -619,7 +619,7 @@ function canonicalLines(facts, storeRows) {
619
619
  */
620
620
  export async function ingestText(text, {
621
621
  memoryDir = null, sourceTag = "text", optimistic = false,
622
- canonical = false, config = null, lexicon = null,
622
+ canonical = false, config = null, lexicon = null, observedAt = "",
623
623
  } = {}) {
624
624
  // Paragraphs first (blank-line separated), so the pronoun carry never bridges
625
625
  // a topic break: a fresh paragraph clears the last-subject it would resolve
@@ -628,10 +628,19 @@ export async function ingestText(text, {
628
628
  const paragraphs = String(text ?? "").split(/\n[ \t]*\n/);
629
629
  const ephemeral = !memoryDir;
630
630
  const dir = memoryDir || await mkdtemp(join(tmpdir(), "tmct-ingest-"));
631
- // `dir` may be a backend handle (a sqlite store), not a path — only a real
632
- // directory string can seed loadConfig's cwd; a handle-holding caller passes
633
- // its own config.
634
- const cfg = config || loadConfig(process.env, typeof dir === "string" ? dir : process.cwd());
631
+ // `dir` may be a backend handle (a sqlite store, or a browser's in-memory
632
+ // store), not a path — only a real directory string can seed loadConfig's
633
+ // cwd, and `process` itself doesn't exist in a browser. A handle-holding
634
+ // caller passes its own config; absent that, `graphFile` is moot for a
635
+ // handle anyway (there is no on-disk repo to resolve it against), so a
636
+ // bare default stands in rather than reaching for `loadConfig`/`process`.
637
+ const cfg = config || (typeof dir === "string" ? loadConfig(process.env, dir) : { graphFile: "" });
638
+ // dispatchTurn's own `env = process.env` default parameter is evaluated
639
+ // eagerly, so it throws in a browser the moment runSentence (below) omits
640
+ // `env` — passing it explicitly here (real env in Node, `{}` in a browser)
641
+ // is the same shape `env` already has to take everywhere else this module
642
+ // runs client-side.
643
+ const runEnv = typeof process !== "undefined" && process.env ? process.env : {};
635
644
  const lex = lexicon || loadLexicon();
636
645
  const nlp = optimistic ? winkInstance() : null;
637
646
  // The fact-degree scan below runs whether or not --optimistic is on, so it
@@ -658,7 +667,7 @@ export async function ingestText(text, {
658
667
  // grounds nothing, else the Fact rows it touched.
659
668
  let lastDecline = "";
660
669
  const strictRows = async (form) => {
661
- const { recognized, rows, decline } = await runSentence(form, { config: cfg, memoryDir: dir });
670
+ const { recognized, rows, decline } = await runSentence(form, { config: cfg, memoryDir: dir, env: runEnv });
662
671
  if (!recognized) lastDecline = decline || lastDecline;
663
672
  return recognized && rows.length ? rows : null;
664
673
  };
@@ -699,7 +708,7 @@ export async function ingestText(text, {
699
708
  for (const row of rows) {
700
709
  await appendFact(dir, {
701
710
  subject: row.subject, predicate: row.predicate, object: row.object,
702
- provenance: tag, quantifier: row.quantifier || "",
711
+ provenance: tag, quantifier: row.quantifier || "", observedAt,
703
712
  });
704
713
  extracted.push({
705
714
  subject: row.subject, predicate: row.predicate, object: row.object,
@@ -717,7 +726,7 @@ export async function ingestText(text, {
717
726
  const tag = `optimistic-extract:${sourceTag}`;
718
727
  for (const t of candidates) {
719
728
  await appendFact(dir, {
720
- subject: t.subject, predicate: t.predicate, object: t.object, provenance: tag,
729
+ subject: t.subject, predicate: t.predicate, object: t.object, provenance: tag, observedAt,
721
730
  });
722
731
  optimisticFacts.push({ ...t, provenance: tag, sentence });
723
732
  }
@@ -548,9 +548,14 @@ export function agentCardMarkup(slot) {
548
548
  * `worldPayload` is `{ name, facts, rules, opening }`, the same shape every
549
549
  * other viz page's world payload takes. `agents` is the roster this page
550
550
  * may cast from, `[{ id, role }]` (role is "predator" or "prey" — see
551
- * MUDIII_ROLES). `scenarios` is `[{ label, worldPayload, agents, gridSize }]`
552
- * — a page given none is the one-square case and ships no dropdown, the
553
- * same rule mud-viz.mjs's own renderMudHtml follows. `assetManifest` is
551
+ * MUDIII_ROLES). `scenarios` is `[{ label, worldPayload, agents, gridSize,
552
+ * puzzle }]` — a page given none is the one-square case and ships no
553
+ * dropdown, the same rule mud-viz.mjs's own renderMudHtml follows. `puzzle`
554
+ * is true for a scenario with no town-square layout of its own (the
555
+ * river-crossing puzzle): no roster is minted, no tick ever runs, and the
556
+ * page shows the actor card and the outlook panel's puzzle plan in place of
557
+ * the chase HUD (see this file's own pageScript, `data-hide-when-puzzle`).
558
+ * `assetManifest` is
554
559
  * data/mudiii-assets.json's own `assets` rows, embedded as page data and
555
560
  * resolved client-side by `propPlacementsFrom` — this is the one parameter
556
561
  * mud-viz.mjs's renderMudHtml has no equivalent of, because mud.html has no
@@ -613,28 +618,29 @@ ${PILL_COMPLETE_CSS}
613
618
  <div class="deck-row">
614
619
  <section class="deck" aria-label="simulation controls">
615
620
  <div class="deck-controls">
616
- <button type="button" class="deck-play" id="autoToggle" aria-pressed="false">&#9654; play</button>
617
- <button type="button" id="stepBtn">step</button>
621
+ <button type="button" class="deck-play" id="autoToggle" aria-pressed="false" data-hide-when-puzzle>&#9654; play</button>
622
+ <button type="button" id="stepBtn" data-hide-when-puzzle>step</button>
618
623
  <span class="deck-hint" id="stepHint" hidden>pause to step</span>
619
- <button type="button" id="resetBtn">reset</button>
624
+ <button type="button" id="resetBtn" data-hide-when-puzzle>reset</button>
620
625
  ${scenarioList.length > 1 ? ` <select id="scenarioSelect" class="deck-select" aria-label="which town square to play">
621
626
  ${scenarioList.map((s, i) => ` <option value="${i}"${i === 0 ? " selected" : ""}>${escapeHtml(s.label || scenarioLabel(s.worldPayload?.name))}</option>`).join("\n")}
622
627
  </select>` : ""}
623
628
  <button type="button" id="editModeBtn" aria-pressed="false">edit</button>
624
629
  <button type="button" class="deck-info-btn" id="deckInfoBtn" aria-expanded="false" aria-controls="deckInfoPopup" aria-label="about this demo">?</button>
625
- <span class="mono deck-turns" id="globalTurnCount">turns: 0</span>
630
+ <span class="mono deck-turns" id="globalTurnCount" data-hide-when-puzzle>turns: 0</span>
626
631
  </div>
632
+ <p class="deck-hint mudiii-puzzle-note" id="puzzleNote" hidden>This scenario is a solved-by-search puzzle, not a chase: nothing moves on its own. Follow one of the four passengers below to see its own facts, and the plan panel to see the crossing itself.</p>
627
633
  <div class="deck-body">
628
634
  <div class="deck-panels">
629
635
  <div class="deck-stack deck-stack-1">
630
- <label class="deck-slider">foxes
636
+ <label class="deck-slider" data-hide-when-puzzle>foxes
631
637
  <input type="range" id="playerCountSlider" min="0" max="${PLAYER_COUNTS.length - 1}" step="1"
632
638
  value="${Math.max(0, PLAYER_COUNTS.indexOf(DEFAULT_PLAYER_COUNT))}"
633
639
  list="playerCountTicks" aria-valuetext="${DEFAULT_PLAYER_COUNT} foxes">
634
640
  <datalist id="playerCountTicks">${PLAYER_COUNTS.map((n, i) => `<option value="${i}" label="${n}"></option>`).join("")}</datalist>
635
641
  <span class="mono" id="playerCountValue">${DEFAULT_PLAYER_COUNT}</span>
636
642
  </label>
637
- <label class="deck-slider">goblins
643
+ <label class="deck-slider" data-hide-when-puzzle>goblins
638
644
  <input type="range" id="npcCountSlider" min="${NPC_COUNT_MIN}" max="${NPC_COUNT_MAX}" step="1"
639
645
  value="${DEFAULT_NPC_COUNT}"
640
646
  list="npcCountTicks" aria-valuetext="${DEFAULT_NPC_COUNT} goblins">
@@ -652,7 +658,7 @@ ${openingAgents.map((a) => ` <option value="${escapeHtml(a.id)}">
652
658
  </label>
653
659
  <span class="deck-hint" id="agentSelectHint" hidden>pause to swap</span>
654
660
  </div>
655
- <div class="deck-stack deck-stack-2">
661
+ <div class="deck-stack deck-stack-2" data-hide-when-puzzle>
656
662
  <label class="deck-slider">delay
657
663
  <input type="range" id="delaySlider" min="80" max="2000" step="20" value="${DEFAULT_DELAY_MS}">
658
664
  <span class="mono" id="delayValue">${DEFAULT_DELAY_MS}ms</span>
@@ -667,7 +673,7 @@ ${openingAgents.map((a) => ` <option value="${escapeHtml(a.id)}">
667
673
  <button type="button" data-mode="overhead" aria-pressed="false">overhead</button>
668
674
  </div>
669
675
  </div>
670
- <div class="deck-stack deck-stack-3">
676
+ <div class="deck-stack deck-stack-3" data-hide-when-puzzle>
671
677
  <button type="button" class="pill affordance" id="foodPill" data-command="place food" aria-pressed="false">place food</button>
672
678
  <label class="deck-teach" title="With this on, a sentence like &quot;The fox is at cell-3-4.&quot; writes a fact into the square instead of running as a command.">
673
679
  <input type="checkbox" id="teachToggle">
@@ -675,7 +681,7 @@ ${openingAgents.map((a) => ` <option value="${escapeHtml(a.id)}">
675
681
  </label>
676
682
  </div>
677
683
  </div>
678
- <section class="map-panel" id="mapPanel" aria-label="the town square, from above">
684
+ <section class="map-panel" id="mapPanel" aria-label="the town square, from above" data-hide-when-puzzle>
679
685
  <div class="map-panel-head">
680
686
  <span class="map-panel-title">the square, from above</span>
681
687
  <span class="mono map-panel-turn" id="mapPanelTurn">turn 0</span>
@@ -755,7 +761,7 @@ ${RING_POINTS.map((point) => ` <span class="dir-slot dir-${point}"><button
755
761
  </form>
756
762
  </div>
757
763
  </section>
758
- <div class="hud-row" id="hudRow" aria-label="every agent's own status"></div>
764
+ <div class="hud-row" id="hudRow" aria-label="every agent's own status" data-hide-when-puzzle></div>
759
765
  </main>
760
766
  <script>
761
767
  const MUDIII_PAGE_DATA = ${pageData};
@@ -830,6 +836,7 @@ const MUDIII_STYLE = `
830
836
  .deck-select:disabled:hover { border-color: var(--square-stone-dark); }
831
837
  .deck-hint { font-family: ${MONO_STACK}; font-size: .58rem; text-transform: uppercase; letter-spacing: .08em; color: var(--square-stone-dark); }
832
838
  .deck-hint[hidden] { display: none; }
839
+ .mudiii-puzzle-note { text-transform: none; letter-spacing: normal; font-size: .78rem; font-family: ${SANS_STACK}; margin: 0 0 .6rem; }
833
840
  .deck-play { background: var(--square-ink) !important; color: var(--parchment); border-color: var(--square-ink) !important; padding: .38rem 1.1rem !important; }
834
841
  .deck-play[aria-pressed="true"] { background: var(--square-accent) !important; border-color: var(--square-accent) !important; color: var(--square-ink); }
835
842
  .deck-turns { margin-left: auto; font-size: .74rem; color: var(--square-stone-dark); background: var(--square-stone-dark); background: rgba(43,35,24,.9); color: var(--square-accent); border-radius: 2px; padding: .1rem .5rem; }
@@ -1150,6 +1157,30 @@ function pageScript() {
1150
1157
  let scenarioIndex = 0;
1151
1158
  const scenario = function () { return DATA.scenarios[scenarioIndex]; };
1152
1159
  const gridSizeOf = function () { return scenario().gridSize || DATA.gridSize; };
1160
+ // A puzzle scenario (the river crossing) carries no town-square layout —
1161
+ // no roster, no ticking, no chase — so its four passengers never populate
1162
+ // agentsById the way a minted cast does. hide-when-puzzle marks every
1163
+ // control that means nothing without one.
1164
+ const isPuzzle = function () { return scenario().puzzle === true; };
1165
+ function applyPuzzleVisibility() {
1166
+ const puzzle = isPuzzle();
1167
+ const nodes = document.querySelectorAll("[data-hide-when-puzzle]");
1168
+ for (let i = 0; i < nodes.length; i += 1) nodes[i].hidden = puzzle;
1169
+ el("puzzleNote").hidden = !puzzle;
1170
+ }
1171
+ // Every numbered instance a puzzle world's own facts place — fox-1, goat-1,
1172
+ // cabbage-1, farmer-1 for the river crossing — read straight off rdf:type
1173
+ // rows rather than a roster the engine minted, because a puzzle world has
1174
+ // no roster. Any world's numbered individuals match this, so a later
1175
+ // puzzle scenario needs no new code here, only its own worldPayload.
1176
+ function puzzleActorIdsFrom(facts) {
1177
+ const ids = new Set();
1178
+ (facts || []).forEach(function (f) {
1179
+ if (f && f.predicate === "rdf:type" && /-\\d+$/.test(f.subject)) ids.add(f.subject);
1180
+ });
1181
+ return Array.from(ids).sort();
1182
+ }
1183
+ let puzzleActorIds = [];
1153
1184
 
1154
1185
  // ---- roster minting -----------------------------------------------------
1155
1186
  // The page asks for a COUNT and names the ids it is about to get back: the
@@ -1610,7 +1641,7 @@ function pageScript() {
1610
1641
  // ---- follow dropdown and camera mode ------------------------------------
1611
1642
  function renderAgentSelect() {
1612
1643
  const select = el("agentSelect");
1613
- const ids = Object.keys(agentsById).sort();
1644
+ const ids = isPuzzle() ? puzzleActorIds : Object.keys(agentsById).sort();
1614
1645
  const current = camera.selectedId;
1615
1646
  select.innerHTML = ids.map(function (id) {
1616
1647
  return '<option value="' + esc(id) + '"' + (id === current ? " selected" : "") + '>' + esc(id) + "</option>";
@@ -1732,13 +1763,13 @@ function pageScript() {
1732
1763
  var presentedPredicates = { "mgx:display-name": true, "mgx:model": true };
1733
1764
  (rows || []).forEach(function (row) {
1734
1765
  if (!row || !row.subject || row.subject.indexOf("@") !== -1) return;
1735
- if (row.predicate === "rdf:type" && /-\d+$/.test(row.subject)) {
1766
+ if (row.predicate === "rdf:type" && /-\\d+$/.test(row.subject)) {
1736
1767
  kinds[row.object] = true;
1737
1768
  instanceIds[row.subject] = true;
1738
1769
  return;
1739
1770
  }
1740
1771
  if (!presentedPredicates[row.predicate]) return;
1741
- if (/-\d+$/.test(row.subject)) instanceIds[row.subject] = true;
1772
+ if (/-\\d+$/.test(row.subject)) instanceIds[row.subject] = true;
1742
1773
  else kinds[row.subject] = true;
1743
1774
  });
1744
1775
  var byKind = {};
@@ -2056,6 +2087,12 @@ function pageScript() {
2056
2087
  return "seen";
2057
2088
  }
2058
2089
 
2090
+ // The belief-and-plan half needs a followed agent's own tick entry; the
2091
+ // puzzle-plan half needs only lastOutlook.puzzle, which agentOutlook
2092
+ // computes whether or not any agent has one (see mudiii-turn.mjs's
2093
+ // agentOutlook) — a puzzle scenario carries no roster, so its followed
2094
+ // passenger never has a belief entry, and the puzzle plan would never show
2095
+ // if the two stayed behind the same early return.
2059
2096
  function renderOutlookPanel() {
2060
2097
  const id = el("agentSelect").value;
2061
2098
  const body = el("outlookBeliefBody");
@@ -2065,20 +2102,19 @@ function pageScript() {
2065
2102
  if (!entry) {
2066
2103
  body.innerHTML = '<tr><td class="outlook-empty" colspan="3">Follow an agent above to see what it believes.</td></tr>';
2067
2104
  planText.textContent = "";
2068
- puzzleText.hidden = true;
2069
- return;
2105
+ } else {
2106
+ const subjects = Object.keys(entry.belief).sort();
2107
+ body.innerHTML = subjects.length
2108
+ ? subjects.map(function (subject) {
2109
+ const cell = entry.belief[subject];
2110
+ const howText = beliefOriginText(cell, entry.beliefOrigin[subject]);
2111
+ return '<tr><td class="mono">' + esc(subject) + '</td><td class="mono">' + esc(cell || "\\u2014") + "</td><td>" + esc(howText) + "</td></tr>";
2112
+ }).join("")
2113
+ : '<tr><td class="outlook-empty" colspan="3">' + esc(id) + " is alone on the board \\u2014 nothing else to believe anything about.</td></tr>";
2114
+ const planLine = entry.plan.length ? entry.plan.join(" \\u2192 ") : "holding";
2115
+ planText.textContent = id + "'s plan (" + entry.rung + "): " + planLine + " \\u2014 " + entry.goal;
2070
2116
  }
2071
- const subjects = Object.keys(entry.belief).sort();
2072
- body.innerHTML = subjects.length
2073
- ? subjects.map(function (subject) {
2074
- const cell = entry.belief[subject];
2075
- const howText = beliefOriginText(cell, entry.beliefOrigin[subject]);
2076
- return '<tr><td class="mono">' + esc(subject) + '</td><td class="mono">' + esc(cell || "\\u2014") + "</td><td>" + esc(howText) + "</td></tr>";
2077
- }).join("")
2078
- : '<tr><td class="outlook-empty" colspan="3">' + esc(id) + " is alone on the board \\u2014 nothing else to believe anything about.</td></tr>";
2079
- const planLine = entry.plan.length ? entry.plan.join(" \\u2192 ") : "holding";
2080
- planText.textContent = id + "'s plan (" + entry.rung + "): " + planLine + " \\u2014 " + entry.goal;
2081
- const puzzle = lastOutlook.puzzle;
2117
+ const puzzle = lastOutlook && lastOutlook.puzzle;
2082
2118
  if (!puzzle) {
2083
2119
  puzzleText.hidden = true;
2084
2120
  puzzleText.textContent = "";
@@ -2126,6 +2162,38 @@ function pageScript() {
2126
2162
  el("stepHint").hidden = true;
2127
2163
  }
2128
2164
 
2165
+ // A puzzle scenario's own boot: no roster to mint, no cast to seed, and no
2166
+ // ticking ever starts. The four passengers a puzzle world places are read
2167
+ // straight off its own facts (puzzleActorIdsFrom), the actor card and the
2168
+ // outlook panel work exactly as they do for a chase board's followed
2169
+ // agent, and the plan panel is the whole point — refreshOutlook() below
2170
+ // computes it the same way it always does.
2171
+ async function bootPuzzle(seq, s) {
2172
+ cast = [];
2173
+ props = [];
2174
+ puzzleActorIds = puzzleActorIdsFrom((s.worldPayload && s.worldPayload.facts) || []);
2175
+ const opened = await window.tmct.open(s.worldPayload, {
2176
+ agents: [],
2177
+ epoch: 0,
2178
+ getTeachEnabled: function () { return el("teachToggle").checked; },
2179
+ });
2180
+ if (seq !== bootSeq) return;
2181
+ session = opened;
2182
+ agentsById = {};
2183
+ itemsById = {};
2184
+ el("chatInput").disabled = false;
2185
+ await callScene("boot", {
2186
+ propPlacements: [], assetManifest: DATA.assetManifest, gridSize: gridSizeOf(), cellSize: 1,
2187
+ agentPresentation: {},
2188
+ });
2189
+ if (seq !== bootSeq) return;
2190
+ camera.selectedId = puzzleActorIds[0] || null;
2191
+ renderAll();
2192
+ await refreshOutlook();
2193
+ showStopped();
2194
+ setSceneStatus("this scenario is a puzzle, not a chase \\u2014 follow one of the four passengers below, and its own plan panel shows the crossing.");
2195
+ }
2196
+
2129
2197
  let bootSeq = 0;
2130
2198
  async function boot() {
2131
2199
  const seq = bootSeq += 1;
@@ -2138,6 +2206,8 @@ function pageScript() {
2138
2206
  deferredSceneCamera = null;
2139
2207
  expandedAgents.clear();
2140
2208
  const s = scenario();
2209
+ applyPuzzleVisibility();
2210
+ if (s.puzzle) return bootPuzzle(seq, s);
2141
2211
  const foxes = mintRoster(rosterPrefixFor(s, "predator"), chosenFoxCount());
2142
2212
  const goblins = mintRoster(rosterPrefixFor(s, "prey"), chosenGoblinCount());
2143
2213
  cast = foxes.concat(goblins);
@@ -2191,6 +2261,10 @@ function pageScript() {
2191
2261
  if (ticker) { ticker.pause(); ticker = null; }
2192
2262
  expandedAgents.clear();
2193
2263
  const s = scenario();
2264
+ // No control ever calls this on a puzzle scenario (resetBtn hides itself
2265
+ // via data-hide-when-puzzle), but a puzzle world has nothing to re-cast
2266
+ // either way, so re-booting is the correct answer if this is reached.
2267
+ if (s.puzzle) return boot();
2194
2268
  const foxes = mintRoster(rosterPrefixFor(s, "predator"), chosenFoxCount());
2195
2269
  const goblins = mintRoster(rosterPrefixFor(s, "prey"), chosenGoblinCount());
2196
2270
  cast = foxes.concat(goblins);
@@ -107,9 +107,10 @@ ${THEME_TOKENS_CSS}
107
107
  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; }
108
108
  .urlinput { flex: 1 1 12rem; min-width: 8rem; }
109
109
  .sources { display: flex; flex-direction: column; gap: .3rem; margin: .6rem 0; }
110
- .sourcerow { display: flex; align-items: center; gap: .5rem; font-size: .78rem; padding: .25rem .1rem; }
110
+ .sourcerow { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; font-size: .78rem; padding: .25rem .1rem; min-width: 0; }
111
111
  .sourcerow.kb { opacity: .85; }
112
112
  .sourcename { min-width: 12rem; }
113
+ @media (max-width: 480px) { .sourcename { min-width: 0; } .sourcestatus { flex-basis: 100%; } }
113
114
  .sourcehome { font-family: ${MONO_STACK}; font-size: .66rem; color: var(--corpus); }
114
115
  .sourcestatus { margin-left: auto; font-family: ${MONO_STACK}; font-size: .66rem; color: var(--muted); }
115
116
  .reqlog { margin-bottom: 1rem; }
@@ -366,6 +367,10 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
366
367
  }
367
368
 
368
369
  async function renderAll() {
370
+ // Chips and tiles are cheap synchronous text writes; they lead so a
371
+ // just-finished poll reads back immediately while the feed's own slower,
372
+ // yielding render catches up behind it.
373
+ renderSourcesPanel();
369
374
  await Promise.all([renderFeed(), renderRank(), renderRequestLog()]);
370
375
  renderSourcesPanel();
371
376
  window.tmct.news = Object.assign({}, window.tmct.news, {
@@ -379,20 +384,32 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
379
384
  async function boot() {
380
385
  window.tmct.news = { phase: "seeding", metrics: { timeToFirstArticleMs: null, timeToFirstCompletePollMs: null }, nextPollAt: "" };
381
386
  appendLog("phase: seeding");
387
+ // The wink vendor is what lets ingested prose ground at all — without it
388
+ // every extract runs lexicon-blind and the whole enrich loop misses.
389
+ // Loaded alongside the seed, tolerated as absent the same way chat.html
390
+ // tolerates it, never blocking the page.
391
+ const winkLoad = (async function () {
392
+ try {
393
+ const mod = await Promise.race([
394
+ import("./vendor/wink.js"),
395
+ new Promise(function (resolve, reject) { setTimeout(function () { reject(new Error("wink vendor load timed out")); }, 20000); }),
396
+ ]);
397
+ window.tmct.page.registerWinkModel(function () { return { winkNLP: mod.winkNLP, model: mod.model }; });
398
+ appendLog("wink vendor loaded — prose grounding armed");
399
+ } catch (err) {
400
+ appendLog("wink vendor unavailable — prose grounding runs lexicon-blind");
401
+ }
402
+ })();
382
403
  const outcome = await loadSeedPayload(fetchWithProgress, "./chat-seed.json", SEED_QUERY, function () {});
383
404
  window.tmct.seed = { state: outcome.status.state, facts: outcome.status.facts };
405
+ await winkLoad;
384
406
  await window.tmct.open({ seedPayload: outcome.payload, vocabSeeded: Boolean(outcome.payload) });
385
- window.tmct.news.phase = "seeded";
386
- appendLog("phase: seeded");
387
- await renderAll();
388
407
 
408
+ // Every control binds before the phase flips to "seeded": the first feed
409
+ // render is deliberately slow (it yields per card), and a click that
410
+ // lands in that window must already have its listener.
389
411
  const startBtn = el("newsStart");
390
- const consented = window.tmct.session.consented;
391
- startBtn.textContent = consented ? "poll now" : "start polling live sources";
392
- if (consented) {
393
- await window.tmct.session.start();
394
- await renderAll();
395
- }
412
+ startBtn.textContent = window.tmct.session.consented ? "poll now" : "start polling live sources";
396
413
 
397
414
  startBtn.addEventListener("click", async function () {
398
415
  startBtn.disabled = true;
@@ -425,7 +442,7 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
425
442
  document.querySelectorAll("[data-source-toggle]").forEach(function (box) {
426
443
  box.addEventListener("change", function () {
427
444
  const ids = [].slice.call(document.querySelectorAll("[data-source-toggle]:checked")).map(function (b) { return b.value; });
428
- window.tmct.session.config.sources = ids;
445
+ window.tmct.session.setSources(ids);
429
446
  renderSourcesPanel();
430
447
  });
431
448
  });
@@ -473,6 +490,14 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
473
490
  el("teachStatus").textContent = "loaded " + file.name + " — press ingest";
474
491
  el("teachFile").dataset.name = file.name;
475
492
  });
493
+
494
+ window.tmct.news.phase = "seeded";
495
+ appendLog("phase: seeded");
496
+ await renderAll();
497
+ if (window.tmct.session.consented) {
498
+ await window.tmct.session.start();
499
+ await renderAll();
500
+ }
476
501
  el("teachIngest").addEventListener("click", async function () {
477
502
  const text = el("teachText").value;
478
503
  if (!text.trim()) return;
@@ -46,6 +46,7 @@ import {
46
46
  } from "../domain/term-ledger.mjs";
47
47
  import { syllogise } from "../domain/syllogise.mjs";
48
48
  import { loadLexicon, lookupNoun } from "../domain/grammar/lexicon.mjs";
49
+ import { pluralOf } from "../domain/inflect.mjs";
49
50
  import { provenanceTagToSource, SOURCE_PRIOR } from "../domain/memory/trust.mjs";
50
51
  import {
51
52
  NEWS_SOURCE_RECORDS, DEFAULT_NEWS_SOURCE_IDS, DEFAULT_NEWS_KB_IDS,
@@ -365,7 +366,7 @@ async function ingestSnapshotFacts(ctx, snapshot) {
365
366
  const lex = lexicon || loadLexicon();
366
367
  const text = joinTitleAndSummary(snapshot.title, snapshot.summary);
367
368
  const sourceTag = `news:${snapshot.sourceId}@${snapshot.id}`;
368
- const result = await ingestText(text, { memoryDir, sourceTag, optimistic: true, lexicon: lex });
369
+ const result = await ingestText(text, { memoryDir, sourceTag, optimistic: true, lexicon: lex, observedAt: nowVal });
369
370
  invalidateCache(cache);
370
371
 
371
372
  const allFacts = [...result.extracted, ...result.optimistic];
@@ -768,7 +769,7 @@ export function ingestUploadedFactRows(rows, { fileLabel, now } = {}) {
768
769
  const NEWS_USAGE = "usage: /news [poll|rank|enrich|sources|add <url>|interval <minutes>]";
769
770
 
770
771
  function pluralize(n, word) {
771
- return `${n} ${word}${n === 1 ? "" : "s"}`;
772
+ return `${n} ${n === 1 ? word : pluralOf(word)}`;
772
773
  }
773
774
 
774
775
  function renderFeedText(feed, focus) {