@lvlup-sw/exarchos 2.0.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 (153) hide show
  1. package/.claude-plugin/marketplace.json +22 -0
  2. package/.claude-plugin/plugin.json +17 -0
  3. package/.mcp.json +17 -0
  4. package/AGENTS.md +59 -0
  5. package/CLAUDE.md.template +62 -0
  6. package/LICENSE +202 -0
  7. package/README.md +258 -0
  8. package/commands/autocompact.md +37 -0
  9. package/commands/checkpoint.md +85 -0
  10. package/commands/cleanup.md +99 -0
  11. package/commands/debug.md +145 -0
  12. package/commands/delegate.md +56 -0
  13. package/commands/ideate.md +82 -0
  14. package/commands/plan.md +150 -0
  15. package/commands/refactor.md +139 -0
  16. package/commands/reload.md +37 -0
  17. package/commands/resume.md +130 -0
  18. package/commands/review.md +51 -0
  19. package/commands/sync-schemas.md +74 -0
  20. package/commands/synthesize.md +122 -0
  21. package/commands/tdd.md +58 -0
  22. package/dist/exarchos-cli.js +8828 -0
  23. package/dist/exarchos-mcp.js +50 -0
  24. package/hooks/hooks.json +53 -0
  25. package/package.json +59 -0
  26. package/rules/coding-standards.md +46 -0
  27. package/rules/mcp-tool-guidance.md +26 -0
  28. package/rules/pr-descriptions.md +12 -0
  29. package/rules/rm-safety.md +9 -0
  30. package/rules/skill-path-resolution.md +10 -0
  31. package/rules/tdd.md +41 -0
  32. package/rules/telemetry-awareness.md +9 -0
  33. package/scripts/assess-refactor-scope.sh +239 -0
  34. package/scripts/check-benchmark-regression.sh +229 -0
  35. package/scripts/check-coderabbit.sh +288 -0
  36. package/scripts/check-coverage-thresholds.sh +194 -0
  37. package/scripts/check-polish-scope.sh +245 -0
  38. package/scripts/check-property-tests.sh +167 -0
  39. package/scripts/check-tdd-compliance.sh +265 -0
  40. package/scripts/coderabbit-review-gate.sh +518 -0
  41. package/scripts/debug-review-gate.sh +201 -0
  42. package/scripts/extract-fix-tasks.sh +179 -0
  43. package/scripts/extract-task.sh +67 -0
  44. package/scripts/generate-traceability.sh +209 -0
  45. package/scripts/investigation-timer.sh +171 -0
  46. package/scripts/needs-schema-sync.sh +174 -0
  47. package/scripts/new-project.sh +103 -0
  48. package/scripts/post-delegation-check.sh +317 -0
  49. package/scripts/pre-synthesis-check.sh +440 -0
  50. package/scripts/reconcile-state.sh +346 -0
  51. package/scripts/reconstruct-stack.sh +432 -0
  52. package/scripts/review-diff.sh +63 -0
  53. package/scripts/review-verdict.sh +169 -0
  54. package/scripts/security-scan.sh +248 -0
  55. package/scripts/select-debug-track.sh +186 -0
  56. package/scripts/setup-worktree.sh +323 -0
  57. package/scripts/spec-coverage-check.sh +230 -0
  58. package/scripts/static-analysis-gate.sh +236 -0
  59. package/scripts/sync-labels.sh +122 -0
  60. package/scripts/validate-companion.sh +161 -0
  61. package/scripts/validate-dotnet-standards.sh +267 -0
  62. package/scripts/validate-installation.sh +101 -0
  63. package/scripts/validate-plugin.sh +223 -0
  64. package/scripts/validate-refactor.sh +234 -0
  65. package/scripts/validate-rm.sh +93 -0
  66. package/scripts/verify-delegation-saga.sh +240 -0
  67. package/scripts/verify-doc-links.sh +211 -0
  68. package/scripts/verify-ideate-artifacts.sh +296 -0
  69. package/scripts/verify-plan-coverage.sh +228 -0
  70. package/scripts/verify-review-triage.sh +219 -0
  71. package/scripts/verify-worktree-baseline.sh +159 -0
  72. package/scripts/verify-worktree.sh +84 -0
  73. package/settings.json +47 -0
  74. package/skills/brainstorming/SKILL.md +127 -0
  75. package/skills/brainstorming/references/design-template.md +65 -0
  76. package/skills/cleanup/SKILL.md +147 -0
  77. package/skills/cleanup/references/merge-verification.md +40 -0
  78. package/skills/debug/SKILL.md +204 -0
  79. package/skills/debug/references/hotfix-track.md +134 -0
  80. package/skills/debug/references/investigation-checklist.md +217 -0
  81. package/skills/debug/references/rca-template.md +150 -0
  82. package/skills/debug/references/state-schema.md +294 -0
  83. package/skills/debug/references/thorough-track.md +194 -0
  84. package/skills/debug/references/triage-questions.md +155 -0
  85. package/skills/debug/references/troubleshooting.md +47 -0
  86. package/skills/delegation/SKILL.md +150 -0
  87. package/skills/delegation/references/adaptive-orchestration.md +31 -0
  88. package/skills/delegation/references/agent-teams-saga.md +248 -0
  89. package/skills/delegation/references/fix-mode.md +74 -0
  90. package/skills/delegation/references/fixer-prompt.md +162 -0
  91. package/skills/delegation/references/implementer-prompt.md +322 -0
  92. package/skills/delegation/references/parallel-strategy.md +124 -0
  93. package/skills/delegation/references/pbt-patterns.md +172 -0
  94. package/skills/delegation/references/pr-fixes-mode.md +154 -0
  95. package/skills/delegation/references/state-management.md +51 -0
  96. package/skills/delegation/references/testing-patterns.md +129 -0
  97. package/skills/delegation/references/troubleshooting.md +33 -0
  98. package/skills/delegation/references/workflow-steps.md +127 -0
  99. package/skills/delegation/references/worktree-enforcement.md +64 -0
  100. package/skills/dotnet-standards/SKILL.md +269 -0
  101. package/skills/dotnet-standards/references/csharp-standards.md +120 -0
  102. package/skills/dotnet-standards/templates/.editorconfig +366 -0
  103. package/skills/dotnet-standards/templates/Directory.Build.props +56 -0
  104. package/skills/dotnet-standards/templates/Directory.Packages.props +69 -0
  105. package/skills/dotnet-standards/templates/global.json +6 -0
  106. package/skills/dotnet-standards/templates/nuget.config +9 -0
  107. package/skills/dotnet-standards/templates/stylecop.json +37 -0
  108. package/skills/git-worktrees/SKILL.md +255 -0
  109. package/skills/implementation-planning/SKILL.md +233 -0
  110. package/skills/implementation-planning/references/plan-document-template.md +42 -0
  111. package/skills/implementation-planning/references/spec-tracing-guide.md +51 -0
  112. package/skills/implementation-planning/references/task-template.md +43 -0
  113. package/skills/implementation-planning/references/testing-strategy-guide.md +88 -0
  114. package/skills/quality-review/SKILL.md +278 -0
  115. package/skills/quality-review/references/code-quality-checklist.md +159 -0
  116. package/skills/quality-review/references/review-report-template.md +65 -0
  117. package/skills/quality-review/references/security-checklist.md +79 -0
  118. package/skills/quality-review/references/typescript-standards.md +24 -0
  119. package/skills/refactor/COMMAND.md +67 -0
  120. package/skills/refactor/SKILL.md +198 -0
  121. package/skills/refactor/phases/auto-chain.md +262 -0
  122. package/skills/refactor/phases/brief.md +176 -0
  123. package/skills/refactor/phases/explore.md +132 -0
  124. package/skills/refactor/phases/overhaul-delegate.md +136 -0
  125. package/skills/refactor/phases/overhaul-plan.md +312 -0
  126. package/skills/refactor/phases/overhaul-review.md +304 -0
  127. package/skills/refactor/phases/polish-implement.md +349 -0
  128. package/skills/refactor/phases/polish-validate.md +218 -0
  129. package/skills/refactor/phases/update-docs.md +234 -0
  130. package/skills/refactor/references/brief-template.md +81 -0
  131. package/skills/refactor/references/doc-update-checklist.md +110 -0
  132. package/skills/refactor/references/explore-checklist.md +73 -0
  133. package/skills/refactor/references/overhaul-track.md +215 -0
  134. package/skills/refactor/references/polish-track.md +170 -0
  135. package/skills/shared/prompts/context-reading.md +58 -0
  136. package/skills/shared/prompts/report-format.md +54 -0
  137. package/skills/shared/prompts/tdd-requirements.md +39 -0
  138. package/skills/shepherd/SKILL.md +264 -0
  139. package/skills/shepherd/references/assess-checklist.md +124 -0
  140. package/skills/shepherd/references/fix-strategies.md +191 -0
  141. package/skills/spec-review/SKILL.md +229 -0
  142. package/skills/spec-review/references/review-checklist.md +60 -0
  143. package/skills/sync-schemas/SKILL.md +114 -0
  144. package/skills/sync-schemas/references/configuration.md +73 -0
  145. package/skills/synthesis/SKILL.md +129 -0
  146. package/skills/synthesis/references/pr-descriptions.md +87 -0
  147. package/skills/synthesis/references/synthesis-steps.md +109 -0
  148. package/skills/synthesis/references/troubleshooting.md +115 -0
  149. package/skills/validate-all-skills.sh +57 -0
  150. package/skills/validate-frontmatter.sh +237 -0
  151. package/skills/workflow-state/SKILL.md +210 -0
  152. package/skills/workflow-state/references/mcp-tool-reference.md +111 -0
  153. package/skills/workflow-state/references/phase-transitions.md +141 -0
@@ -0,0 +1,304 @@
1
+ # Overhaul Track: Review Phase
2
+
3
+ ## Purpose
4
+
5
+ Quality review with refactor-specific criteria for behavior preservation, regression detection, and goal verification.
6
+
7
+ ## Entry Conditions
8
+
9
+ - Track is `overhaul`
10
+ - Delegation phase complete
11
+ - All tasks complete
12
+ - Ready for review
13
+
14
+ ## Refactor-Specific Review Emphasis
15
+
16
+ Refactors require additional scrutiny beyond standard quality review because:
17
+ - Behavior must be preserved exactly (unless intentionally changed)
18
+ - Regressions are easy to introduce and hard to detect
19
+ - Brief goals must be explicitly verified
20
+
21
+ ## Behavior Preservation Checks
22
+
23
+ ### 1. Method Signature Analysis
24
+
25
+ | Check | Verify | Priority |
26
+ |-------|--------|----------|
27
+ | Parameter types unchanged | Same types or compatible widening | HIGH |
28
+ | Return types unchanged | Same type or compatible narrowing | HIGH |
29
+ | Parameter order preserved | No accidental reordering | HIGH |
30
+ | Optional parameters | Same defaults, same optionality | MEDIUM |
31
+ | Overloads preserved | All overloads still present | HIGH |
32
+
33
+ **Detection:**
34
+ ```bash
35
+ # Compare method signatures before/after
36
+ git diff main...HEAD -- "*.ts" | grep -E "^[+-].*function|^[+-].*class|^[+-].*interface"
37
+ ```
38
+
39
+ ### 2. Return Value Equivalence
40
+
41
+ | Aspect | Check For |
42
+ |--------|-----------|
43
+ | Same values | Identical return for same inputs |
44
+ | Same types | No implicit type changes |
45
+ | Same null behavior | Null/undefined handling unchanged |
46
+ | Same error conditions | Same inputs cause same errors |
47
+
48
+ **Verification approach:**
49
+ - Review test assertions for return values
50
+ - Check edge case handling
51
+ - Verify null/undefined paths unchanged
52
+
53
+ ### 3. Side Effect Preservation
54
+
55
+ | Side Effect | Verify Unchanged |
56
+ |-------------|-----------------|
57
+ | State mutations | Same state changes occur |
58
+ | Event emissions | Same events fired in same order |
59
+ | External calls | Same API/DB calls made |
60
+ | Logging | Same log outputs (unless intentional) |
61
+ | File operations | Same I/O patterns |
62
+
63
+ ### 4. Error Handling Consistency
64
+
65
+ | Check | Verify |
66
+ |-------|--------|
67
+ | Exception types | Same exceptions thrown |
68
+ | Exception conditions | Same inputs trigger errors |
69
+ | Error messages | Equivalent messaging |
70
+ | Catch behavior | Same errors caught/propagated |
71
+
72
+ ## Intentional Changes Documentation
73
+
74
+ If behavior changes are intentional, they MUST be:
75
+ 1. Documented in the brief goals
76
+ 2. Covered by updated tests
77
+ 3. Explicitly noted in review
78
+
79
+ **Intentional change checklist:**
80
+ - [ ] Change documented in brief
81
+ - [ ] Old behavior tests updated
82
+ - [ ] New behavior tests added
83
+ - [ ] Breaking change noted (if public API)
84
+
85
+ ## Regression Risk Assessment
86
+
87
+ Evaluate each area touched by refactor:
88
+
89
+ | Risk Level | Criteria | Action |
90
+ |------------|----------|--------|
91
+ | **HIGH** | Public API changes, core logic, data handling | Extra scrutiny, explicit test verification |
92
+ | **MEDIUM** | Internal interfaces, shared utilities | Verify dependent code paths |
93
+ | **LOW** | Private methods, isolated modules | Standard review |
94
+
95
+ ### Area-by-Area Assessment
96
+
97
+ For each file/component changed:
98
+
99
+ ```markdown
100
+ ## Regression Risk: <Component>
101
+
102
+ **Files touched:** `path/to/files`
103
+ **Risk level:** [HIGH | MEDIUM | LOW]
104
+
105
+ **Changed behavior (intentional):**
106
+ - [List any intentional changes]
107
+
108
+ **Regression indicators:**
109
+ - [ ] All existing tests pass
110
+ - [ ] No test assertions changed unexpectedly
111
+ - [ ] Dependent components verified
112
+ - [ ] Edge cases still covered
113
+ ```
114
+
115
+ ## Performance Considerations
116
+
117
+ Refactors should not degrade performance:
118
+
119
+ | Check | Verify |
120
+ |-------|--------|
121
+ | Algorithm complexity | No O(n) to O(n^2) regressions |
122
+ | Memory allocation | No excessive new allocations |
123
+ | Loop iterations | No added unnecessary iterations |
124
+ | Async patterns | No blocking where async expected |
125
+ | Database queries | No N+1 introductions |
126
+
127
+ **Red flags:**
128
+ - New loops inside existing loops
129
+ - Removed caching/memoization
130
+ - Added synchronous I/O
131
+ - Removed batching
132
+
133
+ ## Goal Verification
134
+
135
+ Every goal from the brief must be verified as achieved.
136
+
137
+ ### Goal Verification Matrix
138
+
139
+ | Brief Goal | Evidence | Status |
140
+ |------------|----------|--------|
141
+ | <goal 1> | <test/code reference> | [PASS/FAIL] |
142
+ | <goal 2> | <test/code reference> | [PASS/FAIL] |
143
+ | <goal 3> | <test/code reference> | [PASS/FAIL] |
144
+
145
+ **Goal verification process:**
146
+ 1. Re-read brief goals
147
+ 2. Find implementation of each
148
+ 3. Verify test coverage for each
149
+ 4. Document evidence
150
+
151
+ ## Review Checklist
152
+
153
+ ### Pre-Review
154
+ - [ ] Integration tests pass
155
+ - [ ] All tasks marked complete
156
+ - [ ] Brief goals accessible
157
+
158
+ ### Behavior Preservation
159
+ - [ ] Method signatures analyzed
160
+ - [ ] Return value equivalence checked
161
+ - [ ] Side effects reviewed
162
+ - [ ] Error handling verified
163
+ - [ ] Intentional changes documented
164
+
165
+ ### Regression Assessment
166
+ - [ ] Each component risk-assessed
167
+ - [ ] All existing tests pass (unchanged)
168
+ - [ ] No unexpected test changes
169
+ - [ ] Dependent code paths verified
170
+
171
+ ### Performance
172
+ - [ ] No obvious complexity regressions
173
+ - [ ] No removed optimizations
174
+ - [ ] Memory patterns acceptable
175
+ - [ ] Async patterns preserved
176
+
177
+ ### Goal Achievement
178
+ - [ ] All brief goals mapped to implementation
179
+ - [ ] Each goal has test coverage
180
+ - [ ] No goals left unaddressed
181
+
182
+ ### Quality Standards
183
+ - [ ] Standard quality review criteria (see quality-review/SKILL.md)
184
+ - [ ] SOLID principles maintained or improved
185
+ - [ ] Code readability maintained or improved
186
+
187
+ ## Report Template
188
+
189
+ ```markdown
190
+ ## Overhaul Review Report
191
+
192
+ ### Summary
193
+ - Status: [APPROVED | NEEDS_FIXES | BLOCKED]
194
+ - Track: overhaul
195
+ - Brief: <brief-name>
196
+ - Reviewed: [timestamp]
197
+
198
+ ### Behavior Preservation
199
+ | Area | Status | Notes |
200
+ |------|--------|-------|
201
+ | Method signatures | [OK | CHANGED] | |
202
+ | Return values | [OK | CHANGED] | |
203
+ | Side effects | [OK | CHANGED] | |
204
+ | Error handling | [OK | CHANGED] | |
205
+
206
+ ### Intentional Changes
207
+ [List any intentional behavior changes with justification]
208
+
209
+ ### Regression Risk Assessment
210
+ | Component | Risk | Status |
211
+ |-----------|------|--------|
212
+ | <component> | [HIGH | MED | LOW] | [PASS | CONCERN] |
213
+
214
+ ### Goal Verification
215
+ | Brief Goal | Achieved | Evidence |
216
+ |------------|----------|----------|
217
+ | <goal 1> | [YES | NO] | <reference> |
218
+
219
+ ### Findings
220
+
221
+ #### HIGH Priority (Must Fix)
222
+ 1. [Finding title]
223
+ - File: `path/to/file.ts:42`
224
+ - Issue: [Description]
225
+ - Fix: [Required change]
226
+
227
+ #### MEDIUM Priority (Should Fix)
228
+ 1. [Finding title]
229
+ - Issue: [Description]
230
+ - Suggestion: [Recommended change]
231
+
232
+ ### Verdict
233
+ [APPROVED] Refactor goals achieved, behavior preserved
234
+ [NEEDS_FIXES] Issues found, return to delegate
235
+ [BLOCKED] Fundamental problem requires brief revision
236
+ ```
237
+
238
+ ## State Updates
239
+
240
+ ### On Review Complete
241
+
242
+ **Record review results:**
243
+
244
+ ```
245
+ action: "set", featureId: "refactor-<slug>", updates: {
246
+ "reviews.overhaul": {
247
+ "status": "approved",
248
+ "behaviorPreserved": true,
249
+ "goalsVerified": true,
250
+ "regressionRisk": "low",
251
+ "timestamp": "<timestamp>"
252
+ }
253
+ }
254
+ ```
255
+
256
+ ### On Approval
257
+
258
+ **Advance to synthesize:**
259
+
260
+ ```
261
+ action: "set", featureId: "refactor-<slug>", phase: "synthesize"
262
+ ```
263
+
264
+ ### On Needs Fixes
265
+
266
+ **Record issues for fix cycle:**
267
+
268
+ ```
269
+ action: "set", featureId: "refactor-<slug>", updates: {
270
+ "reviews.overhaul.status": "needs_fixes",
271
+ "reviews.overhaul.issues": ["<issue1>", "<issue2>"]
272
+ }
273
+ ```
274
+
275
+ ## Transition
276
+
277
+ ### If APPROVED:
278
+ 1. Update state: `.phase = "synthesize"`
279
+ 2. Output: "Overhaul review passed. All goals achieved, behavior preserved. Auto-continuing to synthesis..."
280
+ 3. Auto-invoke:
281
+ ```typescript
282
+ Skill({ skill: "exarchos:synthesize", args: "<feature-name>" })
283
+ ```
284
+
285
+ ### If NEEDS_FIXES:
286
+ 1. Update state with issues
287
+ 2. Output: "Overhaul review found issues. Auto-continuing to fixes..."
288
+ 3. Auto-invoke:
289
+ ```typescript
290
+ Skill({ skill: "exarchos:delegate", args: "--fixes <plan-path>" })
291
+ ```
292
+
293
+ ### If BLOCKED:
294
+ 1. Update state: `.phase = "blocked"`
295
+ 2. Output: "Overhaul review blocked: [issue]. Returning to brief..."
296
+ 3. Prompt for brief revision
297
+
298
+ ## Exit Conditions
299
+
300
+ - [ ] All behavior preservation checks pass
301
+ - [ ] Regression risk assessed and acceptable
302
+ - [ ] All brief goals verified achieved
303
+ - [ ] Standard quality review criteria met
304
+ - [ ] State updated with review results
@@ -0,0 +1,349 @@
1
+ # Polish Track: Implement Phase
2
+
3
+ ## Purpose
4
+
5
+ Direct implementation for small, well-scoped refactors. This phase allows the orchestrator to write code directly without delegation to subagents, reducing ceremony while maintaining quality.
6
+
7
+ ## Orchestrator Exception
8
+
9
+ **This is the explicit exception to orchestrator constraints.**
10
+
11
+ The orchestrator constraints in `rules/orchestrator-constraints.md` state the orchestrator MUST NOT write implementation code. The polish track implement phase is the one case where this rule is intentionally violated.
12
+
13
+ ### Why This Exception Exists
14
+
15
+ | Standard Workflow | Polish Track |
16
+ |-------------------|--------------|
17
+ | Delegation overhead justified | Overhead exceeds value for small changes |
18
+ | Context window preserved for coordination | Small changes fit within session |
19
+ | Parallel execution via worktrees | Sequential execution sufficient |
20
+ | Subagent isolation for testing | Direct testing in main branch |
21
+
22
+ ### When the Exception Applies
23
+
24
+ The orchestrator may write code directly ONLY when ALL conditions are met:
25
+
26
+ 1. **Track is polish** - State file shows `.track = "polish"`
27
+ 2. **Brief is captured** - Phase has advanced to "implement"
28
+ 3. **Scope is limited** - 5 or fewer files affected
29
+ 4. **Single concern** - One refactoring goal per session
30
+ 5. **Tests exist** - Affected code has test coverage
31
+
32
+ If any condition is violated, switch to overhaul track.
33
+
34
+ ## Entry Conditions
35
+
36
+ Before starting implementation, verify prerequisites:
37
+
38
+ **Check track:**
39
+ ```
40
+ action: "get", featureId: "refactor-<slug>", query: ".track"
41
+ ```
42
+ Must return: `"polish"`
43
+
44
+ **Check phase:**
45
+ ```
46
+ action: "get", featureId: "refactor-<slug>", query: ".phase"
47
+ ```
48
+ Must return: `"implement"`
49
+
50
+ **Check goals:**
51
+ ```
52
+ action: "get", featureId: "refactor-<slug>", query: ".brief.goals"
53
+ ```
54
+ Must return: populated array
55
+
56
+ ### State Requirements
57
+
58
+ | Field | Requirement |
59
+ |-------|-------------|
60
+ | `.track` | "polish" |
61
+ | `.phase` | "implement" |
62
+ | `.brief.problem` | Non-empty string |
63
+ | `.brief.goals` | 1-3 items |
64
+ | `.brief.affectedAreas` | 1-5 files |
65
+ | `.brief.successCriteria` | 2-3 items |
66
+ | `.explore.scopeAssessment.testCoverage` | "good" or "gaps" (not "none") |
67
+
68
+ ## Implementation Process
69
+
70
+ ### Step 1: Pre-Implementation Verification
71
+
72
+ Run the full test suite before making any changes:
73
+
74
+ ```bash
75
+ npm run test:run
76
+ ```
77
+
78
+ **Gate:** Tests must pass. If tests fail before implementation, stop and investigate. Do not implement on top of a failing test suite.
79
+
80
+ **Record baseline:**
81
+
82
+ ```
83
+ action: "set", featureId: "refactor-<slug>", updates: {
84
+ "implement": {
85
+ "startedAt": "<ISO8601>",
86
+ "baselineTestsPass": true,
87
+ "changesLog": []
88
+ }
89
+ }
90
+ ```
91
+
92
+ ### Step 2: Make Changes Incrementally
93
+
94
+ For each logical change:
95
+
96
+ 1. **Understand the change** - Read affected code
97
+ 2. **Update tests first** (if behavior changes) - TDD: red then green
98
+ 3. **Make the change** - Minimal modification
99
+ 4. **Run tests** - Verify no regression
100
+ 5. **Commit** - Atomic commit for the change
101
+
102
+ ```bash
103
+ # After each change
104
+ npm run test:run
105
+
106
+ # Commit via Graphite
107
+ git add <files>
108
+ gt create refactor/<brief-name> -m "refactor: <description>"
109
+ ```
110
+
111
+ After all changes are complete:
112
+ ```bash
113
+ gt submit --no-interactive --publish --stack
114
+ ```
115
+
116
+ **NEVER use `git commit` or `git push`** — always use `gt create` and `gt submit`.
117
+
118
+ **Log change:**
119
+
120
+ ```
121
+ action: "set", featureId: "refactor-<slug>", updates: {
122
+ "implement.changesLog": [{"file": "<path>", "description": "<what changed>"}]
123
+ }
124
+ ```
125
+
126
+ ### Step 3: Test After Each Change
127
+
128
+ **Critical:** Run tests after EVERY change, not just at the end.
129
+
130
+ | Test Failure | Action |
131
+ |--------------|--------|
132
+ | Test fails after change | Revert and retry with smaller change |
133
+ | Unrelated test fails | Stop, investigate, may need track switch |
134
+ | Lint/type error | Fix before proceeding |
135
+
136
+ ### Step 4: Verify Goals
137
+
138
+ After all changes, verify each goal from brief:
139
+
140
+ ```
141
+ action: "get", featureId: "refactor-<slug>", query: ".brief.goals"
142
+ ```
143
+
144
+ For each goal, confirm it's addressed. If a goal cannot be addressed within polish scope, trigger track switch.
145
+
146
+ ## Scope Monitoring
147
+
148
+ ### Red Flags During Implementation
149
+
150
+ Watch for these indicators that polish is insufficient:
151
+
152
+ | Signal | Description | Threshold |
153
+ |--------|-------------|-----------|
154
+ | File count growing | Started with 3 files, now touching 6+ | >5 files |
155
+ | Test gaps discovered | Affected code lacks tests | Need >2 new test files |
156
+ | Cascading changes | Change in one file requires changes in many | >3 unexpected files |
157
+ | Architecture concerns | Structure questions beyond scope | Needs design document |
158
+ | Duration | Implementation taking too long | >1 hour of changes |
159
+
160
+ ### Monitoring Commands
161
+
162
+ ```bash
163
+ # Check files changed
164
+ git diff --name-only HEAD~N # where N = commits since implement started
165
+
166
+ # Count affected files
167
+ git diff --stat
168
+ ```
169
+
170
+ ### When to Stop
171
+
172
+ **Stop implementation immediately if:**
173
+
174
+ - More than 5 files need modification
175
+ - You discover test coverage is "none" (not "gaps")
176
+ - Multiple unrelated concerns emerge
177
+ - You're writing more than 100 lines of new code
178
+ - Changes require updates to public APIs
179
+
180
+ ## Track Switching
181
+
182
+ ### Detection
183
+
184
+ If scope expands beyond polish limits during implementation:
185
+
186
+ ```bash
187
+ echo "Scope has expanded beyond polish limits."
188
+ echo "Files affected: $(git diff --name-only | wc -l)"
189
+ echo "Switching to overhaul track recommended."
190
+ ```
191
+
192
+ ### Switch Protocol
193
+
194
+ 1. **Commit current work** - Don't lose progress
195
+ 2. **Record switch and change track:**
196
+
197
+ ```
198
+ action: "set", featureId: "refactor-<slug>", updates: {
199
+ "implement.switchReason": "<reason for switch>",
200
+ "implement.switchedAt": "<ISO8601>",
201
+ "track": "overhaul"
202
+ }, phase: "overhaul-plan"
203
+ ```
204
+
205
+ 3. **Create worktree** (if not already in one)
206
+ 4. **Invoke `/exarchos:plan`** - Extract remaining work into tasks
207
+ 5. **Continue via overhaul track**
208
+
209
+ ### Output to User
210
+
211
+ ```text
212
+ Scope has expanded beyond polish limits.
213
+ Reason: [specific reason]
214
+
215
+ Switching to overhaul track. This means:
216
+ - Work will continue in an isolated worktree
217
+ - Remaining changes will be delegated to subagents
218
+ - Full review process will be applied
219
+
220
+ Current progress has been committed. Continue? (Y/n)
221
+ ```
222
+
223
+ ## State Updates
224
+
225
+ ### Implementation Start
226
+
227
+ **Record baseline:**
228
+
229
+ ```
230
+ action: "set", featureId: "refactor-<slug>", updates: {
231
+ "implement": {
232
+ "startedAt": "<ISO8601>",
233
+ "baselineTestsPass": true,
234
+ "changesLog": []
235
+ }
236
+ }
237
+ ```
238
+
239
+ ### After Each Change
240
+
241
+ **Log change:**
242
+
243
+ ```
244
+ action: "set", featureId: "refactor-<slug>", updates: {
245
+ "implement.changesLog": [
246
+ {"file": "<path>", "description": "<what changed>", "commitSha": "<short-sha>"}
247
+ ]
248
+ }
249
+ ```
250
+
251
+ Note: For array appends, the MCP tool handles merging with existing array entries.
252
+
253
+ ### Implementation Complete
254
+
255
+ **Record completion and advance to validate:**
256
+
257
+ ```
258
+ action: "set", featureId: "refactor-<slug>", updates: {
259
+ "implement.completedAt": "<ISO8601>",
260
+ "implement.totalFiles": <count>,
261
+ "implement.totalCommits": <count>
262
+ }, phase: "polish-validate"
263
+ ```
264
+
265
+ ### Track Switch (if needed)
266
+
267
+ **Record switch and change track:**
268
+
269
+ ```
270
+ action: "set", featureId: "refactor-<slug>", updates: {
271
+ "implement.switchReason": "<reason>",
272
+ "implement.switchedAt": "<ISO8601>",
273
+ "track": "overhaul"
274
+ }, phase: "overhaul-plan"
275
+ ```
276
+
277
+ ## Exit Conditions
278
+
279
+ Implementation phase exits when:
280
+
281
+ ### Success Exit -> Validate Phase
282
+
283
+ - All changes from brief are implemented
284
+ - All tests pass
285
+ - No scope expansion occurred
286
+ - Less than or equal to 5 files changed
287
+
288
+ **Advance to validate:**
289
+
290
+ ```
291
+ action: "set", featureId: "refactor-<slug>", phase: "polish-validate"
292
+ ```
293
+
294
+ Next action: `AUTO:refactor-validate`
295
+
296
+ ### Track Switch Exit -> Plan Phase
297
+
298
+ - Scope expanded beyond polish limits
299
+ - Track switched to overhaul
300
+ - Current work committed
301
+
302
+ **Switch to overhaul track:**
303
+
304
+ ```
305
+ action: "set", featureId: "refactor-<slug>", updates: {
306
+ "track": "overhaul"
307
+ }, phase: "overhaul-plan"
308
+ ```
309
+
310
+ Next action: `AUTO:overhaul-plan`
311
+
312
+ ## Anti-Patterns
313
+
314
+ | Don't | Do Instead |
315
+ |-------|------------|
316
+ | Make all changes then test | Test after each change |
317
+ | Skip commits for "small" changes | Commit each logical change |
318
+ | Ignore expanding scope | Stop and switch tracks |
319
+ | Fix unrelated issues found | Note for separate refactor |
320
+ | Skip baseline test run | Always verify green baseline |
321
+ | Force polish when overhaul needed | Accept track switch gracefully |
322
+
323
+ ## Example Implementation Session
324
+
325
+ ```text
326
+ [Phase: implement]
327
+
328
+ 1. Running baseline tests...
329
+ Tests: 42 passed
330
+
331
+ 2. Change 1: Extract validation to UserValidator
332
+ - Created: src/validators/user-validator.ts
333
+ - Modified: src/services/user-service.ts
334
+ - Tests: 42 passed
335
+ - Committed: abc123
336
+
337
+ 3. Change 2: Update UserService imports
338
+ - Modified: src/services/user-service.ts
339
+ - Tests: 42 passed
340
+ - Committed: def456
341
+
342
+ 4. Verifying goals:
343
+ [x] Extract validation logic into separate UserValidator class
344
+ [x] Reduce UserService line count
345
+
346
+ 5. Files changed: 2 (within limit)
347
+
348
+ 6. Transitioning to validate phase...
349
+ ```