feat(perception): vendor mindcraft skills/world library + Pi tool wrappers
The bot was acting blind: it knew its own coordinates but nothing about
what was around it. mc_goto's over-strict safety guards refused every
real path. mc_dig was too low-level to drive a coherent farming loop.
The result: 4+ hours of "trying" with zero physical achievement.
This commit reframes the bridge around a perceive→decide→act loop using
proven primitives from Mindcraft (github.com/kolbytn/mindcraft, MIT —
LICENSE-MINDCRAFT vendored beside the library files).
Changes:
- extensions/lib/ (new, vendored from Mindcraft with attribution)
- world.js (431 LoC) — 21 perception functions: getNearbyBlockTypes,
getNearbyEntities, getInventoryCounts, getNearestBlock, getPosition,
getBiomeName, etc.
- skills.js (2093 LoC) — 30+ action primitives: collectBlock, placeBlock,
goToPosition, goToNearestBlock, craftRecipe, equip, consume,
defendSelf, avoidEnemies, pickupNearbyItems, stay, etc.
- mcdata.js (~600 LoC) — Mindcraft's mc-data adapter. Imports patched
to local paths; mineflayer-auto-eat removed (our installed 5.x has
a divergent API; skills.consume() falls back to bot.consume()).
Added attachPluginsAndInit(bot) export so mineflayer-bridge.ts can
wire plugins onto its externally-created bot.
- settings.js — minimal stub with farmer-bot defaults.
- extensions/mindcraft-skills.ts (new, 406 LoC) — Pi extension registering
15 high-level tools on top of the vendored library:
- Perception: mc_observe, mc_inventory, mc_nearby_blocks, mc_nearby_entities
- Action: mc_collect_block, mc_place_block, mc_go_to, mc_go_to_block,
mc_craft, mc_equip, mc_consume, mc_defend_self, mc_avoid_enemies,
mc_stay, mc_pickup_nearby
ES modules from extensions/lib/ are loaded via dynamic import() at
extension init so the cross-extension require()-race resolves cleanly.
- extensions/mineflayer-bridge.ts
- Expose the live Mineflayer bot on globalThis.__pepaPiBot so the
mindcraft-skills extension can use it (set on connect, cleared on
error/end/manual disconnect).
- Call attachPluginsAndInit(nextBot) right after createBot to load
pathfinder, pvp, collectblock, armorManager and prime
minecraft-data once login completes.
- package.json — new runtime deps: minecraft-data, vec3,
mineflayer-pvp, prismarine-item.
- AGENTS.md — new "Perception → decision → action" section before
"Your tools right now" with full tool catalog and a deprecation
note for the broken mc_goto / mc_build_pyramid_5x5 / low-level
mc_dig from the old bridge.
Smoke test (medium thinking): bot called mc_observe and received a
real JSON snapshot — nearbyBlocks listed coal_ore, oak_log, water,
sand; nearbyEntityTypes listed creeper, zombie, pillager, skeleton.
The bot can finally see what it could not see this morning.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,46 @@ The two files that shape your day-to-day choices:
|
||||
|
||||
When no operator task is active and chat is quiet, you work towards the goal. See Operating principle #5 below for the priority order.
|
||||
|
||||
## Perception → decision → action (read FIRST before any world action)
|
||||
|
||||
You used to be blind: you knew your coords but nothing about what was around you. Now you have proper perception. The cycle is:
|
||||
|
||||
1. **Observe.** Call `mc_observe` first. You get a JSON snapshot of position, health, food, time of day, weather, biome, nearby block types, nearby entities (mobs + players + items), inventory counts.
|
||||
2. **Decide.** Based on the snapshot, pick the **single** most relevant next action. Don't plan 5 steps deep; the snapshot will change after you act.
|
||||
3. **Act.** Call ONE high-level tool from the catalog below.
|
||||
4. **Loop.** Observe again. Append one short diary line if a milestone shifted.
|
||||
|
||||
### Tool catalog — mindcraft-skills.ts (use these)
|
||||
|
||||
**Perception (cheap, read-only):**
|
||||
|
||||
- `mc_observe(radius?)` — one-shot full snapshot. **Use this first in autonomous mode.**
|
||||
- `mc_inventory()` — items as `{name: count}`.
|
||||
- `mc_nearby_blocks(radius?)` — distinct block types within radius (default 16).
|
||||
- `mc_nearby_entities(radius?)` — players, mobs, dropped items with approximate distances.
|
||||
|
||||
**Actions (write to world, may take seconds-to-minutes):**
|
||||
|
||||
- `mc_collect_block(blockType, count?)` — walk to a block of that type, equip the right tool, mine N of them, pick them up. The all-in-one "gather wood / stone / iron" primitive.
|
||||
- `mc_place_block(blockType, x, y, z)` — place one block from inventory at exact coords.
|
||||
- `mc_go_to(x, y, z, minDistance?)` — pathfinder navigation with permission to dig soft obstacles (leaves) and jump.
|
||||
- `mc_go_to_block(blockType, minDistance?, range?)` — find nearest block of type within `range` and walk there.
|
||||
- `mc_craft(itemName, num?)` — craft from inventory. Uses a nearby crafting table when needed.
|
||||
- `mc_equip(itemName)` — hold a tool or wear armor.
|
||||
- `mc_consume(itemName?)` — eat food. Empty arg = first food in inventory.
|
||||
- `mc_defend_self(range?)` — attack hostile mobs within range until clear. Uses best weapon.
|
||||
- `mc_avoid_enemies(distance?)` — run away from nearest hostiles by ~N blocks.
|
||||
- `mc_stay(seconds?)` — stand still N seconds (default 30). Use to wait out night or regen.
|
||||
- `mc_pickup_nearby()` — collect dropped items in vicinity.
|
||||
|
||||
### Deprecated (do not use)
|
||||
|
||||
- `mc_build_pyramid_5x5` — narrow-purpose, pre-perception era. Build via `mc_place_block` loops if needed.
|
||||
- `mc_dig(x, y, z)` — too low-level. Use `mc_collect_block(blockType, n)` which handles the whole cycle.
|
||||
- `mc_goto(x, y, z)` — had over-strict safety guards that refused legitimate paths. Replaced by `mc_go_to` from mindcraft-skills.
|
||||
|
||||
The deprecated tools may still appear in your registry for now; ignore them. They will be removed in a follow-up cleanup.
|
||||
|
||||
## Your tools right now
|
||||
|
||||
When you start, you have:
|
||||
|
||||
Reference in New Issue
Block a user