Skip to content

feat: default worktree directory to parent of agent's cwd#557

Open
jSydorowicz21 wants to merge 3 commits intoRunMaestro:mainfrom
jSydorowicz21:feat/default-worktree-directory
Open

feat: default worktree directory to parent of agent's cwd#557
jSydorowicz21 wants to merge 3 commits intoRunMaestro:mainfrom
jSydorowicz21:feat/default-worktree-directory

Conversation

@jSydorowicz21
Copy link

@jSydorowicz21 jSydorowicz21 commented Mar 11, 2026

Summary

  • Default the worktree base directory to the parent of the agent's working directory instead of leaving it empty
  • Extract getParentDir helper to eliminate duplicated path regex logic
  • Previously, you were required to enter a path for the worktree even if you wanted the logical default to apply, this provides the parent as a default path

Summary by CodeRabbit

  • Bug Fixes
    • Worktree configuration modal now defaults the base path to the parent directory of the agent's current working directory when no existing worktree is configured, offering a more intuitive starting point.
    • Modal open/reset and enable/disable behavior updated to consistently use the session cwd-derived default.

The worktree config modal now pre-fills the base path with the parent
directory of the agent's cwd instead of leaving it empty, so creating
a new worktree no longer requires manual directory selection.
@coderabbitai
Copy link

coderabbitai bot commented Mar 11, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2a4148ea-2fa0-4094-bb26-bf19ea11b3c5

📥 Commits

Reviewing files that changed from the base of the PR and between 504889f and b952a0d.

📒 Files selected for processing (1)
  • src/renderer/components/WorktreeConfigModal.tsx

📝 Walkthrough

Walkthrough

The change updates WorktreeConfigModal.tsx to default basePath to the parent directory of session.cwd (via a new internal getParentDir() helper) instead of an empty string, and adjusts related reset, open-time refresh, and disable-check logic to use existence of session.worktreeConfig.basePath.

Changes

Cohort / File(s) Summary
WorktreeConfigModal
src/renderer/components/WorktreeConfigModal.tsx
Added internal getParentDir(path: string) helper. Default basePath initialization, modal reset, and open-time refresh now use parent directory of session.cwd when session.worktreeConfig.basePath is missing. canDisable logic now depends on existence of session.worktreeConfig.basePath rather than current basePath state.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: defaulting the worktree directory to the parent of the agent's current working directory, which is the primary behavioral change in this PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@greptile-apps
Copy link

greptile-apps bot commented Mar 11, 2026

Greptile Summary

This PR improves the worktree configuration UX by defaulting the base directory input to the parent of the agent's current working directory, removing the need for users to manually type the most common value. It also extracts a getParentDir helper to eliminate duplicated regex logic across the two initialization sites.

The approach is solid, but the change introduces a logic regression in the canDisable guard and two smaller edge cases:

  • canDisable bug: Because basePath now initializes to a non-empty string (the parent dir), canDisable evaluates to true even when no worktree config has ever been saved. This causes the "Disable" button to appear active on first open, before the user has saved anything, and clicking it will invoke onDisableConfig() unnecessarily.
  • Root-level path edge case: getParentDir('/projects') returns '' instead of '/', silently falling back to an empty basePath for sessions whose cwd sits directly under the filesystem root.
  • Missing useEffect dependency: session.cwd is used inside the reset effect but is omitted from its dependency array, so a cwd change while the component is mounted would not update the default until isOpen or session.worktreeConfig changes.

Confidence Score: 3/5

  • The PR is mostly safe but contains a logic regression that enables the Disable button incorrectly; should be fixed before merging.
  • The core feature — defaulting the basePath to the parent dir — is a clear UX improvement and the getParentDir extraction is clean. However, the canDisable regression means the Disable button is incorrectly active for brand-new sessions with no saved config, which can mislead users and trigger an unnecessary onDisableConfig() call. The two additional issues (root-path edge case and missing dependency) are lower severity but worth addressing.
  • src/renderer/components/WorktreeConfigModal.tsx — specifically the canDisable expression on line 66 and the getParentDir return value for root-level paths.

Important Files Changed

Filename Overview
src/renderer/components/WorktreeConfigModal.tsx Adds getParentDir helper and defaults basePath to the parent of session.cwd. Introduces a logic bug where canDisable becomes unconditionally true (enabling the Disable button before any config is saved), a silent edge case in getParentDir for top-level paths, and a missing session.cwd dependency in the reset useEffect.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A([Modal Opens]) --> B{worktreeConfig basePath set?}
    B -- Yes --> C[basePath = saved basePath]
    B -- No --> D[basePath = getParentDir of session.cwd]
    D --> E{cwd directly under root?}
    E -- Yes --> F["getParentDir returns '' - edge case"]
    E -- No --> G[basePath = parent dir e.g. /home/user]
    C --> H[Evaluate canDisable]
    G --> H
    F --> H
    H --> I{worktreeConfig.basePath OR basePath non-empty?}
    I -- "No config + empty basePath" --> J["canDisable = false - Disable button disabled OK"]
    I -- "No config + non-empty default" --> K["canDisable = true - BUG: Disable enabled with nothing to disable"]
    I -- "Saved config exists" --> L["canDisable = true - Disable button enabled OK"]
Loading

Comments Outside Diff (2)

  1. src/renderer/components/WorktreeConfigModal.tsx, line 66 (link)

    Disable button incorrectly enabled with no saved config

    canDisable now evaluates to true whenever session.cwd has a parent directory — which is almost always — even when there is no active worktree configuration saved on the session. Before this PR, basePath initialized to '', so canDisable was false for brand-new sessions with no worktreeConfig. Now basePath defaults to the parent-dir string, making basePath.trim() truthy and canDisable = true unconditionally.

    The user will see the "Disable" button enabled the very first time they open the modal (before ever saving a config), and clicking it will call onDisableConfig() with nothing to actually disable.

    The intent of the button is to allow disabling an already-saved configuration. The fix is to gate it on the persisted config rather than the in-form state:

  2. src/renderer/components/WorktreeConfigModal.tsx, line 93-101 (link)

    session.cwd missing from useEffect dependency array

    getParentDir(session.cwd) is called inside this effect but session.cwd is not listed as a dependency. If the session's working directory ever changes while the component is mounted (e.g. due to a cd command), re-opening the modal would still show the stale default basePath.

Last reviewed commit: 504889f

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/renderer/components/WorktreeConfigModal.tsx`:
- Around line 18-21: getParentDir currently returns an empty string for paths
like "/repo" and "C:\repo" which causes downstream code that uses this value as
basePath (e.g., where basePath is set/used) to lose or misplace the default;
update getParentDir to preserve filesystem roots and trailing-slash semantics:
if the input path already ends with a slash or backslash, return it unchanged;
otherwise compute the parent but if the computed parent is empty and the
original path starts with '/' return '/' (POSIX root), and if it matches a
Windows drive root like /^[A-Za-z]:[\\/]*$/ return the drive root with a
trailing backslash (e.g., "C:\\" or "C:\") so basePath remains a valid root;
implement these checks inside the getParentDir function referenced above.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fbb7aca9-d5d3-4816-bcc2-126ecacb2846

📥 Commits

Reviewing files that changed from the base of the PR and between 3e0710e and 504889f.

📒 Files selected for processing (1)
  • src/renderer/components/WorktreeConfigModal.tsx

- Guard getParentDir against root-level paths returning empty string
- Fix canDisable to only enable Disable button when config is persisted
- Add session.cwd to useEffect dependency array
@jSydorowicz21
Copy link
Author

Addressed feedback, should be good to go

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant