v0.3.0-rc.2: manifesto / needs ladder L0-L10

Adds an explicit hierarchical needs catalogue that the reflex consults
on every tick. The bot now pursues tangible intermediate goals (food,
wood tools, shelter, stone tools, ...) instead of inheriting whatever
the curriculum thought was "next".

Ladder:
  L0  alive          HP>5, food>0, not in lava, not panic-near hostile
  L1  food           ≥6 food items in inventory (or sated + any food)
  L2  tools_wood     wooden_pickaxe + wooden_axe + wooden_sword
  L3  shelter_basic  bed placed nearby or in inventory
  L4  tools_stone    stone-tier triplet
  L5  armor_basic    any chestplate (pursue=null until craft.leather-*
                     lands; ladder gracefully skips)
  L6  food_security  ≥16 food items
  L7  tools_iron     iron-tier triplet (pursue=gather.stone for now)
  L8  armor_iron     iron chestplate (pursue=null for now)
  L9  village_seed   bed + chest in nearby blocks
  L10 village_full   never detected, falls through to curriculum

Each need has detect(snapshot) → bool and pursue(snapshot) →
{skillId, args} | null. The ladder picks the LOWEST unsatisfied
pursuable need. Needs whose pursue is null get recorded as
blockedNeeds and the walk continues — no stalling on missing skills.

Wired into curriculumReflex: manifesto takes precedence over
curriculum.plan when it has a concrete suggestion. Tests can pass
ctx.disableManifesto=true to exercise the curriculum branch
in isolation (existing reflex tests keep passing this way).

Pi self-reflection prompt now includes
"activeNeed (Maslow ladder L0-L10): L2 tools_wood → gather.logs"
so Pi advises at the right level instead of giving generic guidance.

skillId returned by pursue() is validated against the live registry
(rc.1 plumbing) — manifesto cannot accidentally dispatch a
hallucinated skill name.

Tests: 315 green (was 279 on rc.1, +36 new):
- runtime/manifesto/needs.test.js — 24 tests (per-need detect/pursue,
  helper sums)
- runtime/manifesto/state.test.js — 10 tests (ladder walk, hostile
  takeover at L0, armor skipping, caching)
- runtime/reflex.test.js — 2 integration tests (manifesto overrides
  curriculum plan; well-fed bot pursues tools_stone)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-27 17:50:05 +03:00
co-authored by Claude Opus 4.7
parent fcfa2277ba
commit ddc67a5031
9 changed files with 864 additions and 11 deletions
+116
View File
@@ -0,0 +1,116 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { pickActiveNeed, describeActiveNeed, _resetForTest } from "./state.js";
function snap(overrides = {}) {
return {
connected: true,
health: 20,
food: 20,
hasFood: false,
inventory: {},
equipment: { hand: null, head: null, torso: null, legs: null, feet: null },
nearbyBlocks: {},
hazards: { footBlock: "grass_block", belowBlock: "dirt", headBlock: "air" },
isDay: true,
hostileCount: 0,
closestHostile: null,
...overrides,
};
}
test("pickActiveNeed: disconnected → null", () => {
_resetForTest();
assert.equal(pickActiveNeed({ connected: false }), null);
assert.equal(pickActiveNeed(null), null);
});
test("pickActiveNeed: fresh spawn → L0 alive if zero food", () => {
_resetForTest();
const a = pickActiveNeed(snap({ food: 0 }));
assert.equal(a.need.id, "alive");
assert.equal(a.skillId, "survive.acquire-food");
});
test("pickActiveNeed: hp ok, no food in inventory → L1 food (acquire)", () => {
_resetForTest();
const a = pickActiveNeed(snap());
assert.equal(a.need.id, "food");
assert.equal(a.skillId, "survive.acquire-food");
});
test("pickActiveNeed: food covered → L2 tools_wood (gather logs)", () => {
_resetForTest();
const a = pickActiveNeed(snap({ inventory: { bread: 8 } }));
assert.equal(a.need.id, "tools_wood");
assert.equal(a.skillId, "gather.logs");
});
test("pickActiveNeed: tools wood done → L3 shelter (gather wool)", () => {
_resetForTest();
const a = pickActiveNeed(snap({
inventory: {
bread: 8,
wooden_pickaxe: 1, wooden_axe: 1, wooden_sword: 1,
},
}));
assert.equal(a.need.id, "shelter_basic");
// no wool, no bed → gather.wool
assert.equal(a.skillId, "gather.wool");
});
test("pickActiveNeed: shelter done → L4 tools_stone", () => {
_resetForTest();
const a = pickActiveNeed(snap({
nearbyBlocks: { beds: 1 },
inventory: {
bread: 8,
wooden_pickaxe: 1, wooden_axe: 1, wooden_sword: 1,
},
}));
assert.equal(a.need.id, "tools_stone");
assert.equal(a.skillId, "gather.stone");
});
test("pickActiveNeed: armor pursue=null → ladder skips to food_security", () => {
_resetForTest();
// Everything up through tools_stone satisfied, no armor (pursue=null).
// Should advance to food_security, not stall.
const a = pickActiveNeed(snap({
nearbyBlocks: { beds: 1 },
inventory: {
bread: 8,
wooden_pickaxe: 1, wooden_axe: 1, wooden_sword: 1,
stone_pickaxe: 1, stone_axe: 1, stone_sword: 1,
},
}));
assert.equal(a.need.id, "food_security");
assert.ok(a.blockedNeeds.some((b) => b.id === "armor_basic"), "armor_basic recorded as blocked");
});
test("pickActiveNeed: hostile imminent + low HP → L0 takes over", () => {
_resetForTest();
const a = pickActiveNeed(snap({
health: 6,
closestHostile: { name: "creeper", distance: 3 },
inventory: { bread: 8, wooden_pickaxe: 1, wooden_axe: 1, wooden_sword: 1 },
nearbyBlocks: { beds: 1 },
}));
assert.equal(a.need.id, "alive");
assert.equal(a.skillId, "survive.flee");
});
test("describeActiveNeed: returns 'L<n> <id> → <skill>'", () => {
_resetForTest();
const s = describeActiveNeed(snap());
assert.match(s, /^L1 food → /);
});
test("pickActiveNeed: caches within TTL — same snapshot ref returns same result", () => {
_resetForTest();
const s = snap();
const a = pickActiveNeed(s);
const b = pickActiveNeed(s);
assert.equal(a, b, "second call returns cached object");
});