Files
orca/mobile/src/tasks/workspace-create-params.ts
T
Kaynan Sampaio de Camargoandkaynan 69d05b6e24 fix(mobile): resolve permission args when a new session launches an agent (#8469)
The New Workspace flow built a bare launch command client-side and sent it as
`startupCommand`, so the host ran it verbatim and never applied the default
launch args. The first Claude session therefore started in manual mode, while
opening another Claude via the "+" tab (which sends the agent id and lets the
host resolve args) started with `--dangerously-skip-permissions`.

Send `startupAgent` from every client-built create path (blank, reuse-branch,
and new-branch) so the host resolves the launch command, args, env, and
host-shell quoting through the same path the "+" new-tab and CLI use. The
work-item path already delegated via `startupDraft`. Custom `agentDefaultArgs`
are now honored on all paths.

Adds a shared `agentLaunchCreateFields` helper and removes the now-unused
client-side command map, which had also drifted from the canonical launch
commands for continue, hermes, command-code, kiro, and mistral-vibe.

Claude-Session: https://claude.ai/code/session_014iufZnQwPD2obYuvdahjaE

Co-authored-by: kaynan <kaynan.camargo@terceiro-sky.com.br>
2026-07-24 00:29:19 -07:00

179 lines
5.3 KiB
TypeScript

import type {
CreateSparseCheckoutRequest,
GitPushTarget,
SetupDecision,
TuiAgent
} from '../../../src/shared/types'
import { getWorkspaceSourceName } from '../../../src/shared/new-workspace/workspace-source'
import { resolveMobileWorkspaceCreateName } from './mobile-workspace-name'
import type { WorkspaceAgentChoice } from './workspace-agent-selection'
export type WorkspaceCreateSetupDecision = SetupDecision
export type WorkspaceCreateSparseCheckout = CreateSparseCheckoutRequest
export type WorkspaceCreateGitPushTarget = GitPushTarget
export type WorkspaceCreateHostedStartPoint = {
baseBranch: string
pushTarget?: WorkspaceCreateGitPushTarget
}
type WorkspaceCreateGitHubItem = {
provider: 'github'
source: {
type: 'issue' | 'pr'
repoId: string
number: number
title: string
url: string
}
}
type WorkspaceCreateGitLabItem = {
provider: 'gitlab'
source: {
type: 'issue' | 'mr'
repoId: string
number: number
title: string
url: string
}
}
type WorkspaceCreateLinearItem = {
provider: 'linear'
source: {
identifier: string
title: string
url: string
workspaceId?: string
organizationUrlKey?: string
}
}
export type WorkspaceCreateTaskItem =
| WorkspaceCreateGitHubItem
| WorkspaceCreateGitLabItem
| WorkspaceCreateLinearItem
export type WorkspaceCreateParams = Record<string, unknown>
/**
* `worktree.create` fields for launching the picked agent in a fresh session.
*
* Why: send the agent id so the host resolves launch args (permission flags)
* and host-shell quoting, matching the "+" new-tab and CLI paths.
*/
export function agentLaunchCreateFields(agentId: TuiAgent | undefined): {
startupAgent?: TuiAgent
createdWithAgent?: TuiAgent
} {
if (!agentId) {
return {}
}
return { startupAgent: agentId, createdWithAgent: agentId }
}
export function buildTaskWorkspaceCreateParams(args: {
item: WorkspaceCreateTaskItem
targetRepoId: string
setupDecision: WorkspaceCreateSetupDecision
agent?: WorkspaceAgentChoice
workspaceName?: string
note?: string
baseBranch?: string
compareBaseRef?: string
branchNameOverride?: string
pushTarget?: WorkspaceCreateGitPushTarget
sparseCheckout?: WorkspaceCreateSparseCheckout
hostedStartPoint?: WorkspaceCreateHostedStartPoint
nameIsAutoManaged?: boolean
}): WorkspaceCreateParams {
const {
item,
targetRepoId,
setupDecision,
agent,
workspaceName,
note,
baseBranch,
compareBaseRef,
branchNameOverride,
pushTarget,
sparseCheckout,
hostedStartPoint,
nameIsAutoManaged = true
} = args
const shouldLaunchAgent = agent !== 'blank'
const createdWithAgent = shouldLaunchAgent ? (agent as TuiAgent) : undefined
const comment = note?.trim()
const selectedBaseBranch = baseBranch || hostedStartPoint?.baseBranch
const selectedPushTarget = pushTarget ?? hostedStartPoint?.pushTarget
// Why: desktop only sends displayName while the name is still auto-derived; a
// user-edited name suppresses it so the runtime keeps the user's chosen name.
const sourceName =
item.provider === 'linear'
? getWorkspaceSourceName({
provider: 'linear',
type: 'issue',
number: 0,
title: item.source.title,
url: item.source.url,
linearIdentifier: item.source.identifier
})
: getWorkspaceSourceName({ provider: item.provider, ...item.source })
const displayName = nameIsAutoManaged ? { displayName: sourceName.displayName } : {}
const common = {
setupDecision,
activate: true,
...(shouldLaunchAgent ? { startupDraft: item.source.url } : {}),
...(createdWithAgent ? { createdWithAgent } : {}),
...(selectedBaseBranch ? { baseBranch: selectedBaseBranch } : {}),
...(compareBaseRef ? { compareBaseRef } : {}),
...(branchNameOverride ? { branchNameOverride } : {}),
...(selectedPushTarget ? { pushTarget: selectedPushTarget } : {}),
...(sparseCheckout ? { sparseCheckout } : {}),
...(comment ? { comment } : {})
}
if (item.provider === 'github') {
const fallback = `${item.source.type}-${item.source.number}`
return {
repo: `id:${item.source.repoId}`,
name: resolveMobileWorkspaceCreateName({ draft: workspaceName, fallback }),
...displayName,
...common,
...(item.source.type === 'issue'
? { linkedIssue: item.source.number }
: { linkedPR: item.source.number })
}
}
if (item.provider === 'gitlab') {
const fallback = `${item.source.type}-${item.source.number}`
return {
repo: `id:${item.source.repoId}`,
name: resolveMobileWorkspaceCreateName({ draft: workspaceName, fallback }),
...displayName,
...common,
...(item.source.type === 'issue'
? { linkedGitLabIssue: item.source.number }
: { linkedGitLabMR: item.source.number })
}
}
return {
repo: `id:${targetRepoId}`,
name: resolveMobileWorkspaceCreateName({
draft: workspaceName,
fallback: item.source.identifier.toLowerCase()
}),
...displayName,
linkedLinearIssue: item.source.identifier,
...(item.source.workspaceId ? { linkedLinearIssueWorkspaceId: item.source.workspaceId } : {}),
...(item.source.organizationUrlKey
? { linkedLinearIssueOrganizationUrlKey: item.source.organizationUrlKey }
: {}),
...common
}
}