@tobi-or-not/quorum 0.4.0 → 0.6.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 (111) hide show
  1. package/README.md +3 -1
  2. package/dist/bench/fingerprint.d.ts +8 -5
  3. package/dist/bench/fingerprint.js +28 -9
  4. package/dist/bench/records.d.ts +168 -0
  5. package/dist/bench/records.js +106 -1
  6. package/dist/bench/runner.d.ts +18 -0
  7. package/dist/bench/runner.js +30 -4
  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/io.d.ts +5 -0
  12. package/dist/cli/main.d.ts +67 -24
  13. package/dist/cli/main.js +288 -59
  14. package/dist/cli/print-config.d.ts +8 -6
  15. package/dist/cli/print-config.js +26 -8
  16. package/dist/cli/render.d.ts +9 -3
  17. package/dist/cli/render.js +43 -2
  18. package/dist/config/claude-code.d.ts +2 -6
  19. package/dist/config/claude-code.js +6 -44
  20. package/dist/config/command.d.ts +10 -0
  21. package/dist/config/command.js +47 -0
  22. package/dist/config/env.d.ts +32 -19
  23. package/dist/config/env.js +95 -32
  24. package/dist/config/from-config.js +21 -3
  25. package/dist/config/resolve.d.ts +13 -1
  26. package/dist/config/resolve.js +27 -1
  27. package/dist/config/schema.d.ts +152 -5
  28. package/dist/config/schema.js +156 -12
  29. package/dist/core/clock.d.ts +17 -0
  30. package/dist/core/clock.js +14 -0
  31. package/dist/core/coverage.d.ts +74 -0
  32. package/dist/core/coverage.js +221 -0
  33. package/dist/core/diff.d.ts +101 -0
  34. package/dist/core/diff.js +178 -35
  35. package/dist/core/errors.d.ts +12 -3
  36. package/dist/core/errors.js +21 -2
  37. package/dist/core/estimate.d.ts +45 -0
  38. package/dist/core/estimate.js +188 -0
  39. package/dist/core/exclude.d.ts +42 -0
  40. package/dist/core/exclude.js +189 -0
  41. package/dist/core/flags.d.ts +14 -1
  42. package/dist/core/flags.js +56 -0
  43. package/dist/core/inputs.d.ts +38 -0
  44. package/dist/core/inputs.js +228 -0
  45. package/dist/core/limits.d.ts +83 -0
  46. package/dist/core/limits.js +169 -0
  47. package/dist/core/output.d.ts +3 -2
  48. package/dist/core/output.js +3 -2
  49. package/dist/core/parts.d.ts +146 -0
  50. package/dist/core/parts.js +388 -0
  51. package/dist/core/ports.d.ts +67 -2
  52. package/dist/core/ports.js +36 -1
  53. package/dist/core/prompts.d.ts +22 -3
  54. package/dist/core/prompts.js +43 -7
  55. package/dist/core/quorum.d.ts +26 -8
  56. package/dist/core/quorum.js +310 -73
  57. package/dist/core/retry.d.ts +36 -0
  58. package/dist/core/retry.js +46 -0
  59. package/dist/core/secrets.d.ts +98 -0
  60. package/dist/core/secrets.js +507 -0
  61. package/dist/core/stages/context.d.ts +131 -23
  62. package/dist/core/stages/context.js +331 -46
  63. package/dist/core/stages/panel.d.ts +13 -6
  64. package/dist/core/stages/panel.js +79 -19
  65. package/dist/core/stages/research.d.ts +110 -25
  66. package/dist/core/stages/research.js +338 -44
  67. package/dist/core/tokens.d.ts +31 -0
  68. package/dist/core/tokens.js +81 -0
  69. package/dist/core/types.d.ts +280 -25
  70. package/dist/core/verify.d.ts +6 -0
  71. package/dist/core/verify.js +6 -3
  72. package/dist/git/run.d.ts +223 -0
  73. package/dist/git/run.js +608 -0
  74. package/dist/git/tree.d.ts +43 -0
  75. package/dist/git/tree.js +171 -0
  76. package/dist/index.d.ts +26 -2
  77. package/dist/index.js +34 -2
  78. package/dist/providers/anthropic.d.ts +3 -1
  79. package/dist/providers/anthropic.js +10 -3
  80. package/dist/providers/claude-code.d.ts +56 -11
  81. package/dist/providers/claude-code.js +70 -25
  82. package/dist/providers/gemini.d.ts +5 -1
  83. package/dist/providers/gemini.js +65 -11
  84. package/dist/providers/http.d.ts +49 -4
  85. package/dist/providers/http.js +155 -14
  86. package/dist/providers/ollama.d.ts +4 -1
  87. package/dist/providers/ollama.js +13 -5
  88. package/dist/providers/openai-compatible.d.ts +4 -1
  89. package/dist/providers/openai-compatible.js +13 -5
  90. package/dist/providers/options.d.ts +12 -3
  91. package/dist/providers/options.js +30 -10
  92. package/dist/providers/size.d.ts +19 -15
  93. package/dist/providers/size.js +33 -73
  94. package/dist/sources/added.d.ts +49 -0
  95. package/dist/sources/added.js +134 -0
  96. package/dist/sources/diff.d.ts +13 -0
  97. package/dist/sources/diff.js +63 -0
  98. package/dist/sources/local.d.ts +41 -0
  99. package/dist/sources/local.js +251 -0
  100. package/dist/sources/paths.d.ts +45 -0
  101. package/dist/sources/paths.js +230 -0
  102. package/dist/sources/range.d.ts +21 -0
  103. package/dist/sources/range.js +75 -0
  104. package/dist/sources/read.d.ts +69 -0
  105. package/dist/sources/read.js +37 -0
  106. package/dist/sources/repository.d.ts +9 -0
  107. package/dist/sources/repository.js +28 -0
  108. package/dist/sources/skips.d.ts +49 -0
  109. package/dist/sources/skips.js +126 -0
  110. package/package.json +1 -1
  111. package/schema/quorum.schema.json +49 -1
@@ -9,8 +9,8 @@ import { presetOf } from "../providers/presets.js";
9
9
  * are the CLI's progress output on stderr, so a person follows a run without the full event stream.
10
10
  * Each line passes through `inertLine` whole: the reasons, details and file names it carries come
11
11
  * from the finder or the diff, and nothing in them can act on a terminal or a CI log. When `prefixed`,
12
- * a line of an event that names a profile starts with `[<profile>] `: the `flag:` and totals lines
13
- * belong to the whole review and never do.
12
+ * a line of an event that names a profile starts with `[<profile>] `: the `left out:`, `flag:` and totals
13
+ * lines belong to the whole review and never do.
14
14
  */
15
15
  export function renderEvent(event, prefixed = false) {
16
16
  const line = progressLine(event, prefixed);
@@ -19,6 +19,8 @@ export function renderEvent(event, prefixed = false) {
19
19
  : inertLine(line);
20
20
  }
21
21
  const profilePrefix = (profile) => `[${profile}] `;
22
+ /** How many of the files left out the progress line names; the JSON result lists every one. */
23
+ const LISTED_FILES = 5;
22
24
  function progressLine(event, prefixed) {
23
25
  const of = (profile, line) => prefixed
24
26
  ? `${profilePrefix(profile)}${line}`
@@ -32,6 +34,8 @@ function progressLine(event, prefixed) {
32
34
  return of(event.profile, `invalid finding dropped: ${event.reason}`);
33
35
  case 'incomplete':
34
36
  return of(event.entry.profile, `incomplete: ${event.entry.reason} (${event.entry.detail})`);
37
+ case 'left-out':
38
+ return leftOutLine(event.files);
35
39
  case 'flag':
36
40
  return `flag: ${event.flag.code}${where(event.flag)} (${event.flag.detail})`;
37
41
  case 'run:end':
@@ -40,6 +44,25 @@ function progressLine(event, prefixed) {
40
44
  return undefined;
41
45
  }
42
46
  }
47
+ /**
48
+ * The line that names the files a review left out: their count, the first `LISTED_FILES` of them as
49
+ * `<file> (<reason>)`, a skipped or a held one as `<file> (<reason>: <rule>)`, then how many more. A file is
50
+ * a JSON string, as a flag's is; the empty name, which stands for a part of the diff no header names, is
51
+ * `<no path>`.
52
+ */
53
+ function leftOutLine(files) {
54
+ const named = (file) => file === ''
55
+ ? '<no path>'
56
+ : JSON.stringify(file);
57
+ const reasonOf = (entry) => 'rule' in entry
58
+ ? `${entry.reason}: ${entry.rule}`
59
+ : entry.reason;
60
+ const entries = files.slice(0, LISTED_FILES).map(entry => `${named(entry.file)} (${reasonOf(entry)})`);
61
+ const more = files.length > LISTED_FILES
62
+ ? ` and ${files.length - LISTED_FILES} more`
63
+ : '';
64
+ return `left out: ${files.length} file(s): ${entries.join(', ')}${more}`;
65
+ }
43
66
  /** Where a flag points: the file as a JSON string, with the line when it has one, else the line alone. */
44
67
  function where({ file, line }) {
45
68
  if (file !== undefined && line !== undefined)
@@ -65,6 +88,24 @@ export function progressSink(write) {
65
88
  write(line);
66
89
  };
67
90
  }
91
+ /**
92
+ * The lines a path review prints once its estimate is made, before any call: one per profile, starting with
93
+ * `[<id>] ` when several run, then the total, which belongs to the whole review and is never prefixed. The
94
+ * expected figure is the research's alone, as the votes are in the worst case only. Each line is inert.
95
+ */
96
+ export function estimateLines(estimate) {
97
+ const entries = Object.entries(estimate.profiles);
98
+ const prefixed = entries.length > 1;
99
+ return [
100
+ ...entries.map(([id, { parts, expected, votes, worst }]) => {
101
+ const prefix = prefixed
102
+ ? profilePrefix(id)
103
+ : '';
104
+ return `${prefix}estimate: ${parts.length} research part(s), about ${expected} tokens expected for them; then up to ${votes} vote(s), at most ${worst} tokens in all`;
105
+ }),
106
+ `estimate: research about ${estimate.expected} tokens expected, at most ${estimate.worst} with every vote, ${estimate.inFlight} of them reserved at once; the review's token cap is ${estimate.maxReviewTokens} and its deadline ${estimate.reviewTimeoutMs} ms`,
107
+ ].map(inertLine);
108
+ }
68
109
  /**
69
110
  * The origin of a provider defined as data, as the banner and `--print-config` name its endpoint: the
70
111
  * scheme, host and port of its own base URL, else of its preset's. Both are read as own fields, so a
@@ -10,12 +10,8 @@ import type { ProviderSettings } from './schema.ts';
10
10
  /** The issue of a provider whose command is neither set nor on `PATH`. */
11
11
  export declare const CLAUDE_NOT_FOUND = "claude CLI not found; install Claude Code or set QUORUM_CLAUDE_CODE_COMMAND";
12
12
  /**
13
- * The executable `command` names: an absolute path as it is, a bare name in the first absolute entry of the
14
- * environment's `PATH` that holds it (`;` separates the entries on Windows, `:` elsewhere, and a name with no
15
- * extension is looked up as `<name>.exe` there). A match is a regular file the process may run; any file
16
- * system error is no match. Never reads a relative entry, and never a variable the environment only inherits.
17
- * A command the adapter refuses (a relative path with a separator, which would climb out of an entry, or a
18
- * Windows script) names no executable.
13
+ * The executable `command` names (`findExecutable`), unless the adapter refuses the command first: a relative
14
+ * path with a separator, which would climb out of an entry, or a Windows script names no executable.
19
15
  */
20
16
  export declare function findCommand(command: string, env: Env, platform?: NodeJS.Platform): string | undefined;
21
17
  /** What a provider's command comes to: the executable it runs, or the issues that say why there is none. */
@@ -1,6 +1,5 @@
1
- import { accessSync, constants, statSync } from 'node:fs';
2
- import { extname, isAbsolute, join } from 'node:path';
3
1
  import { commandProblem } from "../providers/claude-code.js";
2
+ import { findExecutable } from "./command.js";
4
3
  import { CLAUDE_CODE_COMMAND, envValue } from "./env.js";
5
4
  import { own } from "./profiles.js";
6
5
  import { configPath } from "./schema.js";
@@ -14,51 +13,14 @@ import { configPath } from "./schema.js";
14
13
  export const CLAUDE_NOT_FOUND = `claude CLI not found; install Claude Code or set ${CLAUDE_CODE_COMMAND}`;
15
14
  const NO_EXECUTABLE = 'names no executable file';
16
15
  const DEFAULT_COMMAND = 'claude';
17
- /** Whether `path` names a regular file the process may run; on Windows no file has an execute bit, so a regular file is enough. Any file system error is no. */
18
- function isExecutableFile(path, platform) {
19
- try {
20
- if (!statSync(path).isFile())
21
- return false;
22
- if (platform !== 'win32')
23
- accessSync(path, constants.X_OK);
24
- return true;
25
- }
26
- catch {
27
- return false;
28
- }
29
- }
30
- /** The `PATH` of the environment: its own variable, in the letter case Windows gives its name, else undefined. */
31
- function searchPath(env, platform) {
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);
38
- }
39
16
  /**
40
- * The executable `command` names: an absolute path as it is, a bare name in the first absolute entry of the
41
- * environment's `PATH` that holds it (`;` separates the entries on Windows, `:` elsewhere, and a name with no
42
- * extension is looked up as `<name>.exe` there). A match is a regular file the process may run; any file
43
- * system error is no match. Never reads a relative entry, and never a variable the environment only inherits.
44
- * A command the adapter refuses (a relative path with a separator, which would climb out of an entry, or a
45
- * Windows script) names no executable.
17
+ * The executable `command` names (`findExecutable`), unless the adapter refuses the command first: a relative
18
+ * path with a separator, which would climb out of an entry, or a Windows script names no executable.
46
19
  */
47
20
  export function findCommand(command, env, platform = process.platform) {
48
- if (commandProblem(command) !== undefined)
49
- return undefined;
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));
61
- return entries.map(entry => join(entry, file)).find(candidate => isExecutableFile(candidate, platform));
21
+ return commandProblem(command) === undefined
22
+ ? findExecutable(command, env, platform)
23
+ : undefined;
62
24
  }
63
25
  /**
64
26
  * The command of a `claude-code` provider in use: `variable` (`QUORUM_CLAUDE_CODE_COMMAND`, already checked),
@@ -0,0 +1,10 @@
1
+ import type { Env } from './env.ts';
2
+ /**
3
+ * The executable `command` names: an absolute path as it is, a bare name in the first absolute entry of the
4
+ * environment's `PATH` that holds it (`;` separates the entries on Windows, `:` elsewhere, and a name with no
5
+ * extension is looked up as `<name>.exe` there). A match is a regular file the process may run; any file
6
+ * system error is no match. Never reads a relative entry, and never a variable the environment only inherits.
7
+ * It takes the command as it is given: a caller whose command a user wrote refuses a relative path with a
8
+ * separator, which would climb out of an entry, before it gets here (`findCommand` does).
9
+ */
10
+ export declare function findExecutable(command: string, env: Env, platform: NodeJS.Platform): string | undefined;
@@ -0,0 +1,47 @@
1
+ import { accessSync, constants, statSync } from 'node:fs';
2
+ import { extname, isAbsolute, join } from 'node:path';
3
+ import { envValue } from "./env.js";
4
+ /** Whether `path` names a regular file the process may run; on Windows no file has an execute bit, so a regular file is enough. Any file system error is no. */
5
+ function isExecutableFile(path, platform) {
6
+ try {
7
+ if (!statSync(path).isFile())
8
+ return false;
9
+ if (platform !== 'win32')
10
+ accessSync(path, constants.X_OK);
11
+ return true;
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ }
17
+ /** The `PATH` of the environment: its own variable, in the letter case Windows gives its name, else undefined. */
18
+ function searchPath(env, platform) {
19
+ const name = platform === 'win32'
20
+ ? Object.keys(env).find(key => key.toUpperCase() === 'PATH')
21
+ : 'PATH';
22
+ return name === undefined
23
+ ? undefined
24
+ : envValue(env, name);
25
+ }
26
+ /**
27
+ * The executable `command` names: an absolute path as it is, a bare name in the first absolute entry of the
28
+ * environment's `PATH` that holds it (`;` separates the entries on Windows, `:` elsewhere, and a name with no
29
+ * extension is looked up as `<name>.exe` there). A match is a regular file the process may run; any file
30
+ * system error is no match. Never reads a relative entry, and never a variable the environment only inherits.
31
+ * It takes the command as it is given: a caller whose command a user wrote refuses a relative path with a
32
+ * separator, which would climb out of an entry, before it gets here (`findCommand` does).
33
+ */
34
+ export function findExecutable(command, env, platform) {
35
+ if (isAbsolute(command)) {
36
+ return isExecutableFile(command, platform)
37
+ ? command
38
+ : undefined;
39
+ }
40
+ const file = platform === 'win32' && extname(command) === ''
41
+ ? `${command}.exe`
42
+ : command;
43
+ const entries = (searchPath(env, platform) ?? '').split(platform === 'win32'
44
+ ? ';'
45
+ : ':').filter(entry => isAbsolute(entry));
46
+ return entries.map(entry => join(entry, file)).find(candidate => isExecutableFile(candidate, platform));
47
+ }
@@ -8,13 +8,18 @@ export type Env = Readonly<Record<string, string | undefined>>;
8
8
  * not break a key. A blank variable is unset, and so is one the environment only inherits from its prototype.
9
9
  */
10
10
  export declare function envValue(env: Env, name: string): string | undefined;
11
- /** What the variables of one role set: only the variables that are set. `contextTokens` is `QUORUM_<ROLE>_CONTEXT_TOKENS`, read as a whole number. */
11
+ /**
12
+ * What the variables of one role set: only the variables that are set. `contextTokens`, `timeoutMs` and
13
+ * `retries` are `QUORUM_<ROLE>_CONTEXT_TOKENS`, `_TIMEOUT_MS` and `_RETRIES`, each read as a whole number.
14
+ */
12
15
  export interface RoleOverrides {
13
16
  readonly preset?: string;
14
17
  readonly protocol?: string;
15
18
  readonly baseUrl?: string;
16
19
  readonly model?: string;
17
20
  readonly contextTokens?: number;
21
+ readonly timeoutMs?: number;
22
+ readonly retries?: number;
18
23
  readonly apiKey?: string;
19
24
  }
20
25
  /** What the environment holds for the config layer. */
@@ -25,6 +30,10 @@ export interface EnvLayer {
25
30
  readonly voter: RoleOverrides;
26
31
  /** `QUORUM_CLAUDE_CODE_COMMAND`, trimmed: present only when it is set and `commandProblem` finds nothing wrong with it. */
27
32
  readonly claudeCodeCommand?: string;
33
+ /** `QUORUM_MAX_REVIEW_TOKENS`: present only when it is set and in range. */
34
+ readonly maxReviewTokens?: number;
35
+ /** `QUORUM_REVIEW_TIMEOUT_MS`: present only when it is set and in range. */
36
+ readonly reviewTimeoutMs?: number;
28
37
  /** The deprecation line, when an alias is set, then the line naming the `QUORUM_` variables nothing reads. */
29
38
  readonly warnings: readonly string[];
30
39
  readonly issues: readonly ConfigIssue[];
@@ -37,17 +46,20 @@ export declare const VARIABLE_NAME: RegExp;
37
46
  export declare const CLAUDE_CODE_COMMAND = "QUORUM_CLAUDE_CODE_COMMAND";
38
47
  /**
39
48
  * Every variable the environment layer reads: `QUORUM_CONFIG`, `QUORUM_PROFILES`, `QUORUM_CLAUDE_CODE_COMMAND`, the
40
- * `QUORUM_` form of each role's variables and the deprecated aliases of those that have one. The one list: a
41
- * variable added to `VARIABLES` joins it.
49
+ * review's two limits, the `QUORUM_` form of each role's variables and the deprecated aliases of those that have one.
50
+ * The one list: a variable added to `VARIABLES` or `LIMIT_VARIABLES` joins it.
42
51
  */
43
52
  export declare const READ_VARIABLES: ReadonlySet<string>;
44
53
  /**
45
- * Read the `QUORUM_*` variables: the preset, protocol, base URL, model, context size and key of each role,
46
- * which are `QUORUM_RESEARCH_*` and `QUORUM_VOTER_*`, `QUORUM_PROFILES`, and `QUORUM_CLAUDE_CODE_COMMAND`, the
47
- * executable of the `claude-code` protocol: an absolute path, or a name to find on `PATH`. `RESEARCH_*` and
48
- * `VOTER_*` are read as deprecated aliases of the base URL, model and key, and the `QUORUM_` form wins; the
49
- * context size (`QUORUM_RESEARCH_CONTEXT_TOKENS`, `QUORUM_VOTER_CONTEXT_TOKENS`) has no alias. Any other
50
- * variable set under a `QUORUM_` name is named in one warning. No message repeats a value.
54
+ * Read the `QUORUM_*` variables: the preset, protocol, base URL, model, context size, deadline, retries and key
55
+ * of each role, which are `QUORUM_RESEARCH_*` and `QUORUM_VOTER_*`, `QUORUM_PROFILES`, and
56
+ * `QUORUM_CLAUDE_CODE_COMMAND`, the executable of the `claude-code` protocol: an absolute path, or a name to
57
+ * find on `PATH`; and the review's two limits, the run-level `QUORUM_MAX_REVIEW_TOKENS` and
58
+ * `QUORUM_REVIEW_TIMEOUT_MS`, which belong to no role and are read as strictly as a role's numbers.
59
+ * `RESEARCH_*` and `VOTER_*` are read as deprecated aliases of the base URL, model and key, and
60
+ * the `QUORUM_` form wins; the context size (`QUORUM_RESEARCH_CONTEXT_TOKENS`, `QUORUM_VOTER_CONTEXT_TOKENS`),
61
+ * the deadline (`_TIMEOUT_MS`) and the retries (`_RETRIES`) have no alias. Any other variable set under a
62
+ * `QUORUM_` name is named in one warning. No message repeats a value.
51
63
  */
52
64
  export declare function readEnv(env: Env): EnvLayer;
53
65
  /** A provider of a config: its settings, or an object implementing `Provider`. */
@@ -69,16 +81,17 @@ export declare function setsOnlyBaseUrl(overrides: RoleOverrides): boolean;
69
81
  * Set the variables of each role on its provider. The research variables go on the provider research is
70
82
  * bound to. The voter variables go on the voter's own provider, or, when the voter shares the research
71
83
  * provider, derive a provider named `voter` from it: a copy on the same endpoint, and on another one a copy
72
- * with no key, header, query, body field, model or context size (ADR-0013). A preset or a protocol variable
73
- * builds the role's provider from its variables alone. A context size describes one model on one endpoint,
74
- * so it crosses to neither: a role's variables that name a preset, a protocol, a base URL or a model drop the
75
- * context size of the provider they are set on, the derived voter's included, unless they set one; a key
76
- * variable alone leaves it. A provider object cannot be changed: each variable aimed at one
77
- * is an issue. Nothing it is given changes; nested objects are shared. A role bound to a name that is not an
78
- * own key of `providers` is an issue at that role, and nothing is applied. `builtIn` is true when `providers`
79
- * is the built-in default alone: while the research variables name no preset or protocol, a voter derived from
80
- * it whose variables set a base URL alone speaks OpenAI-compatible to it, as that variable always meant, and
81
- * does not inherit the default's own protocol. A provider of a config keeps what it names.
84
+ * with no key, header, query, body field, model or context size (ADR-0013); its deadline and retries stay, as
85
+ * its `maxTokens` does. A preset or a protocol variable builds the role's provider from its variables alone.
86
+ * A context size describes one model on one endpoint, so it crosses to neither: a role's variables that name a
87
+ * preset, a protocol, a base URL or a model drop the context size of the provider they are set on, the
88
+ * derived voter's included, unless they set one; a variable that sets only a key, a deadline or a retry
89
+ * count leaves it. A provider object cannot be changed: each variable aimed at one is an issue. Nothing it
90
+ * is given changes; nested objects are shared. A role bound to a name that is not an own key of `providers`
91
+ * is an issue at that role, and nothing is applied. `builtIn` is true when `providers` is the built-in
92
+ * default alone: while the research variables name no preset or protocol, a voter derived from it whose
93
+ * variables set a base URL alone speaks OpenAI-compatible to it, as that variable always meant, and does not
94
+ * inherit the default's own protocol. A provider of a config keeps what it names.
82
95
  */
83
96
  export declare function applyRoleOverrides(providers: Readonly<Record<string, ProviderEntry>>, roles: RoleBinding, layer: Pick<EnvLayer, 'research' | 'voter'>, builtIn?: boolean): {
84
97
  providers: Record<string, ProviderEntry>;
@@ -1,3 +1,4 @@
1
+ import { MAX_RETRIES, MAX_TIMEOUT_MS, MIN_TIMEOUT_MS } from "../core/ports.js";
1
2
  import { commandProblem } from "../providers/claude-code.js";
2
3
  import { httpOrigin } from "../providers/http.js";
3
4
  import { wordList } from "../providers/options.js";
@@ -20,6 +21,8 @@ const VARIABLES = [
20
21
  { field: 'baseUrl', suffix: 'BASE_URL', aliased: true },
21
22
  { field: 'model', suffix: 'MODEL', aliased: true },
22
23
  { field: 'contextTokens', suffix: 'CONTEXT_TOKENS', aliased: false },
24
+ { field: 'timeoutMs', suffix: 'TIMEOUT_MS', aliased: false },
25
+ { field: 'retries', suffix: 'RETRIES', aliased: false },
23
26
  { field: 'apiKey', suffix: 'API_KEY', aliased: true },
24
27
  ];
25
28
  const ROLES = ['RESEARCH', 'VOTER'];
@@ -37,24 +40,60 @@ export const VARIABLE_NAME = /^[A-Z][A-Z0-9_]{0,63}$/;
37
40
  const canonicalName = (role, suffix) => `QUORUM_${role}_${suffix}`;
38
41
  /** The variable that names the executable of every `claude-code` provider. */
39
42
  export const CLAUDE_CODE_COMMAND = 'QUORUM_CLAUDE_CODE_COMMAND';
43
+ /** The deadline variables' rule, a role's `_TIMEOUT_MS` and the review's alike: milliseconds in the range a provider's deadline may take. */
44
+ const TIMEOUT_RULE = {
45
+ form: /^[1-9]\d{3,7}$/,
46
+ max: MAX_TIMEOUT_MS,
47
+ message: `must be a whole number of milliseconds, from ${MIN_TIMEOUT_MS} to ${MAX_TIMEOUT_MS}`,
48
+ };
49
+ /** The variables of the review itself, which belong to no role: each by the field it sets and the rule it is read by. */
50
+ const LIMIT_VARIABLES = [
51
+ {
52
+ field: 'maxReviewTokens',
53
+ name: 'QUORUM_MAX_REVIEW_TOKENS',
54
+ rule: { form: /^[1-9]\d{0,15}$/, max: Number.MAX_SAFE_INTEGER, message: `must be a whole number of tokens, from 1 to ${Number.MAX_SAFE_INTEGER}` },
55
+ },
56
+ { field: 'reviewTimeoutMs', name: 'QUORUM_REVIEW_TIMEOUT_MS', rule: TIMEOUT_RULE },
57
+ ];
40
58
  /**
41
59
  * Every variable the environment layer reads: `QUORUM_CONFIG`, `QUORUM_PROFILES`, `QUORUM_CLAUDE_CODE_COMMAND`, the
42
- * `QUORUM_` form of each role's variables and the deprecated aliases of those that have one. The one list: a
43
- * variable added to `VARIABLES` joins it.
60
+ * review's two limits, the `QUORUM_` form of each role's variables and the deprecated aliases of those that have one.
61
+ * The one list: a variable added to `VARIABLES` or `LIMIT_VARIABLES` joins it.
44
62
  */
45
63
  export const READ_VARIABLES = new Set([
46
64
  'QUORUM_CONFIG',
47
65
  'QUORUM_PROFILES',
48
66
  CLAUDE_CODE_COMMAND,
67
+ ...LIMIT_VARIABLES.map(({ name }) => name),
49
68
  ...ROLES.flatMap(role => VARIABLES.map(({ suffix }) => canonicalName(role, suffix))),
50
69
  ...ROLES.flatMap(role => VARIABLES.filter(({ aliased }) => aliased).map(({ suffix }) => `${role}_${suffix}`)),
51
70
  ]);
52
- /** A context size variable: a whole number of tokens, written in decimal digits, from 1 to 999999999. */
53
- const CONTEXT_TOKENS = /^[1-9]\d{0,8}$/;
54
- const CONTEXT_TOKENS_FORM = 'must be a whole number of tokens, from 1 to 999999999';
71
+ /** The variables of a role that hold a whole number, each by the field it sets: decimal digits, no sign, no leading zero. A `Map`, so a field is never found on a prototype. */
72
+ const NUMBERS = new Map([
73
+ [
74
+ 'contextTokens',
75
+ { form: /^[1-9]\d{0,8}$/, max: 999_999_999, message: 'must be a whole number of tokens, from 1 to 999999999' },
76
+ ],
77
+ ['timeoutMs', TIMEOUT_RULE],
78
+ [
79
+ 'retries',
80
+ { form: /^[0-5]$/, max: MAX_RETRIES, message: `must be a whole number, from 0 to ${MAX_RETRIES}` },
81
+ ],
82
+ ]);
83
+ /** The number a variable holds, or the issue at the variable when it is not a whole number in the rule's range, which never repeats it. */
84
+ function readNumber(name, value, rule) {
85
+ return rule.form.test(value) && Number(value) <= rule.max
86
+ ? {
87
+ number: Number(value),
88
+ }
89
+ : {
90
+ issue: { path: name, message: rule.message },
91
+ };
92
+ }
55
93
  /**
56
94
  * The variables of one role that are set, each as its field and value: the `QUORUM_` form, else its alias. A
57
- * context size that is not a whole number in range sets nothing and is an issue at its variable, which never repeats it.
95
+ * number (the context size, the deadline, the retries) that is not a whole number in range sets nothing and is
96
+ * an issue at its variable, which never repeats it.
58
97
  */
59
98
  function readRole(env, role) {
60
99
  const entries = [];
@@ -66,18 +105,16 @@ function readRole(env, role) {
66
105
  : undefined);
67
106
  if (value === undefined)
68
107
  continue;
69
- if (field !== 'contextTokens') {
108
+ const rule = NUMBERS.get(field);
109
+ if (rule === undefined) {
70
110
  entries.push([field, value]);
111
+ continue;
71
112
  }
72
- else if (CONTEXT_TOKENS.test(value)) {
73
- entries.push([
74
- field,
75
- Number(value),
76
- ]);
77
- }
78
- else {
79
- issues.push({ path: name, message: CONTEXT_TOKENS_FORM });
80
- }
113
+ const read = readNumber(name, value, rule);
114
+ if ('issue' in read)
115
+ issues.push(read.issue);
116
+ else
117
+ entries.push([field, read.number]);
81
118
  }
82
119
  return {
83
120
  overrides: Object.fromEntries(entries),
@@ -114,6 +151,25 @@ function unreadWarnings(env) {
114
151
  : `${wordList(printed, 'and')} are not variables quorum reads`,
115
152
  ];
116
153
  }
154
+ /** The review's limits the variables set, each as its field and value, and an issue at each variable that is not a whole number in range, which never repeats it. */
155
+ function readLimits(env) {
156
+ const entries = [];
157
+ const issues = [];
158
+ for (const { field, name, rule } of LIMIT_VARIABLES) {
159
+ const value = envValue(env, name);
160
+ if (value === undefined)
161
+ continue;
162
+ const read = readNumber(name, value, rule);
163
+ if ('issue' in read)
164
+ issues.push(read.issue);
165
+ else
166
+ entries.push([field, read.number]);
167
+ }
168
+ return {
169
+ ...Object.fromEntries(entries),
170
+ issues,
171
+ };
172
+ }
117
173
  /** The profile ids of `QUORUM_PROFILES`, or the one issue that refuses it. Neither repeats the value. */
118
174
  function readProfiles(env) {
119
175
  const value = envValue(env, 'QUORUM_PROFILES');
@@ -151,21 +207,26 @@ function readClaudeCodeCommand(env) {
151
207
  };
152
208
  }
153
209
  /**
154
- * Read the `QUORUM_*` variables: the preset, protocol, base URL, model, context size and key of each role,
155
- * which are `QUORUM_RESEARCH_*` and `QUORUM_VOTER_*`, `QUORUM_PROFILES`, and `QUORUM_CLAUDE_CODE_COMMAND`, the
156
- * executable of the `claude-code` protocol: an absolute path, or a name to find on `PATH`. `RESEARCH_*` and
157
- * `VOTER_*` are read as deprecated aliases of the base URL, model and key, and the `QUORUM_` form wins; the
158
- * context size (`QUORUM_RESEARCH_CONTEXT_TOKENS`, `QUORUM_VOTER_CONTEXT_TOKENS`) has no alias. Any other
159
- * variable set under a `QUORUM_` name is named in one warning. No message repeats a value.
210
+ * Read the `QUORUM_*` variables: the preset, protocol, base URL, model, context size, deadline, retries and key
211
+ * of each role, which are `QUORUM_RESEARCH_*` and `QUORUM_VOTER_*`, `QUORUM_PROFILES`, and
212
+ * `QUORUM_CLAUDE_CODE_COMMAND`, the executable of the `claude-code` protocol: an absolute path, or a name to
213
+ * find on `PATH`; and the review's two limits, the run-level `QUORUM_MAX_REVIEW_TOKENS` and
214
+ * `QUORUM_REVIEW_TIMEOUT_MS`, which belong to no role and are read as strictly as a role's numbers.
215
+ * `RESEARCH_*` and `VOTER_*` are read as deprecated aliases of the base URL, model and key, and
216
+ * the `QUORUM_` form wins; the context size (`QUORUM_RESEARCH_CONTEXT_TOKENS`, `QUORUM_VOTER_CONTEXT_TOKENS`),
217
+ * the deadline (`_TIMEOUT_MS`) and the retries (`_RETRIES`) have no alias. Any other variable set under a
218
+ * `QUORUM_` name is named in one warning. No message repeats a value.
160
219
  */
161
220
  export function readEnv(env) {
162
221
  const { issues: profileIssues, ...profiles } = readProfiles(env);
163
222
  const { issues: commandIssues, ...command } = readClaudeCodeCommand(env);
223
+ const { issues: limitIssues, ...limits } = readLimits(env);
164
224
  const research = readRole(env, 'RESEARCH');
165
225
  const voter = readRole(env, 'VOTER');
166
226
  return {
167
227
  ...profiles,
168
228
  ...command,
229
+ ...limits,
169
230
  research: research.overrides,
170
231
  voter: voter.overrides,
171
232
  warnings: [
@@ -175,6 +236,7 @@ export function readEnv(env) {
175
236
  issues: [
176
237
  ...profileIssues,
177
238
  ...commandIssues,
239
+ ...limitIssues,
178
240
  ...research.issues,
179
241
  ...voter.issues,
180
242
  ],
@@ -290,16 +352,17 @@ function unboundRoles(providers, roles) {
290
352
  * Set the variables of each role on its provider. The research variables go on the provider research is
291
353
  * bound to. The voter variables go on the voter's own provider, or, when the voter shares the research
292
354
  * provider, derive a provider named `voter` from it: a copy on the same endpoint, and on another one a copy
293
- * with no key, header, query, body field, model or context size (ADR-0013). A preset or a protocol variable
294
- * builds the role's provider from its variables alone. A context size describes one model on one endpoint,
295
- * so it crosses to neither: a role's variables that name a preset, a protocol, a base URL or a model drop the
296
- * context size of the provider they are set on, the derived voter's included, unless they set one; a key
297
- * variable alone leaves it. A provider object cannot be changed: each variable aimed at one
298
- * is an issue. Nothing it is given changes; nested objects are shared. A role bound to a name that is not an
299
- * own key of `providers` is an issue at that role, and nothing is applied. `builtIn` is true when `providers`
300
- * is the built-in default alone: while the research variables name no preset or protocol, a voter derived from
301
- * it whose variables set a base URL alone speaks OpenAI-compatible to it, as that variable always meant, and
302
- * does not inherit the default's own protocol. A provider of a config keeps what it names.
355
+ * with no key, header, query, body field, model or context size (ADR-0013); its deadline and retries stay, as
356
+ * its `maxTokens` does. A preset or a protocol variable builds the role's provider from its variables alone.
357
+ * A context size describes one model on one endpoint, so it crosses to neither: a role's variables that name a
358
+ * preset, a protocol, a base URL or a model drop the context size of the provider they are set on, the
359
+ * derived voter's included, unless they set one; a variable that sets only a key, a deadline or a retry
360
+ * count leaves it. A provider object cannot be changed: each variable aimed at one is an issue. Nothing it
361
+ * is given changes; nested objects are shared. A role bound to a name that is not an own key of `providers`
362
+ * is an issue at that role, and nothing is applied. `builtIn` is true when `providers` is the built-in
363
+ * default alone: while the research variables name no preset or protocol, a voter derived from it whose
364
+ * variables set a base URL alone speaks OpenAI-compatible to it, as that variable always meant, and does not
365
+ * inherit the default's own protocol. A provider of a config keeps what it names.
303
366
  */
304
367
  export function applyRoleOverrides(providers, roles, layer, builtIn = false) {
305
368
  const unbound = unboundRoles(providers, roles);
@@ -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, statedRoom, 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`, `worstCase` and `room` the snapshot holds. */
24
24
  function fromObject(name, snapshot) {
25
25
  const { model, complete } = snapshot;
26
26
  if (typeof model !== 'string') {
@@ -33,8 +33,21 @@ function fromObject(name, snapshot) {
33
33
  ],
34
34
  };
35
35
  }
36
+ const worstCase = statedWorstCase(snapshot);
37
+ const room = statedRoom(snapshot);
36
38
  return {
37
- provider: { id: name, model, complete },
39
+ provider: {
40
+ id: name,
41
+ model,
42
+ complete,
43
+ ...statedFacts(snapshot).stated,
44
+ ...worstCase === undefined
45
+ ? {}
46
+ : { worstCase },
47
+ ...room === undefined
48
+ ? {}
49
+ : { room },
50
+ },
38
51
  issues: [],
39
52
  };
40
53
  }
@@ -91,9 +104,14 @@ export async function fromConfig(config, options = {}) {
91
104
  profiles: resolved.profiles.map(({ profile }) => profile),
92
105
  concurrency: resolved.concurrency,
93
106
  maxFindings: resolved.maxFindings,
107
+ partTokens: resolved.partTokens,
108
+ maxReviewTokens: resolved.maxReviewTokens,
109
+ reviewTimeoutMs: resolved.reviewTimeoutMs,
110
+ exclude: resolved.exclude,
94
111
  }, { profiles: ports, events: options.events });
95
112
  return Object.freeze({
96
113
  review: quorum.review,
114
+ estimate: quorum.estimate,
97
115
  warnings: Object.freeze([
98
116
  ...resolved.warnings,
99
117
  ...quorum.warnings,
@@ -15,6 +15,16 @@ export interface ResolvedConfig {
15
15
  readonly profiles: readonly ResolvedProfile[];
16
16
  readonly concurrency?: number;
17
17
  readonly maxFindings?: number;
18
+ /** The most tokens of diff text one research request of a large change holds: the config's alone, no variable sets it; absent when the config does not. */
19
+ readonly partTokens?: number;
20
+ /** The most tokens one review spends: `QUORUM_MAX_REVIEW_TOKENS`, else the config's; absent when neither sets it. */
21
+ readonly maxReviewTokens?: number;
22
+ /** The deadline of one review, in milliseconds: `QUORUM_REVIEW_TIMEOUT_MS`, else the config's; absent when neither sets it. */
23
+ readonly reviewTimeoutMs?: number;
24
+ /** The path patterns of the files every review leaves out; absent when the config lists none. */
25
+ readonly exclude?: readonly string[];
26
+ /** The files sent to the models though held as secrets, each the path as the diff writes it; the CLI merges them with `--send`. Absent when the config lists none. */
27
+ readonly send?: readonly string[];
18
28
  readonly warnings: readonly string[];
19
29
  }
20
30
  /** Whether `value` is a config `resolveConfig` returned. */
@@ -27,7 +37,9 @@ export declare function isResolvedConfig(value: unknown): value is ResolvedConfi
27
37
  * preset's own variable is read only at the preset's origin. Every provider needs a context size, and the issue
28
38
  * of a missing one names what to set (`reportMissingContext`). A `claude-code` provider in use gets its
29
39
  * 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
40
+ * entry of `PATH`, found or refused here, and its billing warning. The review's limits, `maxReviewTokens` and
41
+ * `reviewTimeoutMs`, come from `QUORUM_MAX_REVIEW_TOKENS` and `QUORUM_REVIEW_TIMEOUT_MS`, else from the config,
42
+ * and are kept only when one of them sets them. A resolved config is returned as it is. The
31
43
  * input must already have passed a config schema. `options.selection`, when given, names the profiles that
32
44
  * run, over `QUORUM_PROFILES`, which is still checked; its ids are checked before anything is resolved.
33
45
  *