@codename_inc/spectre 3.7.0 → 4.0.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 (102) hide show
  1. package/README.md +3 -4
  2. package/package.json +3 -2
  3. package/plugins/spectre/.claude-plugin/plugin.json +1 -1
  4. package/plugins/spectre/bin/spectre-register +5 -0
  5. package/plugins/spectre/hooks/hooks.json +3 -14
  6. package/plugins/spectre/hooks/scripts/bootstrap.mjs +98 -0
  7. package/plugins/spectre/hooks/scripts/handoff-resume.mjs +404 -0
  8. package/plugins/spectre/hooks/scripts/lib.mjs +82 -0
  9. package/plugins/spectre/hooks/scripts/load-knowledge.mjs +189 -0
  10. package/plugins/spectre/hooks/scripts/register_learning.mjs +264 -0
  11. package/plugins/spectre/hooks/scripts/{test_bootstrap.cjs → test_bootstrap.mjs} +12 -7
  12. package/plugins/spectre/hooks/scripts/{test_handoff-resume.cjs → test_handoff-resume.mjs} +13 -11
  13. package/plugins/spectre/hooks/scripts/{test_load-knowledge.cjs → test_load-knowledge.mjs} +103 -22
  14. package/plugins/spectre/hooks/scripts/test_register-learning.mjs +335 -0
  15. package/plugins/spectre/skills/apply/SKILL.md +87 -0
  16. package/plugins/spectre/{commands/architecture_review.md → skills/architecture_review/SKILL.md} +9 -0
  17. package/plugins/spectre/{commands/clean.md → skills/clean/SKILL.md} +9 -0
  18. package/plugins/spectre/{commands/code_review.md → skills/code_review/SKILL.md} +9 -0
  19. package/plugins/spectre/{commands/create_plan.md → skills/create_plan/SKILL.md} +9 -0
  20. package/plugins/spectre/{commands/create_tasks.md → skills/create_tasks/SKILL.md} +9 -0
  21. package/plugins/spectre/{commands/create_test_guide.md → skills/create_test_guide/SKILL.md} +9 -0
  22. package/plugins/spectre/{commands/evaluate.md → skills/evaluate/SKILL.md} +11 -2
  23. package/plugins/spectre/{commands/execute.md → skills/execute/SKILL.md} +12 -3
  24. package/plugins/spectre/{commands/fix.md → skills/fix/SKILL.md} +9 -0
  25. package/plugins/spectre/{commands/forget.md → skills/forget/SKILL.md} +9 -0
  26. package/plugins/spectre/skills/{spectre-guide → guide}/SKILL.md +2 -1
  27. package/plugins/spectre/{commands/handoff.md → skills/handoff/SKILL.md} +9 -0
  28. package/plugins/spectre/{commands/kickoff.md → skills/kickoff/SKILL.md} +9 -0
  29. package/plugins/spectre/skills/{spectre-learn → learn}/SKILL.md +19 -59
  30. package/plugins/spectre/skills/learn/references/recall-template.md +34 -0
  31. package/plugins/spectre/{commands/plan.md → skills/plan/SKILL.md} +66 -25
  32. package/plugins/spectre/{commands/plan_review.md → skills/plan_review/SKILL.md} +9 -0
  33. package/plugins/spectre/{commands/quick_dev.md → skills/quick_dev/SKILL.md} +9 -0
  34. package/plugins/spectre/{commands/rebase.md → skills/rebase/SKILL.md} +9 -0
  35. package/plugins/spectre/skills/recall/SKILL.md +17 -0
  36. package/plugins/spectre/{commands/research.md → skills/research/SKILL.md} +9 -0
  37. package/plugins/spectre/{commands/scope.md → skills/scope/SKILL.md} +9 -0
  38. package/plugins/spectre/{commands/ship.md → skills/ship/SKILL.md} +9 -0
  39. package/plugins/spectre/{commands/sweep.md → skills/sweep/SKILL.md} +9 -0
  40. package/plugins/spectre/skills/tdd/SKILL.md +111 -0
  41. package/plugins/spectre/{commands/test.md → skills/test/SKILL.md} +9 -0
  42. package/plugins/spectre/{commands/ux_spec.md → skills/ux_spec/SKILL.md} +9 -0
  43. package/plugins/spectre/{commands/validate.md → skills/validate/SKILL.md} +9 -0
  44. package/plugins/spectre-codex/agents/analyst.toml +117 -0
  45. package/plugins/spectre-codex/agents/dev.toml +65 -0
  46. package/plugins/spectre-codex/agents/finder.toml +101 -0
  47. package/plugins/spectre-codex/agents/patterns.toml +203 -0
  48. package/plugins/spectre-codex/agents/reviewer.toml +123 -0
  49. package/plugins/spectre-codex/agents/sync.toml +146 -0
  50. package/plugins/spectre-codex/agents/tester.toml +205 -0
  51. package/plugins/spectre-codex/agents/web-research.toml +104 -0
  52. package/plugins/spectre-codex/hooks/hooks.json +23 -0
  53. package/plugins/{spectre/hooks/scripts/bootstrap.cjs → spectre-codex/hooks/scripts/bootstrap.mjs} +15 -16
  54. package/plugins/{spectre/hooks/scripts/handoff-resume.cjs → spectre-codex/hooks/scripts/handoff-resume.mjs} +21 -27
  55. package/plugins/{spectre/hooks/scripts/lib.cjs → spectre-codex/hooks/scripts/lib.mjs} +3 -4
  56. package/plugins/spectre-codex/hooks/scripts/load-knowledge.mjs +189 -0
  57. package/plugins/spectre-codex/hooks/scripts/register_learning.mjs +264 -0
  58. package/plugins/spectre-codex/skills/apply/SKILL.md +87 -0
  59. package/plugins/spectre-codex/skills/architecture_review/SKILL.md +129 -0
  60. package/plugins/spectre-codex/skills/clean/SKILL.md +322 -0
  61. package/plugins/spectre-codex/skills/code_review/SKILL.md +417 -0
  62. package/plugins/spectre-codex/skills/create_plan/SKILL.md +126 -0
  63. package/plugins/spectre-codex/skills/create_tasks/SKILL.md +383 -0
  64. package/plugins/spectre-codex/skills/create_test_guide/SKILL.md +129 -0
  65. package/plugins/spectre-codex/skills/evaluate/SKILL.md +59 -0
  66. package/plugins/spectre-codex/skills/execute/SKILL.md +96 -0
  67. package/plugins/spectre-codex/skills/fix/SKILL.md +70 -0
  68. package/plugins/spectre-codex/skills/forget/SKILL.md +67 -0
  69. package/plugins/spectre-codex/skills/guide/SKILL.md +359 -0
  70. package/plugins/spectre-codex/skills/handoff/SKILL.md +170 -0
  71. package/plugins/spectre-codex/skills/kickoff/SKILL.md +124 -0
  72. package/plugins/spectre-codex/skills/learn/SKILL.md +595 -0
  73. package/plugins/{spectre/skills/spectre-learn → spectre-codex/skills/learn}/references/recall-template.md +4 -1
  74. package/plugins/spectre-codex/skills/plan/SKILL.md +211 -0
  75. package/plugins/spectre-codex/skills/plan_review/SKILL.md +42 -0
  76. package/plugins/spectre-codex/skills/quick_dev/SKILL.md +110 -0
  77. package/plugins/spectre-codex/skills/rebase/SKILL.md +82 -0
  78. package/plugins/spectre-codex/skills/recall/SKILL.md +17 -0
  79. package/plugins/spectre-codex/skills/research/SKILL.md +168 -0
  80. package/plugins/spectre-codex/skills/scope/SKILL.md +128 -0
  81. package/plugins/spectre-codex/skills/ship/SKILL.md +181 -0
  82. package/plugins/spectre-codex/skills/sweep/SKILL.md +91 -0
  83. package/plugins/{spectre/skills/spectre-tdd → spectre-codex/skills/tdd}/SKILL.md +1 -1
  84. package/plugins/spectre-codex/skills/test/SKILL.md +389 -0
  85. package/plugins/spectre-codex/skills/ux_spec/SKILL.md +100 -0
  86. package/plugins/spectre-codex/skills/validate/SKILL.md +352 -0
  87. package/src/config.test.js +6 -5
  88. package/src/install.test.js +100 -11
  89. package/src/lib/config.js +107 -54
  90. package/src/lib/constants.js +17 -23
  91. package/src/lib/doctor.js +19 -22
  92. package/src/lib/install.js +98 -313
  93. package/src/lib/knowledge.js +7 -37
  94. package/src/lib/paths.js +0 -12
  95. package/src/pack.test.js +87 -0
  96. package/plugins/spectre/commands/learn.md +0 -15
  97. package/plugins/spectre/commands/recall.md +0 -5
  98. package/plugins/spectre/hooks/scripts/load-knowledge.cjs +0 -120
  99. package/plugins/spectre/hooks/scripts/precompact-warning.cjs +0 -19
  100. package/plugins/spectre/hooks/scripts/register_learning.cjs +0 -144
  101. package/plugins/spectre/hooks/scripts/test_register-learning.cjs +0 -146
  102. package/plugins/spectre/skills/spectre-apply/SKILL.md +0 -189
@@ -0,0 +1,129 @@
1
+ ---
2
+ name: "architecture_review"
3
+ description: "👻 | Conduct principal architecture review"
4
+ user-invocable: true
5
+ ---
6
+
7
+ # architecture_review
8
+
9
+ ## Input Handling
10
+
11
+ Treat the current command arguments as this workflow's input. When invoked from a slash command, use the forwarded `$ARGUMENTS` value.
12
+
13
+
14
+ # architecture_review: Technical review of completed features
15
+
16
+ ## Description
17
+ - **What** — Principal systems architect review focusing on compounding decisions: architectural debt, missed abstractions, performance cliffs, unnecessary complexity
18
+ - **Outcome** — Architecture review report with actionable findings organized by severity and type
19
+
20
+ ## Variables
21
+
22
+ ### Dynamic Variables
23
+ - `feature_description`: Feature being reviewed — (via ARGUMENTS). If
24
+ - `paths_or_files`: Relevant paths to examine — (via ARGUMENTS)
25
+ - `arch_notes_or_docs`: Existing architecture context — (via ARGUMENTS, optional)
26
+
27
+ ### ARGUMENTS Input
28
+
29
+ <ARGUMENTS>
30
+ $ARGUMENTS
31
+ </ARGUMENTS>
32
+
33
+ ## Instructions
34
+
35
+ **Review Philosophy** (cross-cutting guidelines):
36
+ - **Compounding matters**: Focus on what gets harder to change later, not what's easy to fix now
37
+ - **Simplicity is a feature**: The best code is often less code, fewer abstractions, fewer moving parts
38
+ - **Context is king**: A "bad" pattern in isolation might be the right choice given project constraints
39
+ - **Be specific**: Vague feedback like "could be more modular" is useless. Point to exact files, functions, and concrete alternatives
40
+
41
+ **Constraints**:
42
+ - Don't suggest changes that would take longer to implement than the feature itself unless they're critical
43
+ - Don't recommend adding abstractions "for future flexibility" unless there's concrete evidence we'll need them
44
+ - If you don't have concerns in a section, say "No concerns" and move on—don't manufacture feedback
45
+ - Be direct. "This is fine" is a valid assessment.
46
+
47
+ **Adapt**
48
+ - If ARGUMENTS is empty, gather the review scope from the current thread context.
49
+ - If the current thread context is also ambigious, ask the user to clarify the scope of the review.
50
+
51
+ ## Step (1/3) - Review Existing Architecture Documents
52
+ - **Action** - ReviewArchitecture: Find and review existing architecture documents
53
+ - search for docs/architecture.md and read it if it exists
54
+ - if not, continue and use general architectural best practices during review
55
+
56
+ ## Step (1/2) - Explore Implementation
57
+
58
+ - **Action** — ExploreCode: Thoroughly examine the implementation
59
+ - Read the code at `paths_or_files`
60
+ - Understand the data flow
61
+ - Trace the dependencies
62
+ - Review `arch_notes_or_docs` if provided
63
+ - **If**: Paths unclear or missing
64
+ - **Then**: Ask for clarification before proceeding
65
+ - **Else**: Continue to review
66
+
67
+ ## Step (2/2) - Produce Review Report
68
+
69
+ - **Action** — GenerateReview: Create structured architecture review using Report format below
70
+ - Apply Review Philosophy guidelines throughout
71
+ - Apply Constraints (no manufactured feedback, proportionate suggestions)
72
+ - **If**: No concerns in a section
73
+ - **Then**: State "No concerns" and move on
74
+ - **Else**: Provide specific, actionable feedback
75
+
76
+ ## Report
77
+
78
+ **Output Format** — Architecture review with these sections:
79
+
80
+ ### Executive Summary
81
+ 2-3 sentences: What's the architectural story here? Is this feature setting us up well or creating future pain?
82
+
83
+ ### Critical Issues (address before moving on)
84
+ Issues that will cause significant pain if left unaddressed—architectural violations, major performance problems, or patterns that will spread.
85
+
86
+ For each issue:
87
+ - **What**: The specific problem
88
+ - **Where**: Exact file(s) and line(s)
89
+ - **Why it matters**: The compounding cost over time
90
+ - **Suggested fix**: Concrete, implementable alternative
91
+
92
+ ### Simplification Opportunities
93
+ Places where we're overengineering, where a simpler approach would work, or where we've introduced abstractions we don't yet need.
94
+
95
+ ### Architecture Alignment
96
+ - Does this follow existing project patterns, or introduce new ones?
97
+ - If new patterns: Are they intentional improvements or accidental divergence?
98
+ - Are there existing utilities/patterns in the codebase this should have used?
99
+
100
+ ### Future-Proofing Considerations
101
+ - What assumptions is this code making that might not hold?
102
+ - If this feature grows 10x in usage/complexity, what breaks first?
103
+ - Are there integration points that need better contracts/interfaces?
104
+
105
+ ### Performance Notes
106
+ Only mention performance if there's a clear problem or a clear win—don't speculate about micro-optimizations.
107
+
108
+ ### What's Done Well
109
+ Briefly note architectural choices worth preserving or patterns worth spreading to other parts of the codebase.
110
+
111
+ ## Success Criteria
112
+
113
+ **Step 1 - Explore Implementation**:
114
+ - [ ] All specified paths/files read and understood
115
+ - [ ] Data flow traced through implementation
116
+ - [ ] Dependencies identified and examined
117
+ - [ ] Architecture context reviewed if provided
118
+
119
+ **Step 2 - Produce Review Report**:
120
+ - [ ] Executive Summary provides clear architectural assessment (2-3 sentences)
121
+ - [ ] Critical Issues include What/Where/Why/Suggested fix for each
122
+ - [ ] Simplification Opportunities identify overengineering (or "No concerns")
123
+ - [ ] Architecture Alignment addresses pattern consistency
124
+ - [ ] Future-Proofing identifies assumptions and scaling concerns
125
+ - [ ] Performance Notes only included if clear problem/win exists
126
+ - [ ] What's Done Well acknowledges good patterns
127
+ - [ ] All feedback is specific with exact files/lines
128
+ - [ ] No manufactured feedback—"No concerns" used when appropriate
129
+ - [ ] Suggestions proportionate to feature scope
@@ -0,0 +1,322 @@
1
+ ---
2
+ name: "clean"
3
+ description: "👻 | Complete cleanup flow - clean, inspect, lint, test - primary agent"
4
+ user-invocable: true
5
+ ---
6
+
7
+ # clean
8
+
9
+ ## Input Handling
10
+
11
+ Treat the current command arguments as this workflow's input. When invoked from a slash command, use the forwarded `$ARGUMENTS` value.
12
+
13
+ # clean: Analyze recent changes for dead code and artifacts from failed branches
14
+
15
+ ## Description
16
+
17
+ - **What** — Analyze a scoped working set (commit range, unstaged changes, or context window) to identify dead code, orphaned artifacts, and remnants from abandoned implementation attempts; dispatch parallel subagents to investigate and validate findings
18
+ - **Outcome** — Clean code with all dead artifacts from recent work removed; validated removal tasks ready for execution
19
+
20
+ ## Variables
21
+
22
+ ### Dynamic Variables
23
+
24
+ - `commit_id`: Optional starting commit - analyzes all changes **from and including this commit** through HEAD plus staged/unstaged/untracked — (via ARGUMENTS: $ARGUMENTS)
25
+ - **INCLUDES** the commit_id commit itself and all subsequent commits through HEAD
26
+ - If commit_id equals HEAD, working set will be staged + unstaged + untracked only
27
+ - If commit_id is invalid or not in history, **STOP and ask user for guidance**
28
+ - `scope_mode`: One of: `commit_range`, `unstaged`, `context` — determines working set
29
+ - `target_out_dir`: Optional OUT_DIR override
30
+
31
+ ### Static Variables
32
+
33
+ - `out_dir`: docs/tasks/{branch_name}
34
+ - `analysis_dir`: {out_dir}/cleanup_analysis
35
+ - `reports_subdir`: {analysis_dir}/area_reports
36
+ - `validation_subdir`: {analysis_dir}/validations
37
+ - `max_parallel_agents`: 4
38
+
39
+ ## ARGUMENTS Input
40
+
41
+ Optional scope specification. If ambiguous, ask user to clarify.
42
+
43
+ &lt;ARGUMENTS&gt; $ARGUMENTS &lt;/ARGUMENTS&gt;
44
+
45
+ ## Codebase Structure
46
+
47
+ **Relevant Files**:
48
+
49
+ - Working set files determined by scope
50
+ - `package.json` — Dependencies context
51
+ - `tsconfig.json` — TypeScript configuration
52
+ - `.gitignore` — Exclusion patterns to respect
53
+
54
+ ## Instructions
55
+
56
+ - **Primary goal**: Remove dead code artifacts left behind from recent work, especially failed implementation branches
57
+ - Never mark production code as safe to remove without validation
58
+ - Respect .gitignore patterns when analyzing files
59
+ - Document uncertainty clearly; flag items requiring manual review
60
+ - All file paths must be absolute from repository root
61
+ - Focus on artifacts likely created during recent work: unused functions, orphaned imports, commented-out code, debug statements
62
+ - **File safety**: Default filenames (`working_set.json`, `initial_findings.md`, `duplication_report.md`, `cleanup_summary.md`) must never overwrite existing files—if a target exists, create a scoped variant (append scope/task/timestamp) and use that path in messaging.
63
+ - when committing, —no-verify and eslint-disable, or committing code with eslint-disable, is expressly forbidden without the user's explicit permission.
64
+
65
+ ## Step (1/7) - Determine Working Set Scope
66
+
67
+ - **Action** — DetermineScope: Identify which files to analyze
68
+ - **If** ARGUMENTS contains `commit_id` or commit SHA:
69
+ - **First**: Validate commit_id exists: `git rev-parse --verify {commit_id}^{commit} 2>/dev/null`
70
+ - **If validation fails**: STOP and ask user "Commit {commit_id} is invalid or not found in history. Please provide a valid commit SHA or ref."
71
+ - **Else**: proceed with discovery
72
+ - Committed changes: `git log --name-only --pretty=format: {commit_id}^..HEAD | sort -u`
73
+ - **IMPORTANT**: Uses `{commit_id}^..HEAD` to INCLUDE the commit_id commit itself
74
+ - Staged changes: `git diff --cached --name-only`
75
+ - Unstaged changes: `git diff --name-only`
76
+ - Untracked files: `git ls-files --others --exclude-standard`
77
+ - **Working Set** = UNION of all four sets above
78
+ - **ElseIf** ARGUMENTS specifies "unstaged" or "staged":
79
+ - Staged changes: `git diff --cached --name-only`
80
+ - Unstaged changes: `git diff --name-only`
81
+ - Untracked files: `git ls-files --others --exclude-standard`
82
+ - **Working Set** = UNION of all three
83
+ - **ElseIf** ARGUMENTS specifies "context" or mentions current session:
84
+ - Ask user: "Which files from our current session should I analyze? List the files/directories or say 'all discussed files'"
85
+ - **Wait** — User specifies files
86
+ - **Working Set** = User-specified files
87
+ - **Else** (scope ambiguous):
88
+ - Ask user: "How should I scope the cleanup analysis?"
89
+ - `1` — From a specific commit (provide SHA)
90
+ - `2` — Current unstaged/staged changes only
91
+ - `3` — Files we've discussed in this session
92
+ - **Wait** — User selects scope mode
93
+ - **Action** — RecordWorkingSet: Save working set to `{analysis_dir}/working_set.json`
94
+ - Include: file list, scope mode, commit range (if applicable)
95
+ - **Action** — DetermineOutputDir: Set output location
96
+ - `branch_name=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo unknown)`
97
+ - **If** user specifies `target_out_dir` → `OUT_DIR={target_out_dir}`
98
+ - **Else** → `OUT_DIR={out_dir}`
99
+ - `mkdir -p "OUT_DIR/{analysis_dir}/{reports_subdir}"`
100
+ - `mkdir -p "OUT_DIR/{analysis_dir}/{validation_subdir}"`
101
+
102
+ ## Step (2/7) - Analyze Working Set for Dead Code Patterns
103
+
104
+ - **Action** — IdentifyDeadCodePatterns: Scan working set files for common dead code indicators
105
+ - **Patterns to detect** (ordered by likelihood after failed branches):
106
+ 1. **Orphaned imports** — imports with no usage in the file
107
+ 2. **Unused functions/variables** — declared but never called/referenced
108
+ 3. **Commented-out code blocks** — large blocks of commented code (&gt;5 lines)
109
+ 4. **Debug artifacts** — debugger statements, TODO/FIXME from current work
110
+ 5. **Temporary logging** — development-time logging to remove:
111
+ - console.log/warn/error without structured context (bare strings, variable dumps)
112
+ - Logging inside loops or hot paths (per-iteration logging)
113
+ - Debug prefixes: "DEBUG:", "TODO:", "TEMP:", "XXX:", "HACK:"
114
+ - Variable dumps: `console.log(varName)`, `console.log({var1, var2})`
115
+ - Checkpoint logs: "here", "got here", "reached X", "entering/exiting"
116
+ - Timing logs not part of production observability
117
+ - Commented-out logging statements
118
+ 6. **Dead branches** — unreachable code paths, always-false conditions
119
+ 7. **Orphaned exports** — exports not imported anywhere in codebase
120
+ 8. **Duplicate implementations** — similar code suggesting abandoned refactor
121
+ 9. **Test artifacts** — `.only`, skipped tests, test data that should be removed
122
+ 10. **AI code slop** — patterns inconsistent with codebase style:
123
+ - Excessive comments a human wouldn't add or inconsistent with file style
124
+ - Unnecessary defensive checks/try-catch in trusted codepaths
125
+ - Casts to `any` to bypass type issues
126
+ - Over-documentation of obvious code
127
+ - Verbose patterns where codebase uses concise ones
128
+ - For each file in working set: identify potential issues with file:line references
129
+ - **Action** — ChunkAnalysis: Group findings by file/module for parallel investigation
130
+ - Create 2-5 investigation chunks based on working set size
131
+ - Each chunk: area name, files, identified patterns, investigation focus
132
+ - **Action** — SaveInitialFindings: Write to `{analysis_dir}/initial_findings.md` (use a scoped variant like `initial_findings_{timestamp}.md` if the default exists; never overwrite)
133
+ - Include: pattern counts, file list per pattern, investigation priorities
134
+
135
+ ## Step (3/7) - Analyze Duplication
136
+
137
+ - **Action** — DetectDuplication: Find repeated code patterns in working set
138
+
139
+ - **Patterns to detect**:
140
+ - Copy-pasted logic (&gt;5 similar lines, 2+ instances)
141
+ - Nearly-identical functions with cosmetic differences (variable names differ, same logic)
142
+ - Repeated type definitions or interfaces
143
+ - Same validation/transform/fetch patterns across files
144
+ - **Output per cluster**:
145
+ - All instance locations (file:line)
146
+ - Pattern description
147
+ - Extraction recommendation (where to consolidate)
148
+ - Effort estimate (low/medium/high)
149
+ - Ignore intentional duplication (test fixtures, generated code)
150
+
151
+ - **Action** — GenerateDuplicationReport: Write `{analysis_dir}/duplication_report.md` (or a scoped variant if it already exists; do not overwrite)
152
+
153
+ - **Format**:
154
+
155
+ ```plaintext
156
+ ## Duplicate Code Clusters
157
+
158
+ ### Cluster 1: {pattern_name} ({instance_count} instances)
159
+ - `{file1}:{lines}`
160
+ - `{file2}:{lines}`
161
+ - `{file3}:{lines}`
162
+
163
+ **Pattern**: {description}
164
+ **Recommendation**: Extract to `{suggested_location}`
165
+ **Effort**: {low|medium|high}
166
+ ```
167
+
168
+ ## Step (4/7) - Dispatch Investigation Subagents
169
+
170
+ - **Action** — PrepareSubagentPrompts: Generate investigation prompts for each chunk
171
+
172
+ **Subagent Investigation Instructions Template**:
173
+
174
+ ```markdown
175
+ You are investigating recent changes in {area_name} for dead code artifacts.
176
+
177
+ **Context**: These files were recently modified. Look for artifacts from failed implementation attempts, abandoned branches, or incomplete refactors.
178
+
179
+ **Files in scope**: {file_list}
180
+ **Initial patterns detected**: {patterns_for_area}
181
+
182
+ **Your task**:
183
+ 1. Review all files in scope thoroughly
184
+ 2. For EACH potential issue, verify:
185
+ - Is this code actually unused? (check imports, calls, references)
186
+ - Is this a remnant from a failed approach? (check git history if needed)
187
+ - Could this break something if removed? (check dependencies)
188
+ 3. Categorize findings:
189
+ - SAFE_TO_REMOVE: Confirmed dead code, no dependencies
190
+ - NEEDS_VALIDATION: Likely dead but needs confirmation
191
+ - KEEP: Actually used or unclear
192
+ 4. Document evidence for each finding
193
+
194
+ **Output format**: Markdown report with sections per issue type.
195
+ **Critical**: Be conservative. When in doubt, mark NEEDS_VALIDATION.
196
+
197
+ Save your report to: {reports_subdir}/{area_name}_report.md (if that file exists, append a unique identifier such as `{area_name}_{timestamp}.md`; never overwrite)
198
+ ```
199
+
200
+ - **Action** — SpawnSubagents: Launch parallel investigation agents (up to {max_parallel_agents})
201
+ - For each chunk: spawn subagent with investigation prompt
202
+ - Set output path: `{reports_subdir}/{area_name}_report.md` (or scoped variant if default exists)
203
+ - **Wait** — All investigation subagents complete and save reports
204
+
205
+ ## Step (5/7) - Validate High-Risk Findings
206
+
207
+ - **Action** — ConsolidateReports: Read all investigation reports from `{reports_subdir}/`
208
+ - Group findings: SAFE_TO_REMOVE, NEEDS_VALIDATION, KEEP
209
+ - Extract SAFE_TO_REMOVE items involving:
210
+ - Function/class deletions
211
+ - File deletions
212
+ - Export removals
213
+ - **Action** — PrepareValidationPrompts: Generate validation prompts for high-risk items
214
+
215
+ **Subagent Validation Instructions Template**:
216
+
217
+ ```markdown
218
+ You are validating a finding from dead code analysis.
219
+
220
+ **Original finding**:
221
+ {finding_description}
222
+ {file_path}:{line_numbers}
223
+ {reasoning_from_investigation}
224
+
225
+ **Your task**:
226
+ 1. Search codebase for ANY usage (dynamic imports, string refs, reflection)
227
+ 2. Check test files for usage
228
+ 3. Verify the code is actually dead, not just indirectly used
229
+ 4. Determine: CONFIRMED_SAFE, UNSAFE, or UNCERTAIN
230
+
231
+ **Output format**: Markdown with verdict, evidence, reasoning.
232
+
233
+ Save to: {validation_subdir}/{task_id}_validation.md (if that file exists, append a unique identifier; never overwrite)
234
+ ```
235
+
236
+ - **Action** — SpawnValidationAgents: Launch validation agents (up to {max_parallel_agents})
237
+ - **Wait** — All validation subagents complete
238
+
239
+ ## Step (6/7) - Generate Removal Tasks, Verify & Commit
240
+
241
+ - **Action** — ReadValidations: Load validation results from `{validation_subdir}/`
242
+ - Group by verdict: CONFIRMED_SAFE, UNSAFE, UNCERTAIN
243
+ - **Action** — ReconcileFindings: Create final removal list
244
+ - CONFIRMED_SAFE → approved for removal
245
+ - UNSAFE → document why, exclude from removal
246
+ - UNCERTAIN → flag for manual review
247
+ - **Action** — GenerateSummary: Create `{analysis_dir}/cleanup_summary.md` (or a scoped variant if it already exists; do not overwrite)
248
+ - Sections:
249
+ - **Executive Summary**: Scope analyzed, findings count, safe removals
250
+ - **Safe Removals**: List with file:line, what to remove, why it's safe
251
+ - **Manual Review Required**: Items needing human decision
252
+ - **Excluded Items**: What was kept and why
253
+ - **Estimated Impact**: Lines of dead code to remove
254
+ - **Action** — CreateRemovalTasks: Generate removal task files
255
+ - For each CONFIRMED_SAFE: task with exact removal instructions
256
+ - Save to `{analysis_dir}/removal_tasks/task_{id}.md`
257
+ - **Action** — PresentFindings: Show user the summary and request approval
258
+ - Present summary: X files analyzed, Y items safe to remove, Z need review
259
+ - **Wait** — User approves specific tasks or all CONFIRMED_SAFE items
260
+ - **Action** — ExecuteRemovals: Perform removals sequentially
261
+ - **If**: User hasn't approved any tasks → Skip execution
262
+ - **Else**: For each approved task:
263
+ - File deletion → `rm {file_path}`
264
+ - Code removal → Use Edit tool to remove lines
265
+ - Document change in `{analysis_dir}/changes_log.md`
266
+ - **Action** — Verify: Run lint and tests
267
+ - Run lint, fix violations
268
+ - Run tests for affected areas
269
+ - **If**: Tests fail → Rollback change, document failure
270
+ - **Else**: Confirm removal successful
271
+ - **Action** — CommitPlanningArtifacts: Stage and commit analysis docs
272
+ - Check for uncommitted files in `{out_dir}` and `{analysis_dir}`:
273
+ - `working_set.json`, `initial_findings.md`, `duplication_report.md`
274
+ - `cleanup_summary.md`
275
+ - Area reports in `{reports_subdir}/`
276
+ - Validation reports in `{validation_subdir}/`
277
+ - Any other `.md` or `.json` artifacts created during this flow
278
+ - **If** uncommitted planning artifacts exist:
279
+ - Stage all: `git add {out_dir}/ {analysis_dir}/`
280
+ - Commit: `docs(clean): add cleanup analysis artifacts for {branch_name}`
281
+ - **Action** — CommitCodeChanges: Commit removals by type (chore/refactor/fix/test), conventional format
282
+ - **Action** — RenderFooter: Render Next Steps via `Skill(spectre-guide)`
283
+
284
+ ## Step (7/7) - ESLint Compliance Planning
285
+
286
+ **Purpose**: Systematically identify tech debt from eslint-disable comments in the working set.
287
+
288
+ **7a. Collect ESLint Bypasses**:
289
+
290
+ ```bash
291
+ grep -rn "eslint-disable\|@ts-ignore\|@ts-expect-error" --include="*.ts" --include="*.tsx" --include="*.js" --include="*.jsx"
292
+ ```
293
+
294
+ **7b. Group by Module**: Cluster findings by directory or logical module (files that import each other).
295
+
296
+ **7c. For each group with ≥2 bypasses**, dispatch @analyst in parallel:
297
+
298
+ ```plaintext
299
+ Analyze ESLint bypasses in: {file_list}
300
+
301
+ For each bypass:
302
+ 1. Identify the disabled rule(s)
303
+ 2. Understand WHY it was disabled (type issue? legacy code? third-party types?)
304
+ 3. Determine the proper fix (type narrowing, interface update, refactor, etc.)
305
+
306
+ Output a refactor plan:
307
+ - File: path
308
+ - Line: number
309
+ - Rule: disabled-rule-name
310
+ - Reason: why it exists
311
+ - Fix: specific refactor steps
312
+ - Effort: trivial / moderate / significant
313
+ - Risk: low / medium / high
314
+ ```
315
+
316
+ **7d. Present Refactor Summary**:
317
+
318
+ - Group by effort level (trivial fixes first)
319
+ - Flag high-risk items for user decision
320
+ - Create actionable items for future cleanup sprints
321
+
322
+ **Note**: This step is diagnostic. Actual refactoring happens in follow-up tasks, not during clean.