diff --git a/src/main/runtime/orca-runtime.test.ts b/src/main/runtime/orca-runtime.test.ts index 0b410939a..a005e79a8 100644 --- a/src/main/runtime/orca-runtime.test.ts +++ b/src/main/runtime/orca-runtime.test.ts @@ -176,6 +176,9 @@ const { listGitHubAssignableUsersMock, detectInstalledAgentsWithShellPathHydrationMock, detectRemoteAgentsMock, + markCodexProjectTrustedMock, + markCopilotFolderTrustedMock, + markCursorWorkspaceTrustedMock, listGitLabMergeRequestsMock, listGitLabWorkItemsMock, listGitLabIssuesMock, @@ -267,6 +270,9 @@ const { listGitHubAssignableUsersMock: vi.fn(), detectInstalledAgentsWithShellPathHydrationMock: vi.fn(), detectRemoteAgentsMock: vi.fn(), + markCodexProjectTrustedMock: vi.fn(), + markCopilotFolderTrustedMock: vi.fn(), + markCursorWorkspaceTrustedMock: vi.fn(), listGitLabMergeRequestsMock: vi.fn(), listGitLabWorkItemsMock: vi.fn(), listGitLabIssuesMock: vi.fn(), @@ -333,6 +339,12 @@ vi.mock('../ipc/preflight', () => ({ detectRemoteAgents: detectRemoteAgentsMock })) +vi.mock('../agent-trust-presets', () => ({ + markCodexProjectTrusted: markCodexProjectTrustedMock, + markCopilotFolderTrusted: markCopilotFolderTrustedMock, + markCursorWorkspaceTrusted: markCursorWorkspaceTrustedMock +})) + vi.mock('../hooks', () => ({ buildPosixRunnerScript: (script: string) => `#!/usr/bin/env bash\nset -e\n${script}\n`, buildWindowsRunnerScript: (script: string) => `@echo off\r\n${script}\r\n`, @@ -641,6 +653,9 @@ function resetRuntimeTestMocks(): void { detectInstalledAgentsWithShellPathHydrationMock.mockResolvedValue([]) detectRemoteAgentsMock.mockReset() detectRemoteAgentsMock.mockResolvedValue([]) + markCodexProjectTrustedMock.mockReset() + markCopilotFolderTrustedMock.mockReset() + markCursorWorkspaceTrustedMock.mockReset() listGitLabMergeRequestsMock.mockReset() listGitLabMergeRequestsMock.mockResolvedValue({ items: [] }) listGitLabWorkItemsMock.mockReset() @@ -7028,6 +7043,204 @@ describe('OrcaRuntimeService', () => { }) }) + it('applies Settings agent defaults to bare agent command terminal creates', async () => { + const spawn = vi.fn().mockResolvedValue({ id: 'pty-bg' }) + const runtimeStore = { + ...store, + getSettings: () => ({ + ...store.getSettings(), + disabledTuiAgents: [], + agentCmdOverrides: {}, + agentDefaultArgs: { codex: '--dangerously-bypass-approvals-and-sandbox' }, + agentDefaultEnv: { codex: { CODEX_PROFILE: 'captured' } } + }) + } + const runtime = new OrcaRuntimeService(runtimeStore) + runtime.setPtyController({ + spawn, + write: () => true, + kill: () => true, + getForegroundProcess: async () => null + }) + + await runtime.createTerminal(`path:${TEST_WORKTREE_PATH}`, { + command: 'codex', + title: 'worker' + }) + + const spawnCall = spawn.mock.calls[0]?.[0] as + | { command?: string; env?: Record } + | undefined + expect(spawnCall?.command).toBe("codex '--dangerously-bypass-approvals-and-sandbox'") + expect(spawnCall?.env).toMatchObject({ + CODEX_PROFILE: 'captured', + ORCA_WORKTREE_ID: TEST_WORKTREE_ID + }) + expect(spawnCall?.env?.ORCA_AGENT_LAUNCH_TOKEN).toMatch(UUID_RE) + expect(markCodexProjectTrustedMock).toHaveBeenCalledWith(TEST_WORKTREE_PATH) + expect(markCodexProjectTrustedMock.mock.invocationCallOrder[0]).toBeLessThan( + spawn.mock.invocationCallOrder[0]! + ) + }) + + it('matches canonical bare agent commands when a command override is configured', async () => { + const spawn = vi.fn().mockResolvedValue({ id: 'pty-bg' }) + const runtimeStore = { + ...store, + getSettings: () => ({ + ...store.getSettings(), + disabledTuiAgents: [], + agentCmdOverrides: { codex: 'codex --profile work' }, + agentDefaultArgs: { codex: '--dangerously-bypass-approvals-and-sandbox' }, + agentDefaultEnv: {} + }) + } + const runtime = new OrcaRuntimeService(runtimeStore) + runtime.setPtyController({ + spawn, + write: () => true, + kill: () => true, + getForegroundProcess: async () => null + }) + + await runtime.createTerminal(`path:${TEST_WORKTREE_PATH}`, { + command: 'codex' + }) + + const spawnCall = spawn.mock.calls[0]?.[0] as { command?: string } | undefined + expect(spawnCall?.command).toBe( + "codex --profile work '--dangerously-bypass-approvals-and-sandbox'" + ) + }) + + it('keeps non-bare agent command terminal creates unchanged', async () => { + const spawn = vi.fn().mockResolvedValue({ id: 'pty-bg' }) + const runtimeStore = { + ...store, + getSettings: () => ({ + ...store.getSettings(), + disabledTuiAgents: [], + agentCmdOverrides: {}, + agentDefaultArgs: { codex: '--dangerously-bypass-approvals-and-sandbox' }, + agentDefaultEnv: {} + }) + } + const runtime = new OrcaRuntimeService(runtimeStore) + runtime.setPtyController({ + spawn, + write: () => true, + kill: () => true, + getForegroundProcess: async () => null + }) + + await runtime.createTerminal(`path:${TEST_WORKTREE_PATH}`, { + command: 'codex exec summarize' + }) + + const spawnCall = spawn.mock.calls[0]?.[0] as + | { command?: string; env?: Record } + | undefined + expect(spawnCall?.command).toBe('codex exec summarize') + expect(spawnCall?.env?.ORCA_AGENT_LAUNCH_TOKEN).toBeUndefined() + }) + + it('keeps disabled bare agent command terminal creates unchanged', async () => { + const spawn = vi.fn().mockResolvedValue({ id: 'pty-bg' }) + const runtimeStore = { + ...store, + getSettings: () => ({ + ...store.getSettings(), + disabledTuiAgents: ['codex' as const], + agentCmdOverrides: {}, + agentDefaultArgs: { codex: '--dangerously-bypass-approvals-and-sandbox' }, + agentDefaultEnv: {} + }) + } + const runtime = new OrcaRuntimeService(runtimeStore) + runtime.setPtyController({ + spawn, + write: () => true, + kill: () => true, + getForegroundProcess: async () => null + }) + + await runtime.createTerminal(`path:${TEST_WORKTREE_PATH}`, { + command: 'codex' + }) + + const spawnCall = spawn.mock.calls[0]?.[0] as + | { command?: string; env?: Record } + | undefined + expect(spawnCall?.command).toBe('codex') + expect(spawnCall?.env?.ORCA_AGENT_LAUNCH_TOKEN).toBeUndefined() + }) + + it('sends Settings agent defaults through renderer-backed bare agent terminal creates', async () => { + const runtimeStore = { + ...store, + getSettings: () => ({ + ...store.getSettings(), + disabledTuiAgents: [], + agentCmdOverrides: {}, + agentDefaultArgs: { codex: '--dangerously-bypass-approvals-and-sandbox' }, + agentDefaultEnv: { codex: { CODEX_PROFILE: 'captured' } } + }) + } + const runtime = new OrcaRuntimeService(runtimeStore) + + const webContents = { send: vi.fn() } + webContents.send.mockImplementation((_channel: string, payload: { requestId: string }) => { + runtime.syncWindowGraph(1, { + tabs: [], + leaves: [ + { + tabId: 'tab-renderer', + worktreeId: TEST_WORKTREE_ID, + leafId: 'pane:1', + paneRuntimeId: 1, + ptyId: 'pty-renderer', + paneTitle: null + } + ] + }) + ipcMain.emit( + 'terminal:tabCreateReply', + { sender: webContents }, + { requestId: payload.requestId, tabId: 'tab-renderer', title: 'Codex' } + ) + }) + runtime.attachWindow(1) + runtime.syncWindowGraph(1, { tabs: [], leaves: [] }) + electronMocks.BrowserWindow.fromId.mockReturnValue({ + isDestroyed: () => false, + webContents + }) + + await runtime.createTerminal(`path:${TEST_WORKTREE_PATH}`, { + command: 'codex', + rendererBacked: true + }) + + expect(webContents.send).toHaveBeenCalledWith( + 'terminal:requestTabCreate', + expect.objectContaining({ + worktreeId: TEST_WORKTREE_ID, + command: "codex '--dangerously-bypass-approvals-and-sandbox'", + env: { CODEX_PROFILE: 'captured' }, + launchAgent: 'codex', + launchConfig: { + agentCommand: "codex '--dangerously-bypass-approvals-and-sandbox'", + agentArgs: '--dangerously-bypass-approvals-and-sandbox', + agentEnv: { CODEX_PROFILE: 'captured' } + } + }) + ) + expect(markCodexProjectTrustedMock).toHaveBeenCalledWith(TEST_WORKTREE_PATH) + expect(markCodexProjectTrustedMock.mock.invocationCallOrder[0]).toBeLessThan( + webContents.send.mock.invocationCallOrder[0]! + ) + }) + it('injects runtime hook receiver env into terminal sessions', async () => { const spawn = vi.fn().mockResolvedValue({ id: 'pty-hooked' }) const runtime = new OrcaRuntimeService(store, undefined, { @@ -7243,7 +7456,7 @@ describe('OrcaRuntimeService', () => { expect(compoundClaude.env?.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS).toBeUndefined() expect(compoundClaude.env?.TMUX).toBeUndefined() - expect(normalAgent.command).toBe('codex') + expect(normalAgent.command).toBe("codex '--dangerously-bypass-approvals-and-sandbox'") expect(normalAgent.env?.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS).toBeUndefined() expect(normalAgent.env?.TMUX).toBeUndefined() }) @@ -7602,7 +7815,7 @@ describe('OrcaRuntimeService', () => { }) expect(spawn).toHaveBeenCalledWith( expect.objectContaining({ - command: 'codex', + command: "codex '--dangerously-bypass-approvals-and-sandbox'", cwd: TEST_WORKTREE_PATH, worktreeId: TEST_WORKTREE_ID }) @@ -7671,7 +7884,7 @@ describe('OrcaRuntimeService', () => { expect.objectContaining({ requestId: expect.any(String), worktreeId: TEST_WORKTREE_ID, - command: 'codex', + command: "codex '--dangerously-bypass-approvals-and-sandbox'", title: 'Renderer Terminal' }) ) diff --git a/src/main/runtime/orca-runtime.ts b/src/main/runtime/orca-runtime.ts index cc3e26e59..216235198 100644 --- a/src/main/runtime/orca-runtime.ts +++ b/src/main/runtime/orca-runtime.ts @@ -186,7 +186,11 @@ import { resolveTuiAgentLaunchArgs, resolveTuiAgentLaunchEnv } from '../../shared/tui-agent-launch-defaults' -import { isTuiAgent, TUI_AGENT_CONFIG } from '../../shared/tui-agent-config' +import { + getTuiAgentLaunchCommand, + isTuiAgent, + TUI_AGENT_CONFIG +} from '../../shared/tui-agent-config' import { createDraftPasteReadyScanner } from '../../shared/draft-paste-ready-scanner' import { detectInstalledAgentsWithShellPathHydration, detectRemoteAgents } from '../ipc/preflight' import { @@ -944,6 +948,32 @@ type RuntimePtyWorktreeRecord = { waitBlockedAt: number | null } +type TerminalCreateOptions = { + command?: string + claudeAgentTeamsSourceCommand?: string + cwd?: string + env?: Record + launchConfig?: WorktreeStartupLaunch['launchConfig'] + launchToken?: string + launchAgent?: TuiAgent + startupCommandDelivery?: WorktreeStartupLaunch['startupCommandDelivery'] + telemetry?: WorktreeStartupLaunch['telemetry'] + title?: string + focus?: boolean + rendererBacked?: boolean + activate?: boolean + presentation?: RuntimeTerminalPresentation + tabId?: string + leafId?: string + sessionId?: string + persistHostSessionBinding?: boolean + // Why: the headless mobile-session create publishes its own authoritative + // snapshot (with the correct target group) right after spawn. Skip the + // intermediate pty-backed publish so the new tab doesn't briefly flash in + // the wrong (active) group before the corrected snapshot lands. + deferMobileSessionPublish?: boolean +} + type PtyForegroundAgentRefresh = { promise: Promise startedAfterTitleObservation: number @@ -960,6 +990,44 @@ function copySleepingAgentLaunchConfig( } } +function normalizeAgentLaunchCommandForMatch(command: string): string { + return command.trim().replace(/\s+/g, ' ') +} + +function resolveBareAgentLaunchCommand(args: { + command: string | undefined + settings: { + agentCmdOverrides?: Partial> | null + disabledTuiAgents?: Iterable | null + } + platform: NodeJS.Platform + isRemote: boolean +}): TuiAgent | null { + const command = args.command ? normalizeAgentLaunchCommandForMatch(args.command) : '' + if (!command) { + return null + } + + const cmdOverrides = args.settings.agentCmdOverrides ?? {} + for (const agent of Object.keys(TUI_AGENT_CONFIG) as TuiAgent[]) { + if (!isTuiAgentEnabled(agent, args.settings.disabledTuiAgents)) { + continue + } + const override = cmdOverrides[agent]?.trim() + const defaultLaunchCommand = getTuiAgentLaunchCommand(TUI_AGENT_CONFIG[agent], args.platform, { + isRemote: args.isRemote + }) + const launchCommands = override ? [defaultLaunchCommand, override] : [defaultLaunchCommand] + if ( + launchCommands.some((candidate) => command === normalizeAgentLaunchCommandForMatch(candidate)) + ) { + return agent + } + } + + return null +} + function inferCapturedClaudeAgentTeamsMode( launchConfig: SleepingAgentLaunchConfig | undefined, command: string | undefined, @@ -15445,33 +15513,71 @@ export class OrcaRuntimeService { return { handle, tabId: leaf.tabId, title } } + private async resolveAgentTerminalCreateOptions( + workspace: TerminalWorkspaceLaunchScope, + opts: TerminalCreateOptions + ): Promise { + // Why: raw shell commands like `codex exec` must remain user-authored shell. + // Only unmanaged, repo-backed, bare agent launches get Settings defaults. + if ( + !opts.command || + opts.env || + opts.launchConfig || + opts.launchAgent || + opts.startupCommandDelivery || + opts.claudeAgentTeamsSourceCommand || + !workspace.repo || + !this.store + ) { + return opts + } + + const settings = this.store.getSettings() + const platform = this.getAgentLaunchPlatformForWorkspace(workspace) + const isRemote = repoIsRemote(workspace.repo) + const agent = resolveBareAgentLaunchCommand({ + command: opts.command, + settings, + platform, + isRemote + }) + if (!agent) { + return opts + } + + const startupPlan = buildAgentStartupPlan({ + agent, + prompt: '', + cmdOverrides: settings.agentCmdOverrides ?? {}, + agentArgs: resolveTuiAgentLaunchArgs(agent, settings.agentDefaultArgs), + agentEnv: resolveTuiAgentLaunchEnv(agent, settings.agentDefaultEnv), + platform, + isRemote, + allowEmptyPromptLaunch: true + }) + if (!startupPlan) { + return opts + } + + if (workspace.connectionId) { + await this.markRemoteWorkspaceTrustedForAgent(agent, workspace.connectionId, workspace.path) + } else { + this.markLocalWorkspaceTrustedForAgent(agent, workspace.path) + } + + return { + ...opts, + command: startupPlan.launchCommand, + ...(startupPlan.env ? { env: startupPlan.env } : {}), + launchConfig: startupPlan.launchConfig, + launchAgent: agent, + startupCommandDelivery: startupPlan.startupCommandDelivery + } + } + async createTerminal( worktreeSelector?: string, - opts: { - command?: string - claudeAgentTeamsSourceCommand?: string - cwd?: string - env?: Record - launchConfig?: WorktreeStartupLaunch['launchConfig'] - launchToken?: string - launchAgent?: TuiAgent - startupCommandDelivery?: WorktreeStartupLaunch['startupCommandDelivery'] - telemetry?: WorktreeStartupLaunch['telemetry'] - title?: string - focus?: boolean - rendererBacked?: boolean - activate?: boolean - presentation?: RuntimeTerminalPresentation - tabId?: string - leafId?: string - sessionId?: string - persistHostSessionBinding?: boolean - // Why: the headless mobile-session create publishes its own authoritative - // snapshot (with the correct target group) right after spawn. Skip the - // intermediate pty-backed publish so the new tab doesn't briefly flash in - // the wrong (active) group before the corrected snapshot lands. - deferMobileSessionPublish?: boolean - } = {} + opts: TerminalCreateOptions = {} ): Promise { const presentation = resolveTerminalPresentation(opts) const requiresRendererFocus = opts.presentation === 'focused' || opts.focus === true @@ -15494,7 +15600,9 @@ export class OrcaRuntimeService { throw new Error('runtime_unavailable') } const workspace = await this.resolveTerminalWorkspaceLaunchScope(worktreeSelector) - const cwd = this.resolveGuardedWorkspaceTerminalCwd(workspace, opts.cwd) ?? workspace.path + const launchOpts = await this.resolveAgentTerminalCreateOptions(workspace, opts) + const cwd = + this.resolveGuardedWorkspaceTerminalCwd(workspace, launchOpts.cwd) ?? workspace.path const preAllocatedHandle = this.createPreAllocatedTerminalHandle() // Why: mint tabId in main before spawn so paneKey is known at PTY env // build time. Hook-based agent status (Claude/Codex/Cursor/Gemini) keys @@ -15502,25 +15610,27 @@ export class OrcaRuntimeService { // hook payload arrives with an empty paneKey and the renderer cannot // attribute the event. Use a stable UUID leaf because hooks reject the // legacy numeric pane keys after the pane-id migration. - const hintedTabId = opts.tabId?.trim() + const hintedTabId = launchOpts.tabId?.trim() const canAdoptPaneIdentity = hintedTabId !== undefined && isValidHostTerminalTabId(hintedTabId) && - opts.leafId !== undefined && - isTerminalLeafId(opts.leafId) + launchOpts.leafId !== undefined && + isTerminalLeafId(launchOpts.leafId) const tabId = canAdoptPaneIdentity ? (hintedTabId as string) : randomUUID() - const leafId = canAdoptPaneIdentity ? (opts.leafId as string) : randomUUID() + const leafId = canAdoptPaneIdentity ? (launchOpts.leafId as string) : randomUUID() const paneKey = makePaneKey(tabId, leafId) - const launchToken = opts.launchConfig ? (opts.launchToken ?? randomUUID()) : undefined + const launchToken = launchOpts.launchConfig + ? (launchOpts.launchToken ?? randomUUID()) + : undefined const baseEnv = { - ...opts.env, + ...launchOpts.env, ...(launchToken ? { ORCA_AGENT_LAUNCH_TOKEN: launchToken } : {}) } const claudeAgentTeamsSourceCommand = - opts.claudeAgentTeamsSourceCommand?.trim() || opts.command?.trim() || undefined + launchOpts.claudeAgentTeamsSourceCommand?.trim() || launchOpts.command?.trim() || undefined const claudeAgentTeamsMode = this.store?.getSettings?.().claudeAgentTeamsMode const effectiveClaudeAgentTeamsMode = inferCapturedClaudeAgentTeamsMode( - opts.launchConfig, + launchOpts.launchConfig, claudeAgentTeamsSourceCommand, claudeAgentTeamsMode ) @@ -15545,25 +15655,25 @@ export class OrcaRuntimeService { const sequencedStartupCommand = agentTeamsPlan && claudeAgentTeamsSourceCommand && - opts.command && - claudeAgentTeamsSourceCommand !== opts.command + launchOpts.command && + claudeAgentTeamsSourceCommand !== launchOpts.command ? agentTeamsPlan.command : undefined const effectiveLaunchConfig = - opts.launchConfig && agentTeamsPlan + launchOpts.launchConfig && agentTeamsPlan ? { - ...opts.launchConfig, - agentCommand: opts.launchConfig.agentCommand + ...launchOpts.launchConfig, + agentCommand: launchOpts.launchConfig.agentCommand ? effectiveClaudeAgentTeamsMode === 'in-process' || process.platform === 'win32' - ? addClaudeTeammateModeInProcess(opts.launchConfig.agentCommand) - : addClaudeTeammateModeAuto(opts.launchConfig.agentCommand) + ? addClaudeTeammateModeInProcess(launchOpts.launchConfig.agentCommand) + : addClaudeTeammateModeAuto(launchOpts.launchConfig.agentCommand) : agentTeamsPlan.command, agentEnv: { - ...opts.launchConfig.agentEnv, + ...launchOpts.launchConfig.agentEnv, ...agentTeamsPlan.env } } - : opts.launchConfig + : launchOpts.launchConfig // Why: setup/agent sequencing wraps the PTY launch in a wait shell before // Claude Agent Teams runs. Preserve the direct Claude command separately // so the wrapper can exec the teammate-mode variant after setup completes. @@ -15583,29 +15693,31 @@ export class OrcaRuntimeService { cols: 120, rows: 40, cwd, - command: sequencedStartupCommand ? opts.command : (agentTeamsPlan?.command ?? opts.command), + command: sequencedStartupCommand + ? launchOpts.command + : (agentTeamsPlan?.command ?? launchOpts.command), commandDelivery: 'provider', - startupCommandDelivery: opts.startupCommandDelivery, + startupCommandDelivery: launchOpts.startupCommandDelivery, env, envToDelete: agentTeamsPlan?.envToDelete, - telemetry: opts.telemetry, + telemetry: launchOpts.telemetry, connectionId: workspace.connectionId, worktreeId: workspace.id, preAllocatedHandle, tabId, leafId, - ...(opts.sessionId ? { sessionId: opts.sessionId } : {}), - ...(opts.persistHostSessionBinding ? { persistHostSessionBinding: true } : {}) + ...(launchOpts.sessionId ? { sessionId: launchOpts.sessionId } : {}), + ...(launchOpts.persistHostSessionBinding ? { persistHostSessionBinding: true } : {}) }) this.registerPreAllocatedHandleForPty(result.id, preAllocatedHandle) this.registerPty(result.id, workspace.id, workspace.connectionId) const pty = this.getOrCreatePtyWorktreeRecord(result.id) if (pty) { - if (opts.title) { + if (launchOpts.title) { const observedAt = this.nextTitleObservationSequence() - pty.title = opts.title + pty.title = launchOpts.title pty.titleUpdatedAt = observedAt - this.setPtyManagementTitleFromObservedTitle(pty, opts.title, observedAt) + this.setPtyManagementTitleFromObservedTitle(pty, launchOpts.title, observedAt) } else { pty.title = null pty.titleUpdatedAt = null @@ -15616,14 +15728,14 @@ export class OrcaRuntimeService { ? copySleepingAgentLaunchConfig(effectiveLaunchConfig) : null pty.launchToken = launchToken ?? null - pty.launchAgent = opts.launchAgent ?? null + pty.launchAgent = launchOpts.launchAgent ?? null } const handle = pty ? this.issuePtyHandle(pty) : preAllocatedHandle - if (pty && opts.deferMobileSessionPublish !== true) { + if (pty && launchOpts.deferMobileSessionPublish !== true) { this.publishPtyBackedMobileSessionTerminal(workspace.id, pty, { tabId, leafId, - title: opts.title ?? null, + title: launchOpts.title ?? null, activate: presentation === 'focused', // Why: explicit background presentation may carry legacy activate // metadata from an already-owned renderer pane; don't select it on mobile. @@ -15641,11 +15753,11 @@ export class OrcaRuntimeService { // already baked into the PTY env — keeps paneKey hook attribution intact. await this.notifier.revealTerminalSession(workspace.id, { ptyId: result.id, - title: opts.title ?? null, + title: launchOpts.title ?? null, ...(cwd !== workspace.path ? { cwd } : {}), ...(effectiveLaunchConfig ? { launchConfig: effectiveLaunchConfig } : {}), ...(launchToken ? { launchToken } : {}), - ...(opts.launchAgent ? { launchAgent: opts.launchAgent } : {}), + ...(launchOpts.launchAgent ? { launchAgent: launchOpts.launchAgent } : {}), activate: presentation === 'focused', ...(presentation ? { presentation } : {}), tabId, @@ -15665,7 +15777,7 @@ export class OrcaRuntimeService { paneKey, ptyId: result.id, worktreeId: workspace.id, - title: opts.title ?? null, + title: launchOpts.title ?? null, surface, ...(warning ? { warning } : {}) } @@ -15678,8 +15790,13 @@ export class OrcaRuntimeService { const workspace = worktreeSelector ? await this.resolveTerminalWorkspaceLaunchScope(worktreeSelector) : null + const launchOpts = workspace + ? await this.resolveAgentTerminalCreateOptions(workspace, opts) + : opts const worktreeId = workspace?.id - const cwd = workspace ? this.resolveGuardedWorkspaceTerminalCwd(workspace, opts.cwd) : opts.cwd + const cwd = workspace + ? this.resolveGuardedWorkspaceTerminalCwd(workspace, launchOpts.cwd) + : launchOpts.cwd const requestId = randomUUID() // Why: terminal creation is a renderer-side Zustand store operation (like @@ -15703,21 +15820,21 @@ export class OrcaRuntimeService { if (r.error) { reject(new Error(r.error)) } else { - resolve({ tabId: r.tabId!, title: r.title ?? opts.title ?? '' }) + resolve({ tabId: r.tabId!, title: r.title ?? launchOpts.title ?? '' }) } } ipcMain.on('terminal:tabCreateReply', handler) win.webContents.send('terminal:requestTabCreate', { requestId, worktreeId, - command: opts.command, + command: launchOpts.command, cwd, - ...(opts.env ? { env: opts.env } : {}), - ...(opts.launchConfig ? { launchConfig: opts.launchConfig } : {}), - ...(opts.launchToken ? { launchToken: opts.launchToken } : {}), - ...(opts.launchAgent ? { launchAgent: opts.launchAgent } : {}), - startupCommandDelivery: opts.startupCommandDelivery, - title: opts.title, + ...(launchOpts.env ? { env: launchOpts.env } : {}), + ...(launchOpts.launchConfig ? { launchConfig: launchOpts.launchConfig } : {}), + ...(launchOpts.launchToken ? { launchToken: launchOpts.launchToken } : {}), + ...(launchOpts.launchAgent ? { launchAgent: launchOpts.launchAgent } : {}), + startupCommandDelivery: launchOpts.startupCommandDelivery, + title: launchOpts.title, activate: presentation === 'focused', ...(presentation ? { presentation } : {}) }) diff --git a/src/main/startup/desktop-startup-ordering.test.ts b/src/main/startup/desktop-startup-ordering.test.ts index 276242040..7939af31a 100644 --- a/src/main/startup/desktop-startup-ordering.test.ts +++ b/src/main/startup/desktop-startup-ordering.test.ts @@ -41,10 +41,7 @@ describe('desktop startup ordering', () => { const runtimeRpcStart = source.indexOf('await runtimeRpc.start()', serveStart) const automationStart = source.indexOf('automations.start()', serveStart) const desktopSetWebContents = source.indexOf('automations.setWebContents(window.webContents)') - const desktopAutomationStart = source.indexOf( - 'automations.start()', - desktopSetWebContents + 1 - ) + const desktopAutomationStart = source.indexOf('automations.start()', desktopSetWebContents + 1) expect(serveStart).toBeGreaterThanOrEqual(0) expect(serveReady).toBeGreaterThan(serveStart)