@tobi-or-not/quorum 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +1 -1
  2. package/dist/bench/fingerprint.d.ts +7 -5
  3. package/dist/bench/fingerprint.js +22 -9
  4. package/dist/bench/records.d.ts +70 -0
  5. package/dist/bench/records.js +30 -0
  6. package/dist/bench/runner.d.ts +18 -0
  7. package/dist/bench/runner.js +29 -3
  8. package/dist/cli/bench.d.ts +11 -4
  9. package/dist/cli/bench.js +34 -17
  10. package/dist/cli/bin.js +2 -2
  11. package/dist/cli/main.d.ts +34 -14
  12. package/dist/cli/main.js +99 -20
  13. package/dist/cli/print-config.d.ts +8 -6
  14. package/dist/cli/print-config.js +21 -8
  15. package/dist/cli/render.d.ts +2 -2
  16. package/dist/cli/render.js +21 -2
  17. package/dist/config/env.d.ts +32 -19
  18. package/dist/config/env.js +95 -32
  19. package/dist/config/from-config.js +15 -3
  20. package/dist/config/resolve.d.ts +9 -1
  21. package/dist/config/resolve.js +17 -1
  22. package/dist/config/schema.d.ts +141 -5
  23. package/dist/config/schema.js +125 -12
  24. package/dist/core/clock.d.ts +17 -0
  25. package/dist/core/clock.js +14 -0
  26. package/dist/core/coverage.d.ts +49 -0
  27. package/dist/core/coverage.js +144 -0
  28. package/dist/core/diff.d.ts +24 -0
  29. package/dist/core/diff.js +63 -18
  30. package/dist/core/errors.d.ts +12 -3
  31. package/dist/core/errors.js +21 -2
  32. package/dist/core/exclude.d.ts +42 -0
  33. package/dist/core/exclude.js +189 -0
  34. package/dist/core/limits.d.ts +82 -0
  35. package/dist/core/limits.js +163 -0
  36. package/dist/core/output.d.ts +3 -2
  37. package/dist/core/output.js +3 -2
  38. package/dist/core/ports.d.ts +57 -2
  39. package/dist/core/ports.js +36 -1
  40. package/dist/core/quorum.d.ts +24 -8
  41. package/dist/core/quorum.js +187 -56
  42. package/dist/core/retry.d.ts +36 -0
  43. package/dist/core/retry.js +46 -0
  44. package/dist/core/stages/context.d.ts +118 -23
  45. package/dist/core/stages/context.js +304 -46
  46. package/dist/core/stages/panel.d.ts +5 -4
  47. package/dist/core/stages/panel.js +30 -11
  48. package/dist/core/stages/research.d.ts +15 -6
  49. package/dist/core/stages/research.js +75 -18
  50. package/dist/core/tokens.d.ts +31 -0
  51. package/dist/core/tokens.js +81 -0
  52. package/dist/core/types.d.ts +77 -10
  53. package/dist/index.d.ts +1 -1
  54. package/dist/providers/anthropic.d.ts +2 -1
  55. package/dist/providers/anthropic.js +8 -3
  56. package/dist/providers/claude-code.d.ts +51 -11
  57. package/dist/providers/claude-code.js +60 -25
  58. package/dist/providers/gemini.d.ts +4 -1
  59. package/dist/providers/gemini.js +63 -11
  60. package/dist/providers/http.d.ts +49 -4
  61. package/dist/providers/http.js +155 -14
  62. package/dist/providers/ollama.d.ts +3 -1
  63. package/dist/providers/ollama.js +11 -5
  64. package/dist/providers/openai-compatible.d.ts +3 -1
  65. package/dist/providers/openai-compatible.js +11 -5
  66. package/dist/providers/options.d.ts +12 -3
  67. package/dist/providers/options.js +30 -10
  68. package/dist/providers/size.d.ts +10 -14
  69. package/dist/providers/size.js +15 -69
  70. package/package.json +1 -1
  71. package/schema/quorum.schema.json +34 -1
@@ -3,7 +3,7 @@ import { createQuorum } from "../core/quorum.js";
3
3
  import { buildProvider } from "../providers/build.js";
4
4
  import { checkCodeValue } from "./load.js";
5
5
  import { isResolvedConfig, resolveConfig } from "./resolve.js";
6
- import { configInputSchema, configPath, isProvider } from "./schema.js";
6
+ import { configInputSchema, configPath, isProvider, statedFacts, statedWorstCase } from "./schema.js";
7
7
  /** A provider the config defines as data, built by the builder: its issues name the provider where the config defines it. */
8
8
  function fromSpec(name, spec, env) {
9
9
  try {
@@ -20,7 +20,7 @@ function fromSpec(name, spec, env) {
20
20
  };
21
21
  }
22
22
  }
23
- /** A provider object of the config, which the check read once into a snapshot, under the name the config gives it. */
23
+ /** A provider object of the config, which the check read once into a snapshot, under the name the config gives it, with the `timeoutMs`, `retries` and `worstCase` the snapshot holds. */
24
24
  function fromObject(name, snapshot) {
25
25
  const { model, complete } = snapshot;
26
26
  if (typeof model !== 'string') {
@@ -33,8 +33,17 @@ function fromObject(name, snapshot) {
33
33
  ],
34
34
  };
35
35
  }
36
+ const worstCase = statedWorstCase(snapshot);
36
37
  return {
37
- provider: { id: name, model, complete },
38
+ provider: {
39
+ id: name,
40
+ model,
41
+ complete,
42
+ ...statedFacts(snapshot).stated,
43
+ ...worstCase === undefined
44
+ ? {}
45
+ : { worstCase },
46
+ },
38
47
  issues: [],
39
48
  };
40
49
  }
@@ -91,6 +100,9 @@ export async function fromConfig(config, options = {}) {
91
100
  profiles: resolved.profiles.map(({ profile }) => profile),
92
101
  concurrency: resolved.concurrency,
93
102
  maxFindings: resolved.maxFindings,
103
+ maxReviewTokens: resolved.maxReviewTokens,
104
+ reviewTimeoutMs: resolved.reviewTimeoutMs,
105
+ exclude: resolved.exclude,
94
106
  }, { profiles: ports, events: options.events });
95
107
  return Object.freeze({
96
108
  review: quorum.review,
@@ -15,6 +15,12 @@ export interface ResolvedConfig {
15
15
  readonly profiles: readonly ResolvedProfile[];
16
16
  readonly concurrency?: number;
17
17
  readonly maxFindings?: number;
18
+ /** The most tokens one review spends: `QUORUM_MAX_REVIEW_TOKENS`, else the config's; absent when neither sets it. */
19
+ readonly maxReviewTokens?: number;
20
+ /** The deadline of one review, in milliseconds: `QUORUM_REVIEW_TIMEOUT_MS`, else the config's; absent when neither sets it. */
21
+ readonly reviewTimeoutMs?: number;
22
+ /** The path patterns of the files every review leaves out; absent when the config lists none. */
23
+ readonly exclude?: readonly string[];
18
24
  readonly warnings: readonly string[];
19
25
  }
20
26
  /** Whether `value` is a config `resolveConfig` returned. */
@@ -27,7 +33,9 @@ export declare function isResolvedConfig(value: unknown): value is ResolvedConfi
27
33
  * preset's own variable is read only at the preset's origin. Every provider needs a context size, and the issue
28
34
  * of a missing one names what to set (`reportMissingContext`). A `claude-code` provider in use gets its
29
35
  * command as it gets its key: `QUORUM_CLAUDE_CODE_COMMAND`, else the config's, else `claude` in an absolute
30
- * entry of `PATH`, found or refused here, and its billing warning. A resolved config is returned as it is. The
36
+ * entry of `PATH`, found or refused here, and its billing warning. The review's limits, `maxReviewTokens` and
37
+ * `reviewTimeoutMs`, come from `QUORUM_MAX_REVIEW_TOKENS` and `QUORUM_REVIEW_TIMEOUT_MS`, else from the config,
38
+ * and are kept only when one of them sets them. A resolved config is returned as it is. The
31
39
  * input must already have passed a config schema. `options.selection`, when given, names the profiles that
32
40
  * run, over `QUORUM_PROFILES`, which is still checked; its ids are checked before anything is resolved.
33
41
  *
@@ -370,7 +370,9 @@ function bindRoles(roles, names) {
370
370
  * preset's own variable is read only at the preset's origin. Every provider needs a context size, and the issue
371
371
  * of a missing one names what to set (`reportMissingContext`). A `claude-code` provider in use gets its
372
372
  * command as it gets its key: `QUORUM_CLAUDE_CODE_COMMAND`, else the config's, else `claude` in an absolute
373
- * entry of `PATH`, found or refused here, and its billing warning. A resolved config is returned as it is. The
373
+ * entry of `PATH`, found or refused here, and its billing warning. The review's limits, `maxReviewTokens` and
374
+ * `reviewTimeoutMs`, come from `QUORUM_MAX_REVIEW_TOKENS` and `QUORUM_REVIEW_TIMEOUT_MS`, else from the config,
375
+ * and are kept only when one of them sets them. A resolved config is returned as it is. The
374
376
  * input must already have passed a config schema. `options.selection`, when given, names the profiles that
375
377
  * run, over `QUORUM_PROFILES`, which is still checked; its ids are checked before anything is resolved.
376
378
  *
@@ -443,6 +445,9 @@ export function resolveConfig(input, options) {
443
445
  throw new ConfigError(issues);
444
446
  const concurrency = own(input, 'concurrency');
445
447
  const maxFindings = own(input, 'maxFindings');
448
+ const maxReviewTokens = own(layer, 'maxReviewTokens') ?? own(input, 'maxReviewTokens');
449
+ const reviewTimeoutMs = own(layer, 'reviewTimeoutMs') ?? own(input, 'reviewTimeoutMs');
450
+ const exclude = own(input, 'exclude');
446
451
  const resolved = Object.freeze({
447
452
  providers: deepFreeze(Object.fromEntries(checked.providers)),
448
453
  profiles: Object.freeze([...profiles.profiles]),
@@ -452,6 +457,17 @@ export function resolveConfig(input, options) {
452
457
  ...maxFindings === undefined
453
458
  ? {}
454
459
  : { maxFindings },
460
+ ...maxReviewTokens === undefined
461
+ ? {}
462
+ : { maxReviewTokens },
463
+ ...reviewTimeoutMs === undefined
464
+ ? {}
465
+ : { reviewTimeoutMs },
466
+ ...exclude === undefined || exclude.length === 0
467
+ ? {}
468
+ : {
469
+ exclude: Object.freeze([...exclude]),
470
+ },
455
471
  warnings: Object.freeze([
456
472
  ...layer.warnings,
457
473
  ...checked.warnings,
@@ -3,9 +3,33 @@ import type { ConfigIssue } from '../core/errors.ts';
3
3
  import type { JsonSchema, Provider } from '../core/ports.ts';
4
4
  /** Whether `value` implements `Provider` as a code config can hand one over: an object whose `complete` is a function. */
5
5
  export declare function isProvider(value: unknown): value is Provider;
6
+ /** The facts a provider object states of its calls, as the port names them. */
7
+ interface StatedFacts {
8
+ readonly timeoutMs?: number;
9
+ readonly retries?: number;
10
+ }
11
+ /**
12
+ * The facts `provider` states, each read as own data, so a getter never runs and an inherited property
13
+ * or a proxy that throws states nothing: `stated` holds those that pass their check, and `problems` the
14
+ * field and wording of each that does not. A value is never quoted.
15
+ */
16
+ export declare function statedFacts(provider: unknown): {
17
+ readonly stated: StatedFacts;
18
+ readonly problems: ReadonlyArray<{
19
+ readonly field: keyof StatedFacts;
20
+ readonly message: string;
21
+ }>;
22
+ };
23
+ /**
24
+ * The `worstCase` a provider states, as own data: a function, else undefined. It is no fact of `FACTS`: a
25
+ * function is no number to check or to hash, so the fingerprint and the printed config never see it, and a
26
+ * value that is no function is an issue of `providerObject` and is never read here.
27
+ */
28
+ export declare function statedWorstCase(provider: unknown): Provider['worstCase'];
6
29
  /**
7
30
  * `entry` named `id`, the config's key for it, when it is a snapshot the schema made of a provider object: a
8
- * copy that holds `id` as well, built from the snapshot's own data. Anything else is returned as it is.
31
+ * copy that holds `id` as well, built from the snapshot's own data, the facts and the `worstCase` it states
32
+ * included. Anything else is returned as it is.
9
33
  */
10
34
  export declare function nameSnapshot(id: string, entry: unknown): unknown;
11
35
  /**
@@ -75,6 +99,8 @@ export declare const configFileSchema: z.ZodObject<{
75
99
  native: "native";
76
100
  inline: "inline";
77
101
  }>>;
102
+ timeoutMs: z.ZodOptional<z.ZodInt>;
103
+ retries: z.ZodOptional<z.ZodInt>;
78
104
  args: z.ZodOptional<z.ZodArray<z.ZodString>>;
79
105
  }, z.core.$strict>>>;
80
106
  roles: z.ZodOptional<z.ZodObject<{
@@ -83,6 +109,9 @@ export declare const configFileSchema: z.ZodObject<{
83
109
  }, z.core.$strict>>;
84
110
  concurrency: z.ZodOptional<z.ZodInt>;
85
111
  maxFindings: z.ZodOptional<z.ZodInt>;
112
+ maxReviewTokens: z.ZodOptional<z.ZodInt>;
113
+ reviewTimeoutMs: z.ZodOptional<z.ZodInt>;
114
+ exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
86
115
  profiles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
87
116
  extends: z.ZodOptional<z.ZodEnum<{
88
117
  [x: string]: string;
@@ -143,7 +172,55 @@ export declare const configFileSchema: z.ZodObject<{
143
172
  export declare const configCodeSchema: z.ZodObject<{
144
173
  $schema: z.ZodOptional<z.ZodString>;
145
174
  version: z.ZodOptional<z.ZodLiteral<1>>;
146
- providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodPipe<z.ZodCustom<Provider, Provider>, z.ZodTransform<Provider, Provider>>, z.ZodObject<{
175
+ providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodPipe<z.ZodCustom<Provider, Provider>, z.ZodTransform<Provider, Provider>>, z.ZodPipe<z.ZodCustom<{
176
+ apiKey?: string | undefined;
177
+ command?: string | undefined;
178
+ preset?: "anthropic" | "gemini" | "ollama" | "ollama-cloud" | "lmstudio" | "llamacpp" | "vllm" | "openai" | "azure-openai" | "openrouter" | "groq" | "mistral" | "deepseek" | "together" | "fireworks" | "xai" | undefined;
179
+ protocol?: "openai-compatible" | "anthropic" | "gemini" | "ollama" | "claude-code" | undefined;
180
+ baseUrl?: string | undefined;
181
+ model?: string | undefined;
182
+ contextTokens?: number | undefined;
183
+ apiKeyEnv?: string | undefined;
184
+ auth?: "bearer" | "x-api-key" | "none" | "inherit" | "login" | "api-key" | {
185
+ header: string;
186
+ prefix?: string | undefined;
187
+ } | undefined;
188
+ headers?: Record<string, string> | undefined;
189
+ query?: Record<string, string> | undefined;
190
+ extraBody?: Record<string, z.core.util.JSONType> | undefined;
191
+ structuredOutput?: "prompt" | "json" | "schema" | undefined;
192
+ temperature?: number | null | undefined;
193
+ maxTokens?: number | undefined;
194
+ maxTokensField?: "max_tokens" | "max_completion_tokens" | undefined;
195
+ systemPrompt?: "native" | "inline" | undefined;
196
+ timeoutMs?: number | undefined;
197
+ retries?: number | undefined;
198
+ args?: string[] | undefined;
199
+ }, {
200
+ apiKey?: string | undefined;
201
+ command?: string | undefined;
202
+ preset?: "anthropic" | "gemini" | "ollama" | "ollama-cloud" | "lmstudio" | "llamacpp" | "vllm" | "openai" | "azure-openai" | "openrouter" | "groq" | "mistral" | "deepseek" | "together" | "fireworks" | "xai" | undefined;
203
+ protocol?: "openai-compatible" | "anthropic" | "gemini" | "ollama" | "claude-code" | undefined;
204
+ baseUrl?: string | undefined;
205
+ model?: string | undefined;
206
+ contextTokens?: number | undefined;
207
+ apiKeyEnv?: string | undefined;
208
+ auth?: "bearer" | "x-api-key" | "none" | "inherit" | "login" | "api-key" | {
209
+ header: string;
210
+ prefix?: string | undefined;
211
+ } | undefined;
212
+ headers?: Record<string, string> | undefined;
213
+ query?: Record<string, string> | undefined;
214
+ extraBody?: Record<string, z.core.util.JSONType> | undefined;
215
+ structuredOutput?: "prompt" | "json" | "schema" | undefined;
216
+ temperature?: number | null | undefined;
217
+ maxTokens?: number | undefined;
218
+ maxTokensField?: "max_tokens" | "max_completion_tokens" | undefined;
219
+ systemPrompt?: "native" | "inline" | undefined;
220
+ timeoutMs?: number | undefined;
221
+ retries?: number | undefined;
222
+ args?: string[] | undefined;
223
+ }>, z.ZodObject<{
147
224
  apiKey: z.ZodOptional<z.ZodString>;
148
225
  command: z.ZodOptional<z.ZodString>;
149
226
  preset: z.ZodOptional<z.ZodEnum<{
@@ -204,14 +281,19 @@ export declare const configCodeSchema: z.ZodObject<{
204
281
  native: "native";
205
282
  inline: "inline";
206
283
  }>>;
284
+ timeoutMs: z.ZodOptional<z.ZodInt>;
285
+ retries: z.ZodOptional<z.ZodInt>;
207
286
  args: z.ZodOptional<z.ZodArray<z.ZodString>>;
208
- }, z.core.$strict>]>>>;
287
+ }, z.core.$strict>>]>>>;
209
288
  roles: z.ZodOptional<z.ZodObject<{
210
289
  research: z.ZodOptional<z.ZodString>;
211
290
  voter: z.ZodOptional<z.ZodString>;
212
291
  }, z.core.$strict>>;
213
292
  concurrency: z.ZodOptional<z.ZodInt>;
214
293
  maxFindings: z.ZodOptional<z.ZodInt>;
294
+ maxReviewTokens: z.ZodOptional<z.ZodInt>;
295
+ reviewTimeoutMs: z.ZodOptional<z.ZodInt>;
296
+ exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
215
297
  profiles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
216
298
  extends: z.ZodOptional<z.ZodEnum<{
217
299
  [x: string]: string;
@@ -272,7 +354,55 @@ export declare const configCodeSchema: z.ZodObject<{
272
354
  export declare const configInputSchema: z.ZodObject<{
273
355
  $schema: z.ZodOptional<z.ZodString>;
274
356
  version: z.ZodOptional<z.ZodLiteral<1>>;
275
- providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodPipe<z.ZodCustom<Provider, Provider>, z.ZodTransform<Provider, Provider>>, z.ZodObject<{
357
+ providers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodPipe<z.ZodCustom<Provider, Provider>, z.ZodTransform<Provider, Provider>>, z.ZodPipe<z.ZodCustom<{
358
+ apiKey?: string | undefined;
359
+ command?: string | undefined;
360
+ preset?: "anthropic" | "gemini" | "ollama" | "ollama-cloud" | "lmstudio" | "llamacpp" | "vllm" | "openai" | "azure-openai" | "openrouter" | "groq" | "mistral" | "deepseek" | "together" | "fireworks" | "xai" | undefined;
361
+ protocol?: "openai-compatible" | "anthropic" | "gemini" | "ollama" | "claude-code" | undefined;
362
+ baseUrl?: string | undefined;
363
+ model?: string | undefined;
364
+ contextTokens?: number | undefined;
365
+ apiKeyEnv?: string | undefined;
366
+ auth?: "bearer" | "x-api-key" | "none" | "inherit" | "login" | "api-key" | {
367
+ header: string;
368
+ prefix?: string | undefined;
369
+ } | undefined;
370
+ headers?: Record<string, string> | undefined;
371
+ query?: Record<string, string> | undefined;
372
+ extraBody?: Record<string, z.core.util.JSONType> | undefined;
373
+ structuredOutput?: "prompt" | "json" | "schema" | undefined;
374
+ temperature?: number | null | undefined;
375
+ maxTokens?: number | undefined;
376
+ maxTokensField?: "max_tokens" | "max_completion_tokens" | undefined;
377
+ systemPrompt?: "native" | "inline" | undefined;
378
+ timeoutMs?: number | undefined;
379
+ retries?: number | undefined;
380
+ args?: string[] | undefined;
381
+ }, {
382
+ apiKey?: string | undefined;
383
+ command?: string | undefined;
384
+ preset?: "anthropic" | "gemini" | "ollama" | "ollama-cloud" | "lmstudio" | "llamacpp" | "vllm" | "openai" | "azure-openai" | "openrouter" | "groq" | "mistral" | "deepseek" | "together" | "fireworks" | "xai" | undefined;
385
+ protocol?: "openai-compatible" | "anthropic" | "gemini" | "ollama" | "claude-code" | undefined;
386
+ baseUrl?: string | undefined;
387
+ model?: string | undefined;
388
+ contextTokens?: number | undefined;
389
+ apiKeyEnv?: string | undefined;
390
+ auth?: "bearer" | "x-api-key" | "none" | "inherit" | "login" | "api-key" | {
391
+ header: string;
392
+ prefix?: string | undefined;
393
+ } | undefined;
394
+ headers?: Record<string, string> | undefined;
395
+ query?: Record<string, string> | undefined;
396
+ extraBody?: Record<string, z.core.util.JSONType> | undefined;
397
+ structuredOutput?: "prompt" | "json" | "schema" | undefined;
398
+ temperature?: number | null | undefined;
399
+ maxTokens?: number | undefined;
400
+ maxTokensField?: "max_tokens" | "max_completion_tokens" | undefined;
401
+ systemPrompt?: "native" | "inline" | undefined;
402
+ timeoutMs?: number | undefined;
403
+ retries?: number | undefined;
404
+ args?: string[] | undefined;
405
+ }>, z.ZodObject<{
276
406
  apiKey: z.ZodOptional<z.ZodString>;
277
407
  command: z.ZodOptional<z.ZodString>;
278
408
  preset: z.ZodOptional<z.ZodEnum<{
@@ -333,14 +463,19 @@ export declare const configInputSchema: z.ZodObject<{
333
463
  native: "native";
334
464
  inline: "inline";
335
465
  }>>;
466
+ timeoutMs: z.ZodOptional<z.ZodInt>;
467
+ retries: z.ZodOptional<z.ZodInt>;
336
468
  args: z.ZodOptional<z.ZodArray<z.ZodString>>;
337
- }, z.core.$strict>]>>>;
469
+ }, z.core.$strict>>]>>>;
338
470
  roles: z.ZodOptional<z.ZodObject<{
339
471
  research: z.ZodOptional<z.ZodString>;
340
472
  voter: z.ZodOptional<z.ZodString>;
341
473
  }, z.core.$strict>>;
342
474
  concurrency: z.ZodOptional<z.ZodInt>;
343
475
  maxFindings: z.ZodOptional<z.ZodInt>;
476
+ maxReviewTokens: z.ZodOptional<z.ZodInt>;
477
+ reviewTimeoutMs: z.ZodOptional<z.ZodInt>;
478
+ exclude: z.ZodOptional<z.ZodArray<z.ZodString>>;
344
479
  profiles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
345
480
  extends: z.ZodOptional<z.ZodEnum<{
346
481
  [x: string]: string;
@@ -439,3 +574,4 @@ export declare function parseConfig<T>(schema: z.ZodType<T>, value: unknown, pre
439
574
  * secret pasted in the wrong place.
440
575
  */
441
576
  export declare function unknownName(path: string, kind: 'provider' | 'profile', name: string, defined: readonly string[]): ConfigIssue;
577
+ export {};
@@ -1,5 +1,8 @@
1
1
  import { z } from 'zod';
2
2
  import { ConfigError, isSafeSegment, issuePath } from "../core/errors.js";
3
+ import { MAX_PATTERNS, patternProblem, TOO_MANY_PATTERNS } from "../core/exclude.js";
4
+ import { MAX_RETRIES, MAX_STATED_TIMEOUT_MS, MAX_TIMEOUT_MS, MIN_TIMEOUT_MS, retriesProblem, timeoutProblem } from "../core/ports.js";
5
+ import { ownData } from "../core/stages/context.js";
3
6
  import { securityProfile } from "../profiles/security.js";
4
7
  import { wordList } from "../providers/options.js";
5
8
  import { presets, withoutPrototype } from "../providers/presets.js";
@@ -19,6 +22,12 @@ const PROTOCOLS = {
19
22
  const STRUCTURED_OUTPUTS = { prompt: true, json: true, schema: true };
20
23
  const VERSION = 'must be 1, the only config version this quorum reads: upgrade quorum to read a later one';
21
24
  const name = z.string().regex(NAME);
25
+ /** A path pattern of `exclude`, refused in the words `createQuorum` uses, since both ask `patternProblem`. */
26
+ const pattern = z.string().check((ctx) => {
27
+ const problem = patternProblem(ctx.value);
28
+ if (problem !== undefined)
29
+ ctx.issues.push({ code: 'custom', message: problem, input: ctx.value });
30
+ });
22
31
  const roles = z.strictObject({
23
32
  research: name.optional().describe('The provider that looks for candidate findings'),
24
33
  voter: name.optional().describe('The provider every lens votes with, unless the lens names its own'),
@@ -51,9 +60,11 @@ const providerShape = {
51
60
  extraBody: z.record(z.string(), z.json()).optional().describe('JSON values deep-merged into the request body last'),
52
61
  structuredOutput: z.enum(Object.keys(STRUCTURED_OUTPUTS)).optional().describe('How the reply shape reaches the endpoint: described in the prompt, as a JSON object, or as a strict schema'),
53
62
  temperature: z.number().nullable().optional().describe('The sampling temperature; null leaves the field out'),
54
- maxTokens: z.int().min(1).optional().describe('The most tokens the reply may hold'),
63
+ maxTokens: z.int().min(1).optional().describe('The most tokens the reply may hold, thinking included, sent as the server\'s limit; 16000 when unset. On claude-code, Claude Code\'s own limit on each reply'),
55
64
  maxTokensField: z.enum(['max_tokens', 'max_completion_tokens']).optional().describe('The body field that carries maxTokens, on the openai-compatible protocol'),
56
65
  systemPrompt: z.enum(['native', 'inline']).optional().describe('Where the instructions go: the protocol\'s system field, or inline in the first message'),
66
+ timeoutMs: z.int().min(MIN_TIMEOUT_MS).max(MAX_TIMEOUT_MS).optional().describe('The deadline of one attempt of a call, in milliseconds; 600000 when unset. On claude-code, Claude Code\'s wait for each attempt\'s response headers, and the whole run\'s deadline is timeoutMs times retries plus one'),
67
+ retries: z.int().min(0).max(MAX_RETRIES).optional().describe('How many times a call that failed in passing is tried again; 2 when unset'),
57
68
  args: z.array(z.string()).optional().describe('On claude-code, extra claude flags, each with its value: --effort, --fallback-model, --max-budget-usd, or --betas with auth api-key'),
58
69
  };
59
70
  const prompt = z.union([
@@ -103,6 +114,9 @@ function configSchema(provider, promptForm) {
103
114
  roles: roles.optional().describe('The providers every profile uses, unless it names its own. research is required once several providers are defined; voter is research when unset'),
104
115
  concurrency: z.int().min(1).optional().describe('The most provider calls in flight at once in one review, shared by every profile'),
105
116
  maxFindings: z.int().min(1).optional().describe('The most findings of a research reply each profile reads, the only ones that can reach its panel'),
117
+ maxReviewTokens: z.int().min(1).optional().describe('The most tokens, input and output, one review may spend; 2000000 when unset. Set here or in QUORUM_MAX_REVIEW_TOKENS'),
118
+ reviewTimeoutMs: z.int().min(MIN_TIMEOUT_MS).max(MAX_TIMEOUT_MS).optional().describe('The deadline of one review, in milliseconds; 1800000 when unset. Set here or in QUORUM_REVIEW_TIMEOUT_MS'),
119
+ exclude: z.array(pattern.describe('A path pattern: * and ? within a name, ** for whole directories, no / to match a file name in any directory, a leading / for the root')).max(MAX_PATTERNS, { error: TOO_MANY_PATTERNS }).optional().describe('The files left out of every request, by path pattern, each listed as excluded in meta.leftOut; nothing is excluded by default'),
106
120
  profiles: z.record(name, profileSchema(promptForm)).optional().describe('The review profiles, by id: a built-in profile, one that extends it, or one of your own. The ones --profile names run, else the ones QUORUM_PROFILES names, else every one listed here, else the security profile alone'),
107
121
  });
108
122
  }
@@ -112,9 +126,54 @@ export function isProvider(value) {
112
126
  }
113
127
  /** The snapshots the schema made of provider objects, recognised by identity: a settings object is never taken for one, whatever its prototype holds. */
114
128
  const SNAPSHOTS = new WeakSet();
115
- /** A provider object as a snapshot: its fields as plain data, frozen, with no prototype. */
116
- function snapshot(fields) {
117
- const made = Object.freeze(withoutPrototype(Object.entries(fields)));
129
+ /** Each fact a provider states, with the check of its value: a deadline up to what a provider may state, which is more than an option takes. */
130
+ const FACTS = [
131
+ {
132
+ field: 'timeoutMs',
133
+ problem: value => timeoutProblem(value, MAX_STATED_TIMEOUT_MS),
134
+ },
135
+ { field: 'retries', problem: retriesProblem },
136
+ ];
137
+ /**
138
+ * The facts `provider` states, each read as own data, so a getter never runs and an inherited property
139
+ * or a proxy that throws states nothing: `stated` holds those that pass their check, and `problems` the
140
+ * field and wording of each that does not. A value is never quoted.
141
+ */
142
+ export function statedFacts(provider) {
143
+ // No prototype, so a reader of `stated` never finds a fact on `Object.prototype`.
144
+ const stated = Object.create(null);
145
+ const problems = [];
146
+ for (const { field, problem } of FACTS) {
147
+ const value = ownData(provider, field);
148
+ if (value === undefined)
149
+ continue;
150
+ const message = problem(value);
151
+ if (message === undefined)
152
+ stated[field] = value;
153
+ else
154
+ problems.push({ field, message });
155
+ }
156
+ return { stated, problems };
157
+ }
158
+ /**
159
+ * The `worstCase` a provider states, as own data: a function, else undefined. It is no fact of `FACTS`: a
160
+ * function is no number to check or to hash, so the fingerprint and the printed config never see it, and a
161
+ * value that is no function is an issue of `providerObject` and is never read here.
162
+ */
163
+ export function statedWorstCase(provider) {
164
+ const worstCase = ownData(provider, 'worstCase');
165
+ return typeof worstCase === 'function'
166
+ ? worstCase
167
+ : undefined;
168
+ }
169
+ /** A provider object as a snapshot: its fields as plain data, frozen, with no prototype. A `worstCase` it states is kept as a field, and one it does not state leaves no field. */
170
+ function snapshot({ worstCase, ...fields }) {
171
+ const made = Object.freeze(withoutPrototype(Object.entries({
172
+ ...fields,
173
+ ...worstCase === undefined
174
+ ? {}
175
+ : { worstCase },
176
+ })));
118
177
  SNAPSHOTS.add(made);
119
178
  return made;
120
179
  }
@@ -122,7 +181,11 @@ function snapshot(fields) {
122
181
  * The provider-object form of a code config's provider: an object whose `complete` is a function, read once
123
182
  * into a snapshot. The check reads `model` and `complete` one time each, and nothing reads the object again,
124
183
  * so a getter of the program's cannot run outside the guard that hides what it throws. The snapshot calls the
125
- * method read here on the object itself, through `Reflect.apply`, which reads nothing off the function.
184
+ * method read here on the object itself, through `Reflect.apply`, which reads nothing off the function. The
185
+ * `timeoutMs` and `retries` it states are read as own data, so no getter runs for them; the snapshot keeps
186
+ * each that is in range, and a value out of range is an issue at its field. The `worstCase` it states is read
187
+ * as own data too and kept as a function that calls it on the object, so the review's token cap counts
188
+ * what the object says one call may cost; a value that is no function is an issue at its field.
126
189
  */
127
190
  const providerObject = z.custom(value => typeof value === 'object' && value !== null).transform((object, ctx) => {
128
191
  const { model, complete } = object;
@@ -130,20 +193,55 @@ const providerObject = z.custom(value => typeof value === 'object' && value !==
130
193
  ctx.issues.push({ code: 'custom', message: 'complete is not a function', input: object });
131
194
  return z.NEVER;
132
195
  }
196
+ const { stated, problems } = statedFacts(object);
197
+ const worstCase = ownData(object, 'worstCase');
198
+ const issues = [
199
+ ...problems,
200
+ ...worstCase === undefined || typeof worstCase === 'function'
201
+ ? []
202
+ : [
203
+ { field: 'worstCase', message: 'must be a function' },
204
+ ],
205
+ ];
206
+ // `continue` keeps the union from setting this form aside as aborted: the object took its shape, so its issues are the ones reported.
207
+ for (const { field, message } of issues) {
208
+ ctx.issues.push({
209
+ code: 'custom',
210
+ message,
211
+ input: object,
212
+ path: [field],
213
+ continue: true,
214
+ });
215
+ }
216
+ if (issues.length > 0)
217
+ return z.NEVER;
133
218
  return snapshot({
134
219
  model,
135
220
  complete: request => Reflect.apply(complete, object, [request]),
221
+ ...stated,
222
+ ...typeof worstCase === 'function'
223
+ ? {
224
+ worstCase: (request) => Reflect.apply(worstCase, object, [request]),
225
+ }
226
+ : {},
136
227
  });
137
228
  });
138
229
  /**
139
230
  * `entry` named `id`, the config's key for it, when it is a snapshot the schema made of a provider object: a
140
- * copy that holds `id` as well, built from the snapshot's own data. Anything else is returned as it is.
231
+ * copy that holds `id` as well, built from the snapshot's own data, the facts and the `worstCase` it states
232
+ * included. Anything else is returned as it is.
141
233
  */
142
234
  export function nameSnapshot(id, entry) {
143
235
  if (typeof entry !== 'object' || entry === null || !SNAPSHOTS.has(entry))
144
236
  return entry;
145
237
  const { model, complete } = entry;
146
- return snapshot({ id, model, complete });
238
+ return snapshot({
239
+ id,
240
+ model,
241
+ complete,
242
+ ...statedFacts(entry).stated,
243
+ worstCase: statedWorstCase(entry),
244
+ });
147
245
  }
148
246
  /**
149
247
  * A YAML or JSON config: data only, so a provider names the variable that holds its key and never holds
@@ -151,14 +249,29 @@ export function nameSnapshot(id, entry) {
151
249
  * fill is optional, and the references between fields are checked once the layers are merged.
152
250
  */
153
251
  export const configFileSchema = configSchema(z.strictObject(providerShape), prompt);
252
+ /** The settings of a provider in a code config: those of a file, which may also hold the key itself and the executable. */
253
+ const codeSettings = z.strictObject({
254
+ ...providerShape,
255
+ apiKey: z.string().optional().describe('The key itself, which only a code config may hold'),
256
+ command: z.string().optional().describe('On claude-code, the claude executable: an absolute path, or a name found on PATH; only a code config may name it'),
257
+ });
258
+ /**
259
+ * Whether `value` may be the settings of a provider: anything but an object that holds a `complete`, unless
260
+ * that is plain data and no function, which the settings form reports as a field it does not know. An object
261
+ * that holds one is a provider object, read once, by `providerObject` alone; the settings form reads every
262
+ * field it knows through the object, a getter's included, so it is never offered one. Only the key and its
263
+ * descriptor are looked at here, so no getter of the object runs.
264
+ */
265
+ function isSettings(value) {
266
+ if (typeof value !== 'object' || value === null || !('complete' in value))
267
+ return true;
268
+ const descriptor = Object.getOwnPropertyDescriptor(value, 'complete');
269
+ return descriptor !== undefined && Object.hasOwn(descriptor, 'value') && typeof descriptor.value !== 'function';
270
+ }
154
271
  /** What a code config may hold as a provider: settings that may hold their key, or an object implementing `Provider`. */
155
272
  const codeProvider = z.union([
156
273
  providerObject,
157
- z.strictObject({
158
- ...providerShape,
159
- apiKey: z.string().optional().describe('The key itself, which only a code config may hold'),
160
- command: z.string().optional().describe('On claude-code, the claude executable: an absolute path, or a name found on PATH; only a code config may name it'),
161
- }),
274
+ z.custom(isSettings).pipe(codeSettings),
162
275
  ], { error: 'must be the settings of a provider, or an object whose complete is a function' });
163
276
  /** A TS or JS config: the file variant, where a provider may also hold its key, or be an object implementing `Provider`. */
164
277
  export const configCodeSchema = configSchema(codeProvider, prompt);
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The time and the randomness the core reads, and the one timer it arms: the system's, unless a spec
3
+ * injects its own. The review holds it in its context and nothing outside the core sets it.
4
+ */
5
+ export interface Clock {
6
+ /** Milliseconds on a monotonic clock, from an origin of its own: only the difference of two readings means anything. */
7
+ readonly now: () => number;
8
+ /** A number from 0 up to, and not including, 1. */
9
+ readonly random: () => number;
10
+ /** Calls `fire` once, after `ms` milliseconds; returns the function that cancels it, which may be called at any time and any number of times. */
11
+ readonly timer: (ms: number, fire: () => void) => () => void;
12
+ }
13
+ /**
14
+ * The system's clock. Each reading goes through a function that reads the global at the call, never a
15
+ * reference taken when the module loads, so a spec that replaces `Math.random` is seen.
16
+ */
17
+ export declare const systemClock: Clock;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The system's clock. Each reading goes through a function that reads the global at the call, never a
3
+ * reference taken when the module loads, so a spec that replaces `Math.random` is seen.
4
+ */
5
+ export const systemClock = Object.freeze({
6
+ now: () => performance.now(),
7
+ random: () => Math.random(),
8
+ timer: (ms, fire) => {
9
+ const handle = setTimeout(fire, ms);
10
+ return () => {
11
+ clearTimeout(handle);
12
+ };
13
+ },
14
+ });
@@ -0,0 +1,49 @@
1
+ import type { IncompleteEntry, LeftOutFile } from './types.ts';
2
+ /** What a review covers of a diff: the diff every stage reads, and the files it leaves out. */
3
+ export interface ReviewScope {
4
+ /** The diff every stage reads: the given one less the excluded sections. */
5
+ readonly diff: string;
6
+ /** The files left out, excluded or with a change the diff does not carry, in the diff's order, once per file and reason. */
7
+ readonly leftOut: LeftOutFile[];
8
+ }
9
+ /**
10
+ * What a review covers of a diff: the files `excluded` leaves out, and the files whose change the
11
+ * diff does not carry, found from the markers git prints in their place, each section read line by
12
+ * line (a trailing `\r` is dropped), so a Windows-made diff reads as any other. In each section:
13
+ * - a `binary` file shows as a line that starts with `Binary files ` and ends with ` differ`, or one
14
+ * that starts with `GIT binary patch`;
15
+ * - a `submodule` shows as a `Subproject commit` row (past at most one leading `+`, `-` or space), a
16
+ * header of mode 160000 (`new file mode`, `deleted file mode`, `old mode` and `new mode`), or an
17
+ * `index` line that ends in ` 160000`;
18
+ * - a `Submodule` line, which git's `log` and `diff` formats print in place of a header, at the end of
19
+ * the section before it, lists a `submodule` under the empty name, whatever section holds it.
20
+ *
21
+ * A file is listed by the diff's own path, decoded, in the diff's order, once per file and reason.
22
+ * `excluded` is asked once per distinct path a header names; a section it takes is listed as
23
+ * `excluded`, leaves the scope's `diff` and has its own markers left unread, but its `Submodule`
24
+ * lines still list their submodule, since such a line belongs to no section. Nothing a header does
25
+ * not name is ever excluded: the text before the first header, a diff without such headers and a
26
+ * header that names no path quorum reads.
27
+ *
28
+ * A header can read two ways: git does not quote a path that holds a space, so a rename's header
29
+ * (`a/src/auth.js b/src/x b/dist/auth.js`) can name a path the file does not have. A section is
30
+ * therefore excluded only when every `rename to` and `copy to` line it holds names the header's
31
+ * path, as `movedTo` reads them; otherwise it is kept, as a header quorum cannot read is, its markers
32
+ * read and its text sent. A forged line, such as a `format-patch` series carries in the next mail's
33
+ * message, can then only make quorum exclude less. That next mail's headers and message sit at the
34
+ * end of the previous file's section and leave with it when that file is excluded: no code hides
35
+ * there, since `git am` applies only the patch sections, and a `Submodule` line still counts.
36
+ *
37
+ * The empty name stands for a part of the diff that no `diff --git` header names: the text before the
38
+ * first header, a diff without such headers, a header that names no path quorum reads, and a
39
+ * `Submodule` line. A readable header never names the empty path, so it is never a file's.
40
+ *
41
+ * Detection is generous: a line of the same form elsewhere, such as a commit message line of a
42
+ * `format-patch` series, lists the file whose section holds it, since a gap it should not have stops a
43
+ * review for a person to look, where a missed one would pass a change unread. The scope's `diff` is
44
+ * the given string itself when no section was excluded, the kept sections joined by line feeds when
45
+ * some were, and '' when every section was.
46
+ */
47
+ export declare function reviewScope(diff: string, excluded?: (path: string) => boolean): ReviewScope;
48
+ /** The gaps the files left out make for one profile: one per reason, binary then submodule, counting its files, and none for a reason with no file. */
49
+ export declare function leftOutGaps(profile: string, leftOut: readonly LeftOutFile[]): IncompleteEntry[];