@polycode-projects/the-mechanical-code-talker 5.0.27 → 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 +1 -1
- package/src/adapters/memory/inspect.mjs +37 -0
- package/src/domain/agent-traits.mjs +282 -0
- package/src/domain/choice-question.mjs +135 -6
- 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 +118 -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/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/turn-session.mjs +13 -9
|
@@ -4,13 +4,24 @@
|
|
|
4
4
|
// Unlike memory-ask-browser-entry.mjs (factAnswer/factReadBack only), this
|
|
5
5
|
// exposes the FULL turn engine: createChatSession wraps the shared
|
|
6
6
|
// createTurnSession (turn-session.mjs) around chat.mjs's runTurn — the
|
|
7
|
-
// focus/last/planState/researchState threading src/services/chat-session.mjs's
|
|
7
|
+
// focus/last/planState/researchState/newsState threading src/services/chat-session.mjs's
|
|
8
8
|
// createSession.turn does, minus every filesystem side effect (no transcript
|
|
9
9
|
// log, no sidecar, no graph upsert). Memory is an in-memory Backend-B handle,
|
|
10
10
|
// optionally pre-loaded with a built seed payload (scripts/build-chat-seed.mjs),
|
|
11
11
|
// so teach turns, recall, proof chains and the honest miss all run
|
|
12
12
|
// client-side with zero I/O.
|
|
13
13
|
//
|
|
14
|
+
// The news lane's own state (newsState) rides turn-session.mjs's shared
|
|
15
|
+
// threading with no extra wiring here, the same way researchState already
|
|
16
|
+
// does. What IS this file's own job: a persistent newsConfig object (so a
|
|
17
|
+
// `/news add`/`/news interval` mutation survives turn to turn, the same
|
|
18
|
+
// reason liveReferenceOn/synthesisBudgetOn are held here rather than
|
|
19
|
+
// recreated per turn) and registerNewsProvider — the news lane's own
|
|
20
|
+
// provider-set stub seam, the same shape registerResearchProvider gives
|
|
21
|
+
// tests below. Neither building the default fetchers nor registering a stub
|
|
22
|
+
// set fires a fetch; a fetch only happens once the user's own turn actually
|
|
23
|
+
// runs `/news poll` or `/news enrich`.
|
|
24
|
+
//
|
|
14
25
|
// Two browser traps this file still owns, beyond what createTurnSession
|
|
15
26
|
// already covers (passing `env: {}` explicitly, since a browser has no
|
|
16
27
|
// `process` global; the crash-resistant catch fallback):
|
|
@@ -47,7 +58,13 @@ import { registerReferencePackProvider } from "../../adapters/corpus/reference-p
|
|
|
47
58
|
// provider is stubbed. The adapter is fetch-only, so it bundles as-is.
|
|
48
59
|
// registerResearchProvider is the research lane's sibling seam
|
|
49
60
|
// (simple.wikipedia.org) — same stubbing contract for its e2e tests.
|
|
50
|
-
import { registerLiveReferenceProvider, registerResearchProvider } from "../../adapters/corpus/wikipedia-live.mjs";
|
|
61
|
+
import { registerLiveReferenceProvider, registerResearchProvider, getResearchProvider } from "../../adapters/corpus/wikipedia-live.mjs";
|
|
62
|
+
// The news lane's own config resolver and contemporary-source registry —
|
|
63
|
+
// this session's default /news providers are built from the same fetcher
|
|
64
|
+
// factory news.html's own session uses (src/surfaces/web/news-browser-entry.mjs),
|
|
65
|
+
// just over the browser's own fetch rather than an injected test one.
|
|
66
|
+
import { resolveNewsConfig } from "../../services/news.mjs";
|
|
67
|
+
import { newsSourceRecords, normalizeNewsSourceIds, createNewsFetcher, preflightNewsUrl } from "../../adapters/corpus/news-sources.mjs";
|
|
51
68
|
// Best-effort IndexedDB persistence for the page's session store — the page
|
|
52
69
|
// decides when to save/load/clear; this entry only carries the wrapper
|
|
53
70
|
// across the bundle boundary.
|
|
@@ -82,6 +99,48 @@ import { graphAsk, enginePlan } from "./engine-surface.mjs";
|
|
|
82
99
|
* for `ask()` — a question about taught facts has a real graph to traverse
|
|
83
100
|
* while a code-structure question keeps its honest no-code-graph refusal.
|
|
84
101
|
*/
|
|
102
|
+
let registeredNewsProviders = null;
|
|
103
|
+
|
|
104
|
+
/** Swap chat.html's own `/news` providers set — `{ newsFetchers, getResearchProvider,
|
|
105
|
+
* preflightNewsUrl }`, the same stub seam registerResearchProvider gives tests
|
|
106
|
+
* above — so a test (or a future page control) can answer `/news` against a
|
|
107
|
+
* fixed set of sources instead of the real network. Pass null to restore the
|
|
108
|
+
* default: real fetchers, over the browser's own fetch, for every source the
|
|
109
|
+
* session's own newsConfig currently enables. Registering (or not) never
|
|
110
|
+
* fires a fetch by itself — only the user's own `/news poll`/`/news enrich`
|
|
111
|
+
* turn does. */
|
|
112
|
+
export function registerNewsProvider(providers) {
|
|
113
|
+
registeredNewsProviders = providers && typeof providers === "object" ? providers : null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The default `/news` providers for one session's current `newsConfig`:
|
|
117
|
+
* real fetchers for every enabled contemporary source (browser fetch, no
|
|
118
|
+
* request until a fetcher's own fetchItems() runs) and the same research
|
|
119
|
+
* provider `/wiki` and `research <topic>` already use for KB enrichment.
|
|
120
|
+
* Rebuilt only when the enabled source list has actually changed since the
|
|
121
|
+
* last call (`/news add` is the one turn that can change it), so an
|
|
122
|
+
* ordinary turn that never touches `/news` pays nothing repeated here. */
|
|
123
|
+
function newsProvidersFor(config) {
|
|
124
|
+
let cachedProviders = null;
|
|
125
|
+
let cachedKey = null;
|
|
126
|
+
return () => {
|
|
127
|
+
const key = normalizeNewsSourceIds(config.sources).join(",");
|
|
128
|
+
if (cachedProviders && cachedKey === key) return cachedProviders;
|
|
129
|
+
const newsFetchers = new Map();
|
|
130
|
+
for (const id of normalizeNewsSourceIds(config.sources)) {
|
|
131
|
+
const record = newsSourceRecords().find((r) => r.id === id);
|
|
132
|
+
if (record) newsFetchers.set(id, createNewsFetcher(record, { fetchImpl: (...args) => globalThis.fetch(...args) }));
|
|
133
|
+
}
|
|
134
|
+
cachedProviders = {
|
|
135
|
+
newsFetchers,
|
|
136
|
+
getResearchProvider: ({ source } = {}) => getResearchProvider({ source }),
|
|
137
|
+
preflightNewsUrl: (url) => preflightNewsUrl(url, { fetchImpl: (...args) => globalThis.fetch(...args) }),
|
|
138
|
+
};
|
|
139
|
+
cachedKey = key;
|
|
140
|
+
return cachedProviders;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
85
144
|
export function createChatSession({ seedPayload = null, vocabSeeded = false, liveReference = false, onLiveLookup = null, synthesisBudget = 12, digestStructures = null } = {}) {
|
|
86
145
|
setDigestStructures(digestStructures || []);
|
|
87
146
|
const memoryDir = createInMemoryStore();
|
|
@@ -117,12 +176,19 @@ export function createChatSession({ seedPayload = null, vocabSeeded = false, liv
|
|
|
117
176
|
// The auto-synthesis budget for this session's learn-on-miss loads — the
|
|
118
177
|
// page's slider sets it; 0 stores article facts without any entailed rows.
|
|
119
178
|
let synthesisBudgetOn = Number.isFinite(synthesisBudget) ? synthesisBudget : 12;
|
|
179
|
+
// This session's own `/news` config — one persistent, mutable object (not
|
|
180
|
+
// recreated per turn), so a `/news add`/`/news interval` mutation survives
|
|
181
|
+
// turn to turn the same way it does in a CLI session's newsConfig.
|
|
182
|
+
const newsConfig = resolveNewsConfig(null);
|
|
183
|
+
const defaultNewsProviders = newsProvidersFor(newsConfig);
|
|
120
184
|
|
|
121
185
|
const session = createTurnSession({
|
|
122
186
|
memoryDir, graph: codeGraph, lexicon, sessionId, vocabHint,
|
|
123
187
|
buildExtraOptions: () => ({
|
|
124
188
|
liveReference: liveReferenceOn, onLiveLookup,
|
|
125
189
|
synthesisBudget: synthesisBudgetOn,
|
|
190
|
+
newsConfig,
|
|
191
|
+
newsProviders: registeredNewsProviders ?? defaultNewsProviders(),
|
|
126
192
|
}),
|
|
127
193
|
// `result.liveReference` mirrors a `/wiki on|off|supplement|always`
|
|
128
194
|
// command back into this session's own toggle state.
|
|
@@ -186,7 +252,7 @@ publishTmctSurface({
|
|
|
186
252
|
plan: enginePlan,
|
|
187
253
|
page: {
|
|
188
254
|
registerWinkModel, registerReferencePackProvider, registerLiveReferenceProvider,
|
|
189
|
-
registerResearchProvider, normFactTerm, vocabExampleHint, memoryStats,
|
|
255
|
+
registerResearchProvider, registerNewsProvider, normFactTerm, vocabExampleHint, memoryStats,
|
|
190
256
|
openPersistedStore, exportFactsJsonl, researchedFactRows,
|
|
191
257
|
splitSentences: splitSentencesPreservingPaths,
|
|
192
258
|
},
|