Add project Windows runtime selection (#5519)
* Add project Windows runtime selection * Fix project Windows runtime selection Co-authored-by: Orca <help@stably.ai> * fix: preserve WSL shell variables --------- Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com> Co-authored-by: Orca <help@stably.ai> Co-authored-by: Neil <neil@stably.ai>
This commit is contained in:
co-authored by
Orca
Jinwoo-H
Neil
parent
25d2053b25
commit
0ec3882cb8
@@ -62,15 +62,20 @@ import {
|
||||
generateCommitMessageFromContext,
|
||||
generatePullRequestFieldsFromContext,
|
||||
resolveCommitMessageSettings,
|
||||
type CommitMessageGenerationTarget,
|
||||
type DiscoverCommitMessageModelsResult,
|
||||
type GenerateCommitMessageResult,
|
||||
type GeneratePullRequestFieldsResult
|
||||
} from '../text-generation/commit-message-text-generation'
|
||||
import type { CommitMessageAgentEnvironmentResolvers } from '../text-generation/commit-message-agent-environment'
|
||||
import type {
|
||||
CommitMessageAgentEnvironmentResolvers,
|
||||
CommitMessageAgentRuntimeTarget
|
||||
} from '../text-generation/commit-message-agent-environment'
|
||||
import { prepareLocalCommitMessageAgentEnv } from '../text-generation/commit-message-agent-environment'
|
||||
import { getPullRequestDraftContext } from '../text-generation/pull-request-context'
|
||||
import { normalizeRuntimeRelativePath } from './runtime-relative-paths'
|
||||
import { gitExecFileAsync } from '../git/runner'
|
||||
import type { GitRuntimeOptions } from '../git/git-runtime-options'
|
||||
import { resolveHostedReviewBodyForGeneration } from '../source-control/pull-request-template'
|
||||
import type { HostedReviewProvider } from '../../shared/hosted-review'
|
||||
|
||||
@@ -117,10 +122,39 @@ function normalizeRuntimeGitRelativePath(filePath: string): string {
|
||||
return relativePath
|
||||
}
|
||||
|
||||
type RuntimeGitTarget = {
|
||||
worktree: ResolvedRuntimeGitWorktree
|
||||
repo?: Repo
|
||||
connectionId?: string
|
||||
localGitOptions?: GitRuntimeOptions
|
||||
}
|
||||
|
||||
function localGitOptionsForTarget(target: RuntimeGitTarget): GitRuntimeOptions {
|
||||
return target.connectionId ? {} : (target.localGitOptions ?? {})
|
||||
}
|
||||
|
||||
function localAgentRuntimeTargetForTarget(
|
||||
target: RuntimeGitTarget
|
||||
): CommitMessageAgentRuntimeTarget {
|
||||
const wslDistro = localGitOptionsForTarget(target).wslDistro
|
||||
return wslDistro ? { runtime: 'wsl', wslDistro } : { runtime: 'host' }
|
||||
}
|
||||
|
||||
function localTextGenerationTargetForTarget(
|
||||
target: RuntimeGitTarget,
|
||||
env?: NodeJS.ProcessEnv
|
||||
): Extract<CommitMessageGenerationTarget, { kind: 'local' }> {
|
||||
const wslDistro = localGitOptionsForTarget(target).wslDistro
|
||||
return {
|
||||
kind: 'local',
|
||||
cwd: target.worktree.path,
|
||||
...(wslDistro ? { wslDistro } : {}),
|
||||
...(env ? { env } : {})
|
||||
}
|
||||
}
|
||||
|
||||
export type RuntimeGitCommandHost = {
|
||||
resolveRuntimeGitTarget(
|
||||
selector: string
|
||||
): Promise<{ worktree: ResolvedRuntimeGitWorktree; repo?: Repo; connectionId?: string }>
|
||||
resolveRuntimeGitTarget(selector: string): Promise<RuntimeGitTarget>
|
||||
getRuntimeSettings(): GlobalSettings
|
||||
getCommitMessageAgentEnvironment?(): CommitMessageAgentEnvironmentResolvers | undefined
|
||||
}
|
||||
@@ -142,9 +176,10 @@ export class RuntimeGitCommands {
|
||||
? provider.getStatus(target.worktree.path, options)
|
||||
: provider.getStatus(target.worktree.path)
|
||||
}
|
||||
const gitOptions = localGitOptionsForTarget(target)
|
||||
return options
|
||||
? getGitStatus(target.worktree.path, options)
|
||||
: getGitStatus(target.worktree.path)
|
||||
? getGitStatus(target.worktree.path, { ...options, ...gitOptions })
|
||||
: getGitStatus(target.worktree.path, gitOptions)
|
||||
}
|
||||
|
||||
async checkRuntimeGitIgnoredPaths(
|
||||
@@ -159,7 +194,7 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
return provider.checkIgnoredPaths(target.worktree.path, relativePaths)
|
||||
}
|
||||
return checkIgnoredPaths(target.worktree.path, relativePaths)
|
||||
return checkIgnoredPaths(target.worktree.path, relativePaths, localGitOptionsForTarget(target))
|
||||
}
|
||||
|
||||
async getRuntimeGitHistory(
|
||||
@@ -174,7 +209,10 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
return provider.getHistory(target.worktree.path, options)
|
||||
}
|
||||
return getGitHistory(target.worktree.path, options)
|
||||
return getGitHistory(target.worktree.path, {
|
||||
...options,
|
||||
...localGitOptionsForTarget(target)
|
||||
})
|
||||
}
|
||||
|
||||
async getRuntimeGitConflictOperation(worktreeSelector: string): Promise<GitConflictOperation> {
|
||||
@@ -199,7 +237,7 @@ export class RuntimeGitCommands {
|
||||
await provider.abortMerge(target.worktree.path)
|
||||
return { ok: true }
|
||||
}
|
||||
await abortMerge(target.worktree.path)
|
||||
await abortMerge(target.worktree.path, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -213,7 +251,7 @@ export class RuntimeGitCommands {
|
||||
await provider.abortRebase(target.worktree.path)
|
||||
return { ok: true }
|
||||
}
|
||||
await abortRebase(target.worktree.path)
|
||||
await abortRebase(target.worktree.path, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -230,7 +268,7 @@ export class RuntimeGitCommands {
|
||||
await provider.checkoutBranch(target.worktree.path, branch)
|
||||
return { ok: true, branch }
|
||||
}
|
||||
await checkoutBranch(target.worktree.path, branch)
|
||||
await checkoutBranch(target.worktree.path, branch, localGitOptionsForTarget(target))
|
||||
return { ok: true, branch }
|
||||
}
|
||||
|
||||
@@ -243,7 +281,7 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
return provider.listLocalBranches(target.worktree.path)
|
||||
}
|
||||
return listLocalBranches(target.worktree.path)
|
||||
return listLocalBranches(target.worktree.path, localGitOptionsForTarget(target))
|
||||
}
|
||||
|
||||
async getRuntimeGitDiff(
|
||||
@@ -261,7 +299,13 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
return provider.getDiff(target.worktree.path, relativePath, staged, compareAgainstHead)
|
||||
}
|
||||
return getDiff(target.worktree.path, relativePath, staged, compareAgainstHead)
|
||||
return getDiff(
|
||||
target.worktree.path,
|
||||
relativePath,
|
||||
staged,
|
||||
compareAgainstHead,
|
||||
localGitOptionsForTarget(target)
|
||||
)
|
||||
}
|
||||
|
||||
async getRuntimeGitBranchCompare(
|
||||
@@ -276,7 +320,7 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
return provider.getBranchCompare(target.worktree.path, baseRef)
|
||||
}
|
||||
return getBranchCompare(target.worktree.path, baseRef)
|
||||
return getBranchCompare(target.worktree.path, baseRef, localGitOptionsForTarget(target))
|
||||
}
|
||||
|
||||
async getRuntimeGitCommitCompare(
|
||||
@@ -291,7 +335,7 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
return provider.getCommitCompare(target.worktree.path, commitId)
|
||||
}
|
||||
return getCommitCompare(target.worktree.path, commitId)
|
||||
return getCommitCompare(target.worktree.path, commitId, localGitOptionsForTarget(target))
|
||||
}
|
||||
|
||||
async getRuntimeGitUpstreamStatus(
|
||||
@@ -306,7 +350,7 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
return provider.getUpstreamStatus(target.worktree.path, pushTarget)
|
||||
}
|
||||
return getUpstreamStatus(target.worktree.path, pushTarget)
|
||||
return getUpstreamStatus(target.worktree.path, pushTarget, localGitOptionsForTarget(target))
|
||||
}
|
||||
|
||||
async fetchRuntimeGit(
|
||||
@@ -322,7 +366,7 @@ export class RuntimeGitCommands {
|
||||
await provider.fetchRemote(target.worktree.path, pushTarget)
|
||||
return { ok: true }
|
||||
}
|
||||
await gitFetch(target.worktree.path, pushTarget)
|
||||
await gitFetch(target.worktree.path, pushTarget, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -338,7 +382,11 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
return provider.syncForkDefaultBranch(target.worktree.path, expectedUpstream)
|
||||
}
|
||||
return gitSyncForkDefaultBranch(target.worktree.path, expectedUpstream)
|
||||
return gitSyncForkDefaultBranch(
|
||||
target.worktree.path,
|
||||
expectedUpstream,
|
||||
localGitOptionsForTarget(target)
|
||||
)
|
||||
}
|
||||
|
||||
async pullRuntimeGit(
|
||||
@@ -354,7 +402,7 @@ export class RuntimeGitCommands {
|
||||
await provider.pullBranch(target.worktree.path, pushTarget)
|
||||
return { ok: true }
|
||||
}
|
||||
await gitPull(target.worktree.path, pushTarget)
|
||||
await gitPull(target.worktree.path, pushTarget, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -371,7 +419,7 @@ export class RuntimeGitCommands {
|
||||
await provider.fastForwardBranch(target.worktree.path, pushTarget)
|
||||
return { ok: true }
|
||||
}
|
||||
await gitFastForward(target.worktree.path, pushTarget)
|
||||
await gitFastForward(target.worktree.path, pushTarget, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -385,7 +433,7 @@ export class RuntimeGitCommands {
|
||||
await provider.rebaseFromBase(target.worktree.path, baseRef)
|
||||
return { ok: true }
|
||||
}
|
||||
await gitPullRebaseFromBase(target.worktree.path, baseRef)
|
||||
await gitPullRebaseFromBase(target.worktree.path, baseRef, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -407,7 +455,8 @@ export class RuntimeGitCommands {
|
||||
return { ok: true }
|
||||
}
|
||||
await gitPush(target.worktree.path, publish === true, pushTarget, {
|
||||
forceWithLease: forceWithLease === true
|
||||
forceWithLease: forceWithLease === true,
|
||||
...localGitOptionsForTarget(target)
|
||||
})
|
||||
return { ok: true }
|
||||
}
|
||||
@@ -441,12 +490,16 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
)
|
||||
}
|
||||
return getBranchDiff(target.worktree.path, {
|
||||
mergeBase: compare.mergeBase,
|
||||
headOid: compare.headOid,
|
||||
filePath: relativePath,
|
||||
oldPath: oldRelativePath
|
||||
})
|
||||
return getBranchDiff(
|
||||
target.worktree.path,
|
||||
{
|
||||
mergeBase: compare.mergeBase,
|
||||
headOid: compare.headOid,
|
||||
filePath: relativePath,
|
||||
oldPath: oldRelativePath
|
||||
},
|
||||
localGitOptionsForTarget(target)
|
||||
)
|
||||
}
|
||||
|
||||
async getRuntimeGitCommitDiff(
|
||||
@@ -468,12 +521,16 @@ export class RuntimeGitCommands {
|
||||
oldPath: oldRelativePath
|
||||
})
|
||||
}
|
||||
return getCommitDiff(target.worktree.path, {
|
||||
commitOid: args.commitOid,
|
||||
parentOid: args.parentOid,
|
||||
filePath: relativePath,
|
||||
oldPath: oldRelativePath
|
||||
})
|
||||
return getCommitDiff(
|
||||
target.worktree.path,
|
||||
{
|
||||
commitOid: args.commitOid,
|
||||
parentOid: args.parentOid,
|
||||
filePath: relativePath,
|
||||
oldPath: oldRelativePath
|
||||
},
|
||||
localGitOptionsForTarget(target)
|
||||
)
|
||||
}
|
||||
|
||||
async commitRuntimeGit(
|
||||
@@ -491,7 +548,7 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
return provider.commit(target.worktree.path, message)
|
||||
}
|
||||
return commitChanges(target.worktree.path, message)
|
||||
return commitChanges(target.worktree.path, message, localGitOptionsForTarget(target))
|
||||
}
|
||||
|
||||
async generateRuntimeCommitMessage(
|
||||
@@ -547,7 +604,7 @@ export class RuntimeGitCommands {
|
||||
|
||||
let context: CommitMessageDraftContext | null
|
||||
try {
|
||||
context = await getStagedCommitContext(target.worktree.path)
|
||||
context = await getStagedCommitContext(target.worktree.path, localGitOptionsForTarget(target))
|
||||
} catch (error) {
|
||||
console.error('[runtime-git] Failed to read staged commit context:', error)
|
||||
return { success: false, error: 'Failed to read staged changes.' }
|
||||
@@ -557,16 +614,17 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
const localEnv = await prepareLocalCommitMessageAgentEnv(
|
||||
resolvedSettings.params.agentId,
|
||||
this.host.getCommitMessageAgentEnvironment?.()
|
||||
this.host.getCommitMessageAgentEnvironment?.(),
|
||||
localAgentRuntimeTargetForTarget(target)
|
||||
)
|
||||
if (!localEnv.ok) {
|
||||
return { success: false, error: localEnv.error }
|
||||
}
|
||||
return generateCommitMessageFromContext(context, resolvedSettings.params, {
|
||||
kind: 'local',
|
||||
cwd: target.worktree.path,
|
||||
...(localEnv.env ? { env: localEnv.env } : {})
|
||||
})
|
||||
return generateCommitMessageFromContext(
|
||||
context,
|
||||
resolvedSettings.params,
|
||||
localTextGenerationTargetForTarget(target, localEnv.env)
|
||||
)
|
||||
}
|
||||
|
||||
async cancelRuntimeGenerateCommitMessage(worktreeSelector: string): Promise<{ ok: true }> {
|
||||
@@ -636,7 +694,12 @@ export class RuntimeGitCommands {
|
||||
currentDraft: input.draft
|
||||
})
|
||||
: await getPullRequestDraftContext(
|
||||
(argv, options) => gitExecFileAsync(argv, { cwd: target.worktree.path, ...options }),
|
||||
(argv, options) =>
|
||||
gitExecFileAsync(argv, {
|
||||
cwd: target.worktree.path,
|
||||
...localGitOptionsForTarget(target),
|
||||
...options
|
||||
}),
|
||||
{
|
||||
base: input.base,
|
||||
currentTitle: input.title,
|
||||
@@ -666,16 +729,17 @@ export class RuntimeGitCommands {
|
||||
|
||||
const localEnv = await prepareLocalCommitMessageAgentEnv(
|
||||
resolvedSettings.params.agentId,
|
||||
this.host.getCommitMessageAgentEnvironment?.()
|
||||
this.host.getCommitMessageAgentEnvironment?.(),
|
||||
localAgentRuntimeTargetForTarget(target)
|
||||
)
|
||||
if (!localEnv.ok) {
|
||||
return { success: false, error: localEnv.error }
|
||||
}
|
||||
return generatePullRequestFieldsFromContext(context, resolvedSettings.params, {
|
||||
kind: 'local',
|
||||
cwd: target.worktree.path,
|
||||
...(localEnv.env ? { env: localEnv.env } : {})
|
||||
})
|
||||
return generatePullRequestFieldsFromContext(
|
||||
context,
|
||||
resolvedSettings.params,
|
||||
localTextGenerationTargetForTarget(target, localEnv.env)
|
||||
)
|
||||
}
|
||||
|
||||
async cancelRuntimeGeneratePullRequestFields(worktreeSelector: string): Promise<{ ok: true }> {
|
||||
@@ -716,12 +780,19 @@ export class RuntimeGitCommands {
|
||||
}
|
||||
const localEnv = await prepareLocalCommitMessageAgentEnv(
|
||||
typedAgentId,
|
||||
this.host.getCommitMessageAgentEnvironment?.()
|
||||
this.host.getCommitMessageAgentEnvironment?.(),
|
||||
localAgentRuntimeTargetForTarget(target)
|
||||
)
|
||||
if (!localEnv.ok) {
|
||||
return { success: false, error: localEnv.error }
|
||||
}
|
||||
return discoverCommitMessageModelsLocal(typedAgentId, localEnv.env, agentCommandOverride)
|
||||
const localOptions = localGitOptionsForTarget(target)
|
||||
return localOptions.wslDistro
|
||||
? discoverCommitMessageModelsLocal(typedAgentId, localEnv.env, agentCommandOverride, {
|
||||
cwd: target.worktree.path,
|
||||
wslDistro: localOptions.wslDistro
|
||||
})
|
||||
: discoverCommitMessageModelsLocal(typedAgentId, localEnv.env, agentCommandOverride)
|
||||
}
|
||||
|
||||
async stageRuntimeGitPath(worktreeSelector: string, filePath: string): Promise<{ ok: true }> {
|
||||
@@ -735,7 +806,7 @@ export class RuntimeGitCommands {
|
||||
await provider.stageFile(target.worktree.path, relativePath)
|
||||
return { ok: true }
|
||||
}
|
||||
await stageFile(target.worktree.path, relativePath)
|
||||
await stageFile(target.worktree.path, relativePath, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -750,7 +821,7 @@ export class RuntimeGitCommands {
|
||||
await provider.unstageFile(target.worktree.path, relativePath)
|
||||
return { ok: true }
|
||||
}
|
||||
await unstageFile(target.worktree.path, relativePath)
|
||||
await unstageFile(target.worktree.path, relativePath, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -768,7 +839,7 @@ export class RuntimeGitCommands {
|
||||
await provider.bulkStageFiles(target.worktree.path, relativePaths)
|
||||
return { ok: true }
|
||||
}
|
||||
await bulkStageFiles(target.worktree.path, relativePaths)
|
||||
await bulkStageFiles(target.worktree.path, relativePaths, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -786,7 +857,7 @@ export class RuntimeGitCommands {
|
||||
await provider.bulkUnstageFiles(target.worktree.path, relativePaths)
|
||||
return { ok: true }
|
||||
}
|
||||
await bulkUnstageFiles(target.worktree.path, relativePaths)
|
||||
await bulkUnstageFiles(target.worktree.path, relativePaths, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -804,7 +875,7 @@ export class RuntimeGitCommands {
|
||||
await provider.bulkDiscardChanges(target.worktree.path, relativePaths)
|
||||
return { ok: true }
|
||||
}
|
||||
await bulkDiscardChanges(target.worktree.path, relativePaths)
|
||||
await bulkDiscardChanges(target.worktree.path, relativePaths, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
@@ -819,7 +890,7 @@ export class RuntimeGitCommands {
|
||||
await provider.discardChanges(target.worktree.path, relativePath)
|
||||
return { ok: true }
|
||||
}
|
||||
await discardChanges(target.worktree.path, relativePath)
|
||||
await discardChanges(target.worktree.path, relativePath, localGitOptionsForTarget(target))
|
||||
return { ok: true }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user