@northbridge-security/secureai 0.1.13
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/README.md +122 -0
- package/.claude/commands/architect/clean.md +978 -0
- package/.claude/commands/architect/kiss.md +762 -0
- package/.claude/commands/architect/review.md +704 -0
- package/.claude/commands/catchup.md +90 -0
- package/.claude/commands/code.md +115 -0
- package/.claude/commands/commit.md +1218 -0
- package/.claude/commands/cover.md +1298 -0
- package/.claude/commands/fmea.md +275 -0
- package/.claude/commands/kaizen.md +312 -0
- package/.claude/commands/pr.md +503 -0
- package/.claude/commands/todo.md +99 -0
- package/.claude/commands/worktree.md +738 -0
- package/.claude/commands/wrapup.md +103 -0
- package/LICENSE +183 -0
- package/README.md +108 -0
- package/dist/cli.js +75634 -0
- package/docs/agents/devops-reviewer.md +889 -0
- package/docs/agents/kiss-simplifier.md +1088 -0
- package/docs/agents/typescript.md +8 -0
- package/docs/guides/README.md +109 -0
- package/docs/guides/agents.clean.arch.md +244 -0
- package/docs/guides/agents.clean.arch.ts.md +1314 -0
- package/docs/guides/agents.gotask.md +1037 -0
- package/docs/guides/agents.markdown.md +1209 -0
- package/docs/guides/agents.onepassword.md +285 -0
- package/docs/guides/agents.sonar.md +857 -0
- package/docs/guides/agents.tdd.md +838 -0
- package/docs/guides/agents.tdd.ts.md +1062 -0
- package/docs/guides/agents.typesript.md +1389 -0
- package/docs/guides/github-mcp.md +1075 -0
- package/package.json +130 -0
- package/packages/secureai-cli/src/cli.ts +21 -0
- package/tasks/README.md +880 -0
- package/tasks/aws.yml +64 -0
- package/tasks/bash.yml +118 -0
- package/tasks/bun.yml +738 -0
- package/tasks/claude.yml +183 -0
- package/tasks/docker.yml +420 -0
- package/tasks/docs.yml +127 -0
- package/tasks/git.yml +1336 -0
- package/tasks/gotask.yml +132 -0
- package/tasks/json.yml +77 -0
- package/tasks/markdown.yml +95 -0
- package/tasks/onepassword.yml +350 -0
- package/tasks/security.yml +102 -0
- package/tasks/sonar.yml +437 -0
- package/tasks/template.yml +74 -0
- package/tasks/vscode.yml +103 -0
- package/tasks/yaml.yml +121 -0
|
@@ -0,0 +1,738 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Manage git worktrees for experimental refactoring and architecture changes"
|
|
3
|
+
argument-hint: "[--merge|--list|--clear]"
|
|
4
|
+
allowed-tools:
|
|
5
|
+
- "Bash"
|
|
6
|
+
- "Glob"
|
|
7
|
+
- "Read"
|
|
8
|
+
- "Write"
|
|
9
|
+
- "Edit"
|
|
10
|
+
plan-mode: false
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Worktree Management Command
|
|
14
|
+
|
|
15
|
+
Manage git worktrees for isolated experimental work (refactoring, architecture changes, etc.) without affecting the main working directory.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
# Interactive mode - choose operation
|
|
21
|
+
/worktree
|
|
22
|
+
|
|
23
|
+
# Merge changes from latest active worktree
|
|
24
|
+
/worktree --merge
|
|
25
|
+
|
|
26
|
+
# List all worktrees and their purposes
|
|
27
|
+
/worktree --list
|
|
28
|
+
|
|
29
|
+
# Remove all worktrees to clean up repository
|
|
30
|
+
/worktree --clear
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## What This Command Does
|
|
34
|
+
|
|
35
|
+
**Worktrees** are isolated working directories that share the same git repository. They enable:
|
|
36
|
+
|
|
37
|
+
- Experimental refactoring without affecting main branch
|
|
38
|
+
- Architecture changes in isolation
|
|
39
|
+
- Safe testing of breaking changes
|
|
40
|
+
- Clean separation of concurrent work
|
|
41
|
+
|
|
42
|
+
**Common workflow:**
|
|
43
|
+
|
|
44
|
+
1. Agent creates worktree via subagent (e.g., `/architect:clean`)
|
|
45
|
+
2. Experimental changes happen in `.worktree/{name}-{timestamp}/`
|
|
46
|
+
3. User reviews changes in worktree
|
|
47
|
+
4. User runs `/worktree --merge` to integrate successful changes
|
|
48
|
+
5. User runs `/worktree --clear` to remove temporary worktrees
|
|
49
|
+
|
|
50
|
+
## Phase 0: Parse Arguments
|
|
51
|
+
|
|
52
|
+
Parse command-line arguments to determine operation mode.
|
|
53
|
+
|
|
54
|
+
**Argument patterns:**
|
|
55
|
+
|
|
56
|
+
- `--merge` - Merge changes from latest active worktree
|
|
57
|
+
- `--list` - List all worktrees and their purposes
|
|
58
|
+
- `--clear` - Remove all worktrees
|
|
59
|
+
- No arguments - Interactive mode (present 1, 2, 3 options)
|
|
60
|
+
|
|
61
|
+
**Implementation:**
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
# Parse arguments from user input
|
|
65
|
+
MERGE_FLAG=false
|
|
66
|
+
LIST_FLAG=false
|
|
67
|
+
CLEAR_FLAG=false
|
|
68
|
+
|
|
69
|
+
if [[ "$@" == *"--merge"* ]]; then
|
|
70
|
+
MERGE_FLAG=true
|
|
71
|
+
elif [[ "$@" == *"--list"* ]]; then
|
|
72
|
+
LIST_FLAG=true
|
|
73
|
+
elif [[ "$@" == *"--clear"* ]]; then
|
|
74
|
+
CLEAR_FLAG=true
|
|
75
|
+
fi
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Phase 1: Locate Worktrees
|
|
79
|
+
|
|
80
|
+
Find all worktrees in the `.worktree/` directory.
|
|
81
|
+
|
|
82
|
+
**Worktree directory structure:**
|
|
83
|
+
|
|
84
|
+
```text
|
|
85
|
+
.worktree/
|
|
86
|
+
âââ clean-20251122-213602/ # Clean Architecture refactoring
|
|
87
|
+
âââ installer-modules-20251122-214644/ # Module-based installer refactoring
|
|
88
|
+
âââ performance-20251123-100000/ # Performance optimization
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**Detection strategy:**
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# Find all worktree directories
|
|
95
|
+
WORKTREES=($(find .worktree -maxdepth 1 -type d -not -name '.worktree' 2>/dev/null | sort -r))
|
|
96
|
+
|
|
97
|
+
if [ ${#WORKTREES[@]} -eq 0 ]; then
|
|
98
|
+
echo "âšī¸ No worktrees found"
|
|
99
|
+
exit 0
|
|
100
|
+
fi
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
**Extract worktree metadata:**
|
|
104
|
+
|
|
105
|
+
For each worktree directory:
|
|
106
|
+
|
|
107
|
+
1. Parse name and timestamp from directory name (e.g., `clean-20251122-213602`)
|
|
108
|
+
2. Check for `PROGRESS.md` or similar documentation files
|
|
109
|
+
3. Count source files (exclude documentation)
|
|
110
|
+
4. Determine last modification time
|
|
111
|
+
|
|
112
|
+
## Phase 2: Interactive Mode (No Arguments)
|
|
113
|
+
|
|
114
|
+
When no arguments are provided, present options to the user.
|
|
115
|
+
|
|
116
|
+
**Present menu:**
|
|
117
|
+
|
|
118
|
+
```text
|
|
119
|
+
Worktree Management
|
|
120
|
+
|
|
121
|
+
Found 2 active worktrees:
|
|
122
|
+
1. installer-modules-20251122-214644 (most recent)
|
|
123
|
+
2. clean-20251122-213602
|
|
124
|
+
|
|
125
|
+
What would you like to do?
|
|
126
|
+
|
|
127
|
+
1. Merge latest worktree (installer-modules-20251122-214644)
|
|
128
|
+
2. List all worktrees with details
|
|
129
|
+
3. Clear all worktrees
|
|
130
|
+
|
|
131
|
+
Enter choice (1-3):
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
**User selection:**
|
|
135
|
+
|
|
136
|
+
- Choice 1: Set `MERGE_FLAG=true`, proceed to Phase 3
|
|
137
|
+
- Choice 2: Set `LIST_FLAG=true`, proceed to Phase 4
|
|
138
|
+
- Choice 3: Set `CLEAR_FLAG=true`, proceed to Phase 5
|
|
139
|
+
|
|
140
|
+
## Phase 3: Merge Latest Worktree (`--merge`)
|
|
141
|
+
|
|
142
|
+
Merge changes from the most recent worktree into the main working directory.
|
|
143
|
+
|
|
144
|
+
### Step 1: Identify Latest Worktree
|
|
145
|
+
|
|
146
|
+
**Strategy:** Use directory modification time or parse timestamp from directory name.
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
# Get latest worktree by timestamp in directory name
|
|
150
|
+
LATEST_WORKTREE=$(find .worktree -maxdepth 1 -type d -not -name '.worktree' | sort -r | head -1)
|
|
151
|
+
|
|
152
|
+
if [ -z "$LATEST_WORKTREE" ]; then
|
|
153
|
+
echo "â No worktrees found to merge"
|
|
154
|
+
exit 1
|
|
155
|
+
fi
|
|
156
|
+
|
|
157
|
+
echo "âšī¸ Merging from: $LATEST_WORKTREE"
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Step 2: Identify Source Files to Merge
|
|
161
|
+
|
|
162
|
+
**Include:**
|
|
163
|
+
|
|
164
|
+
- `src/**/*.ts` - Source code files
|
|
165
|
+
- `src/**/*.js` - JavaScript files
|
|
166
|
+
- `tests/**/*.test.ts` - Test files
|
|
167
|
+
- `tasks/**/*.yml` - Task definitions
|
|
168
|
+
- New directories created in worktree
|
|
169
|
+
|
|
170
|
+
**Exclude (do NOT copy):**
|
|
171
|
+
|
|
172
|
+
- `PROGRESS.md` - Worktree-specific documentation
|
|
173
|
+
- `PATTERN-GUIDE.md` - Temporary reference files
|
|
174
|
+
- `IMPLEMENTATION-SUMMARY.md` - Worktree-specific notes
|
|
175
|
+
- `REFACTORING-PLAN.md` - Planning documents
|
|
176
|
+
- `.clean-*.md` - Analysis reports
|
|
177
|
+
- `*.local.md` - Local documentation files
|
|
178
|
+
- `.logs/**` - Log files
|
|
179
|
+
- `.worktree/**` - Nested worktrees
|
|
180
|
+
- `node_modules/**` - Dependencies
|
|
181
|
+
|
|
182
|
+
**Detection:**
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
# Find source files in worktree (exclude documentation and temporary files)
|
|
186
|
+
cd "$LATEST_WORKTREE"
|
|
187
|
+
|
|
188
|
+
# Find new or modified source directories
|
|
189
|
+
SRC_DIRS=($(find src -type d -mindepth 1 -maxdepth 2 2>/dev/null | grep -v '.logs' | grep -v '.worktree'))
|
|
190
|
+
|
|
191
|
+
# Find new or modified TypeScript source files
|
|
192
|
+
SRC_FILES=($(find src tests tasks -name "*.ts" -o -name "*.js" -o -name "*.yml" 2>/dev/null | grep -v '.test.ts'))
|
|
193
|
+
|
|
194
|
+
cd - > /dev/null
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Step 3: Copy Source Files to Main Branch
|
|
198
|
+
|
|
199
|
+
**For new directories:**
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
for DIR in "${SRC_DIRS[@]}"; do
|
|
203
|
+
if [ ! -d "$DIR" ]; then
|
|
204
|
+
echo "đ Creating new directory: $DIR"
|
|
205
|
+
mkdir -p "$DIR"
|
|
206
|
+
fi
|
|
207
|
+
done
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**For source files:**
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
# Copy source files from worktree to main branch
|
|
214
|
+
for FILE in "${SRC_FILES[@]}"; do
|
|
215
|
+
SOURCE="$LATEST_WORKTREE/$FILE"
|
|
216
|
+
DEST="$FILE"
|
|
217
|
+
|
|
218
|
+
if [ -f "$SOURCE" ]; then
|
|
219
|
+
# Create parent directory if needed
|
|
220
|
+
mkdir -p "$(dirname "$DEST")"
|
|
221
|
+
|
|
222
|
+
# Copy file
|
|
223
|
+
cp "$SOURCE" "$DEST"
|
|
224
|
+
echo "â Copied: $FILE"
|
|
225
|
+
fi
|
|
226
|
+
done
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Step 4: Handle File Replacements
|
|
230
|
+
|
|
231
|
+
**Strategy from recent session:**
|
|
232
|
+
|
|
233
|
+
- `src/installers/claude.ts` was replaced with a simple re-export (694 lines â 20 lines)
|
|
234
|
+
- New directories `src/installers/base/` and `src/installers/claude/` were added
|
|
235
|
+
- Backward compatibility maintained via re-exports
|
|
236
|
+
|
|
237
|
+
**Detect replaced files:**
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
# Compare file sizes to detect major changes
|
|
241
|
+
for FILE in "${SRC_FILES[@]}"; do
|
|
242
|
+
SOURCE="$LATEST_WORKTREE/$FILE"
|
|
243
|
+
DEST="$FILE"
|
|
244
|
+
|
|
245
|
+
if [ -f "$SOURCE" ] && [ -f "$DEST" ]; then
|
|
246
|
+
SOURCE_SIZE=$(wc -l < "$SOURCE")
|
|
247
|
+
DEST_SIZE=$(wc -l < "$DEST")
|
|
248
|
+
|
|
249
|
+
DIFF=$((DEST_SIZE - SOURCE_SIZE))
|
|
250
|
+
|
|
251
|
+
if [ ${DIFF#-} -gt 100 ]; then
|
|
252
|
+
echo "â ī¸ Significant change: $FILE ($DEST_SIZE â $SOURCE_SIZE lines)"
|
|
253
|
+
fi
|
|
254
|
+
fi
|
|
255
|
+
done
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Step 5: Show Git Status
|
|
259
|
+
|
|
260
|
+
**Display changes:**
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
echo ""
|
|
264
|
+
echo "Git status after merge:"
|
|
265
|
+
git status --short
|
|
266
|
+
|
|
267
|
+
echo ""
|
|
268
|
+
echo "Summary:"
|
|
269
|
+
git status --short | wc -l | xargs echo " Modified/new files:"
|
|
270
|
+
git diff --cached --stat 2>/dev/null || echo " (no staged changes)"
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Suggest next steps:**
|
|
274
|
+
|
|
275
|
+
```text
|
|
276
|
+
Next steps:
|
|
277
|
+
1. Review changes: git diff
|
|
278
|
+
2. Run tests: bun test
|
|
279
|
+
3. Commit changes: git add . && git commit -m "refactor: merge worktree changes"
|
|
280
|
+
4. Clean up worktree: /worktree --clear
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
## Phase 4: List Worktrees (`--list`)
|
|
284
|
+
|
|
285
|
+
Display all worktrees with their purposes and metadata.
|
|
286
|
+
|
|
287
|
+
### Step 1: Parse Worktree Information
|
|
288
|
+
|
|
289
|
+
For each worktree:
|
|
290
|
+
|
|
291
|
+
1. **Name and timestamp**: Parse from directory name (e.g., `installer-modules-20251122-214644`)
|
|
292
|
+
2. **Purpose**: Read from `PROGRESS.md`, first heading, or infer from name
|
|
293
|
+
3. **File count**: Count source files (exclude documentation)
|
|
294
|
+
4. **Last modified**: Get directory modification time
|
|
295
|
+
5. **Size**: Calculate total size of source files
|
|
296
|
+
|
|
297
|
+
**Implementation:**
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
for WORKTREE in "${WORKTREES[@]}"; do
|
|
301
|
+
BASENAME=$(basename "$WORKTREE")
|
|
302
|
+
|
|
303
|
+
# Parse timestamp from name (YYYYMMDD-HHMMSS)
|
|
304
|
+
if [[ "$BASENAME" =~ ([0-9]{8})-([0-9]{6}) ]]; then
|
|
305
|
+
DATE="${BASH_REMATCH[1]}"
|
|
306
|
+
TIME="${BASH_REMATCH[2]}"
|
|
307
|
+
TIMESTAMP="${DATE:0:4}-${DATE:4:2}-${DATE:6:2} ${TIME:0:2}:${TIME:2:2}:${TIME:4:2}"
|
|
308
|
+
fi
|
|
309
|
+
|
|
310
|
+
# Extract purpose from directory name or PROGRESS.md
|
|
311
|
+
if [ -f "$WORKTREE/PROGRESS.md" ]; then
|
|
312
|
+
PURPOSE=$(head -1 "$WORKTREE/PROGRESS.md" | sed 's/^# //')
|
|
313
|
+
else
|
|
314
|
+
# Infer from directory name
|
|
315
|
+
PURPOSE=$(echo "$BASENAME" | sed 's/-[0-9]*-[0-9]*$//' | sed 's/-/ /g' | sed 's/\b\(.\)/\u\1/g')
|
|
316
|
+
fi
|
|
317
|
+
|
|
318
|
+
# Count source files
|
|
319
|
+
FILE_COUNT=$(find "$WORKTREE/src" -name "*.ts" -o -name "*.js" 2>/dev/null | wc -l)
|
|
320
|
+
|
|
321
|
+
# Get size
|
|
322
|
+
SIZE=$(du -sh "$WORKTREE" | cut -f1)
|
|
323
|
+
|
|
324
|
+
echo "đ $BASENAME"
|
|
325
|
+
echo " Purpose: $PURPOSE"
|
|
326
|
+
echo " Created: $TIMESTAMP"
|
|
327
|
+
echo " Files: $FILE_COUNT source files"
|
|
328
|
+
echo " Size: $SIZE"
|
|
329
|
+
echo ""
|
|
330
|
+
done
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### Step 2: Identify Latest Worktree
|
|
334
|
+
|
|
335
|
+
**Highlight most recent:**
|
|
336
|
+
|
|
337
|
+
```bash
|
|
338
|
+
LATEST=$(find .worktree -maxdepth 1 -type d -not -name '.worktree' | sort -r | head -1)
|
|
339
|
+
LATEST_BASENAME=$(basename "$LATEST")
|
|
340
|
+
|
|
341
|
+
echo "Latest worktree: $LATEST_BASENAME (ready for --merge)"
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Step 3: Show Integration Status
|
|
345
|
+
|
|
346
|
+
**Check if worktree has been merged:**
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
# Compare git status - if worktree files exist in main branch, it's been merged
|
|
350
|
+
for WORKTREE in "${WORKTREES[@]}"; do
|
|
351
|
+
BASENAME=$(basename "$WORKTREE")
|
|
352
|
+
|
|
353
|
+
# Check for marker files from this worktree
|
|
354
|
+
MARKER_FILE=$(find "$WORKTREE/src" -name "*.ts" -type f | head -1)
|
|
355
|
+
|
|
356
|
+
if [ -n "$MARKER_FILE" ]; then
|
|
357
|
+
REL_PATH=$(echo "$MARKER_FILE" | sed "s|$WORKTREE/||")
|
|
358
|
+
|
|
359
|
+
if [ -f "$REL_PATH" ]; then
|
|
360
|
+
# Compare file contents
|
|
361
|
+
if diff -q "$MARKER_FILE" "$REL_PATH" > /dev/null 2>&1; then
|
|
362
|
+
echo "â Merged: $BASENAME"
|
|
363
|
+
else
|
|
364
|
+
echo "â ī¸ Partial merge: $BASENAME (files differ)"
|
|
365
|
+
fi
|
|
366
|
+
else
|
|
367
|
+
echo "â Not merged: $BASENAME"
|
|
368
|
+
fi
|
|
369
|
+
fi
|
|
370
|
+
done
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## Phase 5: Clear Worktrees (`--clear`)
|
|
374
|
+
|
|
375
|
+
Remove all worktrees to clean up the repository.
|
|
376
|
+
|
|
377
|
+
### Step 1: List Worktrees to Remove
|
|
378
|
+
|
|
379
|
+
**Show what will be deleted:**
|
|
380
|
+
|
|
381
|
+
```bash
|
|
382
|
+
echo "The following worktrees will be removed:"
|
|
383
|
+
echo ""
|
|
384
|
+
|
|
385
|
+
for WORKTREE in "${WORKTREES[@]}"; do
|
|
386
|
+
BASENAME=$(basename "$WORKTREE")
|
|
387
|
+
SIZE=$(du -sh "$WORKTREE" | cut -f1)
|
|
388
|
+
echo " - $BASENAME ($SIZE)"
|
|
389
|
+
done
|
|
390
|
+
|
|
391
|
+
echo ""
|
|
392
|
+
TOTAL_SIZE=$(du -sh .worktree | cut -f1)
|
|
393
|
+
echo "Total size: $TOTAL_SIZE"
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
### Step 2: Confirm with User
|
|
397
|
+
|
|
398
|
+
**Safety check:**
|
|
399
|
+
|
|
400
|
+
```text
|
|
401
|
+
â ī¸ WARNING: This will permanently delete all worktrees.
|
|
402
|
+
|
|
403
|
+
Are you sure you want to continue? (y/N):
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
**User confirmation required:**
|
|
407
|
+
|
|
408
|
+
- `y` or `yes` - Proceed with deletion
|
|
409
|
+
- Any other input - Cancel operation
|
|
410
|
+
|
|
411
|
+
### Step 3: Remove Worktrees
|
|
412
|
+
|
|
413
|
+
**Delete directories:**
|
|
414
|
+
|
|
415
|
+
```bash
|
|
416
|
+
for WORKTREE in "${WORKTREES[@]}"; do
|
|
417
|
+
BASENAME=$(basename "$WORKTREE")
|
|
418
|
+
|
|
419
|
+
echo "Removing: $BASENAME"
|
|
420
|
+
rm -rf "$WORKTREE"
|
|
421
|
+
|
|
422
|
+
if [ ! -d "$WORKTREE" ]; then
|
|
423
|
+
echo "â Deleted: $BASENAME"
|
|
424
|
+
else
|
|
425
|
+
echo "â Failed to delete: $BASENAME"
|
|
426
|
+
fi
|
|
427
|
+
done
|
|
428
|
+
```
|
|
429
|
+
|
|
430
|
+
**Clean up parent directory:**
|
|
431
|
+
|
|
432
|
+
```bash
|
|
433
|
+
# Remove .worktree directory if empty
|
|
434
|
+
if [ -d ".worktree" ] && [ -z "$(ls -A .worktree)" ]; then
|
|
435
|
+
rmdir .worktree
|
|
436
|
+
echo "â Removed empty .worktree directory"
|
|
437
|
+
fi
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### Step 4: Verify Cleanup
|
|
441
|
+
|
|
442
|
+
**Check remaining worktrees:**
|
|
443
|
+
|
|
444
|
+
```bash
|
|
445
|
+
REMAINING=$(find .worktree -maxdepth 1 -type d -not -name '.worktree' 2>/dev/null | wc -l)
|
|
446
|
+
|
|
447
|
+
if [ "$REMAINING" -eq 0 ]; then
|
|
448
|
+
echo ""
|
|
449
|
+
echo "â
All worktrees removed successfully"
|
|
450
|
+
else
|
|
451
|
+
echo ""
|
|
452
|
+
echo "â ī¸ $REMAINING worktree(s) remain (may require manual removal)"
|
|
453
|
+
fi
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
## Security Considerations
|
|
457
|
+
|
|
458
|
+
**File copy safety:**
|
|
459
|
+
|
|
460
|
+
- Only copy source files from `src/`, `tests/`, `tasks/` directories
|
|
461
|
+
- Exclude documentation files (\*.md) to prevent overwriting project docs
|
|
462
|
+
- Exclude local files (\*.local.md) which may contain sensitive data
|
|
463
|
+
- Exclude log files (.logs/\*\*) which may contain credentials
|
|
464
|
+
|
|
465
|
+
**Git safety:**
|
|
466
|
+
|
|
467
|
+
- Never force push from worktrees
|
|
468
|
+
- Require user review before merging changes
|
|
469
|
+
- Show git diff before committing merged changes
|
|
470
|
+
- Preserve git history (no history rewriting)
|
|
471
|
+
|
|
472
|
+
**Cleanup safety:**
|
|
473
|
+
|
|
474
|
+
- Require explicit confirmation before deleting worktrees
|
|
475
|
+
- Show total size before deletion
|
|
476
|
+
- Verify deletion completed successfully
|
|
477
|
+
- Handle nested worktrees safely (should not exist)
|
|
478
|
+
|
|
479
|
+
## Common Use Cases
|
|
480
|
+
|
|
481
|
+
### Use Case 1: Clean Architecture Refactoring
|
|
482
|
+
|
|
483
|
+
**Workflow:**
|
|
484
|
+
|
|
485
|
+
1. User runs `/architect:clean src/installers/claude.ts`
|
|
486
|
+
2. Subagent creates worktree at `.worktree/clean-{timestamp}/`
|
|
487
|
+
3. Refactoring happens in worktree (interfaces, system files, etc.)
|
|
488
|
+
4. User reviews changes in worktree
|
|
489
|
+
5. User runs `/worktree --merge` to integrate changes
|
|
490
|
+
6. User commits merged changes
|
|
491
|
+
7. User runs `/worktree --clear` to clean up
|
|
492
|
+
|
|
493
|
+
**Files merged:**
|
|
494
|
+
|
|
495
|
+
- `src/installers/base/` (new directory)
|
|
496
|
+
- `src/installers/claude/` (new directory)
|
|
497
|
+
- `src/installers/claude.ts` (replaced with re-export)
|
|
498
|
+
|
|
499
|
+
**Files excluded:**
|
|
500
|
+
|
|
501
|
+
- `PROGRESS.md` (worktree-specific documentation)
|
|
502
|
+
- `.clean-claude-installer.md` (analysis report)
|
|
503
|
+
- `PATTERN-GUIDE.md` (temporary reference)
|
|
504
|
+
|
|
505
|
+
### Use Case 2: Multiple Concurrent Experiments
|
|
506
|
+
|
|
507
|
+
**Workflow:**
|
|
508
|
+
|
|
509
|
+
1. User runs `/architect:clean file1.ts` â worktree A
|
|
510
|
+
2. User runs `/architect:clean file2.ts` â worktree B
|
|
511
|
+
3. User runs `/worktree --list` to see both worktrees
|
|
512
|
+
4. User selects which worktree to merge first
|
|
513
|
+
5. User runs `/worktree --merge` for worktree A
|
|
514
|
+
6. User commits changes from worktree A
|
|
515
|
+
7. User runs `/worktree --merge` for worktree B (now latest)
|
|
516
|
+
8. User commits changes from worktree B
|
|
517
|
+
9. User runs `/worktree --clear` to remove both
|
|
518
|
+
|
|
519
|
+
### Use Case 3: Abandoned Experiment Cleanup
|
|
520
|
+
|
|
521
|
+
**Workflow:**
|
|
522
|
+
|
|
523
|
+
1. User runs `/architect:clean` â creates worktree
|
|
524
|
+
2. Refactoring doesn't work as expected
|
|
525
|
+
3. User decides not to merge changes
|
|
526
|
+
4. User runs `/worktree --clear` to remove worktree
|
|
527
|
+
5. Main branch unaffected
|
|
528
|
+
|
|
529
|
+
## Integration with Other Commands
|
|
530
|
+
|
|
531
|
+
**With `/architect:clean`:**
|
|
532
|
+
|
|
533
|
+
- `/architect:clean` creates worktrees automatically
|
|
534
|
+
- User reviews changes in worktree
|
|
535
|
+
- `/worktree --merge` integrates successful refactorings
|
|
536
|
+
|
|
537
|
+
**With `/commit`:**
|
|
538
|
+
|
|
539
|
+
- After `/worktree --merge`, use `/commit` to create conventional commit
|
|
540
|
+
- Commit message should reference worktree purpose (e.g., "refactor: clean architecture for installers")
|
|
541
|
+
|
|
542
|
+
**With `/cover`:**
|
|
543
|
+
|
|
544
|
+
- After merging, run `/cover --compare` to verify coverage improved
|
|
545
|
+
- Compare before/after coverage reports
|
|
546
|
+
|
|
547
|
+
**With Task Master:**
|
|
548
|
+
|
|
549
|
+
- Mark task as complete after successful worktree merge
|
|
550
|
+
- Document refactoring in task notes
|
|
551
|
+
|
|
552
|
+
## Troubleshooting
|
|
553
|
+
|
|
554
|
+
### Merge Conflicts
|
|
555
|
+
|
|
556
|
+
**Issue:** Files in worktree conflict with changes in main branch.
|
|
557
|
+
|
|
558
|
+
**Solution:**
|
|
559
|
+
|
|
560
|
+
1. Run `/worktree --list` to see which files changed
|
|
561
|
+
2. Manually resolve conflicts using git
|
|
562
|
+
3. Commit resolved changes
|
|
563
|
+
|
|
564
|
+
### Incomplete Merge
|
|
565
|
+
|
|
566
|
+
**Issue:** Some files from worktree not copied to main branch.
|
|
567
|
+
|
|
568
|
+
**Solution:**
|
|
569
|
+
|
|
570
|
+
1. Check `.gitignore` - ensure source files not ignored
|
|
571
|
+
2. Verify file permissions
|
|
572
|
+
3. Manually copy missing files
|
|
573
|
+
4. Re-run `/worktree --merge` after fixing issues
|
|
574
|
+
|
|
575
|
+
### Worktree Not Found
|
|
576
|
+
|
|
577
|
+
**Issue:** `/worktree --merge` says "No worktrees found".
|
|
578
|
+
|
|
579
|
+
**Solution:**
|
|
580
|
+
|
|
581
|
+
1. Check `.worktree/` directory exists
|
|
582
|
+
2. Verify worktree subdirectories present
|
|
583
|
+
3. Use `/worktree --list` to see available worktrees
|
|
584
|
+
|
|
585
|
+
### Cannot Delete Worktree
|
|
586
|
+
|
|
587
|
+
**Issue:** `/worktree --clear` fails to remove worktree.
|
|
588
|
+
|
|
589
|
+
**Solution:**
|
|
590
|
+
|
|
591
|
+
1. Check file permissions
|
|
592
|
+
2. Close any open files in worktree (IDE, terminal)
|
|
593
|
+
3. Manually remove: `rm -rf .worktree/{name}`
|
|
594
|
+
4. Check for git locks
|
|
595
|
+
|
|
596
|
+
## Examples
|
|
597
|
+
|
|
598
|
+
**Example 1: Merge latest worktree**
|
|
599
|
+
|
|
600
|
+
```bash
|
|
601
|
+
# User runs command
|
|
602
|
+
/worktree --merge
|
|
603
|
+
|
|
604
|
+
# Output:
|
|
605
|
+
âšī¸ Merging from: .worktree/installer-modules-20251122-214644
|
|
606
|
+
đ Creating new directory: src/installers/base
|
|
607
|
+
đ Creating new directory: src/installers/claude
|
|
608
|
+
â Copied: src/installers/base/interfaces.ts
|
|
609
|
+
â Copied: src/installers/base/command.system.ts
|
|
610
|
+
â Copied: src/installers/base/filesystem.system.ts
|
|
611
|
+
â Copied: src/installers/base/index.ts
|
|
612
|
+
â Copied: src/installers/claude/types.ts
|
|
613
|
+
â Copied: src/installers/claude/config.ts
|
|
614
|
+
â Copied: src/installers/claude/installer.ts
|
|
615
|
+
â Copied: src/installers/claude/index.ts
|
|
616
|
+
â ī¸ Significant change: src/installers/claude.ts (694 â 20 lines)
|
|
617
|
+
|
|
618
|
+
Git status after merge:
|
|
619
|
+
M src/installers/claude.ts
|
|
620
|
+
?? src/installers/base/
|
|
621
|
+
?? src/installers/claude/
|
|
622
|
+
|
|
623
|
+
Summary:
|
|
624
|
+
Modified/new files: 3
|
|
625
|
+
|
|
626
|
+
Next steps:
|
|
627
|
+
1. Review changes: git diff
|
|
628
|
+
2. Run tests: bun test
|
|
629
|
+
3. Commit changes: git add . && git commit -m "refactor: merge worktree changes"
|
|
630
|
+
4. Clean up worktree: /worktree --clear
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
**Example 2: List worktrees**
|
|
634
|
+
|
|
635
|
+
```bash
|
|
636
|
+
# User runs command
|
|
637
|
+
/worktree --list
|
|
638
|
+
|
|
639
|
+
# Output:
|
|
640
|
+
đ installer-modules-20251122-214644
|
|
641
|
+
Purpose: Installer Modules
|
|
642
|
+
Created: 2025-11-22 21:46:44
|
|
643
|
+
Files: 12 source files
|
|
644
|
+
Size: 156K
|
|
645
|
+
|
|
646
|
+
đ clean-20251122-213602
|
|
647
|
+
Purpose: Clean Architecture Refactoring
|
|
648
|
+
Created: 2025-11-22 21:36:02
|
|
649
|
+
Files: 8 source files
|
|
650
|
+
Size: 98K
|
|
651
|
+
|
|
652
|
+
Latest worktree: installer-modules-20251122-214644 (ready for --merge)
|
|
653
|
+
|
|
654
|
+
â Merged: installer-modules-20251122-214644
|
|
655
|
+
â Not merged: clean-20251122-213602
|
|
656
|
+
```
|
|
657
|
+
|
|
658
|
+
**Example 3: Clear all worktrees**
|
|
659
|
+
|
|
660
|
+
```bash
|
|
661
|
+
# User runs command
|
|
662
|
+
/worktree --clear
|
|
663
|
+
|
|
664
|
+
# Output:
|
|
665
|
+
The following worktrees will be removed:
|
|
666
|
+
|
|
667
|
+
- installer-modules-20251122-214644 (156K)
|
|
668
|
+
- clean-20251122-213602 (98K)
|
|
669
|
+
|
|
670
|
+
Total size: 254K
|
|
671
|
+
|
|
672
|
+
â ī¸ WARNING: This will permanently delete all worktrees.
|
|
673
|
+
|
|
674
|
+
Are you sure you want to continue? (y/N): y
|
|
675
|
+
|
|
676
|
+
Removing: installer-modules-20251122-214644
|
|
677
|
+
â Deleted: installer-modules-20251122-214644
|
|
678
|
+
Removing: clean-20251122-213602
|
|
679
|
+
â Deleted: clean-20251122-213602
|
|
680
|
+
â Removed empty .worktree directory
|
|
681
|
+
|
|
682
|
+
â
All worktrees removed successfully
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
**Example 4: Interactive mode**
|
|
686
|
+
|
|
687
|
+
```bash
|
|
688
|
+
# User runs command
|
|
689
|
+
/worktree
|
|
690
|
+
|
|
691
|
+
# Output:
|
|
692
|
+
Worktree Management
|
|
693
|
+
|
|
694
|
+
Found 2 active worktrees:
|
|
695
|
+
1. installer-modules-20251122-214644 (most recent)
|
|
696
|
+
2. clean-20251122-213602
|
|
697
|
+
|
|
698
|
+
What would you like to do?
|
|
699
|
+
|
|
700
|
+
1. Merge latest worktree (installer-modules-20251122-214644)
|
|
701
|
+
2. List all worktrees with details
|
|
702
|
+
3. Clear all worktrees
|
|
703
|
+
|
|
704
|
+
Enter choice (1-3): 1
|
|
705
|
+
|
|
706
|
+
# Proceeds to merge workflow...
|
|
707
|
+
```
|
|
708
|
+
|
|
709
|
+
## Implementation Notes
|
|
710
|
+
|
|
711
|
+
**Performance:**
|
|
712
|
+
|
|
713
|
+
- Use `find` with `-maxdepth` to avoid deep directory traversal
|
|
714
|
+
- Cache worktree list in Phase 1, reuse in other phases
|
|
715
|
+
- Use `diff -q` for fast file comparison
|
|
716
|
+
- Avoid reading large files unnecessarily
|
|
717
|
+
|
|
718
|
+
**Compatibility:**
|
|
719
|
+
|
|
720
|
+
- Works with git 2.30+
|
|
721
|
+
- Compatible with macOS, Linux, Windows (Git Bash)
|
|
722
|
+
- No external dependencies beyond git and standard Unix tools
|
|
723
|
+
|
|
724
|
+
**Testing:**
|
|
725
|
+
|
|
726
|
+
- Test with multiple worktrees
|
|
727
|
+
- Test with empty worktree directory
|
|
728
|
+
- Test with nested directories
|
|
729
|
+
- Test with special characters in filenames
|
|
730
|
+
- Test merge conflicts
|
|
731
|
+
- Test deletion failures
|
|
732
|
+
|
|
733
|
+
## Related Documentation
|
|
734
|
+
|
|
735
|
+
- [Clean Architecture Guide](../guides/agents.clean.arch.md)
|
|
736
|
+
- [GoTask Usage Guide](../guides/agents.gotask.md)
|
|
737
|
+
- [Commit Command](/commit)
|
|
738
|
+
- [Coverage Command](/cover)
|