@polycode-projects/the-mechanical-code-talker 5.0.26 → 5.0.27

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polycode-projects/the-mechanical-code-talker",
3
- "version": "5.0.26",
3
+ "version": "5.0.27",
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.",
@@ -174,6 +174,7 @@
174
174
  "build:ledger-bundle": "node scripts/build-ledger-bundle.mjs",
175
175
  "build:ingest-bundle": "node scripts/build-ingest-bundle.mjs",
176
176
  "build:research-bundle": "node scripts/build-research-bundle.mjs",
177
+ "build:news-bundle": "node scripts/build-news-bundle.mjs",
177
178
  "build:mud-bundle": "node scripts/build-mud-bundle.mjs",
178
179
  "build:mudiii-bundle": "node scripts/build-mudiii-bundle.mjs",
179
180
  "build:sprites-bundle": "node scripts/build-sprites-bundle.mjs",
@@ -3040,17 +3040,17 @@ function modifierIsWired(shape, kind, entityType) {
3040
3040
  }
3041
3041
  const TRANSITIVE_MAX_DEPTH = 8; // matches renderImpact's own default (codegraph.mjs)
3042
3042
 
3043
- /** A graph's own vocabulary nodes carry their definition text under this
3044
- * property. A code entity's docstring rides `seon:hasDoc` and shares the
3045
- * plain `doc` key, so the PROP is what separates the two. */
3046
- const SCHEMA_DOC_PROP = "mgx:schemaDoc";
3043
+ /** A graph's own vocabulary nodes carry their definition text under one of
3044
+ * these properties. A code entity's docstring rides `seon:hasDoc` and shares
3045
+ * the plain `doc` key, so this set is what separates the two. */
3046
+ const SCHEMA_DOC_PROPS = new Set(["mgx:schemaDoc", "mgx:lexiconDoc"]);
3047
3047
 
3048
3048
  /** The definition text an individual publishes about itself, or null. Reading
3049
3049
  * the meta lane off this attribute rather than a fixed class-name list lets a
3050
3050
  * graph declare its own documented individual class (a glossary term, say)
3051
3051
  * and have "what is X" answer for it like any other vocabulary node. */
3052
3052
  function schemaDefinitionOf(ind) {
3053
- return (ind?.attributes || []).find((a) => a.prop === SCHEMA_DOC_PROP)?.value || null;
3053
+ return (ind?.attributes || []).find((a) => SCHEMA_DOC_PROPS.has(a.prop))?.value || null;
3054
3054
  }
3055
3055
 
3056
3056
  function schemaKindWordFor(cls) {
@@ -4055,7 +4055,20 @@ function renderCore(parsed, result, graph) {
4055
4055
  miss: true, ambiguous: false,
4056
4056
  };
4057
4057
  }
4058
- const entityWord = nounFor(parsed.entityType || "Module", 2);
4058
+ // No entity type was parsed (a bare "what denotes X" names no grain), so the
4059
+ // word for what was searched comes off the kind's own object classes in the
4060
+ // loaded graph rather than defaulting to "modules" — a kind like `denotes`
4061
+ // never targets a module at all, and saying so would misname what was searched.
4062
+ // When the graph holds no edges of this kind at all, there is nothing to
4063
+ // read a class from, and "Module" stays the plain default.
4064
+ const entityWord = parsed.entityType
4065
+ ? nounFor(parsed.entityType, 2)
4066
+ : (() => {
4067
+ const kindClasses = [...classesForKinds(graph, kindsFor(parsed.kind))];
4068
+ if (kindClasses.length === 1) return nounFor(kindClasses[0], 2);
4069
+ if (kindClasses.length > 1) return kindClasses.map((c) => nounFor(c, 2)).join(" or ");
4070
+ return nounFor("Module", 2);
4071
+ })();
4059
4072
  // Name the resolved antecedent, not the raw pronoun: "who touched it" that
4060
4073
  // bound "it" to fnAlpha must say so, or the receipt reads as though nothing
4061
4074
  // was resolved at all. Scoped to a context pronoun so a typed term keeps the
@@ -119,6 +119,8 @@ export function relationKind(group) {
119
119
  if (/\b(touch|chang|modif)/.test(pred)) return "touches";
120
120
  if (/\bcontain/.test(pred)) return "contains";
121
121
  if (/\b(inherit|subclass|extend|specializ)/.test(pred)) return "inherits";
122
+ if (/denot/.test(pred)) return "denotes";
123
+ if (/\bserve/.test(pred)) return "serves";
122
124
  return null;
123
125
  }
124
126
 
@@ -386,6 +388,11 @@ export function impactClosure(graph, ind, { maxDepth = 8 } = {}) {
386
388
  if (!coveredBy.has(e.object)) coveredBy.set(e.object, []);
387
389
  coveredBy.get(e.object).push(e.subjectLabel || e.subject);
388
390
  }
391
+ } else if (kind === "serves") {
392
+ // serves runs subject-provides-object (a handler serves a route), the
393
+ // opposite of imports/calls' subject-depends-on-object — so the
394
+ // dependent here is the OBJECT, not the subject.
395
+ for (const e of g.edges) addDependent(e.subject, e.object, e.objectLabel || e.object, g.predicate);
389
396
  }
390
397
  }
391
398
 
@@ -435,7 +442,7 @@ export function renderImpact(graph, ind, { maxDepth = 8 } = {}) {
435
442
  });
436
443
  const truncatedStructural = graph.truncated.filter((t) => {
437
444
  const kind = relationKind({ predicate: t.predicate });
438
- return kind === "imports" || kind === "calls" || kind === "callsSymbol" || kind === "tests";
445
+ return kind === "imports" || kind === "calls" || kind === "callsSymbol" || kind === "tests" || kind === "serves";
439
446
  });
440
447
  if (truncatedStructural.length) {
441
448
  lines.push(
@@ -7483,6 +7483,7 @@ export async function helpText(codeDomainActive = false, helpRows = undefined) {
7483
7483
  ["/goals", "the goals a trace can be recognized against: the maintenance invariants, the tool goals, this world's objective, and your taught actions"],
7484
7484
  ["/syllogise <term>", "work out and remember what follows from the facts about a term (needed for chains longer than 2 hops)"],
7485
7485
  ["/classify <term>", "run the EL classifier and remember what follows from a term (reaches restriction-shaped conclusions /syllogise's chains can't)"],
7486
+ ["/prove <question>", "check a yes/no entailment by DL tableau refutation (\"is rex a dog\") — reaches disjunction and complement-class shapes /classify's EL rules can't, citing what it rests on"],
7486
7487
  ["/export <path>", "write the memory store to a file, as JSONL (the same shape `tmct memory --export` writes)"],
7487
7488
  ["/ingest <path>", "read a local text file and store every fact the recognizer grounds from it (same recognizer as `tmct extract`)"],
7488
7489
  ["remember <X> is a <Y>", "teach a fact in plain English (\"every X is a Y\" and a bare \"X is a Y\" work too)"],
@@ -12589,6 +12590,24 @@ function elClassifyFocus(rows, seedTerms, onPropertyPredicate, someValuesFromPre
12589
12590
  return focus;
12590
12591
  }
12591
12592
 
12593
+ /** /prove's own single-term resolver: the exact stored spelling a surface
12594
+ * word (`isa[1]`/`isa[2]`) names, so `buildTableauKb`'s individual/class
12595
+ * test and `proveEntailment`/`proveSubsumption`'s own concept-name
12596
+ * arguments see the SAME string the fact rows are keyed under, not just a
12597
+ * normalized guess. Tries every plural/singular spelling `factTermVariants`
12598
+ * produces against every row's subject and object, in row order (row order
12599
+ * never varies the answer — normFactTerm is a pure fold, so every variant
12600
+ * present resolves to the one term the store actually uses); falls back to
12601
+ * the bare normalized surface word when the term is stored nowhere yet (an
12602
+ * honest "nothing constrains this" rather than a thrown error). Pure. */
12603
+ function resolveProveTerm(variants, rows, fallback) {
12604
+ for (const r of rows) {
12605
+ if (variants.has(r.subject)) return r.subject;
12606
+ if (variants.has(r.object)) return r.object;
12607
+ }
12608
+ return fallback;
12609
+ }
12610
+
12592
12611
  /** After a learn-on-miss load stored new facts about `term`, run a bounded,
12593
12612
  * focus-scoped forward-chaining pass so the new facts connect to what's
12594
12613
  * already remembered — the auto sibling of the /syllogise command, plus its
@@ -16290,6 +16309,90 @@ async function runCommand(line, { config, source, graph, focus, memoryDir, trace
16290
16309
  }
16291
16310
  }
16292
16311
 
16312
+ // /prove <question> — check a yes/no entailment by DL tableau refutation
16313
+ // (src/domain/tableau.mjs), for a shape /classify's EL completion rules
16314
+ // can't reach: disjunction elimination, complement classes, and every
16315
+ // other class expression the ALC-through-SHOIQ tableau covers.
16316
+ //
16317
+ // Same posture as /syllogise and /classify: an explicit request, a
16318
+ // required question, never the hot path an ordinary ask runs down. Unlike
16319
+ // those two, this one writes NOTHING — a case-split conclusion's own
16320
+ // provenance is an open design problem (PLAN_SYLLOGIST_EL_DL.md section
16321
+ // 14), so the tableau stays query-time only, and every rendered verdict
16322
+ // cites the taught facts it rests on rather than a stored one.
16323
+ //
16324
+ // The question parses through the same "is X a Y" shape the plain ask
16325
+ // lane's isa family already reads (ISA_ASK_RE) — /prove is the explicit
16326
+ // command for a shape that shape's own live chases can't close, not a
16327
+ // second grammar. Refuses by name on anything else.
16328
+ if (name === "prove") {
16329
+ note(trace, "goal: check a yes/no entailment by DL tableau refutation, citing what it rests on");
16330
+ if (!memoryDir) return mk("no memory store here — /prove works inside a repo session.", { miss: true });
16331
+ if (!argText) {
16332
+ return mk('/prove needs a question, e.g. `/prove is rex a dog` — a yes/no shape it can check by tableau refutation.', { miss: true });
16333
+ }
16334
+ const isaMatch = argText.match(ISA_ASK_RE);
16335
+ if (!isaMatch) {
16336
+ return mk('/prove only reads a yes/no shape today, e.g. "is rex a dog" or "is a stone a mammal".', { miss: true });
16337
+ }
16338
+ const subjectWord = isaMatch[1].trim();
16339
+ const classWord = isaMatch[2].trim();
16340
+ try {
16341
+ const { normFactTerm } = await import("../adapters/memory/core.mjs");
16342
+ const { extractTableauModule, buildTableauKb, proveEntailment, proveSubsumption } = await import("../domain/tableau.mjs");
16343
+ const rows = await factRows(memoryDir, cache);
16344
+ const subjectTerm = resolveProveTerm(factTermVariants(normFactTerm, subjectWord), rows, normFactTerm(subjectWord));
16345
+ const classTerm = resolveProveTerm(factTermVariants(normFactTerm, classWord), rows, normFactTerm(classWord));
16346
+ const reasoning = await resolveReasoningConfigForRepo(memoryDir);
16347
+ const proveOpts = { maxSteps: reasoning.proveSteps, maxBranches: reasoning.proveBranches, maxNodes: reasoning.proveNodes };
16348
+ const moduleRows = extractTableauModule(rows, [subjectTerm, classTerm]);
16349
+ const kb = buildTableauKb(moduleRows);
16350
+ const result = kb.namedIndividuals.has(subjectTerm)
16351
+ ? proveEntailment(kb, subjectTerm, { t: "atom", name: classTerm }, proveOpts)
16352
+ : proveSubsumption(kb, subjectTerm, classTerm, proveOpts);
16353
+ note(trace, `result: ${result.status} (steps ${result.steps}, branches ${result.branches})`);
16354
+ const byId = new Map(moduleRows.map((r) => [r.id, r]));
16355
+
16356
+ if (result.status === "proved") {
16357
+ const premiseRows = result.premises.map((id) => byId.get(id)).filter(Boolean);
16358
+ const cited = premiseRows.map(renderFactLine).join("; ");
16359
+ // A case-split conclusion (the ⊔-rule fired on a genuine owl:unionOf
16360
+ // or owl:oneOf premise, not just the ⊑-rule's own routine
16361
+ // TBox-internalization disjunction, which every proof passes
16362
+ // through) reads as reasoning by cases, not a single deduction.
16363
+ const caseSplit = premiseRows.some((r) => r.predicate === "owl:unionOf" || r.predicate === "owl:oneOf");
16364
+ const conclusion = caseSplit ? `in every case, ${subjectWord} is a ${classWord}.` : `so ${subjectWord} is a ${classWord}.`;
16365
+ return mk(`yes — ${cited}; ${conclusion}`);
16366
+ }
16367
+ if (result.status === "disproved") {
16368
+ // A genuine "no", not a miss: the tableau built a consistent model
16369
+ // where the entailment fails, and names the stored facts that model
16370
+ // had to satisfy along the way (every label on the queried
16371
+ // individual's own node, unioned across the branch it found).
16372
+ const node = (result.model?.nodes || []).find((n) => n.id === subjectTerm);
16373
+ const constrainingIds = [...new Set((node?.labels || []).flatMap((l) => l.from || []))].sort();
16374
+ const constrainingRows = constrainingIds.map((id) => byId.get(id)).filter(Boolean);
16375
+ const suffix = constrainingRows.length ? ` What I remember: ${constrainingRows.map(renderFactLine).join("; ")}.` : "";
16376
+ return mk(`no — I can build a consistent picture where ${subjectWord} is not a ${classWord}.${suffix}`);
16377
+ }
16378
+ // exhausted: the honest budget wall, never a downgraded guess. Names
16379
+ // the specific [reasoning] knob (tmct.toml) that ran out, so the
16380
+ // reply says exactly what to raise for a wider search.
16381
+ const knobByReason = { steps: "prove_steps", branches: "prove_branches", nodes: "prove_nodes" };
16382
+ const budgetByReason = { steps: reasoning.proveSteps, branches: reasoning.proveBranches, nodes: reasoning.proveNodes };
16383
+ const reason = knobByReason[result.reason] ? result.reason : "steps";
16384
+ const res = mk(
16385
+ `I can't prove or disprove that within my budget (${budgetByReason[reason]} ${reason}). Nothing was guessed. `
16386
+ + `Raise \`[reasoning] ${knobByReason[reason]}\` in tmct.toml for a wider search.`,
16387
+ { miss: true },
16388
+ );
16389
+ res.record.budgetExhausted = true;
16390
+ return res;
16391
+ } catch (e) {
16392
+ return mk(String(e?.message || e), { miss: true }); // a broken store reads as its own clean error
16393
+ }
16394
+ }
16395
+
16293
16396
  // /export <path> — write the whole memory store as JSONL, the SAME shape
16294
16397
  // `tmct memory --export` and the tmct_export cold tool already emit
16295
16398
  // (serializeFactsJsonl, export-jsonl.mjs) — so a chat session can take its