@polycode-projects/the-mechanical-code-talker 7.0.0 → 7.1.0
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/package.json +1 -1
- package/src/services/chat-session.mjs +17 -9
- package/src/services/chat-voice.mjs +27 -0
- package/src/services/chat.mjs +274 -209
- package/src/services/world-teach.mjs +14 -7
- package/src/surfaces/web/chat-browser-entry.mjs +15 -4
- package/src/surfaces/web/memory-ask-browser.bundle.js +135 -135
- package/src/surfaces/web/turn-session.mjs +5 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polycode-projects/the-mechanical-code-talker",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "The Mechanical Code Talker (tmct) — a tolerant, offline, $0 chat surface that guides you toward precision queries about a software repository. ELIZA/PARRY-style but domain-obsessed with code. No model calls; indexes a repo on request (tmct index) or reads any producer's graph.",
|
|
@@ -27,6 +27,7 @@ import { createTelemetry } from "./telemetry.mjs";
|
|
|
27
27
|
import * as defaultSource from "../adapters/source.mjs";
|
|
28
28
|
import { resolveExtensions, mergedLexiconExtra, mergedLaneVocab, defaultCodeLaneVocab, activeDomainPacks, defaultCodeDomainPacks } from "./extensions.mjs";
|
|
29
29
|
import { runTurn, hasSeededVocabulary, vocabExampleHint, codeDomainActive as codeDomainActiveOf } from "./chat.mjs";
|
|
30
|
+
import { resolveChatVoice } from "./chat-voice.mjs";
|
|
30
31
|
import { resolveGameConfig } from "../domain/game-config.mjs";
|
|
31
32
|
import { emptyRecord, resolveDiscourseConfig } from "../domain/discourse.mjs";
|
|
32
33
|
import { resolveRecognitionConfig } from "../domain/router/recognize.mjs";
|
|
@@ -114,9 +115,10 @@ const promptFor = (focus) => (focus ? `tmct(${shortLabel(focus.label)})> ` : PRO
|
|
|
114
115
|
* focus/lastAnswer/streams/sessionId).
|
|
115
116
|
*
|
|
116
117
|
* Returns { repo, config, graph, lexicon, memoryDir, moduleCount, version, sessionId,
|
|
117
|
-
* logFile, sidecarFile, bannerLines, empty, focus, lastAnswer, turns, promptFor(),
|
|
118
|
+
* voice, logFile, sidecarFile, bannerLines, empty, focus, lastAnswer, turns, promptFor(),
|
|
118
119
|
* turn(line), close() }. `turn(line)` runs one dispatched turn through runTurn and the
|
|
119
|
-
* full sink sequencing, returning { answer, end, prompt }; `close()` is idempotent.
|
|
120
|
+
* full sink sequencing, returning { answer, end, prompt, taught, … }; `close()` is idempotent.
|
|
121
|
+
* `taught` is true when the turn stored or forgot a fact or a rule on the user's word.
|
|
120
122
|
* `turn(line, {retrieval})` passes this turn's own corpus-retrieval context,
|
|
121
123
|
* overriding the session-level `retrieval` option for that turn.
|
|
122
124
|
*/
|
|
@@ -205,7 +207,13 @@ export async function createSession({
|
|
|
205
207
|
// (the default) preserves today's behavior: a world only goes live via its
|
|
206
208
|
// own "play <world>" opener line.
|
|
207
209
|
adventureWorld,
|
|
210
|
+
// The voice every turn answers in: "default" (the default) or "plain"
|
|
211
|
+
// (chat-voice.mjs's CHAT_VOICES). The plain voice states teach confirmations,
|
|
212
|
+
// cited facts and the greeting in plain sentences that do not name the
|
|
213
|
+
// engine. Any other value throws here, before the session opens anything.
|
|
214
|
+
voice: voiceOption,
|
|
208
215
|
} = {}) {
|
|
216
|
+
const voice = resolveChatVoice(voiceOption);
|
|
209
217
|
// EPHEMERAL mode (--ephemeral, or TMCT_EPHEMERAL=1): read the target graph but
|
|
210
218
|
// write NOTHING back into it. The shipped examples run this way so a demo never
|
|
211
219
|
// dirties the committed code graph (`npm run example:mini` used to fold a session
|
|
@@ -548,7 +556,7 @@ export async function createSession({
|
|
|
548
556
|
let closed = false;
|
|
549
557
|
|
|
550
558
|
return {
|
|
551
|
-
repo, config, graph, lexicon, memoryDir, moduleCount, version, sessionId,
|
|
559
|
+
repo, config, graph, lexicon, memoryDir, moduleCount, version, sessionId, voice,
|
|
552
560
|
logFile, sidecarFile, bannerLines, empty, biasByBundle,
|
|
553
561
|
// Same handle as `memoryDir`, named to match dispatchTool's `memoryBackend`
|
|
554
562
|
// context param — a caller that wants a tool call (tmct_export, …) to read
|
|
@@ -571,15 +579,15 @@ export async function createSession({
|
|
|
571
579
|
|
|
572
580
|
/** One dispatched turn through the FULL sink sequencing (writeLog → writeSidecar
|
|
573
581
|
* → telemetry → upsertGraph, in that exact order). Returns { answer, end, prompt,
|
|
574
|
-
* plan, record, factsTouched } — record is the same sidecar turn record the
|
|
575
|
-
* session persists,
|
|
576
|
-
* (empty when the turn wrote nothing). A throwing runTurn must never abort
|
|
582
|
+
* plan, record, factsTouched, taught } — record is the same sidecar turn record the
|
|
583
|
+
* session persists, factsTouched is runTurn's own diffed Fact-row list
|
|
584
|
+
* (empty when the turn wrote nothing), and taught is runTurn's own flag. A throwing runTurn must never abort
|
|
577
585
|
* the session: a piped/non-interactive driver has no other chance to see
|
|
578
586
|
* this turn's answer. */
|
|
579
587
|
async turn(line, { retrieval: turnRetrieval = null } = {}) {
|
|
580
588
|
let result;
|
|
581
589
|
try {
|
|
582
|
-
result = await runTurn(line, { config, source, graph, focus, last, memoryDir, sessionId, env, lexicon, narrate: narrateOn, liveReference: liveReferenceOn, codeGraphMode: codeGraphModeOn, researchSource: researchSourceOn, vocabHint, tel, biasByBundle, planState, gameConfig, recognitionConfig, researchState, researchConfig, newsState, newsConfig, newsProviders, discourse: discourseRecord, actingSubject, codeDomainActive: domainActive, laneVocab, domainPacks, retrieval: turnRetrieval ?? retrieval });
|
|
590
|
+
result = await runTurn(line, { config, source, graph, focus, last, memoryDir, sessionId, env, lexicon, narrate: narrateOn, liveReference: liveReferenceOn, codeGraphMode: codeGraphModeOn, researchSource: researchSourceOn, vocabHint, tel, biasByBundle, planState, gameConfig, recognitionConfig, researchState, researchConfig, newsState, newsConfig, newsProviders, discourse: discourseRecord, actingSubject, codeDomainActive: domainActive, laneVocab, domainPacks, retrieval: turnRetrieval ?? retrieval, voice });
|
|
583
591
|
} catch (e) {
|
|
584
592
|
const ts = new Date().toISOString();
|
|
585
593
|
const message = e instanceof Error ? e.message : String(e);
|
|
@@ -588,7 +596,7 @@ export async function createSession({
|
|
|
588
596
|
await writeSidecar(errorRecord);
|
|
589
597
|
turnRecords.push(errorRecord);
|
|
590
598
|
turns += 1;
|
|
591
|
-
return { answer: `Something went wrong answering that (${message}). Try rephrasing, or /help.`, end: false, prompt: promptFor(focus) };
|
|
599
|
+
return { answer: `Something went wrong answering that (${message}). Try rephrasing, or /help.`, end: false, prompt: promptFor(focus), taught: false };
|
|
592
600
|
}
|
|
593
601
|
const { record, focus: nextFocus, last: nextLast, end, narrate: nextNarrate, liveReference: nextLiveReference, codeGraphMode: nextCodeGraphMode, researchSource: nextResearchSource } = result;
|
|
594
602
|
// "noted — remembered" reports a durable write. In a session that keeps
|
|
@@ -625,7 +633,7 @@ export async function createSession({
|
|
|
625
633
|
});
|
|
626
634
|
await upsertGraph(record.ts);
|
|
627
635
|
turns += 1;
|
|
628
|
-
return { answer, end: Boolean(end), prompt: promptFor(focus), plan: result.plan ?? null, research: result.research, record, factsTouched: result.factsTouched };
|
|
636
|
+
return { answer, end: Boolean(end), prompt: promptFor(focus), plan: result.plan ?? null, research: result.research, record, factsTouched: result.factsTouched, taught: result.taught };
|
|
629
637
|
},
|
|
630
638
|
|
|
631
639
|
/** End-of-session close: end lines in both artifacts, the final graph upsert
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// chat-voice.mjs — the voices a chat session speaks in, and the one sentence
|
|
2
|
+
// rule the plain voice shares between chat.mjs and world-teach.mjs.
|
|
3
|
+
//
|
|
4
|
+
// The default voice names the engine ("noted — remembered: …", "i learned:
|
|
5
|
+
// …", "Hi. I'm tmct."). The plain voice states the same content in plain
|
|
6
|
+
// sentences, for a host page that shows the answer under its own name. A
|
|
7
|
+
// session picks its voice once, when it opens.
|
|
8
|
+
|
|
9
|
+
export const CHAT_VOICES = Object.freeze(["default", "plain"]);
|
|
10
|
+
export const DEFAULT_VOICE = "default";
|
|
11
|
+
export const PLAIN_VOICE = "plain";
|
|
12
|
+
|
|
13
|
+
/** A session's voice from its caller's `voice` option: absent is the default
|
|
14
|
+
* voice, and a value outside CHAT_VOICES throws. */
|
|
15
|
+
export function resolveChatVoice(voice) {
|
|
16
|
+
if (voice === undefined || voice === null) return DEFAULT_VOICE;
|
|
17
|
+
if (CHAT_VOICES.includes(voice)) return voice;
|
|
18
|
+
throw new Error(`unknown chat voice ${JSON.stringify(voice)}: use one of ${CHAT_VOICES.map((v) => JSON.stringify(v)).join(", ")}`);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** "rover is a dog" as the sentence "Rover is a dog.". The first word takes a
|
|
22
|
+
* capital only when it is a plain lowercase word, so a code path or an id
|
|
23
|
+
* such as "disk-1" keeps its spelling. */
|
|
24
|
+
export function plainSentence(statement) {
|
|
25
|
+
const s = String(statement).trim().replace(/^(["']?)([a-z][a-z']*)(?=[\s"'.,;:!?]|$)/, (_, quote, word) => `${quote}${word[0].toUpperCase()}${word.slice(1)}`);
|
|
26
|
+
return /[.!?]$/.test(s) ? s : `${s}.`;
|
|
27
|
+
}
|