feat(runtime): skill substrate + dynamic groups + reference skills (Phase 2)
Phase 2 of plans/autonomous-survival-bot-prd.md. Establishes the
composable skill contract from PRD §5.2 and ports three reference
skills so future phases can layer survival behaviour on top instead of
adding more ad-hoc branches to reflex.js.
New: runtime/skills/
- index.js: skill registry + runSkill(id, ctx, args) wrapper. Enforces
preconditions, hard timeout, normalises {ok, code, detail, worldDelta}
on every result, runs validate() and calls recover() on failure.
Stable failure codes live in RUNNER_CODES (unknown_skill,
precondition_failed, timeout, threw, validation_failed, done).
- groups.js: registry-derived item/block sets — logs/planks/sticks/beds
derived by suffix; foods intersects a curated allowlist with the live
bot.registry; axes/pickaxes/swords scoped to whatever the connected
server's item table actually ships. Empty set instead of throwing on
missing registry, so skills can emit code:"unsupported_version".
- chop-logs.js: gather.logs reference skill (wraps chopNearestTree).
- eat.js: survive.eat (wraps eatBestFood, preconditions check carrying
edible food from the registry-derived set).
- wander.js: explore.wander (wraps wander).
- contract.test.js + groups.test.js: 14 tests covering precondition
gating, timeout firing recover(), execute exceptions, validate
flipping ok→false, dynamic group filtering across mock registries.
package.json: `npm test` runs the new contract + groups suites.
docs/runtime.md: documents the skill contract, runner, dynamic groups
and the reference skills.
Reflex.js still calls actions.js directly — wiring the scheduler to
runSkill() lands in later phases when the survival curriculum kicks in.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -167,6 +167,49 @@ parsing the log stream:
|
||||
| `lastEscalation` | `{ ts, ageMs }` of the most recent Pi auto-escalation. |
|
||||
| `reflexPaused` | mirror of the local pause flag (so TUI shows the right state immediately). |
|
||||
|
||||
### Skill substrate (Phase 2)
|
||||
|
||||
Lives under `runtime/skills/`. A **skill** is a small composable unit of
|
||||
survival behaviour with a uniform contract:
|
||||
|
||||
```js
|
||||
export const skill = {
|
||||
id: "namespace.action",
|
||||
title: "Human label",
|
||||
timeoutMs: 45_000,
|
||||
preconditions(ctx) -> { ok, code?, detail? }
|
||||
async execute(ctx, args) -> { ok, code, detail, worldDelta }
|
||||
validate?(ctx, result) -> boolean // optional
|
||||
recover?(ctx, result) -> any | null // optional
|
||||
}
|
||||
```
|
||||
|
||||
Registered skills are dispatched via `runSkill(id, ctx, args)` from
|
||||
`runtime/skills/index.js`. The runner enforces the timeout, normalises
|
||||
the result shape, runs `validate()` and calls `recover()` on failure
|
||||
so the scheduler can act on the hint (e.g. "switch to wander"). Stable
|
||||
failure codes the runner itself emits live in `RUNNER_CODES`
|
||||
(`unknown_skill`, `precondition_failed`, `timeout`, `threw`,
|
||||
`validation_failed`, `done`).
|
||||
|
||||
Item/block groups are dynamic: `runtime/skills/groups.js` exposes
|
||||
`logs(bot)`, `planks(bot)`, `sticks(bot)`, `beds(bot)`, `foods(bot)`,
|
||||
`axes(bot)`, `pickaxes(bot)`, `swords(bot)` — every group is derived
|
||||
from `bot.registry`, so a version-sensitive item that doesn't exist on
|
||||
the connected server simply doesn't appear in the set and skills
|
||||
return `code: "unsupported_version"` instead of crashing.
|
||||
|
||||
Reference skills shipped today: `gather.logs`, `survive.eat`,
|
||||
`explore.wander`. The reflex loop still calls the older
|
||||
`runtime/actions.js` primitives directly — porting more behaviours to
|
||||
skills lands in later phases.
|
||||
|
||||
Run the contract + groups tests:
|
||||
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
||||
### Optional: prismarine-viewer
|
||||
|
||||
Set `VIEWER_PORT=<port>` in `.env` to launch
|
||||
|
||||
Reference in New Issue
Block a user