@polycode-projects/the-mechanical-code-talker 6.0.1 → 6.0.3
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/README.md +12 -0
- package/package.json +9 -2
- package/src/adapters/corpus/courtesy.mjs +67 -3
- package/src/adapters/corpus/dbpedia-lookup-live.mjs +8 -0
- package/src/adapters/corpus/wikidata-live.mjs +8 -0
- package/src/adapters/corpus/wikipedia-live.mjs +18 -0
- package/src/adapters/corpus/wiktionary-live.mjs +8 -0
- package/src/adapters/memory/core.mjs +7 -1
- package/src/adapters/memory/rows.mjs +18 -10
- package/src/adapters/source.mjs +12 -9
- package/src/domain/source-breaker.mjs +259 -0
- package/src/services/chat-page-viz.mjs +189 -26
- package/src/services/chat.mjs +242 -77
- package/src/services/ledger-viz.mjs +91 -6
- package/src/services/memory-panel-viz.mjs +12 -8
- package/src/services/news-viz.mjs +388 -348
- package/src/services/news.mjs +41 -7
- package/src/services/p2p-room.mjs +35 -21
- package/src/surfaces/web/chat-browser-entry.mjs +42 -5
- package/src/surfaces/web/http-row-backend.mjs +39 -0
- package/src/surfaces/web/ledger-browser-entry.mjs +30 -8
- package/src/surfaces/web/memory-ask-browser.bundle.js +135 -135
- package/src/surfaces/web/news-browser-entry.mjs +428 -455
- package/src/tools/graph-load.mjs +4 -2
package/src/services/chat.mjs
CHANGED
|
@@ -30,7 +30,7 @@ import { classDisplayName, DYNAMIC_TAIL_OK_RE } from "../domain/ask.mjs";
|
|
|
30
30
|
// about what a predicate says.
|
|
31
31
|
import {
|
|
32
32
|
FACT_PREDICATE_PHRASES, TEACH_PARTICIPLE_SRC, predicatePhrase,
|
|
33
|
-
thirdPersonSingularSurface, baseVerbSurface, gerundVerbSurface,
|
|
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
36
|
import { uuidv7 } from "../adapters/uuid.mjs";
|
|
@@ -38,6 +38,7 @@ import * as defaultSource from "../adapters/source.mjs";
|
|
|
38
38
|
import { loadTemplates, render as renderTemplate } from "../adapters/corpus/templates.mjs";
|
|
39
39
|
import { rankByBiasThenTrust } from "../domain/memory/bias.mjs";
|
|
40
40
|
import { HAS_A_PREDICATE, loadMemory as loadMemoryStore, normFactPredicate, normFactTerm as normFactTermStatic, readFactRows as readStoredFactRows, readRuleRows as readStoredRuleRows } from "../adapters/memory/core.mjs";
|
|
41
|
+
import { BACKEND_REJECTED_CODE, BACKEND_UNAVAILABLE_CODE } from "../adapters/memory/row-backend.mjs";
|
|
41
42
|
import {
|
|
42
43
|
CAPABILITY_REPORT_CAP, NEG_CAPABLE_OF_PREDICATE, NEG_SUBCLASS_PREDICATE, capabilityBaseRate,
|
|
43
44
|
capabilityExtension, isNegatedPredicate, negatedPredicate,
|
|
@@ -81,6 +82,7 @@ import { subClassParents, subClassChildren, descendantSet, ancestryChain, cluste
|
|
|
81
82
|
import { ANSWER_STOP_SET } from "../domain/hub-terms.mjs";
|
|
82
83
|
import { relatedForTerm } from "../domain/skos-view.mjs";
|
|
83
84
|
import { ENUMERATION_LANES, answerAssertsASet, retrievalMarkerLine } from "../domain/retrieval-marker.mjs";
|
|
85
|
+
import { throughSourceBreaker, sourceSkipNoteLine } from "../domain/source-breaker.mjs";
|
|
84
86
|
import { adventureTurn, unclaimedAdventureOpening, foldWorldState } from "./adventure.mjs";
|
|
85
87
|
import { spiderFlyTurn } from "./spider-fly-turn.mjs";
|
|
86
88
|
import { mudiiiTurn } from "./mudiii-turn.mjs";
|
|
@@ -384,6 +386,20 @@ function withRetrievalNote(result, retrieval) {
|
|
|
384
386
|
return { ...result, answer, logLines };
|
|
385
387
|
}
|
|
386
388
|
|
|
389
|
+
/** The skipped-source line, on the same append-onto-`answer` mechanism as
|
|
390
|
+
* withRetrievalNote, and placed beside it: both say what the answer was read
|
|
391
|
+
* from. A turn that asked no external source, or asked one that answered,
|
|
392
|
+
* gets nothing — which is every turn until a source starts failing. */
|
|
393
|
+
function withSourceSkipNote(result, sourceSkips) {
|
|
394
|
+
const line = sourceSkips?.size ? sourceSkipNoteLine(sourceSkips) : null;
|
|
395
|
+
if (!line) return result;
|
|
396
|
+
const answer = `${result.answer}\n\n${line}`;
|
|
397
|
+
const logLines = Array.isArray(result.logLines)
|
|
398
|
+
? result.logLines.map((l) => (l === result.answer ? answer : l))
|
|
399
|
+
: result.logLines;
|
|
400
|
+
return { ...result, answer, logLines };
|
|
401
|
+
}
|
|
402
|
+
|
|
387
403
|
/** Slash-command → (dispatchTool name, arg key). Arg keys are the EXACT ones the
|
|
388
404
|
* server.mjs dispatchTool switch reads (members/subclasses take `class`;
|
|
389
405
|
* impact/exports take `module`; architecture takes `package`; search takes
|
|
@@ -3422,9 +3438,33 @@ const PLACE_ADVERB_OBJECT_RE = /^(?:anywhere|everywhere|nowhere|somewhere)$/i;
|
|
|
3422
3438
|
* tag to a "teach" Source (trust prior in memory/trust.mjs). */
|
|
3423
3439
|
const teachProvenanceTag = (sessionId, ts) => `teach:chat${sessionId ? `:${sessionId}` : ""}${ts ? `@${ts}` : ""}`;
|
|
3424
3440
|
|
|
3441
|
+
/** The store could not be reached or refused service (a 429, a 507, a network
|
|
3442
|
+
* failure). The same write may well land later, so the turn says so and the
|
|
3443
|
+
* session carries on with nothing persisted. Read by code, never by message
|
|
3444
|
+
* text. */
|
|
3445
|
+
const isPersistUnavailable = (error) => error?.code === BACKEND_UNAVAILABLE_CODE;
|
|
3446
|
+
/** The store refused the input itself (an oversized row, a malformed key).
|
|
3447
|
+
* Retrying changes nothing, so this one travels all the way out of the turn
|
|
3448
|
+
* carrying the row and provenance the backend named. */
|
|
3449
|
+
const isPersistRejected = (error) => error?.code === BACKEND_REJECTED_CODE;
|
|
3450
|
+
/** Let a store refusal out of a write helper's own catch. Every other failure
|
|
3451
|
+
* (a malformed slot, a missing grammar, an unparsable sentence) keeps
|
|
3452
|
+
* degrading to null the way it always has. */
|
|
3453
|
+
function rethrowPersistFailure(error) {
|
|
3454
|
+
if (isPersistUnavailable(error) || isPersistRejected(error)) throw error;
|
|
3455
|
+
}
|
|
3456
|
+
/** What a turn says when the store would not take its write. The sentence is
|
|
3457
|
+
* closed and lane-neutral: it never names the fact, so a taught fact, a
|
|
3458
|
+
* taught rule and a retraction all report the same truth. */
|
|
3459
|
+
export const PERSIST_UNAVAILABLE_TEXT = "I understood that, but I couldn't save it. My memory isn't taking writes right now, so nothing changed. We can keep talking, and you can tell me again later.";
|
|
3460
|
+
const PERSIST_UNAVAILABLE_VIA = "persist-unavailable";
|
|
3461
|
+
const persistUnavailableAnswer = () => ({ text: PERSIST_UNAVAILABLE_TEXT, via: PERSIST_UNAVAILABLE_VIA, miss: true });
|
|
3462
|
+
|
|
3425
3463
|
/** Reify one teach-lane fact + confirm (shared by the property and ownership
|
|
3426
3464
|
* frames). Lazy + failure-tolerated: a write failure degrades to null (the
|
|
3427
|
-
* teach-miss text stands), never a crash.
|
|
3465
|
+
* teach-miss text stands), never a crash. A store refusal is the exception —
|
|
3466
|
+
* it travels, so the turn reports why nothing was stored instead of blaming
|
|
3467
|
+
* the vocabulary. */
|
|
3428
3468
|
async function teachFact(memoryDir, sessionId, { subject, predicate, object, quantifier = "", observedAt = "", dateText = "" }) {
|
|
3429
3469
|
try {
|
|
3430
3470
|
const { appendFact, normFactTerm } = await import("../adapters/memory/core.mjs");
|
|
@@ -3442,7 +3482,8 @@ async function teachFact(memoryDir, sessionId, { subject, predicate, object, qua
|
|
|
3442
3482
|
// acknowledgment shows it was registered rather than silently dropped.
|
|
3443
3483
|
const dateSuffix = observedAt && dateText ? ` (as of ${dateText})` : "";
|
|
3444
3484
|
return { text: `noted — remembered: ${s} ${phrase} ${o}${dateSuffix}`, via: "assert", miss: false };
|
|
3445
|
-
} catch {
|
|
3485
|
+
} catch (error) {
|
|
3486
|
+
rethrowPersistFailure(error);
|
|
3446
3487
|
return null;
|
|
3447
3488
|
}
|
|
3448
3489
|
}
|
|
@@ -5992,7 +6033,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
5992
6033
|
};
|
|
5993
6034
|
}
|
|
5994
6035
|
// nothing stored under that triple — fall through to the ordinary cascade
|
|
5995
|
-
} catch { /*
|
|
6036
|
+
} catch (error) { rethrowPersistFailure(error); /* nothing readable under that triple — fall through */ }
|
|
5996
6037
|
}
|
|
5997
6038
|
const retractForgetMatch = !retractNotMatch && memoryDir && !QUESTION_LEAD_RE.test(forgetSrc)
|
|
5998
6039
|
? forgetSrc.match(RETRACT_FORGET_RE) : null;
|
|
@@ -6415,7 +6456,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6415
6456
|
});
|
|
6416
6457
|
if (stored) return stored;
|
|
6417
6458
|
}
|
|
6418
|
-
} catch { /*
|
|
6459
|
+
} catch (error) { rethrowPersistFailure(error); /* the collection isn't readable — the frame declines rather than storing blind */ }
|
|
6419
6460
|
}
|
|
6420
6461
|
|
|
6421
6462
|
// RELATIONAL FACT — "<Name> is the <role> of <Name>". Grouped with the
|
|
@@ -6512,7 +6553,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6512
6553
|
via: "assert", miss: false,
|
|
6513
6554
|
};
|
|
6514
6555
|
}
|
|
6515
|
-
} catch { /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6556
|
+
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6516
6557
|
}
|
|
6517
6558
|
|
|
6518
6559
|
// FILTER RULE TEACH — "a <name> is a <base> who is <property>": stores a
|
|
@@ -6537,7 +6578,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6537
6578
|
via: "assert", miss: false,
|
|
6538
6579
|
};
|
|
6539
6580
|
}
|
|
6540
|
-
} catch { /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6581
|
+
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6541
6582
|
}
|
|
6542
6583
|
|
|
6543
6584
|
// RECURSIVE RULE TEACH — "a <name> is a <baseCase>, or a <recStep> of a
|
|
@@ -6566,7 +6607,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6566
6607
|
via: "assert", miss: false,
|
|
6567
6608
|
};
|
|
6568
6609
|
}
|
|
6569
|
-
} catch { /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6610
|
+
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6570
6611
|
}
|
|
6571
6612
|
|
|
6572
6613
|
// ACTION-RULE TEACH — the five action frames plus the render binding (see
|
|
@@ -6602,7 +6643,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6602
6643
|
via: "assert", miss: false,
|
|
6603
6644
|
};
|
|
6604
6645
|
}
|
|
6605
|
-
} catch { /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6646
|
+
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6606
6647
|
}
|
|
6607
6648
|
|
|
6608
6649
|
const actionSigPassive = ownSrc.match(ACTION_SIGNATURE_PASSIVE_RE);
|
|
@@ -6627,7 +6668,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6627
6668
|
via: "assert", miss: false,
|
|
6628
6669
|
};
|
|
6629
6670
|
}
|
|
6630
|
-
} catch { /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6671
|
+
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6631
6672
|
}
|
|
6632
6673
|
}
|
|
6633
6674
|
|
|
@@ -6663,7 +6704,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6663
6704
|
via: "assert", miss: false,
|
|
6664
6705
|
};
|
|
6665
6706
|
}
|
|
6666
|
-
} catch { /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6707
|
+
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6667
6708
|
}
|
|
6668
6709
|
|
|
6669
6710
|
const precondComp = ownSrc.match(ACTION_PRECOND_COMPARATIVE_RE);
|
|
@@ -6701,7 +6742,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6701
6742
|
via: "assert", miss: false,
|
|
6702
6743
|
};
|
|
6703
6744
|
}
|
|
6704
|
-
} catch { /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6745
|
+
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6705
6746
|
}
|
|
6706
6747
|
|
|
6707
6748
|
const actionConstraint = ownSrc.match(ACTION_CONSTRAINT_TEACH_RE);
|
|
@@ -6726,7 +6767,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6726
6767
|
via: "assert", miss: false,
|
|
6727
6768
|
};
|
|
6728
6769
|
}
|
|
6729
|
-
} catch { /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6770
|
+
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6730
6771
|
}
|
|
6731
6772
|
|
|
6732
6773
|
const actionEffect = ownSrc.match(ACTION_EFFECT_TEACH_RE);
|
|
@@ -6782,7 +6823,7 @@ async function teachLane(query, { memoryDir, sessionId = "", lexicon = null, cac
|
|
|
6782
6823
|
via: "assert", miss: false,
|
|
6783
6824
|
};
|
|
6784
6825
|
}
|
|
6785
|
-
} catch { /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6826
|
+
} catch (error) { rethrowPersistFailure(error); /* malformed slots — fall through to the ordinary honest-miss cascade */ }
|
|
6786
6827
|
}
|
|
6787
6828
|
|
|
6788
6829
|
const rendersAs = ownSrc.match(RENDERS_AS_TEACH_RE);
|
|
@@ -8105,6 +8146,36 @@ function citationProvenance(provenance) {
|
|
|
8105
8146
|
return provenance.replace(/#node:[0-9a-f]+/g, "");
|
|
8106
8147
|
}
|
|
8107
8148
|
|
|
8149
|
+
/** What every rendered fact line ends with: the extractor's caveat, when the
|
|
8150
|
+
* row carries a finding worth declaring, then the source citation. The order
|
|
8151
|
+
* is fixed — a reader sees how the sentence was read, then who said it — and
|
|
8152
|
+
* both halves are optional, so a clean untraced row ends with nothing at all.
|
|
8153
|
+
*
|
|
8154
|
+
* A row whose extractor recorded a finding stays answerable (no lane declines
|
|
8155
|
+
* a stored fact); the caveat is how the answer says which reading it leans
|
|
8156
|
+
* on, the same reader-visible signal renderFactLine's "possibly:" hedge gives
|
|
8157
|
+
* a weak-corpus row. */
|
|
8158
|
+
function factLineTail(f) {
|
|
8159
|
+
const caveat = findingCaveat(f);
|
|
8160
|
+
const cite = f.provenance ? ` (source: ${citationProvenance(f.provenance)})` : "";
|
|
8161
|
+
return `${caveat ? ` ${caveat}` : ""}${cite}`;
|
|
8162
|
+
}
|
|
8163
|
+
|
|
8164
|
+
/** Every extraction finding the rows behind ONE composed sentence carry. A
|
|
8165
|
+
* union or an enumeration reads several stored rows out as a single line, so
|
|
8166
|
+
* the line declares what any of them was read from. */
|
|
8167
|
+
function composedExtraction(rows) {
|
|
8168
|
+
return rows.filter(Boolean).flatMap((r) => (Array.isArray(r.extraction) ? r.extraction : []));
|
|
8169
|
+
}
|
|
8170
|
+
|
|
8171
|
+
/** One fact as an uncited-framing citation step: the phrase, its caveat and
|
|
8172
|
+
* its source. Chains, both-sides refusals and "via:" receipts all read a
|
|
8173
|
+
* premise this way — the same convention renderFactLine uses, without the
|
|
8174
|
+
* "you told me"/"i learned" first-person framing a standalone line carries. */
|
|
8175
|
+
function citedFactPhrase(f) {
|
|
8176
|
+
return `${factPhrase(f)}${factLineTail(f)}`;
|
|
8177
|
+
}
|
|
8178
|
+
|
|
8108
8179
|
/** One rendered fact line. An OPERATOR-asserted fact keeps the true first-person
|
|
8109
8180
|
* provenance ("you told me: …"). A CORPUS fact is presented as clean DATA with its
|
|
8110
8181
|
* source cited, not "i learned: …" — that phrase over-claims and anthropomorphises
|
|
@@ -8116,28 +8187,28 @@ function citationProvenance(provenance) {
|
|
|
8116
8187
|
* that it's lower-confidence, so a distinct, honest hedge ("possibly: …")
|
|
8117
8188
|
* applies here instead. Provenance stays VERBATIM in every case. */
|
|
8118
8189
|
function renderFactLine(f) {
|
|
8119
|
-
const
|
|
8190
|
+
const tail = factLineTail(f);
|
|
8120
8191
|
// A rdfs:subPropertyOf row relates two PREDICATES, not two things — factPhrase
|
|
8121
8192
|
// would compose the raw CURIE ("contains rdfs:subPropertyOf touches"), so this
|
|
8122
8193
|
// shape gets its own dedicated line ahead of the provenance-keyed framing below,
|
|
8123
8194
|
// the same way renderUnionLine/renderEnumerationLine read as a definition
|
|
8124
8195
|
// rather than a first-person claim regardless of who taught it.
|
|
8125
8196
|
if (f.predicate === SUB_PROPERTY_OF_PREDICATE) {
|
|
8126
|
-
return `${gerundVerbSurface(f.subject)} implies ${gerundVerbSurface(f.object)}${
|
|
8197
|
+
return `${gerundVerbSurface(f.subject)} implies ${gerundVerbSurface(f.object)}${tail}`;
|
|
8127
8198
|
}
|
|
8128
8199
|
// ace:chat = the ACE-parsed operator assert; teach:chat = the teach lane's
|
|
8129
8200
|
// natural frames — both are things the operator SAID, so both read first-person.
|
|
8130
|
-
if (f.provenance.includes("ace:chat") || f.provenance.includes("teach:chat")) return `you told me: ${factPhrase(f)}${
|
|
8201
|
+
if (f.provenance.includes("ace:chat") || f.provenance.includes("teach:chat")) return `you told me: ${factPhrase(f)}${tail}`;
|
|
8131
8202
|
// WEAK corpus facts (lower trust, e.g. RelatedTo) — real, cited, but hedged as
|
|
8132
8203
|
// uncertain rather than either flatly stated or falsely claimed as "learned".
|
|
8133
|
-
if (f.provenance.includes("corpus-weak:")) return `possibly: ${factPhrase(f)}${
|
|
8204
|
+
if (f.provenance.includes("corpus-weak:")) return `possibly: ${factPhrase(f)}${tail}`;
|
|
8134
8205
|
// SOLID corpus facts are background DATA — present the relation plainly, cited
|
|
8135
8206
|
// to its source, never "i learned: …" (a first-person claim over corpus data).
|
|
8136
|
-
if (f.provenance.includes("corpus:")) return `${factPhrase(f)}${
|
|
8207
|
+
if (f.provenance.includes("corpus:")) return `${factPhrase(f)}${tail}`;
|
|
8137
8208
|
// Reference-pack facts are the same class of cited data — the "i learned:"
|
|
8138
8209
|
// frame read as a definition-less non-answer on the re-ask.
|
|
8139
|
-
if (f.provenance.includes("reference:")) return `${factPhrase(f)}${
|
|
8140
|
-
return `i learned: ${factPhrase(f)}${
|
|
8210
|
+
if (f.provenance.includes("reference:")) return `${factPhrase(f)}${tail}`;
|
|
8211
|
+
return `i learned: ${factPhrase(f)}${tail}`;
|
|
8141
8212
|
}
|
|
8142
8213
|
|
|
8143
8214
|
/** A union node's stored triples read back as ONE sentence rather than a
|
|
@@ -8149,9 +8220,11 @@ function renderFactLine(f) {
|
|
|
8149
8220
|
* Pure — takes the fact rows, returns one line. */
|
|
8150
8221
|
function renderUnionLine(node, members) {
|
|
8151
8222
|
const sorted = [...members].sort((a, b) => a.object.localeCompare(b.object));
|
|
8152
|
-
|
|
8223
|
+
// One sentence states every arm, so its caveat covers every row it was
|
|
8224
|
+
// composed from, not just the one the citation came off.
|
|
8225
|
+
const tail = factLineTail({ ...node, extraction: composedExtraction([node, ...sorted]) });
|
|
8153
8226
|
const arms = sorted.map((m) => `${indefiniteArticleFor(m.object)} ${m.object}`).join(" or ");
|
|
8154
|
-
return `every ${node.subject} is ${arms}${
|
|
8227
|
+
return `every ${node.subject} is ${arms}${tail}`;
|
|
8155
8228
|
}
|
|
8156
8229
|
|
|
8157
8230
|
/** An enumerated class's stored `owl:oneOf` triples read back as ONE sentence:
|
|
@@ -8169,9 +8242,9 @@ function renderEnumerationLine(cls, members) {
|
|
|
8169
8242
|
? `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`
|
|
8170
8243
|
: names.join("");
|
|
8171
8244
|
const citeSource = sorted.find((m) => m.provenance)?.provenance;
|
|
8172
|
-
const
|
|
8245
|
+
const tail = factLineTail({ provenance: citeSource || "", extraction: composedExtraction(sorted) });
|
|
8173
8246
|
const plural = thirdPersonSingularSurface(String(cls || "").replace(/-/g, " "));
|
|
8174
|
-
return `the ${plural} are exactly ${list}${
|
|
8247
|
+
return `the ${plural} are exactly ${list}${tail}`;
|
|
8175
8248
|
}
|
|
8176
8249
|
|
|
8177
8250
|
/** A universal restriction's stored triples read back as ONE sentence rather
|
|
@@ -8185,18 +8258,16 @@ function renderEnumerationLine(cls, members) {
|
|
|
8185
8258
|
function renderUniversalRestrictionLine(node, rows) {
|
|
8186
8259
|
const onProperty = rows.find((r) => r.predicate === "owl:onProperty");
|
|
8187
8260
|
const allValuesFrom = rows.find((r) => r.predicate === "owl:allValuesFrom");
|
|
8188
|
-
const
|
|
8261
|
+
const tail = factLineTail({ ...node, extraction: composedExtraction([node, onProperty, allValuesFrom]) });
|
|
8189
8262
|
const filler = thirdPersonSingularSurface(String(allValuesFrom?.object || "").replace(/-/g, " "));
|
|
8190
|
-
return `every ${node.subject} ${onProperty?.object || ""} only ${filler}${
|
|
8263
|
+
return `every ${node.subject} ${onProperty?.object || ""} only ${filler}${tail}`;
|
|
8191
8264
|
}
|
|
8192
8265
|
export { renderUnionLine, renderEnumerationLine, renderUniversalRestrictionLine };
|
|
8193
8266
|
|
|
8194
|
-
const SENSE_CITE_RE = / \(source: [^)]*\)$/;
|
|
8195
|
-
|
|
8196
8267
|
/** Append an is-a object's superclass chain to its rendered fact line, before
|
|
8197
|
-
* the citation: "rover is a kind of dog" becomes "rover is a
|
|
8198
|
-
* canine → mammal → animal". Only the subject-side is-a lines
|
|
8199
|
-
* term get a chain; every other line renders unchanged.
|
|
8268
|
+
* the caveat and the citation: "rover is a kind of dog" becomes "rover is a
|
|
8269
|
+
* kind of dog → canine → mammal → animal". Only the subject-side is-a lines
|
|
8270
|
+
* of the queried term get a chain; every other line renders unchanged.
|
|
8200
8271
|
*
|
|
8201
8272
|
* `toward` steers the chain toward a specific ancestor (the class a "list …"
|
|
8202
8273
|
* question actually asked about) when the is-a object has more than one
|
|
@@ -8207,8 +8278,9 @@ function renderFactLineWithChain(f, parents, subjectVariants, { toward = null }
|
|
|
8207
8278
|
const chain = ancestryChain(f.object, parents, { cap: 6, stopAt: ANSWER_STOP_SET, toward });
|
|
8208
8279
|
if (chain.length <= 1) return base;
|
|
8209
8280
|
const suffix = ` → ${chain.slice(1).join(" → ")}`;
|
|
8210
|
-
const
|
|
8211
|
-
|
|
8281
|
+
const tail = factLineTail(f);
|
|
8282
|
+
if (!tail || !base.endsWith(tail)) return base + suffix;
|
|
8283
|
+
return base.slice(0, base.length - tail.length) + suffix + tail;
|
|
8212
8284
|
}
|
|
8213
8285
|
|
|
8214
8286
|
/** Render a subject-scan fact list with each is-a object's superclass chain
|
|
@@ -8335,9 +8407,8 @@ function isaPolarityReply(hit, negHit) {
|
|
|
8335
8407
|
* inconsistency as a derivation — so neither side wins, same discipline as
|
|
8336
8408
|
* isaPolarityReply's both-sides verdict. */
|
|
8337
8409
|
function isaInconsistencyRefusal(posFact, disjointFact) {
|
|
8338
|
-
const cite = (f) => `${factPhrase(f)}${f.provenance ? ` (source: ${citationProvenance(f.provenance)})` : ""}`;
|
|
8339
8410
|
return {
|
|
8340
|
-
text: `you've told me both ${
|
|
8411
|
+
text: `you've told me both ${citedFactPhrase(posFact)} and ${citedFactPhrase(disjointFact)} — together those contradict, and I won't derive an answer from an inconsistency. `
|
|
8341
8412
|
+ `To settle it, say "forget that ${posFact.subject} is ${indefiniteArticleFor(posFact.object)} ${posFact.object}".`,
|
|
8342
8413
|
replace: true,
|
|
8343
8414
|
};
|
|
@@ -8347,21 +8418,22 @@ function isaInconsistencyRefusal(posFact, disjointFact) {
|
|
|
8347
8418
|
* an ordered list of
|
|
8348
8419
|
* premise Fact rows as one continuous argument — "cache is a kind of store;
|
|
8349
8420
|
* store is a kind of component; so redis.mjs is a component" — each premise
|
|
8350
|
-
* cited
|
|
8351
|
-
* uses, just without its "you told me"/"i learned" framing (a
|
|
8352
|
-
* one derivation, not a list of standalone recollections). The
|
|
8353
|
-
* clause is spelled directly from the first premise's subject and
|
|
8354
|
-
* premise's object — sound for any chain length, though today's only
|
|
8355
|
-
* (the live cax-sco/scm-sco chase below) ever passes exactly two. */
|
|
8421
|
+
* cited through citedFactPhrase, the SAME caveat + "(source: …)" convention
|
|
8422
|
+
* renderFactLine uses, just without its "you told me"/"i learned" framing (a
|
|
8423
|
+
* chain reads as one derivation, not a list of standalone recollections). The
|
|
8424
|
+
* conclusion clause is spelled directly from the first premise's subject and
|
|
8425
|
+
* the last premise's object — sound for any chain length, though today's only
|
|
8426
|
+
* caller (the live cax-sco/scm-sco chase below) ever passes exactly two. */
|
|
8356
8427
|
function renderIsaChain(premises) {
|
|
8357
|
-
const step = (f) => `${factPhrase(f)}${f.provenance ? ` (source: ${citationProvenance(f.provenance)})` : ""}`;
|
|
8358
8428
|
const first = premises[0];
|
|
8359
8429
|
const last = premises[premises.length - 1];
|
|
8360
|
-
return `${premises.map(
|
|
8430
|
+
return `${premises.map((f) => citedFactPhrase(f)).join("; ")}; so ${first.subject} is a ${last.object}`;
|
|
8361
8431
|
}
|
|
8362
8432
|
|
|
8363
8433
|
/** Read every reified Fact out of the memory graph as plain {subject, predicate,
|
|
8364
|
-
* object, provenance} rows
|
|
8434
|
+
* object, provenance} rows, each carrying `extraction` when its own record
|
|
8435
|
+
* recorded a finding, so a line rendered off this reader declares the same
|
|
8436
|
+
* caveat a readFactRows row would. Lazy + failure-tolerated: no memory → []. */
|
|
8365
8437
|
async function memoryFacts(memoryDir) {
|
|
8366
8438
|
try {
|
|
8367
8439
|
const { loadMemory } = await import("../adapters/memory/core.mjs");
|
|
@@ -8370,7 +8442,11 @@ async function memoryFacts(memoryDir) {
|
|
|
8370
8442
|
for (const ind of m.individuals || []) {
|
|
8371
8443
|
if (ind?.class !== "Fact") continue;
|
|
8372
8444
|
const get = (k) => (ind.attributes || []).find((a) => a.key === k)?.value || "";
|
|
8373
|
-
|
|
8445
|
+
const extraction = get("extraction").split(" ").filter(Boolean);
|
|
8446
|
+
out.push({
|
|
8447
|
+
subject: get("subject"), predicate: get("predicate"), object: get("object"), provenance: get("provenance"),
|
|
8448
|
+
...(extraction.length ? { extraction } : {}),
|
|
8449
|
+
});
|
|
8374
8450
|
}
|
|
8375
8451
|
return out;
|
|
8376
8452
|
} catch {
|
|
@@ -9021,7 +9097,7 @@ function renderIsaCite(chain, facts) {
|
|
|
9021
9097
|
(f) => f.predicate === step.predicate && f.subject === step.subject && f.object === step.object,
|
|
9022
9098
|
));
|
|
9023
9099
|
if (!steps.length || !steps.every(Boolean)) return null;
|
|
9024
|
-
return steps.map((g) =>
|
|
9100
|
+
return steps.map((g) => citedFactPhrase(g)).join("; ");
|
|
9025
9101
|
}
|
|
9026
9102
|
|
|
9027
9103
|
/** THE capability answer — every reader that asks "can X do Y" renders through
|
|
@@ -9700,7 +9776,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
9700
9776
|
if (declined) return declined;
|
|
9701
9777
|
const steps = order.slice(0, -1).map((n, i) => pairs.find((f) => f.subject === n && f.object === order[i + 1]));
|
|
9702
9778
|
if (steps.every(Boolean)) {
|
|
9703
|
-
const cite = steps.map((g) =>
|
|
9779
|
+
const cite = steps.map((g) => citedFactPhrase(g)).join("; ");
|
|
9704
9780
|
return { text: `${order[0]} — ${cite}; so ${order[0]} is the ${supWord} ${kindSingular}`, replace: true };
|
|
9705
9781
|
}
|
|
9706
9782
|
}
|
|
@@ -10425,7 +10501,7 @@ async function factAnswerReaders(memoryDir, query, envelope, miss, biasByBundle
|
|
|
10425
10501
|
if (!chain || chain.length < 2) return renderFactLine(f);
|
|
10426
10502
|
const steps = chain.map(rowForStep);
|
|
10427
10503
|
if (!steps.every(Boolean)) return renderFactLine(f);
|
|
10428
|
-
const cite = steps.map((g) =>
|
|
10504
|
+
const cite = steps.map((g) => citedFactPhrase(g)).join("; ");
|
|
10429
10505
|
return `${renderFactLine(f)} — via: ${cite}`;
|
|
10430
10506
|
});
|
|
10431
10507
|
const shown = lines.slice(0, FACT_ANSWER_CAP);
|
|
@@ -11505,7 +11581,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
11505
11581
|
const key = af.id || `${af.subject}|${af.predicate}|${af.object}`;
|
|
11506
11582
|
if (seenAlias.has(key)) continue;
|
|
11507
11583
|
seenAlias.add(key);
|
|
11508
|
-
parts.push(
|
|
11584
|
+
parts.push(citedFactPhrase(af));
|
|
11509
11585
|
}
|
|
11510
11586
|
}
|
|
11511
11587
|
return `${node.entity} — ${parts.join("; ")}`;
|
|
@@ -11688,7 +11764,7 @@ async function factReadBackReaders(memoryDir, query, envelope, miss, graph = nul
|
|
|
11688
11764
|
const kindEcho = stripTrailingDiscourseTag(isaAsk[2]).trim();
|
|
11689
11765
|
const chain = [posFact, ...(objFact ? [objFact] : [])].map(renderFactLine).join("; ");
|
|
11690
11766
|
return {
|
|
11691
|
-
text: `no — ${chain}; and ${
|
|
11767
|
+
text: `no — ${chain}; and ${citedFactPhrase(disjointFact)} `
|
|
11692
11768
|
+ `— so ${isaSubject} can never be ${indefiniteArticleFor(kindEcho)} ${kindEcho}.`,
|
|
11693
11769
|
replace: true,
|
|
11694
11770
|
};
|
|
@@ -13188,19 +13264,67 @@ async function cleanMissLiveKey(term, { graph, memoryDir, lexicon, cache }) {
|
|
|
13188
13264
|
return key;
|
|
13189
13265
|
}
|
|
13190
13266
|
|
|
13267
|
+
/** The name a live source goes by in a breaker and in the skipped-source note.
|
|
13268
|
+
* A registered stub with no name of its own answers to this one, so a test
|
|
13269
|
+
* provider is guarded exactly as the shipped one is. */
|
|
13270
|
+
const LIVE_SOURCE_FALLBACK_NAME = "wikipedia";
|
|
13271
|
+
|
|
13272
|
+
/** Runs one live-source lookup behind that source's circuit breaker, so a
|
|
13273
|
+
* source that keeps timing out is skipped for the rest of the session
|
|
13274
|
+
* instead of being asked again every turn. A skipped source adds its name to
|
|
13275
|
+
* `sourceSkips` and answers null, which is the same shape a miss already
|
|
13276
|
+
* takes — the turn proceeds byte-identically, and the answer says the source
|
|
13277
|
+
* was not asked. */
|
|
13278
|
+
async function throughLiveSourceBreaker(provider, sourceSkips, work) {
|
|
13279
|
+
const source = String(provider?.name || LIVE_SOURCE_FALLBACK_NAME);
|
|
13280
|
+
const systemicFailuresOf = typeof provider?.stats === "function"
|
|
13281
|
+
? () => provider.stats().systemicFailures ?? 0
|
|
13282
|
+
: null;
|
|
13283
|
+
return throughSourceBreaker(source, work, { skipped: sourceSkips, label: provider?.label, systemicFailuresOf });
|
|
13284
|
+
}
|
|
13285
|
+
|
|
13191
13286
|
/** The live Wikipedia lookup for an already-gated key: the article, or null
|
|
13192
|
-
* (toggle-off provider, network failure, throttle, drift-guard rejection
|
|
13193
|
-
* all byte-identical to a live-off run).
|
|
13194
|
-
* hook (the web page's "searching
|
|
13195
|
-
* is swallowed too. */
|
|
13196
|
-
async function liveReferenceAnswerForKey(key, onLiveLookup) {
|
|
13197
|
-
|
|
13287
|
+
* (toggle-off provider, network failure, throttle, drift-guard rejection,
|
|
13288
|
+
* a breaker-skipped source — all byte-identical to a live-off run).
|
|
13289
|
+
* `onLiveLookup` is a notify-only hook (the web page's "searching
|
|
13290
|
+
* wikipedia…" statusline); its own failure is swallowed too. */
|
|
13291
|
+
async function liveReferenceAnswerForKey(key, onLiveLookup, sourceSkips = null) {
|
|
13292
|
+
const provider = getLiveReferenceProvider();
|
|
13198
13293
|
let article = null;
|
|
13199
|
-
try {
|
|
13294
|
+
try {
|
|
13295
|
+
article = await throughLiveSourceBreaker(provider, sourceSkips, async () => {
|
|
13296
|
+
try { if (typeof onLiveLookup === "function") onLiveLookup(key); } catch { /* notify-only */ }
|
|
13297
|
+
// The fetch budget covers this lookup: the search and the read it needs,
|
|
13298
|
+
// and nothing like a retry loop past them.
|
|
13299
|
+
try { provider.beginTurn?.(); } catch { /* an older provider has no budget */ }
|
|
13300
|
+
try { return await provider.lookup(key); } catch { return null; }
|
|
13301
|
+
});
|
|
13302
|
+
} catch { article = null; }
|
|
13200
13303
|
if (!article) return null;
|
|
13201
13304
|
return { key, article, text: renderLiveReferenceAnswer(key, article) };
|
|
13202
13305
|
}
|
|
13203
13306
|
|
|
13307
|
+
/** The research lane's provider with its source's breaker in front of every
|
|
13308
|
+
* fetching method. A skipped source answers null to all three, which is the
|
|
13309
|
+
* lane's own "the source had nothing" path, so a run pauses honestly instead
|
|
13310
|
+
* of walking a queue against a dead source. The contract fields the lane
|
|
13311
|
+
* reads (name, origin, provenanceTag) pass straight through. */
|
|
13312
|
+
function guardedResearchProvider(provider, sourceSkips) {
|
|
13313
|
+
if (!provider) return provider;
|
|
13314
|
+
try { provider.beginTurn?.(); } catch { /* an older provider has no budget */ }
|
|
13315
|
+
const guard = (work) => throughLiveSourceBreaker(provider, sourceSkips, work);
|
|
13316
|
+
return {
|
|
13317
|
+
...provider,
|
|
13318
|
+
lookup: (term) => guard(() => provider.lookup(term)),
|
|
13319
|
+
...(typeof provider.pageByTitle === "function"
|
|
13320
|
+
? { pageByTitle: (title) => guard(() => provider.pageByTitle(title)) }
|
|
13321
|
+
: {}),
|
|
13322
|
+
...(typeof provider.linkedTitles === "function"
|
|
13323
|
+
? { linkedTitles: (title, options) => guard(() => provider.linkedTitles(title, options)) }
|
|
13324
|
+
: {}),
|
|
13325
|
+
};
|
|
13326
|
+
}
|
|
13327
|
+
|
|
13204
13328
|
/** The child-pack half of learn-on-miss, for an already-gated key: look the
|
|
13205
13329
|
* key up in the shipped child triples pack and append every fact under child
|
|
13206
13330
|
* provenance, so the SAME question can be re-asked from the store. Null on a
|
|
@@ -14997,7 +15121,7 @@ const ARCH_OVERVIEW_PHRASES = [
|
|
|
14997
15121
|
new RegExp(`^${ARCH_OVERVIEW_LEAD}(?:(?:an?|the)\\s+)?(?:overview|map|diagram)\\s+${ARCH_OVERVIEW_OF_REPO}(?:\\s+here)?\\??$`, "i"),
|
|
14998
15122
|
];
|
|
14999
15123
|
|
|
15000
|
-
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, uiContext = "cli", synthesisBudget = AUTO_SYNTHESIS_BUDGET, codeDomainActive = false }) {
|
|
15124
|
+
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 }) {
|
|
15001
15125
|
// The session-wide hint names a term this session can PROVE resolves; when
|
|
15002
15126
|
// the question itself named a subject the lexicon knows, the hint names that
|
|
15003
15127
|
// instead, so a miss on "how many eyes does a human have" points at "human"
|
|
@@ -15210,7 +15334,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
15210
15334
|
}
|
|
15211
15335
|
let liveKey = null;
|
|
15212
15336
|
try { liveKey = cleanMissLiveTerm(wikiTerm, lexicon ?? undefined); } catch { liveKey = null; }
|
|
15213
|
-
const live = liveKey ? await liveReferenceAnswerForKey(liveKey, onLiveLookup) : null;
|
|
15337
|
+
const live = liveKey ? await liveReferenceAnswerForKey(liveKey, onLiveLookup, sourceSkips) : null;
|
|
15214
15338
|
if (live) {
|
|
15215
15339
|
await ingestReferenceArticle(memoryDir, live.key, live.article, cache, liveProvenanceTag, lexicon, synthesisBudget);
|
|
15216
15340
|
note(trace, `lane: WIKIPEDIA ASK — answered from a live en.wikipedia.org lookup, cited (article "${live.article.title}", revid ${live.article.revid})`);
|
|
@@ -15886,7 +16010,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
15886
16010
|
// exactly as a live-off run would.
|
|
15887
16011
|
if (!bareMetaHit && liveReference && refTerm) {
|
|
15888
16012
|
const liveKey = await cleanMissLiveKey(refTerm, { graph, memoryDir, lexicon, cache });
|
|
15889
|
-
const live = liveKey ? await liveReferenceAnswerForKey(liveKey, onLiveLookup) : null;
|
|
16013
|
+
const live = liveKey ? await liveReferenceAnswerForKey(liveKey, onLiveLookup, sourceSkips) : null;
|
|
15890
16014
|
if (live) bareMetaHit = { text: live.text, replace: true, live };
|
|
15891
16015
|
}
|
|
15892
16016
|
}
|
|
@@ -16236,11 +16360,23 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16236
16360
|
// (4) #2 TEACH lane — a teach-shaped would-miss nothing above answered: route to
|
|
16237
16361
|
// memory, or say what CAN be remembered (LOUD), never the wall / a silent drop.
|
|
16238
16362
|
if (miss && recordMiss && via === "composed") {
|
|
16239
|
-
|
|
16363
|
+
// A store that refuses the write is reported as itself. Left to fall
|
|
16364
|
+
// through, every frame in the lane declines in turn and the answer blames
|
|
16365
|
+
// the vocabulary for something the vocabulary had nothing to do with.
|
|
16366
|
+
let taught = null;
|
|
16367
|
+
try {
|
|
16368
|
+
taught = await teachLane(query, { memoryDir, sessionId, lexicon, cache, planHolder, graph, gameConfig });
|
|
16369
|
+
} catch (error) {
|
|
16370
|
+
if (!isPersistUnavailable(error)) throw error;
|
|
16371
|
+
taught = persistUnavailableAnswer();
|
|
16372
|
+
}
|
|
16240
16373
|
if (taught) {
|
|
16241
16374
|
answer = taught.text; via = taught.via; recordMiss = taught.miss;
|
|
16242
16375
|
if (!taught.miss) dialogueLaneOverride = "teach";
|
|
16243
|
-
|
|
16376
|
+
const teachOutcome = taught.via === PERSIST_UNAVAILABLE_VIA ? "but the store would not take the write"
|
|
16377
|
+
: taught.miss ? "but the payload could not be stored"
|
|
16378
|
+
: "reified into .tmct/memory";
|
|
16379
|
+
note(trace, `lane: (4) TEACH — TEACH_RE/OWNS_TEACH_RE/BARE_DECLARATIVE_RE matched, ${teachOutcome}`);
|
|
16244
16380
|
// `deduced` was computed straight off envelope.parsed alone, but the
|
|
16245
16381
|
// structural grammar has no business parsing a teach-shaped sentence at
|
|
16246
16382
|
// all, so it would otherwise be confidently WRONG or silently absent.
|
|
@@ -16465,7 +16601,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16465
16601
|
// miss byte-identical to a live-off run.
|
|
16466
16602
|
if (miss && recordMiss && via === "composed" && liveReference && refTerm) {
|
|
16467
16603
|
const liveKey = await cleanMissLiveKey(refTerm, { graph, memoryDir, lexicon, cache });
|
|
16468
|
-
const live = liveKey ? await liveReferenceAnswerForKey(liveKey, onLiveLookup) : null;
|
|
16604
|
+
const live = liveKey ? await liveReferenceAnswerForKey(liveKey, onLiveLookup, sourceSkips) : null;
|
|
16469
16605
|
if (live) {
|
|
16470
16606
|
answer = live.text;
|
|
16471
16607
|
via = "reference";
|
|
@@ -16680,7 +16816,7 @@ async function runAsk(query, { config, source, graph, focus, last, templates, me
|
|
|
16680
16816
|
|| (liveReference === "always" ? envelope?.parsed?.object : null);
|
|
16681
16817
|
let liveKey = null;
|
|
16682
16818
|
try { liveKey = supplementTerm ? cleanMissLiveTerm(supplementTerm, lexicon ?? undefined) : null; } catch { liveKey = null; }
|
|
16683
|
-
const live = liveKey ? await liveReferenceAnswerForKey(liveKey, onLiveLookup) : null;
|
|
16819
|
+
const live = liveKey ? await liveReferenceAnswerForKey(liveKey, onLiveLookup, sourceSkips) : null;
|
|
16684
16820
|
if (live) {
|
|
16685
16821
|
answer = `${answer}\nWikipedia adds: ${live.text}`;
|
|
16686
16822
|
await ingestReferenceArticle(memoryDir, live.key, live.article, cache, liveProvenanceTag, lexicon, synthesisBudget);
|
|
@@ -17664,7 +17800,8 @@ async function assertTurn(line, { memoryDir, sessionId, focus, lexicon = null, c
|
|
|
17664
17800
|
.join(", "),
|
|
17665
17801
|
};
|
|
17666
17802
|
return plainTurn(line, answer, { command: "assert", via: "assert", focus, canonical, goal: "teach/remember a new fact" });
|
|
17667
|
-
} catch {
|
|
17803
|
+
} catch (error) {
|
|
17804
|
+
rethrowPersistFailure(error);
|
|
17668
17805
|
return null; // grammar unavailable / write failed — fall through to the engine
|
|
17669
17806
|
}
|
|
17670
17807
|
}
|
|
@@ -18388,9 +18525,21 @@ async function answerWithoutFillerPrefix(input, options, missed) {
|
|
|
18388
18525
|
export async function runTurn(input, options = {}) {
|
|
18389
18526
|
const memoryDir = options?.memoryDir ?? null;
|
|
18390
18527
|
const before = await factRowSnapshot(memoryDir);
|
|
18391
|
-
let result
|
|
18392
|
-
|
|
18393
|
-
|
|
18528
|
+
let result;
|
|
18529
|
+
try {
|
|
18530
|
+
result = await dispatchTurn(input, options);
|
|
18531
|
+
const rescued = await answerWithoutFillerPrefix(input, options, result);
|
|
18532
|
+
if (rescued) result = rescued;
|
|
18533
|
+
} catch (error) {
|
|
18534
|
+
// Every write lane the dispatcher reaches — a rule teach, a retraction, a
|
|
18535
|
+
// game's board snapshot — reports a refused store the same way the teach
|
|
18536
|
+
// lane does. A rejected input is a different thing and travels on,
|
|
18537
|
+
// carrying the row and provenance the backend named.
|
|
18538
|
+
if (!isPersistUnavailable(error)) throw error;
|
|
18539
|
+
result = plainTurn(String(input ?? "").trim(), PERSIST_UNAVAILABLE_TEXT, {
|
|
18540
|
+
via: PERSIST_UNAVAILABLE_VIA, miss: true, focus: options?.focus ?? null,
|
|
18541
|
+
});
|
|
18542
|
+
}
|
|
18394
18543
|
if (!result || typeof result !== "object") return result;
|
|
18395
18544
|
return { ...result, factsTouched: await factsTouchedSince(memoryDir, before) };
|
|
18396
18545
|
}
|
|
@@ -18488,7 +18637,11 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
18488
18637
|
// an answer's typed content is in hand (runAsk, off the ask envelope's
|
|
18489
18638
|
// `discourse` referents); the caller re-threads whatever comes back.
|
|
18490
18639
|
const discourseHolder = { record: discourse ?? emptyDiscourseRecord() };
|
|
18491
|
-
|
|
18640
|
+
// Every external source this turn asked for and did not get, because its
|
|
18641
|
+
// circuit breaker had already given up on it. A name lands here only when
|
|
18642
|
+
// the skip changed what served the answer, and the trailer says so.
|
|
18643
|
+
const sourceSkips = new Set();
|
|
18644
|
+
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, laneVocab: laneVocabValue, domainPacks: domainPacksValue, newsState, newsConfig, newsProviders };
|
|
18492
18645
|
// A DISPATCHED turn (count / slash-command / ask) becomes the new "last
|
|
18493
18646
|
// answer" that why/say-more re-renders; a conversational turn does not.
|
|
18494
18647
|
// Every dispatched turn's result passes through finish() here — the LAST
|
|
@@ -18541,7 +18694,7 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
18541
18694
|
// Goal/canonical lines append onto the PRE-narration `finished` result
|
|
18542
18695
|
// `nextLast` was captured from, so a narrated turn still gets both short
|
|
18543
18696
|
// lines up top plus the full trace block after.
|
|
18544
|
-
return { ...withNarration(withCanonicalLine(withGoalLine(withRetrievalNote(finished, retrieval))), trace, fallbackGoal), last: nextLast, discourse: discourseHolder.record };
|
|
18697
|
+
return { ...withNarration(withCanonicalLine(withGoalLine(withSourceSkipNote(withRetrievalNote(finished, retrieval), sourceSkips))), trace, fallbackGoal), last: nextLast, discourse: discourseHolder.record };
|
|
18545
18698
|
};
|
|
18546
18699
|
|
|
18547
18700
|
// Slash-optional system commands: a bare leading command word ("stats",
|
|
@@ -18722,7 +18875,10 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
18722
18875
|
holder: researchHolder,
|
|
18723
18876
|
memoryDir,
|
|
18724
18877
|
lexicon,
|
|
18725
|
-
provider:
|
|
18878
|
+
provider: guardedResearchProvider(
|
|
18879
|
+
getResearchProvider({ minIntervalMs: resolvedResearchConfig.minIntervalMs, source: effectiveResearchSource }),
|
|
18880
|
+
sourceSkips,
|
|
18881
|
+
),
|
|
18726
18882
|
config: { ...resolvedResearchConfig, source: effectiveResearchSource },
|
|
18727
18883
|
planActive: Boolean(planHolder.state && !planHolder.state.done),
|
|
18728
18884
|
pagerActive: Boolean(Array.isArray(last?.detail?.pending?.items) && last.detail.pending.items.length),
|
|
@@ -19032,17 +19188,26 @@ async function dispatchTurn(input, { config, source = defaultSource, graph = nul
|
|
|
19032
19188
|
// Gated on memoryDir: only a session shell provides a write target, so a bare
|
|
19033
19189
|
// runTurn (tests, library callers) stays pure and falls through to the engine.
|
|
19034
19190
|
if (memoryDir) {
|
|
19035
|
-
|
|
19191
|
+
let asserted = null;
|
|
19192
|
+
let taxonomy = null;
|
|
19193
|
+
try {
|
|
19194
|
+
asserted = await assertTurn(workingLine, ctx);
|
|
19195
|
+
// Bare declarative taxonomy (hyphenated-instance membership, article-led
|
|
19196
|
+
// kind-of) — see bareTaxonomyTeach. Checked here because the ask engine
|
|
19197
|
+
// would otherwise parse these statements as inherits QUESTIONS.
|
|
19198
|
+
if (!asserted) taxonomy = await bareTaxonomyTeach(workingLine, ctx);
|
|
19199
|
+
} catch (error) {
|
|
19200
|
+
if (!isPersistUnavailable(error)) throw error;
|
|
19201
|
+
note(trace, "lane: declarative teach — the sentence parsed, but the store would not take the write");
|
|
19202
|
+
const refusedTurn = plainTurn(workingLine, PERSIST_UNAVAILABLE_TEXT, { via: PERSIST_UNAVAILABLE_VIA, miss: true, focus });
|
|
19203
|
+
return withLast(refusedTurn, "teach/remember a new fact");
|
|
19204
|
+
}
|
|
19036
19205
|
if (asserted) {
|
|
19037
19206
|
note(trace, "goal: teach/remember a new fact (declarative ACE sentence)");
|
|
19038
19207
|
note(trace, "lane: assertTurn — grammar/ace.mjs parseAce matched a full triple with no residue");
|
|
19039
19208
|
asserted.lane = "teach";
|
|
19040
19209
|
return withLast(asserted, "teach/remember a new fact");
|
|
19041
19210
|
}
|
|
19042
|
-
// Bare declarative taxonomy (hyphenated-instance membership, article-led
|
|
19043
|
-
// kind-of) — see bareTaxonomyTeach. Checked here because the ask engine
|
|
19044
|
-
// would otherwise parse these statements as inherits QUESTIONS.
|
|
19045
|
-
const taxonomy = await bareTaxonomyTeach(workingLine, ctx);
|
|
19046
19211
|
if (taxonomy) {
|
|
19047
19212
|
note(trace, "goal: teach/remember a new fact (bare declarative taxonomy)");
|
|
19048
19213
|
note(trace, "lane: bareTaxonomyTeach — hyphenated-instance or article-led kind-of declarative, stored before the ask engine could parse it as a question");
|