Skip to content

feat(cli): add terminal create, split, rename, focus, close, tui-idle wait - #734

Merged
Jinwoo-H merged 12 commits into
stablyai:mainfrom
heyramzi:feat/terminal-create-split
Apr 23, 2026
Merged

Jinwoo-H merged 12 commits into
stablyai:mainfrom
heyramzi:feat/terminal-create-split

Conversation

@heyramzi

@heyramzi heyramzi commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • terminal create --worktree <sel> [--title <name>] [--command <text>] — create a new terminal tab; --title sets the tab name at creation (e.g. DEVELOPER, RUNNER) so orchestration frameworks don't need a separate rename call
  • terminal split --terminal <handle> [--direction h|v] [--command <text>] — split an existing pane horizontally or vertically, optionally running a command in the new pane
  • terminal rename --terminal <handle> [--title <text>] — set or clear a tab's custom title (same action as "Set Title…" in the right-click context menu)
  • terminal focus --terminal <handle> — bring a terminal tab to the foreground, switching the active worktree/view/tab in the renderer
  • terminal close --terminal <handle> — kill the PTY (if running) and close the tab
  • terminal wait --for tui-idle — server-side polling (3 s interval, 5 stable polls) that resolves when the terminal preview matches a TUI idle pattern ("Ask anything", "Enter a prompt", "How can I help", etc.) or output stabilizes; replaces manual sleep loops in orchestration scripts
  • terminal read --cursor <n> — cursor-based reads: pass nextCursor from a previous read to get only new output since then, enabling clean capture of a single agent response

Motivation

Closes #715. Multi-agent orchestration frameworks (e.g. running Claude/OpenCode/Codex/Gemini in parallel across split panes) need full programmatic control over terminal lifecycle — creating named tabs, splitting panes, reading responses, and waiting for TUI agents to finish — without relying on polling hacks or manual UI interaction.

Implementation

All commands follow the existing RPC architecture:

CLI → Unix socket RPC → OrcaRuntimeService → RuntimeNotifier → mainWindow.webContents.send() → preload → useIpcEvents.ts → store
  • terminal split uses a custom window event (orca-split-terminal-pane) to reach the component-local PaneManager, matching the pattern used by FOCUS_TERMINAL_PANE_EVENT
  • terminal wait --for tui-idle uses setInterval polling on leaf.preview inside the runtime; the TerminalWaiter type now carries a condition and pollInterval so cleanup is handled correctly on timeout or terminal-gone errors
  • Cursor tracking adds tailLinesTotal (cumulative complete lines) to RuntimeLeafRecord; cursor-based reads slice the rolling tail buffer using bufferStart = tailLinesTotal - tailBuffer.length

Test plan

  • orca terminal create --worktree active --title "RUNNER" --json → tab appears with correct title
  • orca terminal split --terminal <handle> --direction vertical --command "opencode" --json → pane splits, command runs
  • orca terminal rename --terminal <handle> --title "CTO" → tab title updates in UI
  • orca terminal focus --terminal <handle> → Orca switches to that tab
  • orca terminal close --terminal <handle> → tab closes, PTY killed
  • orca terminal wait --terminal <handle> --for tui-idle --timeout-ms 120000 → resolves when OpenCode/Claude TUI returns to idle prompt
  • orca terminal read --terminal <handle> --cursor <n> → returns only lines written after cursor

🤖 Generated with Claude Code

@heyramzi heyramzi changed the title feat(cli): add terminal create and split commands feat(cli): add terminal create, split, rename, focus, close, tui-idle wait Apr 17, 2026
@AmethystLiang
AmethystLiang requested a review from Jinwoo-H April 19, 2026 17:19
heyramzi and others added 10 commits April 22, 2026 18:53
Adds two new CLI commands:

- `orca terminal create --worktree <selector> [--command <text>]`
  Creates a new terminal tab in the specified worktree. The tab
  appears in the Orca UI immediately; the caller can then poll
  `orca terminal list` for the resulting handle.

- `orca terminal split --terminal <handle> [--direction horizontal|vertical] [--command <text>]`
  Splits an existing terminal pane. Defaults to horizontal split.
  Optionally seeds the new pane with a startup command.

Both commands follow the existing notifier → IPC → renderer pattern
established by `ui:activateWorktree`. A new `SPLIT_TERMINAL_PANE_EVENT`
custom event routes split requests to the correct TerminalPane instance
via `managerRef`, matching the `FOCUS_TERMINAL_PANE_EVENT` pattern.

Closes stablyai#715

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Two additions on top of the terminal create/split PR:

terminal rename
  orca terminal rename --terminal <handle> [--title <text>] [--json]
  Sets a custom title on a terminal tab via the same setTabCustomTitle
  store action that "Set Title..." uses in the right-click context menu.
  Omit --title or pass empty string to reset to the auto-generated title.

Cursor-based terminal read
  orca terminal read --terminal <handle> [--cursor <n>] [--json]
  - readTerminal now returns nextCursor (a line count) on every call
  - --cursor <prev_cursor> returns only lines written after that cursor
  - Enables a clean response-capture pattern for orchestration:
      before=$(orca terminal read --terminal h --json | jq .result.terminal.nextCursor -r)
      orca terminal send --terminal h --text "claude" --enter
      orca terminal wait --terminal h --for exit
      orca terminal read --terminal h --cursor $before --json

Implementation:
  - RuntimeLeafRecord gains tailLinesTotal (total complete lines ever written)
  - appendToTailBuffer returns newCompleteLines so onPtyData can increment it
  - readTerminal slices the tail buffer from the cursor-relative offset
  - nextCursor is now always populated (was always null before)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- terminal wait --for tui-idle: server-side polling (3s interval, 5 stable
  polls) replaces the 25s polling loop in orcastrate's waitForTUIIdle; uses
  TUI idle patterns (Ask anything, Enter a prompt, How can I help, etc.)
- terminal create --title <name>: set tab title at creation time so
  orchestration frameworks can spin up named tabs (CTO, DEVELOPER, etc.)
  in a single call instead of create + rename
- terminal focus --terminal <handle>: bring a tab to the foreground,
  switching active worktree/view/tab in the renderer
- terminal close --terminal <handle>: kill PTY (if running) and close tab

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Add assertGraphReady() guard to splitTerminal to prevent stale graph ops
- Reject non-exit waiters on terminal exit instead of spinning until timeout
- Fix cursor-based reads to use tailBuffer (exclude partial lines)
- Add terminal_exited and terminal_gone to RPC error allowlist
- Move split handler to lifecycle hook for shell-ready command delivery
- Fix --for flag help text to show exit|tui-idle
- Deduplicate direction flag in formatFlagHelp
- Add missing IPC mock handlers in tests
The previous tui-idle implementation used hardcoded prompt patterns
(e.g., "Ask anything") that don't match any real agent CLI. Replace
with the existing OSC title detection system (extractLastOscTitle +
detectAgentStatusFromTitle) that the renderer already uses for
notifications and sidebar badges.

Key changes:
- Detect working→idle transitions via OSC 0/1/2 title sequences
- Only resolve on idle, not permission (agent blocked on approval)
- Reset lastAgentStatus on resolution to prevent stale instant resolves
- Default 5-minute timeout for tui-idle to prevent indefinite hangs
- Add defense-in-depth re-check after waiter registration
- Remove isTUIIdle(), TUI_IDLE_PATTERNS, and polling interval
- Add test for OSC working→idle transition
- Update SKILL.md with tui-idle documentation
Make terminal commands consistent with browser tab commands:

- terminal create: --worktree now optional (auto-resolves from cwd like
  tab create), returns a stable handle + generated title via IPC
  request/reply pattern (mirrors browser's requestTabCreate/replyTabCreate)
- terminal split: returns a handle for the new pane, immediately usable
  for send/read/wait (waits for graph sync + PTY spawn like create)
- terminal switch: added as preferred verb (matches tab switch), terminal
  focus kept as alias
- SKILL.md: fixed missing --terminal flags in wait examples, updated
  create/switch docs
When --terminal is omitted, commands auto-resolve to the active terminal
in the current worktree — matching browser's implicit active tab targeting.
This means `orca terminal send --text "hello" --enter` Just Works.

Also adds:
- terminal.resolveActive RPC route for worktree-scoped active lookup
- SKILL.md: document horizontal (left-right) vs vertical (top-bottom)
  split direction convention, add handle-less command examples
closeTerminal was always tearing down the entire tab because the
notifier only forwarded tabId. In a multi-pane tab the PTY kill
already triggers the renderer's exit handler which calls
PaneManager.closePane(), so we skip the redundant IPC close for
multi-pane tabs to avoid a race that would close the surviving pane.

For single-pane tabs or when no PTY exists, the notifier close still
fires with paneRuntimeId so the renderer can dispatch a pane-level
close event to the lifecycle hook.
@Jinwoo-H
Jinwoo-H force-pushed the feat/terminal-create-split branch from 0a14b94 to dab8d2a Compare April 23, 2026 00:29
@Jinwoo-H

Copy link
Copy Markdown
Contributor

Thanks for the PR! I pushed some hardening fixes and small changes to make these new commands more consistent with the new browser automation commands

- terminal.create RPC now accepts missing worktree gracefully (mirrors
  browser.tabCreate), falling back to the renderer's active worktree
- Help text shows --terminal as optional with brackets on all commands
- Added terminal switch, create, split to the common commands reference
- Updated terminal close description to mention pane-level close
- Use PaneManager.getPanes().length instead of private .panes.size
- Add onRequestTerminalCreate and replyTerminalCreate to PreloadApi type
- Make worktreeId optional in terminal create preload types
@Jinwoo-H
Jinwoo-H merged commit 4f7b488 into stablyai:main Apr 23, 2026
2 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 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.

Feature: terminal create/split via CLI

2 participants