feat(runtime): persistent memory — world-journal + scenario-memory
Closes a structural gap: the bot now actually REMEMBERS what it
discovered and what it tried. Two stores live under state/<host>/ and
are wired in automatically.
runtime/world-journal.js
- Append-only JSONL of discovered points (chopped, placed, base,
shelter, farm, dead_end). Indexed by 16-block spatial grid; O(neighbors)
nearest() lookups; 6 h age prune; 10k line ceiling with trim.
- leanestQuadrant({x,z}) reports the quadrant the bot has the FEWEST
markers in — used by explore.far to circle rather than retread.
- summary() exposed for the stuck-incident proposal body.
runtime/scenario-memory.js
- Sliding window of (skillId, situationHash, code, ok, detail) tuples.
- situationHash() is a coarse fingerprint (16x8x16 cell + day/night +
food/hp bucket + inv key set + closest hostile). So "same kind of
place + same kind of state" matches.
- shouldSkip({skillId, situation}) → true after ≥3 failures within 30
min UNLESS a more-recent success in the same situation un-locks it.
- recentTailFor() exposed for the stuck-incident body.
Wiring (runtime/bot.js):
- dispatchAction captures situationHash BEFORE the action runs and
records (skillId, situation, code, ok) after — failures are attributed
to the dispatch-time state, not the partial-effect state.
- worldDelta fields (choppedAt, minedAt, placedAt, baseAt, shelterAt,
plantedAt, harvestedAt, tilledAt) auto-flow into the journal.
- no_target + silent_dig_failure also write dead_end markers.
Scheduler / skills now consume memory:
- reflex.js curriculum reflex calls memory.shouldSkip — if the same
(skill, situation) failed 3+ times recently, auto-converts to a
wander hint so the bot leaves and tries elsewhere.
- explore.far calls journal.leanestQuadrant when multiple cardinal
directions are walkable and prefers the less-explored one.
- gather.logs walks to the nearest known "chopped" bucket within 96
blocks before falling through to findBlock — chunks with confirmed
trees are more likely to yield another.
stuck-incident body now includes journal byKind + last 12 scenario
entries so Pi can write a structural fix, not just a guard clause.
Architecturally: this is the foundation for "bot rewrites itself".
The proposals Pi now receives carry real signal about what was tried
and what's around, instead of a single snapshot in isolation.
10 new tests (world-journal × 5, scenario-memory × 5). npm test 134/134.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -246,6 +246,33 @@ in-process. The package is **not** a default dep — install it explicitly
|
||||
(`npm i prismarine-viewer`) before enabling. If missing, the runtime
|
||||
logs a warning and continues.
|
||||
|
||||
### Memory: world-journal + scenario-memory (2026-05-26)
|
||||
|
||||
Two persistent stores under `state/<host>/`:
|
||||
|
||||
- **`world-journal.jsonl`** — append-only log of discovered points
|
||||
(`{kind, name, at:{x,y,z}, ts}`). Skills feed it automatically via
|
||||
`worldDelta` on each successful dispatch — chops, mines, placements,
|
||||
base/shelter location, planted/harvested crops, plus `dead_end`
|
||||
markers on `no_target` / `silent_dig_failure`. Indexed by a 16-block
|
||||
spatial grid so `nearest({kind, x, z, radius})` is O(neighbors).
|
||||
Pruned at 6 h age + 10k line ceiling. `leanestQuadrant({x, z})`
|
||||
returns the cardinal quadrant the bot has explored LEAST — used by
|
||||
`explore.far` to circle rather than retread the same patch.
|
||||
- **`scenarios.jsonl`** — sliding window of `(skillId, situationHash,
|
||||
code, ok, detail, ts)` tuples. `situationHash` is a coarse fingerprint
|
||||
of where + how the bot was (16-cell + 8y bucket, day/night, food
|
||||
bucket, hp bucket, inventory key set, closest hostile name). The
|
||||
curriculum reflex calls `memory.shouldSkip({skillId, situation})` —
|
||||
≥3 failures of the same `(skill, situation)` within 30 min and the
|
||||
reflex auto-converts into a wander hint instead of re-dispatching the
|
||||
failing skill. A subsequent success in the same situation un-locks it.
|
||||
|
||||
Both stores feed stuck-incident proposal bodies: when the LLM is
|
||||
asked to patch a stuck state, it sees `byKind` journal counts AND the
|
||||
last 12 scenario-memory entries, so it can write a structural fix
|
||||
based on what's actually been tried, not just one snapshot.
|
||||
|
||||
### Scheduler driven by the curriculum (2026-05-26)
|
||||
|
||||
The reflex chain is now: `defend → eat → sleep → curriculum → idle`.
|
||||
|
||||
Reference in New Issue
Block a user