@polycode-projects/the-mechanical-code-talker 4.0.1 → 4.1.1
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 +2 -1
- package/corpus/sprites/src/sprite-facts.jsonl +375 -8
- package/package.json +1 -1
- package/src/adapters/memory/core.mjs +20 -0
- package/src/domain/ask-vocab.mjs +71 -0
- package/src/domain/ask.mjs +168 -0
- package/src/domain/game-config.mjs +11 -0
- package/src/domain/mud-facts.mjs +15 -0
- package/src/domain/router/drive.mjs +35 -9
- package/src/domain/router/registry.mjs +24 -4
- package/src/domain/router/resolver.mjs +102 -40
- package/src/domain/scene-compose.mjs +117 -0
- package/src/domain/spider-fly-world.mjs +36 -0
- package/src/domain/sprite-facts.mjs +0 -0
- package/src/domain/sprite-request.mjs +156 -0
- package/src/domain/sprite-templates.mjs +161 -14
- package/src/services/adventure-editor.mjs +8 -14
- package/src/services/adventure-viz.mjs +119 -150
- package/src/services/adventure.mjs +97 -35
- package/src/services/chat-page-viz.mjs +64 -48
- package/src/services/chat.mjs +102 -34
- package/src/services/code-explorer-viz.mjs +52 -50
- package/src/services/ingest-viz.mjs +32 -74
- package/src/services/ledger-viz.mjs +87 -70
- package/src/services/memory-panel-viz.mjs +38 -0
- package/src/services/mud-editor.mjs +10 -15
- package/src/services/mud-turn.mjs +6 -6
- package/src/services/mud-viz.mjs +119 -225
- package/src/services/p2p-room.mjs +90 -23
- package/src/services/plan-pddl.mjs +3 -1
- package/src/services/plan-viz.mjs +13 -12
- package/src/services/research-viz.mjs +25 -67
- package/src/services/spider-fly-turn.mjs +14 -22
- package/src/services/spider-fly-viz.mjs +97 -136
- package/src/services/spider-fly.mjs +69 -11
- package/src/services/sprite-catalog-viz.mjs +274 -224
- package/src/services/viz-boot.mjs +71 -0
- package/src/services/viz-room-graph.mjs +203 -0
- package/src/services/viz-theme.mjs +75 -1
- package/src/services/viz-ticker.mjs +22 -0
- package/src/surfaces/web/adventure-browser-entry.mjs +62 -47
- package/src/surfaces/web/chat-browser-entry.mjs +51 -107
- package/src/surfaces/web/code-explorer-browser-entry.mjs +192 -35
- package/src/surfaces/web/engine-surface.mjs +82 -0
- package/src/surfaces/web/ingest-browser-entry.mjs +16 -17
- package/src/surfaces/web/ledger-browser-entry.mjs +24 -56
- package/src/surfaces/web/memory-ask-browser-entry.mjs +55 -13
- package/src/surfaces/web/memory-ask-browser.bundle.js +128 -125
- package/src/surfaces/web/memory-stats.mjs +11 -0
- package/src/surfaces/web/mud-browser-entry.mjs +70 -49
- package/src/surfaces/web/plan-browser-entry.mjs +39 -50
- package/src/surfaces/web/research-browser-entry.mjs +48 -46
- package/src/surfaces/web/spider-fly-browser-entry.mjs +76 -40
- package/src/surfaces/web/sprites-browser-entry.mjs +28 -32
- package/src/surfaces/web/tmct-surface.mjs +147 -0
- package/src/surfaces/web/turn-session.mjs +124 -0
- package/src/tools/definitions.mjs +30 -0
- package/src/tools/handlers/index.mjs +6 -3
- package/src/tools/handlers/kit.mjs +19 -2
- package/src/tools/handlers/tmct-ask.mjs +11 -6
- package/src/tools/handlers/tmct-ingest.mjs +5 -1
- package/src/tools/handlers/tmct-related.mjs +4 -4
- package/src/tools/handlers/tmct-sprite.mjs +147 -0
- package/src/tools/memory-fallthrough.mjs +9 -2
- package/src/tools/server.mjs +37 -6
|
@@ -16,9 +16,8 @@
|
|
|
16
16
|
// class as chat/spider-fly/adventure/plan's own browser bundles) and is
|
|
17
17
|
// never published — only the hosted demo site's public/ledger.html links to
|
|
18
18
|
// it, as an optional sibling script the page degrades honestly without.
|
|
19
|
-
import {
|
|
20
|
-
import { createInMemoryStore, normFactTerm,
|
|
21
|
-
import { serializeFactsJsonl } from "../../adapters/memory/export-jsonl.mjs";
|
|
19
|
+
import { vocabExampleHint } from "../../services/chat.mjs";
|
|
20
|
+
import { createInMemoryStore, normFactTerm, applySeedPayload } from "../../adapters/memory/core.mjs";
|
|
22
21
|
import { splitSentencesPreservingPaths } from "../../services/sentences.mjs";
|
|
23
22
|
import { parseEntities } from "../../domain/codegraph.mjs";
|
|
24
23
|
import { loadLexicon } from "../../domain/grammar/lexicon.mjs";
|
|
@@ -26,6 +25,10 @@ import { registerWinkModel } from "../../adapters/wink-model.mjs";
|
|
|
26
25
|
import { registerResearchProvider } from "../../adapters/corpus/wikipedia-live.mjs";
|
|
27
26
|
import { computeLedgerDataFromPayload } from "../../services/ledger-viz.mjs";
|
|
28
27
|
import { digestTermFromPayloadBrowser } from "./digest-client.mjs";
|
|
28
|
+
import { createTurnSession } from "./turn-session.mjs";
|
|
29
|
+
import { exportFactsJsonl } from "./memory-stats.mjs";
|
|
30
|
+
import { publishTmctSurface } from "./tmct-surface.mjs";
|
|
31
|
+
import { graphAsk, enginePlan } from "./engine-surface.mjs";
|
|
29
32
|
|
|
30
33
|
/**
|
|
31
34
|
* A browser ledger-dock session over the real turn engine — createChatSession's
|
|
@@ -34,7 +37,7 @@ import { digestTermFromPayloadBrowser } from "./digest-client.mjs";
|
|
|
34
37
|
* a fact taught through the dock extends the SAME graph the page renders
|
|
35
38
|
* from, never a disconnected one.
|
|
36
39
|
*
|
|
37
|
-
* Returns { memoryDir, sessionId, turn }, identical to createChatSession.
|
|
40
|
+
* Returns { memoryDir, sessionId, graph, turn }, identical to createChatSession.
|
|
38
41
|
* ledger-viz.mjs's own inline script calls computeLedgerDataFromPayload
|
|
39
42
|
* (re-exported below) on `memoryDir.payload` after a turn whose record shows
|
|
40
43
|
* a successful write (`via: "assert"` or `via: "retract"`, `miss: false`) to
|
|
@@ -43,63 +46,28 @@ import { digestTermFromPayloadBrowser } from "./digest-client.mjs";
|
|
|
43
46
|
*/
|
|
44
47
|
export function createLedgerSession({ seedPayload = null, vocabSeeded = false } = {}) {
|
|
45
48
|
const memoryDir = createInMemoryStore();
|
|
46
|
-
|
|
47
|
-
// carries the classes/prefixes scaffolding the write path recounts —
|
|
48
|
-
// teach turns must work regardless of what the seed payload carries.
|
|
49
|
-
if (seedPayload) memoryDir.payload = { ...memoryDir.payload, ...seedPayload };
|
|
49
|
+
applySeedPayload(memoryDir, seedPayload);
|
|
50
50
|
|
|
51
51
|
const graph = parseEntities({ individuals: [], objectProperties: [] });
|
|
52
52
|
const lexicon = loadLexicon();
|
|
53
53
|
const vocabHint = vocabExampleHint(vocabSeeded);
|
|
54
54
|
const sessionId = globalThis.crypto?.randomUUID?.() ?? String(Date.now());
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
let planState = null;
|
|
59
|
-
let researchState = null;
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
memoryDir,
|
|
63
|
-
sessionId,
|
|
64
|
-
|
|
65
|
-
/** One dispatched turn. A throwing runTurn must never kill the session —
|
|
66
|
-
* the page has no other chance to show this turn's answer. */
|
|
67
|
-
async turn(line) {
|
|
68
|
-
let result;
|
|
69
|
-
try {
|
|
70
|
-
result = await runTurn(line, {
|
|
71
|
-
config: null, source: null, graph, focus, last, memoryDir, sessionId,
|
|
72
|
-
env: {}, lexicon, vocabHint, planState, researchState,
|
|
73
|
-
});
|
|
74
|
-
} catch (e) {
|
|
75
|
-
const message = e instanceof Error ? e.message : String(e);
|
|
76
|
-
return { answer: `Something went wrong answering that (${message}). Try rephrasing, or /help.`, end: false, record: null, research: null };
|
|
77
|
-
}
|
|
78
|
-
focus = result.focus;
|
|
79
|
-
last = result.last;
|
|
80
|
-
if ("planState" in result) planState = result.planState;
|
|
81
|
-
if ("researchState" in result) researchState = result.researchState;
|
|
82
|
-
// `research` distinguishes a queue snapshot (research turn) from null
|
|
83
|
-
// (a research turn that ended the run) from undefined (not a research
|
|
84
|
-
// turn) — the dock's controls only react to the first two.
|
|
85
|
-
return { answer: result.answer, end: Boolean(result.end), record: result.record ?? null, research: result.research };
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/** The session's whole triple store as JSONL — the same
|
|
91
|
-
* { subject, predicate, object, provenance } shape `tmct extract` and
|
|
92
|
-
* `tmct memory --export` emit. The ledger dock's "export facts" control reads
|
|
93
|
-
* this and offers it as a download. */
|
|
94
|
-
export async function exportFactsJsonl(memoryDir) {
|
|
95
|
-
return serializeFactsJsonl(await loadMemory(memoryDir));
|
|
56
|
+
const session = createTurnSession({ memoryDir, graph, lexicon, sessionId, vocabHint });
|
|
57
|
+
return { memoryDir, sessionId, graph, turn: session.turn };
|
|
96
58
|
}
|
|
97
59
|
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
//
|
|
101
|
-
//
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
60
|
+
// `tmct.page` keeps what the page's own script renders with and the engine has
|
|
61
|
+
// no plain-English form for: the payload-to-rows/terms/edges/stats derivation
|
|
62
|
+
// the ledger view re-mounts from after a successful teach, the digest reader,
|
|
63
|
+
// the wink and research seams, and the two serializers behind the dock's
|
|
64
|
+
// paste-ingest and JSONL export.
|
|
65
|
+
publishTmctSurface({
|
|
66
|
+
open: createLedgerSession,
|
|
67
|
+
ask: graphAsk,
|
|
68
|
+
plan: enginePlan,
|
|
69
|
+
page: {
|
|
70
|
+
computeLedgerDataFromPayload, normFactTerm, registerWinkModel, registerResearchProvider,
|
|
71
|
+
splitSentences: splitSentencesPreservingPaths, exportFactsJsonl, digestTermFromPayloadBrowser,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
@@ -1,20 +1,62 @@
|
|
|
1
1
|
// memory-ask-browser-entry.mjs — the esbuild entry for the ledger page's
|
|
2
2
|
// chat dock (`tmct viz`, src/services/ledger-viz.mjs).
|
|
3
3
|
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
4
|
+
// The one COMMITTED browser bundle: `tmct viz` is a real CLI command run
|
|
5
|
+
// against a user's own local .tmct store, so this ships with the package. It
|
|
6
|
+
// deliberately carries the question lanes only (factAnswer/factReadBack) and
|
|
7
|
+
// not the full turn engine — see ledger-browser-entry.mjs's header for the
|
|
8
|
+
// contrast with the demo site's own 1.5MB dock.
|
|
9
|
+
//
|
|
10
|
+
// It publishes the SAME `globalThis.tmct` every other page does, through
|
|
11
|
+
// tmct-surface.mjs, which imports nothing — so this bundle gets the shared
|
|
12
|
+
// contract without the tool layer or the capability router coming with it.
|
|
13
|
+
// `tmct.turn` and `tmct.plan` are unwired here and say so: this dock asks
|
|
14
|
+
// questions, it does not hold a conversation or plan anything.
|
|
9
15
|
import { factAnswer, factReadBack } from "../../services/chat.mjs";
|
|
10
16
|
import { createInMemoryStore, normFactTerm } from "../../adapters/memory/core.mjs";
|
|
11
17
|
import { digestTermFromPayloadBrowser } from "./digest-client.mjs";
|
|
18
|
+
import { publishTmctSurface } from "./tmct-surface.mjs";
|
|
19
|
+
|
|
20
|
+
/** A question-only session over a payload the page already embeds — no fs I/O,
|
|
21
|
+
* no turn engine. Returns `{ memoryDir }`. */
|
|
22
|
+
export function createMemoryAskSession({ payload = null } = {}) {
|
|
23
|
+
const memoryDir = createInMemoryStore();
|
|
24
|
+
if (payload) memoryDir.payload = payload;
|
|
25
|
+
return { memoryDir };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* One question, answered from the page's own embedded store. Runs the same
|
|
30
|
+
* cascade `runAsk` runs — factAnswer first, then factReadBack, which is where
|
|
31
|
+
* the taught-relation chases live ("who is the grandfather of ishmael") that
|
|
32
|
+
* factAnswer's own lanes don't reach.
|
|
33
|
+
*
|
|
34
|
+
* Both are called with `envelope: null, miss: true`, which arms factAnswer's
|
|
35
|
+
* bare-question fallbacks directly and skips the structural-graph parse
|
|
36
|
+
* pipeline this dock has no use for.
|
|
37
|
+
*
|
|
38
|
+
* Returns `{ answer, data, miss }`. `data` is the reader's own result, so a
|
|
39
|
+
* caller still sees the inferred `goal` line it computed on the way.
|
|
40
|
+
*/
|
|
41
|
+
export async function askMemory(request, options, session) {
|
|
42
|
+
let fact = null;
|
|
43
|
+
try { fact = await factAnswer(session.memoryDir, request, null, true, {}); } catch { fact = null; }
|
|
44
|
+
if (!(fact && fact.text)) {
|
|
45
|
+
try { fact = await factReadBack(session.memoryDir, request, null, true, null); } catch { fact = null; }
|
|
46
|
+
}
|
|
47
|
+
if (!(fact && fact.text)) return { answer: null, data: null, miss: true };
|
|
48
|
+
return { answer: fact.text, data: fact, miss: false };
|
|
49
|
+
}
|
|
12
50
|
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
// the
|
|
19
|
-
|
|
20
|
-
|
|
51
|
+
// `tmct.page` keeps the term normalizer the dock refocuses the ledger with,
|
|
52
|
+
// and the client-side digest reader — the narrative the demo ledger's live
|
|
53
|
+
// bundle produces, over the static structure table this page embeds.
|
|
54
|
+
// `fallback`, because the demo ledger page carries this bundle AND the full
|
|
55
|
+
// turn engine at once: this one answers where it is alone, and steps aside
|
|
56
|
+
// wherever the live dock is loaded, whichever order the two arrive in.
|
|
57
|
+
publishTmctSurface({
|
|
58
|
+
open: createMemoryAskSession,
|
|
59
|
+
ask: askMemory,
|
|
60
|
+
page: { normFactTerm, digestTermFromPayloadBrowser },
|
|
61
|
+
fallback: true,
|
|
62
|
+
});
|