feat(runtime): compatibility hardening (Phase 7) (#18)

Phase 7 of plans/autonomous-survival-bot-prd.md. Five small modules
that close the recurring "shared state" and "version-pinned list"
failure modes the PRD flags in §7 and §5.4.

New:
- runtime/movement-profiles.js: named profiles (GATHER, TRAVEL, FLEE,
  BUILD, RETURN_TO_BASE) as pure descriptors via PROFILE_DEFAULTS,
  plus applyProfile(profile, bot) that hands a fresh Movements to
  pathfinder. Avoids the "flee left canDig=false on the shared
  Movements, next chop got stuck in canopy" regression.
- runtime/owned-blocks.js: JSONL ledger of blocks this bot placed/
  removed (state/<host>/owned-blocks.jsonl); isOwned({x,y,z}) for
  O(1) lookups; ensureDir() makes the parent dir lazily.
- runtime/claim-avoidance.js: classifyArea({blocks, isOwned}) returns
  player_build / natural_or_owned / insufficient_data based on
  man-made block density vs ownership ratio; shouldAvoid(area) helper.
  Designed for gather/place skills to call before touching contested
  area.
- runtime/skills/compat.test.js: runs runtime/skills/groups.js against
  real minecraft-data registries for 1.18.2, 1.20.4, 1.21.5; spot-
  checks that pale_oak_log only appears on 1.21+ etc.
- runtime/compat.test.js: 10 tests covering movement descriptors,
  isManMadeBlockName, classifyArea, owned-blocks markPlaced/dedup/
  isOwned/markRemoved.

npm test now 79/79.

Co-authored-by: Yuriy Mayatnikov <mayatnikov@me.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit was merged in pull request #18.
This commit is contained in:
Yuriy Mayatnikov
2026-05-25 22:39:38 +03:00
committed by GitHub
co-authored by mayatnikov Claude Opus 4.7
parent c7eab06f22
commit d2e52a1b79
7 changed files with 457 additions and 1 deletions
+54
View File
@@ -0,0 +1,54 @@
// Movement safety profiles. mineflayer-pathfinder's Movements object
// is shared per-bot — if one skill sets canDig=false and another
// inherits that, you get the live regression from earlier: flee with
// canDig=false leaves the bot stuck in a tree canopy forever.
//
// Each named profile is a flat descriptor (pure JS object) that the
// caller can either inspect directly (tests do this) or apply to a
// pathfinder Movements via applyProfile(profile, bot).
import pathfinderPkg from "mineflayer-pathfinder";
const { Movements } = pathfinderPkg;
export const PROFILES = Object.freeze({
GATHER: "gather",
TRAVEL: "travel",
FLEE: "flee",
BUILD: "build",
RETURN_TO_BASE: "return_to_base",
});
// Pure descriptors — safe to import without a live bot.
export const PROFILE_DEFAULTS = Object.freeze({
[PROFILES.GATHER]: { canDig: true, canPlace: false, allow1by1towers: false },
[PROFILES.TRAVEL]: { canDig: true, canPlace: false, allow1by1towers: false },
// canDig:true on flee is deliberate — observed live: flee with canDig=false
// in dense canopy leaves the bot perched in leaves indefinitely.
[PROFILES.FLEE]: { canDig: true, canPlace: false, allow1by1towers: false, maxDropDown: 8 },
// Build: don't accidentally mine the structure we're placing; allow
// 1x1 step-ups so shelter blueprints can layer.
[PROFILES.BUILD]: { canDig: false, canPlace: true, allow1by1towers: true },
// Return: don't carve tunnels home or place stepping blocks; just walk.
[PROFILES.RETURN_TO_BASE]: { canDig: false, canPlace: false, allow1by1towers: false },
});
export function describeProfile(profile) {
const desc = PROFILE_DEFAULTS[profile];
if (!desc) throw new Error(`unknown movement profile: ${profile}`);
return desc;
}
// Build a fresh Movements applying the descriptor; does NOT call setMovements.
export function buildProfile(profile, bot) {
const desc = describeProfile(profile);
const m = new Movements(bot);
for (const [k, v] of Object.entries(desc)) m[k] = v;
return m;
}
// Convenience: build + apply.
export function applyProfile(profile, bot) {
const m = buildProfile(profile, bot);
bot.pathfinder.setMovements(m);
return m;
}