@polycode-projects/the-mechanical-code-talker 5.0.21 → 5.0.23
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 +4 -0
- package/bin/tmct.mjs +20 -5
- package/package.json +1 -1
- package/src/adapters/toml-config.mjs +5 -0
- package/src/domain/cli-verbs.mjs +1 -0
- package/src/domain/domain.mjs +8 -0
- package/src/domain/interpret/normalize.mjs +86 -1
- package/src/domain/router/drive.mjs +45 -4
- package/src/domain/router/recognize.mjs +345 -0
- package/src/domain/scene-compose.mjs +54 -16
- package/src/domain/scene-random.mjs +104 -0
- package/src/domain/sprite-animation.mjs +102 -0
- package/src/domain/world-snapshot.mjs +25 -0
- package/src/services/adventure-autoplay.mjs +41 -5
- package/src/services/adventure.mjs +137 -34
- package/src/services/chat-session.mjs +5 -1
- package/src/services/chat.mjs +401 -13
- package/src/services/sprite-catalog-viz.mjs +408 -184
- package/src/surfaces/web/adventure-browser-entry.mjs +11 -0
- package/src/surfaces/web/memory-ask-browser.bundle.js +119 -119
- package/src/surfaces/web/sprites-browser-entry.mjs +17 -2
|
@@ -26,11 +26,10 @@
|
|
|
26
26
|
// fact simply has nothing for this module to infer a goal toward.
|
|
27
27
|
import { findActionPath } from "../domain/planning.mjs";
|
|
28
28
|
import { loadMemory, readFactRows } from "../adapters/memory/core.mjs";
|
|
29
|
+
import { baseSubjectOf } from "../domain/world-snapshot.mjs";
|
|
30
|
+
import { declaredGoals } from "../domain/router/recognize.mjs";
|
|
29
31
|
import { foldWorldState, adventureTurn, worldActionRows } from "./adventure.mjs";
|
|
30
32
|
|
|
31
|
-
const SNAPSHOT_RE = /^(.+)@turn(\d+)$/;
|
|
32
|
-
const baseSubjectOf = (subject) => SNAPSHOT_RE.exec(subject)?.[1] ?? subject;
|
|
33
|
-
|
|
34
33
|
const isTypedRow = (rows, subject, type) =>
|
|
35
34
|
(rows || []).some((r) => r.subject === subject && r.predicate === "rdf:type" && r.object === type);
|
|
36
35
|
|
|
@@ -103,6 +102,27 @@ function exposedContainers(exposedRows, exposedState) {
|
|
|
103
102
|
return [...ids].filter((id) => roomOfSubject(id, exposedRows, exposedState) != null).sort();
|
|
104
103
|
}
|
|
105
104
|
|
|
105
|
+
/** The admissible plans for a world carry goal, searched over the EXPOSED
|
|
106
|
+
* fold only — a plan through ground this run has not walked is not
|
|
107
|
+
* admissible. Each plan is the operator sequence a recognized trace would
|
|
108
|
+
* have to match: one `mgx:currently-in` step per room hop, then the
|
|
109
|
+
* `mgx:located-in` step the final take writes. Returns `[]` when the
|
|
110
|
+
* target's room isn't exposed yet or no seen path reaches it, so the goal
|
|
111
|
+
* is excluded rather than guessed at — this hook stays local to autoplay
|
|
112
|
+
* rather than landing in the shared recognizer, since only autoplay's own
|
|
113
|
+
* exposure-bounded search can tell an admissible plan from a guess. */
|
|
114
|
+
export function expandWorldGoal(goal, { here, exposedRows, exposedState }) {
|
|
115
|
+
if (goal?.source !== "world" || !goal.goalState?.subject) return [];
|
|
116
|
+
const target = goal.goalState.subject;
|
|
117
|
+
if (carriedByPlayer(exposedState, target)) return [[]];
|
|
118
|
+
const targetRoom = roomOfSubject(target, exposedRows || [], exposedState);
|
|
119
|
+
if (!targetRoom) return [];
|
|
120
|
+
if (targetRoom === here) return [["mgx:located-in"]];
|
|
121
|
+
const path = findActionPath(here, (room) => room === targetRoom, exposedExitApplyActions(exposedState));
|
|
122
|
+
if (!path || !path.actions.length) return [];
|
|
123
|
+
return [[...path.actions.map(() => "mgx:currently-in"), "mgx:located-in"]];
|
|
124
|
+
}
|
|
125
|
+
|
|
106
126
|
/** One tick's worth of progress toward standing in `targetRoom` and then
|
|
107
127
|
* issuing `finalCommand` once there — the same path-then-act shape the
|
|
108
128
|
* objective fetch above already uses, generalized so opening/unlocking a
|
|
@@ -158,7 +178,20 @@ export async function runAdventureAutoplayTick(memoryDir, opts = {}) {
|
|
|
158
178
|
|
|
159
179
|
const exposedRows = exposedFacts(rows, exposed);
|
|
160
180
|
const exposedState = foldWorldState(exposedRows);
|
|
161
|
-
|
|
181
|
+
// The world's objective is one declared goal among N, gathered by the same
|
|
182
|
+
// enumerator /goals prints. Exposure still bounds it: a marker the run has
|
|
183
|
+
// not seen is not in exposedRows, so it is not in this set either.
|
|
184
|
+
const goals = declaredGoals({ worldRows: exposedRows, ruleRows: [] }, {});
|
|
185
|
+
const worldGoals = goals.filter((g) => g.source === "world");
|
|
186
|
+
const objectiveId = worldGoals.length === 1 ? worldGoals[0].goalState.subject : null;
|
|
187
|
+
|
|
188
|
+
if (worldGoals.length > 1) {
|
|
189
|
+
return {
|
|
190
|
+
turn: state.turnCount,
|
|
191
|
+
goal: `stalled — this world declares ${worldGoals.length} objectives (${worldGoals.map((g) => g.goalState.subject).join(", ")}) and nothing says which one to chase.`,
|
|
192
|
+
plan: null, done: false, stalled: true, exposedRoomIds: exposed,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
162
195
|
|
|
163
196
|
// Win: the objective is already carried — checked against the FULL fold,
|
|
164
197
|
// since what the player itself carries is always self-evidently known,
|
|
@@ -276,7 +309,10 @@ export async function runAdventureAutoplayTick(memoryDir, opts = {}) {
|
|
|
276
309
|
const path = findActionPath(here, hasUnexposedExit, exposedExitApplyActions(exposedState));
|
|
277
310
|
if (!path || !path.actions.length) {
|
|
278
311
|
return {
|
|
279
|
-
turn: state.turnCount,
|
|
312
|
+
turn: state.turnCount,
|
|
313
|
+
goal: goals.length
|
|
314
|
+
? `stalled — every reachable room is already explored, and nothing I've done fits any of the ${goals.length} declared goals for this world.`
|
|
315
|
+
: "stalled — every reachable room is already explored, and this world declares no goal to head for.",
|
|
280
316
|
plan: null, done: false, stalled: true, exposedRoomIds: exposed,
|
|
281
317
|
};
|
|
282
318
|
}
|
|
@@ -9,11 +9,13 @@
|
|
|
9
9
|
// share the slot.
|
|
10
10
|
|
|
11
11
|
import { worldProvenanceTag } from "../domain/worlds-pack.mjs";
|
|
12
|
+
import { parseSnapshotSubject, snapshotSubject } from "../domain/world-snapshot.mjs";
|
|
12
13
|
import { parseImperative, OBJECT_PRONOUNS } from "../domain/grammar/ace.mjs";
|
|
13
14
|
import { loadLexicon, withProperNames, classify } from "../domain/grammar/lexicon.mjs";
|
|
14
15
|
import { register as registerReferent, bind as bindDiscourseForm } from "../domain/discourse.mjs";
|
|
15
16
|
import { createCompletionsGraphAdapter } from "../domain/completions/graph-adapter.mjs";
|
|
16
17
|
import { actionFamilies } from "../domain/router/taught.mjs";
|
|
18
|
+
import { declaredGoals, recognizeGoal, traceOfWorldRows } from "../domain/router/recognize.mjs";
|
|
17
19
|
import { compileDomain, precondHolds, roleBinding } from "../domain/domain.mjs";
|
|
18
20
|
import { getWorldsPackProvider } from "../adapters/corpus/worlds-pack.mjs";
|
|
19
21
|
import { appendFacts, appendRule, loadMemory, normFactTerm, readFactRows, readRuleRows } from "../adapters/memory/core.mjs";
|
|
@@ -21,6 +23,7 @@ import { COMPLETIONS_STORE, generateCompletion } from "./completions.mjs";
|
|
|
21
23
|
import { parseEditorLine, planTaughtTriple } from "./adventure-editor.mjs";
|
|
22
24
|
import { parseMudEditorLine, planTaughtMudTriple } from "./mud-editor.mjs";
|
|
23
25
|
import { worldTeachTurn } from "./world-teach.mjs";
|
|
26
|
+
import { expandWorldGoal } from "./adventure-autoplay.mjs";
|
|
24
27
|
|
|
25
28
|
// ---- recognizers: the closed opening/stop set --------------------------------
|
|
26
29
|
|
|
@@ -177,11 +180,6 @@ async function resumedPosition(memoryDir) {
|
|
|
177
180
|
|
|
178
181
|
// ---- the world-state fold ----------------------------------------------------
|
|
179
182
|
|
|
180
|
-
// A snapshot subject is `base@turnN`, or `base@epochE@turnN` once a recast has
|
|
181
|
-
// moved the world past epoch 0 — the fold below reads both, and epoch-0 writes
|
|
182
|
-
// keep the bare form so an unrecast store never changes shape.
|
|
183
|
-
const SNAPSHOT_RE = /^(.+?)@(?:epoch(\d+)@)?turn(\d+)$/;
|
|
184
|
-
|
|
185
183
|
/** Which run of the world a store is on. Recasting a shared world (mud.html's
|
|
186
184
|
* RESET, a slider, the scenario dropdown) reopens the same deterministic
|
|
187
185
|
* instance ids over a fresh store while peers may still hold the old run's
|
|
@@ -199,21 +197,13 @@ export function worldEpochFact(epoch) {
|
|
|
199
197
|
return { subject: WORLD_EPOCH_SUBJECT, predicate: WORLD_EPOCH_PREDICATE, object: String(epoch) };
|
|
200
198
|
}
|
|
201
199
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return m ? { base: m[1], epoch: m[2] ? Number(m[2]) : 0, turn: Number(m[3]) } : null;
|
|
209
|
-
}
|
|
200
|
+
// The snapshot-subject grammar itself (`{ base, epoch, turn }` for a stamped
|
|
201
|
+
// subject, null for a base row) lives in domain/world-snapshot.mjs, the one
|
|
202
|
+
// place every reader — this lane, autoplay, the recognizer — parses it from.
|
|
203
|
+
// Re-exported here so every existing importer of snapshotSubject and
|
|
204
|
+
// parseSnapshotSubject keeps working.
|
|
205
|
+
export { snapshotSubject, parseSnapshotSubject };
|
|
210
206
|
|
|
211
|
-
/** The snapshot subject a turn writes: bare `@turnN` while the world is on
|
|
212
|
-
* epoch 0 (every store that has never been recast, and every fact written
|
|
213
|
-
* before epochs existed), the epoch-stamped form after. */
|
|
214
|
-
export function snapshotSubject(base, turn, epoch = 0) {
|
|
215
|
-
return epoch > 0 ? `${base}@epoch${epoch}@turn${turn}` : `${base}@turn${turn}`;
|
|
216
|
-
}
|
|
217
207
|
const PLACEMENT_PREDICATES = new Set([
|
|
218
208
|
"mgx:currently-in", "mgx:located-in", "mgx:fixed-in", "mgx:stands-locked-in", "mgx:hidden-in",
|
|
219
209
|
]);
|
|
@@ -303,7 +293,7 @@ export function isMudStatePredicate(predicate) {
|
|
|
303
293
|
export function worldIndividualNames(rows) {
|
|
304
294
|
const names = new Set();
|
|
305
295
|
for (const row of rows || []) {
|
|
306
|
-
if (
|
|
296
|
+
if (parseSnapshotSubject(row.subject)) continue;
|
|
307
297
|
if (row.predicate === "rdf:type" || PLACEMENT_PREDICATES.has(row.predicate)) names.add(row.subject);
|
|
308
298
|
if (EXIT_PREDICATE_RE.test(row.predicate)) { names.add(row.subject); names.add(row.object); }
|
|
309
299
|
}
|
|
@@ -332,8 +322,8 @@ export function foldWorldState(factRows) {
|
|
|
332
322
|
if (Number.isInteger(marked) && marked > epoch) epoch = marked;
|
|
333
323
|
continue;
|
|
334
324
|
}
|
|
335
|
-
const
|
|
336
|
-
if (
|
|
325
|
+
const snap = parseSnapshotSubject(row.subject);
|
|
326
|
+
if (snap && snap.epoch > epoch) epoch = snap.epoch;
|
|
337
327
|
}
|
|
338
328
|
const placements = new Map(); // subject -> { predicate, object, turn, epoch }
|
|
339
329
|
const positions = new Map(); // subject -> { predicate, object, turn, epoch }
|
|
@@ -345,11 +335,11 @@ export function foldWorldState(factRows) {
|
|
|
345
335
|
!prior || rowEpoch > prior.epoch || (rowEpoch === prior.epoch && turn >= prior.turn);
|
|
346
336
|
for (const row of rows) {
|
|
347
337
|
if (row.predicate === WORLD_EPOCH_PREDICATE) continue;
|
|
348
|
-
const
|
|
349
|
-
const base =
|
|
350
|
-
const rowEpoch =
|
|
351
|
-
const turn =
|
|
352
|
-
if (
|
|
338
|
+
const snap = parseSnapshotSubject(row.subject);
|
|
339
|
+
const base = snap ? snap.base : row.subject;
|
|
340
|
+
const rowEpoch = snap ? snap.epoch : epoch;
|
|
341
|
+
const turn = snap ? snap.turn : 0;
|
|
342
|
+
if (snap && rowEpoch === epoch) turnCount = Math.max(turnCount, turn);
|
|
353
343
|
if (PLACEMENT_PREDICATES.has(row.predicate)) {
|
|
354
344
|
if (outranks(rowEpoch, turn, placements.get(base))) placements.set(base, { predicate: row.predicate, object: row.object, turn, epoch: rowEpoch });
|
|
355
345
|
continue;
|
|
@@ -369,7 +359,7 @@ export function foldWorldState(factRows) {
|
|
|
369
359
|
continue;
|
|
370
360
|
}
|
|
371
361
|
const exit = EXIT_PREDICATE_RE.exec(row.predicate);
|
|
372
|
-
if (exit && !
|
|
362
|
+
if (exit && !snap) {
|
|
373
363
|
if (!exits.has(row.subject)) exits.set(row.subject, new Map());
|
|
374
364
|
exits.get(row.subject).set(exit[1], row.object);
|
|
375
365
|
}
|
|
@@ -946,7 +936,7 @@ export function worldDigestRows(rows, state, actingSubject = "player") {
|
|
|
946
936
|
.filter(([, place]) => OUT_OF_PLAY_PLACES.has(place.object))
|
|
947
937
|
.map(([subject]) => subject));
|
|
948
938
|
for (const row of rows || []) {
|
|
949
|
-
if (
|
|
939
|
+
if (parseSnapshotSubject(row.subject)) continue; // folded above
|
|
950
940
|
if (gone.has(row.subject)) continue; // out of the world entirely
|
|
951
941
|
// Room text comes from the world source only. A merged corpus overlaps a
|
|
952
942
|
// room's own vocabulary ("library rdfs:subClassOf literary study"), and
|
|
@@ -2052,6 +2042,17 @@ async function worldOpennessAnswer(line, { memoryDir }) {
|
|
|
2052
2042
|
const WORLD_WHERE_AM_I_RE = /^where\s+am\s+i(?:\s+now)?[?.!\s]*$/i;
|
|
2053
2043
|
const WORLD_OPTIONS_RE = /^(?:what\s+can\s+i\s+do(?:\s+(?:here|now))?|what\s+are\s+my\s+options|what\s+(?:should|do)\s+i\s+do(?:\s+(?:here|now))?|what\s+now)[?.!\s]*$/i;
|
|
2054
2044
|
const WORLD_QUEST_RE = /^(?:what(?:'s|\s+is)\s+(?:the\s+|my\s+)?(?:quest|goal|objective|mission|aim)|what\s+am\s+i\s+(?:trying\s+to\s+do|(?:supposed|meant)\s+to\s+do)|what\s+do\s+i\s+do\s+here)[?.!\s]*$/i;
|
|
2045
|
+
// "what am I doing" — the RECOGNITION question, and a different one from
|
|
2046
|
+
// WORLD_QUEST_RE's "what is my goal". That asks what the world declared; this
|
|
2047
|
+
// asks what THIS run's own moves fit. The two live side by side because the
|
|
2048
|
+
// answers can honestly disagree: a player heading somewhere the world never
|
|
2049
|
+
// marked has a real goal and no declared one.
|
|
2050
|
+
const WORLD_RECOGNIZE_RE = /^(?:what\s+am\s+i\s+doing(?:\s+(?:here|now))?|what\s+have\s+i\s+been\s+doing|what\s+was\s+i\s+doing)[?.!\s]*$/i;
|
|
2051
|
+
// "what is the housekeeper doing" — the same recognizer, over that character's
|
|
2052
|
+
// own @turnN rows. An NPC's scheduled move writes the same snapshot a player
|
|
2053
|
+
// move writes, so nothing here is NPC-specific beyond which actor's steps the
|
|
2054
|
+
// trace reads.
|
|
2055
|
+
const WORLD_RECOGNIZE_OTHER_RE = /^what(?:'s|\s+is|\s+are)\s+(?:the\s+)?(.+?)\s+doing(?:\s+(?:here|now))?[?.!\s]*$/i;
|
|
2055
2056
|
// "who is here" — the room's cast, the question a shared world invites the
|
|
2056
2057
|
// moment a second animal walks in. Answered from the same currently-in
|
|
2057
2058
|
// placements the talk verb resolves against, so who is named is exactly who
|
|
@@ -2075,18 +2076,99 @@ const WORLD_KNOWN_FOOD_RE = new RegExp(
|
|
|
2075
2076
|
"i",
|
|
2076
2077
|
);
|
|
2077
2078
|
|
|
2079
|
+
// A recognition tie lists its survivors with a short Oxford-comma "or" join —
|
|
2080
|
+
// the same shape chat.mjs's own joinOr produces for a discourse tie, kept as a
|
|
2081
|
+
// small local copy rather than an import across the file boundary.
|
|
2082
|
+
const joinOr = (a) => (a.length > 2 ? `${a.slice(0, -1).join(", ")}, or ${a[a.length - 1]}`
|
|
2083
|
+
: a.length === 2 ? `${a[0]} or ${a[1]}` : (a[0] ?? ""));
|
|
2084
|
+
|
|
2085
|
+
/** One subject's own @turnN (or @epochE@turnN) rows out of a wider row set —
|
|
2086
|
+
* what traceOfWorldRows folds into a step list. traceOfWorldRows reads
|
|
2087
|
+
* whatever rows it is given; narrowing to one subject here is what keeps a
|
|
2088
|
+
* "what am I doing" trace from reading another actor's moves as its own. */
|
|
2089
|
+
function subjectSnapshotRows(rows, subject) {
|
|
2090
|
+
return (rows || []).filter((row) => parseSnapshotSubject(row.subject)?.base === subject);
|
|
2091
|
+
}
|
|
2092
|
+
|
|
2093
|
+
/** The world's own cast member `spoken` names, matched by plain id (worlds
|
|
2094
|
+
* name their cast in plain lowercase words — "housekeeper", "gardener" —
|
|
2095
|
+
* same as any other individual), or null when nobody in this world goes by
|
|
2096
|
+
* that name. */
|
|
2097
|
+
function resolveCastMemberByName(rows, state, spoken) {
|
|
2098
|
+
const norm = String(spoken).trim().toLowerCase();
|
|
2099
|
+
if (!norm) return null;
|
|
2100
|
+
return worldIndividualNames(rows).find((id) => id.toLowerCase() === norm && isCastMember(rows, state, id)) ?? null;
|
|
2101
|
+
}
|
|
2102
|
+
|
|
2103
|
+
/** `subject`'s room BEFORE any observed step — the base (unstamped) row a
|
|
2104
|
+
* world writes at turn 0, ignoring every later @turnN move. A recognition
|
|
2105
|
+
* plan has to start where the trace itself starts: expandWorldGoal's search
|
|
2106
|
+
* from the subject's CURRENT room would return only the few steps still
|
|
2107
|
+
* left to take, which a trace of the moves already made can never fit. */
|
|
2108
|
+
function subjectStartRoom(actionRows, subject) {
|
|
2109
|
+
const baseRows = actionRows.filter((row) => !parseSnapshotSubject(row.subject));
|
|
2110
|
+
return foldWorldState(baseRows).placements.get(subject)?.object ?? null;
|
|
2111
|
+
}
|
|
2112
|
+
|
|
2113
|
+
/** The recognition surface's four outcomes — recognized, tied, reject, or
|
|
2114
|
+
* nothing observed yet — over `subject`'s own trace. `thirdPerson` renders
|
|
2115
|
+
* the same recognition in the third person for an NPC intent question
|
|
2116
|
+
* instead of the player's own "what am I doing". Only world and taught goals
|
|
2117
|
+
* are in play here (`tools: []` screens out the tool/maintenance goals a
|
|
2118
|
+
* world never declares), so "the goals this world declares" names what it
|
|
2119
|
+
* actually reads as declared, not the whole router's registry. */
|
|
2120
|
+
function recognitionOutcomeAnswer(subject, { actionRows, ruleRows, state, thirdPerson }) {
|
|
2121
|
+
const trace = traceOfWorldRows(subjectSnapshotRows(actionRows, subject), { actor: subject });
|
|
2122
|
+
if (!trace.length) {
|
|
2123
|
+
return answer(
|
|
2124
|
+
"you haven't done anything yet — make a move and ask again.",
|
|
2125
|
+
`ADVENTURE — recognition aside: no observed step for ${subject} yet`,
|
|
2126
|
+
{ goal: "see what I'm recognized as doing" },
|
|
2127
|
+
);
|
|
2128
|
+
}
|
|
2129
|
+
const goals = declaredGoals({ worldRows: actionRows, ruleRows }, { tools: [] });
|
|
2130
|
+
const origin = subjectStartRoom(actionRows, subject);
|
|
2131
|
+
const expand = (goal) => (origin ? expandWorldGoal(goal, { here: origin, exposedRows: actionRows, exposedState: state }) : []);
|
|
2132
|
+
const r = recognizeGoal(trace, goals, { expand });
|
|
2133
|
+
const note = `ADVENTURE — recognition aside: ${trace.length} observed step(s) against ${goals.length} declared goal(s); ${r.why}`;
|
|
2134
|
+
|
|
2135
|
+
if (r.goal) {
|
|
2136
|
+
const target = r.goal.label.replace(/^carry /, "");
|
|
2137
|
+
const text = thirdPerson
|
|
2138
|
+
? `the ${subject} is heading for ${target} — the last ${trace.length} moves it made are a subsequence of the route that gets there.`
|
|
2139
|
+
: `you're heading for ${target} — your last ${trace.length} move${trace.length === 1 ? "" : "s"} ${trace.length === 1 ? "is" : "are"} a subsequence of the route that gets you there.`;
|
|
2140
|
+
return answer(text, note, { goal: "see what I'm recognized as doing" });
|
|
2141
|
+
}
|
|
2142
|
+
if (r.reject) {
|
|
2143
|
+
const text = thirdPerson
|
|
2144
|
+
? `nothing the ${subject} has done fits any of the ${goals.length} goals this world declares.`
|
|
2145
|
+
: `nothing you've done so far fits any of the ${goals.length} goals this world declares. Say "what is my goal" to see what it does declare.`;
|
|
2146
|
+
return answer(text, note, { miss: true, goal: "see what I'm recognized as doing" });
|
|
2147
|
+
}
|
|
2148
|
+
const labels = r.ambiguous.map((g) => g.label);
|
|
2149
|
+
const text = thirdPerson
|
|
2150
|
+
? `what the ${subject} has done so far fits ${labels.length} goals equally well: ${joinOr(labels)}. A few more moves would tell them apart.`
|
|
2151
|
+
: `what you've done so far fits ${labels.length} goals equally well: ${joinOr(labels)}. A few more moves would tell them apart, so I won't pick one.`;
|
|
2152
|
+
return answer(text, note, { goal: "see what I'm recognized as doing" });
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2078
2155
|
/** The in-game orientation asides, answered from the world fold: the player's
|
|
2079
|
-
* room, the room's real affordances,
|
|
2080
|
-
*
|
|
2156
|
+
* room, the room's real affordances, the world's objective, and what a
|
|
2157
|
+
* trace — the player's own, or a named character's — is recognized as
|
|
2158
|
+
* doing. Null when the line is none of them, so an ordinary question keeps
|
|
2159
|
+
* its lane. */
|
|
2081
2160
|
async function worldContextAnswer(line, { memoryDir, actingSubject = "player" }) {
|
|
2082
2161
|
const l = String(line).trim();
|
|
2083
2162
|
const asksWhere = WORLD_WHERE_AM_I_RE.test(l);
|
|
2084
2163
|
const asksOptions = WORLD_OPTIONS_RE.test(l);
|
|
2085
2164
|
const asksQuest = WORLD_QUEST_RE.test(l);
|
|
2086
2165
|
const asksWhoIsHere = WORLD_WHO_HERE_RE.test(l);
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2166
|
+
const asksRecognize = WORLD_RECOGNIZE_RE.test(l);
|
|
2167
|
+
const recognizeOther = WORLD_RECOGNIZE_OTHER_RE.exec(l);
|
|
2168
|
+
if (!asksWhere && !asksOptions && !asksQuest && !asksWhoIsHere && !asksRecognize && !recognizeOther) return null;
|
|
2169
|
+
let memory;
|
|
2170
|
+
try { memory = await loadMemory(memoryDir); } catch { return null; }
|
|
2171
|
+
const rows = readFactRows(memory);
|
|
2090
2172
|
const state = foldWorldState(worldActionRows(rows));
|
|
2091
2173
|
const here = state.placements.get(actingSubject)?.object ?? null;
|
|
2092
2174
|
|
|
@@ -2116,6 +2198,27 @@ async function worldContextAnswer(line, { memoryDir, actingSubject = "player" })
|
|
|
2116
2198
|
);
|
|
2117
2199
|
}
|
|
2118
2200
|
|
|
2201
|
+
if (asksRecognize) {
|
|
2202
|
+
const actionRows = worldActionRows(rows);
|
|
2203
|
+
const ruleRows = readRuleRows(memory);
|
|
2204
|
+
return recognitionOutcomeAnswer(actingSubject, { actionRows, ruleRows, state, thirdPerson: false });
|
|
2205
|
+
}
|
|
2206
|
+
|
|
2207
|
+
if (recognizeOther) {
|
|
2208
|
+
const spoken = recognizeOther[1].trim();
|
|
2209
|
+
const resolved = resolveCastMemberByName(rows, state, spoken);
|
|
2210
|
+
if (!resolved) {
|
|
2211
|
+
return answer(
|
|
2212
|
+
`there's nobody called "${spoken}" in this world.`,
|
|
2213
|
+
`ADVENTURE — recognition aside: "${spoken}" resolves to no cast member this world names`,
|
|
2214
|
+
{ miss: true },
|
|
2215
|
+
);
|
|
2216
|
+
}
|
|
2217
|
+
const actionRows = worldActionRows(rows);
|
|
2218
|
+
const ruleRows = readRuleRows(memory);
|
|
2219
|
+
return recognitionOutcomeAnswer(resolved, { actionRows, ruleRows, state, thirdPerson: true });
|
|
2220
|
+
}
|
|
2221
|
+
|
|
2119
2222
|
const objectiveId = rows.find((r) => r.predicate === "mgx:is-objective" && r.object === "true")?.subject ?? null;
|
|
2120
2223
|
return objectiveId
|
|
2121
2224
|
? answer(
|
|
@@ -29,6 +29,7 @@ import { resolveExtensions, mergedLexiconExtra, mergedLaneVocab, defaultCodeLane
|
|
|
29
29
|
import { runTurn, hasSeededVocabulary, vocabExampleHint, codeDomainActive as codeDomainActiveOf } from "./chat.mjs";
|
|
30
30
|
import { resolveGameConfig } from "../domain/game-config.mjs";
|
|
31
31
|
import { emptyRecord, resolveDiscourseConfig } from "../domain/discourse.mjs";
|
|
32
|
+
import { resolveRecognitionConfig } from "../domain/router/recognize.mjs";
|
|
32
33
|
import { resolveResearchConfig } from "./research.mjs";
|
|
33
34
|
import { normalizeResearchChoice } from "../adapters/corpus/research-source.mjs";
|
|
34
35
|
import { sessionLogHeaderMarkdown, sessionLogTurnMarkdown, sessionLogEndMarkdown } from "./session-log-format.mjs";
|
|
@@ -486,6 +487,9 @@ export async function createSession({
|
|
|
486
487
|
// The typed discourse record ([discourse] max_referents caps it) — session-scoped
|
|
487
488
|
// like the focus, threaded turn to turn, never persisted.
|
|
488
489
|
let discourseRecord = emptyRecord(resolveDiscourseConfig(toml));
|
|
490
|
+
// The recognition trace cap ([recognition] max_trace) — resolved once per
|
|
491
|
+
// session, read by the surfaces that fold a trace back out of the store.
|
|
492
|
+
const recognitionConfig = resolveRecognitionConfig(toml);
|
|
489
493
|
let closed = false;
|
|
490
494
|
|
|
491
495
|
return {
|
|
@@ -516,7 +520,7 @@ export async function createSession({
|
|
|
516
520
|
async turn(line) {
|
|
517
521
|
let result;
|
|
518
522
|
try {
|
|
519
|
-
result = await runTurn(line, { config, source, graph, focus, last, memoryDir, sessionId, env, lexicon, narrate: narrateOn, liveReference: liveReferenceOn, researchSource: researchSourceOn, vocabHint, tel, biasByBundle, planState, gameConfig, researchState, researchConfig, discourse: discourseRecord, actingSubject, codeDomainActive: domainActive, laneVocab, domainPacks });
|
|
523
|
+
result = await runTurn(line, { config, source, graph, focus, last, memoryDir, sessionId, env, lexicon, narrate: narrateOn, liveReference: liveReferenceOn, researchSource: researchSourceOn, vocabHint, tel, biasByBundle, planState, gameConfig, recognitionConfig, researchState, researchConfig, discourse: discourseRecord, actingSubject, codeDomainActive: domainActive, laneVocab, domainPacks });
|
|
520
524
|
} catch (e) {
|
|
521
525
|
const ts = new Date().toISOString();
|
|
522
526
|
const message = e instanceof Error ? e.message : String(e);
|