class-ai-agent 1.2.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.
Files changed (93) hide show
  1. package/.claude/CLAUDE.md +155 -0
  2. package/.claude/agents/backend.md +395 -0
  3. package/.claude/agents/code-reviewer.md +110 -0
  4. package/.claude/agents/copywriter-seo.md +236 -0
  5. package/.claude/agents/frontend.md +384 -0
  6. package/.claude/agents/project-manager.md +201 -0
  7. package/.claude/agents/qa.md +221 -0
  8. package/.claude/agents/security-auditor.md +143 -0
  9. package/.claude/agents/systems-architect.md +211 -0
  10. package/.claude/agents/test-engineer.md +123 -0
  11. package/.claude/agents/ui-ux-designer.md +210 -0
  12. package/.claude/commands/build.md +132 -0
  13. package/.claude/commands/debug.md +242 -0
  14. package/.claude/commands/deploy.md +40 -0
  15. package/.claude/commands/fix-issue.md +42 -0
  16. package/.claude/commands/plan.md +125 -0
  17. package/.claude/commands/review.md +50 -0
  18. package/.claude/commands/simplify.md +222 -0
  19. package/.claude/commands/spec.md +95 -0
  20. package/.claude/commands/test.md +214 -0
  21. package/.claude/references/accessibility-checklist.md +174 -0
  22. package/.claude/references/performance-checklist.md +150 -0
  23. package/.claude/references/security-checklist.md +94 -0
  24. package/.claude/references/testing-patterns.md +183 -0
  25. package/.claude/rules/api-conventions.md +79 -0
  26. package/.claude/rules/clean-code.md +205 -0
  27. package/.claude/rules/code-style.md +86 -0
  28. package/.claude/rules/database.md +60 -0
  29. package/.claude/rules/error-handling.md +92 -0
  30. package/.claude/rules/git-workflow.md +77 -0
  31. package/.claude/rules/monitoring.md +311 -0
  32. package/.claude/rules/naming-conventions.md +260 -0
  33. package/.claude/rules/project-structure.md +65 -0
  34. package/.claude/rules/security.md +90 -0
  35. package/.claude/rules/system-design.md +162 -0
  36. package/.claude/rules/tech-stack.md +456 -0
  37. package/.claude/rules/testing.md +104 -0
  38. package/.claude/settings.json +14 -0
  39. package/.claude/skills/code-review/SKILL.md +208 -0
  40. package/.claude/skills/deploy/SKILL.md +68 -0
  41. package/.claude/skills/deploy/deploy.md +735 -0
  42. package/.claude/skills/incremental-implementation/SKILL.md +210 -0
  43. package/.claude/skills/security-review/SKILL.md +71 -0
  44. package/.claude/skills/tdd/SKILL.md +217 -0
  45. package/.cursor/CURSOR.md +112 -0
  46. package/.cursor/agents/backend.md +395 -0
  47. package/.cursor/agents/code-reviewer.md +110 -0
  48. package/.cursor/agents/copywriter-seo.md +236 -0
  49. package/.cursor/agents/frontend.md +384 -0
  50. package/.cursor/agents/project-manager.md +201 -0
  51. package/.cursor/agents/qa.md +221 -0
  52. package/.cursor/agents/security-auditor.md +143 -0
  53. package/.cursor/agents/systems-architect.md +211 -0
  54. package/.cursor/agents/test-engineer.md +123 -0
  55. package/.cursor/agents/ui-ux-designer.md +210 -0
  56. package/.cursor/commands/build.md +132 -0
  57. package/.cursor/commands/debug.md +242 -0
  58. package/.cursor/commands/deploy.md +40 -0
  59. package/.cursor/commands/fix-issue.md +42 -0
  60. package/.cursor/commands/plan.md +125 -0
  61. package/.cursor/commands/review.md +50 -0
  62. package/.cursor/commands/simplify.md +222 -0
  63. package/.cursor/commands/spec.md +95 -0
  64. package/.cursor/commands/test.md +214 -0
  65. package/.cursor/references/accessibility-checklist.md +174 -0
  66. package/.cursor/references/performance-checklist.md +150 -0
  67. package/.cursor/references/security-checklist.md +94 -0
  68. package/.cursor/references/testing-patterns.md +183 -0
  69. package/.cursor/rules/api-conventions.mdc +85 -0
  70. package/.cursor/rules/clean-code.mdc +211 -0
  71. package/.cursor/rules/code-style.mdc +92 -0
  72. package/.cursor/rules/cursor-overview.mdc +35 -0
  73. package/.cursor/rules/database.mdc +66 -0
  74. package/.cursor/rules/error-handling.mdc +98 -0
  75. package/.cursor/rules/git-workflow.mdc +83 -0
  76. package/.cursor/rules/monitoring.mdc +317 -0
  77. package/.cursor/rules/naming-conventions.mdc +266 -0
  78. package/.cursor/rules/project-structure.mdc +71 -0
  79. package/.cursor/rules/security.mdc +95 -0
  80. package/.cursor/rules/system-design.mdc +168 -0
  81. package/.cursor/rules/tech-stack.mdc +462 -0
  82. package/.cursor/rules/testing.mdc +110 -0
  83. package/.cursor/settings.json +8 -0
  84. package/.cursor/skills/code-review/SKILL.md +208 -0
  85. package/.cursor/skills/deploy/SKILL.md +68 -0
  86. package/.cursor/skills/deploy/deploy.md +735 -0
  87. package/.cursor/skills/incremental-implementation/SKILL.md +210 -0
  88. package/.cursor/skills/security-review/SKILL.md +71 -0
  89. package/.cursor/skills/tdd/SKILL.md +217 -0
  90. package/AGENTS.md +11 -0
  91. package/README.md +405 -0
  92. package/bin/class-ai-agent.cjs +176 -0
  93. package/package.json +38 -0
@@ -0,0 +1,242 @@
1
+ ---
2
+ name: debug
3
+ description: Systematic debugging and error recovery — find root cause, not symptoms
4
+ ---
5
+
6
+ # /debug — Debugging & Error Recovery
7
+
8
+ > "Fix root causes, not symptoms."
9
+
10
+ ## Purpose
11
+
12
+ Systematically diagnose and fix errors. Stop feature work, preserve evidence, find root cause, add guards, then resume.
13
+
14
+ ## The Stop-the-Line Rule
15
+
16
+ When unexpected failures occur:
17
+
18
+ 1. **STOP** — Halt feature work immediately
19
+ 2. **PRESERVE** — Save error messages, logs, stack traces
20
+ 3. **DIAGNOSE** — Follow the 6-step triage process
21
+ 4. **FIX** — Address root cause, not symptoms
22
+ 5. **GUARD** — Add tests to prevent recurrence
23
+ 6. **RESUME** — Only continue after verification
24
+
25
+ ---
26
+
27
+ ## 6-Step Triage Process
28
+
29
+ ### Step 1: Reproduce
30
+
31
+ Make the failure happen reliably.
32
+
33
+ ```bash
34
+ # Run the failing test
35
+ npm test -- --grep "failing test name"
36
+
37
+ # Or reproduce manually with specific steps
38
+ ```
39
+
40
+ **If not reproducible**, investigate:
41
+ - Timing/race conditions
42
+ - Environment differences (dev vs CI)
43
+ - State leakage between tests
44
+ - Random/flaky behavior
45
+
46
+ ### Step 2: Localize
47
+
48
+ Identify which layer fails:
49
+
50
+ | Layer | Symptoms |
51
+ |-------|----------|
52
+ | **UI/Frontend** | Render errors, missing elements, wrong display |
53
+ | **API/Backend** | HTTP errors, wrong responses, timeout |
54
+ | **Database** | Query errors, constraint violations, missing data |
55
+ | **Build** | Compilation errors, missing dependencies |
56
+ | **External** | Third-party API failures, network issues |
57
+ | **Test itself** | Flaky assertion, wrong expectations |
58
+
59
+ **Use `git bisect` for regressions:**
60
+
61
+ ```bash
62
+ git bisect start
63
+ git bisect bad HEAD
64
+ git bisect good <last-known-good-commit>
65
+ # Git will guide you to the breaking commit
66
+ ```
67
+
68
+ ### Step 3: Reduce
69
+
70
+ Strip away unrelated elements:
71
+
72
+ ```javascript
73
+ // Original complex failing code
74
+ const result = await complexFunction(
75
+ await getConfig(),
76
+ await fetchData(),
77
+ processOptions(opts)
78
+ );
79
+
80
+ // Reduced to find the problem
81
+ const config = await getConfig();
82
+ console.log('config:', config); // Check each step
83
+
84
+ const data = await fetchData();
85
+ console.log('data:', data);
86
+
87
+ const result = await complexFunction(config, data, opts);
88
+ ```
89
+
90
+ ### Step 4: Fix Root Cause
91
+
92
+ **Fix the actual problem, not the symptom:**
93
+
94
+ | Symptom | Bad Fix | Good Fix |
95
+ |---------|---------|----------|
96
+ | Duplicate list items | Dedupe in UI | Fix query returning duplicates |
97
+ | Null reference error | Add `?.` everywhere | Ensure data is loaded before access |
98
+ | Slow API response | Increase timeout | Optimize the query |
99
+ | Flaky test | Add retry logic | Fix the race condition |
100
+
101
+ ### Step 5: Guard Against Recurrence
102
+
103
+ Write a test that catches this specific failure:
104
+
105
+ ```javascript
106
+ it('should not return duplicate items (regression #123)', async () => {
107
+ // Setup that caused the original bug
108
+ await createOrder({ items: [item, item] });
109
+
110
+ // The query that was returning duplicates
111
+ const result = await getOrderItems();
112
+
113
+ // Guard: ensure no duplicates
114
+ const ids = result.map(r => r.id);
115
+ expect(ids).toEqual([...new Set(ids)]);
116
+ });
117
+ ```
118
+
119
+ ### Step 6: Verify End-to-End
120
+
121
+ ```bash
122
+ # Run the specific test
123
+ npm test -- --grep "regression"
124
+
125
+ # Run full test suite
126
+ npm test
127
+
128
+ # Run build
129
+ npm run build
130
+
131
+ # Manual verification if needed
132
+ ```
133
+
134
+ ---
135
+
136
+ ## Error-Specific Triage Trees
137
+
138
+ ### Test Failure
139
+
140
+ ```
141
+ Test fails
142
+ ├── Assertion error
143
+ │ ├── Expected value wrong → Check test expectation
144
+ │ └── Actual value wrong → Debug implementation
145
+ ├── Runtime error
146
+ │ ├── ReferenceError → Check imports, variable names
147
+ │ ├── TypeError → Check types, null checks
148
+ │ └── NetworkError → Check test setup, mocks
149
+ └── Timeout
150
+ ├── Async not awaited → Add missing await
151
+ └── Infinite loop → Check loop conditions
152
+ ```
153
+
154
+ ### Build Error
155
+
156
+ ```
157
+ Build fails
158
+ ├── TypeScript error
159
+ │ ├── Type mismatch → Fix types or add assertion
160
+ │ └── Missing import → Add import statement
161
+ ├── Module not found
162
+ │ ├── Package missing → npm install
163
+ │ └── Path wrong → Fix import path
164
+ └── Syntax error
165
+ └── Check recent changes → git diff
166
+ ```
167
+
168
+ ### Runtime Error
169
+
170
+ ```
171
+ Runtime error
172
+ ├── API returns error
173
+ │ ├── 4xx → Client issue, check request
174
+ │ └── 5xx → Server issue, check logs
175
+ ├── CORS error
176
+ │ └── Check server CORS config
177
+ ├── Undefined/null
178
+ │ └── Add loading state or null check
179
+ └── Network timeout
180
+ └── Check connectivity, increase timeout
181
+ ```
182
+
183
+ ---
184
+
185
+ ## Debugging Tools
186
+
187
+ ### Console Logging (Temporary)
188
+
189
+ ```javascript
190
+ // Add strategic logs
191
+ console.log('[DEBUG] Input:', input);
192
+ console.log('[DEBUG] After transform:', result);
193
+
194
+ // Remove all debug logs before commit
195
+ git diff | grep console.log
196
+ ```
197
+
198
+ ### Node Inspector
199
+
200
+ ```bash
201
+ # Debug Node.js
202
+ node --inspect-brk src/index.js
203
+
204
+ # Debug tests
205
+ node --inspect-brk node_modules/.bin/vitest
206
+ ```
207
+
208
+ ### Git Bisect
209
+
210
+ ```bash
211
+ git bisect start
212
+ git bisect bad # Current commit is broken
213
+ git bisect good abc123 # This commit was working
214
+ # Test each commit git suggests
215
+ git bisect good # or git bisect bad
216
+ git bisect reset # When done
217
+ ```
218
+
219
+ ---
220
+
221
+ ## Common Rationalizations (Avoid These)
222
+
223
+ | Excuse | Reality |
224
+ |--------|---------|
225
+ | "It works on my machine" | Environment differences are bugs |
226
+ | "It's just flaky" | Flaky tests have root causes |
227
+ | "Let's just retry" | Retries hide real problems |
228
+ | "It's a third-party issue" | Still need to handle gracefully |
229
+ | "We'll fix it later" | Tech debt compounds |
230
+
231
+ ---
232
+
233
+ ## Output
234
+
235
+ - Root cause identified and fixed
236
+ - Regression test added
237
+ - All tests passing
238
+ - Clear commit message explaining the fix
239
+
240
+ ## Next Step
241
+
242
+ After fixing, continue with `/build` or run `/review` for verification.
@@ -0,0 +1,40 @@
1
+ # Deploy Command
2
+
3
+ ## Description
4
+ Deploy the application to the target environment.
5
+
6
+ ## Usage
7
+ Tell Claude: "Run the deploy command" or "Deploy to [environment]"
8
+
9
+ ## Steps
10
+
11
+ ### 1. Pre-deploy Checklist
12
+ - [ ] All tests pass (`npm test`)
13
+ - [ ] No linting errors (`npm run lint`)
14
+ - [ ] Environment variables are configured
15
+ - [ ] Database migrations are ready
16
+
17
+ ### 2. Build
18
+ ```bash
19
+ npm run build
20
+ ```
21
+
22
+ ### 3. Deploy
23
+ ```bash
24
+ # Development
25
+ npm run deploy:dev
26
+
27
+ # Production
28
+ npm run deploy:prod
29
+ ```
30
+
31
+ ### 4. Post-deploy Verification
32
+ - Check application health endpoint
33
+ - Verify logs for errors
34
+ - Run smoke tests
35
+
36
+ ## Rollback
37
+ If deployment fails:
38
+ ```bash
39
+ npm run rollback
40
+ ```
@@ -0,0 +1,42 @@
1
+ # Fix Issue Command
2
+
3
+ ## Description
4
+ Analyze and fix a reported bug or issue systematically.
5
+
6
+ ## Usage
7
+ Tell Claude: "Fix issue: [describe the issue]" or "Fix bug in [file/module]"
8
+
9
+ ## Process
10
+
11
+ ### 1. Understand the Issue
12
+ - Read the error message or bug description carefully
13
+ - Identify the affected component(s)
14
+ - Reproduce the issue locally if possible
15
+
16
+ ### 2. Root Cause Analysis
17
+ - Check recent git changes: `git log --oneline -20`
18
+ - Review affected files
19
+ - Look for related tests that may reveal expected behavior
20
+
21
+ ### 3. Plan the Fix
22
+ - Identify the minimal change needed
23
+ - Consider side effects on other components
24
+ - Update or add tests to cover the fix
25
+
26
+ ### 4. Implement
27
+ - Make the targeted fix
28
+ - Ensure code follows `.claude/rules/code-style.md`
29
+ - Handle errors per `.claude/rules/error-handling.md`
30
+
31
+ ### 5. Verify
32
+ - Run relevant tests: `npm test -- --testPathPattern=[affected]`
33
+ - Run full test suite: `npm test`
34
+ - Check linting: `npm run lint`
35
+
36
+ ### 6. Commit
37
+ Follow `.claude/rules/git-workflow.md`:
38
+ ```
39
+ fix: [short description of the fix]
40
+
41
+ Closes #[issue-number]
42
+ ```
@@ -0,0 +1,125 @@
1
+ ---
2
+ name: plan
3
+ description: Decompose specs into small, verifiable tasks with dependency ordering
4
+ ---
5
+
6
+ # /plan — Planning & Task Breakdown
7
+
8
+ > "Vertical slices, not horizontal layers."
9
+
10
+ ## Purpose
11
+
12
+ Transform a specification into an ordered list of small, verifiable tasks. Each task delivers end-to-end functionality.
13
+
14
+ ## Prerequisites
15
+
16
+ - A specification exists (`SPEC.md` or described requirements)
17
+ - Understanding of the codebase structure
18
+
19
+ ## Workflow
20
+
21
+ ### Phase 1: Analysis (Read-Only)
22
+
23
+ 1. **Read the spec** — Understand objectives and acceptance criteria
24
+ 2. **Survey the codebase** — Identify relevant files, patterns, and integration points
25
+ 3. **Map dependencies** — Which components depend on which?
26
+
27
+ > **Do NOT modify code during planning.**
28
+
29
+ ### Phase 2: Vertical Slicing
30
+
31
+ Break work into **vertical slices** — each slice delivers complete functionality through all layers:
32
+
33
+ ```
34
+ ❌ Horizontal (anti-pattern):
35
+ Task 1: Create all DB models
36
+ Task 2: Create all API routes
37
+ Task 3: Create all UI components
38
+
39
+ ✅ Vertical (correct):
40
+ Task 1: User can create a task (DB + API + UI)
41
+ Task 2: User can view task list (DB + API + UI)
42
+ Task 3: User can mark task complete (DB + API + UI)
43
+ ```
44
+
45
+ ### Phase 3: Task Definition
46
+
47
+ Each task must include:
48
+
49
+ ```markdown
50
+ ## Task: [Short description]
51
+
52
+ **Objective**: [What this achieves]
53
+
54
+ **Files to modify**:
55
+ - `src/models/task.ts`
56
+ - `src/routes/tasks.ts`
57
+ - `src/components/TaskList.tsx`
58
+
59
+ **Acceptance Criteria**:
60
+ - [ ] User can [action]
61
+ - [ ] [Validation] is enforced
62
+ - [ ] Test covers [scenario]
63
+
64
+ **Dependencies**: [Task IDs this depends on]
65
+
66
+ **Verification**:
67
+ - [ ] Unit tests pass
68
+ - [ ] Integration test added
69
+ - [ ] Manual verification: [steps]
70
+ ```
71
+
72
+ ### Phase 4: Ordering
73
+
74
+ Order tasks by:
75
+ 1. **Foundation first** — DB models, types, shared utilities
76
+ 2. **Risk-first** — Tackle uncertain/complex items early
77
+ 3. **Dependencies** — Respect the dependency graph
78
+ 4. **Quick wins** — Early momentum with smaller tasks
79
+
80
+ ### Phase 5: Checkpoints
81
+
82
+ Insert checkpoints between major phases:
83
+
84
+ ```markdown
85
+ ---
86
+ ## Checkpoint: Core CRUD Complete
87
+
88
+ **Verify before proceeding**:
89
+ - [ ] All CRUD operations work
90
+ - [ ] Test coverage > 80%
91
+ - [ ] No console errors
92
+ - [ ] Performance acceptable
93
+
94
+ ---
95
+ ```
96
+
97
+ ## Output
98
+
99
+ Save to `tasks/` directory:
100
+
101
+ - `tasks/plan.md` — Full planning document with context
102
+ - `tasks/todo.md` — Actionable task checklist
103
+
104
+ ```markdown
105
+ # TODO: [Feature Name]
106
+
107
+ ## Phase 1: Foundation
108
+ - [ ] Task 1.1: [Description]
109
+ - [ ] Task 1.2: [Description]
110
+
111
+ ## Checkpoint: Foundation Complete
112
+
113
+ ## Phase 2: Core Features
114
+ - [ ] Task 2.1: [Description]
115
+ - [ ] Task 2.2: [Description]
116
+
117
+ ## Checkpoint: Core Complete
118
+
119
+ ## Phase 3: Polish
120
+ - [ ] Task 3.1: [Description]
121
+ ```
122
+
123
+ ## Next Step
124
+
125
+ After plan is approved, run `/build` to implement tasks incrementally.
@@ -0,0 +1,50 @@
1
+ # Review Command
2
+
3
+ ## Description
4
+ Perform a thorough code review of specified files or a pull request.
5
+
6
+ ## Usage
7
+ Tell Claude: "Review [file/PR/feature]" or "Do a code review of [changes]"
8
+
9
+ ## Review Checklist
10
+
11
+ ### Code Quality
12
+ - [ ] Code follows style guide (`.claude/rules/code-style.md`)
13
+ - [ ] No unnecessary complexity or duplication
14
+ - [ ] Functions are small and focused (single responsibility)
15
+ - [ ] Variable and function names are descriptive
16
+
17
+ ### Security
18
+ - [ ] No hardcoded secrets or credentials
19
+ - [ ] Input validation is present
20
+ - [ ] Authentication/authorization checks in place
21
+ - [ ] See `.claude/rules/security.md` for full checklist
22
+
23
+ ### Error Handling
24
+ - [ ] Errors are properly caught and handled
25
+ - [ ] Meaningful error messages
26
+ - [ ] No swallowed exceptions
27
+ - [ ] See `.claude/rules/error-handling.md`
28
+
29
+ ### Testing
30
+ - [ ] Unit tests cover new logic
31
+ - [ ] Edge cases are tested
32
+ - [ ] Tests are readable and maintainable
33
+ - [ ] See `.claude/rules/testing.md`
34
+
35
+ ### Database
36
+ - [ ] Queries are optimized (no N+1)
37
+ - [ ] Transactions used where appropriate
38
+ - [ ] See `.claude/rules/database.md`
39
+
40
+ ### API
41
+ - [ ] Endpoints follow REST conventions
42
+ - [ ] Request/response schemas are documented
43
+ - [ ] See `.claude/rules/api-conventions.md`
44
+
45
+ ## Output Format
46
+ Provide feedback as:
47
+ - 🔴 **Critical** — Must fix before merge
48
+ - 🟡 **Warning** — Should fix, potential issue
49
+ - 🟢 **Suggestion** — Nice to have improvement
50
+ - ✅ **Good** — Highlight what's done well
@@ -0,0 +1,222 @@
1
+ ---
2
+ name: simplify
3
+ description: Reduce complexity without changing behavior — code simplification
4
+ ---
5
+
6
+ # /simplify — Code Simplification
7
+
8
+ > "Complexity is the enemy of execution."
9
+
10
+ ## Purpose
11
+
12
+ Simplify code for clarity and maintainability. Reduce complexity **without changing behavior**.
13
+
14
+ ## When to Use
15
+
16
+ - After `/review` identifies complexity issues
17
+ - When code is hard to understand
18
+ - Before adding new features to tangled code
19
+ - During tech debt cleanup sprints
20
+
21
+ ## Principles
22
+
23
+ ### Chesterton's Fence
24
+
25
+ > Before removing something, understand why it exists.
26
+
27
+ Don't delete code just because it looks unnecessary. Investigate:
28
+ - Git history: `git log -p -- path/to/file`
29
+ - Related tests
30
+ - Comments or documentation
31
+ - Ask team members if unsure
32
+
33
+ ### Rule of 500
34
+
35
+ If a function, file, or class exceeds ~500 lines, it likely needs splitting.
36
+
37
+ ---
38
+
39
+ ## Workflow
40
+
41
+ ### Step 1: Identify Target
42
+
43
+ ```bash
44
+ # Recently modified complex code
45
+ git diff --stat HEAD~10
46
+
47
+ # Or specify scope
48
+ # "Simplify the OrderService class"
49
+ ```
50
+
51
+ ### Step 2: Understand Before Changing
52
+
53
+ 1. **Read the code** — What does it do?
54
+ 2. **Check tests** — What behaviors are verified?
55
+ 3. **Trace callers** — Who uses this code?
56
+ 4. **Note edge cases** — Any special handling?
57
+
58
+ ### Step 3: Identify Opportunities
59
+
60
+ | Pattern | Simplification |
61
+ |---------|---------------|
62
+ | Deep nesting (> 3 levels) | Guard clauses, extract helpers |
63
+ | Long functions (> 30 lines) | Split by responsibility |
64
+ | Nested ternaries | `if/else` or `switch` |
65
+ | Unclear names | Rename for clarity |
66
+ | Duplicated code | Extract shared function |
67
+ | Dead code | Remove entirely |
68
+ | Complex conditionals | Extract to named function |
69
+ | Magic numbers | Named constants |
70
+
71
+ ### Step 4: Apply Incrementally
72
+
73
+ **One change at a time:**
74
+
75
+ ```javascript
76
+ // Before: Deep nesting
77
+ function processOrder(order) {
78
+ if (order) {
79
+ if (order.items.length > 0) {
80
+ if (order.status === 'pending') {
81
+ // ... actual logic buried here
82
+ }
83
+ }
84
+ }
85
+ }
86
+
87
+ // After: Guard clauses
88
+ function processOrder(order) {
89
+ if (!order) return;
90
+ if (order.items.length === 0) return;
91
+ if (order.status !== 'pending') return;
92
+
93
+ // ... actual logic at top level
94
+ }
95
+ ```
96
+
97
+ **Run tests after each change.**
98
+
99
+ ### Step 5: Validate
100
+
101
+ ```bash
102
+ # All tests pass
103
+ npm test
104
+
105
+ # Build succeeds
106
+ npm run build
107
+
108
+ # Behavior unchanged (manual check if needed)
109
+ ```
110
+
111
+ ### Step 6: If Tests Fail
112
+
113
+ **Revert immediately.** Don't debug while mid-simplification.
114
+
115
+ ```bash
116
+ git checkout -- .
117
+ ```
118
+
119
+ Then:
120
+ 1. Reassess the change
121
+ 2. Make a smaller change
122
+ 3. Or add missing tests first
123
+
124
+ ---
125
+
126
+ ## Common Simplifications
127
+
128
+ ### Extract Guard Clauses
129
+
130
+ ```javascript
131
+ // Before
132
+ function getDiscount(user) {
133
+ if (user) {
134
+ if (user.membership === 'premium') {
135
+ return 0.2;
136
+ } else {
137
+ return 0.1;
138
+ }
139
+ }
140
+ return 0;
141
+ }
142
+
143
+ // After
144
+ function getDiscount(user) {
145
+ if (!user) return 0;
146
+ if (user.membership === 'premium') return 0.2;
147
+ return 0.1;
148
+ }
149
+ ```
150
+
151
+ ### Extract Named Functions
152
+
153
+ ```javascript
154
+ // Before
155
+ const eligibleUsers = users.filter(u =>
156
+ u.age >= 18 && u.verified && !u.banned && u.subscription !== 'free'
157
+ );
158
+
159
+ // After
160
+ const isEligible = (user) =>
161
+ user.age >= 18 &&
162
+ user.verified &&
163
+ !user.banned &&
164
+ user.subscription !== 'free';
165
+
166
+ const eligibleUsers = users.filter(isEligible);
167
+ ```
168
+
169
+ ### Replace Nested Ternary
170
+
171
+ ```javascript
172
+ // Before
173
+ const status = isPaid ? (isShipped ? 'complete' : 'processing') : 'pending';
174
+
175
+ // After
176
+ function getOrderStatus(isPaid, isShipped) {
177
+ if (!isPaid) return 'pending';
178
+ if (!isShipped) return 'processing';
179
+ return 'complete';
180
+ }
181
+ ```
182
+
183
+ ### Remove Dead Code
184
+
185
+ ```javascript
186
+ // Before
187
+ function calculate(a, b) {
188
+ // const oldResult = legacyCalculate(a, b); // Commented out
189
+ const result = a + b;
190
+ // console.log('Debug:', result); // Debug log
191
+ return result;
192
+ }
193
+
194
+ // After
195
+ function calculate(a, b) {
196
+ return a + b;
197
+ }
198
+ ```
199
+
200
+ ---
201
+
202
+ ## Red Flags
203
+
204
+ Stop if you find yourself:
205
+
206
+ - Changing behavior while "simplifying"
207
+ - Unable to explain why code exists
208
+ - Simplifying without tests
209
+ - Making changes across unrelated files
210
+ - Creating new abstractions
211
+
212
+ ---
213
+
214
+ ## Output
215
+
216
+ - Simpler, clearer code
217
+ - All tests still passing
218
+ - Atomic commits with clear messages
219
+
220
+ ## Next Step
221
+
222
+ Run `/review` to verify improvements.