Skip to content

feat(worktree): seed the default agent when activating an empty worktree - #15912

Open
CodeHourra wants to merge 1 commit into
stablyai:mainfrom
CodeHourra:feat/empty-worktree-default-agent
Open

CodeHourra wants to merge 1 commit into
stablyai:mainfrom
CodeHourra:feat/empty-worktree-default-agent

Conversation

@CodeHourra

Copy link
Copy Markdown

ELI5

Clicking a worktree that has no tabs used to open a blank terminal. It now opens the same default agent you already picked in Settings → Agents, unless you set that default to a blank terminal.

What Changed

  • Empty worktree/folder activation (sidebar click and the first-visit Terminal path) seeds the global default TUI agent instead of a bare shell.
  • Settings → Agents → Default Agent = blank still opens a blank terminal.
  • Explicit startup commands, setup runners, issue-command splits, persisted empty tab state, and configured default tabs are unchanged.
  • Onboarding folder-agent launch now shares buildDefaultAgentStartupPayload with this path.

Why

The default agent already applied to new agent tabs and onboarding. Activating an empty workspace ignored it, so the first click felt like a different product from Settings. This makes the empty-workspace first tab follow the same setting.

Linked Issue

No existing issue.

Visual Proof

N/A — no layout, chrome, or copy change. The only interaction change is which process the first tab launches:

  • Before: empty worktree click → blank shell
  • After: empty worktree click → defaultTuiAgent (or auto-pick from detected agents when unset); blank keeps a shell

Testing

  • Automated tests added/updated, or explained why not below
  • I manually tested these changes locally

Covered in unit tests:

  • pinned default seeds even when it is not in the detected list
  • blank / disabled default / no detections → no agent launch
  • configured default tabs are not replaced by the global default agent
  • onboarding folder startup still builds from the same payload helper

Platforms exercised by tests: launch plan is built with host platform, remote isRemote, and Windows shell resolution. I did not run a packaged macOS/Linux/Windows/SSH smoke in this PR.

pnpm exec vitest run --config config/vitest.config.ts \
  src/renderer/src/lib/worktree-default-agent-startup.test.ts \
  src/renderer/src/components/terminal/initial-terminal-wiring.test.ts \
  src/renderer/src/lib/worktree-activation-agent-startup.test.ts \
  src/renderer/src/lib/worktree-activation-default-tabs.test.ts \
  src/renderer/src/components/onboarding/onboarding-folder-agent-startup.test.ts

44 tests passed.

AI Disclosure

Cursor Grok 4.6 authored the implementation, tests, and this PR description.

Review

  • Cross-platform: launch platform comes from the repo (getAgentLaunchPlatformForRepo) or renderer platform; Windows shell goes through resolveLocalWindowsAgentStartupShell.
  • SSH / remote / folder: remote worktrees use connectionId + remoteDetectedAgentIds and pass isRemote into the existing startup plan. Folder workspaces share ensureWorktreeHasInitialTerminal; onboarding folders share the payload builder.
  • Agents: uses defaultTuiAgent / disabledTuiAgents / pickTuiAgent and existing buildAgentStartupPlan (cmd overrides, default args/env, native-chat session options). No GitHub-only naming.
  • Performance: extra work is one store read + startup-plan build, and only on first empty activation.
  • Security: no new network, credentials, or process APIs; reuses the current agent launch path.
  • UI: no STYLEGUIDE / token changes.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platoform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • 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)

Summary

  • Empty worktree activation now launches Settings → Agents default agent instead of a blank terminal.
  • Explicit launches, setup, issue commands, persisted empty state, and default-tab templates stay as they are.

Test plan

  • Click a never-visited git worktree with Default Agent = Codex → Codex tab, not a blank shell
  • Same with Default Agent = blank → blank terminal
  • Click a folder workspace with no tabs → same default-agent behavior
  • Open a worktree that already has tabs / persisted empty state → no extra tab
  • Worktree with configured default tabs → those tabs, not the default agent
  • Remote/SSH worktree uses the remote detected-agent list

Made with Cursor

@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1e3265eb-772d-40ff-afe3-847d936ea546

📥 Commits

Reviewing files that changed from the base of the PR and between 9725654 and c7939fa.

📒 Files selected for processing (10)
  • src/renderer/src/components/Terminal.tsx
  • src/renderer/src/components/terminal/initial-terminal-wiring.test.ts
  • src/renderer/src/lib/default-agent-startup-payload.ts
  • src/renderer/src/lib/onboarding-folder-agent-startup.ts
  • src/renderer/src/lib/worktree-activation-agent-startup.test.ts
  • src/renderer/src/lib/worktree-activation-default-tabs.test.ts
  • src/renderer/src/lib/worktree-activation-test-harness.ts
  • src/renderer/src/lib/worktree-default-agent-startup.test.ts
  • src/renderer/src/lib/worktree-default-agent-startup.ts
  • src/renderer/src/lib/worktree-initial-terminal-seeding.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change adds shared logic to resolve a configured or detected default TUI agent and build its startup payload. Onboarding startup now uses this builder. Empty worktree activation uses the default-agent payload when no other startup command exists. Initial terminal creation now uses ensureWorktreeHasInitialTerminal. Tests cover agent resolution, payload construction, activation behavior, default-tab precedence, and state cleanup.

Merge Risk: ⚪ Minimal · up to c7939

This change makes the first tab in an empty worktree follow the configured default agent while preserving blank-terminal and existing-tab behavior. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it does not provide the required linked issue and states that no existing issue is linked. Add a valid linked issue reference after “Fixes #” or obtain an approved exception to the repository requirement.
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 10 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: launching the configured default agent for empty worktree activation.
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.

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.

This branch has not been deployed

No deployments
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