import { tracedInvoke as invoke } from "./telemetry"; import type { AiReviewResult, AiCommitPlan, CommitAiLocalProfile, CommitAiProvider, CommitAiStatus, ConflictFile, GitBlameResult, GitBranch, GitCommit, GitCommitComparison, GitRepositoryFile, GitRemote, MergeStrategy, PullStrategy, RebaseCommit, RebasePlanItem, ReflogEntry, GitSearchHit, GitStash, GitStatus, GitTag, GitWorktree, LocalModelOption, PatchApplyAction, RepositoryBundle, StoredCredential, } from "./types"; export function openRepository(path: string): Promise { return invoke("open_repository", { path }); } export function initRepository(path: string, initialBranch = "main"): Promise { return invoke("init_repository", { path, initialBranch }); } export function openRepoInExplorer(path: string): Promise { return invoke("open_repo_in_explorer", { path }); } export function openRepositoryFile(path: string, file: string): Promise { return invoke("open_repository_file", { path, file }); } export function openRepositoryBundle(path: string, commitLimit = 100): Promise { return invoke("open_repository_bundle", { path, commitLimit }); } export function cloneRepository( remoteUrl: string, parentPath: string, directoryName?: string, username?: string, password?: string, commitLimit = 100, ): Promise { return invoke("clone_repository", { remoteUrl, parentPath, directoryName: directoryName?.trim() ? directoryName.trim() : null, username: username ?? null, password: password ?? null, commitLimit, }); } export function getStatus(path: string): Promise { return invoke("get_status", { path }); } // Sets the taskbar icon badge to ahead + behind + changed status files (0 clears it). Windows only — a no-op on // other platforms, since Windows has no native numeric badge to fall back to. export function setSyncBadge(ahead: number, behind: number, changes: number): Promise { return invoke("set_sync_badge", { ahead, behind, changes }); } export function listBranches(path: string): Promise { return invoke("list_branches", { path }); } export function listRemotes(path: string): Promise { return invoke("list_remotes", { path }); } export function addRemote(path: string, name: string, url: string): Promise { return invoke("add_remote", { path, name, url }); } export function updateRemote(path: string, name: string, url: string): Promise { return invoke("update_remote", { path, name, url }); } export function removeRemote(path: string, name: string): Promise { console.log("remove_remote") return invoke("remove_remote", { path, name }); } export function setBranchUpstream(path: string, branch: string, upstream?: string): Promise { return invoke("set_branch_upstream", { path, branch, upstream: upstream || null }); } export function deleteRemoteBranch(path: string, remote: string, branch: string): Promise { return invoke("delete_remote_branch", { path, remote, branch }); } export function listStashes(path: string): Promise { return invoke("list_stashes", { path }); } export function checkoutBranch(path: string, branch: string): Promise { return invoke("checkout_branch", { path, branch }); } export function createBranch( path: string, branch: string, startPoint?: string, ): Promise { return invoke("create_branch", { path, branch, startPoint: startPoint ?? null }); } export function renameBranch( path: string, oldBranch: string, newBranch: string, ): Promise { return invoke("rename_branch", { path, oldBranch, newBranch }); } export function deleteBranch(path: string, branch: string, force = false): Promise { return invoke("delete_branch", { path, branch, force }); } export function listWorktrees(path: string): Promise { return invoke("list_worktrees", { path }); } export function addWorktree( path: string, worktreePath: string, options: { branch?: string; newBranch?: string; startPoint?: string; detached?: boolean; lock?: boolean; } = {}, ): Promise { return invoke("add_worktree", { path, worktreePath, branch: options.branch ?? null, newBranch: options.newBranch ?? null, startPoint: options.startPoint ?? null, detached: options.detached ?? false, lock: options.lock ?? false, }); } export function removeWorktree(path: string, worktreePath: string, force = false): Promise { return invoke("remove_worktree", { path, worktreePath, force }); } export function moveWorktree(path: string, worktreePath: string, destination: string): Promise { return invoke("move_worktree", { path, worktreePath, destination }); } export function lockWorktree(path: string, worktreePath: string, reason?: string): Promise { return invoke("lock_worktree", { path, worktreePath, reason: reason?.trim() || null }); } export function unlockWorktree(path: string, worktreePath: string): Promise { return invoke("unlock_worktree", { path, worktreePath }); } export function pruneWorktrees(path: string): Promise { return invoke("prune_worktrees", { path }); } export function repairWorktree(path: string, worktreePath: string): Promise { return invoke("repair_worktree", { path, worktreePath }); } export function listTags(path: string): Promise { return invoke("list_tags", { path }); } export function createTag( path: string, name: string, target?: string, message?: string, ): Promise { return invoke("create_tag", { path, name, target: target?.trim() ? target.trim() : null, message: message?.trim() ? message.trim() : null, }); } export function deleteTag(path: string, name: string): Promise { return invoke("delete_tag", { path, name }); } export function pushTag( path: string, name: string, username?: string, password?: string, ): Promise { return invoke("push_tag", { path, name, username: username ?? null, password: password ?? null }); } export function cherryPickCommit(path: string, commit: string): Promise { return invoke("cherry_pick_commit", { path, commit }); } export function cherryPickContinue(path: string): Promise { return invoke("cherry_pick_continue", { path }); } export function cherryPickAbort(path: string): Promise { return invoke("cherry_pick_abort", { path }); } export function stageFiles(path: string, files: string[]): Promise { return invoke("stage_files", { path, files }); } export function unstageFiles(path: string, files: string[]): Promise { return invoke("unstage_files", { path, files }); } export function restoreFiles( path: string, files: string[], staged: boolean, ): Promise { return invoke("restore_files", { path, files, staged }); } export function getFilePatch(path: string, file: string, staged: boolean): Promise { return invoke("get_file_patch", { path, file, staged }); } export function applyFilePatch( path: string, file: string, patch: string, action: PatchApplyAction, ): Promise { return invoke("apply_file_patch", { path, file, patch, action }); } export function commit(path: string, message: string): Promise { return invoke("commit", { path, message }); } export function amendCommit(path: string, message?: string): Promise { return invoke("amend_commit", { path, message: message?.trim() ? message.trim() : null }); } export function lastCommitMessage(path: string): Promise { return invoke("last_commit_message", { path }); } export function undoLastCommit(path: string): Promise { return invoke("undo_last_commit", { path }); } export function stashPush( path: string, message?: string, includeUntracked = true, ): Promise { return invoke("stash_push", { path, message: message?.trim() ? message.trim() : null, includeUntracked, }); } export function stashApply(path: string, selector: string): Promise { return invoke("stash_apply", { path, selector }); } export function stashPop(path: string, selector: string): Promise { return invoke("stash_pop", { path, selector }); } export function stashDrop(path: string, selector: string): Promise { return invoke("stash_drop", { path, selector }); } export function commitAiStatus(): Promise { return invoke("commit_ai_status"); } export function commitAiLoad(modelId: string): Promise { return invoke("commit_ai_load", { modelId }); } export function commitAiLocalModels(): Promise { return invoke("commit_ai_local_models"); } export interface CommitAiGenerateOptions { notes?: string; provider: CommitAiProvider; localProfile?: CommitAiLocalProfile; model?: string; apiKey?: string; baseUrl?: string; } export function commitAiGenerate(path: string, options: CommitAiGenerateOptions): Promise { return invoke("commit_ai_generate", { path, notes: options.notes, provider: options.provider, localProfile: options.localProfile, model: options.model, apiKey: options.apiKey, baseUrl: options.baseUrl, }); } export function commitAiReview(path: string, options: CommitAiGenerateOptions): Promise { return invoke("commit_ai_review", { path, provider: options.provider, model: options.model, apiKey: options.apiKey, baseUrl: options.baseUrl, }); } export function commitAiSplit(path: string, options: CommitAiGenerateOptions): Promise { return invoke("commit_ai_split", { path, provider: options.provider, model: options.model, apiKey: options.apiKey, baseUrl: options.baseUrl, }); } export function pull(path: string, username?: string, password?: string, strategy: PullStrategy = "merge", remote?: string, branch?: string): Promise { return invoke("pull", { path, username: username ?? null, password: password ?? null, strategy, remote: remote || null, branch: branch || null }); } export function fetchRemote(path: string, username?: string, password?: string, prune = false, remote?: string): Promise { return invoke("fetch", { path, username: username ?? null, password: password ?? null, prune, remote: remote || null }); } export function push(path: string, username?: string, password?: string, forceWithLease = false, remote?: string): Promise { return invoke("push", { path, username: username ?? null, password: password ?? null, forceWithLease, remote: remote || null }); } export function getRemoteUrl(path: string): Promise { return invoke("get_remote_url", { path }); } export function credLoad(key: string): Promise { return invoke("cred_load", { key }); } export function credSave( key: string, username: string, password: string, expiresAt: string | null, ): Promise { return invoke("cred_save", { key, username, password, expiresAt }); } export function credDelete(key: string): Promise { return invoke("cred_delete", { key }); } export function listCommits(path: string, limit = 100): Promise { return invoke("list_commits", { path, limit }); } export function restoreToCommit(path: string, commit: string): Promise { return invoke("restore_to_commit", { path, commit }); } export function restoreFileFromCommit( path: string, commit: string, file: string, ): Promise { return invoke("restore_file_from_commit", { path, commit, file }); } export function mergeBranch(path: string, branch: string, strategy: MergeStrategy = "default"): Promise { return invoke("merge_branch", { path, branch, strategy }); } export function mergeContinue(path: string): Promise { return invoke("merge_continue", { path }); } export function mergeAbort(path: string): Promise { return invoke("merge_abort", { path }); } export function revertCommit(path: string, commit: string): Promise { return invoke("revert_commit", { path, commit }); } export function rebaseBranch(path: string, branch: string): Promise { return invoke("rebase_branch", { path, branch }); } export function rebaseContinue(path: string): Promise { return invoke("rebase_continue", { path }); } export function rebaseAbort(path: string): Promise { return invoke("rebase_abort", { path }); } export function listInteractiveRebaseCommits(path: string, base: string): Promise { return invoke("list_interactive_rebase_commits", { path, base }); } export function startInteractiveRebase( path: string, base: string, plan: RebasePlanItem[], ): Promise { return invoke("start_interactive_rebase", { path, base, plan }); } export function listReflog(path: string, limit = 250): Promise { return invoke("list_reflog", { path, limit }); } export function restoreReflogEntry(path: string, commit: string, branch: string): Promise { return invoke("restore_reflog_entry", { path, commit, branch }); } export function listRepositoryFiles(path: string): Promise { return invoke("list_repository_files", { path }); } export function listFileHistory( path: string, file: string, limit = 100, requestId?: string, ): Promise { return invoke("list_file_history", { path, file, limit, requestId: requestId ?? null }); } export function cancelFileHistory(requestId: string): Promise { return invoke("cancel_file_history", { requestId }); } export function getFileBlame(path: string, file: string): Promise { return invoke("get_file_blame", { path, file }); } export function compareCommits( path: string, from: string, to: string, ): Promise { return invoke("compare_commits", { path, from, to }); } export function diffFileAgainstWorkingTree( path: string, commit: string, file: string, ): Promise { return invoke("diff_file_against_working_tree", { path, commit, file }); } export function compareFileToHead( path: string, commit: string, file: string, ): Promise { return invoke("compare_file_to_head", { path, commit, file }); } export function compareFileToParent( path: string, commit: string, file: string, oldFile: string | null = null, ): Promise { return invoke("compare_file_to_parent", { path, commit, file, oldFile }); } export function searchCodeIntroductions( path: string, query: string, caseSensitive = false, limit = 250, searchId?: string, ): Promise { return invoke("search_code_introductions", { path, query, caseSensitive, limit, searchId: searchId ?? null, }); } export function cancelCodeSearch(searchId: string): Promise { return invoke("cancel_code_search", { searchId }); } export function readConflict(path: string, file: string): Promise { return invoke("read_conflict", { path, file }); } export function resolveConflict( path: string, file: string, content: string, ): Promise { return invoke("resolve_conflict", { path, file, content }); } export function resolveConflictSide( path: string, file: string, side: "ours" | "theirs", ): Promise { return invoke("resolve_conflict_side", { path, file, side }); }