@polycode-projects/the-mechanical-code-talker 5.0.26 → 5.0.28
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/corpus/worlds/index.json.gz +0 -0
- package/corpus/worlds/manifest.json +27 -17
- package/corpus/worlds/shards/river-crossing.jsonl.gz +0 -0
- package/corpus/worlds/shards/town-square-chapel.jsonl.gz +0 -0
- package/corpus/worlds/shards/town-square-market.jsonl.gz +0 -0
- package/corpus/worlds/shards/town-square.jsonl.gz +0 -0
- package/corpus/worlds/src/river-crossing.jsonl +29 -0
- package/corpus/worlds/src/town-square-chapel.jsonl +12 -8
- package/corpus/worlds/src/town-square-market.jsonl +12 -8
- package/corpus/worlds/src/town-square.jsonl +12 -8
- package/package.json +2 -1
- package/src/adapters/memory/inspect.mjs +37 -0
- package/src/domain/agent-traits.mjs +282 -0
- package/src/domain/ask.mjs +19 -6
- package/src/domain/choice-question.mjs +135 -6
- package/src/domain/codegraph.mjs +8 -1
- package/src/domain/el-classify.mjs +39 -7
- package/src/domain/fact-phrase.mjs +7 -4
- package/src/domain/interpret/normalize.mjs +58 -2
- package/src/domain/town-square-world.mjs +44 -19
- package/src/services/adventure.mjs +5 -16
- package/src/services/agent-editor.mjs +216 -0
- package/src/services/chat-session.mjs +26 -5
- package/src/services/chat.mjs +221 -58
- package/src/services/mudiii-scene.mjs +32 -5
- package/src/services/mudiii-turn.mjs +7 -3
- package/src/services/mudiii-viz.mjs +215 -1
- package/src/services/news-viz.mjs +489 -0
- package/src/services/predator-prey.mjs +157 -24
- package/src/surfaces/web/chat-browser-entry.mjs +69 -3
- package/src/surfaces/web/memory-ask-browser.bundle.js +155 -155
- package/src/surfaces/web/mudiii-browser-entry.mjs +35 -0
- package/src/surfaces/web/news-browser-entry.mjs +384 -0
- package/src/surfaces/web/turn-session.mjs +13 -9
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
// news-viz.mjs — news.html: a dashboard over the news capability
|
|
2
|
+
// (PLAN_NEWS_FEED.md section 13), on the ledger.html dashboard precedent
|
|
3
|
+
// (src/services/ledger-viz.mjs: `.dash`/`.kpirow`/`.tile`/`.tile-bars`, the
|
|
4
|
+
// same THEME_TOKENS_CSS palette) with chat.html's seed-loading shell
|
|
5
|
+
// (src/services/chat-page-viz.mjs: SEED_STAMP/SEED_BYTES, the tmct.seed
|
|
6
|
+
// phase pill, loadSeedPayload/fetchWithProgress).
|
|
7
|
+
//
|
|
8
|
+
// The page's one behavioural promise, restated everywhere it matters: NO
|
|
9
|
+
// third-party request fires before the visitor presses start (or, on a
|
|
10
|
+
// returning visit, before the page replays that same consent). Every
|
|
11
|
+
// `https://` string this renderer emits — every source's homepage link, the
|
|
12
|
+
// embedded source-registry JSON the source-toggle list reads — sits inside
|
|
13
|
+
// the ONE fenced block `<!-- sources:start -->` … `<!-- sources:end -->`, so
|
|
14
|
+
// that promise is mechanically checkable: nothing outside that block ever
|
|
15
|
+
// names a third party.
|
|
16
|
+
//
|
|
17
|
+
// Every fetched or user-supplied string this page will ever show (a feed
|
|
18
|
+
// item's title/summary, a source's display name, an uploaded fact row) goes
|
|
19
|
+
// through escapeHtml at render time — the second half of the two-layer
|
|
20
|
+
// sanitisation rule (constitution, PLAN_NEWS_FEED.md section 3); the first
|
|
21
|
+
// half (stripMarkup at parse time) already ran in the domain/adapter layers
|
|
22
|
+
// this page's engine calls.
|
|
23
|
+
import {
|
|
24
|
+
THEME_TOKENS_CSS, MONO_STACK, escapeHtml, embedJson, demoEyebrowHtml, EYEBROW_LINKS_CSS,
|
|
25
|
+
} from "./viz-theme.mjs";
|
|
26
|
+
import { loadSeedPayload, fetchWithProgress, factTripleParts } from "./memory-panel-viz.mjs";
|
|
27
|
+
import { predicatePhrase, factSentence, FACT_PREDICATE_PHRASES } from "../domain/fact-phrase.mjs";
|
|
28
|
+
import { NEWS_SOURCE_RECORDS } from "../adapters/corpus/news-sources.mjs";
|
|
29
|
+
|
|
30
|
+
const DEFAULT_TITLE = "tmct news — a dashboard over the graph, fed on your say-so";
|
|
31
|
+
|
|
32
|
+
const DASH_SANS_STACK = `-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif`;
|
|
33
|
+
|
|
34
|
+
/** One `.tile` cell for the KPI row — the zero-state every tile renders in
|
|
35
|
+
* before the first poll, since the dashboard's own JS overwrites every
|
|
36
|
+
* number once the session opens. Static markup only; the live numbers are
|
|
37
|
+
* a client-side re-render (see the inline script's `renderAll`). */
|
|
38
|
+
function kpiTileHtml(label, id) {
|
|
39
|
+
return `<div class="tile" id="${escapeHtml(id)}">
|
|
40
|
+
<span class="tile-label">${escapeHtml(label)}</span>
|
|
41
|
+
<span class="tile-value" data-value>0</span>
|
|
42
|
+
<span class="tile-sub" data-sub></span>
|
|
43
|
+
</div>`;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function barPanelHtml(label, id) {
|
|
47
|
+
return `<div class="tile tile-bars" id="${escapeHtml(id)}">
|
|
48
|
+
<span class="tile-label">${escapeHtml(label)}</span>
|
|
49
|
+
<div class="bundlebars" data-bars><span class="tile-sub">nothing yet</span></div>
|
|
50
|
+
</div>`;
|
|
51
|
+
}
|
|
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) => {
|
|
61
|
+
const cls = r.kind === "kb" ? "kb" : "contemporary";
|
|
62
|
+
return `<label class="sourcerow ${cls}" data-source-id="${escapeHtml(r.id)}">
|
|
63
|
+
<input type="checkbox" data-source-toggle value="${escapeHtml(r.id)}" ${r.enabledByDefault ? "checked" : ""}>
|
|
64
|
+
<span class="sourcename">${escapeHtml(r.name)}</span>
|
|
65
|
+
<a class="sourcehome" href="${escapeHtml(r.homepage)}" target="_blank" rel="noopener">homepage</a>
|
|
66
|
+
<span class="sourcestatus" data-source-status>not yet polled</span>
|
|
67
|
+
</label>`;
|
|
68
|
+
}).join("");
|
|
69
|
+
return `<!-- sources:start -->
|
|
70
|
+
<div class="sources" id="sourcesConfig" aria-label="News sources">
|
|
71
|
+
${rows}
|
|
72
|
+
</div>
|
|
73
|
+
<script type="application/json" id="newsSourceRecordsJson">${embedJson(NEWS_SOURCE_RECORDS)}</script>
|
|
74
|
+
<!-- sources:end -->`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const NEWS_STYLE = `
|
|
78
|
+
${THEME_TOKENS_CSS}
|
|
79
|
+
html { background: var(--bg); }
|
|
80
|
+
body { margin: 0; background: var(--bg); color: var(--ink); font-family: ${DASH_SANS_STACK}; font-size: 15px; line-height: 1.5; }
|
|
81
|
+
.mono { font-family: ${MONO_STACK}; }
|
|
82
|
+
main { max-width: 1100px; margin: 0 auto; padding: 1.4rem 1.2rem 3rem; }
|
|
83
|
+
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
|
|
84
|
+
.eyebrow { font-family: ${MONO_STACK}; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); display: flex; flex-wrap: wrap; gap: .4em 1.2em; margin-bottom: .9rem; }
|
|
85
|
+
${EYEBROW_LINKS_CSS}
|
|
86
|
+
button { font: inherit; color: inherit; background: none; border: none; padding: 0; cursor: pointer; }
|
|
87
|
+
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--corpus); outline-offset: 2px; border-radius: 4px; }
|
|
88
|
+
.dash { display: flex; flex-direction: column; gap: .6rem; margin: 0 0 1.1rem; }
|
|
89
|
+
.kpirow { display: grid; grid-template-columns: repeat(5, 1fr); gap: .6rem; }
|
|
90
|
+
.barpanels { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
|
|
91
|
+
@media (max-width: 900px) { .kpirow { grid-template-columns: repeat(2, 1fr); } .barpanels { grid-template-columns: 1fr; } }
|
|
92
|
+
.tile { background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--line); border-radius: 6px; padding: .6rem .75rem .65rem; display: flex; flex-direction: column; gap: .18rem; min-width: 0; }
|
|
93
|
+
.tile-label { font-family: ${MONO_STACK}; font-size: .62rem; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
|
|
94
|
+
.tile-value { font-family: ${MONO_STACK}; font-size: 1.5rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.15; }
|
|
95
|
+
.tile-sub { font-family: ${MONO_STACK}; font-size: .66rem; color: var(--muted); }
|
|
96
|
+
.bundlebars { display: flex; flex-direction: column; gap: .26rem; margin-top: .4rem; }
|
|
97
|
+
.bbar { display: grid; grid-template-columns: minmax(0,1fr) 3.4rem 1.6rem; align-items: center; gap: .4rem; font-family: ${MONO_STACK}; font-size: .7rem; }
|
|
98
|
+
.bblabel { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
99
|
+
.bbtrack { background: var(--line); border-radius: 99px; height: 5px; overflow: hidden; }
|
|
100
|
+
.bbfill { display: block; height: 100%; background: var(--ink); opacity: .6; border-radius: 99px; }
|
|
101
|
+
.bbn { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
|
|
102
|
+
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: .6rem .7rem; margin-bottom: 1rem; }
|
|
103
|
+
.btn { font-family: ${MONO_STACK}; font-size: .72rem; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: .3rem .65rem; background: var(--bg); }
|
|
104
|
+
.btn:hover { color: var(--ink); border-color: var(--ink); }
|
|
105
|
+
.btn.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
|
|
106
|
+
.btn.ghost { border-color: transparent; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
|
|
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
|
+
.urlinput { flex: 1 1 12rem; min-width: 8rem; }
|
|
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; }
|
|
111
|
+
.sourcerow.kb { opacity: .85; }
|
|
112
|
+
.sourcename { min-width: 12rem; }
|
|
113
|
+
.sourcehome { font-family: ${MONO_STACK}; font-size: .66rem; color: var(--corpus); }
|
|
114
|
+
.sourcestatus { margin-left: auto; font-family: ${MONO_STACK}; font-size: .66rem; color: var(--muted); }
|
|
115
|
+
.reqlog { margin-bottom: 1rem; }
|
|
116
|
+
.reqlog table { width: 100%; border-collapse: collapse; font-family: ${MONO_STACK}; font-size: .7rem; }
|
|
117
|
+
.reqlog th, .reqlog td { text-align: left; padding: .2rem .4rem; border-bottom: 1px solid var(--line); }
|
|
118
|
+
.reqlog tbody:empty::after { content: "no requests yet — nothing has fetched before you press start"; }
|
|
119
|
+
.feed { display: flex; flex-direction: column; gap: .7rem; margin-bottom: 1.2rem; }
|
|
120
|
+
.item { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; }
|
|
121
|
+
.item .hub { font-weight: 700; font-size: 1.05rem; }
|
|
122
|
+
.item .tier { font-family: ${MONO_STACK}; font-size: .64rem; padding: .05rem .5rem; border-radius: 99px; border: 1px solid var(--line); margin-left: .5rem; }
|
|
123
|
+
.item .seedtag { font-family: ${MONO_STACK}; font-size: .64rem; color: var(--muted); margin-left: .5rem; }
|
|
124
|
+
.item .paragraph { margin: .4rem 0; }
|
|
125
|
+
.item .sources-links { font-size: .74rem; color: var(--muted); }
|
|
126
|
+
.item details.facts summary { font-family: ${MONO_STACK}; font-size: .68rem; color: var(--corpus); cursor: pointer; }
|
|
127
|
+
.item .factrow { font-family: ${MONO_STACK}; font-size: .68rem; padding: .15rem 0; border-bottom: 1px dotted var(--line); }
|
|
128
|
+
.item .facttriple { font-family: ${MONO_STACK}; font-size: .62rem; color: var(--muted); padding-left: .6rem; }
|
|
129
|
+
.empty { color: var(--muted); font-size: .85rem; border: 1px dashed var(--line); border-radius: 6px; padding: .8rem 1rem; }
|
|
130
|
+
.teach { background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: .7rem .85rem; margin-bottom: 1rem; }
|
|
131
|
+
.teach textarea { width: 100%; box-sizing: border-box; min-height: 90px; font-family: ${MONO_STACK}; font-size: .76rem; background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 6px; padding: .5rem .6rem; }
|
|
132
|
+
.teach .teachrow { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; align-items: center; }
|
|
133
|
+
.pagelog { font-family: ${MONO_STACK}; font-size: .68rem; color: var(--muted); max-height: 140px; overflow-y: auto; border-top: 1px solid var(--line); padding-top: .4rem; }
|
|
134
|
+
`;
|
|
135
|
+
|
|
136
|
+
/** `renderNewsHtml({ title, seedStamp, seedBytes, digestStructures })` — one
|
|
137
|
+
* self-contained document: the dashboard, the controls row (start / poll
|
|
138
|
+
* interval / stop & forget / source toggles / add-by-URL / enrich now / the
|
|
139
|
+
* two fixture-replay demo buttons), the request log, the feed, and the
|
|
140
|
+
* teach panel. `seedStamp`/`seedBytes` feed the same chat-seed.json loading
|
|
141
|
+
* contract chat.html's own shell uses (chat-page-viz.mjs); `digestStructures`
|
|
142
|
+
* rides through unused today, the same build-time plumbing every other
|
|
143
|
+
* generated page threads even before it has its own digest affordance. */
|
|
144
|
+
export function renderNewsHtml({ title = DEFAULT_TITLE, seedStamp = "", seedBytes = 0, digestStructures = [] } = {}) {
|
|
145
|
+
const digestJson = embedJson(Array.isArray(digestStructures) ? digestStructures : []);
|
|
146
|
+
const factPhrasesJson = embedJson(FACT_PREDICATE_PHRASES);
|
|
147
|
+
|
|
148
|
+
return `<!doctype html>
|
|
149
|
+
<html lang="en">
|
|
150
|
+
<head>
|
|
151
|
+
<meta charset="utf-8">
|
|
152
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
153
|
+
<title>${escapeHtml(title)}</title>
|
|
154
|
+
<link rel="icon" href="./favicon.svg" type="image/svg+xml">
|
|
155
|
+
<link rel="icon" href="./favicon.ico" sizes="any">
|
|
156
|
+
<link rel="apple-touch-icon" href="./apple-touch-icon.png">
|
|
157
|
+
<style>
|
|
158
|
+
${NEWS_STYLE}
|
|
159
|
+
</style>
|
|
160
|
+
</head>
|
|
161
|
+
<body>
|
|
162
|
+
<main>
|
|
163
|
+
<div class="eyebrow"><span>${demoEyebrowHtml("news", "news")}</span><span id="seedPill" data-sub></span></div>
|
|
164
|
+
<h1 class="visually-hidden">news — a dashboard over the graph, fed on your say-so</h1>
|
|
165
|
+
|
|
166
|
+
<section class="dash" id="dash" aria-label="News metrics">
|
|
167
|
+
<div class="kpirow">
|
|
168
|
+
${kpiTileHtml("feed.items", "tileFeedItems")}
|
|
169
|
+
${kpiTileHtml("terms.ungrounded", "tileTermsUngrounded")}
|
|
170
|
+
${kpiTileHtml("facts.from-news", "tileFactsFromNews")}
|
|
171
|
+
${kpiTileHtml("graph.size", "tileGraphSize")}
|
|
172
|
+
${kpiTileHtml("sources.live", "tileSourcesLive")}
|
|
173
|
+
</div>
|
|
174
|
+
<div class="barpanels">
|
|
175
|
+
${barPanelHtml("terms.ranked", "panelTermsRanked")}
|
|
176
|
+
${barPanelHtml("sources.per-source", "panelSourcesPerSource")}
|
|
177
|
+
</div>
|
|
178
|
+
</section>
|
|
179
|
+
|
|
180
|
+
<div class="controls" id="controls">
|
|
181
|
+
<button type="button" class="btn primary" id="newsStart">start polling live sources</button>
|
|
182
|
+
<label class="mono" for="pollInterval">poll every</label>
|
|
183
|
+
<select id="pollInterval">
|
|
184
|
+
<option value="0">off</option>
|
|
185
|
+
<option value="5">5 min</option>
|
|
186
|
+
<option value="15" selected>15 min</option>
|
|
187
|
+
<option value="60">60 min</option>
|
|
188
|
+
</select>
|
|
189
|
+
<button type="button" class="btn ghost" id="stopForget">stop & forget</button>
|
|
190
|
+
<button type="button" class="btn" id="enrichNow">enrich now</button>
|
|
191
|
+
<input type="text" class="urlinput" id="addSourceUrl" placeholder="add a source by url (https only)" autocomplete="off" spellcheck="false">
|
|
192
|
+
<button type="button" class="btn" id="addSourceBtn">add</button>
|
|
193
|
+
<button type="button" class="btn" id="replayNyt">replay recorded NYT sample</button>
|
|
194
|
+
<button type="button" class="btn" id="replayWikipedia">replay recorded Wikipedia sample</button>
|
|
195
|
+
<span class="mono" id="controlsStatus" aria-live="polite"></span>
|
|
196
|
+
</div>
|
|
197
|
+
|
|
198
|
+
${sourcesConfigBlockHtml()}
|
|
199
|
+
|
|
200
|
+
<section class="reqlog" id="requestLog" aria-label="Request log">
|
|
201
|
+
<h2 class="tile-label">request log</h2>
|
|
202
|
+
<table>
|
|
203
|
+
<thead><tr><th>url</th><th>at</th><th>bytes</th><th>status</th></tr></thead>
|
|
204
|
+
<tbody id="requestLogBody"></tbody>
|
|
205
|
+
</table>
|
|
206
|
+
</section>
|
|
207
|
+
|
|
208
|
+
<section class="feed" id="feed" aria-label="News feed">
|
|
209
|
+
<div class="empty" id="feedEmpty">no news items yet — the seed graph builds the first ones once it finishes loading.</div>
|
|
210
|
+
</section>
|
|
211
|
+
|
|
212
|
+
<section class="teach" id="teachPanel">
|
|
213
|
+
<h2 class="tile-label">teach the graph</h2>
|
|
214
|
+
<textarea id="teachText" spellcheck="false" aria-label="Text or fact rows to ingest" placeholder="Paste prose, or drop a .txt/.md/.json/.jsonl file below."></textarea>
|
|
215
|
+
<div class="teachrow">
|
|
216
|
+
<button type="button" class="btn" id="exampleProse">example: prose</button>
|
|
217
|
+
<button type="button" class="btn" id="exampleJsonl">example: facts (.jsonl)</button>
|
|
218
|
+
<button type="button" class="btn" id="teachBrowse">browse…</button>
|
|
219
|
+
<input type="file" id="teachFile" accept=".txt,.md,.json,.jsonl" hidden>
|
|
220
|
+
<button type="button" class="btn primary" id="teachIngest">ingest</button>
|
|
221
|
+
<span class="mono" id="teachStatus" aria-live="polite"></span>
|
|
222
|
+
</div>
|
|
223
|
+
</section>
|
|
224
|
+
|
|
225
|
+
<div class="pagelog" id="pageLog" aria-live="polite"></div>
|
|
226
|
+
</main>
|
|
227
|
+
<script>
|
|
228
|
+
const DIGEST_STRUCTURES = ${digestJson};
|
|
229
|
+
const SEED_STAMP = ${JSON.stringify(seedStamp)};
|
|
230
|
+
const SEED_QUERY = SEED_STAMP ? "?b=" + SEED_STAMP : "";
|
|
231
|
+
const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
232
|
+
</script>
|
|
233
|
+
<!--
|
|
234
|
+
news-browser.bundle.js (built by scripts/build-news-bundle.mjs) publishes
|
|
235
|
+
window.tmct — createNewsSession as tmct.open(), every session verb as
|
|
236
|
+
tmct.session.<verb>(). The inline script below only wires DOM to that
|
|
237
|
+
surface; it never touches the network, the memory store, or the news
|
|
238
|
+
engine directly, so every third-party request this page ever makes is
|
|
239
|
+
traceable to one of the session's own consent-gated methods.
|
|
240
|
+
-->
|
|
241
|
+
<script src="./news-browser.bundle.js"></script>
|
|
242
|
+
<script>
|
|
243
|
+
(function () {
|
|
244
|
+
"use strict";
|
|
245
|
+
const el = (id) => document.getElementById(id);
|
|
246
|
+
const esc = ${escapeHtml.toString()};
|
|
247
|
+
const FACT_PREDICATE_PHRASES = ${factPhrasesJson};
|
|
248
|
+
const predicatePhrase = ${predicatePhrase.toString()};
|
|
249
|
+
const factSentence = ${factSentence.toString()};
|
|
250
|
+
const factTripleParts = ${factTripleParts.toString()};
|
|
251
|
+
const fetchWithProgress = ${fetchWithProgress.toString()};
|
|
252
|
+
const loadSeedPayload = ${loadSeedPayload.toString()};
|
|
253
|
+
|
|
254
|
+
function appendLog(text) {
|
|
255
|
+
const line = document.createElement("div");
|
|
256
|
+
line.textContent = text;
|
|
257
|
+
el("pageLog").appendChild(line);
|
|
258
|
+
el("pageLog").scrollTop = el("pageLog").scrollHeight;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function microbars(items) {
|
|
262
|
+
if (!items.length) return '<span class="tile-sub">nothing yet</span>';
|
|
263
|
+
const max = items.reduce((m, it) => Math.max(m, it.count), 0) || 1;
|
|
264
|
+
return items.map((it) =>
|
|
265
|
+
'<div class="bbar"><span class="bblabel">' + esc(it.label) + '</span><span class="bbtrack"><span class="bbfill" style="width:' + Math.min(100, (it.count / max) * 100).toFixed(1) + '%"></span></span><span class="bbn">' + it.count + '</span></div>',
|
|
266
|
+
).join("");
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function setTile(id, value, sub) {
|
|
270
|
+
const node = el(id);
|
|
271
|
+
if (!node) return;
|
|
272
|
+
node.querySelector("[data-value]").textContent = String(value);
|
|
273
|
+
const subEl = node.querySelector("[data-sub]");
|
|
274
|
+
if (subEl && sub != null) subEl.textContent = sub;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function setBars(id, items) {
|
|
278
|
+
const node = el(id);
|
|
279
|
+
if (!node) return;
|
|
280
|
+
node.querySelector("[data-bars]").innerHTML = microbars(items);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
async function renderRequestLog() {
|
|
284
|
+
const body = el("requestLogBody");
|
|
285
|
+
body.innerHTML = "";
|
|
286
|
+
for (const row of (window.tmct.session ? window.tmct.session.requestLog : []).slice(0, 50)) {
|
|
287
|
+
const tr = document.createElement("tr");
|
|
288
|
+
tr.innerHTML = "<td>" + esc(row.url) + "</td><td>" + esc(row.at) + "</td><td>" + esc(String(row.bytes)) + "</td><td>" + esc(row.status) + "</td>";
|
|
289
|
+
body.appendChild(tr);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
function renderSourceStatus() {
|
|
294
|
+
const health = window.tmct.session ? window.tmct.session.health : [];
|
|
295
|
+
const byId = new Map(health.map((h) => [h.sourceId, h]));
|
|
296
|
+
const config = window.tmct.session ? window.tmct.session.config : { sources: [] };
|
|
297
|
+
const enabled = new Set(config.sources);
|
|
298
|
+
document.querySelectorAll("[data-source-id]").forEach((row) => {
|
|
299
|
+
const id = row.getAttribute("data-source-id");
|
|
300
|
+
const h = byId.get(id);
|
|
301
|
+
const statusEl = row.querySelector("[data-source-status]");
|
|
302
|
+
let text = "off";
|
|
303
|
+
if (enabled.has(id)) {
|
|
304
|
+
if (h && h.autoDisabled) text = "auto-disabled";
|
|
305
|
+
else if (h && h.browserBlocked) text = "source does not permit browser access";
|
|
306
|
+
else if (h && h.lastStatus) text = h.lastStatus;
|
|
307
|
+
else text = "not yet polled";
|
|
308
|
+
}
|
|
309
|
+
statusEl.textContent = text;
|
|
310
|
+
});
|
|
311
|
+
return { byId, enabled };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
async function factListHtml(factIds) {
|
|
315
|
+
const rows = await window.tmct.session.factRows(factIds);
|
|
316
|
+
return rows.map((row) => {
|
|
317
|
+
const triple = factTripleParts(row);
|
|
318
|
+
return '<div class="factrow">' + esc(factSentence(row))
|
|
319
|
+
+ '<details><summary>triple</summary><div class="facttriple">'
|
|
320
|
+
+ esc(triple.subject) + " | " + esc(triple.predicate) + " | " + esc(triple.object)
|
|
321
|
+
+ " (" + esc(row.provenance || "") + ", trust " + esc(String(row.trust || 0)) + ")"
|
|
322
|
+
+ '</div></details></div>';
|
|
323
|
+
}).join("");
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
async function renderFeed() {
|
|
327
|
+
const feedEl = el("feed");
|
|
328
|
+
const emptyEl = el("feedEmpty");
|
|
329
|
+
const feed = await window.tmct.session.buildFeed();
|
|
330
|
+
feedEl.querySelectorAll(".item").forEach((n) => n.remove());
|
|
331
|
+
if (!feed.items.length) { emptyEl.hidden = false; setTile("tileFeedItems", 0, "nothing yet"); return; }
|
|
332
|
+
emptyEl.hidden = true;
|
|
333
|
+
for (const item of feed.items) {
|
|
334
|
+
const card = document.createElement("div");
|
|
335
|
+
card.className = "item";
|
|
336
|
+
const seedTag = feed.seedFallback ? '<span class="seedtag">from the seed graph — start to poll live sources</span>' : "";
|
|
337
|
+
const sourcesText = item.sources.map((s) => esc(s.title || s.url)).join(", ");
|
|
338
|
+
const facts = await factListHtml(item.factIds);
|
|
339
|
+
card.innerHTML =
|
|
340
|
+
'<span class="hub">' + esc(item.hub) + '</span><span class="tier">' + esc(item.tier || "unranked") + '</span>' + seedTag
|
|
341
|
+
+ '<p class="paragraph">' + esc(item.paragraph) + '</p>'
|
|
342
|
+
+ (sourcesText ? '<p class="sources-links">sources: ' + sourcesText + '</p>' : "")
|
|
343
|
+
+ '<details class="facts"><summary>' + item.factIds.length + ' facts</summary>' + facts + '</details>';
|
|
344
|
+
feedEl.appendChild(card);
|
|
345
|
+
}
|
|
346
|
+
setTile("tileFeedItems", feed.items.length, feed.seedFallback ? "from the seed graph" : "live");
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
async function renderRank() {
|
|
350
|
+
const rows = await window.tmct.session.rank({ limit: 8 });
|
|
351
|
+
setTile("tileTermsUngrounded", rows.length, rows.length ? "ranked by occurrence" : "none yet");
|
|
352
|
+
setBars("panelTermsRanked", rows.map((r) => ({
|
|
353
|
+
label: r.term + (r.vocabGrounded ? " (parseable but knowledge-free)" : " (unknown word)"),
|
|
354
|
+
count: r.count,
|
|
355
|
+
})));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function renderSourcesPanel() {
|
|
359
|
+
const { enabled } = renderSourceStatus();
|
|
360
|
+
const config = window.tmct.session ? window.tmct.session.config : { sources: [] };
|
|
361
|
+
setTile("tileSourcesLive", enabled.size, config.pollMinutes ? ("every " + config.pollMinutes + " min") : "on demand");
|
|
362
|
+
const health = window.tmct.session ? window.tmct.session.health : [];
|
|
363
|
+
setBars("panelSourcesPerSource", health.map((h) => ({ label: h.sourceId, count: h.consecutiveFailures ? 0 : 1 })));
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
async function renderAll() {
|
|
367
|
+
await Promise.all([renderFeed(), renderRank(), renderRequestLog()]);
|
|
368
|
+
renderSourcesPanel();
|
|
369
|
+
window.tmct.news = Object.assign({}, window.tmct.news, {
|
|
370
|
+
phase: window.tmct.session.phase,
|
|
371
|
+
metrics: window.tmct.session.metrics,
|
|
372
|
+
nextPollAt: window.tmct.session.nextPollAt,
|
|
373
|
+
});
|
|
374
|
+
appendLog("phase: " + window.tmct.session.phase);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
async function boot() {
|
|
378
|
+
window.tmct.news = { phase: "seeding", metrics: { timeToFirstArticleMs: null, timeToFirstCompletePollMs: null }, nextPollAt: "" };
|
|
379
|
+
appendLog("phase: seeding");
|
|
380
|
+
const outcome = await loadSeedPayload(fetchWithProgress, "./chat-seed.json", SEED_QUERY, function () {});
|
|
381
|
+
window.tmct.seed = { state: outcome.status.state, facts: outcome.status.facts };
|
|
382
|
+
await window.tmct.open({ seedPayload: outcome.payload, vocabSeeded: Boolean(outcome.payload) });
|
|
383
|
+
window.tmct.news.phase = "seeded";
|
|
384
|
+
appendLog("phase: seeded");
|
|
385
|
+
await renderAll();
|
|
386
|
+
|
|
387
|
+
const startBtn = el("newsStart");
|
|
388
|
+
const consented = window.tmct.session.consented;
|
|
389
|
+
startBtn.textContent = consented ? "poll now" : "start polling live sources";
|
|
390
|
+
if (consented) {
|
|
391
|
+
await window.tmct.session.start();
|
|
392
|
+
await renderAll();
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
startBtn.addEventListener("click", async function () {
|
|
396
|
+
startBtn.disabled = true;
|
|
397
|
+
el("controlsStatus").textContent = "polling…";
|
|
398
|
+
await window.tmct.session.start();
|
|
399
|
+
startBtn.textContent = "poll now";
|
|
400
|
+
startBtn.disabled = false;
|
|
401
|
+
el("controlsStatus").textContent = "";
|
|
402
|
+
await renderAll();
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
el("stopForget").addEventListener("click", function () {
|
|
406
|
+
window.tmct.session.revokeConsent();
|
|
407
|
+
startBtn.textContent = "start polling live sources";
|
|
408
|
+
appendLog("stopped and forgot the start preference — this page reads as first-visit next load");
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
el("pollInterval").addEventListener("change", function (ev) {
|
|
412
|
+
const minutes = window.tmct.session.setInterval(Number(ev.target.value));
|
|
413
|
+
ev.target.value = String(minutes);
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
el("enrichNow").addEventListener("click", async function () {
|
|
417
|
+
el("controlsStatus").textContent = "enriching…";
|
|
418
|
+
await window.tmct.session.enrich();
|
|
419
|
+
el("controlsStatus").textContent = "";
|
|
420
|
+
await renderAll();
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
document.querySelectorAll("[data-source-toggle]").forEach(function (box) {
|
|
424
|
+
box.addEventListener("change", function () {
|
|
425
|
+
const ids = [].slice.call(document.querySelectorAll("[data-source-toggle]:checked")).map(function (b) { return b.value; });
|
|
426
|
+
window.tmct.session.config.sources = ids;
|
|
427
|
+
renderSourcesPanel();
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
el("addSourceBtn").addEventListener("click", async function () {
|
|
432
|
+
const url = el("addSourceUrl").value.trim();
|
|
433
|
+
if (!url) return;
|
|
434
|
+
el("controlsStatus").textContent = "checking…";
|
|
435
|
+
const result = await window.tmct.session.addSource(url);
|
|
436
|
+
el("controlsStatus").textContent = result.ok ? ("added as " + result.format) : ("couldn't add: " + result.reason);
|
|
437
|
+
if (result.ok) renderSourcesPanel();
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
async function replayFrom(sourceId, fixtureKey) {
|
|
441
|
+
el("controlsStatus").textContent = "replaying…";
|
|
442
|
+
try {
|
|
443
|
+
const res = await fetch("./news-fixtures.json");
|
|
444
|
+
const bundle = res.ok ? await res.json() : null;
|
|
445
|
+
const fixture = bundle && bundle[fixtureKey];
|
|
446
|
+
if (!fixture) { el("controlsStatus").textContent = "fixture unavailable"; return; }
|
|
447
|
+
await window.tmct.session.replayFixture(sourceId, fixture);
|
|
448
|
+
el("controlsStatus").textContent = "replayed " + fixtureKey;
|
|
449
|
+
await renderAll();
|
|
450
|
+
} catch (err) {
|
|
451
|
+
el("controlsStatus").textContent = "fixture unavailable";
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
el("replayNyt").addEventListener("click", function () { replayFrom("nyt-world", "nyt-world"); });
|
|
455
|
+
el("replayWikipedia").addEventListener("click", function () { replayFrom("wikimedia-featured", "wikimedia-featured"); });
|
|
456
|
+
|
|
457
|
+
el("exampleProse").addEventListener("click", function () {
|
|
458
|
+
el("teachText").value = "A ceasefire is a formal agreement to stop fighting. A tariff is a tax on imported goods.";
|
|
459
|
+
});
|
|
460
|
+
el("exampleJsonl").addEventListener("click", function () {
|
|
461
|
+
el("teachText").value = [
|
|
462
|
+
'{"subject":"ceasefire","predicate":"rdf:type","object":"agreement"}',
|
|
463
|
+
'{"subject":"tariff","predicate":"rdf:type","object":"tax"}',
|
|
464
|
+
].join("\\n");
|
|
465
|
+
});
|
|
466
|
+
el("teachBrowse").addEventListener("click", function () { el("teachFile").click(); });
|
|
467
|
+
el("teachFile").addEventListener("change", async function () {
|
|
468
|
+
const file = el("teachFile").files[0];
|
|
469
|
+
if (!file) return;
|
|
470
|
+
el("teachText").value = await file.text();
|
|
471
|
+
el("teachStatus").textContent = "loaded " + file.name + " — press ingest";
|
|
472
|
+
el("teachFile").dataset.name = file.name;
|
|
473
|
+
});
|
|
474
|
+
el("teachIngest").addEventListener("click", async function () {
|
|
475
|
+
const text = el("teachText").value;
|
|
476
|
+
if (!text.trim()) return;
|
|
477
|
+
const name = el("teachFile").dataset.name || "";
|
|
478
|
+
const result = await window.tmct.session.ingestFile({ name: name, text: text });
|
|
479
|
+
el("teachStatus").textContent = result.error ? result.error : (result.facts + " fact(s), " + result.vocabAdded + " vocab hint(s)");
|
|
480
|
+
await renderAll();
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
boot().catch(function (err) { appendLog("boot failed: " + (err && err.message ? err.message : String(err))); });
|
|
485
|
+
})();
|
|
486
|
+
</script>
|
|
487
|
+
</body>
|
|
488
|
+
</html>`;
|
|
489
|
+
}
|