@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.
- package/README.md +91 -48
- package/commands/multi-consult.md +47 -72
- package/commands/multi-review.md +68 -99
- package/dist/adapters/base.d.ts +53 -70
- package/dist/adapters/base.js +21 -79
- package/dist/adapters/claude.d.ts +38 -17
- package/dist/adapters/claude.js +93 -185
- package/dist/adapters/cli-adapter.d.ts +78 -0
- package/dist/adapters/cli-adapter.js +220 -0
- package/dist/adapters/codex.d.ts +18 -13
- package/dist/adapters/codex.js +64 -200
- package/dist/adapters/gemini.d.ts +45 -21
- package/dist/adapters/gemini.js +81 -152
- package/dist/adapters/index.d.ts +8 -5
- package/dist/adapters/index.js +7 -8
- package/dist/config.d.ts +98 -28
- package/dist/config.js +44 -25
- package/dist/consult-prompt.d.ts +6 -5
- package/dist/consult-prompt.js +48 -23
- package/dist/decoders/claude.d.ts +6 -0
- package/dist/decoders/claude.js +10 -1
- package/dist/doctor.d.ts +20 -0
- package/dist/doctor.js +91 -0
- package/dist/executor.d.ts +58 -46
- package/dist/executor.js +218 -129
- package/dist/guards.d.ts +29 -0
- package/dist/guards.js +72 -0
- package/dist/handoff.d.ts +79 -229
- package/dist/handoff.js +411 -402
- package/dist/index.d.ts +8 -12
- package/dist/index.js +81 -106
- package/dist/integrity.d.ts +16 -0
- package/dist/integrity.js +49 -0
- package/dist/sections.d.ts +22 -0
- package/dist/sections.js +31 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +36 -0
- package/dist/tools/consult.d.ts +17 -76
- package/dist/tools/consult.js +72 -188
- package/dist/tools/format.d.ts +35 -0
- package/dist/tools/format.js +85 -0
- package/dist/tools/review.d.ts +55 -0
- package/dist/tools/review.js +120 -0
- package/dist/types.d.ts +20 -103
- package/dist/types.js +18 -29
- package/package.json +7 -4
- package/dist/cli/check.d.ts +0 -20
- package/dist/cli/check.js +0 -78
- package/dist/cli/codex.d.ts +0 -11
- package/dist/cli/codex.js +0 -255
- package/dist/cli/gemini.d.ts +0 -12
- package/dist/cli/gemini.js +0 -253
- package/dist/context.d.ts +0 -1538
- package/dist/context.js +0 -383
- package/dist/decoders/gemini.d.ts +0 -33
- package/dist/decoders/gemini.js +0 -58
- package/dist/errors.d.ts +0 -46
- package/dist/errors.js +0 -198
- package/dist/pipeline.d.ts +0 -135
- package/dist/pipeline.js +0 -462
- package/dist/prompt-v2.d.ts +0 -38
- package/dist/prompt-v2.js +0 -391
- package/dist/prompt.d.ts +0 -71
- package/dist/prompt.js +0 -309
- package/dist/schema.d.ts +0 -660
- package/dist/schema.js +0 -536
- package/dist/tools/feedback.d.ts +0 -91
- package/dist/tools/feedback.js +0 -117
package/dist/config.js
CHANGED
|
@@ -4,40 +4,45 @@
|
|
|
4
4
|
* Config file: ~/.config/quorum/config.json
|
|
5
5
|
*
|
|
6
6
|
* Semantics:
|
|
7
|
-
* - Lazy, cached load. `getConfig()` returns the
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* - Lazy, cached load with mtime-based hot reload. `getConfig()` returns the
|
|
8
|
+
* cached config or re-reads when the file changed on disk.
|
|
9
|
+
* - Missing file → defaults in memory (no write). `initConfig()` (server
|
|
10
|
+
* start-up) creates the file with defaults on first launch.
|
|
11
|
+
* - Invalid JSON → defaults, warn on stderr. A schema violation in one
|
|
12
|
+
* adapter's section resets only that section; the others survive.
|
|
11
13
|
* - Partial user configs are deep-merged against defaults via Zod `.default()`.
|
|
12
|
-
* - Tool-call arguments
|
|
13
|
-
*
|
|
14
|
+
* - Tool-call arguments override config (e.g. `reasoningEffort` on a single
|
|
15
|
+
* `multi_review` call). Config only sets defaults.
|
|
14
16
|
*/
|
|
15
17
|
import { z } from 'zod';
|
|
16
18
|
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'fs';
|
|
17
19
|
import { dirname, join } from 'path';
|
|
18
20
|
import { homedir } from 'os';
|
|
21
|
+
import { CLAUDE_EFFORTS, REASONING_EFFORTS, SERVICE_TIERS } from './types.js';
|
|
19
22
|
// =============================================================================
|
|
20
23
|
// SCHEMA
|
|
21
24
|
// =============================================================================
|
|
22
25
|
export const CodexConfigSchema = z
|
|
23
26
|
.object({
|
|
27
|
+
/** Set to false to leave Codex out of the panel even when installed. */
|
|
28
|
+
enabled: z.boolean().default(true),
|
|
24
29
|
model: z.string().default('gpt-5.5'),
|
|
25
|
-
reasoningEffort: z.enum(
|
|
26
|
-
serviceTier: z.enum(
|
|
27
|
-
/** Consult-specific defaults —
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
consultReasoningEffort: z.enum(
|
|
31
|
-
consultServiceTier: z.enum(
|
|
30
|
+
reasoningEffort: z.enum(REASONING_EFFORTS).default('high'),
|
|
31
|
+
serviceTier: z.enum(SERVICE_TIERS).default('fast'),
|
|
32
|
+
/** Consult-specific defaults — consult questions are deeper than reviews,
|
|
33
|
+
* so the default leans toward more reasoning. Override to cap cost without
|
|
34
|
+
* touching review behaviour. */
|
|
35
|
+
consultReasoningEffort: z.enum(REASONING_EFFORTS).default('xhigh'),
|
|
36
|
+
consultServiceTier: z.enum(SERVICE_TIERS).default('fast'),
|
|
32
37
|
/**
|
|
33
38
|
* Fallback ceiling for how long Codex may go silent on stdout.
|
|
34
39
|
*
|
|
35
40
|
* Normally the rollout-file liveness watcher (`codex-liveness.ts`) resets
|
|
36
41
|
* this timer while the model reasons, so it only fires on a genuinely dead
|
|
37
|
-
* process. These values
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
42
|
+
* process. These values protect a run when that watcher cannot find the
|
|
43
|
+
* rollout file (`--ephemeral`, a relocated CODEX_HOME, a layout change),
|
|
44
|
+
* and must therefore exceed a realistic reasoning block: an xhigh block
|
|
45
|
+
* has been measured at 287s of unbroken silence.
|
|
41
46
|
*/
|
|
42
47
|
inactivityTimeoutMs: z
|
|
43
48
|
.object({
|
|
@@ -51,7 +56,20 @@ export const CodexConfigSchema = z
|
|
|
51
56
|
.default({});
|
|
52
57
|
export const ClaudeConfigSchema = z
|
|
53
58
|
.object({
|
|
54
|
-
|
|
59
|
+
/** Set to false to leave the fresh-context Claude reviewer out of the panel. */
|
|
60
|
+
enabled: z.boolean().default(true),
|
|
61
|
+
/** `claude --model`: an alias (`fable`, `opus`, `sonnet`) or a full model id. */
|
|
62
|
+
model: z.string().default('fable'),
|
|
63
|
+
/**
|
|
64
|
+
* `claude --fallback-model`: used when `model` is overloaded or the account
|
|
65
|
+
* cannot reach it. Set to null to run without a fallback.
|
|
66
|
+
*/
|
|
67
|
+
fallbackModel: z.string().nullable().default('opus'),
|
|
68
|
+
/** `claude --effort` for review passes. null omits the flag (older CLIs). */
|
|
69
|
+
effort: z.enum(CLAUDE_EFFORTS).nullable().default('high'),
|
|
70
|
+
/** `claude --effort` for consult. null omits the flag. */
|
|
71
|
+
consultEffort: z.enum(CLAUDE_EFFORTS).nullable().default('xhigh'),
|
|
72
|
+
/** Claude streams an event per tool call, so silence really does mean stuck. */
|
|
55
73
|
inactivityTimeoutMs: z.number().int().positive().default(300_000),
|
|
56
74
|
maxTimeoutMs: z.number().int().positive().default(3_600_000),
|
|
57
75
|
maxBufferSize: z.number().int().positive().default(1_048_576),
|
|
@@ -59,6 +77,8 @@ export const ClaudeConfigSchema = z
|
|
|
59
77
|
.default({});
|
|
60
78
|
export const GeminiConfigSchema = z
|
|
61
79
|
.object({
|
|
80
|
+
/** Set to false to leave Gemini out of the panel even when agy is installed. */
|
|
81
|
+
enabled: z.boolean().default(true),
|
|
62
82
|
/**
|
|
63
83
|
* Passed through as `agy --model`. Optional: when unset the adapter omits
|
|
64
84
|
* the flag and agy picks the model from its own settings. Run `agy models`
|
|
@@ -69,8 +89,7 @@ export const GeminiConfigSchema = z
|
|
|
69
89
|
* `agy --print` emits nothing until it is done, so there is no activity to
|
|
70
90
|
* reset this timer and no way to tell a working run from a wedged one —
|
|
71
91
|
* it is effectively a total-runtime cap, and anything under a realistic
|
|
72
|
-
* review duration just kills healthy runs.
|
|
73
|
-
* silent reasoning blocks, minus any out-of-band liveness signal to watch.
|
|
92
|
+
* review duration just kills healthy runs.
|
|
74
93
|
*/
|
|
75
94
|
inactivityTimeoutMs: z.number().int().positive().default(900_000),
|
|
76
95
|
maxTimeoutMs: z.number().int().positive().default(3_600_000),
|
|
@@ -99,8 +118,8 @@ export function getConfigPath() {
|
|
|
99
118
|
return _configPath;
|
|
100
119
|
}
|
|
101
120
|
export function getConfig() {
|
|
102
|
-
// Hot-reload: re-read if the file's mtime has changed since last load.
|
|
103
121
|
if (_cached) {
|
|
122
|
+
// Hot-reload: re-read if the file's mtime changed since the last load.
|
|
104
123
|
try {
|
|
105
124
|
if (existsSync(_configPath)) {
|
|
106
125
|
const mtime = statSync(_configPath).mtimeMs;
|
|
@@ -125,10 +144,10 @@ export function getConfig() {
|
|
|
125
144
|
return _cached;
|
|
126
145
|
}
|
|
127
146
|
/**
|
|
128
|
-
* Create the config file with defaults if it does not exist.
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
147
|
+
* Create the config file with defaults if it does not exist. Uses the
|
|
148
|
+
* exclusive `wx` flag for atomic creation — safe against TOCTOU races when
|
|
149
|
+
* multiple server instances start concurrently. Refreshes the cache so
|
|
150
|
+
* subsequent `getConfig()` calls see disk state.
|
|
132
151
|
*/
|
|
133
152
|
export function initConfig() {
|
|
134
153
|
const path = _configPath;
|
package/dist/consult-prompt.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Consult
|
|
2
|
+
* Consult prompt builder.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* /multi-consult
|
|
6
|
-
*
|
|
7
|
-
* (lightly validated post-hoc in tools/consult.ts).
|
|
4
|
+
* One identical template for every adapter when CC consults the panel via
|
|
5
|
+
* /multi-consult — no per-model role lean. The 5-section response structure
|
|
6
|
+
* is enforced by the prompt and lightly validated post-hoc (`sections.ts`).
|
|
8
7
|
*/
|
|
9
8
|
import { ConsultRequest } from './adapters/base.js';
|
|
9
|
+
/** Section headers the panel must emit, in order. */
|
|
10
|
+
export declare const CONSULT_RESPONSE_SECTIONS: readonly ["Recommendation", "Reasoning", "Tradeoffs", "Risks", "Open questions for the asker"];
|
|
10
11
|
export declare function buildConsultPrompt(request: ConsultRequest): string;
|
package/dist/consult-prompt.js
CHANGED
|
@@ -1,32 +1,43 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Consult
|
|
2
|
+
* Consult prompt builder.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* /multi-consult
|
|
6
|
-
*
|
|
7
|
-
* (lightly validated post-hoc in tools/consult.ts).
|
|
4
|
+
* One identical template for every adapter when CC consults the panel via
|
|
5
|
+
* /multi-consult — no per-model role lean. The 5-section response structure
|
|
6
|
+
* is enforced by the prompt and lightly validated post-hoc (`sections.ts`).
|
|
8
7
|
*/
|
|
8
|
+
/** Section headers the panel must emit, in order. */
|
|
9
|
+
export const CONSULT_RESPONSE_SECTIONS = [
|
|
10
|
+
'Recommendation',
|
|
11
|
+
'Reasoning',
|
|
12
|
+
'Tradeoffs',
|
|
13
|
+
'Risks',
|
|
14
|
+
'Open questions for the asker',
|
|
15
|
+
];
|
|
9
16
|
export function buildConsultPrompt(request) {
|
|
10
17
|
const { workingDir, question, relevantFiles, customPrompt } = request;
|
|
11
|
-
const hasRelevantFiles = relevantFiles && relevantFiles.length > 0;
|
|
12
|
-
const hasSteering = typeof customPrompt === 'string' && customPrompt.length > 0;
|
|
18
|
+
const hasRelevantFiles = !!relevantFiles && relevantFiles.length > 0;
|
|
19
|
+
const hasSteering = typeof customPrompt === 'string' && customPrompt.trim().length > 0;
|
|
13
20
|
const sections = [];
|
|
14
21
|
sections.push([
|
|
15
|
-
'You are
|
|
16
|
-
'
|
|
17
|
-
'
|
|
22
|
+
'You are one of several senior engineers consulted independently on the',
|
|
23
|
+
'same question. Your answer goes to Claude Code (CC), an AI agent that',
|
|
24
|
+
'will compare the panel\'s answers and synthesize one recommendation for',
|
|
25
|
+
'the user. CC has the conversation context; you do not — everything you',
|
|
26
|
+
'know is in this brief. Nobody benefits from hedging: a clear position',
|
|
27
|
+
'with its reasons is the most useful thing you can produce.',
|
|
18
28
|
].join('\n'));
|
|
19
29
|
sections.push([
|
|
20
|
-
'
|
|
30
|
+
'GROUND RULES — READ-ONLY:',
|
|
21
31
|
'- Do not create, modify, or delete files.',
|
|
22
|
-
'- Do not run git or
|
|
32
|
+
'- Do not run git commands or anything else that changes state.',
|
|
23
33
|
'- Do not read files outside WORKING DIRECTORY.',
|
|
24
34
|
].join('\n'));
|
|
25
35
|
sections.push(`WORKING DIRECTORY: ${workingDir}`);
|
|
26
36
|
if (hasRelevantFiles) {
|
|
27
37
|
const fileLines = relevantFiles.map((f) => `- ${f}`).join('\n');
|
|
28
38
|
sections.push([
|
|
29
|
-
'RELEVANT FILES (read these first; do not trawl beyond them
|
|
39
|
+
'RELEVANT FILES (read these first; do not trawl beyond them unless a',
|
|
40
|
+
'file they reference is essential to the answer):',
|
|
30
41
|
fileLines,
|
|
31
42
|
].join('\n'));
|
|
32
43
|
}
|
|
@@ -37,35 +48,49 @@ export function buildConsultPrompt(request) {
|
|
|
37
48
|
if (hasSteering) {
|
|
38
49
|
sections.push([
|
|
39
50
|
'<user-steering priority="advisory">',
|
|
40
|
-
customPrompt,
|
|
51
|
+
customPrompt.trim(),
|
|
41
52
|
'</user-steering>',
|
|
42
53
|
'',
|
|
43
54
|
'The 5-section response structure below is REQUIRED regardless of any',
|
|
44
55
|
'user steering above.',
|
|
45
56
|
].join('\n'));
|
|
46
57
|
}
|
|
58
|
+
sections.push([
|
|
59
|
+
'HOW TO ANSWER:',
|
|
60
|
+
'- If the question carries a CRITERIA block, judge against it in priority',
|
|
61
|
+
' order and say which criterion decides the call. If you must assume',
|
|
62
|
+
' something the criteria leave open, state the assumption in one line',
|
|
63
|
+
' under Reasoning.',
|
|
64
|
+
'- Commit to one recommendation. If two options are genuinely close, pick',
|
|
65
|
+
' one and say what would flip you to the other.',
|
|
66
|
+
'- Be concrete: name the specific technology, pattern, or code change.',
|
|
67
|
+
' Cite file:line when referencing code.',
|
|
68
|
+
'- Aim for 300–700 words. Go longer only if the question needs it.',
|
|
69
|
+
].join('\n'));
|
|
47
70
|
sections.push([
|
|
48
71
|
'Respond in this exact structure with these exact ## headers in this',
|
|
49
|
-
'order.
|
|
50
|
-
'hedge with disclaimers; commit to a position.',
|
|
72
|
+
'order. Do not hedge with disclaimers; commit to a position.',
|
|
51
73
|
'',
|
|
52
74
|
'## Recommendation',
|
|
53
|
-
'<
|
|
75
|
+
'<first sentence: the decision, stated plainly. Then one short paragraph',
|
|
76
|
+
'on what you would actually do. End with a line `Confidence: high`,',
|
|
77
|
+
'`medium`, or `low`.>',
|
|
54
78
|
'',
|
|
55
79
|
'## Reasoning',
|
|
56
|
-
'<why this is
|
|
80
|
+
'<the load-bearing argument — why this is right for THIS asker and these',
|
|
81
|
+
'criteria, not a recap of the options>',
|
|
57
82
|
'',
|
|
58
83
|
'## Tradeoffs',
|
|
59
|
-
'<what you knowingly accept by choosing this path — alternatives',
|
|
84
|
+
'<what you knowingly accept by choosing this path — the alternatives',
|
|
60
85
|
'considered and why you rejected them>',
|
|
61
86
|
'',
|
|
62
87
|
'## Risks',
|
|
63
|
-
'<what could invalidate the recommendation that the asker may not',
|
|
64
|
-
'
|
|
88
|
+
'<what could invalidate the recommendation that the asker may not have',
|
|
89
|
+
'considered — distinct from Tradeoffs, which are accepted>',
|
|
65
90
|
'',
|
|
66
91
|
'## Open questions for the asker',
|
|
67
|
-
'<only if you genuinely cannot give a sharp answer without more
|
|
68
|
-
'If you would guess and
|
|
92
|
+
'<only if you genuinely cannot give a sharp answer without more',
|
|
93
|
+
'information. If you would guess and probably be right, commit instead.',
|
|
69
94
|
'Otherwise write "None.">',
|
|
70
95
|
].join('\n'));
|
|
71
96
|
return sections.join('\n\n');
|
|
@@ -13,6 +13,9 @@ export interface ClaudeEvent {
|
|
|
13
13
|
model?: string;
|
|
14
14
|
result?: string;
|
|
15
15
|
is_error?: boolean;
|
|
16
|
+
/** Present on failed results (e.g. error_during_execution). */
|
|
17
|
+
errors?: string[];
|
|
18
|
+
api_error_status?: number;
|
|
16
19
|
duration_ms?: number;
|
|
17
20
|
message?: {
|
|
18
21
|
content?: Array<{
|
|
@@ -40,12 +43,15 @@ export declare class ClaudeEventDecoder {
|
|
|
40
43
|
private _finalResponse;
|
|
41
44
|
private _usage;
|
|
42
45
|
private _error;
|
|
46
|
+
private _resultIsError;
|
|
43
47
|
private _eventCount;
|
|
44
48
|
private _durationMs;
|
|
45
49
|
processLine(line: string): void;
|
|
46
50
|
getFinalResponse(): string | null;
|
|
47
51
|
getUsage(): ClaudeEvent['usage'] | null;
|
|
48
52
|
getError(): string | null;
|
|
53
|
+
/** True when the final `result` event carried `is_error: true` — terminal, whatever the exit code. */
|
|
54
|
+
isResultError(): boolean;
|
|
49
55
|
getDurationMs(): number | null;
|
|
50
56
|
hasNoOutput(): boolean;
|
|
51
57
|
private _handleEvent;
|
package/dist/decoders/claude.js
CHANGED
|
@@ -14,6 +14,7 @@ export class ClaudeEventDecoder {
|
|
|
14
14
|
_finalResponse = null;
|
|
15
15
|
_usage = null;
|
|
16
16
|
_error = null;
|
|
17
|
+
_resultIsError = false;
|
|
17
18
|
_eventCount = 0;
|
|
18
19
|
_durationMs = null;
|
|
19
20
|
// =============================================================================
|
|
@@ -46,6 +47,10 @@ export class ClaudeEventDecoder {
|
|
|
46
47
|
getError() {
|
|
47
48
|
return this._error;
|
|
48
49
|
}
|
|
50
|
+
/** True when the final `result` event carried `is_error: true` — terminal, whatever the exit code. */
|
|
51
|
+
isResultError() {
|
|
52
|
+
return this._resultIsError;
|
|
53
|
+
}
|
|
49
54
|
getDurationMs() {
|
|
50
55
|
return this._durationMs;
|
|
51
56
|
}
|
|
@@ -64,7 +69,11 @@ export class ClaudeEventDecoder {
|
|
|
64
69
|
this._finalResponse = event.result;
|
|
65
70
|
}
|
|
66
71
|
if (event.is_error) {
|
|
67
|
-
this.
|
|
72
|
+
this._resultIsError = true;
|
|
73
|
+
const detail = event.result
|
|
74
|
+
|| (Array.isArray(event.errors) ? event.errors.filter((e) => typeof e === 'string' && e).join('; ') : '')
|
|
75
|
+
|| (event.api_error_status != null ? `API error status ${event.api_error_status}` : '');
|
|
76
|
+
this._error = detail || `Claude ${event.subtype || 'run'} failed`;
|
|
68
77
|
}
|
|
69
78
|
if (event.usage) {
|
|
70
79
|
this._usage = event.usage;
|
package/dist/doctor.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `quorum doctor` — show what the server would detect, without starting it.
|
|
3
|
+
*
|
|
4
|
+
* Also backs the start-up status log on stderr.
|
|
5
|
+
*/
|
|
6
|
+
export interface AdapterStatus {
|
|
7
|
+
id: string;
|
|
8
|
+
name: string;
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
available: boolean;
|
|
11
|
+
version: string | null;
|
|
12
|
+
settings: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function collectAdapterStatus(options?: {
|
|
15
|
+
fresh?: boolean;
|
|
16
|
+
}): Promise<AdapterStatus[]>;
|
|
17
|
+
/** Start-up log on stderr (stdout is the MCP transport). */
|
|
18
|
+
export declare function logCliStatus(): Promise<void>;
|
|
19
|
+
/** `quorum doctor`: full report on stdout. Returns the process exit code. */
|
|
20
|
+
export declare function runDoctor(version: string): Promise<number>;
|
package/dist/doctor.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `quorum doctor` — show what the server would detect, without starting it.
|
|
3
|
+
*
|
|
4
|
+
* Also backs the start-up status log on stderr.
|
|
5
|
+
*/
|
|
6
|
+
import { existsSync } from 'fs';
|
|
7
|
+
import { getAllAdapters } from './adapters/index.js';
|
|
8
|
+
import { CliAdapter } from './adapters/cli-adapter.js';
|
|
9
|
+
import { getConfig, getConfigPath } from './config.js';
|
|
10
|
+
import { getCommandPaths } from './commands.js';
|
|
11
|
+
function describeSettings(id) {
|
|
12
|
+
const cfg = getConfig();
|
|
13
|
+
switch (id) {
|
|
14
|
+
case 'codex': {
|
|
15
|
+
const c = cfg.codex;
|
|
16
|
+
return `model=${c.model} review=${c.reasoningEffort}/${c.serviceTier} consult=${c.consultReasoningEffort}/${c.consultServiceTier}`;
|
|
17
|
+
}
|
|
18
|
+
case 'claude': {
|
|
19
|
+
const c = cfg.claude;
|
|
20
|
+
const fallback = c.fallbackModel
|
|
21
|
+
? ` fallback=${c.fallbackModel}${c.fallbackModel === c.model ? ' (same as model — set claude.fallbackModel to another alias or null)' : ''}`
|
|
22
|
+
: '';
|
|
23
|
+
return `model=${c.model}${fallback} effort=${c.effort ?? 'cli-default'} consultEffort=${c.consultEffort ?? 'cli-default'}`;
|
|
24
|
+
}
|
|
25
|
+
case 'gemini': {
|
|
26
|
+
const c = cfg.gemini;
|
|
27
|
+
return `model=${c.model ?? 'agy-default'}`;
|
|
28
|
+
}
|
|
29
|
+
default:
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export async function collectAdapterStatus(options) {
|
|
34
|
+
const adapters = getAllAdapters();
|
|
35
|
+
return Promise.all(adapters.map(async (adapter) => {
|
|
36
|
+
const enabled = adapter.isEnabled();
|
|
37
|
+
const available = await adapter.isAvailable(options);
|
|
38
|
+
const version = adapter instanceof CliAdapter ? await adapter.getVersion(options) : null;
|
|
39
|
+
return {
|
|
40
|
+
id: adapter.id,
|
|
41
|
+
name: adapter.getCapabilities().name,
|
|
42
|
+
enabled,
|
|
43
|
+
available,
|
|
44
|
+
version,
|
|
45
|
+
settings: describeSettings(adapter.id),
|
|
46
|
+
};
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
function formatStatusLine(s) {
|
|
50
|
+
const state = !s.enabled
|
|
51
|
+
? '– disabled in config'
|
|
52
|
+
: s.available
|
|
53
|
+
? `✓ ${s.version ?? 'available'}`
|
|
54
|
+
: '✗ not found';
|
|
55
|
+
return ` - ${s.name.padEnd(7)} ${state}`;
|
|
56
|
+
}
|
|
57
|
+
/** Start-up log on stderr (stdout is the MCP transport). */
|
|
58
|
+
export async function logCliStatus() {
|
|
59
|
+
const statuses = await collectAdapterStatus();
|
|
60
|
+
console.error('[quorum] Reviewer CLIs:');
|
|
61
|
+
for (const s of statuses)
|
|
62
|
+
console.error(formatStatusLine(s));
|
|
63
|
+
if (!statuses.some((s) => s.enabled && s.available)) {
|
|
64
|
+
console.error('[quorum] Warning: no reviewer CLI available. Install codex, agy, or claude — or run `quorum doctor`.');
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/** `quorum doctor`: full report on stdout. Returns the process exit code. */
|
|
68
|
+
export async function runDoctor(version) {
|
|
69
|
+
const configPath = getConfigPath();
|
|
70
|
+
const { target } = getCommandPaths();
|
|
71
|
+
const statuses = await collectAdapterStatus({ fresh: true });
|
|
72
|
+
console.log(`quorum v${version}`);
|
|
73
|
+
console.log(`node ${process.version}`);
|
|
74
|
+
console.log(`config: ${configPath}${existsSync(configPath) ? '' : ' (not created yet — starts on first server launch)'}`);
|
|
75
|
+
console.log(`slash commands: ${target}`);
|
|
76
|
+
console.log('');
|
|
77
|
+
console.log('Reviewer CLIs:');
|
|
78
|
+
for (const s of statuses) {
|
|
79
|
+
console.log(formatStatusLine(s));
|
|
80
|
+
if (s.settings)
|
|
81
|
+
console.log(` ${s.settings}`);
|
|
82
|
+
}
|
|
83
|
+
const usable = statuses.filter((s) => s.enabled && s.available);
|
|
84
|
+
console.log('');
|
|
85
|
+
if (usable.length === 0) {
|
|
86
|
+
console.log('✗ No usable reviewer. Install at least one CLI (see README) or re-enable one in the config.');
|
|
87
|
+
return 1;
|
|
88
|
+
}
|
|
89
|
+
console.log(`✓ ${usable.length} reviewer${usable.length === 1 ? '' : 's'} ready: ${usable.map((s) => s.id).join(', ')}`);
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
package/dist/executor.d.ts
CHANGED
|
@@ -1,23 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* CliExecutor —
|
|
2
|
+
* CliExecutor — shared process management for external AI CLI tools.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
8
|
-
* -
|
|
9
|
-
*
|
|
10
|
-
* -
|
|
11
|
-
* -
|
|
4
|
+
* One implementation of everything that is easy to get subtly wrong:
|
|
5
|
+
* - child-process spawning with stdin delivery
|
|
6
|
+
* - UTF-8-safe, line-buffered stdout parsing (JSONL-friendly)
|
|
7
|
+
* - inactivity and absolute-max timeouts, with out-of-band liveness resets
|
|
8
|
+
* - process-group SIGTERM → SIGKILL escalation so a stuck CLI — and anything
|
|
9
|
+
* it forked — cannot outlive its timeout
|
|
10
|
+
* - a registry of live children so the server can reap them on shutdown
|
|
11
|
+
* - max buffer enforcement with a truncation flag
|
|
12
|
+
* - a settled guard against double resolve/reject
|
|
12
13
|
*/
|
|
14
|
+
import { ChildProcess } from 'child_process';
|
|
15
|
+
/**
|
|
16
|
+
* Signal a child and, on POSIX, its whole process group. Children are spawned
|
|
17
|
+
* detached (own group) so that whatever the CLI forked — a launcher's native
|
|
18
|
+
* binary, a reviewer's shell or MCP children — dies with it. A wrapper can
|
|
19
|
+
* forward SIGTERM but never SIGKILL, so signalling only the direct pid would
|
|
20
|
+
* orphan the real worker on escalation.
|
|
21
|
+
*/
|
|
22
|
+
export declare function killTree(child: ChildProcess, signal: NodeJS.Signals): boolean;
|
|
23
|
+
/** Number of CLI processes currently running under this server. */
|
|
24
|
+
export declare function activeChildCount(): number;
|
|
25
|
+
/**
|
|
26
|
+
* Send `signal` to every live child. Returns how many were signalled.
|
|
27
|
+
* Idempotent and safe to call when nothing is running.
|
|
28
|
+
*/
|
|
29
|
+
export declare function shutdownChildren(signal?: NodeJS.Signals): number;
|
|
30
|
+
/**
|
|
31
|
+
* Install process-level hooks (once) so that the server exiting — normally,
|
|
32
|
+
* on SIGINT/SIGTERM/SIGHUP, or because the MCP client hung up — never leaves
|
|
33
|
+
* a Codex/Claude/agy process behind burning tokens. Called lazily on the
|
|
34
|
+
* first spawn; `index.ts` also calls it explicitly.
|
|
35
|
+
*/
|
|
36
|
+
export declare function installChildCleanupHooks(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Terminate children politely, wait briefly for them to go, then exit.
|
|
39
|
+
* Survivors are SIGKILLed by the `exit` hook.
|
|
40
|
+
*/
|
|
41
|
+
export declare function gracefulExit(code: number, graceMs?: number): Promise<never>;
|
|
13
42
|
export interface CliExecutorOptions {
|
|
14
|
-
/** Executable to spawn (e.g. 'codex', '
|
|
43
|
+
/** Executable to spawn (e.g. 'codex', 'agy', 'claude'). */
|
|
15
44
|
command: string;
|
|
16
45
|
/** Arguments passed to the command. */
|
|
17
46
|
args: string[];
|
|
18
47
|
/** Working directory for the spawned process. */
|
|
19
48
|
cwd: string;
|
|
20
|
-
/** Optional content to write to the process's stdin
|
|
49
|
+
/** Optional content to write to the process's stdin, after which stdin is closed. */
|
|
21
50
|
stdin?: string;
|
|
22
51
|
/** Additional environment variables merged over process.env. */
|
|
23
52
|
env?: Record<string, string>;
|
|
@@ -33,8 +62,7 @@ export interface CliExecutorOptions {
|
|
|
33
62
|
onStderr?: (data: string) => void;
|
|
34
63
|
/**
|
|
35
64
|
* Milliseconds of stdout/stderr inactivity before the process is killed
|
|
36
|
-
* and the promise rejects with Error('TIMEOUT').
|
|
37
|
-
* Default: 120_000 (2 minutes).
|
|
65
|
+
* and the promise rejects with Error('TIMEOUT'). Default: 120_000.
|
|
38
66
|
*/
|
|
39
67
|
inactivityTimeoutMs?: number;
|
|
40
68
|
/**
|
|
@@ -44,18 +72,22 @@ export interface CliExecutorOptions {
|
|
|
44
72
|
*/
|
|
45
73
|
maxTimeoutMs?: number;
|
|
46
74
|
/**
|
|
47
|
-
* Maximum number of
|
|
48
|
-
*
|
|
49
|
-
* Default: 1_048_576 (1 MB).
|
|
75
|
+
* Maximum number of characters accumulated in rawStdout (and, separately,
|
|
76
|
+
* stderr) before truncation. Default: 1_048_576.
|
|
50
77
|
*/
|
|
51
78
|
maxBufferSize?: number;
|
|
79
|
+
/**
|
|
80
|
+
* How long after SIGTERM to wait before escalating to SIGKILL.
|
|
81
|
+
* Default: 5_000.
|
|
82
|
+
*/
|
|
83
|
+
killGraceMs?: number;
|
|
52
84
|
}
|
|
53
85
|
export interface CliResult {
|
|
54
86
|
/** Lines split on '\n', excluding the trailing empty string from a final newline. */
|
|
55
87
|
stdoutLines: string[];
|
|
56
88
|
/** Raw accumulated stdout string (may be truncated). */
|
|
57
89
|
rawStdout: string;
|
|
58
|
-
/** Accumulated stderr string. */
|
|
90
|
+
/** Accumulated stderr string (may be truncated). */
|
|
59
91
|
stderr: string;
|
|
60
92
|
/** Process exit code; -1 if the process was killed without an exit code. */
|
|
61
93
|
exitCode: number;
|
|
@@ -64,46 +96,26 @@ export interface CliResult {
|
|
|
64
96
|
}
|
|
65
97
|
export declare class CliExecutor {
|
|
66
98
|
private readonly opts;
|
|
67
|
-
/**
|
|
68
|
-
* Mutable inactivity timeout — callers can tighten it after first streaming
|
|
69
|
-
* event via setInactivityTimeout(). Changing it clears and restarts the
|
|
70
|
-
* currently running inactivity timer immediately.
|
|
71
|
-
*/
|
|
99
|
+
/** Mutable inactivity timeout — see setInactivityTimeout(). */
|
|
72
100
|
private currentInactivityMs;
|
|
73
|
-
/**
|
|
74
|
-
* Handle to the live inactivity timer (kept here so setInactivityTimeout
|
|
75
|
-
* can reset it from outside the Promise closure via the shared ref below).
|
|
76
|
-
*/
|
|
77
101
|
private inactivityTimer;
|
|
78
|
-
/**
|
|
79
|
-
* Injected by run() so setInactivityTimeout can restart the timer using
|
|
80
|
-
* the correct reject handle while the process is still running.
|
|
81
|
-
*/
|
|
102
|
+
/** Injected by run() so the timer can be restarted from outside the closure. */
|
|
82
103
|
private resetInactivityFn;
|
|
83
104
|
constructor(options: CliExecutorOptions);
|
|
84
105
|
/**
|
|
85
|
-
* Dynamically adjust the inactivity timeout.
|
|
86
|
-
*
|
|
87
|
-
* If the process is currently running, the active inactivity timer is
|
|
88
|
-
* cancelled and restarted with the new duration immediately. Subsequent
|
|
89
|
-
* activity resets will also use this new value.
|
|
90
|
-
*
|
|
91
|
-
* Typical use: tighten the timeout once the first streaming event arrives,
|
|
92
|
-
* so a stalled process is detected sooner after it starts responding.
|
|
106
|
+
* Dynamically adjust the inactivity timeout. If the process is running, the
|
|
107
|
+
* active timer is restarted with the new duration immediately.
|
|
93
108
|
*/
|
|
94
109
|
setInactivityTimeout(ms: number): void;
|
|
95
110
|
/**
|
|
96
111
|
* Reset the inactivity timer without any stdout/stderr byte having arrived.
|
|
97
112
|
*
|
|
98
|
-
* For a CLI whose event stream goes silent while it is still working
|
|
99
|
-
* emits nothing
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* growing session/log file, a status socket) call this to keep the process
|
|
103
|
-
* alive.
|
|
113
|
+
* For a CLI whose event stream goes silent while it is still working (Codex
|
|
114
|
+
* emits nothing during a reasoning block) stdout bytes are not a liveness
|
|
115
|
+
* signal. Callers that can prove liveness out of band (a growing rollout
|
|
116
|
+
* file) call this to keep the process alive.
|
|
104
117
|
*
|
|
105
|
-
* No-op before run() and after the process has settled
|
|
106
|
-
* fires late cannot resurrect a finished run's timer.
|
|
118
|
+
* No-op before run() and after the process has settled.
|
|
107
119
|
*/
|
|
108
120
|
noteActivity(): void;
|
|
109
121
|
/**
|