omgkit 2.22.11 → 2.23.0

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,568 @@
1
+ ---
2
+ name: Stacked Diffs Workflow
3
+ description: The agent implements stacked diffs (stacked PRs) for breaking large changes into reviewable chunks. Use when working on complex features, managing dependent changes, or optimizing code review flow.
4
+ category: methodology
5
+ ---
6
+
7
+ # Stacked Diffs Workflow
8
+
9
+ ## Purpose
10
+
11
+ Stacked diffs (also known as stacked PRs or stacked branches) is a code review workflow pioneered at Meta (Facebook) that enables:
12
+
13
+ - **Breaking large changes** into small, reviewable chunks
14
+ - **Parallel code review** of dependent changes
15
+ - **Faster iteration** without waiting for reviews
16
+ - **Cleaner git history** with logical commits
17
+ - **Reduced context switching** for reviewers
18
+
19
+ Meta engineers use stacked diffs extensively with their internal tools, and this practice has spread to companies like Uber, Airbnb, and many others.
20
+
21
+ ## Features
22
+
23
+ | Feature | Description | Benefit |
24
+ |---------|-------------|---------|
25
+ | Dependent PRs | Chain of PRs building on each other | Logical separation |
26
+ | Parallel Review | Review all PRs simultaneously | Faster feedback |
27
+ | Easy Updates | Update any commit in the stack | Flexible iteration |
28
+ | Automatic Rebase | Tools handle rebase complexity | Less manual work |
29
+ | Merge Automation | Merge entire stacks efficiently | Cleaner history |
30
+
31
+ ## Stacked Diffs vs Traditional PRs
32
+
33
+ ### Traditional PR Workflow
34
+
35
+ ```
36
+ Main ─────────────────────────────────────────────►
37
+ \
38
+ └── Feature Branch (1000 lines) ──────────►
39
+
40
+ └── Single large PR
41
+ - Hard to review
42
+ - Long review time
43
+ - All-or-nothing merge
44
+ ```
45
+
46
+ ### Stacked Diffs Workflow
47
+
48
+ ```
49
+ Main ────────────────────────────────────────────────►
50
+ \
51
+ └── PR 1: Add data model (100 lines)
52
+ \
53
+ └── PR 2: Add API endpoint (150 lines)
54
+ \
55
+ └── PR 3: Add frontend (200 lines)
56
+ \
57
+ └── PR 4: Add tests (150 lines)
58
+
59
+ Each PR:
60
+ - Small and focused
61
+ - Can be reviewed in parallel
62
+ - Merged independently (in order)
63
+ ```
64
+
65
+ ## Tools
66
+
67
+ ### Graphite (Recommended)
68
+
69
+ ```bash
70
+ # Install Graphite CLI
71
+ npm install -g @withgraphite/graphite-cli
72
+
73
+ # Authenticate with GitHub
74
+ gt auth
75
+
76
+ # Create first branch in stack
77
+ gt branch create feature/add-data-model
78
+ # ... make changes ...
79
+ git add . && gt commit -m "Add user data model"
80
+
81
+ # Create dependent branch
82
+ gt branch create feature/add-api
83
+ # ... make changes ...
84
+ git add . && gt commit -m "Add user API endpoints"
85
+
86
+ # Create another dependent branch
87
+ gt branch create feature/add-frontend
88
+ # ... make changes ...
89
+ git add . && gt commit -m "Add user frontend components"
90
+
91
+ # View your stack
92
+ gt log
93
+
94
+ # Submit all PRs in stack
95
+ gt stack submit
96
+
97
+ # After PR 1 is approved and merged, restack remaining
98
+ gt stack restack
99
+
100
+ # Sync with remote
101
+ gt repo sync
102
+ ```
103
+
104
+ ### ghstack (GitHub)
105
+
106
+ ```bash
107
+ # Install ghstack
108
+ pip install ghstack
109
+
110
+ # Configure
111
+ ghstack config set github.com
112
+
113
+ # Create stack from commits
114
+ # First, make commits on a local branch
115
+ git checkout -b feature/user-system
116
+ git commit -m "Add user data model"
117
+ git commit -m "Add user API"
118
+ git commit -m "Add user frontend"
119
+
120
+ # Submit stack to GitHub
121
+ ghstack submit
122
+
123
+ # Update a commit in the middle
124
+ git rebase -i HEAD~3
125
+ # Edit the commit
126
+ ghstack submit
127
+
128
+ # After reviews, land the stack
129
+ ghstack land
130
+ ```
131
+
132
+ ### git-branchless
133
+
134
+ ```bash
135
+ # Install git-branchless
136
+ cargo install git-branchless
137
+
138
+ # Initialize
139
+ git branchless init
140
+
141
+ # Create commits (each becomes a "branch")
142
+ git commit -m "Add data model"
143
+ git commit -m "Add API"
144
+ git commit -m "Add frontend"
145
+
146
+ # View stack
147
+ git smartlog
148
+
149
+ # Submit to GitHub
150
+ git branchless submit
151
+
152
+ # Rebase and update
153
+ git branchless reword HEAD~2 # Edit middle commit
154
+ git branchless submit # Update all PRs
155
+ ```
156
+
157
+ ### Sapling (Meta's Tool)
158
+
159
+ ```bash
160
+ # Install Sapling
161
+ brew install sapling
162
+
163
+ # Clone repo
164
+ sl clone https://github.com/org/repo
165
+
166
+ # Create commits in stack
167
+ sl commit -m "Add data model"
168
+ sl commit -m "Add API"
169
+ sl commit -m "Add frontend"
170
+
171
+ # View stack
172
+ sl smartlog
173
+
174
+ # Submit for review
175
+ sl pr submit
176
+
177
+ # Amend a commit in the middle
178
+ sl goto <commit-hash>
179
+ # make changes
180
+ sl amend
181
+
182
+ # Rebase dependent commits
183
+ sl rebase -d <base>
184
+ ```
185
+
186
+ ## Workflow Patterns
187
+
188
+ ### Creating a Stack
189
+
190
+ ```bash
191
+ # Start from main
192
+ git checkout main && git pull
193
+
194
+ # Create first logical change
195
+ gt branch create feat/step-1-models
196
+ # Make changes for data models
197
+ git add . && gt commit -m "feat: add user and post models"
198
+
199
+ # Create second logical change (builds on first)
200
+ gt branch create feat/step-2-api
201
+ # Make changes for API layer
202
+ git add . && gt commit -m "feat: add REST API for users"
203
+
204
+ # Create third logical change (builds on second)
205
+ gt branch create feat/step-3-frontend
206
+ # Make changes for frontend
207
+ git add . && gt commit -m "feat: add user management UI"
208
+
209
+ # Submit entire stack
210
+ gt stack submit
211
+
212
+ # Result: 3 PRs created, each targeting the previous
213
+ ```
214
+
215
+ ### Updating Middle Commits
216
+
217
+ ```bash
218
+ # Scenario: Reviewer requests changes to PR 2 (API layer)
219
+
220
+ # Check out the branch for PR 2
221
+ gt branch checkout feat/step-2-api
222
+
223
+ # Make the requested changes
224
+ # ... edit files ...
225
+
226
+ # Amend the commit
227
+ git add . && git commit --amend
228
+
229
+ # Restack all dependent branches
230
+ gt stack restack
231
+
232
+ # Update all PRs
233
+ gt stack submit
234
+ ```
235
+
236
+ ### Handling Merge Conflicts
237
+
238
+ ```bash
239
+ # When PR 1 is merged and conflicts arise
240
+
241
+ # Sync with remote
242
+ gt repo sync
243
+
244
+ # Restack your branches on top of main
245
+ gt stack restack --onto main
246
+
247
+ # If conflicts occur, resolve them
248
+ # ... resolve conflicts ...
249
+ git add . && git rebase --continue
250
+
251
+ # Update PRs
252
+ gt stack submit
253
+ ```
254
+
255
+ ### Merging a Stack
256
+
257
+ ```bash
258
+ # Option 1: Merge from bottom up
259
+ # After PR 1 approved:
260
+ gh pr merge 123 --squash # PR 1
261
+ gt repo sync
262
+ gt stack restack
263
+
264
+ # After PR 2 approved:
265
+ gh pr merge 124 --squash # PR 2
266
+ gt repo sync
267
+ gt stack restack
268
+
269
+ # Continue until all merged
270
+
271
+ # Option 2: Use Graphite's merge queue
272
+ gt stack merge # Merges all approved PRs in order
273
+ ```
274
+
275
+ ## Best Practices
276
+
277
+ ### 1. Keep PRs Small and Focused
278
+
279
+ ```markdown
280
+ ## Good Stack Structure
281
+
282
+ PR 1: Database migrations and models
283
+ - Add User table migration
284
+ - Add Post table migration
285
+ - Add UserPost junction table
286
+
287
+ PR 2: Repository layer
288
+ - Add UserRepository with CRUD
289
+ - Add PostRepository with CRUD
290
+
291
+ PR 3: Service layer
292
+ - Add UserService with business logic
293
+ - Add PostService with business logic
294
+
295
+ PR 4: API controllers
296
+ - Add /users endpoints
297
+ - Add /posts endpoints
298
+
299
+ PR 5: Integration tests
300
+ - Add API integration tests
301
+ - Add E2E user flow tests
302
+ ```
303
+
304
+ ### 2. Write Clear Stack Descriptions
305
+
306
+ ```markdown
307
+ ## PR Description Template for Stacks
308
+
309
+ ### Stack Overview (in first PR)
310
+ This stack implements user authentication:
311
+ 1. **PR 1** (this PR): Database schema for users
312
+ 2. PR 2: Authentication service
313
+ 3. PR 3: Login/Register endpoints
314
+ 4. PR 4: JWT middleware
315
+ 5. PR 5: Frontend auth components
316
+
317
+ ### This PR
318
+ Adds the database schema and migrations for the user authentication system.
319
+
320
+ ### Dependencies
321
+ - Base: `main`
322
+ - Next in stack: PR #124
323
+
324
+ ### Testing
325
+ - [ ] Unit tests pass
326
+ - [ ] Migration tested locally
327
+
328
+ ### Review Notes
329
+ Please review the schema design first. Later PRs depend on this structure.
330
+ ```
331
+
332
+ ### 3. Coordinate with Reviewers
333
+
334
+ ```typescript
335
+ // PR naming convention for stacks
336
+ const prNamingConvention = {
337
+ format: '[Stack: <stack-name>] <n>/<total>: <description>',
338
+ examples: [
339
+ '[Stack: user-auth] 1/5: Add user database schema',
340
+ '[Stack: user-auth] 2/5: Add authentication service',
341
+ '[Stack: user-auth] 3/5: Add login endpoints',
342
+ '[Stack: user-auth] 4/5: Add JWT middleware',
343
+ '[Stack: user-auth] 5/5: Add frontend components'
344
+ ]
345
+ };
346
+ ```
347
+
348
+ ### 4. Handle Reviews Efficiently
349
+
350
+ ```bash
351
+ # Respond to review comments efficiently
352
+
353
+ # If change affects only one PR
354
+ gt branch checkout feat/affected-branch
355
+ # make changes
356
+ git add . && gt commit --amend
357
+ gt stack submit
358
+
359
+ # If change affects multiple PRs
360
+ # Start from the earliest affected PR
361
+ gt branch checkout feat/earliest-affected
362
+ # make changes
363
+ git add . && gt commit --amend
364
+ gt stack restack # Propagates changes up the stack
365
+ gt stack submit
366
+ ```
367
+
368
+ ## Anti-Patterns
369
+
370
+ | Anti-Pattern | Problem | Solution |
371
+ |--------------|---------|----------|
372
+ | **Huge PRs in stack** | Still hard to review | Keep each PR < 400 lines |
373
+ | **Unrelated changes** | Confuses reviewers | Each PR should be cohesive |
374
+ | **Too many PRs** | Overhead exceeds benefit | 3-7 PRs is ideal |
375
+ | **Unclear dependencies** | Hard to merge correctly | Document stack structure |
376
+ | **No tests per PR** | Can't verify independently | Include relevant tests |
377
+ | **Force pushing shared branches** | Breaks collaborators | Use amend + restack |
378
+
379
+ ## Git Commands for Manual Stacking
380
+
381
+ When tools aren't available, you can manage stacks manually:
382
+
383
+ ```bash
384
+ # Create a stack manually
385
+ git checkout main
386
+ git checkout -b stack/feature-1
387
+ # make changes, commit
388
+
389
+ git checkout -b stack/feature-2
390
+ # make changes, commit
391
+
392
+ git checkout -b stack/feature-3
393
+ # make changes, commit
394
+
395
+ # Create PRs targeting each other
396
+ gh pr create --base main --head stack/feature-1
397
+ gh pr create --base stack/feature-1 --head stack/feature-2
398
+ gh pr create --base stack/feature-2 --head stack/feature-3
399
+
400
+ # After feature-1 merges, rebase the rest
401
+ git checkout stack/feature-2
402
+ git rebase main
403
+ git push --force-with-lease
404
+
405
+ git checkout stack/feature-3
406
+ git rebase stack/feature-2
407
+ git push --force-with-lease
408
+
409
+ # Update PR targets
410
+ gh pr edit 124 --base main # feature-2 now targets main
411
+ ```
412
+
413
+ ### Interactive Rebase for Stack Edits
414
+
415
+ ```bash
416
+ # Edit a commit in the middle of a stack
417
+ git rebase -i main
418
+
419
+ # In the editor, change 'pick' to 'edit' for the commit to modify
420
+ # pick abc123 Add data model
421
+ # edit def456 Add API endpoints <-- edit this one
422
+ # pick ghi789 Add frontend
423
+
424
+ # Make your changes
425
+ git add . && git commit --amend
426
+
427
+ # Continue rebase
428
+ git rebase --continue
429
+
430
+ # Force push all branches
431
+ git push --force-with-lease origin stack/feature-1
432
+ git push --force-with-lease origin stack/feature-2
433
+ git push --force-with-lease origin stack/feature-3
434
+ ```
435
+
436
+ ## IDE Integration
437
+
438
+ ### VS Code with Graphite
439
+
440
+ ```json
441
+ // .vscode/settings.json
442
+ {
443
+ "graphite.enabled": true,
444
+ "graphite.showStackInStatusBar": true,
445
+ "git.branchPrefix": "stack/"
446
+ }
447
+ ```
448
+
449
+ ### JetBrains IDEs
450
+
451
+ ```bash
452
+ # Use terminal integration
453
+ # Add to .zshrc or .bashrc
454
+ alias gs='gt stack'
455
+ alias gb='gt branch'
456
+ alias gc='gt commit'
457
+ ```
458
+
459
+ ## Use Cases
460
+
461
+ ### 1. Large Feature Development
462
+
463
+ ```markdown
464
+ ## Stack: E-commerce Checkout Redesign
465
+
466
+ 1. **PR 1**: Cart data model updates
467
+ - Add discount fields
468
+ - Add shipping options
469
+
470
+ 2. **PR 2**: Cart service layer
471
+ - Discount calculation logic
472
+ - Shipping cost estimation
473
+
474
+ 3. **PR 3**: Checkout API endpoints
475
+ - POST /checkout/initiate
476
+ - POST /checkout/complete
477
+
478
+ 4. **PR 4**: Payment integration
479
+ - Stripe checkout session
480
+ - Webhook handlers
481
+
482
+ 5. **PR 5**: Checkout UI components
483
+ - Cart summary
484
+ - Payment form
485
+ - Order confirmation
486
+
487
+ 6. **PR 6**: E2E tests
488
+ - Full checkout flow tests
489
+ ```
490
+
491
+ ### 2. Refactoring Safely
492
+
493
+ ```markdown
494
+ ## Stack: Extract Service from Monolith
495
+
496
+ 1. **PR 1**: Add new service interface
497
+ - Define contracts
498
+ - Add feature flag
499
+
500
+ 2. **PR 2**: Implement new service
501
+ - Core logic extraction
502
+ - Unit tests
503
+
504
+ 3. **PR 3**: Add service client
505
+ - HTTP client implementation
506
+ - Circuit breaker
507
+
508
+ 4. **PR 4**: Migrate callers (batch 1)
509
+ - Update user service
510
+ - Update order service
511
+
512
+ 5. **PR 5**: Migrate callers (batch 2)
513
+ - Update remaining services
514
+
515
+ 6. **PR 6**: Remove old code
516
+ - Delete deprecated methods
517
+ - Remove feature flag
518
+ ```
519
+
520
+ ### 3. Cross-Team Collaboration
521
+
522
+ ```bash
523
+ # When multiple developers work on a stack
524
+
525
+ # Developer A creates base
526
+ gt branch create feature/base
527
+ git add . && gt commit -m "feat: add base infrastructure"
528
+ gt stack submit
529
+
530
+ # Developer B branches from A's work
531
+ gt branch checkout feature/base
532
+ gt branch create feature/extension
533
+ git add . && gt commit -m "feat: extend with new capability"
534
+ gt stack submit
535
+
536
+ # When A updates their PR
537
+ gt repo sync
538
+ gt stack restack # B's changes are rebased automatically
539
+ ```
540
+
541
+ ## Metrics and Benefits
542
+
543
+ ### Before Stacked Diffs
544
+ | Metric | Value |
545
+ |--------|-------|
546
+ | Average PR size | 1,200 lines |
547
+ | Review turnaround | 3-5 days |
548
+ | Merge conflicts | Frequent |
549
+ | Review quality | Lower |
550
+
551
+ ### After Stacked Diffs
552
+ | Metric | Value |
553
+ |--------|-------|
554
+ | Average PR size | 150-300 lines |
555
+ | Review turnaround | Same day |
556
+ | Merge conflicts | Rare |
557
+ | Review quality | Higher |
558
+
559
+ ## Related Skills
560
+
561
+ - `methodology/finishing-development-branch` - Branch completion
562
+ - `methodology/requesting-code-review` - Code review best practices
563
+ - `devops/github-actions` - CI/CD for stacks
564
+ - `devops/feature-flags` - Trunk-based development
565
+
566
+ ---
567
+
568
+ *Think Omega. Build Omega. Be Omega.*