@massu/core 0.1.1 → 0.4.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.
- package/commands/_shared-preamble.md +76 -0
- package/commands/massu-audit-deps.md +211 -0
- package/commands/massu-changelog.md +174 -0
- package/commands/massu-cleanup.md +315 -0
- package/commands/massu-commit.md +481 -0
- package/commands/massu-create-plan.md +752 -0
- package/commands/massu-dead-code.md +131 -0
- package/commands/massu-debug.md +484 -0
- package/commands/massu-deploy.md +91 -0
- package/commands/massu-deps.md +374 -0
- package/commands/massu-doc-gen.md +279 -0
- package/commands/massu-docs.md +364 -0
- package/commands/massu-estimate.md +313 -0
- package/commands/massu-golden-path.md +973 -0
- package/commands/massu-guide.md +167 -0
- package/commands/massu-hotfix.md +480 -0
- package/commands/massu-loop-playwright.md +837 -0
- package/commands/massu-loop.md +775 -0
- package/commands/massu-new-feature.md +511 -0
- package/commands/massu-parity.md +214 -0
- package/commands/massu-plan.md +456 -0
- package/commands/massu-push-light.md +207 -0
- package/commands/massu-push.md +434 -0
- package/commands/massu-refactor.md +410 -0
- package/commands/massu-release.md +363 -0
- package/commands/massu-review.md +238 -0
- package/commands/massu-simplify.md +281 -0
- package/commands/massu-status.md +278 -0
- package/commands/massu-tdd.md +201 -0
- package/commands/massu-test.md +516 -0
- package/commands/massu-verify-playwright.md +281 -0
- package/commands/massu-verify.md +667 -0
- package/dist/cli.js +7772 -3140
- package/dist/hooks/cost-tracker.js +103 -40
- package/dist/hooks/post-edit-context.js +74 -8
- package/dist/hooks/post-tool-use.js +268 -106
- package/dist/hooks/pre-compact.js +167 -43
- package/dist/hooks/pre-delete-check.js +159 -42
- package/dist/hooks/quality-event.js +103 -40
- package/dist/hooks/security-gate.js +29 -0
- package/dist/hooks/session-end.js +143 -84
- package/dist/hooks/session-start.js +186 -49
- package/dist/hooks/user-prompt.js +189 -43
- package/package.json +10 -15
- package/src/adr-generator.ts +9 -2
- package/src/analytics.ts +9 -3
- package/src/audit-trail.ts +10 -3
- package/src/backfill-sessions.ts +5 -4
- package/src/cli.ts +6 -0
- package/src/cloud-sync.ts +14 -18
- package/src/commands/doctor.ts +193 -6
- package/src/commands/init.ts +230 -5
- package/src/commands/install-commands.ts +137 -0
- package/src/config.ts +68 -2
- package/src/cost-tracker.ts +11 -6
- package/src/db.ts +115 -2
- package/src/dependency-scorer.ts +9 -2
- package/src/docs-tools.ts +21 -16
- package/src/hooks/post-edit-context.ts +4 -4
- package/src/hooks/post-tool-use.ts +130 -0
- package/src/hooks/pre-compact.ts +23 -1
- package/src/hooks/pre-delete-check.ts +92 -4
- package/src/hooks/security-gate.ts +32 -0
- package/src/hooks/session-end.ts +3 -3
- package/src/hooks/session-start.ts +99 -6
- package/src/hooks/user-prompt.ts +46 -1
- package/src/import-resolver.ts +2 -1
- package/src/knowledge-db.ts +169 -0
- package/src/knowledge-indexer.ts +704 -0
- package/src/knowledge-tools.ts +1413 -0
- package/src/license.ts +482 -0
- package/src/memory-db.ts +1364 -23
- package/src/memory-tools.ts +14 -15
- package/src/observability-tools.ts +13 -2
- package/src/observation-extractor.ts +11 -4
- package/src/page-deps.ts +3 -2
- package/src/prompt-analyzer.ts +9 -2
- package/src/python/coupling-detector.ts +124 -0
- package/src/python/domain-enforcer.ts +83 -0
- package/src/python/impact-analyzer.ts +95 -0
- package/src/python/import-parser.ts +244 -0
- package/src/python/import-resolver.ts +135 -0
- package/src/python/migration-indexer.ts +115 -0
- package/src/python/migration-parser.ts +332 -0
- package/src/python/model-indexer.ts +70 -0
- package/src/python/model-parser.ts +279 -0
- package/src/python/route-indexer.ts +58 -0
- package/src/python/route-parser.ts +317 -0
- package/src/python-tools.ts +629 -0
- package/src/regression-detector.ts +9 -3
- package/src/security-scorer.ts +9 -2
- package/src/sentinel-db.ts +45 -89
- package/src/sentinel-tools.ts +8 -11
- package/src/server.ts +29 -7
- package/src/session-archiver.ts +4 -5
- package/src/team-knowledge.ts +9 -2
- package/src/tools.ts +1032 -44
- package/src/validate-features-runner.ts +0 -1
- package/src/validation-engine.ts +9 -2
- package/README.md +0 -40
- package/dist/server.js +0 -7008
- package/src/__tests__/adr-generator.test.ts +0 -260
- package/src/__tests__/analytics.test.ts +0 -282
- package/src/__tests__/audit-trail.test.ts +0 -382
- package/src/__tests__/backfill-sessions.test.ts +0 -690
- package/src/__tests__/cli.test.ts +0 -290
- package/src/__tests__/cloud-sync.test.ts +0 -261
- package/src/__tests__/config-sections.test.ts +0 -359
- package/src/__tests__/config.test.ts +0 -732
- package/src/__tests__/cost-tracker.test.ts +0 -348
- package/src/__tests__/db.test.ts +0 -177
- package/src/__tests__/dependency-scorer.test.ts +0 -325
- package/src/__tests__/docs-integration.test.ts +0 -178
- package/src/__tests__/docs-tools.test.ts +0 -199
- package/src/__tests__/domains.test.ts +0 -236
- package/src/__tests__/hooks.test.ts +0 -221
- package/src/__tests__/import-resolver.test.ts +0 -95
- package/src/__tests__/integration/path-traversal.test.ts +0 -134
- package/src/__tests__/integration/pricing-consistency.test.ts +0 -88
- package/src/__tests__/integration/tool-registration.test.ts +0 -146
- package/src/__tests__/memory-db.test.ts +0 -404
- package/src/__tests__/memory-enhancements.test.ts +0 -316
- package/src/__tests__/memory-tools.test.ts +0 -199
- package/src/__tests__/middleware-tree.test.ts +0 -177
- package/src/__tests__/observability-tools.test.ts +0 -595
- package/src/__tests__/observability.test.ts +0 -437
- package/src/__tests__/observation-extractor.test.ts +0 -167
- package/src/__tests__/page-deps.test.ts +0 -60
- package/src/__tests__/prompt-analyzer.test.ts +0 -298
- package/src/__tests__/regression-detector.test.ts +0 -295
- package/src/__tests__/rules.test.ts +0 -87
- package/src/__tests__/schema-mapper.test.ts +0 -29
- package/src/__tests__/security-scorer.test.ts +0 -238
- package/src/__tests__/security-utils.test.ts +0 -175
- package/src/__tests__/sentinel-db.test.ts +0 -491
- package/src/__tests__/sentinel-scanner.test.ts +0 -750
- package/src/__tests__/sentinel-tools.test.ts +0 -324
- package/src/__tests__/sentinel-types.test.ts +0 -750
- package/src/__tests__/server.test.ts +0 -452
- package/src/__tests__/session-archiver.test.ts +0 -524
- package/src/__tests__/session-state-generator.test.ts +0 -900
- package/src/__tests__/team-knowledge.test.ts +0 -327
- package/src/__tests__/tools.test.ts +0 -340
- package/src/__tests__/transcript-parser.test.ts +0 -195
- package/src/__tests__/trpc-index.test.ts +0 -25
- package/src/__tests__/validate-features-runner.test.ts +0 -517
- package/src/__tests__/validation-engine.test.ts +0 -300
- package/src/core-tools.ts +0 -685
- package/src/memory-queries.ts +0 -804
- package/src/memory-schema.ts +0 -546
- package/src/tool-helpers.ts +0 -41
|
@@ -0,0 +1,410 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: massu-refactor
|
|
3
|
+
description: Safe refactoring with behavioral equivalence, incremental transforms, and automatic rollback
|
|
4
|
+
allowed-tools: Bash(*), Read(*), Write(*), Edit(*), Grep(*), Glob(*)
|
|
5
|
+
---
|
|
6
|
+
name: massu-refactor
|
|
7
|
+
|
|
8
|
+
> **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-9, CR-35 enforced.
|
|
9
|
+
|
|
10
|
+
# CS Refactor: Safe Refactoring Workflow
|
|
11
|
+
|
|
12
|
+
## Objective
|
|
13
|
+
|
|
14
|
+
Restructure code safely, ensuring behavioral equivalence at every step. Changes are applied incrementally with verification after each batch. If behavioral equivalence cannot be maintained, the refactoring is aborted.
|
|
15
|
+
|
|
16
|
+
**Usage**: `/massu-refactor [description of the refactoring]`
|
|
17
|
+
|
|
18
|
+
## Workflow Position
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
/massu-create-plan -> /massu-plan -> /massu-refactor -> /massu-commit -> /massu-push
|
|
22
|
+
(PLAN) (AUDIT PLAN) (EXECUTE REFACTOR) (COMMIT) (PUSH)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## NON-NEGOTIABLE RULES
|
|
28
|
+
|
|
29
|
+
- **Behavioral equivalence is MANDATORY** — tests passing before MUST still pass after
|
|
30
|
+
- **Incremental batches only** — max 3 files per batch, verify after each
|
|
31
|
+
- **Never skip verification** — every batch gets type check + test run
|
|
32
|
+
- **Revert on regression** — if a batch breaks tests, revert it before continuing
|
|
33
|
+
- **FIX ALL ISSUES ENCOUNTERED (CR-9)** — pre-existing issues found during refactoring MUST be fixed
|
|
34
|
+
- **Proof > reasoning. Commands > assumptions.**
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## SCOPE GUARD (MANDATORY)
|
|
39
|
+
|
|
40
|
+
**This command is for MEDIUM refactorings. If ANY of these are true, ABORT:**
|
|
41
|
+
|
|
42
|
+
| Condition | Why It's Too Big | Alternative |
|
|
43
|
+
|-----------|-----------------|-------------|
|
|
44
|
+
| Refactoring touches > 20 files | Needs structured plan | `/massu-create-plan` |
|
|
45
|
+
| Changes database schema | Needs migration workflow | `/massu-internal-migrate` |
|
|
46
|
+
| Changes public API contracts | Needs blast radius plan | `/massu-create-plan` |
|
|
47
|
+
| Renames MCP tool names | Affects all consumers | `/massu-create-plan` |
|
|
48
|
+
| Changes config interface fields | Affects all config users | `/massu-create-plan` |
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
SCOPE CHECK:
|
|
52
|
+
1. Read the target code
|
|
53
|
+
2. Grep for all references to exports/functions/types being changed
|
|
54
|
+
3. Count affected files
|
|
55
|
+
4. IF affected_files > 20:
|
|
56
|
+
OUTPUT: "Refactoring scope is too large ([N] files). Use /massu-create-plan instead."
|
|
57
|
+
ABORT
|
|
58
|
+
5. IF changes database schema:
|
|
59
|
+
OUTPUT: "Refactoring involves schema changes. Use /massu-internal-migrate instead."
|
|
60
|
+
ABORT
|
|
61
|
+
6. IF changes public API contracts:
|
|
62
|
+
OUTPUT: "Refactoring changes public API. Use /massu-create-plan for blast radius analysis."
|
|
63
|
+
ABORT
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## STEP 1: SCOPE ANALYSIS
|
|
69
|
+
|
|
70
|
+
### 1a. Read Target Code
|
|
71
|
+
|
|
72
|
+
Read every file that will be modified to understand current structure:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# Read the primary target file(s)
|
|
76
|
+
# Read all files that import from or reference the target
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 1b. Reference Analysis
|
|
80
|
+
|
|
81
|
+
For each export, function, type, or constant being changed:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Find all references in the codebase
|
|
85
|
+
grep -rn "[export_name]" packages/core/src/ --include="*.ts"
|
|
86
|
+
grep -rn "[export_name]" packages/ --include="*.ts" --include="*.tsx"
|
|
87
|
+
grep -rn "[export_name]" .claude/commands/ --include="*.md"
|
|
88
|
+
grep -rn "[export_name]" scripts/ --include="*.sh"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 1c. Impact Matrix
|
|
92
|
+
|
|
93
|
+
```markdown
|
|
94
|
+
### Impact Matrix
|
|
95
|
+
|
|
96
|
+
| File | References | Type | Action |
|
|
97
|
+
|------|-----------|------|--------|
|
|
98
|
+
| [file_1] | [function/type names] | CHANGE | [what changes] |
|
|
99
|
+
| [file_2] | [function/type names] | CHANGE | [what changes] |
|
|
100
|
+
| [file_3] | [function/type names] | KEEP | [why no change needed] |
|
|
101
|
+
|
|
102
|
+
**Total files affected: [N]**
|
|
103
|
+
**Scope check: [PASS if <= 20 / ABORT if > 20]**
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## STEP 2: BASELINE SNAPSHOT
|
|
109
|
+
|
|
110
|
+
Capture the behavioral baseline BEFORE making any changes:
|
|
111
|
+
|
|
112
|
+
### 2a. Test Baseline
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
npm test 2>&1
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Record:
|
|
119
|
+
```markdown
|
|
120
|
+
### Test Baseline
|
|
121
|
+
| Metric | Value |
|
|
122
|
+
|--------|-------|
|
|
123
|
+
| Total tests | [N] |
|
|
124
|
+
| Passing | [N] |
|
|
125
|
+
| Failing | [N] |
|
|
126
|
+
| Skipped | [N] |
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 2b. Type Check Baseline
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
cd packages/core && npx tsc --noEmit 2>&1
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Record:
|
|
136
|
+
```markdown
|
|
137
|
+
### Type Check Baseline
|
|
138
|
+
| Metric | Value |
|
|
139
|
+
|--------|-------|
|
|
140
|
+
| Type errors | [N] |
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**This baseline is the behavioral contract. After refactoring:**
|
|
144
|
+
- Test count MUST be >= baseline (can add tests, not lose them)
|
|
145
|
+
- Passing count MUST be >= baseline
|
|
146
|
+
- Type error count MUST be <= baseline (can fix errors, not add them)
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
## STEP 3: BLAST RADIUS ANALYSIS (CR-10)
|
|
151
|
+
|
|
152
|
+
**For EVERY export, function, type, or constant being renamed or moved:**
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# Grep entire codebase for the old name
|
|
156
|
+
grep -rn "[old_name]" packages/ website/ scripts/ .claude/ --include="*.ts" --include="*.tsx" --include="*.md" --include="*.sh" --include="*.yaml"
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Categorize Every Occurrence
|
|
160
|
+
|
|
161
|
+
```markdown
|
|
162
|
+
### Blast Radius — [old_name] → [new_name]
|
|
163
|
+
|
|
164
|
+
| File:Line | Occurrence | Category | Reason |
|
|
165
|
+
|-----------|-----------|----------|--------|
|
|
166
|
+
| [file:NN] | [context] | CHANGE | Will be updated |
|
|
167
|
+
| [file:NN] | [context] | KEEP | [reason — e.g., string literal, comment, different variable] |
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**Requirements:**
|
|
171
|
+
- Zero INVESTIGATE items — every occurrence must be categorized as CHANGE or KEEP
|
|
172
|
+
- Every CHANGE item must be tracked in the transformation plan
|
|
173
|
+
- If any occurrence cannot be categorized, STOP and investigate before proceeding
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
## STEP 4: INCREMENTAL TRANSFORMATION
|
|
178
|
+
|
|
179
|
+
Apply changes in small batches. **Maximum 3 files per batch.**
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
TRANSFORMATION LOOP:
|
|
183
|
+
batch_number = 1
|
|
184
|
+
WHILE files_remaining > 0:
|
|
185
|
+
1. Select next batch (max 3 files)
|
|
186
|
+
2. Apply changes to batch
|
|
187
|
+
3. Run type check:
|
|
188
|
+
cd packages/core && npx tsc --noEmit 2>&1
|
|
189
|
+
4. Run tests:
|
|
190
|
+
npm test 2>&1
|
|
191
|
+
5. Compare against baseline:
|
|
192
|
+
- Type errors must be <= baseline
|
|
193
|
+
- Passing tests must be >= baseline
|
|
194
|
+
6. IF check degrades from baseline:
|
|
195
|
+
- REVERT the batch: git checkout -- [batch files]
|
|
196
|
+
- Investigate why the batch caused regression
|
|
197
|
+
- Fix the approach and retry (max 3 retries per batch)
|
|
198
|
+
7. IF check maintains or improves baseline:
|
|
199
|
+
- Record batch as successful
|
|
200
|
+
- Proceed to next batch
|
|
201
|
+
batch_number++
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Batch Record
|
|
205
|
+
|
|
206
|
+
```markdown
|
|
207
|
+
### Batch [N]: [description]
|
|
208
|
+
|
|
209
|
+
| File | Change |
|
|
210
|
+
|------|--------|
|
|
211
|
+
| [file_1] | [what was changed] |
|
|
212
|
+
| [file_2] | [what was changed] |
|
|
213
|
+
|
|
214
|
+
| Check | Before | After | Status |
|
|
215
|
+
|-------|--------|-------|--------|
|
|
216
|
+
| Type errors | [N] | [N] | EQUIVALENT/IMPROVED |
|
|
217
|
+
| Tests passing | [N] | [N] | EQUIVALENT/IMPROVED |
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## STEP 5: NEGATIVE VERIFICATION
|
|
223
|
+
|
|
224
|
+
**For every renamed or removed export, function, type, or constant:**
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
# Verify old name no longer exists in source
|
|
228
|
+
grep -rn "[old_name]" packages/core/src/ --include="*.ts"
|
|
229
|
+
# MUST return 0 matches
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**For moved files:**
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
# Verify old file no longer exists
|
|
236
|
+
ls [old_file_path]
|
|
237
|
+
# MUST fail (file should not exist)
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
```markdown
|
|
241
|
+
### Negative Verification
|
|
242
|
+
|
|
243
|
+
| Old Name/Path | Grep Result | Status |
|
|
244
|
+
|--------------|-------------|--------|
|
|
245
|
+
| [old_name] | 0 matches | CLEAN |
|
|
246
|
+
| [old_path] | File not found | CLEAN |
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
**If ANY old reference remains:** Fix it before proceeding.
|
|
250
|
+
|
|
251
|
+
---
|
|
252
|
+
|
|
253
|
+
## STEP 6: FINAL VERIFICATION
|
|
254
|
+
|
|
255
|
+
Run the full gate sequence:
|
|
256
|
+
|
|
257
|
+
### Gate 1: Pattern Scanner (VR-PATTERN)
|
|
258
|
+
```bash
|
|
259
|
+
bash scripts/massu-pattern-scanner.sh
|
|
260
|
+
# MUST exit 0
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Gate 2: Type Check (VR-TYPE)
|
|
264
|
+
```bash
|
|
265
|
+
cd packages/core && npx tsc --noEmit
|
|
266
|
+
# MUST show 0 errors (or <= baseline)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Gate 3: All Tests (VR-TEST)
|
|
270
|
+
```bash
|
|
271
|
+
npm test
|
|
272
|
+
# MUST exit 0, all tests pass
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Gate 4: Hook Build (VR-HOOK-BUILD)
|
|
276
|
+
```bash
|
|
277
|
+
cd packages/core && npm run build:hooks
|
|
278
|
+
# MUST exit 0
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
### Compare Against Baseline
|
|
282
|
+
|
|
283
|
+
```markdown
|
|
284
|
+
### Baseline Comparison
|
|
285
|
+
|
|
286
|
+
| Metric | Before | After | Delta | Status |
|
|
287
|
+
|--------|--------|-------|-------|--------|
|
|
288
|
+
| Tests passing | [N] | [N] | [+/-N] | EQUIVALENT/IMPROVED |
|
|
289
|
+
| Tests total | [N] | [N] | [+/-N] | EQUIVALENT/IMPROVED |
|
|
290
|
+
| Type errors | [N] | [N] | [+/-N] | EQUIVALENT/IMPROVED |
|
|
291
|
+
| Pattern violations | [N] | [N] | [+/-N] | EQUIVALENT/IMPROVED |
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## STEP 7: BEHAVIORAL EQUIVALENCE PROOF
|
|
297
|
+
|
|
298
|
+
Generate the formal proof table:
|
|
299
|
+
|
|
300
|
+
```markdown
|
|
301
|
+
### Behavioral Equivalence Proof
|
|
302
|
+
|
|
303
|
+
| Metric | Before | After | Delta | Status |
|
|
304
|
+
|--------|--------|-------|-------|--------|
|
|
305
|
+
| Tests passing | [N] | [N] | 0 | EQUIVALENT |
|
|
306
|
+
| Tests total | [N] | [N] | 0 | EQUIVALENT |
|
|
307
|
+
| Type errors | [N] | [N] | 0 | EQUIVALENT |
|
|
308
|
+
| Pattern violations | 0 | 0 | 0 | EQUIVALENT |
|
|
309
|
+
| Hook build | Exit 0 | Exit 0 | - | EQUIVALENT |
|
|
310
|
+
|
|
311
|
+
**BEHAVIORAL EQUIVALENCE: PROVEN / NOT PROVEN**
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
**If NOT PROVEN:** Document the delta and determine if it's acceptable (e.g., test count increased because new tests were added — this is an IMPROVEMENT, not a regression).
|
|
315
|
+
|
|
316
|
+
---
|
|
317
|
+
|
|
318
|
+
## ABORT PROTOCOL
|
|
319
|
+
|
|
320
|
+
**If at any point the refactoring causes test regressions that cannot be resolved within 3 attempts per batch:**
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
# Revert ALL uncommitted changes
|
|
324
|
+
git checkout -- .
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
```markdown
|
|
328
|
+
### REFACTORING ABORTED
|
|
329
|
+
|
|
330
|
+
- **Reason**: [why the refactoring failed]
|
|
331
|
+
- **Batch that failed**: [batch N]
|
|
332
|
+
- **Error**: [what went wrong]
|
|
333
|
+
- **Files reverted**: ALL uncommitted changes
|
|
334
|
+
- **Recommendation**: [suggest /massu-create-plan with specific details about what needs careful planning]
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## MANDATORY PLAN DOCUMENT UPDATE (If Refactor From Plan)
|
|
340
|
+
|
|
341
|
+
**If this refactoring was part of a plan, update the plan document with completion status.**
|
|
342
|
+
|
|
343
|
+
```markdown
|
|
344
|
+
# IMPLEMENTATION STATUS
|
|
345
|
+
|
|
346
|
+
**Plan**: [Plan Name]
|
|
347
|
+
**Status**: REFACTOR COMPLETE
|
|
348
|
+
**Last Updated**: [YYYY-MM-DD HH:MM]
|
|
349
|
+
|
|
350
|
+
## Refactoring Applied
|
|
351
|
+
|
|
352
|
+
| # | Description | Status | Verification | Date |
|
|
353
|
+
|---|-------------|--------|--------------|------|
|
|
354
|
+
| 1 | [Refactoring desc] | COMPLETE | Behavioral Equivalence: PROVEN | [date] |
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
## AUTO-LEARNING PROTOCOL
|
|
360
|
+
|
|
361
|
+
After refactoring, if any issues were discovered:
|
|
362
|
+
|
|
363
|
+
1. **Record the pattern** - What went wrong and how it was fixed
|
|
364
|
+
2. **Check if pattern scanner should be updated** - Can the check be automated?
|
|
365
|
+
3. **Update session state** - Record in `.claude/session-state/CURRENT.md`
|
|
366
|
+
4. **Search codebase-wide** - Verify no other instances of same bad pattern (CR-9)
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## COMPLETION REPORT
|
|
371
|
+
|
|
372
|
+
```markdown
|
|
373
|
+
## CS REFACTOR COMPLETE
|
|
374
|
+
|
|
375
|
+
### Scope
|
|
376
|
+
- **Description**: [what was refactored]
|
|
377
|
+
- **Files changed**: [N]
|
|
378
|
+
- **Batches**: [N]
|
|
379
|
+
|
|
380
|
+
### Blast Radius
|
|
381
|
+
| Category | Count |
|
|
382
|
+
|----------|-------|
|
|
383
|
+
| Files changed | [N] |
|
|
384
|
+
| References updated | [N] |
|
|
385
|
+
| References kept (with reason) | [N] |
|
|
386
|
+
|
|
387
|
+
### Behavioral Equivalence Proof
|
|
388
|
+
| Metric | Before | After | Delta | Status |
|
|
389
|
+
|--------|--------|-------|-------|--------|
|
|
390
|
+
| Tests passing | [N] | [N] | [0] | EQUIVALENT |
|
|
391
|
+
| Type errors | [N] | [N] | [0] | EQUIVALENT |
|
|
392
|
+
|
|
393
|
+
### Verification Gates
|
|
394
|
+
| Gate | Status |
|
|
395
|
+
|------|--------|
|
|
396
|
+
| Pattern Scanner | PASS |
|
|
397
|
+
| Type Safety | PASS |
|
|
398
|
+
| Tests | PASS ([N] passed) |
|
|
399
|
+
| Hook Build | PASS |
|
|
400
|
+
| Negative Verification | PASS (0 stale references) |
|
|
401
|
+
|
|
402
|
+
### Changes Summary
|
|
403
|
+
| File | Change |
|
|
404
|
+
|------|--------|
|
|
405
|
+
| [file] | [description] |
|
|
406
|
+
|
|
407
|
+
### Next Steps
|
|
408
|
+
- Review changes: `git diff`
|
|
409
|
+
- Commit: `/massu-commit`
|
|
410
|
+
```
|