Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/main/ipc/worktree-remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,8 @@ async function spawnLocalStartupAndSetupTerminals(args: {
...(sequencedStartup.viewMode ? { viewMode: sequencedStartup.viewMode } : {}),
startupCommandDelivery: sequencedStartup.startupCommandDelivery,
telemetry: sequencedStartup.telemetry,
activate: true
// Why: the submitting renderer decides whether to open the workspace; activating here yanked users who moved on (#9944).
surfaceOwner: false
})
startupTerminalHandle = terminal.handle
startupTerminal = {
Expand Down Expand Up @@ -477,14 +478,16 @@ async function spawnLocalStartupAndSetupTerminals(args: {
direction: setupLaunchMode === 'split-horizontal' ? 'horizontal' : 'vertical',
command: setupCommand,
env: setup.envVars,
activate: false
activate: false,
surfaceOwner: false
})
} else {
await runtime.createTerminal(`id:${worktree.id}`, {
title: 'Setup',
command: setupCommand,
env: setup.envVars,
activate: false
activate: false,
surfaceOwner: false
})
}
didSpawnSetup = true
Expand Down
49 changes: 47 additions & 2 deletions src/main/ipc/worktrees-local-create-flow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ describe('registerWorktreeHandlers', () => {
launch_source: 'new_workspace_composer',
request_kind: 'new'
},
activate: true
surfaceOwner: false
}
)
expect(runtimeStub.createTerminal).toHaveBeenNthCalledWith(
Expand All @@ -699,14 +699,18 @@ describe('registerWorktreeHandlers', () => {
ORCA_ROOT_PATH: '/workspace/repo',
ORCA_WORKTREE_PATH: '/workspace/improve-dashboard'
},
activate: false
activate: false,
surfaceOwner: false
}
)
const startupCreateCall = runtimeStub.createTerminal.mock.calls[0]
const setupCreateCall = runtimeStub.createTerminal.mock.calls[1]
if (!startupCreateCall || !setupCreateCall) {
throw new Error('expected startup and setup terminal calls')
}
// The submitting renderer decides whether to open the new workspace, so the host must not
// activate it for the startup terminal (#9944).
expect(startupCreateCall[1]).not.toHaveProperty('activate')
const startupCommand = (startupCreateCall[1] as { command: string }).command
const setupCommand = (setupCreateCall[1] as { command: string }).command
expect(startupCommand).toBe('claude --prefill test')
Expand Down Expand Up @@ -782,6 +786,47 @@ describe('registerWorktreeHandlers', () => {
expect(result.setup?.command).toContain('printf')
})

it('splits split-mode setup into the startup terminal without surfacing the workspace', async () => {
addWorktreeMock.mockResolvedValue({})
listWorktreesMock.mockResolvedValueOnce([
{
path: '/workspace/improve-dashboard',
head: 'def',
branch: 'improve-dashboard',
isBare: false,
isMainWorktree: false
}
])
store.getSettings.mockReturnValue({
branchPrefix: 'none',
nestWorkspaces: false,
refreshLocalBaseRefOnWorktreeCreate: false,
workspaceDir: '/workspace',
setupScriptLaunchMode: 'split-vertical'
})
loadHooksMock.mockReturnValue({ scripts: { setup: 'pnpm install' } })
getEffectiveHooksMock.mockReturnValue({ scripts: { setup: 'pnpm install' } })
getEffectiveHooksFromConfigMock.mockReturnValue({ scripts: { setup: 'pnpm install' } })
shouldRunSetupForCreateMock.mockReturnValue(true)

await handlers['worktrees:create'](null, {
repoId: 'repo-1',
name: 'improve-dashboard',
createdWithAgent: 'claude',
startup: { command: 'claude' }
})

expect(runtimeStub.createTerminal).toHaveBeenCalledTimes(1)
// A user who moved on must not be scrolled to the new workspace by its setup pane (#9944).
expect(runtimeStub.splitTerminal).toHaveBeenCalledWith('term-startup', {
direction: 'vertical',
command: expect.stringContaining('setup-runner.sh'),
env: expect.any(Object),
activate: false,
surfaceOwner: false
})
})

it('rejects ask-policy creates before mutating git state when setup decision is missing', async () => {
getEffectiveHooksMock.mockReturnValue({
scripts: {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -18131,6 +18131,12 @@
"unknown": "Unknown host",
"candidateName": "{{value0}} on {{value1}}"
}
},
"creation": {
"worktreeReadyToast": "Worktree {{name}} is ready",
"workspaceReadyToast": "Workspace {{name}} is ready",
"goToWorktree": "Go to worktree",
"goToWorkspace": "Go to workspace"
}
},
"agentSessionContinuation": {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/src/i18n/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -15135,6 +15135,12 @@
"gitlabMergeRequestNumber": "MR #{{value0}}",
"githubPullRequestNumber": "PR #{{value0}}"
}
},
"creation": {
"worktreeReadyToast": "El worktree {{name}} está listo",
"workspaceReadyToast": "El espacio de trabajo {{name}} está listo",
"goToWorktree": "Ir al worktree",
"goToWorkspace": "Ir al espacio de trabajo"
}
},
"agentSessionContinuation": {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/src/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -18052,6 +18052,12 @@
"unknown": "Hôte inconnu",
"candidateName": "{{value0}} sur {{value1}}"
}
},
"creation": {
"worktreeReadyToast": "Le worktree {{name}} est prêt",
"workspaceReadyToast": "L'espace de travail {{name}} est prêt",
"goToWorktree": "Aller au worktree",
"goToWorkspace": "Aller à l'espace de travail"
}
},
"agentSessionContinuation": {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/src/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -17988,6 +17988,12 @@
"unknown": "不明なホスト",
"candidateName": "{{value0}}、{{value1}}"
}
},
"creation": {
"worktreeReadyToast": "ワークツリー {{name}} の準備ができました",
"workspaceReadyToast": "ワークスペース {{name}} の準備ができました",
"goToWorktree": "ワークツリーに移動",
"goToWorkspace": "ワークスペースに移動"
}
},
"agentSessionContinuation": {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/src/i18n/locales/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -17988,6 +17988,12 @@
"unknown": "알 수 없는 호스트",
"candidateName": "{{value1}}의 {{value0}}"
}
},
"creation": {
"worktreeReadyToast": "작업 트리 {{name}} 준비 완료",
"workspaceReadyToast": "워크스페이스 {{name}} 준비 완료",
"goToWorktree": "작업 트리로 이동",
"goToWorkspace": "워크스페이스로 이동"
}
},
"agentSessionContinuation": {
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/src/i18n/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -17953,6 +17953,12 @@
"unknown": "未知主机",
"candidateName": "{{value0}} 在 {{value1}} 上"
}
},
"creation": {
"worktreeReadyToast": "工作树 {{name}} 已就绪",
"workspaceReadyToast": "工作区 {{name}} 已就绪",
"goToWorktree": "转到工作树",
"goToWorkspace": "转到工作区"
}
},
"agentSessionContinuation": {
Expand Down
120 changes: 120 additions & 0 deletions src/renderer/src/lib/worktree-creation-backend-startup-focus.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type * as SyncRuntimeGraphModule from '@/runtime/sync-runtime-graph'
import type { PreloadApi } from '../../../preload/api-types'

type CreateTerminalPayload = Parameters<Parameters<PreloadApi['ui']['onCreateTerminal']>[0]>[0]

const { focusRuntimeTerminalSurface } = vi.hoisted(() => ({
focusRuntimeTerminalSurface: vi.fn(() => true)
}))

vi.mock('@/runtime/sync-runtime-graph', async (importOriginal) => ({
...(await importOriginal<typeof SyncRuntimeGraphModule>()),
focusRuntimeTerminalSurface
}))

import { useAppStore } from '@/store'
import { registerTerminalPresentationIpcBridge } from '@/hooks/ipc-events/terminal-presentation-ipc-bridge'
import { activateAndRevealWorktree } from './worktree-activation'
import { queueWorkspaceActivationTerminalFocus } from './workspace-activation-terminal-focus'
import {
makeCreatedAgentWorktree,
seedEmptyActivatableWorktree
} from './worktree-activation-created-agent-test-state'

const initialAppStoreState = useAppStore.getState()
const AGENT_TAB_ID = 'b1a1c0de-0000-4000-8000-000000000001'
const AGENT_LEAF_ID = 'b1a1c0de-0000-4000-8000-000000000002'
const SETUP_TAB_ID = 'b1a1c0de-0000-4000-8000-000000000003'
const SETUP_LEAF_ID = 'b1a1c0de-0000-4000-8000-000000000004'

let revealTerminal: (payload: CreateTerminalPayload) => void
let frames: FrameRequestCallback[]

beforeEach(() => {
frames = []
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => {
frames.push(callback)
return frames.length
})
vi.stubGlobal('cancelAnimationFrame', () => {})
vi.stubGlobal(
'MutationObserver',
class {
observe(): void {}
disconnect(): void {}
}
)
vi.stubGlobal('document', {
activeElement: null,
body: {},
querySelector: () => null,
addEventListener: () => {},
removeEventListener: () => {}
})
vi.stubGlobal('window', {
api: {
ui: {
onCreateTerminal: (listener: typeof revealTerminal) => {
revealTerminal = listener
return () => {}
},
onRequestTerminalTabMount: () => () => {},
replyTerminalCreate: vi.fn()
}
}
})
registerTerminalPresentationIpcBridge([])
})

afterEach(() => {
vi.unstubAllGlobals()
useAppStore.setState(initialAppStoreState, true)
})

describe('a local agent create watched to completion', () => {
it('opens on and focuses the agent tab the host adopted without activating', () => {
const worktree = makeCreatedAgentWorktree()
seedEmptyActivatableWorktree(worktree)
useAppStore.setState({ activeWorktreeId: null, activeTabId: null })

// The host reveals its startup and setup terminals as main sends them for a local create.
revealTerminal({
requestId: 'reveal-agent',
worktreeId: worktree.id,
ptyId: 'pty-agent',
launchAgent: 'codex',
activate: false,
surfaceOwner: false,
tabId: AGENT_TAB_ID,
leafId: AGENT_LEAF_ID
})
revealTerminal({
requestId: 'reveal-setup',
worktreeId: worktree.id,
ptyId: 'pty-setup',
title: 'Setup',
activate: false,
surfaceOwner: false,
tabId: SETUP_TAB_ID,
leafId: SETUP_LEAF_ID
})
expect(useAppStore.getState().activeWorktreeId).toBeNull()

// The completion rule's activation for a user still on the creation panel.
const activation = activateAndRevealWorktree(worktree.id, {
sidebarRevealBehavior: 'auto',
agent: 'codex',
backendStartupTerminalSpawned: true
})
expect(activation).toEqual({ primaryTabId: null })
expect(useAppStore.getState().tabsByWorktree[worktree.id]?.map((tab) => tab.id)).toEqual([
AGENT_TAB_ID,
SETUP_TAB_ID
])

expect(queueWorkspaceActivationTerminalFocus(worktree.id, activation)).toBe(true)
frames.shift()?.(0)
expect(focusRuntimeTerminalSurface).toHaveBeenCalledWith(AGENT_TAB_ID, null, worktree.id)
})
})
Loading
Loading