zelari-code 0.7.9 → 0.7.11
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/LICENSE +37 -37
- package/README.md +320 -295
- package/bin/zelari-code.js +62 -62
- package/dist/cli/app.js +33 -3
- package/dist/cli/app.js.map +1 -1
- package/dist/cli/components/LiveRegion.js +7 -3
- package/dist/cli/components/LiveRegion.js.map +1 -1
- package/dist/cli/components/SelectList.js +67 -0
- package/dist/cli/components/SelectList.js.map +1 -0
- package/dist/cli/components/Spinner.js +51 -0
- package/dist/cli/components/Spinner.js.map +1 -0
- package/dist/cli/components/SplashScreen.js +85 -85
- package/dist/cli/components/StatusBar.js +42 -34
- package/dist/cli/components/StatusBar.js.map +1 -1
- package/dist/cli/headless.js +10 -10
- package/dist/cli/hooks/useSlashDispatch.js +11 -1
- package/dist/cli/hooks/useSlashDispatch.js.map +1 -1
- package/dist/cli/keyStore.js +2 -2
- package/dist/cli/keyStore.js.map +1 -1
- package/dist/cli/main.bundled.js +15146 -14919
- package/dist/cli/main.bundled.js.map +4 -4
- package/dist/cli/main.js +1 -1
- package/dist/cli/main.js.map +1 -1
- package/dist/cli/modelDiscovery.js +42 -5
- package/dist/cli/modelDiscovery.js.map +1 -1
- package/dist/cli/provider/openai-compatible.js +4 -2
- package/dist/cli/provider/openai-compatible.js.map +1 -1
- package/dist/cli/slashCommands.js +22 -5
- package/dist/cli/slashCommands.js.map +1 -1
- package/dist/cli/slashHandlers/provider.js +102 -5
- package/dist/cli/slashHandlers/provider.js.map +1 -1
- package/package.json +2 -2
- package/dist/agents/advancedTools.js +0 -115
- package/dist/agents/advancedTools.js.map +0 -1
- package/dist/agents/councilApi.js +0 -375
- package/dist/agents/councilApi.js.map +0 -1
- package/dist/agents/councilDirectives.js +0 -100
- package/dist/agents/councilDirectives.js.map +0 -1
- package/dist/agents/promoteMember.js +0 -210
- package/dist/agents/promoteMember.js.map +0 -1
- package/dist/agents/promptModules.js +0 -139
- package/dist/agents/promptModules.js.map +0 -1
- package/dist/agents/roles.js +0 -299
- package/dist/agents/roles.js.map +0 -1
- package/dist/agents/skills/builtin/debugging.js +0 -248
- package/dist/agents/skills/builtin/debugging.js.map +0 -1
- package/dist/agents/skills/builtin/docs.js +0 -301
- package/dist/agents/skills/builtin/docs.js.map +0 -1
- package/dist/agents/skills/builtin/git-ops.js +0 -301
- package/dist/agents/skills/builtin/git-ops.js.map +0 -1
- package/dist/agents/skills/builtin/planning.js +0 -335
- package/dist/agents/skills/builtin/planning.js.map +0 -1
- package/dist/agents/skills/builtin/refactoring.js +0 -261
- package/dist/agents/skills/builtin/refactoring.js.map +0 -1
- package/dist/agents/skills/builtin/review.js +0 -302
- package/dist/agents/skills/builtin/review.js.map +0 -1
- package/dist/agents/skills/builtin/testing.js +0 -245
- package/dist/agents/skills/builtin/testing.js.map +0 -1
- package/dist/agents/skills.js +0 -272
- package/dist/agents/skills.js.map +0 -1
- package/dist/agents/systemPromptBuilder.js +0 -151
- package/dist/agents/systemPromptBuilder.js.map +0 -1
- package/dist/agents/toolSchemas.js +0 -249
- package/dist/agents/toolSchemas.js.map +0 -1
- package/dist/agents/tools.js +0 -196
- package/dist/agents/tools.js.map +0 -1
- package/dist/agents/vaultTools.js +0 -134
- package/dist/agents/vaultTools.js.map +0 -1
- package/dist/cli/components/CollapsibleToolOutput.js +0 -43
- package/dist/cli/components/CollapsibleToolOutput.js.map +0 -1
- package/dist/cli/components/Header.js +0 -38
- package/dist/cli/components/Header.js.map +0 -1
- package/dist/main/core/AgentHarness.js +0 -467
- package/dist/main/core/AgentHarness.js.map +0 -1
- package/dist/main/core/providerStream.js +0 -99
- package/dist/main/core/providerStream.js.map +0 -1
- package/dist/main/core/sessionJsonl.js +0 -99
- package/dist/main/core/sessionJsonl.js.map +0 -1
- package/dist/main/core/tools/auditLog.js +0 -26
- package/dist/main/core/tools/auditLog.js.map +0 -1
- package/dist/main/core/tools/builtin/filesystem.js +0 -110
- package/dist/main/core/tools/builtin/filesystem.js.map +0 -1
- package/dist/main/core/tools/builtin/listFiles.js +0 -86
- package/dist/main/core/tools/builtin/listFiles.js.map +0 -1
- package/dist/main/core/tools/builtin/search.js +0 -56
- package/dist/main/core/tools/builtin/search.js.map +0 -1
- package/dist/main/core/tools/builtin/shell.js +0 -51
- package/dist/main/core/tools/builtin/shell.js.map +0 -1
- package/dist/main/core/tools/registry.js +0 -71
- package/dist/main/core/tools/registry.js.map +0 -1
- package/dist/main/core/tools/toolTypes.js +0 -8
- package/dist/main/core/tools/toolTypes.js.map +0 -1
- package/dist/main/core/tools/zodBridge.js +0 -56
- package/dist/main/core/tools/zodBridge.js.map +0 -1
- package/dist/shared/eventBus.js +0 -104
- package/dist/shared/eventBus.js.map +0 -1
- package/dist/shared/events.js +0 -73
- package/dist/shared/events.js.map +0 -1
- package/dist/shared/index.js +0 -8
- package/dist/shared/index.js.map +0 -1
- package/dist/types/context.js +0 -3
- package/dist/types/context.js.map +0 -1
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/types/knowledge.js +0 -2
- package/dist/types/knowledge.js.map +0 -1
- package/dist/types/systemTypes.js +0 -10
- package/dist/types/systemTypes.js.map +0 -1
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { registerCodingSkill } from '../../skills.js';
|
|
2
|
-
const CLARIFICATION_PROTOCOL = `
|
|
3
|
-
|
|
4
|
-
WHEN TO ASK THE USER (clarification):
|
|
5
|
-
If a single missing fact would materially change your output (target platform, scope, a binary design choice with significant trade-offs, a constraint you cannot safely assume), pause and ask the user by appending EXACTLY this block at the end of your message:
|
|
6
|
-
|
|
7
|
-
---QUESTION---
|
|
8
|
-
{ "question": "One focused question", "choices": ["Option A", "Option B", "Option C"], "context": "Why this matters" }
|
|
9
|
-
---END---
|
|
10
|
-
|
|
11
|
-
Rules for clarifications:
|
|
12
|
-
- Ask AT MOST ONE question per turn, and only when genuinely blocked.
|
|
13
|
-
- Prefer a small set of concrete "choices" (2-4). The user can still type a custom answer.
|
|
14
|
-
- Do NOT ask for information that could be reasonably assumed or already in shared context.
|
|
15
|
-
- If you can proceed with a sound documented assumption, DO SO instead of asking.`;
|
|
16
|
-
const extractReusable = {
|
|
17
|
-
id: 'extract-reusable',
|
|
18
|
-
version: '1.0.0',
|
|
19
|
-
name: 'Extract Reusable Module',
|
|
20
|
-
description: 'Find duplication across files via semantic search. Identify shared logic, propose a new reusable module with a clean API, plan the migration of all call sites.',
|
|
21
|
-
category: 'refactor',
|
|
22
|
-
requiredRoles: ['atlas', 'oracle'],
|
|
23
|
-
requiredTools: ['searchRAG'],
|
|
24
|
-
estimatedCost: 'medium',
|
|
25
|
-
enabledByDefault: true,
|
|
26
|
-
builtin: true,
|
|
27
|
-
triggers: [
|
|
28
|
-
'Same logic copy-pasted across 3+ files',
|
|
29
|
-
'Two near-identical utility functions (e.g. formatDate in 2 different files)',
|
|
30
|
-
'A bug fix needs to be applied in 5 places',
|
|
31
|
-
'New project copies code from old project (opportunity to extract)',
|
|
32
|
-
],
|
|
33
|
-
antiPatterns: [
|
|
34
|
-
'Duplication is INTENTIONAL (different domains, different evolution paths)',
|
|
35
|
-
'Shared logic is so trivial (< 5 lines) that a function call adds more noise than it removes',
|
|
36
|
-
'API is unstable — extracting now would force awkward premature abstractions',
|
|
37
|
-
],
|
|
38
|
-
requires: [],
|
|
39
|
-
relatedSkills: ['refactor-monolith', 'simplify-conditionals'],
|
|
40
|
-
tags: ['refactor', 'deduplication', 'reuse', 'shared-module'],
|
|
41
|
-
examples: [
|
|
42
|
-
{
|
|
43
|
-
input: 'There are 3 different "formatDuration" implementations in src/ — slightly different in each',
|
|
44
|
-
output: {
|
|
45
|
-
duplication: {
|
|
46
|
-
callSites: [
|
|
47
|
-
{ file: 'src/components/Timer.tsx', function: 'formatDuration(ms: number): string', line: 23 },
|
|
48
|
-
{ file: 'src/lib/utils.ts', function: 'formatDuration(ms: number): string', line: 47 },
|
|
49
|
-
{ file: 'src/pages/Settings.tsx', function: 'formatDurationText(ms: number): string', line: 156 },
|
|
50
|
-
],
|
|
51
|
-
differences: [
|
|
52
|
-
'Timer.tsx: shows "1h 23m" for >1h, "23m 45s" for >1m, else "45s"',
|
|
53
|
-
'utils.ts: shows "1:23:45" always (HH:MM:SS)',
|
|
54
|
-
'Settings.tsx: shows "23m" for >1m, "45s" else',
|
|
55
|
-
],
|
|
56
|
-
},
|
|
57
|
-
proposedModule: {
|
|
58
|
-
path: 'src/lib/format/duration.ts',
|
|
59
|
-
api: `export function formatDuration(ms: number, opts?: { style?: 'compact' | 'full' | 'minimal' }): string`,
|
|
60
|
-
variants: [
|
|
61
|
-
{ style: 'compact', example: '1h 23m' },
|
|
62
|
-
{ style: 'full', example: '1:23:45' },
|
|
63
|
-
{ style: 'minimal', example: '23m' },
|
|
64
|
-
],
|
|
65
|
-
},
|
|
66
|
-
migration: [
|
|
67
|
-
{ step: 'Create src/lib/format/duration.ts with the 3-style API', linesToAdd: 30 },
|
|
68
|
-
{ step: 'Update Timer.tsx to call formatDuration(ms, {style:"compact"})', linesToChange: 2 },
|
|
69
|
-
{ step: 'Update utils.ts to call formatDuration(ms, {style:"full"})', linesToChange: 2 },
|
|
70
|
-
{ step: 'Update Settings.tsx to call formatDuration(ms, {style:"minimal"})', linesToChange: 2 },
|
|
71
|
-
],
|
|
72
|
-
benefits: ['Single source of truth for duration formatting', 'Easy to add new styles (e.g. ISO 8601)', 'Tests in one place'],
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
],
|
|
76
|
-
outputSchema: '{ duplication: { callSites: Array<{ file: string; function: string; line: number }>; differences: string[] }; proposedModule: { path: string; api: string; variants: Array<{ style: string; example: string }> }; migration: Array<{ step: string; linesToChange: number }>; benefits: string[] }',
|
|
77
|
-
systemPromptFragment: `You are finding duplicated logic and extracting a reusable module.
|
|
78
|
-
|
|
79
|
-
## Methodology
|
|
80
|
-
1. Use grep/semantic search to find candidate duplication (3+ similar implementations).
|
|
81
|
-
2. Read each call site to understand the VARIATIONS (not just the common pattern).
|
|
82
|
-
3. Design an API that accommodates ALL variations (use options pattern, not multiple functions).
|
|
83
|
-
4. Specify the new module path + function signature + behavior table.
|
|
84
|
-
5. List migration steps: which file + which lines change to use the new module.
|
|
85
|
-
|
|
86
|
-
## Extraction principles
|
|
87
|
-
- **Variations via options, not forks**: prefer formatDuration(ms, opts) over formatDurationCompact()/Full()
|
|
88
|
-
- **Pure functions**: extracted modules should have no hidden state, no I/O
|
|
89
|
-
- **Tests first**: write the test suite for the new module BEFORE migrating call sites
|
|
90
|
-
- **Single responsibility**: extracted module does ONE thing well
|
|
91
|
-
|
|
92
|
-
## Output format (JSON-typed)
|
|
93
|
-
- duplication: { callSites: [{file, function, line}], differences[] }
|
|
94
|
-
- proposedModule: { path, api (TS signature), variants: [{style, example}] }
|
|
95
|
-
- migration: [{step, linesToChange}]
|
|
96
|
-
- benefits: string[] (3-5 bullet points)
|
|
97
|
-
|
|
98
|
-
Stay under 500 words.${CLARIFICATION_PROTOCOL}`,
|
|
99
|
-
};
|
|
100
|
-
const simplifyConditionals = {
|
|
101
|
-
id: 'simplify-conditionals',
|
|
102
|
-
version: '1.0.0',
|
|
103
|
-
name: 'Simplify Conditionals',
|
|
104
|
-
description: 'Reduce cyclomatic complexity of boolean/conditional code. Extract guard clauses, replace nested if-else with lookup tables, simplify boolean expressions using De Morgan\'s laws.',
|
|
105
|
-
category: 'refactor',
|
|
106
|
-
requiredRoles: ['atlas'],
|
|
107
|
-
requiredTools: [],
|
|
108
|
-
estimatedCost: 'low',
|
|
109
|
-
enabledByDefault: true,
|
|
110
|
-
builtin: true,
|
|
111
|
-
triggers: [
|
|
112
|
-
'Cyclomatic complexity > 10 in a single function',
|
|
113
|
-
'Nested if-else > 3 levels deep',
|
|
114
|
-
'Boolean expressions with > 4 terms',
|
|
115
|
-
'Multiple early returns that could be guard clauses',
|
|
116
|
-
'Switch statements with > 8 cases that share structure',
|
|
117
|
-
],
|
|
118
|
-
antiPatterns: [
|
|
119
|
-
'Performance-critical branches (compiler will optimize nested ifs better than lookups)',
|
|
120
|
-
'Complex domain logic that IS the conditional structure (e.g. tax brackets)',
|
|
121
|
-
'Code under active development where the structure is still in flux',
|
|
122
|
-
],
|
|
123
|
-
requires: [],
|
|
124
|
-
relatedSkills: ['extract-reusable', 'refactor-monolith'],
|
|
125
|
-
tags: ['refactor', 'simplification', 'cyclomatic-complexity', 'clean-code'],
|
|
126
|
-
examples: [
|
|
127
|
-
{
|
|
128
|
-
input: 'function canUserEdit(user, doc) { if (user.isAdmin) { return true; } else { if (doc.ownerId === user.id) { return true; } else { if (doc.collaborators.includes(user.id) && !doc.locked) { return true; } else { return false; } } } }',
|
|
129
|
-
output: {
|
|
130
|
-
before: { lines: 9, cyclomaticComplexity: 5 },
|
|
131
|
-
after: { lines: 6, cyclomaticComplexity: 1 },
|
|
132
|
-
refactored: `function canUserEdit(user, doc) {
|
|
133
|
-
if (user.isAdmin) return true;
|
|
134
|
-
if (doc.ownerId === user.id) return true;
|
|
135
|
-
if (doc.collaborators.includes(user.id) && !doc.locked) return true;
|
|
136
|
-
return false;
|
|
137
|
-
}`,
|
|
138
|
-
explanation: 'Extracted guard clauses (early returns). Eliminated 3 levels of nesting. Cyclomatic complexity dropped from 5 to 1. Logic preserved exactly.',
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
input: 'function getDiscount(tier) { if (tier === "bronze") return 0.05; else if (tier === "silver") return 0.10; else if (tier === "gold") return 0.15; else if (tier === "platinum") return 0.20; else return 0; }',
|
|
143
|
-
output: {
|
|
144
|
-
before: { lines: 7, cyclomaticComplexity: 5 },
|
|
145
|
-
after: { lines: 7, cyclomaticComplexity: 1 },
|
|
146
|
-
refactored: `const DISCOUNT_BY_TIER = { bronze: 0.05, silver: 0.10, gold: 0.15, platinum: 0.20 } as const;
|
|
147
|
-
function getDiscount(tier: DiscountTier): number {
|
|
148
|
-
return DISCOUNT_BY_TIER[tier] ?? 0;
|
|
149
|
-
}`,
|
|
150
|
-
explanation: 'Replaced if-else chain with const lookup table. Adding a new tier = one line in the table, no function edit. Type-safe via `as const`. Default 0 via nullish coalescing.',
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
outputSchema: '{ before: { lines: number; cyclomaticComplexity: number }; after: { lines: number; cyclomaticComplexity: number }; refactored: string; explanation: string }',
|
|
155
|
-
systemPromptFragment: `You are reducing the complexity of conditional code.
|
|
156
|
-
|
|
157
|
-
## Common patterns to apply
|
|
158
|
-
1. **Guard clauses**: replace \`if (cond) { ...big block... } else { return false; }\` with \`if (!cond) return false; ...big block...\`
|
|
159
|
-
2. **Lookup tables**: replace \`if/else if/else if/...\` chains with \`const TABLE = { ... } as const; return TABLE[key] ?? default\`
|
|
160
|
-
3. **Boolean simplification**: apply De Morgan's laws (\`!(A && B)\` → \`!A || !B\`), extract complex predicates into named booleans
|
|
161
|
-
4. **Polymorphism**: replace type-checking conditionals (\`if (type === 'A') ... else if (type === 'B') ...\`) with method dispatch
|
|
162
|
-
|
|
163
|
-
## Output format (JSON-typed)
|
|
164
|
-
- before: { lines, cyclomaticComplexity }
|
|
165
|
-
- after: { lines, cyclomaticComplexity }
|
|
166
|
-
- refactored: string (the new code)
|
|
167
|
-
- explanation: string (1-2 sentences on what changed and why)
|
|
168
|
-
|
|
169
|
-
## What NOT to do
|
|
170
|
-
- Don't change behavior — only structure
|
|
171
|
-
- Don't introduce new abstractions for one-off conditionals
|
|
172
|
-
- Don't sacrifice readability for fewer lines (e.g. overly clever ternary chains)
|
|
173
|
-
|
|
174
|
-
Stay under 400 words.${CLARIFICATION_PROTOCOL}`,
|
|
175
|
-
};
|
|
176
|
-
const refactorMonolith = {
|
|
177
|
-
id: 'refactor-monolith',
|
|
178
|
-
version: '1.0.0',
|
|
179
|
-
name: 'Refactor Monolith',
|
|
180
|
-
description: 'Multi-perspective decomposition of large files (>1000 LOC) into focused modules. Identifies natural responsibility boundaries, proposes a module map with line numbers, validates no circular deps, generates a per-phase migration plan.',
|
|
181
|
-
category: 'refactor',
|
|
182
|
-
requiredRoles: ['hephaestus', 'atlas', 'oracle'],
|
|
183
|
-
requiredTools: ['searchRAG', 'createTask'],
|
|
184
|
-
estimatedCost: 'high',
|
|
185
|
-
enabledByDefault: true,
|
|
186
|
-
builtin: true,
|
|
187
|
-
triggers: [
|
|
188
|
-
'Single file > 1000 LOC with mixed responsibilities',
|
|
189
|
-
'Cyclomatic complexity > 50 in a single function',
|
|
190
|
-
'Multiple unrelated imports (>15 distinct packages) in one file',
|
|
191
|
-
'Onboarding new devs is hard because no one file fits in their head',
|
|
192
|
-
'Build/test times are slow because one big file recompiles on every change',
|
|
193
|
-
],
|
|
194
|
-
antiPatterns: [
|
|
195
|
-
'File under 500 LOC — defer; not worth the migration cost',
|
|
196
|
-
'Truly cohesive file even if large (e.g. a state machine FSM)',
|
|
197
|
-
'Quick fix needed urgently — refactor first, fix second',
|
|
198
|
-
'No tests exist — write characterization tests first, refactor second',
|
|
199
|
-
],
|
|
200
|
-
requires: ['extract-reusable'],
|
|
201
|
-
relatedSkills: ['simplify-conditionals', 'architect-feature'],
|
|
202
|
-
tags: ['refactor', 'modularization', 'god-module', 'split', 'architecture'],
|
|
203
|
-
examples: [
|
|
204
|
-
{
|
|
205
|
-
input: 'src/Council.tsx is 1822 LOC with mixed concerns: chat rendering, tool dispatch, voice input, slash commands, file attachments',
|
|
206
|
-
output: {
|
|
207
|
-
currentState: {
|
|
208
|
-
file: 'src/Council.tsx',
|
|
209
|
-
totalLines: 1822,
|
|
210
|
-
responsibilities: ['chat render', 'tool dispatch', 'voice input', 'slash commands', 'file attachments', 'settings panel', 'token counter'],
|
|
211
|
-
},
|
|
212
|
-
proposedModules: [
|
|
213
|
-
{ name: 'ChatStream.tsx', responsibility: 'render assistant/user messages', estimatedLines: 350, dependsOn: ['useChatStream hook'] },
|
|
214
|
-
{ name: 'ToolDispatch.tsx', responsibility: 'show tool execution + results', estimatedLines: 280, dependsOn: ['brain/tool types'] },
|
|
215
|
-
{ name: 'VoiceInput.tsx', responsibility: 'microphone + transcription UI', estimatedLines: 150, dependsOn: ['useVoiceRecorder hook'] },
|
|
216
|
-
{ name: 'SlashCommands.tsx', responsibility: 'command palette + autocomplete', estimatedLines: 200, dependsOn: ['useSlashCommands hook'] },
|
|
217
|
-
{ name: 'useCouncil.ts (hook)', responsibility: 'state + council orchestration logic', estimatedLines: 400, dependsOn: [] },
|
|
218
|
-
],
|
|
219
|
-
migrationPhases: [
|
|
220
|
-
{ phase: 1, name: 'Extract useCouncil hook', exitCriterion: 'Council.tsx < 1500 LOC, all behavior unchanged, all tests pass', durationDays: 2 },
|
|
221
|
-
{ phase: 2, name: 'Extract ChatStream + ToolDispatch', exitCriterion: 'Council.tsx < 1000 LOC', durationDays: 3 },
|
|
222
|
-
{ phase: 3, name: 'Extract VoiceInput + SlashCommands', exitCriterion: 'Council.tsx < 500 LOC OR deleted entirely', durationDays: 2 },
|
|
223
|
-
],
|
|
224
|
-
risks: [
|
|
225
|
-
{ risk: 'Hidden circular imports between new modules', mitigation: 'Run `madge --circular src/` after each phase; CI fails on circular deps.' },
|
|
226
|
-
{ risk: 'Lost re-render optimization (inline JSX vs memoized components)', mitigation: 'Phase 1 establishes React.memo + useMemo conventions before extracting.' },
|
|
227
|
-
],
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
|
-
],
|
|
231
|
-
outputSchema: '{ currentState: { file: string; totalLines: number; responsibilities: string[] }; proposedModules: Array<{ name: string; responsibility: string; estimatedLines: number; dependsOn: string[] }>; migrationPhases: Array<{ phase: number; name: string; exitCriterion: string; durationDays: number }>; risks: Array<{ risk: string; mitigation: string }> }',
|
|
232
|
-
systemPromptFragment: `You are planning a multi-perspective decomposition of a large file.
|
|
233
|
-
|
|
234
|
-
## Methodology
|
|
235
|
-
1. Identify the file's CURRENT responsibilities (read the source if needed).
|
|
236
|
-
2. Search the KB for prior split decisions: searchRAG(query="<file-name-keyword>")
|
|
237
|
-
3. Propose 4-8 NEW modules, each with ONE clear responsibility.
|
|
238
|
-
4. Map existing functions/sections to new modules (with line numbers).
|
|
239
|
-
5. Validate NO circular dependencies between proposed modules.
|
|
240
|
-
6. Plan 3-5 migration phases, each independently shippable with all tests passing.
|
|
241
|
-
|
|
242
|
-
## Module split principles
|
|
243
|
-
- **One job per module**: if you can't describe a module's purpose in ONE sentence, split further
|
|
244
|
-
- **No circular deps**: A imports B, B imports C is fine; A imports B, B imports A is not
|
|
245
|
-
- **Stable abstractions**: the new module boundaries should match NATURAL responsibility seams (state vs UI vs I/O), not arbitrary line counts
|
|
246
|
-
- **Testability first**: each module should be unit-testable in isolation
|
|
247
|
-
|
|
248
|
-
## Output format (JSON-typed)
|
|
249
|
-
- currentState: { file, totalLines, responsibilities[] }
|
|
250
|
-
- proposedModules: Array<{ name, responsibility, estimatedLines, dependsOn[] }>
|
|
251
|
-
- migrationPhases: Array<{ phase, name, exitCriterion, durationDays }>
|
|
252
|
-
- risks: Array<{ risk, mitigation }>
|
|
253
|
-
|
|
254
|
-
Stay under 600 words. Be decisive about module boundaries — pick ONE natural split, don't present 3 equally valid options.${CLARIFICATION_PROTOCOL}`,
|
|
255
|
-
};
|
|
256
|
-
// Register all 3 skills at module load time in topological dependency order.
|
|
257
|
-
// Throws at startup if any \`requires\` cross-reference is invalid.
|
|
258
|
-
registerCodingSkill(extractReusable);
|
|
259
|
-
registerCodingSkill(simplifyConditionals);
|
|
260
|
-
registerCodingSkill(refactorMonolith);
|
|
261
|
-
//# sourceMappingURL=refactoring.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"refactoring.js","sourceRoot":"","sources":["../../../../src/agents/skills/builtin/refactoring.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;kFAamD,CAAC;AAEnF,MAAM,eAAe,GAA0B;IAC7C,EAAE,EAAE,kBAAkB;IAC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EAAE,CAAC,EAAE;oBACjH,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,oCAAoC,EAAE,aAAa,EAAE,2CAA2C,EAAE,YAAY,EAAE,CAAC,EAAE;iBACtI;gBACD,KAAK,EAAE;oBACL,EAAE,IAAI,EAAE,6CAA6C,EAAE,UAAU,EAAE,0EAA0E,EAAE;oBAC/I,EAAE,IAAI,EAAE,iEAAiE,EAAE,UAAU,EAAE,yEAAyE,EAAE;iBACnK;aACF;SACF;KACF;IACD,YAAY,EAAE,6VAA6V;IAC3W,oBAAoB,EAAE;;;;;;;;;;;;;;;;;;;;;;4HAsBoG,sBAAsB,EAAE;CACnJ,CAAC;AAEF,6EAA6E;AAC7E,oEAAoE;AACpE,mBAAmB,CAAC,eAAe,CAAC,CAAC;AACrC,mBAAmB,CAAC,oBAAoB,CAAC,CAAC;AAC1C,mBAAmB,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import * as skillsModule from '../../skills.js';
|
|
2
|
-
const CLARIFICATION_PROTOCOL = `
|
|
3
|
-
|
|
4
|
-
WHEN TO ASK THE USER (clarification):
|
|
5
|
-
If a single missing fact would materially change your output (target platform, scope, a binary design choice with significant trade-offs, a constraint you cannot safely assume), pause and ask the user by appending EXACTLY this block at the end of your message:
|
|
6
|
-
|
|
7
|
-
---QUESTION---
|
|
8
|
-
{ "question": "One focused question", "choices": ["Option A", "Option B", "Option C"], "context": "Why this matters" }
|
|
9
|
-
---END---
|
|
10
|
-
|
|
11
|
-
Rules for clarifications:
|
|
12
|
-
- Ask AT MOST ONE question per turn, and only when genuinely blocked.
|
|
13
|
-
- Prefer a small set of concrete "choices" (2-4). The user can still type a wave-in response.
|
|
14
|
-
- Do NOT ask for information that could be reasonably assumed or already in shared context.
|
|
15
|
-
- If you can proceed with a sound documented assumption, DO SO instead of asking.`;
|
|
16
|
-
const securityAudit = {
|
|
17
|
-
id: 'security-audit',
|
|
18
|
-
version: '1.0.0',
|
|
19
|
-
name: 'Security Audit',
|
|
20
|
-
description: 'OWASP Top 10 + CVE check on dependencies + secrets scan. Identifies injection vectors, auth flaws, unsafe deserialization, hardcoded credentials.',
|
|
21
|
-
category: 'review',
|
|
22
|
-
requiredRoles: ['oracle'],
|
|
23
|
-
requiredTools: ['grep_content', 'read_file'],
|
|
24
|
-
estimatedCost: 'medium',
|
|
25
|
-
enabledByDefault: true,
|
|
26
|
-
builtin: true,
|
|
27
|
-
triggers: [
|
|
28
|
-
'Any code touching auth, session, password, token, or credential storage',
|
|
29
|
-
'Pre-release audit of the codebase',
|
|
30
|
-
'After a security incident or CVE disclosure',
|
|
31
|
-
'Quarterly compliance check',
|
|
32
|
-
'Integrating a new third-party npm dependency that handles user data',
|
|
33
|
-
],
|
|
34
|
-
antiPatterns: [
|
|
35
|
-
'Pure UI code with no I/O — defer to code-review skill',
|
|
36
|
-
'A unit test file — no production risk',
|
|
37
|
-
'Mock/seed data — those credentials are intentionally fake',
|
|
38
|
-
],
|
|
39
|
-
requires: [],
|
|
40
|
-
relatedSkills: ['code-review'],
|
|
41
|
-
tags: ['security', 'owasp', 'audit', 'cve', 'secrets', 'compliance'],
|
|
42
|
-
examples: [
|
|
43
|
-
{
|
|
44
|
-
input: 'Audit src/auth/ directory for security issues',
|
|
45
|
-
output: {
|
|
46
|
-
owaspFindings: [
|
|
47
|
-
{ category: 'A01:2021 Broken Access Control', severity: 'HIGH', file: 'src/auth/middleware.ts:34', issue: 'Missing role check on /admin/* routes — any authenticated user can access admin endpoints' },
|
|
48
|
-
{ category: 'A02:2021 Cryptographic Failures', severity: 'CRITICAL', file: 'src/auth/token.ts:12', issue: 'Tokens stored with SHA-256(password) instead of bcrypt/argon2 — vulnerable to rainbow tables' },
|
|
49
|
-
{ category: 'A03:2021 Injection', severity: 'MEDIUM', file: 'src/auth/login.ts:45', issue: 'Email field not validated; potential XSS if rendered unsafed downstream' },
|
|
50
|
-
],
|
|
51
|
-
cveCheck: 'npm audit: 3 vulnerabilities (1 high, 2 moderate) in jsonwebtoken@8.5.1 (CVE-2022-23529) — upgrade to 9.0.0+',
|
|
52
|
-
secretsScan: 'No hardcoded API keys found in src/. .env files are gitignored.',
|
|
53
|
-
priorityOrder: [
|
|
54
|
-
'1. Fix SHA-256 → bcrypt (CRITICAL)',
|
|
55
|
-
'2. Add role check middleware (HIGH)',
|
|
56
|
-
'3. Upgrade jsonwebtoken (CVE)',
|
|
57
|
-
'4. Add email validation (MEDIUM)',
|
|
58
|
-
],
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
outputSchema: '{ owaspFindings: Array<{ category: string; severity: string; file: string; line: number; issue: string }>; cveCheck: string; secretsScan: string; priorityOrder: string[] }',
|
|
63
|
-
systemPromptFragment: `You are auditing the codebase for security vulnerabilities.
|
|
64
|
-
|
|
65
|
-
## OWASP Top 10 (2021) — check each
|
|
66
|
-
1. **A01 Broken Access Control**: missing role checks, IDOR vulnerabilities
|
|
67
|
-
2. **A02 Cryptographic Failures**: weak hashing (MD5/SHA-1/SHA-256 for passwords), missing TLS
|
|
68
|
-
3. **A03 Injection**: SQL injection, command injection, XSS (especially via unsafe dangerouslySetInnerHTML)
|
|
69
|
-
4. **A04 Insecure Design**: missing rate limiting on auth endpoints
|
|
70
|
-
5. **A05 Security Misconfiguration**: default credentials, exposed debug endpoints
|
|
71
|
-
6. **A06 Vulnerable Components**: outdated dependencies with known CVEs (run npm audit)
|
|
72
|
-
7. **A07 Identification & Auth Failures**: missing MFA, weak password policies
|
|
73
|
-
8. **A08 Software & Data Integrity Failures**: missing signature verification on updates
|
|
74
|
-
9. **A09 Logging & Monitoring Failures**: no audit log on sensitive operations
|
|
75
|
-
10. **A10 SSRF**: user-controlled URLs fetched server-side without allowlist
|
|
76
|
-
|
|
77
|
-
## CVE check
|
|
78
|
-
- Run npm audit (or pip-audit, cargo audit, etc. depending on the stack)
|
|
79
|
-
- Cross-reference with the GitHub Advisory Database
|
|
80
|
-
|
|
81
|
-
## Secrets scan
|
|
82
|
-
- grep for common patterns: API_KEY, SECRET, TOKEN, PASSWORD, BEGIN PRIVATE KEY
|
|
83
|
-
- Check .env files are gitignored
|
|
84
|
-
|
|
85
|
-
## Output format (JSON-typed)
|
|
86
|
-
- owaspFindings: Array<{ category, severity, file, line, issue }>
|
|
87
|
-
- cveCheck: string (results of dependency scan)
|
|
88
|
-
- secretsScan: string (results of hardcoded secrets scan)
|
|
89
|
-
- priorityOrder: string[] (numbered list, CRITICAL first)
|
|
90
|
-
|
|
91
|
-
Stay under 500 words.${CLARIFICATION_PROTOCOL}`,
|
|
92
|
-
};
|
|
93
|
-
const performanceReview = {
|
|
94
|
-
id: 'performance-review',
|
|
95
|
-
version: '1.0.0',
|
|
96
|
-
name: 'Performance Review',
|
|
97
|
-
description: 'Identify algorithmic complexity issues (O(n²), O(n³)), N+1 queries, unnecessary allocations, missing caching opportunities, I/O blocking patterns.',
|
|
98
|
-
category: 'review',
|
|
99
|
-
requiredRoles: ['atlas'],
|
|
100
|
-
requiredTools: ['read_file', 'grep_content'],
|
|
101
|
-
estimatedCost: 'medium',
|
|
102
|
-
enabledByDefault: true,
|
|
103
|
-
builtin: true,
|
|
104
|
-
triggers: [
|
|
105
|
-
'Performance regression report from users',
|
|
106
|
-
'Response time > 1s where it used to be < 100ms',
|
|
107
|
-
'CPU profiling shows a hot function',
|
|
108
|
-
'Memory growth over time (potential leak)',
|
|
109
|
-
'Database query log shows slow queries',
|
|
110
|
-
],
|
|
111
|
-
antiPatterns: [
|
|
112
|
-
'UI-only code with no I/O or loops — defer',
|
|
113
|
-
'Code that handles < 100 items (premature optimization)',
|
|
114
|
-
'One-time scripts — performance rarely matters',
|
|
115
|
-
],
|
|
116
|
-
requires: [],
|
|
117
|
-
relatedSkills: ['code-review'],
|
|
118
|
-
tags: ['performance', 'optimization', 'big-o', 'caching', 'memory', 'profiling'],
|
|
119
|
-
examples: [
|
|
120
|
-
{
|
|
121
|
-
input: 'Review src/lib/search.ts (filters 10,000 documents)',
|
|
122
|
-
output: {
|
|
123
|
-
findings: [
|
|
124
|
-
{ type: 'N+1 query', severity: 'HIGH', file: 'src/lib/search.ts:34', issue: 'For each of 10,000 docs, fires a separate DB query to fetch tags. Total: 10,001 queries per search.', fix: 'Use a single JOIN query to fetch all tags upfront. Reduces to 1 query.' },
|
|
125
|
-
{ type: 'Allocation in hot loop', severity: 'MEDIUM', file: 'src/lib/search.ts:67', issue: 'Creates a new Date object inside the filter loop (10,000 allocations per search).', fix: 'Hoist the comparison date outside the loop.' },
|
|
126
|
-
{ type: 'Missing index', severity: 'MEDIUM', file: 'src/lib/search.ts:45', issue: 'SQL query filters by `created_at` but the table has no index on that column. Full table scan on every search.', fix: 'CREATE INDEX idx_documents_created_at ON documents(created_at);' },
|
|
127
|
-
{ type: 'Caching opportunity', severity: 'LOW', file: 'src/lib/search.ts:89', issue: 'Results identical for the same query within 60s window; no caching layer.', fix: 'Add LRU cache keyed on query hash, TTL 60s.' },
|
|
128
|
-
],
|
|
129
|
-
bigO: 'O(n) becomes O(1) with the JOIN fix + O(1) with the cache',
|
|
130
|
-
expectedSpeedup: '10-100x for typical queries',
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
],
|
|
134
|
-
outputSchema: '{ findings: Array<{ type: string; severity: string; file: string; line: number; issue: string; fix: string }>; bigO: string; expectedSpeedup: string }',
|
|
135
|
-
systemPromptFragment: `You are reviewing code for performance issues.
|
|
136
|
-
|
|
137
|
-
## Common patterns to detect
|
|
138
|
-
1. **N+1 queries**: loop with a DB call inside (fetch all data upfront with a JOIN)
|
|
139
|
-
2. **Allocation in hot loops**: \`new SomeClass()\` inside \`for (...)\` (hoist outside)
|
|
140
|
-
3. **Missing index**: SQL filter on unindexed column (add index, EXPLAIN ANALYZE)
|
|
141
|
-
4. **No caching**: identical computation repeated (LRU cache, memoize)
|
|
142
|
-
5. **Blocking I/O in async**: \`await fs.readFileSync(...)\` (use async readFile)
|
|
143
|
-
6. **Quadratic loops**: nested loops over the same array (use hash map for O(n) lookup)
|
|
144
|
-
7. **Synchronous XHR/fetch**: blocking the main thread (use async/await or worker)
|
|
145
|
-
|
|
146
|
-
## Output format (JSON-typed)
|
|
147
|
-
- findings: Array<{ type, severity, file, line, issue, fix }>
|
|
148
|
-
- bigO: string (the complexity change after fixes)
|
|
149
|
-
- expectedSpeedup: string (estimated speedup magnitude)
|
|
150
|
-
|
|
151
|
-
## Anti-patterns to avoid
|
|
152
|
-
- **Don't propose premature optimizations** (caching for a function called once)
|
|
153
|
-
- **Don't change behavior for performance** unless explicitly asked
|
|
154
|
-
- **Profile first** — don't guess where the hot path is
|
|
155
|
-
|
|
156
|
-
Stay under 500 words.${CLARIFICATION_PROTOCOL}`,
|
|
157
|
-
};
|
|
158
|
-
const testCoverageAnalysis = {
|
|
159
|
-
id: 'test-coverage-analysis',
|
|
160
|
-
version: '1.0.0',
|
|
161
|
-
name: 'Test Coverage Analysis',
|
|
162
|
-
description: 'Identify untested code branches. Suggest specific test cases that would close the coverage gap, prioritizing edge cases and error paths.',
|
|
163
|
-
category: 'review',
|
|
164
|
-
requiredRoles: ['oracle', 'atlas'],
|
|
165
|
-
requiredTools: ['read_file'],
|
|
166
|
-
estimatedCost: 'medium',
|
|
167
|
-
enabledByDefault: true,
|
|
168
|
-
builtin: true,
|
|
169
|
-
triggers: [
|
|
170
|
-
'Coverage report shows < 80% line coverage',
|
|
171
|
-
'A new feature was added without tests',
|
|
172
|
-
'A bug was found that should have been caught by tests',
|
|
173
|
-
'Quarterly coverage audit',
|
|
174
|
-
'Refactoring a high-churn module where regression risk is high',
|
|
175
|
-
],
|
|
176
|
-
antiPatterns: [
|
|
177
|
-
'Tests exist but are tautologies (assertions that always pass)',
|
|
178
|
-
'Coverage targets > 95% (often forces meaningless tests)',
|
|
179
|
-
'Auto-generated code (skip — the generator has its own tests)',
|
|
180
|
-
],
|
|
181
|
-
requires: [],
|
|
182
|
-
relatedSkills: ['code-review'],
|
|
183
|
-
tags: ['review', 'testing', 'coverage', 'edge-cases'],
|
|
184
|
-
examples: [
|
|
185
|
-
{
|
|
186
|
-
input: 'src/lib/formatDuration.ts has 6 branches; coverage report shows only 3 are tested',
|
|
187
|
-
output: {
|
|
188
|
-
untestedBranches: [
|
|
189
|
-
{ branch: 'ms < 0 (negative duration)', file: 'src/lib/formatDuration.ts:12', suggestedTest: "expect(formatDuration(-1000)).toThrow('Negative duration')" },
|
|
190
|
-
{ branch: 'ms === 0', file: 'src/lib/formatDuration.ts:14', suggestedTest: "expect(formatDuration(0)).toBe('0s')" },
|
|
191
|
-
{ branch: 'ms > 1 day (very large)', file: 'src/lib/formatDuration.ts:22', suggestedTest: "expect(formatDuration(86400000 * 2)).toBe('2d')" },
|
|
192
|
-
],
|
|
193
|
-
edgeCases: [
|
|
194
|
-
'ms is NaN (e.g. from a corrupt timestamp) — should throw',
|
|
195
|
-
'ms is Infinity (e.g. from setTimeout overflow) — should cap at a max',
|
|
196
|
-
'style option is invalid — should default to "compact"',
|
|
197
|
-
],
|
|
198
|
-
priorityOrder: ['1. NaN/Infinity handling (data integrity)', '2. ms === 0 boundary (off-by-one)', '3. style validation (UX)'],
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
outputSchema: '{ untestedBranches: Array<{ branch: string; file: string; line: number; suggestedTest: string }>; edgeCases: string[]; priorityOrder: string[] }',
|
|
203
|
-
systemPromptFragment: `You are identifying untested code branches.
|
|
204
|
-
|
|
205
|
-
## Methodology
|
|
206
|
-
1. **Read each branch** in the source file (if/else, switch cases, try/catch).
|
|
207
|
-
2. **Identify untested branches** by reading the corresponding test file.
|
|
208
|
-
3. **Suggest a SPECIFIC test** (not "add a test for X" — write the actual assertion).
|
|
209
|
-
4. **Prioritize edge cases**: NaN, null, undefined, empty array, max int, negative numbers.
|
|
210
|
-
5. **Prioritize error paths**: what happens when validation fails, network drops, etc.?
|
|
211
|
-
|
|
212
|
-
## Output format (JSON-typed)
|
|
213
|
-
- untestedBranches: Array<{ branch, file, line, suggestedTest }>
|
|
214
|
-
- edgeCases: string[] (3-7 cases)
|
|
215
|
-
- priorityOrder: string[] (numbered list)
|
|
216
|
-
|
|
217
|
-
## Test quality principles
|
|
218
|
-
- **One assertion per test** — easier to debug
|
|
219
|
-
- **Specific assertion** — not \`expect(result).toBeTruthy()\` but \`expect(result).toBe('1h 23m')\`
|
|
220
|
-
- **Test the boundary** — \`n=0\`, \`n=1\`, \`n=MAX_INT\`
|
|
221
|
-
- **Test the failure path** — invalid input, network errors, partial data
|
|
222
|
-
|
|
223
|
-
Stay under 400 words.${CLARIFICATION_PROTOCOL}`,
|
|
224
|
-
};
|
|
225
|
-
const codeReview = {
|
|
226
|
-
id: 'code-review',
|
|
227
|
-
version: '1.0.0',
|
|
228
|
-
name: 'Code Review',
|
|
229
|
-
description: 'Multi-role review covering correctness, style, performance, security, and accessibility. Each role emits findings with severity (CRITICAL/HIGH/MEDIUM/LOW). Chairman synthesizes consensus.',
|
|
230
|
-
category: 'review',
|
|
231
|
-
requiredRoles: ['oracle', 'atlas', 'chairman'],
|
|
232
|
-
requiredTools: ['read_file', 'grep_content', 'searchRAG'],
|
|
233
|
-
estimatedCost: 'high',
|
|
234
|
-
enabledByDefault: true,
|
|
235
|
-
builtin: true,
|
|
236
|
-
triggers: [
|
|
237
|
-
'A pull request is ready for review',
|
|
238
|
-
'A code change affects > 100 lines',
|
|
239
|
-
'Code touches auth, payments, or other security-critical paths',
|
|
240
|
-
'Before merging to main',
|
|
241
|
-
'A pre-merge sanity check on critical files',
|
|
242
|
-
],
|
|
243
|
-
antiPatterns: [
|
|
244
|
-
'Single-line change (typo, comment fix) — direct merge',
|
|
245
|
-
'Trivial style fix (whitespace, import order) — direct merge',
|
|
246
|
-
'WIP / draft PR — review when ready',
|
|
247
|
-
'Generated code (e.g. codegen output) — review the upstream generator instead',
|
|
248
|
-
],
|
|
249
|
-
requires: ['security-audit', 'performance-review', 'test-coverage-analysis'],
|
|
250
|
-
relatedSkills: ['security-audit', 'performance-review', 'test-coverage-analysis'],
|
|
251
|
-
tags: ['review', 'multi-role', 'pr-review', 'correctness', 'security'],
|
|
252
|
-
examples: [
|
|
253
|
-
{
|
|
254
|
-
input: 'Review src/components/AuthForm.tsx (180 LOC) — adds passwordless email login',
|
|
255
|
-
output: {
|
|
256
|
-
findings: [
|
|
257
|
-
{ role: 'oracle', severity: 'CRITICAL', line: 67, issue: 'No CSRF token on the form submit', file: 'src/components/AuthForm.tsx' },
|
|
258
|
-
{ role: 'atlas', severity: 'HIGH', line: 23, issue: 'N+1 query: user lookup fires on every keystroke instead of debounced', file: 'src/components/AuthForm.tsx' },
|
|
259
|
-
{ role: 'oracle', severity: 'MEDIUM', line: 102, issue: 'Error message leaks server response body (XSS risk)', file: 'src/components/AuthForm.tsx' },
|
|
260
|
-
{ role: 'chairman', severity: 'LOW', line: 45, issue: 'Variable name `usrEml` should be `userEmail` (style)', file: 'src/components/AuthForm.tsx' },
|
|
261
|
-
],
|
|
262
|
-
consensus: '2 CRITICAL/HIGH blockers must be fixed before merge. CSRF is the most critical. After CSRF fix, N+1 query, then error message.',
|
|
263
|
-
mergeVerdict: 'BLOCK',
|
|
264
|
-
},
|
|
265
|
-
},
|
|
266
|
-
],
|
|
267
|
-
outputSchema: '{ findings: Array<{ role: string; severity: "CRITICAL" | "HIGH" | "MEDIUM" | "LOW"; line: number; issue: string; file: string }>; consensus: string; mergeVerdict: "APPROVE" | "REQUEST_CHANGES" | "BLOCK" }',
|
|
268
|
-
systemPromptFragment: `You are conducting a multi-role code review.
|
|
269
|
-
|
|
270
|
-
## Review roles
|
|
271
|
-
- **oracle (correctness)**: bugs, race conditions, edge cases, error handling
|
|
272
|
-
- **atlas (performance)**: O(n²) algorithms, N+1 queries, unnecessary allocations, missing caching
|
|
273
|
-
- **oracle (security)**: injection, auth bypass, secrets in code, unsafe deserialization (overlaps with security-audit skill — run that first)
|
|
274
|
-
- **atlas (accessibility)**: ARIA labels, keyboard nav, color contrast
|
|
275
|
-
- **chairman (synthesis)**: aggregates all findings, emits verdict (APPROVE / REQUEST_CHANGES / BLOCK)
|
|
276
|
-
|
|
277
|
-
## Severity levels
|
|
278
|
-
- **CRITICAL**: must fix before merge (security, data loss, crash)
|
|
279
|
-
- **HIGH**: should fix before merge (correctness bug, performance regression)
|
|
280
|
-
- **MEDIUM**: nice to fix (code smell, minor perf)
|
|
281
|
-
- **LOW**: nitpick (style, naming)
|
|
282
|
-
|
|
283
|
-
## Output format (JSON-typed)
|
|
284
|
-
- findings: Array<{ role, severity, line, issue, file }>
|
|
285
|
-
- consensus: string (chairman's synthesis)
|
|
286
|
-
- mergeVerdict: 'APPROVE' | 'REQUEST_CHANGES' | 'BLOCK'
|
|
287
|
-
|
|
288
|
-
## Review principles
|
|
289
|
-
- **Be specific**: cite file + line numbers
|
|
290
|
-
- **Be actionable**: each finding has a concrete fix
|
|
291
|
-
- **Don't bikeshed style** — note as LOW or skip
|
|
292
|
-
- **Trust the author** — don't require changes that are preference, not correctness
|
|
293
|
-
|
|
294
|
-
Stay under 600 words.${CLARIFICATION_PROTOCOL}`,
|
|
295
|
-
};
|
|
296
|
-
// prettier-ignore
|
|
297
|
-
const registerCodingSkill = skillsModule['register' + 'Coding' + 'Skill'];
|
|
298
|
-
registerCodingSkill(securityAudit);
|
|
299
|
-
registerCodingSkill(performanceReview);
|
|
300
|
-
registerCodingSkill(testCoverageAnalysis);
|
|
301
|
-
registerCodingSkill(codeReview);
|
|
302
|
-
//# sourceMappingURL=review.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"review.js","sourceRoot":"","sources":["../../../../src/agents/skills/builtin/review.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,YAAY,MAAM,iBAAiB,CAAC;AAEhD,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;kFAamD,CAAC;AAEnF,MAAM,aAAa,GAA0B;IAC3C,EAAE,EAAE,gBAAgB;IACpB,OAAO,EAAE,OAAO;IAChB,IAAI,E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