@polycode-projects/the-mechanical-code-talker 5.0.21 → 5.0.22

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 CHANGED
@@ -1293,6 +1293,10 @@ source = "wikipedia" # wikipedia | wikidata — where "research <topic>"
1293
1293
  [discourse]
1294
1294
  max_referents = 12 # how many referents stay resolvable across turns
1295
1295
 
1296
+ # Goal recognition (src/domain/router/recognize.mjs).
1297
+ [recognition]
1298
+ max_trace = 32 # how many observed steps a recognition reads back
1299
+
1296
1300
  [telemetry]
1297
1301
  enabled = false # local-only counters; never phones home
1298
1302
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polycode-projects/the-mechanical-code-talker",
3
- "version": "5.0.21",
3
+ "version": "5.0.22",
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.",
@@ -147,6 +147,11 @@ export async function normalizeConfig(raw, { configDir } = {}) {
147
147
  // through; default-filling is resolveDiscourseConfig's job.
148
148
  if (src.discourse !== undefined) cfg.discourse = src.discourse;
149
149
 
150
+ // Recognition knob (src/domain/router/recognize.mjs): sparse PASS-THROUGH,
151
+ // the raw `[recognition]` table (max_trace) rides through; default-filling
152
+ // is resolveRecognitionConfig's job.
153
+ if (src.recognition !== undefined) cfg.recognition = src.recognition;
154
+
150
155
  const idx = src.index || {};
151
156
  const index = {};
152
157
  if (idx.languages !== undefined) index.languages = idx.languages;
@@ -197,6 +197,14 @@ const domainIndividuals = (domain) => {
197
197
  return out;
198
198
  };
199
199
 
200
+ /** `{ base, step }` for an @stepN-stamped subject, or null for a bare one —
201
+ * the one parser for the board's own snapshot grammar, so a caller outside
202
+ * this file never keeps a second copy of the regex. */
203
+ export function parseStepSubject(subject) {
204
+ const m = SNAPSHOT_RE.exec(String(subject || ""));
205
+ return m ? { base: m[1], step: Number(m[2]) } : null;
206
+ }
207
+
200
208
  /** The current state as canonical sorted rows over the domain's dynamic
201
209
  * predicates. Prefers the newest @stepN snapshot when one exists, so a
202
210
  * re-plan after per-step execution never reads the stale step-0 board. */
@@ -173,6 +173,10 @@ const isListingRemainder = (rest) => {
173
173
  return LISTING_TAIL_KINDS.has((words[words.length - 1] || "").toLowerCase());
174
174
  };
175
175
 
176
+ // The punctuation set every delimiter-anchored preamble/filler frame in this
177
+ // file treats as a clause boundary.
178
+ const DELIM_SRC = "[,.;:!]|—|–|-";
179
+
176
180
  /** Greeting lead-in with a delimiter (+ optional "quick question" bridge):
177
181
  * "hey there, quick question - <Q>" -> "<Q>". Delimiter and non-empty
178
182
  * remainder are both required, so a bare greeting stays small-talk. */
@@ -186,7 +190,14 @@ const THANKS_PREAMBLE_RE = /^(?:thanks|thank\s+you|many\s+thanks|thx|ty|cheers)(
186
190
  * different wording — a throwaway counting aside before the real content,
187
191
  * never part of the content itself ("ok, one more, teach me: no server is a
188
192
  * client" must peel exactly as "ok cool, <Q>" already does). */
189
- const ACK_PREAMBLE_RE = /^(?:(?:ok(?:ay)?|aight|cool|alright|sure|right|fine|great|nice|got it|gotcha|sounds good|no worries|no problem|(?:just\s+)?(?:one|another)\s+more|another\s+one)[\s,]+)+(.+)$/i;
193
+ const ACK_WORDS_SRC = "ok(?:ay)?|aight|cool|alright|sure|right|fine|great|nice|got it|gotcha|sounds good|no worries|no problem|another\\s+one";
194
+ // The counting arm ("one more", "just one more") requires a trailing
195
+ // delimiter, unlike the ack words above — without it, "one more disk rests
196
+ // on peg-a" loses its own quantifier to this frame.
197
+ const ACK_COUNTING_SRC = "(?:just\\s+)?(?:one|another)\\s+more";
198
+ const ACK_PREAMBLE_RE = new RegExp(
199
+ `^(?:(?:${ACK_WORDS_SRC})[\\s,]+|(?:${ACK_COUNTING_SRC})\\s*(?:${DELIM_SRC})\\s*)+(.+)$`, "i",
200
+ );
190
201
  /** Self-orientation lead-in with a delimiter — "just poking around, <Q>",
191
202
  * "first time using this, <Q>". */
192
203
  const BROWSING_PREAMBLE_RE = /^(?:just\s+(?:poking\s+around|looking\s+around|browsing|exploring|checking\s+(?:this|it)\s+out)|first\s+time\s+(?:trying\s+this\s+out|using\s+this|here)|i'?m\s+new\s+(?:here|around\s+here|to\s+(?:this|all\s+this)(?:\s+(?:repo|codebase|project|app|tool|thing))?))\s*[,.—–-]\s*(.+)$/i;
@@ -342,6 +353,80 @@ export function applyPreambleFrames(text) {
342
353
  return q;
343
354
  }
344
355
 
356
+ // ---- closed FILLER-CLAUSE prefixes: sentence-initial small talk ahead of a
357
+ // real question, distinct from the PREAMBLE frames above because family B
358
+ // (hesitation + pivot) needs no delimiter — an unconditional peel here would
359
+ // change what every existing normalizeQuery caller sees, so this is exposed
360
+ // as its own function and consumed only where a caller opts in explicitly.
361
+
362
+ const alt = (list) => [...list].sort((a, b) => b.length - a.length).map(escapeRegex).join("|");
363
+
364
+ // Family A — interjection + comment. A delimiter is required: a bare
365
+ // interjection followed by a noun ("oh water") is ordinary content.
366
+ const FILLER_INTERJECTIONS = Object.freeze([
367
+ "oh", "ah", "aha", "ooh", "ohh", "wow", "huh", "hm", "hmm", "mm", "mmm",
368
+ "heh", "ha", "yay", "ugh", "oof", "phew", "whoa", "oops", "yikes", "oi",
369
+ ]);
370
+ const FILLER_COMMENT_WORDS = Object.freeze([
371
+ "nice", "cool", "great", "neat", "lovely", "interesting", "good", "ok", "okay",
372
+ "fair enough", "makes sense", "i see", "got it", "fine",
373
+ ]);
374
+
375
+ // Family B — hesitation + pivot. Repeatable, delimiter optional. Deliberately
376
+ // excludes "like"/"so"/"now"/"then"/"right"/"ok": those either carry real
377
+ // content ("like what?") or already peel through LEADING_CONNECTIVE_RE /
378
+ // ACK_PREAMBLE_RE, and duplicating them here would give the same word two
379
+ // competing owners.
380
+ const FILLER_HESITATIONS = Object.freeze([
381
+ "um", "umm", "uhm", "uh", "uhh", "er", "err", "erm", "ehm", "eh",
382
+ "well", "anyway", "anyhow", "anyways", "regardless", "moving on",
383
+ ]);
384
+
385
+ // Family C — meta-announcement: a self-describing announcement of the
386
+ // question about to come. Delimiter required.
387
+ const FILLER_ANNOUNCEMENTS = Object.freeze([
388
+ "quick question", "quick q", "one quick question", "just a quick question",
389
+ "random question", "random thing", "one more random thing", "another random thing",
390
+ "one more thing", "one last thing", "last thing", "one more question",
391
+ "side note", "side question", "sidebar", "off topic", "unrelated",
392
+ "on a different note", "different topic", "changing the subject", "new topic",
393
+ "just curious", "out of curiosity", "curious", "genuinely curious",
394
+ "while i'm here", "while i have you", "before i forget",
395
+ ]);
396
+
397
+ const FILLER_A_SRC = `(?:${alt(FILLER_INTERJECTIONS)})(?:\\s+(?:${alt(FILLER_COMMENT_WORDS)}))?\\s*(?:${DELIM_SRC})\\s*`;
398
+ const FILLER_B_SRC = `(?:${alt(FILLER_HESITATIONS)})\\s*(?:(?:${DELIM_SRC})\\s*|\\s+)`;
399
+ const FILLER_C_SRC = `(?:${alt(FILLER_ANNOUNCEMENTS)})\\s*(?:${DELIM_SRC})\\s*`;
400
+
401
+ // An optional leading "sorry"/"sorry," ahead of any family, once.
402
+ const FILLER_CLAUSE_PREFIX_RE = new RegExp(
403
+ `^(?:sorry\\s*(?:${DELIM_SRC})?\\s*)?(?:${FILLER_A_SRC}|${FILLER_B_SRC}|${FILLER_C_SRC})+`, "i",
404
+ );
405
+
406
+ /** Peel a sentence-initial closed filler clause off `text`. Returns
407
+ * { prefix, remainder } or null when nothing in the closed inventory leads
408
+ * the line. Longest-alternative-first inside each family, so "one more
409
+ * random thing" wins over "one more thing". Pure; no graph, no store. */
410
+ export function fillerClausePrefix(text) {
411
+ const line = String(text || "").trim();
412
+ const m = line.match(FILLER_CLAUSE_PREFIX_RE);
413
+ if (!m || !m[0]) return null;
414
+ const remainder = line.slice(m[0].length).trim();
415
+ if (!remainder) return null; // a bare filler is small talk, not a peel
416
+ return { prefix: m[0].trim(), remainder };
417
+ }
418
+
419
+ /** QUESTION_LEAD_RE is anchored to the FIRST word, so a closed filler clause
420
+ * in front of a question moves the interrogative off word one and every
421
+ * write gate reads the line as a declarative. Peel once, then re-check the
422
+ * same question underneath. */
423
+ export function leadsInterrogative(text) {
424
+ const line = String(text || "").trim();
425
+ if (QUESTION_LEAD_RE.test(line)) return true;
426
+ const peel = fillerClausePrefix(line);
427
+ return Boolean(peel && QUESTION_LEAD_RE.test(peel.remainder));
428
+ }
429
+
345
430
  /** Strippable leading framing clause: "since/[even] though/although/while/
346
431
  * because/[even] if/whereas/given that/now that <clause>, <Q>" -> "<Q>".
347
432
  * Comma-anchored and non-empty-remainder-required, same discipline as
Binary file
@@ -0,0 +1,25 @@
1
+ // domain/world-snapshot.mjs — the one grammar for a snapshot subject: bare
2
+ // `base@turnN` while a world stays on epoch 0, `base@epochE@turnN` once a
3
+ // recast has moved it on. Pure, no imports — every reader of this grammar
4
+ // (the adventure lane, autoplay, the recognizer) reads it from here instead
5
+ // of keeping its own copy.
6
+
7
+ const SNAPSHOT_RE = /^(.+?)@(?:epoch(\d+)@)?turn(\d+)$/;
8
+
9
+ /** The snapshot subject a turn writes: bare `base@turnN` while the world is
10
+ * on epoch 0, `base@epochE@turnN` once a recast has moved it on. */
11
+ export function snapshotSubject(base, turn, epoch = 0) {
12
+ return epoch > 0 ? `${base}@epoch${epoch}@turn${turn}` : `${base}@turn${turn}`;
13
+ }
14
+
15
+ /** Read a snapshot subject back: `{ base, epoch, turn }`, or null when the
16
+ * subject carries no snapshot stamp (a base row). Pure. */
17
+ export function parseSnapshotSubject(subject) {
18
+ const m = SNAPSHOT_RE.exec(String(subject || ""));
19
+ return m ? { base: m[1], epoch: m[2] ? Number(m[2]) : 0, turn: Number(m[3]) } : null;
20
+ }
21
+
22
+ /** The base individual a subject names, snapshot-stamped or not. */
23
+ export function baseSubjectOf(subject) {
24
+ return parseSnapshotSubject(subject)?.base ?? subject;
25
+ }
@@ -26,11 +26,9 @@
26
26
  // fact simply has nothing for this module to infer a goal toward.
27
27
  import { findActionPath } from "../domain/planning.mjs";
28
28
  import { loadMemory, readFactRows } from "../adapters/memory/core.mjs";
29
+ import { baseSubjectOf } from "../domain/world-snapshot.mjs";
29
30
  import { foldWorldState, adventureTurn, worldActionRows } from "./adventure.mjs";
30
31
 
31
- const SNAPSHOT_RE = /^(.+)@turn(\d+)$/;
32
- const baseSubjectOf = (subject) => SNAPSHOT_RE.exec(subject)?.[1] ?? subject;
33
-
34
32
  const isTypedRow = (rows, subject, type) =>
35
33
  (rows || []).some((r) => r.subject === subject && r.predicate === "rdf:type" && r.object === type);
36
34
 
@@ -9,6 +9,7 @@
9
9
  // share the slot.
10
10
 
11
11
  import { worldProvenanceTag } from "../domain/worlds-pack.mjs";
12
+ import { parseSnapshotSubject, snapshotSubject } from "../domain/world-snapshot.mjs";
12
13
  import { parseImperative, OBJECT_PRONOUNS } from "../domain/grammar/ace.mjs";
13
14
  import { loadLexicon, withProperNames, classify } from "../domain/grammar/lexicon.mjs";
14
15
  import { register as registerReferent, bind as bindDiscourseForm } from "../domain/discourse.mjs";
@@ -177,11 +178,6 @@ async function resumedPosition(memoryDir) {
177
178
 
178
179
  // ---- the world-state fold ----------------------------------------------------
179
180
 
180
- // A snapshot subject is `base@turnN`, or `base@epochE@turnN` once a recast has
181
- // moved the world past epoch 0 — the fold below reads both, and epoch-0 writes
182
- // keep the bare form so an unrecast store never changes shape.
183
- const SNAPSHOT_RE = /^(.+?)@(?:epoch(\d+)@)?turn(\d+)$/;
184
-
185
181
  /** Which run of the world a store is on. Recasting a shared world (mud.html's
186
182
  * RESET, a slider, the scenario dropdown) reopens the same deterministic
187
183
  * instance ids over a fresh store while peers may still hold the old run's
@@ -199,21 +195,13 @@ export function worldEpochFact(epoch) {
199
195
  return { subject: WORLD_EPOCH_SUBJECT, predicate: WORLD_EPOCH_PREDICATE, object: String(epoch) };
200
196
  }
201
197
 
202
- /** `{ base, epoch, turn }` for a snapshot subject, or null for a base subject.
203
- * The one parser every reader outside this file should use — a local
204
- * `@turn(\d+)$` regex reads an epoch-stamped subject's base as
205
- * "mole-1@epoch2", which matches no character. */
206
- export function parseSnapshotSubject(subject) {
207
- const m = SNAPSHOT_RE.exec(String(subject || ""));
208
- return m ? { base: m[1], epoch: m[2] ? Number(m[2]) : 0, turn: Number(m[3]) } : null;
209
- }
198
+ // The snapshot-subject grammar itself (`{ base, epoch, turn }` for a stamped
199
+ // subject, null for a base row) lives in domain/world-snapshot.mjs, the one
200
+ // place every reader — this lane, autoplay, the recognizer — parses it from.
201
+ // Re-exported here so every existing importer of snapshotSubject and
202
+ // parseSnapshotSubject keeps working.
203
+ export { snapshotSubject, parseSnapshotSubject };
210
204
 
211
- /** The snapshot subject a turn writes: bare `@turnN` while the world is on
212
- * epoch 0 (every store that has never been recast, and every fact written
213
- * before epochs existed), the epoch-stamped form after. */
214
- export function snapshotSubject(base, turn, epoch = 0) {
215
- return epoch > 0 ? `${base}@epoch${epoch}@turn${turn}` : `${base}@turn${turn}`;
216
- }
217
205
  const PLACEMENT_PREDICATES = new Set([
218
206
  "mgx:currently-in", "mgx:located-in", "mgx:fixed-in", "mgx:stands-locked-in", "mgx:hidden-in",
219
207
  ]);
@@ -303,7 +291,7 @@ export function isMudStatePredicate(predicate) {
303
291
  export function worldIndividualNames(rows) {
304
292
  const names = new Set();
305
293
  for (const row of rows || []) {
306
- if (SNAPSHOT_RE.test(row.subject)) continue;
294
+ if (parseSnapshotSubject(row.subject)) continue;
307
295
  if (row.predicate === "rdf:type" || PLACEMENT_PREDICATES.has(row.predicate)) names.add(row.subject);
308
296
  if (EXIT_PREDICATE_RE.test(row.predicate)) { names.add(row.subject); names.add(row.object); }
309
297
  }
@@ -332,8 +320,8 @@ export function foldWorldState(factRows) {
332
320
  if (Number.isInteger(marked) && marked > epoch) epoch = marked;
333
321
  continue;
334
322
  }
335
- const m = SNAPSHOT_RE.exec(row.subject);
336
- if (m && m[2] && Number(m[2]) > epoch) epoch = Number(m[2]);
323
+ const snap = parseSnapshotSubject(row.subject);
324
+ if (snap && snap.epoch > epoch) epoch = snap.epoch;
337
325
  }
338
326
  const placements = new Map(); // subject -> { predicate, object, turn, epoch }
339
327
  const positions = new Map(); // subject -> { predicate, object, turn, epoch }
@@ -345,11 +333,11 @@ export function foldWorldState(factRows) {
345
333
  !prior || rowEpoch > prior.epoch || (rowEpoch === prior.epoch && turn >= prior.turn);
346
334
  for (const row of rows) {
347
335
  if (row.predicate === WORLD_EPOCH_PREDICATE) continue;
348
- const m = SNAPSHOT_RE.exec(row.subject);
349
- const base = m ? m[1] : row.subject;
350
- const rowEpoch = m ? (m[2] ? Number(m[2]) : 0) : epoch;
351
- const turn = m ? Number(m[3]) : 0;
352
- if (m && rowEpoch === epoch) turnCount = Math.max(turnCount, turn);
336
+ const snap = parseSnapshotSubject(row.subject);
337
+ const base = snap ? snap.base : row.subject;
338
+ const rowEpoch = snap ? snap.epoch : epoch;
339
+ const turn = snap ? snap.turn : 0;
340
+ if (snap && rowEpoch === epoch) turnCount = Math.max(turnCount, turn);
353
341
  if (PLACEMENT_PREDICATES.has(row.predicate)) {
354
342
  if (outranks(rowEpoch, turn, placements.get(base))) placements.set(base, { predicate: row.predicate, object: row.object, turn, epoch: rowEpoch });
355
343
  continue;
@@ -369,7 +357,7 @@ export function foldWorldState(factRows) {
369
357
  continue;
370
358
  }
371
359
  const exit = EXIT_PREDICATE_RE.exec(row.predicate);
372
- if (exit && !m) {
360
+ if (exit && !snap) {
373
361
  if (!exits.has(row.subject)) exits.set(row.subject, new Map());
374
362
  exits.get(row.subject).set(exit[1], row.object);
375
363
  }
@@ -946,7 +934,7 @@ export function worldDigestRows(rows, state, actingSubject = "player") {
946
934
  .filter(([, place]) => OUT_OF_PLAY_PLACES.has(place.object))
947
935
  .map(([subject]) => subject));
948
936
  for (const row of rows || []) {
949
- if (SNAPSHOT_RE.test(row.subject)) continue; // folded above
937
+ if (parseSnapshotSubject(row.subject)) continue; // folded above
950
938
  if (gone.has(row.subject)) continue; // out of the world entirely
951
939
  // Room text comes from the world source only. A merged corpus overlaps a
952
940
  // room's own vocabulary ("library rdfs:subClassOf literary study"), and