Skip to content

feat: improve setup command to support os specific set of commands, mirroring more how Cursor's worktree.json behaves#42

Open
sorioinc wants to merge 1 commit intojohnlindquist:mainfrom
sorioinc:feature/worktree-setup-os-support
Open

feat: improve setup command to support os specific set of commands, mirroring more how Cursor's worktree.json behaves#42
sorioinc wants to merge 1 commit intojohnlindquist:mainfrom
sorioinc:feature/worktree-setup-os-support

Conversation

@sorioinc
Copy link

@sorioinc sorioinc commented Feb 2, 2026

Summary

Enhanced the setup command to support OS-specific configuration keys (setup-worktree-unix and setup-worktree-windows) in worktrees.json. This
change aligns the CLI's behavior with Cursor's worktrees.json configuration structure, allowing for platform-specific setup scripts or
commands.

Key Changes

  • OS Detection: Added isUnix() utility to determine the current platform.
  • Enhanced Configuration Parsing: Updated WorktreeSetupData interface and parsing logic to:
    • Support setup-worktree-unix (prioritized on non-Windows systems).
    • Support setup-worktree-windows (prioritized on Windows).
    • Fallback to the existing setup-worktree key if no OS-specific key is found.
    • Support both array-of-commands and single-string-script formats for all keys.
  • Refactoring: Extracted logic into resolveSetupValue and extractCommands for better testability and reuse.
  • Testing: Added comprehensive unit tests in test/setup.test.ts covering:
    • OS detection.
    • Command extraction priority.
    • Legacy array format support.
    • Script path resolution.

Usage Example (worktrees.json)

{
   "setup-worktree-unix": ["./setup.sh"],
   "setup-worktree-windows": ["setup.bat"],
   "setup-worktree": ["npm install"]
}

Summary by CodeRabbit

  • New Features

    • Added OS-aware setup command resolution supporting Windows and Unix/Linux-specific configurations
    • Introduced secure setup script runner with user confirmation and trust-based execution options
  • Tests

    • Added comprehensive test coverage for setup utilities, including OS detection, command resolution, and configuration parsing

…irroring more how Cursor's worktree.json behaves
@coderabbitai
Copy link

coderabbitai bot commented Feb 2, 2026

📝 Walkthrough

Walkthrough

The PR adds OS-aware command resolution to setup utilities, introducing new exported functions for OS detection, value resolution, and command extraction. A new secure execution function enables interactive confirmation of setup commands. The implementation maintains backward compatibility with existing array-based inputs.

Changes

Cohort / File(s) Summary
Core setup utilities
src/utils/setup.ts
Added OS detection (isUnix), value resolution (resolveSetupValue), and command extraction (extractCommands) functions. Introduced runSetupScriptsSecure for interactive setup execution. Extended WorktreeSetupData interface with OS-specific setup fields and string value support. Refactored existing loadSetupCommands and runSetupScripts to use new extraction logic.
Test coverage
test/setup.test.ts
Comprehensive test suite validating OS detection, command resolution, script path handling, OS-specific key prioritization, and setup file loading across Unix and Windows platforms. Includes temporary filesystem operations and cross-platform mocking.

Sequence Diagram

sequenceDiagram
    actor App as Application
    participant Secure as runSetupScriptsSecure()
    participant Extract as extractCommands()
    participant OS as isUnix()
    participant FS as File System
    participant Resolve as resolveSetupValue()
    participant Execute as Command Executor

    App->>Secure: runSetupScriptsSecure(worktreePath)
    Secure->>FS: Load worktrees.json
    FS-->>Secure: Setup data (object/array)
    Secure->>Extract: extractCommands(data)
    Extract->>OS: Detect platform
    OS-->>Extract: isUnix result
    Extract->>Resolve: resolveSetupValue(value)
    Resolve->>FS: Resolve script paths
    FS-->>Resolve: Normalized paths
    Resolve-->>Extract: string[] of commands
    Extract-->>Secure: Final commands array
    Secure->>App: Display for confirmation
    App-->>Secure: User approval
    Secure->>Execute: Run commands
    Execute-->>Secure: Success/Failure
    Secure-->>App: Boolean result
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Whiskers twitch with delight,
Unix paths and Windows unite,
OS-aware, secure, and true,
Commands confirmed before they're through,
A worktree setup, fluffy and bright! 🌳

🚥 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 enhancement: adding OS-specific command support (setup-worktree-unix, setup-worktree-windows) to mirror Cursor's behavior. It aligns with the primary change across both modified files.
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 docstrings
🧪 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.

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: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/utils/setup.ts (1)

74-94: ⚠️ Potential issue | 🟡 Minor

Surface malformed setup files instead of silently falling back.
If .cursor/worktrees.json is present but invalid, it’s treated like “not found” and the fallback file may run unexpectedly. Consider warning and aborting on parse errors so config issues are visible.

🛠️ Suggested fix (apply similarly for fallback file)
-        const content = await readFile(cursorSetupPath, "utf-8");
-        const data = JSON.parse(content) as WorktreeSetupData | string[];
+        const content = await readFile(cursorSetupPath, "utf-8");
+        let data: WorktreeSetupData | string[];
+        try {
+            data = JSON.parse(content) as WorktreeSetupData | string[];
+        } catch (error: unknown) {
+            console.warn(
+                chalk.yellow(`Failed to parse setup file ${cursorSetupPath}:`),
+                error instanceof Error ? error.message : error
+            );
+            return null;
+        }
🧹 Nitpick comments (1)
test/setup.test.ts (1)

181-274: These tests don’t actually exercise file loading.
The “Setup File Loading” block writes files but then calls extractCommands on in-memory objects, so it never validates file-location priority or parsing. Consider either removing the file I/O or adding a test that calls the real loader/runner with execution mocked.

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