@simonren/quorum 0.7.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 (59) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +144 -0
  3. package/commands/multi-consult.md +109 -0
  4. package/commands/multi-review.md +139 -0
  5. package/dist/adapters/base.d.ts +120 -0
  6. package/dist/adapters/base.js +98 -0
  7. package/dist/adapters/claude.d.ts +25 -0
  8. package/dist/adapters/claude.js +217 -0
  9. package/dist/adapters/codex.d.ts +20 -0
  10. package/dist/adapters/codex.js +227 -0
  11. package/dist/adapters/gemini.d.ts +20 -0
  12. package/dist/adapters/gemini.js +197 -0
  13. package/dist/adapters/index.d.ts +12 -0
  14. package/dist/adapters/index.js +15 -0
  15. package/dist/cli/check.d.ts +20 -0
  16. package/dist/cli/check.js +78 -0
  17. package/dist/cli/codex.d.ts +11 -0
  18. package/dist/cli/codex.js +255 -0
  19. package/dist/cli/gemini.d.ts +12 -0
  20. package/dist/cli/gemini.js +253 -0
  21. package/dist/commands.d.ts +28 -0
  22. package/dist/commands.js +105 -0
  23. package/dist/config.d.ts +244 -0
  24. package/dist/config.js +179 -0
  25. package/dist/consult-prompt.d.ts +10 -0
  26. package/dist/consult-prompt.js +72 -0
  27. package/dist/context.d.ts +1538 -0
  28. package/dist/context.js +383 -0
  29. package/dist/decoders/claude.d.ts +53 -0
  30. package/dist/decoders/claude.js +106 -0
  31. package/dist/decoders/codex.d.ts +71 -0
  32. package/dist/decoders/codex.js +145 -0
  33. package/dist/decoders/gemini.d.ts +33 -0
  34. package/dist/decoders/gemini.js +58 -0
  35. package/dist/decoders/index.d.ts +6 -0
  36. package/dist/decoders/index.js +3 -0
  37. package/dist/errors.d.ts +46 -0
  38. package/dist/errors.js +192 -0
  39. package/dist/executor.d.ts +103 -0
  40. package/dist/executor.js +244 -0
  41. package/dist/handoff.d.ts +270 -0
  42. package/dist/handoff.js +599 -0
  43. package/dist/index.d.ts +18 -0
  44. package/dist/index.js +134 -0
  45. package/dist/pipeline.d.ts +135 -0
  46. package/dist/pipeline.js +462 -0
  47. package/dist/prompt-v2.d.ts +38 -0
  48. package/dist/prompt-v2.js +391 -0
  49. package/dist/prompt.d.ts +71 -0
  50. package/dist/prompt.js +309 -0
  51. package/dist/schema.d.ts +660 -0
  52. package/dist/schema.js +536 -0
  53. package/dist/tools/consult.d.ts +104 -0
  54. package/dist/tools/consult.js +220 -0
  55. package/dist/tools/feedback.d.ts +91 -0
  56. package/dist/tools/feedback.js +117 -0
  57. package/dist/types.d.ts +105 -0
  58. package/dist/types.js +31 -0
  59. package/package.json +54 -0
@@ -0,0 +1,391 @@
1
+ /**
2
+ * Enhanced Prompt Builder v2
3
+ *
4
+ * Builds prompts using rich context with:
5
+ * - Layered information (summary → details)
6
+ * - Focus-area specific emphasis
7
+ * - Smart diff integration
8
+ * - Explicit verification requirements
9
+ * - Targeted questions from CC
10
+ */
11
+ import { contextToPromptString, optimizeContext } from './context.js';
12
+ import { getReviewOutputJsonSchema } from './schema.js';
13
+ import { selectExpertRole } from './adapters/base.js';
14
+ import { FOCUS_AREA_DESCRIPTIONS } from './types.js';
15
+ // =============================================================================
16
+ // PROMPT TEMPLATES
17
+ // =============================================================================
18
+ const PROMPT_TEMPLATES = {
19
+ security: `You are conducting a SECURITY AUDIT. Your primary focus:
20
+
21
+ 1. **Input Validation**
22
+ - Look for unsanitized user input
23
+ - Check for injection vulnerabilities (SQL, NoSQL, Command, XSS)
24
+ - Verify input length/type constraints
25
+
26
+ 2. **Authentication & Authorization**
27
+ - Session management flaws
28
+ - Privilege escalation vectors
29
+ - Missing access controls
30
+
31
+ 3. **Data Protection**
32
+ - Sensitive data exposure
33
+ - Insecure storage
34
+ - Missing encryption
35
+
36
+ 4. **Dependencies**
37
+ - Known vulnerable packages
38
+ - Outdated dependencies
39
+
40
+ For EACH security finding, provide:
41
+ - CWE ID if applicable
42
+ - Attack scenario (how could this be exploited?)
43
+ - Severity based on impact + exploitability`,
44
+ performance: `You are conducting a PERFORMANCE REVIEW. Your primary focus:
45
+
46
+ 1. **Algorithmic Complexity**
47
+ - Time complexity (Big-O notation required)
48
+ - Space complexity
49
+ - Identify O(n²) or worse operations
50
+
51
+ 2. **Database & I/O**
52
+ - N+1 query problems
53
+ - Missing indexes
54
+ - Unoptimized queries
55
+ - Blocking I/O in async contexts
56
+
57
+ 3. **Memory Management**
58
+ - Memory leaks
59
+ - Unnecessary object creation
60
+ - Large object retention
61
+
62
+ 4. **Caching Opportunities**
63
+ - Repeated expensive operations
64
+ - Missing memoization
65
+ - Cache invalidation issues
66
+
67
+ For EACH performance finding, provide:
68
+ - Big-O analysis where applicable
69
+ - Estimated impact (e.g., "10x slower for 1000 items")
70
+ - Concrete optimization suggestion`,
71
+ architecture: `You are conducting an ARCHITECTURE REVIEW. Your primary focus:
72
+
73
+ 1. **SOLID Principles**
74
+ - Single Responsibility violations
75
+ - Open/Closed principle adherence
76
+ - Interface segregation
77
+ - Dependency inversion
78
+
79
+ 2. **Code Organization**
80
+ - Coupling between modules
81
+ - Cohesion within modules
82
+ - Layering violations
83
+
84
+ 3. **Design Patterns**
85
+ - Missing beneficial patterns
86
+ - Anti-patterns present
87
+ - Pattern misuse
88
+
89
+ 4. **Maintainability**
90
+ - Code complexity (cyclomatic complexity)
91
+ - Test coverage implications
92
+ - Documentation gaps
93
+
94
+ For EACH architecture finding, provide:
95
+ - Specific principle/pattern violated
96
+ - Concrete refactoring suggestion
97
+ - Impact on maintainability`,
98
+ correctness: `You are conducting a CORRECTNESS REVIEW. Your primary focus:
99
+
100
+ 1. **Logic Errors**
101
+ - Off-by-one errors
102
+ - Incorrect conditionals
103
+ - Wrong operator usage
104
+
105
+ 2. **Edge Cases**
106
+ - Null/undefined handling
107
+ - Empty collections
108
+ - Boundary conditions
109
+ - Integer overflow
110
+
111
+ 3. **Concurrency**
112
+ - Race conditions
113
+ - Deadlock potential
114
+ - State inconsistency
115
+
116
+ 4. **Error Handling**
117
+ - Uncaught exceptions
118
+ - Silent failures
119
+ - Incorrect error propagation
120
+
121
+ For EACH correctness finding, provide:
122
+ - Specific input that triggers the bug
123
+ - Expected vs actual behavior
124
+ - Fix with test case suggestion`,
125
+ };
126
+ /**
127
+ * Build an enhanced review prompt using rich context
128
+ */
129
+ export function buildEnhancedPrompt(options) {
130
+ const { context, reviewerName, focusAreas = [], maxContextTokens = 100000, includeFullDiffs = true, retryContext, } = options;
131
+ // Optimize context for token budget
132
+ const optimizedContext = optimizeContext(context, {
133
+ maxTokens: maxContextTokens,
134
+ focusAreas,
135
+ includeFullContent: false,
136
+ includeDiffs: includeFullDiffs,
137
+ });
138
+ const sections = [];
139
+ // ==========================================================================
140
+ // SECTION 1: ROLE & EXPERTISE
141
+ // ==========================================================================
142
+ const role = selectExpertRole(focusAreas);
143
+ const focusTemplate = focusAreas.length > 0
144
+ ? PROMPT_TEMPLATES[focusAreas[0]]
145
+ : null;
146
+ sections.push(`# ROLE: ${role.name}
147
+
148
+ ${role.systemPrompt}
149
+
150
+ ${focusTemplate || ''}`);
151
+ // ==========================================================================
152
+ // SECTION 2: TASK DESCRIPTION
153
+ // ==========================================================================
154
+ sections.push(`
155
+ ---
156
+
157
+ # TASK
158
+
159
+ You are reviewing work done by Claude Code (CC), another AI assistant.
160
+
161
+ **Your job is to:**
162
+ 1. ✓ VALIDATE correct findings (agreements)
163
+ 2. ✗ CHALLENGE incorrect claims (disagreements)
164
+ 3. + ADD issues CC missed (new findings)
165
+ 4. ⟷ SUGGEST alternatives where applicable
166
+ 5. ⚠ ASSESS overall risk
167
+
168
+ **Critical requirement:** You must READ THE ACTUAL FILES to verify claims.
169
+ Do not trust CC's descriptions blindly - verify by reading the code yourself.`);
170
+ // ==========================================================================
171
+ // SECTION 3: CONTEXT (What CC Did)
172
+ // ==========================================================================
173
+ sections.push(`
174
+ ---
175
+
176
+ # CONTEXT
177
+
178
+ ${contextToPromptString(optimizedContext)}`);
179
+ // ==========================================================================
180
+ // SECTION 4: CC'S UNCERTAINTIES (Priority for Reviewer)
181
+ // ==========================================================================
182
+ if (context.analysis.uncertainties && context.analysis.uncertainties.length > 0) {
183
+ sections.push(`
184
+ ---
185
+
186
+ # CC'S UNCERTAINTIES - PLEASE VERIFY
187
+
188
+ CC flagged these items as uncertain. Your verification is especially valuable here:
189
+
190
+ ${context.analysis.uncertainties.map((u, i) => `
191
+ ${i + 1}. **${u.topic}**
192
+ Question: ${u.question}
193
+ ${u.ccBestGuess ? `CC's current assumption: ${u.ccBestGuess}` : ''}
194
+ `).join('\n')}`);
195
+ }
196
+ // ==========================================================================
197
+ // SECTION 5: SPECIFIC QUESTIONS (If CC has them)
198
+ // ==========================================================================
199
+ if (context.scope?.questions && context.scope.questions.length > 0) {
200
+ sections.push(`
201
+ ---
202
+
203
+ # SPECIFIC QUESTIONS FROM CC
204
+
205
+ Please address these specific questions:
206
+
207
+ ${context.scope.questions.map((q, i) => `
208
+ ${i + 1}. ${q.question}
209
+ ${q.context ? `Context: ${q.context}` : ''}
210
+ ${q.ccAnswer ? `CC thinks: ${q.ccAnswer} (verify this)` : ''}
211
+ `).join('\n')}`);
212
+ }
213
+ // ==========================================================================
214
+ // SECTION 6: REVIEW PRIORITIES (What to Focus On)
215
+ // ==========================================================================
216
+ if (context.scope?.mustReview && context.scope.mustReview.length > 0) {
217
+ sections.push(`
218
+ ---
219
+
220
+ # PRIORITY REVIEW AREAS
221
+
222
+ Focus your attention on these files:
223
+
224
+ ${context.scope.mustReview.map(r => `
225
+ - **${r.path}**: ${r.reason}
226
+ ${r.specificConcerns ? `Concerns: ${r.specificConcerns.join(', ')}` : ''}
227
+ `).join('\n')}`);
228
+ }
229
+ // ==========================================================================
230
+ // SECTION 7: VERIFICATION REQUIREMENTS
231
+ // ==========================================================================
232
+ sections.push(`
233
+ ---
234
+
235
+ # VERIFICATION REQUIREMENTS
236
+
237
+ For EVERY finding you report, you MUST:
238
+
239
+ 1. **Verify the file exists** - Read it yourself before claiming issues
240
+ 2. **Provide exact location** - file:line format (e.g., \`src/auth.ts:42\`)
241
+ 3. **Include evidence** - Quote the problematic code snippet
242
+ 4. **State confidence** - 0.0 to 1.0 based on how certain you are
243
+ 5. **Provide rationale** - Why this is an issue
244
+
245
+ **DO NOT:**
246
+ - Claim issues in files you haven't read
247
+ - Invent file paths or line numbers
248
+ - Assume code structure without verifying
249
+ - Report vague findings without specific locations`);
250
+ // ==========================================================================
251
+ // SECTION 8: OUTPUT FORMAT
252
+ // ==========================================================================
253
+ const schema = getReviewOutputJsonSchema();
254
+ sections.push(`
255
+ ---
256
+
257
+ # OUTPUT FORMAT
258
+
259
+ Respond with valid JSON matching this schema:
260
+
261
+ \`\`\`json
262
+ ${JSON.stringify(schema, null, 2)}
263
+ \`\`\`
264
+
265
+ **Output rules:**
266
+ - Output ONLY the JSON object
267
+ - No markdown wrapping, no explanatory text before/after
268
+ - All required fields must be present
269
+ - Use empty arrays [] for sections with no findings
270
+ - Confidence scores are 0.0-1.0 (e.g., 0.85 for 85% confident)
271
+ - Severity levels: critical > high > medium > low > info
272
+ - Include file:line in location for ALL findings`);
273
+ // ==========================================================================
274
+ // SECTION 9: RETRY CONTEXT (If Applicable)
275
+ // ==========================================================================
276
+ if (retryContext) {
277
+ sections.push(`
278
+ ---
279
+
280
+ # ⚠️ RETRY ATTEMPT ${retryContext.attemptNumber}/3
281
+
282
+ Previous attempt failed: ${retryContext.previousError}
283
+
284
+ Please ensure:
285
+ - Your response is valid JSON matching the schema EXACTLY
286
+ - All required fields are present
287
+ - No trailing commas or syntax errors
288
+ - No text outside the JSON object`);
289
+ }
290
+ return sections.join('\n');
291
+ }
292
+ // =============================================================================
293
+ // DIFF-FOCUSED PROMPT
294
+ // =============================================================================
295
+ /**
296
+ * Build a prompt focused on reviewing a specific diff
297
+ */
298
+ export function buildDiffReviewPrompt(diff, filePath, context, focusAreas) {
299
+ const role = selectExpertRole(focusAreas);
300
+ return `# ROLE: ${role.name}
301
+
302
+ ${role.systemPrompt}
303
+
304
+ ---
305
+
306
+ # TASK: Review This Diff
307
+
308
+ You are reviewing changes to \`${filePath}\`.
309
+
310
+ **Diff:**
311
+ \`\`\`diff
312
+ ${diff}
313
+ \`\`\`
314
+
315
+ **Focus on:**
316
+ ${focusAreas?.map(f => `- ${f}: ${FOCUS_AREA_DESCRIPTIONS[f]}`).join('\n') || '- General code quality'}
317
+
318
+ **For each issue found:**
319
+ 1. Specify the line number (from the diff, use + lines for new code)
320
+ 2. Explain the issue clearly
321
+ 3. Suggest a fix
322
+ 4. Rate confidence (0.0-1.0)
323
+
324
+ Output JSON with format:
325
+ \`\`\`json
326
+ {
327
+ "findings": [
328
+ {
329
+ "line": <number>,
330
+ "severity": "critical|high|medium|low|info",
331
+ "category": "security|performance|correctness|...",
332
+ "title": "<brief title>",
333
+ "description": "<detailed explanation>",
334
+ "suggestion": "<how to fix>",
335
+ "confidence": <0.0-1.0>
336
+ }
337
+ ],
338
+ "overall_assessment": "<brief summary>",
339
+ "risk_level": "critical|high|medium|low|minimal"
340
+ }
341
+ \`\`\``;
342
+ }
343
+ // =============================================================================
344
+ // INCREMENTAL REVIEW PROMPT
345
+ // =============================================================================
346
+ /**
347
+ * Build a follow-up prompt for clarification
348
+ */
349
+ export function buildFollowUpPrompt(originalContext, previousReview, questions) {
350
+ return `# FOLLOW-UP REVIEW
351
+
352
+ You previously reviewed this code and provided findings.
353
+
354
+ **Original Summary:**
355
+ ${originalContext.analysis.summary}
356
+
357
+ **Your Previous Review:**
358
+ ${previousReview.slice(0, 2000)}${previousReview.length > 2000 ? '...' : ''}
359
+
360
+ ---
361
+
362
+ # CLARIFICATION NEEDED
363
+
364
+ Please address these follow-up questions:
365
+
366
+ ${questions.map((q, i) => `
367
+ ${i + 1}. ${q.question}
368
+ ${q.context ? `Context: ${q.context}` : ''}
369
+ `).join('\n')}
370
+
371
+ ---
372
+
373
+ For each question, provide:
374
+ 1. Your assessment
375
+ 2. Evidence from the code
376
+ 3. Confidence level
377
+
378
+ Output JSON:
379
+ \`\`\`json
380
+ {
381
+ "answers": [
382
+ {
383
+ "question_number": <1-N>,
384
+ "answer": "<your answer>",
385
+ "evidence": "<code snippet or file:line reference>",
386
+ "confidence": <0.0-1.0>
387
+ }
388
+ ]
389
+ }
390
+ \`\`\``;
391
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Prompt Builder for AI Review
3
+ *
4
+ * Builds structured prompts that request JSON output from external CLIs.
5
+ * Supports expert roles for specialized reviews.
6
+ */
7
+ import { FocusArea, OutputType } from './types.js';
8
+ import { ReviewRequest, ExpertRole } from './adapters/base.js';
9
+ export interface PromptBuildOptions {
10
+ /** Request details */
11
+ request: ReviewRequest;
12
+ /** Override the expert role */
13
+ expertRole?: ExpertRole;
14
+ /** Model identifier for the reviewer field */
15
+ reviewerName: string;
16
+ /** Whether to use JSON output (true) or legacy markdown (false) */
17
+ useJsonOutput?: boolean;
18
+ /** Retry context */
19
+ retryContext?: {
20
+ attemptNumber: number;
21
+ previousError: string;
22
+ previousOutput: string;
23
+ };
24
+ }
25
+ /**
26
+ * Build the main review prompt
27
+ */
28
+ export declare function buildReviewPrompt(options: PromptBuildOptions): string;
29
+ /**
30
+ * Build a prompt for peer review (one model reviewing another's output)
31
+ */
32
+ export declare function buildPeerReviewPrompt(reviewerName: string, anonymizedReviewerId: string, reviewToScore: string, originalCcOutput: string): string;
33
+ export { FocusArea, OutputType };
34
+ /**
35
+ * Legacy function - builds old-style 7-section prompt
36
+ * @deprecated Use buildReviewPrompt instead
37
+ */
38
+ export declare function build7SectionPrompt(request: {
39
+ workingDir: string;
40
+ ccOutput: string;
41
+ outputType: OutputType;
42
+ analyzedFiles?: string[];
43
+ focusAreas?: FocusArea[];
44
+ customPrompt?: string;
45
+ }): string;
46
+ /**
47
+ * Legacy function - builds developer instructions
48
+ * @deprecated Use buildReviewPrompt with expertRole instead
49
+ */
50
+ export declare function buildDeveloperInstructions(cli: 'codex' | 'gemini'): string;
51
+ /**
52
+ * Legacy function - builds retry prompt
53
+ * @deprecated Use buildReviewPrompt with retryContext instead
54
+ */
55
+ export declare function buildRetryPrompt(request: {
56
+ workingDir: string;
57
+ ccOutput: string;
58
+ outputType: OutputType;
59
+ analyzedFiles?: string[];
60
+ focusAreas?: FocusArea[];
61
+ customPrompt?: string;
62
+ }, attemptNumber: number, previousError: string, previousOutput: string): string;
63
+ /**
64
+ * Validate feedback output structure
65
+ * Now supports both JSON and legacy markdown formats
66
+ */
67
+ export declare function isValidFeedbackOutput(output: string): boolean;
68
+ /**
69
+ * Detect output type from CC's output content
70
+ */
71
+ export declare function detectOutputType(ccOutput: string): OutputType;