import type { WorkspaceMetadataSet } from '../../shared/worktree/workspace-metadata-set' import type { SparsePresetFailure } from '../../shared/worktree/sparse-preset-failure' import type { ForgetRemovedWorktreesForExecutionHostArgs, ForgetRemovedWorktreesForExecutionHostResult, HostQualifiedDetectedWorktreeResult, HostQualifiedKnownWorktreeResult, LegacyDetectedWorktreeRequest, ListDetectedWorktreesArgs, ListKnownWorktreesForExecutionHostArgs, ProviderRequestId } from '../../shared/detected-worktree-provider-contract' import type { NestedWorktreeRemovalApproval } from '../../shared/worktree/nested-removal' import type { ExecutionHostId } from '../../shared/execution-host' import type { WorkspaceSleepOutcome, WorkspaceSleepRequest } from '../../shared/workspace-sleep' import type { RetiredNameRegistry } from '../../shared/worktree/retired-name-registry' import type { FolderWorkspacePathStatus, FolderWorkspacePathStatusRequest } from '../../shared/folder-workspaces/folder-workspace-path-status' import type { FolderWorkspace } from '../../shared/folder-workspaces/folder-workspace-types' import type { WorktreeBaseStatusEvent, WorktreeRemoteBranchConflictEvent } from '../../shared/worktree/base-ref-drift-types' import type { AdoptProvisionedRootArgs, CreateWorktreeArgs, CreateWorktreeProgressEvent, CreateWorktreeResult, ForceDeleteWorktreeBranchResult, RemoveWorktreeResult, RunApprovedWorktreeSetupArgs, RunApprovedWorktreeSetupResult, 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, GitStatusMetadataChangedEvent, GitWorktreeInfo, Worktree, WorktreeHeadIdentity } from '../../shared/worktree/types' export type WorktreeApi = { /** Retired names prevent path reuse; fully spent tiers are compacted into a watermark. */ listRetiredNames: (args: { repoId: string }) => Promise listDetected: { ( args: ListDetectedWorktreesArgs ): Promise (args: LegacyDetectedWorktreeRequest): Promise } listKnownForExecutionHost?: ( args: ListKnownWorktreesForExecutionHostArgs ) => Promise /** Retire metadata only after an authoritative scan proves the workspace is gone. */ forgetRemovedForExecutionHost?: ( args: ForgetRemovedWorktreesForExecutionHostArgs ) => Promise cancelListDetected?: (args: { providerRequestId: ProviderRequestId }) => Promise /** User act: scan a local repo inside its WSL distro's user-act scope, which may start it. */ scanStartingWslDistro?: (args: { repoId: string }) => Promise create: (args: CreateWorktreeArgs) => Promise adoptProvisionedRoot: (args: AdoptProvisionedRootArgs) => Promise /** Absent on clients whose host cannot run an existing worktree's approved setup. */ runApprovedSetup?: (args: RunApprovedWorktreeSetupArgs) => Promise /** Local creates report progress by creationId; remote/runtime creates emit nothing. */ onCreateProgress: (callback: (data: CreateWorktreeProgressEvent) => void) => () => void prefetchCreateBase: (args: { repoId: string; baseBranch?: string }) => Promise resolvePrBase: (args: { repoId: string prNumber: number headRefName?: string baseRefName?: string isCrossRepository?: boolean /** The user creating or launching from the PR: it may start a stopped WSL distro. */ wakeWslDistro?: boolean }) => Promise /** Same-project MRs return a remote branch; forks fetch the MR head ref and return its SHA. */ resolveMrBase: (args: { repoId: string mrIid: number sourceBranch?: string targetBranch?: string isCrossRepository?: boolean /** The user creating from the MR: it may start a stopped WSL distro. */ wakeWslDistro?: boolean }) => Promise< { baseBranch: string; compareBaseRef?: string; pushTarget?: GitPushTarget } | { error: string } > previewNestedRemoval?: (args: { worktreeId: string hostId?: ExecutionHostId }) => Promise sleep: (request: WorkspaceSleepRequest) => Promise sleepReopened: (worktreeId: string) => Promise /** True once running, so the renderer's subsequent spawn reattaches. */ resumeSleptPane: ( pane: { worktreeId: string; tabId: string; leafId: string }, automatic?: boolean ) => Promise /** Drops main's workspace-sleep record only while no tab holds its pane. */ retireStrandedSleepRecord: (args: { worktreeId: string; paneKey: string }) => Promise remove: (args: { worktreeId: string hostId?: ExecutionHostId force?: boolean approvedNestedWorktrees?: NestedWorktreeRemovalApproval[] // Only explicit Force Delete waives PTY-stop proof; force merely skips dirty-file prompts. allowUnverifiedPtyStop?: boolean skipArchive?: boolean // Waives a failed hook, unlike skipArchive; force does not imply this approval. allowFailedArchiveHook?: boolean snapshotPruneBatchId?: string }) => Promise // Forget local metadata without remote Git/FS work, even when the SSH host is unavailable. 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 /** Read through validCrossStoreLineage; older hosts omit it. */ crossStoreLineage?: Record /** This store's identity, which other stores' records name; absent when unknown. */ installationId?: string }> updateLineage: (args: { worktreeId: string parentWorktreeId?: string noParent?: boolean }) => Promise<{ lineage: WorktreeLineage | null; workspaceLineage?: WorkspaceLineage | null }> persistSortOrder: (args: { orderedIds: string[]; hostIds?: string[] }) => Promise /** Last failure output; memory-only, cleared on restart or when the failure clears. */ getBranchRenameFailureOutput: (args: { worktreeId: string }) => Promise onChanged: (callback: (data: { repoId: string }) => void) => () => void onGitStatusMetadataChanged: ( callback: (data: GitStatusMetadataChangedEvent) => void ) => () => void onHeadIdentitiesChanged: ( callback: (data: { repoId: string; identities: WorktreeHeadIdentity[] }) => void ) => () => void onMetadataSet?: (callback: (set: WorkspaceMetadataSet) => 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 }