import type { ForgetRemovedWorktreesForExecutionHostArgs, ForgetRemovedWorktreesForExecutionHostResult, HostQualifiedDetectedWorktreeResult, HostQualifiedKnownWorktreeResult, LegacyDetectedWorktreeRequest, ListDetectedWorktreesArgs, ListKnownWorktreesForExecutionHostArgs, ProviderRequestId } from '../../shared/detected-worktree-provider-contract' import type { ExecutionHostId } from '../../shared/execution-host' import type { RetiredNameRegistry } from '../../shared/worktree/retired-name-registry' import type { FolderWorkspacePathStatus, FolderWorkspacePathStatusRequest } from '../../shared/folder-workspace-path-status' import type { HostLineageSnapshot, ListDesktopLineageForHostArgs } from '../../shared/host-lineage-contract' import type { FolderWorkspace } from '../../shared/folder-workspace-types' import type { WorktreeBaseStatusEvent, WorktreeRemoteBranchConflictEvent } from '../../shared/worktree/base-ref-drift-types' import type { AdoptProvisionedRootArgs, CreateWorktreeArgs, CreateWorktreeResult, ForceDeleteWorktreeBranchResult, RemoveWorktreeResult, SparsePreset } from '../../shared/worktree/create-types' import type { WorkspaceLineage, WorktreeLineage } from '../../shared/worktree/lineage-types' import type { WorktreeMeta } from '../../shared/worktree/meta-types' import type { DetectedWorktreeListResult, GitHubPrStartPoint, GitPushTarget, Worktree, WorktreeHeadIdentity } from '../../shared/worktree/types' export type WorktreeApi = { list: (args: { repoId: string }) => Promise /** Generated names already spent in this repo, including deleted workspaces. Name suggestions * exclude these so a recreated workspace never lands on a prior occupant's path. Compacted: a * fully spent tier is reported as the watermark rather than as its 552 names. */ listRetiredNames: (args: { repoId: string }) => Promise listDetected: { ( args: ListDetectedWorktreesArgs ): Promise (args: LegacyDetectedWorktreeRequest): Promise } listKnownForExecutionHost?: ( args: ListKnownWorktreesForExecutionHostArgs ) => Promise /** Retires the persisted metadata an authoritative scan proved gone, so it stops feeding the read above. */ forgetRemovedForExecutionHost?: ( args: ForgetRemovedWorktreesForExecutionHostArgs ) => Promise cancelListDetected?: (args: { providerRequestId: ProviderRequestId }) => Promise listAll: () => Promise create: (args: CreateWorktreeArgs) => Promise adoptProvisionedRoot: (args: AdoptProvisionedRootArgs) => Promise /** Two-phase progress for a background `create`, correlated by `creationId`. The remote/runtime * create path emits nothing, so the surface falls back to an indeterminate spinner. */ onCreateProgress: ( callback: (data: { creationId?: string; phase: 'fetching' | 'creating' }) => void ) => () => void prefetchCreateBase: (args: { repoId: string; baseBranch?: string }) => Promise resolvePrBase: (args: { repoId: string prNumber: number headRefName?: string baseRefName?: string isCrossRepository?: boolean }) => Promise /** GitLab parallel of resolvePrBase. For same-project MRs returns * `/`; for fork MRs fetches * refs/merge-requests//head and returns the SHA. */ resolveMrBase: (args: { repoId: string mrIid: number sourceBranch?: string targetBranch?: string isCrossRepository?: boolean }) => Promise< { baseBranch: string; compareBaseRef?: string; pushTarget?: GitPushTarget } | { error: string } > remove: (args: { worktreeId: string hostId?: ExecutionHostId force?: boolean // Why (#11960): distinct from `force`, which the plain Delete confirmation // already sets to skip the dirty-file prompt. Only an explicit Force Delete // may waive the proof that every PTY stopped. allowUnverifiedPtyStop?: boolean skipArchive?: boolean // Why (#19334): distinct from `skipArchive` (never runs the hook) and never implied by // `force` — this waives a hook that ran and FAILED. allowFailedArchiveHook?: boolean snapshotPruneBatchId?: string }) => Promise // Forget a workspace from Orca only (no remote Git/FS work) — for workspaces pinned to a removed/disconnected SSH host. forgetLocal: (args: { worktreeId: string hostId?: ExecutionHostId snapshotPruneBatchId?: string }) => Promise forceDeletePreservedBranch: (args: { worktreeId: string branchName: string expectedHead: string hostId?: ExecutionHostId }) => Promise updateMeta: (args: { worktreeId: string executionHostId?: ExecutionHostId updates: Partial }) => Promise listLineage: () => Promise<{ lineage: Record workspaceLineage?: Record }> listLineageForHost?: (args: ListDesktopLineageForHostArgs) => Promise updateLineage: (args: { worktreeId: string parentWorktreeId?: string noParent?: boolean }) => Promise persistSortOrder: (args: { orderedIds: string[] }) => Promise /** Full CLI output of the last branch auto-rename generation failure, held * in main memory only — null after a restart or once the failure clears. */ getBranchRenameFailureOutput: (args: { worktreeId: string }) => Promise onChanged: (callback: (data: { repoId: string }) => void) => () => void onGitStatusMetadataChanged: (callback: (data: { repoId: string }) => void) => () => void onHeadIdentitiesChanged: ( callback: (data: { repoId: string; identities: WorktreeHeadIdentity[] }) => void ) => () => void onBaseStatus: (callback: (data: WorktreeBaseStatusEvent) => void) => () => void onRemoteBranchConflict: ( callback: (data: WorktreeRemoteBranchConflictEvent) => void ) => () => void } export type FolderWorkspacesApi = { list: () => Promise getPathStatus: (args: FolderWorkspacePathStatusRequest) => Promise create: (args: { projectGroupId: string name?: string folderPath?: string | null connectionId?: string | null linkedTask?: FolderWorkspace['linkedTask'] createdWithAgent?: FolderWorkspace['createdWithAgent'] pendingFirstAgentMessageRename?: boolean }) => Promise update: (args: { folderWorkspaceId: string updates: Partial< Pick< FolderWorkspace, | 'name' | 'folderPath' | 'linkedTask' | 'comment' | 'isArchived' | 'isUnread' | 'isPinned' | 'sortOrder' | 'manualOrder' | 'workspaceStatus' | 'createdWithAgent' | 'pendingFirstAgentMessageRename' | 'firstAgentMessageRenameError' | 'lastActivityAt' | 'diffComments' > > }) => Promise delete: (args: { folderWorkspaceId: string }) => Promise } export type SparsePresetsApi = { list: (args: { repoId: string }) => Promise save: (args: { repoId: string id?: string name: string directories: string[] }) => Promise remove: (args: { repoId: string; presetId: string }) => Promise onChanged: (callback: (data: { repoId: string }) => void) => () => void }