feat(harness): keep input live during a turn; Escape cancels, typing steers#28
Merged
Conversation
…steers Fixes #25 and #26. The bug behind both: during a turn the main goroutine was inside the run loop, so nothing read stdin and the input bar froze until the turn finished. Ctrl-C only ever worked because it rode SIGINT, which is exactly why it was flaky. Now a single pump goroutine owns stdin and feeds a selectable channel, so the editor stays live while the turn runs in a worker goroutine. While it works: type a message and Enter to queue a steer (injected as a user turn at the next iteration boundary, the format-safe point), or press Escape to cancel. Ctrl-C is now reserved for quitting (twice). Scope: live input covers the default free-running posture; with -ask the gate reads approvals mid-turn from the same keyboard, so that posture stays synchronous. Injection lands at iteration boundaries, not mid-tool-chain.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #25 and #26.
Root cause (one bug behind both issues)
During a turn the main goroutine was inside
runTurn/drive, so nothing read stdin: the input bar froze until the turn finished. Ctrl+C only ever worked because it rode a separate path (SIGINT), which is exactly why it was flaky and undebuggable.Fix
A single pump goroutine owns stdin and feeds a
select-able channel, so the editor stays live while the turn runs in a worker goroutine. While the agent works you can:Ctrl+C is reserved for quitting (twice within two seconds), as requested in #26.
How it works
pump()is the only reader of the terminal; every other consumer (readLineMode,readCSI,readPaste,Select,ReadKey,escIsBare) reads decoded runes from the channel.readLineModegains a turn-attend mode thatselects on a keystroke or the turn'sdonechannel, so it stops attending the instant the turn ends without swallowing a keystroke meant for the next prompt. The worker streams the response above the footer while the editor's input row stays live below it; both render under the existing footer mutex.Scope (called out for review)
-ask, the gate reads approvals mid-turn from the same keyboard, so that posture stays synchronous (Ctrl+C quits). A gate mod (executable) does not read stdin, so it keeps live input.Tests
TestAttendTurnQueuesAndCancels— drives the live editor: Enter queues, bare Escape cancels.TestDriveInjectsQueuedSteer— a queued message is injected as a user turn and acted on in place of the judge.TestInterruptsQueue— drain returns and clears (a steer is consumed once).gofmt/vetclean, full suite +-raceonharness/andagent/green.