feat(v0.4.0): vNext — closed-loop world model + settlement contract

Implements the vNext architecture from the research doc: demote the noisy
multi-rail planner in favour of a closed loop (world truth → invariant check)
plus a single utility-driven goal authority.

L1 services (fix no_drop / silent pathfinder hang first):
- InventoryLedger: diff-based "did I actually get it" verifier; acquire-food
  now confirms via ledger.gainedSince instead of the unreliable count/event.
- MotionService.gotoSafe: wall-clock timeout + progress watchdog +
  path_update(noPath/timeout) → structured {reached|stuck|timeout|nopath}.

L3 plan — unify the three competing rails (curriculum/manifesto/storyline):
- Settlement Contract: ordered M0–M9 milestones, each invariant-checked
  against an authoritative world view (early steps delegate to the proven
  curriculum; late game adds farming).
- InvariantChecker + predicate library; GoalManager selects the lowest unmet
  milestone via utility argmax (food-urgency preempts, DEPS-style).
- Wired into the scheduler: bot.js precomputes snapshot.contract; reflex.js
  consumes it in place of the storyline rail. Manifesto L0 still preempts.

Eval + robustness:
- Village Score (single 0..1 metric) on the snapshot + TUI "build" line.
- survive.dig-in skill + dusk_dig_in mode (exposed at night, no bed → cover).
- approach_block helper (GoalNear + lookAt, avoids GoalLookAtBlock #341).

+28 new tests (450 total green). LLM remains entirely off the tick path.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-28 11:05:43 +03:00
co-authored by Claude Opus 4.7
parent 15b6c11002
commit 2a6cc0cdb1
23 changed files with 1662 additions and 36 deletions
+31 -8
View File
@@ -39,6 +39,28 @@ function foodCount(bot) {
return bot.inventory.items().reduce((sum, item) => allowed.has(item.name) ? sum + item.count : sum, 0);
}
// Success here is "did edible food actually enter the inventory". Trusting the
// `playerCollect` event or `nearestEntity` going away is what produced the live
// `no_drop` false-failures (research §A.4). When the InventoryLedger is wired
// (ctx.ledger) we verify by diff against a baseline; otherwise we fall back to
// a local before/after count so the skill still works in unit tests.
function makeFoodTracker(ctx, bot) {
const isFood = (name) => foods(bot).has(name);
if (ctx?.ledger) {
ctx.ledger.update(bot);
const base = ctx.ledger.mark();
return {
mode: "ledger",
gained() {
ctx.ledger.update(bot);
return ctx.ledger.gainedSince(base, isFood);
},
};
}
const before = foodCount(bot);
return { mode: "count", gained: () => foodCount(bot) - before };
}
function nearestPassiveFoodMob(bot, maxDistance = 32) {
const here = bot?.entity?.position;
if (!here) return null;
@@ -127,15 +149,16 @@ export const skill = Object.freeze({
},
async execute(ctx) {
const bot = ctx.bot;
const before = foodCount(bot);
const track = makeFoodTracker(ctx, bot);
const picked = await pickupNearbyDrops(bot);
if (foodCount(bot) > before) {
const dropGain = track.gained();
if (dropGain > 0) {
return {
ok: true,
code: "done",
detail: { source: "drop", picked },
worldDelta: { acquiredFood: foodCount(bot) - before, source: "drop" },
detail: { source: "drop", picked, verify: track.mode },
worldDelta: { acquiredFood: dropGain, source: "drop" },
};
}
@@ -184,15 +207,15 @@ export const skill = Object.freeze({
}
await new Promise((r) => setTimeout(r, 1_000));
await pickupNearbyDrops(bot);
const after = foodCount(bot);
if (after <= before) {
const huntGain = track.gained();
if (huntGain <= 0) {
return { ok: false, code: "no_drop", detail: `hunted ${target.entity.name} but found no edible drop`, worldDelta: null };
}
return {
ok: true,
code: "done",
detail: { source: "hunt", mob: target.entity.name, gained: after - before },
worldDelta: { acquiredFood: after - before, source: "hunt", mob: target.entity.name },
detail: { source: "hunt", mob: target.entity.name, gained: huntGain, verify: track.mode },
worldDelta: { acquiredFood: huntGain, source: "hunt", mob: target.entity.name },
};
} catch (e) {
warn("action", `survive.acquire-food failed: ${e.message}`);