feat(runtime): stuck-incident detector + skill metrics + edit scope (Phase 6) (#17)

Phase 6 of plans/autonomous-survival-bot-prd.md. Expand the
self-improvement loop so the bot can spot and report no-progress
stagnation, not just exception-class failures.

New:
- runtime/stuck-incident.js: detector fires a structured proposal when
  the same noProgressReason persists past 5 min (cooldown 30 min).
  Body includes runtimeState, milestone, suggested skill, slim
  snapshot, last action result, per-skill success/failure metrics
  and a forbidden-paths list. Pure module — caller (bot.js) writes
  the proposal.
- runtime/skill-metrics.js: in-memory per-skill ok/fail counters
  surfaced on snapshot.skillMetrics for the TUI and the incident
  body.
- runtime/stuck-incident.test.js: 6 tests covering null reason,
  threshold gating, cooldown, reason change resetting the timer,
  body composition and metrics snapshot.

Wiring:
- runtime/state-store.js: writeProposal accepts {editScope: string[]}
  and persists it in the frontmatter; readProposalEditScope() reads
  it back so future auto-patch.js can refuse cherry-picks that touch
  other areas.
- runtime/bot.js: tick() invokes the stuck detector each tick,
  records skill ok/fail via skillMetrics, stamps snapshot.skillMetrics
  and writes the stuck proposal via writeProposal({editScope}).
  dispatchAction now records into skillMetrics for both the
  resolved-result and the exception path.

npm test now 46/46.

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 #17.
This commit is contained in:
Yuriy Mayatnikov
2026-05-25 22:35:01 +03:00
committed by GitHub
co-authored by mayatnikov Claude Opus 4.7
parent fc62160524
commit c7eab06f22
7 changed files with 325 additions and 8 deletions
+23
View File
@@ -246,6 +246,29 @@ 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.
### Self-improvement v2 (Phase 6)
Two classes of proposals now land in `state/<host>/proposals/`:
1. **Bug-class failures** — same-label action returns `{ok: false}` 5×
in a row, dominated by `bug` (TypeError, "Cannot read properties")
or persistent timeout. Handled by the older tracker in `bot.js`.
2. **Stuck incidents**`noProgressReason` stays the same for ≥5 min
without a productive dispatch. Handled by
`runtime/stuck-incident.js`. The proposal body includes the
runtimeState, milestone, suggested skill, slim snapshot, last
result, and per-skill success/failure metrics.
Both kinds now persist an **`editScope`** in their frontmatter — an
array of repo-relative path prefixes the auto-patcher is allowed to
modify. `state-store.readProposalEditScope(filename)` reads it back;
hooking `scripts/auto-patch.js` to refuse cherry-picks that touch
other areas is the remaining follow-up.
Per-skill metrics live in memory only (best-effort) but are surfaced
on `snapshot.skillMetrics = { [skillId]: { ok, fail, lastTs } }` so
the TUI can show which skills are reliable and which keep failing.
### Social layer (Phase 5)
Inbound MC chat is classified via `runtime/social/intent.js` into one