@polycode-projects/the-mechanical-code-talker 2.5.2 → 2.5.4
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 +11 -7
- package/bin/tmct.mjs +7 -4
- package/corpus/LICENSES.json +7 -0
- package/corpus/reference/LICENSE-NOTICE +36 -0
- package/corpus/reference/README.md +19 -0
- package/corpus/reference/index.json.gz +0 -0
- package/corpus/reference/manifest.json +367 -0
- package/corpus/reference/shards/ref-00.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-01.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-02.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-03.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-04.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-05.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-06.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-07.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-08.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-09.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-0f.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-10.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-11.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-12.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-13.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-14.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-15.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-16.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-17.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-18.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-19.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-1f.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-20.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-21.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-22.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-23.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-24.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-25.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-26.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-27.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-28.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-29.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-2f.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-30.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-31.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-32.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-33.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-34.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-35.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-36.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-37.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-38.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-39.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3a.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3b.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3c.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3d.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3e.jsonl.gz +0 -0
- package/corpus/reference/shards/ref-3f.jsonl.gz +0 -0
- package/package.json +5 -1
- package/src/adapters/corpus/reference-pack.mjs +113 -0
- package/src/adapters/memory/core.mjs +104 -10
- package/src/domain/ask.mjs +66 -9
- package/src/domain/cli-verbs.mjs +3 -3
- package/src/domain/codegraph.mjs +6 -0
- package/src/domain/dialogue-acts.mjs +160 -0
- package/src/domain/interpret/normalize.mjs +14 -2
- package/src/domain/interpret/strategies/keywords.mjs +10 -1
- package/src/domain/memory/trust.mjs +12 -0
- package/src/domain/reference-pack.mjs +72 -0
- package/src/domain/skos-view.mjs +111 -0
- package/src/domain/syllogise.mjs +647 -56
- package/src/services/chat.mjs +937 -142
- package/src/services/index.mjs +4 -1
- package/src/surfaces/web/chat-browser-entry.mjs +87 -0
- package/src/surfaces/web/memory-ask-browser.bundle.js +1187 -85
- package/src/tools/definitions.mjs +13 -0
- package/src/tools/handlers/index.mjs +2 -0
- package/src/tools/handlers/tmct-related.mjs +30 -0
package/src/services/index.mjs
CHANGED
|
@@ -7,7 +7,10 @@
|
|
|
7
7
|
// the ask() orchestration.
|
|
8
8
|
|
|
9
9
|
// Chat surface (also reachable as the `./chat` subpath export).
|
|
10
|
-
|
|
10
|
+
// createSession is the library's session sink — the same focus/last/planState
|
|
11
|
+
// threading and memory-backend seam every shell shares; runTurn is the pure
|
|
12
|
+
// single-turn engine underneath it.
|
|
13
|
+
export { runChat, createSession, runTurn, COMMANDS, answerCount, renderStats } from "./chat.mjs";
|
|
11
14
|
|
|
12
15
|
// Grammar / NL-over-graph primitives.
|
|
13
16
|
export { ask, resolveObject } from "../domain/ask.mjs";
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// chat-browser-entry.mjs — the esbuild entry for the home page's embedded
|
|
2
|
+
// chat (public/chat-ui.mjs, built by scripts/build-chat-bundle.mjs).
|
|
3
|
+
//
|
|
4
|
+
// Unlike memory-ask-browser-entry.mjs (factAnswer/factReadBack only), this
|
|
5
|
+
// exposes the FULL turn engine: createChatSession wraps chat.mjs's runTurn
|
|
6
|
+
// with a session-shaped closure — the focus/last/planState threading
|
|
7
|
+
// src/services/chat-session.mjs's createSession.turn does, minus every
|
|
8
|
+
// filesystem side effect (no transcript log, no sidecar, no graph upsert).
|
|
9
|
+
// Memory is an in-memory Backend-B handle, optionally pre-loaded with a
|
|
10
|
+
// built seed payload (scripts/build-chat-seed.mjs), so teach turns, recall,
|
|
11
|
+
// proof chains and the honest miss all run client-side with zero I/O.
|
|
12
|
+
//
|
|
13
|
+
// Two browser traps this file owns so no caller can fall into them:
|
|
14
|
+
// - runTurn defaults `env` to process.env, and a browser has no `process`
|
|
15
|
+
// global — every turn here passes `env: {}` explicitly;
|
|
16
|
+
// - the uuid adapter needs node:crypto — the session id comes from the
|
|
17
|
+
// Web Crypto API instead, with a Date.now fallback for contexts
|
|
18
|
+
// without it.
|
|
19
|
+
import { runTurn, vocabExampleHint } from "../../services/chat.mjs";
|
|
20
|
+
import { createInMemoryStore, normFactTerm } from "../../adapters/memory/core.mjs";
|
|
21
|
+
import { parseEntities } from "../../domain/codegraph.mjs";
|
|
22
|
+
import { loadLexicon } from "../../domain/grammar/lexicon.mjs";
|
|
23
|
+
import { registerWinkModel } from "../../adapters/wink-model.mjs";
|
|
24
|
+
// The reference-pack provider seam: the page registers a fetch-backed
|
|
25
|
+
// provider over public/reference-pack/ so the engine's pack lookups work
|
|
26
|
+
// where the gzipped fs layout cannot (the module's own fs loader degrades to
|
|
27
|
+
// null in the browser — build-chat-bundle stubs node:zlib as a thrower its
|
|
28
|
+
// try/catch absorbs).
|
|
29
|
+
import { registerReferencePackProvider } from "../../adapters/corpus/reference-pack.mjs";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A browser chat session over the real turn engine.
|
|
33
|
+
*
|
|
34
|
+
* `seedPayload` (optional) is a serialized memory graph (loadMemory's shape,
|
|
35
|
+
* built by scripts/build-chat-seed.mjs) assigned onto a fresh Backend-B
|
|
36
|
+
* handle. `vocabSeeded` tells the session's vocabulary hint whether that
|
|
37
|
+
* payload carries the starter vocabulary, so an unseeded session offers the
|
|
38
|
+
* teach pointer instead of an example it cannot answer.
|
|
39
|
+
*
|
|
40
|
+
* Returns { memoryDir, sessionId, turn }. `turn(line)` resolves to
|
|
41
|
+
* { answer, end, record, plan } and threads focus/last/planState between
|
|
42
|
+
* calls exactly as the CLI session does.
|
|
43
|
+
*/
|
|
44
|
+
export function createChatSession({ seedPayload = null, vocabSeeded = false } = {}) {
|
|
45
|
+
const memoryDir = createInMemoryStore();
|
|
46
|
+
// Spread onto the store's own empty payload so a partial seed (individuals
|
|
47
|
+
// and objectProperties only) still carries the classes/prefixes scaffolding
|
|
48
|
+
// the write path recounts — teach turns must work on any seed.
|
|
49
|
+
if (seedPayload) memoryDir.payload = { ...memoryDir.payload, ...seedPayload };
|
|
50
|
+
|
|
51
|
+
// A known-empty code graph: code-structure questions get the same honest
|
|
52
|
+
// no-code-graph answer an un-pointed CLI session gives, never a crash.
|
|
53
|
+
const graph = parseEntities({ individuals: [], objectProperties: [] });
|
|
54
|
+
const lexicon = loadLexicon();
|
|
55
|
+
const vocabHint = vocabExampleHint(vocabSeeded);
|
|
56
|
+
const sessionId = globalThis.crypto?.randomUUID?.() ?? String(Date.now());
|
|
57
|
+
|
|
58
|
+
let focus = null;
|
|
59
|
+
let last = null;
|
|
60
|
+
let planState = null;
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
memoryDir,
|
|
64
|
+
sessionId,
|
|
65
|
+
|
|
66
|
+
/** One dispatched turn. A throwing runTurn must never kill the session —
|
|
67
|
+
* the page has no other chance to show this turn's answer. */
|
|
68
|
+
async turn(line) {
|
|
69
|
+
let result;
|
|
70
|
+
try {
|
|
71
|
+
result = await runTurn(line, {
|
|
72
|
+
config: null, source: null, graph, focus, last, memoryDir, sessionId,
|
|
73
|
+
env: {}, lexicon, vocabHint, planState,
|
|
74
|
+
});
|
|
75
|
+
} catch (e) {
|
|
76
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
77
|
+
return { answer: `Something went wrong answering that (${message}). Try rephrasing, or /help.`, end: false, record: null, plan: null };
|
|
78
|
+
}
|
|
79
|
+
focus = result.focus;
|
|
80
|
+
last = result.last;
|
|
81
|
+
if ("planState" in result) planState = result.planState;
|
|
82
|
+
return { answer: result.answer, end: Boolean(result.end), record: result.record ?? null, plan: result.plan ?? null };
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
globalThis.tmctChat = { createChatSession, registerWinkModel, registerReferencePackProvider, normFactTerm, vocabExampleHint };
|