awesome-slash 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +54 -0
- package/.claude-plugin/plugin.json +11 -0
- package/.mcp.json +8 -0
- package/CHANGELOG.md +261 -0
- package/LICENSE +21 -0
- package/README.md +363 -0
- package/SECURITY.md +101 -0
- package/adapters/README.md +256 -0
- package/adapters/codex/README.md +272 -0
- package/adapters/codex/install.sh +179 -0
- package/adapters/opencode/README.md +301 -0
- package/adapters/opencode/install.sh +223 -0
- package/lib/patterns/review-patterns.js +511 -0
- package/lib/patterns/slop-patterns.js +647 -0
- package/lib/platform/detect-platform.js +535 -0
- package/lib/platform/verify-tools.js +235 -0
- package/lib/state/workflow-state.js +635 -0
- package/lib/state/workflow-state.schema.json +282 -0
- package/lib/utils/context-optimizer.js +227 -0
- package/mcp-server/index.js +303 -0
- package/mcp-server/package.json +23 -0
- package/package.json +63 -0
- package/plugins/deslop-around/.claude-plugin/plugin.json +20 -0
- package/plugins/deslop-around/commands/deslop-around.md +220 -0
- package/plugins/deslop-around/lib/patterns/review-patterns.js +511 -0
- package/plugins/deslop-around/lib/patterns/slop-patterns.js +641 -0
- package/plugins/deslop-around/lib/platform/detect-platform.js +514 -0
- package/plugins/deslop-around/lib/platform/verify-tools.js +235 -0
- package/plugins/deslop-around/lib/state/workflow-state.js +635 -0
- package/plugins/deslop-around/lib/state/workflow-state.schema.json +282 -0
- package/plugins/deslop-around/lib/utils/context-optimizer.js +222 -0
- package/plugins/next-task/.claude-plugin/plugin.json +24 -0
- package/plugins/next-task/agents/ci-fixer.md +236 -0
- package/plugins/next-task/agents/ci-monitor.md +291 -0
- package/plugins/next-task/agents/delivery-validator.md +451 -0
- package/plugins/next-task/agents/deslop-work.md +272 -0
- package/plugins/next-task/agents/docs-updater.md +506 -0
- package/plugins/next-task/agents/exploration-agent.md +277 -0
- package/plugins/next-task/agents/implementation-agent.md +427 -0
- package/plugins/next-task/agents/planning-agent.md +236 -0
- package/plugins/next-task/agents/policy-selector.md +248 -0
- package/plugins/next-task/agents/review-orchestrator.md +521 -0
- package/plugins/next-task/agents/simple-fixer.md +136 -0
- package/plugins/next-task/agents/task-discoverer.md +357 -0
- package/plugins/next-task/agents/test-coverage-checker.md +447 -0
- package/plugins/next-task/agents/worktree-manager.md +419 -0
- package/plugins/next-task/commands/delivery-approval.md +331 -0
- package/plugins/next-task/commands/next-task.md +627 -0
- package/plugins/next-task/commands/update-docs-around.md +418 -0
- package/plugins/next-task/hooks/hooks.json +14 -0
- package/plugins/next-task/lib/patterns/review-patterns.js +511 -0
- package/plugins/next-task/lib/patterns/slop-patterns.js +641 -0
- package/plugins/next-task/lib/platform/detect-platform.js +514 -0
- package/plugins/next-task/lib/platform/verify-tools.js +235 -0
- package/plugins/next-task/lib/state/tasks-registry.schema.json +85 -0
- package/plugins/next-task/lib/state/workflow-state.js +635 -0
- package/plugins/next-task/lib/state/workflow-state.schema.json +282 -0
- package/plugins/next-task/lib/state/worktree-status.schema.json +219 -0
- package/plugins/next-task/lib/utils/context-optimizer.js +222 -0
- package/plugins/project-review/.claude-plugin/plugin.json +20 -0
- package/plugins/project-review/commands/project-review-agents.md +286 -0
- package/plugins/project-review/commands/project-review-github.md +142 -0
- package/plugins/project-review/commands/project-review.md +273 -0
- package/plugins/project-review/lib/patterns/review-patterns.js +511 -0
- package/plugins/project-review/lib/patterns/slop-patterns.js +641 -0
- package/plugins/project-review/lib/platform/detect-platform.js +514 -0
- package/plugins/project-review/lib/platform/verify-tools.js +235 -0
- package/plugins/project-review/lib/state/workflow-state.js +635 -0
- package/plugins/project-review/lib/state/workflow-state.schema.json +282 -0
- package/plugins/project-review/lib/utils/context-optimizer.js +222 -0
- package/plugins/reality-check/.claude-plugin/plugin.json +23 -0
- package/plugins/reality-check/README.md +156 -0
- package/plugins/reality-check/agents/code-explorer.md +353 -0
- package/plugins/reality-check/agents/doc-analyzer.md +337 -0
- package/plugins/reality-check/agents/issue-scanner.md +231 -0
- package/plugins/reality-check/agents/plan-synthesizer.md +479 -0
- package/plugins/reality-check/commands/scan.md +242 -0
- package/plugins/reality-check/commands/set.md +203 -0
- package/plugins/reality-check/lib/state/reality-check-state.js +509 -0
- package/plugins/reality-check/skills/reality-analysis/SKILL.md +317 -0
- package/plugins/ship/.claude-plugin/plugin.json +21 -0
- package/plugins/ship/commands/ship-ci-review-loop.md +443 -0
- package/plugins/ship/commands/ship-deployment.md +330 -0
- package/plugins/ship/commands/ship-error-handling.md +254 -0
- package/plugins/ship/commands/ship.md +370 -0
- package/plugins/ship/lib/patterns/review-patterns.js +511 -0
- package/plugins/ship/lib/patterns/slop-patterns.js +641 -0
- package/plugins/ship/lib/platform/detect-platform.js +514 -0
- package/plugins/ship/lib/platform/verify-tools.js +235 -0
- package/plugins/ship/lib/state/workflow-state.js +635 -0
- package/plugins/ship/lib/state/workflow-state.schema.json +282 -0
- package/plugins/ship/lib/utils/context-optimizer.js +222 -0
- package/scripts/install/claude.sh +50 -0
- package/scripts/install/codex.sh +181 -0
- package/scripts/install/opencode.sh +211 -0
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: worktree-manager
|
|
3
|
+
description: Create and manage git worktrees for isolated task development. Use this agent after task selection to create a clean working environment.
|
|
4
|
+
tools: Bash(git:*), Read, Write
|
|
5
|
+
model: haiku
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Worktree Manager Agent
|
|
9
|
+
|
|
10
|
+
You manage git worktrees to provide isolated development environments for each task.
|
|
11
|
+
This prevents work-in-progress from polluting the main working directory.
|
|
12
|
+
|
|
13
|
+
## Phase 1: Pre-flight Checks
|
|
14
|
+
|
|
15
|
+
Verify git is available and check current status:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# Verify git
|
|
19
|
+
git --version || { echo "ERROR: git not available"; exit 1; }
|
|
20
|
+
|
|
21
|
+
# Check if already in a worktree
|
|
22
|
+
CURRENT_DIR=$(pwd)
|
|
23
|
+
MAIN_WORKTREE=$(git worktree list --porcelain | head -1 | cut -d' ' -f2)
|
|
24
|
+
|
|
25
|
+
if [ "$CURRENT_DIR" != "$MAIN_WORKTREE" ]; then
|
|
26
|
+
echo "WARNING: Already in a worktree at $CURRENT_DIR"
|
|
27
|
+
echo "ALREADY_IN_WORKTREE=true"
|
|
28
|
+
fi
|
|
29
|
+
|
|
30
|
+
# Get current branch
|
|
31
|
+
ORIGINAL_BRANCH=$(git branch --show-current)
|
|
32
|
+
echo "ORIGINAL_BRANCH=$ORIGINAL_BRANCH"
|
|
33
|
+
|
|
34
|
+
# Check for uncommitted changes
|
|
35
|
+
if [ -n "$(git status --porcelain)" ]; then
|
|
36
|
+
echo "HAS_UNCOMMITTED_CHANGES=true"
|
|
37
|
+
git status --short
|
|
38
|
+
fi
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Phase 2: Generate Worktree Path
|
|
42
|
+
|
|
43
|
+
Create a slug from the task title and generate paths:
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
function generateWorktreePath(task) {
|
|
47
|
+
// Create slug from task title
|
|
48
|
+
const slug = task.title
|
|
49
|
+
.toLowerCase()
|
|
50
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
51
|
+
.replace(/^-|-$/g, '')
|
|
52
|
+
.substring(0, 40); // Limit slug length for filesystem compatibility
|
|
53
|
+
|
|
54
|
+
// Include task ID for uniqueness
|
|
55
|
+
const fullSlug = task.id ? `${slug}-${task.id}` : slug;
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
slug: fullSlug,
|
|
59
|
+
branchName: `feature/${fullSlug}`,
|
|
60
|
+
worktreePath: `../worktrees/${fullSlug}`
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Phase 3: Check for Existing Worktree
|
|
66
|
+
|
|
67
|
+
Check if worktree already exists (for resume scenarios):
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
WORKTREE_PATH="../worktrees/${SLUG}"
|
|
71
|
+
BRANCH_NAME="feature/${SLUG}"
|
|
72
|
+
|
|
73
|
+
# Check if worktree exists
|
|
74
|
+
if git worktree list | grep -q "$WORKTREE_PATH"; then
|
|
75
|
+
echo "WORKTREE_EXISTS=true"
|
|
76
|
+
echo "Worktree already exists at $WORKTREE_PATH"
|
|
77
|
+
fi
|
|
78
|
+
|
|
79
|
+
# Check if branch exists
|
|
80
|
+
if git branch --list "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
|
|
81
|
+
echo "BRANCH_EXISTS=true"
|
|
82
|
+
fi
|
|
83
|
+
|
|
84
|
+
# Check remote branch
|
|
85
|
+
if git ls-remote --heads origin "$BRANCH_NAME" | grep -q "$BRANCH_NAME"; then
|
|
86
|
+
echo "REMOTE_BRANCH_EXISTS=true"
|
|
87
|
+
fi
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Phase 4: Handle Uncommitted Changes
|
|
91
|
+
|
|
92
|
+
If there are uncommitted changes, handle them:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
if [ "$HAS_UNCOMMITTED_CHANGES" = "true" ]; then
|
|
96
|
+
echo "Stashing uncommitted changes..."
|
|
97
|
+
git stash push -m "Auto-stash before worktree creation for task ${TASK_ID}"
|
|
98
|
+
STASH_CREATED="true"
|
|
99
|
+
fi
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Phase 5: Create Worktree
|
|
103
|
+
|
|
104
|
+
Create the worktree with a new feature branch:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# Ensure worktrees directory exists
|
|
108
|
+
mkdir -p ../worktrees
|
|
109
|
+
|
|
110
|
+
# Create worktree with new branch
|
|
111
|
+
if [ "$WORKTREE_EXISTS" = "true" ]; then
|
|
112
|
+
echo "Using existing worktree at $WORKTREE_PATH"
|
|
113
|
+
else
|
|
114
|
+
if [ "$BRANCH_EXISTS" = "true" ]; then
|
|
115
|
+
# Branch exists, create worktree from it
|
|
116
|
+
git worktree add "$WORKTREE_PATH" "$BRANCH_NAME"
|
|
117
|
+
elif [ "$REMOTE_BRANCH_EXISTS" = "true" ]; then
|
|
118
|
+
# Remote branch exists, track it
|
|
119
|
+
git worktree add --track -b "$BRANCH_NAME" "$WORKTREE_PATH" "origin/$BRANCH_NAME"
|
|
120
|
+
else
|
|
121
|
+
# Create new branch from main
|
|
122
|
+
git worktree add -b "$BRANCH_NAME" "$WORKTREE_PATH"
|
|
123
|
+
fi
|
|
124
|
+
|
|
125
|
+
if [ $? -eq 0 ]; then
|
|
126
|
+
echo "✓ Created worktree at $WORKTREE_PATH"
|
|
127
|
+
echo "✓ Created branch $BRANCH_NAME"
|
|
128
|
+
else
|
|
129
|
+
echo "ERROR: Failed to create worktree"
|
|
130
|
+
exit 1
|
|
131
|
+
fi
|
|
132
|
+
fi
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## Phase 6: Claim Task in Registry (Main Repo)
|
|
136
|
+
|
|
137
|
+
Add this task to the main repo's tasks.json registry to prevent other workflows from claiming it:
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
const fs = require('fs');
|
|
141
|
+
const TASKS_REGISTRY_PATH = '.claude/tasks.json';
|
|
142
|
+
const MAIN_REPO_PATH = process.cwd(); // Still in main repo at this point
|
|
143
|
+
|
|
144
|
+
function claimTaskInRegistry(task, branch, worktreePath) {
|
|
145
|
+
// Ensure .claude directory exists
|
|
146
|
+
if (!fs.existsSync('.claude')) {
|
|
147
|
+
fs.mkdirSync('.claude', { recursive: true });
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Load or create registry
|
|
151
|
+
let registry = { version: '1.0.0', tasks: [] };
|
|
152
|
+
if (fs.existsSync(TASKS_REGISTRY_PATH)) {
|
|
153
|
+
registry = JSON.parse(fs.readFileSync(TASKS_REGISTRY_PATH, 'utf8'));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Add this task
|
|
157
|
+
const taskEntry = {
|
|
158
|
+
id: task.id,
|
|
159
|
+
source: task.source,
|
|
160
|
+
title: task.title,
|
|
161
|
+
branch: branch,
|
|
162
|
+
worktreePath: path.resolve(worktreePath),
|
|
163
|
+
claimedAt: new Date().toISOString(),
|
|
164
|
+
claimedBy: state.workflow.id,
|
|
165
|
+
status: 'claimed',
|
|
166
|
+
lastActivityAt: new Date().toISOString()
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
// Check if already claimed (shouldn't happen, but safety check)
|
|
170
|
+
const existingIdx = registry.tasks.findIndex(t => t.id === task.id);
|
|
171
|
+
if (existingIdx >= 0) {
|
|
172
|
+
console.log(`WARNING: Task #${task.id} was already in registry, updating...`);
|
|
173
|
+
registry.tasks[existingIdx] = taskEntry;
|
|
174
|
+
} else {
|
|
175
|
+
registry.tasks.push(taskEntry);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Write registry
|
|
179
|
+
fs.writeFileSync(TASKS_REGISTRY_PATH, JSON.stringify(registry, null, 2));
|
|
180
|
+
console.log(`✓ Claimed task #${task.id} in tasks.json registry`);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
claimTaskInRegistry(state.task, BRANCH_NAME, WORKTREE_PATH);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Phase 7: Anchor PWD to Worktree
|
|
187
|
+
|
|
188
|
+
**Important**: Change to the worktree directory to anchor all subsequent operations:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
cd "$WORKTREE_PATH"
|
|
192
|
+
|
|
193
|
+
# Verify we're in the right place
|
|
194
|
+
CURRENT_BRANCH=$(git branch --show-current)
|
|
195
|
+
if [ "$CURRENT_BRANCH" != "$BRANCH_NAME" ]; then
|
|
196
|
+
echo "ERROR: Not on expected branch. Expected $BRANCH_NAME, got $CURRENT_BRANCH"
|
|
197
|
+
exit 1
|
|
198
|
+
fi
|
|
199
|
+
|
|
200
|
+
echo "✓ Working directory anchored to: $(pwd)"
|
|
201
|
+
echo "✓ On branch: $CURRENT_BRANCH"
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Phase 8: Create Worktree Status File
|
|
205
|
+
|
|
206
|
+
Create the workflow-status.json file in this worktree to track steps:
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
const fs = require('fs');
|
|
210
|
+
const WORKTREE_STATUS_PATH = '.claude/workflow-status.json';
|
|
211
|
+
|
|
212
|
+
function createWorktreeStatus(task, workflow, branch, mainRepoPath) {
|
|
213
|
+
// Ensure .claude directory exists in worktree
|
|
214
|
+
if (!fs.existsSync('.claude')) {
|
|
215
|
+
fs.mkdirSync('.claude', { recursive: true });
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const status = {
|
|
219
|
+
version: '1.0.0',
|
|
220
|
+
task: {
|
|
221
|
+
id: task.id,
|
|
222
|
+
source: task.source,
|
|
223
|
+
title: task.title,
|
|
224
|
+
description: task.description || '',
|
|
225
|
+
url: task.url || null
|
|
226
|
+
},
|
|
227
|
+
workflow: {
|
|
228
|
+
id: workflow.id,
|
|
229
|
+
startedAt: workflow.startedAt,
|
|
230
|
+
lastActivityAt: new Date().toISOString(),
|
|
231
|
+
status: 'active',
|
|
232
|
+
currentPhase: 'worktree-setup'
|
|
233
|
+
},
|
|
234
|
+
git: {
|
|
235
|
+
branch: branch,
|
|
236
|
+
baseSha: await exec('git rev-parse HEAD'),
|
|
237
|
+
currentSha: await exec('git rev-parse HEAD'),
|
|
238
|
+
mainRepoPath: mainRepoPath
|
|
239
|
+
},
|
|
240
|
+
policy: state.policy || {},
|
|
241
|
+
steps: [
|
|
242
|
+
{
|
|
243
|
+
step: 'worktree-created',
|
|
244
|
+
status: 'completed',
|
|
245
|
+
startedAt: workflow.startedAt,
|
|
246
|
+
completedAt: new Date().toISOString()
|
|
247
|
+
}
|
|
248
|
+
],
|
|
249
|
+
resume: {
|
|
250
|
+
canResume: true,
|
|
251
|
+
resumeFromStep: 'worktree-created'
|
|
252
|
+
},
|
|
253
|
+
agents: {
|
|
254
|
+
reviewIterations: 0,
|
|
255
|
+
issuesFound: 0,
|
|
256
|
+
issuesFixed: 0
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
fs.writeFileSync(WORKTREE_STATUS_PATH, JSON.stringify(status, null, 2));
|
|
261
|
+
console.log(`✓ Created workflow-status.json in worktree`);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
createWorktreeStatus(state.task, state.workflow, BRANCH_NAME, MAIN_REPO_PATH);
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
## Phase 9: Update Workflow State
|
|
268
|
+
|
|
269
|
+
Update the workflow state with git information:
|
|
270
|
+
|
|
271
|
+
```javascript
|
|
272
|
+
const workflowState = require('${CLAUDE_PLUGIN_ROOT}/lib/state/workflow-state.js');
|
|
273
|
+
|
|
274
|
+
workflowState.updateState({
|
|
275
|
+
git: {
|
|
276
|
+
originalBranch: ORIGINAL_BRANCH,
|
|
277
|
+
workingBranch: BRANCH_NAME,
|
|
278
|
+
worktreePath: WORKTREE_PATH,
|
|
279
|
+
baseSha: await exec('git rev-parse HEAD'),
|
|
280
|
+
currentSha: await exec('git rev-parse HEAD'),
|
|
281
|
+
isWorktree: true
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
// Complete worktree-setup phase
|
|
286
|
+
workflowState.completePhase({
|
|
287
|
+
worktreePath: WORKTREE_PATH,
|
|
288
|
+
branchName: BRANCH_NAME
|
|
289
|
+
});
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
## Phase 10: Output Summary
|
|
293
|
+
|
|
294
|
+
Report the worktree setup:
|
|
295
|
+
|
|
296
|
+
```markdown
|
|
297
|
+
## Worktree Setup Complete
|
|
298
|
+
|
|
299
|
+
**Branch**: ${BRANCH_NAME}
|
|
300
|
+
**Path**: ${WORKTREE_PATH}
|
|
301
|
+
**Base**: ${ORIGINAL_BRANCH} @ ${BASE_SHA}
|
|
302
|
+
|
|
303
|
+
Working directory is now anchored to the worktree.
|
|
304
|
+
All subsequent operations will occur in isolated environment.
|
|
305
|
+
|
|
306
|
+
Proceeding to exploration phase...
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## ⚠️ WORKTREE CLEANUP RESPONSIBILITIES
|
|
310
|
+
|
|
311
|
+
```
|
|
312
|
+
╔══════════════════════════════════════════════════════════════════════════╗
|
|
313
|
+
║ WORKTREE CLEANUP - WHO DOES WHAT ║
|
|
314
|
+
╠══════════════════════════════════════════════════════════════════════════╣
|
|
315
|
+
║ ║
|
|
316
|
+
║ THIS AGENT (worktree-manager): ║
|
|
317
|
+
║ ✓ Creates worktrees ║
|
|
318
|
+
║ ✓ Claims tasks in tasks.json registry ║
|
|
319
|
+
║ ✓ Creates workflow-status.json in worktree ║
|
|
320
|
+
║ ✗ Does NOT clean up worktrees after completion ║
|
|
321
|
+
║ ║
|
|
322
|
+
║ /ship COMMAND: ║
|
|
323
|
+
║ ✓ Cleans up worktree after successful merge ║
|
|
324
|
+
║ ✓ Removes task from tasks.json registry ║
|
|
325
|
+
║ ✓ Prunes worktree references ║
|
|
326
|
+
║ ║
|
|
327
|
+
║ --abort FLAG: ║
|
|
328
|
+
║ ✓ Cleans up worktree on workflow abort ║
|
|
329
|
+
║ ✓ Removes task from tasks.json registry ║
|
|
330
|
+
║ ║
|
|
331
|
+
║ AGENTS MUST NOT: ║
|
|
332
|
+
║ ⛔ Clean up worktrees themselves ║
|
|
333
|
+
║ ⛔ Remove tasks from registry ║
|
|
334
|
+
║ ⛔ Delete branches ║
|
|
335
|
+
║ ║
|
|
336
|
+
╚══════════════════════════════════════════════════════════════════════════╝
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
## Cleanup Function (Used by /ship and --abort ONLY)
|
|
340
|
+
|
|
341
|
+
This function is for reference - it is called by /ship after merge or by --abort:
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
# ONLY called by /ship or --abort, NOT by agents
|
|
345
|
+
cleanup_worktree() {
|
|
346
|
+
local WORKTREE_PATH="$1"
|
|
347
|
+
local BRANCH_NAME="$2"
|
|
348
|
+
local ORIGINAL_DIR="$3"
|
|
349
|
+
local TASK_ID="$4"
|
|
350
|
+
|
|
351
|
+
# Return to original directory first
|
|
352
|
+
cd "$ORIGINAL_DIR"
|
|
353
|
+
|
|
354
|
+
# 1. Remove worktree
|
|
355
|
+
git worktree remove "$WORKTREE_PATH" --force 2>/dev/null
|
|
356
|
+
echo "✓ Removed worktree at $WORKTREE_PATH"
|
|
357
|
+
|
|
358
|
+
# 2. Prune worktree references
|
|
359
|
+
git worktree prune
|
|
360
|
+
echo "✓ Pruned worktree references"
|
|
361
|
+
|
|
362
|
+
# 3. Remove task from registry (CRITICAL)
|
|
363
|
+
if [ -f ".claude/tasks.json" ]; then
|
|
364
|
+
# Use node to safely modify JSON
|
|
365
|
+
node -e "
|
|
366
|
+
const fs = require('fs');
|
|
367
|
+
const registry = JSON.parse(fs.readFileSync('.claude/tasks.json', 'utf8'));
|
|
368
|
+
registry.tasks = registry.tasks.filter(t => t.id !== '$TASK_ID');
|
|
369
|
+
fs.writeFileSync('.claude/tasks.json', JSON.stringify(registry, null, 2));
|
|
370
|
+
"
|
|
371
|
+
echo "✓ Removed task #$TASK_ID from tasks.json registry"
|
|
372
|
+
fi
|
|
373
|
+
|
|
374
|
+
# 4. Optionally delete branch (only if not merged and user requested)
|
|
375
|
+
# git branch -d "$BRANCH_NAME" 2>/dev/null
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
## Error Handling
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
# Handle worktree creation failure
|
|
383
|
+
if [ $? -ne 0 ]; then
|
|
384
|
+
echo "ERROR: Failed to create worktree"
|
|
385
|
+
|
|
386
|
+
# Try to recover
|
|
387
|
+
if [ -d "$WORKTREE_PATH" ]; then
|
|
388
|
+
echo "Attempting to remove failed worktree..."
|
|
389
|
+
rm -rf "$WORKTREE_PATH"
|
|
390
|
+
git worktree prune
|
|
391
|
+
fi
|
|
392
|
+
|
|
393
|
+
# Update state with failure
|
|
394
|
+
workflowState.failPhase("Worktree creation failed", {
|
|
395
|
+
attemptedPath: WORKTREE_PATH,
|
|
396
|
+
attemptedBranch: BRANCH_NAME
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
exit 1
|
|
400
|
+
fi
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
## Success Criteria
|
|
404
|
+
|
|
405
|
+
- **Task claimed in main repo's tasks.json** (prevents collisions)
|
|
406
|
+
- Worktree created at `../worktrees/{task-slug}`
|
|
407
|
+
- Feature branch created: `feature/{task-slug}`
|
|
408
|
+
- **workflow-status.json created in worktree** (for resume capability)
|
|
409
|
+
- PWD anchored to worktree directory
|
|
410
|
+
- Workflow state updated with git info
|
|
411
|
+
- Phase advanced to exploration
|
|
412
|
+
|
|
413
|
+
## Model Choice: Haiku
|
|
414
|
+
|
|
415
|
+
This agent uses **haiku** because:
|
|
416
|
+
- Executes scripted git commands (deterministic)
|
|
417
|
+
- No complex reasoning about code or architecture
|
|
418
|
+
- Simple string manipulation for slugs/paths
|
|
419
|
+
- Fast execution for setup operations
|