feat: surface.wait — server-owned pattern/exit waits on the socket - #172
Merged
Conversation
Server-owned, event-driven wait on a terminal surface: block the calling socket connection (with a timeout) until output matches a regex pattern or the surface's child process exits, in one request/response round trip instead of the caller polling surface.read_text in a loop. - exit is fully event-driven, hooked off the existing GHOSTTY_ACTION_SHOW_CHILD_EXITED action via a new SurfaceExitWaitRegistry - pattern polls the surface's live text on a short internal timer (Ghostty has no push-based content-changed callback); still a single call from the caller's perspective - the already-satisfied check and watcher install happen in one main-thread hop, so a marker printed (or a process exit) racing the call can't be missed - each socket connection runs on its own thread, so blocking for the wait's duration never stalls main or other connections
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.
What this does
Agents no longer poll
read_textto know when a sibling surface is done.surface.waitblocks (with timeout) server-side until output matches a pattern or the child process exits, answering in one round trip with a no-missed-events guarantee (condition check + watcher install happen in a single main-queue hop).Scope is task 1 of #166:
pattern+exitconditions,wait-surfaceCLI verb, socket docs, tests_v2 coverage. Agent-state waits andagent.promptfollow once #164's state model lands.Review order
Sources/TerminalController+SurfaceWait.swift— registry + wait implementation (threading rationale in the header comment)CLI/programa.swift—wait-surfaceverb + clientminimumReceiveTimeoutso long waits survive the 15s default read timeoutdocs/v2-api-migration.md,tests_v2/test_surface_wait.pyTest plan
programaandprograma-clischemes buildRefs #166