the-grid-cc 1.7.12 → 1.7.14

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.
@@ -0,0 +1,567 @@
1
+ # /grid:branch - Branch Management
2
+
3
+ ---
4
+ name: grid:branch
5
+ description: Manage git branches for Grid sessions
6
+ allowed-tools:
7
+ - Bash
8
+ - Read
9
+ - Write
10
+ - Task
11
+ - AskUserQuestion
12
+ ---
13
+
14
+ Manage feature branches for Grid work sessions. Handles branch creation, switching, PR creation, and cleanup.
15
+
16
+ ## USAGE
17
+
18
+ ```
19
+ /grid:branch # Show current branch status
20
+ /grid:branch create {name} # Create new feature branch
21
+ /grid:branch switch {name} # Switch to existing branch
22
+ /grid:branch pr # Create PR for current branch
23
+ /grid:branch cleanup # Delete merged branches
24
+ /grid:branch list # List all grid branches
25
+ ```
26
+
27
+ ## SUBCOMMANDS
28
+
29
+ ### status (default)
30
+
31
+ Show current git branch state:
32
+
33
+ ```bash
34
+ # Get branch info
35
+ BRANCH=$(git branch --show-current)
36
+ COMMITS_AHEAD=$(git rev-list --count main..HEAD 2>/dev/null || echo "0")
37
+ COMMITS_BEHIND=$(git rev-list --count HEAD..main 2>/dev/null || echo "0")
38
+ UNCOMMITTED=$(git status --porcelain | wc -l | tr -d ' ')
39
+
40
+ # Check remote tracking
41
+ REMOTE=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || echo "none")
42
+ ```
43
+
44
+ **Output:**
45
+
46
+ ```
47
+ BRANCH STATUS
48
+ =============
49
+
50
+ Current: grid/react-todo-app
51
+ Remote: origin/grid/react-todo-app
52
+
53
+ main
54
+ |
55
+ +--- 5 commits behind
56
+ |
57
+ +--- 12 commits ahead ---> [grid/react-todo-app]
58
+ |
59
+ (3 uncommitted changes)
60
+
61
+ Actions available:
62
+ /grid:branch pr Create pull request
63
+ /grid:branch sync Pull latest from main
64
+
65
+ End of Line.
66
+ ```
67
+
68
+ ### create
69
+
70
+ Create a new feature branch:
71
+
72
+ ```
73
+ /grid:branch create {name}
74
+ ```
75
+
76
+ **Process:**
77
+
78
+ ```bash
79
+ # Validate name
80
+ NAME=$1
81
+ if [[ ! "$NAME" =~ ^[a-z0-9-]+$ ]]; then
82
+ echo "ERROR: Branch name must be lowercase alphanumeric with hyphens only"
83
+ exit 1
84
+ fi
85
+
86
+ # Add prefix if not present
87
+ if [[ ! "$NAME" =~ ^grid/ ]]; then
88
+ NAME="grid/$NAME"
89
+ fi
90
+
91
+ # Check if exists
92
+ if git show-ref --verify --quiet "refs/heads/$NAME"; then
93
+ echo "ERROR: Branch '$NAME' already exists"
94
+ exit 1
95
+ fi
96
+
97
+ # Ensure we're on latest main
98
+ git fetch origin main
99
+ git checkout main
100
+ git pull origin main
101
+
102
+ # Create branch
103
+ git checkout -b "$NAME"
104
+
105
+ echo "Created and switched to: $NAME"
106
+ ```
107
+
108
+ **Output:**
109
+
110
+ ```
111
+ BRANCH CREATED
112
+ ==============
113
+
114
+ Branch: grid/add-dark-mode
115
+ From: main (commit abc1234)
116
+
117
+ Ready for work. Commits will be tracked.
118
+
119
+ Start building with /grid or /grid:quick.
120
+
121
+ End of Line.
122
+ ```
123
+
124
+ ### switch
125
+
126
+ Switch to an existing branch:
127
+
128
+ ```
129
+ /grid:branch switch {name}
130
+ ```
131
+
132
+ **Process:**
133
+
134
+ ```bash
135
+ NAME=$1
136
+
137
+ # Add prefix if searching
138
+ if [[ ! "$NAME" =~ ^grid/ ]] && ! git show-ref --verify --quiet "refs/heads/$NAME"; then
139
+ NAME="grid/$NAME"
140
+ fi
141
+
142
+ # Check uncommitted changes
143
+ if [[ -n $(git status --porcelain) ]]; then
144
+ echo "WARNING: Uncommitted changes detected"
145
+ echo "Options:"
146
+ echo " 1. Stash changes and switch"
147
+ echo " 2. Commit changes first"
148
+ echo " 3. Cancel"
149
+ # Prompt user
150
+ fi
151
+
152
+ git checkout "$NAME"
153
+ ```
154
+
155
+ **Output:**
156
+
157
+ ```
158
+ BRANCH SWITCHED
159
+ ===============
160
+
161
+ Now on: grid/fix-login-bug
162
+ Commits: 3 ahead of main
163
+ Status: Clean working tree
164
+
165
+ Resume work or view with /grid:status.
166
+
167
+ End of Line.
168
+ ```
169
+
170
+ ### pr
171
+
172
+ Create a pull request for the current branch:
173
+
174
+ ```
175
+ /grid:branch pr
176
+ /grid:branch pr --title "Custom title"
177
+ /grid:branch pr --draft
178
+ ```
179
+
180
+ **Pre-flight checks:**
181
+
182
+ ```bash
183
+ # Must be on feature branch
184
+ BRANCH=$(git branch --show-current)
185
+ if [[ "$BRANCH" =~ ^(main|master|production)$ ]]; then
186
+ echo "ERROR: Cannot create PR from protected branch"
187
+ exit 1
188
+ fi
189
+
190
+ # Must have commits
191
+ COMMITS=$(git rev-list --count main..HEAD)
192
+ if [ "$COMMITS" -eq 0 ]; then
193
+ echo "ERROR: No commits to create PR from"
194
+ exit 1
195
+ fi
196
+
197
+ # Must be pushed
198
+ if ! git rev-parse --abbrev-ref --symbolic-full-name @{u} &>/dev/null; then
199
+ echo "Pushing branch to origin..."
200
+ git push -u origin "$BRANCH"
201
+ fi
202
+
203
+ # Check for existing PR
204
+ EXISTING=$(gh pr view --json number 2>/dev/null | jq -r '.number // empty')
205
+ if [ -n "$EXISTING" ]; then
206
+ echo "PR #$EXISTING already exists for this branch"
207
+ echo "View at: $(gh pr view --json url -q '.url')"
208
+ exit 0
209
+ fi
210
+ ```
211
+
212
+ **Generate PR content:**
213
+
214
+ ```bash
215
+ # Gather commit info
216
+ COMMITS=$(git log main..HEAD --pretty=format:"- %s" | head -20)
217
+ FILES_CHANGED=$(git diff --stat main..HEAD | tail -1)
218
+
219
+ # Check for Grid metadata
220
+ CLUSTER=""
221
+ if [ -f ".grid/STATE.md" ]; then
222
+ CLUSTER=$(grep "^## CLUSTER:" .grid/STATE.md | cut -d: -f2 | xargs)
223
+ fi
224
+
225
+ # Check for summaries
226
+ SUMMARIES=""
227
+ for f in .grid/phases/**/SUMMARY.md .grid/quick/*/SUMMARY.md; do
228
+ if [ -f "$f" ]; then
229
+ SUMMARIES="$SUMMARIES\n$(cat $f)"
230
+ fi
231
+ done 2>/dev/null
232
+ ```
233
+
234
+ **Create PR:**
235
+
236
+ ```bash
237
+ gh pr create \
238
+ --title "$TITLE" \
239
+ --body "$(cat <<EOF
240
+ ## Summary
241
+ $DESCRIPTION
242
+
243
+ ## Changes
244
+ $COMMITS
245
+
246
+ ## Stats
247
+ $FILES_CHANGED
248
+
249
+ ## Grid Session
250
+ - **Cluster:** $CLUSTER
251
+ - **Commits:** $(git rev-list --count main..HEAD)
252
+
253
+ ## Test Plan
254
+ - [ ] Code review
255
+ - [ ] Functionality verified
256
+ - [ ] No regressions
257
+
258
+ ---
259
+ *Created via /grid:branch pr*
260
+ EOF
261
+ )" \
262
+ --base main
263
+ ```
264
+
265
+ **Output:**
266
+
267
+ ```
268
+ PULL REQUEST CREATED
269
+ ====================
270
+
271
+ PR #42: feat: add user authentication
272
+ URL: https://github.com/user/repo/pull/42
273
+
274
+ Branch: grid/add-auth -> main
275
+ Commits: 8
276
+ Files changed: 12
277
+
278
+ Status: Open (ready for review)
279
+
280
+ View PR: gh pr view 42
281
+ Check status: gh pr checks 42
282
+
283
+ End of Line.
284
+ ```
285
+
286
+ ### cleanup
287
+
288
+ Delete branches that have been merged:
289
+
290
+ ```
291
+ /grid:branch cleanup
292
+ /grid:branch cleanup --dry-run
293
+ /grid:branch cleanup --force
294
+ ```
295
+
296
+ **Process:**
297
+
298
+ ```bash
299
+ # Get merged branches
300
+ MERGED=$(git branch --merged main | grep "grid/" | grep -v "^\*")
301
+
302
+ if [ -z "$MERGED" ]; then
303
+ echo "No merged grid branches to clean up."
304
+ exit 0
305
+ fi
306
+
307
+ echo "Merged branches to delete:"
308
+ echo "$MERGED"
309
+
310
+ if [ "$1" == "--dry-run" ]; then
311
+ echo "(Dry run - no changes made)"
312
+ exit 0
313
+ fi
314
+
315
+ # Confirm
316
+ read -p "Delete these branches? [y/N] " confirm
317
+ if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
318
+ echo "Cancelled."
319
+ exit 0
320
+ fi
321
+
322
+ # Delete local
323
+ echo "$MERGED" | xargs git branch -d
324
+
325
+ # Delete remote
326
+ for branch in $MERGED; do
327
+ git push origin --delete "$branch" 2>/dev/null || true
328
+ done
329
+ ```
330
+
331
+ **Output:**
332
+
333
+ ```
334
+ BRANCH CLEANUP
335
+ ==============
336
+
337
+ Deleted local branches:
338
+ - grid/add-auth (was abc1234)
339
+ - grid/fix-login (was def5678)
340
+
341
+ Deleted remote branches:
342
+ - origin/grid/add-auth
343
+ - origin/grid/fix-login
344
+
345
+ Remaining grid branches: 2
346
+ - grid/react-todo-app (current)
347
+ - grid/feature-x
348
+
349
+ End of Line.
350
+ ```
351
+
352
+ ### list
353
+
354
+ List all Grid-managed branches:
355
+
356
+ ```
357
+ /grid:branch list
358
+ /grid:branch list --all # Include remote
359
+ /grid:branch list --stale # Only stale (>30 days)
360
+ ```
361
+
362
+ **Output:**
363
+
364
+ ```
365
+ GRID BRANCHES
366
+ =============
367
+
368
+ Local:
369
+ * grid/react-todo-app (current, 12 commits ahead)
370
+ grid/feature-x (3 commits ahead)
371
+ grid/old-experiment (stale: 45 days)
372
+
373
+ Remote only:
374
+ origin/grid/abandoned (stale: 60 days)
375
+
376
+ Legend:
377
+ * = current
378
+ (stale) = no commits in 30+ days
379
+
380
+ Actions:
381
+ /grid:branch switch {name}
382
+ /grid:branch cleanup --stale
383
+
384
+ End of Line.
385
+ ```
386
+
387
+ ### sync
388
+
389
+ Sync current branch with main:
390
+
391
+ ```
392
+ /grid:branch sync
393
+ /grid:branch sync --rebase # Rebase instead of merge
394
+ ```
395
+
396
+ **Process:**
397
+
398
+ ```bash
399
+ # Fetch latest
400
+ git fetch origin main
401
+
402
+ # Check for conflicts
403
+ CONFLICTS=$(git merge-tree $(git merge-base HEAD origin/main) HEAD origin/main | grep -c "^<<<<<<<" || echo "0")
404
+
405
+ if [ "$CONFLICTS" -gt 0 ]; then
406
+ echo "WARNING: Merge will have conflicts"
407
+ echo "Files with conflicts: $CONFLICTS"
408
+ read -p "Continue? [y/N] " confirm
409
+ fi
410
+
411
+ # Merge or rebase
412
+ if [ "$1" == "--rebase" ]; then
413
+ git rebase origin/main
414
+ else
415
+ git merge origin/main --no-edit
416
+ fi
417
+ ```
418
+
419
+ **Output:**
420
+
421
+ ```
422
+ BRANCH SYNCED
423
+ =============
424
+
425
+ Merged main into grid/react-todo-app
426
+
427
+ Before: 5 commits behind main
428
+ After: Up to date with main
429
+
430
+ Merge commit: ghi7890
431
+
432
+ Ready to continue work.
433
+
434
+ End of Line.
435
+ ```
436
+
437
+ ## AUTONOMOUS MODE
438
+
439
+ When Grid is in AUTOPILOT mode, branch operations happen automatically:
440
+
441
+ ### Session Start
442
+ 1. Check if on protected branch
443
+ 2. If yes, create `grid/{cluster-slug}` branch
444
+ 3. If existing grid branch matches cluster, switch to it
445
+
446
+ ### After Each Wave
447
+ 1. Check for uncommitted changes (shouldn't be any with atomic commits)
448
+ 2. Push to remote if auto_push enabled
449
+
450
+ ### Session Complete
451
+ 1. Push final state
452
+ 2. Offer PR creation
453
+ 3. Report branch status
454
+
455
+ ## CONFIGURATION
456
+
457
+ Set preferences in `.grid/config.json`:
458
+
459
+ ```json
460
+ {
461
+ "git": {
462
+ "auto_branch": true,
463
+ "branch_prefix": "grid/",
464
+ "auto_push": "wave",
465
+ "auto_pr": false,
466
+ "protected_branches": ["main", "master", "production"],
467
+ "default_base": "main",
468
+ "sync_strategy": "merge"
469
+ }
470
+ }
471
+ ```
472
+
473
+ ## ERROR HANDLING
474
+
475
+ ### No Git Repository
476
+
477
+ ```
478
+ ERROR: Not a git repository
479
+
480
+ Initialize with:
481
+ git init
482
+ git remote add origin {url}
483
+
484
+ Then retry /grid:branch.
485
+ ```
486
+
487
+ ### No Remote
488
+
489
+ ```
490
+ WARNING: No remote configured
491
+
492
+ Branch operations will be local only.
493
+ Add remote with:
494
+ git remote add origin {url}
495
+ ```
496
+
497
+ ### Uncommitted Changes
498
+
499
+ ```
500
+ WARNING: Uncommitted changes detected
501
+
502
+ Options:
503
+ 1. Stash: git stash
504
+ 2. Commit: /grid:quick "commit message"
505
+ 3. Discard: git checkout -- . (DANGER)
506
+
507
+ Choose action before switching branches.
508
+ ```
509
+
510
+ ### Merge Conflicts
511
+
512
+ ```
513
+ CONFLICT: Merge conflicts detected
514
+
515
+ Conflicting files:
516
+ - src/components/Chat.tsx
517
+ - src/lib/api.ts
518
+
519
+ Options:
520
+ 1. Resolve manually and continue
521
+ 2. Abort merge: git merge --abort
522
+ 3. Accept ours: git checkout --ours {file}
523
+ 4. Accept theirs: git checkout --theirs {file}
524
+
525
+ After resolving: git add {files} && git commit
526
+ ```
527
+
528
+ ## INTEGRATION
529
+
530
+ ### With /grid
531
+
532
+ ```
533
+ /grid "build a chat app"
534
+ -> Auto-creates grid/chat-app branch
535
+ -> All commits go to this branch
536
+ -> On completion, offers PR
537
+ ```
538
+
539
+ ### With /grid:quick
540
+
541
+ ```
542
+ /grid:quick "fix login bug"
543
+ -> Checks current branch
544
+ -> If on main, creates grid/fix-login-bug
545
+ -> Commits to feature branch
546
+ ```
547
+
548
+ ### With /grid:status
549
+
550
+ ```
551
+ /grid:status
552
+ -> Shows branch info in status output
553
+ -> Includes commits ahead/behind
554
+ -> Shows remote tracking status
555
+ ```
556
+
557
+ ## RULES
558
+
559
+ 1. **Never commit to protected branches** - Always create feature branch
560
+ 2. **Atomic commits** - One logical change per commit
561
+ 3. **Descriptive names** - Branch names describe the work
562
+ 4. **Clean before switch** - Handle uncommitted changes
563
+ 5. **Push after waves** - Keep remote in sync
564
+ 6. **Clean up merged** - Delete branches after PR merge
565
+ 7. **Sync regularly** - Keep branches up to date with main
566
+
567
+ End of Line.