@defai.digital/review-domain 13.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +214 -0
- package/dist/comment-builder.d.ts +34 -0
- package/dist/comment-builder.d.ts.map +1 -0
- package/dist/comment-builder.js +171 -0
- package/dist/comment-builder.js.map +1 -0
- package/dist/focus-modes.d.ts +39 -0
- package/dist/focus-modes.d.ts.map +1 -0
- package/dist/focus-modes.js +241 -0
- package/dist/focus-modes.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/markdown-formatter.d.ts +16 -0
- package/dist/markdown-formatter.d.ts.map +1 -0
- package/dist/markdown-formatter.js +183 -0
- package/dist/markdown-formatter.js.map +1 -0
- package/dist/review-service.d.ts +68 -0
- package/dist/review-service.d.ts.map +1 -0
- package/dist/review-service.js +281 -0
- package/dist/review-service.js.map +1 -0
- package/dist/sarif-formatter.d.ts +21 -0
- package/dist/sarif-formatter.d.ts.map +1 -0
- package/dist/sarif-formatter.js +139 -0
- package/dist/sarif-formatter.js.map +1 -0
- package/dist/types.d.ts +91 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Focus Mode Prompts
|
|
3
|
+
*
|
|
4
|
+
* Specialized prompts for each review focus mode.
|
|
5
|
+
* INV-REV-001: Each focus mode MUST only report issues relevant to that focus.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Focus-specific system prompts
|
|
9
|
+
* Each prompt instructs the LLM to focus on specific categories of issues.
|
|
10
|
+
*/
|
|
11
|
+
export const FOCUS_MODE_PROMPTS = {
|
|
12
|
+
security: `You are a security-focused code reviewer. Analyze for:
|
|
13
|
+
- Injection vulnerabilities (SQL, XSS, command injection, LDAP injection)
|
|
14
|
+
- Authentication/authorization issues (broken auth, insecure sessions)
|
|
15
|
+
- Sensitive data exposure (PII leaks, hardcoded credentials, logging secrets)
|
|
16
|
+
- Insecure cryptography (weak algorithms, improper key management)
|
|
17
|
+
- Security misconfigurations (CORS, headers, permissions)
|
|
18
|
+
- OWASP Top 10 vulnerabilities
|
|
19
|
+
- Input validation failures
|
|
20
|
+
- Insecure deserialization
|
|
21
|
+
|
|
22
|
+
Only report security-related issues. Ignore style, naming, or general code quality.
|
|
23
|
+
Tag all comments with category starting with "security/".`,
|
|
24
|
+
architecture: `You are an architecture-focused code reviewer. Analyze for:
|
|
25
|
+
- Single Responsibility Principle violations (classes/functions doing too much)
|
|
26
|
+
- High coupling between modules (tight dependencies, circular imports)
|
|
27
|
+
- Dependency inversion issues (high-level depending on low-level)
|
|
28
|
+
- Circular dependencies
|
|
29
|
+
- God classes/functions (doing too much)
|
|
30
|
+
- Missing abstraction layers
|
|
31
|
+
- Improper separation of concerns
|
|
32
|
+
- Leaky abstractions
|
|
33
|
+
- Interface segregation violations
|
|
34
|
+
- Improper layering (presentation touching data directly)
|
|
35
|
+
|
|
36
|
+
Only report architectural issues. Ignore security, performance, or style issues.
|
|
37
|
+
Tag all comments with category starting with "architecture/".`,
|
|
38
|
+
performance: `You are a performance-focused code reviewer. Analyze for:
|
|
39
|
+
- N+1 query patterns (database queries in loops)
|
|
40
|
+
- Memory leaks (unclosed resources, event listeners not removed)
|
|
41
|
+
- Unnecessary re-renders or re-computations
|
|
42
|
+
- Expensive operations in loops (sorting, regex compilation)
|
|
43
|
+
- Missing caching opportunities
|
|
44
|
+
- Blocking operations in async contexts
|
|
45
|
+
- O(n²) or worse algorithms where O(n) is possible
|
|
46
|
+
- Unnecessary object creation in hot paths
|
|
47
|
+
- String concatenation in loops
|
|
48
|
+
- Unbounded collections growth
|
|
49
|
+
|
|
50
|
+
Only report performance issues. Ignore security, architecture, or style issues.
|
|
51
|
+
Tag all comments with category starting with "performance/".`,
|
|
52
|
+
maintainability: `You are a maintainability-focused code reviewer. Analyze for:
|
|
53
|
+
- Code duplication (DRY violations, copy-paste code)
|
|
54
|
+
- Poor naming (unclear variable/function names, abbreviations)
|
|
55
|
+
- Missing or inadequate documentation
|
|
56
|
+
- Complex conditionals (deeply nested, long chains)
|
|
57
|
+
- Magic numbers/strings without constants
|
|
58
|
+
- Dead code or unreachable branches
|
|
59
|
+
- Inconsistent patterns within the codebase
|
|
60
|
+
- Long functions/methods (>50 lines)
|
|
61
|
+
- Too many parameters (>5)
|
|
62
|
+
- Complex boolean expressions
|
|
63
|
+
|
|
64
|
+
Only report maintainability issues. Ignore security, performance, or architecture issues.
|
|
65
|
+
Tag all comments with category starting with "maintainability/".`,
|
|
66
|
+
correctness: `You are a correctness-focused code reviewer. Analyze for:
|
|
67
|
+
- Logic errors and off-by-one mistakes
|
|
68
|
+
- Null/undefined handling issues (missing null checks, optional chaining)
|
|
69
|
+
- Race conditions (async ordering, shared state)
|
|
70
|
+
- Error handling gaps (uncaught exceptions, unhandled rejections)
|
|
71
|
+
- Type mismatches or unsafe casts
|
|
72
|
+
- Edge cases not handled (empty arrays, zero values)
|
|
73
|
+
- Incorrect assumptions in comments vs code
|
|
74
|
+
- Integer overflow/underflow
|
|
75
|
+
- Floating point precision issues
|
|
76
|
+
- Incorrect comparisons (== vs ===)
|
|
77
|
+
|
|
78
|
+
Only report correctness issues. Focus on bugs, not style or optimization.
|
|
79
|
+
Tag all comments with category starting with "correctness/".`,
|
|
80
|
+
all: `You are a comprehensive code reviewer. Analyze for issues in ALL categories:
|
|
81
|
+
|
|
82
|
+
SECURITY:
|
|
83
|
+
- Injection vulnerabilities, auth issues, data exposure, cryptography issues
|
|
84
|
+
|
|
85
|
+
ARCHITECTURE:
|
|
86
|
+
- SRP violations, high coupling, circular dependencies, missing abstractions
|
|
87
|
+
|
|
88
|
+
PERFORMANCE:
|
|
89
|
+
- N+1 queries, memory leaks, inefficient algorithms, blocking operations
|
|
90
|
+
|
|
91
|
+
MAINTAINABILITY:
|
|
92
|
+
- Code duplication, poor naming, complex conditionals, magic numbers
|
|
93
|
+
|
|
94
|
+
CORRECTNESS:
|
|
95
|
+
- Logic errors, null handling, race conditions, error handling gaps
|
|
96
|
+
|
|
97
|
+
Prioritize critical issues. Provide balanced coverage across all categories.
|
|
98
|
+
Tag comments with appropriate category prefixes (security/, architecture/, performance/, maintainability/, correctness/).`,
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Get the prompt for a specific focus mode
|
|
102
|
+
*/
|
|
103
|
+
export function getFocusModePrompt(focus) {
|
|
104
|
+
return FOCUS_MODE_PROMPTS[focus];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get the response format instructions
|
|
108
|
+
* This instructs the LLM how to format its response for parsing.
|
|
109
|
+
*/
|
|
110
|
+
export const RESPONSE_FORMAT_INSTRUCTIONS = `
|
|
111
|
+
Respond with a JSON array of review comments. Each comment must have:
|
|
112
|
+
{
|
|
113
|
+
"file": "path/to/file.ts",
|
|
114
|
+
"line": 42,
|
|
115
|
+
"lineEnd": 45, // optional, for multi-line issues
|
|
116
|
+
"severity": "critical", // one of: critical, warning, suggestion, note
|
|
117
|
+
"title": "Brief issue title (max 100 chars)",
|
|
118
|
+
"body": "Detailed explanation of the issue and why it matters",
|
|
119
|
+
"rationale": "Why this is important to fix", // optional but recommended
|
|
120
|
+
"suggestion": "How to fix this issue", // required for critical/warning
|
|
121
|
+
"suggestedCode": "code snippet showing the fix", // optional
|
|
122
|
+
"confidence": 0.95, // your confidence 0-1
|
|
123
|
+
"category": "security/sql-injection" // category with focus prefix
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
IMPORTANT:
|
|
127
|
+
- severity must be one of: critical, warning, suggestion, note
|
|
128
|
+
- critical/warning MUST include suggestion field
|
|
129
|
+
- body MUST explain WHY this matters
|
|
130
|
+
- confidence should reflect your certainty (0.0-1.0)
|
|
131
|
+
- Only report issues you are confident about
|
|
132
|
+
- Do not report style issues unless maintainability focus
|
|
133
|
+
|
|
134
|
+
Respond ONLY with the JSON array, no other text.
|
|
135
|
+
`;
|
|
136
|
+
/**
|
|
137
|
+
* Build the complete review prompt
|
|
138
|
+
*/
|
|
139
|
+
export function buildReviewPrompt(focus, fileContents, userContext) {
|
|
140
|
+
const focusPrompt = getFocusModePrompt(focus);
|
|
141
|
+
let prompt = `${focusPrompt}
|
|
142
|
+
|
|
143
|
+
${RESPONSE_FORMAT_INSTRUCTIONS}
|
|
144
|
+
|
|
145
|
+
`;
|
|
146
|
+
if (userContext) {
|
|
147
|
+
prompt += `Additional context from the user:
|
|
148
|
+
${userContext}
|
|
149
|
+
|
|
150
|
+
`;
|
|
151
|
+
}
|
|
152
|
+
prompt += `Files to review:
|
|
153
|
+
|
|
154
|
+
`;
|
|
155
|
+
for (const file of fileContents) {
|
|
156
|
+
prompt += `--- ${file.path} ---
|
|
157
|
+
${file.content}
|
|
158
|
+
|
|
159
|
+
`;
|
|
160
|
+
}
|
|
161
|
+
prompt += `
|
|
162
|
+
Now analyze these files and provide your review comments as a JSON array.`;
|
|
163
|
+
return prompt;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Categories allowed for each focus mode
|
|
167
|
+
* INV-REV-001: Used to validate that comments match their focus mode
|
|
168
|
+
*/
|
|
169
|
+
export const FOCUS_MODE_CATEGORIES = {
|
|
170
|
+
security: [
|
|
171
|
+
'security/injection',
|
|
172
|
+
'security/xss',
|
|
173
|
+
'security/sql-injection',
|
|
174
|
+
'security/command-injection',
|
|
175
|
+
'security/auth',
|
|
176
|
+
'security/authorization',
|
|
177
|
+
'security/data-exposure',
|
|
178
|
+
'security/cryptography',
|
|
179
|
+
'security/configuration',
|
|
180
|
+
'security/deserialization',
|
|
181
|
+
'security/validation',
|
|
182
|
+
'security/other',
|
|
183
|
+
],
|
|
184
|
+
architecture: [
|
|
185
|
+
'architecture/srp-violation',
|
|
186
|
+
'architecture/coupling',
|
|
187
|
+
'architecture/circular-dependency',
|
|
188
|
+
'architecture/god-class',
|
|
189
|
+
'architecture/abstraction',
|
|
190
|
+
'architecture/separation-of-concerns',
|
|
191
|
+
'architecture/layering',
|
|
192
|
+
'architecture/other',
|
|
193
|
+
],
|
|
194
|
+
performance: [
|
|
195
|
+
'performance/n-plus-one',
|
|
196
|
+
'performance/memory-leak',
|
|
197
|
+
'performance/re-render',
|
|
198
|
+
'performance/loop-operation',
|
|
199
|
+
'performance/caching',
|
|
200
|
+
'performance/blocking',
|
|
201
|
+
'performance/algorithm',
|
|
202
|
+
'performance/allocation',
|
|
203
|
+
'performance/other',
|
|
204
|
+
],
|
|
205
|
+
maintainability: [
|
|
206
|
+
'maintainability/duplication',
|
|
207
|
+
'maintainability/naming',
|
|
208
|
+
'maintainability/documentation',
|
|
209
|
+
'maintainability/complexity',
|
|
210
|
+
'maintainability/magic-number',
|
|
211
|
+
'maintainability/dead-code',
|
|
212
|
+
'maintainability/consistency',
|
|
213
|
+
'maintainability/long-function',
|
|
214
|
+
'maintainability/other',
|
|
215
|
+
],
|
|
216
|
+
correctness: [
|
|
217
|
+
'correctness/logic-error',
|
|
218
|
+
'correctness/null-handling',
|
|
219
|
+
'correctness/race-condition',
|
|
220
|
+
'correctness/error-handling',
|
|
221
|
+
'correctness/type-mismatch',
|
|
222
|
+
'correctness/edge-case',
|
|
223
|
+
'correctness/comparison',
|
|
224
|
+
'correctness/overflow',
|
|
225
|
+
'correctness/other',
|
|
226
|
+
],
|
|
227
|
+
all: [], // All categories allowed
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Check if a category is valid for a focus mode
|
|
231
|
+
* INV-REV-001: Validates focus mode isolation
|
|
232
|
+
*/
|
|
233
|
+
export function isCategoryValidForFocus(category, focus) {
|
|
234
|
+
if (focus === 'all') {
|
|
235
|
+
return true; // All categories allowed for 'all' focus
|
|
236
|
+
}
|
|
237
|
+
const allowedCategories = FOCUS_MODE_CATEGORIES[focus];
|
|
238
|
+
// Check exact match or prefix match
|
|
239
|
+
return allowedCategories.some((allowed) => category === allowed || category.startsWith(focus + '/'));
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=focus-modes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focus-modes.js","sourceRoot":"","sources":["../src/focus-modes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAgC;IAC7D,QAAQ,EAAE;;;;;;;;;;;0DAW8C;IAExD,YAAY,EAAE;;;;;;;;;;;;;8DAa8C;IAE5D,WAAW,EAAE;;;;;;;;;;;;;6DAa8C;IAE3D,eAAe,EAAE;;;;;;;;;;;;;iEAa8C;IAE/D,WAAW,EAAE;;;;;;;;;;;;;6DAa8C;IAE3D,GAAG,EAAE;;;;;;;;;;;;;;;;;;0HAkBmH;CACzH,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAkB;IACnD,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;CAyB3C,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAkB,EAClB,YAAiD,EACjD,WAAoB;IAEpB,MAAM,WAAW,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;IAE9C,IAAI,MAAM,GAAG,GAAG,WAAW;;EAE3B,4BAA4B;;CAE7B,CAAC;IAEA,IAAI,WAAW,EAAE,CAAC;QAChB,MAAM,IAAI;EACZ,WAAW;;CAEZ,CAAC;IACA,CAAC;IAED,MAAM,IAAI;;CAEX,CAAC;IAEA,KAAK,MAAM,IAAI,IAAI,YAAY,EAAE,CAAC;QAChC,MAAM,IAAI,OAAO,IAAI,CAAC,IAAI;EAC5B,IAAI,CAAC,OAAO;;CAEb,CAAC;IACA,CAAC;IAED,MAAM,IAAI;0EA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AAO,EAAE,EAAE,CAAC,QAAQ,KAAK,OAAO,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,GAAG,GAAG,CAAC,CACtE,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Review Domain
|
|
3
|
+
*
|
|
4
|
+
* AI-powered code review with focused analysis modes.
|
|
5
|
+
*/
|
|
6
|
+
export type { FileContent, ReviewContext, ParsedReviewResponse, ReviewServiceConfig, ReviewPromptExecutor, ReviewExecutionOptions, DryRunResult, } from './types.js';
|
|
7
|
+
export type { ReviewRequest, ReviewResult, ReviewComment, ReviewFocus, ReviewSummary, SarifOutput, } from './types.js';
|
|
8
|
+
export { FOCUS_MODE_PROMPTS, getFocusModePrompt, RESPONSE_FORMAT_INSTRUCTIONS, buildReviewPrompt, FOCUS_MODE_CATEGORIES, isCategoryValidForFocus, } from './focus-modes.js';
|
|
9
|
+
export { parseReviewResponse, filterCommentsByFocus, filterCommentsByConfidence, validateActionableSuggestions, generateCommentId, } from './comment-builder.js';
|
|
10
|
+
export { formatReviewAsMarkdown, formatCompactSummary } from './markdown-formatter.js';
|
|
11
|
+
export { formatReviewAsSarif, formatSarifAsJson, createEmptySarifReport, } from './sarif-formatter.js';
|
|
12
|
+
export { ReviewService, ReviewError, createReviewService } from './review-service.js';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EACV,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,aAAa,EACb,YAAY,EACZ,aAAa,EACb,WAAW,EACX,aAAa,EACb,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,4BAA4B,EAC5B,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,0BAA0B,EAC1B,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAGvF,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Review Domain
|
|
3
|
+
*
|
|
4
|
+
* AI-powered code review with focused analysis modes.
|
|
5
|
+
*/
|
|
6
|
+
// Focus Modes
|
|
7
|
+
export { FOCUS_MODE_PROMPTS, getFocusModePrompt, RESPONSE_FORMAT_INSTRUCTIONS, buildReviewPrompt, FOCUS_MODE_CATEGORIES, isCategoryValidForFocus, } from './focus-modes.js';
|
|
8
|
+
// Comment Builder
|
|
9
|
+
export { parseReviewResponse, filterCommentsByFocus, filterCommentsByConfidence, validateActionableSuggestions, generateCommentId, } from './comment-builder.js';
|
|
10
|
+
// Markdown Formatter
|
|
11
|
+
export { formatReviewAsMarkdown, formatCompactSummary } from './markdown-formatter.js';
|
|
12
|
+
// SARIF Formatter
|
|
13
|
+
export { formatReviewAsSarif, formatSarifAsJson, createEmptySarifReport, } from './sarif-formatter.js';
|
|
14
|
+
// Review Service
|
|
15
|
+
export { ReviewService, ReviewError, createReviewService } from './review-service.js';
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAuBH,cAAc;AACd,OAAO,EACL,kBAAkB,EAClB,kBAAkB,EAClB,4BAA4B,EAC5B,iBAAiB,EACjB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAE1B,kBAAkB;AAClB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,0BAA0B,EAC1B,6BAA6B,EAC7B,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAE9B,qBAAqB;AACrB,OAAO,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEvF,kBAAkB;AAClB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,GACvB,MAAM,sBAAsB,CAAC;AAE9B,iBAAiB;AACjB,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats review results as markdown output.
|
|
5
|
+
* INV-REV-OUT-001: Comments ordered by severity.
|
|
6
|
+
*/
|
|
7
|
+
import { type ReviewResult } from '@defai.digital/contracts';
|
|
8
|
+
/**
|
|
9
|
+
* Format review result as markdown
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatReviewAsMarkdown(result: ReviewResult): string;
|
|
12
|
+
/**
|
|
13
|
+
* Format a compact summary for CLI output
|
|
14
|
+
*/
|
|
15
|
+
export declare function formatCompactSummary(result: ReviewResult): string;
|
|
16
|
+
//# sourceMappingURL=markdown-formatter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-formatter.d.ts","sourceRoot":"","sources":["../src/markdown-formatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,KAAK,YAAY,EAGlB,MAAM,0BAA0B,CAAC;AAElC;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CA+GnE;AAkED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAqBjE"}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Markdown Formatter
|
|
3
|
+
*
|
|
4
|
+
* Formats review results as markdown output.
|
|
5
|
+
* INV-REV-OUT-001: Comments ordered by severity.
|
|
6
|
+
*/
|
|
7
|
+
import { sortCommentsBySeverity, } from '@defai.digital/contracts';
|
|
8
|
+
/**
|
|
9
|
+
* Format review result as markdown
|
|
10
|
+
*/
|
|
11
|
+
export function formatReviewAsMarkdown(result) {
|
|
12
|
+
const { summary, comments, filesReviewed, linesAnalyzed, durationMs, providerId } = result;
|
|
13
|
+
// Sort comments by severity (INV-REV-OUT-001)
|
|
14
|
+
const sortedComments = sortCommentsBySeverity(comments);
|
|
15
|
+
const lines = [];
|
|
16
|
+
// Header
|
|
17
|
+
lines.push('# Code Review Report');
|
|
18
|
+
lines.push('');
|
|
19
|
+
const focusMode = result.comments.length > 0 && result.comments[0] ? result.comments[0].focus : 'all';
|
|
20
|
+
lines.push(`**Focus:** ${focusMode} | ` +
|
|
21
|
+
`**Files:** ${filesReviewed.length} | ` +
|
|
22
|
+
`**Lines:** ${linesAnalyzed.toLocaleString()} | ` +
|
|
23
|
+
`**Duration:** ${formatDuration(durationMs)}`);
|
|
24
|
+
lines.push('');
|
|
25
|
+
// Summary table
|
|
26
|
+
lines.push('## Summary');
|
|
27
|
+
lines.push('');
|
|
28
|
+
lines.push('| Severity | Count |');
|
|
29
|
+
lines.push('|----------|-------|');
|
|
30
|
+
lines.push(`| Critical | ${summary.bySeverity.critical} |`);
|
|
31
|
+
lines.push(`| Warning | ${summary.bySeverity.warning} |`);
|
|
32
|
+
lines.push(`| Suggestion | ${summary.bySeverity.suggestion} |`);
|
|
33
|
+
lines.push(`| Note | ${summary.bySeverity.note} |`);
|
|
34
|
+
lines.push('');
|
|
35
|
+
lines.push(`**Health Score:** ${summary.healthScore}/100`);
|
|
36
|
+
lines.push(`**Verdict:** ${summary.verdict}`);
|
|
37
|
+
lines.push('');
|
|
38
|
+
// Provider info
|
|
39
|
+
lines.push(`*Reviewed by ${providerId}*`);
|
|
40
|
+
lines.push('');
|
|
41
|
+
if (sortedComments.length === 0) {
|
|
42
|
+
lines.push('---');
|
|
43
|
+
lines.push('');
|
|
44
|
+
lines.push('No issues found.');
|
|
45
|
+
return lines.join('\n');
|
|
46
|
+
}
|
|
47
|
+
// Group comments by severity
|
|
48
|
+
const critical = sortedComments.filter((c) => c.severity === 'critical');
|
|
49
|
+
const warnings = sortedComments.filter((c) => c.severity === 'warning');
|
|
50
|
+
const suggestions = sortedComments.filter((c) => c.severity === 'suggestion');
|
|
51
|
+
const notes = sortedComments.filter((c) => c.severity === 'note');
|
|
52
|
+
// Critical Issues
|
|
53
|
+
if (critical.length > 0) {
|
|
54
|
+
lines.push('---');
|
|
55
|
+
lines.push('');
|
|
56
|
+
lines.push('## Critical Issues');
|
|
57
|
+
lines.push('');
|
|
58
|
+
for (const comment of critical) {
|
|
59
|
+
lines.push(...formatComment(comment, 'CRITICAL'));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Warnings
|
|
63
|
+
if (warnings.length > 0) {
|
|
64
|
+
lines.push('---');
|
|
65
|
+
lines.push('');
|
|
66
|
+
lines.push('## Warnings');
|
|
67
|
+
lines.push('');
|
|
68
|
+
for (const comment of warnings) {
|
|
69
|
+
lines.push(...formatComment(comment, 'WARNING'));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Suggestions
|
|
73
|
+
if (suggestions.length > 0) {
|
|
74
|
+
lines.push('---');
|
|
75
|
+
lines.push('');
|
|
76
|
+
lines.push('## Suggestions');
|
|
77
|
+
lines.push('');
|
|
78
|
+
for (const comment of suggestions) {
|
|
79
|
+
lines.push(...formatComment(comment, 'SUGGESTION'));
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
// Notes
|
|
83
|
+
if (notes.length > 0) {
|
|
84
|
+
lines.push('---');
|
|
85
|
+
lines.push('');
|
|
86
|
+
lines.push('## Notes');
|
|
87
|
+
lines.push('');
|
|
88
|
+
for (const comment of notes) {
|
|
89
|
+
lines.push(...formatComment(comment, 'NOTE'));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Hotspots
|
|
93
|
+
if (summary.hotspots.length > 0) {
|
|
94
|
+
lines.push('---');
|
|
95
|
+
lines.push('');
|
|
96
|
+
lines.push('## File Hotspots');
|
|
97
|
+
lines.push('');
|
|
98
|
+
lines.push('Files with the most issues:');
|
|
99
|
+
lines.push('');
|
|
100
|
+
for (const hotspot of summary.hotspots) {
|
|
101
|
+
lines.push(`- \`${hotspot.file}\`: ${hotspot.commentCount} issue(s)`);
|
|
102
|
+
}
|
|
103
|
+
lines.push('');
|
|
104
|
+
}
|
|
105
|
+
return lines.join('\n');
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Format a single comment
|
|
109
|
+
*/
|
|
110
|
+
function formatComment(comment, badge) {
|
|
111
|
+
const lines = [];
|
|
112
|
+
// Title with severity badge
|
|
113
|
+
lines.push(`### [${badge}] ${comment.title}`);
|
|
114
|
+
// Location
|
|
115
|
+
const location = comment.lineEnd
|
|
116
|
+
? `\`${comment.file}:${comment.line}-${comment.lineEnd}\``
|
|
117
|
+
: `\`${comment.file}:${comment.line}\``;
|
|
118
|
+
lines.push(`**File:** ${location}`);
|
|
119
|
+
lines.push(`**Confidence:** ${Math.round(comment.confidence * 100)}%`);
|
|
120
|
+
lines.push(`**Category:** ${comment.category}`);
|
|
121
|
+
lines.push('');
|
|
122
|
+
// Body (explanation)
|
|
123
|
+
lines.push(comment.body);
|
|
124
|
+
lines.push('');
|
|
125
|
+
// Rationale (if present)
|
|
126
|
+
if (comment.rationale) {
|
|
127
|
+
lines.push('**Why this matters:**');
|
|
128
|
+
lines.push(comment.rationale);
|
|
129
|
+
lines.push('');
|
|
130
|
+
}
|
|
131
|
+
// Suggestion (if present)
|
|
132
|
+
if (comment.suggestion) {
|
|
133
|
+
lines.push('**Suggestion:**');
|
|
134
|
+
lines.push(comment.suggestion);
|
|
135
|
+
lines.push('');
|
|
136
|
+
}
|
|
137
|
+
// Suggested code (if present)
|
|
138
|
+
if (comment.suggestedCode) {
|
|
139
|
+
lines.push('**Suggested fix:**');
|
|
140
|
+
lines.push('```');
|
|
141
|
+
lines.push(comment.suggestedCode);
|
|
142
|
+
lines.push('```');
|
|
143
|
+
lines.push('');
|
|
144
|
+
}
|
|
145
|
+
return lines;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Format duration in human-readable format
|
|
149
|
+
*/
|
|
150
|
+
function formatDuration(ms) {
|
|
151
|
+
if (ms < 1000) {
|
|
152
|
+
return `${ms}ms`;
|
|
153
|
+
}
|
|
154
|
+
const seconds = Math.round(ms / 1000);
|
|
155
|
+
if (seconds < 60) {
|
|
156
|
+
return `${seconds}s`;
|
|
157
|
+
}
|
|
158
|
+
const minutes = Math.floor(seconds / 60);
|
|
159
|
+
const remainingSeconds = seconds % 60;
|
|
160
|
+
return `${minutes}m ${remainingSeconds}s`;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Format a compact summary for CLI output
|
|
164
|
+
*/
|
|
165
|
+
export function formatCompactSummary(result) {
|
|
166
|
+
const { summary, durationMs } = result;
|
|
167
|
+
const parts = [];
|
|
168
|
+
if (summary.bySeverity.critical > 0) {
|
|
169
|
+
parts.push(`${summary.bySeverity.critical} critical`);
|
|
170
|
+
}
|
|
171
|
+
if (summary.bySeverity.warning > 0) {
|
|
172
|
+
parts.push(`${summary.bySeverity.warning} warning`);
|
|
173
|
+
}
|
|
174
|
+
if (summary.bySeverity.suggestion > 0) {
|
|
175
|
+
parts.push(`${summary.bySeverity.suggestion} suggestion`);
|
|
176
|
+
}
|
|
177
|
+
if (summary.bySeverity.note > 0) {
|
|
178
|
+
parts.push(`${summary.bySeverity.note} note`);
|
|
179
|
+
}
|
|
180
|
+
const issuesSummary = parts.length > 0 ? parts.join(', ') : 'No issues';
|
|
181
|
+
return `${issuesSummary} | Health: ${summary.healthScore}/100 | ${formatDuration(durationMs)}`;
|
|
182
|
+
}
|
|
183
|
+
//# sourceMappingURL=markdown-formatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"markdown-formatter.js","sourceRoot":"","sources":["../src/markdown-formatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAGL,sBAAsB,GACvB,MAAM,0BAA0B,CAAC;AAElC;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAAoB;IACzD,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAE3F,8CAA8C;IAC9C,MAAM,cAAc,GAAG,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IAExD,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,SAAS;IACT,KAAK,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACnC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,MAAM,SAAS,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IACtG,KAAK,CAAC,IAAI,CACR,cAAc,SAAS,KAAK;QAC1B,cAAc,aAAa,CAAC,MAAM,KAAK;QACvC,cAAc,aAAa,CAAC,cAAc,EAAE,KAAK;QACjD,iBAAiB,cAAc,CAAC,UAAU,CAAC,EAAE,CAChD,CAAC;IACF,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEf,gBA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INV-REV-OPS-002: Provider Fallback
|
|
8
|
+
*/
|
|
9
|
+
import { type ReviewRequest, type ReviewResult } from '@defai.digital/contracts';
|
|
10
|
+
import type { ReviewServiceConfig, ReviewPromptExecutor, ReviewExecutionOptions, DryRunResult } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Review service for orchestrating AI code review
|
|
13
|
+
*/
|
|
14
|
+
export declare class ReviewService {
|
|
15
|
+
private readonly config;
|
|
16
|
+
private readonly promptExecutor;
|
|
17
|
+
constructor(config?: ReviewServiceConfig, promptExecutor?: ReviewPromptExecutor);
|
|
18
|
+
/**
|
|
19
|
+
* Execute a code review
|
|
20
|
+
* INV-REV-OPS-001: Reviews MUST complete or fail within configured timeout
|
|
21
|
+
*/
|
|
22
|
+
review(request: ReviewRequest, options?: ReviewExecutionOptions): Promise<ReviewResult>;
|
|
23
|
+
/**
|
|
24
|
+
* Execute dry run - show what would be analyzed
|
|
25
|
+
*/
|
|
26
|
+
dryRun(request: ReviewRequest): Promise<DryRunResult>;
|
|
27
|
+
/**
|
|
28
|
+
* Format result based on output format
|
|
29
|
+
*/
|
|
30
|
+
formatResult(result: ReviewResult, format: 'markdown' | 'json' | 'sarif'): string;
|
|
31
|
+
/**
|
|
32
|
+
* Get compact summary for CLI
|
|
33
|
+
*/
|
|
34
|
+
getCompactSummary(result: ReviewResult): string;
|
|
35
|
+
/**
|
|
36
|
+
* Collect files from paths
|
|
37
|
+
*/
|
|
38
|
+
private collectFiles;
|
|
39
|
+
/**
|
|
40
|
+
* Recursively collect files from directory
|
|
41
|
+
*/
|
|
42
|
+
private collectFromDirectory;
|
|
43
|
+
/**
|
|
44
|
+
* Read a single file
|
|
45
|
+
*/
|
|
46
|
+
private readFile;
|
|
47
|
+
/**
|
|
48
|
+
* Execute prompt with timeout
|
|
49
|
+
* INV-REV-OPS-001: Timeout Handling
|
|
50
|
+
*/
|
|
51
|
+
private executeWithTimeout;
|
|
52
|
+
/**
|
|
53
|
+
* Create empty result for dry run
|
|
54
|
+
*/
|
|
55
|
+
private createEmptyResult;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Review error with error code
|
|
59
|
+
*/
|
|
60
|
+
export declare class ReviewError extends Error {
|
|
61
|
+
readonly code: string;
|
|
62
|
+
constructor(code: string, message: string);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create a review service instance
|
|
66
|
+
*/
|
|
67
|
+
export declare function createReviewService(config?: ReviewServiceConfig, promptExecutor?: ReviewPromptExecutor): ReviewService;
|
|
68
|
+
//# sourceMappingURL=review-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"review-service.d.ts","sourceRoot":"","sources":["../src/review-service.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,YAAY,EAKlB,MAAM,0BAA0B,CAAC;AAKlC,OAAO,KAAK,EAEV,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,YAAY,EACb,MAAM,YAAY,CAAC;AAWpB;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAmC;gBAEtD,MAAM,CAAC,EAAE,mBAAmB,EAAE,cAAc,CAAC,EAAE,oBAAoB;IAK/E;;;OAGG;IACG,MAAM,CACV,OAAO,EAAE,aAAa,EACtB,OAAO,CAAC,EAAE,sBAAsB,GAC/B,OAAO,CAAC,YAAY,CAAC;IA8DxB;;OAEG;IACG,MAAM,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IAW3D;;OAEG;IACH,YAAY,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM;IAWjF;;OAEG;IACH,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM;IAI/C;;OAEG;YACW,Y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