Skip to content

add configurable worktree location settings#1926

Open
tarik02 wants to merge 2 commits intopingdotgg:mainfrom
tarik02:add-worktree-location-settings
Open

add configurable worktree location settings#1926
tarik02 wants to merge 2 commits intopingdotgg:mainfrom
tarik02:add-worktree-location-settings

Conversation

@tarik02
Copy link
Copy Markdown

@tarik02 tarik02 commented Apr 11, 2026

Fixes #1878

What Changed

This adds configurable worktree location settings so T3 Code does not have to create worktrees in one fixed global layout.

Specifically, this PR:

  • adds built-in worktree location modes for the default global layout, a project subdirectory layout, and a project sibling layout
  • adds a custom template option for users who need a different absolute path layout
  • updates server-side worktree creation flows to resolve the target path before creating a worktree
  • centralizes path sanitization, template validation, resolution, and preview rendering in shared helpers
  • adds settings UI for selecting the mode, editing a custom template, previewing the final path, and showing inline validation errors
  • adds tests for shared helpers, server plumbing, and settings panel behavior
  • GitCore no longer depends on ServerConfig

Why

Some projects depend on folder-scoped local tooling and parent-directory configuration.

Examples from the issue include setups like direnv, flakes, and similar tooling that only work when the worktree lives under the expected project directory tree. The current global worktree location breaks those setups because the new worktree ends up outside the folder hierarchy those tools rely on.

This change lets users keep the existing global behavior, place worktrees under the project, or define a custom layout when their environment has stricter path requirements.

UI Changes

Before:

  • worktrees were created in the default global location only
  • there was no setting to change that behavior
image

After:

  • General Settings includes a Worktree location setting
  • users can choose a built-in location mode or a custom template
  • the UI shows a live preview of the resolved path and inline validation for invalid custom templates
image image
_20260411_131122.webm

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Medium Risk
Changes how worktree paths are chosen across server and WS RPC flows, and introduces new settings-driven path templating/validation that could affect where repos are created on disk.

Overview
Adds a new server setting (worktreeLocation) that lets users choose where git worktrees are created (default global layout, project-subdirectory, project-sibling, or a validated custom absolute-path template), with a live preview + inline validation in the General Settings UI.

Introduces shared @t3tools/shared/worktreeLocation helpers for sanitization, template validation/substitution, and preview rendering, plus a new server-side WorktreeLocationResolver service/layer that resolves the final create-worktree path from ServerConfig + ServerSettings.

Updates server worktree creation flows (GitManager.preparePullRequestThread, websocket gitCreateWorktree, and bootstrap worktree preparation) to resolve a concrete path before calling GitCore.createWorktree, and adjusts RPC/contracts error unions to include WorktreeLocationResolverError. Also removes GitCore’s dependency on ServerConfig and simplifies several test layers accordingly.

Reviewed by Cursor Bugbot for commit ee02eec. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Add configurable worktree location settings with mode selection and custom templates

  • Introduces WorktreeLocationResolver, a new service that computes worktree paths from server settings supporting four modes: default, project-subdirectory, project-sibling, and custom template.
  • Adds WorktreeLocationSettings to the server settings schema with a mode and optional custom template field; settings can be patched and restored to defaults.
  • Moves worktree path resolution out of GitCore into GitManager and the WebSocket RPC layer; callers must now supply an explicit path to createWorktree.
  • Adds a settings UI in GeneralSettingsPanel with live path preview, inline template validation, and reset-to-defaults support.
  • Shared path computation and validation logic lives in the new worktreeLocation.ts helper module, used by both server and web.
  • Behavioral Change: WsGitCreateWorktreeRpc can now return a WorktreeLocationResolverError; existing callers that do not supply a path will have it resolved dynamically.
📊 Macroscope summarized ee02eec. 20 files reviewed, 2 issues evaluated, 1 issue filtered, 1 comment posted

🗂️ Filtered Issues

apps/server/src/project/Layers/WorktreeLocationResolver.ts — 0 comments posted, 1 evaluated, 1 filtered
  • line 50: On lines 50-53, yield* is used on a plain WorktreeLocationResolverError object returned by createWorktreeLocationResolverError(). Since this function returns an error object (not an Effect), using yield* on it will fail at runtime because the error class is not an Effect/Yieldable. The code should use Effect.fail() to properly fail with this error: return yield* Effect.fail(createWorktreeLocationResolverError(...)) [ Failed validation ]

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 11, 2026

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 468a763f-27ec-4587-8902-9e7bff14a2e7

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added size:XL 500-999 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 11, 2026
return segments.at(-1) ?? input;
}

function getPathDirname(input: string): string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Low src/worktreeLocation.ts:76

getPathDirname returns "C:" for path C:\foo, but C: in Windows refers to the current working directory on that drive, not the root directory C:\. This causes $PROJECT_DIRNAME to resolve to a semantically incorrect path when projects are located at a Windows drive root.

🤖 Copy this AI Prompt to have your agent fix this:
In file packages/shared/src/worktreeLocation.ts around line 76:

`getPathDirname` returns `"C:"` for path `C:\foo`, but `C:` in Windows refers to the current working directory on that drive, not the root directory `C:\`. This causes `$PROJECT_DIRNAME` to resolve to a semantically incorrect path when projects are located at a Windows drive root.

Evidence trail:
1. packages/shared/src/worktreeLocation.ts lines 76-92 - `getPathDirname` function implementation shows `trimmed.slice(0, separatorIndex)` returns `"C:"` for input `C:\foo`
2. packages/shared/src/worktreeLocation.ts lines 54-59 - `trimTrailingSeparators` function confirms input "C:\foo" passes through unchanged
3. https://learn.microsoft.com/en-us/dotnet/standard/io/file-path-formats - Microsoft documentation confirms `C:` is a relative path to current directory on drive C, while `C:\` is the root. States this difference is "a common source of bugs that involve Windows file paths."

Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ee02eec. Configure here.

const TRAILING_SEPARATOR_PATTERN = /[\\/]+$/;
const LEADING_SEPARATOR_PATTERN = /^[\\/]+/;
const ABSOLUTE_TEMPLATE_VARIABLE_PREFIXES = ["$T3_HOME", "$PROJECT_DIRNAME"] as const;
const ABSOLUTE_TEMPLATE_VARIABLES = ["$T3_HOME", "$PROJECT_DIRNAME"] as const;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant identical constant arrays for template variables

Low Severity

ABSOLUTE_TEMPLATE_VARIABLE_PREFIXES and ABSOLUTE_TEMPLATE_VARIABLES are two separate const arrays with identical contents (["$T3_HOME", "$PROJECT_DIRNAME"]). They're used in startsWithAbsoluteTemplatePrefix and validateWorktreeLocationTemplate respectively, but serve the same conceptual purpose of identifying absolute-path template variables. A single constant would be clearer and avoid the risk of them diverging silently in a future edit.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ee02eec. Configure here.

@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 11, 2026

Approvability

Verdict: Needs human review

This PR introduces a new user-facing feature with configurable worktree location settings, including new settings schema, a new service layer, new UI controls, and template validation logic. The scope and runtime behavior changes warrant human review even though individual components appear well-structured.

You can customize Macroscope's approvability policy. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: configurable worktree location

1 participant