Skip to content

Commit 87138ea

Browse files
authored
feat(workflows:work): add incremental commits and branch safety (#93)
- Add branch detection at start of Setup Environment step - Support continuing on existing feature branch or creating new - Require explicit confirmation to commit to default branch - Add incremental commit guidance with decision criteria table - Include heuristic: "Can I write a meaningful commit message?" - Generalize test commands to be framework-agnostic
1 parent 384b416 commit 87138ea

File tree

1 file changed

+66
-19
lines changed
  • plugins/compound-engineering/commands/workflows

1 file changed

+66
-19
lines changed

plugins/compound-engineering/commands/workflows/work.md

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,48 @@ This command takes a work document (plan, specification, or todo file) and execu
3030

3131
2. **Setup Environment**
3232

33-
Choose your work style:
33+
First, check the current branch:
3434

35-
**Option A: Live work on current branch**
3635
```bash
37-
git checkout main && git pull origin main
36+
current_branch=$(git branch --show-current)
37+
default_branch=$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@')
38+
39+
# Fallback if remote HEAD isn't set
40+
if [ -z "$default_branch" ]; then
41+
default_branch=$(git rev-parse --verify origin/main >/dev/null 2>&1 && echo "main" || echo "master")
42+
fi
43+
```
44+
45+
**If already on a feature branch** (not the default branch):
46+
- Ask: "Continue working on `[current_branch]`, or create a new branch?"
47+
- If continuing, proceed to step 3
48+
- If creating new, follow Option A or B below
49+
50+
**If on the default branch**, choose how to proceed:
51+
52+
**Option A: Create a new branch**
53+
```bash
54+
git pull origin [default_branch]
3855
git checkout -b feature-branch-name
3956
```
57+
Use a meaningful name based on the work (e.g., `feat/user-authentication`, `fix/email-validation`).
4058

41-
**Option B: Parallel work with worktree (recommended for parallel development)**
59+
**Option B: Use a worktree (recommended for parallel development)**
4260
```bash
43-
# Ask user first: "Work in parallel with worktree or on current branch?"
44-
# If worktree:
4561
skill: git-worktree
46-
# The skill will create a new branch from main in an isolated worktree
62+
# The skill will create a new branch from the default branch in an isolated worktree
4763
```
4864

65+
**Option C: Continue on the default branch**
66+
- Requires explicit user confirmation
67+
- Only proceed after user explicitly says "yes, commit to [default_branch]"
68+
- Never commit directly to the default branch without explicit permission
69+
4970
**Recommendation**: Use worktree if:
5071
- You want to work on multiple features simultaneously
51-
- You want to keep main clean while experimenting
72+
- You want to keep the default branch clean while experimenting
5273
- You plan to switch between branches frequently
5374

54-
Use live branch if:
55-
- You're working on a single feature
56-
- You prefer staying in the main repository
57-
5875
3. **Create Todo List**
5976
- Use TodoWrite to break plan into actionable tasks
6077
- Include dependencies between tasks
@@ -78,26 +95,56 @@ This command takes a work document (plan, specification, or todo file) and execu
7895
- Run tests after changes
7996
- Mark task as completed in TodoWrite
8097
- Mark off the corresponding checkbox in the plan file ([ ] → [x])
98+
- Evaluate for incremental commit (see below)
8199
```
82100

83101
**IMPORTANT**: Always update the original plan document by checking off completed items. Use the Edit tool to change `- [ ]` to `- [x]` for each task you finish. This keeps the plan as a living document showing progress and ensures no checkboxes are left unchecked.
84102

85-
2. **Follow Existing Patterns**
103+
2. **Incremental Commits**
104+
105+
After completing each task, evaluate whether to create an incremental commit:
106+
107+
| Commit when... | Don't commit when... |
108+
|----------------|---------------------|
109+
| Logical unit complete (model, service, component) | Small part of a larger unit |
110+
| Tests pass + meaningful progress | Tests failing |
111+
| About to switch contexts (backend → frontend) | Purely scaffolding with no behavior |
112+
| About to attempt risky/uncertain changes | Would need a "WIP" commit message |
113+
114+
**Heuristic:** "Can I write a commit message that describes a complete, valuable change? If yes, commit. If the message would be 'WIP' or 'partial X', wait."
115+
116+
**Commit workflow:**
117+
```bash
118+
# 1. Verify tests pass (use project's test command)
119+
# Examples: bin/rails test, npm test, pytest, go test, etc.
120+
121+
# 2. Stage only files related to this logical unit (not `git add .`)
122+
git add <files related to this logical unit>
123+
124+
# 3. Commit with conventional message
125+
git commit -m "feat(scope): description of this unit"
126+
```
127+
128+
**Handling merge conflicts:** If conflicts arise during rebasing or merging, resolve them immediately. Incremental commits make conflict resolution easier since each commit is small and focused.
129+
130+
**Note:** Incremental commits use clean conventional messages without attribution footers. The final Phase 4 commit/PR includes the full attribution.
131+
132+
3. **Follow Existing Patterns**
86133

87134
- The plan should reference similar code - read those files first
88135
- Match naming conventions exactly
89136
- Reuse existing components where possible
90137
- Follow project coding standards (see CLAUDE.md)
91138
- When in doubt, grep for similar implementations
92139

93-
3. **Test Continuously**
140+
4. **Test Continuously**
94141

95142
- Run relevant tests after each significant change
96143
- Don't wait until the end to test
97144
- Fix failures immediately
98145
- Add new tests for new functionality
99146

100-
4. **Figma Design Sync** (if applicable)
147+
5. **Figma Design Sync** (if applicable)
101148

102149
For UI work with Figma designs:
103150

@@ -106,7 +153,7 @@ This command takes a work document (plan, specification, or todo file) and execu
106153
- Fix visual differences identified
107154
- Repeat until implementation matches design
108155

109-
5. **Track Progress**
156+
6. **Track Progress**
110157
- Keep TodoWrite updated as you complete tasks
111158
- Note any blockers or unexpected discoveries
112159
- Create new tasks if scope expands
@@ -119,8 +166,8 @@ This command takes a work document (plan, specification, or todo file) and execu
119166
Always run before submitting:
120167

121168
```bash
122-
# Run full test suite
123-
bin/rails test
169+
# Run full test suite (use project's test command)
170+
# Examples: bin/rails test, npm test, pytest, go test, etc.
124171

125172
# Run linting (per CLAUDE.md)
126173
# Use linting-agent before pushing to origin
@@ -284,7 +331,7 @@ Before creating PR, verify:
284331
285332
- [ ] All clarifying questions asked and answered
286333
- [ ] All TodoWrite tasks marked completed
287-
- [ ] Tests pass (run `bin/rails test`)
334+
- [ ] Tests pass (run project's test command)
288335
- [ ] Linting passes (use linting-agent)
289336
- [ ] Code follows existing patterns
290337
- [ ] Figma designs match implementation (if applicable)

0 commit comments

Comments
 (0)