@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,67 @@
1
+ # /refactor Command
2
+
3
+ ## Purpose
4
+
5
+ Start a refactoring workflow for code improvements, cleanup, or restructuring.
6
+
7
+ ## Usage
8
+
9
+ ```
10
+ /refactor [target] [--polish] [--explore-only]
11
+ ```
12
+
13
+ ## Arguments
14
+
15
+ | Argument | Description |
16
+ |----------|-------------|
17
+ | `target` | Optional. File, directory, or module to refactor. If omitted, will prompt. |
18
+
19
+ ## Flags
20
+
21
+ | Flag | Description |
22
+ |------|-------------|
23
+ | `--polish` | Force polish track (direct implementation, no worktrees). Use for small, well-scoped refactors. |
24
+ | `--explore-only` | Run exploration phase only, output scope assessment without proceeding. |
25
+
26
+ ## Examples
27
+
28
+ ### Start refactor with exploration
29
+ ```
30
+ /refactor src/services/auth
31
+ ```
32
+
33
+ ### Force small refactor mode
34
+ ```
35
+ /refactor src/utils/helpers.ts --polish
36
+ ```
37
+
38
+ ### Just assess scope
39
+ ```
40
+ /refactor src/api --explore-only
41
+ ```
42
+
43
+ ## Workflow Entry
44
+
45
+ The command triggers the refactor skill which:
46
+
47
+ 1. **Explore phase**: Assesses scope (files, concerns, cross-module impact)
48
+ 2. **Track selection**:
49
+ - Polish (<=5 files, single concern) -> direct implementation
50
+ - Overhaul (>5 files or multiple concerns) -> full workflow
51
+ 3. **Brief capture**: Records problem, goals, approach in state
52
+ 4. **Execution**: Track-specific implementation
53
+ 5. **Validation**: Tests pass, goals met, docs updated
54
+
55
+ ## State Initialization
56
+
57
+ **Initialize refactor workflow:**
58
+
59
+ ```
60
+ action: "init", featureId: "refactor-<slug>", workflowType: "refactor"
61
+ ```
62
+
63
+ ## See Also
64
+
65
+ - `/exarchos:debug` - For bug fixes
66
+ - `/exarchos:ideate` - For new features
67
+ - `/exarchos:plan` - For implementation planning (used by overhaul track)
@@ -0,0 +1,198 @@
1
+ ---
2
+ name: refactor
3
+ description: "Code improvement workflow with two tracks: polish (small, direct changes) and overhaul (large, delegated restructuring). Use when the user says \"refactor\", \"clean up\", \"restructure\", \"reorganize\", \"refactor this code\", or runs /refactor. Handles explore, brief, implement, validate, and documentation phases. Do NOT use for bug fixes (use /debug) or new features (use /ideate). Applies to existing code only."
4
+ metadata:
5
+ author: exarchos
6
+ version: 1.0.0
7
+ mcp-server: exarchos
8
+ category: workflow
9
+ phase-affinity:
10
+ - explore
11
+ - brief
12
+ - implement
13
+ - validate
14
+ - update-docs
15
+ - synthesize
16
+ ---
17
+
18
+ # Refactor Workflow Skill
19
+
20
+ ## Overview
21
+
22
+ Two-track workflow for improving existing code. Polish track for small, contained refactors; overhaul track for architectural changes and migrations. Both tracks emphasize exploration before commitment and mandatory documentation updates.
23
+
24
+ ## Triggers
25
+
26
+ Activate this skill when:
27
+ - User runs `/refactor` command
28
+ - User wants to improve existing code structure
29
+ - User mentions "refactor", "restructure", "clean up", "migrate"
30
+ - User asks to "move", "extract", "rename", or "reorganize" code
31
+
32
+ **Disambiguation:** If the user says "fix" or "clean up" — use `/refactor` when the code *works* but needs structural improvement. Use `/debug` when something is *broken* (error, crash, wrong behavior).
33
+
34
+ ## Workflow Overview
35
+
36
+ ```
37
+ /exarchos:refactor
38
+ |
39
+ +-----+-----+
40
+ | Explore |
41
+ +-----+-----+
42
+ |
43
+ +--------------+--------------+
44
+ | |
45
+ --polish (default)
46
+ | |
47
+ v v
48
+ +--------------+ +--------------+
49
+ | Polish | | Overhaul |
50
+ | Track | | Track |
51
+ +--------------+ +--------------+
52
+ ```
53
+
54
+ ## Command Interface
55
+
56
+ ### Start Refactor Workflow
57
+
58
+ ```bash
59
+ # Default: overhaul track
60
+ /refactor "Description of what needs refactoring"
61
+
62
+ # Fast path: polish track
63
+ /refactor --polish "Small contained refactor description"
64
+
65
+ # Explore first, then decide track
66
+ /refactor --explore "Unsure of scope, explore first"
67
+ ```
68
+
69
+ ### Mid-Workflow Commands
70
+
71
+ ```bash
72
+ # Switch from polish to overhaul (during explore/brief)
73
+ /exarchos:refactor --switch-overhaul
74
+
75
+ # Resume after context compaction
76
+ /exarchos:resume
77
+ ```
78
+
79
+ ## Track Comparison
80
+
81
+ | Aspect | Polish | Overhaul |
82
+ |--------|--------|----------|
83
+ | Scope | <=5 files, single concern | No limit |
84
+ | Worktree | No (direct) | Yes (isolated) |
85
+ | Delegation | No | Yes (full workflow) |
86
+ | Documentation | Mandatory update phase | Mandatory update phase |
87
+ | Human Checkpoints | 0 | 1 (merge) |
88
+
89
+ ## Polish Track
90
+
91
+ Fast path for small, contained refactors (<=5 files, single concern). Orchestrator may write code directly (exception to orchestrator constraints). No worktree, no delegation.
92
+
93
+ Phases: Explore -> Brief -> Implement -> Validate -> Update Docs -> Complete
94
+
95
+ For detailed phase instructions, state management, and auto-chain behavior, see `@skills/refactor/references/polish-track.md`.
96
+
97
+ ## Overhaul Track
98
+
99
+ Rigorous path for architectural changes, migrations, and multi-file restructuring. Uses full delegation model with worktree isolation.
100
+
101
+ Phases: Explore -> Brief -> Plan -> Delegate -> Review -> Update Docs -> Synthesize
102
+
103
+ For detailed phase instructions, skill invocations, and auto-chain behavior, see `@skills/refactor/references/overhaul-track.md`.
104
+
105
+ ## State Management
106
+
107
+ Initialize refactor workflow:
108
+ ```
109
+ action: "init", featureId: "refactor-<slug>", workflowType: "refactor"
110
+ ```
111
+
112
+ Full state schema:
113
+ ```json
114
+ {
115
+ "version": "1.1",
116
+ "featureId": "refactor-<slug>",
117
+ "workflowType": "refactor",
118
+ "track": "polish | overhaul",
119
+ "phase": "explore | brief | polish-implement | polish-validate | polish-update-docs | overhaul-plan | overhaul-delegate | overhaul-review | overhaul-update-docs | synthesize | completed | cancelled | blocked",
120
+ "explore": {
121
+ "startedAt": "ISO8601",
122
+ "completedAt": "ISO8601 | null",
123
+ "scopeAssessment": {
124
+ "filesAffected": ["string"],
125
+ "modulesAffected": ["string"],
126
+ "testCoverage": "good | gaps | none",
127
+ "recommendedTrack": "polish | overhaul"
128
+ }
129
+ },
130
+ "brief": { // See references/brief-template.md for field descriptions
131
+ "problem": "string",
132
+ "goals": ["string"],
133
+ "approach": "string",
134
+ "affectedAreas": ["string"],
135
+ "outOfScope": ["string"],
136
+ "successCriteria": ["string"],
137
+ "docsToUpdate": ["string"]
138
+ },
139
+ "artifacts": {
140
+ "plan": "string | null",
141
+ "pr": "string | null",
142
+ "updatedDocs": ["string"]
143
+ },
144
+ "validation": {
145
+ "testsPass": "boolean",
146
+ "goalsVerified": ["string"],
147
+ "docsUpdated": "boolean"
148
+ }
149
+ }
150
+ ```
151
+
152
+ ## Track Switching
153
+
154
+ If scope expands beyond polish limits during explore or brief phase, use `mcp__exarchos__exarchos_workflow` with `action: "set"` to set `track` to "overhaul" and update `explore.scopeAssessment.recommendedTrack`.
155
+
156
+ **Scope thresholds:** If >5 files affected OR changes cross module boundaries -> recommend overhaul track.
157
+
158
+ **Indicators to switch:**
159
+ - More than 5 files affected
160
+ - Multiple concerns identified
161
+ - Cross-module changes needed
162
+ - Test coverage gaps require new tests
163
+
164
+ Output: "Scope expanded beyond polish limits. Switching to overhaul track."
165
+
166
+ ## Integration Points
167
+
168
+ **CRITICAL:** All skill invocations MUST use explicit `Skill()` tool calls:
169
+
170
+ | Skill | Invocation | Usage |
171
+ |-------|------------|-------|
172
+ | `/exarchos:plan` | `Skill({ skill: "exarchos:plan", args: "--refactor <state-file>" })` | Task extraction from brief |
173
+ | `/exarchos:delegate` | `Skill({ skill: "exarchos:delegate", args: "<state-file>" })` | Subagent dispatch for TDD |
174
+ | `/exarchos:review` | `Skill({ skill: "exarchos:review", args: "<state-file>" })` | Quality review |
175
+ | `/exarchos:synthesize` | `Skill({ skill: "exarchos:synthesize", args: "<feature>" })` | PR creation |
176
+
177
+ ## Anti-Patterns
178
+
179
+ | Don't | Do Instead |
180
+ |-------|------------|
181
+ | Skip exploration | Always assess scope first (see `references/explore-checklist.md`) |
182
+ | Use polish for large changes | Switch to overhaul when scope expands |
183
+ | Skip doc updates | Documentation is mandatory (see `references/doc-update-checklist.md`) |
184
+ | Add features during refactor | Scope creep - stick to brief goals |
185
+ | Skip tests because "just moving code" | Refactors need test verification |
186
+ | Create design document for polish | Use brief in state file instead |
187
+ | Work in main for overhaul | Use worktree isolation |
188
+
189
+ ## Exarchos Integration
190
+
191
+ When Exarchos MCP tools are available, emit events throughout the refactor workflow:
192
+
193
+ 1. **At workflow start (explore):** `mcp__exarchos__exarchos_event` with `action: "append"` → `workflow.started` with workflowType "refactor"
194
+ 2. **On track selection:** Auto-emitted by `exarchos_workflow` `set` when `phase` is provided — emits `workflow.transition` with selected track (polish/overhaul)
195
+ 3. **On each phase transition:** Auto-emitted by `exarchos_workflow` `set` when `phase` is provided — emits `workflow.transition` with from/to/trigger/featureId
196
+ 4. **Overhaul track stacking:** Handled by `/delegate` (subagents use `gt create` per implementer prompt)
197
+ 5. **Polish track commit:** Single `gt create -m "refactor: <description>"` — no multi-branch stacking needed
198
+ 6. **On complete:** Auto-emitted by `exarchos_workflow` `set` when transitioning to terminal state — emits `workflow.transition` to "completed"
@@ -0,0 +1,262 @@
1
+ # Auto-Chain Behavior
2
+
3
+ ## Purpose
4
+
5
+ Define automatic phase transitions for refactor workflows, minimizing human intervention while maintaining quality.
6
+
7
+ ## Design Principle
8
+
9
+ **Single human checkpoint per track.**
10
+
11
+ - Polish track: One checkpoint at completion (commit approval)
12
+ - Overhaul track: One checkpoint at merge (PR approval)
13
+
14
+ All other transitions are automatic.
15
+
16
+ ## Polish Track Auto-Chain
17
+
18
+ ```text
19
+ explore → brief → implement → validate → update-docs → CHECKPOINT
20
+ ```
21
+
22
+ ### Transition Rules
23
+
24
+ | From | To | Condition | Auto? |
25
+ |------|-----|-----------|-------|
26
+ | explore | brief | Scope assessed | Yes |
27
+ | brief | implement | Brief captured | Yes |
28
+ | implement | validate | Changes complete | Yes |
29
+ | validate | update-docs | Validation passed | Yes |
30
+ | update-docs | complete | Docs updated | Yes |
31
+ | complete | — | Human approves commit | CHECKPOINT |
32
+
33
+ ### Polish Auto-Chain Commands
34
+
35
+ After each phase, use the SessionStart hook with the featureId to determine the next action:
36
+
37
+ ```text
38
+ # After explore
39
+ The SessionStart hook determines the next action automatically.
40
+ Returns: AUTO:refactor-brief
41
+
42
+ # After brief
43
+ The SessionStart hook determines the next action automatically.
44
+ Returns: AUTO:polish-implement
45
+
46
+ # After implement
47
+ The SessionStart hook determines the next action automatically.
48
+ Returns: AUTO:refactor-validate
49
+
50
+ # After validate (passed)
51
+ The SessionStart hook determines the next action automatically.
52
+ Returns: AUTO:refactor-update-docs
53
+
54
+ # After update-docs
55
+ The SessionStart hook determines the next action automatically.
56
+ Returns: WAIT:human-checkpoint:polish-update-docs
57
+ ```
58
+
59
+ ### Polish Checkpoint
60
+
61
+ At completion, present to user:
62
+
63
+ ```markdown
64
+ ## Polish Refactor Complete
65
+
66
+ **Changes Made:**
67
+ <summary of files modified>
68
+
69
+ **Goals Achieved:**
70
+ - <goal 1>: ✓
71
+ - <goal 2>: ✓
72
+
73
+ **Validation:**
74
+ - Tests: ✓ All passing
75
+ - Docs: ✓ Updated
76
+
77
+ **Action Required:**
78
+ Ready to commit changes. Approve to commit, or request modifications.
79
+ ```
80
+
81
+ ## Overhaul Track Auto-Chain
82
+
83
+ ```text
84
+ explore → brief → plan → delegate → review → update-docs → synthesize → CHECKPOINT
85
+ ↑ │
86
+ └─── fixes ──────────┘ (if review fails)
87
+ ```
88
+
89
+ ### Transition Rules
90
+
91
+ | From | To | Condition | Auto? |
92
+ |------|-----|-----------|-------|
93
+ | explore | brief | Scope assessed | Yes |
94
+ | brief | plan | Brief captured | Yes |
95
+ | plan | delegate | Plan created | Yes |
96
+ | delegate | review | All tasks complete | Yes |
97
+ | review (pass) | update-docs | Review approved | Yes |
98
+ | review (fail) | delegate | Fix tasks dispatched | Yes (loop) |
99
+ | update-docs | synthesize | Docs updated | Yes |
100
+ | synthesize | complete | Human approves PR | CHECKPOINT |
101
+
102
+ ### Overhaul Auto-Chain Commands
103
+
104
+ Use the SessionStart hook with the featureId after each phase:
105
+
106
+ ```text
107
+ # After explore
108
+ Returns: AUTO:refactor-brief
109
+
110
+ # After brief
111
+ Returns: AUTO:overhaul-plan
112
+
113
+ # After plan
114
+ Returns: AUTO:refactor-delegate
115
+
116
+ # After delegate
117
+ Returns: AUTO:refactor-review
118
+
119
+ # After review (passed)
120
+ Returns: AUTO:refactor-update-docs
121
+
122
+ # After review (failed)
123
+ Returns: AUTO:refactor-delegate:--fixes
124
+
125
+ # After update-docs
126
+ Returns: AUTO:refactor-synthesize
127
+
128
+ # After synthesize
129
+ Returns: WAIT:human-checkpoint:synthesize
130
+ ```
131
+
132
+ ### Overhaul Checkpoint
133
+
134
+ #### PR Approval
135
+
136
+ ```markdown
137
+ ## Refactor PR Ready
138
+
139
+ **PR:** <url>
140
+
141
+ **Summary:**
142
+ <refactor summary>
143
+
144
+ **Goals Achieved:**
145
+ - <goal 1>: ✓
146
+ - <goal 2>: ✓
147
+
148
+ **Review Status:**
149
+ - Behavior preserved: ✓
150
+ - Tests passing: ✓
151
+ - Docs updated: ✓
152
+
153
+ **Action Required:**
154
+ Review PR and approve merge, or request changes.
155
+ ```
156
+
157
+ ## Track Switching
158
+
159
+ If polish track discovers scope expansion, it switches to overhaul:
160
+
161
+ ```text
162
+ polish:implement → [scope expands] → overhaul:plan
163
+ ```
164
+
165
+ Auto-chain handles this via MCP tools:
166
+
167
+ ```text
168
+ # When scope expands during implement, use mcp__exarchos__exarchos_workflow with action: "set":
169
+ # 1. First call: Set updates
170
+ updates: { "implement.switchReason": "<reason>", "implement.switchedAt": "<ISO8601>" }
171
+
172
+ # 2. Second call: Transition phase and track
173
+ phase: "plan"
174
+ updates: { "track": "overhaul" }
175
+
176
+ # Next action returns
177
+ The SessionStart hook determines the next action automatically.
178
+ Returns: AUTO:overhaul-plan
179
+ ```
180
+
181
+ ## Failure Handling
182
+
183
+ ### Polish Track Failures
184
+
185
+ | Failure | Recovery |
186
+ |---------|----------|
187
+ | Validate fails | Return to implement, fix issues |
188
+ | Tests fail | Fix tests, re-validate |
189
+ | Scope expands | Switch to overhaul track |
190
+
191
+ ### Overhaul Track Failures
192
+
193
+ | Failure | Recovery |
194
+ |---------|----------|
195
+ | Review fails | Delegate fixes, re-review |
196
+ | Synthesize fails | Fix PR issues, re-synthesize |
197
+
198
+ All recoveries are automatic loops until success.
199
+
200
+ ## State Machine Summary
201
+
202
+ ```text
203
+ ┌─────────────────────────────────────────────────────────────────┐
204
+ │ REFACTOR WORKFLOW │
205
+ ├─────────────────────────────────────────────────────────────────┤
206
+ │ │
207
+ │ START → explore → brief ─┬─→ [polish] ─→ implement ─→ validate │
208
+ │ │ ↓ │
209
+ │ │ update-docs │
210
+ │ │ ↓ │
211
+ │ │ ▣ COMPLETE │
212
+ │ │ │
213
+ │ └─→ [overhaul] ─→ plan ─→ delegate │
214
+ │ ↓ │
215
+ │ review ───┐ │
216
+ │ ↓ │ │
217
+ │ update-docs │ │
218
+ │ ↓ │ │
219
+ │ synthesize │ │
220
+ │ ↓ │ │
221
+ │ ▣ PR-MERGE │ │
222
+ │ │ │
223
+ │ delegate:--fixes ←────────────┘ │
224
+ │ (on review fail) │
225
+ │ │
226
+ │ Legend: ▣ = Human Checkpoint │
227
+ └─────────────────────────────────────────────────────────────────┘
228
+ ```
229
+
230
+ ## Integration with workflow-auto-resume.md
231
+
232
+ The auto-chain actions are handled by workflow-auto-resume.md rules.
233
+
234
+ **CRITICAL:** Use explicit `Skill()` tool invocations to ensure skills are actually invoked:
235
+
236
+ | Action | Skill Invocation |
237
+ |--------|------------------|
238
+ | AUTO:refactor-brief | Continue to brief capture (inline) |
239
+ | AUTO:polish-implement | Continue to implement phase (inline - orchestrator implements) |
240
+ | AUTO:refactor-validate | Continue to validate phase (inline) |
241
+ | AUTO:refactor-update-docs | Continue to update-docs phase (inline) |
242
+ | AUTO:overhaul-plan | `Skill({ skill: "exarchos:plan", args: "--refactor <state-file>" })` |
243
+ | AUTO:refactor-delegate | `Skill({ skill: "exarchos:delegate", args: "<state-file>" })` |
244
+ | AUTO:refactor-delegate:--fixes | `Skill({ skill: "exarchos:delegate", args: "--fixes <state-file>" })` |
245
+ | AUTO:refactor-review | `Skill({ skill: "exarchos:review", args: "<state-file>" })` |
246
+ | AUTO:refactor-synthesize | `Skill({ skill: "exarchos:synthesize", args: "<feature-name>" })` |
247
+
248
+ ### Example Overhaul Chain
249
+
250
+ ```typescript
251
+ // After brief complete
252
+ Skill({ skill: "exarchos:plan", args: "--refactor ~/.claude/workflow-state/refactor-auth.state.json" })
253
+
254
+ // After plan complete (invoked by /exarchos:plan skill)
255
+ Skill({ skill: "exarchos:delegate", args: "~/.claude/workflow-state/refactor-auth.state.json" })
256
+
257
+ // After all tasks complete (invoked by /exarchos:delegate skill)
258
+ Skill({ skill: "exarchos:review", args: "~/.claude/workflow-state/refactor-auth.state.json" })
259
+
260
+ // After review passes, update-docs runs inline, then:
261
+ Skill({ skill: "exarchos:synthesize", args: "refactor-auth" })
262
+ ```
@@ -0,0 +1,176 @@
1
+ # Brief Phase
2
+
3
+ ## Purpose
4
+
5
+ Capture refactoring intent in a structured format without the overhead of a full design document.
6
+
7
+ ## Entry Conditions
8
+
9
+ - Explore phase complete
10
+ - Track selected (polish or overhaul)
11
+ - Scope assessment available in state
12
+
13
+ ## Brief Structure
14
+
15
+ The brief captures these required fields:
16
+
17
+ ### 1. Problem Statement
18
+
19
+ **What's wrong with the current code?** Be specific and measurable.
20
+
21
+ Good examples:
22
+ - "UserService class has grown to 500 lines with authentication, validation, and persistence mixed together"
23
+ - "The payment module uses 4 different error handling patterns inconsistently"
24
+ - "Test setup duplicated across 12 test files with slight variations"
25
+
26
+ Bad examples:
27
+ - "Code is messy"
28
+ - "Need to clean things up"
29
+ - "Could be better"
30
+
31
+ ### 2. Goals
32
+
33
+ **What specific outcomes will this refactor achieve?** Each goal must be verifiable.
34
+
35
+ Good goals:
36
+ - "Extract validation into UserValidator class (<100 lines)"
37
+ - "Consolidate error handling to single pattern using Result type"
38
+ - "Create shared TestFixtures reducing setup duplication by 80%"
39
+
40
+ Bad goals:
41
+ - "Improve code quality"
42
+ - "Make it cleaner"
43
+ - "Better organization"
44
+
45
+ ### 3. Approach
46
+
47
+ **How will you achieve the goals?** High-level strategy.
48
+
49
+ Polish approach (1-2 sentences):
50
+ - "Extract methods, create new class, update callers"
51
+
52
+ Overhaul approach (phases):
53
+ - "Phase 1: Create adapter for new pattern alongside old"
54
+ - "Phase 2: Migrate internal callers"
55
+ - "Phase 3: Migrate external callers"
56
+ - "Phase 4: Remove old pattern"
57
+
58
+ ### 4. Affected Areas
59
+
60
+ **Specific paths that will change.** From explore phase.
61
+
62
+ ### 5. Out of Scope
63
+
64
+ **What you're explicitly NOT changing.** Prevents scope creep.
65
+
66
+ Examples:
67
+ - "Not changing the public API"
68
+ - "Not addressing performance issues"
69
+ - "Not updating unrelated tests"
70
+
71
+ ### 6. Success Criteria
72
+
73
+ **How will you verify the refactor is complete?**
74
+
75
+ - All existing tests pass
76
+ - New tests added for [specific areas]
77
+ - [Goal 1] achieved (measurable)
78
+ - No new linting errors
79
+ - Documentation updated
80
+
81
+ ### 7. Docs to Update
82
+
83
+ **Documentation that needs updating.** From explore phase.
84
+
85
+ ## Brief Depth by Track
86
+
87
+ | Field | Polish | Overhaul |
88
+ |-------|--------|----------|
89
+ | Problem | 1-2 sentences | Paragraph with context |
90
+ | Goals | 1-3 items | 3-5 items |
91
+ | Approach | 1-2 sentences | Phases described |
92
+ | Out of Scope | 1-2 items | 3+ items |
93
+ | Success Criteria | 2-3 items | 4+ items |
94
+
95
+ ## Interactive Capture
96
+
97
+ When in brief phase, prompt user for each field if not provided:
98
+
99
+ ```
100
+ ## Refactor Brief
101
+
102
+ Based on exploration, preparing brief for <polish|overhaul> track.
103
+
104
+ **Problem:** <from user or prompt>
105
+ **Goals:** <from user or prompt>
106
+ ...
107
+ ```
108
+
109
+ ## State Update
110
+
111
+ **Save brief and advance:**
112
+
113
+ ```
114
+ action: "set", featureId: "refactor-<slug>", updates: {
115
+ "brief": {
116
+ "problem": "<problem statement>",
117
+ "goals": ["<goal 1>", "<goal 2>"],
118
+ "approach": "<approach description>",
119
+ "affectedAreas": ["<from explore>"],
120
+ "outOfScope": ["<exclusion 1>"],
121
+ "successCriteria": ["<criterion 1>"],
122
+ "docsToUpdate": ["<from explore>"],
123
+ "capturedAt": "<ISO8601>"
124
+ }
125
+ }, phase: "<implement|plan>"
126
+ ```
127
+
128
+ Phase transitions:
129
+ - Polish track -> `implement`
130
+ - Overhaul track -> `plan`
131
+
132
+ ## Validation
133
+
134
+ Before proceeding, validate brief completeness:
135
+
136
+ ```
137
+ Required fields check:
138
+ [x] Problem: defined
139
+ [x] Goals: at least 1
140
+ [x] Approach: defined
141
+ [x] Affected areas: from explore
142
+ [x] Out of scope: at least 1
143
+ [x] Success criteria: at least 2
144
+ [x] Docs to update: from explore (can be empty)
145
+ ```
146
+
147
+ If validation fails, prompt for missing fields.
148
+
149
+ ## Exit Conditions
150
+
151
+ - All required fields captured
152
+ - Brief stored in state
153
+ - Phase transitioned appropriately:
154
+ - Polish -> implement
155
+ - Overhaul -> plan
156
+
157
+ ## Transition
158
+
159
+ After brief is captured, auto-continue to next phase:
160
+
161
+ ### Polish Track
162
+
163
+ 1. Update state: `.phase = "implement"`
164
+ 2. Output: "Brief captured. Auto-continuing to implementation..."
165
+ 3. Continue with implement phase inline (no Skill invocation - orchestrator implements directly)
166
+
167
+ ### Overhaul Track
168
+
169
+ 1. Update state: `.phase = "plan"`
170
+ 2. Output: "Brief captured. Auto-continuing to planning..."
171
+ 3. Invoke immediately:
172
+ ```typescript
173
+ Skill({ skill: "exarchos:plan", args: "--refactor ~/.claude/workflow-state/<feature>.state.json" })
174
+ ```
175
+
176
+ This is NOT a human checkpoint - workflow continues autonomously.