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>
92 lines
2.3 KiB
JavaScript
92 lines
2.3 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { scoreSite } from "./base-site.js";
|
|
|
|
function block(name, x, z, y = 64, distance = null) {
|
|
return {
|
|
name,
|
|
position: { x, y, z },
|
|
distance: distance ?? Math.hypot(x, z),
|
|
};
|
|
}
|
|
|
|
test("scoreSite: empty surroundings → near-floor score", () => {
|
|
const out = scoreSite({
|
|
blocks: [],
|
|
surfaceYs: [64, 64, 64, 64, 64],
|
|
players: [],
|
|
position: { x: 0, y: 64, z: 0 },
|
|
});
|
|
// no wood -0, no stone -0, no water -0, flat +2, no players +2,
|
|
// no foreign builds +3 → 7
|
|
assert.equal(out.score, 7);
|
|
});
|
|
|
|
test("scoreSite: wood + stone + water + flat + no players + no claims → high", () => {
|
|
const out = scoreSite({
|
|
blocks: [
|
|
block("oak_log", 5, 5),
|
|
block("stone", 4, 0),
|
|
block("water", 10, 0),
|
|
],
|
|
surfaceYs: [64, 64, 64, 64, 64],
|
|
players: [],
|
|
position: { x: 0, y: 64, z: 0 },
|
|
});
|
|
// wood +3, stone +2, water +2, flat +2, no players +2, no claims +3 → 14
|
|
assert.equal(out.score, 14);
|
|
});
|
|
|
|
test("scoreSite: foreign build subtracts heavily", () => {
|
|
const out = scoreSite({
|
|
blocks: [
|
|
block("oak_log", 5, 5),
|
|
block("oak_planks", 6, 0), // man-made, not owned
|
|
],
|
|
surfaceYs: [64, 64, 64, 64, 64],
|
|
players: [],
|
|
position: { x: 0, y: 64, z: 0 },
|
|
isOwned: () => false,
|
|
});
|
|
// wood +3, no stone 0, no water 0, flat +2, no players +2, foreign -10 → -3
|
|
assert.equal(out.score, -3);
|
|
});
|
|
|
|
test("scoreSite: bot-owned man-made blocks don't penalise", () => {
|
|
const out = scoreSite({
|
|
blocks: [
|
|
block("oak_log", 5, 5),
|
|
block("crafting_table", 2, 0),
|
|
],
|
|
surfaceYs: [64, 64, 64, 64, 64],
|
|
players: [],
|
|
position: { x: 0, y: 64, z: 0 },
|
|
isOwned: () => true,
|
|
});
|
|
// wood +3, flat +2, no players +2, no foreign +3 → 10
|
|
assert.equal(out.score, 10);
|
|
});
|
|
|
|
test("scoreSite: bumpy surface loses the flatness +2", () => {
|
|
const out = scoreSite({
|
|
blocks: [],
|
|
surfaceYs: [60, 64, 64, 68, 65],
|
|
players: [],
|
|
position: { x: 0, y: 64, z: 0 },
|
|
});
|
|
// flat 0, no players +2, no foreign +3 → 5
|
|
assert.equal(out.score, 5);
|
|
});
|
|
|
|
test("scoreSite: nearby player loses the +2", () => {
|
|
const out = scoreSite({
|
|
blocks: [],
|
|
surfaceYs: [64, 64, 64, 64, 64],
|
|
players: [{ distance: 10 }],
|
|
position: { x: 0, y: 64, z: 0 },
|
|
});
|
|
// flat +2, players 0, no foreign +3 → 5
|
|
assert.equal(out.score, 5);
|
|
});
|