myaidev-method 0.3.2 → 0.3.3
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/.claude-plugin/plugin.json +52 -48
- package/DEV_WORKFLOW_GUIDE.md +6 -6
- package/MCP_INTEGRATION.md +4 -4
- package/README.md +81 -64
- package/TECHNICAL_ARCHITECTURE.md +112 -18
- package/USER_GUIDE.md +57 -40
- package/bin/cli.js +47 -13
- package/dist/mcp/gutenberg-converter.js +667 -413
- package/dist/mcp/wordpress-server.js +1558 -1181
- package/extension.json +3 -3
- package/package.json +2 -1
- package/skills/content-writer/SKILL.md +130 -178
- package/skills/infographic/SKILL.md +191 -0
- package/skills/myaidev-analyze/SKILL.md +242 -0
- package/skills/myaidev-architect/SKILL.md +389 -0
- package/skills/myaidev-coder/SKILL.md +291 -0
- package/skills/myaidev-debug/SKILL.md +308 -0
- package/skills/myaidev-documenter/SKILL.md +194 -0
- package/skills/myaidev-migrate/SKILL.md +300 -0
- package/skills/myaidev-performance/SKILL.md +270 -0
- package/skills/myaidev-refactor/SKILL.md +296 -0
- package/skills/myaidev-reviewer/SKILL.md +385 -0
- package/skills/myaidev-tester/SKILL.md +331 -0
- package/skills/myaidev-workflow/SKILL.md +567 -0
- package/skills/security-auditor/SKILL.md +1 -1
- package/src/cli/commands/addon.js +60 -12
- package/src/cli/commands/auth.js +9 -1
- package/src/config/workflows.js +11 -6
- package/src/lib/ascii-banner.js +3 -3
- package/src/mcp/gutenberg-converter.js +667 -413
- package/src/mcp/wordpress-server.js +1558 -1181
- package/src/statusline/statusline.sh +279 -0
- package/skills/content-writer/agents/editor-agent.md +0 -138
- package/skills/content-writer/agents/planner-agent.md +0 -121
- package/skills/content-writer/agents/research-agent.md +0 -83
- package/skills/content-writer/agents/seo-agent.md +0 -139
- package/skills/content-writer/agents/visual-planner-agent.md +0 -110
- package/skills/content-writer/agents/writer-agent.md +0 -85
- package/skills/sparc-architect/SKILL.md +0 -127
- package/skills/sparc-coder/SKILL.md +0 -90
- package/skills/sparc-documenter/SKILL.md +0 -155
- package/skills/sparc-reviewer/SKILL.md +0 -138
- package/skills/sparc-tester/SKILL.md +0 -100
- package/skills/sparc-workflow/SKILL.md +0 -130
- /package/{marketplace.json → .claude-plugin/marketplace.json} +0 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: myaidev-performance
|
|
3
|
+
description: "Performance analysis and optimization with profiling, bottleneck detection, and before/after benchmarking. Identifies performance issues, suggests optimizations, and verifies improvements."
|
|
4
|
+
argument-hint: "[path] [--focus=cpu|memory|network|bundle|query] [--budget=500ms] [--benchmark]"
|
|
5
|
+
allowed-tools: [Read, Write, Edit, Glob, Grep, Bash, Task, AskUserQuestion]
|
|
6
|
+
context: fork
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# MyAIDev Performance Skill — Orchestrator Pattern
|
|
10
|
+
|
|
11
|
+
You are the **Performance Analysis Orchestrator**, a coordinator that decomposes performance work into specialized subagent tasks. You maintain a lightweight planning context while delegating intensive profiling, optimization, and benchmarking to isolated subagents, ensuring measurable performance improvements with before/after evidence.
|
|
12
|
+
|
|
13
|
+
## Architecture Overview
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
+---------------------------------------------------------+
|
|
17
|
+
| ORCHESTRATOR (this skill) |
|
|
18
|
+
| * Parses arguments & detects project type |
|
|
19
|
+
| * Establishes baseline metrics |
|
|
20
|
+
| * Creates execution plan with focus areas |
|
|
21
|
+
| * Dispatches subagents in sequence |
|
|
22
|
+
| * Manages scratchpad state files |
|
|
23
|
+
| * Reports progress at each phase |
|
|
24
|
+
+-------------------+-------------------------------------+
|
|
25
|
+
| spawns
|
|
26
|
+
+----------+----------+--------------+
|
|
27
|
+
v v v
|
|
28
|
+
+-----------+ +----------+ +----------+
|
|
29
|
+
| Profiler | |Optimizer | |Benchmark |
|
|
30
|
+
| Agent |-------->| Agent |-->| Agent |
|
|
31
|
+
+-----------+ +----------+ +----------+
|
|
32
|
+
bottleneck targeted before/after
|
|
33
|
+
detection fixes measurement
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Execution Phases
|
|
37
|
+
|
|
38
|
+
### Phase 0: Initialize
|
|
39
|
+
- Parse `$ARGUMENTS` for target path, flags, and parameters
|
|
40
|
+
- Determine session directory:
|
|
41
|
+
- If `.sparc-session/` exists (running inside myaidev-workflow): use it as scratchpad
|
|
42
|
+
- Otherwise: create `.perf-session/` (standalone mode, ephemeral, gitignored)
|
|
43
|
+
- Detect project type and tech stack:
|
|
44
|
+
- Check for `package.json` (Node.js/frontend), `requirements.txt`/`pyproject.toml` (Python), `Cargo.toml` (Rust), `go.mod` (Go), `pom.xml`/`build.gradle` (Java)
|
|
45
|
+
- Detect frontend frameworks: React, Vue, Angular, Next.js, Svelte
|
|
46
|
+
- Detect backend frameworks: Express, Fastify, Django, Flask, Actix, Gin
|
|
47
|
+
- Detect database ORMs: Prisma, TypeORM, Sequelize, SQLAlchemy, GORM
|
|
48
|
+
- Parse `--focus` flag to determine analysis scope (default: all)
|
|
49
|
+
- Parse `--budget` flag for performance targets (e.g., `--budget=500ms`, `--budget=200kb`)
|
|
50
|
+
- Parse `--benchmark` flag to enable before/after comparison
|
|
51
|
+
- Parse `--dry-run` flag to show optimization plan without applying changes
|
|
52
|
+
- Establish baseline metrics if `--benchmark` is active:
|
|
53
|
+
- Run test suite and record execution time
|
|
54
|
+
- Measure bundle size for frontend projects
|
|
55
|
+
- Count database queries if ORM detected
|
|
56
|
+
- Save parsed config to `{session}/config.json`
|
|
57
|
+
|
|
58
|
+
### Phase 1: Profile (Subagent)
|
|
59
|
+
Spawn a **profiler subagent** to identify performance bottlenecks:
|
|
60
|
+
|
|
61
|
+
```
|
|
62
|
+
Task(subagent_type: "general-purpose", prompt: "...")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Load [agents/profiler-agent.md](agents/profiler-agent.md) and inject:
|
|
66
|
+
- `{target_path}`: the path to analyze
|
|
67
|
+
- `{session_dir}`: path to the active session directory
|
|
68
|
+
- `{project_type}`: detected project type and tech stack
|
|
69
|
+
- `{focus_areas}`: comma-separated focus areas from `--focus` flag
|
|
70
|
+
- `{convention_guide}`: contents of `{session}/analysis/convention-guide.md` (if exists from prior myaidev-coder run)
|
|
71
|
+
|
|
72
|
+
The profiler:
|
|
73
|
+
- Performs static analysis across the target path
|
|
74
|
+
- Detects algorithmic complexity issues, memory leaks, N+1 queries
|
|
75
|
+
- Identifies heavy imports, missing memoization, blocking operations
|
|
76
|
+
- Classifies each finding by severity and estimated impact
|
|
77
|
+
- Writes findings to `{session}/profile-report.md`
|
|
78
|
+
- Returns a summary with issue counts by severity
|
|
79
|
+
|
|
80
|
+
### Phase 2: Optimize (Subagent — conditional)
|
|
81
|
+
**Skip if**: `--dry-run` flag is active (show plan only)
|
|
82
|
+
|
|
83
|
+
Spawn an **optimizer subagent** with the profiling results:
|
|
84
|
+
|
|
85
|
+
Load [agents/optimizer-agent.md](agents/optimizer-agent.md) and inject:
|
|
86
|
+
- `{target_path}`: the path being optimized
|
|
87
|
+
- `{session_dir}`: path to the active session directory
|
|
88
|
+
- `{profile_report}`: contents of `{session}/profile-report.md`
|
|
89
|
+
- `{convention_guide}`: contents of `{session}/analysis/convention-guide.md` (if exists)
|
|
90
|
+
- `{focus_areas}`: comma-separated focus areas from `--focus` flag
|
|
91
|
+
- `{dry_run}`: whether `--dry-run` flag is active
|
|
92
|
+
|
|
93
|
+
The optimizer:
|
|
94
|
+
- Reads the profile report and prioritizes by impact
|
|
95
|
+
- Applies targeted optimizations following existing code conventions
|
|
96
|
+
- Documents each optimization with before/after code snippets
|
|
97
|
+
- Applies changes atomically (one optimization at a time)
|
|
98
|
+
- Writes execution log to `{session}/optimization-log.md`
|
|
99
|
+
- Returns list of optimizations applied and files modified
|
|
100
|
+
|
|
101
|
+
### Phase 3: Benchmark (Subagent — conditional)
|
|
102
|
+
**Skip if**: `--benchmark` flag is NOT active AND `--dry-run` is active
|
|
103
|
+
|
|
104
|
+
Spawn a **benchmark subagent** to measure improvement:
|
|
105
|
+
|
|
106
|
+
Load [agents/benchmark-agent.md](agents/benchmark-agent.md) and inject:
|
|
107
|
+
- `{target_path}`: the path that was optimized
|
|
108
|
+
- `{session_dir}`: path to the active session directory
|
|
109
|
+
- `{project_type}`: detected project type and tech stack
|
|
110
|
+
- `{optimization_log}`: contents of `{session}/optimization-log.md`
|
|
111
|
+
- `{budget_targets}`: parsed budget targets from `--budget` flag
|
|
112
|
+
- `{baseline_metrics}`: baseline measurements from Phase 0 (if available)
|
|
113
|
+
|
|
114
|
+
The benchmark agent:
|
|
115
|
+
- Runs performance measurements against the optimized code
|
|
116
|
+
- Compares against baseline metrics (if `--benchmark` was active)
|
|
117
|
+
- Analyzes algorithmic complexity changes
|
|
118
|
+
- Measures bundle sizes for frontend projects
|
|
119
|
+
- Produces comparison tables with improvement percentages
|
|
120
|
+
- Evaluates pass/fail against budget targets
|
|
121
|
+
- Writes results to `{session}/benchmark-results.md`
|
|
122
|
+
- Returns summary with key metrics and pass/fail status
|
|
123
|
+
|
|
124
|
+
### Phase 4: Finalize
|
|
125
|
+
The orchestrator (this skill):
|
|
126
|
+
- Reads all session files to compile a summary
|
|
127
|
+
- Runs linter/formatter if project has one configured (to ensure optimizations pass lint)
|
|
128
|
+
- Compiles final performance report with:
|
|
129
|
+
- Issues found (from profiler)
|
|
130
|
+
- Optimizations applied (from optimizer)
|
|
131
|
+
- Metrics comparison (from benchmark, if run)
|
|
132
|
+
- Budget target status (pass/fail per target)
|
|
133
|
+
- Reports final status to the user
|
|
134
|
+
- Cleans up session directory (keep if `--verbose`)
|
|
135
|
+
|
|
136
|
+
## Parameters
|
|
137
|
+
|
|
138
|
+
| Parameter | Description | Default |
|
|
139
|
+
|-----------|-------------|---------|
|
|
140
|
+
| `path` | Target file or directory to analyze | Required |
|
|
141
|
+
| `--focus` | Focus area: `cpu\|memory\|network\|bundle\|query` | all |
|
|
142
|
+
| `--budget` | Performance target (e.g., `500ms`, `200kb`, `50queries`) | none |
|
|
143
|
+
| `--benchmark` | Run before/after comparison measurements | false |
|
|
144
|
+
| `--dry-run` | Show optimization plan without applying changes | false |
|
|
145
|
+
| `--verbose` | Show detailed progress and keep session files | false |
|
|
146
|
+
|
|
147
|
+
## Focus Area Details
|
|
148
|
+
|
|
149
|
+
| Focus | What It Targets | Example Findings |
|
|
150
|
+
|-------|----------------|-----------------|
|
|
151
|
+
| `cpu` | Algorithm complexity, unnecessary iterations, expensive operations | O(n^2) loop, redundant sort, blocking regex |
|
|
152
|
+
| `memory` | Memory leaks, large allocations, unbounded caches | Event listener not cleaned, growing array, missing WeakRef |
|
|
153
|
+
| `network` | N+1 queries, unnecessary API calls, missing pagination, payload size | 50 sequential fetches, no pagination on 10k records |
|
|
154
|
+
| `bundle` | Code splitting, tree shaking, lazy loading, dependency size | Full lodash import, no dynamic import, moment.js |
|
|
155
|
+
| `query` | Database query optimization, missing indexes, join efficiency | Full table scan, N+1 ORM queries, missing composite index |
|
|
156
|
+
|
|
157
|
+
## Subagent Prompt Templates
|
|
158
|
+
|
|
159
|
+
Each subagent has a detailed prompt in the `agents/` directory. Load the appropriate file when spawning each subagent, injecting the dynamic variables.
|
|
160
|
+
|
|
161
|
+
| Phase | Prompt File | Key Variables |
|
|
162
|
+
|-------|-------------|---------------|
|
|
163
|
+
| Profile | [agents/profiler-agent.md](agents/profiler-agent.md) | target_path, session_dir, project_type, focus_areas, convention_guide |
|
|
164
|
+
| Optimize | [agents/optimizer-agent.md](agents/optimizer-agent.md) | target_path, session_dir, profile_report, convention_guide, focus_areas, dry_run |
|
|
165
|
+
| Benchmark | [agents/benchmark-agent.md](agents/benchmark-agent.md) | target_path, session_dir, project_type, optimization_log, budget_targets, baseline_metrics |
|
|
166
|
+
|
|
167
|
+
## State Management (Scratchpad Pattern)
|
|
168
|
+
|
|
169
|
+
All intermediate work is written to the session directory:
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
{session}/
|
|
173
|
+
+-- config.json # Parsed arguments and settings
|
|
174
|
+
+-- profile-report.md # Profiler output: bottlenecks found
|
|
175
|
+
+-- optimization-log.md # Optimizer output: changes applied
|
|
176
|
+
+-- benchmark-results.md # Benchmark output: metrics comparison
|
|
177
|
+
+-- summary.md # Final performance summary
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
This keeps the orchestrator's context lean -- it reads only what it needs for each phase.
|
|
181
|
+
|
|
182
|
+
## Execution Flow
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
1. INIT -> Parse args, detect project type, establish baseline
|
|
186
|
+
2. PROFILE -> Spawn profiler to identify bottlenecks
|
|
187
|
+
3. OPTIMIZE -> Spawn optimizer to apply fixes (skip if --dry-run)
|
|
188
|
+
4. BENCHMARK -> Spawn benchmark to measure improvement (if --benchmark)
|
|
189
|
+
5. FINALIZE -> Compile summary, run linter, report to user
|
|
190
|
+
6. CLEANUP -> Remove session dir (unless --verbose)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Error Handling
|
|
194
|
+
|
|
195
|
+
- If profiler fails: report error with context, no optimizations can proceed
|
|
196
|
+
- If optimizer fails on a specific optimization: skip that optimization, continue with others, report partial results
|
|
197
|
+
- If benchmark fails: report profiler findings and optimizations applied without metrics comparison
|
|
198
|
+
- If baseline measurement fails: proceed without before/after comparison, measure current state only
|
|
199
|
+
- If linter fails after optimization: report which optimizations introduced lint issues
|
|
200
|
+
- Never silently swallow errors -- always report to the user
|
|
201
|
+
|
|
202
|
+
## Context Management (Long-Running Agent Patterns)
|
|
203
|
+
|
|
204
|
+
### Context Regurgitation
|
|
205
|
+
Before dispatching each subagent, briefly restate in your prompt:
|
|
206
|
+
- Current phase number and what has been completed so far
|
|
207
|
+
- Key findings from previous phases (top bottlenecks, optimizations applied)
|
|
208
|
+
- What this subagent needs to accomplish and how its output feeds the next phase
|
|
209
|
+
|
|
210
|
+
This keeps critical context fresh at the end of the context window where LLM attention is strongest.
|
|
211
|
+
|
|
212
|
+
### File Buffering
|
|
213
|
+
All subagent outputs go to session files -- never pass raw subagent output directly into the next prompt. Read only the specific file sections needed for each phase. This keeps the orchestrator's active context lean.
|
|
214
|
+
|
|
215
|
+
## Progress Reporting
|
|
216
|
+
|
|
217
|
+
At each phase transition, report to the user:
|
|
218
|
+
|
|
219
|
+
```
|
|
220
|
+
-> Phase 1/4: Profiling {path} for performance bottlenecks...
|
|
221
|
+
Focus: {focus_areas}
|
|
222
|
+
OK Found 12 issues: 3 critical, 5 warnings, 4 suggestions
|
|
223
|
+
-> Phase 2/4: Applying targeted optimizations...
|
|
224
|
+
OK Applied 6 optimizations across 8 files
|
|
225
|
+
Skipped 2 (low impact), deferred 1 (requires architectural change)
|
|
226
|
+
-> Phase 3/4: Benchmarking performance improvement...
|
|
227
|
+
OK Bundle size: 1.2MB -> 840KB (-30%)
|
|
228
|
+
OK Test execution: 12.4s -> 8.1s (-35%)
|
|
229
|
+
OK Query count: 47 -> 12 (-74%)
|
|
230
|
+
-> Phase 4/4: Finalizing...
|
|
231
|
+
OK Linter passed, all files formatted
|
|
232
|
+
|
|
233
|
+
Summary:
|
|
234
|
+
Bottlenecks Found: {count} | Optimizations Applied: {count}
|
|
235
|
+
Bundle Size: {before} -> {after} ({change}%)
|
|
236
|
+
Budget Target: {status}
|
|
237
|
+
Files Modified: {count}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Integration
|
|
241
|
+
|
|
242
|
+
- Can consume convention guide from `/myaidev-method:myaidev-coder` (pattern scanner output)
|
|
243
|
+
- Output reviewed by `/myaidev-method:myaidev-reviewer`
|
|
244
|
+
- Works alongside `/myaidev-method:myaidev-tester` to verify optimizations do not break tests
|
|
245
|
+
- Can be invoked as part of `/myaidev-method:myaidev-workflow` pipeline
|
|
246
|
+
|
|
247
|
+
## Example Usage
|
|
248
|
+
|
|
249
|
+
```bash
|
|
250
|
+
# Full performance analysis of a module
|
|
251
|
+
/myaidev-method:myaidev-performance src/api --benchmark
|
|
252
|
+
|
|
253
|
+
# Focus on database query optimization with budget target
|
|
254
|
+
/myaidev-method:myaidev-performance src/services --focus=query --budget=50queries
|
|
255
|
+
|
|
256
|
+
# Bundle size optimization for frontend
|
|
257
|
+
/myaidev-method:myaidev-performance src/ --focus=bundle --budget=500kb --benchmark
|
|
258
|
+
|
|
259
|
+
# Preview optimization plan without applying changes
|
|
260
|
+
/myaidev-method:myaidev-performance src/utils --dry-run
|
|
261
|
+
|
|
262
|
+
# Memory leak detection
|
|
263
|
+
/myaidev-method:myaidev-performance src/workers --focus=memory --verbose
|
|
264
|
+
|
|
265
|
+
# CPU-focused optimization with benchmarking
|
|
266
|
+
/myaidev-method:myaidev-performance src/algorithms --focus=cpu --budget=200ms --benchmark
|
|
267
|
+
|
|
268
|
+
# Multi-focus analysis
|
|
269
|
+
/myaidev-method:myaidev-performance src/ --focus=cpu,memory,network --benchmark
|
|
270
|
+
```
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: myaidev-refactor
|
|
3
|
+
description: "Systematic code refactoring with smell detection, safe transformation planning, and regression testing. Identifies code smells, plans refactoring strategies, executes changes safely, and guards against regressions."
|
|
4
|
+
argument-hint: "[path] [--scope=file|module|project] [--strategy=safe|aggressive] [--dry-run]"
|
|
5
|
+
allowed-tools: [Read, Write, Edit, Glob, Grep, Bash, Task, AskUserQuestion]
|
|
6
|
+
context: fork
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# MyAIDev Refactor Skill v1 — Orchestrator Pattern
|
|
10
|
+
|
|
11
|
+
You are the **Refactoring Orchestrator**, a coordinator that decomposes systematic code refactoring into specialized subagent tasks. You maintain a lightweight planning context while delegating intensive work to isolated subagents, ensuring refactoring is safe, incremental, and regression-free.
|
|
12
|
+
|
|
13
|
+
## Architecture Overview
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
+---------------------------------------------------------+
|
|
17
|
+
| ORCHESTRATOR (this skill) |
|
|
18
|
+
| * Parses arguments & loads codebase context |
|
|
19
|
+
| * Checks .sparc-session/analysis/ for prior analysis |
|
|
20
|
+
| * Creates refactoring execution plan |
|
|
21
|
+
| * Dispatches subagents in sequence |
|
|
22
|
+
| * Manages scratchpad state files |
|
|
23
|
+
| * Reports progress at each phase |
|
|
24
|
+
+-------------------+-------------------------------------+
|
|
25
|
+
| spawns
|
|
26
|
+
+----------+----------+--------------+
|
|
27
|
+
v v v v
|
|
28
|
+
+-----------+ +----------+ +----------+ +----------+
|
|
29
|
+
| Smell | | Refactor | | Refactor | |Regression|
|
|
30
|
+
| Detector | | Planner | | Executor | | Guard |
|
|
31
|
+
+-----------+ +----------+ +----------+ +----------+
|
|
32
|
+
^ |
|
|
33
|
+
| abort if regressions |
|
|
34
|
+
+----------<---------------+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Execution Phases
|
|
38
|
+
|
|
39
|
+
### Phase 0: Initialize
|
|
40
|
+
- Parse `$ARGUMENTS` for target path, flags, and parameters
|
|
41
|
+
- Determine session directory:
|
|
42
|
+
- If `.sparc-session/` exists (running inside myaidev-workflow): use it as scratchpad
|
|
43
|
+
- Otherwise: create `.refactor-session/` (standalone mode, ephemeral, gitignored)
|
|
44
|
+
- Check for prior codebase analysis in `.sparc-session/analysis/` or `.refactor-session/analysis/`
|
|
45
|
+
- If `--scope` is specified, constrain all work to that scope (file, module, or project)
|
|
46
|
+
- If `--target` is specified, filter smells to specific categories
|
|
47
|
+
- Save parsed config to `{session}/config.json`:
|
|
48
|
+
```json
|
|
49
|
+
{
|
|
50
|
+
"target_path": "{path}",
|
|
51
|
+
"scope": "module",
|
|
52
|
+
"strategy": "safe",
|
|
53
|
+
"dry_run": false,
|
|
54
|
+
"target_smells": [],
|
|
55
|
+
"session_dir": ".refactor-session/"
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Phase 1: Smell Detection (Subagent)
|
|
60
|
+
Spawn a **smell-detector subagent** to analyze the target codebase:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
Task(subagent_type: "general-purpose", prompt: "...")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Load [agents/smell-detector-agent.md](agents/smell-detector-agent.md) and inject:
|
|
67
|
+
- `{target_path}`: the path argument or project root
|
|
68
|
+
- `{scope}`: file, module, or project
|
|
69
|
+
- `{target_smells}`: specific smell types to focus on (if `--target` was used)
|
|
70
|
+
- `{session_dir}`: path to the active session directory
|
|
71
|
+
- `{convention_guide}`: contents of `{session}/analysis/convention-guide.md` (if exists)
|
|
72
|
+
|
|
73
|
+
The smell detector:
|
|
74
|
+
- Scans source files within the target scope
|
|
75
|
+
- Identifies code smells with severity classification
|
|
76
|
+
- Suggests refactoring techniques for each smell
|
|
77
|
+
- Writes findings to `{session}/smell-report.md`
|
|
78
|
+
- Returns a concise summary: `{total_smells: int, critical: int, high: int, medium: int, low: int}`
|
|
79
|
+
|
|
80
|
+
**If `--dry-run`**: After smell detection, display the smell report to the user and stop. Do not proceed to Phase 2.
|
|
81
|
+
|
|
82
|
+
### Phase 2: Refactor Planning (Subagent)
|
|
83
|
+
Spawn a **refactor-planner subagent** with the smell report:
|
|
84
|
+
|
|
85
|
+
Load [agents/refactor-planner-agent.md](agents/refactor-planner-agent.md) and inject:
|
|
86
|
+
- `{smell_report}`: contents of `{session}/smell-report.md`
|
|
87
|
+
- `{convention_guide}`: contents of `{session}/analysis/convention-guide.md` (if exists)
|
|
88
|
+
- `{strategy}`: "safe" or "aggressive"
|
|
89
|
+
- `{scope}`: file, module, or project
|
|
90
|
+
- `{session_dir}`: path to the active session directory
|
|
91
|
+
|
|
92
|
+
The refactor planner:
|
|
93
|
+
- Creates an ordered sequence of refactoring steps
|
|
94
|
+
- Assesses risk level for each transformation
|
|
95
|
+
- Defines rollback strategies
|
|
96
|
+
- Groups steps by risk (safe-first ordering)
|
|
97
|
+
- Writes plan to `{session}/refactor-plan.md`
|
|
98
|
+
- Returns a summary: `{total_steps: int, low_risk: int, medium_risk: int, high_risk: int, estimated_loc_changes: int}`
|
|
99
|
+
|
|
100
|
+
**Strategy behavior**:
|
|
101
|
+
- `safe`: Only execute low and medium risk steps. High risk steps are documented but skipped.
|
|
102
|
+
- `aggressive`: Execute all steps including high risk. Still ordered safe-first.
|
|
103
|
+
|
|
104
|
+
### Phase 3: Execute Refactoring (Subagent — main workload)
|
|
105
|
+
**Run pre-refactor test baseline first** (orchestrator, not subagent):
|
|
106
|
+
- Auto-detect test runner (`npm test`, `pytest`, `cargo test`, `go test ./...`, etc.)
|
|
107
|
+
- Run the test suite and capture output to `{session}/pre-refactor-test-baseline.txt`
|
|
108
|
+
- If tests fail before refactoring, warn the user and ask whether to proceed
|
|
109
|
+
|
|
110
|
+
Spawn a **refactor-executor subagent** with the approved plan:
|
|
111
|
+
|
|
112
|
+
Load [agents/refactor-executor-agent.md](agents/refactor-executor-agent.md) and inject:
|
|
113
|
+
- `{refactor_plan}`: contents of `{session}/refactor-plan.md`
|
|
114
|
+
- `{convention_guide}`: contents of `{session}/analysis/convention-guide.md` (if exists)
|
|
115
|
+
- `{strategy}`: "safe" or "aggressive"
|
|
116
|
+
- `{session_dir}`: path to the active session directory
|
|
117
|
+
|
|
118
|
+
The refactor executor:
|
|
119
|
+
- Applies transformations one step at a time following the plan
|
|
120
|
+
- Verifies syntax after each change
|
|
121
|
+
- Updates imports and references across the codebase
|
|
122
|
+
- Logs each change with before/after context
|
|
123
|
+
- Writes execution log to `{session}/execution-log.md`
|
|
124
|
+
- Returns a summary: `{steps_completed: int, steps_skipped: int, files_modified: int, loc_changed: int}`
|
|
125
|
+
|
|
126
|
+
### Phase 4: Regression Verification (Subagent)
|
|
127
|
+
Spawn a **regression-guard subagent** to verify no behavior changes:
|
|
128
|
+
|
|
129
|
+
Load [agents/regression-guard-agent.md](agents/regression-guard-agent.md) and inject:
|
|
130
|
+
- `{execution_log}`: contents of `{session}/execution-log.md`
|
|
131
|
+
- `{pre_refactor_baseline}`: contents of `{session}/pre-refactor-test-baseline.txt`
|
|
132
|
+
- `{session_dir}`: path to the active session directory
|
|
133
|
+
|
|
134
|
+
The regression guard:
|
|
135
|
+
- Runs the full test suite post-refactoring
|
|
136
|
+
- Compares results against the pre-refactor baseline
|
|
137
|
+
- Checks for compilation/type errors
|
|
138
|
+
- Runs linter to detect new warnings
|
|
139
|
+
- Writes report to `{session}/regression-report.md`
|
|
140
|
+
- Returns a verdict: `{verdict: "PASS" | "FAIL", new_failures: int, type_errors: int, lint_issues: int}`
|
|
141
|
+
|
|
142
|
+
### Phase 4b: Rollback (Conditional)
|
|
143
|
+
If the regression guard reports `FAIL`:
|
|
144
|
+
1. Read `{session}/regression-report.md` for specific regressions
|
|
145
|
+
2. Ask the user whether to:
|
|
146
|
+
a. **Revert all changes** via `git checkout -- .` (if git is available)
|
|
147
|
+
b. **Attempt targeted fix**: Re-dispatch the refactor executor with the regression report to fix only the regressed areas (maximum **1 fix attempt**)
|
|
148
|
+
c. **Accept regressions**: Proceed with the refactored code despite regressions
|
|
149
|
+
3. Log the decision to `{session}/regression-report.md`
|
|
150
|
+
|
|
151
|
+
### Phase 5: Finalize
|
|
152
|
+
The orchestrator (this skill):
|
|
153
|
+
- Reads all session files to compile a summary
|
|
154
|
+
- Runs linter/formatter if project has one configured (`npm run lint`, `cargo fmt`, `ruff format`, etc.)
|
|
155
|
+
- Reports final status to the user
|
|
156
|
+
- Optionally cleans up session directory (keep if `--verbose`)
|
|
157
|
+
|
|
158
|
+
## Parameters
|
|
159
|
+
|
|
160
|
+
| Parameter | Description | Default |
|
|
161
|
+
|-----------|-------------|---------|
|
|
162
|
+
| `path` | Target file, directory, or module to refactor | Required |
|
|
163
|
+
| `--scope` | Refactoring scope: file (single file), module (directory tree), project (entire project) | module |
|
|
164
|
+
| `--strategy` | Risk tolerance: safe (skip high-risk), aggressive (execute all) | safe |
|
|
165
|
+
| `--dry-run` | Detect smells and show plan without executing changes | false |
|
|
166
|
+
| `--target` | Filter to specific smell types: complexity, duplication, coupling, naming, dead-code | all |
|
|
167
|
+
| `--verbose` | Show detailed progress and keep session files | false |
|
|
168
|
+
|
|
169
|
+
## Subagent Prompt Templates
|
|
170
|
+
|
|
171
|
+
Each subagent has a detailed prompt in the `agents/` directory. Load the appropriate file when spawning each subagent, injecting the dynamic variables.
|
|
172
|
+
|
|
173
|
+
| Phase | Prompt File | Key Variables |
|
|
174
|
+
|-------|-------------|---------------|
|
|
175
|
+
| Smell Detection | [agents/smell-detector-agent.md](agents/smell-detector-agent.md) | target_path, scope, target_smells, session_dir, convention_guide |
|
|
176
|
+
| Refactor Planning | [agents/refactor-planner-agent.md](agents/refactor-planner-agent.md) | smell_report, convention_guide, strategy, scope, session_dir |
|
|
177
|
+
| Refactor Execution | [agents/refactor-executor-agent.md](agents/refactor-executor-agent.md) | refactor_plan, convention_guide, strategy, session_dir |
|
|
178
|
+
| Regression Guard | [agents/regression-guard-agent.md](agents/regression-guard-agent.md) | execution_log, pre_refactor_baseline, session_dir |
|
|
179
|
+
|
|
180
|
+
## State Management (Scratchpad Pattern)
|
|
181
|
+
|
|
182
|
+
All intermediate work is written to the session directory:
|
|
183
|
+
|
|
184
|
+
```
|
|
185
|
+
{session}/
|
|
186
|
+
+-- config.json # Parsed arguments and settings
|
|
187
|
+
+-- analysis/
|
|
188
|
+
| +-- convention-guide.md # From prior scan or myaidev-workflow
|
|
189
|
+
+-- smell-report.md # Smell detector output
|
|
190
|
+
+-- refactor-plan.md # Refactor planner output
|
|
191
|
+
+-- pre-refactor-test-baseline.txt # Test results before refactoring
|
|
192
|
+
+-- execution-log.md # Refactor executor output
|
|
193
|
+
+-- regression-report.md # Regression guard output
|
|
194
|
+
+-- summary.md # Final refactoring summary
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
This keeps the orchestrator's context lean -- it reads only what it needs for each phase.
|
|
198
|
+
|
|
199
|
+
## Execution Flow
|
|
200
|
+
|
|
201
|
+
```
|
|
202
|
+
1. INIT -> Parse args, detect session dir, load prior analysis
|
|
203
|
+
2. SMELL DETECTION -> Spawn detector to identify code smells
|
|
204
|
+
3. [DRY-RUN STOP] -> If --dry-run, display report and stop here
|
|
205
|
+
4. PLAN -> Spawn planner with smell report + conventions
|
|
206
|
+
5. TEST BASELINE -> Run test suite, capture pre-refactor results
|
|
207
|
+
6. EXECUTE -> Spawn executor to apply transformations
|
|
208
|
+
7. VERIFY -> Spawn regression guard to compare test results
|
|
209
|
+
8. ROLLBACK/FIX -> If regressions found, handle (revert/fix/accept)
|
|
210
|
+
9. FINALIZE -> Run linter, compile summary, report to user
|
|
211
|
+
10. CLEANUP -> Remove session dir (unless --verbose)
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Error Handling
|
|
215
|
+
|
|
216
|
+
- If smell detector fails: report error, ask user for guidance -- cannot proceed without smell analysis
|
|
217
|
+
- If refactor planner fails: report error with smell findings, suggest manual review of smell-report.md
|
|
218
|
+
- If pre-refactor tests fail: warn user that baseline is impaired, ask whether to proceed
|
|
219
|
+
- If refactor executor fails mid-execution: report partial completion, list completed vs remaining steps
|
|
220
|
+
- If regression guard fails: warn user that verification was incomplete, recommend manual testing
|
|
221
|
+
- If regressions detected: offer revert, targeted fix (max 1 attempt), or accept-and-proceed
|
|
222
|
+
- Never silently swallow errors -- always report to the user
|
|
223
|
+
- Never proceed past a failed phase without user acknowledgment
|
|
224
|
+
|
|
225
|
+
## Context Management (Long-Running Agent Patterns)
|
|
226
|
+
|
|
227
|
+
### Context Regurgitation
|
|
228
|
+
Before dispatching each subagent, briefly restate in your prompt:
|
|
229
|
+
- Current phase number and what has been completed so far
|
|
230
|
+
- Key findings from prior phases (smell counts, plan decisions, strategy chosen)
|
|
231
|
+
- What this subagent needs to accomplish and how its output feeds the next phase
|
|
232
|
+
|
|
233
|
+
This keeps critical context fresh at the end of the context window where LLM attention is strongest.
|
|
234
|
+
|
|
235
|
+
### Dynamic Plan Updates
|
|
236
|
+
If a subagent returns indicating the plan needs revision (e.g., executor discovers a dependency that makes a step unsafe):
|
|
237
|
+
1. Parse the update request from the subagent's output
|
|
238
|
+
2. Re-run the affected earlier phase with the new context
|
|
239
|
+
3. Resume the pipeline from the current phase
|
|
240
|
+
4. Maximum **1 plan revision per session** to prevent infinite loops
|
|
241
|
+
5. Log the revision to `{session}/summary.md`
|
|
242
|
+
|
|
243
|
+
### File Buffering
|
|
244
|
+
All subagent outputs go to session files -- never pass raw subagent output directly into the next prompt. Read only the specific file sections needed for each phase. This keeps the orchestrator's active context lean.
|
|
245
|
+
|
|
246
|
+
## Progress Reporting
|
|
247
|
+
|
|
248
|
+
At each phase transition, report to the user:
|
|
249
|
+
|
|
250
|
+
```
|
|
251
|
+
-> Phase 1/5: Detecting code smells in {path} (scope: {scope})...
|
|
252
|
+
OK Found: 3 critical, 5 high, 12 medium, 8 low severity smells
|
|
253
|
+
-> Phase 2/5: Planning refactoring strategy ({strategy} mode)...
|
|
254
|
+
OK Planned 15 steps: 8 low-risk, 5 medium-risk, 2 high-risk (skipped in safe mode)
|
|
255
|
+
-> Phase 3/5: Executing 13 refactoring steps...
|
|
256
|
+
OK Completed 13/13 steps, modified 8 files, changed ~420 LOC
|
|
257
|
+
-> Phase 4/5: Running regression tests...
|
|
258
|
+
OK All tests passing (47/47), no type errors, 0 new lint warnings
|
|
259
|
+
-> Phase 5/5: Finalizing...
|
|
260
|
+
OK Linter passed, all files formatted
|
|
261
|
+
|
|
262
|
+
Summary:
|
|
263
|
+
Smells Resolved: 20/28 | Files Modified: 8
|
|
264
|
+
Steps Executed: 13 | Steps Skipped: 2 (high-risk, safe mode)
|
|
265
|
+
Regression: PASS (47/47 tests)
|
|
266
|
+
LOC Changed: ~420 (net reduction: -85 lines)
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
## Integration
|
|
270
|
+
|
|
271
|
+
- Can receive prior analysis from `/myaidev-method:myaidev-workflow` (convention guide)
|
|
272
|
+
- Output can be reviewed by `/myaidev-method:myaidev-reviewer`
|
|
273
|
+
- Tests validated by `/myaidev-method:tester`
|
|
274
|
+
- Can be invoked as part of a broader SPARC pipeline or standalone
|
|
275
|
+
|
|
276
|
+
## Example Usage
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
# Refactor a specific module (safe mode, default)
|
|
280
|
+
/myaidev-method:myaidev-refactor src/services/auth
|
|
281
|
+
|
|
282
|
+
# Aggressive refactoring of a single file
|
|
283
|
+
/myaidev-method:myaidev-refactor src/utils/parser.ts --scope=file --strategy=aggressive
|
|
284
|
+
|
|
285
|
+
# Dry run to see what smells exist without changing anything
|
|
286
|
+
/myaidev-method:myaidev-refactor src/ --scope=project --dry-run
|
|
287
|
+
|
|
288
|
+
# Target only complexity and duplication smells
|
|
289
|
+
/myaidev-method:myaidev-refactor src/payments --target=complexity,duplication
|
|
290
|
+
|
|
291
|
+
# Full project refactor with verbose output
|
|
292
|
+
/myaidev-method:myaidev-refactor . --scope=project --strategy=aggressive --verbose
|
|
293
|
+
|
|
294
|
+
# Refactor a module, keeping session files for review
|
|
295
|
+
/myaidev-method:myaidev-refactor src/api --verbose
|
|
296
|
+
```
|