|
|
|
|
@@ -48,7 +48,9 @@ echo "Current branch: $BRANCH"
|
|
|
|
|
echo "Repository: $(basename "$(git rev-parse --show-toplevel)")"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Tell the user their options, then **wait for a reply**:
|
|
|
|
|
**Check the user's most recent message first.** If they already asked for a worktree, named the worktree skill, or asked for an isolated workspace in the message that invoked you, that IS the explicit ask — proceed directly to Step 3 without re-prompting.
|
|
|
|
|
|
|
|
|
|
Otherwise, tell the user their options and **wait for a reply**:
|
|
|
|
|
|
|
|
|
|
> "You're on `<branch>` in `<repo>`. I can set up an isolated worktree, or we can work directly here. What do you prefer?"
|
|
|
|
|
|
|
|
|
|
@@ -66,15 +68,13 @@ The default is always Step 4. Step 3 requires an explicit "yes, create a worktre
|
|
|
|
|
|
|
|
|
|
You have two mechanisms. Try them in this order.
|
|
|
|
|
|
|
|
|
|
### 3a. Native Worktree Tools (preferred — STOP HERE if available)
|
|
|
|
|
### 3a. Native Worktree Tools (preferred)
|
|
|
|
|
|
|
|
|
|
Check your available tools — do you have `EnterWorktree`, `WorktreeCreate`, a `/worktree` command, or a `--worktree` flag? **If YES: use it now and skip to Step 4.**
|
|
|
|
|
Do you already have a way to create a worktree? It might be a tool with a name like `EnterWorktree`, `WorktreeCreate`, a `/worktree` command, or a `--worktree` flag. If you do, use it and skip to Step 4.
|
|
|
|
|
|
|
|
|
|
Native tools handle directory placement, branch creation, and cleanup automatically. Using `git worktree add` when you have a native tool creates phantom state — your harness can't see or manage worktrees it didn't create, and cleanup becomes impossible.
|
|
|
|
|
Native tools handle directory placement, branch creation, and cleanup automatically. Using `git worktree add` when you have a native tool creates phantom state your harness can't see or manage.
|
|
|
|
|
|
|
|
|
|
**Even if `.worktrees/` already exists, even under time pressure, even if `git worktree add` feels faster — use your native tool.** There are no exceptions.
|
|
|
|
|
|
|
|
|
|
**Only proceed to Step 3b if you have confirmed you have NO native worktree/isolation tool.**
|
|
|
|
|
Only proceed to Step 3b if you have no native worktree tool available.
|
|
|
|
|
|
|
|
|
|
### 3b. Git Worktree Fallback
|
|
|
|
|
|
|
|
|
|
@@ -82,25 +82,25 @@ Native tools handle directory placement, branch creation, and cleanup automatica
|
|
|
|
|
|
|
|
|
|
#### Directory Selection
|
|
|
|
|
|
|
|
|
|
Follow this priority order:
|
|
|
|
|
Follow this priority order. Explicit user preference always beats observed filesystem state.
|
|
|
|
|
|
|
|
|
|
1. **Check existing directories:**
|
|
|
|
|
1. **Check your instructions for a declared worktree directory preference.** If the user has already specified one, use it without asking.
|
|
|
|
|
|
|
|
|
|
2. **Check for an existing project-local worktree directory:**
|
|
|
|
|
```bash
|
|
|
|
|
ls -d .worktrees 2>/dev/null # Preferred (hidden)
|
|
|
|
|
ls -d worktrees 2>/dev/null # Alternative
|
|
|
|
|
```
|
|
|
|
|
If found, use that directory. If both exist, `.worktrees` wins.
|
|
|
|
|
If found, use it. If both exist, `.worktrees` wins.
|
|
|
|
|
|
|
|
|
|
2. **Check for existing global directory:**
|
|
|
|
|
3. **Check for an existing global directory:**
|
|
|
|
|
```bash
|
|
|
|
|
project=$(basename "$(git rev-parse --show-toplevel)")
|
|
|
|
|
ls -d ~/.config/superpowers/worktrees/$project 2>/dev/null
|
|
|
|
|
```
|
|
|
|
|
If found, use it (backward compatibility with legacy global path).
|
|
|
|
|
|
|
|
|
|
3. **Check your project's agent instruction file** (CLAUDE.md, GEMINI.md, AGENTS.md, .cursorrules, or equivalent) for a worktree directory preference. If specified, use it without asking.
|
|
|
|
|
|
|
|
|
|
4. **Default to `.worktrees/`.**
|
|
|
|
|
4. **If there is no other guidance available**, default to `.worktrees/` at the project root.
|
|
|
|
|
|
|
|
|
|
#### Safety Verification (project-local directories only)
|
|
|
|
|
|
|
|
|
|
@@ -129,7 +129,7 @@ git worktree add "$path" -b "$BRANCH_NAME"
|
|
|
|
|
cd "$path"
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**Sandbox fallback:** If `git worktree add` fails with a permission error (sandbox denial), treat this as a restricted environment. Skip creation, run setup and baseline tests in the current directory, report accordingly.
|
|
|
|
|
**Sandbox fallback:** If `git worktree add` fails with a permission error (sandbox denial), tell the user the sandbox blocked worktree creation and you're working in the current directory instead. Then run setup and baseline tests in place.
|
|
|
|
|
|
|
|
|
|
## Step 4: Project Setup
|
|
|
|
|
|
|
|
|
|
@@ -199,7 +199,7 @@ Ready to implement <feature-name>
|
|
|
|
|
| Tests fail during baseline | Report failures + ask |
|
|
|
|
|
| No package.json/Cargo.toml | Skip dependency install |
|
|
|
|
|
| User gives no worktree preference | Work in place (Step 2 default) |
|
|
|
|
|
| Plan touches multiple repos | Offer worktree per repo (same Step 1→2→3 flow, matching branch names) |
|
|
|
|
|
| Plan touches multiple repos | Offer a matching worktree per repo, same branch name |
|
|
|
|
|
|
|
|
|
|
## Common Mistakes
|
|
|
|
|
|
|
|
|
|
@@ -243,7 +243,7 @@ Ready to implement <feature-name>
|
|
|
|
|
- Create worktree without verifying it's ignored (project-local)
|
|
|
|
|
- Skip baseline test verification
|
|
|
|
|
- Proceed with failing tests without asking
|
|
|
|
|
- Infer worktree consent from the task description, plan, or skill invocation — only an explicit user reply counts
|
|
|
|
|
- Infer worktree consent from the task description or plan — only an explicit user request counts
|
|
|
|
|
|
|
|
|
|
**Always:**
|
|
|
|
|
- Run Step 1 detection first
|
|
|
|
|
@@ -258,9 +258,9 @@ Ready to implement <feature-name>
|
|
|
|
|
## Integration
|
|
|
|
|
|
|
|
|
|
**Called by:**
|
|
|
|
|
- **subagent-driven-development** - Ensures isolated workspace (creates one or verifies existing)
|
|
|
|
|
- **executing-plans** - Ensures isolated workspace (creates one or verifies existing)
|
|
|
|
|
- Any skill needing isolated workspace
|
|
|
|
|
- **subagent-driven-development** - Calls this to detect the workspace and optionally set up worktree isolation on request
|
|
|
|
|
- **executing-plans** - Calls this to detect the workspace and optionally set up worktree isolation on request
|
|
|
|
|
- Any skill that may use worktree isolation
|
|
|
|
|
|
|
|
|
|
**Pairs with:**
|
|
|
|
|
- **finishing-a-development-branch** - REQUIRED for cleanup after work complete
|
|
|
|
|
|