@polycode-projects/the-mechanical-code-talker 5.0.26 → 5.0.28
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/corpus/worlds/index.json.gz +0 -0
- package/corpus/worlds/manifest.json +27 -17
- package/corpus/worlds/shards/river-crossing.jsonl.gz +0 -0
- package/corpus/worlds/shards/town-square-chapel.jsonl.gz +0 -0
- package/corpus/worlds/shards/town-square-market.jsonl.gz +0 -0
- package/corpus/worlds/shards/town-square.jsonl.gz +0 -0
- package/corpus/worlds/src/river-crossing.jsonl +29 -0
- package/corpus/worlds/src/town-square-chapel.jsonl +12 -8
- package/corpus/worlds/src/town-square-market.jsonl +12 -8
- package/corpus/worlds/src/town-square.jsonl +12 -8
- package/package.json +2 -1
- package/src/adapters/memory/inspect.mjs +37 -0
- package/src/domain/agent-traits.mjs +282 -0
- package/src/domain/ask.mjs +19 -6
- package/src/domain/choice-question.mjs +135 -6
- package/src/domain/codegraph.mjs +8 -1
- package/src/domain/el-classify.mjs +39 -7
- package/src/domain/fact-phrase.mjs +7 -4
- package/src/domain/interpret/normalize.mjs +58 -2
- package/src/domain/town-square-world.mjs +44 -19
- package/src/services/adventure.mjs +5 -16
- package/src/services/agent-editor.mjs +216 -0
- package/src/services/chat-session.mjs +26 -5
- package/src/services/chat.mjs +221 -58
- package/src/services/mudiii-scene.mjs +32 -5
- package/src/services/mudiii-turn.mjs +7 -3
- package/src/services/mudiii-viz.mjs +215 -1
- package/src/services/news-viz.mjs +489 -0
- package/src/services/predator-prey.mjs +157 -24
- package/src/surfaces/web/chat-browser-entry.mjs +69 -3
- package/src/surfaces/web/memory-ask-browser.bundle.js +155 -155
- package/src/surfaces/web/mudiii-browser-entry.mjs +35 -0
- package/src/surfaces/web/news-browser-entry.mjs +384 -0
- package/src/surfaces/web/turn-session.mjs +13 -9
|
@@ -47,6 +47,9 @@ import { worldProvenanceTag } from "../domain/worlds-pack.mjs";
|
|
|
47
47
|
import { mulberry32 } from "../domain/seeded-random.mjs";
|
|
48
48
|
import { fnv1a32 } from "../domain/hash.mjs";
|
|
49
49
|
import { DEFAULT_GAME_CONFIG } from "../domain/game-config.mjs";
|
|
50
|
+
import {
|
|
51
|
+
agentTraitsOf, classChainOf, fearedClassesOf, instanceFactsFrom, rowsDeclareDrives, traitValuesOf,
|
|
52
|
+
} from "../domain/agent-traits.mjs";
|
|
50
53
|
import { objectClassChain, parseSnapshotSubject, snapshotSubject, worldEpochFact, WORLD_EPOCH_PREDICATE } from "./adventure.mjs";
|
|
51
54
|
|
|
52
55
|
export { DEFAULT_VISION_RADIUS, believedCellOf, nearestBelievedTarget, beliefSnapshotFor };
|
|
@@ -82,6 +85,38 @@ export function rolesHunting(role, roles = MUDIII_ROLES) {
|
|
|
82
85
|
return CAST_ROLES.filter((other) => rolesHuntedBy(other, roles).includes(role));
|
|
83
86
|
}
|
|
84
87
|
|
|
88
|
+
/** The rows-aware sibling of rolesHuntedBy: the class names THIS subject
|
|
89
|
+
* moves toward, read off its own chain's mgx:pursues rows. Empty for a
|
|
90
|
+
* subject whose world states none — on a board whose rows state no drives
|
|
91
|
+
* at all, the decision chain falls back to the cast's role links. Pure. */
|
|
92
|
+
export function pursuedBy(rows, subject) {
|
|
93
|
+
return traitValuesOf(rows, subject, "mgx:pursues");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The rows-aware sibling of rolesHunting: the class names THIS subject
|
|
97
|
+
* moves away from — its declared mgx:evades set when its chain states one,
|
|
98
|
+
* otherwise every class whose members declare mgx:consumes for a class on
|
|
99
|
+
* this subject's own chain. One appetite row carries both the hunt and the
|
|
100
|
+
* flight, so a world never states the fear twice. Pure. */
|
|
101
|
+
export function fearedBy(rows, subject) {
|
|
102
|
+
return fearedClassesOf(rows, subject);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Provenance for the trait rows a spawn copies from a class onto an
|
|
106
|
+
* instance — its own tag family, apart from the world tag, so the ledger,
|
|
107
|
+
* the editors and a later respawn can tell a copied row from an authored
|
|
108
|
+
* one. */
|
|
109
|
+
const spawnProvenanceTag = (kind, id, epoch) => `spawn:${kind}:${id}@epoch${epoch}`;
|
|
110
|
+
|
|
111
|
+
/** The trait rows a fresh mint of `id` (an instance of `kind`) carries as its
|
|
112
|
+
* own, ready to append: instanceFactsFrom minus the rdf:type row the mint
|
|
113
|
+
* itself already writes, each stamped with the spawn provenance. */
|
|
114
|
+
function spawnTraitCopies(rows, kind, id, epoch) {
|
|
115
|
+
return instanceFactsFrom(rows, kind, id)
|
|
116
|
+
.filter((copied) => copied.predicate !== "rdf:type")
|
|
117
|
+
.map((copied) => ({ ...copied, provenance: spawnProvenanceTag(kind, id, epoch) }));
|
|
118
|
+
}
|
|
119
|
+
|
|
85
120
|
const PLACEMENT_PREDICATE = "mgx:currently-in";
|
|
86
121
|
const MASS_PREDICATE = "mgx:hasMass";
|
|
87
122
|
const MOOD_PREDICATE = "mgx:feels";
|
|
@@ -587,7 +622,7 @@ function goalLine(kind, { subject, cell, arrived, boardNoun = "square", catches
|
|
|
587
622
|
// arrival, and a cast that sets no interval never spawns that kind at all.
|
|
588
623
|
|
|
589
624
|
function runEcologyPass({
|
|
590
|
-
state, layout, roles, config, turn, epoch,
|
|
625
|
+
state, rows, layout, roles, config, turn, epoch,
|
|
591
626
|
postMovePlacements, postMoveMass, liveItemIds, itemCellOf, itemMassOf, foodIds,
|
|
592
627
|
}) {
|
|
593
628
|
const k = turn;
|
|
@@ -597,6 +632,17 @@ function runEcologyPass({
|
|
|
597
632
|
const carriesPrey = config.carryPreyToWeb === true;
|
|
598
633
|
const laysEggs = config.layEggs === true;
|
|
599
634
|
const webbedAt = (c) => hasActiveWebAt(layout, state, k, c.x, c.y, config.webDurationTurns);
|
|
635
|
+
// On a board whose rows state drives, contact only removes what the eater's
|
|
636
|
+
// own mgx:consumes chain names — an appetite nobody declared eats nothing.
|
|
637
|
+
// On a board with no drive rows, the role pairing decides alone, exactly as
|
|
638
|
+
// it always has.
|
|
639
|
+
const factDriven = rowsDeclareDrives(rows);
|
|
640
|
+
const eats = (eaterId, targetId) => {
|
|
641
|
+
if (!factDriven) return true;
|
|
642
|
+
const appetite = traitValuesOf(rows, eaterId, "mgx:consumes");
|
|
643
|
+
const chain = classChainOf(rows, targetId);
|
|
644
|
+
return appetite.some((eaten) => chain.includes(eaten));
|
|
645
|
+
};
|
|
600
646
|
|
|
601
647
|
const predators = [...postMovePlacements.keys()].filter((id) => roleOfId(id, roles) === "predator").sort();
|
|
602
648
|
const prey = [...postMovePlacements.keys()].filter((id) => roleOfId(id, roles) === "prey").sort();
|
|
@@ -613,6 +659,7 @@ function runEcologyPass({
|
|
|
613
659
|
if (takenAgents.has(preyId)) continue;
|
|
614
660
|
const qc = postMovePlacements.get(preyId);
|
|
615
661
|
if (pc.x !== qc.x || pc.y !== qc.y) continue;
|
|
662
|
+
if (!eats(predatorId, preyId)) continue;
|
|
616
663
|
takenAgents.add(preyId);
|
|
617
664
|
const gained = finalMass.get(preyId) ?? 0;
|
|
618
665
|
finalMass.set(predatorId, (finalMass.get(predatorId) ?? 0) + gained);
|
|
@@ -634,6 +681,7 @@ function runEcologyPass({
|
|
|
634
681
|
if (claimed.has(preyId)) continue;
|
|
635
682
|
const qc = postMovePlacements.get(preyId);
|
|
636
683
|
if (pc.x !== qc.x || pc.y !== qc.y) continue;
|
|
684
|
+
if (!eats(predatorId, preyId)) continue;
|
|
637
685
|
carriedBy.set(predatorId, preyId);
|
|
638
686
|
claimed.add(preyId);
|
|
639
687
|
events.push({ type: "catch-prey", predator: predatorId, prey: preyId, cell: cellId(pc.x, pc.y) });
|
|
@@ -669,6 +717,7 @@ function runEcologyPass({
|
|
|
669
717
|
if (takenItems.has(itemId)) continue;
|
|
670
718
|
if (!foodIds.has(itemId)) continue;
|
|
671
719
|
if (itemCellOf.get(itemId) !== here) continue;
|
|
720
|
+
if (!eats(preyId, itemId)) continue;
|
|
672
721
|
takenItems.add(itemId);
|
|
673
722
|
const gained = itemMassOf.get(itemId) ?? 0;
|
|
674
723
|
finalMass.set(preyId, (finalMass.get(preyId) ?? 0) + gained);
|
|
@@ -743,6 +792,7 @@ function runEcologyPass({
|
|
|
743
792
|
const hatchlingId = `${roles.predator.idPrefix}-${nextHatchlingNum}`;
|
|
744
793
|
nextHatchlingNum += 1;
|
|
745
794
|
const hatchlingMass = share + (i === 0 ? remainder : 0);
|
|
795
|
+
writes.push(...spawnTraitCopies(rows, roles.predator.kind, hatchlingId, epoch));
|
|
746
796
|
writes.push({ subject: hatchlingId, predicate: "rdf:type", object: roles.predator.kind });
|
|
747
797
|
writes.push({ subject: stamp(hatchlingId), predicate: PLACEMENT_PREDICATE, object: eggCell });
|
|
748
798
|
writes.push({ subject: stamp(hatchlingId), predicate: MASS_PREDICATE, object: String(hatchlingMass) });
|
|
@@ -781,12 +831,14 @@ function runEcologyPass({
|
|
|
781
831
|
const preyId = `${roles.prey.idPrefix}-${1 + maxIdSuffix(state.placements.keys(), roles.prey.kind)}`;
|
|
782
832
|
const cell = seededPick(free, seedKey(layout.name, epoch, k, preyId, "spawn"));
|
|
783
833
|
occupied.add(cell);
|
|
834
|
+
const preySpawnMass = agentTraitsOf(rows, roles.prey.kind).mass ?? config.preyInitialMass;
|
|
835
|
+
writes.push(...spawnTraitCopies(rows, roles.prey.kind, preyId, epoch));
|
|
784
836
|
writes.push({ subject: preyId, predicate: "rdf:type", object: roles.prey.kind });
|
|
785
837
|
writes.push({ subject: stamp(preyId), predicate: PLACEMENT_PREDICATE, object: cell });
|
|
786
|
-
writes.push({ subject: stamp(preyId), predicate: MASS_PREDICATE, object: String(
|
|
838
|
+
writes.push({ subject: stamp(preyId), predicate: MASS_PREDICATE, object: String(preySpawnMass) });
|
|
787
839
|
writes.push({ subject: stamp(preyId), predicate: FACING_PREDICATE, object: DEFAULT_FACING });
|
|
788
|
-
events.push({ type: "spawn-prey", agent: preyId, cell, mass: round2(
|
|
789
|
-
spawned.push({ id: preyId, role: "prey", cell, mass:
|
|
840
|
+
events.push({ type: "spawn-prey", agent: preyId, cell, mass: round2(preySpawnMass) });
|
|
841
|
+
spawned.push({ id: preyId, role: "prey", cell, mass: preySpawnMass });
|
|
790
842
|
}
|
|
791
843
|
}
|
|
792
844
|
|
|
@@ -858,7 +910,8 @@ export async function startTownSquareGame(memoryDir, {
|
|
|
858
910
|
layout, agents = null, predatorCount = null, preyCount = null,
|
|
859
911
|
config = DEFAULT_GAME_CONFIG.mudiii, roles = MUDIII_ROLES, epoch = 0,
|
|
860
912
|
} = {}) {
|
|
861
|
-
const
|
|
913
|
+
const rows = readFactRows(await loadMemory(memoryDir));
|
|
914
|
+
const state = foldTownSquareState(rows);
|
|
862
915
|
const firstPredator = `${roles.predator.idPrefix}-1`;
|
|
863
916
|
if (state.placements.get(firstPredator)?.epoch === epoch) return { started: false, facts: [] };
|
|
864
917
|
|
|
@@ -874,14 +927,21 @@ export async function startTownSquareGame(memoryDir, {
|
|
|
874
927
|
const spec = roster[id];
|
|
875
928
|
const role = spec.role ?? roleOfId(id, roles);
|
|
876
929
|
const kind = role === "predator" ? roles.predator.kind : roles.prey.kind;
|
|
877
|
-
const mass = spec.mass
|
|
930
|
+
const mass = spec.mass
|
|
931
|
+
?? agentTraitsOf(rows, kind).mass
|
|
932
|
+
?? (role === "predator" ? config.predatorInitialMass : config.preyInitialMass);
|
|
933
|
+
// The class's traits copy onto the instance BEFORE its own stamped rows:
|
|
934
|
+
// both rank as turn 0 of this epoch in the fold, and the fold takes the
|
|
935
|
+
// later row on a tied rank, so an explicit roster mass (a fixture's
|
|
936
|
+
// seeded starvation) must land after the copied class default.
|
|
937
|
+
facts.push(...spawnTraitCopies(rows, kind, id, epoch));
|
|
878
938
|
facts.push({ subject: id, predicate: "rdf:type", object: kind });
|
|
879
939
|
facts.push({ subject: stamp(id), predicate: PLACEMENT_PREDICATE, object: spec.cell });
|
|
880
940
|
facts.push({ subject: stamp(id), predicate: MASS_PREDICATE, object: String(mass) });
|
|
881
941
|
facts.push({ subject: stamp(id), predicate: MOOD_PREDICATE, object: "calm" });
|
|
882
942
|
facts.push({ subject: stamp(id), predicate: FACING_PREDICATE, object: spec.facing ?? DEFAULT_FACING });
|
|
883
943
|
}
|
|
884
|
-
await appendFacts(memoryDir, facts.map((f) => ({ ...f, provenance: worldProvenanceTag(layout.name) })));
|
|
944
|
+
await appendFacts(memoryDir, facts.map((f) => ({ ...f, provenance: f.provenance ?? worldProvenanceTag(layout.name) })));
|
|
885
945
|
return { started: true, facts };
|
|
886
946
|
}
|
|
887
947
|
|
|
@@ -1056,6 +1116,32 @@ function readLiveBoard(rows, state, { config, roles }) {
|
|
|
1056
1116
|
};
|
|
1057
1117
|
}
|
|
1058
1118
|
|
|
1119
|
+
/** `rows` widened with a bare `rdf:type` row for every rostered id that has
|
|
1120
|
+
* none — the rows every trait read below resolves against. A hand-taught
|
|
1121
|
+
* board can place `fox-1` by id without ever typing it (the pre-placement
|
|
1122
|
+
* then makes the mint's idempotency guard skip the roster write), and the
|
|
1123
|
+
* class chain would dead-end on the bare id while the roster itself already
|
|
1124
|
+
* knows the kind. The synthetic row states only what `liveOfKind` has
|
|
1125
|
+
* already concluded from the id, so this stays a pure function of the row
|
|
1126
|
+
* set. */
|
|
1127
|
+
function withRosterTypeRows(rows, { predators, prey, liveItemIds, roles }) {
|
|
1128
|
+
const typed = new Set();
|
|
1129
|
+
for (const row of rows || []) {
|
|
1130
|
+
if (row.predicate === "rdf:type") typed.add(row.subject);
|
|
1131
|
+
}
|
|
1132
|
+
const synthetic = [];
|
|
1133
|
+
for (const id of predators) {
|
|
1134
|
+
if (!typed.has(id)) synthetic.push({ subject: id, predicate: "rdf:type", object: roles.predator.kind });
|
|
1135
|
+
}
|
|
1136
|
+
for (const id of prey) {
|
|
1137
|
+
if (!typed.has(id)) synthetic.push({ subject: id, predicate: "rdf:type", object: roles.prey.kind });
|
|
1138
|
+
}
|
|
1139
|
+
for (const id of liveItemIds) {
|
|
1140
|
+
if (!typed.has(id)) synthetic.push({ subject: id, predicate: "rdf:type", object: kindOfItem(id, roles) });
|
|
1141
|
+
}
|
|
1142
|
+
return synthetic.length ? [...rows, ...synthetic] : rows;
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1059
1145
|
/** The render payload's `items` half — `{ id: { kind, cell } }` — over
|
|
1060
1146
|
* `liveItemIds`, skipping anything in `taken` (a tick's eaten set; a resting
|
|
1061
1147
|
* board passes none). Pure. */
|
|
@@ -1146,6 +1232,33 @@ export async function runTownSquareTick(memoryDir, {
|
|
|
1146
1232
|
const agentsOfRoles = (roleList, exceptId) =>
|
|
1147
1233
|
roleList.flatMap((r) => liveIdsOfRole[r] ?? []).filter((id) => id !== exceptId).sort();
|
|
1148
1234
|
|
|
1235
|
+
// The one gate between the two ways a cast can be driven. Rows that state
|
|
1236
|
+
// any drive at all drive EVERY threat/quarry/forage read below through the
|
|
1237
|
+
// trait resolver; rows that state none leave the injected roles object and
|
|
1238
|
+
// config numbers deciding alone, so a cast written before the trait
|
|
1239
|
+
// vocabulary existed behaves exactly as it always did.
|
|
1240
|
+
const traitRows = withRosterTypeRows(rows, { predators, prey, liveItemIds, roles });
|
|
1241
|
+
const factDriven = rowsDeclareDrives(traitRows);
|
|
1242
|
+
const traitsCache = new Map();
|
|
1243
|
+
const traitsOf = (subject) => {
|
|
1244
|
+
if (!traitsCache.has(subject)) traitsCache.set(subject, agentTraitsOf(traitRows, subject));
|
|
1245
|
+
return traitsCache.get(subject);
|
|
1246
|
+
};
|
|
1247
|
+
const chainCache = new Map();
|
|
1248
|
+
const chainSetOf = (subject) => {
|
|
1249
|
+
if (!chainCache.has(subject)) chainCache.set(subject, new Set(classChainOf(traitRows, subject)));
|
|
1250
|
+
return chainCache.get(subject);
|
|
1251
|
+
};
|
|
1252
|
+
const liveAgents = [...predators, ...prey].sort();
|
|
1253
|
+
const agentsOfClasses = (classNames, exceptId) => (classNames.length
|
|
1254
|
+
? liveAgents.filter((id) => id !== exceptId && classNames.some((c) => chainSetOf(id).has(c)))
|
|
1255
|
+
: []);
|
|
1256
|
+
const forageTargetsOf = (agentId) => {
|
|
1257
|
+
const appetite = traitsOf(agentId).consumes;
|
|
1258
|
+
if (!appetite.length) return [];
|
|
1259
|
+
return liveItemIds.filter((id) => foodIds.has(id) && appetite.some((c) => chainSetOf(id).has(c)));
|
|
1260
|
+
};
|
|
1261
|
+
|
|
1149
1262
|
const decide = (agentId, role) => {
|
|
1150
1263
|
const fromCell = parseCellId(state.placements.get(agentId).cell);
|
|
1151
1264
|
// The visitor's hand, checked before any of the belief chain below. A
|
|
@@ -1153,7 +1266,8 @@ export async function runTownSquareTick(memoryDir, {
|
|
|
1153
1266
|
// it would have on a turn nobody touched.
|
|
1154
1267
|
const driven = acceptedManualMove(manualMoves?.[agentId], fromCell, applyActions);
|
|
1155
1268
|
const restingFacing = state.facing.get(agentId)?.value ?? DEFAULT_FACING;
|
|
1156
|
-
const visionRadius =
|
|
1269
|
+
const visionRadius = traitsOf(agentId).visionRadius
|
|
1270
|
+
?? (role === "predator" ? config.predatorVisionRadius : config.preyVisionRadius);
|
|
1157
1271
|
const beliefOpts = { visionRadius, toldFacts };
|
|
1158
1272
|
// True unless a caller explicitly turns it off. A config object built by
|
|
1159
1273
|
// hand (a fixture, a test, an older tmct.toml read before this key
|
|
@@ -1166,13 +1280,23 @@ export async function runTownSquareTick(memoryDir, {
|
|
|
1166
1280
|
// visionRadius: Infinity call, not new belief machinery. The rival-threat
|
|
1167
1281
|
// lookup below stays on beliefOpts either way: this switch is about food.
|
|
1168
1282
|
const foodBeliefOpts = foodVisionGated ? beliefOpts : { ...beliefOpts, visionRadius: Infinity };
|
|
1169
|
-
// Who counts as a threat
|
|
1170
|
-
//
|
|
1171
|
-
//
|
|
1172
|
-
//
|
|
1173
|
-
|
|
1174
|
-
const huntsAgents =
|
|
1175
|
-
|
|
1283
|
+
// Who counts as a threat, who counts as quarry and what counts as food
|
|
1284
|
+
// all come off the agent's OWN trait rows when the world states drives,
|
|
1285
|
+
// and off the cast's role links when it states none. Nothing hunts a
|
|
1286
|
+
// predator on either shipped board, so a predator's threat list is empty
|
|
1287
|
+
// and a second predator in view is just another animal on the square.
|
|
1288
|
+
const huntsAgents = factDriven
|
|
1289
|
+
? pursuedBy(traitRows, agentId).length > 0
|
|
1290
|
+
: rolesHuntedBy(role, roles).length > 0;
|
|
1291
|
+
const hunters = factDriven
|
|
1292
|
+
? agentsOfClasses(fearedBy(traitRows, agentId), agentId)
|
|
1293
|
+
: agentsOfRoles(rolesHunting(role, roles), agentId);
|
|
1294
|
+
const quarryCandidates = !huntsAgents ? [] : (factDriven
|
|
1295
|
+
? agentsOfClasses(pursuedBy(traitRows, agentId), agentId)
|
|
1296
|
+
: agentsOfRoles(rolesHuntedBy(role, roles), agentId));
|
|
1297
|
+
const forageCandidates = huntsAgents ? [] : (factDriven
|
|
1298
|
+
? forageTargetsOf(agentId)
|
|
1299
|
+
: [...foodIds].sort());
|
|
1176
1300
|
const threat = driven ? null : nearestBelievedTarget(agentId, fromCell, hunters, state, beliefOpts);
|
|
1177
1301
|
|
|
1178
1302
|
let rung;
|
|
@@ -1235,7 +1359,7 @@ export async function runTownSquareTick(memoryDir, {
|
|
|
1235
1359
|
} else if (threat) {
|
|
1236
1360
|
const towardFood = huntsAgents
|
|
1237
1361
|
? null
|
|
1238
|
-
: nearestBelievedTarget(agentId, fromCell,
|
|
1362
|
+
: nearestBelievedTarget(agentId, fromCell, forageCandidates, state, foodBeliefOpts);
|
|
1239
1363
|
if (blendsPreyDecision && !huntsAgents && towardFood) {
|
|
1240
1364
|
// The one case the two rungs disagree about: this prey believes a
|
|
1241
1365
|
// predator AND food, so a strict order has to pick between them and a
|
|
@@ -1270,8 +1394,8 @@ export async function runTownSquareTick(memoryDir, {
|
|
|
1270
1394
|
}
|
|
1271
1395
|
} else {
|
|
1272
1396
|
const quarry = huntsAgents
|
|
1273
|
-
? nearestBelievedTarget(agentId, fromCell,
|
|
1274
|
-
: nearestBelievedTarget(agentId, fromCell,
|
|
1397
|
+
? nearestBelievedTarget(agentId, fromCell, quarryCandidates, state, beliefOpts)
|
|
1398
|
+
: nearestBelievedTarget(agentId, fromCell, forageCandidates, state, foodBeliefOpts);
|
|
1275
1399
|
if (quarry) {
|
|
1276
1400
|
rung = huntsAgents ? "chase" : "forage";
|
|
1277
1401
|
const path = findActionPath(fromCell, (s) => s.x === quarry.cell.x && s.y === quarry.cell.y, applyActions, { stateKey: pathStateKey });
|
|
@@ -1343,8 +1467,11 @@ export async function runTownSquareTick(memoryDir, {
|
|
|
1343
1467
|
const postMoveMass = new Map();
|
|
1344
1468
|
for (const id of [...predators, ...prey]) {
|
|
1345
1469
|
const role = agents[id].role;
|
|
1346
|
-
const
|
|
1347
|
-
const
|
|
1470
|
+
const traits = traitsOf(id);
|
|
1471
|
+
const drain = traits.massDrainPerTurn
|
|
1472
|
+
?? (role === "predator" ? config.predatorMassDecrementPerTurn : config.preyMassDecrementPerTurn);
|
|
1473
|
+
const start = traits.mass
|
|
1474
|
+
?? (role === "predator" ? config.predatorInitialMass : config.preyInitialMass);
|
|
1348
1475
|
const prior = state.mass.get(id)?.value ?? start;
|
|
1349
1476
|
postMoveMass.set(id, Math.max(0, prior - drain));
|
|
1350
1477
|
}
|
|
@@ -1356,7 +1483,7 @@ export async function runTownSquareTick(memoryDir, {
|
|
|
1356
1483
|
}
|
|
1357
1484
|
|
|
1358
1485
|
const pass = runEcologyPass({
|
|
1359
|
-
state, layout: lay, roles, config, turn: k, epoch,
|
|
1486
|
+
state, rows: traitRows, layout: lay, roles, config, turn: k, epoch,
|
|
1360
1487
|
postMovePlacements, postMoveMass, liveItemIds, itemCellOf, itemMassOf, foodIds,
|
|
1361
1488
|
});
|
|
1362
1489
|
|
|
@@ -1445,7 +1572,7 @@ export async function runTownSquareTick(memoryDir, {
|
|
|
1445
1572
|
|
|
1446
1573
|
const turnMarker = { subject: stamp(BOARD_SUBJECT), predicate: TURN_PLAYED_PREDICATE, object: String(k) };
|
|
1447
1574
|
const writes = [...movementWrites, ...pass.writes, ...moodWrites, turnMarker];
|
|
1448
|
-
await appendFacts(memoryDir, writes.map((f) => ({ ...f, provenance: `${worldProvenanceTag(lay.name)}:turn${k}` })));
|
|
1575
|
+
await appendFacts(memoryDir, writes.map((f) => ({ ...f, provenance: f.provenance ?? `${worldProvenanceTag(lay.name)}:turn${k}` })));
|
|
1449
1576
|
|
|
1450
1577
|
return {
|
|
1451
1578
|
turn: k,
|
|
@@ -1488,6 +1615,9 @@ export async function townSquareBoard(memoryDir, {
|
|
|
1488
1615
|
const rows = readFactRows(await loadMemory(memoryDir));
|
|
1489
1616
|
const state = foldTownSquareState(rows);
|
|
1490
1617
|
const board = readLiveBoard(rows, state, { config, roles });
|
|
1618
|
+
const traitRows = withRosterTypeRows(rows, {
|
|
1619
|
+
predators: board.predators, prey: board.prey, liveItemIds: board.liveItemIds, roles,
|
|
1620
|
+
});
|
|
1491
1621
|
|
|
1492
1622
|
const agents = {};
|
|
1493
1623
|
const rostered = [
|
|
@@ -1496,8 +1626,11 @@ export async function townSquareBoard(memoryDir, {
|
|
|
1496
1626
|
];
|
|
1497
1627
|
for (const [id, role] of rostered) {
|
|
1498
1628
|
const cell = state.placements.get(id).cell;
|
|
1499
|
-
const
|
|
1500
|
-
const
|
|
1629
|
+
const traits = agentTraitsOf(traitRows, id);
|
|
1630
|
+
const visionRadius = traits.visionRadius
|
|
1631
|
+
?? (role === "predator" ? config.predatorVisionRadius : config.preyVisionRadius);
|
|
1632
|
+
const initialMass = traits.mass
|
|
1633
|
+
?? (role === "predator" ? config.predatorInitialMass : config.preyInitialMass);
|
|
1501
1634
|
agents[id] = {
|
|
1502
1635
|
role,
|
|
1503
1636
|
cell,
|
|
@@ -4,13 +4,24 @@
|
|
|
4
4
|
// Unlike memory-ask-browser-entry.mjs (factAnswer/factReadBack only), this
|
|
5
5
|
// exposes the FULL turn engine: createChatSession wraps the shared
|
|
6
6
|
// createTurnSession (turn-session.mjs) around chat.mjs's runTurn — the
|
|
7
|
-
// focus/last/planState/researchState threading src/services/chat-session.mjs's
|
|
7
|
+
// focus/last/planState/researchState/newsState threading src/services/chat-session.mjs's
|
|
8
8
|
// createSession.turn does, minus every filesystem side effect (no transcript
|
|
9
9
|
// log, no sidecar, no graph upsert). Memory is an in-memory Backend-B handle,
|
|
10
10
|
// optionally pre-loaded with a built seed payload (scripts/build-chat-seed.mjs),
|
|
11
11
|
// so teach turns, recall, proof chains and the honest miss all run
|
|
12
12
|
// client-side with zero I/O.
|
|
13
13
|
//
|
|
14
|
+
// The news lane's own state (newsState) rides turn-session.mjs's shared
|
|
15
|
+
// threading with no extra wiring here, the same way researchState already
|
|
16
|
+
// does. What IS this file's own job: a persistent newsConfig object (so a
|
|
17
|
+
// `/news add`/`/news interval` mutation survives turn to turn, the same
|
|
18
|
+
// reason liveReferenceOn/synthesisBudgetOn are held here rather than
|
|
19
|
+
// recreated per turn) and registerNewsProvider — the news lane's own
|
|
20
|
+
// provider-set stub seam, the same shape registerResearchProvider gives
|
|
21
|
+
// tests below. Neither building the default fetchers nor registering a stub
|
|
22
|
+
// set fires a fetch; a fetch only happens once the user's own turn actually
|
|
23
|
+
// runs `/news poll` or `/news enrich`.
|
|
24
|
+
//
|
|
14
25
|
// Two browser traps this file still owns, beyond what createTurnSession
|
|
15
26
|
// already covers (passing `env: {}` explicitly, since a browser has no
|
|
16
27
|
// `process` global; the crash-resistant catch fallback):
|
|
@@ -47,7 +58,13 @@ import { registerReferencePackProvider } from "../../adapters/corpus/reference-p
|
|
|
47
58
|
// provider is stubbed. The adapter is fetch-only, so it bundles as-is.
|
|
48
59
|
// registerResearchProvider is the research lane's sibling seam
|
|
49
60
|
// (simple.wikipedia.org) — same stubbing contract for its e2e tests.
|
|
50
|
-
import { registerLiveReferenceProvider, registerResearchProvider } from "../../adapters/corpus/wikipedia-live.mjs";
|
|
61
|
+
import { registerLiveReferenceProvider, registerResearchProvider, getResearchProvider } from "../../adapters/corpus/wikipedia-live.mjs";
|
|
62
|
+
// The news lane's own config resolver and contemporary-source registry —
|
|
63
|
+
// this session's default /news providers are built from the same fetcher
|
|
64
|
+
// factory news.html's own session uses (src/surfaces/web/news-browser-entry.mjs),
|
|
65
|
+
// just over the browser's own fetch rather than an injected test one.
|
|
66
|
+
import { resolveNewsConfig } from "../../services/news.mjs";
|
|
67
|
+
import { newsSourceRecords, normalizeNewsSourceIds, createNewsFetcher, preflightNewsUrl } from "../../adapters/corpus/news-sources.mjs";
|
|
51
68
|
// Best-effort IndexedDB persistence for the page's session store — the page
|
|
52
69
|
// decides when to save/load/clear; this entry only carries the wrapper
|
|
53
70
|
// across the bundle boundary.
|
|
@@ -82,6 +99,48 @@ import { graphAsk, enginePlan } from "./engine-surface.mjs";
|
|
|
82
99
|
* for `ask()` — a question about taught facts has a real graph to traverse
|
|
83
100
|
* while a code-structure question keeps its honest no-code-graph refusal.
|
|
84
101
|
*/
|
|
102
|
+
let registeredNewsProviders = null;
|
|
103
|
+
|
|
104
|
+
/** Swap chat.html's own `/news` providers set — `{ newsFetchers, getResearchProvider,
|
|
105
|
+
* preflightNewsUrl }`, the same stub seam registerResearchProvider gives tests
|
|
106
|
+
* above — so a test (or a future page control) can answer `/news` against a
|
|
107
|
+
* fixed set of sources instead of the real network. Pass null to restore the
|
|
108
|
+
* default: real fetchers, over the browser's own fetch, for every source the
|
|
109
|
+
* session's own newsConfig currently enables. Registering (or not) never
|
|
110
|
+
* fires a fetch by itself — only the user's own `/news poll`/`/news enrich`
|
|
111
|
+
* turn does. */
|
|
112
|
+
export function registerNewsProvider(providers) {
|
|
113
|
+
registeredNewsProviders = providers && typeof providers === "object" ? providers : null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The default `/news` providers for one session's current `newsConfig`:
|
|
117
|
+
* real fetchers for every enabled contemporary source (browser fetch, no
|
|
118
|
+
* request until a fetcher's own fetchItems() runs) and the same research
|
|
119
|
+
* provider `/wiki` and `research <topic>` already use for KB enrichment.
|
|
120
|
+
* Rebuilt only when the enabled source list has actually changed since the
|
|
121
|
+
* last call (`/news add` is the one turn that can change it), so an
|
|
122
|
+
* ordinary turn that never touches `/news` pays nothing repeated here. */
|
|
123
|
+
function newsProvidersFor(config) {
|
|
124
|
+
let cachedProviders = null;
|
|
125
|
+
let cachedKey = null;
|
|
126
|
+
return () => {
|
|
127
|
+
const key = normalizeNewsSourceIds(config.sources).join(",");
|
|
128
|
+
if (cachedProviders && cachedKey === key) return cachedProviders;
|
|
129
|
+
const newsFetchers = new Map();
|
|
130
|
+
for (const id of normalizeNewsSourceIds(config.sources)) {
|
|
131
|
+
const record = newsSourceRecords().find((r) => r.id === id);
|
|
132
|
+
if (record) newsFetchers.set(id, createNewsFetcher(record, { fetchImpl: (...args) => globalThis.fetch(...args) }));
|
|
133
|
+
}
|
|
134
|
+
cachedProviders = {
|
|
135
|
+
newsFetchers,
|
|
136
|
+
getResearchProvider: ({ source } = {}) => getResearchProvider({ source }),
|
|
137
|
+
preflightNewsUrl: (url) => preflightNewsUrl(url, { fetchImpl: (...args) => globalThis.fetch(...args) }),
|
|
138
|
+
};
|
|
139
|
+
cachedKey = key;
|
|
140
|
+
return cachedProviders;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
85
144
|
export function createChatSession({ seedPayload = null, vocabSeeded = false, liveReference = false, onLiveLookup = null, synthesisBudget = 12, digestStructures = null } = {}) {
|
|
86
145
|
setDigestStructures(digestStructures || []);
|
|
87
146
|
const memoryDir = createInMemoryStore();
|
|
@@ -117,12 +176,19 @@ export function createChatSession({ seedPayload = null, vocabSeeded = false, liv
|
|
|
117
176
|
// The auto-synthesis budget for this session's learn-on-miss loads — the
|
|
118
177
|
// page's slider sets it; 0 stores article facts without any entailed rows.
|
|
119
178
|
let synthesisBudgetOn = Number.isFinite(synthesisBudget) ? synthesisBudget : 12;
|
|
179
|
+
// This session's own `/news` config — one persistent, mutable object (not
|
|
180
|
+
// recreated per turn), so a `/news add`/`/news interval` mutation survives
|
|
181
|
+
// turn to turn the same way it does in a CLI session's newsConfig.
|
|
182
|
+
const newsConfig = resolveNewsConfig(null);
|
|
183
|
+
const defaultNewsProviders = newsProvidersFor(newsConfig);
|
|
120
184
|
|
|
121
185
|
const session = createTurnSession({
|
|
122
186
|
memoryDir, graph: codeGraph, lexicon, sessionId, vocabHint,
|
|
123
187
|
buildExtraOptions: () => ({
|
|
124
188
|
liveReference: liveReferenceOn, onLiveLookup,
|
|
125
189
|
synthesisBudget: synthesisBudgetOn,
|
|
190
|
+
newsConfig,
|
|
191
|
+
newsProviders: registeredNewsProviders ?? defaultNewsProviders(),
|
|
126
192
|
}),
|
|
127
193
|
// `result.liveReference` mirrors a `/wiki on|off|supplement|always`
|
|
128
194
|
// command back into this session's own toggle state.
|
|
@@ -186,7 +252,7 @@ publishTmctSurface({
|
|
|
186
252
|
plan: enginePlan,
|
|
187
253
|
page: {
|
|
188
254
|
registerWinkModel, registerReferencePackProvider, registerLiveReferenceProvider,
|
|
189
|
-
registerResearchProvider, normFactTerm, vocabExampleHint, memoryStats,
|
|
255
|
+
registerResearchProvider, registerNewsProvider, normFactTerm, vocabExampleHint, memoryStats,
|
|
190
256
|
openPersistedStore, exportFactsJsonl, researchedFactRows,
|
|
191
257
|
splitSentences: splitSentencesPreservingPaths,
|
|
192
258
|
},
|