These rules govern the complete workflow from discovery through implementation.
Before planning implementation, you will explore and design the solution.
Process:
- User tasks you with analyzing a problem or feature
- Create analysis and design documents exploring the solution space
- Documents may include: current state analysis, proposed changes, trade-offs, dependencies
- Iterate with user feedback until the approach is clear
- When user approves the design, proceed to Rule 1
Document characteristics:
- Exploratory and descriptive
- May contain diffs for illustration, but
PLAN.mdholds the authoritative diffs - May contain multiple options or alternatives
- Should identify files to modify and rough scope
- Serves as input for creating the formal plan
[Requires user approval] Before transitioning from Rule 0 (discovery/design) to Rule 1 (commit planning), you must get explicit user approval. Do not begin writing commits to PLAN.md until the user confirms they are ready to move from brainstorming to implementation planning.
You will create or update a PLAN.md for every change you plan to make.
PLAN.mdwill be an annotated diff containing every change you want to make before making themPLAN.mdcontains the authoritative diffs - discovery documents may have illustrative diffs, butPLAN.mdis canonical- The purpose of Rule 1 is to pre-emptively prevent Rule 3 violations
- When coming from Rule 6 (code review cycle), append new commits to the existing
PLAN.md
Format:
# Plan: <brief description>
## Files to Modify
### Commit N: `path/to/file.py` - <description>
```diff
- old line
+ new line
```
Reason: <why this change>When to update PLAN.md for existing commits:
If a planned commit becomes invalid during implementation (stale, nonsensical, or exceeds line limit), see Rule 4 for how to split or redesign it. This applies only to commits already in the plan that need correction—not to new commits added via Rule 6.
After creating PLAN.md, create a task list to track implementation progress.
Process:
- Create one task per commit in the plan
- Add RULES.md review checkpoints every 10 commits
- The first task must be "Review RULES.md - initial review before starting"
Task format:
Commit <N>: <file> - <description>, in compliance with RULES.md
See "Task List Setup" section below for complete structure and examples.
Your commits must be microcommits.
Restrictions:
- Changes are restricted to 5-20 lines per commit for code files
- You may have more than one file with 5-20 lines each, but you should minimize this
- If a planned commit no longer makes sense or is stale, see Rule 4 for redesign procedures
Exemptions (no line limit):
- File deletions
- File renames/moves
- Markdown files (
.md)
This rule governs validation, splitting, and PLAN.md maintenance for existing planned commits.
Run this command before every commit to verify Rule 3 compliance:
git diff --cached --numstat -M | awk '
/\.md$/ { next } # Skip markdown files
/=>/ { next } # Skip renames/moves (detected by -M)
$1 == 0 { next } # Skip pure deletions
{
lines = $1 + $2
print lines, $3
sum += lines
if ($2 == 0 && $1 > 0) { newfiles = newfiles $3 "\n" }
}
END {
if (sum > 20) {
msg = "---\nValidation failed. Commit exceeds line limit (" sum " lines).\n"
msg = msg "Are you sure this is the smallest commit size?\n"
msg = msg "Can you break this into smaller commits?\n"
msg = msg "- reference Rule 4 from RULES.md"
if (length(newfiles) > 0) {
msg = msg "\n\nNew file(s) detected:\n" newfiles
msg = msg "\nWas this (these) supposed to be a move/rename?\n"
msg = msg "- If yes: investigate why git did not detect it (use git diff -M)\n"
msg = msg "- If move + contribution: split into 2 commits per Rule 4 (move first, then contribute)"
}
print msg > "/dev/stderr"
exit 1
}
}
'What this validates:
- Counts lines changed in code files (excludes
.md) - Exempts file deletions (no line limit)
- Exempts file renames/moves (detected via
-Mflag) - If a new file addition fails validation, prompts to check if it should have been a rename
If the command exits with an error, the commit is too large.
When a commit passes verification and is committed:
- Mark the commit as complete in
PLAN.mdby adding a status indicator - Proceed to the next commit
Example PLAN.md update:
### Commit 3: `renderer.py` - Update loop logic [COMPLETE]If verification fails due to exceeding 20 lines:
git reset HEADto unstage- Split the changes into smaller commits (see Splitting Commits below)
- Update
PLAN.mdto document the split - Re-stage and verify each smaller commit
If a planned commit no longer applies or doesn't make sense:
- Do not attempt the commit
- Update
PLAN.mdto mark the commit as redesigned - Add new commit entries with the original number + letter suffix
- Continue with the redesigned commits
When splitting is required, always prefer depth-wise splitting over length-wise splitting.
Large commits typically exceed the line limit because of closures (blocks like { ... }, scriptblocks, function bodies, class definitions). Splitting by line count often breaks logical units. Instead, split by depth:
- First commit: Create the outer shape with a placeholder
- Following commits: Add depth to the enclosed block
A 45-line scriptblock was staged:
Add-ScriptMethods $Object @{
Method1 = {
# 15 lines of logic
}
Method2 = {
# 12 lines of logic
}
Method3 = {
# 10 lines of logic
}
}Wrong (length-wise): Split at line 20, breaking Method1 mid-body.
Correct (depth-wise):
Commit 5a: Object.ps1 - Add method block shape
Add-ScriptMethods $Object @{
Method1 = {
# WIP
}
Method2 = {
# WIP
}
Method3 = {
# WIP
}
}Commit 5b: Object.ps1 - Implement Method1
Commit 5c: Object.ps1 - Implement Method2
Commit 5d: Object.ps1 - Implement Method3
The # WIP placeholder can be replaced with other shape lines (parameter declarations, return statements) if the commit stays under the line limit.
Document the split with lettered sub-commits:
### Commit 5: [SPLIT - see 5a-5d]
> Original exceeded 20 lines due to closure depth. Split into shape + implementations.
### Commit 5a: `Object.ps1` - Add method block shape
```diff
+Add-ScriptMethods $Object @{
+ Method1 = {
+ # WIP
+ }
+ Method2 = {
+ # WIP
+ }
+ Method3 = {
+ # WIP
+ }
+} Method1 = {
- # WIP
+ param($Arg)
+ # actual implementation
+ return $result
}Replace the single commit task with lettered sub-tasks:
Before:
Commit 5: Object.ps1 - Add methods, in compliance with RULES.md
After:
Commit 5a: Object.ps1 - Add method block shape, in compliance with RULES.md
Commit 5b: Object.ps1 - Implement Method1, in compliance with RULES.md
Commit 5c: Object.ps1 - Implement Method2, in compliance with RULES.md
Commit 5d: Object.ps1 - Implement Method3, in compliance with RULES.md
| Strategy | When to Use | Priority |
|---|---|---|
| Depth-based | Closures, blocks, nested structures | Preferred |
| Logical grouping | Related lines that form a coherent unit | Secondary |
| Sequential flow | Changes that must happen in order | Secondary |
When a commit approach is fundamentally wrong:
Update the task description and PLAN.md entry:
Before:
Commit 5: Config.ps1 - Replace fragment list
After:
Commit 5: Config.ps1 - Update fragment names in mapping
If the change requires multiple new commits:
Update PLAN.md:
### Commit 5: [REDESIGNED]
> Original approach was incompatible with existing cache structure.
> Split into Commits 5a-5d below.
### Commit 5a: `Config.ps1` - Add new fragment discovery
...Update task list:
Commit 5: [REDESIGNED - see 5a-5d]
Commit 5a: Config.ps1 - Add new fragment discovery, in compliance with RULES.md
Commit 5b: Config.ps1 - Update layer mappings, in compliance with RULES.md
Commit 5c: Config.ps1 - Remove old fragment list, in compliance with RULES.md
Commit 5d: Config.ps1 - Update cache initialization, in compliance with RULES.md
Each significant work unit should have an associated implementation branch.
Branch naming: Use a descriptive prefix:
feature/<name>- New functionalityrefactor/<name>- Code restructuringfix/<name>- Bug fixes
Workflow:
- Complete implementation on branch
- [Requires user approval] Create
PR.mddetailing the changes - [Requires user approval] Submit PR to GitHub using
ghCLI - [Requires user approval] Merge with merge commit (to track original PR number)
PR.md:
- Located in repository root (untracked)
- Removed after PR submission (do not commit)
Merge command:
gh pr merge <PR_NUMBER> --merge --delete-branchNote: If the user performs a code review at any point, proceed to Rule 6.
When the user performs a code review and requests changes:
- Create a review document capturing the requested changes
- Return to Rule 0 - treat the review feedback as a new discovery/design task
- Iterate through Rule 0 until the approach is clear
- Proceed to Rule 1 - append new commits to the existing
PLAN.md - Continue through Rules 3-5 with the new commits
Important: Rule 6 adds new commits to address review feedback. It does not modify, split, or redesign existing commits—that's Rule 4's domain. The review cycle flows through Rule 0 → Rule 1 (append) → Rule 2 → Rule 3 → Rule 4 → Rule 5.
Review document characteristics:
- Captures specific feedback from the code review
- Identifies what needs to change and why
- May contain illustrative diffs (authoritative diffs go in
PLAN.md) - May propose solutions or alternatives
- Serves as input for the appended plan
PLAN.md append format:
---
## Code Review Changes (Review #1)
### Commit 57: `Network.ps1` - Fix WaitForSSH duplication
```diff
...Reason: Code review identified redundant method.
This cycle can repeat multiple times until the PR is approved.
When starting implementation of a PLAN.md, create a task list as follows:
The first task must always be:
Review RULES.md - initial review before starting
Create one task per commit in the plan. Format:
Commit <N>: <file> - <description>, in compliance with RULES.md
Examples:
Commit 1: renderer.py - Add fragment discovery function, in compliance with RULES.mdCommit 18: Create Logger.ps1 - module shape, in compliance with RULES.md
Insert a review checkpoint every 10 commits:
Review RULES.md - checkpoint after commit <N>
Place these after commits 10, 20, 30, 40, 50, etc.
1. Review RULES.md - initial review before starting
2. Commit 1: ...
3. Commit 2: ...
...
11. Commit 10: ...
12. Review RULES.md - checkpoint after commit 10
13. Commit 11: ...
...
For each commit task:
- Mark as in_progress before starting
- Make the code change (5-20 lines max)
- Stage the change with
git add - Verify compliance with the pre-commit check (Rule 4)
- Commit with descriptive message
- Mark as completed in task list immediately after commit
- Mark as completed in
PLAN.md(Rule 4)
For review tasks:
- Mark as in_progress
- Re-read RULES.md completely
- Verify recent commits followed the rules
- Mark as completed
┌───────────────────────────────────────────────────────────────────────┐
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Rule 0 │───▶│ Rule 1 │───▶│ Rule 2 │───▶│ Rule 3 │ │
│ │ Discovery│ │ Plan │ │ Tasks │ │ Micro- │ │
│ │ & Design │ │ │ │ │ │ commits │ │
│ └──────────┘ └──────────┘ └──────────┘ └────┬─────┘ │
│ ▲ │ │
│ │ ▼ │
│ │ ┌──────────┐ │
│ │ │ Rule 4 │ │
│ │ │ Verify & │ │
│ │ │ Split │ │
│ │ └────┬─────┘ │
│ │ │ │
│ │ ▼ │
│ │ ┌──────────┐ │
│ │ │ Rule 5 │ │
│ │ │ Branch & │ │
│ │ │ PR │ │
│ │ └────┬─────┘ │
│ │ │ │
│ │ ┌──────────┐ │ │
│ └───────────────────│ Rule 6 │◀──────────────┘ │
│ (append) │ Review │ (if review requested) │
│ │ Cycle │ │
│ └──────────┘ │
│ │
└───────────────────────────────────────────────────────────────────────┘
Rules 0-4 exist to minimize review load and ensure thoughtful implementation.
Rule 0 ensures we understand the problem before committing to a solution.
Rules 1-4 ensure commits are planned, tracked, and reviewable:
| Change Type | Naturally Digestible? | Microcommit Required? |
|---|---|---|
| File deletion | Yes | No |
| File rename/move | Yes | No |
| Markdown files | Yes | No |
| Any code change | No | Yes |
Commits are not PRs. A commit should take less than 5 seconds to review. If understanding a commit takes more than a minute, the commit sucks.
- File operations are human-readable because content doesn't matter - only the path
- Documentation is human-readable by design
- Source code is not human-readable - changes must be small and obvious
Rule 6 ensures code review feedback is handled with the same rigor as initial implementation, cycling back through the full workflow to append new commits.
1. [completed] Review RULES.md - initial review before starting
2. [completed] Commit 1: renderer.py - Add discover_fragments
3. [completed] Commit 2: renderer.py - Update create_environment
4. [in_progress] Commit 3: renderer.py - Update get_environment
5. [pending] Commit 4a: renderer.py - Add method block shape
6. [pending] Commit 4b: renderer.py - Implement first method
7. [pending] Commit 4c: renderer.py - Implement second method
8. [pending] Commit 5: renderer.py - Update render_script
...
13. [pending] Review RULES.md - checkpoint after commit 10
...
Note: Commit 4 was split into 4a-4c using depth-wise splitting because the original exceeded 20 lines due to nested closures.