feat(ui): launch an agent with selected terminal text as context - #358
Merged
Conversation
Issue: Add a way to select terminal output and hand it to a new AI agent session as context, generalizing the existing "send diff comments to agent" pending-delivery mechanism to cover both flows. A follow-up code review then found a P0 regression the same diff introduced in the pre-existing diff-comments flow, a delivery-guarantee regression, an unbounded context preview, missing tests, and a leftover debug-logging block. Solution: Selection release shows a "Launch agent" pill; the modal (selection_agent_overlay.zig) lets the user pick an agent, review the selection, and write instructions, then queues a LaunchAgentWithContext action. The runtime spawns the session and defers sending the prompt until the target agent is confirmed running (drainPendingSessionSends), falling back to sending anyway at a deadline instead of dropping silently. The review fixes: match agent names without the PTY newline (fixes send-to-agent for claude/codex/gemini), show a "+N more lines" indicator when the context preview truncates, drop leftover diagnostic logging, restore prompt focus after the agent dropdown closes, and add test coverage for drainPendingSessionSends and relative --log-dir resolution.
forketyfork
marked this pull request as ready for review
August 15, 2026 12:25
Issue: The selection-agent-context review (P0/P1 already fixed in the base branch) also flagged five P2 structural issues: two runtime handlers half-adopting SpawnSessionContext instead of taking it directly, nine call sites manually pairing selection-menu invalidation with terminal layout changes instead of one structural choke point, two new UI actions carrying a raw session slot index instead of the stable-ID pattern the pending-send mechanism already uses, hand-rolled modal chrome duplicated between two dialog components, and a "resolve a Pin to a cell" branch duplicated four times. Solution: handleExternalSpawnRequest and handleLaunchAgentWithContext now take a single *const SpawnSessionContext built once per frame. applyTerminalLayout/applyTerminalLayoutIfSizeChanged now invalidate selection menus internally, so every call site gets it for free instead of relying on a paired call. OpenSelectionAgentAction and LaunchAgentWithContextAction now carry the source session's stable id, resolved back to a slot via findSessionIndexById() when handled, so a grid reindex between queuing and handling can't retarget the wrong terminal. A new ui/components/modal_frame.zig extracts the shared scrim+panel rendering and Escape/Cmd+W dismiss check used by confirm_dialog and selection_agent_overlay. session_interaction.zig gains a single pinToCoords() helper for resolving a Pin to (x, y) in whichever page is visible, replacing four inline copies of the same viewport/active branch.
3 tasks
There was a problem hiding this comment.
Pull request overview
Adds a selection-to-agent workflow integrated through the UI action pipeline and runtime session management.
Changes:
- Adds a selection pill and agent-launch modal.
- Generalizes deferred prompt delivery and repairs diff-comment delivery.
- Adds documentation, tests, logging-path handling, and rendering fixes.
Validation: Not run during this review.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/ui/types.zig |
Adds selection-agent actions. |
src/ui/session_view_state.zig |
Tracks selection-pill state. |
src/ui/mod.zig |
Exports the new overlay. |
src/ui/components/session_interaction.zig |
Implements pill interaction and positioning. |
src/ui/components/selection_agent_overlay.zig |
Implements the agent-launch modal. |
src/ui/components/glyph_badge.zig |
Supports custom badge colors. |
src/ui/components/diff_overlay.zig |
Repairs agent command delivery and clipping. |
src/main.zig |
Registers overlay tests. |
src/logging.zig |
Resolves relative log directories. |
src/c.zig |
Exposes SDL clip-state API. |
src/app/runtime.zig |
Spawns agents and manages deferred sends. |
README.md |
Documents selection-to-agent behavior. |
docs/ARCHITECTURE.md |
Adds component documentation and ADR-015. |
Suppressed comments (2)
src/ui/components/selection_agent_overlay.zig:262
- This default branch consumes SDL lifecycle events while the modal is open.
UiRoot.handleEventcauses the runtime to skip its event switch for every consumed event, so quit/close, resize, focus, and window-destroy events never reach their handlers. Consume the remaining input events explicitly, but returnfalsefor unrelated events as the other overlays do.
else => return true,
src/ui/components/selection_agent_overlay.zig:214
SDL_EVENT_TEXT_INPUTis still inserted while the agent dropdown owns focus. Pressing a printable key with the dropdown open first hits the dropdown's key-down branch, then the corresponding text-input event silently modifies the prompt even thoughprompt_focusedis false. Ignore text input until prompt focus is restored.
c.SDL_EVENT_TEXT_INPUT => {
_ = self.prompt.insert(self.allocator, std.mem.span(event.text.text), host.now_ms);
return true;
},
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Issue: Automated review on the selection-agent-context PR flagged four problems: the context preview box was too short to show the new "more lines" overflow indicator, the prompt field never rendered a highlight for Cmd+A select-all, ADR-015 described a toast-and-drop deadline behavior that no longer matches the implementation, and the deadline delivery test used a fabricated session whose sendInput silently no-ops, so it couldn't actually catch a regression that dropped the payload. Solution: grow context_height to fit five rows instead of four; draw a selection highlight behind the wrapped prompt lines when select_all is set, matching the (highlight-only, caret still blinks) pattern already used in search_utils.zig and diff_overlay.zig; correct the ADR-015 prose to describe the detected-agent-first, send-anyway-at-deadline behavior; and rewrite the deadline test to back the fabricated session with a real pipe standing in for the PTY, asserting the exact bytes written to the other end.
…to refactor/selection-agent-followups # Conflicts: # docs/ARCHITECTURE.md
…lowups refactor(ui): apply the remaining code-review structural cleanups
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.
Issue
There was no way to hand terminal output to an AI agent as context without manually copying and pasting it. Building this also surfaced problems in the adjacent, pre-existing "send diff comments to agent" feature, which shares its pending-delivery mechanism with the new flow:
sendCommentsToAgentcompared a newline-terminated PTY input string against the bare agent name, soAgentKind.fromStringnever matched — "send to agent" was broken for claude/codex/gemini.log.warndump fired on every modal open.--log-dirresolution path had no test coverage.error.LabelTextureFailed.Solution
selection_agent_overlay.zig) to pick an agent (Claude/Codex/Gemini), review the selected context, and write instructions.LaunchAgentWithContextaction; the runtime spawns a new terminal in the source session's working directory and defers sending the composed prompt until the target agent is confirmed running viadrainPendingSessionSends, a generalized pending-send state machine that also now backs the pre-existing diff-comments-to-agent flow (documented as ADR-015).drainPendingSessionSendsnow sends anyway once the deadline passes instead of dropping the queued text.drainPendingSessionSends(missing/dead session, deadline-based delivery) and for relative--log-dirresolution.Context
Documented as ADR-015 in
docs/ARCHITECTURE.md.Test plan