@tobi-or-not/quorum 0.1.0 → 0.3.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/LICENSE +202 -0
- package/README.md +5 -0
- package/dist/bench/fingerprint.d.ts +36 -0
- package/dist/bench/fingerprint.js +79 -0
- package/dist/bench/records.d.ts +62 -0
- package/dist/bench/records.js +161 -0
- package/dist/bench/report.d.ts +110 -0
- package/dist/bench/report.js +332 -0
- package/dist/bench/run-dir.d.ts +101 -0
- package/dist/bench/run-dir.js +379 -0
- package/dist/bench/runner.d.ts +80 -0
- package/dist/bench/runner.js +160 -0
- package/dist/bench/score.d.ts +30 -0
- package/dist/bench/score.js +38 -0
- package/dist/bench/stats.d.ts +51 -0
- package/dist/bench/stats.js +83 -0
- package/dist/bench/suite.d.ts +87 -0
- package/dist/bench/suite.js +286 -0
- package/dist/cli/bench.d.ts +32 -0
- package/dist/cli/bench.js +463 -0
- package/dist/cli/bin.js +9 -1
- package/dist/cli/io.d.ts +45 -0
- package/dist/cli/io.js +45 -0
- package/dist/cli/main.d.ts +7 -37
- package/dist/cli/main.js +47 -60
- package/dist/cli/print-config.js +38 -9
- package/dist/cli/render.d.ts +10 -0
- package/dist/cli/render.js +37 -16
- package/dist/config/claude-code.js +42 -11
- package/dist/config/env.js +135 -32
- package/dist/config/from-config.js +43 -9
- package/dist/config/load.d.ts +43 -0
- package/dist/config/load.js +205 -46
- package/dist/config/profiles.js +87 -20
- package/dist/config/resolve.js +194 -47
- package/dist/config/schema.js +98 -23
- package/dist/core/diff.d.ts +10 -0
- package/dist/core/diff.js +90 -17
- package/dist/core/errors.js +14 -5
- package/dist/core/flags.js +30 -6
- package/dist/core/output.js +49 -13
- package/dist/core/policy.js +6 -2
- package/dist/core/profile.js +42 -15
- package/dist/core/prompts.d.ts +3 -1
- package/dist/core/prompts.js +28 -8
- package/dist/core/quorum.js +128 -33
- package/dist/core/sanitize.d.ts +16 -1
- package/dist/core/sanitize.js +31 -5
- package/dist/core/stages/context.js +30 -5
- package/dist/core/stages/panel.js +55 -9
- package/dist/core/stages/research.js +13 -3
- package/dist/core/verify.js +6 -2
- package/dist/index.js +5 -1
- package/dist/providers/anthropic.js +28 -5
- package/dist/providers/build.js +57 -16
- package/dist/providers/claude-code.js +206 -51
- package/dist/providers/gemini.js +61 -14
- package/dist/providers/http.js +32 -9
- package/dist/providers/messages.js +14 -2
- package/dist/providers/ollama.js +31 -8
- package/dist/providers/openai-compatible.js +51 -15
- package/dist/providers/options.js +120 -40
- package/dist/providers/presets.js +143 -16
- package/dist/providers/reply.js +15 -5
- package/dist/providers/size.js +11 -3
- package/package.json +6 -5
package/dist/cli/main.js
CHANGED
|
@@ -5,17 +5,18 @@ import packageJson from '../../package.json' with { type: 'json' };
|
|
|
5
5
|
import { readEnv } from "../config/env.js";
|
|
6
6
|
import { fromConfig } from "../config/from-config.js";
|
|
7
7
|
import { loadConfig } from "../config/load.js";
|
|
8
|
+
import { decodeDiff } from "../core/diff.js";
|
|
8
9
|
import { ConfigError } from "../core/errors.js";
|
|
9
10
|
import { inertJson, inertLine } from "../core/sanitize.js";
|
|
11
|
+
import { runBench } from "./bench.js";
|
|
12
|
+
import { errorLines, errorMessage, EXIT } from "./io.js";
|
|
10
13
|
import { printConfig } from "./print-config.js";
|
|
11
14
|
import { bannerLines, progressSink } from "./render.js";
|
|
12
|
-
|
|
13
|
-
export const EXIT = { ok: 0, finding: 1, usage: 2, runtime: 3, incomplete: 4, interrupted: 130 };
|
|
14
|
-
/** The most diff the CLI reads, from stdin or a file, in bytes: a larger one is refused and reading stops there. */
|
|
15
|
-
export const MAX_DIFF_BYTES = 16 * 1024 * 1024;
|
|
15
|
+
export { errorMessage, EXIT };
|
|
16
16
|
const USAGE = [
|
|
17
17
|
'Usage: quorum [options] [diff-file]',
|
|
18
18
|
' git diff | quorum [options]',
|
|
19
|
+
' quorum bench [options] <suite>',
|
|
19
20
|
'',
|
|
20
21
|
'Options:',
|
|
21
22
|
' -c, --config <path> Read this config file, over QUORUM_CONFIG',
|
|
@@ -58,10 +59,15 @@ const OPTIONS = {
|
|
|
58
59
|
* The run is interrupted when `io.signal` aborts: it then writes `interrupted` and returns 130, whatever
|
|
59
60
|
* error ended the review, and writes no result. A review that has already resolved is complete.
|
|
60
61
|
*
|
|
62
|
+
* The one subcommand is `bench`: when the first argument is `bench`, the rest goes to `runBench` and its exit
|
|
63
|
+
* code is returned, before any review flag is read. A file named `bench` is reviewed as `quorum ./bench`.
|
|
64
|
+
*
|
|
61
65
|
* Everything the CLI writes is inert (invariant I3): each stderr line passes through `inertLine`, and
|
|
62
66
|
* the JSON result through `inertJson`.
|
|
63
67
|
*/
|
|
64
68
|
export async function runCli(io) {
|
|
69
|
+
if (io.argv[0] === 'bench')
|
|
70
|
+
return runBench(io, io.argv.slice(1));
|
|
65
71
|
let flags;
|
|
66
72
|
try {
|
|
67
73
|
flags = parseFlags(io.argv);
|
|
@@ -81,8 +87,11 @@ export async function runCli(io) {
|
|
|
81
87
|
const printing = values['print-config'] === true;
|
|
82
88
|
let diff = '';
|
|
83
89
|
try {
|
|
84
|
-
if (values.config === '')
|
|
85
|
-
throw new ConfigError([
|
|
90
|
+
if (values.config === '') {
|
|
91
|
+
throw new ConfigError([
|
|
92
|
+
{ path: '--config', message: 'must name a file' },
|
|
93
|
+
]);
|
|
94
|
+
}
|
|
86
95
|
if (printing && positionals.length > 0)
|
|
87
96
|
throw new Error('--print-config takes no diff file');
|
|
88
97
|
if (!printing)
|
|
@@ -93,9 +102,19 @@ export async function runCli(io) {
|
|
|
93
102
|
}
|
|
94
103
|
let quorum;
|
|
95
104
|
try {
|
|
96
|
-
const selection = values.profile === undefined
|
|
97
|
-
|
|
98
|
-
|
|
105
|
+
const selection = values.profile === undefined
|
|
106
|
+
? undefined
|
|
107
|
+
: { ids: values.profile, path: '--profile' };
|
|
108
|
+
const { config, source } = await loadConfig({
|
|
109
|
+
cwd: io.cwd,
|
|
110
|
+
env: io.env,
|
|
111
|
+
configPath: values.config,
|
|
112
|
+
selection,
|
|
113
|
+
});
|
|
114
|
+
quorum = await fromConfig(config, {
|
|
115
|
+
env: io.env,
|
|
116
|
+
events: progressSink(line => io.stderr.write(`${line}\n`)),
|
|
117
|
+
});
|
|
99
118
|
if (printing) {
|
|
100
119
|
io.stdout.write(printConfig(config, source));
|
|
101
120
|
return EXIT.ok;
|
|
@@ -117,7 +136,9 @@ export async function runCli(io) {
|
|
|
117
136
|
if (error instanceof ConfigError && quorum === undefined)
|
|
118
137
|
writeWarnings(io, readEnv(io.env).warnings);
|
|
119
138
|
io.stderr.write(`${errorLines(error)}\n`);
|
|
120
|
-
return error instanceof ConfigError
|
|
139
|
+
return error instanceof ConfigError
|
|
140
|
+
? EXIT.usage
|
|
141
|
+
: EXIT.runtime;
|
|
121
142
|
}
|
|
122
143
|
}
|
|
123
144
|
/** Write each warning as an inert `warning:` line. */
|
|
@@ -163,12 +184,19 @@ export function exitCodeFor(result, options = {}) {
|
|
|
163
184
|
if (result.meta.incomplete.some(entry => entry.reason === 'request-too-large' && gates(entry.profile)))
|
|
164
185
|
return EXIT.incomplete;
|
|
165
186
|
const incomplete = result.unreviewed.some(verdict => gates(verdict.profile)) || result.meta.incomplete.some(entry => gates(entry.profile));
|
|
166
|
-
return incomplete && options.allowIncomplete !== true
|
|
187
|
+
return incomplete && options.allowIncomplete !== true
|
|
188
|
+
? EXIT.incomplete
|
|
189
|
+
: EXIT.ok;
|
|
167
190
|
}
|
|
168
191
|
/** The flags of `argv` and its positional arguments; a usage error of `parseArgs` is raised as a `ConfigError`, one issue per line of its message. */
|
|
169
192
|
function parseFlags(argv) {
|
|
170
193
|
try {
|
|
171
|
-
return parseArgs({
|
|
194
|
+
return parseArgs({
|
|
195
|
+
args: [...argv],
|
|
196
|
+
options: OPTIONS,
|
|
197
|
+
strict: true,
|
|
198
|
+
allowPositionals: true,
|
|
199
|
+
});
|
|
172
200
|
}
|
|
173
201
|
catch (error) {
|
|
174
202
|
if (!(error instanceof Error) || !error.code?.startsWith('ERR_PARSE_ARGS_'))
|
|
@@ -186,53 +214,12 @@ async function readDiff(io, positionals) {
|
|
|
186
214
|
const [path, ...extra] = positionals;
|
|
187
215
|
if (extra.length > 0)
|
|
188
216
|
throw new Error(`unexpected arguments: ${extra.join(' ')}`);
|
|
189
|
-
if (path)
|
|
190
|
-
return readCapped(createReadStream(resolve(io.cwd, path)));
|
|
191
|
-
if (io.stdin.isTTY)
|
|
217
|
+
if (!path && io.stdin.isTTY)
|
|
192
218
|
throw new Error('no diff given');
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
* the loop closes the stream, so no more is read.
|
|
200
|
-
*/
|
|
201
|
-
async function readCapped(chunks) {
|
|
202
|
-
const encoder = new TextEncoder();
|
|
203
|
-
const decoder = new TextDecoder();
|
|
204
|
-
let bytes = 0;
|
|
205
|
-
let text = '';
|
|
206
|
-
for await (const chunk of chunks) {
|
|
207
|
-
const data = typeof chunk === 'string' ? encoder.encode(chunk) : chunk;
|
|
208
|
-
bytes += data.byteLength;
|
|
209
|
-
if (bytes > MAX_DIFF_BYTES)
|
|
210
|
-
throw new Error('the diff is over 16 MiB, the most quorum reads');
|
|
211
|
-
text += decoder.decode(data, { stream: true });
|
|
212
|
-
}
|
|
213
|
-
return text + decoder.decode();
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* The `Error:` lines of a failure, each inert: a ConfigError's issues one per line, as its message
|
|
217
|
-
* lists them, and any other failure's message on one line, so a line break in a file name or in text
|
|
218
|
-
* a server sent cannot start a line of its own.
|
|
219
|
-
*/
|
|
220
|
-
function errorLines(error) {
|
|
221
|
-
const lines = error instanceof ConfigError ? error.message.split('\n') : [errorMessage(error)];
|
|
222
|
-
return lines.map((line, index) => inertLine(index === 0 ? `Error: ${line}` : line)).join('\n');
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* The text of a failure, for any value a promise can reject with: an `Error`'s message, else the
|
|
226
|
-
* value's text form, else a fixed text when even that throws, as it does for an object without a
|
|
227
|
-
* prototype. It never throws, so neither do the lines built from it.
|
|
228
|
-
*/
|
|
229
|
-
export function errorMessage(error) {
|
|
230
|
-
if (error instanceof Error)
|
|
231
|
-
return error.message;
|
|
232
|
-
try {
|
|
233
|
-
return String(error);
|
|
234
|
-
}
|
|
235
|
-
catch {
|
|
236
|
-
return 'an error with no text form';
|
|
237
|
-
}
|
|
219
|
+
const diff = await decodeDiff(path
|
|
220
|
+
? createReadStream(resolve(io.cwd, path))
|
|
221
|
+
: io.stdin);
|
|
222
|
+
if (diff === undefined)
|
|
223
|
+
throw new Error('the diff is over 16 MiB, the most quorum reads');
|
|
224
|
+
return diff;
|
|
238
225
|
}
|
package/dist/cli/print-config.js
CHANGED
|
@@ -16,17 +16,26 @@ function sha256(text) {
|
|
|
16
16
|
}
|
|
17
17
|
/** The keys of a record, each with the redacted word: a header, query or body value can be a credential. */
|
|
18
18
|
function redactedValues(record) {
|
|
19
|
-
return record === undefined
|
|
19
|
+
return record === undefined
|
|
20
|
+
? undefined
|
|
21
|
+
: Object.fromEntries(Object.keys(record).map(key => [key, REDACTED]));
|
|
20
22
|
}
|
|
21
23
|
/** The auth style as set: a name, or the header and the prefix a key is sent with. Neither holds the key. */
|
|
22
24
|
function authView(auth) {
|
|
23
|
-
return typeof auth === 'object'
|
|
25
|
+
return typeof auth === 'object'
|
|
26
|
+
? {
|
|
27
|
+
header: own(auth, 'header'),
|
|
28
|
+
prefix: own(auth, 'prefix'),
|
|
29
|
+
}
|
|
30
|
+
: auth;
|
|
24
31
|
}
|
|
25
32
|
/** Where the instructions go (`native` or `inline`), the only values a spec accepts; any other value is a prompt, so it prints as its hash. */
|
|
26
33
|
function systemPromptView(value) {
|
|
27
34
|
if (value === undefined || value === 'native' || value === 'inline')
|
|
28
35
|
return value;
|
|
29
|
-
return typeof value === 'string'
|
|
36
|
+
return typeof value === 'string'
|
|
37
|
+
? sha256(value)
|
|
38
|
+
: REDACTED;
|
|
30
39
|
}
|
|
31
40
|
/**
|
|
32
41
|
* A provider defined as data, field by field: a field of a spec that is not listed here prints nothing.
|
|
@@ -39,10 +48,14 @@ function specView(spec) {
|
|
|
39
48
|
preset: own(spec, 'preset'),
|
|
40
49
|
protocol: own(spec, 'protocol'),
|
|
41
50
|
command: own(spec, 'command'),
|
|
42
|
-
origin: cli
|
|
51
|
+
origin: cli
|
|
52
|
+
? undefined
|
|
53
|
+
: providerOrigin(spec),
|
|
43
54
|
model: own(spec, 'model'),
|
|
44
55
|
contextTokens: own(spec, 'contextTokens'),
|
|
45
|
-
apiKey: own(spec, 'apiKey') === undefined
|
|
56
|
+
apiKey: own(spec, 'apiKey') === undefined
|
|
57
|
+
? undefined
|
|
58
|
+
: REDACTED,
|
|
46
59
|
auth: authView(own(spec, 'auth') ?? (cli ? 'inherit' : undefined)),
|
|
47
60
|
args: own(spec, 'args'),
|
|
48
61
|
headers: redactedValues(own(spec, 'headers')),
|
|
@@ -58,7 +71,12 @@ function specView(spec) {
|
|
|
58
71
|
/** A provider object by what it implements and its model, when that is a string; never its function. */
|
|
59
72
|
function objectView(provider) {
|
|
60
73
|
const model = own(provider, 'model');
|
|
61
|
-
return {
|
|
74
|
+
return {
|
|
75
|
+
implements: 'Provider',
|
|
76
|
+
model: typeof model === 'string'
|
|
77
|
+
? model
|
|
78
|
+
: undefined,
|
|
79
|
+
};
|
|
62
80
|
}
|
|
63
81
|
/** A profile that runs: its providers, the votes its policy needs, and each prompt as its hash. */
|
|
64
82
|
function profileView({ profile, research, voters }) {
|
|
@@ -67,7 +85,10 @@ function profileView({ profile, research, voters }) {
|
|
|
67
85
|
research,
|
|
68
86
|
lenses: { ...voters },
|
|
69
87
|
thresholds: thresholdsFor(profile),
|
|
70
|
-
prompts: {
|
|
88
|
+
prompts: {
|
|
89
|
+
research: sha256(profile.prompts.research),
|
|
90
|
+
vote: sha256(profile.prompts.vote),
|
|
91
|
+
},
|
|
71
92
|
};
|
|
72
93
|
}
|
|
73
94
|
/**
|
|
@@ -85,8 +106,16 @@ function profileView({ profile, research, voters }) {
|
|
|
85
106
|
export function printConfig(config, source) {
|
|
86
107
|
const view = {
|
|
87
108
|
source: source ?? null,
|
|
88
|
-
providers: Object.fromEntries(Object.entries(config.providers).map(([name, provider]) => [
|
|
89
|
-
|
|
109
|
+
providers: Object.fromEntries(Object.entries(config.providers).map(([name, provider]) => [
|
|
110
|
+
name,
|
|
111
|
+
isProvider(provider)
|
|
112
|
+
? objectView(provider)
|
|
113
|
+
: specView(provider),
|
|
114
|
+
])),
|
|
115
|
+
profiles: Object.fromEntries(config.profiles.map(resolved => [
|
|
116
|
+
resolved.profile.id,
|
|
117
|
+
profileView(resolved),
|
|
118
|
+
])),
|
|
90
119
|
concurrency: config.concurrency ?? DEFAULT_CONCURRENCY,
|
|
91
120
|
maxFindings: config.maxFindings ?? DEFAULT_MAX_FINDINGS,
|
|
92
121
|
warnings: [...config.warnings],
|
package/dist/cli/render.d.ts
CHANGED
|
@@ -22,6 +22,16 @@ export declare function progressSink(write: (line: string) => void): EventSink;
|
|
|
22
22
|
* polluted `Object.prototype` fills neither.
|
|
23
23
|
*/
|
|
24
24
|
export declare function providerOrigin(spec: Exclude<ResolvedProvider, Provider>): string;
|
|
25
|
+
/**
|
|
26
|
+
* Who researches and who votes in each profile of a config, by profile in run order, as the banner names
|
|
27
|
+
* them: `<model> @ <origin>` for a provider (see `bannerLines`), the panel as one provider when every lens
|
|
28
|
+
* shares it, else each lens's. The labels are not yet inert: the caller makes each line it writes inert.
|
|
29
|
+
*/
|
|
30
|
+
export declare function profileProviders(config: ResolvedConfig): Array<{
|
|
31
|
+
readonly profile: string;
|
|
32
|
+
readonly research: string;
|
|
33
|
+
readonly panel: string;
|
|
34
|
+
}>;
|
|
25
35
|
/**
|
|
26
36
|
* The lines a run prints before its progress: who researches and who votes, from the resolved config, as
|
|
27
37
|
* `<model> @ <origin>` (a provider object as `<model> @ the provider object <name>`, a `claude-code`
|
package/dist/cli/render.js
CHANGED
|
@@ -14,14 +14,20 @@ import { presetOf } from "../providers/presets.js";
|
|
|
14
14
|
*/
|
|
15
15
|
export function renderEvent(event, prefixed = false) {
|
|
16
16
|
const line = progressLine(event, prefixed);
|
|
17
|
-
return line === undefined
|
|
17
|
+
return line === undefined
|
|
18
|
+
? undefined
|
|
19
|
+
: inertLine(line);
|
|
18
20
|
}
|
|
19
21
|
const profilePrefix = (profile) => `[${profile}] `;
|
|
20
22
|
function progressLine(event, prefixed) {
|
|
21
|
-
const of = (profile, line) => prefixed
|
|
23
|
+
const of = (profile, line) => prefixed
|
|
24
|
+
? `${profilePrefix(profile)}${line}`
|
|
25
|
+
: line;
|
|
22
26
|
switch (event.type) {
|
|
23
27
|
case 'stage:end':
|
|
24
|
-
return event.stage === 'dedup'
|
|
28
|
+
return event.stage === 'dedup'
|
|
29
|
+
? of(event.profile, `${event.count} candidate(s) after dedup`)
|
|
30
|
+
: undefined;
|
|
25
31
|
case 'finding:invalid':
|
|
26
32
|
return of(event.profile, `invalid finding dropped: ${event.reason}`);
|
|
27
33
|
case 'incomplete':
|
|
@@ -69,22 +75,35 @@ export function providerOrigin(spec) {
|
|
|
69
75
|
}
|
|
70
76
|
/** Where a provider defined as data is reached, as the banner names it: its origin, or `claude-code` for the CLI, which has none. */
|
|
71
77
|
function endpointOf(spec) {
|
|
72
|
-
return isClaudeCode(own(spec, 'protocol'))
|
|
78
|
+
return isClaudeCode(own(spec, 'protocol'))
|
|
79
|
+
? 'claude-code'
|
|
80
|
+
: providerOrigin(spec);
|
|
73
81
|
}
|
|
74
82
|
/** What a provider reads as in the banner: its model and where it is reached, a provider object by its config key. */
|
|
75
83
|
function providerLabel(providers, name) {
|
|
76
84
|
// Resolution bound every profile to providers it kept, so each name is found.
|
|
77
85
|
const entry = own(providers, name);
|
|
78
|
-
return isProvider(entry)
|
|
86
|
+
return isProvider(entry)
|
|
87
|
+
? `${entry.model} @ the provider object ${name}`
|
|
88
|
+
: `${own(entry, 'model')} @ ${endpointOf(entry)}`;
|
|
79
89
|
}
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return
|
|
90
|
+
/**
|
|
91
|
+
* Who researches and who votes in each profile of a config, by profile in run order, as the banner names
|
|
92
|
+
* them: `<model> @ <origin>` for a provider (see `bannerLines`), the panel as one provider when every lens
|
|
93
|
+
* shares it, else each lens's. The labels are not yet inert: the caller makes each line it writes inert.
|
|
94
|
+
*/
|
|
95
|
+
export function profileProviders(config) {
|
|
96
|
+
const label = (name) => providerLabel(config.providers, name);
|
|
97
|
+
return config.profiles.map(({ profile, research, voters }) => {
|
|
98
|
+
const lenses = Object.entries(voters);
|
|
99
|
+
return {
|
|
100
|
+
profile: profile.id,
|
|
101
|
+
research: label(research),
|
|
102
|
+
panel: new Set(lenses.map(([, name]) => name)).size === 1
|
|
103
|
+
? label(lenses[0][1])
|
|
104
|
+
: lenses.map(([lens, name]) => `${lens} (${label(name)})`).join(', '),
|
|
105
|
+
};
|
|
106
|
+
});
|
|
88
107
|
}
|
|
89
108
|
/**
|
|
90
109
|
* The lines a run prints before its progress: who researches and who votes, from the resolved config, as
|
|
@@ -95,8 +114,10 @@ function profileBanner({ research, voters }, providers) {
|
|
|
95
114
|
*/
|
|
96
115
|
export function bannerLines(config) {
|
|
97
116
|
const prefixed = config.profiles.length > 1;
|
|
98
|
-
return config.
|
|
99
|
-
const prefix = prefixed
|
|
100
|
-
|
|
117
|
+
return profileProviders(config).flatMap(({ profile, research, panel }) => {
|
|
118
|
+
const prefix = prefixed
|
|
119
|
+
? profilePrefix(profile)
|
|
120
|
+
: '';
|
|
121
|
+
return [`Research (${research})...`, `Panel will use ${panel}`].map(line => inertLine(`${prefix}${line}`));
|
|
101
122
|
});
|
|
102
123
|
}
|
|
@@ -29,8 +29,12 @@ function isExecutableFile(path, platform) {
|
|
|
29
29
|
}
|
|
30
30
|
/** The `PATH` of the environment: its own variable, in the letter case Windows gives its name, else undefined. */
|
|
31
31
|
function searchPath(env, platform) {
|
|
32
|
-
const name = platform === 'win32'
|
|
33
|
-
|
|
32
|
+
const name = platform === 'win32'
|
|
33
|
+
? Object.keys(env).find(key => key.toUpperCase() === 'PATH')
|
|
34
|
+
: 'PATH';
|
|
35
|
+
return name === undefined
|
|
36
|
+
? undefined
|
|
37
|
+
: envValue(env, name);
|
|
34
38
|
}
|
|
35
39
|
/**
|
|
36
40
|
* The executable `command` names: an absolute path as it is, a bare name in the first absolute entry of the
|
|
@@ -43,10 +47,17 @@ function searchPath(env, platform) {
|
|
|
43
47
|
export function findCommand(command, env, platform = process.platform) {
|
|
44
48
|
if (commandProblem(command) !== undefined)
|
|
45
49
|
return undefined;
|
|
46
|
-
if (isAbsolute(command))
|
|
47
|
-
return isExecutableFile(command, platform)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
if (isAbsolute(command)) {
|
|
51
|
+
return isExecutableFile(command, platform)
|
|
52
|
+
? command
|
|
53
|
+
: undefined;
|
|
54
|
+
}
|
|
55
|
+
const file = platform === 'win32' && extname(command) === ''
|
|
56
|
+
? `${command}.exe`
|
|
57
|
+
: command;
|
|
58
|
+
const entries = (searchPath(env, platform) ?? '').split(platform === 'win32'
|
|
59
|
+
? ';'
|
|
60
|
+
: ':').filter(entry => isAbsolute(entry));
|
|
50
61
|
return entries.map(entry => join(entry, file)).find(candidate => isExecutableFile(candidate, platform));
|
|
51
62
|
}
|
|
52
63
|
/**
|
|
@@ -62,11 +73,31 @@ export function claudeCodeCommand(name, settings, variable, env) {
|
|
|
62
73
|
const found = findCommand(variable ?? named ?? DEFAULT_COMMAND, env);
|
|
63
74
|
if (found !== undefined)
|
|
64
75
|
return { command: found, issues: [] };
|
|
65
|
-
if (variable !== undefined)
|
|
66
|
-
return {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
if (variable !== undefined) {
|
|
77
|
+
return {
|
|
78
|
+
issues: [
|
|
79
|
+
{ path: CLAUDE_CODE_COMMAND, message: NO_EXECUTABLE },
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
if (named !== undefined) {
|
|
84
|
+
return {
|
|
85
|
+
issues: [
|
|
86
|
+
{
|
|
87
|
+
path: configPath(['providers', name, 'command']),
|
|
88
|
+
message: NO_EXECUTABLE,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
issues: [
|
|
95
|
+
{
|
|
96
|
+
path: configPath(['providers', name]),
|
|
97
|
+
message: CLAUDE_NOT_FOUND,
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
};
|
|
70
101
|
}
|
|
71
102
|
/**
|
|
72
103
|
* The warning of a provider that runs under `inherit` (or sets no `auth`) while `ANTHROPIC_API_KEY` is set:
|