@simonren/quorum 0.9.1 → 0.11.1

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 (68) hide show
  1. package/README.md +91 -48
  2. package/commands/multi-consult.md +47 -72
  3. package/commands/multi-review.md +68 -99
  4. package/dist/adapters/base.d.ts +53 -70
  5. package/dist/adapters/base.js +21 -79
  6. package/dist/adapters/claude.d.ts +38 -17
  7. package/dist/adapters/claude.js +93 -185
  8. package/dist/adapters/cli-adapter.d.ts +78 -0
  9. package/dist/adapters/cli-adapter.js +220 -0
  10. package/dist/adapters/codex.d.ts +18 -13
  11. package/dist/adapters/codex.js +64 -200
  12. package/dist/adapters/gemini.d.ts +45 -21
  13. package/dist/adapters/gemini.js +81 -152
  14. package/dist/adapters/index.d.ts +8 -5
  15. package/dist/adapters/index.js +7 -8
  16. package/dist/config.d.ts +98 -28
  17. package/dist/config.js +44 -25
  18. package/dist/consult-prompt.d.ts +6 -5
  19. package/dist/consult-prompt.js +48 -23
  20. package/dist/decoders/claude.d.ts +6 -0
  21. package/dist/decoders/claude.js +10 -1
  22. package/dist/doctor.d.ts +20 -0
  23. package/dist/doctor.js +91 -0
  24. package/dist/executor.d.ts +58 -46
  25. package/dist/executor.js +218 -129
  26. package/dist/guards.d.ts +29 -0
  27. package/dist/guards.js +72 -0
  28. package/dist/handoff.d.ts +79 -229
  29. package/dist/handoff.js +411 -402
  30. package/dist/index.d.ts +8 -12
  31. package/dist/index.js +81 -106
  32. package/dist/integrity.d.ts +16 -0
  33. package/dist/integrity.js +49 -0
  34. package/dist/sections.d.ts +22 -0
  35. package/dist/sections.js +31 -0
  36. package/dist/server.d.ts +9 -0
  37. package/dist/server.js +36 -0
  38. package/dist/tools/consult.d.ts +17 -76
  39. package/dist/tools/consult.js +72 -188
  40. package/dist/tools/format.d.ts +35 -0
  41. package/dist/tools/format.js +85 -0
  42. package/dist/tools/review.d.ts +55 -0
  43. package/dist/tools/review.js +120 -0
  44. package/dist/types.d.ts +20 -103
  45. package/dist/types.js +18 -29
  46. package/package.json +7 -4
  47. package/dist/cli/check.d.ts +0 -20
  48. package/dist/cli/check.js +0 -78
  49. package/dist/cli/codex.d.ts +0 -11
  50. package/dist/cli/codex.js +0 -255
  51. package/dist/cli/gemini.d.ts +0 -12
  52. package/dist/cli/gemini.js +0 -253
  53. package/dist/context.d.ts +0 -1538
  54. package/dist/context.js +0 -383
  55. package/dist/decoders/gemini.d.ts +0 -33
  56. package/dist/decoders/gemini.js +0 -58
  57. package/dist/errors.d.ts +0 -46
  58. package/dist/errors.js +0 -198
  59. package/dist/pipeline.d.ts +0 -135
  60. package/dist/pipeline.js +0 -462
  61. package/dist/prompt-v2.d.ts +0 -38
  62. package/dist/prompt-v2.js +0 -391
  63. package/dist/prompt.d.ts +0 -71
  64. package/dist/prompt.js +0 -309
  65. package/dist/schema.d.ts +0 -660
  66. package/dist/schema.js +0 -536
  67. package/dist/tools/feedback.d.ts +0 -91
  68. package/dist/tools/feedback.js +0 -117
package/dist/context.js DELETED
@@ -1,383 +0,0 @@
1
- /**
2
- * Rich Context Protocol for Review Handoff
3
- *
4
- * Defines the structured information that should flow from CC to reviewers.
5
- * This replaces the simple "ccOutput: string" with a rich, queryable context.
6
- */
7
- import { z } from 'zod';
8
- // =============================================================================
9
- // FILE CHANGE CONTEXT
10
- // =============================================================================
11
- /**
12
- * Represents a change to a single file with semantic understanding
13
- */
14
- export const FileChangeSchema = z.object({
15
- path: z.string().describe('Relative path from working directory'),
16
- language: z.string().optional().describe('Programming language'),
17
- changeType: z.enum(['created', 'modified', 'deleted', 'renamed']),
18
- // The actual changes
19
- diff: z.string().optional().describe('Unified diff format'),
20
- linesAdded: z.number().int().nonnegative().optional(),
21
- linesRemoved: z.number().int().nonnegative().optional(),
22
- // For small/new files, include full content
23
- content: z.string().optional().describe('Full file content (for new/small files)'),
24
- // Semantic understanding
25
- changedSymbols: z.array(z.object({
26
- name: z.string(),
27
- type: z.enum(['function', 'class', 'variable', 'type', 'import', 'export', 'other']),
28
- lineStart: z.number().int().positive().optional(),
29
- lineEnd: z.number().int().positive().optional(),
30
- })).optional().describe('Symbols that were modified'),
31
- // Relationships
32
- imports: z.array(z.string()).optional().describe('Modules this file imports'),
33
- importedBy: z.array(z.string()).optional().describe('Files that import this module'),
34
- testFile: z.string().optional().describe('Related test file path'),
35
- });
36
- // =============================================================================
37
- // EXECUTION CONTEXT
38
- // =============================================================================
39
- /**
40
- * Results from running tests, build, lint, etc.
41
- */
42
- export const ExecutionContextSchema = z.object({
43
- // Test results
44
- tests: z.object({
45
- ran: z.boolean(),
46
- passed: z.number().int().nonnegative().optional(),
47
- failed: z.number().int().nonnegative().optional(),
48
- skipped: z.number().int().nonnegative().optional(),
49
- failures: z.array(z.object({
50
- testName: z.string(),
51
- file: z.string().optional(),
52
- error: z.string(),
53
- })).optional(),
54
- }).optional(),
55
- // Build status
56
- build: z.object({
57
- ran: z.boolean(),
58
- success: z.boolean().optional(),
59
- errors: z.array(z.object({
60
- file: z.string(),
61
- line: z.number().int().positive().optional(),
62
- message: z.string(),
63
- })).optional(),
64
- warnings: z.array(z.object({
65
- file: z.string(),
66
- line: z.number().int().positive().optional(),
67
- message: z.string(),
68
- })).optional(),
69
- }).optional(),
70
- // Type checking
71
- typeCheck: z.object({
72
- ran: z.boolean(),
73
- errors: z.array(z.object({
74
- file: z.string(),
75
- line: z.number().int().positive().optional(),
76
- message: z.string(),
77
- code: z.string().optional(), // e.g., "TS2345"
78
- })).optional(),
79
- }).optional(),
80
- // Linting
81
- lint: z.object({
82
- ran: z.boolean(),
83
- issues: z.array(z.object({
84
- file: z.string(),
85
- line: z.number().int().positive().optional(),
86
- rule: z.string().optional(),
87
- severity: z.enum(['error', 'warning', 'info']),
88
- message: z.string(),
89
- })).optional(),
90
- }).optional(),
91
- });
92
- // =============================================================================
93
- // GIT CONTEXT
94
- // =============================================================================
95
- export const GitContextSchema = z.object({
96
- branch: z.string().optional(),
97
- baseBranch: z.string().optional().describe('Branch this was based on (e.g., main)'),
98
- // Recent commits by CC
99
- commits: z.array(z.object({
100
- hash: z.string(),
101
- message: z.string(),
102
- filesChanged: z.array(z.string()),
103
- })).optional(),
104
- // If this is for a PR
105
- pullRequest: z.object({
106
- title: z.string().optional(),
107
- description: z.string().optional(),
108
- targetBranch: z.string().optional(),
109
- }).optional(),
110
- // Uncommitted changes
111
- uncommittedChanges: z.boolean().optional(),
112
- });
113
- // =============================================================================
114
- // CC'S ANALYSIS & DECISIONS
115
- // =============================================================================
116
- export const CCAnalysisSchema = z.object({
117
- // What CC was asked to do
118
- originalRequest: z.string().describe("User's original request/task"),
119
- taskType: z.enum(['feature', 'bugfix', 'refactor', 'security-fix', 'performance', 'review', 'other']).optional(),
120
- // What CC did
121
- summary: z.string().describe('Brief summary of changes made'),
122
- // CC's findings (if reviewing/analyzing)
123
- findings: z.array(z.object({
124
- category: z.string(),
125
- description: z.string(),
126
- location: z.string().optional(),
127
- confidence: z.number().min(0).max(1).optional(),
128
- addressed: z.boolean().optional().describe('Whether CC already fixed this'),
129
- })).optional(),
130
- // What CC is uncertain about
131
- uncertainties: z.array(z.object({
132
- topic: z.string(),
133
- question: z.string(),
134
- ccBestGuess: z.string().optional().describe("CC's current assumption"),
135
- })).optional().describe('Things CC is unsure about - reviewer should verify'),
136
- // Assumptions CC made
137
- assumptions: z.array(z.string()).optional(),
138
- // Decisions CC made and why
139
- decisions: z.array(z.object({
140
- decision: z.string(),
141
- rationale: z.string(),
142
- alternatives: z.array(z.string()).optional(),
143
- })).optional(),
144
- // Overall confidence
145
- confidence: z.number().min(0).max(1).optional().describe("CC's overall confidence in the work"),
146
- });
147
- // =============================================================================
148
- // REVIEW SCOPE & GUIDANCE
149
- // =============================================================================
150
- export const ReviewScopeSchema = z.object({
151
- // What MUST be reviewed (critical paths)
152
- mustReview: z.array(z.object({
153
- path: z.string(),
154
- reason: z.string(),
155
- specificConcerns: z.array(z.string()).optional(),
156
- })).optional(),
157
- // What SHOULD be reviewed (important but not critical)
158
- shouldReview: z.array(z.object({
159
- path: z.string(),
160
- reason: z.string(),
161
- })).optional(),
162
- // What MAY be reviewed (nice to have)
163
- mayReview: z.array(z.string()).optional(),
164
- // What to SKIP (already validated, unchanged, etc.)
165
- skipReview: z.array(z.object({
166
- path: z.string(),
167
- reason: z.string(),
168
- })).optional(),
169
- // Specific questions CC wants answered
170
- questions: z.array(z.object({
171
- question: z.string(),
172
- context: z.string().optional(),
173
- relevantFiles: z.array(z.string()).optional(),
174
- ccAnswer: z.string().optional().describe("What CC thinks - for comparison"),
175
- })).optional(),
176
- });
177
- // =============================================================================
178
- // FULL REVIEW CONTEXT
179
- // =============================================================================
180
- /**
181
- * Complete context for a review request.
182
- * This is what should be passed from CC to reviewers.
183
- */
184
- export const ReviewContextSchema = z.object({
185
- // Metadata
186
- timestamp: z.string().datetime().optional(),
187
- workingDir: z.string(),
188
- // Code changes
189
- changes: z.object({
190
- files: z.array(FileChangeSchema),
191
- totalLinesAdded: z.number().int().nonnegative().optional(),
192
- totalLinesRemoved: z.number().int().nonnegative().optional(),
193
- impactedModules: z.array(z.string()).optional(),
194
- }),
195
- // CC's work
196
- analysis: CCAnalysisSchema,
197
- // Execution results
198
- execution: ExecutionContextSchema.optional(),
199
- // Git info
200
- git: GitContextSchema.optional(),
201
- // Review guidance
202
- scope: ReviewScopeSchema.optional(),
203
- // Focus areas
204
- focusAreas: z.array(z.string()).optional(),
205
- // Custom instructions
206
- customInstructions: z.string().optional(),
207
- });
208
- // =============================================================================
209
- // CONTEXT BUILDERS
210
- // =============================================================================
211
- /**
212
- * Build a minimal context from legacy inputs
213
- */
214
- export function buildMinimalContext(workingDir, ccOutput, analyzedFiles, focusAreas, customPrompt) {
215
- return {
216
- workingDir,
217
- changes: {
218
- files: (analyzedFiles || []).map(path => ({
219
- path,
220
- changeType: 'modified',
221
- })),
222
- },
223
- analysis: {
224
- originalRequest: 'Not specified',
225
- summary: ccOutput,
226
- },
227
- focusAreas,
228
- customInstructions: customPrompt,
229
- };
230
- }
231
- /**
232
- * Build context from git diff
233
- */
234
- export async function buildContextFromGitDiff(workingDir, baseBranch = 'main') {
235
- // This would shell out to git to get actual diff info
236
- // For now, return a placeholder
237
- return {
238
- workingDir,
239
- git: {
240
- baseBranch,
241
- },
242
- };
243
- }
244
- /**
245
- * Optimize context to fit within token limits while preserving important info
246
- */
247
- export function optimizeContext(context, options) {
248
- const optimized = { ...context };
249
- // Prioritize files based on focus areas
250
- if (options.focusAreas && options.focusAreas.length > 0) {
251
- const priorityPatterns = getPriorityPatterns(options.focusAreas);
252
- optimized.changes.files = optimized.changes.files.sort((a, b) => {
253
- const aPriority = getPriority(a.path, priorityPatterns);
254
- const bPriority = getPriority(b.path, priorityPatterns);
255
- return bPriority - aPriority;
256
- });
257
- }
258
- // Truncate diffs if too large
259
- if (!options.includeDiffs) {
260
- optimized.changes.files = optimized.changes.files.map(f => ({
261
- ...f,
262
- diff: undefined,
263
- }));
264
- }
265
- // Remove full content if not needed
266
- if (!options.includeFullContent) {
267
- optimized.changes.files = optimized.changes.files.map(f => ({
268
- ...f,
269
- content: undefined,
270
- }));
271
- }
272
- return optimized;
273
- }
274
- function getPriorityPatterns(focusAreas) {
275
- const patterns = [];
276
- if (focusAreas.includes('security')) {
277
- patterns.push(/auth/i, /login/i, /password/i, /crypto/i, /token/i, /api/i);
278
- }
279
- if (focusAreas.includes('performance')) {
280
- patterns.push(/database/i, /query/i, /cache/i, /service/i);
281
- }
282
- if (focusAreas.includes('testing')) {
283
- patterns.push(/test/i, /spec/i, /mock/i);
284
- }
285
- return patterns;
286
- }
287
- function getPriority(path, patterns) {
288
- return patterns.filter(p => p.test(path)).length;
289
- }
290
- // =============================================================================
291
- // CONTEXT SERIALIZATION FOR PROMPTS
292
- // =============================================================================
293
- /**
294
- * Convert context to a string suitable for inclusion in prompts
295
- */
296
- export function contextToPromptString(context) {
297
- const sections = [];
298
- // Section 1: Task Overview
299
- sections.push(`## Task Overview
300
- **Original Request:** ${context.analysis.originalRequest}
301
- **Summary:** ${context.analysis.summary}
302
- ${context.analysis.taskType ? `**Task Type:** ${context.analysis.taskType}` : ''}
303
- ${context.analysis.confidence !== undefined ? `**CC Confidence:** ${Math.round(context.analysis.confidence * 100)}%` : ''}`);
304
- // Section 2: Files Changed
305
- if (context.changes.files.length > 0) {
306
- sections.push(`\n## Files Changed (${context.changes.files.length})`);
307
- for (const file of context.changes.files) {
308
- let fileInfo = `\n### ${file.path} [${file.changeType}]`;
309
- if (file.changedSymbols && file.changedSymbols.length > 0) {
310
- fileInfo += `\nModified: ${file.changedSymbols.map(s => `${s.name} (${s.type})`).join(', ')}`;
311
- }
312
- if (file.linesAdded !== undefined || file.linesRemoved !== undefined) {
313
- fileInfo += `\nLines: +${file.linesAdded || 0} / -${file.linesRemoved || 0}`;
314
- }
315
- if (file.diff) {
316
- fileInfo += `\n\`\`\`diff\n${file.diff}\n\`\`\``;
317
- }
318
- sections.push(fileInfo);
319
- }
320
- }
321
- // Section 3: CC's Uncertainties (IMPORTANT for reviewer)
322
- if (context.analysis.uncertainties && context.analysis.uncertainties.length > 0) {
323
- sections.push(`\n## CC's Uncertainties (Please Verify)`);
324
- for (const u of context.analysis.uncertainties) {
325
- sections.push(`\n**${u.topic}**
326
- Question: ${u.question}
327
- ${u.ccBestGuess ? `CC's guess: ${u.ccBestGuess}` : ''}`);
328
- }
329
- }
330
- // Section 4: Questions for Reviewer
331
- if (context.scope?.questions && context.scope.questions.length > 0) {
332
- sections.push(`\n## Specific Questions`);
333
- for (const q of context.scope.questions) {
334
- sections.push(`\n- ${q.question}${q.ccAnswer ? ` (CC thinks: ${q.ccAnswer})` : ''}`);
335
- }
336
- }
337
- // Section 5: Execution Results
338
- if (context.execution) {
339
- const exec = context.execution;
340
- const execLines = [];
341
- if (exec.tests?.ran) {
342
- const t = exec.tests;
343
- execLines.push(`Tests: ${t.passed || 0} passed, ${t.failed || 0} failed, ${t.skipped || 0} skipped`);
344
- if (t.failures && t.failures.length > 0) {
345
- for (const f of t.failures.slice(0, 3)) {
346
- execLines.push(` ❌ ${f.testName}: ${f.error.slice(0, 100)}`);
347
- }
348
- }
349
- }
350
- if (exec.build?.ran) {
351
- execLines.push(`Build: ${exec.build.success ? '✓ Success' : '❌ Failed'}`);
352
- }
353
- if (exec.typeCheck?.ran && exec.typeCheck.errors && exec.typeCheck.errors.length > 0) {
354
- execLines.push(`Type Errors: ${exec.typeCheck.errors.length}`);
355
- }
356
- if (execLines.length > 0) {
357
- sections.push(`\n## Execution Results\n${execLines.join('\n')}`);
358
- }
359
- }
360
- // Section 6: Review Priorities
361
- if (context.scope?.mustReview && context.scope.mustReview.length > 0) {
362
- sections.push(`\n## Priority Review Areas`);
363
- for (const r of context.scope.mustReview) {
364
- sections.push(`- **${r.path}**: ${r.reason}`);
365
- }
366
- }
367
- return sections.join('\n');
368
- }
369
- /**
370
- * Check if a file:line reference is valid
371
- */
372
- export function verifyFileLineReference(reference, verification) {
373
- if (!verification.existingFiles.has(reference.file)) {
374
- return { valid: false, reason: `File does not exist: ${reference.file}` };
375
- }
376
- if (reference.line !== undefined) {
377
- const lineCount = verification.fileLineCounts.get(reference.file);
378
- if (lineCount && reference.line > lineCount) {
379
- return { valid: false, reason: `Line ${reference.line} exceeds file length (${lineCount} lines)` };
380
- }
381
- }
382
- return { valid: true };
383
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * GeminiEventDecoder — Parses Gemini CLI stream-json JSONL events.
3
- *
4
- * Concatenates assistant message deltas into a final response,
5
- * tracks stats from the result event, and emits progress callbacks.
6
- */
7
- export interface GeminiEvent {
8
- type: string;
9
- session_id?: string;
10
- model?: string;
11
- role?: string;
12
- content?: string;
13
- delta?: boolean;
14
- tool_name?: string;
15
- tool_id?: string;
16
- status?: string;
17
- stats?: {
18
- total_tokens: number;
19
- input_tokens: number;
20
- output_tokens: number;
21
- duration_ms: number;
22
- [key: string]: unknown;
23
- };
24
- }
25
- export declare class GeminiEventDecoder {
26
- private assistantChunks;
27
- private _stats;
28
- onProgress?: (eventType: string, detail?: string) => void;
29
- processLine(line: string): void;
30
- getFinalResponse(): string;
31
- getStats(): GeminiEvent['stats'] | null;
32
- private describeEvent;
33
- }
@@ -1,58 +0,0 @@
1
- /**
2
- * GeminiEventDecoder — Parses Gemini CLI stream-json JSONL events.
3
- *
4
- * Concatenates assistant message deltas into a final response,
5
- * tracks stats from the result event, and emits progress callbacks.
6
- */
7
- export class GeminiEventDecoder {
8
- assistantChunks = [];
9
- _stats = null;
10
- onProgress;
11
- processLine(line) {
12
- let event;
13
- try {
14
- const parsed = JSON.parse(line);
15
- if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed))
16
- return;
17
- event = parsed;
18
- }
19
- catch {
20
- return;
21
- }
22
- if (!event.type)
23
- return;
24
- this.onProgress?.(event.type, this.describeEvent(event));
25
- switch (event.type) {
26
- case 'message':
27
- if (event.role === 'assistant' && event.delta && event.content) {
28
- this.assistantChunks.push(event.content);
29
- }
30
- break;
31
- case 'result':
32
- if (event.stats) {
33
- this._stats = event.stats;
34
- }
35
- break;
36
- }
37
- }
38
- getFinalResponse() {
39
- return this.assistantChunks.join('');
40
- }
41
- getStats() {
42
- return this._stats;
43
- }
44
- describeEvent(event) {
45
- switch (event.type) {
46
- case 'init':
47
- return `model: ${event.model || 'unknown'}`;
48
- case 'tool_use':
49
- return `tool: ${event.tool_name || 'unknown'}`;
50
- case 'tool_result':
51
- return `status: ${event.status || 'unknown'}`;
52
- case 'result':
53
- return `status: ${event.status || 'unknown'}`;
54
- default:
55
- return '';
56
- }
57
- }
58
- }
package/dist/errors.d.ts DELETED
@@ -1,46 +0,0 @@
1
- /**
2
- * Error Handling for AI Reviewer MCP Server
3
- */
4
- import { FeedbackError, CliType } from './types.js';
5
- /**
6
- * Create a CLI not found error
7
- */
8
- export declare function createCliNotFoundError(cli: CliType): FeedbackError;
9
- /**
10
- * Create a timeout error
11
- */
12
- export declare function createTimeoutError(cli: CliType, durationMs: number): FeedbackError;
13
- /**
14
- * Create a rate limit error
15
- */
16
- export declare function createRateLimitError(cli: CliType, retryAfterMs?: number): FeedbackError;
17
- /**
18
- * Create an auth error
19
- */
20
- export declare function createAuthError(cli: CliType, message: string): FeedbackError;
21
- /**
22
- * Create an invalid response error
23
- */
24
- export declare function createInvalidResponseError(cli: CliType, rawOutput: string): FeedbackError;
25
- /**
26
- * Create a CLI crash error
27
- */
28
- export declare function createCliError(cli: CliType, exitCode: number, stderr: string): FeedbackError;
29
- /**
30
- * Format an error for user display
31
- */
32
- export declare function formatErrorForUser(error: FeedbackError): string;
33
- /**
34
- * Detect error type from CLI output and error messages
35
- */
36
- export declare function detectErrorType(cli: CliType, error: Error & {
37
- code?: string;
38
- }, stdout: string, stderr: string, exitCode: number | null): FeedbackError;
39
- /**
40
- * Parse retry-after from error response
41
- */
42
- export declare function parseRetryAfter(errorMessage: string): number | undefined;
43
- /**
44
- * Generate suggestion based on error type
45
- */
46
- export declare function getSuggestion(error: FeedbackError): string | undefined;