import type { ElectronAPI } from '@electron-toolkit/preload' import type { CliInstallStatus } from '../../shared/cli-install-types' import type { Repo, Worktree, WorktreeMeta, CreateWorktreeArgs, CreateWorktreeResult, PRInfo, PRCheckDetail, PRComment, IssueInfo, GlobalSettings, NotificationDispatchRequest, NotificationDispatchResult, OrcaHooks, PersistedUIState, WorkspaceSessionState, WorktreeSetupLaunch, UpdateStatus, DirEntry, GitBranchCompareResult, GitConflictOperation, GitStatusEntry, GitDiffResult, SearchOptions, SearchResult } from '../../shared/types' import type { RuntimeStatus, RuntimeSyncWindowGraph } from '../../shared/runtime-types' type ReposApi = { list: () => Promise add: (args: { path: string; kind?: 'git' | 'folder' }) => Promise remove: (args: { repoId: string }) => Promise update: (args: { repoId: string updates: Partial< Pick > }) => Promise pickFolder: () => Promise pickDirectory: () => Promise clone: (args: { url: string; destination: string }) => Promise cloneAbort: () => Promise onCloneProgress: (callback: (data: { phase: string; percent: number }) => void) => () => void getGitUsername: (args: { repoId: string }) => Promise getBaseRefDefault: (args: { repoId: string }) => Promise searchBaseRefs: (args: { repoId: string; query: string; limit?: number }) => Promise onChanged: (callback: () => void) => () => void } type WorktreesApi = { list: (args: { repoId: string }) => Promise listAll: () => Promise create: (args: CreateWorktreeArgs) => Promise remove: (args: { worktreeId: string; force?: boolean }) => Promise updateMeta: (args: { worktreeId: string; updates: Partial }) => Promise persistSortOrder: (args: { orderedIds: string[] }) => Promise onChanged: (callback: (data: { repoId: string }) => void) => () => void } type PtyApi = { spawn: (opts: { cols: number rows: number cwd?: string env?: Record }) => Promise<{ id: string }> write: (id: string, data: string) => void resize: (id: string, cols: number, rows: number) => void kill: (id: string) => Promise hasChildProcesses: (id: string) => Promise onData: (callback: (data: { id: string; data: string }) => void) => () => void onExit: (callback: (data: { id: string; code: number }) => void) => () => void } type GhApi = { prForBranch: (args: { repoPath: string; branch: string }) => Promise issue: (args: { repoPath: string; number: number }) => Promise listIssues: (args: { repoPath: string; limit?: number }) => Promise prChecks: (args: { repoPath: string prNumber: number headSha?: string noCache?: boolean }) => Promise prComments: (args: { repoPath: string prNumber: number noCache?: boolean }) => Promise resolveReviewThread: (args: { repoPath: string threadId: string resolve: boolean }) => Promise updatePRTitle: (args: { repoPath: string; prNumber: number; title: string }) => Promise mergePR: (args: { repoPath: string prNumber: number method?: 'merge' | 'squash' | 'rebase' }) => Promise<{ ok: true } | { ok: false; error: string }> checkOrcaStarred: () => Promise starOrca: () => Promise } type SettingsApi = { get: () => Promise set: (args: Partial) => Promise listFonts: () => Promise } type CliApi = { getInstallStatus: () => Promise install: () => Promise remove: () => Promise } type NotificationsApi = { dispatch: (args: NotificationDispatchRequest) => Promise openSystemSettings: () => Promise } type ShellApi = { openPath: (path: string) => Promise openUrl: (url: string) => Promise openFilePath: (path: string) => Promise openFileUri: (uri: string) => Promise pathExists: (path: string) => Promise pickImage: () => Promise copyFile: (args: { srcPath: string; destPath: string }) => Promise } type HooksApi = { check: (args: { repoId: string }) => Promise<{ hasHooks: boolean; hooks: OrcaHooks | null }> } type CacheApi = { getGitHub: () => Promise<{ pr: Record issue: Record }> setGitHub: (args: { cache: { pr: Record issue: Record } }) => Promise } type SessionApi = { get: () => Promise set: (args: WorkspaceSessionState) => Promise /** Synchronous session save for beforeunload — blocks until flushed to disk. */ setSync: (args: WorkspaceSessionState) => void } type UpdaterApi = { getVersion: () => Promise getStatus: () => Promise check: () => Promise download: () => Promise quitAndInstall: () => Promise onStatus: (callback: (status: UpdateStatus) => void) => () => void } type UIApi = { get: () => Promise set: (args: Partial) => Promise onOpenSettings: (callback: () => void) => () => void onActivateWorktree: ( callback: (data: { repoId: string; worktreeId: string; setup?: WorktreeSetupLaunch }) => void ) => () => void onTerminalZoom: (callback: (direction: 'in' | 'out' | 'reset') => void) => () => void readClipboardText: () => Promise writeClipboardText: (text: string) => Promise onFileDrop: ( callback: (data: { path: string; target: 'editor' | 'terminal' }) => void ) => () => void getZoomLevel: () => number setZoomLevel: (level: number) => void onFullscreenChanged: (callback: (isFullScreen: boolean) => void) => () => void onWindowCloseRequested: (callback: () => void) => () => void confirmWindowClose: () => void } type RuntimeApi = { syncWindowGraph: (graph: RuntimeSyncWindowGraph) => Promise getStatus: () => Promise } type FsApi = { readDir: (args: { dirPath: string }) => Promise readFile: (args: { filePath: string }) => Promise<{ content: string; isBinary: boolean; isImage?: boolean; mimeType?: string }> writeFile: (args: { filePath: string; content: string }) => Promise createFile: (args: { filePath: string }) => Promise createDir: (args: { dirPath: string }) => Promise rename: (args: { oldPath: string; newPath: string }) => Promise deletePath: (args: { targetPath: string }) => Promise authorizeExternalPath: (args: { targetPath: string }) => Promise stat: (args: { filePath: string }) => Promise<{ size: number; isDirectory: boolean; mtime: number }> listFiles: (args: { rootPath: string }) => Promise search: (args: SearchOptions) => Promise } type GitApi = { status: (args: { worktreePath: string }) => Promise conflictOperation: (args: { worktreePath: string }) => Promise diff: (args: { worktreePath: string filePath: string staged: boolean }) => Promise branchCompare: (args: { worktreePath: string baseRef: string }) => Promise branchDiff: (args: { worktreePath: string compare: { baseRef: string baseOid: string headOid: string mergeBase: string } filePath: string oldPath?: string }) => Promise stage: (args: { worktreePath: string; filePath: string }) => Promise unstage: (args: { worktreePath: string; filePath: string }) => Promise discard: (args: { worktreePath: string; filePath: string }) => Promise remoteFileUrl: (args: { worktreePath: string relativePath: string line: number }) => Promise } type PreflightStatus = { git: { installed: boolean } gh: { installed: boolean; authenticated: boolean } } type PreflightApi = { check: () => Promise } type Api = { repos: ReposApi worktrees: WorktreesApi pty: PtyApi gh: GhApi settings: SettingsApi cli: CliApi preflight: PreflightApi notifications: NotificationsApi shell: ShellApi hooks: HooksApi cache: CacheApi session: SessionApi updater: UpdaterApi fs: FsApi git: GitApi ui: UIApi runtime: RuntimeApi } declare global { // oxlint-disable-next-line typescript-eslint/consistent-type-definitions -- declaration merging requires interface interface Window { electron: ElectronAPI api: Api } }