feat: improve setup command to support os specific set of commands, mirroring more how Cursor's worktree.json behaves#42
Conversation
…irroring more how Cursor's worktree.json behaves
📝 WalkthroughWalkthroughThe 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
Sequence DiagramsequenceDiagram
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
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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 | 🟡 MinorSurface malformed setup files instead of silently falling back.
If.cursor/worktrees.jsonis 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 callsextractCommandson 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.
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
Usage Example (
worktrees.json){ "setup-worktree-unix": ["./setup.sh"], "setup-worktree-windows": ["setup.bat"], "setup-worktree": ["npm install"] }Summary by CodeRabbit
New Features
Tests