milens 0.7.2 → 0.7.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.
Files changed (52) hide show
  1. package/.agents/skills/adapters/SKILL.md +59 -59
  2. package/.agents/skills/analyzer/SKILL.md +83 -83
  3. package/.agents/skills/apps/SKILL.md +65 -65
  4. package/.agents/skills/docs/SKILL.md +63 -63
  5. package/.agents/skills/milens/SKILL.md +322 -322
  6. package/.agents/skills/milens-security-review/SKILL.md +224 -224
  7. package/.agents/skills/orchestrator/SKILL.md +64 -64
  8. package/.agents/skills/parser/SKILL.md +86 -86
  9. package/.agents/skills/root/SKILL.md +89 -89
  10. package/.agents/skills/scripts/SKILL.md +56 -56
  11. package/.agents/skills/security/SKILL.md +67 -67
  12. package/.agents/skills/server/SKILL.md +84 -84
  13. package/.agents/skills/store/SKILL.md +77 -77
  14. package/.agents/skills/test/SKILL.md +155 -155
  15. package/.agents/skills/ui/SKILL.md +56 -56
  16. package/README.md +577 -577
  17. package/adapters/README.md +144 -144
  18. package/adapters/claude-code/.claude/mcp.json +9 -9
  19. package/adapters/claude-code/.claude/settings.json.hooks-snippet.json +26 -26
  20. package/adapters/claude-code/.claude-plugin/plugin.json +11 -11
  21. package/adapters/claude-code/.mcp.json +9 -9
  22. package/adapters/claude-code/CLAUDE.md +81 -81
  23. package/adapters/claude-code/hooks/hooks.json +27 -27
  24. package/adapters/codex/.codex/config.toml +3 -3
  25. package/adapters/copilot/.vscode/mcp.json +10 -10
  26. package/adapters/cursor/.cursor/mcp.json +9 -9
  27. package/adapters/cursor/.cursorrules +69 -69
  28. package/adapters/gemini/.gemini/context.md +81 -81
  29. package/adapters/gemini/.gemini/settings.json +9 -9
  30. package/adapters/opencode/.opencode/config.json +8 -8
  31. package/adapters/zed/.zed/settings.json +8 -8
  32. package/dist/build-info.d.ts +2 -2
  33. package/dist/build-info.js +2 -2
  34. package/dist/cli.js +482 -482
  35. package/dist/parser/lang-css.js +9 -9
  36. package/dist/parser/lang-go.js +58 -58
  37. package/dist/parser/lang-html.js +3 -3
  38. package/dist/parser/lang-java.js +37 -37
  39. package/dist/parser/lang-js.js +105 -105
  40. package/dist/parser/lang-php.js +45 -45
  41. package/dist/parser/lang-py.js +43 -43
  42. package/dist/parser/lang-ruby.js +28 -28
  43. package/dist/parser/lang-rust.js +48 -48
  44. package/dist/parser/lang-ts.js +210 -210
  45. package/dist/server/mcp-prompts.js +502 -502
  46. package/dist/server/mcp.js +56 -56
  47. package/dist/skills.js +296 -296
  48. package/dist/store/annotations.js +1 -1
  49. package/dist/store/db.js +224 -224
  50. package/dist/store/schema.sql +144 -144
  51. package/dist/store/vectors.js +2 -2
  52. package/package.json +85 -85
@@ -10,86 +10,86 @@ async function plannerHandler(args) {
10
10
  role: 'user',
11
11
  content: {
12
12
  type: 'text',
13
- text: `You are the Milens Planner Agent. Execute this workflow to create a detailed implementation plan for: "${args.feature}"
14
- ${args.target ? `\nPrimary target symbol: "${args.target}"` : ''}
15
-
16
- ## STEP 1 — RESEARCH (Codebase Intelligence)
17
- Call these tools in sequence to understand project structure:
18
- 1. \`codebase_summary({})\` → compact overview: symbols, domains, top hubs, test coverage %
19
- 2. \`domains({})\` → module clusters with file/symbol counts — identify which domains are relevant to this feature
20
- 3. \`routes({})\` → inventory of API endpoints — identify which routes need changes or new routes needed
21
- ${args.target ? `4. \`smart_context({name: "${args.target}", intent: "understand"})\` → 360° view of the target symbol (incoming refs, outgoing deps, callers, file peers)` : `4. \`query({query: "${args.feature.split(' ')[0]}"})\` → find relevant symbols by name`}
22
-
23
- ## STEP 2 — TARGET ANALYSIS
24
- ${args.target ? `Perform deep analysis on "${args.target}":
25
- 1. \`smart_context({name: "${args.target}", intent: "edit"})\` → direct callers, blast radius, test coverage, re-export chains
26
- 2. \`edit_check({name: "${args.target}"})\` → pre-edit safety: callers, export status, inherited-by warnings, test coverage
27
- 3. \`trace({name: "${args.target}", direction: "to"})\` → execution paths from entrypoints TO this symbol — understand how code reaches it
28
- 4. \`impact({target: "${args.target}", direction: "upstream", depth: 3})\` → blast radius: what WILL break if this changes
29
- - depth 1 = WILL BREAK (direct callers)
30
- - depth 2 = LIKELY AFFECTED (indirect callers)
31
- - depth 3 = MAY NEED TESTING (transitive dependents)` : `No target symbol specified. Use \`codebase_summary()\` and \`domains()\` output to identify key symbols that need modification. For each key symbol found, run:
32
- 1. \`smart_context({name: "keySymbol", intent: "edit"})\` → callers + blast radius
33
- 2. \`edit_check({name: "keySymbol"})\` → pre-edit safety
34
- 3. \`impact({target: "keySymbol", depth: 2})\` → upstream dependents`}
35
-
36
- ## STEP 3 — TEST STRATEGY
37
- ${args.target ? `1. \`test_plan({name: "${args.target}"})\` → mock plan + >=3 test scenarios for the target symbol
38
- 2. \`test_coverage_gaps({limit: 10})\` → nearby untested exported symbols sorted by risk` : `1. \`test_coverage_gaps({limit: 20})\` → all untested exported symbols, sorted by risk (heat + deps)
39
- 2. For top 5 untested symbols from gaps: \`test_plan({name})\` → mock strategy + scenarios`}
40
- ${args.target ? `3. \`impact({target: "${args.target}", direction: "upstream", depth: 1})\` → identify test files that import or call this symbol` : `3. \`test_impact({})\` → map changed files to which test files need to run`}
41
-
42
- ## STEP 4 — DEPENDENCY DEEPENING (if needed)
43
- For any key relationships discovered in steps 1-3:
44
- - \`explain_relationship({from: "A", to: "B"})\` → shortest dependency path between two symbols
45
- - \`get_type_hierarchy({name: "keySymbol"})\` → inheritance chain if dealing with classes/interfaces
46
- - \`grep({pattern: "keySymbol"})\` → ALL text references (templates, configs, SCSS, docs, routes) — catches what impact() misses
47
-
48
- ## OUTPUT FORMAT — Implementation Plan
49
-
50
- Produce a detailed Implementation Plan in the following structure:
51
-
52
- ### 1. Overview
53
- 2-3 sentences summarizing what the feature does and the high-level approach.
54
-
55
- ### 2. Requirements
56
- - Bullet list of functional and non-functional requirements
57
- - Derived from codebase_summary + domains + routes analysis
58
-
59
- ### 3. Architecture Changes
60
- For each file that needs changes, specify:
61
- - **File:** relative path
62
- - **Symbol:** names of symbols being added/modified/deleted
63
- - **Description:** what changes and why
64
- - **Risk Level:** LOW / MEDIUM / HIGH / CRITICAL (from impact() data — use heat + dependents count)
65
- - **Dependencies:** other symbols this change depends on (from context() outgoing links)
66
-
67
- ### 4. Implementation Steps
68
- Ordered list (by dependency — leaf nodes first, shared dependencies before consumers):
69
- For each step:
70
- - **Action:** CREATE / MODIFY / DELETE / CONFIG
71
- - **File:** relative path
72
- - **Why:** purpose of this change
73
- - **Dependencies:** prerequisite steps (by step number)
74
- - **Risk:** LOW / MEDIUM / HIGH / CRITICAL
75
- - **Impacted Symbols:** symbols affected by this change (from impact() output)
76
-
77
- ### 5. Testing Strategy
78
- - Test files to create/modify (from test_plan() output)
79
- - Mock requirements (from test_plan() dependencies-to-mock)
80
- - Test scenarios (from test_plan() >=3 scenarios per symbol)
81
- - Coverage improvement estimate (from test_coverage_gaps() baseline vs expected)
82
- - Command to run tests: \`npx vitest run <files>\`
83
-
84
- ### 6. Risks & Mitigations
85
- - Each risk from impact() depth-2+ dependents
86
- - Risk level, likelihood, mitigation strategy
87
-
88
- ### 7. Success Criteria
89
- - Measurable checkboxes: [ ] each criterion
90
- - E.g. [ ] Feature works end-to-end, [ ] All tests pass, [ ] No new dead code, [ ] Test coverage improves by X%
91
-
92
- Important: Use specific file paths, symbol names, and risk levels from the tool outputs. Never guess — always cite which tool produced each finding.
13
+ text: `You are the Milens Planner Agent. Execute this workflow to create a detailed implementation plan for: "${args.feature}"
14
+ ${args.target ? `\nPrimary target symbol: "${args.target}"` : ''}
15
+
16
+ ## STEP 1 — RESEARCH (Codebase Intelligence)
17
+ Call these tools in sequence to understand project structure:
18
+ 1. \`codebase_summary({})\` → compact overview: symbols, domains, top hubs, test coverage %
19
+ 2. \`domains({})\` → module clusters with file/symbol counts — identify which domains are relevant to this feature
20
+ 3. \`routes({})\` → inventory of API endpoints — identify which routes need changes or new routes needed
21
+ ${args.target ? `4. \`smart_context({name: "${args.target}", intent: "understand"})\` → 360° view of the target symbol (incoming refs, outgoing deps, callers, file peers)` : `4. \`query({query: "${args.feature.split(' ')[0]}"})\` → find relevant symbols by name`}
22
+
23
+ ## STEP 2 — TARGET ANALYSIS
24
+ ${args.target ? `Perform deep analysis on "${args.target}":
25
+ 1. \`smart_context({name: "${args.target}", intent: "edit"})\` → direct callers, blast radius, test coverage, re-export chains
26
+ 2. \`edit_check({name: "${args.target}"})\` → pre-edit safety: callers, export status, inherited-by warnings, test coverage
27
+ 3. \`trace({name: "${args.target}", direction: "to"})\` → execution paths from entrypoints TO this symbol — understand how code reaches it
28
+ 4. \`impact({target: "${args.target}", direction: "upstream", depth: 3})\` → blast radius: what WILL break if this changes
29
+ - depth 1 = WILL BREAK (direct callers)
30
+ - depth 2 = LIKELY AFFECTED (indirect callers)
31
+ - depth 3 = MAY NEED TESTING (transitive dependents)` : `No target symbol specified. Use \`codebase_summary()\` and \`domains()\` output to identify key symbols that need modification. For each key symbol found, run:
32
+ 1. \`smart_context({name: "keySymbol", intent: "edit"})\` → callers + blast radius
33
+ 2. \`edit_check({name: "keySymbol"})\` → pre-edit safety
34
+ 3. \`impact({target: "keySymbol", depth: 2})\` → upstream dependents`}
35
+
36
+ ## STEP 3 — TEST STRATEGY
37
+ ${args.target ? `1. \`test_plan({name: "${args.target}"})\` → mock plan + >=3 test scenarios for the target symbol
38
+ 2. \`test_coverage_gaps({limit: 10})\` → nearby untested exported symbols sorted by risk` : `1. \`test_coverage_gaps({limit: 20})\` → all untested exported symbols, sorted by risk (heat + deps)
39
+ 2. For top 5 untested symbols from gaps: \`test_plan({name})\` → mock strategy + scenarios`}
40
+ ${args.target ? `3. \`impact({target: "${args.target}", direction: "upstream", depth: 1})\` → identify test files that import or call this symbol` : `3. \`test_impact({})\` → map changed files to which test files need to run`}
41
+
42
+ ## STEP 4 — DEPENDENCY DEEPENING (if needed)
43
+ For any key relationships discovered in steps 1-3:
44
+ - \`explain_relationship({from: "A", to: "B"})\` → shortest dependency path between two symbols
45
+ - \`get_type_hierarchy({name: "keySymbol"})\` → inheritance chain if dealing with classes/interfaces
46
+ - \`grep({pattern: "keySymbol"})\` → ALL text references (templates, configs, SCSS, docs, routes) — catches what impact() misses
47
+
48
+ ## OUTPUT FORMAT — Implementation Plan
49
+
50
+ Produce a detailed Implementation Plan in the following structure:
51
+
52
+ ### 1. Overview
53
+ 2-3 sentences summarizing what the feature does and the high-level approach.
54
+
55
+ ### 2. Requirements
56
+ - Bullet list of functional and non-functional requirements
57
+ - Derived from codebase_summary + domains + routes analysis
58
+
59
+ ### 3. Architecture Changes
60
+ For each file that needs changes, specify:
61
+ - **File:** relative path
62
+ - **Symbol:** names of symbols being added/modified/deleted
63
+ - **Description:** what changes and why
64
+ - **Risk Level:** LOW / MEDIUM / HIGH / CRITICAL (from impact() data — use heat + dependents count)
65
+ - **Dependencies:** other symbols this change depends on (from context() outgoing links)
66
+
67
+ ### 4. Implementation Steps
68
+ Ordered list (by dependency — leaf nodes first, shared dependencies before consumers):
69
+ For each step:
70
+ - **Action:** CREATE / MODIFY / DELETE / CONFIG
71
+ - **File:** relative path
72
+ - **Why:** purpose of this change
73
+ - **Dependencies:** prerequisite steps (by step number)
74
+ - **Risk:** LOW / MEDIUM / HIGH / CRITICAL
75
+ - **Impacted Symbols:** symbols affected by this change (from impact() output)
76
+
77
+ ### 5. Testing Strategy
78
+ - Test files to create/modify (from test_plan() output)
79
+ - Mock requirements (from test_plan() dependencies-to-mock)
80
+ - Test scenarios (from test_plan() >=3 scenarios per symbol)
81
+ - Coverage improvement estimate (from test_coverage_gaps() baseline vs expected)
82
+ - Command to run tests: \`npx vitest run <files>\`
83
+
84
+ ### 6. Risks & Mitigations
85
+ - Each risk from impact() depth-2+ dependents
86
+ - Risk level, likelihood, mitigation strategy
87
+
88
+ ### 7. Success Criteria
89
+ - Measurable checkboxes: [ ] each criterion
90
+ - E.g. [ ] Feature works end-to-end, [ ] All tests pass, [ ] No new dead code, [ ] Test coverage improves by X%
91
+
92
+ Important: Use specific file paths, symbol names, and risk levels from the tool outputs. Never guess — always cite which tool produced each finding.
93
93
  `,
94
94
  },
95
95
  }],
@@ -105,75 +105,75 @@ async function reviewerHandler(args) {
105
105
  role: 'user',
106
106
  content: {
107
107
  type: 'text',
108
- text: `You are the Milens Reviewer Agent. Perform a thorough code review of the current changes.
109
- ${args.change_description ? `\nContext: "${args.change_description}"` : ''}
110
-
111
- ## STEP 1 — PR RISK SCAN
112
- Run \`review_pr({})\` to get:
113
- - All changed symbols with risk scores (LOW/MEDIUM/HIGH/CRITICAL)
114
- - Risk score factors: heat (centrality), number of dependents, test coverage (no test = +25 risk points)
115
- - Summary: count of symbols by risk level
116
-
117
- ## STEP 2 — DEEP DIVE ON CRITICAL/HIGH
118
- For each symbol rated CRITICAL or HIGH:
119
- 1. Run \`review_symbol({name: "symbolName"})\` → deep dive: role, heat, dependents list, dependencies list, test status, risk recommendation
120
- 2. Run \`context({name: "symbolName"})\` → full 360°: incoming refs (who calls it) + outgoing deps (what it calls)
121
- 3. Run \`grep({pattern: "symbolName"})\` → ALL text references across the project including templates, configs, routes, SCSS, docs
122
-
123
- ## STEP 3 — DEAD CODE DETECTION
124
- Run \`find_dead_code({limit: 30})\` → identify exported symbols with zero incoming references.
125
- Cross-reference with changed files: if any changed symbol appears in dead code list, flag it for removal consideration.
126
-
127
- ## STEP 4 — SECURITY & TECH DEBT SCAN
128
- 1. Run \`grep({pattern: "password|secret|api_key|token|private_key|AKIA", scope: "code"})\` → hardcoded secrets
129
- 2. Run \`grep({pattern: "TODO|FIXME|HACK|console\\\\.log", scope: "code"})\` → tech debt markers
130
- 3. Run \`grep({pattern: "eval|exec|child_process|Function\\\\(", scope: "code"})\` → dangerous code patterns
131
-
132
- ## STEP 5 — VERIFY SCOPE
133
- Run \`detect_changes({})\` → verify only expected files changed.
134
- If unexpected files appear → flag as a concern (unintended side effects).
135
-
136
- ## OUTPUT FORMAT — Review Report
137
-
138
- Produce a comprehensive code review report:
139
-
140
- ### 1. Risk Summary
141
- | Risk Level | Count | Symbols |
142
- |---|---|---|
143
- | CRITICAL | N | symbol1, symbol2, ... |
144
- | HIGH | N | ... |
145
- | MEDIUM | N | ... |
146
- | LOW | N | ... |
147
-
148
- ### 2. Per-Symbol Deep Dives (for CRITICAL/HIGH only)
149
- For each CRITICAL and HIGH symbol:
150
- - **Symbol:** name [kind] file:line
151
- - **Risk Score:** N / 100
152
- - **Dependents:** count + top 5 names — these WILL break if symbol changes
153
- - **Dependencies:** count + top 5 names — what it relies on
154
- - **Test Coverage:** yes/no — if no, explain risk
155
- - **Text References:** grep() matches in templates/configs/routes
156
- - **Assessment:** detailed analysis of the change
157
- - **Recommendation:** MERGE / FIX / REWRITE / ADD_TESTS
158
-
159
- ### 3. Dead Code List
160
- List of unreferenced exported symbols from find_dead_code().
161
- If any are in changed files, recommend removal.
162
-
163
- ### 4. Security Concerns
164
- Any grep matches for secrets, dangerous patterns, or data leaks.
165
- For each finding: file, line, pattern matched, severity, fix suggestion.
166
-
167
- ### 5. Recommendations
168
- - [ ] Symbols safe to merge (LOW/MEDIUM risk)
169
- - [ ] Symbols needing fixes before merge (HIGH/CRITICAL)
170
- - [ ] Tests that should be added
171
- - [ ] Dead code candidates for removal
172
-
173
- ### 6. Verdict
174
- - **APPROVE** — all changes are safe
175
- - **APPROVE WITH COMMENTS** — minor issues, merge and fix later
176
- - **REQUEST CHANGES** — critical issues, cannot merge
108
+ text: `You are the Milens Reviewer Agent. Perform a thorough code review of the current changes.
109
+ ${args.change_description ? `\nContext: "${args.change_description}"` : ''}
110
+
111
+ ## STEP 1 — PR RISK SCAN
112
+ Run \`review_pr({})\` to get:
113
+ - All changed symbols with risk scores (LOW/MEDIUM/HIGH/CRITICAL)
114
+ - Risk score factors: heat (centrality), number of dependents, test coverage (no test = +25 risk points)
115
+ - Summary: count of symbols by risk level
116
+
117
+ ## STEP 2 — DEEP DIVE ON CRITICAL/HIGH
118
+ For each symbol rated CRITICAL or HIGH:
119
+ 1. Run \`review_symbol({name: "symbolName"})\` → deep dive: role, heat, dependents list, dependencies list, test status, risk recommendation
120
+ 2. Run \`context({name: "symbolName"})\` → full 360°: incoming refs (who calls it) + outgoing deps (what it calls)
121
+ 3. Run \`grep({pattern: "symbolName"})\` → ALL text references across the project including templates, configs, routes, SCSS, docs
122
+
123
+ ## STEP 3 — DEAD CODE DETECTION
124
+ Run \`find_dead_code({limit: 30})\` → identify exported symbols with zero incoming references.
125
+ Cross-reference with changed files: if any changed symbol appears in dead code list, flag it for removal consideration.
126
+
127
+ ## STEP 4 — SECURITY & TECH DEBT SCAN
128
+ 1. Run \`grep({pattern: "password|secret|api_key|token|private_key|AKIA", scope: "code"})\` → hardcoded secrets
129
+ 2. Run \`grep({pattern: "TODO|FIXME|HACK|console\\\\.log", scope: "code"})\` → tech debt markers
130
+ 3. Run \`grep({pattern: "eval|exec|child_process|Function\\\\(", scope: "code"})\` → dangerous code patterns
131
+
132
+ ## STEP 5 — VERIFY SCOPE
133
+ Run \`detect_changes({})\` → verify only expected files changed.
134
+ If unexpected files appear → flag as a concern (unintended side effects).
135
+
136
+ ## OUTPUT FORMAT — Review Report
137
+
138
+ Produce a comprehensive code review report:
139
+
140
+ ### 1. Risk Summary
141
+ | Risk Level | Count | Symbols |
142
+ |---|---|---|
143
+ | CRITICAL | N | symbol1, symbol2, ... |
144
+ | HIGH | N | ... |
145
+ | MEDIUM | N | ... |
146
+ | LOW | N | ... |
147
+
148
+ ### 2. Per-Symbol Deep Dives (for CRITICAL/HIGH only)
149
+ For each CRITICAL and HIGH symbol:
150
+ - **Symbol:** name [kind] file:line
151
+ - **Risk Score:** N / 100
152
+ - **Dependents:** count + top 5 names — these WILL break if symbol changes
153
+ - **Dependencies:** count + top 5 names — what it relies on
154
+ - **Test Coverage:** yes/no — if no, explain risk
155
+ - **Text References:** grep() matches in templates/configs/routes
156
+ - **Assessment:** detailed analysis of the change
157
+ - **Recommendation:** MERGE / FIX / REWRITE / ADD_TESTS
158
+
159
+ ### 3. Dead Code List
160
+ List of unreferenced exported symbols from find_dead_code().
161
+ If any are in changed files, recommend removal.
162
+
163
+ ### 4. Security Concerns
164
+ Any grep matches for secrets, dangerous patterns, or data leaks.
165
+ For each finding: file, line, pattern matched, severity, fix suggestion.
166
+
167
+ ### 5. Recommendations
168
+ - [ ] Symbols safe to merge (LOW/MEDIUM risk)
169
+ - [ ] Symbols needing fixes before merge (HIGH/CRITICAL)
170
+ - [ ] Tests that should be added
171
+ - [ ] Dead code candidates for removal
172
+
173
+ ### 6. Verdict
174
+ - **APPROVE** — all changes are safe
175
+ - **APPROVE WITH COMMENTS** — minor issues, merge and fix later
176
+ - **REQUEST CHANGES** — critical issues, cannot merge
177
177
  `,
178
178
  },
179
179
  }],
@@ -189,67 +189,67 @@ async function testerHandler(args) {
189
189
  role: 'user',
190
190
  content: {
191
191
  type: 'text',
192
- text: `You are the Milens Tester Agent. Execute a test-driven development workflow to improve test coverage.
193
- ${args.focus ? `\nFocus symbol: "${args.focus}"` : ''}
194
-
195
- ## STEP 1 — IDENTIFY COVERAGE GAPS
196
- 1. Run \`test_coverage_gaps({limit: 20})\` → untested exported symbols sorted by risk (heat × dependents).
197
- - Risk levels: CRITICAL (heat>80), HIGH (heat>50), MEDIUM (heat>30), LOW
198
- - Pay special attention to HIGH and CRITICAL — these are exploitable gaps
199
- ${args.focus ? `2. Run \`smart_context({name: "${args.focus}", intent: "test"})\` → existing tests for this symbol, dependencies to mock, callers to cover` : `2. From the gaps list, identify the top 5 critical symbols to prioritize`}
200
-
201
- ## STEP 2 — BUILD TEST PLANS
202
- ${args.focus ? `Run \`test_plan({name: "${args.focus}"})\` → generates:
203
- - Mock plan: which dependencies to mock and how
204
- - >=3 test scenarios: happy path, edge cases, error handling
205
- - Suggested test file location` : `For each of the top 5 untested symbols from gaps, run \`test_plan({name: "symbolName"})\` → mock plan + >=3 test scenarios each`}
206
- ${args.focus ? `\nAlso run \`context({name: "${args.focus}"})\` → full incoming/outgoing to understand all relationships before writing tests.` : `\nAlso run \`context({name: "symbolName"})\` for each symbol → understand full relationships before writing tests.`}
207
-
208
- ## STEP 3 — IMPLEMENT TESTS
209
- Implement the test scenarios from test_plan():
210
- - Create test files in the suggested locations
211
- - Write >=3 test cases per symbol: happy path, edge case, error condition
212
- - Mock external dependencies per the mock plan
213
- - Use the same test framework as existing tests in the project
214
- ${args.focus ? `- Verify tests reference "${args.focus}" correctly (check context() output for import paths)` : `- Verify tests reference the correct symbol names and import paths`}
215
-
216
- ## STEP 4 — VERIFY IMPACT
217
- After writing tests:
218
- 1. Run \`test_impact({})\` → maps changed code to affected test files — verify new tests are in the list
219
- 2. Run \`test_coverage_gaps({limit: 10})\` again → verify coverage improved (symbols should drop off the gaps list)
220
- 3. Run \`review_symbol({name: "symbolName"})\` for the tested symbol → confirm "test coverage: yes" now shows
221
-
222
- ## OUTPUT FORMAT — Test Coverage Report
223
-
224
- ### 1. Coverage Gaps Summary
225
- | Priority | Symbol | Kind | Risk | Heat | Dependents | File |
226
- |---|---|---|---|---|---|---|
227
- | 1 | ... | ... | ... | ... | ... | ... |
228
-
229
- ### 2. Test Plans (for top 5)
230
- For each symbol:
231
- - **Symbol:** name [kind] file:line
232
- - **Mock Dependencies:** list from test_plan() dependencies-to-mock
233
- - **Test Scenarios:** >=3 scenarios from test_plan()
234
- 1. Happy path: description
235
- 2. Edge case: description
236
- 3. Error handling: description
237
-
238
- ### 3. Suggested Test Files
239
- | Symbol | Test File | Test Framework |
240
- |---|---|---|
241
- | ... | src/__tests__/...test.ts | vitest |
242
-
243
- ### 4. Coverage Improvement Estimate
244
- - **Before:** X% (from initial test_coverage_gaps)
245
- - **After:** Y% (estimated after implementing all test plans)
246
- - **Delta:** +Z%
247
- - **Remaining gaps:** N symbols still untested
248
-
249
- ### 5. Run Command
250
- \`\`\`bash
251
- npx vitest run <test files>
252
- \`\`\`
192
+ text: `You are the Milens Tester Agent. Execute a test-driven development workflow to improve test coverage.
193
+ ${args.focus ? `\nFocus symbol: "${args.focus}"` : ''}
194
+
195
+ ## STEP 1 — IDENTIFY COVERAGE GAPS
196
+ 1. Run \`test_coverage_gaps({limit: 20})\` → untested exported symbols sorted by risk (heat × dependents).
197
+ - Risk levels: CRITICAL (heat>80), HIGH (heat>50), MEDIUM (heat>30), LOW
198
+ - Pay special attention to HIGH and CRITICAL — these are exploitable gaps
199
+ ${args.focus ? `2. Run \`smart_context({name: "${args.focus}", intent: "test"})\` → existing tests for this symbol, dependencies to mock, callers to cover` : `2. From the gaps list, identify the top 5 critical symbols to prioritize`}
200
+
201
+ ## STEP 2 — BUILD TEST PLANS
202
+ ${args.focus ? `Run \`test_plan({name: "${args.focus}"})\` → generates:
203
+ - Mock plan: which dependencies to mock and how
204
+ - >=3 test scenarios: happy path, edge cases, error handling
205
+ - Suggested test file location` : `For each of the top 5 untested symbols from gaps, run \`test_plan({name: "symbolName"})\` → mock plan + >=3 test scenarios each`}
206
+ ${args.focus ? `\nAlso run \`context({name: "${args.focus}"})\` → full incoming/outgoing to understand all relationships before writing tests.` : `\nAlso run \`context({name: "symbolName"})\` for each symbol → understand full relationships before writing tests.`}
207
+
208
+ ## STEP 3 — IMPLEMENT TESTS
209
+ Implement the test scenarios from test_plan():
210
+ - Create test files in the suggested locations
211
+ - Write >=3 test cases per symbol: happy path, edge case, error condition
212
+ - Mock external dependencies per the mock plan
213
+ - Use the same test framework as existing tests in the project
214
+ ${args.focus ? `- Verify tests reference "${args.focus}" correctly (check context() output for import paths)` : `- Verify tests reference the correct symbol names and import paths`}
215
+
216
+ ## STEP 4 — VERIFY IMPACT
217
+ After writing tests:
218
+ 1. Run \`test_impact({})\` → maps changed code to affected test files — verify new tests are in the list
219
+ 2. Run \`test_coverage_gaps({limit: 10})\` again → verify coverage improved (symbols should drop off the gaps list)
220
+ 3. Run \`review_symbol({name: "symbolName"})\` for the tested symbol → confirm "test coverage: yes" now shows
221
+
222
+ ## OUTPUT FORMAT — Test Coverage Report
223
+
224
+ ### 1. Coverage Gaps Summary
225
+ | Priority | Symbol | Kind | Risk | Heat | Dependents | File |
226
+ |---|---|---|---|---|---|---|
227
+ | 1 | ... | ... | ... | ... | ... | ... |
228
+
229
+ ### 2. Test Plans (for top 5)
230
+ For each symbol:
231
+ - **Symbol:** name [kind] file:line
232
+ - **Mock Dependencies:** list from test_plan() dependencies-to-mock
233
+ - **Test Scenarios:** >=3 scenarios from test_plan()
234
+ 1. Happy path: description
235
+ 2. Edge case: description
236
+ 3. Error handling: description
237
+
238
+ ### 3. Suggested Test Files
239
+ | Symbol | Test File | Test Framework |
240
+ |---|---|---|
241
+ | ... | src/__tests__/...test.ts | vitest |
242
+
243
+ ### 4. Coverage Improvement Estimate
244
+ - **Before:** X% (from initial test_coverage_gaps)
245
+ - **After:** Y% (estimated after implementing all test plans)
246
+ - **Delta:** +Z%
247
+ - **Remaining gaps:** N symbols still untested
248
+
249
+ ### 5. Run Command
250
+ \`\`\`bash
251
+ npx vitest run <test files>
252
+ \`\`\`
253
253
  `,
254
254
  },
255
255
  }],
@@ -263,107 +263,107 @@ async function architectHandler() {
263
263
  role: 'user',
264
264
  content: {
265
265
  type: 'text',
266
- text: `You are the Milens Architect Agent. Perform a comprehensive architecture analysis of this codebase.
267
-
268
- ## STEP 1 — CODEBASE OVERVIEW
269
- Run \`codebase_summary({})\` → compact overview:
270
- - Total symbols, links, files
271
- - Test coverage percentage
272
- - Domain clusters with symbol counts
273
- - Top hubs (high-heat symbols >70) — these are critical architecture nodes
274
-
275
- ## STEP 2 — DOMAIN MAP
276
- Run \`domains({})\` → module clusters:
277
- - Each domain represents a logical module (group of files with high internal coupling)
278
- - Note domain boundaries — where does one module end and another begin?
279
- - Identify cross-domain dependencies (potential architecture violations)
280
-
281
- ## STEP 3 — ROUTE INVENTORY
282
- Run \`routes({})\` → all detected API endpoints:
283
- - Group by framework (Express, FastAPI, NestJS, Flask, Go, PHP, Rails)
284
- - Map each route to its handler symbol
285
- - Identify: public APIs, internal APIs, deprecated routes
286
-
287
- ## STEP 4 — EXECUTION FLOWS
288
- For the top 3-5 entry points (identified from routes() or top hubs):
289
- 1. Run \`trace({name: "entrypointSymbol", direction: "to"})\` → execution paths from entrypoint inward
290
- 2. Run \`trace({name: "topHubSymbol", direction: "from"})\` → downstream call tree from central hubs
291
- This reveals the critical execution paths through the system.
292
-
293
- ## STEP 5 — CLASS HIERARCHY
294
- For each top class/interface from codebase_summary() top hubs:
295
- Run \`get_type_hierarchy({name: "className"})\` → inheritance tree:
296
- - ancestors (extends/implements)
297
- - descendants (extended/implemented by)
298
- Note deep inheritance chains (>3 levels) — potential refactoring targets.
299
-
300
- ## STEP 6 — COUPLING ANALYSIS
301
- For key architectural pairs (domains that depend on each other, hub-to-hub connections):
302
- Run \`explain_relationship({from: "A", to: "B"})\` → shortest dependency path.
303
- Identify:
304
- - Tight coupling (path length = 1) — high risk of cascading changes
305
- - Loose coupling (path length >= 3) — healthier architecture
306
- - Circular dependencies (path loops) — critical architecture flaw
307
-
308
- ## STEP 7 — GLOBAL REFERENCE CHECK
309
- Run \`grep({pattern: "TODO|FIXME|DEPRECATED|HACK"})\` → tech debt markers.
310
- Run \`find_dead_code({limit: 30})\` → orphaned exports — removed functionality still in codebase.
311
-
312
- ## OUTPUT FORMAT — Architecture Analysis
313
-
314
- ### 1. Architecture Overview
315
- 2-3 paragraphs: architecture style (monolith/microservices/layered/hexagonal), primary language/framework, overall health assessment.
316
-
317
- ### 2. Domain Map
318
- | Domain | Files | Symbols | % of Codebase | Dependencies On | Depended By |
319
- |---|---|---|---|---|---|
320
- | ... | ... | ... | ... | ... | ... |
321
-
322
- ### 3. Route Inventory
323
- | Method | Path | Framework | Handler Symbol | File | Status |
324
- |---|---|---|---|---|---|
325
- | GET | /api/users | express | getUsers [method] | src/routes/users.ts:25 | active |
326
-
327
- ### 4. Class / Type Hierarchy
328
- For each top-level class/interface:
329
- - Symbol: name [kind] file:line
330
- - Inheritance chain: BaseClass → ParentClass → ThisClass → ChildClass1 → ChildClass2
331
- - Depth: N levels (warning if >3)
332
-
333
- ### 5. Critical Execution Paths
334
- For each entry point traced:
335
- \`\`\`
336
- EntryPoint
337
- → Middleware (step 1)
338
- → ServiceLayer (step 2)
339
- → Repository/DB (step 3)
340
- → TargetSymbol (step 4)
341
- \`\`\`
342
-
343
- ### 6. Coupling Hotspots
344
- | Symbol A | Symbol B | Path Length | Type | Risk | Recommendation |
345
- |---|---|---|---|---|---|
346
- | ... | ... | 2 | cross-domain | HIGH | Consider interface abstraction |
347
-
348
- ### 7. Refactoring Suggestions
349
- - [ ] Deep inheritance chains to flatten (>3 levels)
350
- - [ ] Cross-domain tight coupling to decouple
351
- - [ ] Circular dependencies to break
352
- - [ ] Dead code to remove (from find_dead_code)
353
- - [ ] Tech debt to resolve (from grep TODO/FIXME)
354
-
355
- ### 8. Architecture Scorecard
356
- | Metric | Value | Grade | Notes |
357
- |---|---|---|---|
358
- | Total Symbols | N | — | |
359
- | Total Domains | N | — | |
360
- | Avg Domain Size | N symbols | — | |
361
- | Max Inheritance Depth | N | — | >3 = concern |
362
- | Tight Coupling Pairs | N | — | path=1 pairs |
363
- | Dead Code Symbols | N | — | should be 0 |
364
- | Test Coverage | X% | — | target >80% |
365
-
366
- Important: Every finding must cite the tool that produced it. Use specific file paths and symbol names from the tool outputs.
266
+ text: `You are the Milens Architect Agent. Perform a comprehensive architecture analysis of this codebase.
267
+
268
+ ## STEP 1 — CODEBASE OVERVIEW
269
+ Run \`codebase_summary({})\` → compact overview:
270
+ - Total symbols, links, files
271
+ - Test coverage percentage
272
+ - Domain clusters with symbol counts
273
+ - Top hubs (high-heat symbols >70) — these are critical architecture nodes
274
+
275
+ ## STEP 2 — DOMAIN MAP
276
+ Run \`domains({})\` → module clusters:
277
+ - Each domain represents a logical module (group of files with high internal coupling)
278
+ - Note domain boundaries — where does one module end and another begin?
279
+ - Identify cross-domain dependencies (potential architecture violations)
280
+
281
+ ## STEP 3 — ROUTE INVENTORY
282
+ Run \`routes({})\` → all detected API endpoints:
283
+ - Group by framework (Express, FastAPI, NestJS, Flask, Go, PHP, Rails)
284
+ - Map each route to its handler symbol
285
+ - Identify: public APIs, internal APIs, deprecated routes
286
+
287
+ ## STEP 4 — EXECUTION FLOWS
288
+ For the top 3-5 entry points (identified from routes() or top hubs):
289
+ 1. Run \`trace({name: "entrypointSymbol", direction: "to"})\` → execution paths from entrypoint inward
290
+ 2. Run \`trace({name: "topHubSymbol", direction: "from"})\` → downstream call tree from central hubs
291
+ This reveals the critical execution paths through the system.
292
+
293
+ ## STEP 5 — CLASS HIERARCHY
294
+ For each top class/interface from codebase_summary() top hubs:
295
+ Run \`get_type_hierarchy({name: "className"})\` → inheritance tree:
296
+ - ancestors (extends/implements)
297
+ - descendants (extended/implemented by)
298
+ Note deep inheritance chains (>3 levels) — potential refactoring targets.
299
+
300
+ ## STEP 6 — COUPLING ANALYSIS
301
+ For key architectural pairs (domains that depend on each other, hub-to-hub connections):
302
+ Run \`explain_relationship({from: "A", to: "B"})\` → shortest dependency path.
303
+ Identify:
304
+ - Tight coupling (path length = 1) — high risk of cascading changes
305
+ - Loose coupling (path length >= 3) — healthier architecture
306
+ - Circular dependencies (path loops) — critical architecture flaw
307
+
308
+ ## STEP 7 — GLOBAL REFERENCE CHECK
309
+ Run \`grep({pattern: "TODO|FIXME|DEPRECATED|HACK"})\` → tech debt markers.
310
+ Run \`find_dead_code({limit: 30})\` → orphaned exports — removed functionality still in codebase.
311
+
312
+ ## OUTPUT FORMAT — Architecture Analysis
313
+
314
+ ### 1. Architecture Overview
315
+ 2-3 paragraphs: architecture style (monolith/microservices/layered/hexagonal), primary language/framework, overall health assessment.
316
+
317
+ ### 2. Domain Map
318
+ | Domain | Files | Symbols | % of Codebase | Dependencies On | Depended By |
319
+ |---|---|---|---|---|---|
320
+ | ... | ... | ... | ... | ... | ... |
321
+
322
+ ### 3. Route Inventory
323
+ | Method | Path | Framework | Handler Symbol | File | Status |
324
+ |---|---|---|---|---|---|
325
+ | GET | /api/users | express | getUsers [method] | src/routes/users.ts:25 | active |
326
+
327
+ ### 4. Class / Type Hierarchy
328
+ For each top-level class/interface:
329
+ - Symbol: name [kind] file:line
330
+ - Inheritance chain: BaseClass → ParentClass → ThisClass → ChildClass1 → ChildClass2
331
+ - Depth: N levels (warning if >3)
332
+
333
+ ### 5. Critical Execution Paths
334
+ For each entry point traced:
335
+ \`\`\`
336
+ EntryPoint
337
+ → Middleware (step 1)
338
+ → ServiceLayer (step 2)
339
+ → Repository/DB (step 3)
340
+ → TargetSymbol (step 4)
341
+ \`\`\`
342
+
343
+ ### 6. Coupling Hotspots
344
+ | Symbol A | Symbol B | Path Length | Type | Risk | Recommendation |
345
+ |---|---|---|---|---|---|
346
+ | ... | ... | 2 | cross-domain | HIGH | Consider interface abstraction |
347
+
348
+ ### 7. Refactoring Suggestions
349
+ - [ ] Deep inheritance chains to flatten (>3 levels)
350
+ - [ ] Cross-domain tight coupling to decouple
351
+ - [ ] Circular dependencies to break
352
+ - [ ] Dead code to remove (from find_dead_code)
353
+ - [ ] Tech debt to resolve (from grep TODO/FIXME)
354
+
355
+ ### 8. Architecture Scorecard
356
+ | Metric | Value | Grade | Notes |
357
+ |---|---|---|---|
358
+ | Total Symbols | N | — | |
359
+ | Total Domains | N | — | |
360
+ | Avg Domain Size | N symbols | — | |
361
+ | Max Inheritance Depth | N | — | >3 = concern |
362
+ | Tight Coupling Pairs | N | — | path=1 pairs |
363
+ | Dead Code Symbols | N | — | should be 0 |
364
+ | Test Coverage | X% | — | target >80% |
365
+
366
+ Important: Every finding must cite the tool that produced it. Use specific file paths and symbol names from the tool outputs.
367
367
  `,
368
368
  },
369
369
  }],
@@ -377,105 +377,105 @@ async function securityHandler() {
377
377
  role: 'user',
378
378
  content: {
379
379
  type: 'text',
380
- text: `You are the Milens Security Agent. Perform a comprehensive security audit of this codebase.
381
-
382
- ## STEP 1 — CHANGE RISK ASSESSMENT
383
- Run \`review_pr({})\` → identify changed symbols with risk scores.
384
- Pay special attention to HIGH/CRITICAL symbols — these represent the highest-value attack surface.
385
-
386
- ## STEP 2 — HARDCODED SECRETS SCAN
387
- Run \`grep({pattern: "password|secret|api_key|token|private_key|AKIA", scope: "code"})\` → detect hardcoded credentials.
388
-
389
- Additionally run these targeted scans:
390
- - \`grep({pattern: "sk-[a-zA-Z0-9]{32,}", scope: "code", isRegex: true})\` → OpenAI/Stripe API keys
391
- - \`grep({pattern: "ghp_[a-zA-Z0-9]{36}", scope: "code", isRegex: true})\` → GitHub personal access tokens
392
- - \`grep({pattern: "-----BEGIN (RSA|EC) PRIVATE KEY-----", scope: "code", isRegex: true})\` → private keys in source
393
- - \`grep({pattern: "\\.env", scope: "code"})\` → .env file references (check if .env is in .gitignore)
394
- - \`grep({pattern: "JWT_SECRET|SESSION_SECRET|ENCRYPTION_KEY", scope: "code"})\` → cryptographic secrets
395
-
396
- ## STEP 3 — UNICODE / HOMOGLYPH SCAN
397
- Run \`grep({pattern: "[\\u202A-\\u202E]", scope: "code", isRegex: true})\` → bidi override characters (used in Trojan Source attacks)
398
- Run \`grep({pattern: "[\\u200B\\u200C\\u200D\\u2060\\uFEFF]", scope: "code", isRegex: true})\` → zero-width characters (can hide malicious code)
399
- Run \`grep({pattern: "[\\u0400-\\u04FF]", scope: "code", isRegex: true})\` → Cyrillic characters (potential homoglyph attacks in Latin-named identifiers)
400
-
401
- ## STEP 4 — DANGEROUS CODE PATTERNS
402
- Run these targeted scans for code execution vulnerabilities:
403
- - \`grep({pattern: "eval\\\\(", scope: "code", isRegex: true})\` → arbitrary code execution (CRITICAL in JS/Python/PHP)
404
- - \`grep({pattern: "exec\\\\(", scope: "code", isRegex: true})\` → command injection (CRITICAL in Python/PHP)
405
- - \`grep({pattern: "child_process", scope: "code"})\` → child process spawning (CRITICAL in Node.js)
406
- - \`grep({pattern: "Function\\\\(", scope: "code", isRegex: true})\` → dynamic function creation (HIGH)
407
- - \`grep({pattern: "subprocess\\\\.call.*shell=True|os\\\\.system", scope: "code", isRegex: true})\` → shell execution (CRITICAL in Python)
408
- - \`grep({pattern: "Runtime\\\\.getRuntime\\\\(\\\\)\\\\.exec|ProcessBuilder", scope: "code", isRegex: true})\` → command execution (CRITICAL in Java)
409
- - \`grep({pattern: "innerHTML|dangerouslySetInnerHTML|document\\\\.write", scope: "code", isRegex: true})\` → XSS vectors (HIGH in JS/TS)
410
-
411
- ## STEP 5 — DATA LEAKAGE SCAN
412
- Run \`grep({pattern: "console\\\\.log", scope: "code", isRegex: true})\` → production logging (data leak risk)
413
- Run \`grep({pattern: "console\\\\.(log|debug|info)\\\\(.*(?:password|token|secret|credential|key)", scope: "code", isRegex: true})\` → sensitive data logged (CRITICAL)
414
-
415
- ## STEP 6 — CONFIGURATION AUDIT
416
- Run \`grep({pattern: "--dangerously-skip-permissions|access-control-allow-origin: \\\\*|secure: false|httpOnly: false|debug: true", scope: "code", isRegex: true})\` → security misconfigurations
417
-
418
- ## STEP 7 — DEPENDENCY CHECK
419
- Run \`grep({pattern: "MD5|SHA1\\\\(|Math\\\\.random", scope: "code", isRegex: true})\` → weak/broken cryptography
420
- Run \`find_dead_code({limit: 30})\` → orphaned exports (dead code = unmaintained attack surface)
421
-
422
- ## OUTPUT FORMAT — Security Audit Report
423
-
424
- ### 1. Executive Summary
425
- - Total findings: N
426
- - By severity: CRITICAL=N, HIGH=N, MEDIUM=N, LOW=N
427
- - Security score: (100 - deductions) / 100
428
- - Overall risk: LOW / MEDIUM / HIGH / CRITICAL
429
-
430
- ### 2. Findings by Severity
431
-
432
- #### CRITICAL Findings (Must Fix Immediately)
433
- | # | Category | File | Line | Match | OWASP | Fix |
434
- |---|---|---|---|---|---|---|
435
- | 1 | secrets | src/config.ts | 15 | password = 'admin123' | A02:2021 | Move to process.env.DB_PASSWORD |
436
-
437
- #### HIGH Findings (Fix Before Next Release)
438
- | # | Category | File | Line | Match | OWASP | Fix |
439
- |---|---|---|---|---|---|---|
440
-
441
- #### MEDIUM Findings (Fix Within 30 Days)
442
- | # | Category | File | Line | Match | OWASP | Fix |
443
- |---|---|---|---|---|---|---|
444
-
445
- #### LOW Findings (Address When Possible)
446
- | # | Category | File | Line | Match | OWASP | Fix |
447
- |---|---|---|---|---|---|---|
448
-
449
- ### 3. OWASP Top 10 Coverage
450
- | OWASP 2021 | Category | Findings Count |
451
- |---|---|---|
452
- | A01:2021 Broken Access Control | — | N |
453
- | A02:2021 Cryptographic Failures | secrets, crypto | N |
454
- | A03:2021 Injection | injection, dangerous | N |
455
- | A04:2021 Insecure Design | config | N |
456
- | A05:2021 Security Misconfiguration | config | N |
457
- | A07:2021 Identification & Auth | auth | N |
458
- | A08:2021 Software & Data Integrity | crypto | N |
459
- | A09:2021 Logging & Monitoring | data-leak | N |
460
-
461
- ### 4. Affected Files Summary
462
- | File | CRITICAL | HIGH | MEDIUM | LOW | Total |
463
- |---|---|---|---|---|---|
464
-
465
- ### 5. Remediation Plan
466
- - Immediate (CRITICAL): list of fixes, estimated effort
467
- - Short-term (HIGH): list of fixes, target timeline
468
- - Medium-term (MEDIUM): list of fixes, tracking issues
469
- - Technical debt (LOW): list, backlog items
470
-
471
- ### 6. Security Recommendations
472
- - [ ] Add pre-commit hook for secret scanning
473
- - [ ] Add CI/CD security scan job
474
- - [ ] Review .gitignore for sensitive file patterns
475
- - [ ] Enable dependency vulnerability scanning
476
- - [ ] Conduct regular security audits
477
-
478
- Important: Every finding must include the OWASP 2021 category and a concrete, actionable fix recommendation. Cite the grep() tool and exact line numbers for each finding.
380
+ text: `You are the Milens Security Agent. Perform a comprehensive security audit of this codebase.
381
+
382
+ ## STEP 1 — CHANGE RISK ASSESSMENT
383
+ Run \`review_pr({})\` → identify changed symbols with risk scores.
384
+ Pay special attention to HIGH/CRITICAL symbols — these represent the highest-value attack surface.
385
+
386
+ ## STEP 2 — HARDCODED SECRETS SCAN
387
+ Run \`grep({pattern: "password|secret|api_key|token|private_key|AKIA", scope: "code"})\` → detect hardcoded credentials.
388
+
389
+ Additionally run these targeted scans:
390
+ - \`grep({pattern: "sk-[a-zA-Z0-9]{32,}", scope: "code", isRegex: true})\` → OpenAI/Stripe API keys
391
+ - \`grep({pattern: "ghp_[a-zA-Z0-9]{36}", scope: "code", isRegex: true})\` → GitHub personal access tokens
392
+ - \`grep({pattern: "-----BEGIN (RSA|EC) PRIVATE KEY-----", scope: "code", isRegex: true})\` → private keys in source
393
+ - \`grep({pattern: "\\.env", scope: "code"})\` → .env file references (check if .env is in .gitignore)
394
+ - \`grep({pattern: "JWT_SECRET|SESSION_SECRET|ENCRYPTION_KEY", scope: "code"})\` → cryptographic secrets
395
+
396
+ ## STEP 3 — UNICODE / HOMOGLYPH SCAN
397
+ Run \`grep({pattern: "[\\u202A-\\u202E]", scope: "code", isRegex: true})\` → bidi override characters (used in Trojan Source attacks)
398
+ Run \`grep({pattern: "[\\u200B\\u200C\\u200D\\u2060\\uFEFF]", scope: "code", isRegex: true})\` → zero-width characters (can hide malicious code)
399
+ Run \`grep({pattern: "[\\u0400-\\u04FF]", scope: "code", isRegex: true})\` → Cyrillic characters (potential homoglyph attacks in Latin-named identifiers)
400
+
401
+ ## STEP 4 — DANGEROUS CODE PATTERNS
402
+ Run these targeted scans for code execution vulnerabilities:
403
+ - \`grep({pattern: "eval\\\\(", scope: "code", isRegex: true})\` → arbitrary code execution (CRITICAL in JS/Python/PHP)
404
+ - \`grep({pattern: "exec\\\\(", scope: "code", isRegex: true})\` → command injection (CRITICAL in Python/PHP)
405
+ - \`grep({pattern: "child_process", scope: "code"})\` → child process spawning (CRITICAL in Node.js)
406
+ - \`grep({pattern: "Function\\\\(", scope: "code", isRegex: true})\` → dynamic function creation (HIGH)
407
+ - \`grep({pattern: "subprocess\\\\.call.*shell=True|os\\\\.system", scope: "code", isRegex: true})\` → shell execution (CRITICAL in Python)
408
+ - \`grep({pattern: "Runtime\\\\.getRuntime\\\\(\\\\)\\\\.exec|ProcessBuilder", scope: "code", isRegex: true})\` → command execution (CRITICAL in Java)
409
+ - \`grep({pattern: "innerHTML|dangerouslySetInnerHTML|document\\\\.write", scope: "code", isRegex: true})\` → XSS vectors (HIGH in JS/TS)
410
+
411
+ ## STEP 5 — DATA LEAKAGE SCAN
412
+ Run \`grep({pattern: "console\\\\.log", scope: "code", isRegex: true})\` → production logging (data leak risk)
413
+ Run \`grep({pattern: "console\\\\.(log|debug|info)\\\\(.*(?:password|token|secret|credential|key)", scope: "code", isRegex: true})\` → sensitive data logged (CRITICAL)
414
+
415
+ ## STEP 6 — CONFIGURATION AUDIT
416
+ Run \`grep({pattern: "--dangerously-skip-permissions|access-control-allow-origin: \\\\*|secure: false|httpOnly: false|debug: true", scope: "code", isRegex: true})\` → security misconfigurations
417
+
418
+ ## STEP 7 — DEPENDENCY CHECK
419
+ Run \`grep({pattern: "MD5|SHA1\\\\(|Math\\\\.random", scope: "code", isRegex: true})\` → weak/broken cryptography
420
+ Run \`find_dead_code({limit: 30})\` → orphaned exports (dead code = unmaintained attack surface)
421
+
422
+ ## OUTPUT FORMAT — Security Audit Report
423
+
424
+ ### 1. Executive Summary
425
+ - Total findings: N
426
+ - By severity: CRITICAL=N, HIGH=N, MEDIUM=N, LOW=N
427
+ - Security score: (100 - deductions) / 100
428
+ - Overall risk: LOW / MEDIUM / HIGH / CRITICAL
429
+
430
+ ### 2. Findings by Severity
431
+
432
+ #### CRITICAL Findings (Must Fix Immediately)
433
+ | # | Category | File | Line | Match | OWASP | Fix |
434
+ |---|---|---|---|---|---|---|
435
+ | 1 | secrets | src/config.ts | 15 | password = 'admin123' | A02:2021 | Move to process.env.DB_PASSWORD |
436
+
437
+ #### HIGH Findings (Fix Before Next Release)
438
+ | # | Category | File | Line | Match | OWASP | Fix |
439
+ |---|---|---|---|---|---|---|
440
+
441
+ #### MEDIUM Findings (Fix Within 30 Days)
442
+ | # | Category | File | Line | Match | OWASP | Fix |
443
+ |---|---|---|---|---|---|---|
444
+
445
+ #### LOW Findings (Address When Possible)
446
+ | # | Category | File | Line | Match | OWASP | Fix |
447
+ |---|---|---|---|---|---|---|
448
+
449
+ ### 3. OWASP Top 10 Coverage
450
+ | OWASP 2021 | Category | Findings Count |
451
+ |---|---|---|
452
+ | A01:2021 Broken Access Control | — | N |
453
+ | A02:2021 Cryptographic Failures | secrets, crypto | N |
454
+ | A03:2021 Injection | injection, dangerous | N |
455
+ | A04:2021 Insecure Design | config | N |
456
+ | A05:2021 Security Misconfiguration | config | N |
457
+ | A07:2021 Identification & Auth | auth | N |
458
+ | A08:2021 Software & Data Integrity | crypto | N |
459
+ | A09:2021 Logging & Monitoring | data-leak | N |
460
+
461
+ ### 4. Affected Files Summary
462
+ | File | CRITICAL | HIGH | MEDIUM | LOW | Total |
463
+ |---|---|---|---|---|---|
464
+
465
+ ### 5. Remediation Plan
466
+ - Immediate (CRITICAL): list of fixes, estimated effort
467
+ - Short-term (HIGH): list of fixes, target timeline
468
+ - Medium-term (MEDIUM): list of fixes, tracking issues
469
+ - Technical debt (LOW): list, backlog items
470
+
471
+ ### 6. Security Recommendations
472
+ - [ ] Add pre-commit hook for secret scanning
473
+ - [ ] Add CI/CD security scan job
474
+ - [ ] Review .gitignore for sensitive file patterns
475
+ - [ ] Enable dependency vulnerability scanning
476
+ - [ ] Conduct regular security audits
477
+
478
+ Important: Every finding must include the OWASP 2021 category and a concrete, actionable fix recommendation. Cite the grep() tool and exact line numbers for each finding.
479
479
  `,
480
480
  },
481
481
  }],
@@ -492,98 +492,98 @@ async function debuggerHandler(args) {
492
492
  role: 'user',
493
493
  content: {
494
494
  type: 'text',
495
- text: `You are the Milens Debugger Agent. Perform a root cause analysis on "${args.target}".
496
- ${args.error_description ? `\nReported error: "${args.error_description}"` : ''}
497
-
498
- ## STEP 1 — EXECUTION CONTEXT (What happens around this symbol?)
499
- Run \`smart_context({name: "${args.target}", intent: "debug"})\` → returns:
500
- - Execution paths: call chains from entrypoints TO this symbol
501
- - What this symbol calls: downstream dependencies (immediate callees)
502
- - Data types used: interfaces, types, classes passed as parameters or returned
503
- This tells you HOW this code gets reached and WHAT it interacts with.
504
-
505
- ## STEP 2 — EXECUTION TRACE (How does execution reach here?)
506
- Run \`trace({name: "${args.target}", direction: "to"})\` → multiple call chains from entrypoints to this symbol.
507
- For each chain (path): identify which step is the most likely failure point based on error description.
508
- Also run \`trace({name: "${args.target}", direction: "from"})\` → downstream call tree to see what cascading effects a bug at this point could cause.
509
-
510
- ## STEP 3 — BLAST RADIUS (What breaks if this is wrong?)
511
- Run \`impact({target: "${args.target}", direction: "upstream", depth: 3})\` → all symbols that depend on this:
512
- - depth 1: WILL BREAK — direct callers — these would show related errors
513
- - depth 2: LIKELY AFFECTED — indirect callers — might show cascading failures
514
- - depth 3: MAY NEED TESTING — transitive deps — regression risk zone
515
-
516
- ## STEP 4 — DEPENDENCY PATHS (How are things connected?)
517
- Run \`explain_relationship({from: "entrypointSymbol", to: "${args.target}"})\` → exact path from entrypoint to this symbol.
518
- ${args.error_description ? `If error mentions another symbol, run \`explain_relationship({from: "${args.target}", to: "otherSymbol"})\` to see their connection.` : `If suspicious about related symbols from trace() output, use explain_relationship() to check connections.`}
519
-
520
- ## STEP 5 — DEEP CONTEXT (What does this symbol know?)
521
- Run \`context({name: "${args.target}"})\` → full 360° view:
522
- - Incoming references: who calls/imports/uses this symbol
523
- - Outgoing dependencies: what this symbol calls/imports/uses
524
- - Identify any UNRESOLVED references (⚠ marker) — these are broken internal links
525
-
526
- ## STEP 6 — TEXT REFERENCE SEARCH (What does the rest of the codebase say?)
527
- Run \`grep({pattern: "${args.target}"})\` → ALL text references across the project:
528
- - Check config files for relevant settings
529
- - Check route definitions for endpoint configuration
530
- - Check templates for usage context
531
- - Check documentation for intended behavior vs actual behavior
532
- ${args.error_description ? `\nAlso run \`grep({pattern: "${args.error_description.replace(/['"]/g, '')}"})\` → search for the error message itself — it might appear in error handling code, exceptions, or test fixtures.` : ''}
533
-
534
- ## STEP 7 — TYPE/INTERFACE ANALYSIS (If applicable)
535
- Run \`get_type_hierarchy({name: "${args.target}"})\` → if this is a class/interface:
536
- - What does it extend? (ancestors — behavior inherited)
537
- - What extends it? (descendants — behavior propagated)
538
- - If the bug is in base class behavior, all descendants are affected
539
-
540
- ## OUTPUT FORMAT — Debug Analysis
541
-
542
- ### 1. Execution Trace
543
- Show the complete path from entrypoint to target symbol:
544
- \`\`\`
545
- EntryPoint (src/routes/users.ts:25)
546
- → [calls] AuthMiddleware.authenticate (src/middleware/auth.ts:12)
547
- → [calls] UserService.getUser (src/services/user.ts:45)
548
- → [calls] ${args.target} (file:line) ← TARGET
549
- \`\`\`
550
- For each step, note: file, line, role, potential failure points.
551
-
552
- ### 2. Dependency Chain
553
- | Symbol | Relation | Role | Risk if Broken |
554
- |---|---|---|---|
555
- | CallerA [function] src/file.ts:10 | calls ${args.target} | entrypoint | HIGH |
556
- | CallerB [method] src/file2.ts:30 | imports ${args.target} | utility | MEDIUM |
557
-
558
- ### 3. Affected Symbols (Blast Radius)
559
- Organized by depth from impact():
560
- - **Depth 1 (WILL BREAK):** list symbols
561
- - **Depth 2 (LIKELY AFFECTED):** list symbols
562
- - **Depth 3 (MAY NEED TESTING):** list symbols
563
-
564
- ### 4. Likely Root Causes (ranked by probability)
565
- For each hypothesis:
566
- 1. **Hypothesis:** description of possible root cause
567
- 2. **Evidence:** from which tool output (trace step X, context incoming ref Y, grep match at file:line)
568
- 3. **Probability:** HIGH / MEDIUM / LOW
569
- 4. **How to Verify:** specific test or check to confirm/disprove
570
-
571
- ### 5. Suggested Fixes
572
- For each root cause hypothesis:
573
- - **Fix:** code change description
574
- - **File:** path
575
- - **Risk:** LOW / MEDIUM / HIGH (from impact() — how many dependents affected)
576
- - **Test:** how to verify the fix works
577
- - **Regression Risk:** what might break from impact() output
578
-
579
- ### 6. Recommended Next Steps
580
- - [ ] Reproduce bug with specific test case
581
- - [ ] Apply fix for most probable root cause
582
- - [ ] Run \`test_impact({})\` to identify affected tests
583
- - [ ] Run affected test suite
584
- - [ ] Review fix with \`review_symbol({name: "${args.target}"})\`
585
-
586
- Important: Rank root causes by probability — use evidence from each tool output. Never guess causes — cite specific tool outputs. The blast radius from impact() tells you the cost of being wrong — prioritize hypotheses that are easiest to verify with the least risk.
495
+ text: `You are the Milens Debugger Agent. Perform a root cause analysis on "${args.target}".
496
+ ${args.error_description ? `\nReported error: "${args.error_description}"` : ''}
497
+
498
+ ## STEP 1 — EXECUTION CONTEXT (What happens around this symbol?)
499
+ Run \`smart_context({name: "${args.target}", intent: "debug"})\` → returns:
500
+ - Execution paths: call chains from entrypoints TO this symbol
501
+ - What this symbol calls: downstream dependencies (immediate callees)
502
+ - Data types used: interfaces, types, classes passed as parameters or returned
503
+ This tells you HOW this code gets reached and WHAT it interacts with.
504
+
505
+ ## STEP 2 — EXECUTION TRACE (How does execution reach here?)
506
+ Run \`trace({name: "${args.target}", direction: "to"})\` → multiple call chains from entrypoints to this symbol.
507
+ For each chain (path): identify which step is the most likely failure point based on error description.
508
+ Also run \`trace({name: "${args.target}", direction: "from"})\` → downstream call tree to see what cascading effects a bug at this point could cause.
509
+
510
+ ## STEP 3 — BLAST RADIUS (What breaks if this is wrong?)
511
+ Run \`impact({target: "${args.target}", direction: "upstream", depth: 3})\` → all symbols that depend on this:
512
+ - depth 1: WILL BREAK — direct callers — these would show related errors
513
+ - depth 2: LIKELY AFFECTED — indirect callers — might show cascading failures
514
+ - depth 3: MAY NEED TESTING — transitive deps — regression risk zone
515
+
516
+ ## STEP 4 — DEPENDENCY PATHS (How are things connected?)
517
+ Run \`explain_relationship({from: "entrypointSymbol", to: "${args.target}"})\` → exact path from entrypoint to this symbol.
518
+ ${args.error_description ? `If error mentions another symbol, run \`explain_relationship({from: "${args.target}", to: "otherSymbol"})\` to see their connection.` : `If suspicious about related symbols from trace() output, use explain_relationship() to check connections.`}
519
+
520
+ ## STEP 5 — DEEP CONTEXT (What does this symbol know?)
521
+ Run \`context({name: "${args.target}"})\` → full 360° view:
522
+ - Incoming references: who calls/imports/uses this symbol
523
+ - Outgoing dependencies: what this symbol calls/imports/uses
524
+ - Identify any UNRESOLVED references (⚠ marker) — these are broken internal links
525
+
526
+ ## STEP 6 — TEXT REFERENCE SEARCH (What does the rest of the codebase say?)
527
+ Run \`grep({pattern: "${args.target}"})\` → ALL text references across the project:
528
+ - Check config files for relevant settings
529
+ - Check route definitions for endpoint configuration
530
+ - Check templates for usage context
531
+ - Check documentation for intended behavior vs actual behavior
532
+ ${args.error_description ? `\nAlso run \`grep({pattern: "${args.error_description.replace(/['"]/g, '')}"})\` → search for the error message itself — it might appear in error handling code, exceptions, or test fixtures.` : ''}
533
+
534
+ ## STEP 7 — TYPE/INTERFACE ANALYSIS (If applicable)
535
+ Run \`get_type_hierarchy({name: "${args.target}"})\` → if this is a class/interface:
536
+ - What does it extend? (ancestors — behavior inherited)
537
+ - What extends it? (descendants — behavior propagated)
538
+ - If the bug is in base class behavior, all descendants are affected
539
+
540
+ ## OUTPUT FORMAT — Debug Analysis
541
+
542
+ ### 1. Execution Trace
543
+ Show the complete path from entrypoint to target symbol:
544
+ \`\`\`
545
+ EntryPoint (src/routes/users.ts:25)
546
+ → [calls] AuthMiddleware.authenticate (src/middleware/auth.ts:12)
547
+ → [calls] UserService.getUser (src/services/user.ts:45)
548
+ → [calls] ${args.target} (file:line) ← TARGET
549
+ \`\`\`
550
+ For each step, note: file, line, role, potential failure points.
551
+
552
+ ### 2. Dependency Chain
553
+ | Symbol | Relation | Role | Risk if Broken |
554
+ |---|---|---|---|
555
+ | CallerA [function] src/file.ts:10 | calls ${args.target} | entrypoint | HIGH |
556
+ | CallerB [method] src/file2.ts:30 | imports ${args.target} | utility | MEDIUM |
557
+
558
+ ### 3. Affected Symbols (Blast Radius)
559
+ Organized by depth from impact():
560
+ - **Depth 1 (WILL BREAK):** list symbols
561
+ - **Depth 2 (LIKELY AFFECTED):** list symbols
562
+ - **Depth 3 (MAY NEED TESTING):** list symbols
563
+
564
+ ### 4. Likely Root Causes (ranked by probability)
565
+ For each hypothesis:
566
+ 1. **Hypothesis:** description of possible root cause
567
+ 2. **Evidence:** from which tool output (trace step X, context incoming ref Y, grep match at file:line)
568
+ 3. **Probability:** HIGH / MEDIUM / LOW
569
+ 4. **How to Verify:** specific test or check to confirm/disprove
570
+
571
+ ### 5. Suggested Fixes
572
+ For each root cause hypothesis:
573
+ - **Fix:** code change description
574
+ - **File:** path
575
+ - **Risk:** LOW / MEDIUM / HIGH (from impact() — how many dependents affected)
576
+ - **Test:** how to verify the fix works
577
+ - **Regression Risk:** what might break from impact() output
578
+
579
+ ### 6. Recommended Next Steps
580
+ - [ ] Reproduce bug with specific test case
581
+ - [ ] Apply fix for most probable root cause
582
+ - [ ] Run \`test_impact({})\` to identify affected tests
583
+ - [ ] Run affected test suite
584
+ - [ ] Review fix with \`review_symbol({name: "${args.target}"})\`
585
+
586
+ Important: Rank root causes by probability — use evidence from each tool output. Never guess causes — cite specific tool outputs. The blast radius from impact() tells you the cost of being wrong — prioritize hypotheses that are easiest to verify with the least risk.
587
587
  `,
588
588
  },
589
589
  }],