mirror of
https://github.com/stablyai/orca.git
synced 2026-10-18 00:03:20 +00:00
* feat(mobile): start a workspace from a branch, issue/PR, or Linear ticket Unify mobile workspace creation with desktop. The "+" Create Workspace modal now has a primary "Start from" field that opens a tabbed search drawer (Branch · GitHub · GitLab · Linear), letting a user start a workspace from an existing/new git branch, a GitHub issue/PR, a GitLab issue/MR, or a Linear ticket — in addition to the default blank workspace. No new backend is required: the search RPCs (github.listWorkItems, gitlab.listWorkItems, linear.searchIssues/listIssues, repo.searchRefs) and the worktree.create linked-item params were already used by the mobile Tasks screen. This surfaces them in the create flow, reusing the existing pure modules (buildTaskWorkspaceCreateParams, shouldResolveHostedReviewStartPoint, filterAvailableTaskProviders). Details: - New pure modules: workspace-source-selection, use-workspace-source-search, source-workspace-create, worktree-create-retry, blank-workspace-create (the blank/retry path extracted from the modal for reuse + line budget). - New UI: WorkspaceSourcePickerDrawer (+ row) and SetupHookTrustDrawer (extracted from the modal). - Older paired desktops (missing the mobile.tasks.v1 capability) degrade to Branch + Blank only; GitLab/Linear tabs appear only when available. - GitHub/GitLab sources pin their repo; switching repos resets the source. PR/MR sources resolve their base branch at create time; SSH repos gate search until connected (Linear search is repo/SSH-independent). * fix(mobile): hydrate settings/trust before availability probes settle Review fixes for #7985: setTrustedOrcaHooks/setRuntimeSettings no longer wait on status.get/preflight.check/linear.status (a first-open preflight.check can take seconds, widening the spurious setup-trust re-prompt window). Also adds param-parity tests for createBlankWorkspace and a GitLab MR base-resolve test. * feat(mobile): match desktop's Smart source picker exactly Rework the mobile create-workspace source picker to be a faithful port of desktop's Smart picker instead of the earlier divergent "Start from" drawer. The mobile field is now the workspace-name input AND the source search, with the exact desktop tabs — Smart · GitHub · Linear · GitLab · Branch · Name. "Smart" fans out across GitHub + GitLab + Linear + branches, prepends a "Use '<name>'" row, and resolves pasted URLs / #123 / STA-42 to exact items (with a cross-repo switch prompt). Selecting a source shows a pill and moves the editable name into Advanced. The invented "Blank workspace" concept is removed — the neutral state is just a typed/empty name (blank submit still yields a creature name). DRY: the pure desktop logic (smart-workspace-source-results, -command-value, github-links, gitlab-links, work-item-link-query-bounds, github-work-item-identity) moves to src/shared/new-workspace/ with re-export shims at the old renderer paths, so both renderer and mobile share one implementation. composer-branch-selection and workspace-name were already shared and are reused directly. Two read-only lookup RPCs are allowlisted for mobile so pasted GitLab URLs and cross-repo GitHub URLs resolve to exact items (github.workItemByOwnerRepo, gitlab.workItemByPath). New mobile modules are split for max-lines: use-mobile-composer-source (selection state + desktop-parity handlers, PR/MR base resolve), use-smart-workspace-source + smart-source-fan-out/-search-requests/-paste-intent (RPC orchestration), composer-linked-work-item / work-item-lookup-text / mobile-smart-source-modes (pure logic), and SmartWorkspaceSourceField/Drawer/Row + SmartWorkspaceAdvancedFields. Replaces WorkspaceSourcePickerDrawer/Row, workspace-source-selection, use-workspace-source-search, and MobileWorkspaceNameInput. Reviewed by three adversarial agents + re-reviewed after fixes: GitHub search now returns issues AND PRs (not issues-only), Linear defaults to assigned, create-branch preserves slashy names, cross-repo PR base resolves against the item's own repo, displayName is suppressed for user-edited names, and the smart-mode GitHub fan-out respects availability. tsc/oxlint/max-lines-ratchet clean; 1328 mobile tests pass. * fix(mobile): keep smart source drawer fully visible * refactor: share workspace creation behavior across clients * fix: address workspace creation review findings --------- Co-authored-by: Brennan Benson <brennanbenson@Brennans-MacBook-Pro.local>
251 lines
8.4 KiB
TypeScript
251 lines
8.4 KiB
TypeScript
import type { RpcClient } from '../transport/rpc-client'
|
|
import { resolveComposerMrBase, resolveComposerPrBase } from './composer-source-base-resolve'
|
|
import type {
|
|
MobileComposerCreateSelection,
|
|
MobileLinkedWorkItem
|
|
} from './mobile-composer-source-types'
|
|
import { resolveMobileWorkspaceCreateName } from './mobile-workspace-name'
|
|
import type { WorkspaceAgentChoice } from './workspace-agent-selection'
|
|
import {
|
|
buildTaskWorkspaceCreateParams,
|
|
type WorkspaceCreateSetupDecision,
|
|
type WorkspaceCreateTaskItem
|
|
} from './workspace-create-params'
|
|
import { createWorktreeWithNameRetry, type WorktreeCreateResult } from './worktree-create-retry'
|
|
|
|
// The agent bundle the modal already resolved: the choice drives
|
|
// buildTaskWorkspaceCreateParams for work-item sources; the explicit launch
|
|
// command is used for branch sources (which have no work-item URL to seed the draft).
|
|
export type WorkspaceCreateAgentBundle = {
|
|
choice: WorkspaceAgentChoice
|
|
startupCommand: string | undefined
|
|
}
|
|
|
|
export type CreateWorkspaceFromComposerArgs = {
|
|
client: RpcClient
|
|
selection: MobileComposerCreateSelection
|
|
targetRepoId: string
|
|
setupDecision: WorkspaceCreateSetupDecision
|
|
agent: WorkspaceCreateAgentBundle
|
|
workspaceName: string | undefined
|
|
note: string | undefined
|
|
nameIsAutoManaged?: boolean
|
|
}
|
|
|
|
export async function createWorkspaceFromComposerSource(
|
|
args: CreateWorkspaceFromComposerArgs
|
|
): Promise<WorktreeCreateResult> {
|
|
if (args.selection.kind === 'branch') {
|
|
return createBranchWorkspace({ ...args, selection: args.selection })
|
|
}
|
|
if (args.selection.kind === 'new-branch') {
|
|
return createNewBranchWorkspace({ ...args, selection: args.selection })
|
|
}
|
|
return createWorkItemWorkspace({ ...args, selection: args.selection })
|
|
}
|
|
|
|
function toTaskItem(item: MobileLinkedWorkItem, targetRepoId: string): WorkspaceCreateTaskItem {
|
|
if (item.provider === 'github') {
|
|
return {
|
|
provider: 'github',
|
|
source: {
|
|
type: item.type === 'pr' ? 'pr' : 'issue',
|
|
repoId: item.repoId ?? targetRepoId,
|
|
number: item.number,
|
|
title: item.title,
|
|
url: item.url
|
|
}
|
|
}
|
|
}
|
|
if (item.provider === 'gitlab') {
|
|
return {
|
|
provider: 'gitlab',
|
|
source: {
|
|
type: item.type === 'mr' ? 'mr' : 'issue',
|
|
repoId: item.repoId ?? targetRepoId,
|
|
number: item.number,
|
|
title: item.title,
|
|
url: item.url
|
|
}
|
|
}
|
|
}
|
|
return {
|
|
provider: 'linear',
|
|
source: {
|
|
identifier: item.linearIdentifier ?? '',
|
|
title: item.title,
|
|
url: item.url,
|
|
...(item.linearWorkspaceId ? { workspaceId: item.linearWorkspaceId } : {}),
|
|
...(item.linearOrganizationUrlKey
|
|
? { organizationUrlKey: item.linearOrganizationUrlKey }
|
|
: {})
|
|
}
|
|
}
|
|
}
|
|
|
|
async function createWorkItemWorkspace(args: {
|
|
client: RpcClient
|
|
selection: Extract<MobileComposerCreateSelection, { kind: 'work-item' }>
|
|
targetRepoId: string
|
|
setupDecision: WorkspaceCreateSetupDecision
|
|
agent: WorkspaceCreateAgentBundle
|
|
workspaceName: string | undefined
|
|
note: string | undefined
|
|
nameIsAutoManaged?: boolean
|
|
}): Promise<WorktreeCreateResult> {
|
|
const { client, selection, targetRepoId, setupDecision, agent, workspaceName, note } = args
|
|
const item = selection.item
|
|
const taskItem = toTaskItem(item, targetRepoId)
|
|
|
|
// The composer resolves PR/MR base at select time; only re-resolve as a
|
|
// fallback when a linked PR/MR reached create without one.
|
|
let baseBranch = selection.baseBranch
|
|
let compareBaseRef = selection.compareBaseRef
|
|
let pushTarget = selection.pushTarget
|
|
let branchNameOverride = selection.branchNameOverride
|
|
if (!baseBranch && item.provider !== 'linear' && (item.type === 'pr' || item.type === 'mr')) {
|
|
const repoId = item.repoId ?? targetRepoId
|
|
const resolved =
|
|
item.type === 'pr'
|
|
? await resolveComposerPrBase({ client, repoId, prNumber: item.number }).catch(() => null)
|
|
: await resolveComposerMrBase({ client, repoId, mrIid: item.number }).catch(() => null)
|
|
if (resolved) {
|
|
baseBranch = resolved.baseBranch
|
|
compareBaseRef = resolved.compareBaseRef
|
|
pushTarget = resolved.pushTarget
|
|
branchNameOverride = resolved.branchNameOverride ?? branchNameOverride
|
|
}
|
|
}
|
|
|
|
const params = buildTaskWorkspaceCreateParams({
|
|
item: taskItem,
|
|
targetRepoId,
|
|
setupDecision,
|
|
agent: agent.choice,
|
|
workspaceName,
|
|
note,
|
|
baseBranch,
|
|
compareBaseRef,
|
|
branchNameOverride,
|
|
pushTarget,
|
|
nameIsAutoManaged: args.nameIsAutoManaged
|
|
})
|
|
// buildTaskWorkspaceCreateParams computes the name; reuse it as the retry base
|
|
// so collisions still append -2, -3, ... like the blank path does.
|
|
const baseName = String(params.name)
|
|
return createWorktreeWithNameRetry({
|
|
client,
|
|
baseName,
|
|
buildParams: (name) => ({ ...params, name })
|
|
})
|
|
}
|
|
|
|
async function createBranchWorkspace(args: {
|
|
client: RpcClient
|
|
selection: Extract<MobileComposerCreateSelection, { kind: 'branch' }>
|
|
targetRepoId: string
|
|
setupDecision: WorkspaceCreateSetupDecision
|
|
agent: WorkspaceCreateAgentBundle
|
|
workspaceName: string | undefined
|
|
note: string | undefined
|
|
}): Promise<WorktreeCreateResult> {
|
|
const { client, selection, targetRepoId, setupDecision, agent, workspaceName, note } = args
|
|
const createdWithAgentId = agent.choice === 'blank' ? undefined : agent.choice
|
|
const comment = note?.trim()
|
|
const applyCommon = (params: Record<string, unknown>): Record<string, unknown> => {
|
|
if (createdWithAgentId) {
|
|
params.createdWithAgent = createdWithAgentId
|
|
}
|
|
if (comment) {
|
|
params.comment = comment
|
|
}
|
|
return params
|
|
}
|
|
|
|
if (selection.reuse) {
|
|
// Reusing a fixed existing branch: branchNameOverride is pinned to the reused
|
|
// branch, so a branch collision can't be cleared by suffixing the display
|
|
// name — fail fast instead of burning the retry budget.
|
|
const baseName = resolveMobileWorkspaceCreateName({
|
|
draft: workspaceName,
|
|
fallback: selection.localBranchName
|
|
})
|
|
return createWorktreeWithNameRetry({
|
|
client,
|
|
baseName,
|
|
maxAttempts: 1,
|
|
buildParams: (name) =>
|
|
applyCommon({
|
|
repo: `id:${targetRepoId}`,
|
|
name,
|
|
setupDecision,
|
|
baseBranch: selection.refName,
|
|
branchNameOverride: selection.localBranchName,
|
|
startupCommand: agent.startupCommand
|
|
})
|
|
})
|
|
}
|
|
|
|
// New branch off the selected ref. The retry base is the branch name so a
|
|
// collision bumps the branch itself.
|
|
const baseName = resolveMobileWorkspaceCreateName({
|
|
draft: workspaceName,
|
|
fallback: selection.branchNameOverride || selection.localBranchName
|
|
})
|
|
return createWorktreeWithNameRetry({
|
|
client,
|
|
baseName,
|
|
buildParams: (candidate) => {
|
|
const params: Record<string, unknown> = {
|
|
repo: `id:${targetRepoId}`,
|
|
name: candidate,
|
|
setupDecision,
|
|
baseBranch: selection.baseBranch,
|
|
startupCommand: agent.startupCommand
|
|
}
|
|
if (selection.branchNameOverride) {
|
|
params.branchNameOverride = candidate
|
|
}
|
|
return applyCommon(params)
|
|
}
|
|
})
|
|
}
|
|
|
|
async function createNewBranchWorkspace(args: {
|
|
client: RpcClient
|
|
selection: Extract<MobileComposerCreateSelection, { kind: 'new-branch' }>
|
|
targetRepoId: string
|
|
setupDecision: WorkspaceCreateSetupDecision
|
|
agent: WorkspaceCreateAgentBundle
|
|
workspaceName: string | undefined
|
|
note: string | undefined
|
|
}): Promise<WorktreeCreateResult> {
|
|
const { client, selection, targetRepoId, setupDecision, agent, note } = args
|
|
const createdWithAgentId = agent.choice === 'blank' ? undefined : agent.choice
|
|
const comment = note?.trim()
|
|
// A brand-new branch off the repo's default base. The typed name is kept as the
|
|
// git branch (via branchNameOverride) so a slash like `feature/login` survives;
|
|
// the runtime sanitizes the worktree folder from the same name. The retry base is
|
|
// the branch name so a collision bumps the branch (and folder) together.
|
|
return createWorktreeWithNameRetry({
|
|
client,
|
|
baseName: selection.branchName,
|
|
buildParams: (candidate) => {
|
|
const params: Record<string, unknown> = {
|
|
repo: `id:${targetRepoId}`,
|
|
name: candidate,
|
|
setupDecision,
|
|
branchNameOverride: candidate,
|
|
startupCommand: agent.startupCommand
|
|
}
|
|
if (createdWithAgentId) {
|
|
params.createdWithAgent = createdWithAgentId
|
|
}
|
|
if (comment) {
|
|
params.comment = comment
|
|
}
|
|
return params
|
|
}
|
|
})
|
|
}
|