@polycode-projects/the-mechanical-code-talker 2.10.0 → 2.10.2

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.
@@ -0,0 +1,79 @@
1
+ // code-explorer-browser-entry.mjs — the esbuild entry for the code explorer's
2
+ // LIVE chat dock (public/code-explorer.bundle.js / electron/renderer/
3
+ // code-explorer.bundle.js). It mirrors ledger-browser-entry.mjs, but seeds the
4
+ // full runTurn engine from a CODE graph instead of a memory payload: the dock
5
+ // answers "what does X import" / "which functions call Y" over the loaded
6
+ // graph, the same compositional shapes the hint rail suggests.
7
+ //
8
+ // The graph enters through source.mjs's provider seam — the same seam the CLI
9
+ // and HTTP surfaces read — so runTurn's symbol-grain lanes see the whole
10
+ // payload, while parseEntities builds the coarse graph the flat lanes read.
11
+ // Gitignored, built fresh by scripts/build-code-explorer-bundle.mjs; the page
12
+ // degrades to a static view when it is absent (renderCodeExplorerHtml's own
13
+ // contract), so nothing here is ever published.
14
+ import { runTurn } from "../../services/chat.mjs";
15
+ import { createInMemoryStore, normFactTerm } from "../../adapters/memory/core.mjs";
16
+ import { parseEntities } from "../../domain/codegraph.mjs";
17
+ import { loadLexicon } from "../../domain/grammar/lexicon.mjs";
18
+ import { registerWinkModel } from "../../adapters/wink-model.mjs";
19
+ import * as source from "../../adapters/source.mjs";
20
+ import { computeCodeExplorerData, computeCodeLedger } from "../../services/code-explorer-viz.mjs";
21
+ import { generateCodeHints } from "../../domain/code-explorer-hints.mjs";
22
+
23
+ /**
24
+ * A browser code-explorer session over the real turn engine. Registers the
25
+ * loaded payload with source.mjs's provider seam, parses the coarse graph, and
26
+ * dispatches every turn through the same runTurn the CLI runs. Teaches land in
27
+ * an in-memory store so a taught fact never touches disk. Returns
28
+ * { sessionId, turn }, the createChatSession shape the page's dock expects.
29
+ */
30
+ export function createCodeExplorerSession({ graphPayload } = {}) {
31
+ const payload = graphPayload || { individuals: [], objectProperties: [] };
32
+ source.registerProvider(() => payload);
33
+
34
+ const graph = parseEntities(payload);
35
+ const memoryDir = createInMemoryStore();
36
+ const lexicon = loadLexicon();
37
+ const sessionId = globalThis.crypto?.randomUUID?.() ?? String(Date.now());
38
+ // A stable virtual path: the provider answers every fetch, so no file is
39
+ // ever read, but the code lanes still do path math (join/dirname) on it.
40
+ const config = { graphFile: "graph.json" };
41
+
42
+ let focus = null;
43
+ let last = null;
44
+ let planState = null;
45
+
46
+ return {
47
+ sessionId,
48
+ async turn(line) {
49
+ let result;
50
+ try {
51
+ result = await runTurn(line, {
52
+ config, source, graph, focus, last, memoryDir, sessionId,
53
+ env: {}, lexicon, vocabHint: "", planState,
54
+ });
55
+ } catch (e) {
56
+ const message = e instanceof Error ? e.message : String(e);
57
+ return { answer: `Something went wrong answering that (${message}). Try rephrasing, or /help.`, end: false, record: null };
58
+ }
59
+ focus = result.focus;
60
+ last = result.last;
61
+ if ("planState" in result) planState = result.planState;
62
+ return { answer: result.answer, end: Boolean(result.end), record: result.record ?? null };
63
+ },
64
+ };
65
+ }
66
+
67
+ // Exposed for the page's inline client: the re-derivation helpers so a graph
68
+ // swapped through the desktop picker re-renders without duplicating logic, plus
69
+ // the wink loader hook registerWinkModel and normFactTerm the dock shares with
70
+ // the ledger page.
71
+ globalThis.tmctCodeExplorer = {
72
+ createCodeExplorerSession,
73
+ computeCodeExplorerData,
74
+ computeCodeLedger,
75
+ generateCodeHints,
76
+ parseEntities,
77
+ normFactTerm,
78
+ registerWinkModel,
79
+ };