import type { GitHubPrStartPoint } from '../../shared/worktree/types' import type { Repo } from '../../shared/repo-types' import { fetchPrHeadTrackingRef, fetchGitHubPullRequestHeadRef } from '../github/pr-head-tracking-ref' import { resolveGitHubPrStartPoint } from '../github/pr-start-point' import { resolvePrStartPointUnlessWslStopped } from '../github/pr-start-point-wsl-gate' import { resolveGitHubReviewHeadRemote } from '../github/review-head-remote' import { gitExecFileAsync } from '../git/runner' import { getLocalProjectGitExecOptions, getLocalProjectGhExecOptions } from '../workspaces/execution-host/project-runtime-git-options' import { isFolderRepo } from '../../shared/repo-kind' import { requireRepoLocalGitRoute } from '../workspaces/execution-host/repo-execution-host' import type { ProjectRuntimeResolutionStore } from '../workspaces/execution-host/local-project-runtime-resolution' import { reviewStartPointFailure } from '../../shared/review-start-point-failure-copy' export type RuntimeGitHubWorktreeBaseArgs = { repoSelector: 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 } export async function resolveRuntimeGitHubWorktreeBase( args: RuntimeGitHubWorktreeBaseArgs, deps: { store: ProjectRuntimeResolutionStore | null resolveRepo: (selector: string) => Promise } ): Promise { if (!deps.store) { throw new Error('runtime_unavailable') } let repo: Repo try { repo = await deps.resolveRepo(args.repoSelector) } catch { return reviewStartPointFailure('repoNotFound') } if (isFolderRepo(repo)) { return reviewStartPointFailure('folderUnsupported') } // Use shared host gating: executionHostId may be a row's only SSH marker. requireRepoLocalGitRoute(repo) const localGitExecOptions = getLocalProjectGitExecOptions(deps.store, repo) const localGhOptions = getLocalProjectGhExecOptions(deps.store, repo) const gitExec = (gitArgs: string[]) => gitExecFileAsync(gitArgs, localGitExecOptions) const resolveRemote = (): Promise => resolveGitHubReviewHeadRemote({ repoPath: repo.path, issueSourcePreference: repo.issueSourcePreference, connectionId: null, localGitOptions: localGhOptions, gitExec }) const fetchRemoteTrackingRef = (remote: string, branch: string): Promise => fetchPrHeadTrackingRef(repo, remote, branch, { localGitExecOptions }) const fetchPullRequestHeadRef = (remote: string, prNumber: number): Promise => fetchGitHubPullRequestHeadRef(repo, remote, prNumber, { localGitExecOptions }) // A paired client's push-target ensure asks unprompted; it must not start a stopped distro (E9). return resolvePrStartPointUnlessWslStopped( { path: repo.path, wslDistro: localGitExecOptions.wslDistro }, { wakeWslDistro: args.wakeWslDistro }, () => resolveGitHubPrStartPoint({ repoPath: repo.path, prNumber: args.prNumber, headRefName: args.headRefName, baseRefName: args.baseRefName, isCrossRepository: args.isCrossRepository, issueSourcePreference: repo.issueSourcePreference, connectionId: null, localGitOptions: localGhOptions, gitExec, fetchRemoteTrackingRef, fetchPullRequestHeadRef, resolveRemote }) ) }