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:
@@ -0,0 +1,91 @@
|
||||
// Manifesto state: cached "active need" for the current tick.
|
||||
//
|
||||
// Each reflex pass calls pickActiveNeed(snapshot) — it walks the
|
||||
// needs ladder from level 0 upward and returns the FIRST need whose
|
||||
// detect() is false AND whose pursue() returns a non-null skill id.
|
||||
// Needs whose pursue() returns null (e.g. armour while we lack craft
|
||||
// skills) are recorded as "blocked at this level" but the ladder
|
||||
// continues — that way the bot still makes progress on lower-priority
|
||||
// concerns instead of stalling.
|
||||
|
||||
import { NEEDS, getNeed } from "./needs.js";
|
||||
import { isRegistered } from "../skill-registry.js";
|
||||
import { info } from "../log.js";
|
||||
|
||||
const CACHE_TTL_MS = 3_000;
|
||||
|
||||
let _cache = null;
|
||||
let _lastNeedId = null;
|
||||
|
||||
export function _resetForTest() {
|
||||
_cache = null;
|
||||
_lastNeedId = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* pickActiveNeed(snapshot) →
|
||||
* {
|
||||
* need: { id, level, title },
|
||||
* skillId: string, // dispatch this skill
|
||||
* args: object | undefined,
|
||||
* blockedNeeds: Array<{id, level}> // needs above this one whose pursue=null
|
||||
* } | null
|
||||
*
|
||||
* Returns null only when *every* need is satisfied (i.e. village_full
|
||||
* is detected, which is never true in practice — global goal). In
|
||||
* that case callers should fall back to the curriculum.
|
||||
*/
|
||||
export function pickActiveNeed(snapshot) {
|
||||
if (!snapshot?.connected) return null;
|
||||
const now = Date.now();
|
||||
if (_cache && _cache.snapshot === snapshot && now - _cache.ts < CACHE_TTL_MS) {
|
||||
return _cache.result;
|
||||
}
|
||||
const blocked = [];
|
||||
let chosen = null;
|
||||
for (const need of NEEDS) {
|
||||
let satisfied;
|
||||
try {
|
||||
satisfied = !!need.detect(snapshot);
|
||||
} catch (e) {
|
||||
info("manifesto", `need ${need.id}.detect threw: ${e?.message ?? e}`);
|
||||
satisfied = true;
|
||||
}
|
||||
if (satisfied) continue;
|
||||
let plan;
|
||||
try {
|
||||
plan = need.pursue(snapshot);
|
||||
} catch (e) {
|
||||
info("manifesto", `need ${need.id}.pursue threw: ${e?.message ?? e}`);
|
||||
plan = null;
|
||||
}
|
||||
if (!plan || !plan.skillId) {
|
||||
blocked.push({ id: need.id, level: need.level });
|
||||
continue;
|
||||
}
|
||||
if (!isRegistered(plan.skillId)) {
|
||||
info("manifesto", `need ${need.id}: pursue suggested unknown skill ${plan.skillId}; skipping`);
|
||||
blocked.push({ id: need.id, level: need.level });
|
||||
continue;
|
||||
}
|
||||
chosen = { need: { id: need.id, level: need.level, title: need.title }, skillId: plan.skillId, args: plan.args, blockedNeeds: blocked };
|
||||
break;
|
||||
}
|
||||
if (chosen) {
|
||||
if (_lastNeedId !== chosen.need.id) {
|
||||
info("manifesto", `active need: L${chosen.need.level} ${chosen.need.id} → ${chosen.skillId}`);
|
||||
_lastNeedId = chosen.need.id;
|
||||
}
|
||||
}
|
||||
_cache = { snapshot, ts: now, result: chosen };
|
||||
return chosen;
|
||||
}
|
||||
|
||||
export function describeActiveNeed(snapshot) {
|
||||
const a = pickActiveNeed(snapshot);
|
||||
if (!a) return null;
|
||||
return `L${a.need.level} ${a.need.id} → ${a.skillId}`;
|
||||
}
|
||||
|
||||
// Re-export ladder for callers that want to enumerate.
|
||||
export { NEEDS, getNeed };
|
||||
Reference in New Issue
Block a user