Why
A fatal error mid-session currently loses the terminal state and can lose the last bits of session progress. Sessions are precious — crashes should degrade gracefully.
What
Process-level crash handler:
process.on("uncaughtException") + unhandledRejection: restore the terminal (leave alt-screen, show cursor, disable mouse), flush the current session JSONL to disk, print a short message with the session id and a klaatai chat --resume <id> hint, exit non-zero
- Detect startup crash loops: if the last run crashed during boot (marker file), start with a safe-mode hint (skip plugins/MCP) instead of crashing identically again
Where to start
src/engine/app.ts / src/engine/terminal.ts — terminal teardown helpers already exist
- Session persistence: session-save path in
src/screens/repl.ts
- Marker file under
~/.klaatai/
Acceptance criteria
- Simulated throw inside a running REPL restores the terminal and prints the resume hint
- Session file is intact and resumable afterwards
- typecheck + tests green
Why
A fatal error mid-session currently loses the terminal state and can lose the last bits of session progress. Sessions are precious — crashes should degrade gracefully.
What
Process-level crash handler:
process.on("uncaughtException")+unhandledRejection: restore the terminal (leave alt-screen, show cursor, disable mouse), flush the current session JSONL to disk, print a short message with the session id and aklaatai chat --resume <id>hint, exit non-zeroWhere to start
src/engine/app.ts/src/engine/terminal.ts— terminal teardown helpers already existsrc/screens/repl.ts~/.klaatai/Acceptance criteria