Skip to content

refactor(tabs): reuse the shared tab-order helper instead of three copies - #26704

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/simplify-launch-tab-order
Oct 9, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/simplify-launch-tab-order

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25
Prod 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​7 $\color{#cf222e}{\Huge{\mathbf{−}}}$​49 $\color{#cf222e}{\Huge{\mathbf{−}}}$​42

ELI5

When Orca opens a new tab, it saves where that tab sits in the tab bar so the tab lands at the end instead of jumping to the front. One small function, persistAgentLaunchTabOrder, already does this. Three other places had pasted their own copy of that function's body instead of calling it. This PR deletes the three copies and calls the function. Nothing you see changes.

What Changed

The problem. The same tab-order code (read the worktree's terminal, editor and browser tabs, merge them with the saved tab-bar order, move the new tab to the end, save) was copied into three files on top of the shared function. Every copy is a place where a later fix has to be repeated by hand, and copies of this logic have already drifted: the plain "new terminal" path (terminal-tab-create.ts) leaves out browser tabs, and every copy, including the shared function, leaves out simulator and chat tabs that the tab bar itself counts.

User-facing change: none. Tabs open in exactly the same spot as before.

What was replaced (each was a line-for-line match of the shared function: same inputs, same merge call, same save):

  • sleeping-agent-session-launch.ts: the private appendTabToWorktreeOrder function (resuming a sleeping agent session).
  • launch-ai-vault-session.ts: the inline block that ran after an AI vault session resume.
  • run-quick-command-in-new-tab.ts: the inline block that ran after a plain (non-agent) quick command opened its terminal. The block's later fresh.setRecentQuickCommandForGroup(...) call now reads the store directly, the way the other branches in that file already do.

Line delta: source −42 (7 added, 49 removed). One new test adds 25 lines.

This is phase 2, PR 1 of the agent-launch simplification. It changes nothing about how an agent receives its prompt. It only touches where a new tab is placed in the tab bar.

Why

Calling the existing function is the smallest change that removes the copies, and it adds no new abstraction. On purpose, this PR does not fix the drift listed above. Fixing it would change behavior, and this PR is meant to be a pure deletion. Those gaps are follow-ups:

  • terminal-tab-create.ts is a near-copy that leaves out browser tab ids. It stays as it is.
  • The shared function leaves out simulator and chat tab ids. That only matters when a worktree has no split-group layout. It is not verified at runtime.

Linked Issue

None (maintainer refactor).

Visual Proof

N/A — no UI change; pure refactor.

Testing

  • pnpm vitest run --config config/vitest.config.ts on the tests next to each changed file: run-quick-command-in-new-tab.test.ts, launch-ai-vault-session.test.ts, sleeping-agent-session-launch-windows-quoting.test.ts and the seven resume-sleeping-agent-session*.test.ts files. 10 files, 106 tests pass.

  • New test in run-quick-command-in-new-tab.test.ts: the quick-command terminal goes after existing editor and browser tabs in the saved order. It passes against main's original copy and against this branch, so it pins the behavior that already existed.

  • pnpm tc:web passes. orca-ci-checks (lint, code quality, localization) passes 22/22.

  • Not run: manual app testing. The change is a call swap with matching logic.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

Review

Self-reviewed. Each removed block was compared against launch-agent-tab-order.ts: same store reads, same reconcileTabOrder arguments, same filter-and-push, same setTabBarOrder call. Both versions read store state after setActiveTabType.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Renderer-only, with no platform, SSH or mobile impact: the same store calls run in the same order.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Author: @BrennanKB5

… logic

Sleeping-session resume, AI vault resume and the plain quick-command
terminal each carried a line-for-line copy of persistAgentLaunchTabOrder.
Call the helper instead. No behavior change.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Visual Proof: live UI pass

This PR only swaps three copies of the "put the new tab at the end of the tab bar" code for the shared helper, so nothing should look different. I checked that in a hidden, isolated build of this branch (6b614fea6b8). The workspace already had a terminal, an editor tab (README.md) and a browser tab. I then opened a new tab each of the three ways that changed, and each new tab landed at the far right, after the editor and browser tabs. The agent in these runs is a stand-in script, not a real agent.

Setup: Terminal 1, README.md, New Tab (browser)
26704-setup.png

A. Run a Quick Command in a new tab. "QA quick echo" opens at the far right and prints its output.
26704-A-quick-command.png

B. Resume an AI Vault session in a new tab. Terminal 3 opens at the far right and runs the stand-in with --resume <session id>.
26704-B-ai-vault.png

C. Wake a sleeping agent session by selecting its workspace. The resume tab (Terminal 2) opens at the far right, after notes.txt and the browser tab.
26704-C-wake.png

All three rows pass. The store's tab order agrees with what's on screen: the new tab is last in both the group order and the saved tab-bar order.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Ready summary

  • Problem: the "put a new tab at the end of the tab bar" logic was copied into three files instead of calling the shared helper, so the copies could drift. A fourth near-copy already has.
  • User-facing change: none (pure refactor), −42 source lines. It doesn't change how an agent receives its prompt.
  • Verified:
    • Live UI pass on a hidden, isolated build: a Quick Command tab, an AI Vault resume tab and a woken sleeping session each land last, after the existing editor and browser tabs. The app's saved tab order matches the screen. Screenshots are in the comment above.
    • 106 named tests, the web typecheck and all 22 repository checks pass. CI is green.
    • I checked each removed copy against the helper.
  • Follow-ups, not in this PR:
    • the "+" new-terminal path's near-copy omits browser tabs;
    • the helper omits chat and simulator tab ids;
    • the helper's name should be widened.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 9, 2026 03:31
@coderabbitai

coderabbitai Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bac3464e-be28-43e0-8d31-0fc90724abc7
📥 Commits

Reviewing files that changed from the base of the PR and between dec18a8 and 6b614fe.

📒 Files selected for processing (4)
  • src/renderer/src/lib/launch-ai-vault-session.ts
  • src/renderer/src/lib/run-quick-command-in-new-tab.test.ts
  • src/renderer/src/lib/run-quick-command-in-new-tab.ts
  • src/renderer/src/lib/sleeping-agent-session-launch.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

AI vault, quick-command, and sleeping-agent session launches now use persistAgentLaunchTabOrder to persist the new tab order. The quick-command path records recent history through a fresh store lookup. A test checks that a new terminal tab follows existing editor, terminal, and browser tabs.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 6b614

This refactor preserves tab ordering for quick commands and session resumes, with no concrete user-facing regression established. No actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: replacing duplicated tab-order logic with the shared helper.
Description check Passed The description is complete and focused. It explains the change, rationale, scope, testing, visual impact, maintainer issue exception, and follow-up limitations. It also reports the relevant automated…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@brennanb2025
brennanb2025 merged commit 8d3c922 into main Oct 9, 2026
54 checks passed
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.

1 participant