@polycode-projects/the-mechanical-code-talker 5.0.29 → 5.0.31

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.
@@ -2848,6 +2848,10 @@ const SUBCLASS_PREDICATE = "rdfs:subClassOf";
2848
2848
  // direct-write teach paths below stay in that family without re-typing the
2849
2849
  // CURIE string at each call site.
2850
2850
  const TYPE_PREDICATE = "rdf:type";
2851
+ // Role-hierarchy declaration — ACE pattern 19's own emitted predicate
2852
+ // (grammar/ace.mjs's parseSubProperty), named here for the same reason
2853
+ // SUBCLASS_PREDICATE and TYPE_PREDICATE are.
2854
+ const SUB_PROPERTY_OF_PREDICATE = "rdfs:subPropertyOf";
2851
2855
  // HAS_A_PREDICATE (imported from memory/core.mjs, the canonical home) keeps
2852
2856
  // generalVerbTeach's "has"/"have" special case in the same family ConceptNet's
2853
2857
  // /r/HasA corpus facts already use, rather than minting a redundant mgx:has.
@@ -7664,14 +7668,25 @@ const WORLD_INTERNAL_PREDICATES = new Set([
7664
7668
  "mgx:is-container", "mgx:is-open",
7665
7669
  ]);
7666
7670
 
7667
- /** A `<role> rdf:type owl:TransitiveProperty` declaration is role scaffolding,
7668
- * not a fact about the role a reader wants listed back in English — it never
7669
- * renders as a plain fact line, the same discipline that keeps the
7670
- * restriction scaffolding predicates (owl:onProperty, owl:someValuesFrom, …)
7671
- * out of FACT_PREDICATE_PHRASES. */
7672
- function isTransitivePropertyDeclaration(f) {
7673
- return f.predicate === TYPE_PREDICATE && f.object === "transitiveproperty";
7674
- }
7671
+ /** A role-axiom declaration — `<role> rdf:type owl:TransitiveProperty` or
7672
+ * `<role> rdfs:subPropertyOf <role>` — is role scaffolding, not a fact about
7673
+ * the role a reader wants listed back in English. Neither ever renders as a
7674
+ * plain fact line, the same discipline that keeps the restriction scaffolding
7675
+ * predicates (RESTRICTION_SCAFFOLDING_PREDICATES, below) out of the describe
7676
+ * lane. */
7677
+ function isRoleScaffoldingDeclaration(f) {
7678
+ return (f.predicate === TYPE_PREDICATE && f.object === "transitiveproperty")
7679
+ || f.predicate === SUB_PROPERTY_OF_PREDICATE;
7680
+ }
7681
+
7682
+ /** A restriction node's own internal edges — which property it restricts
7683
+ * (owl:onProperty) and which filler it restricts to (owl:someValuesFrom,
7684
+ * owl:allValuesFrom) — name the restriction's SHAPE, not a fact about the
7685
+ * role or the filler a reader wants listed back. Neither ever renders as a
7686
+ * plain fact line in the describe lane. */
7687
+ const RESTRICTION_SCAFFOLDING_PREDICATES = new Set([
7688
+ "owl:onProperty", "owl:someValuesFrom", "owl:allValuesFrom",
7689
+ ]);
7675
7690
 
7676
7691
  /** The world PLACEMENT predicates carry curated phrases above so they render as
7677
7692
  * English, but they must stay OUT of the query-marker families derived from
@@ -7716,6 +7731,15 @@ function baseVerbSurface(verb) {
7716
7731
  if (/(?:s|x|z|ch|sh|o)es$/i.test(w)) return w.slice(0, -2);
7717
7732
  return w.replace(/s$/i, "");
7718
7733
  }
7734
+ /** The gerund surface of a 3sg-minted role predicate — "contains" -> "containing",
7735
+ * "touches" -> "touching" — the naive INVERSE of the "-ing"-stripping fold
7736
+ * verbPredicateFromSurface (ace.mjs) already accepts alongside a 3sg surface
7737
+ * when parsing patterns 16, 17 and 19. Same accepted naive-morphology trade
7738
+ * thirdPersonSingularSurface/baseVerbSurface already make. */
7739
+ function gerundVerbSurface(verb) {
7740
+ const base = baseVerbSurface(verb);
7741
+ return /[^aeiou]e$/i.test(base) && base.length > 2 ? `${base.slice(0, -1)}ing` : `${base}ing`;
7742
+ }
7719
7743
  function predicatePhrase(predicate) {
7720
7744
  if (FACT_PREDICATE_PHRASES[predicate]) return FACT_PREDICATE_PHRASES[predicate];
7721
7745
  const p = String(predicate || "");
@@ -7824,6 +7848,14 @@ function citationProvenance(provenance) {
7824
7848
  * applies here instead. Provenance stays VERBATIM in every case. */
7825
7849
  function renderFactLine(f) {
7826
7850
  const cite = f.provenance ? ` (source: ${citationProvenance(f.provenance)})` : "";
7851
+ // A rdfs:subPropertyOf row relates two PREDICATES, not two things — factPhrase
7852
+ // would compose the raw CURIE ("contains rdfs:subPropertyOf touches"), so this
7853
+ // shape gets its own dedicated line ahead of the provenance-keyed framing below,
7854
+ // the same way renderUnionLine/renderEnumerationLine read as a definition
7855
+ // rather than a first-person claim regardless of who taught it.
7856
+ if (f.predicate === SUB_PROPERTY_OF_PREDICATE) {
7857
+ return `${gerundVerbSurface(f.subject)} implies ${gerundVerbSurface(f.object)}${cite}`;
7858
+ }
7827
7859
  // ace:chat = the ACE-parsed operator assert; teach:chat = the teach lane's
7828
7860
  // natural frames — both are things the operator SAID, so both read first-person.
7829
7861
  if (f.provenance.includes("ace:chat") || f.provenance.includes("teach:chat")) return `you told me: ${factPhrase(f)}${cite}`;
@@ -7872,7 +7904,23 @@ function renderEnumerationLine(cls, members) {
7872
7904
  const plural = thirdPersonSingularSurface(String(cls || "").replace(/-/g, " "));
7873
7905
  return `the ${plural} are exactly ${list}${cite}`;
7874
7906
  }
7875
- export { renderUnionLine, renderEnumerationLine };
7907
+
7908
+ /** A universal restriction's stored triples read back as ONE sentence rather
7909
+ * than the restriction node's raw scaffolding rows: "every heart contains
7910
+ * only valves (source: …)". `node` is the `<parent> rdfs:subClassOf
7911
+ * <restriction>` fact row (the parent and the citation both come from it);
7912
+ * `rows` are the restriction node's own rows, from which its owl:onProperty
7913
+ * role and owl:allValuesFrom filler are read — order-independent, the same
7914
+ * way renderUnionLine/renderEnumerationLine are. Pure — takes the fact rows,
7915
+ * returns one line. */
7916
+ function renderUniversalRestrictionLine(node, rows) {
7917
+ const onProperty = rows.find((r) => r.predicate === "owl:onProperty");
7918
+ const allValuesFrom = rows.find((r) => r.predicate === "owl:allValuesFrom");
7919
+ const cite = node.provenance ? ` (source: ${citationProvenance(node.provenance)})` : "";
7920
+ const filler = thirdPersonSingularSurface(String(allValuesFrom?.object || "").replace(/-/g, " "));
7921
+ return `every ${node.subject} ${onProperty?.object || ""} only ${filler}${cite}`;
7922
+ }
7923
+ export { renderUnionLine, renderEnumerationLine, renderUniversalRestrictionLine };
7876
7924
 
7877
7925
  const SENSE_CITE_RE = / \(source: [^)]*\)$/;
7878
7926
 
@@ -9007,6 +9055,166 @@ async function findWiderConsistencyClash(rows, variants, reasoning) {
9007
9055
  }
9008
9056
  export { findWiderConsistencyClash };
9009
9057
 
9058
+ /** TRACK B1: a plain isa-shaped miss falls through to a bounded, automatic
9059
+ * tableau proof before the isa reader's own recovery text renders. Called
9060
+ * from the isa branch immediately after `deeperChainExists` is computed and
9061
+ * immediately before `knownSubjectIsa.length` is checked — the one point
9062
+ * that dominates every exit the branch takes, whichever of the three
9063
+ * reasons (a subject with an `rdf:type` row, a subject with only an
9064
+ * `owl:disjointWith` row, or a subject the store has never seen) sent it
9065
+ * there.
9066
+ *
9067
+ * Three things gate the prover, and none of them runs it: the question
9068
+ * already parsed through ISA_ASK_RE (true by construction — every caller
9069
+ * matched it to reach here); every live chase above already missed (true
9070
+ * by construction — this runs immediately before the isa branch's own
9071
+ * recovery text); and the extracted module holds a DL-only axiom shape
9072
+ * (`moduleHasDlShape`) — without one the tableau can only redo the
9073
+ * subclass walk the chases just finished, so running it would spend a
9074
+ * budget to reach the identical miss they already reached.
9075
+ *
9076
+ * Two-sided, PROVED ONLY. Proves `subject : class`; `proved` renders yes.
9077
+ * A `disproved` first pass tries the NEGATION (`subject : ¬class`);
9078
+ * `proved` there renders no — a store-entailed negation, never the
9079
+ * counter-model `/prove` itself renders as "no", since a counter-model
9080
+ * under the open-world rule means "not entailed", not "entailed false",
9081
+ * and converting that into a denial on a plain question would turn
9082
+ * abstention into a guess. Anything else (both passes disproved, either
9083
+ * exhausted, or the ex-falso guard below firing) returns null, so the
9084
+ * isa branch's own miss text renders byte-identical.
9085
+ *
9086
+ * The ex-falso guard runs before either proof pass: an individual whose
9087
+ * own premises already clash proves anything asked of it (the shipped
9088
+ * `inference.dl.cardinality-clash` corpus row shows the shape doing this
9089
+ * under an explicit `/prove`), and an automatic fallback must never turn
9090
+ * that into a confident yes — it renders the clash instead, through the
9091
+ * same premise-quoting text `findWiderConsistencyClash` above already
9092
+ * uses.
9093
+ *
9094
+ * Returns `{ text, replace: true }` on a proved verdict or a clash,
9095
+ * `{ budgetExhausted: true }` when a pass exhausted its budget (the caller
9096
+ * reads this flag to stamp the turn record the same way `/prove`'s own
9097
+ * budget wall does, and renders nothing else — the existing miss stands),
9098
+ * or `null` when nothing here changes the answer. */
9099
+ // A cheap, LITERAL duplicate of tableau.mjs's own moduleHasDlShape
9100
+ // vocabulary (DL_SHAPE_PREDICATES there) — checked here, inline, before
9101
+ // this file's own dynamic `import("../domain/tableau.mjs")`, so the
9102
+ // overwhelming majority of ordinary isa misses (nothing DL-shaped in the
9103
+ // store at all) never pay that module's first-load parse cost on the hot
9104
+ // path. Keep in sync with tableau.mjs's DL_SHAPE_PREDICATES by hand; a
9105
+ // drift here only ever makes this pre-check MISS a real DL shape (falling
9106
+ // through to the authoritative, imported moduleHasDlShape below, which
9107
+ // still runs whenever this pre-check can't rule the store out), never
9108
+ // falsely certify one.
9109
+ const CHAT_DL_SHAPE_PREDICATES = new Set([
9110
+ "owl:unionof", "owl:complementof", "owl:oneof", "owl:allvaluesfrom",
9111
+ "owl:mincardinality", "owl:maxcardinality", "owl:cardinality",
9112
+ "rdfs:subpropertyof", "owl:inverseof",
9113
+ ]);
9114
+ function storeMightHaveDlShape(rows) {
9115
+ return rows.some((r) => {
9116
+ const p = String(r?.predicate || "").trim().toLowerCase();
9117
+ if (CHAT_DL_SHAPE_PREDICATES.has(p)) return true;
9118
+ return p === "rdf:type" && String(r?.object || "").toLowerCase() === "transitiveproperty";
9119
+ });
9120
+ }
9121
+
9122
+ /** TRACK B2: the English phrase naming a proved case-split's own disjuncts
9123
+ * — "a cat or a dog" — from tableau.mjs's own `cases` (a proved result's
9124
+ * distinct owl:unionOf/owl:oneOf disjuncts, deduped, sorted, capped at
9125
+ * MAX_PROVEN_CASES) and `casesTotal` (the real count before the cap). Once
9126
+ * the real count outruns the cap, names the count instead of listing
9127
+ * beyond it, rather than silently truncating the sentence. Each case is a
9128
+ * concept-expression atom or nominal (tableau.mjs's own shape), so its
9129
+ * display term is `.name` or `.ind` respectively. */
9130
+ function renderCasesPhrase(cases, casesTotal) {
9131
+ if (casesTotal > cases.length) return `one of ${casesTotal} possibilities`;
9132
+ return cases
9133
+ .map((c) => (c.t === "nom" ? c.ind : c.name))
9134
+ .map((term) => `${indefiniteArticleFor(term)} ${term}`)
9135
+ .join(" or ");
9136
+ }
9137
+
9138
+ /** The proved-verdict conclusion clause both `/prove` and the automatic
9139
+ * fallback render: "so X is a Y." for a single deduction, or "in every
9140
+ * case — <cases> — X is a Y." once `result.cases` names a genuine
9141
+ * case analysis the proof actually reasoned through — never the ⊑-rule's
9142
+ * own routine TBox-internalization disjunction, which every proof passes
9143
+ * through regardless of a union/oneOf premise and which tableau.mjs's own
9144
+ * `isGenuineDisjunction` already excludes from `cases`. `negate` renders
9145
+ * the negative form the store-entailed-negation path needs. */
9146
+ function renderProvedConclusion(result, subjectWord, classWord, { negate = false } = {}) {
9147
+ const predicate = negate ? `is not a ${classWord}` : `is a ${classWord}`;
9148
+ if (!result.cases || !result.cases.length) return `so ${subjectWord} ${predicate}.`;
9149
+ return `in every case — ${renderCasesPhrase(result.cases, result.casesTotal)} — ${subjectWord} ${predicate}.`;
9150
+ }
9151
+ async function autoProveFallback(memoryDir, cache, allRows, subjectWord, subjCandidates, objVariants, classWord) {
9152
+ // storeMightHaveDlShape already ruled out "nothing DL-shaped anywhere in
9153
+ // the store" without paying tableau.mjs's own first-load parse cost — see
9154
+ // its own docblock. Only a store that passes it ever reaches the import.
9155
+ if (!storeMightHaveDlShape(allRows)) return null;
9156
+ const {
9157
+ extractTableauModule, buildTableauKb, proveEntailment, proveSubsumption, proveSubsumptionOfNegation,
9158
+ findTableauViolations, moduleHasDlShape,
9159
+ } = await import("../domain/tableau.mjs");
9160
+ const { normFactTerm } = await import("../adapters/memory/core.mjs");
9161
+ const subjectTerm = resolveProveTerm(subjCandidates, allRows, normFactTerm(subjectWord));
9162
+ const classTerm = resolveProveTerm(objVariants, allRows, normFactTerm(classWord));
9163
+ // The subject's own stored TYPES seed the module too, not just its name —
9164
+ // extractTableauModule's structural walk starts from class/role
9165
+ // vocabulary, so an individual reached only through its own `rdf:type`
9166
+ // edge never pulls in that class's own restrictions or union membership
9167
+ // unless the class is seeded directly. Same discipline
9168
+ // findWiderConsistencyClash already applies above.
9169
+ const typeSeeds = allRows.filter((r) => r.predicate === "rdf:type" && subjCandidates.has(r.subject)).map((r) => r.object);
9170
+ const moduleRows = extractTableauModule(allRows, [subjectTerm, classTerm, ...typeSeeds]);
9171
+ // Both cheap, in-memory, no I/O — the gate that keeps the ordinary miss
9172
+ // off the hot-path cost of reading tmct.toml at all. Only a DL-shaped
9173
+ // module ever reaches resolveReasoningConfigForRepo below.
9174
+ if (!moduleHasDlShape(moduleRows)) return null;
9175
+ const reasoning = await resolveReasoningConfigForRepo(memoryDir);
9176
+ if (!reasoning.askProveFallback) return null;
9177
+ const kb = buildTableauKb(moduleRows);
9178
+ const proveOpts = { maxSteps: reasoning.askProveSteps, maxBranches: reasoning.askProveBranches, maxNodes: reasoning.askProveNodes };
9179
+ const isIndividual = kb.namedIndividuals.has(subjectTerm);
9180
+ const byId = new Map(moduleRows.map((r) => [r.id, r]));
9181
+
9182
+ if (isIndividual) {
9183
+ const violation = findTableauViolations(kb, [subjectTerm], proveOpts)[0];
9184
+ if (violation) {
9185
+ const cited = violation.premises.map((id) => byId.get(id)).filter(Boolean).map(renderFactLine).join("; ");
9186
+ return {
9187
+ text: `I can't answer that — what I've been told about ${violation.subject} is inconsistent: `
9188
+ + `${cited || "the facts I hold about it clash"}. I'd need one of those retracted before I can answer honestly.`,
9189
+ replace: true,
9190
+ };
9191
+ }
9192
+ }
9193
+
9194
+ const renderProvedCite = (result) => result.premises.map((id) => byId.get(id)).filter(Boolean).map(renderFactLine).join("; ");
9195
+
9196
+ const positive = isIndividual
9197
+ ? proveEntailment(kb, subjectTerm, { t: "atom", name: classTerm }, proveOpts)
9198
+ : proveSubsumption(kb, subjectTerm, classTerm, proveOpts);
9199
+ if (positive.status === "proved") {
9200
+ const cited = renderProvedCite(positive);
9201
+ const conclusion = renderProvedConclusion(positive, subjectWord, classWord);
9202
+ return { text: `yes — ${cited}; ${conclusion}`, replace: true };
9203
+ }
9204
+ if (positive.status === "exhausted") return { budgetExhausted: true };
9205
+
9206
+ // Step 1 disproved: a counter-model, never rendered on this path. Step 2
9207
+ // asks the negation — a store-entailed negation is a grounded no.
9208
+ const negative = isIndividual
9209
+ ? proveEntailment(kb, subjectTerm, { t: "not", c: { t: "atom", name: classTerm } }, proveOpts)
9210
+ : proveSubsumptionOfNegation(kb, subjectTerm, classTerm, proveOpts);
9211
+ if (negative.status === "exhausted") return { budgetExhausted: true };
9212
+ if (negative.status !== "proved") return null;
9213
+ const cited = renderProvedCite(negative);
9214
+ const conclusion = renderProvedConclusion(negative, subjectWord, classWord, { negate: true });
9215
+ return { text: `no — ${cited}; ${conclusion}`, replace: true };
9216
+ }
9217
+
9010
9218
  async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle = {}, cache = null, focusLabel = null) {
9011
9219
  let normFactTerm; let normFactPredicate;
9012
9220
  try { ({ normFactTerm, normFactPredicate } = await import("../adapters/memory/core.mjs")); } catch { return null; }
@@ -9346,7 +9554,8 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
9346
9554
  // and mechanics predicates are dropped so "what is the letter" never reads
9347
9555
  // back where it's hidden or that it's the objective (WORLD_INTERNAL_PREDICATES).
9348
9556
  const subjectHits = (await factRows(memoryDir, cache))
9349
- .filter((f) => variants.has(f.subject) && !WORLD_INTERNAL_PREDICATES.has(f.predicate) && !isTransitivePropertyDeclaration(f));
9557
+ .filter((f) => variants.has(f.subject) && !WORLD_INTERNAL_PREDICATES.has(f.predicate)
9558
+ && !isRoleScaffoldingDeclaration(f) && !RESTRICTION_SCAFFOLDING_PREDICATES.has(f.predicate));
9350
9559
  // Matched through normFactPredicate, so a fact stored under a minted
9351
9560
  // spelling of the same relation ("mgx:used-for", from the participle
9352
9561
  // teach frame, in a store written before the spellings converged) is
@@ -9981,7 +10190,8 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
9981
10190
  // objective, and those datatype internals render as garbled non-English
9982
10191
  // besides. The adventure's own where/openness readers answer the legitimate
9983
10192
  // in-game questions from the world fold.
9984
- hits = hits.filter((f) => !WORLD_INTERNAL_PREDICATES.has(f.predicate) && !isTransitivePropertyDeclaration(f));
10193
+ hits = hits.filter((f) => !WORLD_INTERNAL_PREDICATES.has(f.predicate)
10194
+ && !isRoleScaffoldingDeclaration(f) && !RESTRICTION_SCAFFOLDING_PREDICATES.has(f.predicate));
9985
10195
  // A corpus-weak-only result set (every hit resolved ONLY through
9986
10196
  // ConceptNet's /r/RelatedTo tier) still composes its hedged "possibly"
9987
10197
  // lines below exactly as before — this reader's whole job is showing
@@ -11340,6 +11550,16 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
11340
11550
  const deeperChainExists = [...subjCandidates].some(
11341
11551
  (subj) => findIsaChain(subj, objVariants, chainTypeEdges, chainSubClassSucc, { maxHops: DEEP_CHAIN_PROBE_HOPS }),
11342
11552
  );
11553
+ // TRACK B1 — the automatic /prove fallback: every live chase above has
11554
+ // already missed, so this is the one point upstream of every exit the
11555
+ // isa branch takes (see autoProveFallback's own docblock). A proved
11556
+ // verdict or an ex-falso clash replaces the miss outright; an exhausted
11557
+ // budget merges onto whichever of the three recovery texts below still
11558
+ // renders, so the miss itself stays byte-identical and only gains the
11559
+ // marker chatbench/infbench read apart from a parse miss.
11560
+ const autoProve = await autoProveFallback(memoryDir, cache, rows, subjectWord, subjCandidates, objVariants, kindWord);
11561
+ if (autoProve?.text) return autoProve;
11562
+ const askProveBudgetExhausted = !!autoProve?.budgetExhausted;
11343
11563
  if (knownSubjectIsa.length) {
11344
11564
  const shown = knownSubjectIsa.slice(0, 3).map(renderFactLine).join("; ");
11345
11565
  // A someValuesFrom restriction node among the subject's own remembered
@@ -11369,6 +11589,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
11369
11589
  text: `I can't confirm that — nothing I remember says ${subjectWord} is a ${kindWord}. I do know: ${shown}. ${recovery}`,
11370
11590
  replace: true,
11371
11591
  miss: true, // still a MISS in the turn record — honest wording, not an answer
11592
+ ...(askProveBudgetExhausted ? { budgetExhausted: true } : {}),
11372
11593
  };
11373
11594
  }
11374
11595
  // A stored CONVERSE ("every dog is a mammal" asked as "is a mammal a
@@ -11383,6 +11604,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
11383
11604
  text: `I can't confirm that — what I know runs the other way: ${renderFactLine(converseHit)}. A kind doesn't reverse. If it's true, teach me: "every ${subjectWord} is a ${kindWord}". If it isn't, teach me: "no ${subjectWord} is a ${kindWord}".`,
11384
11605
  replace: true,
11385
11606
  miss: true,
11607
+ ...(askProveBudgetExhausted ? { budgetExhausted: true } : {}),
11386
11608
  };
11387
11609
  }
11388
11610
  // Subject with NO isa facts: only divert when it's mentioned NOWHERE at
@@ -11395,6 +11617,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
11395
11617
  text: `I can't confirm that — I don't know "${subjectWord}" at all yet. If it's true, teach me: "${subjectWord} is a kind of ${kindWord}". If it isn't, teach me: "no ${subjectWord} is a ${kindWord}".`,
11396
11618
  replace: true,
11397
11619
  miss: true,
11620
+ ...(askProveBudgetExhausted ? { budgetExhausted: true } : {}),
11398
11621
  };
11399
11622
  }
11400
11623
  return null; // the honest miss stands (never a guessed "no")
@@ -15171,6 +15394,10 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
15171
15394
  if (liveGameOwnWord) bareMetaHit = null;
15172
15395
  const coldPronounDecline = focus?.label ? null : coldPronounDeclineText(query);
15173
15396
  let selfContainedMiss = false;
15397
+ // TRACK B1: the automatic /prove fallback's own budget-exhaustion marker,
15398
+ // read off a fact-lane hit the same way selfContainedMiss is — merged onto
15399
+ // the turn record below, the same field /prove's own budget wall stamps.
15400
+ let budgetExhausted = false;
15174
15401
  if (bareMetaHit?.reference) {
15175
15402
  // The bare-form reference hit mirrors (4h): the cited answer replaces the
15176
15403
  // miss, the turn is no longer recorded as one, and the article's grounded
@@ -15326,6 +15553,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
15326
15553
  // the empty-graph orientation pointer below stays off it — a pronoun
15327
15554
  // decline with an index pointer under it is two answers to one turn.
15328
15555
  if (fact.selfContainedMiss) selfContainedMiss = true;
15556
+ if (fact.budgetExhausted) budgetExhausted = true;
15329
15557
  // A `weakOnly` hit (the "what do you know about X" reader's
15330
15558
  // corpus-weak-only hedge) is shown as `answer` above like any other
15331
15559
  // fact-lane hit, but doesn't count as REAL grounding — via/recordMiss
@@ -15911,6 +16139,10 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
15911
16139
  // Premise-derived trust for a LIVE-CHASE-ONLY entailment answer; omitted
15912
16140
  // entirely when this turn didn't answer via one of those.
15913
16141
  ...(entailedTrust !== null ? { entailedTrust } : {}),
16142
+ // The automatic /prove fallback's own budget wall — the same marker
16143
+ // /prove's own explicit budget wall stamps, so chatbench/infbench can
16144
+ // count a budget miss apart from a parse miss.
16145
+ ...(budgetExhausted ? { budgetExhausted: true } : {}),
15914
16146
  };
15915
16147
  const logLines = [ts, `> ${query}`, answer, ""];
15916
16148
  // `detail` feeds why/say-more's verbose re-render: the traversal receipt + the
@@ -16419,9 +16651,10 @@ async function runCommand(line, { config, source, graph, focus, memoryDir, trace
16419
16651
  // A case-split conclusion (the ⊔-rule fired on a genuine owl:unionOf
16420
16652
  // or owl:oneOf premise, not just the ⊑-rule's own routine
16421
16653
  // TBox-internalization disjunction, which every proof passes
16422
- // through) reads as reasoning by cases, not a single deduction.
16423
- const caseSplit = premiseRows.some((r) => r.predicate === "owl:unionOf" || r.predicate === "owl:oneOf");
16424
- const conclusion = caseSplit ? `in every case, ${subjectWord} is a ${classWord}.` : `so ${subjectWord} is a ${classWord}.`;
16654
+ // through) reads as reasoning by cases, not a single deduction, and
16655
+ // names the cases it split on (result.cases, tableau.mjs's own
16656
+ // isGenuineDisjunction filter).
16657
+ const conclusion = renderProvedConclusion(result, subjectWord, classWord);
16425
16658
  return mk(`yes — ${cited}; ${conclusion}`);
16426
16659
  }
16427
16660
  if (result.status === "disproved") {
@@ -50,8 +50,15 @@ const TIER2_EMPTY_VOCAB_FILE = join(dirname(fileURLToPath(import.meta.url)), "..
50
50
  export const EXTENSION_KINDS = Object.freeze(["corpus", "lexicon", "templates", "pack", "ontology"]);
51
51
 
52
52
  // The definitional-band-first predicate order for the ConceptNet seed (re-declared,
53
- // not imported, to keep this module off chat.mjs's heavy graph).
54
- const CONCEPTNET_PREFER = ["rdfs:subClassOf", "rdf:type", "mgx:usedFor", "mgx:partOf", "mgx:capableOf"];
53
+ // not imported, to keep this module off chat.mjs's heavy graph). The five
54
+ // relational predicates after the definitional backbone are the ones a
55
+ // commonsense multiple-choice question keys on (atLocation, causes, desires,
56
+ // motivatedByGoal, hasSubevent) — ranked ahead of the rest so the band cap
57
+ // buys them before it buys more RelatedTo.
58
+ const CONCEPTNET_PREFER = [
59
+ "rdfs:subClassOf", "rdf:type", "mgx:usedFor", "mgx:partOf", "mgx:capableOf",
60
+ "mgx:atLocation", "mgx:causes", "mgx:desires", "mgx:motivatedByGoal", "mgx:hasSubevent",
61
+ ];
55
62
 
56
63
  /** The shipped defaults — a FRESH object per call, so a caller can never
57
64
  * accidentally mutate a module-level singleton. */
@@ -548,9 +548,14 @@ export function agentCardMarkup(slot) {
548
548
  * `worldPayload` is `{ name, facts, rules, opening }`, the same shape every
549
549
  * other viz page's world payload takes. `agents` is the roster this page
550
550
  * may cast from, `[{ id, role }]` (role is "predator" or "prey" — see
551
- * MUDIII_ROLES). `scenarios` is `[{ label, worldPayload, agents, gridSize }]`
552
- * — a page given none is the one-square case and ships no dropdown, the
553
- * same rule mud-viz.mjs's own renderMudHtml follows. `assetManifest` is
551
+ * MUDIII_ROLES). `scenarios` is `[{ label, worldPayload, agents, gridSize,
552
+ * puzzle }]` — a page given none is the one-square case and ships no
553
+ * dropdown, the same rule mud-viz.mjs's own renderMudHtml follows. `puzzle`
554
+ * is true for a scenario with no town-square layout of its own (the
555
+ * river-crossing puzzle): no roster is minted, no tick ever runs, and the
556
+ * page shows the actor card and the outlook panel's puzzle plan in place of
557
+ * the chase HUD (see this file's own pageScript, `data-hide-when-puzzle`).
558
+ * `assetManifest` is
554
559
  * data/mudiii-assets.json's own `assets` rows, embedded as page data and
555
560
  * resolved client-side by `propPlacementsFrom` — this is the one parameter
556
561
  * mud-viz.mjs's renderMudHtml has no equivalent of, because mud.html has no
@@ -613,28 +618,29 @@ ${PILL_COMPLETE_CSS}
613
618
  <div class="deck-row">
614
619
  <section class="deck" aria-label="simulation controls">
615
620
  <div class="deck-controls">
616
- <button type="button" class="deck-play" id="autoToggle" aria-pressed="false">&#9654; play</button>
617
- <button type="button" id="stepBtn">step</button>
621
+ <button type="button" class="deck-play" id="autoToggle" aria-pressed="false" data-hide-when-puzzle>&#9654; play</button>
622
+ <button type="button" id="stepBtn" data-hide-when-puzzle>step</button>
618
623
  <span class="deck-hint" id="stepHint" hidden>pause to step</span>
619
- <button type="button" id="resetBtn">reset</button>
624
+ <button type="button" id="resetBtn" data-hide-when-puzzle>reset</button>
620
625
  ${scenarioList.length > 1 ? ` <select id="scenarioSelect" class="deck-select" aria-label="which town square to play">
621
626
  ${scenarioList.map((s, i) => ` <option value="${i}"${i === 0 ? " selected" : ""}>${escapeHtml(s.label || scenarioLabel(s.worldPayload?.name))}</option>`).join("\n")}
622
627
  </select>` : ""}
623
628
  <button type="button" id="editModeBtn" aria-pressed="false">edit</button>
624
629
  <button type="button" class="deck-info-btn" id="deckInfoBtn" aria-expanded="false" aria-controls="deckInfoPopup" aria-label="about this demo">?</button>
625
- <span class="mono deck-turns" id="globalTurnCount">turns: 0</span>
630
+ <span class="mono deck-turns" id="globalTurnCount" data-hide-when-puzzle>turns: 0</span>
626
631
  </div>
632
+ <p class="deck-hint mudiii-puzzle-note" id="puzzleNote" hidden>This scenario is a solved-by-search puzzle, not a chase: nothing moves on its own. Follow one of the four passengers below to see its own facts, and the plan panel to see the crossing itself.</p>
627
633
  <div class="deck-body">
628
634
  <div class="deck-panels">
629
635
  <div class="deck-stack deck-stack-1">
630
- <label class="deck-slider">foxes
636
+ <label class="deck-slider" data-hide-when-puzzle>foxes
631
637
  <input type="range" id="playerCountSlider" min="0" max="${PLAYER_COUNTS.length - 1}" step="1"
632
638
  value="${Math.max(0, PLAYER_COUNTS.indexOf(DEFAULT_PLAYER_COUNT))}"
633
639
  list="playerCountTicks" aria-valuetext="${DEFAULT_PLAYER_COUNT} foxes">
634
640
  <datalist id="playerCountTicks">${PLAYER_COUNTS.map((n, i) => `<option value="${i}" label="${n}"></option>`).join("")}</datalist>
635
641
  <span class="mono" id="playerCountValue">${DEFAULT_PLAYER_COUNT}</span>
636
642
  </label>
637
- <label class="deck-slider">goblins
643
+ <label class="deck-slider" data-hide-when-puzzle>goblins
638
644
  <input type="range" id="npcCountSlider" min="${NPC_COUNT_MIN}" max="${NPC_COUNT_MAX}" step="1"
639
645
  value="${DEFAULT_NPC_COUNT}"
640
646
  list="npcCountTicks" aria-valuetext="${DEFAULT_NPC_COUNT} goblins">
@@ -652,7 +658,7 @@ ${openingAgents.map((a) => ` <option value="${escapeHtml(a.id)}">
652
658
  </label>
653
659
  <span class="deck-hint" id="agentSelectHint" hidden>pause to swap</span>
654
660
  </div>
655
- <div class="deck-stack deck-stack-2">
661
+ <div class="deck-stack deck-stack-2" data-hide-when-puzzle>
656
662
  <label class="deck-slider">delay
657
663
  <input type="range" id="delaySlider" min="80" max="2000" step="20" value="${DEFAULT_DELAY_MS}">
658
664
  <span class="mono" id="delayValue">${DEFAULT_DELAY_MS}ms</span>
@@ -667,7 +673,7 @@ ${openingAgents.map((a) => ` <option value="${escapeHtml(a.id)}">
667
673
  <button type="button" data-mode="overhead" aria-pressed="false">overhead</button>
668
674
  </div>
669
675
  </div>
670
- <div class="deck-stack deck-stack-3">
676
+ <div class="deck-stack deck-stack-3" data-hide-when-puzzle>
671
677
  <button type="button" class="pill affordance" id="foodPill" data-command="place food" aria-pressed="false">place food</button>
672
678
  <label class="deck-teach" title="With this on, a sentence like &quot;The fox is at cell-3-4.&quot; writes a fact into the square instead of running as a command.">
673
679
  <input type="checkbox" id="teachToggle">
@@ -675,7 +681,7 @@ ${openingAgents.map((a) => ` <option value="${escapeHtml(a.id)}">
675
681
  </label>
676
682
  </div>
677
683
  </div>
678
- <section class="map-panel" id="mapPanel" aria-label="the town square, from above">
684
+ <section class="map-panel" id="mapPanel" aria-label="the town square, from above" data-hide-when-puzzle>
679
685
  <div class="map-panel-head">
680
686
  <span class="map-panel-title">the square, from above</span>
681
687
  <span class="mono map-panel-turn" id="mapPanelTurn">turn 0</span>
@@ -755,7 +761,7 @@ ${RING_POINTS.map((point) => ` <span class="dir-slot dir-${point}"><button
755
761
  </form>
756
762
  </div>
757
763
  </section>
758
- <div class="hud-row" id="hudRow" aria-label="every agent's own status"></div>
764
+ <div class="hud-row" id="hudRow" aria-label="every agent's own status" data-hide-when-puzzle></div>
759
765
  </main>
760
766
  <script>
761
767
  const MUDIII_PAGE_DATA = ${pageData};
@@ -830,6 +836,7 @@ const MUDIII_STYLE = `
830
836
  .deck-select:disabled:hover { border-color: var(--square-stone-dark); }
831
837
  .deck-hint { font-family: ${MONO_STACK}; font-size: .58rem; text-transform: uppercase; letter-spacing: .08em; color: var(--square-stone-dark); }
832
838
  .deck-hint[hidden] { display: none; }
839
+ .mudiii-puzzle-note { text-transform: none; letter-spacing: normal; font-size: .78rem; font-family: ${SANS_STACK}; margin: 0 0 .6rem; }
833
840
  .deck-play { background: var(--square-ink) !important; color: var(--parchment); border-color: var(--square-ink) !important; padding: .38rem 1.1rem !important; }
834
841
  .deck-play[aria-pressed="true"] { background: var(--square-accent) !important; border-color: var(--square-accent) !important; color: var(--square-ink); }
835
842
  .deck-turns { margin-left: auto; font-size: .74rem; color: var(--square-stone-dark); background: var(--square-stone-dark); background: rgba(43,35,24,.9); color: var(--square-accent); border-radius: 2px; padding: .1rem .5rem; }
@@ -1150,6 +1157,30 @@ function pageScript() {
1150
1157
  let scenarioIndex = 0;
1151
1158
  const scenario = function () { return DATA.scenarios[scenarioIndex]; };
1152
1159
  const gridSizeOf = function () { return scenario().gridSize || DATA.gridSize; };
1160
+ // A puzzle scenario (the river crossing) carries no town-square layout —
1161
+ // no roster, no ticking, no chase — so its four passengers never populate
1162
+ // agentsById the way a minted cast does. hide-when-puzzle marks every
1163
+ // control that means nothing without one.
1164
+ const isPuzzle = function () { return scenario().puzzle === true; };
1165
+ function applyPuzzleVisibility() {
1166
+ const puzzle = isPuzzle();
1167
+ const nodes = document.querySelectorAll("[data-hide-when-puzzle]");
1168
+ for (let i = 0; i < nodes.length; i += 1) nodes[i].hidden = puzzle;
1169
+ el("puzzleNote").hidden = !puzzle;
1170
+ }
1171
+ // Every numbered instance a puzzle world's own facts place — fox-1, goat-1,
1172
+ // cabbage-1, farmer-1 for the river crossing — read straight off rdf:type
1173
+ // rows rather than a roster the engine minted, because a puzzle world has
1174
+ // no roster. Any world's numbered individuals match this, so a later
1175
+ // puzzle scenario needs no new code here, only its own worldPayload.
1176
+ function puzzleActorIdsFrom(facts) {
1177
+ const ids = new Set();
1178
+ (facts || []).forEach(function (f) {
1179
+ if (f && f.predicate === "rdf:type" && /-\\d+$/.test(f.subject)) ids.add(f.subject);
1180
+ });
1181
+ return Array.from(ids).sort();
1182
+ }
1183
+ let puzzleActorIds = [];
1153
1184
 
1154
1185
  // ---- roster minting -----------------------------------------------------
1155
1186
  // The page asks for a COUNT and names the ids it is about to get back: the
@@ -1610,7 +1641,7 @@ function pageScript() {
1610
1641
  // ---- follow dropdown and camera mode ------------------------------------
1611
1642
  function renderAgentSelect() {
1612
1643
  const select = el("agentSelect");
1613
- const ids = Object.keys(agentsById).sort();
1644
+ const ids = isPuzzle() ? puzzleActorIds : Object.keys(agentsById).sort();
1614
1645
  const current = camera.selectedId;
1615
1646
  select.innerHTML = ids.map(function (id) {
1616
1647
  return '<option value="' + esc(id) + '"' + (id === current ? " selected" : "") + '>' + esc(id) + "</option>";
@@ -1732,13 +1763,13 @@ function pageScript() {
1732
1763
  var presentedPredicates = { "mgx:display-name": true, "mgx:model": true };
1733
1764
  (rows || []).forEach(function (row) {
1734
1765
  if (!row || !row.subject || row.subject.indexOf("@") !== -1) return;
1735
- if (row.predicate === "rdf:type" && /-\d+$/.test(row.subject)) {
1766
+ if (row.predicate === "rdf:type" && /-\\d+$/.test(row.subject)) {
1736
1767
  kinds[row.object] = true;
1737
1768
  instanceIds[row.subject] = true;
1738
1769
  return;
1739
1770
  }
1740
1771
  if (!presentedPredicates[row.predicate]) return;
1741
- if (/-\d+$/.test(row.subject)) instanceIds[row.subject] = true;
1772
+ if (/-\\d+$/.test(row.subject)) instanceIds[row.subject] = true;
1742
1773
  else kinds[row.subject] = true;
1743
1774
  });
1744
1775
  var byKind = {};
@@ -2056,6 +2087,12 @@ function pageScript() {
2056
2087
  return "seen";
2057
2088
  }
2058
2089
 
2090
+ // The belief-and-plan half needs a followed agent's own tick entry; the
2091
+ // puzzle-plan half needs only lastOutlook.puzzle, which agentOutlook
2092
+ // computes whether or not any agent has one (see mudiii-turn.mjs's
2093
+ // agentOutlook) — a puzzle scenario carries no roster, so its followed
2094
+ // passenger never has a belief entry, and the puzzle plan would never show
2095
+ // if the two stayed behind the same early return.
2059
2096
  function renderOutlookPanel() {
2060
2097
  const id = el("agentSelect").value;
2061
2098
  const body = el("outlookBeliefBody");
@@ -2065,20 +2102,19 @@ function pageScript() {
2065
2102
  if (!entry) {
2066
2103
  body.innerHTML = '<tr><td class="outlook-empty" colspan="3">Follow an agent above to see what it believes.</td></tr>';
2067
2104
  planText.textContent = "";
2068
- puzzleText.hidden = true;
2069
- return;
2105
+ } else {
2106
+ const subjects = Object.keys(entry.belief).sort();
2107
+ body.innerHTML = subjects.length
2108
+ ? subjects.map(function (subject) {
2109
+ const cell = entry.belief[subject];
2110
+ const howText = beliefOriginText(cell, entry.beliefOrigin[subject]);
2111
+ return '<tr><td class="mono">' + esc(subject) + '</td><td class="mono">' + esc(cell || "\\u2014") + "</td><td>" + esc(howText) + "</td></tr>";
2112
+ }).join("")
2113
+ : '<tr><td class="outlook-empty" colspan="3">' + esc(id) + " is alone on the board \\u2014 nothing else to believe anything about.</td></tr>";
2114
+ const planLine = entry.plan.length ? entry.plan.join(" \\u2192 ") : "holding";
2115
+ planText.textContent = id + "'s plan (" + entry.rung + "): " + planLine + " \\u2014 " + entry.goal;
2070
2116
  }
2071
- const subjects = Object.keys(entry.belief).sort();
2072
- body.innerHTML = subjects.length
2073
- ? subjects.map(function (subject) {
2074
- const cell = entry.belief[subject];
2075
- const howText = beliefOriginText(cell, entry.beliefOrigin[subject]);
2076
- return '<tr><td class="mono">' + esc(subject) + '</td><td class="mono">' + esc(cell || "\\u2014") + "</td><td>" + esc(howText) + "</td></tr>";
2077
- }).join("")
2078
- : '<tr><td class="outlook-empty" colspan="3">' + esc(id) + " is alone on the board \\u2014 nothing else to believe anything about.</td></tr>";
2079
- const planLine = entry.plan.length ? entry.plan.join(" \\u2192 ") : "holding";
2080
- planText.textContent = id + "'s plan (" + entry.rung + "): " + planLine + " \\u2014 " + entry.goal;
2081
- const puzzle = lastOutlook.puzzle;
2117
+ const puzzle = lastOutlook && lastOutlook.puzzle;
2082
2118
  if (!puzzle) {
2083
2119
  puzzleText.hidden = true;
2084
2120
  puzzleText.textContent = "";
@@ -2126,6 +2162,38 @@ function pageScript() {
2126
2162
  el("stepHint").hidden = true;
2127
2163
  }
2128
2164
 
2165
+ // A puzzle scenario's own boot: no roster to mint, no cast to seed, and no
2166
+ // ticking ever starts. The four passengers a puzzle world places are read
2167
+ // straight off its own facts (puzzleActorIdsFrom), the actor card and the
2168
+ // outlook panel work exactly as they do for a chase board's followed
2169
+ // agent, and the plan panel is the whole point — refreshOutlook() below
2170
+ // computes it the same way it always does.
2171
+ async function bootPuzzle(seq, s) {
2172
+ cast = [];
2173
+ props = [];
2174
+ puzzleActorIds = puzzleActorIdsFrom((s.worldPayload && s.worldPayload.facts) || []);
2175
+ const opened = await window.tmct.open(s.worldPayload, {
2176
+ agents: [],
2177
+ epoch: 0,
2178
+ getTeachEnabled: function () { return el("teachToggle").checked; },
2179
+ });
2180
+ if (seq !== bootSeq) return;
2181
+ session = opened;
2182
+ agentsById = {};
2183
+ itemsById = {};
2184
+ el("chatInput").disabled = false;
2185
+ await callScene("boot", {
2186
+ propPlacements: [], assetManifest: DATA.assetManifest, gridSize: gridSizeOf(), cellSize: 1,
2187
+ agentPresentation: {},
2188
+ });
2189
+ if (seq !== bootSeq) return;
2190
+ camera.selectedId = puzzleActorIds[0] || null;
2191
+ renderAll();
2192
+ await refreshOutlook();
2193
+ showStopped();
2194
+ setSceneStatus("this scenario is a puzzle, not a chase \\u2014 follow one of the four passengers below, and its own plan panel shows the crossing.");
2195
+ }
2196
+
2129
2197
  let bootSeq = 0;
2130
2198
  async function boot() {
2131
2199
  const seq = bootSeq += 1;
@@ -2138,6 +2206,8 @@ function pageScript() {
2138
2206
  deferredSceneCamera = null;
2139
2207
  expandedAgents.clear();
2140
2208
  const s = scenario();
2209
+ applyPuzzleVisibility();
2210
+ if (s.puzzle) return bootPuzzle(seq, s);
2141
2211
  const foxes = mintRoster(rosterPrefixFor(s, "predator"), chosenFoxCount());
2142
2212
  const goblins = mintRoster(rosterPrefixFor(s, "prey"), chosenGoblinCount());
2143
2213
  cast = foxes.concat(goblins);
@@ -2191,6 +2261,10 @@ function pageScript() {
2191
2261
  if (ticker) { ticker.pause(); ticker = null; }
2192
2262
  expandedAgents.clear();
2193
2263
  const s = scenario();
2264
+ // No control ever calls this on a puzzle scenario (resetBtn hides itself
2265
+ // via data-hide-when-puzzle), but a puzzle world has nothing to re-cast
2266
+ // either way, so re-booting is the correct answer if this is reached.
2267
+ if (s.puzzle) return boot();
2194
2268
  const foxes = mintRoster(rosterPrefixFor(s, "predator"), chosenFoxCount());
2195
2269
  const goblins = mintRoster(rosterPrefixFor(s, "prey"), chosenGoblinCount());
2196
2270
  cast = foxes.concat(goblins);