Skip to content

refactor(ui): apply the remaining code-review structural cleanups - #359

Merged
forketyfork merged 2 commits into
feat/selection-agent-contextfrom
refactor/selection-agent-followups
Aug 15, 2026
Merged

refactor(ui): apply the remaining code-review structural cleanups#359
forketyfork merged 2 commits into
feat/selection-agent-contextfrom
refactor/selection-agent-followups

Conversation

@forketyfork

@forketyfork forketyfork commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Issue

Follow-up structural cleanup on top of the selection-agent-context feature (#358):

  • handleExternalSpawnRequest and handleLaunchAgentWithContext each still took ~15 flat parameters and rebuilt a SpawnSessionContext locally instead of accepting the struct directly, even though the struct existed specifically to avoid that duplication.
  • 9 call sites in runtime.zig manually paired hideSelectionMenus() with a terminal-layout-changing call, relying on every future call site remembering to do the same.
  • OpenSelectionAgentAction/LaunchAgentWithContextAction carried a raw session slot index captured at queue time, rather than the stable-ID pattern PendingSessionSend already uses to survive grid reindexing.
  • selection_agent_overlay.zig hand-rolled the same scrim/panel/dismiss-key chrome as confirm_dialog.zig, with no shared code to keep them from drifting.
  • session_interaction.zig had four inline copies of "resolve a Pin to (x, y) honoring is_viewing_scrollback".

Solution

  • run() now builds one SpawnSessionContext per frame and both handlers take *const SpawnSessionContext directly.
  • applyTerminalLayout/applyTerminalLayoutIfSizeChanged now call hideSelectionMenus() internally (unconditionally / only when the layout actually changed, matching prior call-site behavior), so invalidation is structural instead of a convention every caller has to remember. applyRuntimeResizeForScaleChange, which duplicated the same resize logic inline, now delegates to applyTerminalLayout so the window-resize path gets the same guarantee.
  • OpenSelectionAgentAction/LaunchAgentWithContextAction now carry the source session's stable id; handlers resolve it back to a slot index via findSessionIndexById() at handling time.
  • New ui/components/modal_frame.zig exports renderScrimAndPanel() and isDismissKey(), adopted by both confirm_dialog.zig and selection_agent_overlay.zig.
  • New pinToCoords() helper in session_interaction.zig replaces the four inline pointFromPin branches in selectionCellForPin, selectWord, selectLine, and getLinkMatchAtPin.

No behavior changes are intended — this is a pure structural cleanup. docs/ARCHITECTURE.md updated for the new modal_frame.zig module and the stable-ID convention on these two actions.

Context

Base branch: feat/selection-agent-context (#358).

Test plan

  • Trigger each of the 9 layout-changing paths that used to manually call hideSelectionMenus() (closing the last terminal, closing a mid-grid terminal, font size change, window resize, grid reflow) with an active text selection, and confirm the selection pill/menu disappears in every case.
  • Select text, open "Launch agent", then trigger a grid reindex (e.g. close another terminal) before launching — confirm the agent still launches in the originally selected terminal's directory.
  • Open the selection-agent modal and the quit-confirm dialog and confirm both still dismiss on Escape and ⌘W and render identical scrim/panel chrome.

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.
@forketyfork
forketyfork requested a balanced review from Copilot August 15, 2026 13:06
@forketyfork
forketyfork marked this pull request as ready for review August 15, 2026 13:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors selection-agent and modal infrastructure to centralize shared behavior while preserving existing functionality.

Changes:

  • Uses stable session IDs and shared spawn/layout contexts.
  • Extracts shared modal chrome, dismissal handling, and pin-coordinate resolution.
  • Documents the new module and stable-ID convention.

Validation was not run; the listed manual tests remain pending.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/ui/types.zig Changes selection-agent actions to stable session IDs.
src/ui/components/session_interaction.zig Captures stable IDs and centralizes pin resolution.
src/ui/components/selection_agent_overlay.zig Uses stable IDs and shared modal helpers.
src/ui/components/modal_frame.zig Adds shared modal rendering and dismissal utilities.
src/ui/components/confirm_dialog.zig Adopts shared modal helpers.
src/app/runtime.zig Centralizes spawn context and layout invalidation.
docs/ARCHITECTURE.md Documents the structural conventions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…to refactor/selection-agent-followups

# Conflicts:
#	docs/ARCHITECTURE.md
@forketyfork
forketyfork merged commit 8fcac95 into feat/selection-agent-context Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants