feat(runtime): hybrid script reflex + Ink TUI + Pi-on-demand escalation #4

Merged
halofourteen merged 2 commits from feat/runtime-tui into main 2026-05-25 16:04:48 +03:00
halofourteen commented 2026-05-25 16:00:03 +03:00 (Migrated from github.com)

Summary

Pivot from pure-Pi runtime (LLM in every tick) to a hybrid: long-running Node daemon with a script-driven reflex loop, plus an Ink TUI dashboard, plus Pi/Codex only invoked on demand.

  • runtime/bot.js — single long-running process. Owns MC connection (Mineflayer + AuthMe), reflex tick loop, IPC server, reconnect policy. No LLM in the hot path.
  • runtime/reflex.js — priority chain: defend > eat > sleep > idle. Stubs today; only the chain + dispatch is live.
  • runtime/perceive.js — JSON snapshot of HP/food/pos/time/weather/inventory/players/hostiles.
  • runtime/ipc-protocol.js + runtime/ipc-server.js — newline-JSON over Unix socket at `state//bot.sock` (perms 0600, cleaned on shutdown).
  • runtime/pi-bridge.js — spawn `pi -p ""`, stream stdout/stderr back over IPC.
  • tui/tui.tsx — Ink dashboard. Panels: status bar, event log, MC chat tail, Pi escalation panel, command bar. Hotkeys p/s/r/c/a/q.
  • tui/ipc-client.js — socket client with EventEmitter surface.
  • extensions/mindcraft-skills.ts — also wraps every skill call in a hard timeout (separate commit). Fixes the live hang of `mc_avoid_enemies` that triggered this pivot.
  • docs/runtime.md — full guide. README + AGENTS updated to point at the new mode while keeping Pi-only as a fallback.

Why

Pure-Pi was slow (20–60s/decision), expensive (every tick paid for reasoning), and invisible (tmux capture-pane was the only window in). The hybrid runtime keeps Pi as the cortex for the genuinely hard cases — proposals, new skills, ambiguous situations — while reflexes handle the routine on plain JS.

Test plan

  • Smoke test: `npm run bot` connects to play.xmatic.team, spawns at expected coords, IPC socket created with 0600 perms, SIGTERM cleans up.
  • Live: connect TUI via `npm run tui`, verify status updates each tick.
  • Live: send chat from TUI (`c` key).
  • Live: trigger ask-Pi from TUI (`a` key) — verify stdout streams into Pi panel.
  • Decide reflex bodies in a follow-up: defend (real attack/flee), eat (real consume), sleep (`bot.sleep`).
  • Wire automatic escalation: reflex chain → N consecutive noops → askPi() with snapshot.

🤖 Generated with Claude Code

## Summary Pivot from pure-Pi runtime (LLM in every tick) to a hybrid: long-running Node daemon with a script-driven reflex loop, plus an Ink TUI dashboard, plus Pi/Codex only invoked on demand. - **runtime/bot.js** — single long-running process. Owns MC connection (Mineflayer + AuthMe), reflex tick loop, IPC server, reconnect policy. No LLM in the hot path. - **runtime/reflex.js** — priority chain: defend > eat > sleep > idle. Stubs today; only the chain + dispatch is live. - **runtime/perceive.js** — JSON snapshot of HP/food/pos/time/weather/inventory/players/hostiles. - **runtime/ipc-protocol.js** + **runtime/ipc-server.js** — newline-JSON over Unix socket at \`state/<host>/bot.sock\` (perms 0600, cleaned on shutdown). - **runtime/pi-bridge.js** — spawn \`pi -p "<prompt>"\`, stream stdout/stderr back over IPC. - **tui/tui.tsx** — Ink dashboard. Panels: status bar, event log, MC chat tail, Pi escalation panel, command bar. Hotkeys p/s/r/c/a/q. - **tui/ipc-client.js** — socket client with EventEmitter surface. - **extensions/mindcraft-skills.ts** — also wraps every skill call in a hard timeout (separate commit). Fixes the live hang of \`mc_avoid_enemies\` that triggered this pivot. - **docs/runtime.md** — full guide. README + AGENTS updated to point at the new mode while keeping Pi-only as a fallback. ## Why Pure-Pi was slow (20–60s/decision), expensive (every tick paid for reasoning), and invisible (tmux capture-pane was the only window in). The hybrid runtime keeps Pi as the cortex for the genuinely hard cases — proposals, new skills, ambiguous situations — while reflexes handle the routine on plain JS. ## Test plan - [x] Smoke test: \`npm run bot\` connects to play.xmatic.team, spawns at expected coords, IPC socket created with 0600 perms, SIGTERM cleans up. - [ ] Live: connect TUI via \`npm run tui\`, verify status updates each tick. - [ ] Live: send chat from TUI (\`c\` key). - [ ] Live: trigger ask-Pi from TUI (\`a\` key) — verify stdout streams into Pi panel. - [ ] Decide reflex bodies in a follow-up: defend (real attack/flee), eat (real consume), sleep (\`bot.sleep\`). - [ ] Wire automatic escalation: reflex chain → N consecutive noops → askPi() with snapshot. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.