@in-the-loop-labs/pair-review 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.
- package/LICENSE +674 -0
- package/README.md +371 -0
- package/bin/git-diff-lines +146 -0
- package/bin/pair-review.js +49 -0
- package/package.json +71 -0
- package/public/css/ai-summary-modal.css +183 -0
- package/public/css/pr.css +8698 -0
- package/public/css/repo-settings.css +891 -0
- package/public/css/styles.css +479 -0
- package/public/favicon.png +0 -0
- package/public/index.html +1104 -0
- package/public/js/components/AIPanel.js +1639 -0
- package/public/js/components/AISummaryModal.js +278 -0
- package/public/js/components/AnalysisConfigModal.js +684 -0
- package/public/js/components/ConfirmDialog.js +227 -0
- package/public/js/components/PreviewModal.js +344 -0
- package/public/js/components/ProgressModal.js +678 -0
- package/public/js/components/ReviewModal.js +531 -0
- package/public/js/components/SplitButton.js +382 -0
- package/public/js/components/StatusIndicator.js +265 -0
- package/public/js/components/SuggestionNavigator.js +489 -0
- package/public/js/components/Toast.js +166 -0
- package/public/js/local.js +1580 -0
- package/public/js/modules/analysis-history.js +940 -0
- package/public/js/modules/comment-manager.js +643 -0
- package/public/js/modules/diff-renderer.js +585 -0
- package/public/js/modules/file-comment-manager.js +1242 -0
- package/public/js/modules/gap-coordinates.js +190 -0
- package/public/js/modules/hunk-parser.js +358 -0
- package/public/js/modules/line-tracker.js +386 -0
- package/public/js/modules/panel-resizer.js +228 -0
- package/public/js/modules/storage-cleanup.js +36 -0
- package/public/js/modules/suggestion-manager.js +692 -0
- package/public/js/pr.js +3503 -0
- package/public/js/repo-settings.js +691 -0
- package/public/js/utils/file-order.js +87 -0
- package/public/js/utils/markdown.js +97 -0
- package/public/js/utils/suggestion-ui.js +55 -0
- package/public/js/utils/tier-icons.js +25 -0
- package/public/local.html +460 -0
- package/public/pr.html +329 -0
- package/public/repo-settings.html +243 -0
- package/src/ai/analyzer.js +2592 -0
- package/src/ai/claude-cli.js +153 -0
- package/src/ai/claude-provider.js +261 -0
- package/src/ai/codex-provider.js +361 -0
- package/src/ai/copilot-provider.js +345 -0
- package/src/ai/gemini-provider.js +375 -0
- package/src/ai/index.js +47 -0
- package/src/ai/prompts/baseline/_meta.json +14 -0
- package/src/ai/prompts/baseline/level1/balanced.js +239 -0
- package/src/ai/prompts/baseline/level1/fast.js +194 -0
- package/src/ai/prompts/baseline/level1/thorough.js +319 -0
- package/src/ai/prompts/baseline/level2/balanced.js +248 -0
- package/src/ai/prompts/baseline/level2/fast.js +201 -0
- package/src/ai/prompts/baseline/level2/thorough.js +367 -0
- package/src/ai/prompts/baseline/level3/balanced.js +280 -0
- package/src/ai/prompts/baseline/level3/fast.js +220 -0
- package/src/ai/prompts/baseline/level3/thorough.js +459 -0
- package/src/ai/prompts/baseline/orchestration/balanced.js +259 -0
- package/src/ai/prompts/baseline/orchestration/fast.js +213 -0
- package/src/ai/prompts/baseline/orchestration/thorough.js +446 -0
- package/src/ai/prompts/config.js +52 -0
- package/src/ai/prompts/index.js +267 -0
- package/src/ai/prompts/shared/diff-instructions.js +50 -0
- package/src/ai/prompts/shared/output-schema.js +179 -0
- package/src/ai/prompts/shared/valid-files.js +37 -0
- package/src/ai/provider.js +260 -0
- package/src/config.js +139 -0
- package/src/database.js +2284 -0
- package/src/git/gitattributes.js +207 -0
- package/src/git/worktree.js +688 -0
- package/src/github/client.js +893 -0
- package/src/github/parser.js +247 -0
- package/src/local-review.js +691 -0
- package/src/main.js +987 -0
- package/src/routes/analysis.js +897 -0
- package/src/routes/comments.js +534 -0
- package/src/routes/config.js +250 -0
- package/src/routes/local.js +1728 -0
- package/src/routes/pr.js +1164 -0
- package/src/routes/shared.js +218 -0
- package/src/routes/worktrees.js +500 -0
- package/src/server.js +295 -0
- package/src/utils/diff-annotator.js +414 -0
- package/src/utils/instructions.js +33 -0
- package/src/utils/json-extractor.js +107 -0
- package/src/utils/line-validation.js +183 -0
- package/src/utils/logger.js +142 -0
- package/src/utils/paths.js +161 -0
- package/src/utils/stats-calculator.js +86 -0
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
/**
|
|
3
|
+
* Level 2 Thorough Prompt - File Context Analysis (Deep Review)
|
|
4
|
+
*
|
|
5
|
+
* This is the thorough tier variant of Level 2 analysis (file context).
|
|
6
|
+
* It is optimized for careful, detailed reviews with extended reasoning
|
|
7
|
+
* and comprehensive guidance for file-level pattern analysis.
|
|
8
|
+
*
|
|
9
|
+
* Tier-specific optimizations applied:
|
|
10
|
+
* - EXTENDED: Focus areas with more detailed analysis considerations
|
|
11
|
+
* - ADDED: Confidence calibration guidance section
|
|
12
|
+
* - ADDED: Reasoning framework section (multi-phase analysis)
|
|
13
|
+
* - EXPANDED: Category definitions with examples
|
|
14
|
+
* - EXPANDED: Guidelines with additional considerations
|
|
15
|
+
* - INCLUDED: All optional sections including file-level-guidance
|
|
16
|
+
*
|
|
17
|
+
* Section categories:
|
|
18
|
+
* - locked: Cannot be modified by variants (data integrity)
|
|
19
|
+
* - required: Must be present, content can be rephrased
|
|
20
|
+
* - optional: Can be removed entirely if unhelpful
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Tagged prompt template for Level 2 Thorough analysis
|
|
25
|
+
*
|
|
26
|
+
* Placeholders:
|
|
27
|
+
* - {{reviewIntro}} - Review introduction line
|
|
28
|
+
* - {{prContext}} - PR context section
|
|
29
|
+
* - {{customInstructions}} - Custom instructions section (optional)
|
|
30
|
+
* - {{lineNumberGuidance}} - Line number guidance section
|
|
31
|
+
* - {{generatedFiles}} - Generated files exclusion section (optional)
|
|
32
|
+
* - {{validFiles}} - List of valid files for suggestions
|
|
33
|
+
*/
|
|
34
|
+
const taggedPrompt = `<section name="role" required="true" tier="thorough">
|
|
35
|
+
{{reviewIntro}}
|
|
36
|
+
</section>
|
|
37
|
+
|
|
38
|
+
<section name="pr-context" locked="true">
|
|
39
|
+
{{prContext}}
|
|
40
|
+
</section>
|
|
41
|
+
|
|
42
|
+
<section name="custom-instructions" optional="true" tier="balanced,thorough">
|
|
43
|
+
{{customInstructions}}
|
|
44
|
+
</section>
|
|
45
|
+
|
|
46
|
+
<section name="level-header" required="true" tier="thorough">
|
|
47
|
+
# Level 2 Review - Deep File Context Analysis
|
|
48
|
+
</section>
|
|
49
|
+
|
|
50
|
+
<section name="line-number-guidance" required="true" tier="thorough">
|
|
51
|
+
{{lineNumberGuidance}}
|
|
52
|
+
</section>
|
|
53
|
+
|
|
54
|
+
<section name="reasoning-encouragement" required="true" tier="thorough">
|
|
55
|
+
## Reasoning Framework
|
|
56
|
+
|
|
57
|
+
For each file, build a mental model before identifying issues:
|
|
58
|
+
|
|
59
|
+
**Phase 1: Understand the File's Contract**
|
|
60
|
+
- What implicit contracts does this file establish? (error handling conventions, naming patterns, abstraction levels)
|
|
61
|
+
- What invariants should be maintained? (ordering, initialization patterns, resource lifecycle)
|
|
62
|
+
- What are the file's extension points and how should new code integrate with them?
|
|
63
|
+
|
|
64
|
+
**Phase 2: Evaluate Change Integration**
|
|
65
|
+
- How do the changes interact with existing code paths?
|
|
66
|
+
- Are there implicit dependencies that the changes might break?
|
|
67
|
+
- Do the changes respect or violate the file's established boundaries?
|
|
68
|
+
|
|
69
|
+
**Phase 3: Multi-step Impact Analysis**
|
|
70
|
+
- Trace through: if this code runs, what downstream effects occur within the file?
|
|
71
|
+
- Consider edge cases: what happens at boundaries, with null/empty inputs, under concurrent access?
|
|
72
|
+
- Think about maintenance: will a future developer understand why this code exists?
|
|
73
|
+
|
|
74
|
+
**Output Calibration**
|
|
75
|
+
Surface issues that genuinely require file context understanding. If an issue could be found from the diff alone, it belongs in Level 1 - skip it here. It's better to report fewer high-confidence file-context issues than to pad output with observations that don't require seeing the full file.
|
|
76
|
+
</section>
|
|
77
|
+
|
|
78
|
+
<section name="generated-files" optional="true" tier="balanced,thorough">
|
|
79
|
+
{{generatedFiles}}
|
|
80
|
+
</section>
|
|
81
|
+
|
|
82
|
+
<section name="valid-files" locked="true">
|
|
83
|
+
## Valid Files for Suggestions
|
|
84
|
+
You should ONLY create suggestions for files in this list:
|
|
85
|
+
{{validFiles}}
|
|
86
|
+
|
|
87
|
+
Do NOT create suggestions for any files not in this list. If you cannot find issues in these files, that's okay - just return fewer suggestions.
|
|
88
|
+
</section>
|
|
89
|
+
|
|
90
|
+
<section name="analysis-process" required="true" tier="thorough">
|
|
91
|
+
## Analysis Process
|
|
92
|
+
|
|
93
|
+
For each file with changes:
|
|
94
|
+
|
|
95
|
+
1. **Build Context First**
|
|
96
|
+
- Read the full file to understand its purpose and architecture
|
|
97
|
+
- Run the annotated diff tool with the file path to see precise line numbers
|
|
98
|
+
- Identify the file's implicit rules: How does it handle errors? What naming conventions does it use? What patterns recur?
|
|
99
|
+
|
|
100
|
+
2. **Analyze Integration Quality**
|
|
101
|
+
- Do the changes follow or violate the file's established patterns?
|
|
102
|
+
- Are there related code sections that should change together but didn't?
|
|
103
|
+
- Does the change maintain the file's abstraction boundaries?
|
|
104
|
+
|
|
105
|
+
3. **Generate Contextual Findings**
|
|
106
|
+
- Only report issues that require seeing the full file to understand
|
|
107
|
+
- Attach suggestions to the specific line where the issue manifests
|
|
108
|
+
- Skip files where you find no genuine file-level concerns
|
|
109
|
+
</section>
|
|
110
|
+
|
|
111
|
+
<section name="focus-areas" required="true" tier="thorough">
|
|
112
|
+
## Analysis Focus Areas
|
|
113
|
+
Carefully identify and analyze the following within file context:
|
|
114
|
+
|
|
115
|
+
### Consistency
|
|
116
|
+
- Naming convention consistency within the file
|
|
117
|
+
- Error handling patterns - are they consistent with the rest of the file?
|
|
118
|
+
- Logging patterns and conventions
|
|
119
|
+
- Comment and documentation style consistency
|
|
120
|
+
- Import organization and grouping patterns
|
|
121
|
+
- Function/method ordering and organization
|
|
122
|
+
|
|
123
|
+
### Integration Quality
|
|
124
|
+
- How well do changes integrate with existing code patterns?
|
|
125
|
+
- Are there related sections that should change together?
|
|
126
|
+
- Do changes maintain the file's existing abstraction levels?
|
|
127
|
+
- Is the code organization coherent after the changes?
|
|
128
|
+
|
|
129
|
+
### Security (File Scope)
|
|
130
|
+
- Security patterns consistent with the rest of the file
|
|
131
|
+
- Input validation matching file's established patterns
|
|
132
|
+
- Sensitive data handling consistency
|
|
133
|
+
- Access control patterns within the file
|
|
134
|
+
|
|
135
|
+
### Performance (File Scope)
|
|
136
|
+
- Performance patterns consistent with file conventions
|
|
137
|
+
- Resource management following file patterns
|
|
138
|
+
- Caching and memoization consistency
|
|
139
|
+
- Algorithm choices consistent with similar functions in file
|
|
140
|
+
|
|
141
|
+
### Code Quality
|
|
142
|
+
- Design pattern consistency within the file
|
|
143
|
+
- Complexity appropriate for the file's style
|
|
144
|
+
- Duplication with other code in the same file
|
|
145
|
+
- Magic numbers or hardcoded values that should use file constants
|
|
146
|
+
- Type usage consistent with file patterns
|
|
147
|
+
|
|
148
|
+
### Documentation
|
|
149
|
+
- Documentation style matching file conventions
|
|
150
|
+
- Missing documentation for changes that file's style would require
|
|
151
|
+
- Outdated comments that no longer match the changed code
|
|
152
|
+
- JSDoc/docstring consistency with other functions in file
|
|
153
|
+
|
|
154
|
+
### Good Practices
|
|
155
|
+
- Good practices worth praising in the context of file conventions
|
|
156
|
+
- Clean integration with existing code
|
|
157
|
+
- Thoughtful handling of file-specific patterns
|
|
158
|
+
- Improvements to overall file quality
|
|
159
|
+
</section>
|
|
160
|
+
|
|
161
|
+
<section name="available-commands" required="true" tier="thorough">
|
|
162
|
+
## Available Commands (READ-ONLY)
|
|
163
|
+
You have READ-ONLY access to the codebase. You may run commands like:
|
|
164
|
+
- The annotated diff tool shown above with file path (preferred for viewing changes with line numbers)
|
|
165
|
+
- \`cat -n <file>\` to view files with line numbers
|
|
166
|
+
- grep, find, ls commands as needed
|
|
167
|
+
|
|
168
|
+
IMPORTANT: Do NOT modify any files. Do NOT run write commands (rm, mv, git commit, etc.).
|
|
169
|
+
Your role is strictly to analyze and report findings.
|
|
170
|
+
|
|
171
|
+
Note: You may optionally use parallel read-only Tasks to examine multiple files simultaneously if that would be helpful for a thorough analysis.
|
|
172
|
+
</section>
|
|
173
|
+
|
|
174
|
+
<section name="output-schema" locked="true">
|
|
175
|
+
## Output Format
|
|
176
|
+
|
|
177
|
+
**>>> CRITICAL: Output ONLY valid JSON. No markdown, no \`\`\`json blocks. Start with { end with }. <<<**
|
|
178
|
+
|
|
179
|
+
Output JSON with this structure:
|
|
180
|
+
{
|
|
181
|
+
"level": 2,
|
|
182
|
+
"suggestions": [{
|
|
183
|
+
"file": "path/to/file",
|
|
184
|
+
"line": 42,
|
|
185
|
+
"old_or_new": "NEW",
|
|
186
|
+
"type": "bug|improvement|praise|suggestion|design|performance|security|code-style",
|
|
187
|
+
"title": "Brief title",
|
|
188
|
+
"description": "Detailed explanation mentioning why full file context was needed",
|
|
189
|
+
"suggestion": "How to fix/improve based on file context (omit for praise items)",
|
|
190
|
+
"confidence": 0.0-1.0
|
|
191
|
+
}],
|
|
192
|
+
"fileLevelSuggestions": [{
|
|
193
|
+
"file": "path/to/file",
|
|
194
|
+
"type": "bug|improvement|praise|suggestion|design|performance|security|code-style",
|
|
195
|
+
"title": "Brief title describing file-level concern",
|
|
196
|
+
"description": "Explanation of the file-level observation (architecture, organization, naming, etc.)",
|
|
197
|
+
"suggestion": "How to address the file-level concern (omit for praise items)",
|
|
198
|
+
"confidence": 0.0-1.0
|
|
199
|
+
}],
|
|
200
|
+
"summary": "Brief summary of file context findings"
|
|
201
|
+
}
|
|
202
|
+
</section>
|
|
203
|
+
|
|
204
|
+
<section name="diff-instructions" required="true" tier="thorough">
|
|
205
|
+
## old_or_new Field Reference
|
|
206
|
+
Use "NEW" (the default) for added lines [+] and context lines. Use "OLD" only for deleted lines [-]. When uncertain, use "NEW".
|
|
207
|
+
</section>
|
|
208
|
+
|
|
209
|
+
<section name="confidence-guidance" required="true" tier="thorough">
|
|
210
|
+
## Confidence Calibration
|
|
211
|
+
**Confidence** reflects your certainty that something IS an issue:
|
|
212
|
+
- High (0.8-1.0): You're certain this is a real problem
|
|
213
|
+
- Medium (0.5-0.79): Likely an issue, but context might justify it
|
|
214
|
+
- Low (0.3-0.49): Possibly an issue, requires human judgment
|
|
215
|
+
- Very low (<0.3): Observation only - flag for human awareness
|
|
216
|
+
|
|
217
|
+
Note: Confidence is about certainty, not severity. A minor style issue can have high confidence. A potential security issue might have low confidence if you're unsure it's exploitable.
|
|
218
|
+
</section>
|
|
219
|
+
|
|
220
|
+
<section name="category-definitions" required="true" tier="thorough">
|
|
221
|
+
## Category Definitions
|
|
222
|
+
|
|
223
|
+
### Issue Types
|
|
224
|
+
- **bug**: Errors visible when considering file context. Code that will fail or behave incorrectly in the context of how the file works.
|
|
225
|
+
- Example: New function doesn't follow file's error handling pattern, causing uncaught exceptions
|
|
226
|
+
- **improvement**: Enhancements to better integrate with file patterns. The code works but could be more consistent.
|
|
227
|
+
- Example: New function uses different naming convention than rest of file
|
|
228
|
+
- **praise**: Good practices that follow file conventions. Positive feedback for well-integrated code.
|
|
229
|
+
- Example: New code follows the file's established patterns perfectly
|
|
230
|
+
- **suggestion**: General recommendations based on file context. Ideas that may improve file coherence.
|
|
231
|
+
- Example: Consider grouping this function with similar ones in the file
|
|
232
|
+
- **design**: Architecture and structural concerns within the file.
|
|
233
|
+
- Example: New class breaks single responsibility pattern established in file
|
|
234
|
+
- **performance**: Efficiency issues that deviate from file's performance patterns.
|
|
235
|
+
- Example: New code doesn't use the caching pattern used elsewhere in the file
|
|
236
|
+
- **security**: Security issues visible in file context.
|
|
237
|
+
- Example: New endpoint doesn't follow file's authentication pattern
|
|
238
|
+
- **code-style**: Formatting, naming, and style inconsistencies within the file.
|
|
239
|
+
- Example: Indentation differs from rest of file, variable naming doesn't match convention
|
|
240
|
+
</section>
|
|
241
|
+
|
|
242
|
+
<section name="file-level-guidance" required="true" tier="thorough">
|
|
243
|
+
## File-Level vs Line-Level Suggestions
|
|
244
|
+
|
|
245
|
+
Use **line-level suggestions** (the \`suggestions\` array) when the issue manifests at a specific location, even if understanding it required file context.
|
|
246
|
+
|
|
247
|
+
Use **file-level suggestions** (the \`fileLevelSuggestions\` array) when:
|
|
248
|
+
- The observation concerns overall file organization or architecture
|
|
249
|
+
- The issue cannot be pinpointed to a single line (e.g., "this module mixes responsibilities")
|
|
250
|
+
- The praise applies to how changes integrate with the file as a whole
|
|
251
|
+
|
|
252
|
+
File-level suggestions have no line number - they apply to the entire file.
|
|
253
|
+
</section>
|
|
254
|
+
|
|
255
|
+
<section name="guidelines" required="true" tier="thorough">
|
|
256
|
+
## Guidelines
|
|
257
|
+
|
|
258
|
+
### Scope
|
|
259
|
+
- You may attach suggestions to any line within modified files, including context lines
|
|
260
|
+
- Focus on issues that require full file context - don't duplicate Level 1 diff-only findings
|
|
261
|
+
- Look for patterns and consistency issues not visible from the diff alone
|
|
262
|
+
|
|
263
|
+
### Output Quality
|
|
264
|
+
- For "praise" type: Omit the suggestion field (no action needed)
|
|
265
|
+
- For other types: Include specific, actionable suggestions grounded in file context
|
|
266
|
+
- Explain why file context was needed to identify the issue
|
|
267
|
+
- Be specific about what patterns exist and how to match them
|
|
268
|
+
|
|
269
|
+
### Philosophy
|
|
270
|
+
- Be constructive - the goal is to help maintain file consistency
|
|
271
|
+
- Treat the file's established conventions as authoritative
|
|
272
|
+
- Distinguish between "must fix for consistency" and "nice to have"
|
|
273
|
+
- Lower confidence when uncertain about file conventions
|
|
274
|
+
- Praise good integration to reinforce positive practices
|
|
275
|
+
|
|
276
|
+
### Priority Order
|
|
277
|
+
1. Breaking file conventions that could cause bugs or security issues
|
|
278
|
+
2. Consistency issues affecting maintainability
|
|
279
|
+
3. Stylistic suggestions for file coherence
|
|
280
|
+
4. Praise for excellent integration
|
|
281
|
+
</section>`;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Section definitions with metadata
|
|
285
|
+
* Used for parsing and validation
|
|
286
|
+
*/
|
|
287
|
+
const sections = [
|
|
288
|
+
{ name: 'role', required: true, tier: ['thorough'] },
|
|
289
|
+
{ name: 'pr-context', locked: true },
|
|
290
|
+
{ name: 'custom-instructions', optional: true, tier: ['balanced', 'thorough'] },
|
|
291
|
+
{ name: 'level-header', required: true, tier: ['thorough'] },
|
|
292
|
+
{ name: 'line-number-guidance', required: true, tier: ['thorough'] },
|
|
293
|
+
{ name: 'reasoning-encouragement', required: true, tier: ['thorough'] },
|
|
294
|
+
{ name: 'generated-files', optional: true, tier: ['balanced', 'thorough'] },
|
|
295
|
+
{ name: 'valid-files', locked: true },
|
|
296
|
+
{ name: 'analysis-process', required: true, tier: ['thorough'] },
|
|
297
|
+
{ name: 'focus-areas', required: true, tier: ['thorough'] },
|
|
298
|
+
{ name: 'available-commands', required: true, tier: ['thorough'] },
|
|
299
|
+
{ name: 'output-schema', locked: true },
|
|
300
|
+
{ name: 'diff-instructions', required: true, tier: ['thorough'] },
|
|
301
|
+
{ name: 'confidence-guidance', required: true, tier: ['thorough'] },
|
|
302
|
+
{ name: 'category-definitions', required: true, tier: ['thorough'] },
|
|
303
|
+
{ name: 'file-level-guidance', required: true, tier: ['thorough'] },
|
|
304
|
+
{ name: 'guidelines', required: true, tier: ['thorough'] }
|
|
305
|
+
];
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Default section order for Level 2 Thorough
|
|
309
|
+
* Note: Added reasoning-encouragement, confidence-guidance, and category-definitions sections
|
|
310
|
+
*/
|
|
311
|
+
const defaultOrder = [
|
|
312
|
+
'role',
|
|
313
|
+
'pr-context',
|
|
314
|
+
'custom-instructions',
|
|
315
|
+
'level-header',
|
|
316
|
+
'line-number-guidance',
|
|
317
|
+
'reasoning-encouragement',
|
|
318
|
+
'generated-files',
|
|
319
|
+
'valid-files',
|
|
320
|
+
'analysis-process',
|
|
321
|
+
'focus-areas',
|
|
322
|
+
'available-commands',
|
|
323
|
+
'output-schema',
|
|
324
|
+
'diff-instructions',
|
|
325
|
+
'confidence-guidance',
|
|
326
|
+
'category-definitions',
|
|
327
|
+
'file-level-guidance',
|
|
328
|
+
'guidelines'
|
|
329
|
+
];
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Parse the tagged prompt into section objects
|
|
333
|
+
* @returns {Array<Object>} Array of section objects with name, attributes, and content
|
|
334
|
+
*/
|
|
335
|
+
function parseSections() {
|
|
336
|
+
const sectionRegex = /<section\s+name="([^"]+)"([^>]*)>([\s\S]*?)<\/section>/g;
|
|
337
|
+
const parsed = [];
|
|
338
|
+
let match;
|
|
339
|
+
|
|
340
|
+
while ((match = sectionRegex.exec(taggedPrompt)) !== null) {
|
|
341
|
+
const [, name, attrs, content] = match;
|
|
342
|
+
const section = {
|
|
343
|
+
name,
|
|
344
|
+
content: content.trim(),
|
|
345
|
+
locked: attrs.includes('locked="true"'),
|
|
346
|
+
required: attrs.includes('required="true"'),
|
|
347
|
+
optional: attrs.includes('optional="true"')
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// Extract tier attribute if present
|
|
351
|
+
const tierMatch = attrs.match(/tier="([^"]+)"/);
|
|
352
|
+
if (tierMatch) {
|
|
353
|
+
section.tier = tierMatch[1].split(',').map(t => t.trim());
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
parsed.push(section);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
return parsed;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
module.exports = {
|
|
363
|
+
taggedPrompt,
|
|
364
|
+
sections,
|
|
365
|
+
defaultOrder,
|
|
366
|
+
parseSections
|
|
367
|
+
};
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
/**
|
|
3
|
+
* Level 3 Balanced Prompt - Codebase Context Analysis
|
|
4
|
+
*
|
|
5
|
+
* This is the canonical baseline prompt for Level 3 analysis (codebase context).
|
|
6
|
+
* It uses tagged XML format to enable machine-readable optimization.
|
|
7
|
+
*
|
|
8
|
+
* Section categories:
|
|
9
|
+
* - locked: Cannot be modified by variants (data integrity)
|
|
10
|
+
* - required: Must be present, content can be rephrased
|
|
11
|
+
* - optional: Can be removed entirely if unhelpful
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
// Note: Shared sections (valid-files, output-schema, diff-instructions) exist in ../shared/
|
|
15
|
+
// for future variant generation and consistency checking. Baseline prompts are self-contained
|
|
16
|
+
// with their own embedded section content to avoid runtime dependencies.
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Tagged prompt template for Level 3 Balanced analysis
|
|
20
|
+
*
|
|
21
|
+
* Placeholders:
|
|
22
|
+
* - {{reviewIntro}} - Review introduction line
|
|
23
|
+
* - {{prContext}} - PR context section
|
|
24
|
+
* - {{customInstructions}} - Custom instructions section (optional)
|
|
25
|
+
* - {{lineNumberGuidance}} - Line number guidance section
|
|
26
|
+
* - {{generatedFiles}} - Generated files exclusion section (optional)
|
|
27
|
+
* - {{changedFiles}} - List of changed files in this PR
|
|
28
|
+
* - {{testingGuidance}} - Testing-specific guidance based on context
|
|
29
|
+
*/
|
|
30
|
+
const taggedPrompt = `<section name="role" required="true">
|
|
31
|
+
{{reviewIntro}}
|
|
32
|
+
</section>
|
|
33
|
+
|
|
34
|
+
<section name="pr-context" locked="true">
|
|
35
|
+
{{prContext}}
|
|
36
|
+
</section>
|
|
37
|
+
|
|
38
|
+
<section name="custom-instructions" optional="true">
|
|
39
|
+
{{customInstructions}}
|
|
40
|
+
</section>
|
|
41
|
+
|
|
42
|
+
<section name="level-header" required="true">
|
|
43
|
+
# Level 3 Review - Analyze Change Impact on Codebase
|
|
44
|
+
</section>
|
|
45
|
+
|
|
46
|
+
<section name="line-number-guidance" required="true">
|
|
47
|
+
{{lineNumberGuidance}}
|
|
48
|
+
</section>
|
|
49
|
+
|
|
50
|
+
<section name="generated-files" optional="true">
|
|
51
|
+
{{generatedFiles}}
|
|
52
|
+
</section>
|
|
53
|
+
|
|
54
|
+
<section name="changed-files" locked="true">
|
|
55
|
+
{{changedFiles}}
|
|
56
|
+
</section>
|
|
57
|
+
|
|
58
|
+
<section name="purpose" required="true">
|
|
59
|
+
## Purpose
|
|
60
|
+
Level 3 analyzes how the changes connect to and impact the broader codebase.
|
|
61
|
+
|
|
62
|
+
**IMPORTANT**: This is NOT a general codebase review or architectural audit.
|
|
63
|
+
Focus exclusively on relationships between these specific changes and existing code.
|
|
64
|
+
</section>
|
|
65
|
+
|
|
66
|
+
<section name="analysis-process" required="true">
|
|
67
|
+
## Analysis Process
|
|
68
|
+
Start from the changed files and explore outward to understand connections:
|
|
69
|
+
|
|
70
|
+
1. Identify files that reference or are referenced by changed files
|
|
71
|
+
2. Check how changes relate to tests, configurations, and documentation
|
|
72
|
+
3. Evaluate whether changes follow, improve, or violate established patterns
|
|
73
|
+
4. Assess impact on other parts of the system
|
|
74
|
+
|
|
75
|
+
Explore deeply as needed, but stay focused on relationships to the changes.
|
|
76
|
+
Skip general codebase review - evaluate these specific changes in their broader context.
|
|
77
|
+
</section>
|
|
78
|
+
|
|
79
|
+
<section name="focus-areas" required="true">
|
|
80
|
+
## Focus Areas
|
|
81
|
+
Analyze how these changes affect or relate to:
|
|
82
|
+
|
|
83
|
+
**Architecture & Patterns** (high priority)
|
|
84
|
+
- Existing architecture: do changes fit with, improve, or disrupt architectural patterns?
|
|
85
|
+
- Established patterns: do changes follow or violate patterns used elsewhere?
|
|
86
|
+
- Cross-file dependencies: how do changes impact files that depend on them?
|
|
87
|
+
|
|
88
|
+
**Contracts & Compatibility** (high priority)
|
|
89
|
+
- Breaking changes: do changes break existing functionality or contracts?
|
|
90
|
+
- API contracts: do changes maintain consistency with existing API patterns?
|
|
91
|
+
- Backward compatibility: do changes maintain compatibility with prior versions?
|
|
92
|
+
|
|
93
|
+
**Testing & Documentation**
|
|
94
|
+
- {{testingGuidance}}
|
|
95
|
+
- Documentation: do changes require doc updates? Are they consistent with documented APIs?
|
|
96
|
+
- Configuration: do changes necessitate configuration updates?
|
|
97
|
+
|
|
98
|
+
**Performance & Security**
|
|
99
|
+
- Performance of connected components: how do changes affect performance elsewhere?
|
|
100
|
+
- System scalability: how do changes impact the system's ability to scale?
|
|
101
|
+
- Security of connected systems: do changes introduce security risks in other parts?
|
|
102
|
+
- Data flow security: how do changes affect security across data flows?
|
|
103
|
+
</section>
|
|
104
|
+
|
|
105
|
+
<section name="available-commands" required="true">
|
|
106
|
+
## Available Commands (READ-ONLY)
|
|
107
|
+
You have READ-ONLY access to the codebase:
|
|
108
|
+
- find . -name "*.test.js" to locate test files
|
|
109
|
+
- grep -r "pattern" to search for patterns
|
|
110
|
+
- \`cat -n <file>\` to view files with line numbers
|
|
111
|
+
- ls, tree commands to explore structure
|
|
112
|
+
- Any other read-only commands as needed
|
|
113
|
+
|
|
114
|
+
**>>> CRITICAL: Do NOT modify any files. Do NOT run write commands (rm, mv, git commit, etc.). <<<**
|
|
115
|
+
|
|
116
|
+
You may use parallel read-only Tasks to explore different areas of the codebase if helpful.
|
|
117
|
+
</section>
|
|
118
|
+
|
|
119
|
+
<section name="output-schema" locked="true">
|
|
120
|
+
## Output Format
|
|
121
|
+
|
|
122
|
+
**>>> CRITICAL: Output ONLY valid JSON. No markdown, no \`\`\`json blocks. Start with { end with }. <<<**
|
|
123
|
+
|
|
124
|
+
Output JSON with this structure:
|
|
125
|
+
{
|
|
126
|
+
"level": 3,
|
|
127
|
+
"suggestions": [{
|
|
128
|
+
"file": "path/to/file",
|
|
129
|
+
"line": 42,
|
|
130
|
+
"old_or_new": "NEW",
|
|
131
|
+
"type": "bug|improvement|praise|suggestion|design|performance|security|code-style",
|
|
132
|
+
"title": "Brief title",
|
|
133
|
+
"description": "Detailed explanation mentioning why codebase context was needed",
|
|
134
|
+
"suggestion": "How to fix/improve based on codebase context (omit for praise items)",
|
|
135
|
+
"confidence": 0.0-1.0
|
|
136
|
+
}],
|
|
137
|
+
"fileLevelSuggestions": [{
|
|
138
|
+
"file": "path/to/file",
|
|
139
|
+
"type": "bug|improvement|praise|suggestion|design|performance|security|code-style",
|
|
140
|
+
"title": "Brief title describing file-level concern",
|
|
141
|
+
"description": "Explanation of the file-level observation from codebase perspective",
|
|
142
|
+
"suggestion": "How to address the file-level concern (omit for praise items)",
|
|
143
|
+
"confidence": 0.0-1.0
|
|
144
|
+
}],
|
|
145
|
+
"summary": "Brief summary of how these changes connect to and impact the codebase"
|
|
146
|
+
}
|
|
147
|
+
</section>
|
|
148
|
+
|
|
149
|
+
<section name="diff-instructions" required="true">
|
|
150
|
+
## Line Number Reference (old_or_new field)
|
|
151
|
+
The "old_or_new" field indicates which line number column to use:
|
|
152
|
+
- **"NEW"** (default): Use the NEW column number. This is correct for:
|
|
153
|
+
- ADDED lines marked with [+]
|
|
154
|
+
- CONTEXT lines (unchanged lines that appear in both versions)
|
|
155
|
+
- **"OLD"**: Use the OLD column number. ONLY use this for DELETED lines marked with [-].
|
|
156
|
+
|
|
157
|
+
**IMPORTANT**: Context lines exist in BOTH the old and new file - always use "NEW" for context lines.
|
|
158
|
+
Only use "OLD" when the line is prefixed with [-] indicating it was deleted.
|
|
159
|
+
|
|
160
|
+
If you are unsure, use "NEW" - it is correct for the vast majority of suggestions.
|
|
161
|
+
</section>
|
|
162
|
+
|
|
163
|
+
<section name="file-level-guidance" optional="true">
|
|
164
|
+
## Line-Level vs File-Level Suggestions
|
|
165
|
+
Prefer line-level comments (in the "suggestions" array) when the issue can be anchored to specific lines. Use file-level suggestions (in the "fileLevelSuggestions" array) only for observations that truly apply to the entire file and cannot be tied to specific lines.
|
|
166
|
+
|
|
167
|
+
File-level suggestions are appropriate for:
|
|
168
|
+
- Architectural concerns about the file's role in the codebase
|
|
169
|
+
- Missing tests for the file's functionality
|
|
170
|
+
- Integration issues with other parts of the codebase
|
|
171
|
+
- File-level design pattern inconsistencies with the rest of the codebase
|
|
172
|
+
- Documentation gaps for the file
|
|
173
|
+
- Organizational issues (file location, module structure)
|
|
174
|
+
|
|
175
|
+
File-level suggestions should NOT have a line number. They apply to the entire file.
|
|
176
|
+
</section>
|
|
177
|
+
|
|
178
|
+
<section name="guidelines" required="true">
|
|
179
|
+
## Important Guidelines
|
|
180
|
+
|
|
181
|
+
**Line vs File-Level Suggestions**
|
|
182
|
+
- Prefer line-level comments when the issue can be anchored to specific lines
|
|
183
|
+
- Use fileLevelSuggestions only for observations that truly apply to the entire file
|
|
184
|
+
- You may attach suggestions to context lines when they reveal codebase-level issues
|
|
185
|
+
|
|
186
|
+
**Focus & Quality**
|
|
187
|
+
- Focus on how changes interact with the broader codebase
|
|
188
|
+
- Look especially for missing tests, documentation, and integration issues
|
|
189
|
+
- When uncertain, prefer to omit rather than include marginal suggestions
|
|
190
|
+
|
|
191
|
+
**Confidence Calibration**
|
|
192
|
+
- High (0.8+): Clear issues you're certain about
|
|
193
|
+
- Medium (0.5-0.79): Likely issues with some uncertainty
|
|
194
|
+
- Lower: Observations you're less sure about
|
|
195
|
+
|
|
196
|
+
**Output Requirements**
|
|
197
|
+
- For "praise" type: Omit the suggestion field entirely
|
|
198
|
+
- For other types: Always include specific, actionable suggestions
|
|
199
|
+
</section>`;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Section definitions with metadata
|
|
203
|
+
* Used for parsing and validation
|
|
204
|
+
*/
|
|
205
|
+
const sections = [
|
|
206
|
+
{ name: 'role', required: true },
|
|
207
|
+
{ name: 'pr-context', locked: true },
|
|
208
|
+
{ name: 'custom-instructions', optional: true },
|
|
209
|
+
{ name: 'level-header', required: true },
|
|
210
|
+
{ name: 'line-number-guidance', required: true },
|
|
211
|
+
{ name: 'generated-files', optional: true },
|
|
212
|
+
{ name: 'changed-files', locked: true },
|
|
213
|
+
{ name: 'purpose', required: true },
|
|
214
|
+
{ name: 'analysis-process', required: true },
|
|
215
|
+
{ name: 'focus-areas', required: true },
|
|
216
|
+
{ name: 'available-commands', required: true },
|
|
217
|
+
{ name: 'output-schema', locked: true },
|
|
218
|
+
{ name: 'diff-instructions', required: true },
|
|
219
|
+
{ name: 'file-level-guidance', optional: true },
|
|
220
|
+
{ name: 'guidelines', required: true }
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Default section order for Level 3 Balanced
|
|
225
|
+
*/
|
|
226
|
+
const defaultOrder = [
|
|
227
|
+
'role',
|
|
228
|
+
'pr-context',
|
|
229
|
+
'custom-instructions',
|
|
230
|
+
'level-header',
|
|
231
|
+
'line-number-guidance',
|
|
232
|
+
'generated-files',
|
|
233
|
+
'changed-files',
|
|
234
|
+
'purpose',
|
|
235
|
+
'analysis-process',
|
|
236
|
+
'focus-areas',
|
|
237
|
+
'available-commands',
|
|
238
|
+
'output-schema',
|
|
239
|
+
'diff-instructions',
|
|
240
|
+
'file-level-guidance',
|
|
241
|
+
'guidelines'
|
|
242
|
+
];
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Parse the tagged prompt into section objects
|
|
246
|
+
* @returns {Array<Object>} Array of section objects with name, attributes, and content
|
|
247
|
+
*/
|
|
248
|
+
function parseSections() {
|
|
249
|
+
const sectionRegex = /<section\s+name="([^"]+)"([^>]*)>([\s\S]*?)<\/section>/g;
|
|
250
|
+
const parsed = [];
|
|
251
|
+
let match;
|
|
252
|
+
|
|
253
|
+
while ((match = sectionRegex.exec(taggedPrompt)) !== null) {
|
|
254
|
+
const [, name, attrs, content] = match;
|
|
255
|
+
const section = {
|
|
256
|
+
name,
|
|
257
|
+
content: content.trim(),
|
|
258
|
+
locked: attrs.includes('locked="true"'),
|
|
259
|
+
required: attrs.includes('required="true"'),
|
|
260
|
+
optional: attrs.includes('optional="true"')
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
// Extract tier attribute if present
|
|
264
|
+
const tierMatch = attrs.match(/tier="([^"]+)"/);
|
|
265
|
+
if (tierMatch) {
|
|
266
|
+
section.tier = tierMatch[1].split(',').map(t => t.trim());
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
parsed.push(section);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return parsed;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
module.exports = {
|
|
276
|
+
taggedPrompt,
|
|
277
|
+
sections,
|
|
278
|
+
defaultOrder,
|
|
279
|
+
parseSections
|
|
280
|
+
};
|