fix(v0.3.1): mechanical food/stuck fixes — bot reaches the chicken now

The wedge wasn't only in the manifesto layer; several mechanical bugs
kept the bot in a dead random-walk:

- storyline / manifesto / curriculum: "local food" now means an edible
  passive mob within <=32 blocks. A distant chicken or a cod no longer
  fools the bot into dispatching acquire-food (which then fails on
  no_path). Long-range food goes through scout-food instead.

- scout-food: partial approach to a target now counts as progress
  (approached_target, e.g. moved:14); a blocked heading is NOT counted
  as movement; added blind/tunnel fallback so it doesn't die when the
  pathfinder can't route cleanly.

- acquire-food: on no_path it now also tries a blind/tunnel approach to
  the animal; no_drop routes back into food scouting instead of giving
  up.

- explore.far / relocate / flee: fewer false "done" results (micro-steps
  no longer counted as success), more genuine escapes from stuck.

- scripts/show-story.js: live IPC now actually renders the current
  storyline step.

Verification: scripts/lint-patch.js clean; npm test 404/404 green; bot
relaunched in tmux `pepa`. Live logs show real progress — bot switched
to survive.scout-food, approached the chicken (approached_target
moved:14), then reached survive.acquire-food: hunting chicken. Food
isn't fully closed yet but the remaining issue is concrete pickup/drop,
not dead random-walk.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-28 09:20:07 +03:00
co-authored by Claude Opus 4.7
parent b68d4b3ee7
commit 1cf60f81e9
19 changed files with 548 additions and 106 deletions
+51 -4
View File
@@ -8,6 +8,7 @@ const { pathfinder, goals, Movements } = pathfinderPkg;
import { info, warn } from "../log.js";
import { foods } from "./groups.js";
import { blindWalkOrTunnelOut } from "./explore-far.js";
const PASSIVE_FOOD_MOBS = new Set(["cow", "pig", "chicken", "sheep", "rabbit", "mooshroom"]);
@@ -61,6 +62,41 @@ function nearbyDroppedItems(bot, maxDistance = 8) {
.sort((a, b) => a.distance - b.distance);
}
function horizontalDistance(a, b) {
return Math.hypot((b?.x ?? 0) - (a?.x ?? 0), (b?.z ?? 0) - (a?.z ?? 0));
}
function yawToward(from, to) {
if (!from || !to) return null;
const dx = to.x - from.x;
const dz = to.z - from.z;
if (Math.hypot(dx, dz) < 0.5) return null;
return -Math.atan2(dx, dz);
}
async function fallbackApproachFoodMob(bot, target, err) {
try { bot.pathfinder?.stop?.(); } catch {}
const start = bot.entity.position.clone?.() ?? { ...bot.entity.position };
const alreadyMoved = horizontalDistance(start, bot.entity.position);
if (alreadyMoved >= 4) {
return { ok: true, moved: alreadyMoved, mode: "pathfinder_partial", error: err?.message ?? "path failed" };
}
const yaw = yawToward(bot.entity.position, target.entity.position);
if (yaw === null) return { ok: false, moved: 0, error: err?.message ?? "path failed" };
const blind = await blindWalkOrTunnelOut(bot, {
yaw,
dirName: `toward-${target.entity.name}`,
blindMs: 8_000,
minMove: 4,
reason: `acquire-food target ${target.entity.name}`,
});
const moved = horizontalDistance(start, bot.entity.position);
if (blind.ok || moved >= 4) {
return { ok: true, moved, mode: "blind_target", error: err?.message ?? "path failed" };
}
return { ok: false, moved, error: err?.message ?? "path failed" };
}
async function pickupNearbyDrops(bot) {
ensurePathfinder(bot);
setMovementsForTravel(bot);
@@ -115,7 +151,18 @@ export const skill = Object.freeze({
"pathToFoodMob",
);
} catch (e) {
return { ok: false, code: "no_path", detail: e.message, worldDelta: null };
const approached = await fallbackApproachFoodMob(bot, target, e);
const current = Object.values(bot.entities ?? {}).find((entity) => entity.id === target.entity.id);
const dist = current?.position?.distanceTo(bot.entity.position) ?? Infinity;
if (!approached.ok) return { ok: false, code: "no_path", detail: e.message, worldDelta: null };
if (dist > 4) {
return {
ok: false,
code: "approached_target",
detail: { target: target.entity.name, moved: Math.round(approached.moved), mode: approached.mode, error: approached.error },
worldDelta: { moved: Math.round(approached.moved), target: target.entity.name, mode: approached.mode },
};
}
}
info("action", `survive.acquire-food: hunting ${target.entity.name} (${target.distance.toFixed(1)}m)`);
@@ -153,11 +200,11 @@ export const skill = Object.freeze({
}
},
recover(ctx, result) {
if (result.code === "no_target" || result.code === "no_path") {
return { hint: "wander", reason: "need to search for passive food mobs" };
if (result.code === "no_target" || result.code === "no_path" || result.code === "approached_target" || result.code === "no_drop") {
return { hint: "scout-food", reason: "need a long-range food search, not local acquire-food retry" };
}
return null;
},
});
export const _internal = { foodCount, nearestPassiveFoodMob };
export const _internal = { foodCount, nearestPassiveFoodMob, yawToward, horizontalDistance };