truss-code-review-mcp 1.0.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.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +60 -0
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +88 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/ai-review.d.ts +21 -0
  8. package/dist/lib/ai-review.d.ts.map +1 -0
  9. package/dist/lib/ai-review.js +185 -0
  10. package/dist/lib/ai-review.js.map +1 -0
  11. package/dist/lib/complexity.d.ts +20 -0
  12. package/dist/lib/complexity.d.ts.map +1 -0
  13. package/dist/lib/complexity.js +272 -0
  14. package/dist/lib/complexity.js.map +1 -0
  15. package/dist/lib/license.d.ts +15 -0
  16. package/dist/lib/license.d.ts.map +1 -0
  17. package/dist/lib/license.js +72 -0
  18. package/dist/lib/license.js.map +1 -0
  19. package/dist/lib/patterns.d.ts +27 -0
  20. package/dist/lib/patterns.d.ts.map +1 -0
  21. package/dist/lib/patterns.js +102 -0
  22. package/dist/lib/patterns.js.map +1 -0
  23. package/dist/tools/check-complexity.d.ts +6 -0
  24. package/dist/tools/check-complexity.d.ts.map +1 -0
  25. package/dist/tools/check-complexity.js +34 -0
  26. package/dist/tools/check-complexity.js.map +1 -0
  27. package/dist/tools/deep-review.d.ts +6 -0
  28. package/dist/tools/deep-review.d.ts.map +1 -0
  29. package/dist/tools/deep-review.js +58 -0
  30. package/dist/tools/deep-review.js.map +1 -0
  31. package/dist/tools/detect-antipatterns.d.ts +6 -0
  32. package/dist/tools/detect-antipatterns.d.ts.map +1 -0
  33. package/dist/tools/detect-antipatterns.js +44 -0
  34. package/dist/tools/detect-antipatterns.js.map +1 -0
  35. package/dist/tools/explain-code.d.ts +6 -0
  36. package/dist/tools/explain-code.d.ts.map +1 -0
  37. package/dist/tools/explain-code.js +56 -0
  38. package/dist/tools/explain-code.js.map +1 -0
  39. package/dist/tools/optimize-code.d.ts +6 -0
  40. package/dist/tools/optimize-code.d.ts.map +1 -0
  41. package/dist/tools/optimize-code.js +57 -0
  42. package/dist/tools/optimize-code.js.map +1 -0
  43. package/dist/tools/review-diff.d.ts +8 -0
  44. package/dist/tools/review-diff.d.ts.map +1 -0
  45. package/dist/tools/review-diff.js +333 -0
  46. package/dist/tools/review-diff.js.map +1 -0
  47. package/dist/tools/security-review.d.ts +6 -0
  48. package/dist/tools/security-review.d.ts.map +1 -0
  49. package/dist/tools/security-review.js +57 -0
  50. package/dist/tools/security-review.js.map +1 -0
  51. package/dist/tools/suggest-tests.d.ts +6 -0
  52. package/dist/tools/suggest-tests.d.ts.map +1 -0
  53. package/dist/tools/suggest-tests.js +78 -0
  54. package/dist/tools/suggest-tests.js.map +1 -0
  55. package/evals/eval-complexity.ts +202 -0
  56. package/evals/eval-review.ts +196 -0
  57. package/evals/run-evals.ts +51 -0
  58. package/glama.json +4 -0
  59. package/package.json +36 -0
  60. package/smithery.yaml +15 -0
  61. package/src/data/antipatterns/go.json +98 -0
  62. package/src/data/antipatterns/javascript.json +122 -0
  63. package/src/data/antipatterns/python.json +98 -0
  64. package/src/index.ts +109 -0
  65. package/src/lib/ai-review.ts +220 -0
  66. package/src/lib/complexity.ts +284 -0
  67. package/src/lib/license.ts +95 -0
  68. package/src/lib/patterns.ts +131 -0
  69. package/src/tools/check-complexity.ts +43 -0
  70. package/src/tools/deep-review.ts +67 -0
  71. package/src/tools/detect-antipatterns.ts +54 -0
  72. package/src/tools/explain-code.ts +65 -0
  73. package/src/tools/optimize-code.ts +66 -0
  74. package/src/tools/review-diff.ts +374 -0
  75. package/src/tools/security-review.ts +66 -0
  76. package/src/tools/suggest-tests.ts +90 -0
  77. package/tsconfig.json +19 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TRUSS
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # TRUSS Code Review MCP Server
2
+
3
+ AI-powered code review tools for Claude Code. Automated complexity analysis, anti-pattern detection, security review, and optimization — directly in your editor.
4
+
5
+ ## Quick Start
6
+
7
+ ```json
8
+ {
9
+ "mcpServers": {
10
+ "code-review": {
11
+ "command": "npx",
12
+ "args": ["-y", "truss-code-review-mcp"]
13
+ }
14
+ }
15
+ }
16
+ ```
17
+
18
+ ## Tools
19
+
20
+ ### Free Tier (no key needed)
21
+
22
+ | Tool | Description |
23
+ |------|-------------|
24
+ | `review_diff` | Analyze a git diff for common issues (debug statements, TODOs, secrets, commented-out code) |
25
+ | `check_complexity` | Calculate cyclomatic complexity of functions (JS/TS, Python, Go) |
26
+ | `detect_antipatterns` | Detect language-specific anti-patterns with fix suggestions |
27
+
28
+ ### Pro Tier ($25/mo)
29
+
30
+ Requires `TRUSS_LICENSE_KEY` + your own `ANTHROPIC_API_KEY` or `OPENAI_API_KEY`.
31
+
32
+ | Tool | Description |
33
+ |------|-------------|
34
+ | `deep_review` | AI-powered comprehensive code review with scored findings |
35
+ | `suggest_tests` | Generate complete, runnable test files |
36
+ | `explain_code` | Generate documentation, docstrings, and data flow analysis |
37
+ | `security_review` | OWASP-based security analysis with CWE references |
38
+ | `optimize_code` | Performance optimization with before/after code |
39
+
40
+ ## Configuration
41
+
42
+ ```bash
43
+ # Free tier — just install, no config needed
44
+
45
+ # Pro tier
46
+ export TRUSS_LICENSE_KEY="truss_..."
47
+ export ANTHROPIC_API_KEY="sk-ant-..." # or OPENAI_API_KEY
48
+ ```
49
+
50
+ ## Anti-Pattern Coverage
51
+
52
+ **JavaScript/TypeScript:** `var` usage, loose equality (`==`), `any` type, `eval()`, `innerHTML`, sync I/O, `@ts-ignore`, console statements, callback hell, magic numbers
53
+
54
+ **Python:** bare `except`, mutable default args, wildcard imports, `global` statement, string concatenation in loops, hardcoded credentials, `type()` comparison, debug prints
55
+
56
+ **Go:** ignored errors, goroutine leaks, mutex without defer, `string([]byte)` in loops, `panic()` in library code, `init()` functions, naked returns, error wrapping with `%s`
57
+
58
+ ## License
59
+
60
+ MIT
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ // Free tier tools
5
+ import { registerReviewDiff } from './tools/review-diff.js';
6
+ import { registerCheckComplexity } from './tools/check-complexity.js';
7
+ import { registerDetectAntipatterns } from './tools/detect-antipatterns.js';
8
+ // Pro tier tools
9
+ import { registerDeepReview } from './tools/deep-review.js';
10
+ import { registerSuggestTests } from './tools/suggest-tests.js';
11
+ import { registerExplainCode } from './tools/explain-code.js';
12
+ import { registerSecurityReview } from './tools/security-review.js';
13
+ import { registerOptimizeCode } from './tools/optimize-code.js';
14
+ // Helpers
15
+ import { getLicenseStatus, hasAiKey } from './lib/license.js';
16
+ const server = new McpServer({
17
+ name: '@truss-dev/code-review-mcp',
18
+ version: '1.0.0',
19
+ });
20
+ // ── Status Tool ─────────────────────────────────────────────────────
21
+ server.tool('check_review_status', 'Check license tier and AI key configuration for code review tools.', {}, async () => {
22
+ const license = await getLicenseStatus();
23
+ const aiKeyPresent = hasAiKey();
24
+ return {
25
+ content: [
26
+ {
27
+ type: 'text',
28
+ text: JSON.stringify({
29
+ license: {
30
+ tier: license.tier,
31
+ valid: license.valid,
32
+ expires_at: license.expiresAt,
33
+ },
34
+ ai_key_configured: aiKeyPresent,
35
+ free_tools: [
36
+ 'review_diff — Rule-based diff analysis',
37
+ 'check_complexity — Cyclomatic complexity calculator',
38
+ 'detect_antipatterns — Language-specific anti-pattern detection',
39
+ ],
40
+ pro_tools: [
41
+ 'deep_review — AI-powered comprehensive review',
42
+ 'suggest_tests — Generate test cases',
43
+ 'explain_code — Generate documentation',
44
+ 'security_review — OWASP security analysis',
45
+ 'optimize_code — Performance optimization',
46
+ ],
47
+ ...(license.tier === 'free'
48
+ ? {
49
+ upgrade_info: {
50
+ url: 'https://truss.dev/pricing',
51
+ price: '$25/mo',
52
+ note: 'Set TRUSS_LICENSE_KEY + your own ANTHROPIC_API_KEY or OPENAI_API_KEY',
53
+ },
54
+ }
55
+ : {}),
56
+ ...(!aiKeyPresent && license.tier === 'pro'
57
+ ? {
58
+ warning: 'Pro license active but no AI key configured. Set ANTHROPIC_API_KEY or OPENAI_API_KEY to use AI-powered tools.',
59
+ }
60
+ : {}),
61
+ }, null, 2),
62
+ },
63
+ ],
64
+ };
65
+ });
66
+ // ── Register All Tools ──────────────────────────────────────────────
67
+ // Free tier
68
+ registerReviewDiff(server);
69
+ registerCheckComplexity(server);
70
+ registerDetectAntipatterns(server);
71
+ // Pro tier
72
+ registerDeepReview(server);
73
+ registerSuggestTests(server);
74
+ registerExplainCode(server);
75
+ registerSecurityReview(server);
76
+ registerOptimizeCode(server);
77
+ // ── Start Server ────────────────────────────────────────────────────
78
+ async function main() {
79
+ const transport = new StdioServerTransport();
80
+ process.on('SIGINT', () => process.exit(0));
81
+ process.on('SIGTERM', () => process.exit(0));
82
+ await server.connect(transport);
83
+ }
84
+ main().catch((err) => {
85
+ console.error('Fatal error starting MCP server:', err);
86
+ process.exit(1);
87
+ });
88
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAGjF,kBAAkB;AAClB,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAE5E,iBAAiB;AACjB,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAEhE,UAAU;AACV,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE9D,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;IAC3B,IAAI,EAAE,4BAA4B;IAClC,OAAO,EAAE,OAAO;CACjB,CAAC,CAAC;AAEH,uEAAuE;AAEvE,MAAM,CAAC,IAAI,CACT,qBAAqB,E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AAoB,CAAC,MAAM,CAAC,CAAC;AAC7B,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAC5B,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAC/B,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAE7B,uEAAuE;AAEvE,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAE7C,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAE7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,GAAG,CAAC,CAAC;IACvD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * AI integration for pro-tier tools.
3
+ * Supports Anthropic (Claude) and OpenAI (GPT) APIs.
4
+ * Uses the customer's own API key.
5
+ */
6
+ export interface AiReviewResult {
7
+ content: string;
8
+ model: string;
9
+ provider: 'anthropic' | 'openai';
10
+ tokensUsed: {
11
+ input: number;
12
+ output: number;
13
+ };
14
+ }
15
+ export declare function aiReview(systemPrompt: string, userPrompt: string): Promise<AiReviewResult>;
16
+ export declare const DEEP_REVIEW_SYSTEM = "You are an expert code reviewer. Provide a comprehensive code review covering:\n1. Architecture and design quality\n2. Security vulnerabilities\n3. Performance concerns\n4. Error handling completeness\n5. Code clarity and maintainability\n6. Edge cases and potential bugs\n\nFormat your response as JSON with this structure:\n{\n \"summary\": \"Overall assessment (2-3 sentences)\",\n \"score\": <1-10>,\n \"findings\": [\n {\n \"category\": \"security|performance|architecture|maintainability|bug|error_handling\",\n \"severity\": \"critical|high|medium|low|info\",\n \"title\": \"Short title\",\n \"description\": \"Detailed explanation\",\n \"suggestion\": \"How to fix it\",\n \"line_hint\": \"relevant code snippet or null\"\n }\n ],\n \"positives\": [\"Things done well\"]\n}";
17
+ export declare const SUGGEST_TESTS_SYSTEM = "You are a test engineering expert. Given source code, generate comprehensive test cases.\nWrite complete, runnable test code (not pseudocode) using the specified test framework.\nCover: happy paths, edge cases, error conditions, boundary values, and integration points.\nReturn ONLY the test file content, ready to save and run. Include all necessary imports.";
18
+ export declare const EXPLAIN_CODE_SYSTEM = "You are a technical writer and code documentation expert.\nGiven source code, provide:\n1. A high-level explanation of what the code does and why\n2. Detailed inline documentation (docstrings/JSDoc for each function)\n3. A summary of the data flow and key algorithms\n4. Any non-obvious design decisions or trade-offs\n\nFormat your response as JSON:\n{\n \"summary\": \"What this code does (2-3 sentences)\",\n \"purpose\": \"Why this code exists\",\n \"functions\": [\n {\n \"name\": \"function_name\",\n \"docstring\": \"Complete docstring/JSDoc\",\n \"explanation\": \"What it does and how\"\n }\n ],\n \"data_flow\": \"How data moves through the code\",\n \"design_notes\": [\"Important design decisions\"]\n}";
19
+ export declare const SECURITY_REVIEW_SYSTEM = "You are a security engineer specializing in application security (OWASP Top 10, CWE).\nPerform a focused security review of the provided code.\n\nFor each finding, include:\n- CWE ID and name\n- OWASP category if applicable\n- Severity (critical/high/medium/low)\n- Detailed description of the vulnerability\n- Proof of concept or attack scenario\n- Specific remediation steps with code examples\n\nFormat your response as JSON:\n{\n \"risk_level\": \"critical|high|medium|low|none\",\n \"findings\": [\n {\n \"title\": \"Vulnerability title\",\n \"cwe_id\": \"CWE-XXX\",\n \"cwe_name\": \"CWE Name\",\n \"owasp_category\": \"A01:2021 or null\",\n \"severity\": \"critical|high|medium|low\",\n \"description\": \"Detailed description\",\n \"attack_scenario\": \"How this could be exploited\",\n \"remediation\": \"How to fix with code example\",\n \"affected_lines\": \"Line numbers or code snippet\"\n }\n ],\n \"positive_practices\": [\"Security measures already in place\"],\n \"recommendations\": [\"General security improvements\"]\n}";
20
+ export declare const OPTIMIZE_CODE_SYSTEM = "You are a performance optimization expert. Analyze code for optimization opportunities.\nFocus on: algorithmic complexity, memory usage, I/O efficiency, caching opportunities, and language-specific optimizations.\n\nFor each optimization, show the before and after code.\n\nFormat your response as JSON:\n{\n \"current_assessment\": \"Brief assessment of current performance characteristics\",\n \"optimizations\": [\n {\n \"title\": \"Optimization title\",\n \"category\": \"algorithm|memory|io|caching|language_specific\",\n \"impact\": \"high|medium|low\",\n \"description\": \"What the optimization does and why\",\n \"before\": \"Current code snippet\",\n \"after\": \"Optimized code snippet\",\n \"expected_improvement\": \"Expected impact (e.g., O(n^2) -> O(n log n))\"\n }\n ],\n \"summary\": \"Overall optimization potential\"\n}";
21
+ //# sourceMappingURL=ai-review.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-review.d.ts","sourceRoot":"","sources":["../../src/lib/ai-review.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,WAAW,GAAG,QAAQ,CAAC;IACjC,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C;AA2FD,wBAAsB,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAUhG;AAID,eAAO,MAAM,kBAAkB,2zBAuB7B,CAAC;AAEH,eAAO,MAAM,oBAAoB,4WAGwD,CAAC;AAE1F,eAAO,MAAM,mBAAmB,0uBAoB9B,CAAC;AAEH,eAAO,MAAM,sBAAsB,4kCA6BjC,CAAC;AAEH,eAAO,MAAM,oBAAoB,w3BAoB/B,CAAC"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * AI integration for pro-tier tools.
3
+ * Supports Anthropic (Claude) and OpenAI (GPT) APIs.
4
+ * Uses the customer's own API key.
5
+ */
6
+ function detectProvider() {
7
+ const anthropicKey = process.env.ANTHROPIC_API_KEY;
8
+ if (anthropicKey) {
9
+ return { provider: 'anthropic', key: anthropicKey };
10
+ }
11
+ const openaiKey = process.env.OPENAI_API_KEY;
12
+ if (openaiKey) {
13
+ return { provider: 'openai', key: openaiKey };
14
+ }
15
+ return null;
16
+ }
17
+ async function callAnthropic(systemPrompt, userPrompt, key) {
18
+ const response = await fetch('https://api.anthropic.com/v1/messages', {
19
+ method: 'POST',
20
+ headers: {
21
+ 'Content-Type': 'application/json',
22
+ 'x-api-key': key,
23
+ 'anthropic-version': '2023-06-01',
24
+ },
25
+ body: JSON.stringify({
26
+ model: 'claude-sonnet-4-20250514',
27
+ max_tokens: 4096,
28
+ system: systemPrompt,
29
+ messages: [{ role: 'user', content: userPrompt }],
30
+ }),
31
+ signal: AbortSignal.timeout(60000),
32
+ });
33
+ if (!response.ok) {
34
+ const error = await response.text();
35
+ throw new Error(`Anthropic API error (${response.status}): ${error}`);
36
+ }
37
+ const body = await response.json();
38
+ return {
39
+ content: body.content.map(c => c.text).join('\n'),
40
+ model: body.model,
41
+ provider: 'anthropic',
42
+ tokensUsed: { input: body.usage.input_tokens, output: body.usage.output_tokens },
43
+ };
44
+ }
45
+ async function callOpenAI(systemPrompt, userPrompt, key) {
46
+ const response = await fetch('https://api.openai.com/v1/chat/completions', {
47
+ method: 'POST',
48
+ headers: {
49
+ 'Content-Type': 'application/json',
50
+ 'Authorization': `Bearer ${key}`,
51
+ },
52
+ body: JSON.stringify({
53
+ model: 'gpt-4o',
54
+ max_tokens: 4096,
55
+ messages: [
56
+ { role: 'system', content: systemPrompt },
57
+ { role: 'user', content: userPrompt },
58
+ ],
59
+ }),
60
+ signal: AbortSignal.timeout(60000),
61
+ });
62
+ if (!response.ok) {
63
+ const error = await response.text();
64
+ throw new Error(`OpenAI API error (${response.status}): ${error}`);
65
+ }
66
+ const body = await response.json();
67
+ return {
68
+ content: body.choices[0]?.message.content ?? '',
69
+ model: body.model,
70
+ provider: 'openai',
71
+ tokensUsed: { input: body.usage.prompt_tokens, output: body.usage.completion_tokens },
72
+ };
73
+ }
74
+ export async function aiReview(systemPrompt, userPrompt) {
75
+ const creds = detectProvider();
76
+ if (!creds) {
77
+ throw new Error('No AI API key found. Set ANTHROPIC_API_KEY or OPENAI_API_KEY.');
78
+ }
79
+ if (creds.provider === 'anthropic') {
80
+ return callAnthropic(systemPrompt, userPrompt, creds.key);
81
+ }
82
+ return callOpenAI(systemPrompt, userPrompt, creds.key);
83
+ }
84
+ // ── Prompt templates ────────────────────────────────────────────────
85
+ export const DEEP_REVIEW_SYSTEM = `You are an expert code reviewer. Provide a comprehensive code review covering:
86
+ 1. Architecture and design quality
87
+ 2. Security vulnerabilities
88
+ 3. Performance concerns
89
+ 4. Error handling completeness
90
+ 5. Code clarity and maintainability
91
+ 6. Edge cases and potential bugs
92
+
93
+ Format your response as JSON with this structure:
94
+ {
95
+ "summary": "Overall assessment (2-3 sentences)",
96
+ "score": <1-10>,
97
+ "findings": [
98
+ {
99
+ "category": "security|performance|architecture|maintainability|bug|error_handling",
100
+ "severity": "critical|high|medium|low|info",
101
+ "title": "Short title",
102
+ "description": "Detailed explanation",
103
+ "suggestion": "How to fix it",
104
+ "line_hint": "relevant code snippet or null"
105
+ }
106
+ ],
107
+ "positives": ["Things done well"]
108
+ }`;
109
+ export const SUGGEST_TESTS_SYSTEM = `You are a test engineering expert. Given source code, generate comprehensive test cases.
110
+ Write complete, runnable test code (not pseudocode) using the specified test framework.
111
+ Cover: happy paths, edge cases, error conditions, boundary values, and integration points.
112
+ Return ONLY the test file content, ready to save and run. Include all necessary imports.`;
113
+ export const EXPLAIN_CODE_SYSTEM = `You are a technical writer and code documentation expert.
114
+ Given source code, provide:
115
+ 1. A high-level explanation of what the code does and why
116
+ 2. Detailed inline documentation (docstrings/JSDoc for each function)
117
+ 3. A summary of the data flow and key algorithms
118
+ 4. Any non-obvious design decisions or trade-offs
119
+
120
+ Format your response as JSON:
121
+ {
122
+ "summary": "What this code does (2-3 sentences)",
123
+ "purpose": "Why this code exists",
124
+ "functions": [
125
+ {
126
+ "name": "function_name",
127
+ "docstring": "Complete docstring/JSDoc",
128
+ "explanation": "What it does and how"
129
+ }
130
+ ],
131
+ "data_flow": "How data moves through the code",
132
+ "design_notes": ["Important design decisions"]
133
+ }`;
134
+ export const SECURITY_REVIEW_SYSTEM = `You are a security engineer specializing in application security (OWASP Top 10, CWE).
135
+ Perform a focused security review of the provided code.
136
+
137
+ For each finding, include:
138
+ - CWE ID and name
139
+ - OWASP category if applicable
140
+ - Severity (critical/high/medium/low)
141
+ - Detailed description of the vulnerability
142
+ - Proof of concept or attack scenario
143
+ - Specific remediation steps with code examples
144
+
145
+ Format your response as JSON:
146
+ {
147
+ "risk_level": "critical|high|medium|low|none",
148
+ "findings": [
149
+ {
150
+ "title": "Vulnerability title",
151
+ "cwe_id": "CWE-XXX",
152
+ "cwe_name": "CWE Name",
153
+ "owasp_category": "A01:2021 or null",
154
+ "severity": "critical|high|medium|low",
155
+ "description": "Detailed description",
156
+ "attack_scenario": "How this could be exploited",
157
+ "remediation": "How to fix with code example",
158
+ "affected_lines": "Line numbers or code snippet"
159
+ }
160
+ ],
161
+ "positive_practices": ["Security measures already in place"],
162
+ "recommendations": ["General security improvements"]
163
+ }`;
164
+ export const OPTIMIZE_CODE_SYSTEM = `You are a performance optimization expert. Analyze code for optimization opportunities.
165
+ Focus on: algorithmic complexity, memory usage, I/O efficiency, caching opportunities, and language-specific optimizations.
166
+
167
+ For each optimization, show the before and after code.
168
+
169
+ Format your response as JSON:
170
+ {
171
+ "current_assessment": "Brief assessment of current performance characteristics",
172
+ "optimizations": [
173
+ {
174
+ "title": "Optimization title",
175
+ "category": "algorithm|memory|io|caching|language_specific",
176
+ "impact": "high|medium|low",
177
+ "description": "What the optimization does and why",
178
+ "before": "Current code snippet",
179
+ "after": "Optimized code snippet",
180
+ "expected_improvement": "Expected impact (e.g., O(n^2) -> O(n log n))"
181
+ }
182
+ ],
183
+ "summary": "Overall optimization potential"
184
+ }`;
185
+ //# sourceMappingURL=ai-review.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-review.js","sourceRoot":"","sources":["../../src/lib/ai-review.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,SAAS,cAAc;IACrB,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IACnD,IAAI,YAAY,EAAE,CAAC;QACjB,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC;IACtD,CAAC;IAED,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAC7C,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;IAChD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,KAAK,UAAU,aAAa,CAAC,YAAoB,EAAE,UAAkB,EAAE,GAAW;IAChF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,uCAAuC,EAAE;QACpE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,WAAW,EAAE,GAAG;YAChB,mBAAmB,EAAE,YAAY;SAClC;QACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC;YACnB,KAAK,EAAE,0BAA0B;YACjC,UAAU,EAAE,IAAI;YAChB,MAAM,EAAE,YAAY;YACpB,QAAQ,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;SAClD,CAAC;QACF,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC;KACnC,CAAC,CAA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;;;;;;;;;;;;;;;;;;;;;;EA6BpC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;EAoBlC,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Cyclomatic complexity calculator.
3
+ * Uses regex-based analysis (not AST) for JS/TS, Python, Go.
4
+ * Counts decision points: if, else if, for, while, switch case, &&, ||, ternary, catch, etc.
5
+ */
6
+ export interface FunctionComplexity {
7
+ name: string;
8
+ startLine: number;
9
+ endLine: number;
10
+ complexity: number;
11
+ rating: 'simple' | 'moderate' | 'complex' | 'very_complex';
12
+ }
13
+ export interface ComplexityResult {
14
+ functions: FunctionComplexity[];
15
+ overall: number;
16
+ averagePerFunction: number;
17
+ rating: 'simple' | 'moderate' | 'complex' | 'very_complex';
18
+ }
19
+ export declare function calculateComplexity(code: string, language: string): ComplexityResult;
20
+ //# sourceMappingURL=complexity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"complexity.d.ts","sourceRoot":"","sources":["../../src/lib/complexity.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,cAAc,CAAC;CAC5D;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,QAAQ,GAAG,UAAU,GAAG,SAAS,GAAG,cAAc,CAAC;CAC5D;AAuND,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAiDpF"}