milens 0.6.3 → 0.6.4
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/.agents/skills/adapters/SKILL.md +31 -0
- package/.agents/skills/analyzer/SKILL.md +55 -0
- package/.agents/skills/apps/SKILL.md +42 -0
- package/.agents/skills/docs/SKILL.md +46 -0
- package/.agents/skills/milens/SKILL.md +168 -0
- package/.agents/skills/milens-code-review/SKILL.md +186 -0
- package/.agents/skills/milens-eval/SKILL.md +221 -0
- package/.agents/skills/milens-plan/SKILL.md +227 -0
- package/.agents/skills/milens-refactor-clean/SKILL.md +209 -0
- package/.agents/skills/milens-security-review/SKILL.md +224 -0
- package/.agents/skills/milens-tdd/SKILL.md +156 -0
- package/.agents/skills/parser/SKILL.md +60 -0
- package/.agents/skills/root/SKILL.md +64 -0
- package/.agents/skills/scripts/SKILL.md +27 -0
- package/.agents/skills/security/SKILL.md +44 -0
- package/.agents/skills/server/SKILL.md +46 -0
- package/.agents/skills/store/SKILL.md +53 -0
- package/.agents/skills/test/SKILL.md +73 -0
- package/LICENSE +75 -75
- package/README.md +508 -432
- package/adapters/README.md +107 -0
- package/adapters/claude-code/.claude/mcp.json +9 -0
- package/adapters/claude-code/CLAUDE.md +58 -0
- package/adapters/codex/.codex/codex.md +52 -0
- package/adapters/copilot/.github/copilot-instructions.md +62 -0
- package/adapters/cursor/.cursorrules +9 -0
- package/adapters/gemini/.gemini/context.md +58 -0
- package/adapters/opencode/.opencode/config.json +9 -0
- package/adapters/opencode/AGENTS.md +58 -0
- package/adapters/zed/.zed/settings.json +8 -0
- package/dist/agents-md.d.ts +3 -0
- package/dist/agents-md.d.ts.map +1 -0
- package/dist/agents-md.js +112 -0
- package/dist/agents-md.js.map +1 -0
- package/dist/analyzer/engine.js +1 -1
- package/dist/analyzer/engine.js.map +1 -1
- package/dist/cli.js +1190 -401
- package/dist/cli.js.map +1 -1
- package/dist/metrics.d.ts +51 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +64 -0
- package/dist/metrics.js.map +1 -0
- package/dist/parser/lang-go.js +47 -47
- package/dist/parser/lang-java.js +29 -29
- package/dist/parser/lang-js.js +105 -105
- package/dist/parser/lang-php.js +38 -38
- package/dist/parser/lang-py.js +34 -34
- package/dist/parser/lang-ruby.js +14 -14
- package/dist/parser/lang-rust.js +30 -30
- package/dist/parser/lang-ts.js +191 -191
- package/dist/security/deps.d.ts +38 -0
- package/dist/security/deps.d.ts.map +1 -0
- package/dist/security/deps.js +685 -0
- package/dist/security/deps.js.map +1 -0
- package/dist/security/rules.d.ts +42 -0
- package/dist/security/rules.d.ts.map +1 -0
- package/dist/security/rules.js +940 -0
- package/dist/security/rules.js.map +1 -0
- package/dist/server/hooks.d.ts +26 -0
- package/dist/server/hooks.d.ts.map +1 -0
- package/dist/server/hooks.js +253 -0
- package/dist/server/hooks.js.map +1 -0
- package/dist/server/mcp-prompts.d.ts +277 -0
- package/dist/server/mcp-prompts.d.ts.map +1 -0
- package/dist/server/mcp-prompts.js +627 -0
- package/dist/server/mcp-prompts.js.map +1 -0
- package/dist/server/mcp.d.ts.map +1 -1
- package/dist/server/mcp.js +618 -643
- package/dist/server/mcp.js.map +1 -1
- package/dist/server/test-plan.d.ts +20 -0
- package/dist/server/test-plan.d.ts.map +1 -0
- package/dist/server/test-plan.js +100 -0
- package/dist/server/test-plan.js.map +1 -0
- package/dist/skills.js +152 -152
- package/dist/store/annotations.d.ts +41 -0
- package/dist/store/annotations.d.ts.map +1 -0
- package/dist/store/annotations.js +192 -0
- package/dist/store/annotations.js.map +1 -0
- package/dist/store/confidence.d.ts +18 -0
- package/dist/store/confidence.d.ts.map +1 -0
- package/dist/store/confidence.js +82 -0
- package/dist/store/confidence.js.map +1 -0
- package/dist/store/db.d.ts +37 -14
- package/dist/store/db.d.ts.map +1 -1
- package/dist/store/db.js +332 -239
- package/dist/store/db.js.map +1 -1
- package/dist/store/schema.sql +128 -116
- package/dist/store/vectors.js +2 -2
- package/dist/types.d.ts +101 -0
- package/dist/types.d.ts.map +1 -1
- package/docs/README.md +24 -0
- package/package.json +80 -66
- package/dist/gateway/analyzer.d.ts +0 -6
- package/dist/gateway/analyzer.d.ts.map +0 -1
- package/dist/gateway/analyzer.js +0 -218
- package/dist/gateway/analyzer.js.map +0 -1
- package/dist/gateway/cache.d.ts +0 -35
- package/dist/gateway/cache.d.ts.map +0 -1
- package/dist/gateway/cache.js +0 -175
- package/dist/gateway/cache.js.map +0 -1
- package/dist/gateway/config.d.ts +0 -10
- package/dist/gateway/config.d.ts.map +0 -1
- package/dist/gateway/config.js +0 -167
- package/dist/gateway/config.js.map +0 -1
- package/dist/gateway/context-memory.d.ts +0 -68
- package/dist/gateway/context-memory.d.ts.map +0 -1
- package/dist/gateway/context-memory.js +0 -157
- package/dist/gateway/context-memory.js.map +0 -1
- package/dist/gateway/observability.d.ts +0 -83
- package/dist/gateway/observability.d.ts.map +0 -1
- package/dist/gateway/observability.js +0 -152
- package/dist/gateway/observability.js.map +0 -1
- package/dist/gateway/privacy.d.ts +0 -27
- package/dist/gateway/privacy.d.ts.map +0 -1
- package/dist/gateway/privacy.js +0 -139
- package/dist/gateway/privacy.js.map +0 -1
- package/dist/gateway/providers.d.ts +0 -66
- package/dist/gateway/providers.d.ts.map +0 -1
- package/dist/gateway/providers.js +0 -377
- package/dist/gateway/providers.js.map +0 -1
- package/dist/gateway/router.d.ts +0 -18
- package/dist/gateway/router.d.ts.map +0 -1
- package/dist/gateway/router.js +0 -102
- package/dist/gateway/router.js.map +0 -1
- package/dist/gateway/server.d.ts +0 -20
- package/dist/gateway/server.d.ts.map +0 -1
- package/dist/gateway/server.js +0 -387
- package/dist/gateway/server.js.map +0 -1
- package/dist/gateway/translator.d.ts +0 -19
- package/dist/gateway/translator.d.ts.map +0 -1
- package/dist/gateway/translator.js +0 -340
- package/dist/gateway/translator.js.map +0 -1
- package/dist/gateway/types.d.ts +0 -215
- package/dist/gateway/types.d.ts.map +0 -1
- package/dist/gateway/types.js +0 -3
- package/dist/gateway/types.js.map +0 -1
- package/dist/store/gateway-schema.sql +0 -53
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: milens-eval
|
|
3
|
+
description: Evaluation & Quality Gate — plan, implement, verify scope, review risk, run tests, check coverage, and pass/fail
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# milens-eval — Evaluation & Quality Gate
|
|
7
|
+
|
|
8
|
+
A structured quality gate for feature development: plan tests, implement changes, verify scope, review risks, run impacted tests, check coverage gaps, and produce a pass/fail verdict.
|
|
9
|
+
|
|
10
|
+
## Tools Required
|
|
11
|
+
|
|
12
|
+
| Tool | Purpose |
|
|
13
|
+
|---|---|
|
|
14
|
+
| `mcp_milens_test_plan` | Generate test strategy before implementation |
|
|
15
|
+
| `mcp_milens_detect_changes` | Verify only expected files changed after implementation |
|
|
16
|
+
| `mcp_milens_review_pr` | Risk assessment of the changes |
|
|
17
|
+
| `mcp_milens_test_impact` | Identify and run affected test files |
|
|
18
|
+
| `mcp_milens_test_coverage_gaps` | Verify no new untested critical symbols introduced |
|
|
19
|
+
|
|
20
|
+
> **CRITICAL:** All milens MCP tool calls MUST include the `repo` parameter set to the **absolute path of the workspace root**.
|
|
21
|
+
|
|
22
|
+
## Workflow
|
|
23
|
+
|
|
24
|
+
### Step 1: Plan Tests (Before Implementation)
|
|
25
|
+
|
|
26
|
+
Before writing code, plan the test strategy.
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
mcp_milens_test_plan({name: "<symbolName>", repo: "<workspaceRoot>"})
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This provides:
|
|
33
|
+
- **Mock strategy** — what dependencies to isolate
|
|
34
|
+
- **Test scenarios** — happy path, error states, edge cases
|
|
35
|
+
- **Affected test files** — existing test files that may need updates
|
|
36
|
+
|
|
37
|
+
Review the plan to ensure it covers:
|
|
38
|
+
- Core functionality (happy path)
|
|
39
|
+
- Input validation (error handling)
|
|
40
|
+
- Integration points (service boundaries)
|
|
41
|
+
- Edge cases (null, empty, boundary values)
|
|
42
|
+
|
|
43
|
+
### Step 2: Implement Changes
|
|
44
|
+
|
|
45
|
+
Write the actual code changes. This is the implementation phase:
|
|
46
|
+
1. Write or update the target symbol(s)
|
|
47
|
+
2. Implement tests following the plan from Step 1
|
|
48
|
+
3. Follow existing code conventions and patterns
|
|
49
|
+
4. No `console.log`, no commented-out code, no debug artifacts
|
|
50
|
+
|
|
51
|
+
### Step 3: Detect Changes
|
|
52
|
+
|
|
53
|
+
Verify the scope of changes matches expectations.
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
mcp_milens_detect_changes({repo: "<workspaceRoot>"})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Check:
|
|
60
|
+
- **Expected files present** — all intended modifications are listed
|
|
61
|
+
- **No unexpected files** — no config drift, accidental staging, or side effects
|
|
62
|
+
- **No missing files** — if a file you expected to change is absent, investigate
|
|
63
|
+
|
|
64
|
+
### Step 4: Review Risk
|
|
65
|
+
|
|
66
|
+
Assess the quality and risk of the changes.
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
mcp_milens_review_pr({repo: "<workspaceRoot>"})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Focus on:
|
|
73
|
+
- **CRITICAL symbols** — any symbol rated CRITICAL needs thorough review
|
|
74
|
+
- **Risk distribution** — how many HIGH/MEDIUM/LOW symbols changed
|
|
75
|
+
- **Review suggestions** — automated findings to address
|
|
76
|
+
|
|
77
|
+
### Step 5: Run Tests
|
|
78
|
+
|
|
79
|
+
Identify and run all affected tests.
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
mcp_milens_test_impact({repo: "<workspaceRoot>"})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
This returns the list of test files impacted by the changes. Run them all:
|
|
86
|
+
- If any test fails: fix before proceeding
|
|
87
|
+
- If a test you didn't expect is affected: investigate why
|
|
88
|
+
- If a test you expected is missing: your test files may not be indexed
|
|
89
|
+
|
|
90
|
+
### Step 6: Check Coverage Gaps
|
|
91
|
+
|
|
92
|
+
Verify no new untested critical symbols were introduced.
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
mcp_milens_test_coverage_gaps({repo: "<workspaceRoot>", limit: 20})
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Review the output:
|
|
99
|
+
- **Newly introduced symbols** — should have test coverage
|
|
100
|
+
- **Pre-existing gaps** — note them but don't fail the gate (they're not new)
|
|
101
|
+
- **HIGH risk + no tests** — if any HIGH-risk symbol in the change has no tests, this is a failure
|
|
102
|
+
|
|
103
|
+
### Step 7: Quality Gate Verdict
|
|
104
|
+
|
|
105
|
+
Apply the pass/fail criteria (see Quality Gate section below) and produce a verdict:
|
|
106
|
+
|
|
107
|
+
**PASSED:**
|
|
108
|
+
- All test files pass
|
|
109
|
+
- No CRITICAL review_pr findings
|
|
110
|
+
- No unexpected files in detect_changes
|
|
111
|
+
- No new HIGH-risk uncovered symbols
|
|
112
|
+
|
|
113
|
+
**CONDITIONAL PASS:**
|
|
114
|
+
- All tests pass
|
|
115
|
+
- CRITICAL review_pr findings are acknowledged and documented with remediation plan
|
|
116
|
+
- Minor unexpected files that are harmless (lockfile updates)
|
|
117
|
+
|
|
118
|
+
**FAILED:**
|
|
119
|
+
- Any test fails
|
|
120
|
+
- Hardcoded secrets found
|
|
121
|
+
- Blast radius exceeds safe threshold without justification
|
|
122
|
+
- New HIGH-risk symbols with zero test coverage
|
|
123
|
+
|
|
124
|
+
## Example Session
|
|
125
|
+
|
|
126
|
+
### Input
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
"evaluate the feature branch for the new rate limiter"
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Tool Calls
|
|
133
|
+
|
|
134
|
+
**Step 1 — Test plan:**
|
|
135
|
+
```
|
|
136
|
+
mcp_milens_test_plan({name: "RateLimiter", repo: "/home/user/project"})
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**Output:**
|
|
140
|
+
```
|
|
141
|
+
Test Plan for RateLimiter:
|
|
142
|
+
Mock strategy: stub Redis client, stub clock
|
|
143
|
+
Tests:
|
|
144
|
+
1. allows requests within limit
|
|
145
|
+
2. blocks requests exceeding limit
|
|
146
|
+
3. resets counter after window expires
|
|
147
|
+
4. handles Redis connection failure gracefully
|
|
148
|
+
Affected: src/__tests__/middleware.test.ts (new)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Step 2 — Implement** rate limiter class and tests.
|
|
152
|
+
|
|
153
|
+
**Step 3 — Detect changes:**
|
|
154
|
+
```
|
|
155
|
+
mcp_milens_detect_changes({repo: "/home/user/project"})
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
**Output:**
|
|
159
|
+
```
|
|
160
|
+
Changed files:
|
|
161
|
+
src/middleware/rateLimiter.ts [new]
|
|
162
|
+
src/__tests__/middleware.test.ts [new]
|
|
163
|
+
src/middleware/index.ts [modified] — barrel export
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
3 files — all expected.
|
|
167
|
+
|
|
168
|
+
**Step 4 — Review risk:**
|
|
169
|
+
```
|
|
170
|
+
mcp_milens_review_pr({repo: "/home/user/project"})
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Output:**
|
|
174
|
+
```
|
|
175
|
+
Affected symbols:
|
|
176
|
+
RateLimiter [class] MEDIUM — 2 callers, 4 tests
|
|
177
|
+
applyRateLimit [function] LOW — 0 callers (internal helper)
|
|
178
|
+
|
|
179
|
+
No CRITICAL findings. 1 LOW suggestion: add JSDoc to RateLimiter class.
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**Step 5 — Test impact:**
|
|
183
|
+
```
|
|
184
|
+
mcp_milens_test_impact({repo: "/home/user/project"})
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Output:**
|
|
188
|
+
```
|
|
189
|
+
Affected test files:
|
|
190
|
+
src/__tests__/middleware.test.ts (new)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
Run tests: `npm test -- middleware.test.ts` — all 4 pass.
|
|
194
|
+
|
|
195
|
+
**Step 6 — Coverage gaps:**
|
|
196
|
+
```
|
|
197
|
+
mcp_milens_test_coverage_gaps({repo: "/home/user/project", limit: 20})
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**Output:** No new HIGH-risk symbols introduced. 3 pre-existing LOW/medium gaps unrelated to this change.
|
|
201
|
+
|
|
202
|
+
**Step 7 — Verdict: PASSED.**
|
|
203
|
+
|
|
204
|
+
## Best Practices
|
|
205
|
+
|
|
206
|
+
1. **Test plan before code, not after.** Step 1 exists to prevent "I'll test it later." Write the plan, review it, then implement.
|
|
207
|
+
2. **detect_changes is your safety net.** If it shows a `package-lock.json` change you didn't intend, something went wrong. Investigate every unexpected file.
|
|
208
|
+
3. **Treat CRITICAL review findings as blockers.** Don't rationalize them away. A CRITICAL finding means the change introduces significant risk.
|
|
209
|
+
4. **Coverage gaps are relative to the change.** Don't fail the gate because of pre-existing gaps. Fail only if the change itself introduces new uncovered critical symbols.
|
|
210
|
+
5. **Conditional passes need a deadline.** If you issue a "Conditional Pass," document exactly what must be fixed and by when. An open-ended conditional is a failed gate in disguise.
|
|
211
|
+
|
|
212
|
+
## Quality Gate
|
|
213
|
+
|
|
214
|
+
| Criteria | Pass | Fail |
|
|
215
|
+
|---|---|---|
|
|
216
|
+
| Test plan exists | Test plan generated with ≥3 scenarios | No test plan or < 3 scenarios |
|
|
217
|
+
| Change scope | `detect_changes` shows only expected files | Unexpected files in diff (unless harmless) |
|
|
218
|
+
| Review risk | No CRITICAL findings | Unresolved CRITICAL findings |
|
|
219
|
+
| Test execution | All `test_impact` files pass | Any test file fails |
|
|
220
|
+
| Coverage gaps | No new HIGH-risk symbols without tests | New HIGH-risk symbol has 0 test coverage |
|
|
221
|
+
| Gate verdict | PASSED or CONDITIONAL PASS (with documented remediation) | FAILED — must fix and re-run evaluation |
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: milens-plan
|
|
3
|
+
description: Implementation Planning — research codebase, analyze impact, plan tests, and produce a structured implementation plan
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# milens-plan — Implementation Planning
|
|
7
|
+
|
|
8
|
+
Research the codebase end-to-end before writing code: understand structure, trace execution, assess blast radius, plan tests, and produce a structured plan following the ECC Planner specification.
|
|
9
|
+
|
|
10
|
+
## Tools Required
|
|
11
|
+
|
|
12
|
+
| Tool | Purpose |
|
|
13
|
+
|---|---|
|
|
14
|
+
| `mcp_milens_codebase_summary` | High-level project overview (languages, file count, domain count) |
|
|
15
|
+
| `mcp_milens_domains` | Module clusters showing logical groupings |
|
|
16
|
+
| `mcp_milens_routes` | API endpoints inventory with handler mappings |
|
|
17
|
+
| `mcp_milens_smart_context` | Intent-aware symbol analysis (edit intent) |
|
|
18
|
+
| `mcp_milens_edit_check` | Pre-edit safety: callers, export status, re-export chains, warnings |
|
|
19
|
+
| `mcp_milens_trace` | Execution flow from entrypoints to target |
|
|
20
|
+
| `mcp_milens_impact` | Blast radius: what breaks if target changes |
|
|
21
|
+
| `mcp_milens_test_plan` | Mock strategy + test scenarios for a symbol |
|
|
22
|
+
| `mcp_milens_test_coverage_gaps` | Related untested symbols |
|
|
23
|
+
|
|
24
|
+
> **CRITICAL:** All milens MCP tool calls MUST include the `repo` parameter set to the **absolute path of the workspace root**.
|
|
25
|
+
|
|
26
|
+
## Workflow
|
|
27
|
+
|
|
28
|
+
### Step 1: Project Overview
|
|
29
|
+
|
|
30
|
+
Understand the codebase at a high level.
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
mcp_milens_codebase_summary({repo: "<workspaceRoot>"})
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Captures: languages, file counts, total symbols, top-level domains, entry points.
|
|
37
|
+
|
|
38
|
+
### Step 2: Domain Structure
|
|
39
|
+
|
|
40
|
+
Map module clusters to understand logical groupings.
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
mcp_milens_domains({repo: "<workspaceRoot>"})
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Shows which files form cohesive modules based on the dependency graph. Helps identify:
|
|
47
|
+
- Where the target code lives
|
|
48
|
+
- Which domains interact with it
|
|
49
|
+
- Natural boundaries for the change
|
|
50
|
+
|
|
51
|
+
### Step 3: API Surface (optional)
|
|
52
|
+
|
|
53
|
+
If the project is a web service, inventory the endpoints.
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
mcp_milens_routes({repo: "<workspaceRoot>"})
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Useful when the change touches:
|
|
60
|
+
- Route handlers
|
|
61
|
+
- Middleware
|
|
62
|
+
- Request/response types
|
|
63
|
+
- Authentication/authorization
|
|
64
|
+
|
|
65
|
+
### Step 4: Target Analysis
|
|
66
|
+
|
|
67
|
+
Zoom in on the specific symbol to change.
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
mcp_milens_smart_context({name: "<symbolName>", intent: "edit", repo: "<workspaceRoot>"})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The `edit` intent returns: callers, export status, and immediate blast radius — only what matters for editing.
|
|
74
|
+
|
|
75
|
+
### Step 5: Pre-Edit Safety Check
|
|
76
|
+
|
|
77
|
+
Run `edit_check` for pre-edit warnings.
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
mcp_milens_edit_check({name: "<symbolName>", repo: "<workspaceRoot>"})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
This returns:
|
|
84
|
+
- **Callers** — who calls this symbol
|
|
85
|
+
- **Export status** — whether it's public API
|
|
86
|
+
- **Re-export chains** — barrel file re-exports that extend blast radius
|
|
87
|
+
- **Warnings** — breaking change risks, high fan-in, etc.
|
|
88
|
+
|
|
89
|
+
### Step 6: Execution Flow
|
|
90
|
+
|
|
91
|
+
Trace how the target gets called at runtime.
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
mcp_milens_trace({name: "<symbolName>", direction: "to", repo: "<workspaceRoot>"})
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Shows the call chains from entrypoints down to this symbol. Critical for understanding:
|
|
98
|
+
- What triggers this code
|
|
99
|
+
- What data flows into it
|
|
100
|
+
- What side effects it may have
|
|
101
|
+
|
|
102
|
+
### Step 7: Blast Radius
|
|
103
|
+
|
|
104
|
+
Assess the full impact of the proposed change.
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
mcp_milens_impact({target: "<symbolName>", depth: 3, repo: "<workspaceRoot>"})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Shows all symbols that break if the target changes, up to the specified depth.
|
|
111
|
+
- If depth-1 dependents > 5: **STOP and warn** before proceeding
|
|
112
|
+
- If depth-3 dependents > 20: **consider a facade or adapter pattern**
|
|
113
|
+
|
|
114
|
+
### Step 8: Test Strategy
|
|
115
|
+
|
|
116
|
+
Plan the testing approach.
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
mcp_milens_test_plan({name: "<symbolName>", repo: "<workspaceRoot>"})
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Covers:
|
|
123
|
+
- Mock strategy (what to isolate)
|
|
124
|
+
- Test scenarios (happy path, edge cases, error handling)
|
|
125
|
+
- Affected test files
|
|
126
|
+
|
|
127
|
+
### Step 9: Coverage Gaps (optional)
|
|
128
|
+
|
|
129
|
+
Check for related symbols that lack test coverage.
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
mcp_milens_test_coverage_gaps({repo: "<workspaceRoot>", limit: 10})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
If neighboring symbols are untested, consider adding tests as part of the change.
|
|
136
|
+
|
|
137
|
+
### Step 10: Produce Implementation Plan
|
|
138
|
+
|
|
139
|
+
Consolidate all findings into a structured plan:
|
|
140
|
+
|
|
141
|
+
1. **Executive Summary** — what changes, why, at what risk level
|
|
142
|
+
2. **Codebase Context** — domains, routes, and structure (from Steps 1-3)
|
|
143
|
+
3. **Symbol Analysis** — target details, callers, execution flow (from Steps 4-6)
|
|
144
|
+
4. **Impact Assessment** — blast radius, breaking change risks, dependents map (from Step 7)
|
|
145
|
+
5. **Test Strategy** — test plan, mock strategy, coverage gaps (from Steps 8-9)
|
|
146
|
+
6. **Implementation Steps** — ordered, actionable steps with file paths
|
|
147
|
+
7. **Risk Mitigation** — rollback plan, feature flags, phased deployment options
|
|
148
|
+
|
|
149
|
+
## Example Session
|
|
150
|
+
|
|
151
|
+
### Input
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
"plan a change to add rate limiting to the login handler"
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### Tool Calls
|
|
158
|
+
|
|
159
|
+
**Step 1:**
|
|
160
|
+
```
|
|
161
|
+
mcp_milens_codebase_summary({repo: "/home/user/project"})
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**Output:** TypeScript project, 120 files, 850 symbols, 5 domains (auth, routes, db, utils, config).
|
|
165
|
+
|
|
166
|
+
**Step 2:**
|
|
167
|
+
```
|
|
168
|
+
mcp_milens_domains({repo: "/home/user/project"})
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**Output:** `auth` domain contains login handler, token manager, session store.
|
|
172
|
+
|
|
173
|
+
**Step 4:**
|
|
174
|
+
```
|
|
175
|
+
mcp_milens_smart_context({name: "loginHandler", intent: "edit", repo: "/home/user/project"})
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Output:** 3 callers (Express route, rate limiter middleware, integration test), no re-exports.
|
|
179
|
+
|
|
180
|
+
**Step 5:**
|
|
181
|
+
```
|
|
182
|
+
mcp_milens_edit_check({name: "loginHandler", repo: "/home/user/project"})
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Output:** 3 callers, exported, no re-export chains, **WARNING: exported function — changing signature is a breaking change.**
|
|
186
|
+
|
|
187
|
+
**Step 6:**
|
|
188
|
+
```
|
|
189
|
+
mcp_milens_trace({name: "loginHandler", direction: "to", repo: "/home/user/project"})
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Output:** Chain: `Express router → authMiddleware → loginHandler → tokenService.sign()`
|
|
193
|
+
|
|
194
|
+
**Step 7:**
|
|
195
|
+
```
|
|
196
|
+
mcp_milens_impact({target: "loginHandler", depth: 3, repo: "/home/user/project"})
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
**Output:** Depth-1: 3 dependents (route, integration test, auth docs). Depth-2: 8 dependents. Depth-3: 14 dependents. **No STOP threshold breached.**
|
|
200
|
+
|
|
201
|
+
**Step 8:**
|
|
202
|
+
```
|
|
203
|
+
mcp_milens_test_plan({name: "loginHandler", repo: "/home/user/project"})
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**Output:** Mock `tokenService`, `userStore`. 4 test scenarios: valid login, invalid password, rate limit exceeded, database failure.
|
|
207
|
+
|
|
208
|
+
**Step 10 — Plan produced** (see plan format above).
|
|
209
|
+
|
|
210
|
+
## Best Practices
|
|
211
|
+
|
|
212
|
+
1. **Never skip impact analysis.** Even a "small" change can ripple through re-export chains. `impact` catches what intuition misses.
|
|
213
|
+
2. **Use `edit` intent for `smart_context`** when planning edits — it omits irrelevant detail and focuses on callers and blast radius.
|
|
214
|
+
3. **Stop at depth-3 for impact.** Deeper assessment rarely changes the implementation strategy but adds noise.
|
|
215
|
+
4. **Trace before planning.** Understanding the execution path prevents "add rate limiter after JWT decode" mistakes where ordering matters.
|
|
216
|
+
5. **Write the plan before the code.** The structured plan from Step 10 is the deliverable. Implementation follows the plan — not the other way around.
|
|
217
|
+
|
|
218
|
+
## Quality Gate
|
|
219
|
+
|
|
220
|
+
| Criteria | Pass | Fail |
|
|
221
|
+
|---|---|---|
|
|
222
|
+
| Codebase overview | All 3 overview tools succeed (summary, domains, routes) | Any tool fails or returns empty |
|
|
223
|
+
| Target analysis | `smart_context` + `edit_check` both run | Either tool skipped for the target symbol |
|
|
224
|
+
| Impact assessment | `impact` at depth 3 completed, dependents counted | Impact not run or depth < 3 |
|
|
225
|
+
| Blast radius check | < 5 depth-1 dependents OR user warned and confirmed | > 5 depth-1 dependents without user confirmation |
|
|
226
|
+
| Test plan | `test_plan` covers happy path, edge cases, and errors | Less than 3 scenarios in the plan |
|
|
227
|
+
| Implementation plan | All 7 sections of the plan filled | Missing sections or incomplete analysis |
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: milens-refactor-clean
|
|
3
|
+
description: Safe Refactoring with Blast Radius Check — find dead code, verify impact, remove safely, and verify test coverage
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# milens-refactor-clean — Safe Refactoring with Blast Radius Check
|
|
7
|
+
|
|
8
|
+
Identify dead or unwanted code, verify it's truly unused via context and text search, assess blast radius, remove safely, and confirm only expected files changed.
|
|
9
|
+
|
|
10
|
+
## Tools Required
|
|
11
|
+
|
|
12
|
+
| Tool | Purpose |
|
|
13
|
+
|---|---|
|
|
14
|
+
| `mcp_milens_find_dead_code` | Find exported symbols with zero incoming references |
|
|
15
|
+
| `mcp_milens_context` | Verify a symbol is truly unused (incoming refs check) |
|
|
16
|
+
| `mcp_milens_impact` | Blast radius assessment before removal |
|
|
17
|
+
| `mcp_milens_grep` | Text search for symbol name in configs, templates, docs |
|
|
18
|
+
| `mcp_milens_detect_changes` | Post-refactor verification of changed files |
|
|
19
|
+
| `mcp_milens_test_impact` | Identify affected test files to run |
|
|
20
|
+
|
|
21
|
+
> **CRITICAL:** All milens MCP tool calls MUST include the `repo` parameter set to the **absolute path of the workspace root**.
|
|
22
|
+
|
|
23
|
+
## Workflow
|
|
24
|
+
|
|
25
|
+
### Step 1: Find Candidates
|
|
26
|
+
|
|
27
|
+
Identify exported symbols with zero incoming code references.
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
mcp_milens_find_dead_code({repo: "<workspaceRoot>", limit: 30})
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The output lists symbols that the static analysis graph shows as unreferenced. These are removal candidates.
|
|
34
|
+
|
|
35
|
+
**Important caveats:**
|
|
36
|
+
- Symbols used only via reflection, `eval`, or dynamic imports won't show references
|
|
37
|
+
- Side-effect-only imports (e.g., `import "./init"`) may look unused
|
|
38
|
+
- Config-based routing (React Router, NestJS decorators) may not resolve to references
|
|
39
|
+
|
|
40
|
+
### Step 2: Verify Truly Unused
|
|
41
|
+
|
|
42
|
+
For each candidate, run context to confirm zero incoming references.
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
mcp_milens_context({name: "<symbolName>", repo: "<workspaceRoot>"})
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Look at the **incoming references** count:
|
|
49
|
+
- **0 incoming refs** — likely safe to remove
|
|
50
|
+
- **1+ incoming refs** — the symbol is used via paths the dead code detector missed; do NOT remove without further investigation
|
|
51
|
+
|
|
52
|
+
### Step 3: Check Text References
|
|
53
|
+
|
|
54
|
+
Even if context shows 0 code references, the symbol may appear in non-code files.
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
mcp_milens_grep({pattern: "<symbolName>", repo: "<workspaceRoot>"})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Check for matches in:
|
|
61
|
+
- **Config files** — `.json`, `.yaml`, `.toml`, `.env`
|
|
62
|
+
- **Template files** — `.html`, `.vue`, `.jsx`, `.tsx` (usage in markup)
|
|
63
|
+
- **Documentation** — `*.md`, `*.mdx`
|
|
64
|
+
- **Route definitions** — string-based routing (Express, FastAPI)
|
|
65
|
+
- **Package scripts** — `package.json` scripts referencing the symbol
|
|
66
|
+
|
|
67
|
+
### Step 4: Assess Blast Radius
|
|
68
|
+
|
|
69
|
+
Before deleting, understand what removing the symbol would affect (even if nothing references it now — for safety).
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
mcp_milens_impact({target: "<symbolName>", depth: 3, repo: "<workspaceRoot>"})
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Check:
|
|
76
|
+
- **Depth-1 dependents** — should be 0 for true dead code
|
|
77
|
+
- **Transitive dependents** — if > 0, something references this indirectly
|
|
78
|
+
|
|
79
|
+
### Step 5: Remove the Code
|
|
80
|
+
|
|
81
|
+
After verification, remove:
|
|
82
|
+
1. The symbol itself (function, class, interface, etc.)
|
|
83
|
+
2. Its imports if they're now unused
|
|
84
|
+
3. Related tests (now orphaned)
|
|
85
|
+
|
|
86
|
+
### Step 6: Verify Change Scope
|
|
87
|
+
|
|
88
|
+
Confirm only expected files changed.
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
mcp_milens_detect_changes({repo: "<workspaceRoot>"})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Check that:
|
|
95
|
+
- Only the files you intended to modify appear
|
|
96
|
+
- No config files, lockfiles, or unrelated modules changed
|
|
97
|
+
- No accidental deletions
|
|
98
|
+
|
|
99
|
+
### Step 7: Run Affected Tests
|
|
100
|
+
|
|
101
|
+
Identify and run tests impacted by the removal.
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
mcp_milens_test_impact({repo: "<workspaceRoot>"})
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
This lists test files that reference the removed code or its dependents. Run all affected tests to ensure nothing is broken.
|
|
108
|
+
|
|
109
|
+
## Example Session
|
|
110
|
+
|
|
111
|
+
### Input
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
"remove unused utility functions from the helpers module"
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Tool Calls
|
|
118
|
+
|
|
119
|
+
**Step 1 — Find candidates:**
|
|
120
|
+
```
|
|
121
|
+
mcp_milens_find_dead_code({repo: "/home/user/project", limit: 30})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Output:**
|
|
125
|
+
```
|
|
126
|
+
1. formatDateLegacy [function] src/utils/helpers.ts:45
|
|
127
|
+
2. unusedValidator [function] src/utils/helpers.ts:78
|
|
128
|
+
3. OldUserType [interface] src/types/legacy.ts:12
|
|
129
|
+
4. debugLog [function] src/utils/helpers.ts:102
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
**Step 2 — Verify context for each:**
|
|
133
|
+
```
|
|
134
|
+
mcp_milens_context({name: "formatDateLegacy", repo: "/home/user/project"})
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Output:** 0 incoming refs, 1 outgoing dep (calls `toISOString`). Safe to remove.
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
mcp_milens_context({name: "unusedValidator", repo: "/home/user/project"})
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Output:** 0 incoming refs. Safe to remove.
|
|
144
|
+
|
|
145
|
+
```
|
|
146
|
+
mcp_milens_context({name: "debugLog", repo: "/home/user/project"})
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
**Output:** 3 incoming refs — used in `server.ts`, `logger.ts`, `middleware.ts`. NOT dead code — skip.
|
|
150
|
+
|
|
151
|
+
**Step 3 — Text search for remaining candidates:**
|
|
152
|
+
```
|
|
153
|
+
mcp_milens_grep({pattern: "formatDateLegacy", repo: "/home/user/project"})
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Output:** 1 match in `docs/migration-guide.md` — documentation reference only, still safe to remove with a docs update.
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
mcp_milens_grep({pattern: "OldUserType", repo: "/home/user/project"})
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Output:** 0 matches across all files. Fully dead.
|
|
163
|
+
|
|
164
|
+
**Step 4 — Impact check:**
|
|
165
|
+
```
|
|
166
|
+
mcp_milens_impact({target: "formatDateLegacy", depth: 3, repo: "/home/user/project"})
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
**Output:** Depth-1: 0 dependents. No blast radius.
|
|
170
|
+
|
|
171
|
+
**Step 5 — Remove `formatDateLegacy` and `OldUserType`** in file editor
|
|
172
|
+
|
|
173
|
+
**Step 6 — Verify scope:**
|
|
174
|
+
```
|
|
175
|
+
mcp_milens_detect_changes({repo: "/home/user/project"})
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**Output:**
|
|
179
|
+
```
|
|
180
|
+
Changed files:
|
|
181
|
+
src/utils/helpers.ts [modified] — expected
|
|
182
|
+
src/types/legacy.ts [modified] — expected
|
|
183
|
+
docs/migration-guide.md [modified] — expected (updated reference)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Step 7 — Test impact:**
|
|
187
|
+
```
|
|
188
|
+
mcp_milens_test_impact({repo: "/home/user/project"})
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**Output:** 2 affected test files — `src/__tests__/helpers.test.ts`, `src/__tests__/types.test.ts`. Both pass after updating.
|
|
192
|
+
|
|
193
|
+
## Best Practices
|
|
194
|
+
|
|
195
|
+
1. **Context beats dead-code detection.** A symbol tagged as "dead" by the detector may still be used via dynamic patterns. Always verify with `context` before deleting.
|
|
196
|
+
2. **Grep is the backstop.** `context` only catches code-level references. `grep` catches template usage, string-based routing, config files, and docs. Never skip Step 3.
|
|
197
|
+
3. **Remove in small batches.** Delete 1-3 symbols per commit. Large-scale deletion makes `detect_changes` harder to verify and `git bisect` harder to use.
|
|
198
|
+
4. **Update docs proactively.** If `grep` finds documentation references, update or remove them in the same commit. Stale docs referencing deleted symbols are worse than no docs.
|
|
199
|
+
5. **Test impact is not optional.** Removing code can break tests that import the symbol directly. Run `test_impact` and fix before committing.
|
|
200
|
+
|
|
201
|
+
## Quality Gate
|
|
202
|
+
|
|
203
|
+
| Criteria | Pass | Fail |
|
|
204
|
+
|---|---|---|
|
|
205
|
+
| Dead code identified | `find_dead_code` returns candidates | Tool fails or returns empty (with large codebase) |
|
|
206
|
+
| Verification complete | `context` + `grep` run for every candidate marked for removal | Any candidate removed without both checks |
|
|
207
|
+
| Blast radius safe | All removed symbols have 0 depth-1 dependents | Any symbol with dependents removed without justification |
|
|
208
|
+
| Change scope clean | `detect_changes` shows only expected files | Unexpected files in the diff |
|
|
209
|
+
| Tests pass | All `test_impact` files pass | Any affected test file fails |
|