@polycode-projects/the-mechanical-code-talker 1.8.18 → 1.8.20

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/chat.mjs +33 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polycode-projects/the-mechanical-code-talker",
3
- "version": "1.8.18",
3
+ "version": "1.8.20",
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; no codebase index of its own.",
package/src/chat.mjs CHANGED
@@ -4501,6 +4501,13 @@ const FACT_ANSWER_CAP = 32;
4501
4501
  const CAN_ASK_RE = /^(?:can|could)\s+(?:an?\s+)?([\w'-]+(?:\s+[\w'-]+)*?)\s+([a-z]+)[?.!\s]*$/i;
4502
4502
  const WHAT_CAN_DO_RE = /^what\s+can\s+(?:an?\s+)?(.+?)\s+do[?.!\s]*$/i;
4503
4503
  const WHAT_HAS_RE = /^what\s+has\s+(?:an?\s+)?(.+?)[?.!\s]*$/i;
4504
+ // "what is used for riding" / "what can be used for riding" / "what is for
4505
+ // riding" — the reverse-by-object mirror of BUG 1's forward reader ("what is
4506
+ // a tree used for"), missing until now: BUG 1 only ever filtered a KNOWN
4507
+ // subject's facts down to mgx:usedFor; nothing answered the reverse question
4508
+ // (object known, subject unknown), so it fell all the way through to the
4509
+ // code-graph miss cascade — actively misleading for a pure vocabulary query.
4510
+ const WHAT_USED_FOR_RE = /^what\s+(?:(?:can\s+be|is)\s+used\s+for|is\s+for)\s+(.+?)[?.!\s]*$/i;
4504
4511
  // Widened 2026-07-11 (live-caught follow-up to the ambiguousParse fix, commit
4505
4512
  // 5c858bf): on the FIRST turn of a graph-less session, dispatchTool's
4506
4513
  // loadGraph() throws its own documented "the graph is empty... this repo
@@ -4548,6 +4555,32 @@ async function factAnswer(memoryDir, query, envelope, miss, biasByBundle = {}) {
4548
4555
  try { ({ normFactTerm } = await import("./memory/core.mjs")); } catch { return null; }
4549
4556
  const q = String(query).trim();
4550
4557
 
4558
+ // (a-pre) "what is used for riding" / "what can be used for riding" / "what
4559
+ // is for riding" — the reverse-by-OBJECT mirror of BUG 1's forward reader
4560
+ // ("what is a tree used for", the (a) block just below). Checked BEFORE (a)
4561
+ // deliberately: this phrasing's leading "what is …" ALSO matches (a)'s own
4562
+ // BARE_WHATIS_RE, which would otherwise greedily treat "used for riding" as
4563
+ // one literal term to define — a guaranteed miss, since no vocabulary term
4564
+ // is ever named "used for riding" — and (a) always returns (hit, honest
4565
+ // per-relation "no", or null), never falling through to a later reader. Only
4566
+ // takes over when it finds a REAL hit; a non-match or zero-hit case falls
4567
+ // through unchanged to (a) and beyond, so ordinary miss messaging is
4568
+ // untouched. mgx:usedFor instead of mgx:hasA; same filter/rank/render/
4569
+ // paginate recipe as (b4)'s WHAT_HAS_RE below.
4570
+ const usedForQ = q.match(WHAT_USED_FOR_RE);
4571
+ if (usedForQ) {
4572
+ const variants = factTermVariants(normFactTerm, usedForQ[1]);
4573
+ const hits = (await factRows(memoryDir)).filter((f) => f.predicate === "mgx:usedFor" && variants.has(f.object));
4574
+ if (hits.length) {
4575
+ const ranked = rankByBiasThenTrust(uniqueFacts(hits), biasByBundle);
4576
+ const lines = ranked.map(renderFactLine);
4577
+ const shown = lines.slice(0, FACT_ANSWER_CAP);
4578
+ const rest = lines.slice(FACT_ANSWER_CAP);
4579
+ const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
4580
+ return { text: shown.join("\n") + extra, replace: true, ...(rest.length ? { pending: { items: rest, noun: "facts" } } : {}) };
4581
+ }
4582
+ }
4583
+
4551
4584
  // (a) meta-shaped questions ("what is a module", "what does cache mean") — the
4552
4585
  // parsed object term, matched against fact SUBJECTS; consulted for hits (append
4553
4586
  // alongside the schema-docs answer) and misses (facts answer alone) alike.