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:
@@ -0,0 +1,28 @@
|
||||
// Per-skill ok/fail counters. Aggregated for the lifetime of the bot
|
||||
// process (best-effort persistence is left for a future iteration —
|
||||
// today's counters reset on restart, which keeps the data store
|
||||
// simple while still being useful for incident bodies and the TUI).
|
||||
|
||||
export function createSkillMetrics() {
|
||||
const counts = new Map(); // id → { ok, fail, lastTs }
|
||||
|
||||
function record(id, ok) {
|
||||
const cur = counts.get(id) ?? { ok: 0, fail: 0, lastTs: 0 };
|
||||
if (ok) cur.ok++;
|
||||
else cur.fail++;
|
||||
cur.lastTs = Date.now();
|
||||
counts.set(id, cur);
|
||||
}
|
||||
|
||||
function snapshot() {
|
||||
const out = {};
|
||||
for (const [id, m] of counts) out[id] = { ...m };
|
||||
return out;
|
||||
}
|
||||
|
||||
function reset() {
|
||||
counts.clear();
|
||||
}
|
||||
|
||||
return { record, snapshot, reset };
|
||||
}
|
||||
Reference in New Issue
Block a user