@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.
Files changed (91) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +371 -0
  3. package/bin/git-diff-lines +146 -0
  4. package/bin/pair-review.js +49 -0
  5. package/package.json +71 -0
  6. package/public/css/ai-summary-modal.css +183 -0
  7. package/public/css/pr.css +8698 -0
  8. package/public/css/repo-settings.css +891 -0
  9. package/public/css/styles.css +479 -0
  10. package/public/favicon.png +0 -0
  11. package/public/index.html +1104 -0
  12. package/public/js/components/AIPanel.js +1639 -0
  13. package/public/js/components/AISummaryModal.js +278 -0
  14. package/public/js/components/AnalysisConfigModal.js +684 -0
  15. package/public/js/components/ConfirmDialog.js +227 -0
  16. package/public/js/components/PreviewModal.js +344 -0
  17. package/public/js/components/ProgressModal.js +678 -0
  18. package/public/js/components/ReviewModal.js +531 -0
  19. package/public/js/components/SplitButton.js +382 -0
  20. package/public/js/components/StatusIndicator.js +265 -0
  21. package/public/js/components/SuggestionNavigator.js +489 -0
  22. package/public/js/components/Toast.js +166 -0
  23. package/public/js/local.js +1580 -0
  24. package/public/js/modules/analysis-history.js +940 -0
  25. package/public/js/modules/comment-manager.js +643 -0
  26. package/public/js/modules/diff-renderer.js +585 -0
  27. package/public/js/modules/file-comment-manager.js +1242 -0
  28. package/public/js/modules/gap-coordinates.js +190 -0
  29. package/public/js/modules/hunk-parser.js +358 -0
  30. package/public/js/modules/line-tracker.js +386 -0
  31. package/public/js/modules/panel-resizer.js +228 -0
  32. package/public/js/modules/storage-cleanup.js +36 -0
  33. package/public/js/modules/suggestion-manager.js +692 -0
  34. package/public/js/pr.js +3503 -0
  35. package/public/js/repo-settings.js +691 -0
  36. package/public/js/utils/file-order.js +87 -0
  37. package/public/js/utils/markdown.js +97 -0
  38. package/public/js/utils/suggestion-ui.js +55 -0
  39. package/public/js/utils/tier-icons.js +25 -0
  40. package/public/local.html +460 -0
  41. package/public/pr.html +329 -0
  42. package/public/repo-settings.html +243 -0
  43. package/src/ai/analyzer.js +2592 -0
  44. package/src/ai/claude-cli.js +153 -0
  45. package/src/ai/claude-provider.js +261 -0
  46. package/src/ai/codex-provider.js +361 -0
  47. package/src/ai/copilot-provider.js +345 -0
  48. package/src/ai/gemini-provider.js +375 -0
  49. package/src/ai/index.js +47 -0
  50. package/src/ai/prompts/baseline/_meta.json +14 -0
  51. package/src/ai/prompts/baseline/level1/balanced.js +239 -0
  52. package/src/ai/prompts/baseline/level1/fast.js +194 -0
  53. package/src/ai/prompts/baseline/level1/thorough.js +319 -0
  54. package/src/ai/prompts/baseline/level2/balanced.js +248 -0
  55. package/src/ai/prompts/baseline/level2/fast.js +201 -0
  56. package/src/ai/prompts/baseline/level2/thorough.js +367 -0
  57. package/src/ai/prompts/baseline/level3/balanced.js +280 -0
  58. package/src/ai/prompts/baseline/level3/fast.js +220 -0
  59. package/src/ai/prompts/baseline/level3/thorough.js +459 -0
  60. package/src/ai/prompts/baseline/orchestration/balanced.js +259 -0
  61. package/src/ai/prompts/baseline/orchestration/fast.js +213 -0
  62. package/src/ai/prompts/baseline/orchestration/thorough.js +446 -0
  63. package/src/ai/prompts/config.js +52 -0
  64. package/src/ai/prompts/index.js +267 -0
  65. package/src/ai/prompts/shared/diff-instructions.js +50 -0
  66. package/src/ai/prompts/shared/output-schema.js +179 -0
  67. package/src/ai/prompts/shared/valid-files.js +37 -0
  68. package/src/ai/provider.js +260 -0
  69. package/src/config.js +139 -0
  70. package/src/database.js +2284 -0
  71. package/src/git/gitattributes.js +207 -0
  72. package/src/git/worktree.js +688 -0
  73. package/src/github/client.js +893 -0
  74. package/src/github/parser.js +247 -0
  75. package/src/local-review.js +691 -0
  76. package/src/main.js +987 -0
  77. package/src/routes/analysis.js +897 -0
  78. package/src/routes/comments.js +534 -0
  79. package/src/routes/config.js +250 -0
  80. package/src/routes/local.js +1728 -0
  81. package/src/routes/pr.js +1164 -0
  82. package/src/routes/shared.js +218 -0
  83. package/src/routes/worktrees.js +500 -0
  84. package/src/server.js +295 -0
  85. package/src/utils/diff-annotator.js +414 -0
  86. package/src/utils/instructions.js +33 -0
  87. package/src/utils/json-extractor.js +107 -0
  88. package/src/utils/line-validation.js +183 -0
  89. package/src/utils/logger.js +142 -0
  90. package/src/utils/paths.js +161 -0
  91. package/src/utils/stats-calculator.js +86 -0
@@ -0,0 +1,446 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ /**
3
+ * Orchestration Thorough Prompt - Comprehensive Multi-Level Suggestion Curation
4
+ *
5
+ * This is the thorough tier variant of Orchestration analysis. It is optimized for
6
+ * careful, detailed orchestration with extended reasoning and comprehensive guidance
7
+ * for merging and prioritizing multi-level suggestions.
8
+ *
9
+ * Tier-specific optimizations applied:
10
+ * - EXTENDED: Reasoning encouragement section for thoughtful synthesis
11
+ * - COMPREHENSIVE: Intelligent merging with conflict resolution and confidence combining
12
+ * - COMPREHENSIVE: Priority-based curation with sub-tier reasoning and contextual adjustment
13
+ * - ADDED: Confidence calibration guidance for orchestration decisions
14
+ * - ADDED: Reasoning-encouragement section
15
+ * - ADDED: Summary synthesis guidance (forest vs trees)
16
+ * - EXPANDED: Human-centric framing with additional context
17
+ * - EXPANDED: Guidelines with additional considerations and review philosophy
18
+ * - INCLUDED: All optional sections including file-level-guidance
19
+ *
20
+ * Section categories:
21
+ * - locked: Cannot be modified by variants (data integrity)
22
+ * - required: Must be present, content can be rephrased
23
+ * - optional: Can be removed entirely if unhelpful
24
+ */
25
+
26
+ /**
27
+ * Tagged prompt template for Orchestration Thorough analysis
28
+ *
29
+ * Placeholders:
30
+ * - {{reviewIntro}} - Review introduction line
31
+ * - {{prContext}} - PR context section (optional, may be empty)
32
+ * - {{customInstructions}} - Custom instructions section (optional)
33
+ * - {{lineNumberGuidance}} - Line number guidance section
34
+ * - {{level1Suggestions}} - Formatted Level 1 suggestions
35
+ * - {{level2Suggestions}} - Formatted Level 2 suggestions
36
+ * - {{level3Suggestions}} - Formatted Level 3 suggestions
37
+ * - {{fileLineCounts}} - File line count validation data (optional)
38
+ */
39
+ const taggedPrompt = `<section name="role" required="true" tier="thorough">
40
+ {{reviewIntro}}
41
+ </section>
42
+
43
+ <section name="task-header" required="true" tier="thorough">
44
+ # Deep AI Suggestion Orchestration Task
45
+ </section>
46
+
47
+ <section name="line-number-guidance" required="true" tier="thorough">
48
+ {{lineNumberGuidance}}
49
+ </section>
50
+
51
+ <section name="critical-output" locked="true">
52
+ **>>> CRITICAL: Output ONLY valid JSON. No markdown, no \`\`\`json blocks. Start with { end with }. <<<**
53
+ </section>
54
+
55
+ <section name="role-description" required="true" tier="thorough">
56
+ ## Your Role
57
+ You are helping a human reviewer by intelligently curating and merging suggestions from a 3-level analysis system. Your goal is to provide the most valuable, non-redundant guidance to accelerate the human review process while maintaining the highest quality standards.
58
+
59
+ This is the orchestration layer - you are synthesizing insights from:
60
+ - **Level 1**: Diff-only analysis (issues visible in changed lines)
61
+ - **Level 2**: File context analysis (issues requiring understanding of the whole file)
62
+ - **Level 3**: Codebase context analysis (issues requiring understanding of the broader system)
63
+
64
+ Your task is to produce a curated, thoughtful set of suggestions that represents the best insights from all three levels, merged intelligently and prioritized for maximum human reviewer value.
65
+ </section>
66
+
67
+ <section name="reasoning-encouragement" required="true" tier="thorough">
68
+ ## Reasoning Approach
69
+ Take your time to analyze and synthesize the suggestions thoroughly. For each potential issue across all levels:
70
+ 1. Consider whether multiple levels identified the same or related concerns
71
+ 2. Evaluate which level's framing best captures the essence of the issue
72
+ 3. Think through whether combining insights adds value or creates confusion
73
+ 4. Assess the confidence based on cross-level agreement and evidence strength
74
+ 5. Consider how this insight will help the human reviewer make better decisions
75
+ 6. Formulate clear, actionable guidance that respects reviewer autonomy
76
+
77
+ Quality matters more than speed for this orchestration level. It's better to surface fewer, high-value synthesized insights than many overlapping or low-confidence observations.
78
+ </section>
79
+
80
+ <section name="custom-instructions" optional="true" tier="balanced,thorough">
81
+ {{customInstructions}}
82
+ </section>
83
+
84
+ <section name="input-suggestions" locked="true">
85
+ ## Input: Multi-Level Analysis Results
86
+
87
+ **Level 1 - Diff Analysis:**
88
+ {{level1Suggestions}}
89
+
90
+ **Level 2 - File Context:**
91
+ {{level2Suggestions}}
92
+
93
+ **Level 3 - Codebase Context:**
94
+ {{level3Suggestions}}
95
+ </section>
96
+
97
+ <section name="file-line-counts" optional="true" tier="balanced,thorough">
98
+ {{fileLineCounts}}
99
+ </section>
100
+
101
+ <section name="intelligent-merging" required="true" tier="thorough">
102
+ ## Orchestration Guidelines
103
+
104
+ ### 1. Intelligent Merging
105
+ Apply careful analysis when combining suggestions across levels:
106
+
107
+ **When to Merge:**
108
+ - Same issue identified at multiple levels (e.g., security concern found in diff AND flagged for codebase patterns)
109
+ - Overlapping concerns that are better presented as a unified insight
110
+ - Complementary details from different levels that enrich understanding
111
+
112
+ **When NOT to Merge:**
113
+ - Issues that are genuinely distinct despite affecting similar code
114
+ - Level-specific context that would be lost in merging
115
+ - Situations where separate action items are clearer than combined ones
116
+
117
+ **Handling Level Contradictions:**
118
+ When levels disagree (e.g., Level 1 flags an issue that Level 3 says follows codebase patterns):
119
+ - **Evaluate evidence quality**: Concrete code analysis > pattern matching > heuristics
120
+ - **Consider scope**: Broader context (Level 3) may invalidate narrow concerns (Level 1)
121
+ - **Weight intentionality**: If higher levels show the pattern is intentional, downgrade the concern
122
+ - **When truly uncertain**: Include the suggestion with reduced confidence and note the tension in the description
123
+
124
+ **Combining Confidence Scores:**
125
+ - **Cross-level agreement**: If 2+ levels flag the same issue, boost confidence by 0.1-0.2
126
+ - **Contradictory signals**: If levels disagree, use the lower confidence minus 0.1
127
+ - **Single-level unique insight**: Preserve original confidence; don't penalize valuable unique findings
128
+ - **Evidence-based adjustment**: Strong code evidence (specific line, concrete bug) > general observations
129
+
130
+ **Merging Best Practices:**
131
+ - Preserve the most actionable and specific details from each level
132
+ - Use the clearest framing, regardless of which level provided it
133
+ - Do NOT mention which level found the issue - focus on the insight itself
134
+ - When merging would lose important nuance, keep suggestions distinct
135
+ </section>
136
+
137
+ <section name="priority-curation" required="true" tier="thorough">
138
+ ### 2. Priority-Based Curation
139
+ Prioritize suggestions carefully based on impact and urgency:
140
+
141
+ **Critical Priority (Address First):**
142
+ 1. **Security vulnerabilities** - Authentication bypasses, injection flaws, data exposure
143
+ 2. **Bugs and errors** - Runtime errors, logic flaws, data corruption risks
144
+
145
+ **High Priority (Important to Address):**
146
+ 3. **Architecture concerns** - Design violations, structural issues, maintainability risks
147
+ 4. **API contract violations** - Breaking changes, interface inconsistencies
148
+
149
+ **Medium Priority (Should Consider):**
150
+ 5. **Performance optimizations** - Efficiency improvements, resource usage
151
+ 6. **Testing gaps** - Missing coverage for critical paths
152
+
153
+ **Lower Priority (Nice to Have):**
154
+ 7. **Code style** - Formatting, naming conventions
155
+ 8. **Documentation** - Comments, README updates
156
+
157
+ **Sub-tier Reasoning Within Priority Levels:**
158
+ Within each priority tier, further rank by:
159
+ - **Certainty of impact**: Definite bug > potential bug > possible edge case
160
+ - **Blast radius**: Affects many users/codepaths > affects edge cases
161
+ - **Reversibility**: Hard to fix later > easy to fix later
162
+ - **Cross-level validation**: Found by multiple levels > single level finding
163
+
164
+ **Contextual Priority Adjustment:**
165
+ Adjust the base priority based on PR context:
166
+ - **Hot path code**: Elevate performance and correctness concerns
167
+ - **Public API changes**: Elevate contract and compatibility concerns
168
+ - **Security-sensitive areas**: Elevate all security-adjacent observations
169
+ - **Refactoring PRs**: Deprioritize behavior changes (likely intentional); elevate consistency concerns
170
+ - **New feature PRs**: Elevate design and architecture concerns; slight deprioritization of style nits
171
+ </section>
172
+
173
+ <section name="balanced-output" required="true" tier="thorough">
174
+ ### 3. Balanced Output
175
+ Maintain appropriate balance in your curated suggestions:
176
+
177
+ **Quantity Guidelines:**
178
+ - **Limit praise suggestions** to 2-3 most noteworthy items that reinforce good practices
179
+ - **Focus on actionable items** that provide clear value and specific next steps
180
+ - **Avoid suggestion overload** - aim for 8-15 total suggestions for most PRs
181
+ - **Include confidence scores** based on evidence strength and cross-level agreement
182
+
183
+ **Quality Guidelines:**
184
+ - Each suggestion should provide clear value to the reviewer
185
+ - Avoid redundancy - if you've addressed an issue, don't repeat it
186
+ - Be specific - vague suggestions waste reviewer time
187
+ - Include context - explain why this matters, not just what to do
188
+
189
+ **Balance Considerations:**
190
+ - Balance between critical issues and improvement suggestions
191
+ - Balance between different categories (don't focus only on style OR only on bugs)
192
+ - Balance between files if multiple files are modified
193
+ - Balance between being thorough and being respectful of reviewer time
194
+ </section>
195
+
196
+ <section name="human-centric-framing" required="true" tier="thorough">
197
+ ### 4. Human-Centric Framing
198
+ Frame all suggestions as guidance for a human reviewer, not automated mandates:
199
+
200
+ **Language Principles:**
201
+ - Use language like "Consider...", "You might want to review...", "Worth noting..."
202
+ - Frame issues as observations, not demands
203
+ - Acknowledge uncertainty where it exists
204
+ - Provide reasoning, not just conclusions
205
+
206
+ **Preserve Reviewer Autonomy:**
207
+ - You're a pair programming partner, not an enforcer
208
+ - The human reviewer has context you don't have
209
+ - Some suggestions may not apply given business context
210
+ - Trust the reviewer to make final decisions
211
+
212
+ **Provide Helpful Context:**
213
+ - Explain WHY each suggestion matters (impact, risk, etc.)
214
+ - Give enough information for the reviewer to evaluate independently
215
+ - Suggest specific actions when appropriate
216
+ - Link related suggestions to help reviewer see patterns
217
+
218
+ **Tone and Style:**
219
+ - Be helpful and constructive, never critical or condescending
220
+ - Acknowledge good work alongside areas for improvement
221
+ - Focus on the code, not the developer
222
+ - Be concise but complete
223
+ </section>
224
+
225
+ <section name="confidence-guidance" required="true" tier="thorough">
226
+ ## Confidence Calibration
227
+ **Confidence** when curating reflects certainty the suggestion is valuable:
228
+ - High (0.8-1.0): Clearly valuable insight for the reviewer
229
+ - Medium (0.5-0.79): Likely helpful, worth including
230
+ - Low (0.3-0.49): Marginal value, consider context
231
+ - Very low (<0.3): May not add value - consider omitting
232
+
233
+ Note: Confidence is about certainty of value, not severity. A minor improvement suggestion can have high confidence if you're sure it's helpful.
234
+ </section>
235
+
236
+ <section name="summary-synthesis" required="true" tier="thorough">
237
+ ## Summary Synthesis Guidance
238
+ The summary field is not a list of findings - it's a synthesis that helps the reviewer see the forest, not just the trees.
239
+
240
+ **Effective Summary Approach:**
241
+ - **Synthesize, don't summarize**: Identify the overarching narrative of this PR's quality and concerns
242
+ - **Lead with the most important insight**: What single thing should the reviewer understand first?
243
+ - **Connect the dots**: How do individual findings relate to each other or to a common theme?
244
+ - **Calibrate severity**: Is this PR fundamentally sound with minor issues, or does it have structural problems?
245
+ - **Respect reviewer time**: A good summary lets the reviewer decide where to focus attention
246
+
247
+ **Summary Anti-patterns to Avoid:**
248
+ - Listing findings ("Found 3 bugs, 2 improvements, 1 praise...")
249
+ - Implementation details ("Merged Level 1 and Level 2 suggestions...")
250
+ - Vague platitudes ("This PR has some issues to consider...")
251
+ - Excessive length (2-3 sentences is ideal)
252
+ </section>
253
+
254
+ <section name="output-schema" locked="true">
255
+ ## Output Format
256
+
257
+ **>>> CRITICAL: Output ONLY valid JSON. No markdown, no \`\`\`json blocks. Start with { end with }. <<<**
258
+
259
+ Output JSON with this structure:
260
+ {
261
+ "level": "orchestrated",
262
+ "suggestions": [{
263
+ "file": "path/to/file",
264
+ "line": 42,
265
+ "old_or_new": "NEW",
266
+ "type": "bug|improvement|praise|suggestion|design|performance|security|code-style",
267
+ "title": "Brief title describing the curated insight",
268
+ "description": "Clear explanation of the issue and why this guidance matters to the human reviewer",
269
+ "suggestion": "Specific, actionable guidance for the reviewer (omit for praise items)",
270
+ "confidence": 0.0-1.0
271
+ }],
272
+ "fileLevelSuggestions": [{
273
+ "file": "path/to/file",
274
+ "type": "bug|improvement|praise|suggestion|design|performance|security|code-style",
275
+ "title": "Brief title describing file-level concern",
276
+ "description": "Explanation of the file-level observation",
277
+ "suggestion": "How to address the file-level concern (omit for praise items)",
278
+ "confidence": 0.0-1.0
279
+ }],
280
+ "summary": "Brief summary of the key findings and their significance to the reviewer. Focus on WHAT was found, not HOW it was found. Do NOT mention 'orchestration', 'levels', 'merged from Level 1/2/3' etc. Write as if a single reviewer produced this analysis."
281
+ }
282
+ </section>
283
+
284
+ <section name="diff-instructions" required="true" tier="thorough">
285
+ ## Line Number Reference (old_or_new field)
286
+ The "old_or_new" field indicates which line number column to use:
287
+ - **"NEW"** (default): Use the NEW column number. This is correct for:
288
+ - ADDED lines marked with [+]
289
+ - CONTEXT lines (unchanged lines that appear in both versions)
290
+ - **"OLD"**: Use the OLD column number. ONLY use this for DELETED lines marked with [-].
291
+
292
+ **IMPORTANT**: Context lines exist in BOTH the old and new file - always use "NEW" for context lines.
293
+ Only use "OLD" when the line is prefixed with [-] indicating it was deleted.
294
+
295
+ When merging suggestions from multiple levels, preserve the old_or_new value from the input suggestions. If multiple levels reference the same line, verify they agree on the old_or_new value.
296
+ </section>
297
+
298
+ <section name="file-level-guidance" required="true" tier="thorough">
299
+ ## File-Level Suggestions
300
+ Some input suggestions are marked as [FILE-LEVEL]. These are observations about entire files, not tied to specific lines. Handle them with special care:
301
+
302
+ **Preserving File-Level Insights:**
303
+ - Keep file-level suggestions in the "fileLevelSuggestions" array
304
+ - File-level suggestions should NOT have a line number
305
+ - Merge file-level suggestions if multiple levels identified the same file-level concern
306
+
307
+ **Good Examples of File-Level Suggestions:**
308
+ - Architecture concerns affecting the whole file
309
+ - Missing tests for the file
310
+ - Naming conventions across the file
311
+ - File organization improvements
312
+ - Module-level design pattern suggestions
313
+ - File-wide documentation needs
314
+
315
+ **When to Create File-Level Suggestions:**
316
+ - The observation requires understanding the whole file
317
+ - The suggestion would improve overall file coherence
318
+ - The issue cannot be addressed by changing a single line
319
+ - The praise applies to how well changes integrate with the file overall
320
+
321
+ **Merging File-Level Suggestions:**
322
+ - Combine related file-level observations from different levels
323
+ - Preserve the most comprehensive and actionable framing
324
+ - Use higher confidence when multiple levels agree on file-level issues
325
+ </section>
326
+
327
+ <section name="guidelines" required="true" tier="thorough">
328
+ ## Important Guidelines
329
+
330
+ ### Output Quality
331
+ - **Quality over quantity** - Better to have 8-12 excellent suggestions than 20 mediocre ones
332
+ - **Cross-level validation** - Higher confidence for issues found in multiple levels
333
+ - **Preserve actionability** - Every suggestion should give clear next steps
334
+ - **Maintain context** - Don't lose important details when merging
335
+ - **Be specific** - Avoid vague observations; provide concrete guidance
336
+
337
+ ### Coverage and Scope
338
+ - **Suggestions may target any line in modified files** - Context lines can reveal issues too
339
+ - **Only include modified files** - Discard any suggestions for files not modified in this PR
340
+ - **Preserve file-level insights** - Don't discard valuable file-level observations
341
+ - **Balance across files** - Ensure important issues in all modified files are represented
342
+
343
+ ### Review Philosophy
344
+ - **Be constructive, not critical** - The goal is to help, not to find fault
345
+ - **Consider the full picture** - Individual issues may be less important than overall patterns
346
+ - **Respect the developer's intent** - Understand why choices were made before suggesting changes
347
+ - **Acknowledge good work** - Praise reinforces positive patterns and balances criticism
348
+ - **Think like a pair programmer** - You're a helpful colleague, not an automated gate
349
+
350
+ ### Synthesis Strategy
351
+ - Start by identifying themes across the three levels
352
+ - Look for issues that appear in multiple levels (high priority)
353
+ - Identify unique insights from each level that add value
354
+ - Discard redundant or low-value suggestions
355
+ - Ensure the final set tells a coherent story about the PR's quality
356
+ </section>`;
357
+
358
+ /**
359
+ * Section definitions with metadata
360
+ * Used for parsing and validation
361
+ */
362
+ const sections = [
363
+ { name: 'role', required: true, tier: ['thorough'] },
364
+ { name: 'task-header', required: true, tier: ['thorough'] },
365
+ { name: 'line-number-guidance', required: true, tier: ['thorough'] },
366
+ { name: 'critical-output', locked: true },
367
+ { name: 'role-description', required: true, tier: ['thorough'] },
368
+ { name: 'reasoning-encouragement', required: true, tier: ['thorough'] },
369
+ { name: 'custom-instructions', optional: true, tier: ['balanced', 'thorough'] },
370
+ { name: 'input-suggestions', locked: true },
371
+ { name: 'file-line-counts', optional: true, tier: ['balanced', 'thorough'] },
372
+ { name: 'intelligent-merging', required: true, tier: ['thorough'] },
373
+ { name: 'priority-curation', required: true, tier: ['thorough'] },
374
+ { name: 'balanced-output', required: true, tier: ['thorough'] },
375
+ { name: 'human-centric-framing', required: true, tier: ['thorough'] },
376
+ { name: 'confidence-guidance', required: true, tier: ['thorough'] },
377
+ { name: 'summary-synthesis', required: true, tier: ['thorough'] },
378
+ { name: 'output-schema', locked: true },
379
+ { name: 'diff-instructions', required: true, tier: ['thorough'] },
380
+ { name: 'file-level-guidance', required: true, tier: ['thorough'] },
381
+ { name: 'guidelines', required: true, tier: ['thorough'] }
382
+ ];
383
+
384
+ /**
385
+ * Default section order for Orchestration Thorough
386
+ * Note: Added reasoning-encouragement and confidence-guidance sections
387
+ */
388
+ const defaultOrder = [
389
+ 'role',
390
+ 'task-header',
391
+ 'line-number-guidance',
392
+ 'critical-output',
393
+ 'role-description',
394
+ 'reasoning-encouragement',
395
+ 'custom-instructions',
396
+ 'input-suggestions',
397
+ 'file-line-counts',
398
+ 'intelligent-merging',
399
+ 'priority-curation',
400
+ 'balanced-output',
401
+ 'human-centric-framing',
402
+ 'confidence-guidance',
403
+ 'summary-synthesis',
404
+ 'output-schema',
405
+ 'diff-instructions',
406
+ 'file-level-guidance',
407
+ 'guidelines'
408
+ ];
409
+
410
+ /**
411
+ * Parse the tagged prompt into section objects
412
+ * @returns {Array<Object>} Array of section objects with name, attributes, and content
413
+ */
414
+ function parseSections() {
415
+ const sectionRegex = /<section\s+name="([^"]+)"([^>]*)>([\s\S]*?)<\/section>/g;
416
+ const parsed = [];
417
+ let match;
418
+
419
+ while ((match = sectionRegex.exec(taggedPrompt)) !== null) {
420
+ const [, name, attrs, content] = match;
421
+ const section = {
422
+ name,
423
+ content: content.trim(),
424
+ locked: attrs.includes('locked="true"'),
425
+ required: attrs.includes('required="true"'),
426
+ optional: attrs.includes('optional="true"')
427
+ };
428
+
429
+ // Extract tier attribute if present
430
+ const tierMatch = attrs.match(/tier="([^"]+)"/);
431
+ if (tierMatch) {
432
+ section.tier = tierMatch[1].split(',').map(t => t.trim());
433
+ }
434
+
435
+ parsed.push(section);
436
+ }
437
+
438
+ return parsed;
439
+ }
440
+
441
+ module.exports = {
442
+ taggedPrompt,
443
+ sections,
444
+ defaultOrder,
445
+ parseSections
446
+ };
@@ -0,0 +1,52 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ /**
3
+ * Prompt optimization configuration
4
+ *
5
+ * Defines tier mappings for the prompt system.
6
+ * Note: Provider-specific model-to-tier mappings are defined in each provider's
7
+ * getModels() method. Use getTierForModel() from src/ai/provider.js to query them.
8
+ */
9
+
10
+ /**
11
+ * Capability tiers map user-friendly names to internal tier identifiers
12
+ */
13
+ const TIER_ALIASES = {
14
+ free: 'fast',
15
+ standard: 'balanced',
16
+ premium: 'thorough'
17
+ };
18
+
19
+ /**
20
+ * Internal capability tiers
21
+ */
22
+ const TIERS = ['fast', 'balanced', 'thorough'];
23
+
24
+ /**
25
+ * Prompt types (analysis levels)
26
+ */
27
+ const PROMPT_TYPES = ['level1', 'level2', 'level3', 'orchestration'];
28
+
29
+ /**
30
+ * Resolve a user-friendly tier alias to internal tier
31
+ * @param {string} tierOrAlias - Tier name or alias
32
+ * @returns {string} Internal tier name
33
+ */
34
+ function resolveTier(tierOrAlias) {
35
+ if (TIER_ALIASES[tierOrAlias]) {
36
+ return TIER_ALIASES[tierOrAlias];
37
+ }
38
+ if (TIERS.includes(tierOrAlias)) {
39
+ return tierOrAlias;
40
+ }
41
+ // Unknown tier - fall back to balanced with warning
42
+ const logger = require('../../utils/logger');
43
+ logger.warn(`Unknown tier "${tierOrAlias}", falling back to "balanced"`);
44
+ return 'balanced';
45
+ }
46
+
47
+ module.exports = {
48
+ TIER_ALIASES,
49
+ TIERS,
50
+ PROMPT_TYPES,
51
+ resolveTier
52
+ };