@uniswap/ai-toolkit-nx-claude 0.5.29 → 0.5.30-next.1

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.
Files changed (87) hide show
  1. package/dist/cli-generator.cjs +28 -59
  2. package/dist/packages/ai-toolkit-nx-claude/src/cli-generator.d.ts +8 -10
  3. package/dist/packages/ai-toolkit-nx-claude/src/cli-generator.d.ts.map +1 -1
  4. package/dist/packages/ai-toolkit-nx-claude/src/index.d.ts +0 -1
  5. package/dist/packages/ai-toolkit-nx-claude/src/index.d.ts.map +1 -1
  6. package/generators.json +0 -15
  7. package/package.json +4 -35
  8. package/dist/content/agents/agnostic/CLAUDE.md +0 -282
  9. package/dist/content/agents/agnostic/agent-capability-analyst.md +0 -575
  10. package/dist/content/agents/agnostic/agent-optimizer.md +0 -396
  11. package/dist/content/agents/agnostic/agent-orchestrator.md +0 -475
  12. package/dist/content/agents/agnostic/cicd-agent.md +0 -301
  13. package/dist/content/agents/agnostic/claude-agent-discovery.md +0 -304
  14. package/dist/content/agents/agnostic/claude-docs-fact-checker.md +0 -435
  15. package/dist/content/agents/agnostic/claude-docs-initializer.md +0 -782
  16. package/dist/content/agents/agnostic/claude-docs-manager.md +0 -595
  17. package/dist/content/agents/agnostic/code-explainer.md +0 -269
  18. package/dist/content/agents/agnostic/code-generator.md +0 -785
  19. package/dist/content/agents/agnostic/commit-message-generator.md +0 -101
  20. package/dist/content/agents/agnostic/context-loader.md +0 -432
  21. package/dist/content/agents/agnostic/debug-assistant.md +0 -321
  22. package/dist/content/agents/agnostic/doc-writer.md +0 -536
  23. package/dist/content/agents/agnostic/feedback-collector.md +0 -165
  24. package/dist/content/agents/agnostic/infrastructure-agent.md +0 -406
  25. package/dist/content/agents/agnostic/migration-assistant.md +0 -489
  26. package/dist/content/agents/agnostic/pattern-learner.md +0 -481
  27. package/dist/content/agents/agnostic/performance-analyzer.md +0 -528
  28. package/dist/content/agents/agnostic/plan-reviewer.md +0 -173
  29. package/dist/content/agents/agnostic/planner.md +0 -235
  30. package/dist/content/agents/agnostic/pr-creator.md +0 -498
  31. package/dist/content/agents/agnostic/pr-reviewer.md +0 -142
  32. package/dist/content/agents/agnostic/prompt-engineer.md +0 -541
  33. package/dist/content/agents/agnostic/refactorer.md +0 -311
  34. package/dist/content/agents/agnostic/researcher.md +0 -349
  35. package/dist/content/agents/agnostic/security-analyzer.md +0 -1087
  36. package/dist/content/agents/agnostic/stack-splitter.md +0 -642
  37. package/dist/content/agents/agnostic/style-enforcer.md +0 -568
  38. package/dist/content/agents/agnostic/test-runner.md +0 -481
  39. package/dist/content/agents/agnostic/test-writer.md +0 -292
  40. package/dist/content/commands/agnostic/CLAUDE.md +0 -207
  41. package/dist/content/commands/agnostic/address-pr-issues.md +0 -205
  42. package/dist/content/commands/agnostic/auto-spec.md +0 -386
  43. package/dist/content/commands/agnostic/claude-docs.md +0 -409
  44. package/dist/content/commands/agnostic/claude-init-plus.md +0 -439
  45. package/dist/content/commands/agnostic/create-pr.md +0 -79
  46. package/dist/content/commands/agnostic/daily-standup.md +0 -185
  47. package/dist/content/commands/agnostic/deploy.md +0 -441
  48. package/dist/content/commands/agnostic/execute-plan.md +0 -167
  49. package/dist/content/commands/agnostic/explain-file.md +0 -303
  50. package/dist/content/commands/agnostic/explore.md +0 -82
  51. package/dist/content/commands/agnostic/fix-bug.md +0 -273
  52. package/dist/content/commands/agnostic/gen-tests.md +0 -185
  53. package/dist/content/commands/agnostic/generate-commit-message.md +0 -92
  54. package/dist/content/commands/agnostic/git-worktree-orchestrator.md +0 -647
  55. package/dist/content/commands/agnostic/implement-spec.md +0 -270
  56. package/dist/content/commands/agnostic/monitor.md +0 -581
  57. package/dist/content/commands/agnostic/perf-analyze.md +0 -214
  58. package/dist/content/commands/agnostic/plan.md +0 -453
  59. package/dist/content/commands/agnostic/refactor.md +0 -315
  60. package/dist/content/commands/agnostic/refine-linear-task.md +0 -575
  61. package/dist/content/commands/agnostic/research.md +0 -49
  62. package/dist/content/commands/agnostic/review-code.md +0 -321
  63. package/dist/content/commands/agnostic/review-plan.md +0 -109
  64. package/dist/content/commands/agnostic/review-pr.md +0 -393
  65. package/dist/content/commands/agnostic/split-stack.md +0 -705
  66. package/dist/content/commands/agnostic/update-claude-md.md +0 -401
  67. package/dist/content/commands/agnostic/work-through-pr-comments.md +0 -873
  68. package/dist/generators/add-agent/CLAUDE.md +0 -130
  69. package/dist/generators/add-agent/files/__name__.md.template +0 -37
  70. package/dist/generators/add-agent/generator.cjs +0 -640
  71. package/dist/generators/add-agent/schema.json +0 -59
  72. package/dist/generators/add-command/CLAUDE.md +0 -131
  73. package/dist/generators/add-command/files/__name__.md.template +0 -46
  74. package/dist/generators/add-command/generator.cjs +0 -643
  75. package/dist/generators/add-command/schema.json +0 -50
  76. package/dist/generators/files/src/index.ts.template +0 -1
  77. package/dist/generators/init/CLAUDE.md +0 -520
  78. package/dist/generators/init/generator.cjs +0 -3304
  79. package/dist/generators/init/schema.json +0 -180
  80. package/dist/packages/ai-toolkit-nx-claude/src/generators/add-agent/generator.d.ts +0 -5
  81. package/dist/packages/ai-toolkit-nx-claude/src/generators/add-agent/generator.d.ts.map +0 -1
  82. package/dist/packages/ai-toolkit-nx-claude/src/generators/add-command/generator.d.ts +0 -5
  83. package/dist/packages/ai-toolkit-nx-claude/src/generators/add-command/generator.d.ts.map +0 -1
  84. package/dist/packages/ai-toolkit-nx-claude/src/generators/init/generator.d.ts +0 -5
  85. package/dist/packages/ai-toolkit-nx-claude/src/generators/init/generator.d.ts.map +0 -1
  86. package/dist/packages/ai-toolkit-nx-claude/src/utils/auto-update-utils.d.ts +0 -30
  87. package/dist/packages/ai-toolkit-nx-claude/src/utils/auto-update-utils.d.ts.map +0 -1
@@ -1,705 +0,0 @@
1
- ---
2
- name: split-stack
3
- description: Automatically split a monolithic branch with many changes into a logical, reviewable stack of PRs using semantic analysis and Graphite.
4
- argument-hint: [base-branch]
5
- allowed-tools: Bash(git rev-parse:*), Bash(git log:*), Bash(git diff:*), Bash(git status:*), Bash(git check-ref-format:*), Bash(git ls-files:*), Bash(git rev-list:*), Bash(git fetch:*), Bash(npx nx:*), Bash(which:*), Read(*), Grep(*), Glob(*), AskUserQuestion(*), Task(subagent_type:stack-splitter), mcp__graphite__run_gt_cmd(*), mcp__graphite__learn_gt(*), mcp__nx-mcp__nx_project_details(*)
6
- ---
7
-
8
- # Split Stack
9
-
10
- Automatically split a monolithic branch with many changes into a logical, reviewable stack of PRs using semantic analysis and Graphite (gt).
11
-
12
- ## Usage
13
-
14
- ```bash
15
- /split-stack # Split current branch from main
16
- /split-stack develop # Split current branch from develop
17
- ```
18
-
19
- ## Prerequisites
20
-
21
- Before using this command, ensure you have:
22
-
23
- - **Graphite CLI** installed: `npm install -g @withgraphite/graphite-cli@latest`
24
- - **Repository initialized** with Graphite: `gt repo init`
25
- - **Clean working directory**: No uncommitted changes (`git status` should be clean)
26
- - **Feature branch** with 3+ commits to split
27
- - **Git worktree support** (Git 2.5+)
28
-
29
- To verify your setup:
30
-
31
- ```bash
32
- gt --version # Should show 1.0.0 or higher
33
- git status # Should show "nothing to commit, working tree clean"
34
- ```
35
-
36
- ## Overview
37
-
38
- When you've built many features/changes in a single branch (common during experimentation), this command helps you break it into a logical, reviewable stack of PRs automatically.
39
-
40
- **How it works:**
41
-
42
- 1. **Analyze Changes**: Examines all commits and file changes since the branch diverged
43
- 2. **Semantic Grouping**: Groups related changes by functionality, not just files
44
- 3. **Dependency Analysis**: Uses Nx project graph to understand dependencies
45
- 4. **Plan Generation**: Creates a logical split plan optimized for reviewability
46
- 5. **User Approval**: Presents the plan and waits for your approval/modifications
47
- 6. **Execute Splits**: Uses `gt split` to create the stack
48
-
49
- ## Workflow
50
-
51
- ### Step 1: Detect Current State
52
-
53
- First, understand the current branch and its relationship to the base branch:
54
-
55
- ```bash
56
- # Validate branch name format and security
57
- validate_branch_name() {
58
- local branch="$1"
59
-
60
- # Check for valid git ref format
61
- if ! git check-ref-format "refs/heads/$branch" 2>/dev/null; then
62
- echo "❌ Invalid branch name format: $branch"
63
- exit 1
64
- fi
65
-
66
- # Additional check for shell metacharacters (security)
67
- if [[ "$branch" =~ [;\|\&\$\`\(\)\<\>] ]]; then
68
- echo "❌ Branch name contains invalid characters: $branch"
69
- exit 1
70
- fi
71
-
72
- # Verify branch actually exists
73
- if ! git rev-parse --verify "refs/heads/$branch" >/dev/null 2>&1; then
74
- echo "❌ Branch does not exist: $branch"
75
- exit 1
76
- fi
77
- }
78
-
79
- # Get current branch
80
- CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
81
-
82
- # Determine base branch (default: main)
83
- BASE_BRANCH=${1:-main}
84
-
85
- # Validate both branches
86
- validate_branch_name "$CURRENT_BRANCH"
87
- validate_branch_name "$BASE_BRANCH"
88
-
89
- # Ensure we're on a feature branch
90
- if [[ "$CURRENT_BRANCH" == "$BASE_BRANCH" ]] || [[ "$CURRENT_BRANCH" == "main" ]] || [[ "$CURRENT_BRANCH" == "master" ]]; then
91
- echo "❌ Cannot split stack from main/master branch"
92
- echo "Please check out a feature branch first"
93
- exit 1
94
- fi
95
-
96
- echo "📊 Analyzing branch: $CURRENT_BRANCH"
97
- echo "📍 Base branch: $BASE_BRANCH"
98
- ```
99
-
100
- ### Step 2: Analyze All Changes
101
-
102
- Gather comprehensive information about the changes:
103
-
104
- ```bash
105
- # Get all commits since divergence
106
- git log --oneline "$BASE_BRANCH..$CURRENT_BRANCH"
107
-
108
- # Get full diff since divergence
109
- git diff "$BASE_BRANCH...$CURRENT_BRANCH" --stat
110
-
111
- # Get list of all changed files with change types
112
- git diff "$BASE_BRANCH...$CURRENT_BRANCH" --name-status
113
-
114
- # Get detailed diff for semantic analysis
115
- git diff "$BASE_BRANCH...$CURRENT_BRANCH"
116
- ```
117
-
118
- **Key analysis points:**
119
-
120
- - Total number of commits
121
- - Total lines changed
122
- - Files modified by directory/package
123
- - Types of changes (A=added, M=modified, D=deleted, R=renamed)
124
-
125
- ### Step 3: Semantic Analysis with Stack Splitter Agent
126
-
127
- Use the specialized `stack-splitter` agent to analyze changes semantically:
128
-
129
- ```typescript
130
- const analysisResult = await Task({
131
- subagent_type: 'stack-splitter',
132
- description: 'Analyze branch changes semantically',
133
- prompt: `
134
- Analyze the changes in branch "${CURRENT_BRANCH}" since it diverged from "${BASE_BRANCH}".
135
-
136
- Current branch: ${CURRENT_BRANCH}
137
- Base branch: ${BASE_BRANCH}
138
-
139
- Commits:
140
- ${commits}
141
-
142
- File changes:
143
- ${fileChanges}
144
-
145
- Full diff:
146
- ${fullDiff}
147
-
148
- Your task:
149
- 1. Semantically group changes into logical units (features, bug fixes, refactors, etc.)
150
- 2. Consider Nx project dependencies and structure
151
- 3. Identify clear boundaries between different functional areas
152
- 4. Optimize for reviewability - each PR should tell a coherent story
153
- 5. Ensure dependencies are ordered correctly (foundational changes first)
154
-
155
- Provide a structured split plan with:
156
- - PR title and description for each split
157
- - List of commits/files to include in each PR
158
- - Rationale for the grouping
159
- - Dependencies between PRs in the stack
160
- - Estimated reviewability score (1-10) for each PR
161
- `,
162
- });
163
- ```
164
-
165
- ### Step 4: Present the Split Plan
166
-
167
- Display the proposed split plan to the user:
168
-
169
- ```markdown
170
- ## 📋 Proposed Stack Split Plan
171
-
172
- **Current Branch:** `feature/big-changes`
173
- **Base Branch:** `main`
174
- **Total Commits:** 15
175
- **Total Files Changed:** 42
176
- **Total Lines:** +1,234 -567
177
-
178
- ---
179
-
180
- ### Stack Structure (bottom to top)
181
-
182
- #### PR #1: `feat: add authentication types and interfaces`
183
-
184
- **Commits:** 3 commits (abc123f, def456a, ghi789b)
185
- **Files:** 5 files (+123 -12)
186
-
187
- - `packages/auth/src/types.ts`
188
- - `packages/auth/src/interfaces/auth.interface.ts`
189
- - `packages/auth/src/interfaces/user.interface.ts`
190
- - `packages/auth/src/constants.ts`
191
- - `packages/auth/README.md`
192
-
193
- **Rationale:** Foundational types and interfaces that other changes depend on. No implementation logic yet, making it easy to review.
194
-
195
- **Dependencies:** None (base of stack)
196
- **Reviewability Score:** 9/10
197
-
198
- ---
199
-
200
- #### PR #2: `feat: implement JWT authentication service`
201
-
202
- **Commits:** 5 commits (jkl012c, mno345d, pqr678e, stu901f, vwx234g)
203
- **Files:** 12 files (+456 -89)
204
-
205
- - `packages/auth/src/services/jwt.service.ts`
206
- - `packages/auth/src/services/jwt.service.spec.ts`
207
- - `packages/auth/src/guards/jwt.guard.ts`
208
- - `packages/auth/src/guards/jwt.guard.spec.ts`
209
- - ... (8 more files)
210
-
211
- **Rationale:** Core authentication implementation. Builds on types from PR #1. Includes tests for easier review.
212
-
213
- **Dependencies:** PR #1
214
- **Reviewability Score:** 7/10
215
-
216
- ---
217
-
218
- #### PR #3: `feat: add authentication UI components`
219
-
220
- **Commits:** 4 commits (yza567h, bcd890i, efg123j, hij456k)
221
- **Files:** 15 files (+456 -234)
222
-
223
- - `packages/web/src/components/LoginForm.tsx`
224
- - `packages/web/src/components/SignupForm.tsx`
225
- - `packages/web/src/hooks/useAuth.ts`
226
- - ... (12 more files)
227
-
228
- **Rationale:** Frontend components that use the auth service. Can be reviewed independently once service is approved.
229
-
230
- **Dependencies:** PR #2
231
- **Reviewability Score:** 8/10
232
-
233
- ---
234
-
235
- #### PR #4: `feat: integrate auth with API routes`
236
-
237
- **Commits:** 3 commits (klm789l, nop012m, qrs345n)
238
- **Files:** 10 files (+199 -12)
239
-
240
- - `packages/api/src/routes/auth.routes.ts`
241
- - `packages/api/src/middleware/auth.middleware.ts`
242
- - ... (8 more files)
243
-
244
- **Rationale:** Ties everything together. Smallest PR at the top of the stack.
245
-
246
- **Dependencies:** PR #2, PR #3
247
- **Reviewability Score:** 8/10
248
-
249
- ---
250
-
251
- ### Summary
252
-
253
- - **Total PRs:** 4
254
- - **Average PR size:** ~250 lines
255
- - **Stack depth:** 4 (linear dependency chain)
256
- - **Estimated review time per PR:** 15-30 minutes
257
-
258
- Each PR is focused, testable, and tells a clear story. The stack builds logically from foundation (types) → implementation (service) → UI → integration.
259
- ```
260
-
261
- ### Step 5: Get User Approval
262
-
263
- Ask the user if they approve the plan or want modifications:
264
-
265
- ```typescript
266
- const userDecision = await AskUserQuestion({
267
- questions: [
268
- {
269
- question: 'How would you like to proceed with this split plan?',
270
- header: 'Action',
271
- multiSelect: false,
272
- options: [
273
- {
274
- label: 'Approve and Execute',
275
- description: 'This plan looks good - execute the splits now',
276
- },
277
- {
278
- label: 'Modify Plan',
279
- description: 'I want to adjust the grouping or split differently',
280
- },
281
- {
282
- label: 'Review Manually',
283
- description: 'Show me how to use gt split manually with this plan',
284
- },
285
- {
286
- label: 'Cancel',
287
- description: 'Cancel the operation',
288
- },
289
- ],
290
- },
291
- ],
292
- });
293
- ```
294
-
295
- ### Step 6: Execute Splits with Graphite
296
-
297
- If approved, execute the splits using `gt split`:
298
-
299
- ```bash
300
- # Graphite split workflow
301
- # Note: gt split is interactive, so we'll guide the user through it
302
-
303
- echo "🔄 Executing stack split..."
304
- echo ""
305
- echo "I'll now use 'gt split' to create the stack."
306
- echo "This will involve:"
307
- echo "1. Identifying commit boundaries for each PR"
308
- echo "2. Creating intermediate branches"
309
- echo "3. Submitting the stack to Graphite"
310
- echo ""
311
-
312
- # For each PR in the plan (starting from the bottom of the stack):
313
-
314
- ## PR #1: Foundational types
315
- echo "📦 Creating PR #1: feat: add authentication types and interfaces"
316
- echo "Commits: abc123f, def456a, ghi789b"
317
-
318
- # Use gt split to create the first PR with secure commit message
319
- # Create temporary file for commit message (prevents injection)
320
- COMMIT_MSG_FILE=$(mktemp)
321
- trap "rm -f $COMMIT_MSG_FILE" EXIT
322
-
323
- cat > "$COMMIT_MSG_FILE" <<'EOF'
324
- feat: add authentication types and interfaces
325
-
326
- Add foundational types and interfaces for authentication system:
327
- - User types and interfaces
328
- - Auth token types
329
- - Constants for auth configuration
330
-
331
- This provides the type foundation that the auth service will build upon.
332
- EOF
333
-
334
- # Use file instead of -m flag for security
335
- gt split -F "$COMMIT_MSG_FILE"
336
-
337
- ## PR #2: JWT service implementation
338
- echo "📦 Creating PR #2: feat: implement JWT authentication service"
339
- # Continue with remaining commits...
340
- ```
341
-
342
- **Important Notes about `gt split`:**
343
-
344
- - `gt split` is interactive - you'll be prompted to select commits
345
- - It creates a new branch at the specified commit
346
- - Automatically restacks dependent branches
347
- - Each split becomes a separate PR in the stack
348
-
349
- ### Alternative: Manual Split Instructions
350
-
351
- If the user chooses "Review Manually", provide step-by-step instructions:
352
-
353
- ````markdown
354
- ## 📖 Manual Split Instructions
355
-
356
- You can manually split this branch using these `gt` commands:
357
-
358
- ### 1. Split into PR #1 (foundational types)
359
-
360
- ```bash
361
- # Create commit message file (secure approach)
362
- cat > /tmp/pr1-msg.txt <<'EOF'
363
- feat: add authentication types and interfaces
364
- EOF
365
-
366
- # Rebase interactively to mark split point
367
- gt split -F /tmp/pr1-msg.txt
368
- # When prompted, select commits: abc123f, def456a, ghi789b
369
- ```
370
- ````
371
-
372
- This creates a new branch at commit ghi789b and moves the remaining commits to a new branch stacked on top.
373
-
374
- ### 2. Split into PR #2 (JWT service)
375
-
376
- ```bash
377
- # Create commit message file for PR #2
378
- cat > /tmp/pr2-msg.txt <<'EOF'
379
- feat: implement JWT authentication service
380
- EOF
381
-
382
- # Now you're on the second branch
383
- gt split -F /tmp/pr2-msg.txt
384
- # Select commits: jkl012c through vwx234g
385
- ```
386
-
387
- ### 3. Continue for remaining PRs
388
-
389
- Repeat the process for each PR in the plan.
390
-
391
- ### 4. Submit the stack
392
-
393
- ```bash
394
- # Submit all PRs in the stack
395
- gt submit --stack --no-interactive
396
- ```
397
-
398
- ### Useful gt commands during splitting
399
-
400
- ```bash
401
- gt state # View current stack structure
402
- gt up # Move up the stack
403
- gt down # Move down the stack
404
- gt restack # Rebase the entire stack if needed
405
- gt checkout # Interactively switch between branches in the stack
406
- ```
407
-
408
- ````
409
-
410
- ## Semantic Analysis Principles
411
-
412
- The stack-splitter agent follows these principles when analyzing changes:
413
-
414
- ### 1. Logical Boundaries
415
-
416
- Group changes that:
417
-
418
- - Implement the same feature or fix the same bug
419
- - Share the same domain/context (auth, payments, UI, etc.)
420
- - Have natural dependencies (types → implementation → tests → integration)
421
-
422
- ### 2. Dependency Awareness
423
-
424
- - Use Nx project graph to understand package dependencies
425
- - Foundational changes go at the bottom of the stack
426
- - Integration/glue code goes at the top
427
- - Ensure each PR can be reviewed independently of PRs above it
428
-
429
- ### 3. Reviewability Optimization
430
-
431
- Each PR should:
432
-
433
- - Tell a coherent story with a clear purpose
434
- - Be small enough to review in 15-30 minutes
435
- - Include tests relevant to its changes
436
- - Have a descriptive title and description
437
- - Not mix unrelated concerns
438
-
439
- ### 4. Stack Depth Consideration
440
-
441
- - Prefer shallow stacks (2-4 PRs) over deep ones (5+ PRs)
442
- - Each additional level adds review coordination overhead
443
- - Balance granularity with practical reviewability
444
-
445
- ### 5. File Grouping Patterns
446
-
447
- Common patterns for grouping files:
448
-
449
- - **Feature pattern**: types → implementation → tests → docs
450
- - **Vertical slice**: backend API → frontend UI → integration
451
- - **Refactor pattern**: extract → replace → cleanup
452
- - **Package pattern**: all changes to one package in one PR (if logical)
453
-
454
- ## Best Practices
455
-
456
- ### Before Running
457
-
458
- 1. **Commit all changes**: Ensure all work is committed (not necessarily pushed)
459
- 2. **Clean working directory**: No uncommitted changes
460
- 3. **Up-to-date base**: Fetch latest from base branch (`git fetch origin`)
461
-
462
- ### During Execution
463
-
464
- 1. **Review the plan carefully**: Does the grouping make sense?
465
- 2. **Consider your reviewers**: What size PRs work best for your team?
466
- 3. **Think about dependencies**: Can PR #2 be reviewed if PR #1 isn't merged yet?
467
-
468
- ### After Splitting
469
-
470
- 1. **Review each PR individually**: `gh pr view <number>` or open in browser
471
- 2. **Check CI status**: Ensure all PRs pass tests
472
- 3. **Add context to PR descriptions**: Reference the stack structure
473
- 4. **Use Graphite dashboard**: View and manage your stack at graphite.dev
474
-
475
- ## Error Handling
476
-
477
- ### No Changes to Split
478
-
479
- ```bash
480
- if [[ -z "$(git log --oneline "$BASE_BRANCH..$CURRENT_BRANCH")" ]]; then
481
- echo "❌ No commits found between $BASE_BRANCH and $CURRENT_BRANCH"
482
- echo "Either:"
483
- echo " - You're already on the base branch"
484
- echo " - This branch is up-to-date with base"
485
- echo " - The base branch name is incorrect"
486
- exit 1
487
- fi
488
- ````
489
-
490
- ### Too Few Changes
491
-
492
- ```bash
493
- COMMIT_COUNT=$(git log --oneline "$BASE_BRANCH..$CURRENT_BRANCH" | wc -l)
494
-
495
- if [[ $COMMIT_COUNT -lt 2 ]]; then
496
- echo "⚠️ This branch only has $COMMIT_COUNT commit(s)"
497
- echo "Stack splitting works best with 3+ commits"
498
- echo "Consider using a regular PR instead"
499
- exit 0
500
- fi
501
- ```
502
-
503
- ### Uncommitted Changes
504
-
505
- ```bash
506
- if [[ -n "$(git status --porcelain)" ]]; then
507
- echo "❌ You have uncommitted changes"
508
- echo "Please commit or stash them before splitting"
509
- git status --short
510
- exit 1
511
- fi
512
- ```
513
-
514
- ### Graphite Not Initialized
515
-
516
- ```bash
517
- if ! gt status &>/dev/null; then
518
- echo "❌ Graphite (gt) is not initialized in this repository"
519
- echo "Run: gt init"
520
- exit 1
521
- fi
522
- ```
523
-
524
- ## Integration with Nx
525
-
526
- For Nx monorepos, the agent can use project structure for better grouping:
527
-
528
- ```typescript
529
- // Get Nx project details for affected projects
530
- const affectedProjects = await Bash('npx nx show projects --affected --base="$BASE_BRANCH"');
531
-
532
- // Get project graph to understand dependencies
533
- const projectGraph = await Task({
534
- subagent_type: 'general-purpose',
535
- prompt: 'Use mcp__nx-mcp__nx_project_details to get details about affected Nx projects',
536
- });
537
- ```
538
-
539
- This helps create splits that respect package boundaries and dependencies.
540
-
541
- ## Example Session
542
-
543
- ```bash
544
- $ /split-stack
545
-
546
- 📊 Analyzing branch: feature/auth-system
547
- 📍 Base branch: main
548
-
549
- 📈 Branch Statistics:
550
- - Total commits: 15
551
- - Files changed: 42
552
- - Lines added: +1,234
553
- - Lines removed: -567
554
- - Affected packages: 4 (auth, web, api, shared)
555
-
556
- 🔍 Analyzing changes semantically...
557
-
558
- [Agent analyzes commits, diffs, and Nx structure]
559
-
560
- ## 📋 Proposed Stack Split Plan
561
-
562
- [... plan shown above ...]
563
-
564
- How would you like to proceed with this split plan?
565
- ○ Approve and Execute
566
- ○ Modify Plan
567
- ○ Review Manually
568
- ○ Cancel
569
-
570
- > Approve and Execute
571
-
572
- 🔄 Executing stack split...
573
-
574
- 📦 Creating PR #1: feat: add authentication types and interfaces
575
- ✅ Branch created: feature/auth-types
576
- ✅ Commits: abc123f, def456a, ghi789b
577
-
578
- 📦 Creating PR #2: feat: implement JWT authentication service
579
- ✅ Branch created: feature/jwt-service
580
- ✅ Commits: jkl012c, mno345d, pqr678e, stu901f, vwx234g
581
-
582
- [... continues for all PRs ...]
583
-
584
- 🚀 Submitting stack to Graphite...
585
-
586
- ✅ Stack created successfully!
587
-
588
- 📊 Stack Summary:
589
- - PR #1: https://github.com/owner/repo/pull/101 (ready for review)
590
- - PR #2: https://github.com/owner/repo/pull/102 (depends on #101)
591
- - PR #3: https://github.com/owner/repo/pull/103 (depends on #102)
592
- - PR #4: https://github.com/owner/repo/pull/104 (depends on #103)
593
-
594
- 🎯 Next Steps:
595
- 1. Review each PR on Graphite: https://app.graphite.dev
596
- 2. PRs will auto-merge down the stack as each is approved
597
- 3. Use 'gt up' and 'gt down' to navigate the stack locally
598
- ```
599
-
600
- ## Advanced Features
601
-
602
- ### Custom Split Boundaries
603
-
604
- If you want to manually specify split points:
605
-
606
- ```bash
607
- /split-stack main --splits="3,7,12"
608
- ```
609
-
610
- This would create splits after commits 3, 7, and 12, resulting in 4 PRs.
611
-
612
- ### Dry Run Mode
613
-
614
- Preview the split plan without executing:
615
-
616
- ```bash
617
- /split-stack --dry-run
618
- ```
619
-
620
- ### Interactive Refinement
621
-
622
- After seeing the initial plan, refine it interactively:
623
-
624
- - Merge two PRs
625
- - Split one PR into two
626
- - Reorder PRs in the stack
627
- - Adjust PR titles and descriptions
628
-
629
- ## Tips
630
-
631
- 1. **Commit granularity matters**: More granular commits make splitting easier
632
- 2. **Use descriptive commit messages**: They help the semantic analysis
633
- 3. **Group tests with features**: Include test changes in the same PR as the feature
634
- 4. **Document dependencies**: Add PR descriptions explaining stack dependencies
635
- 5. **Review from bottom up**: Start reviewing the foundational PRs first
636
-
637
- ## Limitations
638
-
639
- - Works best with 3-15 commits (too few = not worth splitting, too many = hard to analyze)
640
- - Requires clean git history (avoid merge commits, prefer rebase workflow)
641
- - `gt split` is interactive - fully automated splitting is limited
642
- - Semantic analysis is best-effort - review the plan carefully
643
-
644
- ## Troubleshooting
645
-
646
- ### "Graphite (gt) is not initialized"
647
-
648
- **Solution:** Run `gt repo init` in your repository root.
649
-
650
- ### "You have uncommitted changes"
651
-
652
- **Solution:** Commit or stash your changes:
653
-
654
- ```bash
655
- git stash # Temporarily stash changes
656
- # OR
657
- git commit -am "WIP" # Commit work in progress
658
- ```
659
-
660
- ### "Invalid branch name"
661
-
662
- **Solution:** Branch names must contain only letters, numbers, hyphens, underscores, slashes, and dots. Avoid special characters and shell metacharacters.
663
-
664
- ### "No commits found between branches"
665
-
666
- **Solutions:**
667
-
668
- - Verify you're on a feature branch (not main): `git branch --show-current`
669
- - Check the base branch name is correct: `git branch -a`
670
- - Ensure your branch has commits: `git log main..HEAD`
671
-
672
- ### "Branch does not exist"
673
-
674
- **Solution:** Verify branch names with `git branch -a` and ensure you're using the correct branch name.
675
-
676
- ### "Split failed mid-operation"
677
-
678
- **Recovery steps:**
679
-
680
- 1. Check current git state: `git status`
681
- 2. List active worktrees: `git worktree list`
682
- 3. Remove failed worktree: `git worktree remove <path>`
683
- 4. Reset to starting point: `git reset --hard origin/your-branch`
684
-
685
- ### Graphite CLI not found
686
-
687
- **Solution:** Install Graphite CLI globally:
688
-
689
- ```bash
690
- npm install -g @withgraphite/graphite-cli@latest
691
- ```
692
-
693
- ### Permission denied errors
694
-
695
- **Solution:** Ensure you have write permissions to the repository and can push to the remote.
696
-
697
- ## Related Commands
698
-
699
- - `/plan`: Create implementation plans for features
700
- - `/create-pr`: Create individual PRs
701
- - `/review-pr`: Review PRs in a stack
702
-
703
- ## Notes
704
-
705
- This command is designed to work with your existing Graphite (gt) workflow and respects your preference for manual approval before making changes.