@polycode-projects/the-mechanical-code-talker 5.0.29 → 5.0.30
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/conceptnet/README.md +85 -41
- package/corpus/conceptnet/commonsenseqa-seed.mjs +322 -0
- package/corpus/conceptnet/filter-dump.mjs +6 -1
- package/corpus/conceptnet/manifest.json +51 -0
- package/corpus/conceptnet/quality-filter.mjs +11 -0
- package/corpus/conceptnet/slice.jsonl +28365 -42942
- package/package.json +1 -1
- package/src/domain/news-feed.mjs +30 -6
- package/src/services/chat-page-viz.mjs +6 -3
- package/src/services/extensions.mjs +9 -2
- package/src/services/news-viz.mjs +2 -0
- package/src/services/news.mjs +3 -2
- package/src/surfaces/web/memory-ask-browser.bundle.js +52 -52
- package/src/surfaces/web/news-browser-entry.mjs +20 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polycode-projects/the-mechanical-code-talker",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.30",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "The Mechanical Code Talker (tmct) — a tolerant, offline, $0 chat surface that guides you toward precision queries about a software repository. ELIZA/PARRY-style but domain-obsessed with code. No model calls; indexes a repo on request (tmct index) or reads any producer's graph.",
|
package/src/domain/news-feed.mjs
CHANGED
|
@@ -60,11 +60,35 @@ export function scoreHubs(rows, windowRows, { limit = 6 } = {}) {
|
|
|
60
60
|
.slice(0, limit);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
+
/** One normalization pass over `rows`: each term to the row indices touching
|
|
64
|
+
* it, plus every row's own normalized pair. Built once per feed assembly and
|
|
65
|
+
* shared across every hub's walk — re-normalizing the whole store per
|
|
66
|
+
* frontier term is minutes of main-thread work on a browser-sized graph. */
|
|
67
|
+
export function buildTermAdjacency(rows) {
|
|
68
|
+
const byTerm = new Map();
|
|
69
|
+
const terms = new Array(rows.length);
|
|
70
|
+
for (let i = 0; i < rows.length; i += 1) {
|
|
71
|
+
const s = normFactTerm(rows[i].subject);
|
|
72
|
+
const o = normFactTerm(rows[i].object);
|
|
73
|
+
terms[i] = [s, o];
|
|
74
|
+
let forSubject = byTerm.get(s);
|
|
75
|
+
if (!forSubject) byTerm.set(s, (forSubject = []));
|
|
76
|
+
forSubject.push(i);
|
|
77
|
+
if (o !== s) {
|
|
78
|
+
let forObject = byTerm.get(o);
|
|
79
|
+
if (!forObject) byTerm.set(o, (forObject = []));
|
|
80
|
+
forObject.push(i);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return { byTerm, terms };
|
|
84
|
+
}
|
|
85
|
+
|
|
63
86
|
/** Breadth-first over subject/object adjacency from `hub`, exactly `hops`
|
|
64
87
|
* levels deep, then capped by content-addressed id — so the cap never
|
|
65
88
|
* depends on `rows`' own order, only on which rows the hop-bounded walk
|
|
66
89
|
* actually reaches. */
|
|
67
|
-
export function subgraphAround(rows, hub, { hops = NEWS_HUB_HOPS, cap = 60 } = {}) {
|
|
90
|
+
export function subgraphAround(rows, hub, { hops = NEWS_HUB_HOPS, cap = 60, adjacency = null } = {}) {
|
|
91
|
+
const adj = adjacency ?? buildTermAdjacency(rows);
|
|
68
92
|
const hubTerm = normFactTerm(hub);
|
|
69
93
|
const visited = new Set([hubTerm]);
|
|
70
94
|
let frontier = [hubTerm];
|
|
@@ -72,11 +96,10 @@ export function subgraphAround(rows, hub, { hops = NEWS_HUB_HOPS, cap = 60 } = {
|
|
|
72
96
|
for (let hop = 0; hop < hops; hop += 1) {
|
|
73
97
|
const nextFrontier = new Set();
|
|
74
98
|
for (const term of [...frontier].sort()) {
|
|
75
|
-
const
|
|
76
|
-
|
|
99
|
+
for (const idx of adj.byTerm.get(term) ?? []) {
|
|
100
|
+
const row = rows[idx];
|
|
77
101
|
collected.set(row.id, row);
|
|
78
|
-
const s =
|
|
79
|
-
const o = normFactTerm(row.object);
|
|
102
|
+
const [s, o] = adj.terms[idx];
|
|
80
103
|
if (!visited.has(s)) nextFrontier.add(s);
|
|
81
104
|
if (!visited.has(o)) nextFrontier.add(o);
|
|
82
105
|
}
|
|
@@ -174,8 +197,9 @@ export function renderNewsParagraph(hub, subgraphRows) {
|
|
|
174
197
|
export function buildNewsItems(rows, { now, windowMs, limit = 6, sourcesByFactId = new Map() } = {}) {
|
|
175
198
|
const windowRows = newsWindowRows(rows, { now, windowMs });
|
|
176
199
|
const hubs = scoreHubs(rows, windowRows, { limit });
|
|
200
|
+
const adjacency = buildTermAdjacency(rows);
|
|
177
201
|
const items = hubs.map(({ term, changed }) => {
|
|
178
|
-
const subgraphRows = subgraphAround(rows, term);
|
|
202
|
+
const subgraphRows = subgraphAround(rows, term, { adjacency });
|
|
179
203
|
const factIds = subgraphRows.map((r) => r.id).sort();
|
|
180
204
|
return {
|
|
181
205
|
id: `news-feed:${sha256HexPrefix(`${term}\0${factIds.join(",")}`, 8)}`,
|
|
@@ -63,8 +63,11 @@ function provKey(tier) {
|
|
|
63
63
|
* (no chip: a miss, or an answer that grounds in nothing citable, e.g. /help
|
|
64
64
|
* output or a focus-set confirmation).
|
|
65
65
|
*
|
|
66
|
-
* Reads the SAME "(source: ...)" citation(s) the
|
|
67
|
-
* carries
|
|
66
|
+
* Reads the SAME "(source: ...)" / "(sources: ...; ...)" citation(s) the
|
|
67
|
+
* visible answer text already carries — the singular form a flat fact
|
|
68
|
+
* citation or a proof-chain step uses, the plural, semicolon-joined form a
|
|
69
|
+
* digest read-back's source line uses (termDigestReadBack, chat.mjs) — via
|
|
70
|
+
* `bucketFor` (the page's own spliced copy of ledger-viz.mjs's
|
|
68
71
|
* `provBucketFor`, injected rather than imported so this function stays
|
|
69
72
|
* `.toString()`-splice safe — the same discipline spider-fly-viz.mjs's own
|
|
70
73
|
* `threadCellsForSpiderPlan` holds its own injected `geometry` to).
|
|
@@ -94,7 +97,7 @@ function provKey(tier) {
|
|
|
94
97
|
*/
|
|
95
98
|
export function provenanceChipFor(answer, record, bucketFor) {
|
|
96
99
|
if (!record || record.miss) return null;
|
|
97
|
-
const cites = [...String(answer || "").matchAll(/\(
|
|
100
|
+
const cites = [...String(answer || "").matchAll(/\(sources?: ([^)]+)\)/g)].flatMap((m) => m[1].split("; "));
|
|
98
101
|
if (!cites.length) return record.via === "assert" ? "taught" : null;
|
|
99
102
|
const buckets = cites.map((c) => bucketFor([], c));
|
|
100
103
|
const allTaught = buckets.every((b) => b === "taught");
|
|
@@ -50,8 +50,15 @@ const TIER2_EMPTY_VOCAB_FILE = join(dirname(fileURLToPath(import.meta.url)), "..
|
|
|
50
50
|
export const EXTENSION_KINDS = Object.freeze(["corpus", "lexicon", "templates", "pack", "ontology"]);
|
|
51
51
|
|
|
52
52
|
// The definitional-band-first predicate order for the ConceptNet seed (re-declared,
|
|
53
|
-
// not imported, to keep this module off chat.mjs's heavy graph).
|
|
54
|
-
|
|
53
|
+
// not imported, to keep this module off chat.mjs's heavy graph). The five
|
|
54
|
+
// relational predicates after the definitional backbone are the ones a
|
|
55
|
+
// commonsense multiple-choice question keys on (atLocation, causes, desires,
|
|
56
|
+
// motivatedByGoal, hasSubevent) — ranked ahead of the rest so the band cap
|
|
57
|
+
// buys them before it buys more RelatedTo.
|
|
58
|
+
const CONCEPTNET_PREFER = [
|
|
59
|
+
"rdfs:subClassOf", "rdf:type", "mgx:usedFor", "mgx:partOf", "mgx:capableOf",
|
|
60
|
+
"mgx:atLocation", "mgx:causes", "mgx:desires", "mgx:motivatedByGoal", "mgx:hasSubevent",
|
|
61
|
+
];
|
|
55
62
|
|
|
56
63
|
/** The shipped defaults — a FRESH object per call, so a caller can never
|
|
57
64
|
* accidentally mutate a module-level singleton. */
|
|
@@ -331,6 +331,8 @@ const SEED_BYTES = ${Number(seedBytes) || 0};
|
|
|
331
331
|
if (!feed.items.length) { emptyEl.hidden = false; setTile("tileFeedItems", 0, "nothing yet"); return; }
|
|
332
332
|
emptyEl.hidden = true;
|
|
333
333
|
for (const item of feed.items) {
|
|
334
|
+
// One yield per card keeps the page clickable while a long feed renders.
|
|
335
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
334
336
|
const card = document.createElement("div");
|
|
335
337
|
card.className = "item";
|
|
336
338
|
const seedTag = feed.seedFallback ? '<span class="seedtag">from the seed graph — start to poll live sources</span>' : "";
|
package/src/services/news.mjs
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
|
|
40
40
|
import { normFactTerm, normFactPredicate, factIdFor, sha256Bytes } from "../domain/hash.mjs";
|
|
41
41
|
import {
|
|
42
|
-
newsWindowRows, scoreHubs, subgraphAround, renderNewsParagraph, buildNewsItems, evictNewsFacts,
|
|
42
|
+
newsWindowRows, scoreHubs, subgraphAround, buildTermAdjacency, renderNewsParagraph, buildNewsItems, evictNewsFacts,
|
|
43
43
|
} from "../domain/news-feed.mjs";
|
|
44
44
|
import {
|
|
45
45
|
createTermLedger, bumpTerms, rankedTerms, markTerm, groundedSweep, ledgerPayload, ledgerFromPayload,
|
|
@@ -293,8 +293,9 @@ function collectItemSources(subgraphRows, sourcesByFactId) {
|
|
|
293
293
|
* buildNewsItems's own, already-pinned window contract. */
|
|
294
294
|
function assembleNewsItems(rows, windowRows, { now, limit, sourcesByFactId }) {
|
|
295
295
|
const hubs = scoreHubs(rows, windowRows, { limit });
|
|
296
|
+
const adjacency = buildTermAdjacency(rows);
|
|
296
297
|
const items = hubs.map(({ term, changed }) => {
|
|
297
|
-
const subgraphRows = subgraphAround(rows, term);
|
|
298
|
+
const subgraphRows = subgraphAround(rows, term, { adjacency });
|
|
298
299
|
const factIds = subgraphRows.map((r) => r.id).sort();
|
|
299
300
|
return {
|
|
300
301
|
id: `news-feed:${sha256HexPrefix(`${term}\0${factIds.join(",")}`, 8)}`,
|