@polycode-projects/the-mechanical-code-talker 7.0.0 → 7.1.0
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 +1 -1
- package/src/services/chat-session.mjs +17 -9
- package/src/services/chat-voice.mjs +27 -0
- package/src/services/chat.mjs +274 -209
- package/src/services/world-teach.mjs +14 -7
- package/src/surfaces/web/chat-browser-entry.mjs +15 -4
- package/src/surfaces/web/memory-ask-browser.bundle.js +135 -135
- package/src/surfaces/web/turn-session.mjs +5 -3
package/src/services/chat.mjs
CHANGED
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
thirdPersonSingularSurface, baseVerbSurface, gerundVerbSurface, findingCaveat,
|
|
34
34
|
} from "../domain/fact-phrase.mjs";
|
|
35
35
|
import { emptyRecord as emptyDiscourseRecord, advanceTurn as advanceDiscourseTurn, register as registerReferent, bind as bindDiscourseForm } from "../domain/discourse.mjs";
|
|
36
|
+
import { DEFAULT_VOICE, PLAIN_VOICE, resolveChatVoice, plainSentence } from "./chat-voice.mjs";
|
|
36
37
|
import { uuidv7 } from "../adapters/uuid.mjs";
|
|
37
38
|
import * as defaultSource from "../adapters/source.mjs";
|
|
38
39
|
import { loadTemplates, render as renderTemplate } from "../adapters/corpus/templates.mjs";
|
|
@@ -1029,7 +1030,8 @@ const memoryClassLine = (ind) => String(ind.label || ind.id || "").trim();
|
|
|
1029
1030
|
* answer off the store. Returns { text, pending } or null (→ the next lane owns
|
|
1030
1031
|
* it). A real restrictor tail declines rather than answering a shorter question
|
|
1031
1032
|
* nobody asked. */
|
|
1032
|
-
async function answerMemoryClassQuery(memoryDir, query) {
|
|
1033
|
+
async function answerMemoryClassQuery(memoryDir, query, voice = DEFAULT_VOICE) {
|
|
1034
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
1033
1035
|
if (!memoryDir) return null;
|
|
1034
1036
|
const q = String(query).trim();
|
|
1035
1037
|
const listM = q.match(MEMORY_CLASS_LIST_TRIGGER_RE);
|
|
@@ -1061,7 +1063,7 @@ async function answerMemoryClassQuery(memoryDir, query) {
|
|
|
1061
1063
|
const inds = rows || (mem.individuals || []).filter((i) => (i.class || "") === cls);
|
|
1062
1064
|
if (countM) return { text: `${inds.length} ${inds.length === 1 ? plural.replace(/s$/, "") : plural}.`, kind: "count" };
|
|
1063
1065
|
if (!inds.length) return { text: `I don't have any ${plural} stored yet.`, miss: true };
|
|
1064
|
-
const lines = rows ? rows.map(
|
|
1066
|
+
const lines = rows ? rows.map(factLine) : inds.map(memoryClassLine);
|
|
1065
1067
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
1066
1068
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
1067
1069
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -1210,7 +1212,8 @@ const EXCLUSION_TAIL_RE = /^(?:but\s+not|except(?:\s+for)?|excluding|other\s+tha
|
|
|
1210
1212
|
* restrictor tail rather than answering as if it weren't there. An exclusion
|
|
1211
1213
|
* tail ("but not greek letters") is its own case: it resolves the excluded
|
|
1212
1214
|
* phrase the same way and subtracts, rather than falling into that refusal. */
|
|
1213
|
-
async function answerMembershipList(memoryDir, query, biasByBundle = {}, cache = null) {
|
|
1215
|
+
async function answerMembershipList(memoryDir, query, biasByBundle = {}, cache = null, voice = DEFAULT_VOICE) {
|
|
1216
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
1214
1217
|
if (!memoryDir) return null;
|
|
1215
1218
|
const m = String(query).trim().match(MEMBERSHIP_LIST_RE);
|
|
1216
1219
|
if (!m) return null;
|
|
@@ -1224,8 +1227,8 @@ async function answerMembershipList(memoryDir, query, biasByBundle = {}, cache =
|
|
|
1224
1227
|
});
|
|
1225
1228
|
const renderMembers = (directList, inheritedList, note) => {
|
|
1226
1229
|
const lines = [
|
|
1227
|
-
...directList.map(
|
|
1228
|
-
...inheritedList.map((f) => renderFactLineWithChain(f, parents, subjectSet, { toward: classTerm })),
|
|
1230
|
+
...directList.map(factLine),
|
|
1231
|
+
...inheritedList.map((f) => renderFactLineWithChain(f, parents, subjectSet, { toward: classTerm, voice })),
|
|
1229
1232
|
];
|
|
1230
1233
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
1231
1234
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
@@ -1292,7 +1295,8 @@ const COLLECTION_CONTENTS_ALL_RE =
|
|
|
1292
1295
|
* whose type doesn't match what's declared, or what any member's own isa
|
|
1293
1296
|
* fact says, is an honest miss naming the mismatch — never the unfiltered
|
|
1294
1297
|
* contents rendered as if they answered the question that wasn't asked. */
|
|
1295
|
-
async function answerCollectionContents(memoryDir, query, biasByBundle = {}, cache = null) {
|
|
1298
|
+
async function answerCollectionContents(memoryDir, query, biasByBundle = {}, cache = null, voice = DEFAULT_VOICE) {
|
|
1299
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
1296
1300
|
if (!memoryDir) return null;
|
|
1297
1301
|
const q = String(query).trim();
|
|
1298
1302
|
// The unrestricted twin is tried first: its "what is in"/"the contents of"
|
|
@@ -1311,7 +1315,7 @@ async function answerCollectionContents(memoryDir, query, biasByBundle = {}, cac
|
|
|
1311
1315
|
if (!members.length) return null; // no containment rows at all — answerMembershipList keeps this noun
|
|
1312
1316
|
const renderMembers = (list, noun) => {
|
|
1313
1317
|
const ranked = rankByBiasThenTrust(uniqueFacts(list), biasByBundle);
|
|
1314
|
-
const lines = ranked.map(
|
|
1318
|
+
const lines = ranked.map(factLine);
|
|
1315
1319
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
1316
1320
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
1317
1321
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -1345,7 +1349,8 @@ const EXAMPLE_OF_RE = /^(?:give me\s+|what(?:'s|\s+is)\s+)?(?:an\s+example\s+of|
|
|
|
1345
1349
|
* class exactly as answerMembershipList does, and declines the same way: null
|
|
1346
1350
|
* for a code-countable or untaught class, a named-tail refusal for a real
|
|
1347
1351
|
* restrictor. */
|
|
1348
|
-
async function answerMembershipExample(memoryDir, query, biasByBundle = {}, cache = null) {
|
|
1352
|
+
async function answerMembershipExample(memoryDir, query, biasByBundle = {}, cache = null, voice = DEFAULT_VOICE) {
|
|
1353
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
1349
1354
|
if (!memoryDir) return null;
|
|
1350
1355
|
const m = String(query).trim().match(EXAMPLE_OF_RE);
|
|
1351
1356
|
if (!m) return null;
|
|
@@ -1363,7 +1368,7 @@ async function answerMembershipExample(memoryDir, query, biasByBundle = {}, cach
|
|
|
1363
1368
|
// directMembers is never empty here: longestTaughtClassInRun only reads a
|
|
1364
1369
|
// phrase as "on record" once something is taught directly under it, and the
|
|
1365
1370
|
// example is always that direct member, not one only reached by closure.
|
|
1366
|
-
return { text: `${
|
|
1371
|
+
return { text: `${factLine(directMembers[0])}\nSay "list ${asked}" for all ${n}.` };
|
|
1367
1372
|
}
|
|
1368
1373
|
|
|
1369
1374
|
/** "words with the letter p in it" / "words containing p" / "which words
|
|
@@ -2018,6 +2023,10 @@ const T_CONCEPT = "concept-force";
|
|
|
2018
2023
|
* failure said out loud, never a crashed turn or a silently different answer. */
|
|
2019
2024
|
const TEMPLATES_UNAVAILABLE = "response templates unavailable — ask a question, or /help for commands.";
|
|
2020
2025
|
|
|
2026
|
+
/** The plain voice's greeting and empty-graph orientation. It is a constant
|
|
2027
|
+
* in code because a browser bundle cannot read the template file. */
|
|
2028
|
+
const PLAIN_GREETING = "Hello. Ask about anything in the library, or tell me a fact to remember.";
|
|
2029
|
+
|
|
2021
2030
|
let templatesPromise = null;
|
|
2022
2031
|
/** Load data/templates/responses.jsonl once per process; null on failure. */
|
|
2023
2032
|
function chatTemplates() {
|
|
@@ -2518,6 +2527,7 @@ function conversationalTurn(line, ctx) {
|
|
|
2518
2527
|
? emptyGraphTemplateId(ctx.uiContext, ctx.codeDomainActive, T_GREETING_EMPTY, T_GREETING_EMPTY_NEUTRAL, T_GREETING_EMPTY_BROWSER)
|
|
2519
2528
|
: (T_GREETING_BY_PHRASE[greetHit] || T_GREETING);
|
|
2520
2529
|
note(ctx.trace, `pattern: template "${id}" (data/templates/responses.jsonl)`);
|
|
2530
|
+
if (ctx.voice === PLAIN_VOICE) return mk(PLAIN_GREETING, { lane: "greeting" });
|
|
2521
2531
|
return mk(t(id, { vocabHint: ctx.vocabHint }), { lane: "greeting" });
|
|
2522
2532
|
}
|
|
2523
2533
|
}
|
|
@@ -2595,7 +2605,7 @@ function conversationalTurn(line, ctx) {
|
|
|
2595
2605
|
|| CAPABILITY_PHRASES.some((re) => re.test(applyPreambleFrames(raw))) || ORIENT_OPENERS.has(q)) {
|
|
2596
2606
|
note(ctx.trace, "goal: get oriented — what can tmct answer, how do I start");
|
|
2597
2607
|
note(ctx.trace, "lane: conversational — help/orientation (CAPABILITY_PHRASES/ORIENT_OPENERS / bare help / ?)");
|
|
2598
|
-
return mk(orientationAnswer(ctx.templates, ctx.graph, ctx.vocabHint, ctx.uiContext, ctx.codeDomainActive), { lane: "help" });
|
|
2608
|
+
return mk(orientationAnswer(ctx.templates, ctx.graph, ctx.vocabHint, ctx.uiContext, ctx.codeDomainActive, ctx.voice), { lane: "help" });
|
|
2599
2609
|
}
|
|
2600
2610
|
// Fuzzy-typo fallback (A4): every exact/collapsed closed-set lookup above missed —
|
|
2601
2611
|
// try a bounded edit-distance match against the flattened conversational phrase
|
|
@@ -2613,10 +2623,11 @@ function conversationalTurn(line, ctx) {
|
|
|
2613
2623
|
if (bucket === "identity") {
|
|
2614
2624
|
return mk(t(identitySelfTemplateId(ctx.uiContext, ctx.codeDomainActive), { vocabHint: ctx.vocabHint }), { lane: "help" });
|
|
2615
2625
|
}
|
|
2616
|
-
if (bucket === "capability") return mk(orientationAnswer(ctx.templates, ctx.graph, ctx.vocabHint, ctx.uiContext, ctx.codeDomainActive), { lane: "help" });
|
|
2626
|
+
if (bucket === "capability") return mk(orientationAnswer(ctx.templates, ctx.graph, ctx.vocabHint, ctx.uiContext, ctx.codeDomainActive, ctx.voice), { lane: "help" });
|
|
2617
2627
|
const id = (!T_GREETING_BY_PHRASE[fuzzyHit] && noCodeGraph(ctx.graph))
|
|
2618
2628
|
? uiTemplateId(ctx.uiContext, T_GREETING_EMPTY, T_GREETING_EMPTY_BROWSER)
|
|
2619
2629
|
: (T_GREETING_BY_PHRASE[fuzzyHit] || T_GREETING);
|
|
2630
|
+
if (ctx.voice === PLAIN_VOICE) return mk(PLAIN_GREETING, { lane: "greeting" });
|
|
2620
2631
|
return mk(t(id, { vocabHint: ctx.vocabHint }), { lane: "greeting" });
|
|
2621
2632
|
}
|
|
2622
2633
|
}
|
|
@@ -2687,8 +2698,9 @@ function orientationExamples(graph) {
|
|
|
2687
2698
|
* graph, the standard one (with live {example1}/{example2} query examples from
|
|
2688
2699
|
* the loaded graph) otherwise. `codeDomainActive` picks the empty variant's own
|
|
2689
2700
|
* wording: today's code-structure clause when true, a neutral one when false. */
|
|
2690
|
-
function orientationAnswer(templates, graph, vocabHint, uiContext = "cli", codeDomainActive = false) {
|
|
2701
|
+
function orientationAnswer(templates, graph, vocabHint, uiContext = "cli", codeDomainActive = false, voice = DEFAULT_VOICE) {
|
|
2691
2702
|
if (noCodeGraph(graph)) {
|
|
2703
|
+
if (voice === PLAIN_VOICE) return PLAIN_GREETING;
|
|
2692
2704
|
const id = emptyGraphTemplateId(uiContext, codeDomainActive, T_ORIENTATION_EMPTY, T_ORIENTATION_EMPTY_NEUTRAL, T_ORIENTATION_EMPTY_BROWSER);
|
|
2693
2705
|
return tRender(templates, id, { vocabHint }) ?? TEMPLATES_UNAVAILABLE;
|
|
2694
2706
|
}
|
|
@@ -2710,13 +2722,14 @@ const ORIENTATION_EMPTY_FALLBACK_BROWSER = "I'm tmct — a deterministic, offlin
|
|
|
2710
2722
|
* through the SAME template (T_ORIENTATION_EMPTY/T_ORIENTATION_EMPTY_BROWSER)
|
|
2711
2723
|
* conversationalTurn's orientation branch uses, so there is exactly one copy of
|
|
2712
2724
|
* that wording to keep in sync, not two hand-duplicated strings. */
|
|
2713
|
-
function orientationText(graph, templates, vocabHint, uiContext = "cli", codeDomainActive = false) {
|
|
2725
|
+
function orientationText(graph, templates, vocabHint, uiContext = "cli", codeDomainActive = false, voice = DEFAULT_VOICE) {
|
|
2714
2726
|
// A null (never-loaded) graph reads as "unknown, not empty" to noCodeGraph,
|
|
2715
2727
|
// which is the right call for the greeting/orientation CARD — but there is no
|
|
2716
2728
|
// entity count to render from one either, so the empty wording is the only
|
|
2717
2729
|
// truthful thing left to say. Without this the entity tally below threw on a
|
|
2718
2730
|
// graph-less runTurn.
|
|
2719
2731
|
if (!graph || noCodeGraph(graph)) {
|
|
2732
|
+
if (voice === PLAIN_VOICE) return PLAIN_GREETING;
|
|
2720
2733
|
const id = emptyGraphTemplateId(uiContext, codeDomainActive, T_ORIENTATION_EMPTY, T_ORIENTATION_EMPTY_NEUTRAL, T_ORIENTATION_EMPTY_BROWSER);
|
|
2721
2734
|
// ORIENTATION_EMPTY_FALLBACK_BROWSER already carries no code vocabulary,
|
|
2722
2735
|
// so it doubles as the neutral CLI fallback too — only the domain-active
|
|
@@ -3471,6 +3484,30 @@ export const PERSIST_UNAVAILABLE_TEXT = "I understood that, but I couldn't save
|
|
|
3471
3484
|
const PERSIST_UNAVAILABLE_VIA = "persist-unavailable";
|
|
3472
3485
|
const persistUnavailableAnswer = () => ({ text: PERSIST_UNAVAILABLE_TEXT, via: PERSIST_UNAVAILABLE_VIA, miss: true });
|
|
3473
3486
|
|
|
3487
|
+
/** A teach confirmation in both voices. `statement` is what was stored, as a
|
|
3488
|
+
* sentence body ("rover is a dog"). The default voice says "noted —
|
|
3489
|
+
* remembered: <statement>"; the plain voice states it as a sentence.
|
|
3490
|
+
* `taught` marks a reply that changed memory on the user's word, so the turn
|
|
3491
|
+
* result can say so without reading the wording. */
|
|
3492
|
+
function rememberedReply(statement, via = "assert") {
|
|
3493
|
+
return { text: `noted — remembered: ${statement}`, plainText: plainSentence(statement), via, miss: false, taught: true };
|
|
3494
|
+
}
|
|
3495
|
+
|
|
3496
|
+
/** A lane reply's text in the session's voice. A reply with one wording reads
|
|
3497
|
+
* the same in both voices. */
|
|
3498
|
+
function voicedText(reply, voice) {
|
|
3499
|
+
return voice === PLAIN_VOICE && reply.plainText ? reply.plainText : reply.text;
|
|
3500
|
+
}
|
|
3501
|
+
|
|
3502
|
+
/** A turn built in the default voice, put in the session's voice. The plain
|
|
3503
|
+
* wording a lane wrote beside the default one stops here and does not reach
|
|
3504
|
+
* the turn result. */
|
|
3505
|
+
function turnInVoice({ plainText, ...turn }, voice) {
|
|
3506
|
+
if (voice !== PLAIN_VOICE || !plainText) return turn;
|
|
3507
|
+
const logLines = Array.isArray(turn.logLines) ? turn.logLines.map((l) => (l === turn.answer ? plainText : l)) : turn.logLines;
|
|
3508
|
+
return { ...turn, answer: plainText, logLines };
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3474
3511
|
/** Reify one teach-lane fact + confirm (shared by the property and ownership
|
|
3475
3512
|
* frames). Lazy + failure-tolerated: a write failure degrades to null (the
|
|
3476
3513
|
* teach-miss text stands), never a crash. A store refusal is the exception —
|
|
@@ -3492,7 +3529,7 @@ async function teachFact(memoryDir, sessionId, { subject, predicate, object, qua
|
|
|
3492
3529
|
// The dated-teach frame's own echo: the user typed the date, so the
|
|
3493
3530
|
// acknowledgment shows it was registered rather than silently dropped.
|
|
3494
3531
|
const dateSuffix = observedAt && dateText ? ` (as of ${dateText})` : "";
|
|
3495
|
-
return {
|
|
3532
|
+
return rememberedReply(`${s} ${phrase} ${o}${dateSuffix}`);
|
|
3496
3533
|
} catch (error) {
|
|
3497
3534
|
rethrowPersistFailure(error);
|
|
3498
3535
|
return null;
|
|
@@ -5681,11 +5718,11 @@ const NEGATIVE_UNIVERSAL_TEACH_RE = /^no\s+([\w-]+)\s+(is|are)\s+(?:an?\s+)?(?:(
|
|
|
5681
5718
|
const SINGULAR_NEGATION_TEACH_RE = /^(?:an?\s+)?([\w-]+)\s+(?:is\s+not|isn't)\s+(?:an?\s+)?(?:(?:kind|type)\s+of\s+)?([\w-]+)$/i;
|
|
5682
5719
|
|
|
5683
5720
|
/** The mint (or the reflexive refusal) shared by every "no X is Y"-shaped
|
|
5684
|
-
* teach surface: null only when the store write itself fails.
|
|
5721
|
+
* teach surface: null only when the store write itself fails. ackStatement
|
|
5685
5722
|
* overrides teachFact's own acknowledgment for a caller whose surface form
|
|
5686
5723
|
* isn't already the canonical "no X is a Y" restatement, so the user still
|
|
5687
5724
|
* sees how the sentence actually landed. */
|
|
5688
|
-
async function mintNegativeUniversal(subject, object, { memoryDir, sessionId, observedAt, dateText,
|
|
5725
|
+
async function mintNegativeUniversal(subject, object, { memoryDir, sessionId, observedAt, dateText, ackStatement }) {
|
|
5689
5726
|
if (subject.toLowerCase() === object.toLowerCase()) {
|
|
5690
5727
|
return {
|
|
5691
5728
|
text: `I can't store "no ${subject} is a ${object}" — every ${subject} is a ${subject} by definition, so that exclusion contradicts itself. Nothing was stored.`,
|
|
@@ -5702,7 +5739,7 @@ async function mintNegativeUniversal(subject, object, { memoryDir, sessionId, ob
|
|
|
5702
5739
|
via: "teach-miss", miss: true,
|
|
5703
5740
|
};
|
|
5704
5741
|
}
|
|
5705
|
-
return
|
|
5742
|
+
return ackStatement ? { ...stored, ...rememberedReply(ackStatement) } : stored;
|
|
5706
5743
|
}
|
|
5707
5744
|
|
|
5708
5745
|
/** The mint (or the reflexive refusal) for a NEGATIVE_UNIVERSAL_TEACH_RE
|
|
@@ -5952,7 +5989,8 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
5952
5989
|
if (firstOk && secondOk) {
|
|
5953
5990
|
return {
|
|
5954
5991
|
text: `noted — remembered both: ${stripNoted(first.text)}; and ${stripNoted(second.text)}`,
|
|
5955
|
-
|
|
5992
|
+
plainText: `${voicedText(first, PLAIN_VOICE)} ${voicedText(second, PLAIN_VOICE)}`,
|
|
5993
|
+
via: "assert", miss: false, taught: Boolean(first.taught || second.taught),
|
|
5956
5994
|
};
|
|
5957
5995
|
}
|
|
5958
5996
|
if (firstOk || secondOk) {
|
|
@@ -5962,7 +6000,8 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
5962
6000
|
return {
|
|
5963
6001
|
text: `noted — remembered: ${stripNoted(ok.text)}. The other half ("${badHalf}") I couldn't store`
|
|
5964
6002
|
+ `${bad ? ` — ${stripNoted(bad.text)}` : ", it isn't a fact shape I recognize."}`,
|
|
5965
|
-
|
|
6003
|
+
plainText: `${voicedText(ok, PLAIN_VOICE)} The other half ("${badHalf}") was not stored.`,
|
|
6004
|
+
via: "assert", miss: false, taught: Boolean(ok.taught),
|
|
5966
6005
|
};
|
|
5967
6006
|
}
|
|
5968
6007
|
if (first || second) {
|
|
@@ -5982,7 +6021,8 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
5982
6021
|
if (first && !first.miss) {
|
|
5983
6022
|
return {
|
|
5984
6023
|
text: `${first.text} — the second part ("${ownSubject[2].trim()}") names its own subject, so I didn't store it; teach it as its own sentence if you meant it.`,
|
|
5985
|
-
|
|
6024
|
+
plainText: `${voicedText(first, PLAIN_VOICE)} The second part ("${ownSubject[2].trim()}") names its own subject, so it was not stored. Say it as its own sentence to store it.`,
|
|
6025
|
+
via: "assert", miss: false, taught: Boolean(first.taught),
|
|
5986
6026
|
};
|
|
5987
6027
|
}
|
|
5988
6028
|
// the first half didn't store — fall through to the ordinary cascade
|
|
@@ -6059,7 +6099,8 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6059
6099
|
await removeFactsForLoc(memoryDir, [row.id]);
|
|
6060
6100
|
return {
|
|
6061
6101
|
text: `noted — forgotten: "${locSubject} ${predicatePhrase(locPredicate)} ${locObject}" is no longer stored.`,
|
|
6062
|
-
|
|
6102
|
+
plainText: plainSentence(`"${locSubject} ${predicatePhrase(locPredicate)} ${locObject}" is no longer stored`),
|
|
6103
|
+
via: "retract", miss: false, taught: true,
|
|
6063
6104
|
};
|
|
6064
6105
|
}
|
|
6065
6106
|
// nothing stored under that triple — fall through to the ordinary cascade
|
|
@@ -6108,6 +6149,9 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6108
6149
|
text: `${stored.text} — you told me earlier that ${negSubject} ${predicatePhrase(positive.predicate)} ${negObject}, so both are now stored `
|
|
6109
6150
|
+ `and I'll report the disagreement rather than pick one. `
|
|
6110
6151
|
+ `To drop the earlier fact instead, say "forget that ${negSubject} is ${indefiniteArticleFor(negObject)} ${negObject}".`,
|
|
6152
|
+
plainText: `${stored.plainText} The earlier fact that ${negSubject} ${predicatePhrase(positive.predicate)} ${negObject} is stored too, `
|
|
6153
|
+
+ `so answers report the disagreement. `
|
|
6154
|
+
+ `To drop the earlier fact instead, say "forget that ${negSubject} is ${indefiniteArticleFor(negObject)} ${negObject}".`,
|
|
6111
6155
|
};
|
|
6112
6156
|
}
|
|
6113
6157
|
}
|
|
@@ -6148,9 +6192,9 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6148
6192
|
if (objectIsDeclaredNoun || subjectIsIndividual) {
|
|
6149
6193
|
const negUniversal = await mintNegativeUniversal(negationSubject, negationObject, {
|
|
6150
6194
|
memoryDir, sessionId, observedAt, dateText,
|
|
6151
|
-
|
|
6152
|
-
? `
|
|
6153
|
-
:
|
|
6195
|
+
ackStatement: objectIsDeclaredNoun
|
|
6196
|
+
? `no ${negationSubject} is a ${negationObject}`
|
|
6197
|
+
: `${negationSubject} is not a ${negationObject}`,
|
|
6154
6198
|
});
|
|
6155
6199
|
if (negUniversal) return negUniversal;
|
|
6156
6200
|
}
|
|
@@ -6238,7 +6282,9 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6238
6282
|
return {
|
|
6239
6283
|
text: `noted — forgotten your own record of "${retractSubject} ${retractedPhrase} ${retractObject}", `
|
|
6240
6284
|
+ "but it's still stored, told to me by someone else.",
|
|
6241
|
-
|
|
6285
|
+
plainText: `Your own record of "${retractSubject} ${retractedPhrase} ${retractObject}" is no longer stored. `
|
|
6286
|
+
+ "The fact is still stored from another source.",
|
|
6287
|
+
via: "retract", miss: false, taught: true,
|
|
6242
6288
|
};
|
|
6243
6289
|
}
|
|
6244
6290
|
if (result.found) {
|
|
@@ -6248,7 +6294,10 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6248
6294
|
+ (extra > 0 ? ` (${extra} entailed fact${extra === 1 ? "" : "s"} that depended on it went too)` : "")
|
|
6249
6295
|
+ (result.truncated ? " — this cascade may not be complete (a lot depended on it); ask again if something still looks stale" : "")
|
|
6250
6296
|
+ ".",
|
|
6251
|
-
|
|
6297
|
+
plainText: plainSentence(`"${retractSubject} ${retractedPhrase} ${retractObject}" is no longer stored`
|
|
6298
|
+
+ (extra > 0 ? ` (${extra} entailed fact${extra === 1 ? "" : "s"} that depended on it went too)` : ""))
|
|
6299
|
+
+ (result.truncated ? " Some facts that depended on it may still be stored; ask again if something still looks stale." : ""),
|
|
6300
|
+
via: "retract", miss: false, taught: true,
|
|
6252
6301
|
};
|
|
6253
6302
|
}
|
|
6254
6303
|
return {
|
|
@@ -6326,12 +6375,14 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6326
6375
|
const at = livePlan.cursor > 0 ? `step ${livePlan.cursor} of ${livePlan.actions.length}` : `0 of ${livePlan.actions.length} moves made`;
|
|
6327
6376
|
const goalText = livePlan.goalText ?? livePlan.goalTexts?.join("; ") ?? "the held goal";
|
|
6328
6377
|
const remembered = `noted — remembered: "${board[0]}".`;
|
|
6378
|
+
const plainRemembered = plainSentence(board[0]);
|
|
6329
6379
|
const replan = await solveHeldGoals({ memoryDir, planHolder, gameConfig });
|
|
6330
6380
|
if (replan.plan) {
|
|
6331
6381
|
const moves = replan.plan.actions.map((a, i) => `${i + 1}. ${a.label}`).join("; ");
|
|
6332
6382
|
return {
|
|
6333
6383
|
text: `${remembered} That changes the board the live plan was standing on (${at}, toward: ${goalText}), so I replanned from the board as it now stands: ${moves}. Say "next" to make move 1.`,
|
|
6334
|
-
|
|
6384
|
+
plainText: `${plainRemembered} That changes the board the live plan was standing on (${at}, toward: ${goalText}). The new plan from the board as it now stands: ${moves}. Say "next" to make move 1.`,
|
|
6385
|
+
via: "plan", miss: false, taught: true,
|
|
6335
6386
|
};
|
|
6336
6387
|
}
|
|
6337
6388
|
// The write STANDS, but nothing reaches the goal from the moved board:
|
|
@@ -6344,7 +6395,8 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6344
6395
|
};
|
|
6345
6396
|
return {
|
|
6346
6397
|
text: `${remembered} That changes the board the live plan was standing on (${at}, toward: ${goalText}) — from this new board no plan reaches the goal within ${maxDepth} moves, so the old plan is dropped. Re-teach the board or say "forget the goal".`,
|
|
6347
|
-
|
|
6398
|
+
plainText: `${plainRemembered} That changes the board the live plan was standing on (${at}, toward: ${goalText}). From this new board no plan reaches the goal within ${maxDepth} moves, so the old plan is dropped. Re-teach the board or say "forget the goal".`,
|
|
6399
|
+
via: "plan", miss: false, taught: true,
|
|
6348
6400
|
};
|
|
6349
6401
|
}
|
|
6350
6402
|
}
|
|
@@ -6439,7 +6491,9 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6439
6491
|
return {
|
|
6440
6492
|
text: `noted — remembered: ${collection} is a collection of ${typedMemberSurface}. `
|
|
6441
6493
|
+ `Say "<x> is in the ${collection}" to add one, and "what is in the ${collection}" to read them back.`,
|
|
6442
|
-
|
|
6494
|
+
plainText: `${plainSentence(`${collection} is a collection of ${typedMemberSurface}`)} `
|
|
6495
|
+
+ `Say "<x> is in the ${collection}" to add one, and "what is in the ${collection}" to read them back.`,
|
|
6496
|
+
via: "assert", miss: false, taught: true,
|
|
6443
6497
|
};
|
|
6444
6498
|
}
|
|
6445
6499
|
}
|
|
@@ -6578,10 +6632,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6578
6632
|
provenance: teachProvenanceTag(sessionId, new Date().toISOString()),
|
|
6579
6633
|
});
|
|
6580
6634
|
if (id) {
|
|
6581
|
-
return {
|
|
6582
|
-
text: `noted — remembered: a ${compose2[1]} is a ${compose2[2]} of a ${compose2[3]}`,
|
|
6583
|
-
via: "assert", miss: false,
|
|
6584
|
-
};
|
|
6635
|
+
return rememberedReply(`a ${compose2[1]} is a ${compose2[2]} of a ${compose2[3]}`);
|
|
6585
6636
|
}
|
|
6586
6637
|
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6587
6638
|
}
|
|
@@ -6603,10 +6654,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6603
6654
|
provenance: teachProvenanceTag(sessionId, new Date().toISOString()),
|
|
6604
6655
|
});
|
|
6605
6656
|
if (id) {
|
|
6606
|
-
return {
|
|
6607
|
-
text: `noted — remembered: a ${filterRule[1]} is a ${filterRule[2]} who is ${filterRule[3]}`,
|
|
6608
|
-
via: "assert", miss: false,
|
|
6609
|
-
};
|
|
6657
|
+
return rememberedReply(`a ${filterRule[1]} is a ${filterRule[2]} who is ${filterRule[3]}`);
|
|
6610
6658
|
}
|
|
6611
6659
|
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6612
6660
|
}
|
|
@@ -6632,10 +6680,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6632
6680
|
provenance: teachProvenanceTag(sessionId, new Date().toISOString()),
|
|
6633
6681
|
});
|
|
6634
6682
|
if (id) {
|
|
6635
|
-
return {
|
|
6636
|
-
text: `noted — remembered: a ${recursiveRule[1]} is a ${recursiveRule[2]}, or a ${recursiveRule[3]} of a ${recursiveRule[1]}`,
|
|
6637
|
-
via: "assert", miss: false,
|
|
6638
|
-
};
|
|
6683
|
+
return rememberedReply(`a ${recursiveRule[1]} is a ${recursiveRule[2]}, or a ${recursiveRule[3]} of a ${recursiveRule[1]}`);
|
|
6639
6684
|
}
|
|
6640
6685
|
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6641
6686
|
}
|
|
@@ -6668,10 +6713,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6668
6713
|
provenance: teachProvenanceTag(sessionId, new Date().toISOString()),
|
|
6669
6714
|
});
|
|
6670
6715
|
if (id) {
|
|
6671
|
-
return {
|
|
6672
|
-
text: `noted — remembered: you can ${verb} a ${actionSig[2].toLowerCase()} ${prep} a ${actionSig[4].toLowerCase()}`,
|
|
6673
|
-
via: "assert", miss: false,
|
|
6674
|
-
};
|
|
6716
|
+
return rememberedReply(`you can ${verb} a ${actionSig[2].toLowerCase()} ${prep} a ${actionSig[4].toLowerCase()}`);
|
|
6675
6717
|
}
|
|
6676
6718
|
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6677
6719
|
}
|
|
@@ -6693,10 +6735,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6693
6735
|
provenance: teachProvenanceTag(sessionId, new Date().toISOString()),
|
|
6694
6736
|
});
|
|
6695
6737
|
if (id) {
|
|
6696
|
-
return {
|
|
6697
|
-
text: `noted — remembered: you can ${verb} a ${actionSigPassive[1].toLowerCase()} ${prep} a ${actionSigPassive[4].toLowerCase()}`,
|
|
6698
|
-
via: "assert", miss: false,
|
|
6699
|
-
};
|
|
6738
|
+
return rememberedReply(`you can ${verb} a ${actionSigPassive[1].toLowerCase()} ${prep} a ${actionSigPassive[4].toLowerCase()}`);
|
|
6700
6739
|
}
|
|
6701
6740
|
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6702
6741
|
}
|
|
@@ -6729,10 +6768,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6729
6768
|
provenance: teachProvenanceTag(sessionId, new Date().toISOString()),
|
|
6730
6769
|
});
|
|
6731
6770
|
if (id) {
|
|
6732
|
-
return {
|
|
6733
|
-
text: `noted — remembered: to ${verb} ${prep}, nothing may ${precondNothing[5].toLowerCase()} ${precondNothing[6].toLowerCase()} the ${role === "target" ? "target" : precondNothing[2].toLowerCase()}`,
|
|
6734
|
-
via: "assert", miss: false,
|
|
6735
|
-
};
|
|
6771
|
+
return rememberedReply(`to ${verb} ${prep}, nothing may ${precondNothing[5].toLowerCase()} ${precondNothing[6].toLowerCase()} the ${role === "target" ? "target" : precondNothing[2].toLowerCase()}`);
|
|
6736
6772
|
}
|
|
6737
6773
|
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6738
6774
|
}
|
|
@@ -6767,10 +6803,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6767
6803
|
provenance: teachProvenanceTag(sessionId, new Date().toISOString()),
|
|
6768
6804
|
});
|
|
6769
6805
|
if (id) {
|
|
6770
|
-
return {
|
|
6771
|
-
text: `noted — remembered: to ${verb} ${prep}, the ${precondComp[5].toLowerCase()} must be ${precondComp[6].toLowerCase()} than the ${rightWord}`,
|
|
6772
|
-
via: "assert", miss: false,
|
|
6773
|
-
};
|
|
6806
|
+
return rememberedReply(`to ${verb} ${prep}, the ${precondComp[5].toLowerCase()} must be ${precondComp[6].toLowerCase()} than the ${rightWord}`);
|
|
6774
6807
|
}
|
|
6775
6808
|
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6776
6809
|
}
|
|
@@ -6792,10 +6825,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6792
6825
|
provenance: teachProvenanceTag(sessionId, new Date().toISOString()),
|
|
6793
6826
|
});
|
|
6794
6827
|
if (id) {
|
|
6795
|
-
return {
|
|
6796
|
-
text: `noted — remembered: to ${verb} ${prep}, the ${actionConstraint[5].toLowerCase()} may not be with the ${actionConstraint[6].toLowerCase()} without the ${actionConstraint[7].toLowerCase()}`,
|
|
6797
|
-
via: "assert", miss: false,
|
|
6798
|
-
};
|
|
6828
|
+
return rememberedReply(`to ${verb} ${prep}, the ${actionConstraint[5].toLowerCase()} may not be with the ${actionConstraint[6].toLowerCase()} without the ${actionConstraint[7].toLowerCase()}`);
|
|
6799
6829
|
}
|
|
6800
6830
|
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6801
6831
|
}
|
|
@@ -6847,11 +6877,8 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6847
6877
|
provenance: teachProvenanceTag(sessionId, new Date().toISOString()),
|
|
6848
6878
|
});
|
|
6849
6879
|
if (id) {
|
|
6850
|
-
return {
|
|
6851
|
-
|
|
6852
|
-
+ (namedSubjectRole ? "" : ` (the ${subjectRole} rides along on every ${verb} move — its class must have exactly one member when we plan)`),
|
|
6853
|
-
via: "assert", miss: false,
|
|
6854
|
-
};
|
|
6880
|
+
return rememberedReply(`${gerund} a ${actionEffect[2].toLowerCase()} ${prep} a ${actionEffect[4].toLowerCase()} makes the ${subjectWord.toLowerCase()} ${actionEffect[6].toLowerCase()} ${actionEffect[7].toLowerCase()} the ${actionEffect[8].toLowerCase()}`
|
|
6881
|
+
+ (namedSubjectRole ? "" : ` (the ${subjectRole} rides along on every ${verb} move — its class must have exactly one member when we plan)`));
|
|
6855
6882
|
}
|
|
6856
6883
|
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6857
6884
|
}
|
|
@@ -7056,7 +7083,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
7056
7083
|
object: participleObject(np[7]), observedAt, dateText,
|
|
7057
7084
|
});
|
|
7058
7085
|
const stripNoted = (t) => String(t).replace(/^noted — remembered(?:\s+\d+\s+facts?)?:\s*/i, "").trim();
|
|
7059
|
-
if (isaStored && relStored) return { text: `noted — remembered both: ${stripNoted(isaStored.text)}; and ${stripNoted(relStored.text)}`, via: "assert", miss: false };
|
|
7086
|
+
if (isaStored && relStored) return { text: `noted — remembered both: ${stripNoted(isaStored.text)}; and ${stripNoted(relStored.text)}`, plainText: `${isaStored.plainText} ${relStored.plainText}`, via: "assert", miss: false, taught: true };
|
|
7060
7087
|
if (relStored) return relStored;
|
|
7061
7088
|
if (isaStored) return isaStored;
|
|
7062
7089
|
}
|
|
@@ -7076,7 +7103,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
7076
7103
|
// universal success, so every caller (this loop AND the top-level
|
|
7077
7104
|
// declarative-sentence dispatch in runTurn) gets it uniformly.
|
|
7078
7105
|
const stored = await assertTurn(cand, { memoryDir, sessionId, focus: null, lexicon, cache, observedAt, dateText });
|
|
7079
|
-
if (stored) return { text: stored.answer, via: "assert", miss: false };
|
|
7106
|
+
if (stored) return { text: stored.answer, plainText: stored.plainText, via: "assert", miss: false, taught: Boolean(stored.taught) };
|
|
7080
7107
|
}
|
|
7081
7108
|
// CAPABILITY over a GROUNDED subject — "penguins swim" (habitual) or "a
|
|
7082
7109
|
// penguin can swim" (explicit) after "every penguin is a thing". The ACE
|
|
@@ -7468,7 +7495,7 @@ async function moduleOrientLane(query, { graph, codeDomainActive = null }) {
|
|
|
7468
7495
|
return null;
|
|
7469
7496
|
}
|
|
7470
7497
|
|
|
7471
|
-
async function metaLane(query, { graph, memoryDir, last = null, templates = null, vocabHint = null, focus = null, uiContext = "cli", codeDomainActive = false }) {
|
|
7498
|
+
async function metaLane(query, { graph, memoryDir, last = null, templates = null, vocabHint = null, focus = null, uiContext = "cli", codeDomainActive = false, voice = DEFAULT_VOICE }) {
|
|
7472
7499
|
// Preamble-peeled twin of `q`: a self-intro/greeting lead ("I'm new here,
|
|
7473
7500
|
// what should I read first") wraps exactly the orientation questions this
|
|
7474
7501
|
// lane owns, and the anchored META_ORIENT_RE can't see past it. Peeling
|
|
@@ -7479,7 +7506,7 @@ async function metaLane(query, { graph, memoryDir, last = null, templates = null
|
|
|
7479
7506
|
return { text: await memorySummary(memoryDir, graph, uiContext), via: "meta" };
|
|
7480
7507
|
}
|
|
7481
7508
|
if (peeled !== q && META_ORIENT_RE.test(peeled)) {
|
|
7482
|
-
const text = orientationText(graph, templates, vocabHint, uiContext, codeDomainActive);
|
|
7509
|
+
const text = orientationText(graph, templates, vocabHint, uiContext, codeDomainActive, voice);
|
|
7483
7510
|
return { text: last?.answer === text ? META_ORIENT_REPEAT_ONELINER : text, via: "meta" };
|
|
7484
7511
|
}
|
|
7485
7512
|
if (META_ORIENT_RE.test(q)) {
|
|
@@ -7489,7 +7516,7 @@ async function metaLane(query, { graph, memoryDir, last = null, templates = null
|
|
|
7489
7516
|
// reprints orientationText(graph) verbatim on every repeat, never
|
|
7490
7517
|
// collapsing. Mirrors ORIENTATION_REPEAT_ONELINER's identity-check
|
|
7491
7518
|
// pattern exactly, with its own distinct oneliner text.
|
|
7492
|
-
const text = orientationText(graph, templates, vocabHint, uiContext, codeDomainActive);
|
|
7519
|
+
const text = orientationText(graph, templates, vocabHint, uiContext, codeDomainActive, voice);
|
|
7493
7520
|
return { text: last?.answer === text ? META_ORIENT_REPEAT_ONELINER : text, via: "meta" };
|
|
7494
7521
|
}
|
|
7495
7522
|
// A bare "what is in here" with NO standing focus — see
|
|
@@ -7504,7 +7531,7 @@ async function metaLane(query, { graph, memoryDir, last = null, templates = null
|
|
|
7504
7531
|
if (!focus?.label) {
|
|
7505
7532
|
const stripped = normalizeQuery(String(query)).trim().replace(/[?.!]+$/, "").trim();
|
|
7506
7533
|
if (NO_FOCUS_WHATS_IN_HERE_RE.test(stripped)) {
|
|
7507
|
-
const text = orientationText(graph, templates, vocabHint, uiContext, codeDomainActive);
|
|
7534
|
+
const text = orientationText(graph, templates, vocabHint, uiContext, codeDomainActive, voice);
|
|
7508
7535
|
return { text: last?.answer === text ? META_ORIENT_REPEAT_ONELINER : text, via: "meta" };
|
|
7509
7536
|
}
|
|
7510
7537
|
}
|
|
@@ -8256,7 +8283,7 @@ function citedFactPhrase(f) {
|
|
|
8256
8283
|
* identically to a solid corpus fact would lose the only reader-visible signal
|
|
8257
8284
|
* that it's lower-confidence, so a distinct, honest hedge ("possibly: …")
|
|
8258
8285
|
* applies here instead. Provenance stays VERBATIM in every case. */
|
|
8259
|
-
function renderFactLine(f) {
|
|
8286
|
+
function renderFactLine(f, voice = DEFAULT_VOICE) {
|
|
8260
8287
|
const tail = factLineTail(f);
|
|
8261
8288
|
// A rdfs:subPropertyOf row relates two PREDICATES, not two things — factPhrase
|
|
8262
8289
|
// would compose the raw CURIE ("contains rdfs:subPropertyOf touches"), so this
|
|
@@ -8278,6 +8305,8 @@ function renderFactLine(f) {
|
|
|
8278
8305
|
// Reference-pack facts are the same class of cited data — the "i learned:"
|
|
8279
8306
|
// frame read as a definition-less non-answer on the re-ask.
|
|
8280
8307
|
if (f.provenance.includes("reference:")) return `${factPhrase(f)}${tail}`;
|
|
8308
|
+
// The plain voice cites every other source the same way.
|
|
8309
|
+
if (voice === PLAIN_VOICE) return `${factPhrase(f)}${tail}`;
|
|
8281
8310
|
return `i learned: ${factPhrase(f)}${tail}`;
|
|
8282
8311
|
}
|
|
8283
8312
|
|
|
@@ -8404,8 +8433,9 @@ function senseScreenBlocksWalk(screen, from, toVariants) {
|
|
|
8404
8433
|
* a sense join, so the rendered line stops at the last ancestor the fact's
|
|
8405
8434
|
* own object really sits under rather than reading "…→ region → body part"
|
|
8406
8435
|
* off a geographic subject. */
|
|
8407
|
-
function renderFactLineWithChain(f, parents, subjectVariants, { toward = null, screen = null } = {}) {
|
|
8408
|
-
const
|
|
8436
|
+
function renderFactLineWithChain(f, parents, subjectVariants, { toward = null, screen = null, voice = DEFAULT_VOICE } = {}) {
|
|
8437
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
8438
|
+
const base = factLine(f);
|
|
8409
8439
|
if (!ISA_PREDICATES.has(f.predicate) || !subjectVariants.has(f.subject)) return base;
|
|
8410
8440
|
let chain = ancestryChain(f.object, parents, { cap: 6, stopAt: ANSWER_STOP_SET, toward });
|
|
8411
8441
|
if (screen) {
|
|
@@ -8428,11 +8458,11 @@ function renderFactLineWithChain(f, parents, subjectVariants, { toward = null, s
|
|
|
8428
8458
|
* Returns `{ lines, grouped }`. `lines` is the flat, chain-enhanced rendering
|
|
8429
8459
|
* (indented by `indent`) the caller uses when senses do not split. `grouped`
|
|
8430
8460
|
* is a ready `{ text, replace, pending? }` answer when they do, else null. */
|
|
8431
|
-
function senseSplitFactList(hits, rows, subjectVariants, { indent = "", cache = null } = {}) {
|
|
8461
|
+
function senseSplitFactList(hits, rows, subjectVariants, { indent = "", cache = null, voice = DEFAULT_VOICE } = {}) {
|
|
8432
8462
|
const subClassEdges = rows.filter((f) => f.predicate === SUBCLASS_PREDICATE).map((f) => [f.subject, f.object]);
|
|
8433
8463
|
const parents = subClassParents(subClassEdges);
|
|
8434
8464
|
const screen = readTimeSenseScreen(rows, cache);
|
|
8435
|
-
const lines = hits.map((f) => `${indent}${renderFactLineWithChain(f, parents, subjectVariants, { screen })}`);
|
|
8465
|
+
const lines = hits.map((f) => `${indent}${renderFactLineWithChain(f, parents, subjectVariants, { screen, voice })}`);
|
|
8436
8466
|
|
|
8437
8467
|
const isaSubjectFacts = hits.filter((f) => ISA_PREDICATES.has(f.predicate) && subjectVariants.has(f.subject));
|
|
8438
8468
|
const isaObjects = [...new Set(isaSubjectFacts.map((f) => f.object))];
|
|
@@ -8450,7 +8480,7 @@ function senseSplitFactList(hits, rows, subjectVariants, { indent = "", cache =
|
|
|
8450
8480
|
const restItems = [];
|
|
8451
8481
|
let shownCount = 0;
|
|
8452
8482
|
const addLine = (f) => {
|
|
8453
|
-
const rendered = renderFactLineWithChain(f, parents, subjectVariants, { screen });
|
|
8483
|
+
const rendered = renderFactLineWithChain(f, parents, subjectVariants, { screen, voice });
|
|
8454
8484
|
if (shownCount < FACT_ANSWER_CAP) { shownCount += 1; return `${indent}${rendered}`; }
|
|
8455
8485
|
restItems.push(rendered);
|
|
8456
8486
|
return null;
|
|
@@ -8524,16 +8554,17 @@ function indefiniteArticleFor(term) {
|
|
|
8524
8554
|
*
|
|
8525
8555
|
* Shared by the two is-a readers (the memory-facts lane and the full ladder),
|
|
8526
8556
|
* so a disagreement reads identically whichever one answers. */
|
|
8527
|
-
function isaPolarityReply(hit, negHit) {
|
|
8557
|
+
function isaPolarityReply(hit, negHit, voice = DEFAULT_VOICE) {
|
|
8558
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
8528
8559
|
if (hit && negHit) {
|
|
8529
8560
|
return {
|
|
8530
|
-
text: `you've told me both, and I won't pick between them — ${
|
|
8561
|
+
text: `you've told me both, and I won't pick between them — ${factLine(hit)}; ${factLine(negHit)}. `
|
|
8531
8562
|
+ `To settle it, say "forget that ${hit.subject} is ${indefiniteArticleFor(hit.object)} ${hit.object}".`,
|
|
8532
8563
|
replace: true,
|
|
8533
8564
|
};
|
|
8534
8565
|
}
|
|
8535
|
-
if (negHit) return { text: `no — ${
|
|
8536
|
-
if (hit) return { text: `yes — ${
|
|
8566
|
+
if (negHit) return { text: `no — ${factLine(negHit)}`, replace: true };
|
|
8567
|
+
if (hit) return { text: `yes — ${factLine(hit)}`, replace: true };
|
|
8537
8568
|
return null;
|
|
8538
8569
|
}
|
|
8539
8570
|
|
|
@@ -9259,7 +9290,8 @@ function renderIsaCite(chain, facts) {
|
|
|
9259
9290
|
* subject with capability facts of its own ("a dog can bark") is better
|
|
9260
9291
|
* answered by citing them than by reciting what other animals do.
|
|
9261
9292
|
*/
|
|
9262
|
-
function capabilityReply(subjectText, objectText, facts, { maxHops = 3 } = {}) {
|
|
9293
|
+
function capabilityReply(subjectText, objectText, facts, { maxHops = 3, voice = DEFAULT_VOICE } = {}) {
|
|
9294
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
9263
9295
|
const subj = factTermVariants(normFactTermStatic, subjectText);
|
|
9264
9296
|
const obj = factTermVariants(normFactTermStatic, objectText);
|
|
9265
9297
|
const r = resolveCapabilityPolarity(subj, obj, facts, { maxHops });
|
|
@@ -9273,7 +9305,7 @@ function capabilityReply(subjectText, objectText, facts, { maxHops = 3 } = {}) {
|
|
|
9273
9305
|
// SOURCES, not inside the knowledge, so both are true statements about who
|
|
9274
9306
|
// said what. Report them and pick nothing.
|
|
9275
9307
|
if (r.verdict === "both") {
|
|
9276
|
-
const lines = [...r.negative, ...r.positive].map(
|
|
9308
|
+
const lines = [...r.negative, ...r.positive].map(factLine).join("\n");
|
|
9277
9309
|
return {
|
|
9278
9310
|
text: `I have both, at the same level of detail — my sources disagree, so I won't pick:\n${lines}`,
|
|
9279
9311
|
replace: true,
|
|
@@ -9283,11 +9315,13 @@ function capabilityReply(subjectText, objectText, facts, { maxHops = 3 } = {}) {
|
|
|
9283
9315
|
|
|
9284
9316
|
if (r.verdict === "yes" || r.verdict === "no") {
|
|
9285
9317
|
const winner = r.verdict === "no" ? r.negative[0] : r.positive[0];
|
|
9286
|
-
let text = `${r.verdict} — ${
|
|
9318
|
+
let text = `${r.verdict} — ${factLine(winner)}${viaChain(r.chain)}`;
|
|
9287
9319
|
// a direct fact beat a general default: say WHAT it overrides, or the
|
|
9288
9320
|
// answer silently contradicts what the same store says about the class
|
|
9289
9321
|
if (r.overrides) {
|
|
9290
|
-
text +=
|
|
9322
|
+
text += voice === PLAIN_VOICE
|
|
9323
|
+
? `. This holds over the general rule that ${citedFactPhrase(r.overrides.fact)}.`
|
|
9324
|
+
: `. That overrides what I know about ${r.overrides.fact.subject} generally: ${factLine(r.overrides.fact)}`;
|
|
9291
9325
|
}
|
|
9292
9326
|
return { text, replace: true };
|
|
9293
9327
|
}
|
|
@@ -9308,7 +9342,8 @@ function capabilityReply(subjectText, objectText, facts, { maxHops = 3 } = {}) {
|
|
|
9308
9342
|
* base rate to report and no reason to believe the subject is a real term at
|
|
9309
9343
|
* all — an unresolved "it" belongs to the pronoun lane, not here.
|
|
9310
9344
|
*/
|
|
9311
|
-
function capabilityBaseRateReply(subjectText, objectText, facts, { maxHops = 3 } = {}) {
|
|
9345
|
+
function capabilityBaseRateReply(subjectText, objectText, facts, { maxHops = 3, voice = DEFAULT_VOICE } = {}) {
|
|
9346
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
9312
9347
|
const subj = factTermVariants(normFactTermStatic, subjectText);
|
|
9313
9348
|
const obj = factTermVariants(normFactTermStatic, objectText);
|
|
9314
9349
|
const baseRate = capabilityBaseRate(subj, obj, facts, { maxHops });
|
|
@@ -9328,7 +9363,7 @@ function capabilityBaseRateReply(subjectText, objectText, facts, { maxHops = 3 }
|
|
|
9328
9363
|
].join(", ");
|
|
9329
9364
|
const named = [...baseRate.positive, ...baseRate.negative]
|
|
9330
9365
|
.slice(0, CAPABILITY_REPORT_CAP)
|
|
9331
|
-
.map((s) =>
|
|
9366
|
+
.map((s) => factLine(s.fact));
|
|
9332
9367
|
return {
|
|
9333
9368
|
text: `${opener} ${lead}, and of the ${baseRate.kinds} kind${baseRate.kinds === 1 ? "" : "s"} of ${baseRate.klass} I know, ${split}.\n${named.join("\n")}`,
|
|
9334
9369
|
replace: true,
|
|
@@ -9341,10 +9376,10 @@ function capabilityBaseRateReply(subjectText, objectText, facts, { maxHops = 3 }
|
|
|
9341
9376
|
const shown = extension.slice(0, CAPABILITY_REPORT_CAP);
|
|
9342
9377
|
const rest = extension.slice(shown.length);
|
|
9343
9378
|
return {
|
|
9344
|
-
text: `${opener} ${lead}, and nothing I know about ${baseRate.klass} says whether one can ${objectText}. I do know ${extension.length} thing${extension.length === 1 ? "" : "s"} that can ${objectText}${rest.length ? ` (first ${shown.length} shown)` : ""}:\n${shown.map(
|
|
9379
|
+
text: `${opener} ${lead}, and nothing I know about ${baseRate.klass} says whether one can ${objectText}. I do know ${extension.length} thing${extension.length === 1 ? "" : "s"} that can ${objectText}${rest.length ? ` (first ${shown.length} shown)` : ""}:\n${shown.map(factLine).join("\n")}`,
|
|
9345
9380
|
replace: true,
|
|
9346
9381
|
miss: true,
|
|
9347
|
-
...(rest.length ? { pending: { items: rest.map(
|
|
9382
|
+
...(rest.length ? { pending: { items: rest.map(factLine), noun: "facts" } } : {}),
|
|
9348
9383
|
};
|
|
9349
9384
|
}
|
|
9350
9385
|
|
|
@@ -9494,9 +9529,9 @@ function uniqueFacts(rows) {
|
|
|
9494
9529
|
* deducible (withDeducedGoal, below) — the ledger page's chat dock renders
|
|
9495
9530
|
* it as its own "Goal (inferred)" line; every other consumer reads named
|
|
9496
9531
|
* fields and is unaffected. */
|
|
9497
|
-
export async function factAnswer(memoryDir, query, envelope, miss, biasByBundle = {}, cache = null, focusLabel = null) {
|
|
9532
|
+
export async function factAnswer(memoryDir, query, envelope, miss, biasByBundle = {}, cache = null, focusLabel = null, voice = DEFAULT_VOICE) {
|
|
9498
9533
|
return withEnumerationLane(
|
|
9499
|
-
withDeducedGoal(await factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle, cache, focusLabel), envelope, query),
|
|
9534
|
+
withDeducedGoal(await factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle, cache, focusLabel, voice), envelope, query),
|
|
9500
9535
|
ENUMERATION_LANES.FACT_SET,
|
|
9501
9536
|
);
|
|
9502
9537
|
}
|
|
@@ -9561,7 +9596,8 @@ function withDeducedGoal(res, envelope, query) {
|
|
|
9561
9596
|
* subclass steps above it. They are cited ahead of the restriction's own
|
|
9562
9597
|
* premises so the answer shows the whole route it took, not just the last
|
|
9563
9598
|
* step of it. */
|
|
9564
|
-
async function restrictionExistentialHit(memoryDir, cache, subjectVariants, fillerVariants, subjectWord = null, chainPremises = []) {
|
|
9599
|
+
async function restrictionExistentialHit(memoryDir, cache, subjectVariants, fillerVariants, subjectWord = null, chainPremises = [], voice = DEFAULT_VOICE) {
|
|
9600
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
9565
9601
|
const { ON_PROPERTY_PREDICATE, SOME_VALUES_FROM_PREDICATE } = await import("../domain/syllogise.mjs");
|
|
9566
9602
|
const rows = await factRows(memoryDir, cache);
|
|
9567
9603
|
const onPropertyOf = new Map();
|
|
@@ -9591,7 +9627,7 @@ async function restrictionExistentialHit(memoryDir, cache, subjectVariants, fill
|
|
|
9591
9627
|
.map((id) => byId.get(id))
|
|
9592
9628
|
.filter((r) => r && r.predicate === SUBCLASS_PREDICATE);
|
|
9593
9629
|
const cited = premises.length ? premises : [hit];
|
|
9594
|
-
return { text: `yes — ${[...chainPremises, ...cited].map(
|
|
9630
|
+
return { text: `yes — ${[...chainPremises, ...cited].map(factLine).join("; ")}`, replace: true };
|
|
9595
9631
|
}
|
|
9596
9632
|
if (subjectRestrictions.length && subjectWord) {
|
|
9597
9633
|
return {
|
|
@@ -9614,7 +9650,8 @@ async function restrictionExistentialHit(memoryDir, cache, subjectVariants, fill
|
|
|
9614
9650
|
* unrelated part of the store never spends this turn's budget, and both
|
|
9615
9651
|
* stay silent on a subject their own check couldn't finish rather than
|
|
9616
9652
|
* clearing it. Returns the refusal text citing both premises, or null. */
|
|
9617
|
-
async function findWiderConsistencyClash(rows, variants, reasoning) {
|
|
9653
|
+
async function findWiderConsistencyClash(rows, variants, reasoning, voice = DEFAULT_VOICE) {
|
|
9654
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
9618
9655
|
const { extractTableauModule, buildTableauKb, findTableauViolations } = await import("../domain/tableau.mjs");
|
|
9619
9656
|
const { elUnsatisfiableClasses } = await import("../domain/el-classify.mjs");
|
|
9620
9657
|
// An individual's own stored TYPES seed the module too, not just its own
|
|
@@ -9633,7 +9670,7 @@ async function findWiderConsistencyClash(rows, variants, reasoning) {
|
|
|
9633
9670
|
const proveOpts = { maxSteps: reasoning.proveSteps, maxBranches: reasoning.proveBranches, maxNodes: reasoning.proveNodes };
|
|
9634
9671
|
const violation = findTableauViolations(kb, tableauSubjects, proveOpts)[0];
|
|
9635
9672
|
if (violation) {
|
|
9636
|
-
const cited = violation.premises.map((id) => byId.get(id)).filter(Boolean).map(
|
|
9673
|
+
const cited = violation.premises.map((id) => byId.get(id)).filter(Boolean).map(factLine).join("; ");
|
|
9637
9674
|
return `I can't answer that — what I've been told about ${violation.subject} is inconsistent: `
|
|
9638
9675
|
+ `${cited || "the facts I hold about it clash"}. I'd need one of those retracted before I can answer honestly.`;
|
|
9639
9676
|
}
|
|
@@ -9642,7 +9679,7 @@ async function findWiderConsistencyClash(rows, variants, reasoning) {
|
|
|
9642
9679
|
const elCheck = elUnsatisfiableClasses(moduleRows, { budget: reasoning.classifyBudget, rounds: reasoning.classifyRounds, focus: new Set(seeds) });
|
|
9643
9680
|
const unsatHit = elCheck.unsatisfiable.find((c) => variants.has(c) || typeSeeds.includes(c));
|
|
9644
9681
|
if (unsatHit) {
|
|
9645
|
-
const cited = elCheck.premisesOf(unsatHit).map((id) => byId.get(id)).filter(Boolean).map(
|
|
9682
|
+
const cited = elCheck.premisesOf(unsatHit).map((id) => byId.get(id)).filter(Boolean).map(factLine).join("; ");
|
|
9646
9683
|
return `I can't answer that — "${unsatHit}" can never have any members: `
|
|
9647
9684
|
+ `${cited || "its own subclass chain is unsatisfiable"}. I'd need one of those retracted before I can answer honestly.`;
|
|
9648
9685
|
}
|
|
@@ -9743,7 +9780,8 @@ function renderProvedConclusion(result, subjectWord, classWord, { negate = false
|
|
|
9743
9780
|
if (!result.cases || !result.cases.length) return `so ${subjectWord} ${predicate}.`;
|
|
9744
9781
|
return `in every case — ${renderCasesPhrase(result.cases, result.casesTotal)} — ${subjectWord} ${predicate}.`;
|
|
9745
9782
|
}
|
|
9746
|
-
async function autoProveFallback(memoryDir, cache, allRows, subjectWord, subjCandidates, objVariants, classWord) {
|
|
9783
|
+
async function autoProveFallback(memoryDir, cache, allRows, subjectWord, subjCandidates, objVariants, classWord, voice = DEFAULT_VOICE) {
|
|
9784
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
9747
9785
|
// storeMightHaveDlShape already ruled out "nothing DL-shaped anywhere in
|
|
9748
9786
|
// the store" without paying tableau.mjs's own first-load parse cost — see
|
|
9749
9787
|
// its own docblock. Only a store that passes it ever reaches the import.
|
|
@@ -9777,7 +9815,7 @@ async function autoProveFallback(memoryDir, cache, allRows, subjectWord, subjCan
|
|
|
9777
9815
|
if (isIndividual) {
|
|
9778
9816
|
const violation = findTableauViolations(kb, [subjectTerm], proveOpts)[0];
|
|
9779
9817
|
if (violation) {
|
|
9780
|
-
const cited = violation.premises.map((id) => byId.get(id)).filter(Boolean).map(
|
|
9818
|
+
const cited = violation.premises.map((id) => byId.get(id)).filter(Boolean).map(factLine).join("; ");
|
|
9781
9819
|
return {
|
|
9782
9820
|
text: `I can't answer that — what I've been told about ${violation.subject} is inconsistent: `
|
|
9783
9821
|
+ `${cited || "the facts I hold about it clash"}. I'd need one of those retracted before I can answer honestly.`,
|
|
@@ -9786,7 +9824,7 @@ async function autoProveFallback(memoryDir, cache, allRows, subjectWord, subjCan
|
|
|
9786
9824
|
}
|
|
9787
9825
|
}
|
|
9788
9826
|
|
|
9789
|
-
const renderProvedCite = (result) => result.premises.map((id) => byId.get(id)).filter(Boolean).map(
|
|
9827
|
+
const renderProvedCite = (result) => result.premises.map((id) => byId.get(id)).filter(Boolean).map(factLine).join("; ");
|
|
9790
9828
|
|
|
9791
9829
|
const positive = isIndividual
|
|
9792
9830
|
? proveEntailment(kb, subjectTerm, { t: "atom", name: classTerm }, proveOpts)
|
|
@@ -9810,7 +9848,8 @@ async function autoProveFallback(memoryDir, cache, allRows, subjectWord, subjCan
|
|
|
9810
9848
|
return { text: `no — ${cited}; ${conclusion}`, replace: true };
|
|
9811
9849
|
}
|
|
9812
9850
|
|
|
9813
|
-
async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle = {}, cache = null, focusLabel = null) {
|
|
9851
|
+
async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle = {}, cache = null, focusLabel = null, voice = DEFAULT_VOICE) {
|
|
9852
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
9814
9853
|
let normFactTerm; let normFactPredicate;
|
|
9815
9854
|
try { ({ normFactTerm, normFactPredicate } = await import("../adapters/memory/core.mjs")); } catch { return null; }
|
|
9816
9855
|
const q = String(query).trim();
|
|
@@ -9833,7 +9872,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
9833
9872
|
const hits = (await factRows(memoryDir, cache)).filter((f) => f.predicate === "mgx:usedFor" && variants.has(f.object));
|
|
9834
9873
|
if (hits.length) {
|
|
9835
9874
|
const ranked = rankByBiasThenTrust(uniqueFacts(hits), biasByBundle);
|
|
9836
|
-
const lines = ranked.map(
|
|
9875
|
+
const lines = ranked.map(factLine);
|
|
9837
9876
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
9838
9877
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
9839
9878
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -9854,7 +9893,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
9854
9893
|
const hits = (await factRows(memoryDir, cache)).filter((f) => f.predicate === predicate && variants.has(f.object));
|
|
9855
9894
|
if (!hits.length) continue; // try the next candidate marker, don't give up yet
|
|
9856
9895
|
const ranked = rankByBiasThenTrust(uniqueFacts(hits), biasByBundle);
|
|
9857
|
-
const lines = ranked.map(
|
|
9896
|
+
const lines = ranked.map(factLine);
|
|
9858
9897
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
9859
9898
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
9860
9899
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -9945,7 +9984,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
9945
9984
|
.filter((f) => locativePreposition(f.predicate) !== null && variants.has(f.subject));
|
|
9946
9985
|
if (hits.length) {
|
|
9947
9986
|
const ranked = rankByBiasThenTrust(uniqueFacts(hits), biasByBundle);
|
|
9948
|
-
const lines = ranked.map(
|
|
9987
|
+
const lines = ranked.map(factLine);
|
|
9949
9988
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
9950
9989
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
9951
9990
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -9970,7 +10009,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
9970
10009
|
);
|
|
9971
10010
|
if (hits.length) {
|
|
9972
10011
|
const ranked = rankByBiasThenTrust(uniqueFacts(hits), biasByBundle);
|
|
9973
|
-
const lines = ranked.map(
|
|
10012
|
+
const lines = ranked.map(factLine);
|
|
9974
10013
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
9975
10014
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
9976
10015
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -10004,7 +10043,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10004
10043
|
);
|
|
10005
10044
|
if (hits.length) {
|
|
10006
10045
|
const ranked = rankByBiasThenTrust(uniqueFacts(hits), biasByBundle);
|
|
10007
|
-
const lines = ranked.map(
|
|
10046
|
+
const lines = ranked.map(factLine);
|
|
10008
10047
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
10009
10048
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
10010
10049
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -10034,7 +10073,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10034
10073
|
);
|
|
10035
10074
|
if (hits.length) {
|
|
10036
10075
|
const ranked = rankByBiasThenTrust(uniqueFacts(hits), biasByBundle);
|
|
10037
|
-
const lines = ranked.map(
|
|
10076
|
+
const lines = ranked.map(factLine);
|
|
10038
10077
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
10039
10078
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
10040
10079
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -10186,7 +10225,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10186
10225
|
// Same corpus-weak-only demotion as the subject-side hits above.
|
|
10187
10226
|
if (objectHits.length && !objectHits.some(isRealGrounding)) objectHits = [];
|
|
10188
10227
|
if (objectHits.length) {
|
|
10189
|
-
const objLines = objectHits.map(
|
|
10228
|
+
const objLines = objectHits.map(factLine);
|
|
10190
10229
|
const objShown = objLines.slice(0, FACT_ANSWER_CAP);
|
|
10191
10230
|
const objRest = objLines.slice(FACT_ANSWER_CAP);
|
|
10192
10231
|
const objExtra = objRest.length ? `\n…and ${objRest.length} more — say 'more' to see them.` : "";
|
|
@@ -10205,7 +10244,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10205
10244
|
// bark". Every other hit keeps its ranked place behind it.
|
|
10206
10245
|
hits = definitionFirst(rankByBiasThenTrust(hits, biasByBundle));
|
|
10207
10246
|
const allRows = await factRows(memoryDir, cache);
|
|
10208
|
-
const { lines, grouped } = senseSplitFactList(hits, allRows, variants, { cache });
|
|
10247
|
+
const { lines, grouped } = senseSplitFactList(hits, allRows, variants, { cache, voice });
|
|
10209
10248
|
// A long undifferentiated "what is X" leads with the digest — a bounded
|
|
10210
10249
|
// narrative over the same facts — and holds the full list behind the escape.
|
|
10211
10250
|
// It wins over the sense-split grouping here: the digest's own selector
|
|
@@ -10261,12 +10300,12 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10261
10300
|
// block already follows.
|
|
10262
10301
|
const reversed = facts.find((f) => f.predicate === compPredicate && subj.has(f.object) && obj.has(f.subject));
|
|
10263
10302
|
const caveat = reversed
|
|
10264
|
-
? ` — though you also told me the opposite: ${
|
|
10303
|
+
? ` — though you also told me the opposite: ${factLine(reversed)}. Both are stored; I won't silently pick one.`
|
|
10265
10304
|
: "";
|
|
10266
|
-
return { text: `yes — ${
|
|
10305
|
+
return { text: `yes — ${factLine(hit)}${caveat}`, replace: true };
|
|
10267
10306
|
}
|
|
10268
10307
|
const known = facts.filter((f) => f.predicate === compPredicate && (subj.has(f.subject) || subj.has(f.object)));
|
|
10269
|
-
const shown = known.length ? ` I do know: ${known.slice(0, 3).map(
|
|
10308
|
+
const shown = known.length ? ` I do know: ${known.slice(0, 3).map(factLine).join("; ")}.` : "";
|
|
10270
10309
|
return {
|
|
10271
10310
|
text: `I can't confirm that — nothing I remember compares them that way.${shown} If it's true, teach me: "${subjTerm} is ${compAsk[2].toLowerCase()} than ${objTerm}".`,
|
|
10272
10311
|
replace: true,
|
|
@@ -10292,7 +10331,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10292
10331
|
const canBeRows = await factRows(memoryDir, cache);
|
|
10293
10332
|
const canBePremises = propertyPremises(canBeRows, canBeSubject, property, normFactTerm)
|
|
10294
10333
|
?? capabilityPremises(canBeRows, canBeSubject, new Set([`be ${property}`, property]), normFactTerm);
|
|
10295
|
-
if (canBePremises) return { text: `yes — ${canBePremises.map(
|
|
10334
|
+
if (canBePremises) return { text: `yes — ${canBePremises.map(factLine).join("; ")}`, replace: true };
|
|
10296
10335
|
}
|
|
10297
10336
|
|
|
10298
10337
|
// (b0) Derived forward yes/no readers — FORWARD_YESNO_MARKERS, one per
|
|
@@ -10311,7 +10350,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10311
10350
|
const subj = factTermVariants(normFactTerm, m[1]);
|
|
10312
10351
|
const obj = factTermVariants(normFactTerm, m[2]);
|
|
10313
10352
|
const hit = facts.find((f) => f.predicate === predicate && subj.has(f.subject) && obj.has(f.object));
|
|
10314
|
-
if (hit) return { text: `yes — ${
|
|
10353
|
+
if (hit) return { text: `yes — ${factLine(hit)}`, replace: true };
|
|
10315
10354
|
// A curated phrase can share its English verb with the general-verb
|
|
10316
10355
|
// teach mint ("eats" renders mgx:consumes, but teaching "X eats Y"
|
|
10317
10356
|
// stores mgx:eat): when the subject holds a fact under the verb's own
|
|
@@ -10327,7 +10366,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10327
10366
|
const teachHint = FORWARD_YESNO_TEACHABLE.has(predicate) ? ` If it's true, teach me: "${m[1]} ${phrase} ${m[2]}".` : "";
|
|
10328
10367
|
const sameRelation = facts.filter((f) => f.predicate === predicate && subj.has(f.subject));
|
|
10329
10368
|
if (sameRelation.length) {
|
|
10330
|
-
const shown = sameRelation.slice(0, 3).map(
|
|
10369
|
+
const shown = sameRelation.slice(0, 3).map(factLine).join("; ");
|
|
10331
10370
|
return {
|
|
10332
10371
|
text: `I can't confirm that — nothing I remember says ${m[1]} ${phrase} ${m[2]}. I do know: ${shown}.${teachHint}`,
|
|
10333
10372
|
replace: true,
|
|
@@ -10368,6 +10407,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10368
10407
|
const reply = isaPolarityReply(
|
|
10369
10408
|
isaRows.find((f) => ISA_PREDICATES.has(f.predicate) && onTerms(f)),
|
|
10370
10409
|
isaRows.find((f) => f.predicate === NEG_SUBCLASS_PREDICATE && onTerms(f)),
|
|
10410
|
+
voice,
|
|
10371
10411
|
);
|
|
10372
10412
|
return reply; // no remembered fact — null, so the honest miss stands (never a guessed "no")
|
|
10373
10413
|
}
|
|
@@ -10382,7 +10422,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10382
10422
|
if (can) {
|
|
10383
10423
|
const facts = await factRows(memoryDir, cache);
|
|
10384
10424
|
const canUniversal = can[1];
|
|
10385
|
-
let reply = capabilityReply(can[2], can[3], facts);
|
|
10425
|
+
let reply = capabilityReply(can[2], can[3], facts, { voice });
|
|
10386
10426
|
if (reply && surfacedCan !== collapsedSurface(q)) reply = withoutPolarityLead(reply);
|
|
10387
10427
|
// Quantified ("can all/every X ..."): the stored facts are generic, and a
|
|
10388
10428
|
// bare "yes" would claim universality the memory can't support — the same
|
|
@@ -10402,7 +10442,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10402
10442
|
const subj = factTermVariants(normFactTerm, can[2]);
|
|
10403
10443
|
const knownCan = facts.filter((f) => f.predicate === "mgx:capableOf" && subj.has(f.subject));
|
|
10404
10444
|
if (knownCan.length) {
|
|
10405
|
-
const shown = knownCan.slice(0, 3).map(
|
|
10445
|
+
const shown = knownCan.slice(0, 3).map(factLine).join("; ");
|
|
10406
10446
|
// The teach hint names the subject as the GRAPH stores it (singular),
|
|
10407
10447
|
// not as the user typed it — 'teach me: "a birds can swim"' is a
|
|
10408
10448
|
// garbled hint that can't round-trip.
|
|
@@ -10414,7 +10454,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10414
10454
|
}
|
|
10415
10455
|
// nothing about the subject at all — report the class base rate, and answer
|
|
10416
10456
|
// neither yes nor no
|
|
10417
|
-
return capabilityBaseRateReply(can[2], can[3], facts);
|
|
10457
|
+
return capabilityBaseRateReply(can[2], can[3], facts, { voice });
|
|
10418
10458
|
}
|
|
10419
10459
|
|
|
10420
10460
|
// (b2a-count) "how many legs does a dog have" — the count surface of the
|
|
@@ -10434,7 +10474,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10434
10474
|
.map((f) => ({ fact: f, quantified: HAS_PREDICATES.has(f.predicate) && countSubj.has(f.subject) ? quantifiedPossession(f.object) : null }))
|
|
10435
10475
|
.find(({ quantified }) => quantified && [...factTermVariants(normFactTerm, quantified.part)].some((v) => partVariants.has(v)));
|
|
10436
10476
|
if (quantifiedHit) {
|
|
10437
|
-
return { text: `${quantifiedHit.quantified.count} — ${
|
|
10477
|
+
return { text: `${quantifiedHit.quantified.count} — ${factLine(quantifiedHit.fact)}`, replace: true };
|
|
10438
10478
|
}
|
|
10439
10479
|
}
|
|
10440
10480
|
|
|
@@ -10455,7 +10495,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10455
10495
|
(f) => HAS_PREDICATES.has(f.predicate) && subjectSet.has(f.subject) && obj.has(f.object),
|
|
10456
10496
|
);
|
|
10457
10497
|
const hit = hasHit(subj);
|
|
10458
|
-
if (hit) return { text: `yes — ${
|
|
10498
|
+
if (hit) return { text: `yes — ${factLine(hit)}`, replace: true };
|
|
10459
10499
|
// The ⊑-lift walks a BOUNDED chain (not one hop): "every canine has fur"
|
|
10460
10500
|
// + "every dog is a canine" + "rex is a dog" answers "does rex have fur"
|
|
10461
10501
|
// citing all three premises. Cycle-safe, and the bound keeps a deep
|
|
@@ -10486,7 +10526,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10486
10526
|
const liftedTerms = factTermVariants(normFactTerm, step.object);
|
|
10487
10527
|
const lifted = hasHit(liftedTerms);
|
|
10488
10528
|
if (lifted) {
|
|
10489
|
-
return { text: `yes — ${[...nextChain.map(
|
|
10529
|
+
return { text: `yes — ${[...nextChain.map(factLine), factLine(lifted)].join("; ")}`, replace: true };
|
|
10490
10530
|
}
|
|
10491
10531
|
// A class-level "every argyle has a receptacle" is stored as a
|
|
10492
10532
|
// someValuesFrom restriction, not a flat possession triple, so the
|
|
@@ -10496,7 +10536,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10496
10536
|
// the restriction's own premises. `subjectWord` stays null here so
|
|
10497
10537
|
// the mid-walk "/classify" nudge never fires: the walk is still
|
|
10498
10538
|
// going, and the direct call below owns that miss.
|
|
10499
|
-
const liftedRestriction = await restrictionExistentialHit(memoryDir, cache, liftedTerms, obj, null, nextChain);
|
|
10539
|
+
const liftedRestriction = await restrictionExistentialHit(memoryDir, cache, liftedTerms, obj, null, nextChain, voice);
|
|
10500
10540
|
if (liftedRestriction) return liftedRestriction;
|
|
10501
10541
|
nextFrontier.push({ terms: liftedTerms, chain: nextChain });
|
|
10502
10542
|
}
|
|
@@ -10508,7 +10548,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10508
10548
|
// EL classification stores the SAME knowledge as a subClassOf-to-
|
|
10509
10549
|
// restriction chain rather than a flat possession triple, so try that
|
|
10510
10550
|
// shape before declining.
|
|
10511
|
-
return restrictionExistentialHit(memoryDir, cache, subj, obj, doesHave[1].trim());
|
|
10551
|
+
return restrictionExistentialHit(memoryDir, cache, subj, obj, doesHave[1].trim(), [], voice);
|
|
10512
10552
|
}
|
|
10513
10553
|
|
|
10514
10554
|
// (b2b-el) "does a heart contain a hinge" — DOES_HAVE_ASK_RE only ever
|
|
@@ -10520,7 +10560,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10520
10560
|
if (doesExistential) {
|
|
10521
10561
|
const subj = factTermVariants(normFactTerm, doesExistential[1]);
|
|
10522
10562
|
const obj = factTermVariants(normFactTerm, doesExistential[3]);
|
|
10523
|
-
const hit = await restrictionExistentialHit(memoryDir, cache, subj, obj, doesExistential[1].trim());
|
|
10563
|
+
const hit = await restrictionExistentialHit(memoryDir, cache, subj, obj, doesExistential[1].trim(), [], voice);
|
|
10524
10564
|
if (hit) return hit;
|
|
10525
10565
|
}
|
|
10526
10566
|
|
|
@@ -10540,7 +10580,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10540
10580
|
const obj = factTermVariants(normFactTerm, doAsk[3]);
|
|
10541
10581
|
// the SAME resolver (b2) answers through, so "do penguins fly" and "can a
|
|
10542
10582
|
// penguin fly" can never disagree in one session
|
|
10543
|
-
let reply = capabilityReply(doAsk[2], doAsk[3], facts);
|
|
10583
|
+
let reply = capabilityReply(doAsk[2], doAsk[3], facts, { voice });
|
|
10544
10584
|
if (reply && surfacedDo !== collapsedSurface(q)) reply = withoutPolarityLead(reply);
|
|
10545
10585
|
if (reply && universal) {
|
|
10546
10586
|
// Echo the quantifier as typed ("every dog", "all dogs") — "all dog"
|
|
@@ -10554,14 +10594,14 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10554
10594
|
if (miss) {
|
|
10555
10595
|
const knownCan = facts.filter((f) => f.predicate === "mgx:capableOf" && subj.has(f.subject));
|
|
10556
10596
|
if (knownCan.length) {
|
|
10557
|
-
const shown = knownCan.slice(0, 3).map(
|
|
10597
|
+
const shown = knownCan.slice(0, 3).map(factLine).join("; ");
|
|
10558
10598
|
return {
|
|
10559
10599
|
text: `I can't confirm that — nothing I remember says ${doAsk[2]} can ${doAsk[3]}. I do know: ${shown}. If it's true, teach me: "a ${knownCan[0].subject} can ${doAsk[3]}".`,
|
|
10560
10600
|
replace: true,
|
|
10561
10601
|
miss: true,
|
|
10562
10602
|
};
|
|
10563
10603
|
}
|
|
10564
|
-
const base = capabilityBaseRateReply(doAsk[2], doAsk[3], facts);
|
|
10604
|
+
const base = capabilityBaseRateReply(doAsk[2], doAsk[3], facts, { voice });
|
|
10565
10605
|
if (base) return base;
|
|
10566
10606
|
// A subject NO fact row mentions on either side has nothing to answer
|
|
10567
10607
|
// from at all — without this the turn fell through to the
|
|
@@ -10596,7 +10636,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10596
10636
|
.filter((f) => (f.predicate === "mgx:capableOf" || f.predicate === NEG_CAPABLE_OF_PREDICATE) && variants.has(f.subject));
|
|
10597
10637
|
if (!hits.length) return null;
|
|
10598
10638
|
const ranked = rankByBiasThenTrust(uniqueFacts(hits), biasByBundle);
|
|
10599
|
-
const lines = ranked.map(
|
|
10639
|
+
const lines = ranked.map(factLine);
|
|
10600
10640
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
10601
10641
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
10602
10642
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -10652,11 +10692,11 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10652
10692
|
const ranked = rankByBiasThenTrust(inKind.length ? inKind : capable, biasByBundle);
|
|
10653
10693
|
const lines = ranked.map((f) => {
|
|
10654
10694
|
const chain = inKind.length ? chainBySubject.get(f.subject) : null;
|
|
10655
|
-
if (!chain || chain.length < 2) return
|
|
10695
|
+
if (!chain || chain.length < 2) return factLine(f);
|
|
10656
10696
|
const steps = chain.map(rowForStep);
|
|
10657
|
-
if (!steps.every(Boolean)) return
|
|
10697
|
+
if (!steps.every(Boolean)) return factLine(f);
|
|
10658
10698
|
const cite = steps.map((g) => citedFactPhrase(g)).join("; ");
|
|
10659
|
-
return `${
|
|
10699
|
+
return `${factLine(f)} — via: ${cite}`;
|
|
10660
10700
|
});
|
|
10661
10701
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
10662
10702
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
@@ -10679,7 +10719,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10679
10719
|
);
|
|
10680
10720
|
if (negHits.length) {
|
|
10681
10721
|
const ranked = rankByBiasThenTrust(uniqueFacts(negHits), biasByBundle);
|
|
10682
|
-
const lines = ranked.map(
|
|
10722
|
+
const lines = ranked.map(factLine);
|
|
10683
10723
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
10684
10724
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
10685
10725
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -10701,7 +10741,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10701
10741
|
const hits = capabilityExtension(verbVariants, await factRows(memoryDir, cache));
|
|
10702
10742
|
if (hits.length) {
|
|
10703
10743
|
const ranked = rankByBiasThenTrust(uniqueFacts(hits), biasByBundle);
|
|
10704
|
-
const lines = ranked.map(
|
|
10744
|
+
const lines = ranked.map(factLine);
|
|
10705
10745
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
10706
10746
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
10707
10747
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -10721,7 +10761,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10721
10761
|
const hits = (await factRows(memoryDir, cache)).filter((f) => f.predicate === "mgx:hasA" && variants.has(f.object));
|
|
10722
10762
|
if (!hits.length) return null;
|
|
10723
10763
|
const ranked = rankByBiasThenTrust(uniqueFacts(hits), biasByBundle);
|
|
10724
|
-
const lines = ranked.map(
|
|
10764
|
+
const lines = ranked.map(factLine);
|
|
10725
10765
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
10726
10766
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
10727
10767
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -10770,7 +10810,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10770
10810
|
// the inherits relation, always "known" by construction.
|
|
10771
10811
|
if (!hits.length) return null;
|
|
10772
10812
|
const ranked = rankByBiasThenTrust(uniqueFacts(hits), biasByBundle);
|
|
10773
|
-
const lines = ranked.map(
|
|
10813
|
+
const lines = ranked.map(factLine);
|
|
10774
10814
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
10775
10815
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
10776
10816
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -10906,7 +10946,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10906
10946
|
// discipline, scoped to this subject's own signature-connected module so
|
|
10907
10947
|
// an unrelated part of the store never spends this turn's budget.
|
|
10908
10948
|
const reasoning = await resolveReasoningConfigForRepo(memoryDir);
|
|
10909
|
-
const widerClash = await findWiderConsistencyClash(rows, variants, reasoning);
|
|
10949
|
+
const widerClash = await findWiderConsistencyClash(rows, variants, reasoning, voice);
|
|
10910
10950
|
if (widerClash) return { text: widerClash, replace: true };
|
|
10911
10951
|
// echo the STORED spelling ("caches" asked → "cache" known), never a guess
|
|
10912
10952
|
const literalHit = hits.find((f) => variants.has(f.subject) || variants.has(f.object));
|
|
@@ -10923,7 +10963,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10923
10963
|
hits = rankByBiasThenTrust(hits, biasByBundle);
|
|
10924
10964
|
const header = `${hits.length} remembered fact${hits.length === 1 ? "" : "s"} about ${term}`
|
|
10925
10965
|
+ `${viaSubtype ? " (including its known subtypes)" : ""}:`;
|
|
10926
|
-
const { lines, grouped } = senseSplitFactList(hits, rows, variants, { indent: " ", cache });
|
|
10966
|
+
const { lines, grouped } = senseSplitFactList(hits, rows, variants, { indent: " ", cache, voice });
|
|
10927
10967
|
if (grouped) return { ...grouped, text: `${header}\n${grouped.text}`, ...(weakOnly ? { weakOnly: true } : {}) };
|
|
10928
10968
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
10929
10969
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
@@ -10988,7 +11028,8 @@ const WHAT_ELSE_BARE_RE = /^(?:(?:and|so|but|ok|okay|now|then)\s+)*(?:what\s+els
|
|
|
10988
11028
|
* That second check reuses this codebase's own established repeat-detection
|
|
10989
11029
|
* discipline (comparing rendered lines against `last.answer` bytes — see
|
|
10990
11030
|
* ORIENTATION_REPEAT_ONELINER/WALL_REPEAT_ONELINER for the same pattern). */
|
|
10991
|
-
async function whatElseAnswer(memoryDir, query, last) {
|
|
11031
|
+
async function whatElseAnswer(memoryDir, query, last, voice = DEFAULT_VOICE) {
|
|
11032
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
10992
11033
|
if (!memoryDir) return null;
|
|
10993
11034
|
const q = String(query).trim();
|
|
10994
11035
|
const m = q.match(WHAT_ELSE_IS_RE) || q.match(WHAT_ELSE_ABOUT_RE) || q.match(WHAT_ELSE_CAN_DO_RE);
|
|
@@ -11014,7 +11055,7 @@ async function whatElseAnswer(memoryDir, query, last) {
|
|
|
11014
11055
|
replace: true,
|
|
11015
11056
|
};
|
|
11016
11057
|
if (!hits.length) return nothingMore;
|
|
11017
|
-
const lines = hits.map(
|
|
11058
|
+
const lines = hits.map(factLine);
|
|
11018
11059
|
const prevAnswer = String(last?.answer || "");
|
|
11019
11060
|
if (lines.every((l) => prevAnswer.includes(l))) return nothingMore;
|
|
11020
11061
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
@@ -11041,7 +11082,8 @@ async function whatElseAnswer(memoryDir, query, last) {
|
|
|
11041
11082
|
* guard. ALWAYS renders a visible prefix naming the synonym term AND the
|
|
11042
11083
|
* corpus row that licensed the match — never a silent substitution. Returns
|
|
11043
11084
|
* { text } or null. Lazy + failure-tolerated throughout. */
|
|
11044
|
-
async function synonymFactAnswer(memoryDir, query, envelope) {
|
|
11085
|
+
async function synonymFactAnswer(memoryDir, query, envelope, voice = DEFAULT_VOICE) {
|
|
11086
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
11045
11087
|
if (!memoryDir) return null;
|
|
11046
11088
|
const term = metaTermOf(query, envelope);
|
|
11047
11089
|
if (!term) return null;
|
|
@@ -11052,7 +11094,7 @@ async function synonymFactAnswer(memoryDir, query, envelope) {
|
|
|
11052
11094
|
const variants = factTermVariants(normFactTerm, variant);
|
|
11053
11095
|
const hits = facts.filter((f) => variants.has(f.subject)).sort(compareFactsByContent);
|
|
11054
11096
|
if (!hits.length) continue;
|
|
11055
|
-
const lines = hits.map(
|
|
11097
|
+
const lines = hits.map(factLine);
|
|
11056
11098
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
11057
11099
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
11058
11100
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -11291,14 +11333,15 @@ function inheritsChain(graph, startId) {
|
|
|
11291
11333
|
* subject-side answer or a schema hit. Returns { text, replace:true } or null,
|
|
11292
11334
|
* plus factAnswer's same additive `goal` field when one is deducible
|
|
11293
11335
|
* (withDeducedGoal). */
|
|
11294
|
-
export async function factReadBack(memoryDir, query, envelope, miss, graph = null, focusLabel = null, biasByBundle = {}, cache = null) {
|
|
11336
|
+
export async function factReadBack(memoryDir, query, envelope, miss, graph = null, focusLabel = null, biasByBundle = {}, cache = null, voice = DEFAULT_VOICE) {
|
|
11295
11337
|
return withEnumerationLane(
|
|
11296
|
-
withDeducedGoal(await factReadBackReaders(memoryDir, query, envelope, miss, graph, focusLabel, biasByBundle, cache), envelope, query),
|
|
11338
|
+
withDeducedGoal(await factReadBackReaders(memoryDir, query, envelope, miss, graph, focusLabel, biasByBundle, cache, voice), envelope, query),
|
|
11297
11339
|
ENUMERATION_LANES.FACT_READBACK,
|
|
11298
11340
|
);
|
|
11299
11341
|
}
|
|
11300
11342
|
|
|
11301
|
-
async function factReadBackReaders(memoryDir, query, envelope, miss, graph = null, focusLabel = null, biasByBundle = {}, cache = null) {
|
|
11343
|
+
async function factReadBackReaders(memoryDir, query, envelope, miss, graph = null, focusLabel = null, biasByBundle = {}, cache = null, voice = DEFAULT_VOICE) {
|
|
11344
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
11302
11345
|
if (!miss) return null;
|
|
11303
11346
|
let normFactTerm;
|
|
11304
11347
|
try { ({ normFactTerm } = await import("../adapters/memory/core.mjs")); } catch { return null; }
|
|
@@ -11427,7 +11470,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
11427
11470
|
const isa = rows.filter((f) => ISA_PREDICATES.has(f.predicate));
|
|
11428
11471
|
const byTrust = (a, b) => (b.trust - a.trust) || compareFactsByContent(a, b);
|
|
11429
11472
|
const renderMany = (hits) => {
|
|
11430
|
-
const lines = hits.map(
|
|
11473
|
+
const lines = hits.map(factLine);
|
|
11431
11474
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
11432
11475
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
11433
11476
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -11534,7 +11577,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
11534
11577
|
const { loadMemory, findRuleByName, resolveRelationChase } = await import("../adapters/memory/core.mjs");
|
|
11535
11578
|
const { findActionPath } = await import("../domain/planning.mjs");
|
|
11536
11579
|
const memory = await loadMemory(memoryDir);
|
|
11537
|
-
const relationChaseHelpers = { relationFactsFor, renderFactLine, factPhrase, factTermVariants, byTrust, rows, HAS_PROPERTY_PREDICATE, findActionPath };
|
|
11580
|
+
const relationChaseHelpers = { relationFactsFor, renderFactLine: factLine, factPhrase, factTermVariants, byTrust, rows, HAS_PROPERTY_PREDICATE, findActionPath };
|
|
11538
11581
|
const hit = await resolveRelationChase(memory, relationName, subject, object, relationChaseHelpers);
|
|
11539
11582
|
if (hit) return { text: `yes — ${hit.citation.join("; ")}`, replace: true };
|
|
11540
11583
|
// A bare `return null` on any miss here would be wrong — the
|
|
@@ -11619,7 +11662,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
11619
11662
|
// `factTermVariants`/`byTrust`/`rows`/`HAS_PROPERTY_PREDICATE` are this
|
|
11620
11663
|
// block's own local closures/constants, threaded through explicitly.
|
|
11621
11664
|
const { findReachableSet } = await import("../domain/planning.mjs");
|
|
11622
|
-
const relationChaseHelpersWho = { relationFactsFor: relationFactsForWho, renderFactLine, factPhrase, factTermVariants, byTrust, rows, HAS_PROPERTY_PREDICATE, findReachableSet };
|
|
11665
|
+
const relationChaseHelpersWho = { relationFactsFor: relationFactsForWho, renderFactLine: factLine, factPhrase, factTermVariants, byTrust, rows, HAS_PROPERTY_PREDICATE, findReachableSet };
|
|
11623
11666
|
const hits = await resolveRelationChaseReverse(memoryWho, relationName, object, relationChaseHelpersWho);
|
|
11624
11667
|
if (hits.length) {
|
|
11625
11668
|
const lines = hits.map((h) => `${h.subject} — ${h.citation.join("; ")}`);
|
|
@@ -11658,7 +11701,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
11658
11701
|
const nameVariants = factTermVariants(normFactTerm, whoBare[1]);
|
|
11659
11702
|
const hits = rankByBiasThenTrust(rows.filter((f) => nameVariants.has(f.subject) || nameVariants.has(f.object)), biasByBundle);
|
|
11660
11703
|
if (hits.length) {
|
|
11661
|
-
const lines = hits.map(
|
|
11704
|
+
const lines = hits.map(factLine);
|
|
11662
11705
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
11663
11706
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
11664
11707
|
const extra = rest.length ? `\n…and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -11739,7 +11782,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
11739
11782
|
const seenAlias = new Set();
|
|
11740
11783
|
const parts = [];
|
|
11741
11784
|
for (const e of path.actions) {
|
|
11742
|
-
parts.push(
|
|
11785
|
+
parts.push(factLine(e.fact));
|
|
11743
11786
|
for (const af of e.aliasFacts) {
|
|
11744
11787
|
const key = af.id || `${af.subject}|${af.predicate}|${af.object}`;
|
|
11745
11788
|
if (seenAlias.has(key)) continue;
|
|
@@ -11860,7 +11903,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
11860
11903
|
const chainRefusal = disjointRefusalFor(hit.subject);
|
|
11861
11904
|
if (chainRefusal) return chainRefusal;
|
|
11862
11905
|
}
|
|
11863
|
-
const polarityReply = isaPolarityReply(hit, negHit || directDisjoint);
|
|
11906
|
+
const polarityReply = isaPolarityReply(hit, negHit || directDisjoint, voice);
|
|
11864
11907
|
if (polarityReply) return polarityReply;
|
|
11865
11908
|
// DISJOINTNESS ACROSS BOTH CHAINS: nothing above found a stored fact of
|
|
11866
11909
|
// either polarity, but "no" can still be PROVEN when the subject's own
|
|
@@ -11925,7 +11968,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
11925
11968
|
: null;
|
|
11926
11969
|
if (posFact && disjointFact && (!objectNeedsLift || objFact)) {
|
|
11927
11970
|
const kindEcho = stripTrailingDiscourseTag(isaAsk[2]).trim();
|
|
11928
|
-
const chain = [posFact, ...(objFact ? [objFact] : [])].map(
|
|
11971
|
+
const chain = [posFact, ...(objFact ? [objFact] : [])].map(factLine).join("; ");
|
|
11929
11972
|
return {
|
|
11930
11973
|
text: `no — ${chain}; and ${citedFactPhrase(disjointFact)} `
|
|
11931
11974
|
+ `— so ${isaSubject} can never be ${indefiniteArticleFor(kindEcho)} ${kindEcho}.`,
|
|
@@ -11952,7 +11995,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
11952
11995
|
.sort(byTrust)[0];
|
|
11953
11996
|
if (bridged) {
|
|
11954
11997
|
return {
|
|
11955
|
-
text: `yes — the code graph says ${ent.label} inherits ${bridgeSubjects.get(bridged.subject)}, and ${
|
|
11998
|
+
text: `yes — the code graph says ${ent.label} inherits ${bridgeSubjects.get(bridged.subject)}, and ${factLine(bridged)}`,
|
|
11956
11999
|
replace: true,
|
|
11957
12000
|
};
|
|
11958
12001
|
}
|
|
@@ -12050,10 +12093,10 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12050
12093
|
const posHit = isa
|
|
12051
12094
|
.filter((f) => negSubjVariants.has(f.subject) && negObjVariants.has(f.object))
|
|
12052
12095
|
.sort(byTrust)[0];
|
|
12053
|
-
if (posHit) return { text: `no — ${
|
|
12096
|
+
if (posHit) return { text: `no — ${factLine(posHit)}`, replace: true };
|
|
12054
12097
|
const negDisjoint = disjointRows.find((f) => (negSubjVariants.has(f.subject) && negObjVariants.has(f.object))
|
|
12055
12098
|
|| (negSubjVariants.has(f.object) && negObjVariants.has(f.subject)));
|
|
12056
|
-
if (negDisjoint) return { text: `yes — ${
|
|
12099
|
+
if (negDisjoint) return { text: `yes — ${factLine(negDisjoint)}`, replace: true };
|
|
12057
12100
|
const negSubjectWord = negSubject[1].trim();
|
|
12058
12101
|
const negKindWord = stripTrailingDiscourseTag(isaAsk[2]).trim();
|
|
12059
12102
|
return {
|
|
@@ -12075,7 +12118,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12075
12118
|
const typeFact = chainTypeRows.concat(chainSubClassRows).find((f) => f.subject === v.subject && f.object === v.viaType);
|
|
12076
12119
|
const disjointFact = disjointRows.find((f) => (f.subject === v.viaClass && f.object === v.object)
|
|
12077
12120
|
|| (f.subject === v.object && f.object === v.viaClass));
|
|
12078
|
-
const parts = [typeFact, disjointFact].filter(Boolean).map(
|
|
12121
|
+
const parts = [typeFact, disjointFact].filter(Boolean).map(factLine);
|
|
12079
12122
|
return { text: `no — ${parts.length ? parts.join("; ") : `${v.viaClass} and ${v.object} are disjoint.`}`, replace: true };
|
|
12080
12123
|
}
|
|
12081
12124
|
}
|
|
@@ -12115,7 +12158,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12115
12158
|
if (!hit) continue;
|
|
12116
12159
|
const propFact = propertyRows.find((f) => f.subject === hit.subject && f.predicate === hit.viaProperty && f.object === hit.viaValue);
|
|
12117
12160
|
const typeFact = chainTypeRows.find((f) => f.subject === hit.viaValue && f.object === hit.viaType);
|
|
12118
|
-
const parts = [propFact, typeFact].filter(Boolean).map(
|
|
12161
|
+
const parts = [propFact, typeFact].filter(Boolean).map(factLine);
|
|
12119
12162
|
return {
|
|
12120
12163
|
text: `yes — ${parts.length ? parts.join("; ") : `${hit.subject} ${hit.viaProperty} ${hit.viaValue}, and ${hit.viaValue} is a ${hit.viaType}.`}`,
|
|
12121
12164
|
replace: true,
|
|
@@ -12240,11 +12283,11 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12240
12283
|
// budget merges onto whichever of the three recovery texts below still
|
|
12241
12284
|
// renders, so the miss itself stays byte-identical and only gains the
|
|
12242
12285
|
// marker infbench reads apart from a parse miss.
|
|
12243
|
-
const autoProve = await autoProveFallback(memoryDir, cache, rows, subjectWord, subjCandidates, objVariants, kindWord);
|
|
12286
|
+
const autoProve = await autoProveFallback(memoryDir, cache, rows, subjectWord, subjCandidates, objVariants, kindWord, voice);
|
|
12244
12287
|
if (autoProve?.text) return autoProve;
|
|
12245
12288
|
const askProveBudgetExhausted = !!autoProve?.budgetExhausted;
|
|
12246
12289
|
if (knownSubjectIsa.length) {
|
|
12247
|
-
const shown = knownSubjectIsa.slice(0, 3).map(
|
|
12290
|
+
const shown = knownSubjectIsa.slice(0, 3).map(factLine).join("; ");
|
|
12248
12291
|
// A someValuesFrom restriction node among the subject's own remembered
|
|
12249
12292
|
// isa facts means the gap is a class expression /syllogise's plain
|
|
12250
12293
|
// scm-sco chase never reaches — /classify is the offer that can
|
|
@@ -12284,7 +12327,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12284
12327
|
.sort(byTrust)[0];
|
|
12285
12328
|
if (converseHit) {
|
|
12286
12329
|
return {
|
|
12287
|
-
text: `I can't confirm that — what I know runs the other way: ${
|
|
12330
|
+
text: `I can't confirm that — what I know runs the other way: ${factLine(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}".`,
|
|
12288
12331
|
replace: true,
|
|
12289
12332
|
miss: true,
|
|
12290
12333
|
...(askProveBudgetExhausted ? { budgetExhausted: true } : {}),
|
|
@@ -12428,7 +12471,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12428
12471
|
const hit = rows
|
|
12429
12472
|
.filter((f) => f.predicate === OWNED_BY_PREDICATE && thingVariants.has(f.subject) && ownerVariants.has(f.object))
|
|
12430
12473
|
.sort(byTrust)[0];
|
|
12431
|
-
if (hit) return { text: `yes — ${
|
|
12474
|
+
if (hit) return { text: `yes — ${factLine(hit)}`, replace: true };
|
|
12432
12475
|
return {
|
|
12433
12476
|
text: `no — no remembered fact says ${ownerRaw.trim().toLowerCase()} owns/maintains ${thingRaw.trim()}.`,
|
|
12434
12477
|
replace: true,
|
|
@@ -12452,7 +12495,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12452
12495
|
const hit = rows
|
|
12453
12496
|
.filter((f) => f.predicate === OWNED_BY_PREDICATE && thingVariants.has(f.subject) && ownerVariants.has(f.object))
|
|
12454
12497
|
.sort(byTrust)[0];
|
|
12455
|
-
if (hit) return { text: `yes — ${
|
|
12498
|
+
if (hit) return { text: `yes — ${factLine(hit)}`, replace: true };
|
|
12456
12499
|
return {
|
|
12457
12500
|
text: `no — no remembered fact says ${thingRaw.trim().toLowerCase()} is owned by ${ownerRaw.trim()}.`,
|
|
12458
12501
|
replace: true,
|
|
@@ -12474,7 +12517,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12474
12517
|
const hit = rows
|
|
12475
12518
|
.filter((f) => f.predicate === HAS_A_PREDICATE && subjVariants.has(f.subject) && objVariants.has(f.object))
|
|
12476
12519
|
.sort(byTrust)[0];
|
|
12477
|
-
if (hit) return { text: `yes — ${
|
|
12520
|
+
if (hit) return { text: `yes — ${factLine(hit)}`, replace: true };
|
|
12478
12521
|
return null; // no remembered fact — honest decline, never a guessed "no"
|
|
12479
12522
|
}
|
|
12480
12523
|
|
|
@@ -12562,8 +12605,8 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12562
12605
|
// discipline isaAsk's own class↔instance bridge follows just above.
|
|
12563
12606
|
return {
|
|
12564
12607
|
text: viaSuper
|
|
12565
|
-
? `yes — the code graph says ${bridgeEnt.label} inherits ${viaSuper}, and ${
|
|
12566
|
-
: `yes — ${
|
|
12608
|
+
? `yes — the code graph says ${bridgeEnt.label} inherits ${viaSuper}, and ${factLine(hit)}`
|
|
12609
|
+
: `yes — ${factLine(hit)}`,
|
|
12567
12610
|
replace: true,
|
|
12568
12611
|
};
|
|
12569
12612
|
}
|
|
@@ -12574,7 +12617,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12574
12617
|
// the store doesn't already hold. A two-step taxonomy stays a miss here.
|
|
12575
12618
|
const inheritedProperty = propertyPremises(rows, subjVariants, adjective, normFactTerm);
|
|
12576
12619
|
if (inheritedProperty) {
|
|
12577
|
-
return { text: `yes — ${inheritedProperty.map(
|
|
12620
|
+
return { text: `yes — ${inheritedProperty.map(factLine).join("; ")}`, replace: true };
|
|
12578
12621
|
}
|
|
12579
12622
|
// No property hit — but a bare "is X Y" (no article) is exactly the
|
|
12580
12623
|
// same claim as "is X a Y" would have been had the user included the
|
|
@@ -12700,7 +12743,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12700
12743
|
.sort(byTrust)[0];
|
|
12701
12744
|
if (hit) {
|
|
12702
12745
|
const verdict = isNegatedPredicate(hit.predicate) ? "no" : "yes";
|
|
12703
|
-
return { text: `${verdict} — ${
|
|
12746
|
+
return { text: `${verdict} — ${factLine(hit)}`, replace: true, generalVerbQuery: true };
|
|
12704
12747
|
}
|
|
12705
12748
|
// A KNOWN subject under the SAME relation, no row matching this
|
|
12706
12749
|
// object: an honest, specific miss citing what the subject IS
|
|
@@ -12709,7 +12752,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12709
12752
|
// what it does know, and `miss: true` keeps it out of recall.
|
|
12710
12753
|
const sameRelation = rows.filter((f) => polar.includes(f.predicate) && subjVariants.has(f.subject));
|
|
12711
12754
|
if (sameRelation.length) {
|
|
12712
|
-
const shown = sameRelation.slice(0, 3).map(
|
|
12755
|
+
const shown = sameRelation.slice(0, 3).map(factLine).join("; ");
|
|
12713
12756
|
return {
|
|
12714
12757
|
text: `I can't confirm that — nothing I remember says ${factPhrase({ subject, predicate, object })}. I do know: ${shown}.`,
|
|
12715
12758
|
replace: true,
|
|
@@ -12770,7 +12813,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12770
12813
|
const hits = rankByBiasThenTrust(rows.filter((f) => variants.has(f.subject) || variants.has(f.object)), biasByBundle);
|
|
12771
12814
|
if (!hits.length) return null;
|
|
12772
12815
|
const term = variants.has(hits[0].subject) ? hits[0].subject : hits[0].object;
|
|
12773
|
-
const lines = hits.map((f) => ` ${
|
|
12816
|
+
const lines = hits.map((f) => ` ${factLine(f)}`);
|
|
12774
12817
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
12775
12818
|
const rest = lines.slice(FACT_ANSWER_CAP);
|
|
12776
12819
|
const extra = rest.length ? `\n …and ${rest.length} more — say 'more' to see them.` : "";
|
|
@@ -12825,7 +12868,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12825
12868
|
const bridgeFor = (hit) => isa.find((g) => g.subject === hit.object && qualifierVariants.has(g.object));
|
|
12826
12869
|
const confirmed = hits.map((hit) => ({ hit, bridge: bridgeFor(hit) })).find(({ bridge }) => bridge);
|
|
12827
12870
|
if (confirmed) {
|
|
12828
|
-
return { text: `${
|
|
12871
|
+
return { text: `${factLine(confirmed.hit)} — ${factLine(confirmed.bridge)}`, replace: true };
|
|
12829
12872
|
}
|
|
12830
12873
|
}
|
|
12831
12874
|
return renderMany(hits);
|
|
@@ -12843,7 +12886,8 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
12843
12886
|
* only (a `/describe` names ONE code entity as the subject of its own facts,
|
|
12844
12887
|
* not every fact that merely mentions it in passing) — null when memory holds
|
|
12845
12888
|
* nothing about this subject. */
|
|
12846
|
-
async function describedFacts(memoryDir, label, biasByBundle = {}, cache = null) {
|
|
12889
|
+
async function describedFacts(memoryDir, label, biasByBundle = {}, cache = null, voice = DEFAULT_VOICE) {
|
|
12890
|
+
const factLine = (f) => renderFactLine(f, voice);
|
|
12847
12891
|
let normFactTerm;
|
|
12848
12892
|
try { ({ normFactTerm } = await import("../adapters/memory/core.mjs")); } catch { return null; }
|
|
12849
12893
|
const rows = await factRows(memoryDir, cache);
|
|
@@ -12851,7 +12895,7 @@ async function describedFacts(memoryDir, label, biasByBundle = {}, cache = null)
|
|
|
12851
12895
|
const variants = factTermVariants(normFactTerm, label);
|
|
12852
12896
|
const hits = rankByBiasThenTrust(rows.filter((f) => variants.has(f.subject)), biasByBundle);
|
|
12853
12897
|
if (!hits.length) return null;
|
|
12854
|
-
return `taught facts:\n${hits.map((f) => ` ${
|
|
12898
|
+
return `taught facts:\n${hits.map((f) => ` ${factLine(f)}`).join("\n")}`;
|
|
12855
12899
|
}
|
|
12856
12900
|
|
|
12857
12901
|
// ---- W5: corpus on-demand — LOCAL tier only, behind an explicit flag ----
|
|
@@ -13305,15 +13349,15 @@ function unknownVocabTermOffer(term) {
|
|
|
13305
13349
|
* stands. The envelope is deliberately NOT passed on: it was parsed from the
|
|
13306
13350
|
* question about the full phrase, and metaTermOf would read the phrase back
|
|
13307
13351
|
* out of it and re-ask the question that just missed. */
|
|
13308
|
-
async function adjectiveQualifiedHeadAnswer(term, { memoryDir, biasByBundle = {}, cache = null, graph = null, lexicon = null }) {
|
|
13352
|
+
async function adjectiveQualifiedHeadAnswer(term, { memoryDir, biasByBundle = {}, cache = null, graph = null, lexicon = null, voice = DEFAULT_VOICE }) {
|
|
13309
13353
|
const words = String(term ?? "").trim().toLowerCase().split(/\s+/);
|
|
13310
13354
|
if (words.length !== 2) return null;
|
|
13311
13355
|
const [modifier, head] = words;
|
|
13312
13356
|
const lex = lexicon || loadLexicon();
|
|
13313
13357
|
if (!lookupAdjective(lex, modifier) || !lookupNoun(lex, head)) return null;
|
|
13314
13358
|
const headQuery = `what is ${indefiniteArticleFor(head)} ${head}`;
|
|
13315
|
-
const hit = (await factAnswer(memoryDir, headQuery, null, true, biasByBundle, cache))
|
|
13316
|
-
?? (await factReadBack(memoryDir, headQuery, null, true, graph, null, biasByBundle, cache));
|
|
13359
|
+
const hit = (await factAnswer(memoryDir, headQuery, null, true, biasByBundle, cache, null, voice))
|
|
13360
|
+
?? (await factReadBack(memoryDir, headQuery, null, true, graph, null, biasByBundle, cache, voice));
|
|
13317
13361
|
if (!hit || hit.miss || !hit.text) return null;
|
|
13318
13362
|
return `I have nothing under "${term}". Here's what I know about ${indefiniteArticleFor(head)} ${head}:\n${hit.text}`;
|
|
13319
13363
|
}
|
|
@@ -15295,7 +15339,7 @@ const ARCH_OVERVIEW_PHRASES = [
|
|
|
15295
15339
|
new RegExp(`^${ARCH_OVERVIEW_LEAD}(?:(?:an?|the)\\s+)?(?:overview|map|diagram)\\s+${ARCH_OVERVIEW_OF_REPO}(?:\\s+here)?\\??$`, "i"),
|
|
15296
15340
|
];
|
|
15297
15341
|
|
|
15298
|
-
async function runAsk(query, { config, source, graph, focus, last, templates, memoryDir, sessionId = "", lexicon = null, env, trace, vocabHint: sessionVocabHint = null, tel = null, biasByBundle = {}, cache = null, vocabAntecedent = null, planHolder = null, discourseHolder = null, gameConfig = DEFAULT_GAME_CONFIG, liveReference = false, onLiveLookup = null, sourceSkips = null, uiContext = "cli", synthesisBudget = AUTO_SYNTHESIS_BUDGET, codeDomainActive = false, codeGraphMode = false, ingested = false }) {
|
|
15342
|
+
async function runAsk(query, { config, source, graph, focus, last, templates, memoryDir, sessionId = "", lexicon = null, env, trace, vocabHint: sessionVocabHint = null, tel = null, biasByBundle = {}, cache = null, vocabAntecedent = null, planHolder = null, discourseHolder = null, gameConfig = DEFAULT_GAME_CONFIG, liveReference = false, onLiveLookup = null, sourceSkips = null, uiContext = "cli", synthesisBudget = AUTO_SYNTHESIS_BUDGET, codeDomainActive = false, codeGraphMode = false, ingested = false, voice = DEFAULT_VOICE }) {
|
|
15299
15343
|
// The session-wide hint names a term this session can PROVE resolves; when
|
|
15300
15344
|
// the question itself named a subject the lexicon knows, the hint names that
|
|
15301
15345
|
// instead, so a miss on "how many eyes does a human have" points at "human"
|
|
@@ -15854,12 +15898,14 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
15854
15898
|
// question-shape lookup (a plan frame is a request/instruct, a stored
|
|
15855
15899
|
// teach is an inform, whatever the surface punctuation looked like).
|
|
15856
15900
|
let dialogueLaneOverride = null;
|
|
15901
|
+
// Whether the teach lane below changed memory on the user's word.
|
|
15902
|
+
let taughtThisTurn = false;
|
|
15857
15903
|
// (0) "what else is X" — recognized off the RAW query text, before every
|
|
15858
15904
|
// other lane below (all of which read `envelope`, already relaxed/reparsed
|
|
15859
15905
|
// by ask()'s noise-strip cascade, which silently drops "else"). via is set
|
|
15860
15906
|
// to a value NONE of the downstream via gates match, so a hit here is final.
|
|
15861
15907
|
if (memoryDir) {
|
|
15862
|
-
const whatElse = await whatElseAnswer(memoryDir, query, last);
|
|
15908
|
+
const whatElse = await whatElseAnswer(memoryDir, query, last, voice);
|
|
15863
15909
|
if (whatElse) {
|
|
15864
15910
|
// A cold "what else" carries miss:true — it resolved no subject, so the
|
|
15865
15911
|
// turn is a miss in better words, exactly like the isa ladder's closers.
|
|
@@ -15899,7 +15945,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
15899
15945
|
// codebase", "how do i start") → a summary / orientation, answered before the
|
|
15900
15946
|
// fact-dump readers so "what do you know" gets a summary, not raw facts.
|
|
15901
15947
|
if (!handled && miss) {
|
|
15902
|
-
const meta = await metaLane(query, { graph, memoryDir, last, templates, vocabHint, focus, uiContext, codeDomainActive });
|
|
15948
|
+
const meta = await metaLane(query, { graph, memoryDir, last, templates, vocabHint, focus, uiContext, codeDomainActive, voice });
|
|
15903
15949
|
if (meta) {
|
|
15904
15950
|
// A lane may answer with a better-worded decline (the module-orient
|
|
15905
15951
|
// residue guard) — still a miss in the turn record, like the isa
|
|
@@ -16158,8 +16204,8 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16158
16204
|
const factQuery = bareNounShape && !bareWhatisShape
|
|
16159
16205
|
? `what is ${indefiniteArticleFor(bareNoun)} ${bareNoun}`
|
|
16160
16206
|
: gateQuery;
|
|
16161
|
-
bareMetaHit = (await factAnswer(memoryDir, factQuery, envelope, miss, biasByBundle, cache, newFocus?.label))
|
|
16162
|
-
?? (await factReadBack(memoryDir, factQuery, envelope, miss, graph, newFocus?.label, biasByBundle, cache));
|
|
16207
|
+
bareMetaHit = (await factAnswer(memoryDir, factQuery, envelope, miss, biasByBundle, cache, newFocus?.label, voice))
|
|
16208
|
+
?? (await factReadBack(memoryDir, factQuery, envelope, miss, graph, newFocus?.label, biasByBundle, cache, voice));
|
|
16163
16209
|
if (bareNounShape && !bareWhatisShape && bareMetaHit?.miss) bareMetaHit = null;
|
|
16164
16210
|
// An honest-miss return never diverts the gate — EXCEPT the capability
|
|
16165
16211
|
// family's can't-confirm, which names the subject's real capabilities
|
|
@@ -16183,8 +16229,8 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16183
16229
|
const key = refTerm ? await cleanMissPackKey(refTerm, { graph, memoryDir, lexicon, cache }) : null;
|
|
16184
16230
|
const learned = key ? await childPackFactsForKey(key, { memoryDir, env, cache, synthesisBudget }) : null;
|
|
16185
16231
|
if (learned) {
|
|
16186
|
-
const fact = (await factAnswer(memoryDir, factQuery, envelope, miss, biasByBundle, cache, newFocus?.label))
|
|
16187
|
-
?? (await factReadBack(memoryDir, factQuery, envelope, miss, graph, newFocus?.label, biasByBundle, cache));
|
|
16232
|
+
const fact = (await factAnswer(memoryDir, factQuery, envelope, miss, biasByBundle, cache, newFocus?.label, voice))
|
|
16233
|
+
?? (await factReadBack(memoryDir, factQuery, envelope, miss, graph, newFocus?.label, biasByBundle, cache, voice));
|
|
16188
16234
|
if (fact && !fact.miss) bareMetaHit = { text: fact.text, replace: true, child: learned };
|
|
16189
16235
|
}
|
|
16190
16236
|
if (!bareMetaHit && key) {
|
|
@@ -16349,7 +16395,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16349
16395
|
// AST shape. A pronoun-shortened follow-up ("who touched it") is exactly
|
|
16350
16396
|
// 3 words, so without this guard isConversational would discard a correct,
|
|
16351
16397
|
// already-composed answer for the generic orientation wall.
|
|
16352
|
-
const orientation = orientationAnswer(templates, graph, vocabHint, uiContext, codeDomainActive);
|
|
16398
|
+
const orientation = orientationAnswer(templates, graph, vocabHint, uiContext, codeDomainActive, voice);
|
|
16353
16399
|
const repeat = last?.answer === orientation;
|
|
16354
16400
|
answer = repeat ? ORIENTATION_REPEAT_ONELINER : orientation;
|
|
16355
16401
|
via = "template"; handled = true;
|
|
@@ -16383,11 +16429,11 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16383
16429
|
// The retry can only run when the raw read already returned nothing, so
|
|
16384
16430
|
// it turns a wall into an answer and never overrides one.
|
|
16385
16431
|
const peeledForFacts = applyPreambleFrames(String(query));
|
|
16386
|
-
const fact = (await factAnswer(memoryDir, query, envelope, miss, biasByBundle, cache, newFocus?.label))
|
|
16387
|
-
?? (await factReadBack(memoryDir, query, envelope, miss, graph, newFocus?.label, biasByBundle, cache))
|
|
16432
|
+
const fact = (await factAnswer(memoryDir, query, envelope, miss, biasByBundle, cache, newFocus?.label, voice))
|
|
16433
|
+
?? (await factReadBack(memoryDir, query, envelope, miss, graph, newFocus?.label, biasByBundle, cache, voice))
|
|
16388
16434
|
?? (peeledForFacts && peeledForFacts !== String(query).trim()
|
|
16389
|
-
? (await factAnswer(memoryDir, peeledForFacts, envelope, miss, biasByBundle, cache, newFocus?.label))
|
|
16390
|
-
?? (await factReadBack(memoryDir, peeledForFacts, envelope, miss, graph, newFocus?.label, biasByBundle, cache))
|
|
16435
|
+
? (await factAnswer(memoryDir, peeledForFacts, envelope, miss, biasByBundle, cache, newFocus?.label, voice))
|
|
16436
|
+
?? (await factReadBack(memoryDir, peeledForFacts, envelope, miss, graph, newFocus?.label, biasByBundle, cache, voice))
|
|
16391
16437
|
: null);
|
|
16392
16438
|
if (fact) {
|
|
16393
16439
|
answer = fact.replace ? fact.text : `${answer}\n${fact.text}`;
|
|
@@ -16533,7 +16579,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16533
16579
|
// declined, so it can never hijack a real schema/concept-force answer.
|
|
16534
16580
|
// Every hit cites its synonym term + licensing corpus source.
|
|
16535
16581
|
if (miss && recordMiss && via === "composed") {
|
|
16536
|
-
const syn = await synonymFactAnswer(memoryDir, query, envelope);
|
|
16582
|
+
const syn = await synonymFactAnswer(memoryDir, query, envelope, voice);
|
|
16537
16583
|
if (syn) {
|
|
16538
16584
|
answer = syn.text; via = "fact"; recordMiss = false;
|
|
16539
16585
|
if (syn.pending) factPending = syn.pending;
|
|
@@ -16556,7 +16602,8 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16556
16602
|
taught = persistUnavailableAnswer();
|
|
16557
16603
|
}
|
|
16558
16604
|
if (taught) {
|
|
16559
|
-
answer = taught
|
|
16605
|
+
answer = voicedText(taught, voice); via = taught.via; recordMiss = taught.miss;
|
|
16606
|
+
taughtThisTurn = Boolean(taught.taught);
|
|
16560
16607
|
if (!taught.miss) dialogueLaneOverride = "teach";
|
|
16561
16608
|
const teachOutcome = taught.via === PERSIST_UNAVAILABLE_VIA ? "but the store would not take the write"
|
|
16562
16609
|
: taught.miss ? "but the payload could not be stored"
|
|
@@ -16594,7 +16641,9 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16594
16641
|
placed = world.placements.has(normFactTerm(loc[1]));
|
|
16595
16642
|
} catch { placed = false; }
|
|
16596
16643
|
if (placed) {
|
|
16597
|
-
answer =
|
|
16644
|
+
answer = voice === PLAIN_VOICE
|
|
16645
|
+
? `${answer}\n(This is stored as your note. The game world itself only changes through actions like go, take and open.)`
|
|
16646
|
+
: `${answer}\n(noted as your note — the game world itself only changes through actions like go, take and open.)`;
|
|
16598
16647
|
note(trace, "intermediate: mid-game locative teach — stored as a note; the adventure fold only moves through actions");
|
|
16599
16648
|
}
|
|
16600
16649
|
}
|
|
@@ -16756,8 +16805,8 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16756
16805
|
const key = refTerm ? await cleanMissPackKey(refTerm, { graph, memoryDir, lexicon, cache }) : null;
|
|
16757
16806
|
const learned = key ? await childPackFactsForKey(key, { memoryDir, env, cache, synthesisBudget }) : null;
|
|
16758
16807
|
if (learned) {
|
|
16759
|
-
const fact = (await factAnswer(memoryDir, query, envelope, miss, biasByBundle, cache, newFocus?.label))
|
|
16760
|
-
?? (await factReadBack(memoryDir, query, envelope, miss, graph, newFocus?.label, biasByBundle, cache));
|
|
16808
|
+
const fact = (await factAnswer(memoryDir, query, envelope, miss, biasByBundle, cache, newFocus?.label, voice))
|
|
16809
|
+
?? (await factReadBack(memoryDir, query, envelope, miss, graph, newFocus?.label, biasByBundle, cache, voice));
|
|
16761
16810
|
if (fact && !fact.miss && !fact.weakOnly) {
|
|
16762
16811
|
answer = fact.replace ? fact.text : `${answer}\n${fact.text}`;
|
|
16763
16812
|
via = "fact";
|
|
@@ -16879,7 +16928,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16879
16928
|
// adjective is never silently dropped. Only on a REAL hit for the
|
|
16880
16929
|
// head noun; with nothing there either, the ordinary teach-offer
|
|
16881
16930
|
// stands.
|
|
16882
|
-
const headFallback = await adjectiveQualifiedHeadAnswer(cleanTerm, { memoryDir, biasByBundle, cache, graph, lexicon });
|
|
16931
|
+
const headFallback = await adjectiveQualifiedHeadAnswer(cleanTerm, { memoryDir, biasByBundle, cache, graph, lexicon, voice });
|
|
16883
16932
|
if (headFallback) {
|
|
16884
16933
|
answer = headFallback;
|
|
16885
16934
|
via = "fact";
|
|
@@ -17067,7 +17116,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
17067
17116
|
// `goal`: the SAME deduced string the debug trace's own "goal:" line
|
|
17068
17117
|
// carries. Only runAsk ever sets this field, so the always-on goal line is
|
|
17069
17118
|
// scoped to real ask-engine turns by construction.
|
|
17070
|
-
return { answer, logLines, record, focus: newFocus, detail, effectiveQuery, goal: deduced, lane, ...(planResult ? { plan: planResult } : {}) };
|
|
17119
|
+
return { answer, logLines, record, focus: newFocus, detail, effectiveQuery, goal: deduced, lane, ...(planResult ? { plan: planResult } : {}), ...(taughtThisTurn ? { taught: true } : {}) };
|
|
17071
17120
|
}
|
|
17072
17121
|
|
|
17073
17122
|
/** A non-ask, non-dispatch chat turn (count answer, /stats) — the same
|
|
@@ -17198,7 +17247,7 @@ export function renderDeclaredGoals(goals) {
|
|
|
17198
17247
|
return lines.join("\n").replace(/\n+$/, "");
|
|
17199
17248
|
}
|
|
17200
17249
|
|
|
17201
|
-
async function runCommand(line, { config, source, graph, focus, memoryDir, trace, narrate = false, liveReference = false, researchSource = null, tel = null, biasByBundle = {}, cache = null, codeDomainActive = false, codeGraphMode = false, laneVocab = null, domainPacks = null, lexicon = null, newsState = null, newsConfig = null, newsProviders = null }) {
|
|
17250
|
+
async function runCommand(line, { config, source, graph, focus, memoryDir, trace, narrate = false, liveReference = false, researchSource = null, tel = null, biasByBundle = {}, cache = null, codeDomainActive = false, codeGraphMode = false, laneVocab = null, domainPacks = null, lexicon = null, newsState = null, newsConfig = null, newsProviders = null, voice = DEFAULT_VOICE }) {
|
|
17202
17251
|
const ts = new Date().toISOString();
|
|
17203
17252
|
const sp = line.indexOf(" ");
|
|
17204
17253
|
const name = (sp === -1 ? line.slice(1) : line.slice(1, sp)).toLowerCase();
|
|
@@ -17567,7 +17616,7 @@ async function runCommand(line, { config, source, graph, focus, memoryDir, trace
|
|
|
17567
17616
|
|
|
17568
17617
|
if (result.status === "proved") {
|
|
17569
17618
|
const premiseRows = result.premises.map((id) => byId.get(id)).filter(Boolean);
|
|
17570
|
-
const cited = premiseRows.map(renderFactLine).join("; ");
|
|
17619
|
+
const cited = premiseRows.map((f) => renderFactLine(f, voice)).join("; ");
|
|
17571
17620
|
// A case-split conclusion (the ⊔-rule fired on a genuine owl:unionOf
|
|
17572
17621
|
// or owl:oneOf premise, not just the ⊑-rule's own routine
|
|
17573
17622
|
// TBox-internalization disjunction, which every proof passes
|
|
@@ -17585,7 +17634,7 @@ async function runCommand(line, { config, source, graph, focus, memoryDir, trace
|
|
|
17585
17634
|
const node = (result.model?.nodes || []).find((n) => n.id === subjectTerm);
|
|
17586
17635
|
const constrainingIds = [...new Set((node?.labels || []).flatMap((l) => l.from || []))].sort();
|
|
17587
17636
|
const constrainingRows = constrainingIds.map((id) => byId.get(id)).filter(Boolean);
|
|
17588
|
-
const suffix = constrainingRows.length ? ` What I remember: ${constrainingRows.map(renderFactLine).join("; ")}.` : "";
|
|
17637
|
+
const suffix = constrainingRows.length ? ` What I remember: ${constrainingRows.map((f) => renderFactLine(f, voice)).join("; ")}.` : "";
|
|
17589
17638
|
return mk(`no — I can build a consistent picture where ${subjectWord} is not a ${classWord}.${suffix}`);
|
|
17590
17639
|
}
|
|
17591
17640
|
// exhausted: the honest budget wall, never a downgraded guess. Names
|
|
@@ -17791,7 +17840,7 @@ async function runCommand(line, { config, source, graph, focus, memoryDir, trace
|
|
|
17791
17840
|
// matching taught facts (subject === the resolved entity, trust-ranked)
|
|
17792
17841
|
// under the code-map answer, mirroring the ask-path's fact-append pattern.
|
|
17793
17842
|
if (name === "describe" && memoryDir) {
|
|
17794
|
-
const facts = await describedFacts(memoryDir, ent.label, biasByBundle, cache);
|
|
17843
|
+
const facts = await describedFacts(memoryDir, ent.label, biasByBundle, cache, voice);
|
|
17795
17844
|
if (facts) { answer = `${answer}\n${facts}`; note(trace, "source: memory facts (describedFacts) appended to the code-map answer"); }
|
|
17796
17845
|
}
|
|
17797
17846
|
return mk(answer, { resolvedIds: [ent.id], newFocus: nextFocus(graph, focus, ent) });
|
|
@@ -18001,6 +18050,11 @@ async function assertTurn(line, { memoryDir, sessionId, focus, lexicon = null, c
|
|
|
18001
18050
|
// acknowledgment shows it was registered rather than silently dropped.
|
|
18002
18051
|
const dateSuffix = observedAt && dateText ? ` (as of ${dateText})` : "";
|
|
18003
18052
|
const answer = `noted — remembered ${n} fact${n === 1 ? "" : "s"}: ${shown}${paraphraseSuffix}${dateSuffix}`;
|
|
18053
|
+
// The plain voice states each triple in words. It leaves the paraphrase
|
|
18054
|
+
// out, because the phrased triple already says the same thing.
|
|
18055
|
+
const plainText = res.triples
|
|
18056
|
+
.map((t) => plainSentence(`${normFactTerm(t.subject)} ${predicatePhrase(t.predicate)} ${normFactTerm(t.object)}${dateSuffix}`))
|
|
18057
|
+
.join(" ");
|
|
18004
18058
|
// The canonical restatement of what was committed — `machine` is the same
|
|
18005
18059
|
// fact(s) in the compact notation ask.mjs's canonicalOf() uses for
|
|
18006
18060
|
// query-side parses, so both lanes share one consistent syntax.
|
|
@@ -18010,7 +18064,7 @@ async function assertTurn(line, { memoryDir, sessionId, focus, lexicon = null, c
|
|
|
18010
18064
|
.map((t) => `fact(${JSON.stringify(normFactTerm(t.subject))}, ${JSON.stringify(t.predicate)}, ${JSON.stringify(normFactTerm(t.object))})`)
|
|
18011
18065
|
.join(", "),
|
|
18012
18066
|
};
|
|
18013
|
-
return plainTurn(line, answer, { command: "assert", via: "assert", focus, canonical, goal: "teach/remember a new fact" });
|
|
18067
|
+
return { ...plainTurn(line, answer, { command: "assert", via: "assert", focus, canonical, goal: "teach/remember a new fact" }), plainText, taught: true };
|
|
18014
18068
|
} catch (error) {
|
|
18015
18069
|
rethrowPersistFailure(error);
|
|
18016
18070
|
return null; // grammar unavailable / write failed — fall through to the engine
|
|
@@ -18744,7 +18798,13 @@ async function answerWithoutFillerPrefix(input, options, missed) {
|
|
|
18744
18798
|
* store, standing in for the before-snapshot. A caller running many turns over
|
|
18745
18799
|
* one document folds once and threads it; folding a seed-sized graph again per
|
|
18746
18800
|
* turn, to read back the rows the caller just handed over, is the most
|
|
18747
|
-
* expensive thing an ingest does.
|
|
18801
|
+
* expensive thing an ingest does.
|
|
18802
|
+
*
|
|
18803
|
+
* `taught` on the result is true when the turn changed memory on the user's
|
|
18804
|
+
* word: it stored a fact or a rule the user stated, or it forgot one. It is
|
|
18805
|
+
* false on every other turn. Read it instead of the reply's wording, which
|
|
18806
|
+
* differs between voices. `options.voice` is "default" (the default) or
|
|
18807
|
+
* "plain" (chat-voice.mjs's CHAT_VOICES); any other value throws. */
|
|
18748
18808
|
export async function runTurn(input, options = {}) {
|
|
18749
18809
|
const memoryDir = options?.memoryDir ?? null;
|
|
18750
18810
|
const before = options?.factRowsBefore || await factRowSnapshot(memoryDir);
|
|
@@ -18764,10 +18824,11 @@ export async function runTurn(input, options = {}) {
|
|
|
18764
18824
|
});
|
|
18765
18825
|
}
|
|
18766
18826
|
if (!result || typeof result !== "object") return result;
|
|
18767
|
-
return { ...result, ...(await factsTouchedSince(memoryDir, before)) };
|
|
18827
|
+
return { ...result, taught: Boolean(result.taught), ...(await factsTouchedSince(memoryDir, before)) };
|
|
18768
18828
|
}
|
|
18769
18829
|
|
|
18770
|
-
async function dispatchTurn(input, { config, source = defaultSource, graph = null, focus = null, last = null, memoryDir = null, sessionId = "", env = process.env, lexicon = null, narrate = false, liveReference = false, researchSource = null, onLiveLookup = null, vocabHint = null, tel = null, biasByBundle = {}, factRowsCache: injectedFactRowsCache = null, planState = null, gameConfig = null, uiContext = "cli", synthesisBudget = AUTO_SYNTHESIS_BUDGET, researchState = null, researchConfig = null, newsState = null, newsConfig = null, newsProviders = null, discourse = null, _noSplit = false, actingSubject = "player", codeDomainActive = null, codeGraphMode = false, ingested = false, laneVocab = null, domainPacks = null, retrieval = null } = {}) {
|
|
18830
|
+
async function dispatchTurn(input, { config, source = defaultSource, graph = null, focus = null, last = null, memoryDir = null, sessionId = "", env = process.env, lexicon = null, narrate = false, liveReference = false, researchSource = null, onLiveLookup = null, vocabHint = null, tel = null, biasByBundle = {}, factRowsCache: injectedFactRowsCache = null, planState = null, gameConfig = null, uiContext = "cli", synthesisBudget = AUTO_SYNTHESIS_BUDGET, researchState = null, researchConfig = null, newsState = null, newsConfig = null, newsProviders = null, discourse = null, _noSplit = false, actingSubject = "player", codeDomainActive = null, codeGraphMode = false, ingested = false, laneVocab = null, domainPacks = null, retrieval = null, voice: voiceOption } = {}) {
|
|
18831
|
+
const voice = resolveChatVoice(voiceOption);
|
|
18771
18832
|
// Every game's tuning knobs (spider-fly's mass economy, guess-the-number's
|
|
18772
18833
|
// bounds, the shared plan lane's search-depth cap) — a caller's own
|
|
18773
18834
|
// gameConfig (chat-session.mjs resolves one per session from tmct.toml)
|
|
@@ -18864,7 +18925,7 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
18864
18925
|
// circuit breaker had already given up on it. A name lands here only when
|
|
18865
18926
|
// the skip changed what served the answer, and the trailer says so.
|
|
18866
18927
|
const sourceSkips = new Set();
|
|
18867
|
-
const ctx = { config, source, graph, focus, last, memoryDir, sessionId, templates, env, lexicon, trace, narrate, liveReference, researchSource, onLiveLookup, sourceSkips, vocabHint: resolvedVocabHint, tel, biasByBundle, cache: factRowsCache, vocabAntecedent, planHolder, discourseHolder, gameConfig: resolvedGameConfig, uiContext, synthesisBudget, codeDomainActive: domainActive, codeGraphMode, ingested, laneVocab: laneVocabValue, domainPacks: domainPacksValue, newsState, newsConfig, newsProviders };
|
|
18928
|
+
const ctx = { config, source, graph, focus, last, memoryDir, sessionId, templates, env, lexicon, trace, narrate, liveReference, researchSource, onLiveLookup, sourceSkips, vocabHint: resolvedVocabHint, tel, biasByBundle, cache: factRowsCache, vocabAntecedent, planHolder, discourseHolder, gameConfig: resolvedGameConfig, uiContext, synthesisBudget, codeDomainActive: domainActive, codeGraphMode, ingested, laneVocab: laneVocabValue, domainPacks: domainPacksValue, newsState, newsConfig, newsProviders, voice };
|
|
18868
18929
|
// A DISPATCHED turn (count / slash-command / ask) becomes the new "last
|
|
18869
18930
|
// answer" that why/say-more re-renders; a conversational turn does not.
|
|
18870
18931
|
// Every dispatched turn's result passes through finish() here — the LAST
|
|
@@ -19231,14 +19292,16 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
19231
19292
|
let f = focus; let l = last; let ps = planHolder.state; let d = discourseHolder.record;
|
|
19232
19293
|
const receipts = [];
|
|
19233
19294
|
let finalRec = null;
|
|
19295
|
+
let taughtAny = false;
|
|
19234
19296
|
// dispatchTurn, not runTurn: the OUTER wrapper's before/after snapshot
|
|
19235
19297
|
// already spans every sentence, so a per-sentence diff would only pay
|
|
19236
19298
|
// for a narrower answer to the same question.
|
|
19237
19299
|
for (const sentence of sentences) {
|
|
19238
19300
|
const r = await dispatchTurn(sentence, {
|
|
19239
19301
|
config, source, graph, focus: f, last: l, memoryDir, sessionId, env, lexicon,
|
|
19240
|
-
narrate: false, vocabHint, tel, biasByBundle, planState: ps, discourse: d, _noSplit: true,
|
|
19302
|
+
narrate: false, vocabHint, tel, biasByBundle, planState: ps, discourse: d, _noSplit: true, voice,
|
|
19241
19303
|
});
|
|
19304
|
+
taughtAny = taughtAny || Boolean(r.taught);
|
|
19242
19305
|
f = r.focus ?? f;
|
|
19243
19306
|
l = r.last ?? l;
|
|
19244
19307
|
if ("planState" in r) ps = r.planState;
|
|
@@ -19261,7 +19324,7 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
19261
19324
|
const goalTail = String(finalRec.answer ?? "").split("\n").slice(1).join("\n").trim();
|
|
19262
19325
|
answer = goalTail ? `${bullets}\n\n${goalTail}` : bullets;
|
|
19263
19326
|
}
|
|
19264
|
-
const combined = { ...finalRec, answer };
|
|
19327
|
+
const combined = { ...finalRec, answer, taught: taughtAny };
|
|
19265
19328
|
combined.planState = ps;
|
|
19266
19329
|
combined.focus = f;
|
|
19267
19330
|
combined.last = l;
|
|
@@ -19430,14 +19493,16 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
19430
19493
|
if (asserted) {
|
|
19431
19494
|
note(trace, "goal: teach/remember a new fact (declarative ACE sentence)");
|
|
19432
19495
|
note(trace, "lane: assertTurn — grammar/ace.mjs parseAce matched a full triple with no residue");
|
|
19496
|
+
asserted = turnInVoice(asserted, voice);
|
|
19433
19497
|
asserted.lane = "teach";
|
|
19434
19498
|
return withLast(asserted, "teach/remember a new fact");
|
|
19435
19499
|
}
|
|
19436
19500
|
if (taxonomy) {
|
|
19437
19501
|
note(trace, "goal: teach/remember a new fact (bare declarative taxonomy)");
|
|
19438
19502
|
note(trace, "lane: bareTaxonomyTeach — hyphenated-instance or article-led kind-of declarative, stored before the ask engine could parse it as a question");
|
|
19439
|
-
const taxonomyTurn = plainTurn(workingLine, taxonomy
|
|
19503
|
+
const taxonomyTurn = plainTurn(workingLine, voicedText(taxonomy, voice), { via: taxonomy.via, miss: taxonomy.miss, focus });
|
|
19440
19504
|
if (!taxonomy.miss) { taxonomyTurn.lane = "teach"; taxonomyTurn.goal = "teach/remember a new fact"; }
|
|
19505
|
+
if (taxonomy.taught) taxonomyTurn.taught = true;
|
|
19441
19506
|
return withLast(taxonomyTurn, "teach/remember a new fact");
|
|
19442
19507
|
}
|
|
19443
19508
|
}
|
|
@@ -19476,7 +19541,7 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
19476
19541
|
// (Session/Source/Rule) it skips. Placed here so ask()'s CODE-graph lanes never
|
|
19477
19542
|
// steal the phrasing; declines cleanly for a code-graph noun or a real restrictor.
|
|
19478
19543
|
if (memoryDir) {
|
|
19479
|
-
const memClass = await answerMemoryClassQuery(memoryDir, workingLine);
|
|
19544
|
+
const memClass = await answerMemoryClassQuery(memoryDir, workingLine, voice);
|
|
19480
19545
|
if (memClass != null) {
|
|
19481
19546
|
const goal = "list or count a memory-store kind (facts/utterances/sessions/sources/rules)";
|
|
19482
19547
|
note(trace, `goal: ${goal}`);
|
|
@@ -19514,7 +19579,7 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
19514
19579
|
// answerMembershipList below: those read "in the alphabet" as an
|
|
19515
19580
|
// unanswerable restrictor tail over a CLASS, not a container's contents.
|
|
19516
19581
|
if (memoryDir) {
|
|
19517
|
-
const collectionContents = await answerCollectionContents(memoryDir, workingLine, biasByBundle, factRowsCache);
|
|
19582
|
+
const collectionContents = await answerCollectionContents(memoryDir, workingLine, biasByBundle, factRowsCache, voice);
|
|
19518
19583
|
if (collectionContents != null) {
|
|
19519
19584
|
const goal = "list a declared collection's taught contents";
|
|
19520
19585
|
note(trace, `goal: ${goal}`);
|
|
@@ -19540,7 +19605,7 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
19540
19605
|
// from its own trigger, ahead of the conversational orientation lane that would
|
|
19541
19606
|
// otherwise claim the bare "list …" phrasing.
|
|
19542
19607
|
if (memoryDir) {
|
|
19543
|
-
const memberList = await answerMembershipList(memoryDir, workingLine, biasByBundle, factRowsCache);
|
|
19608
|
+
const memberList = await answerMembershipList(memoryDir, workingLine, biasByBundle, factRowsCache, voice);
|
|
19544
19609
|
if (memberList != null) {
|
|
19545
19610
|
const goal = "list the taught members of a class";
|
|
19546
19611
|
note(trace, `goal: ${goal}`);
|
|
@@ -19555,7 +19620,7 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
19555
19620
|
// class rather than the whole enumeration, right next to the list trigger it
|
|
19556
19621
|
// shares a class-resolution path with.
|
|
19557
19622
|
if (memoryDir) {
|
|
19558
|
-
const memberExample = await answerMembershipExample(memoryDir, workingLine, biasByBundle, factRowsCache);
|
|
19623
|
+
const memberExample = await answerMembershipExample(memoryDir, workingLine, biasByBundle, factRowsCache, voice);
|
|
19559
19624
|
if (memberExample != null) {
|
|
19560
19625
|
const goal = "give an example of a taught class's member";
|
|
19561
19626
|
note(trace, `goal: ${goal}`);
|