feat(runtime): scheduler-via-runSkill + Pi banter escalation + base-site (follow-ups) (#20)

Three closures of remaining PRD follow-ups, one merge:

1. Reflex scheduler now drives behaviour from the curriculum.
   - reflex.js: replaced ad-hoc techTreeReflex + autonomousReflex with
     curriculumReflex that dispatches the skill suggested by
     snapshot.curriculum.plan via runSkill. Per-skill backoff for
     missing_tool / missing_material / no_target / no_food_source /
     unsupported_version. recover() hint with `{hint:"wander"}` swaps
     the next tick to wander for 60 s.
   - Chain is now: defend > eat > sleep > curriculum > idle.
   - reflex.test.js: 11 new tests covering busy/disconnected,
     defend/eat preemption, dispatch by id, unknown-skill fallback,
     per-skill + wander-hint backoffs, onComplete updating backoff.

2. Pi escalation for ADDRESSED_BANTER with hard rate limit.
   - bot.js: when generateReply returns {escalate:true}, spawn askPi
     with bot state + last 5 lines from that speaker (redacted via
     chatMemory). Reply capped at 200 chars, sent as one chat line.
   - Rate cap: 6 calls/hour, 90 s min gap. Suppressed escalations
     log once and silently drop.

3. Phase 4 substrate.
   - runtime/locations.js: atomic JSON store
     (state/<host>/locations.json) with setLocation / getLocation /
     nearestLocation / removeLocation; 6 tests.
   - runtime/base-site.js: scoreCurrentPosition(bot) + pure scoreSite
     bundle (wood / stone / water / flatness / no-players /
     no-foreign-builds, owned-blocks excluded from claim penalty);
     6 tests.
   - runtime/skills/choose-base.js: village.choose-base skill — scores
     the current spot, writes locations.base if score ≥ 8, otherwise
     returns code:"too_weak" with a wander recover hint.
   - curriculum.js: new final milestone village.base-site fires
     village.choose-base until a base location exists.
   - bot.js: stamps snapshot.locations from listLocations() each tick
     so the curriculum can read it without coupling to disk.

docs/runtime.md updated with three new sections.
npm test now 116/116.

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 #20.
This commit is contained in:
Yuriy Mayatnikov
2026-05-26 10:46:14 +03:00
committed by GitHub
co-authored by mayatnikov Claude Opus 4.7
parent 82a8250a12
commit ea4f16a0da
13 changed files with 947 additions and 139 deletions
+58
View File
@@ -0,0 +1,58 @@
// village.choose-base — score the bot's current position as a candidate
// base site, and if it clears the minimum bar, persist it under
// state/<host>/locations.json as "base". The skill is intentionally
// shallow: a single tick at the bot's current footing, no global scan.
// The curriculum can dispatch it repeatedly while the bot wanders, and
// the threshold means most calls will return `code: "too_weak"` and
// move on.
import { scoreCurrentPosition } from "../base-site.js";
import { setLocation, getLocation } from "../locations.js";
const MIN_BASE_SCORE = 8; // out of ~14 max; tuned to "good enough"
export const skill = Object.freeze({
id: "village.choose-base",
title: "Score the current spot as a base candidate",
timeoutMs: 5_000,
preconditions(ctx) {
if (!ctx?.bot) return { ok: false, code: "no_bot", detail: "bot missing" };
// If we already have a base, this skill is a no-op the curriculum
// shouldn't be asking for. Defer gracefully.
if (getLocation("base")) return { ok: false, code: "already_have_base", detail: "base location already set" };
return { ok: true };
},
async execute(ctx) {
const result = scoreCurrentPosition(ctx.bot);
if (!result?.position) {
return { ok: false, code: "no_position", detail: "bot has no position", worldDelta: null };
}
if (result.score < MIN_BASE_SCORE) {
return {
ok: false,
code: "too_weak",
detail: { score: result.score, reasons: result.reasons },
worldDelta: null,
};
}
const loc = setLocation("base", {
x: result.position.x,
y: result.position.y,
z: result.position.z,
dimension: ctx.snapshot?.dimension ?? "overworld",
radius: 8,
note: `auto-chosen base, score=${result.score}`,
});
return {
ok: true,
code: "done",
detail: { location: loc, score: result.score, reasons: result.reasons },
worldDelta: { baseAt: { x: loc.x, y: loc.y, z: loc.z }, score: result.score },
};
},
recover(ctx, result) {
// Most failures (too_weak) want us to wander and re-evaluate.
if (result.code === "too_weak") return { hint: "wander", reason: "current spot doesn't pass base threshold" };
return null;
},
});
+2
View File
@@ -26,6 +26,7 @@ import { skill as chopLogs } from "./chop-logs.js";
import { skill as eat } from "./eat.js";
import { skill as wander } from "./wander.js";
import { skill as gatherStone } from "./gather-stone.js";
import { skill as chooseBase } from "./choose-base.js";
import {
craftPlanksSkill,
craftSticksSkill,
@@ -55,6 +56,7 @@ register(chopLogs);
register(eat);
register(wander);
register(gatherStone);
register(chooseBase);
register(craftPlanksSkill);
register(craftSticksSkill);
register(craftWoodenAxeSkill);