review BLOCKER: PTY input forwarding + raw mode toggle
Phase 1 review caught a structural gap: executor.exec only drained the
PTY master fd, never forwarded user keystrokes — vim/less/htop/nano
would render and hang on input. PHASE1.md §5 specified bidirectional
multiplex but only the read leg landed. tcgetattr/tcsetattr were also
missing, so even with input forwarding the parent's line discipline
would buffer until newline (breaking single-key UIs).
ffi/libc:
- struct termios opaque buffer + tcgetattr/tcsetattr + cfmakeraw
- M.set_raw(fd) saves termios + applies cfmakeraw; returns saved or
(nil, err) when fd isn't a tty (scripted / piped-stdin runs)
- M.restore_termios(fd, saved)
- struct pollfd + M.poll (POLLIN constant)
executor:
- multiplex(sess): poll(stdin, master); reads master on any revents
(POLLHUP fires when child closes its slave end, not POLLIN — the
revents != 0 check catches both); forwards stdin keystrokes to
master; loop exits when master read returns 0 (EOF / child gone)
- stdin polling is only enabled when stdin_is_tty (set_raw succeeded);
piped-stdin runs (tests / scripted) would otherwise drain queued
aish commands into the child of the *current* cmd, swallowing them
- raw mode is restored before returning so the user lands back at the
aish prompt in canonical mode
renderer + repl:
- exec_output(out, code) split into exec_begin() (top rule, before
spawn) + exec_end(code) (closing rule with exit, after wait). PTY
multiplex streams the body live to stdout in between; the renderer
never re-prints the body.
PHASE1.md §3:
- tcgetattr/tcsetattr changed from "optional" to "required for
single-key UIs to work — done-criteria #2"; poll added to the libc
row description.
Verified:
- non-interactive smoke (echo / false / exit 7 / ls /nonexistent /
printf multi-line) — all exit codes correct, output streamed live,
a\nb\nc\n preserved byte-for-byte
- scripted-stdin run reaches all expected lines (no stdin draining
into a non-interactive child)
- aish prompt + framed exec block + exit-code line all render in
correct order
Live interactive verification (vim / less / htop in a real terminal)
still needs a user-test pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+8
-5
@@ -31,12 +31,15 @@ function M.assistant(text)
|
||||
end
|
||||
end
|
||||
|
||||
-- Frame captured shell-exec output with a top rule + the body + a closing
|
||||
-- rule that carries the exit code (red on non-zero).
|
||||
function M.exec_output(output, exit_code)
|
||||
output = (output or ""):gsub("\n$", "")
|
||||
-- Phase 1: executor.exec streams output live to stdout (PTY multiplex), so
|
||||
-- the frame is split — exec_begin before the spawn, exec_end after wait().
|
||||
-- The body is not re-rendered here; live output lands directly between the
|
||||
-- two rules.
|
||||
function M.exec_begin()
|
||||
emit(A.dim, "─── exec output ───", A.reset, "\n")
|
||||
if output ~= "" then emit(output, "\n") end
|
||||
end
|
||||
|
||||
function M.exec_end(exit_code)
|
||||
if exit_code and exit_code ~= 0 then
|
||||
emit(A.dim, "─── exit ", A.reset,
|
||||
A.red, tostring(exit_code), A.reset,
|
||||
|
||||
Reference in New Issue
Block a user