@polycode-projects/the-mechanical-code-talker 5.0.25 → 5.0.26
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/README.md +74 -11
- package/bin/tmct.mjs +81 -0
- package/package.json +5 -1
- package/src/adapters/corpus/courtesy.mjs +91 -28
- package/src/adapters/corpus/dbpedia-lookup-live.mjs +116 -0
- package/src/adapters/corpus/news-sources.mjs +436 -0
- package/src/adapters/corpus/research-source.mjs +16 -3
- package/src/adapters/corpus/wiktionary-live.mjs +158 -0
- package/src/adapters/news-store.mjs +87 -0
- package/src/adapters/toml-config.mjs +18 -0
- package/src/domain/choice-question.mjs +275 -0
- package/src/domain/cli-verbs.mjs +20 -0
- package/src/domain/dialogue-acts.mjs +1 -0
- package/src/domain/el-classify.mjs +569 -0
- package/src/domain/fact-phrase.mjs +70 -0
- package/src/domain/feed-normalize.mjs +224 -0
- package/src/domain/grammar/ace.mjs +223 -7
- package/src/domain/grammar/lexicon-core.json +2 -0
- package/src/domain/memory/trust.mjs +15 -0
- package/src/domain/news-feed.mjs +219 -0
- package/src/domain/reasoning-config.mjs +56 -0
- package/src/domain/sprite-animation.mjs +20 -2
- package/src/domain/tableau.mjs +1225 -0
- package/src/domain/term-ledger.mjs +118 -0
- package/src/services/chat.mjs +420 -20
- package/src/services/extract-facts.mjs +91 -1
- package/src/services/index.mjs +12 -0
- package/src/services/init.mjs +33 -0
- package/src/services/news.mjs +918 -0
- package/src/services/sprite-catalog-viz.mjs +148 -78
- package/src/surfaces/web/memory-ask-browser.bundle.js +132 -132
- package/src/surfaces/web/sprites-browser-entry.mjs +4 -4
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// term-ledger.mjs — counts every fact-ungrounded term the news loop sees, so
|
|
2
|
+
// the enrichment queue can work the most-mentioned gaps first
|
|
3
|
+
// (PLAN_NEWS_FEED.md section 6.3). Pure: every timestamp arrives as a `now`
|
|
4
|
+
// parameter from the caller, nothing here reads the wall clock, so two peers
|
|
5
|
+
// replaying the same bump/mark/sweep sequence converge on the same ledger.
|
|
6
|
+
|
|
7
|
+
import { normFactTerm } from "./hash.mjs";
|
|
8
|
+
|
|
9
|
+
const ITEM_IDS_CAP = 12;
|
|
10
|
+
|
|
11
|
+
/** Ledger entry field order fixed once here so `ledgerPayload` serializes
|
|
12
|
+
* byte-identically across peers regardless of insertion order elsewhere. */
|
|
13
|
+
function newEntry(term, vocabGrounded, now) {
|
|
14
|
+
return {
|
|
15
|
+
term,
|
|
16
|
+
count: 0,
|
|
17
|
+
vocabGrounded,
|
|
18
|
+
itemIds: [],
|
|
19
|
+
firstSeen: now,
|
|
20
|
+
lastSeen: now,
|
|
21
|
+
status: "pending",
|
|
22
|
+
missedAt: "",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createTermLedger() {
|
|
27
|
+
return { terms: new Map() };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** `termCounts`: Map<term, occurrences-in-this-text>. Normalizes keys through
|
|
31
|
+
* `normFactTerm`, so dedupe across cycles is inherent — one entry per
|
|
32
|
+
* normalized term. `vocabGroundedByTerm` (raw term or normalized term ->
|
|
33
|
+
* boolean) seeds a NEW entry's `vocabGrounded` flag once; an existing entry's
|
|
34
|
+
* flag is never revisited, because lexicon membership does not change. */
|
|
35
|
+
export function bumpTerms(ledger, termCounts, itemId, now, vocabGroundedByTerm = new Map()) {
|
|
36
|
+
for (const [rawTerm, occurrences] of termCounts) {
|
|
37
|
+
const term = normFactTerm(rawTerm);
|
|
38
|
+
if (!term) continue;
|
|
39
|
+
let entry = ledger.terms.get(term);
|
|
40
|
+
if (!entry) {
|
|
41
|
+
const vocabGrounded = vocabGroundedByTerm.has(rawTerm)
|
|
42
|
+
? Boolean(vocabGroundedByTerm.get(rawTerm))
|
|
43
|
+
: Boolean(vocabGroundedByTerm.get(term));
|
|
44
|
+
entry = newEntry(term, vocabGrounded, now);
|
|
45
|
+
ledger.terms.set(term, entry);
|
|
46
|
+
}
|
|
47
|
+
entry.count += occurrences;
|
|
48
|
+
entry.lastSeen = now;
|
|
49
|
+
if (itemId && !entry.itemIds.includes(itemId) && entry.itemIds.length < ITEM_IDS_CAP) {
|
|
50
|
+
entry.itemIds.push(itemId);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return ledger;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const byRank = (a, b) => b.count - a.count || (a.term < b.term ? -1 : a.term > b.term ? 1 : 0);
|
|
57
|
+
|
|
58
|
+
/** A "missed" entry whose `missedAt + ttlMs` has passed `now` reads as
|
|
59
|
+
* "pending" here — the negative-cache expiry, computed fresh on every call
|
|
60
|
+
* from the arguments alone. The ledger itself is never mutated by this. */
|
|
61
|
+
function effectiveStatus(entry, now, ttlMs) {
|
|
62
|
+
if (entry.status !== "missed" || now == null || !ttlMs) return entry.status;
|
|
63
|
+
const missedAtMs = Date.parse(entry.missedAt);
|
|
64
|
+
if (!Number.isFinite(missedAtMs)) return entry.status;
|
|
65
|
+
const nowMs = typeof now === "number" ? now : Date.parse(now);
|
|
66
|
+
if (!Number.isFinite(nowMs)) return entry.status;
|
|
67
|
+
return nowMs - missedAtMs >= ttlMs ? "pending" : entry.status;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Entries sorted count desc then term asc; `status` filters on the entry's
|
|
71
|
+
* effective status (after the negative-cache expiry above) when given. */
|
|
72
|
+
export function rankedTerms(ledger, { limit = 20, status = null, now = null, ttlMs = 0 } = {}) {
|
|
73
|
+
const withEffectiveStatus = [...ledger.terms.values()].map((entry) => ({
|
|
74
|
+
...entry,
|
|
75
|
+
status: effectiveStatus(entry, now, ttlMs),
|
|
76
|
+
}));
|
|
77
|
+
const filtered = status == null ? withEffectiveStatus : withEffectiveStatus.filter((e) => e.status === status);
|
|
78
|
+
return filtered.sort(byRank).slice(0, limit);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Sets an entry's status; stamps `missedAt` when the new status is
|
|
82
|
+
* "missed" (the negative-cache clock). A no-op for a term with no entry. */
|
|
83
|
+
export function markTerm(ledger, term, status, now) {
|
|
84
|
+
const entry = ledger.terms.get(normFactTerm(term));
|
|
85
|
+
if (!entry) return ledger;
|
|
86
|
+
entry.status = status;
|
|
87
|
+
if (status === "missed") entry.missedAt = now;
|
|
88
|
+
return ledger;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Flips every pending/missed entry `isFactGrounded(term)` now answers true
|
|
92
|
+
* for to "grounded"; returns the flipped terms, sorted. `vocabGrounded` never
|
|
93
|
+
* gates this — fact-grounding and vocab-grounding are independent states. */
|
|
94
|
+
export function groundedSweep(ledger, isFactGrounded) {
|
|
95
|
+
const flipped = [];
|
|
96
|
+
for (const entry of ledger.terms.values()) {
|
|
97
|
+
if ((entry.status === "pending" || entry.status === "missed") && isFactGrounded(entry.term)) {
|
|
98
|
+
entry.status = "grounded";
|
|
99
|
+
flipped.push(entry.term);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return flipped.sort();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** JSON-safe snapshot, entries in ranking order — the determinism contract:
|
|
106
|
+
* two peers with the same bump/mark/sweep history serialize identically. */
|
|
107
|
+
export function ledgerPayload(ledger) {
|
|
108
|
+
const entries = [...ledger.terms.values()].sort(byRank).map((entry) => ({ ...entry, itemIds: [...entry.itemIds] }));
|
|
109
|
+
return { terms: entries };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function ledgerFromPayload(payload) {
|
|
113
|
+
const ledger = createTermLedger();
|
|
114
|
+
for (const entry of payload?.terms ?? []) {
|
|
115
|
+
ledger.terms.set(entry.term, { ...entry, itemIds: [...(entry.itemIds ?? [])] });
|
|
116
|
+
}
|
|
117
|
+
return ledger;
|
|
118
|
+
}
|