@polycode-projects/the-mechanical-code-talker 5.0.33 → 5.0.35
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 +1 -1
- package/src/domain/choice-question.mjs +91 -0
- package/src/domain/news-feed.mjs +216 -11
- package/src/services/chat.mjs +208 -14
- package/src/services/extract-facts.mjs +124 -15
- package/src/services/news-viz.mjs +164 -19
- package/src/services/news.mjs +17 -3
- package/src/surfaces/web/memory-ask-browser.bundle.js +62 -62
- 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; }
|
|
@@ -125,6 +139,8 @@ ${THEME_TOKENS_CSS}
|
|
|
125
139
|
.item .paragraph { margin: .4rem 0; }
|
|
126
140
|
.item .sources-links { font-size: .74rem; color: var(--muted); }
|
|
127
141
|
.item details.facts summary { font-family: ${MONO_STACK}; font-size: .68rem; color: var(--corpus); cursor: pointer; }
|
|
142
|
+
.item details.background summary { font-family: ${MONO_STACK}; font-size: .68rem; color: var(--muted); cursor: pointer; }
|
|
143
|
+
.item details.background p { margin: .35rem 0 0; color: var(--muted); }
|
|
128
144
|
.item .factrow { font-family: ${MONO_STACK}; font-size: .68rem; padding: .15rem 0; border-bottom: 1px dotted var(--line); }
|
|
129
145
|
.item .facttriple { font-family: ${MONO_STACK}; font-size: .62rem; color: var(--muted); padding-left: .6rem; }
|
|
130
146
|
.empty { color: var(--muted); font-size: .85rem; border: 1px dashed var(--line); border-radius: 6px; padding: .8rem 1rem; }
|
|
@@ -206,8 +222,20 @@ ${NEWS_STYLE}
|
|
|
206
222
|
</table>
|
|
207
223
|
</section>
|
|
208
224
|
|
|
209
|
-
<section class="
|
|
210
|
-
<div class="
|
|
225
|
+
<section class="feedwrap" aria-label="News feed">
|
|
226
|
+
<div class="feedbar">
|
|
227
|
+
<label for="feedSort">sort</label>
|
|
228
|
+
<select id="feedSort">
|
|
229
|
+
<option value="newest" selected>newest first</option>
|
|
230
|
+
<option value="facts">most facts first</option>
|
|
231
|
+
<option value="changed">most changed first</option>
|
|
232
|
+
</select>
|
|
233
|
+
<span class="feedcount" id="feedCount" aria-live="polite"></span>
|
|
234
|
+
</div>
|
|
235
|
+
<div class="pills" id="feedPills" aria-label="Filter the feed by key term"></div>
|
|
236
|
+
<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>
|
|
238
|
+
</div>
|
|
211
239
|
</section>
|
|
212
240
|
|
|
213
241
|
<section class="teach" id="teachPanel">
|
|
@@ -324,13 +352,80 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
324
352
|
}).join("");
|
|
325
353
|
}
|
|
326
354
|
|
|
327
|
-
|
|
355
|
+
// The last built feed and one rendered card per item, so a sort change or a
|
|
356
|
+
// pill toggle re-orders what is already on screen instead of rebuilding
|
|
357
|
+
// every card's fact list from the store again.
|
|
358
|
+
let feedItems = [];
|
|
359
|
+
const cardsByItemId = new Map();
|
|
360
|
+
const activePillTerms = new Set();
|
|
361
|
+
|
|
362
|
+
const MAX_PILLS = 12;
|
|
363
|
+
|
|
364
|
+
function itemMatchesActivePills(item) {
|
|
365
|
+
if (!activePillTerms.size) return true;
|
|
366
|
+
const haystack = (item.hub + " " + item.paragraph).toLowerCase();
|
|
367
|
+
for (const term of activePillTerms) {
|
|
368
|
+
if (item.hub === term || haystack.indexOf(term) !== -1) return true;
|
|
369
|
+
}
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
function sortedFeedItems() {
|
|
374
|
+
const mode = el("feedSort").value;
|
|
375
|
+
const items = feedItems.slice();
|
|
376
|
+
if (mode === "facts") items.sort((a, b) => b.factIds.length - a.factIds.length || (a.hub < b.hub ? -1 : 1));
|
|
377
|
+
else if (mode === "changed") items.sort((a, b) => b.changedCount - a.changedCount || (a.hub < b.hub ? -1 : 1));
|
|
378
|
+
return items;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
function renderPills() {
|
|
382
|
+
const pillsEl = el("feedPills");
|
|
383
|
+
const terms = feedItems
|
|
384
|
+
.slice()
|
|
385
|
+
.sort((a, b) => b.changedCount - a.changedCount || (a.hub < b.hub ? -1 : 1))
|
|
386
|
+
.map((it) => it.hub)
|
|
387
|
+
.slice(0, MAX_PILLS);
|
|
388
|
+
for (const term of [...activePillTerms]) if (terms.indexOf(term) === -1) activePillTerms.delete(term);
|
|
389
|
+
pillsEl.innerHTML = terms.map((term) =>
|
|
390
|
+
'<button type="button" class="pill" data-pill-term="' + esc(term) + '" aria-pressed="'
|
|
391
|
+
+ (activePillTerms.has(term) ? "true" : "false") + '">' + esc(term) + '</button>',
|
|
392
|
+
).join("");
|
|
393
|
+
pillsEl.querySelectorAll("[data-pill-term]").forEach(function (btn) {
|
|
394
|
+
btn.addEventListener("click", function () {
|
|
395
|
+
const term = btn.getAttribute("data-pill-term");
|
|
396
|
+
if (activePillTerms.has(term)) activePillTerms.delete(term); else activePillTerms.add(term);
|
|
397
|
+
btn.setAttribute("aria-pressed", activePillTerms.has(term) ? "true" : "false");
|
|
398
|
+
paintFeed();
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
function paintFeed() {
|
|
328
404
|
const feedEl = el("feed");
|
|
329
405
|
const emptyEl = el("feedEmpty");
|
|
406
|
+
feedEl.querySelectorAll(".item").forEach((n) => n.remove());
|
|
407
|
+
const shown = sortedFeedItems().filter(itemMatchesActivePills);
|
|
408
|
+
for (const item of shown) {
|
|
409
|
+
const card = cardsByItemId.get(item.id);
|
|
410
|
+
if (card) feedEl.appendChild(card);
|
|
411
|
+
}
|
|
412
|
+
emptyEl.hidden = shown.length > 0;
|
|
413
|
+
if (!shown.length) {
|
|
414
|
+
emptyEl.textContent = feedItems.length
|
|
415
|
+
? "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.";
|
|
417
|
+
}
|
|
418
|
+
el("feedCount").textContent = shown.length === feedItems.length
|
|
419
|
+
? (feedItems.length + " article" + (feedItems.length === 1 ? "" : "s"))
|
|
420
|
+
: (shown.length + " of " + feedItems.length + " articles");
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
async function renderFeed() {
|
|
424
|
+
const feedEl = el("feed");
|
|
330
425
|
const feed = await window.tmct.session.buildFeed();
|
|
426
|
+
feedItems = feed.items;
|
|
427
|
+
cardsByItemId.clear();
|
|
331
428
|
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
429
|
for (const item of feed.items) {
|
|
335
430
|
// One yield per card keeps the page clickable while a long feed renders.
|
|
336
431
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
@@ -339,16 +434,31 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
339
434
|
const seedTag = feed.seedFallback ? '<span class="seedtag">from the seed graph — start to poll live sources</span>' : "";
|
|
340
435
|
const sourcesText = item.sources.map((s) => esc(s.title || s.url)).join(", ");
|
|
341
436
|
const facts = await factListHtml(item.factIds);
|
|
437
|
+
const background = item.backgroundParagraph
|
|
438
|
+
? '<details class="background"><summary>what the graph already knew</summary><p>' + esc(item.backgroundParagraph) + '</p></details>'
|
|
439
|
+
: "";
|
|
342
440
|
card.innerHTML =
|
|
343
441
|
'<span class="hub">' + esc(item.hub) + '</span><span class="tier">' + esc(item.tier || "unranked") + '</span>' + seedTag
|
|
344
442
|
+ '<p class="paragraph">' + esc(item.paragraph) + '</p>'
|
|
443
|
+
+ background
|
|
345
444
|
+ (sourcesText ? '<p class="sources-links">sources: ' + sourcesText + '</p>' : "")
|
|
346
445
|
+ '<details class="facts"><summary>' + item.factIds.length + ' facts</summary>' + facts + '</details>';
|
|
347
|
-
|
|
446
|
+
cardsByItemId.set(item.id, card);
|
|
447
|
+
// Each card shows the moment it is built; the paint below re-orders and
|
|
448
|
+
// filters what is already on screen.
|
|
449
|
+
if (itemMatchesActivePills(item)) { el("feedEmpty").hidden = true; feedEl.appendChild(card); }
|
|
348
450
|
}
|
|
451
|
+
renderPills();
|
|
452
|
+
paintFeed();
|
|
349
453
|
setTile("tileFeedItems", feed.items.length, feed.seedFallback ? "from the seed graph" : "live");
|
|
350
454
|
}
|
|
351
455
|
|
|
456
|
+
async function renderGraphTiles() {
|
|
457
|
+
const stats = await window.tmct.session.stats();
|
|
458
|
+
setTile("tileFactsFromNews", stats.factsFromNews, stats.factsFromNews ? "polled, replayed or enriched" : "nothing ingested yet");
|
|
459
|
+
setTile("tileGraphSize", stats.graphSize, "facts in this session's graph");
|
|
460
|
+
}
|
|
461
|
+
|
|
352
462
|
async function renderRank() {
|
|
353
463
|
const rows = await window.tmct.session.rank({ limit: 8 });
|
|
354
464
|
setTile("tileTermsUngrounded", rows.length, rows.length ? "ranked by occurrence" : "none yet");
|
|
@@ -371,7 +481,7 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
371
481
|
// just-finished poll reads back immediately while the feed's own slower,
|
|
372
482
|
// yielding render catches up behind it.
|
|
373
483
|
renderSourcesPanel();
|
|
374
|
-
await Promise.all([renderFeed(), renderRank(), renderRequestLog()]);
|
|
484
|
+
await Promise.all([renderFeed(), renderRank(), renderRequestLog(), renderGraphTiles()]);
|
|
375
485
|
renderSourcesPanel();
|
|
376
486
|
window.tmct.news = Object.assign({}, window.tmct.news, {
|
|
377
487
|
phase: window.tmct.session.phase,
|
|
@@ -409,15 +519,44 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
409
519
|
// render is deliberately slow (it yields per card), and a click that
|
|
410
520
|
// lands in that window must already have its listener.
|
|
411
521
|
const startBtn = el("newsStart");
|
|
412
|
-
|
|
522
|
+
// Read once, here. The first render below takes a while, a visitor can
|
|
523
|
+
// press start inside it, and that press grants consent — so re-reading
|
|
524
|
+
// the flag afterwards to decide whether to replay a returning visit's
|
|
525
|
+
// poll would poll a second time on top of the one already running.
|
|
526
|
+
const returningVisit = window.tmct.session.consented;
|
|
527
|
+
startBtn.textContent = returningVisit ? "poll now" : "start polling live sources";
|
|
528
|
+
|
|
529
|
+
el("feedSort").addEventListener("change", paintFeed);
|
|
530
|
+
|
|
531
|
+
// A poll can run for a while, so the button reads back its own state the
|
|
532
|
+
// moment it is pressed and the status line follows the session's phase
|
|
533
|
+
// until it settles.
|
|
534
|
+
function markBusy(button, label) {
|
|
535
|
+
button.dataset.idleLabel = button.textContent;
|
|
536
|
+
button.textContent = label;
|
|
537
|
+
button.disabled = true;
|
|
538
|
+
button.setAttribute("aria-busy", "true");
|
|
539
|
+
}
|
|
540
|
+
function markIdle(button, label) {
|
|
541
|
+
button.textContent = label || button.dataset.idleLabel || button.textContent;
|
|
542
|
+
button.disabled = false;
|
|
543
|
+
button.removeAttribute("aria-busy");
|
|
544
|
+
}
|
|
545
|
+
function followPhase(label) {
|
|
546
|
+
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 = ""; };
|
|
549
|
+
}
|
|
413
550
|
|
|
414
551
|
startBtn.addEventListener("click", async function () {
|
|
415
|
-
startBtn
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
552
|
+
markBusy(startBtn, "polling…");
|
|
553
|
+
const stopFollowing = followPhase("polling…");
|
|
554
|
+
try {
|
|
555
|
+
await window.tmct.session.start();
|
|
556
|
+
} finally {
|
|
557
|
+
stopFollowing();
|
|
558
|
+
markIdle(startBtn, "poll now");
|
|
559
|
+
}
|
|
421
560
|
await renderAll();
|
|
422
561
|
});
|
|
423
562
|
|
|
@@ -433,9 +572,15 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
433
572
|
});
|
|
434
573
|
|
|
435
574
|
el("enrichNow").addEventListener("click", async function () {
|
|
436
|
-
el("
|
|
437
|
-
|
|
438
|
-
|
|
575
|
+
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
|
+
}
|
|
439
584
|
await renderAll();
|
|
440
585
|
});
|
|
441
586
|
|
|
@@ -494,7 +639,7 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
494
639
|
window.tmct.news.phase = "seeded";
|
|
495
640
|
appendLog("phase: seeded");
|
|
496
641
|
await renderAll();
|
|
497
|
-
if (
|
|
642
|
+
if (returningVisit) {
|
|
498
643
|
await window.tmct.session.start();
|
|
499
644
|
await renderAll();
|
|
500
645
|
}
|
package/src/services/news.mjs
CHANGED
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
import { normFactTerm, normFactPredicate, factIdFor, sha256Bytes } from "../domain/hash.mjs";
|
|
41
41
|
import {
|
|
42
42
|
newsWindowRows, scoreHubs, subgraphAround, buildTermAdjacency, renderNewsParagraph, buildNewsItems, evictNewsFacts,
|
|
43
|
+
conceptTerms, isQuantityTerm,
|
|
43
44
|
} from "../domain/news-feed.mjs";
|
|
44
45
|
import {
|
|
45
46
|
createTermLedger, bumpTerms, rankedTerms, markTerm, groundedSweep, ledgerPayload, ledgerFromPayload,
|
|
@@ -291,9 +292,19 @@ function collectItemSources(subgraphRows, sourcesByFactId) {
|
|
|
291
292
|
/** The item-assembly buildNewsItems runs internally, exposed here so
|
|
292
293
|
* buildFeed's seed-only fallback (S1: score hubs over the WHOLE graph, not
|
|
293
294
|
* just news/research-tagged rows) can reuse the same shape without widening
|
|
294
|
-
* buildNewsItems's own, already-pinned window contract.
|
|
295
|
+
* buildNewsItems's own, already-pinned window contract.
|
|
296
|
+
*
|
|
297
|
+
* The newsworthiness gate's test 2 only (PLAN_NEWS_FEED.md section 17.6): a
|
|
298
|
+
* seed-only graph carries no news rows at all, so tests 1 (reported) and 3
|
|
299
|
+
* (anchored) have nothing to read — every candidate would fail them
|
|
300
|
+
* trivially and empty the page, which is exactly the fallback exists to
|
|
301
|
+
* prevent. Dropping class and bare-quantity terms still holds: neither ever
|
|
302
|
+
* makes a good card title, seed graph or not. */
|
|
295
303
|
function assembleNewsItems(rows, windowRows, { now, limit, sourcesByFactId }) {
|
|
296
|
-
const
|
|
304
|
+
const concepts = conceptTerms(rows);
|
|
305
|
+
const candidates = scoreHubs(rows, windowRows, { limit: Infinity })
|
|
306
|
+
.filter(({ term }) => !concepts.has(term) && !isQuantityTerm(term));
|
|
307
|
+
const hubs = candidates.slice(0, limit);
|
|
297
308
|
const adjacency = buildTermAdjacency(rows);
|
|
298
309
|
const items = hubs.map(({ term, changed }) => {
|
|
299
310
|
const subgraphRows = subgraphAround(rows, term, { adjacency });
|
|
@@ -307,6 +318,8 @@ function assembleNewsItems(rows, windowRows, { now, limit, sourcesByFactId }) {
|
|
|
307
318
|
paragraph: renderNewsParagraph(term, subgraphRows),
|
|
308
319
|
tier: tierOfRows(subgraphRows),
|
|
309
320
|
sources: collectItemSources(subgraphRows, sourcesByFactId),
|
|
321
|
+
background: [],
|
|
322
|
+
backgroundParagraph: "",
|
|
310
323
|
};
|
|
311
324
|
});
|
|
312
325
|
return items.sort((a, b) => (toMs(b.builtAt) - toMs(a.builtAt)) || byId(a, b));
|
|
@@ -784,7 +797,8 @@ function renderFeedText(feed, focus) {
|
|
|
784
797
|
const seedTag = feed.seedFallback ? " (from the seed graph — start to poll live sources)" : "";
|
|
785
798
|
const sourceNames = it.sources.map((s) => s.title || s.url).filter(Boolean);
|
|
786
799
|
const sourcesText = sourceNames.length ? ` sources: ${sourceNames.join(", ")}` : "";
|
|
787
|
-
|
|
800
|
+
const backgroundText = it.backgroundParagraph ? ` what the graph already knew: ${it.backgroundParagraph}` : "";
|
|
801
|
+
return `${i + 1}. ${it.paragraph} (${it.tier || "unranked"})${sourcesText}${seedTag}${backgroundText}`;
|
|
788
802
|
})
|
|
789
803
|
.join("\n");
|
|
790
804
|
}
|