@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
package/LICENSE
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
AutomatosX Open Source Edition - Apache License 2.0
|
|
2
|
+
|
|
3
|
+
This license applies ONLY to the AutomatosX Open Source Edition code
|
|
4
|
+
published on GitHub at https://github.com/defai-digital/automatosx
|
|
5
|
+
|
|
6
|
+
This license does NOT apply to:
|
|
7
|
+
- AutomatosX Pro Edition (proprietary software - separate EULA)
|
|
8
|
+
- AutomatosX Enterprise Edition (proprietary software - separate agreement)
|
|
9
|
+
|
|
10
|
+
For commercial editions, see COMMERCIAL-LICENSE.md
|
|
11
|
+
|
|
12
|
+
===============================================================================
|
|
13
|
+
|
|
14
|
+
Apache License
|
|
15
|
+
Version 2.0, January 2004
|
|
16
|
+
http://www.apache.org/licenses/
|
|
17
|
+
|
|
18
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
19
|
+
|
|
20
|
+
1. Definitions.
|
|
21
|
+
|
|
22
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
23
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
24
|
+
|
|
25
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
26
|
+
the copyright owner that is granting the License.
|
|
27
|
+
|
|
28
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
29
|
+
other entities that control, are controlled by, or are under common
|
|
30
|
+
control with that entity. For the purposes of this definition,
|
|
31
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
32
|
+
direction or management of such entity, whether by contract or
|
|
33
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
34
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
35
|
+
|
|
36
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
37
|
+
exercising permissions granted by this License.
|
|
38
|
+
|
|
39
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
40
|
+
including but not limited to software source code, documentation
|
|
41
|
+
source, and configuration files.
|
|
42
|
+
|
|
43
|
+
"Object" form shall mean any form resulting from mechanical
|
|
44
|
+
transformation or translation of a Source form, including but
|
|
45
|
+
not limited to compiled object code, generated documentation,
|
|
46
|
+
and conversions to other media types.
|
|
47
|
+
|
|
48
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
49
|
+
Object form, made available under the License, as indicated by a
|
|
50
|
+
copyright notice that is included in or attached to the work
|
|
51
|
+
(an example is provided in the Appendix below).
|
|
52
|
+
|
|
53
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
54
|
+
form, that is based on (or derived from) the Work and for which the
|
|
55
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
56
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
57
|
+
of this License, Derivative Works shall not include works that remain
|
|
58
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
59
|
+
the Work and Derivative Works thereof.
|
|
60
|
+
|
|
61
|
+
"Contribution" shall mean any work of authorship, including
|
|
62
|
+
the original version of the Work and any modifications or additions
|
|
63
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
64
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
65
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
66
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
67
|
+
means any form of electronic, verbal, or written communication sent
|
|
68
|
+
to the Licensor or its representatives, including but not limited to
|
|
69
|
+
communication on electronic mailing lists, source code control systems,
|
|
70
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
71
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
72
|
+
excluding communication that is conspicuously marked or otherwise
|
|
73
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
74
|
+
|
|
75
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
76
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
77
|
+
subsequently incorporated within the Work.
|
|
78
|
+
|
|
79
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
80
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
81
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
82
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
83
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
84
|
+
Work and such Derivative Works in Source or Object form.
|
|
85
|
+
|
|
86
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
87
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
88
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
89
|
+
(except as stated in this section) patent license to make, have made,
|
|
90
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
91
|
+
where such license applies only to those patent claims licensable
|
|
92
|
+
by such Contributor that are necessarily infringed by their
|
|
93
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
94
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
95
|
+
institute patent litigation against any entity (including a
|
|
96
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
97
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
98
|
+
or contributory patent infringement, then any patent licenses
|
|
99
|
+
granted to You under this License for that Work shall terminate
|
|
100
|
+
as of the date such litigation is filed.
|
|
101
|
+
|
|
102
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
103
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
104
|
+
modifications, and in Source or Object form, provided that You
|
|
105
|
+
meet the following conditions:
|
|
106
|
+
|
|
107
|
+
(a) You must give any other recipients of the Work or
|
|
108
|
+
Derivative Works a copy of this License; and
|
|
109
|
+
|
|
110
|
+
(b) You must cause any modified files to carry prominent notices
|
|
111
|
+
stating that You changed the files; and
|
|
112
|
+
|
|
113
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
114
|
+
that You distribute, all copyright, patent, trademark, and
|
|
115
|
+
attribution notices from the Source form of the Work,
|
|
116
|
+
excluding those notices that do not pertain to any part of
|
|
117
|
+
the Derivative Works; and
|
|
118
|
+
|
|
119
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
120
|
+
distribution, then any Derivative Works that You distribute must
|
|
121
|
+
include a readable copy of the attribution notices contained
|
|
122
|
+
within such NOTICE file, excluding those notices that do not
|
|
123
|
+
pertain to any part of the Derivative Works, in at least one
|
|
124
|
+
of the following places: within a NOTICE text file distributed
|
|
125
|
+
as part of the Derivative Works; within the Source form or
|
|
126
|
+
documentation, if provided along with the Derivative Works; or,
|
|
127
|
+
within a display generated by the Derivative Works, if and
|
|
128
|
+
wherever such third-party notices normally appear. The contents
|
|
129
|
+
of the NOTICE file are for informational purposes only and
|
|
130
|
+
do not modify the License. You may add Your own attribution
|
|
131
|
+
notices within Derivative Works that You distribute, alongside
|
|
132
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
133
|
+
that such additional attribution notices cannot be construed
|
|
134
|
+
as modifying the License.
|
|
135
|
+
|
|
136
|
+
You may add Your own copyright statement to Your modifications and
|
|
137
|
+
may provide additional or different license terms and conditions
|
|
138
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
139
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
140
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
141
|
+
the conditions stated in this License.
|
|
142
|
+
|
|
143
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
144
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
145
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
146
|
+
this License, without any additional terms or conditions.
|
|
147
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
148
|
+
the terms of any separate license agreement you may have executed
|
|
149
|
+
with Licensor regarding such Contributions.
|
|
150
|
+
|
|
151
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
152
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
153
|
+
except as required for reasonable and customary use in describing the
|
|
154
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
155
|
+
|
|
156
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
157
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
158
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
159
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
160
|
+
implied, including, without limitation, any warranties or conditions
|
|
161
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
162
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
163
|
+
appropriateness of using or redistributing the Work and assume any
|
|
164
|
+
risks associated with Your exercise of permissions under this License.
|
|
165
|
+
|
|
166
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
167
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
168
|
+
unless required by applicable law (such as deliberate and grossly
|
|
169
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
170
|
+
liable to You for damages, including any direct, indirect, special,
|
|
171
|
+
incidental, or consequential damages of any character arising as a
|
|
172
|
+
result of this License or out of the use or inability to use the
|
|
173
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
174
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
175
|
+
other commercial damages or losses), even if such Contributor
|
|
176
|
+
has been advised of the possibility of such damages.
|
|
177
|
+
|
|
178
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
179
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
180
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
181
|
+
or other liability obligations and/or rights consistent with this
|
|
182
|
+
License. However, in accepting such obligations, You may act only
|
|
183
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
184
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
185
|
+
defend, and hold each Contributor harmless for any liability
|
|
186
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
187
|
+
of your accepting any such warranty or additional liability.
|
|
188
|
+
|
|
189
|
+
END OF TERMS AND CONDITIONS
|
|
190
|
+
|
|
191
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
192
|
+
|
|
193
|
+
To apply the Apache License to your work, attach the following
|
|
194
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
195
|
+
replaced with your own identifying information. (Don't include
|
|
196
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
197
|
+
comment syntax for the file format. We also recommend that a
|
|
198
|
+
file or class name and description of purpose be included on the
|
|
199
|
+
same "printed page" as the copyright notice for easier
|
|
200
|
+
identification within third-party archives.
|
|
201
|
+
|
|
202
|
+
Copyright 2024-2025 DEFAI Private Limited
|
|
203
|
+
|
|
204
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
205
|
+
you may not use this file except in compliance with the License.
|
|
206
|
+
You may obtain a copy of the License at
|
|
207
|
+
|
|
208
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
209
|
+
|
|
210
|
+
Unless required by applicable law or agreed to in writing, software
|
|
211
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
212
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
213
|
+
See the License for the specific language governing permissions and
|
|
214
|
+
limitations under the License.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comment Builder
|
|
3
|
+
*
|
|
4
|
+
* Parses LLM responses and builds validated review comments.
|
|
5
|
+
* Enforces INV-REV-002 (Confidence Filtering), INV-REV-003 (Explanation Required),
|
|
6
|
+
* and INV-REV-004 (Actionable Suggestions).
|
|
7
|
+
*/
|
|
8
|
+
import { type ReviewComment, type ReviewFocus } from '@defai.digital/contracts';
|
|
9
|
+
import type { ParsedReviewResponse } from './types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Parse LLM response into review comments
|
|
12
|
+
* Validates against schema and enforces invariants
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseReviewResponse(response: string, focus: ReviewFocus, minConfidence: number): ParsedReviewResponse;
|
|
15
|
+
/**
|
|
16
|
+
* Filter comments by focus mode
|
|
17
|
+
* INV-REV-001: Focus Mode Isolation
|
|
18
|
+
*/
|
|
19
|
+
export declare function filterCommentsByFocus(comments: ReviewComment[], focus: ReviewFocus): ReviewComment[];
|
|
20
|
+
/**
|
|
21
|
+
* Filter comments by confidence threshold
|
|
22
|
+
* INV-REV-002: Confidence Filtering
|
|
23
|
+
*/
|
|
24
|
+
export declare function filterCommentsByConfidence(comments: ReviewComment[], minConfidence: number): ReviewComment[];
|
|
25
|
+
/**
|
|
26
|
+
* Validate that critical/warning comments have suggestions
|
|
27
|
+
* INV-REV-004: Actionable Suggestions
|
|
28
|
+
*/
|
|
29
|
+
export declare function validateActionableSuggestions(comments: ReviewComment[]): {
|
|
30
|
+
valid: boolean;
|
|
31
|
+
invalidComments: ReviewComment[];
|
|
32
|
+
};
|
|
33
|
+
export { v4 as generateCommentId } from 'uuid';
|
|
34
|
+
//# sourceMappingURL=comment-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment-builder.d.ts","sourceRoot":"","sources":["../src/comment-builder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,WAAW,EAGjB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAmBvD;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,WAAW,EAClB,aAAa,EAAE,MAAM,GACpB,oBAAoB,CAqDtB;AAsFD;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,aAAa,EAAE,EACzB,KAAK,EAAE,WAAW,GACjB,aAAa,EAAE,CASjB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,aAAa,EAAE,EACzB,aAAa,EAAE,MAAM,GACpB,aAAa,EAAE,CAEjB;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,aAAa,EAAE,GACxB;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,eAAe,EAAE,aAAa,EAAE,CAAA;CAAE,CAUtD;AAGD,OAAO,EAAE,EAAE,IAAI,iBAAiB,EAAE,MAAM,MAAM,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comment Builder
|
|
3
|
+
*
|
|
4
|
+
* Parses LLM responses and builds validated review comments.
|
|
5
|
+
* Enforces INV-REV-002 (Confidence Filtering), INV-REV-003 (Explanation Required),
|
|
6
|
+
* and INV-REV-004 (Actionable Suggestions).
|
|
7
|
+
*/
|
|
8
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
9
|
+
import { ReviewCommentSchema, ReviewCommentSeveritySchema, } from '@defai.digital/contracts';
|
|
10
|
+
import { isCategoryValidForFocus } from './focus-modes.js';
|
|
11
|
+
/**
|
|
12
|
+
* Parse LLM response into review comments
|
|
13
|
+
* Validates against schema and enforces invariants
|
|
14
|
+
*/
|
|
15
|
+
export function parseReviewResponse(response, focus, minConfidence) {
|
|
16
|
+
const errors = [];
|
|
17
|
+
const comments = [];
|
|
18
|
+
// Try to extract JSON array from response
|
|
19
|
+
let rawComments;
|
|
20
|
+
try {
|
|
21
|
+
// Handle responses that might have text before/after JSON
|
|
22
|
+
const jsonMatch = /\[[\s\S]*\]/.exec(response);
|
|
23
|
+
if (!jsonMatch) {
|
|
24
|
+
return {
|
|
25
|
+
comments: [],
|
|
26
|
+
success: false,
|
|
27
|
+
errors: ['No JSON array found in response'],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
rawComments = JSON.parse(jsonMatch[0]);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
return {
|
|
34
|
+
comments: [],
|
|
35
|
+
success: false,
|
|
36
|
+
errors: [`Failed to parse JSON: ${e instanceof Error ? e.message : 'Unknown error'}`],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (!Array.isArray(rawComments)) {
|
|
40
|
+
return {
|
|
41
|
+
comments: [],
|
|
42
|
+
success: false,
|
|
43
|
+
errors: ['Response is not an array'],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
for (let i = 0; i < rawComments.length; i++) {
|
|
47
|
+
const raw = rawComments[i];
|
|
48
|
+
if (!raw)
|
|
49
|
+
continue;
|
|
50
|
+
const result = buildComment(raw, focus, minConfidence);
|
|
51
|
+
if (result.success && result.comment) {
|
|
52
|
+
comments.push(result.comment);
|
|
53
|
+
}
|
|
54
|
+
else if (result.error) {
|
|
55
|
+
errors.push(`Comment ${i}: ${result.error}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const result = {
|
|
59
|
+
comments,
|
|
60
|
+
success: errors.length === 0,
|
|
61
|
+
};
|
|
62
|
+
if (errors.length > 0) {
|
|
63
|
+
result.errors = errors;
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Build a single validated comment
|
|
69
|
+
*/
|
|
70
|
+
function buildComment(raw, focus, minConfidence) {
|
|
71
|
+
// Validate required fields
|
|
72
|
+
if (!raw.file || typeof raw.file !== 'string') {
|
|
73
|
+
return { success: false, error: 'Missing or invalid file path' };
|
|
74
|
+
}
|
|
75
|
+
if (!raw.line || typeof raw.line !== 'number' || raw.line < 1) {
|
|
76
|
+
return { success: false, error: 'Missing or invalid line number' };
|
|
77
|
+
}
|
|
78
|
+
if (!raw.severity || !isValidSeverity(raw.severity)) {
|
|
79
|
+
return { success: false, error: `Invalid severity: ${raw.severity}` };
|
|
80
|
+
}
|
|
81
|
+
if (!raw.title || typeof raw.title !== 'string') {
|
|
82
|
+
return { success: false, error: 'Missing title' };
|
|
83
|
+
}
|
|
84
|
+
// INV-REV-003: Explanation Required - body must be present
|
|
85
|
+
if (!raw.body || typeof raw.body !== 'string' || raw.body.length < 10) {
|
|
86
|
+
return { success: false, error: 'Missing or too short body (min 10 chars)' };
|
|
87
|
+
}
|
|
88
|
+
// INV-REV-002: Confidence Filtering
|
|
89
|
+
const confidence = typeof raw.confidence === 'number' ? raw.confidence : 0.5;
|
|
90
|
+
if (confidence < minConfidence) {
|
|
91
|
+
return { success: false, error: `Confidence ${confidence} below threshold ${minConfidence}` };
|
|
92
|
+
}
|
|
93
|
+
// INV-REV-004: Actionable Suggestions for critical/warning
|
|
94
|
+
const severity = raw.severity;
|
|
95
|
+
if ((severity === 'critical' || severity === 'warning') && !raw.suggestion) {
|
|
96
|
+
return { success: false, error: `${severity} comment must have suggestion` };
|
|
97
|
+
}
|
|
98
|
+
// INV-REV-001: Focus Mode Isolation
|
|
99
|
+
const category = raw.category || `${focus}/other`;
|
|
100
|
+
if (focus !== 'all' && !isCategoryValidForFocus(category, focus)) {
|
|
101
|
+
// Allow but warn - don't reject outright
|
|
102
|
+
// The comment will still be included but this is noted
|
|
103
|
+
}
|
|
104
|
+
const comment = {
|
|
105
|
+
commentId: uuidv4(),
|
|
106
|
+
file: raw.file,
|
|
107
|
+
line: raw.line,
|
|
108
|
+
lineEnd: raw.lineEnd,
|
|
109
|
+
severity,
|
|
110
|
+
title: raw.title.slice(0, 100), // Enforce max length
|
|
111
|
+
body: raw.body.slice(0, 2000),
|
|
112
|
+
rationale: raw.rationale?.slice(0, 500),
|
|
113
|
+
suggestion: raw.suggestion?.slice(0, 1000),
|
|
114
|
+
suggestedCode: raw.suggestedCode?.slice(0, 2000),
|
|
115
|
+
focus,
|
|
116
|
+
confidence: Math.max(0, Math.min(1, confidence)), // Clamp to 0-1
|
|
117
|
+
category: category.slice(0, 50),
|
|
118
|
+
};
|
|
119
|
+
// Validate against schema
|
|
120
|
+
const validation = ReviewCommentSchema.safeParse(comment);
|
|
121
|
+
if (!validation.success) {
|
|
122
|
+
return {
|
|
123
|
+
success: false,
|
|
124
|
+
error: `Schema validation failed: ${validation.error.errors.map((e) => e.message).join(', ')}`,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return { success: true, comment };
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check if a severity value is valid
|
|
131
|
+
*/
|
|
132
|
+
function isValidSeverity(severity) {
|
|
133
|
+
return ReviewCommentSeveritySchema.safeParse(severity).success;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Filter comments by focus mode
|
|
137
|
+
* INV-REV-001: Focus Mode Isolation
|
|
138
|
+
*/
|
|
139
|
+
export function filterCommentsByFocus(comments, focus) {
|
|
140
|
+
if (focus === 'all') {
|
|
141
|
+
return comments;
|
|
142
|
+
}
|
|
143
|
+
return comments.filter((comment) => {
|
|
144
|
+
// Check if category matches focus
|
|
145
|
+
return isCategoryValidForFocus(comment.category, focus);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Filter comments by confidence threshold
|
|
150
|
+
* INV-REV-002: Confidence Filtering
|
|
151
|
+
*/
|
|
152
|
+
export function filterCommentsByConfidence(comments, minConfidence) {
|
|
153
|
+
return comments.filter((comment) => comment.confidence >= minConfidence);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Validate that critical/warning comments have suggestions
|
|
157
|
+
* INV-REV-004: Actionable Suggestions
|
|
158
|
+
*/
|
|
159
|
+
export function validateActionableSuggestions(comments) {
|
|
160
|
+
const invalidComments = comments.filter((comment) => {
|
|
161
|
+
const needsSuggestion = comment.severity === 'critical' || comment.severity === 'warning';
|
|
162
|
+
return needsSuggestion && !comment.suggestion;
|
|
163
|
+
});
|
|
164
|
+
return {
|
|
165
|
+
valid: invalidComments.length === 0,
|
|
166
|
+
invalidComments,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
// Export uuid for testing
|
|
170
|
+
export { v4 as generateCommentId } from 'uuid';
|
|
171
|
+
//# sourceMappingURL=comment-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comment-builder.js","sourceRoot":"","sources":["../src/comment-builder.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAGL,mBAAmB,EACnB,2BAA2B,GAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAoB3D;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,QAAgB,EAChB,KAAkB,EAClB,aAAqB;IAErB,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,QAAQ,GAAoB,EAAE,CAAC;IAErC,0CAA0C;IAC1C,IAAI,WAAyB,CAAC;IAC9B,IAAI,CAAC;QACH,0DAA0D;QAC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IAED,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QACjC,kCAAkC;QAClC,OAAO,uBAAuB,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CACxC,QAAyB,EACzB,aAAqB;IAErB,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,IAAI,aAAa,CAAC,CAAC;AAC3E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAC3C,QAAyB;IAEzB,MAAM,eAAe,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;QAClD,MAAM,eAAe,GAAG,OAAO,CAAC,QAAQ,KAAK,UAAU,IAAI,OAAO,CAAC,QAAQ,KAAK,SAAS,CAAC;QAC1F,OAAO,eAAe,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC;IAChD,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,KAAK,EAAE,eAAe,CAAC,MAAM,KAAK,CAAC;QACnC,eAAe;KAChB,CAAC;AACJ,CAAC;AAED,0BAA0B;AAC1B,OAAO,EAAE,EAAE,IAAI,iBAAiB,EAAE,MAAM,MAAM,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
import type { ReviewFocus } from '@defai.digital/contracts';
|
|
8
|
+
/**
|
|
9
|
+
* Focus-specific system prompts
|
|
10
|
+
* Each prompt instructs the LLM to focus on specific categories of issues.
|
|
11
|
+
*/
|
|
12
|
+
export declare const FOCUS_MODE_PROMPTS: Record<ReviewFocus, string>;
|
|
13
|
+
/**
|
|
14
|
+
* Get the prompt for a specific focus mode
|
|
15
|
+
*/
|
|
16
|
+
export declare function getFocusModePrompt(focus: ReviewFocus): string;
|
|
17
|
+
/**
|
|
18
|
+
* Get the response format instructions
|
|
19
|
+
* This instructs the LLM how to format its response for parsing.
|
|
20
|
+
*/
|
|
21
|
+
export declare const RESPONSE_FORMAT_INSTRUCTIONS = "\nRespond with a JSON array of review comments. Each comment must have:\n{\n \"file\": \"path/to/file.ts\",\n \"line\": 42,\n \"lineEnd\": 45, // optional, for multi-line issues\n \"severity\": \"critical\", // one of: critical, warning, suggestion, note\n \"title\": \"Brief issue title (max 100 chars)\",\n \"body\": \"Detailed explanation of the issue and why it matters\",\n \"rationale\": \"Why this is important to fix\", // optional but recommended\n \"suggestion\": \"How to fix this issue\", // required for critical/warning\n \"suggestedCode\": \"code snippet showing the fix\", // optional\n \"confidence\": 0.95, // your confidence 0-1\n \"category\": \"security/sql-injection\" // category with focus prefix\n}\n\nIMPORTANT:\n- severity must be one of: critical, warning, suggestion, note\n- critical/warning MUST include suggestion field\n- body MUST explain WHY this matters\n- confidence should reflect your certainty (0.0-1.0)\n- Only report issues you are confident about\n- Do not report style issues unless maintainability focus\n\nRespond ONLY with the JSON array, no other text.\n";
|
|
22
|
+
/**
|
|
23
|
+
* Build the complete review prompt
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildReviewPrompt(focus: ReviewFocus, fileContents: {
|
|
26
|
+
path: string;
|
|
27
|
+
content: string;
|
|
28
|
+
}[], userContext?: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Categories allowed for each focus mode
|
|
31
|
+
* INV-REV-001: Used to validate that comments match their focus mode
|
|
32
|
+
*/
|
|
33
|
+
export declare const FOCUS_MODE_CATEGORIES: Record<ReviewFocus, string[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Check if a category is valid for a focus mode
|
|
36
|
+
* INV-REV-001: Validates focus mode isolation
|
|
37
|
+
*/
|
|
38
|
+
export declare function isCategoryValidForFocus(category: string, focus: ReviewFocus): boolean;
|
|
39
|
+
//# sourceMappingURL=focus-modes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"focus-modes.d.ts","sourceRoot":"","sources":["../src/focus-modes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAE5D;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CA6F1D,CAAC;AAEF;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAE7D;AAED;;;GAGG;AACH,eAAO,MAAM,4BAA4B,qnCAyBxC,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,WAAW,EAClB,YAAY,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,EAAE,EACjD,WAAW,CAAC,EAAE,MAAM,GACnB,MAAM,CA+BR;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,CA2D/D,CAAC;AAEF;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAWrF"}
|