feat(runtime): state persistence + proposals + supervisor hot-restart (#6)
Closes the self-improvement loop end-to-end:
reflex fails 3× → proposal file → operator approves in TUI →
`npm run propose:apply <file>` spawns Pi on a feature branch →
Pi commits the patch → supervisor watches runtime/*.js and
restarts the child on change.
runtime/state-store.js — atomic current-task.json writes, daily diary
append, proposals/ + proposals/approved/ helpers.
runtime/bot.js:
- ctx.dispatch writes current-task.json on start and updates it on
completion / failure / throw.
- failure tracker: 3 consecutive same-label failures → writeProposal()
with the snapshot, labels, and a suggested-next-step section.
30-min cooldown prevents proposal spam.
- on startup, surfaces resume info (previous task + pending proposal
count); on death, clears current-task.json + writes diary line.
- new IPC commands: PROPOSAL_LATEST returns the newest pending
proposal body; PROPOSAL_APPROVE moves it to proposals/approved/.
tui/tui.tsx — status bar shows `[proposals N, press y]` badge when
bot.pendingProposals > 0. Hotkey 'y' opens the proposal panel; 'y'
approves, 'n'/Esc closes.
scripts/propose-apply.js — given an approved proposal filename, creates
a `feat/proposal-<slug>` branch and spawns `pi -p` with the proposal
+ repo-conventions prompt. Refuses on dirty tree. No auto-push, no
auto-merge — operator reviews the diff and decides.
runtime/supervisor.js — forks bot.js as a child, watches runtime/*.js,
restarts on file change or on child exit code 42. Rate-limited at 5
restarts/minute. SIGINT/SIGTERM forward cleanly. `npm run bot` now
goes through the supervisor; `npm run bot:bare` skips it.
Smoke-tested: supervisor spawned, bot connected to MC, spawned at
expected coords, diary line written, state cleanup on SIGTERM correct.
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 #6.
This commit is contained in:
@@ -14,6 +14,7 @@ export const EVENT_TYPES = Object.freeze({
|
||||
ASK_PI_CHUNK: "ask-pi-chunk", // streamed stdout chunk from Pi subprocess
|
||||
ASK_PI_DONE: "ask-pi-done", // Pi subprocess exited { code, durationMs }
|
||||
HELLO: "hello", // sent on client connect with current snapshot
|
||||
PROPOSAL: "proposal", // pending proposal payload { filename, body }
|
||||
});
|
||||
|
||||
// Client → server commands.
|
||||
@@ -24,6 +25,8 @@ export const COMMAND_TYPES = Object.freeze({
|
||||
CHAT: "cmd:chat", // { text } sent into MC as bot
|
||||
ASK_PI: "cmd:ask-pi", // { prompt } spawn `pi -p` and stream output
|
||||
SNAPSHOT: "cmd:snapshot", // request immediate STATUS event
|
||||
PROPOSAL_LATEST: "cmd:proposal-latest", // request latest pending proposal
|
||||
PROPOSAL_APPROVE: "cmd:proposal-approve", // { filename } move to approved/
|
||||
});
|
||||
|
||||
export function encodeFrame(obj) {
|
||||
|
||||
Reference in New Issue
Block a user