@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
|
@@ -104,6 +104,11 @@ ${THEME_TOKENS_CSS}
|
|
|
104
104
|
.btn:hover { color: var(--ink); border-color: var(--ink); }
|
|
105
105
|
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
|
|
106
106
|
.btn.ghost { border-color: transparent; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
|
|
107
|
+
.btn[disabled] { opacity: .55; cursor: progress; }
|
|
108
|
+
.btn[aria-busy="true"] { opacity: .55; cursor: progress; }
|
|
109
|
+
.btn[aria-busy="true"]::after { content: ""; display: inline-block; width: .5em; height: .5em; margin-left: .45em; border-radius: 50%; background: currentColor; animation: pulse 1s ease-in-out infinite; }
|
|
110
|
+
@keyframes pulse { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }
|
|
111
|
+
@media (prefers-reduced-motion: reduce) { .btn[aria-busy="true"]::after { animation: none; opacity: .7; } }
|
|
107
112
|
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
113
|
.urlinput { flex: 1 1 12rem; min-width: 8rem; }
|
|
109
114
|
.sources { display: flex; flex-direction: column; gap: .3rem; margin: .6rem 0; }
|
|
@@ -117,7 +122,16 @@ ${THEME_TOKENS_CSS}
|
|
|
117
122
|
.reqlog table { width: 100%; border-collapse: collapse; font-family: ${MONO_STACK}; font-size: .7rem; }
|
|
118
123
|
.reqlog th, .reqlog td { text-align: left; padding: .2rem .4rem; border-bottom: 1px solid var(--line); }
|
|
119
124
|
.reqlog tbody:empty::after { content: "no requests yet — nothing has fetched before you press start"; }
|
|
120
|
-
.
|
|
125
|
+
.feedwrap { margin-bottom: 1.2rem; }
|
|
126
|
+
.feedbar { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin-bottom: .45rem; }
|
|
127
|
+
.feedbar label { font-family: ${MONO_STACK}; font-size: .66rem; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
|
|
128
|
+
.feedcount { font-family: ${MONO_STACK}; font-size: .66rem; color: var(--muted); margin-left: auto; }
|
|
129
|
+
.pills { display: flex; flex-wrap: wrap; gap: .3rem; margin-bottom: .5rem; }
|
|
130
|
+
.pill { font-family: ${MONO_STACK}; font-size: .66rem; color: var(--muted); background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: .15rem .6rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
131
|
+
.pill:hover { color: var(--ink); border-color: var(--ink); }
|
|
132
|
+
.pill[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
|
|
133
|
+
.feed { display: flex; flex-direction: column; gap: .7rem; max-height: 62vh; overflow-y: auto; overscroll-behavior: contain; padding-right: .25rem; }
|
|
134
|
+
@media (max-width: 480px) { .feedcount { margin-left: 0; flex-basis: 100%; } .feed { max-height: 70vh; } }
|
|
121
135
|
.item { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; }
|
|
122
136
|
.item .hub { font-weight: 700; font-size: 1.05rem; }
|
|
123
137
|
.item .tier { font-family: ${MONO_STACK}; font-size: .64rem; padding: .05rem .5rem; border-radius: 99px; border: 1px solid var(--line); margin-left: .5rem; }
|
|
@@ -206,8 +220,20 @@ ${NEWS_STYLE}
|
|
|
206
220
|
</table>
|
|
207
221
|
</section>
|
|
208
222
|
|
|
209
|
-
<section class="
|
|
210
|
-
<div class="
|
|
223
|
+
<section class="feedwrap" aria-label="News feed">
|
|
224
|
+
<div class="feedbar">
|
|
225
|
+
<label for="feedSort">sort</label>
|
|
226
|
+
<select id="feedSort">
|
|
227
|
+
<option value="newest" selected>newest first</option>
|
|
228
|
+
<option value="facts">most facts first</option>
|
|
229
|
+
<option value="changed">most changed first</option>
|
|
230
|
+
</select>
|
|
231
|
+
<span class="feedcount" id="feedCount" aria-live="polite"></span>
|
|
232
|
+
</div>
|
|
233
|
+
<div class="pills" id="feedPills" aria-label="Filter the feed by key term"></div>
|
|
234
|
+
<div class="feed" id="feed" tabindex="0">
|
|
235
|
+
<div class="empty" id="feedEmpty">no news items yet — the seed graph builds the first ones once it finishes loading.</div>
|
|
236
|
+
</div>
|
|
211
237
|
</section>
|
|
212
238
|
|
|
213
239
|
<section class="teach" id="teachPanel">
|
|
@@ -324,13 +350,80 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
324
350
|
}).join("");
|
|
325
351
|
}
|
|
326
352
|
|
|
327
|
-
|
|
353
|
+
// The last built feed and one rendered card per item, so a sort change or a
|
|
354
|
+
// pill toggle re-orders what is already on screen instead of rebuilding
|
|
355
|
+
// every card's fact list from the store again.
|
|
356
|
+
let feedItems = [];
|
|
357
|
+
const cardsByItemId = new Map();
|
|
358
|
+
const activePillTerms = new Set();
|
|
359
|
+
|
|
360
|
+
const MAX_PILLS = 12;
|
|
361
|
+
|
|
362
|
+
function itemMatchesActivePills(item) {
|
|
363
|
+
if (!activePillTerms.size) return true;
|
|
364
|
+
const haystack = (item.hub + " " + item.paragraph).toLowerCase();
|
|
365
|
+
for (const term of activePillTerms) {
|
|
366
|
+
if (item.hub === term || haystack.indexOf(term) !== -1) return true;
|
|
367
|
+
}
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function sortedFeedItems() {
|
|
372
|
+
const mode = el("feedSort").value;
|
|
373
|
+
const items = feedItems.slice();
|
|
374
|
+
if (mode === "facts") items.sort((a, b) => b.factIds.length - a.factIds.length || (a.hub < b.hub ? -1 : 1));
|
|
375
|
+
else if (mode === "changed") items.sort((a, b) => b.changedCount - a.changedCount || (a.hub < b.hub ? -1 : 1));
|
|
376
|
+
return items;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function renderPills() {
|
|
380
|
+
const pillsEl = el("feedPills");
|
|
381
|
+
const terms = feedItems
|
|
382
|
+
.slice()
|
|
383
|
+
.sort((a, b) => b.changedCount - a.changedCount || (a.hub < b.hub ? -1 : 1))
|
|
384
|
+
.map((it) => it.hub)
|
|
385
|
+
.slice(0, MAX_PILLS);
|
|
386
|
+
for (const term of [...activePillTerms]) if (terms.indexOf(term) === -1) activePillTerms.delete(term);
|
|
387
|
+
pillsEl.innerHTML = terms.map((term) =>
|
|
388
|
+
'<button type="button" class="pill" data-pill-term="' + esc(term) + '" aria-pressed="'
|
|
389
|
+
+ (activePillTerms.has(term) ? "true" : "false") + '">' + esc(term) + '</button>',
|
|
390
|
+
).join("");
|
|
391
|
+
pillsEl.querySelectorAll("[data-pill-term]").forEach(function (btn) {
|
|
392
|
+
btn.addEventListener("click", function () {
|
|
393
|
+
const term = btn.getAttribute("data-pill-term");
|
|
394
|
+
if (activePillTerms.has(term)) activePillTerms.delete(term); else activePillTerms.add(term);
|
|
395
|
+
btn.setAttribute("aria-pressed", activePillTerms.has(term) ? "true" : "false");
|
|
396
|
+
paintFeed();
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function paintFeed() {
|
|
328
402
|
const feedEl = el("feed");
|
|
329
403
|
const emptyEl = el("feedEmpty");
|
|
404
|
+
feedEl.querySelectorAll(".item").forEach((n) => n.remove());
|
|
405
|
+
const shown = sortedFeedItems().filter(itemMatchesActivePills);
|
|
406
|
+
for (const item of shown) {
|
|
407
|
+
const card = cardsByItemId.get(item.id);
|
|
408
|
+
if (card) feedEl.appendChild(card);
|
|
409
|
+
}
|
|
410
|
+
emptyEl.hidden = shown.length > 0;
|
|
411
|
+
if (!shown.length) {
|
|
412
|
+
emptyEl.textContent = feedItems.length
|
|
413
|
+
? "no article matches the terms you picked — unpick a pill to see the rest."
|
|
414
|
+
: "no news items yet — the seed graph builds the first ones once it finishes loading.";
|
|
415
|
+
}
|
|
416
|
+
el("feedCount").textContent = shown.length === feedItems.length
|
|
417
|
+
? (feedItems.length + " article" + (feedItems.length === 1 ? "" : "s"))
|
|
418
|
+
: (shown.length + " of " + feedItems.length + " articles");
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
async function renderFeed() {
|
|
422
|
+
const feedEl = el("feed");
|
|
330
423
|
const feed = await window.tmct.session.buildFeed();
|
|
424
|
+
feedItems = feed.items;
|
|
425
|
+
cardsByItemId.clear();
|
|
331
426
|
feedEl.querySelectorAll(".item").forEach((n) => n.remove());
|
|
332
|
-
if (!feed.items.length) { emptyEl.hidden = false; setTile("tileFeedItems", 0, "nothing yet"); return; }
|
|
333
|
-
emptyEl.hidden = true;
|
|
334
427
|
for (const item of feed.items) {
|
|
335
428
|
// One yield per card keeps the page clickable while a long feed renders.
|
|
336
429
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -344,11 +437,22 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
344
437
|
+ '<p class="paragraph">' + esc(item.paragraph) + '</p>'
|
|
345
438
|
+ (sourcesText ? '<p class="sources-links">sources: ' + sourcesText + '</p>' : "")
|
|
346
439
|
+ '<details class="facts"><summary>' + item.factIds.length + ' facts</summary>' + facts + '</details>';
|
|
347
|
-
|
|
440
|
+
cardsByItemId.set(item.id, card);
|
|
441
|
+
// Each card shows the moment it is built; the paint below re-orders and
|
|
442
|
+
// filters what is already on screen.
|
|
443
|
+
if (itemMatchesActivePills(item)) { el("feedEmpty").hidden = true; feedEl.appendChild(card); }
|
|
348
444
|
}
|
|
445
|
+
renderPills();
|
|
446
|
+
paintFeed();
|
|
349
447
|
setTile("tileFeedItems", feed.items.length, feed.seedFallback ? "from the seed graph" : "live");
|
|
350
448
|
}
|
|
351
449
|
|
|
450
|
+
async function renderGraphTiles() {
|
|
451
|
+
const stats = await window.tmct.session.stats();
|
|
452
|
+
setTile("tileFactsFromNews", stats.factsFromNews, stats.factsFromNews ? "polled, replayed or enriched" : "nothing ingested yet");
|
|
453
|
+
setTile("tileGraphSize", stats.graphSize, "facts in this session's graph");
|
|
454
|
+
}
|
|
455
|
+
|
|
352
456
|
async function renderRank() {
|
|
353
457
|
const rows = await window.tmct.session.rank({ limit: 8 });
|
|
354
458
|
setTile("tileTermsUngrounded", rows.length, rows.length ? "ranked by occurrence" : "none yet");
|
|
@@ -371,7 +475,7 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
371
475
|
// just-finished poll reads back immediately while the feed's own slower,
|
|
372
476
|
// yielding render catches up behind it.
|
|
373
477
|
renderSourcesPanel();
|
|
374
|
-
await Promise.all([renderFeed(), renderRank(), renderRequestLog()]);
|
|
478
|
+
await Promise.all([renderFeed(), renderRank(), renderRequestLog(), renderGraphTiles()]);
|
|
375
479
|
renderSourcesPanel();
|
|
376
480
|
window.tmct.news = Object.assign({}, window.tmct.news, {
|
|
377
481
|
phase: window.tmct.session.phase,
|
|
@@ -409,15 +513,44 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
409
513
|
// render is deliberately slow (it yields per card), and a click that
|
|
410
514
|
// lands in that window must already have its listener.
|
|
411
515
|
const startBtn = el("newsStart");
|
|
412
|
-
|
|
516
|
+
// Read once, here. The first render below takes a while, a visitor can
|
|
517
|
+
// press start inside it, and that press grants consent — so re-reading
|
|
518
|
+
// the flag afterwards to decide whether to replay a returning visit's
|
|
519
|
+
// poll would poll a second time on top of the one already running.
|
|
520
|
+
const returningVisit = window.tmct.session.consented;
|
|
521
|
+
startBtn.textContent = returningVisit ? "poll now" : "start polling live sources";
|
|
522
|
+
|
|
523
|
+
el("feedSort").addEventListener("change", paintFeed);
|
|
524
|
+
|
|
525
|
+
// A poll can run for a while, so the button reads back its own state the
|
|
526
|
+
// moment it is pressed and the status line follows the session's phase
|
|
527
|
+
// until it settles.
|
|
528
|
+
function markBusy(button, label) {
|
|
529
|
+
button.dataset.idleLabel = button.textContent;
|
|
530
|
+
button.textContent = label;
|
|
531
|
+
button.disabled = true;
|
|
532
|
+
button.setAttribute("aria-busy", "true");
|
|
533
|
+
}
|
|
534
|
+
function markIdle(button, label) {
|
|
535
|
+
button.textContent = label || button.dataset.idleLabel || button.textContent;
|
|
536
|
+
button.disabled = false;
|
|
537
|
+
button.removeAttribute("aria-busy");
|
|
538
|
+
}
|
|
539
|
+
function followPhase(label) {
|
|
540
|
+
el("controlsStatus").textContent = label;
|
|
541
|
+
const id = setInterval(function () { el("controlsStatus").textContent = window.tmct.session.phase + "…"; }, 400);
|
|
542
|
+
return function () { clearInterval(id); el("controlsStatus").textContent = ""; };
|
|
543
|
+
}
|
|
413
544
|
|
|
414
545
|
startBtn.addEventListener("click", async function () {
|
|
415
|
-
startBtn
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
546
|
+
markBusy(startBtn, "polling…");
|
|
547
|
+
const stopFollowing = followPhase("polling…");
|
|
548
|
+
try {
|
|
549
|
+
await window.tmct.session.start();
|
|
550
|
+
} finally {
|
|
551
|
+
stopFollowing();
|
|
552
|
+
markIdle(startBtn, "poll now");
|
|
553
|
+
}
|
|
421
554
|
await renderAll();
|
|
422
555
|
});
|
|
423
556
|
|
|
@@ -433,9 +566,15 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
433
566
|
});
|
|
434
567
|
|
|
435
568
|
el("enrichNow").addEventListener("click", async function () {
|
|
436
|
-
el("
|
|
437
|
-
|
|
438
|
-
|
|
569
|
+
const enrichBtn = el("enrichNow");
|
|
570
|
+
markBusy(enrichBtn, "enriching…");
|
|
571
|
+
const stopFollowing = followPhase("enriching…");
|
|
572
|
+
try {
|
|
573
|
+
await window.tmct.session.enrich();
|
|
574
|
+
} finally {
|
|
575
|
+
stopFollowing();
|
|
576
|
+
markIdle(enrichBtn);
|
|
577
|
+
}
|
|
439
578
|
await renderAll();
|
|
440
579
|
});
|
|
441
580
|
|
|
@@ -494,7 +633,7 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
494
633
|
window.tmct.news.phase = "seeded";
|
|
495
634
|
appendLog("phase: seeded");
|
|
496
635
|
await renderAll();
|
|
497
|
-
if (
|
|
636
|
+
if (returningVisit) {
|
|
498
637
|
await window.tmct.session.start();
|
|
499
638
|
await renderAll();
|
|
500
639
|
}
|