Introduce pluggable VCS driver foundation #2435
Mergedjuliusmarmingemerged 46 commits into
main fromrefs/pull/2435/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/server/src/vcs/GitVcsDriver.ts line 359Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +107,21 @@107+ process,108+ "GitVcsDriver.isInsideWorkTree",109+ cwd,110+ ["rev-parse", "--is-inside-work-tree"],111+ {112+ allowNonZeroExit: true,113+ timeoutMs: 5_000,114+ maxOutputBytes: 4_096,115+ },116+ ).pipe(Effect.map((result) => result.exitCode === 0 && result.stdout.trim() === "true"));117+118+ const execute: VcsDriverShape["execute"] = (input) =>119+ gitCommand(process, input.operation, input.cwd, input.args, {120+ ...(input.stdin !== undefined ? { stdin: input.stdin } : {}),121+ ...(input.allowNonZeroExit !== undefined ? { allowNonZeroExit: input.allowNonZeroExit } : {}),122+ ...(input.timeoutMs !== undefined ? { timeoutMs: input.timeoutMs } : {}),123+ ...(input.maxOutputBytes !== undefined ? { maxOutputBytes: input.maxOutputBytes } : {}),124+ ...(input.truncateOutputAtMaxBytes !== undefined125+ ? { truncateOutputAtMaxBytes: input.truncateOutputAtMaxBytes }126+ : {}),127+ });
- apps/server/src/vcs/GitVcsDriver.ts lines 349 to 359Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +107,21 @@107+ process,108+ "GitVcsDriver.isInsideWorkTree",109+ cwd,110+ ["rev-parse", "--is-inside-work-tree"],111+ {112+ allowNonZeroExit: true,113+ timeoutMs: 5_000,114+ maxOutputBytes: 4_096,115+ },116+ ).pipe(Effect.map((result) => result.exitCode === 0 && result.stdout.trim() === "true"));117+118+ const execute: VcsDriverShape["execute"] = (input) =>119+ gitCommand(process, input.operation, input.cwd, input.args, {120+ ...(input.stdin !== undefined ? { stdin: input.stdin } : {}),121+ ...(input.allowNonZeroExit !== undefined ? { allowNonZeroExit: input.allowNonZeroExit } : {}),122+ ...(input.timeoutMs !== undefined ? { timeoutMs: input.timeoutMs } : {}),123+ ...(input.maxOutputBytes !== undefined ? { maxOutputBytes: input.maxOutputBytes } : {}),124+ ...(input.truncateOutputAtMaxBytes !== undefined125+ ? { truncateOutputAtMaxBytes: input.truncateOutputAtMaxBytes }126+ : {}),127+ });
- apps/server/src/checkpointing/Layers/CheckpointStore.ts line 151Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -120,18 +117,19 @@120117 operation,121118 cwd: input.cwd,122119 args: ["add", "-A", "--", "."],123120 env: commitEnv,124121 });125122126- const writeTreeResult = yield* git.execute({123+ const writeTreeResult = yield* vcs.execute({127124 operation,128125 cwd: input.cwd,129126 args: ["write-tree"],130127 env: commitEnv,131128 });132129 const treeOid = writeTreeResult.stdout.trim();133130 if (treeOid.length === 0) {134- return yield* new GitCommandError({131+ return yield* new VcsProcessExitError({135132 operation,136133 command: "git write-tree",137134 cwd: input.cwd,135+ exitCode: 0,
- apps/server/src/checkpointing/Layers/CheckpointStore.ts line 43Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -27,4 +27,17 @@27- const git = yield* GitCore;28-29- const resolveHeadCommit = (cwd: string): Effect.Effect<string | null, GitCommandError> =>30- git27+ const vcsRegistry = yield* VcsDriverRegistry;28+ const vcs = {29+ execute: (input: {30+ readonly operation: string;31+ readonly cwd: string;32+ readonly args: ReadonlyArray<string>;33+ readonly stdin?: string;34+ readonly env?: NodeJS.ProcessEnv;35+ readonly allowNonZeroExit?: boolean;36+ readonly timeoutMs?: number;37+ readonly maxOutputBytes?: number;38+ readonly truncateOutputAtMaxBytes?: boolean;39+ }) =>40+ vcsRegistry41+ .resolve({ cwd: input.cwd, requestedKind: "git" })42+ .pipe(Effect.flatMap((handle) => handle.driver.execute(input))),43+ };
- apps/server/src/vcs/VcsStatusBroadcaster.ts line 207Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +176,21 @@176+ });177+178+ const getOrLoadRemoteStatus = Effect.fn("VcsStatusBroadcaster.getOrLoadRemoteStatus")(179+ function* (cwd: string) {180+ const cached = yield* getCachedStatus(cwd);181+ if (cached?.remote) {182+ return cached.remote.value;183+ }184+ return yield* loadRemoteStatus(cwd);185+ },186+ );187+188+ const getStatus: VcsStatusBroadcasterShape["getStatus"] = Effect.fn(189+ "VcsStatusBroadcaster.getStatus",190+ )(function* (input) {191+ const [local, remote] = yield* Effect.all([192+ getOrLoadLocalStatus(input.cwd),193+ getOrLoadRemoteStatus(input.cwd),194+ ]);195+ return mergeGitStatusParts(local, remote);196+ });
- apps/server/src/checkpointing/Layers/CheckpointStore.ts line 43Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -27,4 +27,17 @@27- const git = yield* GitCore;28-29- const resolveHeadCommit = (cwd: string): Effect.Effect<string | null, GitCommandError> =>30- git27+ const vcsRegistry = yield* VcsDriverRegistry;28+ const vcs = {29+ execute: (input: {30+ readonly operation: string;31+ readonly cwd: string;32+ readonly args: ReadonlyArray<string>;33+ readonly stdin?: string;34+ readonly env?: NodeJS.ProcessEnv;35+ readonly allowNonZeroExit?: boolean;36+ readonly timeoutMs?: number;37+ readonly maxOutputBytes?: number;38+ readonly truncateOutputAtMaxBytes?: boolean;39+ }) =>40+ vcsRegistry41+ .resolve({ cwd: input.cwd, requestedKind: "git" })42+ .pipe(Effect.flatMap((handle) => handle.driver.execute(input))),43+ };
- apps/web/src/components/BranchToolbar.logic.ts lines 46 to 46OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -43,4 +43,4 @@4343 }44444545 export function resolveEnvModeLabel(mode: EnvMode): string {46- return mode === "worktree" ? "New worktree" : "Current checkout";46+ return mode === "worktree" ? "New worktree" : "Current switchRef";
- apps/server/src/vcs/GitVcsDriver.ts line 44Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +23,21 @@23+24+export interface ExecuteGitInput {25+ readonly operation: string;26+ readonly cwd: string;27+ readonly args: ReadonlyArray<string>;28+ readonly stdin?: string;29+ readonly env?: NodeJS.ProcessEnv;30+ readonly allowNonZeroExit?: boolean;31+ readonly timeoutMs?: number;32+ readonly maxOutputBytes?: number;33+ readonly truncateOutputAtMaxBytes?: boolean;34+ readonly progress?: ExecuteGitProgress;35+}36+37+export interface ExecuteGitResult {38+ readonly code: number;39+ readonly stdout: string;40+ readonly stderr: string;41+ readonly stdoutTruncated: boolean;42+ readonly stderrTruncated: boolean;43+}
- apps/server/src/sourceControl/GitHubSourceControlProvider.ts line 109Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +85,21 @@85+ ...toChangeRequest(item),86+ updatedAt: item.updatedAt,87+ })),88+ )89+ : Effect.fail(90+ new SourceControlProviderError({91+ provider: "github",92+ operation: "listChangeRequests",93+ detail: "GitHub CLI returned invalid change request JSON.",94+ cause: decoded.failure,95+ }),96+ ),97+ ),98+ ),99+ ),100+ Effect.mapError((error) =>101+ Schema.is(SourceControlProviderError)(error)102+ ? error103+ : providerError("listChangeRequests", error),104+ ),105+ );
- apps/server/src/git/GitManager.ts line 1048OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1035,4 +1045,4 @@10351045 }10361046 }103710471038- const defaultFromGh = yield* gitHubCli1048+ const defaultFromProvider = yield* (yield* sourceControlProvider(cwd))
- apps/server/src/git/GitManager.ts line 702OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -654,4 +699,4 @@654699 .pipe(655700 Effect.catchIf(isNotGitRepositoryError, () => Effect.succeed(nonRepositoryStatusDetails)),656701 );657- const hostingProvider = details.isRepo702+ const sourceControlProvider = details.isRepo
- @@ -75,6 +113,10 @@7511376114 interface PullRequestInfo extends OpenPrInfo, PullRequestHeadRemoteInfo {77115 state: "open" | "closed" | "merged";78- updatedAt: string | null;116+ updatedAt: Option.Option<DateTime.Utc>;79117 }80118119+const pullRequestUpdatedAtDescOrder: Order.Order<PullRequestInfo> = Order.mapInput(120+ Order.flip(Option.makeOrder(DateTime.Order)),121+ (pullRequest) => pullRequest.updatedAt,122+);
- apps/server/src/git/GitManager.ts line 125Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -75,6 +113,10 @@7511376114 interface PullRequestInfo extends OpenPrInfo, PullRequestHeadRemoteInfo {77115 state: "open" | "closed" | "merged";78- updatedAt: string | null;116+ updatedAt: Option.Option<DateTime.Utc>;79117 }80118119+const pullRequestUpdatedAtDescOrder: Order.Order<PullRequestInfo> = Order.mapInput(120+ Order.flip(Option.makeOrder(DateTime.Order)),121+ (pullRequest) => pullRequest.updatedAt,122+);
- packages/client-runtime/src/sourceControlDiscoveryState.ts lines 76 to 200Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +135,21 @@135+ refreshInFlight.set(targetKey, tracked);136+ return tracked;137+ }138+139+ function getSnapshot(target: SourceControlDiscoveryTarget): SourceControlDiscoveryState {140+ const targetKey = getSourceControlDiscoveryTargetKey(target);141+ if (targetKey === null) {142+ return EMPTY_SOURCE_CONTROL_DISCOVERY_STATE;143+ }144+145+ return config.getRegistry().get(sourceControlDiscoveryStateAtom(targetKey));146+ }147+148+ function reset(): void {149+ refreshInFlight.clear();150+ for (const key of knownSourceControlDiscoveryKeys) {151+ setState(key, INITIAL_SOURCE_CONTROL_DISCOVERY_STATE);152+ }153+ knownSourceControlDiscoveryKeys.clear();154+ }155+
- packages/client-runtime/src/sourceControlDiscoveryState.ts lines 36 to 44Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +24,21 @@24+ error: null,25+ isPending: false,26+});27+28+const INITIAL_SOURCE_CONTROL_DISCOVERY_STATE = Object.freeze<SourceControlDiscoveryState>({29+ data: null,30+ error: null,31+ isPending: true,32+});33+34+/* --- Atoms ---------------------------------------------------------- */35+36+const knownSourceControlDiscoveryKeys = new Set<string>();37+38+export const sourceControlDiscoveryStateAtom = Atom.family((key: string) => {39+ knownSourceControlDiscoveryKeys.add(key);40+ return Atom.make(INITIAL_SOURCE_CONTROL_DISCOVERY_STATE).pipe(41+ Atom.keepAlive,42+ Atom.withLabel(`source-control-discovery:${key}`),43+ );44+});@@ -496,2 +448,2 @@496448497449 if (event === "child_exit") {
- apps/server/src/git/GitManager.ts line 1670Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1639,3 +1662,6 @@1639166216401663 const currentBranch = branchStep.name ?? initialStatus.branch;16411664 const commitAction = isCommitAction(input.action) ? input.action : null;1665+ const changeRequestTerms = wantsPr1666+ ? getChangeRequestTerminologyForKind((yield* sourceControlProvider(input.cwd)).kind)1667+ : null;
juliusmarminge merged this6d7fe2e
juliusmarminge closed this
Sign in to join this conversation.



Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
9b72afe9-19aa-41ae-a95e-de88371d3c73You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands and usage tips.