@simonren/quorum 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +217 -0
- package/dist/adapters/codex.d.ts +18 -13
- package/dist/adapters/codex.js +64 -200
- package/dist/adapters/gemini.d.ts +30 -20
- package/dist/adapters/gemini.js +56 -148
- package/dist/adapters/index.d.ts +8 -5
- package/dist/adapters/index.js +7 -8
- package/dist/config.d.ts +116 -28
- package/dist/config.js +50 -28
- 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/adapters/codex.js
CHANGED
|
@@ -1,89 +1,53 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Codex CLI
|
|
2
|
+
* Codex CLI adapter.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Spawns `codex exec --json` in a read-only sandbox with the prompt on stdin
|
|
5
|
+
* and decodes the JSONL event stream. Because Codex is byte-silent on stdout
|
|
6
|
+
* for the whole of a reasoning block, liveness is proven out of band by
|
|
7
|
+
* watching the session rollout file (`codex-liveness.ts`).
|
|
7
8
|
*/
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { registerAdapter, } from './base.js';
|
|
9
|
+
import { registerAdapter } from './base.js';
|
|
10
|
+
import { CliAdapter } from './cli-adapter.js';
|
|
11
11
|
import { CliExecutor } from '../executor.js';
|
|
12
12
|
import { CodexEventDecoder } from '../decoders/index.js';
|
|
13
13
|
import { watchCodexThreadLiveness } from '../codex-liveness.js';
|
|
14
|
-
import { buildSimpleHandoff, buildHandoffPrompt, buildAdversarialHandoffPrompt, selectRole, } from '../handoff.js';
|
|
15
|
-
import { buildConsultPrompt } from '../consult-prompt.js';
|
|
16
14
|
import { getConfig } from '../config.js';
|
|
17
|
-
|
|
18
|
-
// CODEX ADAPTER
|
|
19
|
-
// =============================================================================
|
|
20
|
-
export class CodexAdapter {
|
|
15
|
+
export class CodexAdapter extends CliAdapter {
|
|
21
16
|
id = 'codex';
|
|
17
|
+
binary = 'codex';
|
|
18
|
+
installHint = 'Install with: npm install -g @openai/codex-cli, then run `codex login`';
|
|
19
|
+
authHint = 'Run `codex login` to authenticate';
|
|
20
|
+
extraRateLimitPatterns = ['usage limit', 'insufficient_quota'];
|
|
22
21
|
getCapabilities() {
|
|
23
22
|
return {
|
|
24
23
|
name: 'Codex',
|
|
25
|
-
description: 'OpenAI Codex
|
|
26
|
-
strengths: ['correctness', 'performance', 'security', 'testing'],
|
|
27
|
-
weaknesses: ['documentation'],
|
|
28
|
-
hasFilesystemAccess: true,
|
|
29
|
-
supportsStructuredOutput: false,
|
|
30
|
-
maxContextTokens: 128000,
|
|
31
|
-
reasoningLevels: ['high', 'xhigh'],
|
|
24
|
+
description: 'OpenAI Codex CLI in a read-only sandbox; reasoning effort and service tier are configurable',
|
|
32
25
|
};
|
|
33
26
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const proc = spawn('codex', ['--version'], {
|
|
43
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
44
|
-
});
|
|
45
|
-
proc.on('close', (code) => done(code === 0));
|
|
46
|
-
proc.on('error', () => done(false));
|
|
47
|
-
const timer = setTimeout(() => { proc.kill(); done(false); }, 5000);
|
|
48
|
-
});
|
|
27
|
+
getLimits(ctx) {
|
|
28
|
+
const cfg = getConfig().codex;
|
|
29
|
+
const effort = this.effortFor(ctx);
|
|
30
|
+
return {
|
|
31
|
+
inactivityTimeoutMs: cfg.inactivityTimeoutMs[effort] ?? cfg.inactivityTimeoutMs.high,
|
|
32
|
+
maxTimeoutMs: cfg.maxTimeoutMs,
|
|
33
|
+
maxBufferSize: cfg.maxBufferSize,
|
|
34
|
+
};
|
|
49
35
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
try {
|
|
61
|
-
const handoff = buildSimpleHandoff(request.workingDir, request.ccOutput, request.analyzedFiles, request.focusAreas, request.customPrompt);
|
|
62
|
-
const prompt = request.reviewMode === 'adversarial'
|
|
63
|
-
? buildAdversarialHandoffPrompt({ handoff })
|
|
64
|
-
: buildHandoffPrompt({ handoff, role: selectRole(request.focusAreas) });
|
|
65
|
-
const cfg = getConfig().codex;
|
|
66
|
-
const result = await this.runCli(prompt, request.workingDir, request.reasoningEffort ?? cfg.reasoningEffort, request.serviceTier);
|
|
67
|
-
if (result.exitCode !== 0) {
|
|
68
|
-
const error = this.categorizeError(result.stderr);
|
|
69
|
-
return { success: false, error, suggestion: this.getSuggestion(error), executionTimeMs: Date.now() - startTime };
|
|
70
|
-
}
|
|
71
|
-
if (!result.stdout.trim()) {
|
|
72
|
-
return {
|
|
73
|
-
success: false,
|
|
74
|
-
error: { type: 'cli_error', message: 'Codex returned empty response' },
|
|
75
|
-
suggestion: 'Try again or use /multi-review instead',
|
|
76
|
-
executionTimeMs: Date.now() - startTime,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
return { success: true, output: result.stdout, executionTimeMs: Date.now() - startTime };
|
|
80
|
-
}
|
|
81
|
-
catch (error) {
|
|
82
|
-
return this.handleException(error, startTime);
|
|
83
|
-
}
|
|
36
|
+
/** Request value > per-kind config default. */
|
|
37
|
+
effortFor(ctx) {
|
|
38
|
+
const cfg = getConfig().codex;
|
|
39
|
+
return ctx.reasoningEffort ?? (ctx.kind === 'consult' ? cfg.consultReasoningEffort : cfg.reasoningEffort);
|
|
40
|
+
}
|
|
41
|
+
/** Request value > per-kind config default. Explicit 'default' emits no flag. */
|
|
42
|
+
tierFor(ctx) {
|
|
43
|
+
const cfg = getConfig().codex;
|
|
44
|
+
return ctx.serviceTier ?? (ctx.kind === 'consult' ? cfg.consultServiceTier : cfg.serviceTier);
|
|
84
45
|
}
|
|
85
|
-
async runCli(prompt, workingDir,
|
|
46
|
+
async runCli(prompt, workingDir, ctx) {
|
|
86
47
|
const cfg = getConfig().codex;
|
|
48
|
+
const reasoningEffort = this.effortFor(ctx);
|
|
49
|
+
const effectiveTier = this.tierFor(ctx);
|
|
50
|
+
const limits = this.getLimits(ctx);
|
|
87
51
|
const args = [
|
|
88
52
|
'exec',
|
|
89
53
|
'--json', // JSONL streaming events
|
|
@@ -93,43 +57,38 @@ export class CodexAdapter {
|
|
|
93
57
|
'--sandbox', 'read-only',
|
|
94
58
|
'--skip-git-repo-check',
|
|
95
59
|
'-C', workingDir,
|
|
96
|
-
'-', //
|
|
60
|
+
'-', // prompt on stdin
|
|
97
61
|
];
|
|
98
|
-
// Caller-supplied serviceTier overrides config. Explicit 'default' is an
|
|
99
|
-
// opt-out and emits no flag (uses Codex API default).
|
|
100
|
-
const effectiveTier = serviceTier ?? cfg.serviceTier;
|
|
101
62
|
if (effectiveTier !== 'default') {
|
|
102
63
|
args.push('-c', `service_tier=${effectiveTier}`);
|
|
103
64
|
}
|
|
104
65
|
const decoder = new CodexEventDecoder();
|
|
105
66
|
const cliStartTime = Date.now();
|
|
106
67
|
const tierLabel = effectiveTier !== 'default' ? ` [${effectiveTier}]` : '';
|
|
107
|
-
console.error(`[codex] Running with ${reasoningEffort} reasoning${tierLabel}...`);
|
|
68
|
+
console.error(`[codex] Running ${ctx.kind} with ${reasoningEffort} reasoning${tierLabel}...`);
|
|
108
69
|
decoder.onProgress = (eventType, detail) => {
|
|
109
70
|
const elapsed = Math.round((Date.now() - cliStartTime) / 1000);
|
|
110
|
-
|
|
111
|
-
console.error(`[codex] ${eventType}${detailStr} (${elapsed}s)`);
|
|
71
|
+
console.error(`[codex] ${eventType}${detail ? ` — ${detail}` : ''} (${elapsed}s)`);
|
|
112
72
|
};
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
// mid-thought. Codex keeps appending reasoning summaries to its session
|
|
117
|
-
// rollout file throughout, so watch that file and treat growth as liveness.
|
|
118
|
-
// The watcher is best-effort: if the rollout file cannot be found we simply
|
|
119
|
-
// fall back to the stdout-only behaviour.
|
|
73
|
+
// Liveness: Codex keeps appending reasoning summaries to its rollout file
|
|
74
|
+
// while stdout is silent. Growth of that file resets the inactivity timer.
|
|
75
|
+
// Best-effort — if the file cannot be found we fall back to stdout-only.
|
|
120
76
|
let stopLiveness;
|
|
77
|
+
// Set once the run has settled so a late line can never start a watcher
|
|
78
|
+
// after the `.finally` below has already had its only chance to stop it.
|
|
79
|
+
let disposed = false;
|
|
121
80
|
const executor = new CliExecutor({
|
|
122
|
-
command:
|
|
81
|
+
command: this.binary,
|
|
123
82
|
args,
|
|
124
83
|
cwd: workingDir,
|
|
125
84
|
stdin: prompt,
|
|
126
|
-
inactivityTimeoutMs:
|
|
127
|
-
maxTimeoutMs:
|
|
128
|
-
maxBufferSize:
|
|
85
|
+
inactivityTimeoutMs: limits.inactivityTimeoutMs,
|
|
86
|
+
maxTimeoutMs: limits.maxTimeoutMs,
|
|
87
|
+
maxBufferSize: limits.maxBufferSize,
|
|
129
88
|
onLine: (line) => {
|
|
130
89
|
decoder.processLine(line);
|
|
131
90
|
const threadId = decoder.getThreadId();
|
|
132
|
-
if (stopLiveness === undefined && threadId !== null) {
|
|
91
|
+
if (!disposed && stopLiveness === undefined && threadId !== null) {
|
|
133
92
|
stopLiveness = watchCodexThreadLiveness({
|
|
134
93
|
threadId,
|
|
135
94
|
onActivity: () => executor.noteActivity(),
|
|
@@ -137,126 +96,31 @@ export class CodexAdapter {
|
|
|
137
96
|
}
|
|
138
97
|
},
|
|
139
98
|
});
|
|
140
|
-
// `.finally`
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
// exists. `codex exec` runs a multi-turn agent loop, so a turn can emit a
|
|
148
|
-
// message and a later turn can fail; without this check, that failure would
|
|
149
|
-
// be reported as a successful review with stale content.
|
|
99
|
+
// `.finally` so a TIMEOUT/MAX_TIMEOUT rejection still tears the watcher down.
|
|
100
|
+
const result = await executor.run().finally(() => { disposed = true; stopLiveness?.(); });
|
|
101
|
+
console.error(`[codex] ✓ complete (${Math.round((Date.now() - cliStartTime) / 1000)}s)`);
|
|
102
|
+
// A fatal error (top-level `error` or `turn.failed`) is terminal and wins
|
|
103
|
+
// even when a — possibly intermediate/stale — agent_message exists: `codex
|
|
104
|
+
// exec` runs a multi-turn loop, so a turn can emit a message and a later
|
|
105
|
+
// turn can fail.
|
|
150
106
|
const fatalError = decoder.getFatalError();
|
|
151
107
|
if (fatalError) {
|
|
152
|
-
|
|
153
|
-
return { stdout: '', stderr: combined, exitCode: 1, truncated: false };
|
|
108
|
+
return { stdout: '', stderr: this.combineDiagnostics(fatalError, result.stderr), exitCode: 1, truncated: false };
|
|
154
109
|
}
|
|
155
|
-
// No fatal error: a completed response wins even if a NON-fatal
|
|
156
|
-
// appeared earlier.
|
|
157
|
-
//
|
|
158
|
-
// purely informational ("Codex can still see every skill"); the turn still
|
|
159
|
-
// completes and produces an agent_message. Use `!== null` (not truthiness) so
|
|
160
|
-
// an empty-string response is preserved for the caller's empty-response
|
|
161
|
-
// handling rather than misclassified as "no result event".
|
|
162
|
-
// (Checking getError() first discarded otherwise-successful reviews.)
|
|
110
|
+
// No fatal error: a completed response wins even if a NON-fatal item-level
|
|
111
|
+
// error appeared earlier (e.g. the informational "skills shortened" notice).
|
|
112
|
+
// `!== null` so an empty-string response reaches empty-response handling.
|
|
163
113
|
const finalResponse = decoder.getFinalResponse();
|
|
164
114
|
if (finalResponse !== null) {
|
|
165
|
-
return {
|
|
166
|
-
stdout: finalResponse,
|
|
167
|
-
stderr: result.stderr,
|
|
168
|
-
exitCode: result.exitCode,
|
|
169
|
-
truncated: result.truncated,
|
|
170
|
-
};
|
|
115
|
+
return { stdout: finalResponse, stderr: result.stderr, exitCode: result.exitCode, truncated: result.truncated };
|
|
171
116
|
}
|
|
172
|
-
// No response: surface a non-fatal item-level error if one was captured.
|
|
173
117
|
const decoderError = decoder.getError();
|
|
174
118
|
if (decoderError) {
|
|
175
|
-
|
|
176
|
-
return { stdout: '', stderr: combined, exitCode: 1, truncated: false };
|
|
177
|
-
}
|
|
178
|
-
if (decoder.hasNoOutput()) {
|
|
179
|
-
const combined = result.stderr ? `No output from Codex\n\nCLI stderr: ${result.stderr}` : 'No output from Codex';
|
|
180
|
-
return { stdout: '', stderr: combined, exitCode: 1, truncated: false };
|
|
181
|
-
}
|
|
182
|
-
const combined = result.stderr ? `No result event from Codex\n\nCLI stderr: ${result.stderr}` : 'No result event from Codex';
|
|
183
|
-
return { stdout: '', stderr: combined, exitCode: 1, truncated: false };
|
|
184
|
-
}
|
|
185
|
-
handleException(error, startTime) {
|
|
186
|
-
const err = error;
|
|
187
|
-
if (err.code === 'ENOENT') {
|
|
188
|
-
return { success: false, error: { type: 'cli_not_found', message: 'Codex CLI not found' },
|
|
189
|
-
suggestion: 'Install with: npm install -g @openai/codex-cli', executionTimeMs: Date.now() - startTime };
|
|
190
|
-
}
|
|
191
|
-
if (err.message === 'TIMEOUT') {
|
|
192
|
-
return { success: false, error: { type: 'timeout', message: 'Codex timed out — no events received' },
|
|
193
|
-
suggestion: 'Try a smaller scope or use /multi-review', executionTimeMs: Date.now() - startTime };
|
|
194
|
-
}
|
|
195
|
-
if (err.message === 'MAX_TIMEOUT') {
|
|
196
|
-
return { success: false, error: { type: 'timeout', message: 'Task exceeded 60 minute maximum' },
|
|
197
|
-
suggestion: 'Try a smaller scope', executionTimeMs: Date.now() - startTime };
|
|
198
|
-
}
|
|
199
|
-
return { success: false, error: { type: 'cli_error', message: err.message }, executionTimeMs: Date.now() - startTime };
|
|
200
|
-
}
|
|
201
|
-
categorizeError(stderr) {
|
|
202
|
-
const lower = stderr.toLowerCase();
|
|
203
|
-
if (lower.includes('rate limit') || lower.includes('rate_limit')) {
|
|
204
|
-
return { type: 'rate_limit', message: `Codex rate limit: ${stderr.slice(0, 500)}` };
|
|
205
|
-
}
|
|
206
|
-
if (lower.includes('unauthorized') || lower.includes('authentication') || stderr.includes('401') || stderr.includes('403')) {
|
|
207
|
-
return { type: 'auth_error', message: `Authentication failed: ${stderr.slice(0, 500)}`, details: { stderr } };
|
|
208
|
-
}
|
|
209
|
-
if (lower.includes('invalid_json_schema') || lower.includes('invalid_request_error')) {
|
|
210
|
-
return { type: 'cli_error', message: `API error: ${stderr.slice(0, 500)}` };
|
|
211
|
-
}
|
|
212
|
-
return { type: 'cli_error', message: stderr.slice(0, 500) || 'Unknown error' };
|
|
213
|
-
}
|
|
214
|
-
getSuggestion(error) {
|
|
215
|
-
switch (error.type) {
|
|
216
|
-
case 'rate_limit': return 'Wait and retry, or use /multi-review instead';
|
|
217
|
-
case 'auth_error': return 'Run `codex login` to authenticate';
|
|
218
|
-
case 'cli_not_found': return 'Install with: npm install -g @openai/codex-cli';
|
|
219
|
-
default: return 'Check the error message and try again';
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
async runConsult(request) {
|
|
223
|
-
const startTime = Date.now();
|
|
224
|
-
if (!existsSync(request.workingDir)) {
|
|
225
|
-
return {
|
|
226
|
-
success: false,
|
|
227
|
-
error: { type: 'cli_error', message: `Working directory does not exist: ${request.workingDir}` },
|
|
228
|
-
suggestion: 'Check that the working directory path is correct',
|
|
229
|
-
executionTimeMs: Date.now() - startTime,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
try {
|
|
233
|
-
const prompt = buildConsultPrompt(request);
|
|
234
|
-
// Consult-specific defaults live in config (Zod defaults to xhigh + fast).
|
|
235
|
-
// Request value > config value > Zod default. Users who want to cap cost
|
|
236
|
-
// can set codex.consultServiceTier: "flex" without touching review.
|
|
237
|
-
const cfg = getConfig().codex;
|
|
238
|
-
const reasoningEffort = request.reasoningEffort ?? cfg.consultReasoningEffort;
|
|
239
|
-
const serviceTier = request.serviceTier ?? cfg.consultServiceTier;
|
|
240
|
-
const result = await this.runCli(prompt, request.workingDir, reasoningEffort, serviceTier);
|
|
241
|
-
if (result.exitCode !== 0) {
|
|
242
|
-
const error = this.categorizeError(result.stderr);
|
|
243
|
-
return { success: false, error, suggestion: this.getSuggestion(error), executionTimeMs: Date.now() - startTime };
|
|
244
|
-
}
|
|
245
|
-
if (!result.stdout.trim()) {
|
|
246
|
-
return {
|
|
247
|
-
success: false,
|
|
248
|
-
error: { type: 'cli_error', message: 'Codex returned empty response' },
|
|
249
|
-
suggestion: 'Try again or use /multi-review instead',
|
|
250
|
-
executionTimeMs: Date.now() - startTime,
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
return { success: true, output: result.stdout, executionTimeMs: Date.now() - startTime };
|
|
254
|
-
}
|
|
255
|
-
catch (error) {
|
|
256
|
-
return this.handleException(error, startTime);
|
|
119
|
+
return { stdout: '', stderr: this.combineDiagnostics(decoderError, result.stderr), exitCode: 1, truncated: false };
|
|
257
120
|
}
|
|
121
|
+
const reason = decoder.hasNoOutput() ? 'No output from Codex' : 'No result event from Codex';
|
|
122
|
+
return { stdout: '', stderr: this.combineDiagnostics(reason, result.stderr), exitCode: 1, truncated: false };
|
|
258
123
|
}
|
|
259
124
|
}
|
|
260
|
-
// Register the adapter
|
|
261
|
-
registerAdapter(new CodexAdapter());
|
|
262
125
|
export const codexAdapter = new CodexAdapter();
|
|
126
|
+
registerAdapter(codexAdapter);
|
|
@@ -1,28 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Gemini
|
|
2
|
+
* Gemini adapter (via the Antigravity CLI, `agy`).
|
|
3
3
|
*
|
|
4
|
-
* Google replaced `gemini-cli` with the Antigravity CLI
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Gemini under the hood — only the CLI brand changed — so the adapter id and
|
|
8
|
-
* config key remain `gemini`.
|
|
4
|
+
* Google replaced `gemini-cli` with the Antigravity CLI at I/O 2026; the
|
|
5
|
+
* free-tier `gemini` binary stopped serving requests on 2026-06-18. The model
|
|
6
|
+
* is still Gemini, so the adapter id and config key remain `gemini`.
|
|
9
7
|
*
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* -
|
|
8
|
+
* agy specifics:
|
|
9
|
+
* - the prompt must be the positional after `--print` (stdin alone makes agy
|
|
10
|
+
* print --help and exit 0), so the prompt size is bounded by the OS argv
|
|
11
|
+
* limit — see MAX_ARGV_PROMPT_BYTES
|
|
12
|
+
* - no streaming output, so the inactivity timeout is a total-runtime cap;
|
|
13
|
+
* agy has its own print-mode timeout (default 5m) which is set to match
|
|
14
|
+
* - `--sandbox` restricts the terminal only. agy's file tools CAN still write
|
|
15
|
+
* to the workspace (verified with `--sandbox` and with `--mode plan`), and
|
|
16
|
+
* agy has no read-only switch, so the tool handlers fingerprint the working
|
|
17
|
+
* tree before and after every run and flag any change (`integrity.ts`)
|
|
18
|
+
* - `--add-dir` scopes reads; `--model` is optional (`gemini.model`)
|
|
15
19
|
*/
|
|
16
|
-
import {
|
|
17
|
-
|
|
20
|
+
import { ReviewerCapabilities } from './base.js';
|
|
21
|
+
import { CliAdapter, CliOutcome, RunContext, RunLimits } from './cli-adapter.js';
|
|
22
|
+
/**
|
|
23
|
+
* Linux caps a single argv string at 128 KiB (MAX_ARG_STRLEN); macOS caps the
|
|
24
|
+
* whole argv+env block. A prompt beyond this would make spawn fail with E2BIG,
|
|
25
|
+
* so refuse early with a message that says what to shrink.
|
|
26
|
+
*/
|
|
27
|
+
export declare const MAX_ARGV_PROMPT_BYTES = 120000;
|
|
28
|
+
export declare class GeminiAdapter extends CliAdapter {
|
|
18
29
|
readonly id = "gemini";
|
|
30
|
+
protected readonly binary = "agy";
|
|
31
|
+
protected readonly installHint = "Install with: curl -fsSL https://antigravity.google/cli/install.sh | bash, then run `agy` and complete the Google OAuth sign-in";
|
|
32
|
+
protected readonly authHint = "Run `agy` and complete the Google OAuth sign-in";
|
|
33
|
+
protected extraRateLimitPatterns: string[];
|
|
19
34
|
getCapabilities(): ReviewerCapabilities;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
private runCli;
|
|
23
|
-
private handleException;
|
|
24
|
-
private categorizeError;
|
|
25
|
-
private getSuggestion;
|
|
26
|
-
runConsult(request: ConsultRequest): Promise<ConsultResult>;
|
|
35
|
+
protected getLimits(): RunLimits;
|
|
36
|
+
protected runCli(prompt: string, workingDir: string, ctx: RunContext): Promise<CliOutcome>;
|
|
27
37
|
}
|
|
28
38
|
export declare const geminiAdapter: GeminiAdapter;
|
package/dist/adapters/gemini.js
CHANGED
|
@@ -1,113 +1,86 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Gemini
|
|
2
|
+
* Gemini adapter (via the Antigravity CLI, `agy`).
|
|
3
3
|
*
|
|
4
|
-
* Google replaced `gemini-cli` with the Antigravity CLI
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Gemini under the hood — only the CLI brand changed — so the adapter id and
|
|
8
|
-
* config key remain `gemini`.
|
|
4
|
+
* Google replaced `gemini-cli` with the Antigravity CLI at I/O 2026; the
|
|
5
|
+
* free-tier `gemini` binary stopped serving requests on 2026-06-18. The model
|
|
6
|
+
* is still Gemini, so the adapter id and config key remain `gemini`.
|
|
9
7
|
*
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* -
|
|
8
|
+
* agy specifics:
|
|
9
|
+
* - the prompt must be the positional after `--print` (stdin alone makes agy
|
|
10
|
+
* print --help and exit 0), so the prompt size is bounded by the OS argv
|
|
11
|
+
* limit — see MAX_ARGV_PROMPT_BYTES
|
|
12
|
+
* - no streaming output, so the inactivity timeout is a total-runtime cap;
|
|
13
|
+
* agy has its own print-mode timeout (default 5m) which is set to match
|
|
14
|
+
* - `--sandbox` restricts the terminal only. agy's file tools CAN still write
|
|
15
|
+
* to the workspace (verified with `--sandbox` and with `--mode plan`), and
|
|
16
|
+
* agy has no read-only switch, so the tool handlers fingerprint the working
|
|
17
|
+
* tree before and after every run and flag any change (`integrity.ts`)
|
|
18
|
+
* - `--add-dir` scopes reads; `--model` is optional (`gemini.model`)
|
|
15
19
|
*/
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { registerAdapter, } from './base.js';
|
|
20
|
+
import { registerAdapter } from './base.js';
|
|
21
|
+
import { CliAdapter } from './cli-adapter.js';
|
|
19
22
|
import { CliExecutor } from '../executor.js';
|
|
20
|
-
import { buildSimpleHandoff, buildHandoffPrompt, buildAdversarialHandoffPrompt, selectRole, } from '../handoff.js';
|
|
21
|
-
import { buildConsultPrompt } from '../consult-prompt.js';
|
|
22
23
|
import { getConfig } from '../config.js';
|
|
23
24
|
const AGY_INSTALL_CMD = 'curl -fsSL https://antigravity.google/cli/install.sh | bash';
|
|
24
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Linux caps a single argv string at 128 KiB (MAX_ARG_STRLEN); macOS caps the
|
|
27
|
+
* whole argv+env block. A prompt beyond this would make spawn fail with E2BIG,
|
|
28
|
+
* so refuse early with a message that says what to shrink.
|
|
29
|
+
*/
|
|
30
|
+
export const MAX_ARGV_PROMPT_BYTES = 120_000;
|
|
31
|
+
export class GeminiAdapter extends CliAdapter {
|
|
25
32
|
id = 'gemini';
|
|
33
|
+
binary = 'agy';
|
|
34
|
+
installHint = `Install with: ${AGY_INSTALL_CMD}, then run \`agy\` and complete the Google OAuth sign-in`;
|
|
35
|
+
authHint = 'Run `agy` and complete the Google OAuth sign-in';
|
|
36
|
+
extraRateLimitPatterns = ['resource exhausted', 'resource_exhausted'];
|
|
26
37
|
getCapabilities() {
|
|
27
38
|
return {
|
|
28
39
|
name: 'Gemini',
|
|
29
|
-
description: 'Google Gemini
|
|
30
|
-
strengths: ['architecture', 'maintainability', 'scalability', 'documentation'],
|
|
31
|
-
weaknesses: ['security'],
|
|
32
|
-
hasFilesystemAccess: true,
|
|
33
|
-
supportsStructuredOutput: false,
|
|
34
|
-
maxContextTokens: 2000000,
|
|
35
|
-
reasoningLevels: undefined,
|
|
40
|
+
description: 'Google Gemini via the Antigravity CLI (agy) in sandbox mode; model set in agy or via gemini.model',
|
|
36
41
|
};
|
|
37
42
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} };
|
|
46
|
-
const proc = spawn('agy', ['--version'], {
|
|
47
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
48
|
-
});
|
|
49
|
-
proc.on('close', (code) => done(code === 0));
|
|
50
|
-
proc.on('error', () => done(false));
|
|
51
|
-
const timer = setTimeout(() => { proc.kill(); done(false); }, 5000);
|
|
52
|
-
});
|
|
43
|
+
getLimits() {
|
|
44
|
+
const cfg = getConfig().gemini;
|
|
45
|
+
return {
|
|
46
|
+
inactivityTimeoutMs: cfg.inactivityTimeoutMs,
|
|
47
|
+
maxTimeoutMs: cfg.maxTimeoutMs,
|
|
48
|
+
maxBufferSize: cfg.maxBufferSize,
|
|
49
|
+
};
|
|
53
50
|
}
|
|
54
|
-
async
|
|
55
|
-
const
|
|
56
|
-
|
|
51
|
+
async runCli(prompt, workingDir, ctx) {
|
|
52
|
+
const cfg = getConfig().gemini;
|
|
53
|
+
const limits = this.getLimits();
|
|
54
|
+
const promptBytes = Buffer.byteLength(prompt, 'utf8');
|
|
55
|
+
if (promptBytes > MAX_ARGV_PROMPT_BYTES) {
|
|
57
56
|
return {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
stdout: '',
|
|
58
|
+
stderr: `Prompt is ${promptBytes} bytes; agy takes the prompt as a command-line argument and the OS limit is ~${MAX_ARGV_PROMPT_BYTES} bytes. Shorten the brief (ccOutput/question) or the file lists.`,
|
|
59
|
+
exitCode: 1,
|
|
60
|
+
truncated: false,
|
|
62
61
|
};
|
|
63
62
|
}
|
|
64
|
-
try {
|
|
65
|
-
const handoff = buildSimpleHandoff(request.workingDir, request.ccOutput, request.analyzedFiles, request.focusAreas, request.customPrompt);
|
|
66
|
-
const prompt = request.reviewMode === 'adversarial'
|
|
67
|
-
? buildAdversarialHandoffPrompt({ handoff })
|
|
68
|
-
: buildHandoffPrompt({ handoff, role: selectRole(request.focusAreas) });
|
|
69
|
-
const result = await this.runCli(prompt, request.workingDir);
|
|
70
|
-
if (result.exitCode !== 0) {
|
|
71
|
-
const error = this.categorizeError(result.stderr);
|
|
72
|
-
return { success: false, error, suggestion: this.getSuggestion(error), executionTimeMs: Date.now() - startTime };
|
|
73
|
-
}
|
|
74
|
-
if (!result.stdout.trim()) {
|
|
75
|
-
return {
|
|
76
|
-
success: false,
|
|
77
|
-
error: { type: 'cli_error', message: 'agy returned empty response' },
|
|
78
|
-
suggestion: 'Try again or use /multi-review instead',
|
|
79
|
-
executionTimeMs: Date.now() - startTime,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
return { success: true, output: result.stdout, executionTimeMs: Date.now() - startTime };
|
|
83
|
-
}
|
|
84
|
-
catch (error) {
|
|
85
|
-
return this.handleException(error, startTime);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
async runCli(prompt, workingDir) {
|
|
89
|
-
const cfg = getConfig().gemini;
|
|
90
|
-
// agy requires the prompt as the positional after --print; passing only via
|
|
91
|
-
// stdin makes it print --help and exit 0. Sandbox keeps terminal-restricted
|
|
92
|
-
// execution like the old gemini-cli's `--approval-mode plan`.
|
|
93
63
|
const args = [
|
|
64
|
+
...(cfg.model ? ['--model', cfg.model] : []),
|
|
65
|
+
// agy's own print-mode timeout defaults to 5m and would end long reviews
|
|
66
|
+
// before quorum's timer; keep the two in step. Go duration syntax.
|
|
67
|
+
'--print-timeout', `${Math.ceil(limits.inactivityTimeoutMs / 1000)}s`,
|
|
94
68
|
'--sandbox',
|
|
95
69
|
'--add-dir', workingDir,
|
|
96
70
|
'--print', prompt,
|
|
97
71
|
];
|
|
98
72
|
const cliStartTime = Date.now();
|
|
99
|
-
console.error(
|
|
73
|
+
console.error(`[gemini] Running ${ctx.kind} via agy${cfg.model ? ` (${cfg.model})` : ''}...`);
|
|
100
74
|
const executor = new CliExecutor({
|
|
101
|
-
command:
|
|
75
|
+
command: this.binary,
|
|
102
76
|
args,
|
|
103
77
|
cwd: workingDir,
|
|
104
|
-
inactivityTimeoutMs:
|
|
105
|
-
maxTimeoutMs:
|
|
106
|
-
maxBufferSize:
|
|
78
|
+
inactivityTimeoutMs: limits.inactivityTimeoutMs,
|
|
79
|
+
maxTimeoutMs: limits.maxTimeoutMs,
|
|
80
|
+
maxBufferSize: limits.maxBufferSize,
|
|
107
81
|
});
|
|
108
82
|
const result = await executor.run();
|
|
109
|
-
|
|
110
|
-
console.error(`[gemini] ✓ complete (${elapsed}s)`);
|
|
83
|
+
console.error(`[gemini] ✓ complete (${Math.round((Date.now() - cliStartTime) / 1000)}s)`);
|
|
111
84
|
return {
|
|
112
85
|
stdout: result.rawStdout,
|
|
113
86
|
stderr: result.stderr,
|
|
@@ -115,71 +88,6 @@ export class GeminiAdapter {
|
|
|
115
88
|
truncated: result.truncated,
|
|
116
89
|
};
|
|
117
90
|
}
|
|
118
|
-
handleException(error, startTime) {
|
|
119
|
-
const err = error;
|
|
120
|
-
if (err.code === 'ENOENT') {
|
|
121
|
-
return { success: false, error: { type: 'cli_not_found', message: 'agy CLI not found' },
|
|
122
|
-
suggestion: `Install with: ${AGY_INSTALL_CMD}`, executionTimeMs: Date.now() - startTime };
|
|
123
|
-
}
|
|
124
|
-
if (err.message === 'TIMEOUT') {
|
|
125
|
-
return { success: false, error: { type: 'timeout', message: 'agy timed out — no output received' },
|
|
126
|
-
suggestion: 'Try a smaller scope or use /multi-review', executionTimeMs: Date.now() - startTime };
|
|
127
|
-
}
|
|
128
|
-
if (err.message === 'MAX_TIMEOUT') {
|
|
129
|
-
return { success: false, error: { type: 'timeout', message: 'Task exceeded 60 minute maximum' },
|
|
130
|
-
suggestion: 'Try a smaller scope', executionTimeMs: Date.now() - startTime };
|
|
131
|
-
}
|
|
132
|
-
return { success: false, error: { type: 'cli_error', message: err.message }, executionTimeMs: Date.now() - startTime };
|
|
133
|
-
}
|
|
134
|
-
categorizeError(stderr) {
|
|
135
|
-
const lower = stderr.toLowerCase();
|
|
136
|
-
if (lower.includes('rate limit') || lower.includes('quota')) {
|
|
137
|
-
return { type: 'rate_limit', message: `Rate limit or quota exceeded: ${stderr.slice(0, 500)}` };
|
|
138
|
-
}
|
|
139
|
-
if (lower.includes('unauthorized') || lower.includes('authentication') || lower.includes('oauth') || stderr.includes('401') || stderr.includes('403')) {
|
|
140
|
-
return { type: 'auth_error', message: `Authentication failed: ${stderr.slice(0, 500)}`, details: { stderr } };
|
|
141
|
-
}
|
|
142
|
-
return { type: 'cli_error', message: stderr.slice(0, 500) || 'Unknown error' };
|
|
143
|
-
}
|
|
144
|
-
getSuggestion(error) {
|
|
145
|
-
switch (error.type) {
|
|
146
|
-
case 'rate_limit': return 'Wait and retry, or use /multi-review instead';
|
|
147
|
-
case 'auth_error': return 'Run `agy` and complete the Google OAuth sign-in';
|
|
148
|
-
case 'cli_not_found': return `Install with: ${AGY_INSTALL_CMD}`;
|
|
149
|
-
default: return 'Check the error message and try again';
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
async runConsult(request) {
|
|
153
|
-
const startTime = Date.now();
|
|
154
|
-
if (!existsSync(request.workingDir)) {
|
|
155
|
-
return {
|
|
156
|
-
success: false,
|
|
157
|
-
error: { type: 'cli_error', message: `Working directory does not exist: ${request.workingDir}` },
|
|
158
|
-
suggestion: 'Check that the working directory path is correct',
|
|
159
|
-
executionTimeMs: Date.now() - startTime,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
try {
|
|
163
|
-
const prompt = buildConsultPrompt(request);
|
|
164
|
-
const result = await this.runCli(prompt, request.workingDir);
|
|
165
|
-
if (result.exitCode !== 0) {
|
|
166
|
-
const error = this.categorizeError(result.stderr);
|
|
167
|
-
return { success: false, error, suggestion: this.getSuggestion(error), executionTimeMs: Date.now() - startTime };
|
|
168
|
-
}
|
|
169
|
-
if (!result.stdout.trim()) {
|
|
170
|
-
return {
|
|
171
|
-
success: false,
|
|
172
|
-
error: { type: 'cli_error', message: 'agy returned empty response' },
|
|
173
|
-
suggestion: 'Try again or use /multi-review instead',
|
|
174
|
-
executionTimeMs: Date.now() - startTime,
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
return { success: true, output: result.stdout, executionTimeMs: Date.now() - startTime };
|
|
178
|
-
}
|
|
179
|
-
catch (error) {
|
|
180
|
-
return this.handleException(error, startTime);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
91
|
}
|
|
184
|
-
registerAdapter(new GeminiAdapter());
|
|
185
92
|
export const geminiAdapter = new GeminiAdapter();
|
|
93
|
+
registerAdapter(geminiAdapter);
|