compact-agent 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +394 -0
- package/bin/anycode.js +2 -0
- package/bin/crowcoder.js +19 -0
- package/bin/ecc-hooks.cjs +138 -0
- package/dist/agents.d.ts +17 -0
- package/dist/agents.js +1603 -0
- package/dist/agents.js.map +1 -0
- package/dist/api.d.ts +16 -0
- package/dist/api.js +115 -0
- package/dist/api.js.map +1 -0
- package/dist/autonomous-loops.d.ts +108 -0
- package/dist/autonomous-loops.js +526 -0
- package/dist/autonomous-loops.js.map +1 -0
- package/dist/codemaps.d.ts +53 -0
- package/dist/codemaps.js +325 -0
- package/dist/codemaps.js.map +1 -0
- package/dist/compaction.d.ts +30 -0
- package/dist/compaction.js +125 -0
- package/dist/compaction.js.map +1 -0
- package/dist/config.d.ts +5 -0
- package/dist/config.js +79 -0
- package/dist/config.js.map +1 -0
- package/dist/content-engine.d.ts +97 -0
- package/dist/content-engine.js +721 -0
- package/dist/content-engine.js.map +1 -0
- package/dist/cost-tracker.d.ts +49 -0
- package/dist/cost-tracker.js +150 -0
- package/dist/cost-tracker.js.map +1 -0
- package/dist/counter-button.d.ts +35 -0
- package/dist/counter-button.js +48 -0
- package/dist/counter-button.js.map +1 -0
- package/dist/counter.d.ts +21 -0
- package/dist/counter.js +31 -0
- package/dist/counter.js.map +1 -0
- package/dist/coverage.d.ts +23 -0
- package/dist/coverage.js +215 -0
- package/dist/coverage.js.map +1 -0
- package/dist/docs-sync.d.ts +23 -0
- package/dist/docs-sync.js +266 -0
- package/dist/docs-sync.js.map +1 -0
- package/dist/ecc.d.ts +41 -0
- package/dist/ecc.js +644 -0
- package/dist/ecc.js.map +1 -0
- package/dist/evaluation.d.ts +24 -0
- package/dist/evaluation.js +412 -0
- package/dist/evaluation.js.map +1 -0
- package/dist/export.d.ts +22 -0
- package/dist/export.js +109 -0
- package/dist/export.js.map +1 -0
- package/dist/git-workflow.d.ts +22 -0
- package/dist/git-workflow.js +197 -0
- package/dist/git-workflow.js.map +1 -0
- package/dist/hook-controls.d.ts +34 -0
- package/dist/hook-controls.js +90 -0
- package/dist/hook-controls.js.map +1 -0
- package/dist/hooks.d.ts +30 -0
- package/dist/hooks.js +130 -0
- package/dist/hooks.js.map +1 -0
- package/dist/html-parser.d.ts +18 -0
- package/dist/html-parser.js +101 -0
- package/dist/html-parser.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +1230 -0
- package/dist/index.js.map +1 -0
- package/dist/learning.d.ts +35 -0
- package/dist/learning.js +238 -0
- package/dist/learning.js.map +1 -0
- package/dist/login.d.ts +37 -0
- package/dist/login.js +191 -0
- package/dist/login.js.map +1 -0
- package/dist/memory.d.ts +39 -0
- package/dist/memory.js +183 -0
- package/dist/memory.js.map +1 -0
- package/dist/model-router.d.ts +23 -0
- package/dist/model-router.js +145 -0
- package/dist/model-router.js.map +1 -0
- package/dist/modes.d.ts +17 -0
- package/dist/modes.js +217 -0
- package/dist/modes.js.map +1 -0
- package/dist/orchestration.d.ts +37 -0
- package/dist/orchestration.js +139 -0
- package/dist/orchestration.js.map +1 -0
- package/dist/package-detect.d.ts +36 -0
- package/dist/package-detect.js +529 -0
- package/dist/package-detect.js.map +1 -0
- package/dist/permissions.d.ts +25 -0
- package/dist/permissions.js +50 -0
- package/dist/permissions.js.map +1 -0
- package/dist/pm2-manager.d.ts +40 -0
- package/dist/pm2-manager.js +127 -0
- package/dist/pm2-manager.js.map +1 -0
- package/dist/query.d.ts +15 -0
- package/dist/query.js +278 -0
- package/dist/query.js.map +1 -0
- package/dist/refactor.d.ts +22 -0
- package/dist/refactor.js +226 -0
- package/dist/refactor.js.map +1 -0
- package/dist/retry.d.ts +20 -0
- package/dist/retry.js +88 -0
- package/dist/retry.js.map +1 -0
- package/dist/rules.d.ts +34 -0
- package/dist/rules.js +942 -0
- package/dist/rules.js.map +1 -0
- package/dist/schema.d.ts +23 -0
- package/dist/schema.js +12 -0
- package/dist/schema.js.map +1 -0
- package/dist/search-first.d.ts +17 -0
- package/dist/search-first.js +301 -0
- package/dist/search-first.js.map +1 -0
- package/dist/security.d.ts +10 -0
- package/dist/security.js +145 -0
- package/dist/security.js.map +1 -0
- package/dist/sessions.d.ts +21 -0
- package/dist/sessions.js +112 -0
- package/dist/sessions.js.map +1 -0
- package/dist/skill-create.d.ts +38 -0
- package/dist/skill-create.js +389 -0
- package/dist/skill-create.js.map +1 -0
- package/dist/skills.d.ts +34 -0
- package/dist/skills.js +161 -0
- package/dist/skills.js.map +1 -0
- package/dist/strategic-compaction.d.ts +24 -0
- package/dist/strategic-compaction.js +144 -0
- package/dist/strategic-compaction.js.map +1 -0
- package/dist/system-prompt.d.ts +3 -0
- package/dist/system-prompt.js +101 -0
- package/dist/system-prompt.js.map +1 -0
- package/dist/theme.d.ts +60 -0
- package/dist/theme.js +220 -0
- package/dist/theme.js.map +1 -0
- package/dist/tools/bash.d.ts +2 -0
- package/dist/tools/bash.js +49 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/edit.d.ts +2 -0
- package/dist/tools/edit.js +76 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/glob.d.ts +2 -0
- package/dist/tools/glob.js +54 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +2 -0
- package/dist/tools/grep.js +64 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.js +27 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/list-dir.d.ts +2 -0
- package/dist/tools/list-dir.js +51 -0
- package/dist/tools/list-dir.js.map +1 -0
- package/dist/tools/read.d.ts +2 -0
- package/dist/tools/read.js +56 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/types.d.ts +45 -0
- package/dist/tools/types.js +2 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +2 -0
- package/dist/tools/web-fetch.js +41 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +27 -0
- package/dist/tools/web-search.js +139 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/write.d.ts +2 -0
- package/dist/tools/write.js +36 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.js +57 -0
- package/dist/types.js.map +1 -0
- package/dist/users.d.ts +51 -0
- package/dist/users.js +193 -0
- package/dist/users.js.map +1 -0
- package/dist/verification.d.ts +73 -0
- package/dist/verification.js +269 -0
- package/dist/verification.js.map +1 -0
- package/dist/walkthrough.d.ts +10 -0
- package/dist/walkthrough.js +121 -0
- package/dist/walkthrough.js.map +1 -0
- package/package.json +58 -0
- package/resources/ecc/agents/architect.json +16 -0
- package/resources/ecc/agents/architect.md +212 -0
- package/resources/ecc/agents/build-error-resolver.json +17 -0
- package/resources/ecc/agents/build-error-resolver.md +116 -0
- package/resources/ecc/agents/chief-of-staff.json +17 -0
- package/resources/ecc/agents/chief-of-staff.md +153 -0
- package/resources/ecc/agents/code-reviewer.json +16 -0
- package/resources/ecc/agents/code-reviewer.md +238 -0
- package/resources/ecc/agents/database-reviewer.json +16 -0
- package/resources/ecc/agents/database-reviewer.md +92 -0
- package/resources/ecc/agents/doc-updater.json +16 -0
- package/resources/ecc/agents/doc-updater.md +108 -0
- package/resources/ecc/agents/e2e-runner.json +17 -0
- package/resources/ecc/agents/e2e-runner.md +109 -0
- package/resources/ecc/agents/go-build-resolver.json +17 -0
- package/resources/ecc/agents/go-build-resolver.md +96 -0
- package/resources/ecc/agents/go-reviewer.json +16 -0
- package/resources/ecc/agents/go-reviewer.md +77 -0
- package/resources/ecc/agents/harness-optimizer.json +15 -0
- package/resources/ecc/agents/harness-optimizer.md +34 -0
- package/resources/ecc/agents/loop-operator.json +16 -0
- package/resources/ecc/agents/loop-operator.md +36 -0
- package/resources/ecc/agents/planner.json +15 -0
- package/resources/ecc/agents/planner.md +212 -0
- package/resources/ecc/agents/python-reviewer.json +16 -0
- package/resources/ecc/agents/python-reviewer.md +99 -0
- package/resources/ecc/agents/refactor-cleaner.json +17 -0
- package/resources/ecc/agents/refactor-cleaner.md +87 -0
- package/resources/ecc/agents/security-reviewer.json +16 -0
- package/resources/ecc/agents/security-reviewer.md +109 -0
- package/resources/ecc/agents/tdd-guide.json +17 -0
- package/resources/ecc/agents/tdd-guide.md +93 -0
- package/resources/ecc/commands/add-language-rules.md +39 -0
- package/resources/ecc/commands/database-migration.md +36 -0
- package/resources/ecc/commands/feature-development.md +38 -0
- package/resources/ecc/prompts/build-fix.prompt.md +47 -0
- package/resources/ecc/prompts/code-review.prompt.md +56 -0
- package/resources/ecc/prompts/plan.prompt.md +52 -0
- package/resources/ecc/prompts/refactor.prompt.md +50 -0
- package/resources/ecc/prompts/security-review.prompt.md +70 -0
- package/resources/ecc/prompts/tdd.prompt.md +47 -0
- package/resources/ecc/rules/common-agents.md +53 -0
- package/resources/ecc/rules/common-coding-style.md +52 -0
- package/resources/ecc/rules/common-development-workflow.md +33 -0
- package/resources/ecc/rules/common-git-workflow.md +28 -0
- package/resources/ecc/rules/common-hooks.md +34 -0
- package/resources/ecc/rules/common-patterns.md +35 -0
- package/resources/ecc/rules/common-performance.md +59 -0
- package/resources/ecc/rules/common-security.md +33 -0
- package/resources/ecc/rules/common-testing.md +33 -0
- package/resources/ecc/rules/golang-coding-style.md +31 -0
- package/resources/ecc/rules/golang-hooks.md +16 -0
- package/resources/ecc/rules/golang-patterns.md +44 -0
- package/resources/ecc/rules/golang-security.md +33 -0
- package/resources/ecc/rules/golang-testing.md +30 -0
- package/resources/ecc/rules/kotlin-coding-style.md +39 -0
- package/resources/ecc/rules/kotlin-hooks.md +16 -0
- package/resources/ecc/rules/kotlin-patterns.md +50 -0
- package/resources/ecc/rules/kotlin-security.md +58 -0
- package/resources/ecc/rules/kotlin-testing.md +38 -0
- package/resources/ecc/rules/php-coding-style.md +25 -0
- package/resources/ecc/rules/php-hooks.md +21 -0
- package/resources/ecc/rules/php-patterns.md +23 -0
- package/resources/ecc/rules/php-security.md +24 -0
- package/resources/ecc/rules/php-testing.md +26 -0
- package/resources/ecc/rules/python-coding-style.md +42 -0
- package/resources/ecc/rules/python-hooks.md +19 -0
- package/resources/ecc/rules/python-patterns.md +39 -0
- package/resources/ecc/rules/python-security.md +30 -0
- package/resources/ecc/rules/python-testing.md +38 -0
- package/resources/ecc/rules/swift-coding-style.md +47 -0
- package/resources/ecc/rules/swift-hooks.md +20 -0
- package/resources/ecc/rules/swift-patterns.md +66 -0
- package/resources/ecc/rules/swift-security.md +33 -0
- package/resources/ecc/rules/swift-testing.md +45 -0
- package/resources/ecc/rules/typescript-coding-style.md +63 -0
- package/resources/ecc/rules/typescript-hooks.md +20 -0
- package/resources/ecc/rules/typescript-patterns.md +50 -0
- package/resources/ecc/rules/typescript-security.md +26 -0
- package/resources/ecc/rules/typescript-testing.md +16 -0
- package/resources/ecc/skills/agent-introspection-debugging/SKILL.md +152 -0
- package/resources/ecc/skills/agent-introspection-debugging/agents/openai.yaml +7 -0
- package/resources/ecc/skills/agent-sort/SKILL.md +214 -0
- package/resources/ecc/skills/agent-sort/agents/openai.yaml +7 -0
- package/resources/ecc/skills/api-design/SKILL.md +522 -0
- package/resources/ecc/skills/api-design/agents/openai.yaml +7 -0
- package/resources/ecc/skills/article-writing/SKILL.md +78 -0
- package/resources/ecc/skills/article-writing/agents/openai.yaml +7 -0
- package/resources/ecc/skills/backend-patterns/SKILL.md +597 -0
- package/resources/ecc/skills/backend-patterns/agents/openai.yaml +7 -0
- package/resources/ecc/skills/brand-voice/SKILL.md +96 -0
- package/resources/ecc/skills/brand-voice/agents/openai.yaml +7 -0
- package/resources/ecc/skills/brand-voice/references/voice-profile-schema.md +55 -0
- package/resources/ecc/skills/bun-runtime/SKILL.md +83 -0
- package/resources/ecc/skills/bun-runtime/agents/openai.yaml +7 -0
- package/resources/ecc/skills/coding-standards/SKILL.md +548 -0
- package/resources/ecc/skills/coding-standards/agents/openai.yaml +7 -0
- package/resources/ecc/skills/content-engine/SKILL.md +130 -0
- package/resources/ecc/skills/content-engine/agents/openai.yaml +7 -0
- package/resources/ecc/skills/crosspost/SKILL.md +110 -0
- package/resources/ecc/skills/crosspost/agents/openai.yaml +7 -0
- package/resources/ecc/skills/deep-research/SKILL.md +154 -0
- package/resources/ecc/skills/deep-research/agents/openai.yaml +7 -0
- package/resources/ecc/skills/dmux-workflows/SKILL.md +143 -0
- package/resources/ecc/skills/dmux-workflows/agents/openai.yaml +7 -0
- package/resources/ecc/skills/documentation-lookup/SKILL.md +89 -0
- package/resources/ecc/skills/documentation-lookup/agents/openai.yaml +7 -0
- package/resources/ecc/skills/e2e-testing/SKILL.md +325 -0
- package/resources/ecc/skills/e2e-testing/agents/openai.yaml +7 -0
- package/resources/ecc/skills/eval-harness/SKILL.md +235 -0
- package/resources/ecc/skills/eval-harness/agents/openai.yaml +7 -0
- package/resources/ecc/skills/everything-claude-code/SKILL.md +442 -0
- package/resources/ecc/skills/everything-claude-code/agents/openai.yaml +7 -0
- package/resources/ecc/skills/exa-search/SKILL.md +169 -0
- package/resources/ecc/skills/exa-search/agents/openai.yaml +7 -0
- package/resources/ecc/skills/fal-ai-media/SKILL.md +276 -0
- package/resources/ecc/skills/fal-ai-media/agents/openai.yaml +7 -0
- package/resources/ecc/skills/frontend-patterns/SKILL.md +647 -0
- package/resources/ecc/skills/frontend-patterns/agents/openai.yaml +7 -0
- package/resources/ecc/skills/frontend-slides/SKILL.md +183 -0
- package/resources/ecc/skills/frontend-slides/STYLE_PRESETS.md +330 -0
- package/resources/ecc/skills/frontend-slides/agents/openai.yaml +7 -0
- package/resources/ecc/skills/investor-materials/SKILL.md +95 -0
- package/resources/ecc/skills/investor-materials/agents/openai.yaml +7 -0
- package/resources/ecc/skills/investor-outreach/SKILL.md +90 -0
- package/resources/ecc/skills/investor-outreach/agents/openai.yaml +7 -0
- package/resources/ecc/skills/market-research/SKILL.md +74 -0
- package/resources/ecc/skills/market-research/agents/openai.yaml +7 -0
- package/resources/ecc/skills/mcp-server-patterns/SKILL.md +66 -0
- package/resources/ecc/skills/mcp-server-patterns/agents/openai.yaml +7 -0
- package/resources/ecc/skills/mle-workflow/SKILL.md +346 -0
- package/resources/ecc/skills/mle-workflow/agents/openai.yaml +7 -0
- package/resources/ecc/skills/nextjs-turbopack/SKILL.md +43 -0
- package/resources/ecc/skills/nextjs-turbopack/agents/openai.yaml +7 -0
- package/resources/ecc/skills/product-capability/SKILL.md +140 -0
- package/resources/ecc/skills/product-capability/agents/openai.yaml +7 -0
- package/resources/ecc/skills/security-review/SKILL.md +494 -0
- package/resources/ecc/skills/security-review/agents/openai.yaml +7 -0
- package/resources/ecc/skills/strategic-compact/SKILL.md +102 -0
- package/resources/ecc/skills/strategic-compact/agents/openai.yaml +7 -0
- package/resources/ecc/skills/tdd-workflow/SKILL.md +409 -0
- package/resources/ecc/skills/tdd-workflow/agents/openai.yaml +7 -0
- package/resources/ecc/skills/verification-loop/SKILL.md +125 -0
- package/resources/ecc/skills/verification-loop/agents/openai.yaml +7 -0
- package/resources/ecc/skills/video-editing/SKILL.md +307 -0
- package/resources/ecc/skills/video-editing/agents/openai.yaml +7 -0
- package/resources/ecc/skills/x-api/SKILL.md +229 -0
- package/resources/ecc/skills/x-api/agents/openai.yaml +7 -0
package/dist/agents.js
ADDED
|
@@ -0,0 +1,1603 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
// ── Language Detection ────────────────────────────────────
|
|
4
|
+
export function detectProjectLanguage(cwd) {
|
|
5
|
+
const fileExtMap = {
|
|
6
|
+
'.ts': 'typescript',
|
|
7
|
+
'.tsx': 'typescript',
|
|
8
|
+
'.js': 'typescript',
|
|
9
|
+
'.jsx': 'typescript',
|
|
10
|
+
'.py': 'python',
|
|
11
|
+
'.pyw': 'python',
|
|
12
|
+
'.go': 'go',
|
|
13
|
+
'.rs': 'rust',
|
|
14
|
+
'.java': 'java',
|
|
15
|
+
'.kt': 'kotlin',
|
|
16
|
+
'.kts': 'kotlin',
|
|
17
|
+
'.cpp': 'cpp',
|
|
18
|
+
'.cc': 'cpp',
|
|
19
|
+
'.cxx': 'cpp',
|
|
20
|
+
'.h': 'cpp',
|
|
21
|
+
'.hpp': 'cpp',
|
|
22
|
+
'.php': 'php',
|
|
23
|
+
'.sql': 'sql',
|
|
24
|
+
'.cs': 'csharp',
|
|
25
|
+
};
|
|
26
|
+
const configFileMap = {
|
|
27
|
+
'tsconfig.json': 'typescript',
|
|
28
|
+
'package.json': 'typescript',
|
|
29
|
+
'Cargo.toml': 'rust',
|
|
30
|
+
'go.mod': 'go',
|
|
31
|
+
'pyproject.toml': 'python',
|
|
32
|
+
'setup.py': 'python',
|
|
33
|
+
'requirements.txt': 'python',
|
|
34
|
+
'pom.xml': 'java',
|
|
35
|
+
'build.gradle': 'java',
|
|
36
|
+
'build.gradle.kts': 'kotlin',
|
|
37
|
+
'Gemfile': 'ruby',
|
|
38
|
+
'composer.json': 'php',
|
|
39
|
+
'CMakeLists.txt': 'cpp',
|
|
40
|
+
'Makefile': 'cpp',
|
|
41
|
+
'.csproj': 'csharp',
|
|
42
|
+
'.sln': 'csharp',
|
|
43
|
+
};
|
|
44
|
+
// Check config files first (highest priority)
|
|
45
|
+
for (const [file, lang] of Object.entries(configFileMap)) {
|
|
46
|
+
if (existsSync(join(cwd, file))) {
|
|
47
|
+
return lang;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
// Scan source files for extensions
|
|
51
|
+
const counts = {};
|
|
52
|
+
try {
|
|
53
|
+
const files = readdirSync(cwd, { recursive: true, withFileTypes: true });
|
|
54
|
+
for (const f of files) {
|
|
55
|
+
if (!f.isFile())
|
|
56
|
+
continue;
|
|
57
|
+
const name = f.name;
|
|
58
|
+
if (name.startsWith('.'))
|
|
59
|
+
continue;
|
|
60
|
+
const ext = name.slice(name.lastIndexOf('.'));
|
|
61
|
+
const lang = fileExtMap[ext];
|
|
62
|
+
if (lang)
|
|
63
|
+
counts[lang] = (counts[lang] || 0) + 1;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// can't read dir
|
|
68
|
+
}
|
|
69
|
+
// Return the most common language
|
|
70
|
+
if (Object.keys(counts).length > 0) {
|
|
71
|
+
return Object.entries(counts).sort(([, a], [, b]) => b - a)[0][0];
|
|
72
|
+
}
|
|
73
|
+
return 'typescript'; // default fallback
|
|
74
|
+
}
|
|
75
|
+
// ── TypeScript/JavaScript Review Agent ────────────────────
|
|
76
|
+
export function buildTSReviewPrompt(cwd, target) {
|
|
77
|
+
return `Perform a detailed TypeScript/JavaScript code review.
|
|
78
|
+
|
|
79
|
+
**Project Path**: ${cwd}
|
|
80
|
+
${target ? `**Target Files/Diff**: ${target}` : ''}
|
|
81
|
+
|
|
82
|
+
## Review Checklist
|
|
83
|
+
|
|
84
|
+
### Type Safety (CRITICAL severity)
|
|
85
|
+
- [ ] Strict mode enabled? Check tsconfig.json for "strict": true
|
|
86
|
+
- [ ] No \`any\` types — all parameters and returns have explicit types
|
|
87
|
+
- [ ] All function parameters typed, especially for external API calls
|
|
88
|
+
- [ ] Union types use discriminated unions, not implicit type narrowing
|
|
89
|
+
- [ ] No implicit \`any\` from \`Object\` or untyped spread
|
|
90
|
+
- [ ] Generic constraints are properly defined (e.g., \`T extends X\`)
|
|
91
|
+
|
|
92
|
+
### Null/Undefined Safety (HIGH severity)
|
|
93
|
+
- [ ] Use \`??\` (nullish coalescing) instead of \`||\` for defaults
|
|
94
|
+
- [ ] Use optional chaining (\`?.\`) for deep property access
|
|
95
|
+
- [ ] Non-null assertions (!) justified and documented
|
|
96
|
+
- [ ] Discriminated unions handle all branches explicitly
|
|
97
|
+
- [ ] No assumption that values exist — check guards present
|
|
98
|
+
- [ ] Consider \`Result<T, E>\` or \`Option<T>\` patterns for error cases
|
|
99
|
+
|
|
100
|
+
### Promise & Async Patterns (HIGH severity)
|
|
101
|
+
- [ ] No floating promises — all promises are awaited or explicitly .catch()
|
|
102
|
+
- [ ] Async functions declared explicitly, no implicit Promise returns
|
|
103
|
+
- [ ] Error handling in .catch() blocks or try-catch
|
|
104
|
+
- [ ] Race conditions handled when using Promise.all/race
|
|
105
|
+
- [ ] No \`void\` returns from async functions in callbacks
|
|
106
|
+
- [ ] Timeouts set for long-running async operations
|
|
107
|
+
|
|
108
|
+
### ESM Import Standards (MEDIUM severity)
|
|
109
|
+
- [ ] Use \`import/export\` (ESM), not \`require\` (CommonJS)
|
|
110
|
+
- [ ] Import order: Node built-ins, packages, then local files
|
|
111
|
+
- [ ] Named imports used where appropriate (not \`import *\`)
|
|
112
|
+
- [ ] No circular imports
|
|
113
|
+
- [ ] File extensions included in relative imports (.js/.ts)
|
|
114
|
+
|
|
115
|
+
### Code Quality (MEDIUM severity)
|
|
116
|
+
- [ ] Max function length ~50 lines — extract if larger
|
|
117
|
+
- [ ] Max file length ~300 lines — split if larger
|
|
118
|
+
- [ ] No console.log in production — use logger
|
|
119
|
+
- [ ] Avoid deeply nested conditionals — use early returns
|
|
120
|
+
- [ ] DRY: duplicated logic extracted to functions
|
|
121
|
+
- [ ] No magic numbers — use named constants
|
|
122
|
+
|
|
123
|
+
### Performance (MEDIUM severity)
|
|
124
|
+
- [ ] N+1 queries avoided in database loops
|
|
125
|
+
- [ ] Memoization used for expensive computations
|
|
126
|
+
- [ ] Event listeners cleaned up (removeEventListener)
|
|
127
|
+
- [ ] No memory leaks in subscriptions — unsubscribe on cleanup
|
|
128
|
+
- [ ] Reasonable algorithm complexity for datasets
|
|
129
|
+
- [ ] Large objects not held in memory unnecessarily
|
|
130
|
+
|
|
131
|
+
### Testing & Documentation (MEDIUM severity)
|
|
132
|
+
- [ ] Unit tests for critical functions exist
|
|
133
|
+
- [ ] Happy path and edge cases tested
|
|
134
|
+
- [ ] Public functions have JSDoc comments
|
|
135
|
+
- [ ] Complex logic has inline comments explaining "why"
|
|
136
|
+
- [ ] Error messages are helpful and actionable
|
|
137
|
+
|
|
138
|
+
### Common Antipatterns (NIT to HIGH severity)
|
|
139
|
+
- [ ] No \`==\` (use \`===\` always)
|
|
140
|
+
- [ ] No bare \`try-catch\` (catch all errors without handling)
|
|
141
|
+
- [ ] No mutable default arguments
|
|
142
|
+
- [ ] No reassignment of parameters
|
|
143
|
+
- [ ] No var declarations (use const/let)
|
|
144
|
+
- [ ] No hardcoded values in strings (config/constants)
|
|
145
|
+
|
|
146
|
+
## Output Format
|
|
147
|
+
|
|
148
|
+
For each issue found:
|
|
149
|
+
\`\`\`
|
|
150
|
+
[File:Line] SEVERITY — Issue Description
|
|
151
|
+
Why: Explain the problem
|
|
152
|
+
Fix: How to resolve it
|
|
153
|
+
Example: Show the corrected code
|
|
154
|
+
\`\`\`
|
|
155
|
+
|
|
156
|
+
End with summary:
|
|
157
|
+
- Total issues by severity (CRITICAL / HIGH / MEDIUM / LOW / NIT)
|
|
158
|
+
- Top 3 recommendations
|
|
159
|
+
- Overall verdict: APPROVE / REQUEST CHANGES / NEEDS DISCUSSION`;
|
|
160
|
+
}
|
|
161
|
+
// ── Python Review Agent ────────────────────────────────────
|
|
162
|
+
export function buildPyReviewPrompt(cwd, target) {
|
|
163
|
+
return `Perform a detailed Python code review following PEP 8 and modern best practices.
|
|
164
|
+
|
|
165
|
+
**Project Path**: ${cwd}
|
|
166
|
+
${target ? `**Target Files/Diff**: ${target}` : ''}
|
|
167
|
+
|
|
168
|
+
## Review Checklist
|
|
169
|
+
|
|
170
|
+
### Type Hints (CRITICAL severity)
|
|
171
|
+
- [ ] All function parameters have type hints
|
|
172
|
+
- [ ] All function return types annotated
|
|
173
|
+
- [ ] Class attributes typed (using typing annotations or PEP 526)
|
|
174
|
+
- [ ] Complex types use type aliases for clarity
|
|
175
|
+
- [ ] Type hints are checked with mypy (or pyright)
|
|
176
|
+
- [ ] No implicit \`Any\` types without justification
|
|
177
|
+
|
|
178
|
+
### PEP 8 Style (MEDIUM severity)
|
|
179
|
+
- [ ] 4-space indentation (not tabs)
|
|
180
|
+
- [ ] Line length ≤ 79 characters (100 for comments)
|
|
181
|
+
- [ ] CamelCase for classes, snake_case for functions/variables
|
|
182
|
+
- [ ] UPPER_SNAKE_CASE for constants
|
|
183
|
+
- [ ] No trailing whitespace
|
|
184
|
+
- [ ] Blank lines: 2 between top-level functions/classes, 1 between methods
|
|
185
|
+
|
|
186
|
+
### String & F-String Usage (MEDIUM severity)
|
|
187
|
+
- [ ] Use f-strings over .format() or % formatting
|
|
188
|
+
- [ ] No hardcoded strings in business logic (use constants/config)
|
|
189
|
+
- [ ] Docstrings use triple quotes and follow Google style
|
|
190
|
+
- [ ] Raw strings (r"...") for regex patterns
|
|
191
|
+
- [ ] No string concatenation in loops (use list + join)
|
|
192
|
+
|
|
193
|
+
### Async & Concurrency (HIGH severity)
|
|
194
|
+
- [ ] async/await used correctly (not mixing with threading carelessly)
|
|
195
|
+
- [ ] asyncio event loop managed properly
|
|
196
|
+
- [ ] No blocking I/O in async functions
|
|
197
|
+
- [ ] Timeout handling for async operations
|
|
198
|
+
- [ ] Concurrent tasks properly awaited (asyncio.gather)
|
|
199
|
+
- [ ] Thread safety considered if using threading/multiprocessing
|
|
200
|
+
|
|
201
|
+
### Exception Handling (HIGH severity)
|
|
202
|
+
- [ ] Specific exceptions caught (never bare \`except:\`)
|
|
203
|
+
- [ ] Finally blocks used for cleanup (or context managers)
|
|
204
|
+
- [ ] Custom exceptions defined where needed
|
|
205
|
+
- [ ] No silent swallowing of exceptions
|
|
206
|
+
- [ ] Exceptions logged with context before re-raising
|
|
207
|
+
- [ ] Context managers (with statement) for resource management
|
|
208
|
+
|
|
209
|
+
### Pathlib & File I/O (MEDIUM severity)
|
|
210
|
+
- [ ] Use \`pathlib.Path\` instead of \`os.path\`
|
|
211
|
+
- [ ] File operations use context managers (\`with open(...)\`)
|
|
212
|
+
- [ ] Encoding explicitly specified (utf-8)
|
|
213
|
+
- [ ] No hardcoded paths — use config/environment
|
|
214
|
+
- [ ] Existence checks before file operations
|
|
215
|
+
|
|
216
|
+
### Function & Code Quality (MEDIUM severity)
|
|
217
|
+
- [ ] Max function length ~30 lines — extract if larger
|
|
218
|
+
- [ ] Functions have single responsibility
|
|
219
|
+
- [ ] No more than 3-4 parameters (use dataclass if more)
|
|
220
|
+
- [ ] DRY: repeated logic extracted to functions
|
|
221
|
+
- [ ] Comprehensions readable (not overly nested)
|
|
222
|
+
- [ ] Generator expressions used for large datasets
|
|
223
|
+
|
|
224
|
+
### Data Structures & Best Practices (MEDIUM severity)
|
|
225
|
+
- [ ] Use dataclasses or Pydantic for structured data
|
|
226
|
+
- [ ] Prefer \`dict.get(key)\` over \`key in dict\` checks
|
|
227
|
+
- [ ] Use \`enumerate()\` instead of \`range(len())\`
|
|
228
|
+
- [ ] List/dict/set comprehensions preferred over loops
|
|
229
|
+
- [ ] No mutable default arguments (use None + factory pattern)
|
|
230
|
+
- [ ] Immutable sequences (tuples) for fixed data
|
|
231
|
+
|
|
232
|
+
### Testing & Documentation (MEDIUM severity)
|
|
233
|
+
- [ ] Docstrings on all public functions/classes
|
|
234
|
+
- [ ] Unit tests cover happy path and edge cases
|
|
235
|
+
- [ ] Test fixtures/factories for test data
|
|
236
|
+
- [ ] No \`print()\` statements in production (use logging)
|
|
237
|
+
- [ ] Logging configured with proper levels (DEBUG, INFO, WARNING, ERROR)
|
|
238
|
+
- [ ] README documents setup and usage
|
|
239
|
+
|
|
240
|
+
### Performance (MEDIUM severity)
|
|
241
|
+
- [ ] N+1 queries avoided (use select_related/prefetch_related for ORM)
|
|
242
|
+
- [ ] Large lists not loaded entirely when pagination possible
|
|
243
|
+
- [ ] Expensive operations not in loops
|
|
244
|
+
- [ ] Caching used for repeated calculations
|
|
245
|
+
- [ ] Algorithm complexity reasonable for dataset size
|
|
246
|
+
|
|
247
|
+
## Output Format
|
|
248
|
+
|
|
249
|
+
For each issue found:
|
|
250
|
+
\`\`\`
|
|
251
|
+
[File:Line] SEVERITY — Issue Description
|
|
252
|
+
Why: Explain the problem
|
|
253
|
+
Fix: How to resolve it
|
|
254
|
+
Example: Show corrected code
|
|
255
|
+
\`\`\`
|
|
256
|
+
|
|
257
|
+
End with summary:
|
|
258
|
+
- Issues by severity (CRITICAL / HIGH / MEDIUM / LOW / NIT)
|
|
259
|
+
- Top 3 recommendations
|
|
260
|
+
- Overall verdict: APPROVE / REQUEST CHANGES / NEEDS DISCUSSION`;
|
|
261
|
+
}
|
|
262
|
+
// ── Go Review Agent ───────────────────────────────────────
|
|
263
|
+
export function buildGoReviewPrompt(cwd, target) {
|
|
264
|
+
return `Perform a detailed Go code review following Effective Go and Go Proverbs.
|
|
265
|
+
|
|
266
|
+
**Project Path**: ${cwd}
|
|
267
|
+
${target ? `**Target Files/Diff**: ${target}` : ''}
|
|
268
|
+
|
|
269
|
+
## Review Checklist
|
|
270
|
+
|
|
271
|
+
### Error Handling (CRITICAL severity)
|
|
272
|
+
- [ ] All errors returned (no \`_ = err\` unless explicitly justified with comment)
|
|
273
|
+
- [ ] Errors wrapped with context (\`fmt.Errorf("doing X: %w", err)\`)
|
|
274
|
+
- [ ] Custom error types defined for domain errors
|
|
275
|
+
- [ ] No panic in libraries (only main/tests)
|
|
276
|
+
- [ ] Error handling is consistent across functions
|
|
277
|
+
- [ ] Error messages are helpful and actionable
|
|
278
|
+
|
|
279
|
+
### Interface & Struct Design (HIGH severity)
|
|
280
|
+
- [ ] Interfaces small (1-3 methods, defined where used)
|
|
281
|
+
- [ ] Receiver type correct (value vs pointer)
|
|
282
|
+
- [ ] No unnecessary interface satisfaction checks
|
|
283
|
+
- [ ] Struct embedding used for composition
|
|
284
|
+
- [ ] Public/private (exported/unexported) symbols consistent
|
|
285
|
+
- [ ] Methods on pointers when they modify receiver
|
|
286
|
+
|
|
287
|
+
### Context Usage (HIGH severity)
|
|
288
|
+
- [ ] Context.Context is first parameter for long-running operations
|
|
289
|
+
- [ ] Context cancellation respected in loops
|
|
290
|
+
- [ ] Timeouts set on contexts where appropriate
|
|
291
|
+
- [ ] Context not stored in struct fields (passed as param)
|
|
292
|
+
- [ ] No context.Background() in production code (use passed context)
|
|
293
|
+
|
|
294
|
+
### Goroutines & Concurrency (HIGH severity)
|
|
295
|
+
- [ ] Goroutine leaks prevented (always channel close/cancel)
|
|
296
|
+
- [ ] WaitGroup or context used to coordinate goroutines
|
|
297
|
+
- [ ] No data races (use go run -race to verify)
|
|
298
|
+
- [ ] Channels properly closed (only sender closes)
|
|
299
|
+
- [ ] Select blocks use timeout or context for deadlock prevention
|
|
300
|
+
- [ ] Shared memory access protected by sync.Mutex or channels
|
|
301
|
+
|
|
302
|
+
### Code Style & Formatting (MEDIUM severity)
|
|
303
|
+
- [ ] gofmt applied (files auto-formatted)
|
|
304
|
+
- [ ] goimports run (unused imports removed, needed imports added)
|
|
305
|
+
- [ ] No blank lines in code blocks
|
|
306
|
+
- [ ] Function comments start with function name
|
|
307
|
+
- [ ] Package comments explain package purpose
|
|
308
|
+
- [ ] Comments explain "why", not "what"
|
|
309
|
+
|
|
310
|
+
### Function & File Structure (MEDIUM severity)
|
|
311
|
+
- [ ] Public functions appear before private in file
|
|
312
|
+
- [ ] Max function complexity reasonable
|
|
313
|
+
- [ ] No duplicate logic — extract to helpers
|
|
314
|
+
- [ ] Single responsibility principle
|
|
315
|
+
- [ ] Related functions in same package
|
|
316
|
+
- [ ] Tests in same package with \`_test.go\` suffix
|
|
317
|
+
|
|
318
|
+
### Testing Strategy (MEDIUM severity)
|
|
319
|
+
- [ ] Table-driven tests used for multiple scenarios
|
|
320
|
+
- [ ] Subtests used for clarity (\`t.Run("scenario", ...)\`)
|
|
321
|
+
- [ ] Test coverage for critical paths
|
|
322
|
+
- [ ] No external dependencies in unit tests (use mocks)
|
|
323
|
+
- [ ] Benchmarks for performance-critical code
|
|
324
|
+
- [ ] Fuzz tests for parsing/validation
|
|
325
|
+
|
|
326
|
+
### Common Patterns (MEDIUM severity)
|
|
327
|
+
- [ ] defer used for cleanup (files, locks, etc.)
|
|
328
|
+
- [ ] Type assertions checked (\`v, ok := x.(Type)\`)
|
|
329
|
+
- [ ] No init() functions (prefer explicit initialization)
|
|
330
|
+
- [ ] Package naming: short, lowercase, no underscores
|
|
331
|
+
- [ ] Constants and vars grouped logically
|
|
332
|
+
- [ ] Enums implemented with iota
|
|
333
|
+
|
|
334
|
+
### Performance (LOW severity)
|
|
335
|
+
- [ ] Allocations minimized in hot loops
|
|
336
|
+
- [ ] String building uses strings.Builder, not concatenation
|
|
337
|
+
- [ ] Unnecessary allocations avoided
|
|
338
|
+
- [ ] Reasonable algorithm complexity
|
|
339
|
+
|
|
340
|
+
## Output Format
|
|
341
|
+
|
|
342
|
+
For each issue found:
|
|
343
|
+
\`\`\`
|
|
344
|
+
[File:Line] SEVERITY — Issue Description
|
|
345
|
+
Why: Explain the problem
|
|
346
|
+
Fix: How to resolve it
|
|
347
|
+
Example: Show corrected code
|
|
348
|
+
\`\`\`
|
|
349
|
+
|
|
350
|
+
End with summary:
|
|
351
|
+
- Issues by severity (CRITICAL / HIGH / MEDIUM / LOW / NIT)
|
|
352
|
+
- Top 3 recommendations
|
|
353
|
+
- Overall verdict: APPROVE / REQUEST CHANGES / NEEDS DISCUSSION`;
|
|
354
|
+
}
|
|
355
|
+
// ── Rust Review Agent ─────────────────────────────────────
|
|
356
|
+
export function buildRustReviewPrompt(cwd, target) {
|
|
357
|
+
return `Perform a detailed Rust code review following Rust API Guidelines and Clippy lints.
|
|
358
|
+
|
|
359
|
+
**Project Path**: ${cwd}
|
|
360
|
+
${target ? `**Target Files/Diff**: ${target}` : ''}
|
|
361
|
+
|
|
362
|
+
## Review Checklist
|
|
363
|
+
|
|
364
|
+
### Ownership & Lifetimes (CRITICAL severity)
|
|
365
|
+
- [ ] Ownership rules followed (move vs copy)
|
|
366
|
+
- [ ] Lifetimes explicitly annotated where needed
|
|
367
|
+
- [ ] No dangling references
|
|
368
|
+
- [ ] String slices (\`&str\`) for non-owned string parameters
|
|
369
|
+
- [ ] \`&[T]\` instead of \`&Vec<T>\` for function parameters
|
|
370
|
+
- [ ] Lifetimes don't leak implementation details to callers
|
|
371
|
+
|
|
372
|
+
### Error Handling (CRITICAL severity)
|
|
373
|
+
- [ ] All fallible operations return \`Result<T, E>\`
|
|
374
|
+
- [ ] Error types implement Display and Error traits
|
|
375
|
+
- [ ] Error context added with ? operator properly
|
|
376
|
+
- [ ] Custom error types for domain errors
|
|
377
|
+
- [ ] No panics in library code (only tests/main)
|
|
378
|
+
- [ ] expect()/unwrap() only in tests or with justification
|
|
379
|
+
|
|
380
|
+
### Smart Pointers (HIGH severity)
|
|
381
|
+
- [ ] \`unique_ptr\` equivalent (\`Box<T>\`) for owned allocations
|
|
382
|
+
- [ ] \`shared_ptr\` equivalent (\`Arc<T>\`) for shared ownership
|
|
383
|
+
- [ ] \`Rc<T>\` vs \`Arc<T>\` chosen correctly
|
|
384
|
+
- [ ] Circular references broken with \`Weak<T>\`
|
|
385
|
+
- [ ] Reference counting overhead justified
|
|
386
|
+
- [ ] No raw pointers unless using unsafe
|
|
387
|
+
|
|
388
|
+
### Unsafe Blocks (HIGH severity)
|
|
389
|
+
- [ ] Unsafe blocks minimal and well-documented
|
|
390
|
+
- [ ] Safety invariants documented above unsafe blocks
|
|
391
|
+
- [ ] All unsafe operations justified with comments
|
|
392
|
+
- [ ] Bounds checking done before pointer dereference
|
|
393
|
+
- [ ] No undefined behavior possible
|
|
394
|
+
- [ ] Consider safe abstractions instead of unsafe
|
|
395
|
+
|
|
396
|
+
### Clippy Lints (MEDIUM severity)
|
|
397
|
+
- [ ] \`#![warn(clippy::all)]\` enabled (or strict superset)
|
|
398
|
+
- [ ] No \`clone()\` used unnecessarily
|
|
399
|
+
- [ ] \`map().collect()\` chains are clear and efficient
|
|
400
|
+
- [ ] match over if-let chains for >2 variants
|
|
401
|
+
- [ ] Function complexity reasonable
|
|
402
|
+
- [ ] No premature optimization
|
|
403
|
+
|
|
404
|
+
### Const Correctness (HIGH severity)
|
|
405
|
+
- [ ] const used for true compile-time constants
|
|
406
|
+
- [ ] Mutable references used only when mutation needed
|
|
407
|
+
- [ ] Associated consts used for type-scoped constants
|
|
408
|
+
- [ ] const generics used appropriately (Rust 1.51+)
|
|
409
|
+
|
|
410
|
+
### Code Quality & Style (MEDIUM severity)
|
|
411
|
+
- [ ] cargo fmt applied (consistent formatting)
|
|
412
|
+
- [ ] rustfmt.toml configured appropriately
|
|
413
|
+
- [ ] Naming follows Rust conventions (snake_case functions, CamelCase types)
|
|
414
|
+
- [ ] Public API items have documentation comments
|
|
415
|
+
- [ ] Examples in doc comments run under cargo test --doc
|
|
416
|
+
- [ ] Private items documented if complex
|
|
417
|
+
|
|
418
|
+
### Testing & Documentation (MEDIUM severity)
|
|
419
|
+
- [ ] Unit tests in same file with #[cfg(test)]
|
|
420
|
+
- [ ] Integration tests in tests/ directory
|
|
421
|
+
- [ ] Doc tests included for public API
|
|
422
|
+
- [ ] All public functions documented
|
|
423
|
+
- [ ] Examples provided for non-obvious APIs
|
|
424
|
+
- [ ] SAFETY comments for all unsafe blocks
|
|
425
|
+
|
|
426
|
+
### Trait & Generic Design (MEDIUM severity)
|
|
427
|
+
- [ ] Traits are cohesive (single responsibility)
|
|
428
|
+
- [ ] Generic constraints expressed properly
|
|
429
|
+
- [ ] Trait bounds clear in signatures
|
|
430
|
+
- [ ] Orphan rule followed (no blanket implementations)
|
|
431
|
+
- [ ] Associated types used to avoid over-generalization
|
|
432
|
+
|
|
433
|
+
### Performance (MEDIUM severity)
|
|
434
|
+
- [ ] No unnecessary allocations in hot paths
|
|
435
|
+
- [ ] Iterator chains preferred over loops
|
|
436
|
+
- [ ] SIMD opportunities considered
|
|
437
|
+
- [ ] Lazy evaluation used where beneficial
|
|
438
|
+
- [ ] Profile before optimizing
|
|
439
|
+
|
|
440
|
+
## Output Format
|
|
441
|
+
|
|
442
|
+
For each issue found:
|
|
443
|
+
\`\`\`
|
|
444
|
+
[File:Line] SEVERITY — Issue Description
|
|
445
|
+
Why: Explain the problem
|
|
446
|
+
Fix: How to resolve it
|
|
447
|
+
Example: Show corrected code
|
|
448
|
+
\`\`\`
|
|
449
|
+
|
|
450
|
+
End with summary:
|
|
451
|
+
- Issues by severity (CRITICAL / HIGH / MEDIUM / LOW / NIT)
|
|
452
|
+
- Top 3 recommendations
|
|
453
|
+
- Overall verdict: APPROVE / REQUEST CHANGES / NEEDS DISCUSSION`;
|
|
454
|
+
}
|
|
455
|
+
// ── Java Review Agent ─────────────────────────────────────
|
|
456
|
+
export function buildJavaReviewPrompt(cwd, target) {
|
|
457
|
+
return `Perform a detailed Java code review following Google Java Style Guide and Spring best practices.
|
|
458
|
+
|
|
459
|
+
**Project Path**: ${cwd}
|
|
460
|
+
${target ? `**Target Files/Diff**: ${target}` : ''}
|
|
461
|
+
|
|
462
|
+
## Review Checklist
|
|
463
|
+
|
|
464
|
+
### Null Safety (CRITICAL severity)
|
|
465
|
+
- [ ] Optional<T> used instead of null returns
|
|
466
|
+
- [ ] Optional.orElse() or orElseThrow() for null handling
|
|
467
|
+
- [ ] No .get() without isPresent() check
|
|
468
|
+
- [ ] @Nullable/@NonNull annotations used
|
|
469
|
+
- [ ] @SpringBootTest or @ExtendWith for Spring tests
|
|
470
|
+
- [ ] No NullPointerException in tests
|
|
471
|
+
|
|
472
|
+
### Resource Management (HIGH severity)
|
|
473
|
+
- [ ] try-with-resources for all Closeable resources
|
|
474
|
+
- [ ] No try-finally for resource cleanup (use try-with)
|
|
475
|
+
- [ ] Connection/Statement properly closed
|
|
476
|
+
- [ ] File streams closed in try-with-resources
|
|
477
|
+
- [ ] No resource leaks in exception paths
|
|
478
|
+
|
|
479
|
+
### Collections & Streams (HIGH severity)
|
|
480
|
+
- [ ] Stream operations preferred over explicit loops
|
|
481
|
+
- [ ] List.of()/Map.of()/Set.of() for immutable collections
|
|
482
|
+
- [ ] Not creating new lists/maps unnecessarily
|
|
483
|
+
- [ ] Terminal operations present in streams (not lazy)
|
|
484
|
+
- [ ] flatMap not over-nested for readability
|
|
485
|
+
- [ ] Collectors used appropriately (toList, groupingBy, etc.)
|
|
486
|
+
|
|
487
|
+
### Spring Boot Patterns (HIGH severity)
|
|
488
|
+
- [ ] @Autowired only on constructor (not fields)
|
|
489
|
+
- [ ] Constructor injection preferred
|
|
490
|
+
- [ ] No circular dependencies
|
|
491
|
+
- [ ] @Service/@Repository/@Controller used correctly
|
|
492
|
+
- [ ] @Transactional scoped appropriately (not on getters)
|
|
493
|
+
- [ ] @ConfigurationProperties for external config
|
|
494
|
+
- [ ] Proper exception handling with @ControllerAdvice
|
|
495
|
+
|
|
496
|
+
### JPA & ORM (HIGH severity)
|
|
497
|
+
- [ ] Lazy loading avoided (use fetch joins when needed)
|
|
498
|
+
- [ ] N+1 query problem addressed with joins
|
|
499
|
+
- [ ] Entities not modified outside transaction
|
|
500
|
+
- [ ] @Transactional readOnly=true for queries
|
|
501
|
+
- [ ] Proper cascade configuration (avoid cascading deletes)
|
|
502
|
+
- [ ] No business logic in entity constructors
|
|
503
|
+
|
|
504
|
+
### Code Style & Conventions (MEDIUM severity)
|
|
505
|
+
- [ ] 4-space indentation
|
|
506
|
+
- [ ] max 100 chars per line
|
|
507
|
+
- [ ] CamelCase for classes, camelCase for variables
|
|
508
|
+
- [ ] UPPER_SNAKE_CASE for constants
|
|
509
|
+
- [ ] @Override annotation always present
|
|
510
|
+
- [ ] Comments explain "why", not "what"
|
|
511
|
+
|
|
512
|
+
### Type Safety (MEDIUM severity)
|
|
513
|
+
- [ ] Generic type bounds appropriate (<T extends SomeClass>)
|
|
514
|
+
- [ ] Wildcard types used appropriately (? extends, ? super)
|
|
515
|
+
- [ ] Unchecked casts minimized and justified
|
|
516
|
+
- [ ] Type erasure understood (no instanceof with generics)
|
|
517
|
+
- [ ] Raw types not used
|
|
518
|
+
|
|
519
|
+
### Testing & Documentation (MEDIUM severity)
|
|
520
|
+
- [ ] JUnit 5 tests with @Test annotation
|
|
521
|
+
- [ ] Mocks/stubs for external dependencies
|
|
522
|
+
- [ ] Test names describe what is tested
|
|
523
|
+
- [ ] Arrange-Act-Assert pattern in tests
|
|
524
|
+
- [ ] Public classes/methods documented with JavaDoc
|
|
525
|
+
- [ ] @param, @return, @throws documented in JavaDoc
|
|
526
|
+
|
|
527
|
+
### Object-Oriented Design (MEDIUM severity)
|
|
528
|
+
- [ ] Inheritance used sparingly (prefer composition)
|
|
529
|
+
- [ ] Final classes/methods for immutables
|
|
530
|
+
- [ ] Immutable objects preferred
|
|
531
|
+
- [ ] Encapsulation maintained (private fields, public getters)
|
|
532
|
+
- [ ] SOLID principles followed
|
|
533
|
+
- [ ] No god classes (single responsibility)
|
|
534
|
+
|
|
535
|
+
### Performance & Caching (MEDIUM severity)
|
|
536
|
+
- [ ] Caching strategy documented
|
|
537
|
+
- [ ] @Cacheable used appropriately with TTL
|
|
538
|
+
- [ ] Batch operations used for bulk inserts/updates
|
|
539
|
+
- [ ] Index hints provided for complex queries
|
|
540
|
+
- [ ] N+1 queries eliminated
|
|
541
|
+
- [ ] Unnecessary database calls avoided
|
|
542
|
+
|
|
543
|
+
## Output Format
|
|
544
|
+
|
|
545
|
+
For each issue found:
|
|
546
|
+
\`\`\`
|
|
547
|
+
[File:Line] SEVERITY — Issue Description
|
|
548
|
+
Why: Explain the problem
|
|
549
|
+
Fix: How to resolve it
|
|
550
|
+
Example: Show corrected code
|
|
551
|
+
\`\`\`
|
|
552
|
+
|
|
553
|
+
End with summary:
|
|
554
|
+
- Issues by severity (CRITICAL / HIGH / MEDIUM / LOW / NIT)
|
|
555
|
+
- Top 3 recommendations
|
|
556
|
+
- Overall verdict: APPROVE / REQUEST CHANGES / NEEDS DISCUSSION`;
|
|
557
|
+
}
|
|
558
|
+
// ── C++ Review Agent ──────────────────────────────────────
|
|
559
|
+
export function buildCppReviewPrompt(cwd, target) {
|
|
560
|
+
return `Perform a detailed C++ code review following C++ Core Guidelines.
|
|
561
|
+
|
|
562
|
+
**Project Path**: ${cwd}
|
|
563
|
+
${target ? `**Target Files/Diff**: ${target}` : ''}
|
|
564
|
+
|
|
565
|
+
## Review Checklist
|
|
566
|
+
|
|
567
|
+
### Memory Management (CRITICAL severity)
|
|
568
|
+
- [ ] Smart pointers (unique_ptr/shared_ptr) for all ownership
|
|
569
|
+
- [ ] No raw owning pointers
|
|
570
|
+
- [ ] RAII pattern used (resource acquired = initialization)
|
|
571
|
+
- [ ] No manual new/delete
|
|
572
|
+
- [ ] std::make_unique/make_shared preferred
|
|
573
|
+
- [ ] Move semantics used to avoid copies
|
|
574
|
+
- [ ] No memory leaks possible in exception paths
|
|
575
|
+
|
|
576
|
+
### Const Correctness (HIGH severity)
|
|
577
|
+
- [ ] const methods when no modification
|
|
578
|
+
- [ ] const references for parameters (non-owned)
|
|
579
|
+
- [ ] const correctness propagates up call chain
|
|
580
|
+
- [ ] mutable only for truly mutable state
|
|
581
|
+
- [ ] const data members by default
|
|
582
|
+
- [ ] const correctness in templates
|
|
583
|
+
|
|
584
|
+
### Pointer & Reference Safety (HIGH severity)
|
|
585
|
+
- [ ] std::string_view for non-owning string parameters
|
|
586
|
+
- [ ] References preferred over pointers where nullability not needed
|
|
587
|
+
- [ ] Pointer arithmetic minimized (use span, range)
|
|
588
|
+
- [ ] Null pointer checks before dereference
|
|
589
|
+
- [ ] Bounds checking in array operations
|
|
590
|
+
- [ ] std::optional<T&> for optional references
|
|
591
|
+
|
|
592
|
+
### RAII & Resource Management (HIGH severity)
|
|
593
|
+
- [ ] Destructors properly cleanup resources
|
|
594
|
+
- [ ] Copy/move constructors & assignment defined correctly
|
|
595
|
+
- [ ] No resource leaks in exception scenarios
|
|
596
|
+
- [ ] Custom deleters for non-standard resources
|
|
597
|
+
- [ ] scopedexit pattern for cleanup
|
|
598
|
+
- [ ] File handles/network sockets closed
|
|
599
|
+
|
|
600
|
+
### Class Design (HIGH severity)
|
|
601
|
+
- [ ] Single Responsibility Principle
|
|
602
|
+
- [ ] Virtual destructors for base classes
|
|
603
|
+
- [ ] No implicit conversions unless intentional
|
|
604
|
+
- [ ] Constexpr used for compile-time evaluation
|
|
605
|
+
- [ ] Access specifiers (public/private/protected) appropriate
|
|
606
|
+
- [ ] Deleted copy/move constructors when appropriate
|
|
607
|
+
|
|
608
|
+
### STL & Standard Library (MEDIUM severity)
|
|
609
|
+
- [ ] std::vector preferred for dynamic arrays
|
|
610
|
+
- [ ] std::string for text (not char arrays)
|
|
611
|
+
- [ ] std::array for fixed-size arrays
|
|
612
|
+
- [ ] std::map/unordered_map for key-value
|
|
613
|
+
- [ ] Iterator validity understood
|
|
614
|
+
- [ ] Range-based for loops preferred
|
|
615
|
+
- [ ] Algorithm library used where applicable
|
|
616
|
+
|
|
617
|
+
### Error Handling (MEDIUM severity)
|
|
618
|
+
- [ ] Exceptions preferred to error codes
|
|
619
|
+
- [ ] Exception safety guaranteed (strong or basic)
|
|
620
|
+
- [ ] noexcept used appropriately
|
|
621
|
+
- [ ] Custom exception types for domain errors
|
|
622
|
+
- [ ] Exception specifications avoided (noexcept only)
|
|
623
|
+
- [ ] Exception handling path tested
|
|
624
|
+
|
|
625
|
+
### Code Quality (MEDIUM severity)
|
|
626
|
+
- [ ] clang-format applied (consistent style)
|
|
627
|
+
- [ ] no using namespace std (except in function scope)
|
|
628
|
+
- [ ] Names meaningful and consistent
|
|
629
|
+
- [ ] Functions single responsibility
|
|
630
|
+
- [ ] Complexity reasonable
|
|
631
|
+
- [ ] Magic numbers replaced with constants
|
|
632
|
+
- [ ] Comments explain non-obvious logic
|
|
633
|
+
|
|
634
|
+
### Testing & Documentation (MEDIUM severity)
|
|
635
|
+
- [ ] Unit tests for critical functions
|
|
636
|
+
- [ ] Integration tests for module interactions
|
|
637
|
+
- [ ] Doxygen/standard doc comments on public API
|
|
638
|
+
- [ ] Examples for complex APIs
|
|
639
|
+
- [ ] Build/usage documented in README
|
|
640
|
+
- [ ] Valgrind/AddressSanitizer used for testing
|
|
641
|
+
|
|
642
|
+
### Template Metaprogramming (MEDIUM severity)
|
|
643
|
+
- [ ] Template complexity justified
|
|
644
|
+
- [ ] SFINAE/concepts used for overload resolution
|
|
645
|
+
- [ ] Template instantiation bloat minimized
|
|
646
|
+
- [ ] Explicit instantiations documented
|
|
647
|
+
- [ ] compile_time checks (static_assert) used
|
|
648
|
+
- [ ] C++20 concepts preferred over enable_if
|
|
649
|
+
|
|
650
|
+
### Performance (MEDIUM severity)
|
|
651
|
+
- [ ] Move semantics used to avoid copies
|
|
652
|
+
- [ ] Unnecessary allocations avoided
|
|
653
|
+
- [ ] Algorithm complexity appropriate
|
|
654
|
+
- [ ] Profiling done before optimization
|
|
655
|
+
- [ ] Cache-friendly data layout considered
|
|
656
|
+
- [ ] Inline hints used judiciously
|
|
657
|
+
|
|
658
|
+
## Output Format
|
|
659
|
+
|
|
660
|
+
For each issue found:
|
|
661
|
+
\`\`\`
|
|
662
|
+
[File:Line] SEVERITY — Issue Description
|
|
663
|
+
Why: Explain the problem
|
|
664
|
+
Fix: How to resolve it
|
|
665
|
+
Example: Show corrected code
|
|
666
|
+
\`\`\`
|
|
667
|
+
|
|
668
|
+
End with summary:
|
|
669
|
+
- Issues by severity (CRITICAL / HIGH / MEDIUM / LOW / NIT)
|
|
670
|
+
- Top 3 recommendations
|
|
671
|
+
- Overall verdict: APPROVE / REQUEST CHANGES / NEEDS DISCUSSION`;
|
|
672
|
+
}
|
|
673
|
+
// ── Kotlin Review Agent ───────────────────────────────────
|
|
674
|
+
export function buildKotlinReviewPrompt(cwd, target) {
|
|
675
|
+
return `Perform a detailed Kotlin code review following Kotlin Coding Conventions.
|
|
676
|
+
|
|
677
|
+
**Project Path**: ${cwd}
|
|
678
|
+
${target ? `**Target Files/Diff**: ${target}` : ''}
|
|
679
|
+
|
|
680
|
+
## Review Checklist
|
|
681
|
+
|
|
682
|
+
### Null Safety (CRITICAL severity)
|
|
683
|
+
- [ ] Non-nullable types preferred (T over T?)
|
|
684
|
+
- [ ] Safe calls (.?) and not-null asserts (!) justified
|
|
685
|
+
- [ ] Elvis operator (?:) used appropriately
|
|
686
|
+
- [ ] Nullable types handled explicitly
|
|
687
|
+
- [ ] No !! unless in tests
|
|
688
|
+
- [ ] lateinit used only when unavoidable
|
|
689
|
+
|
|
690
|
+
### Data Classes & Immutability (HIGH severity)
|
|
691
|
+
- [ ] data class used for value objects
|
|
692
|
+
- [ ] val used by default (var only when needed)
|
|
693
|
+
- [ ] copy() method used for modifications (immutable pattern)
|
|
694
|
+
- [ ] Destructuring used for data class decomposition
|
|
695
|
+
- [ ] Private constructors for singletons
|
|
696
|
+
- [ ] Sealed classes for restricted hierarchies
|
|
697
|
+
|
|
698
|
+
### Coroutines (HIGH severity)
|
|
699
|
+
- [ ] Coroutines used for async instead of callbacks
|
|
700
|
+
- [ ] Proper scope (GlobalScope avoided)
|
|
701
|
+
- [ ] Exception handling in coroutine scopes
|
|
702
|
+
- [ ] Cancellation properly handled
|
|
703
|
+
- [ ] launch vs async used correctly
|
|
704
|
+
- [ ] Job/Task awaited properly
|
|
705
|
+
|
|
706
|
+
### Control Flow & Expressions (HIGH severity)
|
|
707
|
+
- [ ] when instead of if-else chains (>2 branches)
|
|
708
|
+
- [ ] when uses all branches (exhaustive or else)
|
|
709
|
+
- [ ] Scope functions (let, run, apply, also) used appropriately
|
|
710
|
+
- [ ] if-expression returns values where possible
|
|
711
|
+
- [ ] No unnecessary nested blocks
|
|
712
|
+
- [ ] early returns for guard conditions
|
|
713
|
+
|
|
714
|
+
### Extension Functions (MEDIUM severity)
|
|
715
|
+
- [ ] Extension functions for utility operations
|
|
716
|
+
- [ ] Receiver clarity in extension scopes
|
|
717
|
+
- [ ] No extension functions on Any/Object
|
|
718
|
+
- [ ] Documented for non-obvious purposes
|
|
719
|
+
- [ ] Scope functions (with, let) used correctly
|
|
720
|
+
|
|
721
|
+
### Collections & Sequences (MEDIUM severity)
|
|
722
|
+
- [ ] listOf/mapOf/setOf for immutable collections
|
|
723
|
+
- [ ] Sequences used for lazy evaluation
|
|
724
|
+
- [ ] map/filter/reduce chains clear and efficient
|
|
725
|
+
- [ ] groupBy for grouping operations
|
|
726
|
+
- [ ] associate for creating maps from collections
|
|
727
|
+
- [ ] Any unnecessary list conversions avoided
|
|
728
|
+
|
|
729
|
+
### Lambda & Functional Style (MEDIUM severity)
|
|
730
|
+
- [ ] Single-expression lambdas preferred
|
|
731
|
+
- [ ] it implicit parameter used
|
|
732
|
+
- [ ] Function types clear in signatures
|
|
733
|
+
- [ ] Higher-order functions well-documented
|
|
734
|
+
- [ ] DSLs used appropriately (builders)
|
|
735
|
+
- [ ] filter/map chains readable
|
|
736
|
+
|
|
737
|
+
### String Interpolation (MEDIUM severity)
|
|
738
|
+
- [ ] String templates used over concatenation
|
|
739
|
+
- [ ] Template expressions wrapped in ${'${...}'}
|
|
740
|
+
- [ ] Triple quotes for multiline strings
|
|
741
|
+
- [ ] Raw strings (""" """) for regex/JSON
|
|
742
|
+
- [ ] No string building in loops
|
|
743
|
+
|
|
744
|
+
### Testing & Documentation (MEDIUM severity)
|
|
745
|
+
- [ ] JUnit 5 tests with @Test
|
|
746
|
+
- [ ] Mockk or similar for mocking
|
|
747
|
+
- [ ] Test names describe behavior
|
|
748
|
+
- [ ] Arrange-Act-Assert pattern
|
|
749
|
+
- [ ] Doc comments on public APIs
|
|
750
|
+
- [ ] KDoc used for documentation
|
|
751
|
+
|
|
752
|
+
### Spring Boot Integration (MEDIUM severity)
|
|
753
|
+
- [ ] @SpringBootTest or @ExtendWith for tests
|
|
754
|
+
- [ ] Constructor injection preferred
|
|
755
|
+
- [ ] No @Autowired on properties
|
|
756
|
+
- [ ] data class for config properties
|
|
757
|
+
- [ ] Proper @Transactional usage
|
|
758
|
+
- [ ] @ControllerAdvice for exception handling
|
|
759
|
+
|
|
760
|
+
### Code Style & Conventions (MEDIUM severity)
|
|
761
|
+
- [ ] ktlint applied (consistent formatting)
|
|
762
|
+
- [ ] No redundant modifiers (public, final)
|
|
763
|
+
- [ ] Proper naming (camelCase, PascalCase for classes)
|
|
764
|
+
- [ ] Comments explain "why" not "what"
|
|
765
|
+
- [ ] Function length reasonable (<30 lines)
|
|
766
|
+
- [ ] File length reasonable (<300 lines)
|
|
767
|
+
|
|
768
|
+
## Output Format
|
|
769
|
+
|
|
770
|
+
For each issue found:
|
|
771
|
+
\`\`\`
|
|
772
|
+
[File:Line] SEVERITY — Issue Description
|
|
773
|
+
Why: Explain the problem
|
|
774
|
+
Fix: How to resolve it
|
|
775
|
+
Example: Show corrected code
|
|
776
|
+
\`\`\`
|
|
777
|
+
|
|
778
|
+
End with summary:
|
|
779
|
+
- Issues by severity (CRITICAL / HIGH / MEDIUM / LOW / NIT)
|
|
780
|
+
- Top 3 recommendations
|
|
781
|
+
- Overall verdict: APPROVE / REQUEST CHANGES / NEEDS DISCUSSION`;
|
|
782
|
+
}
|
|
783
|
+
// ── PHP Review Agent ──────────────────────────────────────
|
|
784
|
+
export function buildPhpReviewPrompt(cwd, target) {
|
|
785
|
+
return `Perform a detailed PHP code review following PSR standards and Laravel best practices.
|
|
786
|
+
|
|
787
|
+
**Project Path**: ${cwd}
|
|
788
|
+
${target ? `**Target Files/Diff**: ${target}` : ''}
|
|
789
|
+
|
|
790
|
+
## Review Checklist
|
|
791
|
+
|
|
792
|
+
### Type Safety (CRITICAL severity)
|
|
793
|
+
- [ ] declare(strict_types=1) at top of every file
|
|
794
|
+
- [ ] All function parameters typed
|
|
795
|
+
- [ ] All function return types specified
|
|
796
|
+
- [ ] Class properties typed
|
|
797
|
+
- [ ] No use of mixed type (be specific)
|
|
798
|
+
- [ ] Type checking enabled (mypy/phpstan)
|
|
799
|
+
|
|
800
|
+
### Null Safety (HIGH severity)
|
|
801
|
+
- [ ] Null coalescing (??) over isset checks
|
|
802
|
+
- [ ] Nullsafe operator (?->) for deep access
|
|
803
|
+
- [ ] Optional<T> pattern or explicit null handling
|
|
804
|
+
- [ ] No silent null failures
|
|
805
|
+
- [ ] Type hints include ? for nullable types
|
|
806
|
+
- [ ] Early returns for guard conditions
|
|
807
|
+
|
|
808
|
+
### PSR Standards (HIGH severity)
|
|
809
|
+
- [ ] PSR-1: Basic Coding Standard followed
|
|
810
|
+
- [ ] PSR-12: Extended Coding Style followed
|
|
811
|
+
- [ ] PSR-4: Autoloading (Composer) used
|
|
812
|
+
- [ ] PHP_EOL for line endings
|
|
813
|
+
- [ ] 4-space indentation
|
|
814
|
+
- [ ] CamelCase for classes, camelCase for methods/variables
|
|
815
|
+
|
|
816
|
+
### Eloquent & Database Patterns (HIGH severity)
|
|
817
|
+
- [ ] Model relationships defined clearly
|
|
818
|
+
- [ ] Eager loading used (with()) to prevent N+1
|
|
819
|
+
- [ ] Proper use of select() for specific columns
|
|
820
|
+
- [ ] Scopes used for reusable query logic
|
|
821
|
+
- [ ] Soft deletes used when appropriate
|
|
822
|
+
- [ ] Mass assignment protected ($guarded, $fillable)
|
|
823
|
+
|
|
824
|
+
### Validation & Request Handling (HIGH severity)
|
|
825
|
+
- [ ] Form request validation classes used
|
|
826
|
+
- [ ] Validate all user input
|
|
827
|
+
- [ ] Validation messages customized
|
|
828
|
+
- [ ] Gate/Policy authorization checks
|
|
829
|
+
- [ ] CSRF protection enabled
|
|
830
|
+
- [ ] SQL injection prevention (parameterized queries)
|
|
831
|
+
|
|
832
|
+
### Error Handling (HIGH severity)
|
|
833
|
+
- [ ] Specific exception types caught
|
|
834
|
+
- [ ] Custom exception classes for domain errors
|
|
835
|
+
- [ ] Try-catch blocks don't swallow errors silently
|
|
836
|
+
- [ ] Proper logging of exceptions
|
|
837
|
+
- [ ] HTTP exception codes correct
|
|
838
|
+
- [ ] Error messages helpful to user
|
|
839
|
+
|
|
840
|
+
### Laravel Patterns (HIGH severity)
|
|
841
|
+
- [ ] Service/Repository pattern for business logic
|
|
842
|
+
- [ ] Middleware for cross-cutting concerns
|
|
843
|
+
- [ ] Jobs/Queues for async work
|
|
844
|
+
- [ ] Facades used appropriately
|
|
845
|
+
- [ ] Providers register services correctly
|
|
846
|
+
- [ ] Config values injected via constructor
|
|
847
|
+
|
|
848
|
+
### String & Text (MEDIUM severity)
|
|
849
|
+
- [ ] Heredoc/Nowdoc for multiline strings
|
|
850
|
+
- [ ] String interpolation clear
|
|
851
|
+
- [ ] No hardcoded strings in code
|
|
852
|
+
- [ ] String matching case-sensitive when needed
|
|
853
|
+
- [ ] Encoding specified for functions (e.g., mb_strlen)
|
|
854
|
+
- [ ] UTF-8 handling correct for multilingual apps
|
|
855
|
+
|
|
856
|
+
### Collections & Arrays (MEDIUM severity)
|
|
857
|
+
- [ ] Collection methods preferred over array functions
|
|
858
|
+
- [ ] array_map/filter over manual loops
|
|
859
|
+
- [ ] Spread operator used appropriately
|
|
860
|
+
- [ ] array_keys/array_values for key/value iteration
|
|
861
|
+
- [ ] Null coalescing in array access ([...] ?? default)
|
|
862
|
+
- [ ] Named array keys for clarity
|
|
863
|
+
|
|
864
|
+
### Testing & Documentation (MEDIUM severity)
|
|
865
|
+
- [ ] PHPUnit tests for critical functions
|
|
866
|
+
- [ ] Feature tests for workflows
|
|
867
|
+
- [ ] Mocking used for external dependencies
|
|
868
|
+
- [ ] Assertions clear and meaningful
|
|
869
|
+
- [ ] PHPDoc comments on public methods
|
|
870
|
+
- [ ] README documents setup and usage
|
|
871
|
+
|
|
872
|
+
### Code Quality & Performance (MEDIUM severity)
|
|
873
|
+
- [ ] No hardcoded values (use config/constants)
|
|
874
|
+
- [ ] Max function length ~30 lines
|
|
875
|
+
- [ ] Single Responsibility Principle
|
|
876
|
+
- [ ] DRY: no code duplication
|
|
877
|
+
- [ ] Memory usage reasonable (no memory leaks)
|
|
878
|
+
- [ ] N+1 query problems addressed
|
|
879
|
+
|
|
880
|
+
### Security Best Practices (HIGH severity)
|
|
881
|
+
- [ ] Input validation on all user data
|
|
882
|
+
- [ ] Output escaping (htmlspecialchars, blade {{...}})
|
|
883
|
+
- [ ] Authentication/authorization checks
|
|
884
|
+
- [ ] CSRF tokens used
|
|
885
|
+
- [ ] Password hashing (bcrypt/argon2)
|
|
886
|
+
- [ ] Secrets not in code or version control
|
|
887
|
+
|
|
888
|
+
## Output Format
|
|
889
|
+
|
|
890
|
+
For each issue found:
|
|
891
|
+
\`\`\`
|
|
892
|
+
[File:Line] SEVERITY — Issue Description
|
|
893
|
+
Why: Explain the problem
|
|
894
|
+
Fix: How to resolve it
|
|
895
|
+
Example: Show corrected code
|
|
896
|
+
\`\`\`
|
|
897
|
+
|
|
898
|
+
End with summary:
|
|
899
|
+
- Issues by severity (CRITICAL / HIGH / MEDIUM / LOW / NIT)
|
|
900
|
+
- Top 3 recommendations
|
|
901
|
+
- Overall verdict: APPROVE / REQUEST CHANGES / NEEDS DISCUSSION`;
|
|
902
|
+
}
|
|
903
|
+
// ── Database Review Agent ─────────────────────────────────
|
|
904
|
+
export function buildDbReviewPrompt(cwd, target) {
|
|
905
|
+
return `Perform a detailed database code/schema review for SQL, migrations, and queries.
|
|
906
|
+
|
|
907
|
+
**Project Path**: ${cwd}
|
|
908
|
+
${target ? `**Target Files/Diff**: ${target}` : ''}
|
|
909
|
+
|
|
910
|
+
## Review Checklist
|
|
911
|
+
|
|
912
|
+
### SQL Injection & Security (CRITICAL severity)
|
|
913
|
+
- [ ] Parameterized queries used (? placeholders or named params)
|
|
914
|
+
- [ ] No string interpolation in SQL
|
|
915
|
+
- [ ] Input validation before SQL operations
|
|
916
|
+
- [ ] User input never directly in WHERE clauses
|
|
917
|
+
- [ ] SQL comments not from user input
|
|
918
|
+
- [ ] Proper escaping if concatenation unavoidable
|
|
919
|
+
- [ ] Prepared statements cached/reused
|
|
920
|
+
|
|
921
|
+
### Query Performance (CRITICAL severity)
|
|
922
|
+
- [ ] N+1 query problem identified and addressed
|
|
923
|
+
- [ ] Indexes on WHERE, JOIN, ORDER BY columns
|
|
924
|
+
- [ ] SELECT * avoided (specify columns needed)
|
|
925
|
+
- [ ] Pagination used for large result sets
|
|
926
|
+
- [ ] EXPLAIN PLAN reviewed for complex queries
|
|
927
|
+
- [ ] Join order reasonable for query optimizer
|
|
928
|
+
- [ ] Subqueries not in SELECT list (use JOIN instead)
|
|
929
|
+
|
|
930
|
+
### Schema Design (HIGH severity)
|
|
931
|
+
- [ ] Proper primary keys defined
|
|
932
|
+
- [ ] Foreign keys establish referential integrity
|
|
933
|
+
- [ ] Data types appropriate for values
|
|
934
|
+
- [ ] NOT NULL constraints where needed
|
|
935
|
+
- [ ] Unique constraints on natural keys
|
|
936
|
+
- [ ] No excessive denormalization (3NF minimum)
|
|
937
|
+
- [ ] No magic numbers as IDs (use surrogates)
|
|
938
|
+
|
|
939
|
+
### Migrations (HIGH severity)
|
|
940
|
+
- [ ] Migrations are reversible (up/down)
|
|
941
|
+
- [ ] Migrations handle schema changes safely
|
|
942
|
+
- [ ] Data migrations include rollback path
|
|
943
|
+
- [ ] Migrations tested for up and down
|
|
944
|
+
- [ ] Migration order dependencies documented
|
|
945
|
+
- [ ] Breaking changes to schema documented
|
|
946
|
+
- [ ] Backward compatibility maintained during migration
|
|
947
|
+
|
|
948
|
+
### Supabase RLS (HIGH severity if applicable)
|
|
949
|
+
- [ ] Row Level Security policies defined
|
|
950
|
+
- [ ] auth.uid() used for user isolation
|
|
951
|
+
- [ ] RLS policies tested for security
|
|
952
|
+
- [ ] Policies not overly permissive
|
|
953
|
+
- [ ] authenticated/anon roles separated
|
|
954
|
+
- [ ] Service role distinguished from user role
|
|
955
|
+
|
|
956
|
+
### Constraints & Validation (HIGH severity)
|
|
957
|
+
- [ ] CHECK constraints enforce business rules
|
|
958
|
+
- [ ] DEFAULT values set appropriately
|
|
959
|
+
- [ ] Generated columns for computed data
|
|
960
|
+
- [ ] GENERATED ALWAYS for audit columns
|
|
961
|
+
- [ ] UNIQUE constraints prevent duplicates
|
|
962
|
+
- [ ] FK constraints cascade appropriately
|
|
963
|
+
|
|
964
|
+
### Transaction Handling (MEDIUM severity)
|
|
965
|
+
- [ ] Transactions used for multi-step operations
|
|
966
|
+
- [ ] Isolation level appropriate (READ COMMITTED typical)
|
|
967
|
+
- [ ] Deadlock prevention considered
|
|
968
|
+
- [ ] Rollback logic in case of failure
|
|
969
|
+
- [ ] No long-running transactions
|
|
970
|
+
- [ ] Connection pooling considered for performance
|
|
971
|
+
|
|
972
|
+
### NULL Handling (MEDIUM severity)
|
|
973
|
+
- [ ] NULL vs empty string distinguished
|
|
974
|
+
- [ ] COALESCE used appropriately
|
|
975
|
+
- [ ] IFNULL/NULLIF used where needed
|
|
976
|
+
- [ ] NOT NULL constraints explicit
|
|
977
|
+
- [ ] NULL handling in comparisons (IS NULL, not = NULL)
|
|
978
|
+
- [ ] Database NULL behavior matches application
|
|
979
|
+
|
|
980
|
+
### Indexing Strategy (MEDIUM severity)
|
|
981
|
+
- [ ] Indexes on frequently filtered columns
|
|
982
|
+
- [ ] Composite indexes for multi-column filters
|
|
983
|
+
- [ ] Index cardinality considered
|
|
984
|
+
- [ ] Covering indexes for hot queries
|
|
985
|
+
- [ ] No redundant indexes
|
|
986
|
+
- [ ] Index maintenance cost vs benefit evaluated
|
|
987
|
+
|
|
988
|
+
### Data Integrity (MEDIUM severity)
|
|
989
|
+
- [ ] Audit columns (created_at, updated_at) tracked
|
|
990
|
+
- [ ] Soft deletes used for historical data
|
|
991
|
+
- [ ] Data archival strategy documented
|
|
992
|
+
- [ ] Backup/restore tested
|
|
993
|
+
- [ ] Data validation rules consistent
|
|
994
|
+
- [ ] Temporal data handled correctly
|
|
995
|
+
|
|
996
|
+
### Scalability Considerations (MEDIUM severity)
|
|
997
|
+
- [ ] Sharding strategy documented if needed
|
|
998
|
+
- [ ] Replication setup for HA
|
|
999
|
+
- [ ] Connection pool sizing appropriate
|
|
1000
|
+
- [ ] Query results cached where beneficial
|
|
1001
|
+
- [ ] Read replicas leveraged for reporting
|
|
1002
|
+
- [ ] Growth projections documented
|
|
1003
|
+
|
|
1004
|
+
## Output Format
|
|
1005
|
+
|
|
1006
|
+
For each issue found:
|
|
1007
|
+
\`\`\`
|
|
1008
|
+
[File:Line] SEVERITY — Issue Description
|
|
1009
|
+
Why: Explain the problem
|
|
1010
|
+
Fix: How to resolve it
|
|
1011
|
+
Example: Show corrected SQL/migration
|
|
1012
|
+
\`\`\`
|
|
1013
|
+
|
|
1014
|
+
End with summary:
|
|
1015
|
+
- Issues by severity (CRITICAL / HIGH / MEDIUM / LOW / NIT)
|
|
1016
|
+
- Performance recommendations
|
|
1017
|
+
- Security recommendations
|
|
1018
|
+
- Overall verdict: APPROVE / REQUEST CHANGES / NEEDS DISCUSSION`;
|
|
1019
|
+
}
|
|
1020
|
+
// ── TypeScript Build Fix Agent ────────────────────────────
|
|
1021
|
+
export function buildTSBuildFixPrompt(cwd, errors) {
|
|
1022
|
+
const strategy = errors
|
|
1023
|
+
? `The following TypeScript build errors were captured:
|
|
1024
|
+
|
|
1025
|
+
\`\`\`
|
|
1026
|
+
${errors.slice(0, 5000)}
|
|
1027
|
+
\`\`\`
|
|
1028
|
+
|
|
1029
|
+
Analyze and fix them one at a time.`
|
|
1030
|
+
: `Run \`npx tsc --noEmit\` in ${cwd} and capture the output.
|
|
1031
|
+
If there are errors, analyze them and fix them one at a time.
|
|
1032
|
+
After each fix, re-run the build to verify.`;
|
|
1033
|
+
return `${strategy}
|
|
1034
|
+
|
|
1035
|
+
## Error Resolution Process
|
|
1036
|
+
|
|
1037
|
+
For each TypeScript error found:
|
|
1038
|
+
|
|
1039
|
+
1. **Parse the error message**
|
|
1040
|
+
- Extract file path and line number
|
|
1041
|
+
- Identify error code (TS1234, etc.)
|
|
1042
|
+
- Understand the root cause
|
|
1043
|
+
|
|
1044
|
+
2. **Fix the error** — Common fixes:
|
|
1045
|
+
- **TS7053**: Index signature missing — add Record<string, T> or explicit index type
|
|
1046
|
+
- **TS2339**: Property missing — add to type definition or interface
|
|
1047
|
+
- **TS2322**: Type mismatch — ensure types are compatible or cast explicitly
|
|
1048
|
+
- **TS2345**: Argument type incorrect — check function signature
|
|
1049
|
+
- **TS2304**: Name not found — check imports or global declarations
|
|
1050
|
+
- **TS2571**: Cannot invoke (not a function) — verify the value is callable
|
|
1051
|
+
- **TS2722**: Argument of optional — use non-null assertion or guard
|
|
1052
|
+
- **TS18048**: Value is not accessible — check null/undefined safety
|
|
1053
|
+
|
|
1054
|
+
3. **Verify**
|
|
1055
|
+
- Run \`npx tsc --noEmit\` again
|
|
1056
|
+
- Confirm error is resolved
|
|
1057
|
+
- No new errors introduced
|
|
1058
|
+
|
|
1059
|
+
4. **Repeat** until build succeeds
|
|
1060
|
+
|
|
1061
|
+
## Common Patterns
|
|
1062
|
+
|
|
1063
|
+
**Missing Type Definition**:
|
|
1064
|
+
\`\`\`typescript
|
|
1065
|
+
// Bad
|
|
1066
|
+
const x = {}; // x is type {}
|
|
1067
|
+
x.foo = 1; // Error: property foo doesn't exist
|
|
1068
|
+
|
|
1069
|
+
// Good
|
|
1070
|
+
const x: Record<string, number> = {};
|
|
1071
|
+
x.foo = 1;
|
|
1072
|
+
\`\`\`
|
|
1073
|
+
|
|
1074
|
+
**Null Safety**:
|
|
1075
|
+
\`\`\`typescript
|
|
1076
|
+
// Bad
|
|
1077
|
+
const val = getValue(); // might be null
|
|
1078
|
+
console.log(val.length); // Error: possibly null
|
|
1079
|
+
|
|
1080
|
+
// Good
|
|
1081
|
+
const val = getValue();
|
|
1082
|
+
if (val) {
|
|
1083
|
+
console.log(val.length);
|
|
1084
|
+
}
|
|
1085
|
+
\`\`\`
|
|
1086
|
+
|
|
1087
|
+
**Type Assertion**:
|
|
1088
|
+
\`\`\`typescript
|
|
1089
|
+
// Bad
|
|
1090
|
+
const x = fetch(url); // Promise<Response>
|
|
1091
|
+
x.json(); // Error: no such property
|
|
1092
|
+
|
|
1093
|
+
// Good
|
|
1094
|
+
const res = await fetch(url);
|
|
1095
|
+
const data = await res.json();
|
|
1096
|
+
\`\`\`
|
|
1097
|
+
|
|
1098
|
+
Be methodical: fix errors from top to bottom (earlier errors may affect later ones).`;
|
|
1099
|
+
}
|
|
1100
|
+
// ── Go Build Fix Agent ────────────────────────────────────
|
|
1101
|
+
export function buildGoBuildFixPrompt(cwd, errors) {
|
|
1102
|
+
const strategy = errors
|
|
1103
|
+
? `The following Go build errors were captured:
|
|
1104
|
+
|
|
1105
|
+
\`\`\`
|
|
1106
|
+
${errors.slice(0, 5000)}
|
|
1107
|
+
\`\`\`
|
|
1108
|
+
|
|
1109
|
+
Analyze and fix them one at a time.`
|
|
1110
|
+
: `Run \`go build ./...\` in ${cwd} and capture the output.
|
|
1111
|
+
If there are errors, analyze them and fix them one at a time.
|
|
1112
|
+
After each fix, re-run the build to verify.`;
|
|
1113
|
+
return `${strategy}
|
|
1114
|
+
|
|
1115
|
+
## Error Resolution Process
|
|
1116
|
+
|
|
1117
|
+
For each Go error:
|
|
1118
|
+
|
|
1119
|
+
1. **Parse the error message**
|
|
1120
|
+
- Extract file path and line number
|
|
1121
|
+
- Identify error category
|
|
1122
|
+
- Understand the root cause
|
|
1123
|
+
|
|
1124
|
+
2. **Fix the error** — Common fixes:
|
|
1125
|
+
- **undefined: X** — Import missing or name misspelled. Check package.
|
|
1126
|
+
- **cannot use X as Y** — Type mismatch. Check types match or cast.
|
|
1127
|
+
- **X redeclared** — Variable/function declared twice. Remove duplicate.
|
|
1128
|
+
- **X is not exported** — Use lowercase for unexported, uppercase for exported
|
|
1129
|
+
- **assignment to entry in nil map** — Initialize map before use (make(map[K]V))
|
|
1130
|
+
- **cannot index X** — X is not indexable (array/slice/map)
|
|
1131
|
+
- **missing return statement** — All code paths must return
|
|
1132
|
+
- **unused variable X** — Remove if unused, use _ if intentional
|
|
1133
|
+
|
|
1134
|
+
3. **Verify**
|
|
1135
|
+
- Run \`go build ./...\` again
|
|
1136
|
+
- Confirm error is resolved
|
|
1137
|
+
- No new errors introduced
|
|
1138
|
+
|
|
1139
|
+
4. **Repeat** until build succeeds
|
|
1140
|
+
|
|
1141
|
+
## Common Patterns
|
|
1142
|
+
|
|
1143
|
+
**Import Missing**:
|
|
1144
|
+
\`\`\`go
|
|
1145
|
+
// Bad
|
|
1146
|
+
func main() {
|
|
1147
|
+
fmt.Println("hi") // Error: undefined fmt
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
// Good
|
|
1151
|
+
import "fmt"
|
|
1152
|
+
|
|
1153
|
+
func main() {
|
|
1154
|
+
fmt.Println("hi")
|
|
1155
|
+
}
|
|
1156
|
+
\`\`\`
|
|
1157
|
+
|
|
1158
|
+
**Type Mismatch**:
|
|
1159
|
+
\`\`\`go
|
|
1160
|
+
// Bad
|
|
1161
|
+
var x int = "hello" // Error: cannot use string as int
|
|
1162
|
+
|
|
1163
|
+
// Good
|
|
1164
|
+
var x string = "hello"
|
|
1165
|
+
// or
|
|
1166
|
+
var y int = 42
|
|
1167
|
+
\`\`\`
|
|
1168
|
+
|
|
1169
|
+
**Nil Map**:
|
|
1170
|
+
\`\`\`go
|
|
1171
|
+
// Bad
|
|
1172
|
+
var m map[string]int
|
|
1173
|
+
m["key"] = 1 // Error: assignment to entry in nil map
|
|
1174
|
+
|
|
1175
|
+
// Good
|
|
1176
|
+
m := make(map[string]int)
|
|
1177
|
+
m["key"] = 1
|
|
1178
|
+
\`\`\`
|
|
1179
|
+
|
|
1180
|
+
**Unused Variable**:
|
|
1181
|
+
\`\`\`go
|
|
1182
|
+
// Bad
|
|
1183
|
+
x := 1 // Error: x declared but not used
|
|
1184
|
+
|
|
1185
|
+
// Good
|
|
1186
|
+
x := 1
|
|
1187
|
+
fmt.Println(x) // or remove x if not needed
|
|
1188
|
+
// or
|
|
1189
|
+
_ = 1 // if intentionally unused
|
|
1190
|
+
\`\`\`
|
|
1191
|
+
|
|
1192
|
+
Be methodical and compile after each fix.`;
|
|
1193
|
+
}
|
|
1194
|
+
// ── Rust Build Fix Agent ──────────────────────────────────
|
|
1195
|
+
export function buildRustBuildFixPrompt(cwd, errors) {
|
|
1196
|
+
const strategy = errors
|
|
1197
|
+
? `The following Rust build errors were captured:
|
|
1198
|
+
|
|
1199
|
+
\`\`\`
|
|
1200
|
+
${errors.slice(0, 5000)}
|
|
1201
|
+
\`\`\`
|
|
1202
|
+
|
|
1203
|
+
Analyze and fix them one at a time.`
|
|
1204
|
+
: `Run \`cargo build\` in ${cwd} and capture the output.
|
|
1205
|
+
If there are errors, analyze them and fix them one at a time.
|
|
1206
|
+
After each fix, re-run cargo build to verify.`;
|
|
1207
|
+
return `${strategy}
|
|
1208
|
+
|
|
1209
|
+
## Error Resolution Process
|
|
1210
|
+
|
|
1211
|
+
For each Rust error:
|
|
1212
|
+
|
|
1213
|
+
1. **Parse the error message**
|
|
1214
|
+
- Read error code (E0xxx)
|
|
1215
|
+
- Extract file path and line number
|
|
1216
|
+
- Understand the error description
|
|
1217
|
+
|
|
1218
|
+
2. **Fix the error** — Common fixes:
|
|
1219
|
+
- **E0425: cannot find value** — Variable not in scope or misspelled
|
|
1220
|
+
- **E0433: cannot find module** — Module not imported or doesn't exist
|
|
1221
|
+
- **E0308: mismatched types** — Return type, argument type incorrect
|
|
1222
|
+
- **E0382: use of moved value** — Ownership issue. Use references or clone.
|
|
1223
|
+
- **E0502: cannot borrow as mutable** — Immutable borrow still in scope
|
|
1224
|
+
- **E0507: cannot move out** — Move from non-Copy type. Use references.
|
|
1225
|
+
- **E0599: no method named** — Method doesn't exist on type
|
|
1226
|
+
- **E0277: trait not implemented** — Type doesn't implement required trait
|
|
1227
|
+
|
|
1228
|
+
3. **Verify**
|
|
1229
|
+
- Run \`cargo build\` again
|
|
1230
|
+
- Confirm error is resolved
|
|
1231
|
+
- No new errors introduced
|
|
1232
|
+
|
|
1233
|
+
4. **Repeat** until build succeeds
|
|
1234
|
+
|
|
1235
|
+
## Common Patterns
|
|
1236
|
+
|
|
1237
|
+
**Ownership/Move**:
|
|
1238
|
+
\`\`\`rust
|
|
1239
|
+
// Bad
|
|
1240
|
+
let s = String::from("hello");
|
|
1241
|
+
let s2 = s;
|
|
1242
|
+
println!("{}", s); // Error: s was moved
|
|
1243
|
+
|
|
1244
|
+
// Good
|
|
1245
|
+
let s = String::from("hello");
|
|
1246
|
+
let s2 = &s; // Borrow instead of move
|
|
1247
|
+
println!("{}", s); // OK
|
|
1248
|
+
\`\`\`
|
|
1249
|
+
|
|
1250
|
+
**Type Mismatch**:
|
|
1251
|
+
\`\`\`rust
|
|
1252
|
+
// Bad
|
|
1253
|
+
fn foo() -> i32 {
|
|
1254
|
+
"hello" // Error: expected i32, found &str
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
// Good
|
|
1258
|
+
fn foo() -> &'static str {
|
|
1259
|
+
"hello"
|
|
1260
|
+
}
|
|
1261
|
+
\`\`\`
|
|
1262
|
+
|
|
1263
|
+
**Import Missing**:
|
|
1264
|
+
\`\`\`rust
|
|
1265
|
+
// Bad
|
|
1266
|
+
fn main() {
|
|
1267
|
+
println!("hi"); // Error: println! not in scope (in no_std context)
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// Good
|
|
1271
|
+
use std::println; // or ensure std library available
|
|
1272
|
+
fn main() {
|
|
1273
|
+
println!("hi");
|
|
1274
|
+
}
|
|
1275
|
+
\`\`\`
|
|
1276
|
+
|
|
1277
|
+
**Borrow Checker**:
|
|
1278
|
+
\`\`\`rust
|
|
1279
|
+
// Bad
|
|
1280
|
+
let mut x = 1;
|
|
1281
|
+
let r1 = &x;
|
|
1282
|
+
let r2 = &mut x; // Error: cannot borrow as mutable while immutable borrow exists
|
|
1283
|
+
|
|
1284
|
+
// Good
|
|
1285
|
+
let mut x = 1;
|
|
1286
|
+
{
|
|
1287
|
+
let r1 = &x;
|
|
1288
|
+
println!("{}", r1);
|
|
1289
|
+
} // r1 goes out of scope
|
|
1290
|
+
let r2 = &mut x; // OK
|
|
1291
|
+
\`\`\`
|
|
1292
|
+
|
|
1293
|
+
Be methodical and follow the compiler's guidance.`;
|
|
1294
|
+
}
|
|
1295
|
+
// ── Java Build Fix Agent ──────────────────────────────────
|
|
1296
|
+
export function buildJavaBuildFixPrompt(cwd, errors) {
|
|
1297
|
+
const strategy = errors
|
|
1298
|
+
? `The following Java build errors were captured:
|
|
1299
|
+
|
|
1300
|
+
\`\`\`
|
|
1301
|
+
${errors.slice(0, 5000)}
|
|
1302
|
+
\`\`\`
|
|
1303
|
+
|
|
1304
|
+
Analyze and fix them one at a time.`
|
|
1305
|
+
: `Run \`mvn clean compile\` or \`gradle build\` in ${cwd} and capture the output.
|
|
1306
|
+
If there are errors, analyze them and fix them one at a time.
|
|
1307
|
+
After each fix, re-run the build to verify.`;
|
|
1308
|
+
return `${strategy}
|
|
1309
|
+
|
|
1310
|
+
## Error Resolution Process
|
|
1311
|
+
|
|
1312
|
+
For each Java error:
|
|
1313
|
+
|
|
1314
|
+
1. **Parse the error message**
|
|
1315
|
+
- Extract file path and line number
|
|
1316
|
+
- Identify error category (compilation, missing dependency, etc.)
|
|
1317
|
+
- Understand the root cause
|
|
1318
|
+
|
|
1319
|
+
2. **Fix the error** — Common fixes:
|
|
1320
|
+
- **cannot find symbol** — Missing import or undefined variable/method
|
|
1321
|
+
- **incompatible types** — Type mismatch in assignment or method call
|
|
1322
|
+
- **missing return statement** — Method must return value on all paths
|
|
1323
|
+
- **method not found** — Check method name, parameters, and receiver type
|
|
1324
|
+
- **type mismatch** — Generic types, inheritance issues
|
|
1325
|
+
- **duplicate class** — Class defined in multiple files or same file
|
|
1326
|
+
- **does not override abstract method** — Implement abstract methods
|
|
1327
|
+
|
|
1328
|
+
3. **Verify**
|
|
1329
|
+
- Run build command again
|
|
1330
|
+
- Confirm error is resolved
|
|
1331
|
+
- No new errors introduced
|
|
1332
|
+
|
|
1333
|
+
4. **Repeat** until build succeeds
|
|
1334
|
+
|
|
1335
|
+
## Common Patterns
|
|
1336
|
+
|
|
1337
|
+
**Missing Import**:
|
|
1338
|
+
\`\`\`java
|
|
1339
|
+
// Bad
|
|
1340
|
+
public class Main {
|
|
1341
|
+
public static void main(String[] args) {
|
|
1342
|
+
List<String> items = new ArrayList<>(); // Error: List not found
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
// Good
|
|
1347
|
+
import java.util.*;
|
|
1348
|
+
|
|
1349
|
+
public class Main {
|
|
1350
|
+
public static void main(String[] args) {
|
|
1351
|
+
List<String> items = new ArrayList<>();
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
\`\`\`
|
|
1355
|
+
|
|
1356
|
+
**Type Mismatch**:
|
|
1357
|
+
\`\`\`java
|
|
1358
|
+
// Bad
|
|
1359
|
+
int x = "hello"; // Error: incompatible types
|
|
1360
|
+
|
|
1361
|
+
// Good
|
|
1362
|
+
String x = "hello";
|
|
1363
|
+
\`\`\`
|
|
1364
|
+
|
|
1365
|
+
**Missing Override**:
|
|
1366
|
+
\`\`\`java
|
|
1367
|
+
// Bad
|
|
1368
|
+
class Child extends Parent {
|
|
1369
|
+
public void method() { } // Error: missing @Override
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
// Good
|
|
1373
|
+
class Child extends Parent {
|
|
1374
|
+
@Override
|
|
1375
|
+
public void method() { }
|
|
1376
|
+
}
|
|
1377
|
+
\`\`\`
|
|
1378
|
+
|
|
1379
|
+
Be methodical and fix errors from top to bottom.`;
|
|
1380
|
+
}
|
|
1381
|
+
// ── C++ Build Fix Agent ───────────────────────────────────
|
|
1382
|
+
export function buildCppBuildFixPrompt(cwd, errors) {
|
|
1383
|
+
const strategy = errors
|
|
1384
|
+
? `The following C++ build errors were captured:
|
|
1385
|
+
|
|
1386
|
+
\`\`\`
|
|
1387
|
+
${errors.slice(0, 5000)}
|
|
1388
|
+
\`\`\`
|
|
1389
|
+
|
|
1390
|
+
Analyze and fix them one at a time.`
|
|
1391
|
+
: `Run \`cmake --build .\` or \`make\` in ${cwd} and capture the output.
|
|
1392
|
+
If there are errors, analyze them and fix them one at a time.
|
|
1393
|
+
After each fix, re-run the build to verify.`;
|
|
1394
|
+
return `${strategy}
|
|
1395
|
+
|
|
1396
|
+
## Error Resolution Process
|
|
1397
|
+
|
|
1398
|
+
For each C++ error:
|
|
1399
|
+
|
|
1400
|
+
1. **Parse the error message**
|
|
1401
|
+
- Extract file path and line number
|
|
1402
|
+
- Identify error category (compilation, linker, etc.)
|
|
1403
|
+
- Understand the root cause
|
|
1404
|
+
|
|
1405
|
+
2. **Fix the error** — Common fixes:
|
|
1406
|
+
- **undefined reference to** — Linker error. Link required library or define function.
|
|
1407
|
+
- **no matching function for call** — Function not found or parameter mismatch
|
|
1408
|
+
- **invalid use of** — Template, non-const reference, etc.
|
|
1409
|
+
- **error: expected primary-expression** — Syntax error
|
|
1410
|
+
- **was not declared in this scope** — Variable/function not in scope
|
|
1411
|
+
- **incomplete type** — Forward declaration instead of definition
|
|
1412
|
+
- **private within this context** — Access control issue
|
|
1413
|
+
|
|
1414
|
+
3. **Verify**
|
|
1415
|
+
- Run build command again
|
|
1416
|
+
- Confirm error is resolved
|
|
1417
|
+
- No new errors introduced
|
|
1418
|
+
|
|
1419
|
+
4. **Repeat** until build succeeds
|
|
1420
|
+
|
|
1421
|
+
## Common Patterns
|
|
1422
|
+
|
|
1423
|
+
**Undefined Reference**:
|
|
1424
|
+
\`\`\`cpp
|
|
1425
|
+
// Bad (missing #include or link)
|
|
1426
|
+
// Error: undefined reference to 'foo'
|
|
1427
|
+
int foo(); // Declaration
|
|
1428
|
+
int main() { foo(); } // Definition missing or not linked
|
|
1429
|
+
|
|
1430
|
+
// Good
|
|
1431
|
+
void foo() { } // Definition
|
|
1432
|
+
|
|
1433
|
+
int main() { foo(); }
|
|
1434
|
+
\`\`\`
|
|
1435
|
+
|
|
1436
|
+
**Function Not Found**:
|
|
1437
|
+
\`\`\`cpp
|
|
1438
|
+
// Bad
|
|
1439
|
+
void foo(int x, int y);
|
|
1440
|
+
int main() { foo(1); } // Error: no matching function (missing parameter)
|
|
1441
|
+
|
|
1442
|
+
// Good
|
|
1443
|
+
void foo(int x, int y);
|
|
1444
|
+
int main() { foo(1, 2); }
|
|
1445
|
+
\`\`\`
|
|
1446
|
+
|
|
1447
|
+
**Template Issues**:
|
|
1448
|
+
\`\`\`cpp
|
|
1449
|
+
// Bad (incomplete type)
|
|
1450
|
+
class Foo; // Forward declaration only
|
|
1451
|
+
void bar(Foo f) {} // Error: incomplete type
|
|
1452
|
+
|
|
1453
|
+
// Good
|
|
1454
|
+
class Foo {}; // Definition
|
|
1455
|
+
void bar(Foo f) {}
|
|
1456
|
+
\`\`\`
|
|
1457
|
+
|
|
1458
|
+
**Const Issues**:
|
|
1459
|
+
\`\`\`cpp
|
|
1460
|
+
// Bad
|
|
1461
|
+
void foo(int& x);
|
|
1462
|
+
const int y = 5;
|
|
1463
|
+
foo(y); // Error: cannot bind const to non-const reference
|
|
1464
|
+
|
|
1465
|
+
// Good
|
|
1466
|
+
void foo(const int& x);
|
|
1467
|
+
const int y = 5;
|
|
1468
|
+
foo(y); // OK
|
|
1469
|
+
\`\`\`
|
|
1470
|
+
|
|
1471
|
+
Be methodical and check link flags in CMakeLists.txt if linker errors.`;
|
|
1472
|
+
}
|
|
1473
|
+
// ── PyTorch Build Fix Agent ───────────────────────────────
|
|
1474
|
+
export function buildPyTorchBuildFixPrompt(cwd, errors) {
|
|
1475
|
+
const strategy = errors
|
|
1476
|
+
? `The following PyTorch/CUDA training errors were captured:
|
|
1477
|
+
|
|
1478
|
+
\`\`\`
|
|
1479
|
+
${errors.slice(0, 5000)}
|
|
1480
|
+
\`\`\`
|
|
1481
|
+
|
|
1482
|
+
Analyze and fix them one at a time.`
|
|
1483
|
+
: `Run training script in ${cwd} and capture errors.
|
|
1484
|
+
If there are errors, analyze them and fix them one at a time.
|
|
1485
|
+
After each fix, re-run to verify.`;
|
|
1486
|
+
return `${strategy}
|
|
1487
|
+
|
|
1488
|
+
## Error Resolution Process
|
|
1489
|
+
|
|
1490
|
+
For each PyTorch/CUDA error:
|
|
1491
|
+
|
|
1492
|
+
1. **Parse the error message**
|
|
1493
|
+
- Identify error type (CUDA, OOM, import, runtime, etc.)
|
|
1494
|
+
- Extract file path and line number
|
|
1495
|
+
- Understand the root cause
|
|
1496
|
+
|
|
1497
|
+
2. **Fix the error** — Common fixes:
|
|
1498
|
+
- **RuntimeError: CUDA out of memory** — Reduce batch size, model size, or clear cache
|
|
1499
|
+
- **ImportError: No module named 'torch'** — Install PyTorch: \`pip install torch\`
|
|
1500
|
+
- **CUDA runtime error: no kernel image** — CUDA compute capability mismatch
|
|
1501
|
+
- **RuntimeError: Expected all tensors** — Device mismatch (CPU vs GPU)
|
|
1502
|
+
- **IndexError: invalid index** — Tensor shape or indexing error
|
|
1503
|
+
- **ValueError: expected 4D tensor** — Wrong tensor shape
|
|
1504
|
+
- **UserWarning: volatile** — Use torch.no_grad() instead
|
|
1505
|
+
|
|
1506
|
+
3. **Verify**
|
|
1507
|
+
- Run training script again
|
|
1508
|
+
- Confirm error is resolved
|
|
1509
|
+
- Monitor GPU memory usage
|
|
1510
|
+
|
|
1511
|
+
4. **Repeat** until training succeeds
|
|
1512
|
+
|
|
1513
|
+
## Common Patterns
|
|
1514
|
+
|
|
1515
|
+
**CUDA Out of Memory**:
|
|
1516
|
+
\`\`\`python
|
|
1517
|
+
# Bad
|
|
1518
|
+
batch_size = 512
|
|
1519
|
+
model = LargeModel()
|
|
1520
|
+
for batch in data:
|
|
1521
|
+
optimizer.zero_grad()
|
|
1522
|
+
out = model(batch.cuda()) # Error: CUDA out of memory
|
|
1523
|
+
|
|
1524
|
+
# Good
|
|
1525
|
+
batch_size = 32 # Smaller batch
|
|
1526
|
+
model = model.cuda()
|
|
1527
|
+
for batch in data:
|
|
1528
|
+
batch = batch.cuda()
|
|
1529
|
+
optimizer.zero_grad()
|
|
1530
|
+
out = model(batch)
|
|
1531
|
+
loss = criterion(out, target)
|
|
1532
|
+
loss.backward()
|
|
1533
|
+
optimizer.step()
|
|
1534
|
+
\`\`\`
|
|
1535
|
+
|
|
1536
|
+
**Device Mismatch**:
|
|
1537
|
+
\`\`\`python
|
|
1538
|
+
# Bad
|
|
1539
|
+
model = MyModel()
|
|
1540
|
+
x = torch.randn(10).cuda()
|
|
1541
|
+
out = model(x) # Error: Expected all tensors on same device
|
|
1542
|
+
|
|
1543
|
+
# Good
|
|
1544
|
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
1545
|
+
model = MyModel().to(device)
|
|
1546
|
+
x = torch.randn(10).to(device)
|
|
1547
|
+
out = model(x)
|
|
1548
|
+
\`\`\`
|
|
1549
|
+
|
|
1550
|
+
**Shape Mismatch**:
|
|
1551
|
+
\`\`\`python
|
|
1552
|
+
# Bad
|
|
1553
|
+
x = torch.randn(3, 224, 224) # Missing batch dimension
|
|
1554
|
+
out = model(x) # Error: Expected 4D tensor
|
|
1555
|
+
|
|
1556
|
+
# Good
|
|
1557
|
+
x = torch.randn(1, 3, 224, 224) # Batch of 1
|
|
1558
|
+
out = model(x)
|
|
1559
|
+
\`\`\`
|
|
1560
|
+
|
|
1561
|
+
**Gradient Computation**:
|
|
1562
|
+
\`\`\`python
|
|
1563
|
+
# Bad
|
|
1564
|
+
with torch.no_grad():
|
|
1565
|
+
out = model(x)
|
|
1566
|
+
loss = criterion(out, y)
|
|
1567
|
+
loss.backward() # Error: leaf variable that requires grad is being used
|
|
1568
|
+
|
|
1569
|
+
# Good
|
|
1570
|
+
out = model(x)
|
|
1571
|
+
loss = criterion(out, y)
|
|
1572
|
+
loss.backward()
|
|
1573
|
+
\`\`\`
|
|
1574
|
+
|
|
1575
|
+
Be methodical: check CUDA availability, memory usage, tensor shapes.`;
|
|
1576
|
+
}
|
|
1577
|
+
// ── Auto-Detect Review Agent ──────────────────────────────
|
|
1578
|
+
export function buildAutoReviewPrompt(cwd, target) {
|
|
1579
|
+
const lang = detectProjectLanguage(cwd);
|
|
1580
|
+
switch (lang) {
|
|
1581
|
+
case 'typescript':
|
|
1582
|
+
return buildTSReviewPrompt(cwd, target);
|
|
1583
|
+
case 'python':
|
|
1584
|
+
return buildPyReviewPrompt(cwd, target);
|
|
1585
|
+
case 'go':
|
|
1586
|
+
return buildGoReviewPrompt(cwd, target);
|
|
1587
|
+
case 'rust':
|
|
1588
|
+
return buildRustReviewPrompt(cwd, target);
|
|
1589
|
+
case 'java':
|
|
1590
|
+
return buildJavaReviewPrompt(cwd, target);
|
|
1591
|
+
case 'cpp':
|
|
1592
|
+
return buildCppReviewPrompt(cwd, target);
|
|
1593
|
+
case 'kotlin':
|
|
1594
|
+
return buildKotlinReviewPrompt(cwd, target);
|
|
1595
|
+
case 'php':
|
|
1596
|
+
return buildPhpReviewPrompt(cwd, target);
|
|
1597
|
+
case 'sql':
|
|
1598
|
+
return buildDbReviewPrompt(cwd, target);
|
|
1599
|
+
default:
|
|
1600
|
+
return buildTSReviewPrompt(cwd, target);
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
//# sourceMappingURL=agents.js.map
|