@polycode-projects/the-mechanical-code-talker 5.0.25 → 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.
Files changed (36) hide show
  1. package/README.md +74 -11
  2. package/bin/tmct.mjs +81 -0
  3. package/package.json +6 -1
  4. package/src/adapters/corpus/courtesy.mjs +91 -28
  5. package/src/adapters/corpus/dbpedia-lookup-live.mjs +116 -0
  6. package/src/adapters/corpus/news-sources.mjs +436 -0
  7. package/src/adapters/corpus/research-source.mjs +16 -3
  8. package/src/adapters/corpus/wiktionary-live.mjs +158 -0
  9. package/src/adapters/news-store.mjs +87 -0
  10. package/src/adapters/toml-config.mjs +18 -0
  11. package/src/domain/ask.mjs +19 -6
  12. package/src/domain/choice-question.mjs +275 -0
  13. package/src/domain/cli-verbs.mjs +20 -0
  14. package/src/domain/codegraph.mjs +8 -1
  15. package/src/domain/dialogue-acts.mjs +1 -0
  16. package/src/domain/el-classify.mjs +569 -0
  17. package/src/domain/fact-phrase.mjs +70 -0
  18. package/src/domain/feed-normalize.mjs +224 -0
  19. package/src/domain/grammar/ace.mjs +223 -7
  20. package/src/domain/grammar/lexicon-core.json +2 -0
  21. package/src/domain/memory/trust.mjs +15 -0
  22. package/src/domain/news-feed.mjs +219 -0
  23. package/src/domain/reasoning-config.mjs +56 -0
  24. package/src/domain/sprite-animation.mjs +20 -2
  25. package/src/domain/tableau.mjs +1225 -0
  26. package/src/domain/term-ledger.mjs +118 -0
  27. package/src/services/chat.mjs +523 -20
  28. package/src/services/extract-facts.mjs +91 -1
  29. package/src/services/index.mjs +12 -0
  30. package/src/services/init.mjs +33 -0
  31. package/src/services/news-viz.mjs +489 -0
  32. package/src/services/news.mjs +918 -0
  33. package/src/services/sprite-catalog-viz.mjs +148 -78
  34. package/src/surfaces/web/memory-ask-browser.bundle.js +132 -132
  35. package/src/surfaces/web/news-browser-entry.mjs +384 -0
  36. package/src/surfaces/web/sprites-browser-entry.mjs +4 -4
@@ -46,7 +46,7 @@ import { setConstructionBanks } from "../domain/interpret/strategies/constructio
46
46
  import { nlpAdapter } from "../adapters/ask-nlp.mjs";
47
47
  import { readConstructionFiles } from "../adapters/corpus/construction-banks.mjs";
48
48
  import { fuzzyMatchInSet, fuzzyBound } from "../domain/interpret/fuzzy.mjs";
49
- import { loadLexicon, lookupNoun, lookupVerb, lookupAdjective, lookupProperName, readsAsIndividualName } from "../domain/grammar/lexicon.mjs";
49
+ import { loadLexicon, lookupNoun, lookupVerb, lookupAdjective, lookupProperName, readsAsIndividualName, CODE_REF_SHAPE } from "../domain/grammar/lexicon.mjs";
50
50
  import { pickPhrase } from "../domain/answer-variants.mjs";
51
51
  import {
52
52
  REFERENCE_PACK_NAME, cleanMissReferenceTerm, renderReferenceAnswer, referenceProvenanceTag,
@@ -62,6 +62,7 @@ import { loadResearchQueue, saveResearchQueue } from "../adapters/research-queue
62
62
  import { CHILD_PACK_NAME, childProvenanceTag } from "../domain/child-pack.mjs";
63
63
  import { getChildPackProvider } from "../adapters/corpus/child-pack.mjs";
64
64
  import { dialogueActForLane } from "../domain/dialogue-acts.mjs";
65
+ import { splitChoiceQuestion } from "../domain/choice-question.mjs";
65
66
  import { subClassParents, subClassChildren, descendantSet, ancestryChain, clusterSenses } from "../domain/sense-split.mjs";
66
67
  import { ANSWER_STOP_SET } from "../domain/hub-terms.mjs";
67
68
  import { relatedForTerm } from "../domain/skos-view.mjs";
@@ -3675,6 +3676,40 @@ async function isAnchorableTerm(term, lex, memoryDir, cache = null, graph = null
3675
3676
  }
3676
3677
  export { isAnchorableTerm };
3677
3678
 
3679
+ /** Per-option grounding for the closed multiple-choice lane (splitChoiceQuestion,
3680
+ * choice-question.mjs): for each option, looks for a stored Fact row whose
3681
+ * {subject, object} pair is {sourceTerm, option} in either direction, under
3682
+ * any predicate. This is PAIR-level grounding, not the term-level check
3683
+ * isAnchorableTerm runs above — almost every option answers "is this term
3684
+ * known at all", but only a stated relation between the source term and THAT
3685
+ * option decides a choice question, which is what this function tests.
3686
+ *
3687
+ * Reads the same rows the rest of chat reads (factRows/factRowsCache), and
3688
+ * pulls the child pack for `sourceTerm` ONCE per turn, only when memory holds
3689
+ * no fact for it yet — the same childPackFactsForKey the learn-on-miss
3690
+ * cascade calls elsewhere in this file. Never pulls per option: seeding the
3691
+ * graph from the question's own distractors would ground every option for
3692
+ * free, which is a slow way to guess rather than an honest probe.
3693
+ *
3694
+ * `chain` stays null on every entry here — a direct-edge probe only. A
3695
+ * bounded findIsaChain chase for an option with no direct edge is later work
3696
+ * (rung 3), which is why `graph` already rides this signature unused. */
3697
+ async function probeChoiceOptions(parsed, { memoryDir, env, cache, graph, synthesisBudget = AUTO_SYNTHESIS_BUDGET }) {
3698
+ const sourceVariants = factTermVariants(normFactTermStatic, parsed.sourceTerm);
3699
+ let rows = await factRows(memoryDir, cache);
3700
+ const hasSourceFacts = rows.some((f) => sourceVariants.has(f.subject) || sourceVariants.has(f.object));
3701
+ if (!hasSourceFacts && memoryDir) {
3702
+ const learned = await childPackFactsForKey(parsed.sourceTerm, { memoryDir, env, cache, synthesisBudget });
3703
+ if (learned) rows = await factRows(memoryDir, cache);
3704
+ }
3705
+ return parsed.options.map((option) => {
3706
+ const optionVariants = factTermVariants(normFactTermStatic, option.text);
3707
+ const facts = rows.filter((f) => (sourceVariants.has(f.subject) && optionVariants.has(f.object))
3708
+ || (sourceVariants.has(f.object) && optionVariants.has(f.subject)));
3709
+ return { label: option.label, text: option.text, grounds: facts.length > 0, facts, chain: null };
3710
+ });
3711
+ }
3712
+
3678
3713
  /** The "both sides ungrounded" grounding NUDGE: reuses teachSuggestion's own
3679
3714
  * "compute a hint, APPEND it to the existing honest-miss message, never
3680
3715
  * replace/silently guess" pattern (see its docblock, above, and the
@@ -5634,6 +5669,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
5634
5669
  // through to the ordinary cascade exactly as it always has.
5635
5670
  if (retractNotMatch) {
5636
5671
  const { loadMemory: loadMemForNeg, normFactTerm: normTermForNeg, readFactRows: readRowsForNeg } = await import("../adapters/memory/core.mjs");
5672
+ const { DISJOINT_PREDICATE: NEG_DISJOINT_PREDICATE } = await import("../domain/syllogise.mjs");
5637
5673
  const negSubject = normTermForNeg(retractSubject);
5638
5674
  const negObject = normTermForNeg(retractObject);
5639
5675
  const priorRows = readRowsForNeg(await loadMemForNeg(memoryDir));
@@ -5663,13 +5699,41 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
5663
5699
  // declining exactly as it always has — this widens which NOUN pairs
5664
5700
  // read as an exclusion, never which property claims do.
5665
5701
  const singularNegation = retractSrc.match(SINGULAR_NEGATION_TEACH_RE);
5666
- if (singularNegation && lookupNoun(loadLexicon(), singularNegation[2])) {
5702
+ if (singularNegation) {
5667
5703
  const [, negationSubject, negationObject] = singularNegation;
5668
- const negUniversal = await mintNegativeUniversal(negationSubject, negationObject, {
5669
- memoryDir, sessionId, observedAt, dateText,
5670
- ackText: `noted — remembered: no ${negationSubject} is a ${negationObject}`,
5671
- });
5672
- if (negUniversal) return negUniversal;
5704
+ const objectIsDeclaredNoun = !!lookupNoun(loadLexicon(), negationObject);
5705
+ // WIDENED ARM — an individual-level negative stores with no lexicon
5706
+ // entry required at all, so long as (a) the subject reads as an
5707
+ // individual — a declared proper name, a code-ref shape, or a term
5708
+ // this store already carries as an rdf:type/subClassOf subject — and
5709
+ // (b) the object is a class this store already carries (the object
5710
+ // of a taught isa fact, or either side of a taught disjointness),
5711
+ // never a bare adjective. TAUGHT facts only (never corpus background)
5712
+ // decide both checks, the same discipline isTaughtFact applies
5713
+ // elsewhere in this file — a corpus row mentioning "mortal" must never
5714
+ // be able to smuggle an adjective past the guard "zeus is not mortal"
5715
+ // keeps.
5716
+ const isTaughtRow = (r) => !String(r.provenance || "").includes("corpus:") && !String(r.provenance || "").includes("web:");
5717
+ const normNegationSubject = normTermForNeg(negationSubject);
5718
+ const normNegationObject = normTermForNeg(negationObject);
5719
+ const objectIsStoredClass = !objectIsDeclaredNoun && priorRows.some((r) => isTaughtRow(r) && (
5720
+ (ISA_PREDICATES.has(r.predicate) && r.object === normNegationObject)
5721
+ || (r.predicate === NEG_DISJOINT_PREDICATE && (r.subject === normNegationObject || r.object === normNegationObject))
5722
+ ));
5723
+ const subjectIsIndividual = objectIsStoredClass && (
5724
+ !!lookupProperName(loadLexicon(), negationSubject)
5725
+ || CODE_REF_SHAPE.test(negationSubject)
5726
+ || priorRows.some((r) => isTaughtRow(r) && r.subject === normNegationSubject && ISA_PREDICATES.has(r.predicate))
5727
+ );
5728
+ if (objectIsDeclaredNoun || subjectIsIndividual) {
5729
+ const negUniversal = await mintNegativeUniversal(negationSubject, negationObject, {
5730
+ memoryDir, sessionId, observedAt, dateText,
5731
+ ackText: objectIsDeclaredNoun
5732
+ ? `noted — remembered: no ${negationSubject} is a ${negationObject}`
5733
+ : `noted — remembered: ${negationSubject} is not a ${negationObject}`,
5734
+ });
5735
+ if (negUniversal) return negUniversal;
5736
+ }
5673
5737
  }
5674
5738
 
5675
5739
  // Nothing stored to disagree with. The gate above is right to refuse
@@ -7418,6 +7482,8 @@ export async function helpText(codeDomainActive = false, helpRows = undefined) {
7418
7482
  ["/capabilities", "what /plan can plan over: the built-in graph tools plus your taught actions"],
7419
7483
  ["/goals", "the goals a trace can be recognized against: the maintenance invariants, the tool goals, this world's objective, and your taught actions"],
7420
7484
  ["/syllogise <term>", "work out and remember what follows from the facts about a term (needed for chains longer than 2 hops)"],
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"],
7421
7487
  ["/export <path>", "write the memory store to a file, as JSONL (the same shape `tmct memory --export` writes)"],
7422
7488
  ["/ingest <path>", "read a local text file and store every fact the recognizer grounds from it (same recognizer as `tmct extract`)"],
7423
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)"],
@@ -7586,6 +7652,10 @@ const FACT_PREDICATE_PHRASES = {
7586
7652
  "mgxneg:subClassOf": "is not a kind of",
7587
7653
  "rdf:type": "is a",
7588
7654
  "owl:disjointWith": "is not a",
7655
+ "owl:unionOf": "is either",
7656
+ "owl:complementOf": "is anything that is not",
7657
+ "owl:oneOf": "includes exactly",
7658
+ "owl:differentFrom": "is not the same as",
7589
7659
  "mgx:partOf": "is part of",
7590
7660
  "mgx:memberOf": "is a member of",
7591
7661
  "mgx:collectionOf": "is a collection of",
@@ -7639,6 +7709,15 @@ const WORLD_INTERNAL_PREDICATES = new Set([
7639
7709
  "mgx:is-container", "mgx:is-open",
7640
7710
  ]);
7641
7711
 
7712
+ /** A `<role> rdf:type owl:TransitiveProperty` declaration is role scaffolding,
7713
+ * not a fact about the role a reader wants listed back in English — it never
7714
+ * renders as a plain fact line, the same discipline that keeps the
7715
+ * restriction scaffolding predicates (owl:onProperty, owl:someValuesFrom, …)
7716
+ * out of FACT_PREDICATE_PHRASES. */
7717
+ function isTransitivePropertyDeclaration(f) {
7718
+ return f.predicate === TYPE_PREDICATE && f.object === "transitiveproperty";
7719
+ }
7720
+
7642
7721
  /** The world PLACEMENT predicates carry curated phrases above so they render as
7643
7722
  * English, but they must stay OUT of the query-marker families derived from
7644
7723
  * FACT_PREDICATE_PHRASES — "what is in the study" is a members-of-class query,
@@ -7805,6 +7884,41 @@ function renderFactLine(f) {
7805
7884
  return `i learned: ${factPhrase(f)}${cite}`;
7806
7885
  }
7807
7886
 
7887
+ /** A union node's stored triples read back as ONE sentence rather than a
7888
+ * row-per-member dump: "every pet is a cat or a dog (source: …)". `node` is
7889
+ * the `<parent> rdfs:subClassOf <unionNode>` fact row (the parent and the
7890
+ * citation both come from it); `members` are the union node's own
7891
+ * `owl:unionOf` rows, sorted here by member name so the same union always
7892
+ * reads back the same way regardless of the order its rows arrived in.
7893
+ * Pure — takes the fact rows, returns one line. */
7894
+ function renderUnionLine(node, members) {
7895
+ const sorted = [...members].sort((a, b) => a.object.localeCompare(b.object));
7896
+ const cite = node.provenance ? ` (source: ${citationProvenance(node.provenance)})` : "";
7897
+ const arms = sorted.map((m) => `${indefiniteArticleFor(m.object)} ${m.object}`).join(" or ");
7898
+ return `every ${node.subject} is ${arms}${cite}`;
7899
+ }
7900
+
7901
+ /** An enumerated class's stored `owl:oneOf` triples read back as ONE sentence:
7902
+ * "the primary colours are exactly red, yellow and blue (source: …)". `cls`
7903
+ * is the enumerated class's own term; `members` are its `owl:oneOf` rows,
7904
+ * sorted here by member name for the same order-independence renderUnionLine
7905
+ * keeps. The class name pluralizes through the same naive "+s/+es/+ies" fold
7906
+ * thirdPersonSingularSurface already applies to a verb lemma — the same
7907
+ * accepted trade documented there. Pure — takes the fact rows, returns one
7908
+ * line. */
7909
+ function renderEnumerationLine(cls, members) {
7910
+ const sorted = [...members].sort((a, b) => a.object.localeCompare(b.object));
7911
+ const names = sorted.map((m) => m.object);
7912
+ const list = names.length > 1
7913
+ ? `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`
7914
+ : names.join("");
7915
+ const citeSource = sorted.find((m) => m.provenance)?.provenance;
7916
+ const cite = citeSource ? ` (source: ${citationProvenance(citeSource)})` : "";
7917
+ const plural = thirdPersonSingularSurface(String(cls || "").replace(/-/g, " "));
7918
+ return `the ${plural} are exactly ${list}${cite}`;
7919
+ }
7920
+ export { renderUnionLine, renderEnumerationLine };
7921
+
7808
7922
  const SENSE_CITE_RE = / \(source: [^)]*\)$/;
7809
7923
 
7810
7924
  /** Append an is-a object's superclass chain to its rendered fact line, before
@@ -8426,6 +8540,14 @@ function apposedFactTerm(term, rows, normFactTerm) {
8426
8540
  * factReadBack(...)` — never both). */
8427
8541
  const CAN_ASK_RE = /^(?:can|could)\s+(all\s+|every\s+)?(?:an?\s+)?([\w'-]+(?:\s+[\w'-]+)*?)\s+([a-z]+)[?.!\s]*$/i;
8428
8542
  const DOES_HAVE_ASK_RE = /^(?:does|do)\s+(?:an?\s+|the\s+)?(.+?)\s+have\s+(?:an?\s+|the\s+)?(.+?)[?.!\s]*$/i;
8543
+ /** The class-level existential sibling of DOES_HAVE_ASK_RE for a verb OTHER
8544
+ * than "have" — "does a heart contain a hinge". A someValuesFrom
8545
+ * restriction (taught, or EL-entailed by /classify) never cares which
8546
+ * English near-synonym for "has" named it, and the store carries no
8547
+ * per-verb sense distinction for this shape yet, so restrictionExistentialHit
8548
+ * answers on the (subject, filler) SHAPE alone, tried only once
8549
+ * DOES_HAVE_ASK_RE's own literal-"have" reader has already declined. */
8550
+ const DOES_EXISTENTIAL_ASK_RE = /^(?:does|do)\s+(?:an?\s+|the\s+)?(.+?)\s+([a-z]+)\s+(?:an?\s+|the\s+)?(.+?)[?.!\s]*$/i;
8429
8551
  const WHAT_CAN_DO_RE = /^what\s+can\s+(?:an?\s+)?(.+?)\s+do[?.!\s]*$/i;
8430
8552
  const WHAT_HAS_RE = /^what\s+has\s+(?:an?\s+)?(.+?)[?.!\s]*$/i;
8431
8553
  // "what is used for riding" / "what can be used for riding" / "what is for
@@ -8828,6 +8950,61 @@ function withDeducedGoal(res, envelope, query) {
8828
8950
  return goal ? { ...res, goal } : res;
8829
8951
  }
8830
8952
 
8953
+ /** The class-level existential mirror of a direct hasA/tmct:has fact: a
8954
+ * stored (taught, or EL-entailed by /classify) someValuesFrom restriction
8955
+ * reachable from the subject names the filler. Runs off `factRows` rather
8956
+ * than the reduced `memoryFacts` shape because the citation needs each
8957
+ * hit's own `justification` — an EL-derived restriction cites the taught
8958
+ * premises it composed (e.g. "heart is a kind of some-has-valve; valve is a
8959
+ * kind of flap"), not just its own single entailed row. Falls back to
8960
+ * citing the hit itself when no subClassOf premise is on record (a directly
8961
+ * taught, unchained restriction). Returns the rendered `{text,
8962
+ * replace: true}` yes turn on a hit. On a miss, `subjectWord` (the surface
8963
+ * text the question named the subject with) decides the reply: the subject
8964
+ * has SOME remembered restriction that just doesn't reach this filler, so
8965
+ * the miss names `/classify` — the one command that can compose further
8966
+ * ("/syllogise" is never offered here, since its plain scm-sco chase never
8967
+ * touches a class expression) — or, with no restriction on the subject at
8968
+ * all, plain null so the caller's own miss cascade stands unchanged. */
8969
+ async function restrictionExistentialHit(memoryDir, cache, subjectVariants, fillerVariants, subjectWord = null) {
8970
+ const { ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE } = await import("../domain/syllogise.mjs");
8971
+ const rows = await factRows(memoryDir, cache);
8972
+ const onPropertyOf = new Map();
8973
+ const someValuesFromOf = new Map();
8974
+ for (const r of rows) {
8975
+ if (r.predicate === ON_PROPERTY_PREDICATE) onPropertyOf.set(r.subject, r.object);
8976
+ else if (r.predicate === SOME_VALUES_FROM_PREDICATE) someValuesFromOf.set(r.subject, r.object);
8977
+ }
8978
+ // Restricted to a genuine someValuesFrom restriction — onProperty alone
8979
+ // also marks a cardinality restriction (owl:maxCardinality/minCardinality/
8980
+ // cardinality, no someValuesFrom row of its own), which classifyEl's EL
8981
+ // rules never touch; offering /classify over one would be wrong advice,
8982
+ // and it would also swallow a query the cardinality live chases
8983
+ // (factReadBackReaders' CARD_AT_LEAST_ASK_RE/CARD_EXISTENCE_ASK_RE) are
8984
+ // the ones meant to answer, including a provable "no".
8985
+ const subjectRestrictions = rows.filter((r) => r.predicate === SUBCLASS_PREDICATE && subjectVariants.has(r.subject)
8986
+ && onPropertyOf.has(r.object) && someValuesFromOf.has(r.object));
8987
+ const hit = subjectRestrictions
8988
+ .filter((r) => fillerVariants.has(someValuesFromOf.get(r.object)))
8989
+ .sort((a, b) => a.object.localeCompare(b.object))[0];
8990
+ if (hit) {
8991
+ const byId = new Map(rows.map((r) => [r.id, r]));
8992
+ const premises = (hit.justification || [])
8993
+ .map((id) => byId.get(id))
8994
+ .filter((r) => r && r.predicate === SUBCLASS_PREDICATE);
8995
+ const cited = premises.length ? premises : [hit];
8996
+ return { text: `yes — ${cited.map(renderFactLine).join("; ")}`, replace: true };
8997
+ }
8998
+ if (subjectRestrictions.length && subjectWord) {
8999
+ return {
9000
+ text: `I can't confirm that — nothing I remember composes to it yet. Run "/classify ${subjectWord}", then ask me again.`,
9001
+ replace: true,
9002
+ miss: true,
9003
+ };
9004
+ }
9005
+ return null;
9006
+ }
9007
+
8831
9008
  async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle = {}, cache = null, focusLabel = null) {
8832
9009
  let normFactTerm; let normFactPredicate;
8833
9010
  try { ({ normFactTerm, normFactPredicate } = await import("../adapters/memory/core.mjs")); } catch { return null; }
@@ -9167,7 +9344,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
9167
9344
  // and mechanics predicates are dropped so "what is the letter" never reads
9168
9345
  // back where it's hidden or that it's the objective (WORLD_INTERNAL_PREDICATES).
9169
9346
  const subjectHits = (await factRows(memoryDir, cache))
9170
- .filter((f) => variants.has(f.subject) && !WORLD_INTERNAL_PREDICATES.has(f.predicate));
9347
+ .filter((f) => variants.has(f.subject) && !WORLD_INTERNAL_PREDICATES.has(f.predicate) && !isTransitivePropertyDeclaration(f));
9171
9348
  // Matched through normFactPredicate, so a fact stored under a minted
9172
9349
  // spelling of the same relation ("mgx:used-for", from the participle
9173
9350
  // teach frame, in a store written before the spellings converged) is
@@ -9452,7 +9629,24 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
9452
9629
  if (!nextFrontier.length) break;
9453
9630
  frontier = nextFrontier;
9454
9631
  }
9455
- return null;
9632
+ // No direct or ⊑-lifted possession fact — a bare-existential teach or an
9633
+ // EL classification stores the SAME knowledge as a subClassOf-to-
9634
+ // restriction chain rather than a flat possession triple, so try that
9635
+ // shape before declining.
9636
+ return restrictionExistentialHit(memoryDir, cache, subj, obj, doesHave[1].trim());
9637
+ }
9638
+
9639
+ // (b2b-el) "does a heart contain a hinge" — DOES_HAVE_ASK_RE only ever
9640
+ // matches the literal verb "have"; a class-level existential question can
9641
+ // use any near-synonym, so this sibling reader tries the SAME restriction
9642
+ // chase restrictionExistentialHit runs above, keyed on shape alone, once
9643
+ // (b2b)'s own literal-"have" surface has already declined to match at all.
9644
+ const doesExistential = q.match(DOES_EXISTENTIAL_ASK_RE);
9645
+ if (doesExistential) {
9646
+ const subj = factTermVariants(normFactTerm, doesExistential[1]);
9647
+ const obj = factTermVariants(normFactTerm, doesExistential[3]);
9648
+ const hit = await restrictionExistentialHit(memoryDir, cache, subj, obj, doesExistential[1].trim());
9649
+ if (hit) return hit;
9456
9650
  }
9457
9651
 
9458
9652
  // (b2c) "do birds fly" — the do-support surface of (b2), same capableOf
@@ -9773,7 +9967,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
9773
9967
  // objective, and those datatype internals render as garbled non-English
9774
9968
  // besides. The adventure's own where/openness readers answer the legitimate
9775
9969
  // in-game questions from the world fold.
9776
- hits = hits.filter((f) => !WORLD_INTERNAL_PREDICATES.has(f.predicate));
9970
+ hits = hits.filter((f) => !WORLD_INTERNAL_PREDICATES.has(f.predicate) && !isTransitivePropertyDeclaration(f));
9777
9971
  // A corpus-weak-only result set (every hit resolved ONLY through
9778
9972
  // ConceptNet's /r/RelatedTo tier) still composes its hedged "possibly"
9779
9973
  // lines below exactly as before — this reader's whole job is showing
@@ -11123,9 +11317,29 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
11123
11317
  );
11124
11318
  if (knownSubjectIsa.length) {
11125
11319
  const shown = knownSubjectIsa.slice(0, 3).map(renderFactLine).join("; ");
11126
- const recovery = deeperChainExists
11127
- ? `The facts to settle it are here, but the chain is longer than I follow while answering. Run "/syllogise ${subjectWord}", then ask me again.`
11128
- : `If it's true, teach me: "${subjectWord} is a kind of ${kindWord}". If it isn't, teach me: "no ${subjectWord} is a ${kindWord}".`;
11320
+ // A someValuesFrom restriction node among the subject's own remembered
11321
+ // isa facts means the gap is a class expression /syllogise's plain
11322
+ // scm-sco chase never reaches — /classify is the offer that can
11323
+ // actually close it, named instead of /syllogise rather than beside
11324
+ // it, so the offer never points at a command that provably can't help.
11325
+ // A CARDINALITY restriction (owl:maxCardinality/minCardinality/
11326
+ // cardinality, also onProperty-bearing but with no someValuesFrom row
11327
+ // of its own) is excluded on purpose: classifyEl's rules don't touch
11328
+ // that shape either.
11329
+ const { ON_PROPERTY_PREDICATE: RESTRICTION_ON_PROPERTY, SOME_VALUES_FROM_PREDICATE: RESTRICTION_SOME_VALUES_FROM } = await import("../domain/syllogise.mjs");
11330
+ const onPropertyNodes = new Set();
11331
+ const someValuesFromNodes = new Set();
11332
+ for (const f of rows) {
11333
+ if (f.predicate === RESTRICTION_ON_PROPERTY) onPropertyNodes.add(f.subject);
11334
+ else if (f.predicate === RESTRICTION_SOME_VALUES_FROM) someValuesFromNodes.add(f.subject);
11335
+ }
11336
+ const restrictionNodes = new Set([...onPropertyNodes].filter((n) => someValuesFromNodes.has(n)));
11337
+ const involvesRestriction = knownSubjectIsa.some((f) => restrictionNodes.has(f.object));
11338
+ const recovery = involvesRestriction
11339
+ ? `The facts to settle it are here, but reaching it means composing a restriction /syllogise doesn't follow. Run "/classify ${subjectWord}", then ask me again.`
11340
+ : deeperChainExists
11341
+ ? `The facts to settle it are here, but the chain is longer than I follow while answering. Run "/syllogise ${subjectWord}", then ask me again.`
11342
+ : `If it's true, teach me: "${subjectWord} is a kind of ${kindWord}". If it isn't, teach me: "no ${subjectWord} is a ${kindWord}".`;
11129
11343
  return {
11130
11344
  text: `I can't confirm that — nothing I remember says ${subjectWord} is a ${kindWord}. I do know: ${shown}. ${recovery}`,
11131
11345
  replace: true,
@@ -12318,26 +12532,125 @@ async function ingestReferenceArticle(memoryDir, key, article, cache, tagFor = r
12318
12532
  // materialisation, not the whole-store maintenance job /syllogise runs.
12319
12533
  const AUTO_SYNTHESIS_BUDGET = 12;
12320
12534
 
12535
+ /** The `[reasoning]` knobs for a classification pass rooted at `memoryDir` —
12536
+ * the repo's own `tmct.toml` when it sets one, the shipped defaults
12537
+ * otherwise. `resolveReasoningConfig` wants the NORMALIZED sparse pass-
12538
+ * through `normalizeConfig` produces (a bare `loadTomlConfig` object has no
12539
+ * `.reasoning` key of its own), the same load-then-normalize sequence the
12540
+ * CLI's own `resolveRuntimeConfig` already runs. Failure-tolerant: a missing
12541
+ * or unreadable `tmct.toml` degrades to the defaults, never a thrown error. */
12542
+ async function resolveReasoningConfigForRepo(memoryDir) {
12543
+ const { resolveReasoningConfig } = await import("../domain/reasoning-config.mjs");
12544
+ try {
12545
+ const { loadTomlConfig, normalizeConfig } = await import("../adapters/toml-config.mjs");
12546
+ const raw = await loadTomlConfig(memoryDir);
12547
+ const normalized = await normalizeConfig(raw, { configDir: memoryDir });
12548
+ return resolveReasoningConfig(normalized);
12549
+ } catch {
12550
+ return resolveReasoningConfig(null);
12551
+ }
12552
+ }
12553
+
12554
+ /** The focus set classifyEl needs to reach a bare-existential or transitive-
12555
+ * role chain rooted at `seedTerms`: each seed's own `rdfs:subClassOf`
12556
+ * descendant walk, folded through every someValuesFrom restriction it
12557
+ * reaches onto that restriction's own filler, walked again from there — so
12558
+ * a taught "heart ⊑ ∃has.valve, valve ⊑ ∃has.hinge" reaches both `valve`
12559
+ * and `hinge` from a focus seeded on `heart` alone. classifyEl's own focus
12560
+ * gate takes its input as given (unlike syllogise's `expandFocus`, it has no
12561
+ * expansion step of its own), so this walk runs here rather than inside the
12562
+ * classifier. Bounded by `hops`. Pure. */
12563
+ function elClassifyFocus(rows, seedTerms, onPropertyPredicate, someValuesFromPredicate, hops = 8) {
12564
+ const subClassOf = new Map();
12565
+ const onPropertyOf = new Map();
12566
+ const someValuesFromOf = new Map();
12567
+ for (const r of rows) {
12568
+ if (r.predicate === SUBCLASS_PREDICATE) {
12569
+ if (!subClassOf.has(r.subject)) subClassOf.set(r.subject, []);
12570
+ subClassOf.get(r.subject).push(r.object);
12571
+ } else if (r.predicate === onPropertyPredicate) {
12572
+ onPropertyOf.set(r.subject, r.object);
12573
+ } else if (r.predicate === someValuesFromPredicate) {
12574
+ someValuesFromOf.set(r.subject, r.object);
12575
+ }
12576
+ }
12577
+ const focus = new Set(seedTerms);
12578
+ let frontier = [...focus];
12579
+ for (let hop = 0; hop < hops && frontier.length; hop += 1) {
12580
+ const next = [];
12581
+ for (const t of frontier) {
12582
+ for (const obj of subClassOf.get(t) || []) {
12583
+ if (!focus.has(obj)) { focus.add(obj); next.push(obj); }
12584
+ const filler = onPropertyOf.has(obj) ? someValuesFromOf.get(obj) : null;
12585
+ if (filler && !focus.has(filler)) { focus.add(filler); next.push(filler); }
12586
+ }
12587
+ }
12588
+ frontier = next;
12589
+ }
12590
+ return focus;
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
+
12321
12611
  /** After a learn-on-miss load stored new facts about `term`, run a bounded,
12322
12612
  * focus-scoped forward-chaining pass so the new facts connect to what's
12323
- * already remembered — the auto sibling of the /syllogise command. Derived
12613
+ * already remembered — the auto sibling of the /syllogise command, plus its
12614
+ * EL sibling (the auto sibling of /classify): the same seed focus feeds
12615
+ * both, syllogise expanding it through its own `expandFocus`, classifyEl
12616
+ * through `elClassifyFocus` since it has no such option of its own. Derived
12324
12617
  * facts carry entailed:* provenance at their discounted trust and are
12325
- * retractable. Failure-tolerated: a synthesis miss never disturbs the answer
12326
- * the load already composed. Returns the count derived. */
12618
+ * retractable. Both passes are failure-tolerated and independent of each
12619
+ * other: neither a syllogise miss nor an EL miss disturbs the answer the
12620
+ * load already composed, or the other pass's own result. Returns the total
12621
+ * count derived across both. */
12327
12622
  async function synthesiseAroundTerm(memoryDir, term, cache, budget = AUTO_SYNTHESIS_BUDGET) {
12328
12623
  if (!memoryDir || !term || budget <= 0) return 0;
12624
+ let count = 0;
12329
12625
  try {
12330
12626
  const { syllogise } = await import("../domain/syllogise.mjs");
12331
12627
  const { loadMemory, readFactRows, appendFacts, normFactTerm } = await import("../adapters/memory/core.mjs");
12628
+ const seedFocus = [...factTermVariants(normFactTerm, term)];
12332
12629
  const res = await syllogise(memoryDir, {
12333
- focus: [...factTermVariants(normFactTerm, term)],
12630
+ focus: seedFocus,
12334
12631
  expandFocus: true,
12335
12632
  budget,
12336
12633
  store: { loadMemory, readFactRows, appendFacts },
12337
12634
  });
12338
- if (res?.count && cache) cache.rows = null;
12339
- return res?.count || 0;
12340
- } catch { return 0; }
12635
+ if (res?.count) { count += res.count; if (cache) cache.rows = null; }
12636
+ } catch { /* a syllogise miss never disturbs the answer the load already composed */ }
12637
+ try {
12638
+ const { classifyEl } = await import("../domain/el-classify.mjs");
12639
+ const { ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE } = await import("../domain/syllogise.mjs");
12640
+ const { loadMemory, readFactRows, appendFacts, normFactTerm } = await import("../adapters/memory/core.mjs");
12641
+ const seedFocus = [...factTermVariants(normFactTerm, term)];
12642
+ const rows = readFactRows(await loadMemory(memoryDir));
12643
+ const focus = elClassifyFocus(rows, seedFocus, ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE);
12644
+ const reasoning = await resolveReasoningConfigForRepo(memoryDir);
12645
+ const elRes = await classifyEl(memoryDir, {
12646
+ budget: reasoning.classifyBudget,
12647
+ rounds: reasoning.classifyRounds,
12648
+ focus,
12649
+ store: { loadMemory, readFactRows, appendFacts },
12650
+ });
12651
+ if (elRes?.count) { count += elRes.count; if (cache) cache.rows = null; }
12652
+ } catch { /* an EL pass miss never disturbs the answer the load already composed */ }
12653
+ return count;
12341
12654
  }
12342
12655
 
12343
12656
  /** The term an explicit "ask Wikipedia" phrasing names — "what does wikipedia
@@ -15948,6 +16261,138 @@ async function runCommand(line, { config, source, graph, focus, memoryDir, trace
15948
16261
  }
15949
16262
  }
15950
16263
 
16264
+ // /classify <term> — run one bounded EL saturation pass (src/domain/el-
16265
+ // classify.mjs) over what's remembered about a term and WRITE the entailed
16266
+ // facts it closes over. /syllogise's own rule set only chains
16267
+ // rdfs:subClassOf/rdf:type edges; /classify's seven EL completion rules
16268
+ // additionally reach class expressions the graph never declared as a node
16269
+ // (an owl:someValuesFrom restriction), so the two commands cover different
16270
+ // ground rather than one superseding the other. Same posture as
16271
+ // /syllogise: an explicit request, a required term (the whole-store pass
16272
+ // spends its budget on facts nobody asked about), and every written fact
16273
+ // carries entailed:el-* provenance, a justification and a trust discounted
16274
+ // below the premises it rode.
16275
+ if (name === "classify") {
16276
+ note(trace, "goal: classify what's remembered about one term under the EL completion rules, writing what follows");
16277
+ if (!memoryDir) return mk("no memory store here — /classify works inside a repo session.", { miss: true });
16278
+ if (!argText) {
16279
+ return mk('/classify needs a term, e.g. `/classify heart` — it closes over what I remember about that term.', { miss: true });
16280
+ }
16281
+ try {
16282
+ const { classifyEl } = await import("../domain/el-classify.mjs");
16283
+ const { loadMemory, readFactRows, appendFacts, normFactTerm } = await import("../adapters/memory/core.mjs");
16284
+ const { SUBCLASS_PREDICATE, ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE } = await import("../domain/syllogise.mjs");
16285
+ const reasoning = await resolveReasoningConfigForRepo(memoryDir);
16286
+ const rows = readFactRows(await loadMemory(memoryDir));
16287
+ const focus = elClassifyFocus(rows, [...factTermVariants(normFactTerm, argText)], ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE);
16288
+ const res = await classifyEl(memoryDir, {
16289
+ budget: reasoning.classifyBudget,
16290
+ rounds: reasoning.classifyRounds,
16291
+ focus,
16292
+ store: { loadMemory, readFactRows, appendFacts },
16293
+ });
16294
+ note(trace, `result: derived ${res.count} entailed fact(s) (rounds ${res.rounds}, budget ${res.budget})`);
16295
+ if (!res.count) {
16296
+ return mk(`nothing new classifies from what I remember about "${argText}" — no entailed facts derived (rounds ${res.rounds}, budget ${res.budget}).`, { miss: true });
16297
+ }
16298
+ const lines = [`derived ${res.count} entailed fact(s) classifying "${argText}":`];
16299
+ for (const d of res.derived) lines.push(` ${d.subject} ${SUBCLASS_PREDICATE} ${d.object} (${d.rule})`);
16300
+ // Same reasoning as /syllogise's own budget-wall line: a truncated pass
16301
+ // that still can't answer the question is worse than no offer at all.
16302
+ if (res.truncated) {
16303
+ lines.push(`budget of ${res.budget} reached — more may follow; run \`tmct classify --budget <n>\` for a wider pass.`);
16304
+ }
16305
+ lines.push("These are derived, not taught — /memory shows each one's provenance and premises.");
16306
+ return mk(lines.join("\n"));
16307
+ } catch (e) {
16308
+ return mk(String(e?.message || e), { miss: true }); // a broken store reads as its own clean error
16309
+ }
16310
+ }
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
+
15951
16396
  // /export <path> — write the whole memory store as JSONL, the SAME shape
15952
16397
  // `tmct memory --export` and the tmct_export cold tool already emit
15953
16398
  // (serializeFactsJsonl, export-jsonl.mjs) — so a chat session can take its
@@ -17533,6 +17978,64 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
17533
17978
  }
17534
17979
 
17535
17980
  if (workingLine.startsWith("/")) return withLast(await runCommand(workingLine, ctx), "use a specific tool/command directly");
17981
+ // CLOSED MULTIPLE-CHOICE — "is a whale a fish or a mammal", "A) ... B) ...".
17982
+ // Recognized and answered ENTIRELY here, before the write boundary just
17983
+ // below (assertTurn/bareTaxonomyTeach): a choice question's own object slot
17984
+ // carries "or", and falling through would hand that slot to the teach-offer
17985
+ // cascade, which reads it as a thing to be taught — the same failure mode
17986
+ // TEMPORAL_COMPARISON_RE (runAsk, above) exists to dodge for its own shape.
17987
+ // Placed here rather than beside the temporal lanes in runAsk (the closer
17988
+ // stylistic precedent) because runAsk's own band sits AFTER this boundary —
17989
+ // a choice question routed there would still pass through assertTurn first,
17990
+ // resting the write-boundary guarantee on teachLane's own stand-down gates
17991
+ // rather than on control flow. Every branch below resolves the turn; none
17992
+ // falls through, so the boundary holds structurally.
17993
+ {
17994
+ const parsed = splitChoiceQuestion(workingLine);
17995
+ if (parsed) {
17996
+ const choiceGoal = "pick the option a stated relation grounds, among a closed set of alternatives";
17997
+ const refMiss = (text) => {
17998
+ note(trace, `goal: ${choiceGoal}`);
17999
+ note(trace, `lane: splitChoiceQuestion — "${workingLine}" parsed as a ${parsed.shape} choice question but could not compose an answer`);
18000
+ return withLast(plainTurn(workingLine, text, { via: "miss", miss: true, focus, goal: choiceGoal }), choiceGoal);
18001
+ };
18002
+ if (!parsed.sourceTerm) {
18003
+ return refMiss(`I can't tell what these options are alternatives about — nothing in "${parsed.stem}" reads as a subject term to check them against.`);
18004
+ }
18005
+ const probed = await probeChoiceOptions(parsed, { memoryDir, env, cache: factRowsCache, graph, synthesisBudget });
18006
+ const grounded = probed.filter((o) => o.grounds);
18007
+ note(trace, `goal: ${choiceGoal}`);
18008
+ if (grounded.length === 0) {
18009
+ note(trace, `lane: splitChoiceQuestion — no stated relation between "${parsed.sourceTerm}" and any of ${probed.length} options; the honest miss, never a guess`);
18010
+ return refMiss(`I don't know how "${parsed.sourceTerm}" relates to any of ${joinOr(probed.map((o) => o.text))}. Nothing I hold connects it to one of them.`);
18011
+ }
18012
+ if (grounded.length > 1) {
18013
+ // A tie is reported, never broken — whatever the grounded options'
18014
+ // own edge weights, this branch fires on COUNT alone.
18015
+ note(trace, `lane: splitChoiceQuestion — ${grounded.length} of ${probed.length} options ground against "${parsed.sourceTerm}"; reported as a tie`);
18016
+ const text = `More than one of those grounds: ${joinOr(grounded.map((o) => o.text))}. I have a stated relation from ${parsed.sourceTerm} to each, so nothing in what I hold picks between them.`;
18017
+ const turn = plainTurn(workingLine, text, { via: "composed", miss: false, focus, goal: choiceGoal });
18018
+ turn.lane = "ask-choice";
18019
+ turn.detail = {
18020
+ traversal: `${grounded.length} of ${probed.length} options grounded against "${parsed.sourceTerm}"`,
18021
+ matches: grounded.flatMap((o) => o.facts),
18022
+ };
18023
+ return withLast(turn, choiceGoal);
18024
+ }
18025
+ const winner = grounded[0];
18026
+ const fact = winner.facts.slice().sort((a, b) => b.trust - a.trust)[0];
18027
+ note(trace, `lane: splitChoiceQuestion — exactly one option ("${winner.label}") grounds against "${parsed.sourceTerm}"; cited the deciding fact`);
18028
+ const text = `${winner.text} — ${factPhrase(fact)} (source: ${citationProvenance(fact.provenance)}).`;
18029
+ const turn = plainTurn(workingLine, text, { via: "composed", miss: false, focus, goal: choiceGoal });
18030
+ turn.lane = "ask-choice";
18031
+ turn.detail = {
18032
+ traversal: `option "${winner.label}" grounded against "${parsed.sourceTerm}" via ${fact.predicate}`,
18033
+ matches: winner.facts,
18034
+ selectedLabel: winner.label,
18035
+ };
18036
+ return withLast(turn, choiceGoal);
18037
+ }
18038
+ }
17536
18039
  // Declarative ACE sentences ("every module is a artifact") ASSERT into tmct's
17537
18040
  // own memory and confirm — they are statements to remember, not graph queries.
17538
18041
  // Gated on memoryDir: only a session shell provides a write target, so a bare