feat(jj): support colocated Jujutsu repositories #13816
Closedknocking4thcylinder(GitHub profile, opens in a new tab)wants to merge 27 commits into
main fromrefs/pull/13816/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/mobile/src/features/threads/git/GitBranchesSheet.tsx line 182OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -168,3 +171,12 @@168171 />169172 </View>170173174+ {currentWorktreePath ? (175+ <View className="gap-3 rounded-[20px] bg-card p-4">176+ <Text className="text-foreground-secondary text-sm">{currentWorktreePath}</Text>177+ <SheetActionButton178+ icon="trash"179+ label={`Remove ${vcsTerminology.workspaceNoun}`}180+ disabled={busy}181+ onPress={() => {182+ void gitActions.onRemoveSelectedThreadWorkspace().then(() => navigation.goBack());apps/mobile/src/state/use-selected-thread-git-actions.ts line 331OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -294,0 +311,21 @@311+ const project = selectedThreadProject;312+ const worktreePath = selectedThreadWorktreePath;313+ if (!thread || !project || !worktreePath) {314+ return;315+ }316+ const confirmed = await new Promise<boolean>((resolve) => {317+ Alert.alert(318+ `Remove this ${vcsTerminology.workspaceNoun}?`,319+ `${worktreePath}\n\nThe thread stays; only the ${vcsTerminology.workspaceNoun} is deleted.`,320+ [321+ { text: "Cancel", style: "cancel", onPress: () => resolve(false) },322+ { text: "Remove", style: "destructive", onPress: () => resolve(true) },323+ ],324+ );325+ });326+ if (!confirmed) {327+ return;328+ }329+ const result = await removeWorktree({330+ environmentId: thread.environmentId,331+ input: { cwd: project.workspaceRoot, path: worktreePath, force: true },apps/mobile/src/state/use-selected-thread-git-actions.ts lines 342 to 346OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -294,0 +326,21 @@326+ if (!confirmed) {327+ return;328+ }329+ const result = await removeWorktree({330+ environmentId: thread.environmentId,331+ input: { cwd: project.workspaceRoot, path: worktreePath, force: true },332+ });333+ if (AsyncResult.isFailure(result)) {334+ const error = Cause.squash(result.cause);335+ showGitActionResult({336+ type: "error",337+ title: `Failed to remove ${vcsTerminology.workspaceNoun}`,338+ description: error instanceof Error ? error.message : "An error occurred.",339+ });340+ return;341+ }342+ await syncSelectedThreadBranchState({343+ thread,344+ cwd: project.workspaceRoot,345+ nextThreadState: { worktreePath: null },346+ });apps/server/src/git/GitManager.ts lines 2931 to 2936Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2717,15 +2931,6 @@2717- providers,2718- ),2719- style: settings.sourceControlWritingStyle,2720- })),2721- ),2722- ),2723- Effect.mapError(2724- (cause) =>2725- new GitManagerError({2726- operation: "runStackedAction",2727- cwd: input.cwd,2728- detail: "Failed to get server settings.",2729- cause,2730- }),2731- ),2931+ const textGenerationSettings = yield* withChangeRequestServices(2932+ resolveTextGenerationSettings({2933+ operation: "runStackedAction",2934+ cwd: input.cwd,2935+ ...(input.threadId !== undefined ? { threadId: input.threadId } : {}),2936+ }),apps/server/src/git/GitWorkflowService.ts lines 121 to 122OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -35,3 +103,20 @@103+ readonly createRef: (104+ input: VcsCreateRefInput,105+ ) => Effect.Effect<VcsCreateRefResult, GitCommandError>;106+ readonly switchRef: (107+ input: VcsSwitchRefInput,108+ ) => Effect.Effect<VcsSwitchRefResult, GitCommandError>;109+ readonly renameBranch: (input: {110+ readonly cwd: string;111+ readonly oldBranch: string;112+ readonly newBranch: string;113+ }) => Effect.Effect<{ readonly branch: string }, GitManagerServiceError>;114+}115+116+type WorkflowKind = "git" | "jj";117+118+/** Routes every workflow call to the driver that owns the directory it names. */35119 export class GitWorkflowService extends Context.Service<36120 GitWorkflowService,37- {121+ VcsWorkflowOps & {122+ /** Git specifically, not "a repository this service can serve": a jj workspace answers false. */apps/server/src/jj/JjWorkspaces.ts lines 175 to 184OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +164,21 @@164+ return yield* Effect.fail(165+ jjFailure(166+ operation,167+ input.cwd,168+ `${worktreePath} already exists and is not a Jujutsu workspace.`,169+ ),170+ );171+ }172+ }173+174+ yield* assertBookmarkUsable(driver, operation, input.cwd, targetRef);175+ if (input.newRefName !== undefined) {176+ yield* run(177+ operation,178+ input.cwd,179+ ["bookmark", "create", input.newRefName, "-r", localBookmarkRevset(baseRef)],180+ { timeoutMs: 20_000 },181+ ).pipe(182+ mapJjFailure(operation, input.cwd, `Could not create bookmark ${input.newRefName}.`),183+ );184+ }apps/server/src/jj/JjWorkspaces.ts lines 309 to 318OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +298,21 @@298+299+ if (dirty && input.force !== true) {300+ return yield* Effect.fail(301+ jjFailure(302+ operation,303+ input.cwd,304+ "Workspace has uncommitted or unbookmarked changes. Remove it with force to discard them.",305+ ),306+ );307+ }308+309+ const segmentBookmark = segment.at(-1)?.localBookmarks.toSorted()[0];310+ if (stranded && segmentBookmark !== undefined) {311+ // `jj workspace add -r <bookmark>` leaves the bookmark on the base, so the agent's own312+ // commits sit on no ref. Moving the bookmark to `@-` first is the jj spelling of what313+ // git's worktree branch does for free; a failure here must not block the removal.314+ yield* bookmarkTo({315+ cwd: input.path,316+ name: segmentBookmark,317+ revset: "@-",318+ operation,apps/server/src/project/RepositoryIdentityResolver.ts lines 107 to 113OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -97,3 +104,10 @@97104 };98105 }99106107+function isDirectorySync(candidate: string): boolean {108+ try {109+ return NodeFS.statSync(candidate).isDirectory();110+ } catch {111+ return false;112+ }113+}apps/server/src/vcs/JjAvailability.ts lines 93 to 105Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +83,21 @@83+ });84+85+ return Effect.fn("JjAvailability.availability")(function* (86+ cwd: string,87+ ): Effect.fn.Return<JjAvailability, never> {88+ const known = yield* Ref.get(cached);89+ if (Option.isSome(known)) {90+ return known.value;91+ }92+93+ return yield* probeLock.withPermits(1)(94+ Effect.gen(function* () {95+ const raced = yield* Ref.get(cached);96+ if (Option.isSome(raced)) {97+ return raced.value;98+ }99+ const availability = yield* probe(cwd);100+ yield* Ref.set(cached, Option.some(availability));101+ return availability;102+ }),103+ );apps/server/src/vcs/JjRevset.ts lines 44 to 46Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +26,21 @@26+ return parsed === null ? null : { remote: parsed.remoteName, name: parsed.branchName };27+}28+29+/**30+ * `file:"<escaped>"` is jj's literal fileset form, git's `--literal-pathspecs` equivalent. Bare31+ * arguments are parsed as fileset *expressions*, so `a~b` silently becomes a difference and32+ * `a (1).png` fails to parse; a bare leading `-` is parsed as an option instead of a path.33+ */34+export function literalFilesetPath(filePath: string): string {35+ return `file:"${escapeRevsetString(filePath)}"`;36+}37+38+/** `bookmarks(exact:"<escaped>")` resolves a local bookmark unambiguously. */39+export function localBookmarkRevset(name: string): string {40+ return `bookmarks(exact:"${escapeRevsetString(name)}")`;41+}42+43+/** `<name>@<remote>` is the only form jj accepts for a remote bookmark. */44+export function remoteBookmarkRevset(remote: string, name: string): string {45+ return `${name}@${remote}`;46+}apps/server/src/vcs/JjVcsDriver.ts lines 352 to 362Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +337,21 @@337+ );338+339+ const jjLog = (340+ operation: string,341+ cwd: string,342+ args: ReadonlyArray<string>,343+ options?: JjProcess.JjCommandOptions,344+ ) => JjProcess.jjCommand(vcsProcess, operation, cwd, args, options);345+346+ const changeFromRevset = Effect.fn("JjVcsDriver.changeFromRevset")(function* (347+ operation: string,348+ cwd: string,349+ revset: string,350+ ignoreWorkingCopy: boolean,351+ ): Effect.fn.Return<JjChange | null, VcsError> {352+ const result = yield* jjLog(353+ operation,354+ cwd,355+ ["log", "-r", revset, "--no-graph", "--limit", "1", "-T", CHANGE_TEMPLATE],356+ { timeoutMs: 20_000, maxOutputBytes: 4 * 1024 * 1024, ignoreWorkingCopy },357+ );apps/server/src/vcs/JjVcsDriver.ts line 722OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +702,21 @@702+ const filterIgnoredPaths: VcsDriver.VcsDriver["Service"]["filterIgnoredPaths"] = Effect.fn(703+ "JjVcsDriver.filterIgnoredPaths",704+ )(function* (cwd: string, relativePaths: ReadonlyArray<string>) {705+ if (relativePaths.length === 0) {706+ return relativePaths;707+ }708+709+ const operation = "JjVcsDriver.filterIgnoredPaths";710+ // Deliberately not `ensureUsable`: nothing here spawns jj, and leaving the paths unfiltered in711+ // a repository T3 cannot operate on is safer than failing the caller's whole listing.712+ const paths = yield* repoPaths(cwd);713+ if (paths.gitDir === null) {714+ return relativePaths;715+ }716+717+ const ignoredPaths = new Set<string>();718+ for (const chunk of chunkPathsForCheckIgnore(relativePaths)) {719+ const result = yield* JjProcess.colocatedGitCommand(720+ vcsProcess,721+ operation,722+ { gitDir: paths.gitDir, workTree: cwd, cwd },apps/web/src/components/ChatView.tsx line 6572Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -6566,4 +6568,4 @@65666568 disabled={isRestoringThreadBranch}65676569 onClick={handleRestoreThreadBranch}65686570 >6569- {isRestoringThreadBranch ? "Restoring..." : "Restore branch"}6571+ {isRestoringThreadBranch ? "Restoring..." : `Restore ${vcsTerminology.refNoun}`}apps/web/src/components/settings/VcsConfigurationSettings.tsx line 142OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +122,21 @@122+ }123+ };124+125+ const config = configuration.data;126+ const kind = config?.kind;127+ return (128+ <SettingsSection title="Repository configuration">129+ {member === null ? (130+ <p className="px-4 py-3 text-sm text-muted-foreground">131+ Choose one checkout to edit its Git or Jujutsu configuration.132+ </p>133+ ) : configuration.error ? (134+ <p className="px-4 py-3 text-sm text-destructive">{configuration.error}</p>135+ ) : !config ? (136+ <p className="px-4 py-3 text-sm text-muted-foreground">137+ Loading repository configuration...138+ </p>139+ ) : (140+ <>141+ <ConfigurationRow142+ key={`name:${config.userName.repository}:${config.userName.effective}`}packages/client-runtime/src/state/gitActions.ts lines 377 to 386Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -294,14 +375,15 @@375+ return noRefHint(gitStatus, vcs, `creating a ${terminology.singular}`);294376 }295377 if (hasChanges) {296- return "Commit local changes before creating a PR.";378+ return `Commit local changes before creating a ${terminology.singular}.`;297379 }298- if (!gitStatus.hasUpstream && !hasOriginRemote) {299- return 'Add an "origin" remote before creating a PR.';380+ if (!gitStatus.hasUpstream && !hasPrimaryRemote) {381+ return `Add an "origin" remote before creating a ${terminology.singular}.`;300382 }301383 if (!isAhead) {302- return "No local commits to include in a PR.";384+ return `No local commits to include in a ${terminology.singular}.`;303385 }304386 if (isBehind) {305- return "Branch is behind upstream. Pull/rebase before creating a PR.";387+ return `${vcs.refNounTitle} is behind upstream. Pull/rebase before creating a ${terminology.singular}.`;306388 }307- return "Create PR is currently unavailable.";389+ return `Create ${terminology.shortLabel} is currently unavailable.`;
- apps/server/src/jj/JjWorkspaces.ts line 186OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +166,21 @@166+ operation,167+ input.cwd,168+ `${worktreePath} already exists and is not a Jujutsu workspace.`,169+ ),170+ );171+ }172+ }173+174+ yield* assertBookmarkUsable(driver, operation, input.cwd, targetRef);175+ const localBookmarkExists =176+ input.newRefName !== undefined &&177+ (yield* driver178+ .listBookmarks(input.cwd)179+ .pipe(mapJjFailure(operation, input.cwd, "Could not list Jujutsu bookmarks."))).some(180+ (bookmark) => bookmark.remote === null && bookmark.name === input.newRefName,181+ );182+ if (input.newRefName !== undefined && !localBookmarkExists) {183+ yield* run(184+ operation,185+ input.cwd,186+ ["bookmark", "create", input.newRefName, "-r", localBookmarkRevset(baseRef)],
juliusmarminge closed this
Sign in to join this conversation.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: pingdotgg/t3code/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
f17b357d-40eb-4d26-971f-7c2760aad90c📥 Commits
Reviewing files that changed from the base of the PR and between be45bb0f1d8b16a9c726360efb8680e5494e4cea and 6b66421bd41c7f1b2fa27f0dab575cdabc6817ab.
📒 Files selected for processing (3)
apps/web/src/components/settings/SourceControlSettings.tsxapps/web/src/components/settings/settingsSearch.tsdocs/user/source-control.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
📝 Walkthrough
Walkthrough#
The pull request adds Jujutsu support alongside Git. It adds a Jujutsu driver and server workflows, updates repository detection and checkpoint and review-diff support, and routes operations by VCS kind. Web and mobile clients gain VCS-specific labels and Jujutsu controls.
Changes#
Jujutsu VCS support
packages/contracts/src/git.ts,packages/shared/src/vcs.ts,apps/server/src/vcs/*apps/server/src/jj/*,apps/server/src/git/*,apps/server/src/checkpointing/*,apps/server/src/orchestration/Layers/*,apps/server/src/server.ts,apps/server/src/sourceControl/*,apps/server/src/project/*,apps/server/src/review/*apps/mobile/src/features/*,apps/mobile/src/state/*,apps/web/src/components/*,apps/web/src/hooks/*,apps/web/src/state/*,packages/client-runtime/src/state/*.github/actions/setup-jj/action.yml,.github/workflows/*,docs/*,apps/server/src/vcs/testing/*,packages/shared/src/git.ts,packages/shared/package.jsonPriority: ➖ Normal
Estimated code review effort: 5 (Critical) | ~120 minutes
Sequence Diagram(s)#
Suggested reviewers:
juliusmarmingeMerge Risk: 🔵 Low · up to
6b664Jujutsu users may see Git-specific terminology in branch-change messaging, but the affected actions remain functional. The remaining risk is bounded to user-facing copy.
Security Architecture Review#
Security architecture risk: 🟡 Moderate · up to
6b664Jujutsu support adds a substantial repository-management path. The reviewed code does not establish a new security vulnerability, but some failed workspace operations can leave repository state inconsistent or remove a workspace without preserving its bookmark.
Retained concerns
Security review details
Security Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 25.51% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 98 functions across 65 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.