@tobi-or-not/quorum 0.0.0-stage → 0.2.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 (90) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +95 -2
  3. package/dist/cli/bin.d.ts +2 -0
  4. package/dist/cli/bin.js +48 -0
  5. package/dist/cli/main.d.ts +91 -0
  6. package/dist/cli/main.js +275 -0
  7. package/dist/cli/print-config.d.ts +14 -0
  8. package/dist/cli/print-config.js +124 -0
  9. package/dist/cli/render.d.ts +32 -0
  10. package/dist/cli/render.js +114 -0
  11. package/dist/config/claude-code.d.ts +37 -0
  12. package/dist/config/claude-code.js +111 -0
  13. package/dist/config/define.d.ts +10 -0
  14. package/dist/config/define.js +11 -0
  15. package/dist/config/env.d.ts +94 -0
  16. package/dist/config/env.js +375 -0
  17. package/dist/config/from-config.d.ts +24 -0
  18. package/dist/config/from-config.js +102 -0
  19. package/dist/config/load.d.ts +69 -0
  20. package/dist/config/load.js +543 -0
  21. package/dist/config/profiles.d.ts +39 -0
  22. package/dist/config/profiles.js +172 -0
  23. package/dist/config/resolve.d.ts +39 -0
  24. package/dist/config/resolve.js +462 -0
  25. package/dist/config/schema.d.ts +441 -0
  26. package/dist/config/schema.js +367 -0
  27. package/dist/core/concurrency.d.ts +9 -0
  28. package/dist/core/concurrency.js +31 -0
  29. package/dist/core/diff.d.ts +69 -0
  30. package/dist/core/diff.js +371 -0
  31. package/dist/core/errors.d.ts +48 -0
  32. package/dist/core/errors.js +80 -0
  33. package/dist/core/flags.d.ts +24 -0
  34. package/dist/core/flags.js +132 -0
  35. package/dist/core/output.d.ts +53 -0
  36. package/dist/core/output.js +388 -0
  37. package/dist/core/policy.d.ts +43 -0
  38. package/dist/core/policy.js +114 -0
  39. package/dist/core/ports.d.ts +56 -0
  40. package/dist/core/ports.js +1 -0
  41. package/dist/core/profile.d.ts +27 -0
  42. package/dist/core/profile.js +161 -0
  43. package/dist/core/prompts.d.ts +41 -0
  44. package/dist/core/prompts.js +108 -0
  45. package/dist/core/quorum.d.ts +28 -0
  46. package/dist/core/quorum.js +417 -0
  47. package/dist/core/sanitize.d.ts +45 -0
  48. package/dist/core/sanitize.js +80 -0
  49. package/dist/core/stages/context.d.ts +104 -0
  50. package/dist/core/stages/context.js +132 -0
  51. package/dist/core/stages/dedup.d.ts +9 -0
  52. package/dist/core/stages/dedup.js +18 -0
  53. package/dist/core/stages/panel.d.ts +32 -0
  54. package/dist/core/stages/panel.js +151 -0
  55. package/dist/core/stages/research.d.ts +53 -0
  56. package/dist/core/stages/research.js +106 -0
  57. package/dist/core/types.d.ts +297 -0
  58. package/dist/core/types.js +7 -0
  59. package/dist/core/verify.d.ts +14 -0
  60. package/dist/core/verify.js +81 -0
  61. package/dist/index.d.ts +44 -0
  62. package/dist/index.js +38 -0
  63. package/dist/profiles/security.d.ts +15 -0
  64. package/dist/profiles/security.js +41 -0
  65. package/dist/providers/anthropic.d.ts +14 -0
  66. package/dist/providers/anthropic.js +115 -0
  67. package/dist/providers/build.d.ts +45 -0
  68. package/dist/providers/build.js +196 -0
  69. package/dist/providers/claude-code.d.ts +208 -0
  70. package/dist/providers/claude-code.js +973 -0
  71. package/dist/providers/gemini.d.ts +12 -0
  72. package/dist/providers/gemini.js +177 -0
  73. package/dist/providers/http.d.ts +50 -0
  74. package/dist/providers/http.js +241 -0
  75. package/dist/providers/messages.d.ts +14 -0
  76. package/dist/providers/messages.js +22 -0
  77. package/dist/providers/ollama.d.ts +17 -0
  78. package/dist/providers/ollama.js +138 -0
  79. package/dist/providers/openai-compatible.d.ts +15 -0
  80. package/dist/providers/openai-compatible.js +188 -0
  81. package/dist/providers/options.d.ts +127 -0
  82. package/dist/providers/options.js +358 -0
  83. package/dist/providers/presets.d.ts +33 -0
  84. package/dist/providers/presets.js +195 -0
  85. package/dist/providers/reply.d.ts +18 -0
  86. package/dist/providers/reply.js +55 -0
  87. package/dist/providers/size.d.ts +50 -0
  88. package/dist/providers/size.js +116 -0
  89. package/package.json +60 -4
  90. package/schema/quorum.schema.json +523 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,96 @@
1
- # Temporary Holding Version
1
+ # Quorum :ballot_box:
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Quorum** reviews a diff with several model calls instead of one. A model, the finder, proposes candidate findings, and a panel of voters blind to each other, one per lens, judges each one. Whether a finding is kept, and at what confidence, is computed in code from the split of their votes, never reported by a model. The default profile reviews security through a model you point it at: over four HTTP protocols (Ollama's native API, OpenAI-compatible `/chat/completions`, the Anthropic Messages API and the Gemini API), with presets for the common vendors, local or hosted, or through your installed Claude Code CLI.
4
+
5
+ Quorum is pre-release (`0.x`): the API may change. It assists a reviewer; it does not replace human review of untrusted changes.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ npm install -g @tobi-or-not/quorum # the quorum command, which runs on Node
11
+ ```
12
+
13
+ It needs Node `^22.18.0 || >=23.6.0`. Each release also carries a standalone binary for Linux and macOS, on x64 and arm64, that needs neither Node nor Bun:
14
+
15
+ ```bash
16
+ gh release download --repo this-is-tobi/quorum --pattern 'quorum-linux-x64' --pattern SHA256SUMS # or linux-arm64, darwin-x64, darwin-arm64
17
+ ```
18
+
19
+ Or run the image, which holds a binary compiled the same way, from the same commit, and runs as a non-root user. Inside it `localhost` is the container, so name the endpoint. On Docker Desktop a server on your machine is `host.docker.internal`; on Linux add `--add-host=host.docker.internal:host-gateway` ([Installation](./docs/10-getting-started/10-installation.md#a-container-image) has the rest):
20
+
21
+ ```bash
22
+ docker run --rm -i \
23
+ -e QUORUM_RESEARCH_PROTOCOL=ollama -e QUORUM_RESEARCH_BASE_URL=http://host.docker.internal:11434 \
24
+ -e QUORUM_RESEARCH_MODEL=qwen3.6:27b -e QUORUM_RESEARCH_CONTEXT_TOKENS=32768 \
25
+ ghcr.io/this-is-tobi/quorum:<version> < my.diff > result.json
26
+ ```
27
+
28
+ To build it from a clone instead, with Bun 1.3.0 or newer:
29
+
30
+ ```bash
31
+ git clone https://github.com/this-is-tobi/quorum.git && cd quorum
32
+ bun install
33
+ bun run compile # a standalone binary in ./bin/quorum
34
+ install -m 0755 ./bin/quorum /usr/local/bin/quorum # on your $PATH
35
+ ```
36
+
37
+ [Installation](./docs/10-getting-started/10-installation.md) has the prerequisites, checking the npm package's provenance, checking a release binary against its checksums and its attestation, running the image with a config file, a key and a model on the host and checking its attestation, why the installed command runs on Node and not on Bun, running it from the clone without the binary, and a check that it works without a model.
38
+
39
+ ## Try it
40
+
41
+ ```bash
42
+ export QUORUM_RESEARCH_MODEL=qwen3.6:27b # a model your local Ollama serves
43
+ export QUORUM_RESEARCH_CONTEXT_TOKENS=32768 # its context window, in tokens
44
+ quorum ./my.diff > result.json # review a diff file
45
+ git diff origin/main...HEAD | quorum > result.json # or what your branch changes
46
+ ```
47
+
48
+ `QUORUM_RESEARCH_CONTEXT_TOKENS` is the model's context window in tokens, which quorum checks every request against, and without it the run exits `2` with a message that names it. With no provider configured and no base URL, preset or protocol variable, quorum talks to the Ollama on this machine through its native API, `http://localhost:11434`, which Ollama listens on, on `127.0.0.1`, by default. That API takes `num_ctx`, `truncate: false` and `shift: false`, so quorum tells the server the context size and the server refuses an overflow, where Ollama's OpenAI-compatible `/v1` would cut the prompt in silence. Refusing needs Ollama 0.12.6 or later: an older server ignores `truncate` and `shift`. A base URL variable set on its own means an OpenAI-compatible server, as before. Keep the number at most what `ollama show <model>` reports for the model, since Ollama clamps a larger `num_ctx` to it, and read the context a running model loaded in the `CONTEXT` column of `ollama ps`.
49
+
50
+ To review through your installed Claude Code CLI instead, run `claude` headless and isolated for each request:
51
+
52
+ ```bash
53
+ export QUORUM_RESEARCH_PROTOCOL=claude-code # your installed Claude Code CLI, found on PATH
54
+ export QUORUM_RESEARCH_MODEL=sonnet # an alias, or a model id, that `claude --model` takes
55
+ export QUORUM_RESEARCH_CONTEXT_TOKENS=1000000 # its context window, in tokens
56
+ quorum ./my.diff > result.json
57
+ ```
58
+
59
+ Requires Claude Code 2.1.311 or newer. [`claudeCode`](./docs/20-using/30-providers.md#claudecode) has the command line, the isolation and the auth modes, and [Claude Code](./docs/20-using/20-configuration.md#claude-code) the setup, in CI too.
60
+
61
+ The JSON result goes to stdout, and the exit code says what to do with it: `0` for a complete review in which no gating profile kept a `high` finding, `1` when one did, complete or not, `2` for a usage or configuration error, `3` when the research call failed, `4` when a gating profile's review is incomplete otherwise, and `130` when the run was interrupted. [Quick start](./docs/10-getting-started/20-quickstart.md) walks one review through, and [Start here](./docs/01-readme.md) lays out three tracks: review a diff, use it from code or review something else, and know what it protects against.
62
+
63
+ ## Documentation
64
+
65
+ **Website:** <https://this-is-tobi.com/quorum/introduction>
66
+
67
+ **Table of Contents** *- md sources*:
68
+
69
+ *Getting started*
70
+ - [Installation](./docs/10-getting-started/10-installation.md) *- Node and the npm package, a release binary, the container image, or Bun and the clone, a standalone binary on your `$PATH`, and a check that it works without a model*
71
+ - [Quick start](./docs/10-getting-started/20-quickstart.md) *- Point it at a model, review a diff, and read the progress, the result and the exit code*
72
+
73
+ *Using it*
74
+ - [The CLI](./docs/20-using/10-cli.md) *- The invocation, stdout and stderr, every exit code and its causes, and gating a CI job on them*
75
+ - [Configuration](./docs/20-using/20-configuration.md) *- The config file and its trust model in CI, the `QUORUM_*` variables and the voter's fallback, the context size each provider states, running Claude Code, the keys, `--print-config`, and the errors a bad setting causes*
76
+ - [Providers](./docs/20-using/30-providers.md) *- The provider port, the shipped adapters and their options, Claude Code run isolated as a provider, the presets, `ProviderError`, and writing a provider of your own*
77
+ - [Profiles](./docs/20-using/40-profiles.md) *- The security profile, writing your own, several in one review, gating and guidelines*
78
+ - [Lenses and policy](./docs/20-using/50-lenses-and-policy.md) *- The panel's questions, the rules that turn kept votes into a confidence, failed votes, and what a level means*
79
+ - [Prompts](./docs/20-using/60-prompts.md) *- The layout of every request, the templates and their variables, the notices, and what is not configurable*
80
+
81
+ *Security*
82
+ - [Threat model](./docs/30-security/10-threat-model.md) *- The attacker, the assets, the residual risk stated plainly, the controls in place, and what the panel's independence is worth*
83
+ - [Output handling](./docs/30-security/30-output-handling.md) *- What the CLI writes and how it is made inert, the advisory flags, and printing a review yourself*
84
+
85
+ *Recipes*
86
+ - [Local models](./docs/90-recipes/10-local-models.md) *- Ollama, vLLM and llama.cpp: the window each gives a request, choosing a model, and what reasoning mode does to a request*
87
+
88
+ *Reference*
89
+ - [Glossary](./docs/95-reference/10-glossary.md) *- The words these pages use in one particular way, and the acronyms they assume*
90
+ - [The JSON result](./docs/95-reference/20-json-result.md) *- Every field of a result in the order it is written, the incomplete reasons, and an example*
91
+ - [Library API](./docs/95-reference/30-library-api.md) *- `createQuorum`, its ports, the events, abort, the errors and every export*
92
+ - [Architecture](./docs/95-reference/40-architecture.md) *- The modules, the dependency rule, the stages of a review, and how the suite runs*
93
+
94
+ ## License
95
+
96
+ quorum is released under the [Apache License 2.0](./LICENSE).
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env node
2
+ import { inertLine } from "../core/sanitize.js";
3
+ import { errorMessage, EXIT, interruptSignal, runCli } from "./main.js";
4
+ // The first SIGINT or SIGTERM aborts the review; the second says so and exits 130 at once, for a provider that ignores it.
5
+ const signal = interruptSignal(process, (code) => {
6
+ process.stderr.write('interrupted\n');
7
+ process.exit(code);
8
+ });
9
+ // An error nothing caught is a failed run, never a finding (exit 1): one inert line, no stack, exit 3.
10
+ function fail(error) {
11
+ process.stderr.write(`${inertLine(`Error: ${errorMessage(error)}`)}\n`);
12
+ process.exit(EXIT.runtime);
13
+ }
14
+ process.on('uncaughtException', fail);
15
+ process.on('unhandledRejection', fail);
16
+ // Exit 3 until the run settles. A provider whose promise never settles, and holds no timer or socket,
17
+ // empties the event loop: the runtime then exits with the code it holds, which must never be 0 with no result.
18
+ process.exitCode = EXIT.runtime;
19
+ let settled = false;
20
+ process.once('beforeExit', () => {
21
+ if (settled)
22
+ return;
23
+ if (signal.aborted)
24
+ process.exitCode = EXIT.interrupted;
25
+ process.stderr.write(signal.aborted ? 'interrupted\n' : 'Error: the run stopped without a result\n');
26
+ });
27
+ // Inside the async function, so a working directory that no longer exists fails the run with exit 3.
28
+ async function main() {
29
+ return runCli({
30
+ argv: process.argv.slice(2),
31
+ cwd: process.cwd(),
32
+ env: process.env,
33
+ stdin: process.stdin,
34
+ stdout: process.stdout,
35
+ stderr: process.stderr,
36
+ signal,
37
+ });
38
+ }
39
+ main()
40
+ .then((code) => {
41
+ settled = true;
42
+ process.exitCode = code;
43
+ })
44
+ .catch((error) => {
45
+ settled = true;
46
+ process.stderr.write(`${inertLine(`Error: ${errorMessage(error)}`)}\n`);
47
+ process.exitCode = EXIT.runtime;
48
+ });
@@ -0,0 +1,91 @@
1
+ import type { Env } from '../config/env.ts';
2
+ import type { QuorumResult } from '../core/types.ts';
3
+ /** Exit codes (ADR-0008, amended by ADR-0012). */
4
+ export declare const EXIT: {
5
+ readonly ok: 0;
6
+ readonly finding: 1;
7
+ readonly usage: 2;
8
+ readonly runtime: 3;
9
+ readonly incomplete: 4;
10
+ readonly interrupted: 130;
11
+ };
12
+ /** The most diff the CLI reads, from stdin or a file, in bytes: a larger one is refused and reading stops there. */
13
+ export declare const MAX_DIFF_BYTES: number;
14
+ export interface CliIO {
15
+ /** Arguments after the executable and script, e.g. `process.argv.slice(2)`. */
16
+ argv: readonly string[];
17
+ /** The directory a relative diff path and a relative `--config` resolve against, e.g. `process.cwd()`. */
18
+ readonly cwd: string;
19
+ /** Environment variables, e.g. `process.env`. */
20
+ env: Env;
21
+ stdin: AsyncIterable<Uint8Array | string> & {
22
+ isTTY?: boolean;
23
+ };
24
+ stdout: {
25
+ write: (text: string) => unknown;
26
+ };
27
+ stderr: {
28
+ write: (text: string) => unknown;
29
+ };
30
+ /** The review's signal: once it is aborted, a run that ends without a result exits 130. */
31
+ readonly signal?: AbortSignal;
32
+ }
33
+ /**
34
+ * Run one review and return the process exit code. Never throws: usage and configuration problems
35
+ * exit 2, runtime failures exit 3, an interrupt exits 130, and an incomplete review (a finding its
36
+ * failed votes left undecided, or a research gap) of a gating profile exits 4 unless a `high` finding
37
+ * was kept by a gating profile, so CI can tell a broken run and a partial review from a real finding
38
+ * (exit 1) and from a clean one (exit 0). `exitCodeFor` maps the result; advisory flags never change it.
39
+ *
40
+ * It reads at most 16 MiB of diff, from stdin or a file, counted in bytes: a larger diff is a usage error,
41
+ * and reading stops at the chunk that crosses the cap.
42
+ *
43
+ * Its flags are `--config`, `--profile`, `--allow-incomplete`, `--print-config`, `--help` and `--version`;
44
+ * a usage error prints the usage after its message. Its settings are the config file `--config` or
45
+ * `QUORUM_CONFIG` names (`--config` resolved against `io.cwd`, `QUORUM_CONFIG` an absolute path), and the
46
+ * `QUORUM_*` variables of `io.env` with their deprecated aliases. Each warning is printed once, before the
47
+ * banner, and when the configuration is refused the environment's warnings come before the `Error:` lines,
48
+ * since a deprecated or mistyped variable is often what caused the error.
49
+ *
50
+ * `--print-config` reads no diff and calls no model: it writes the resolved config as YAML on stdout
51
+ * (see `printConfig`), warnings included, and returns 0; a diff argument with it is a usage error, and
52
+ * a configuration the run refuses, one of its providers that cannot be built included, exits 2 as in a run.
53
+ *
54
+ * The run is interrupted when `io.signal` aborts: it then writes `interrupted` and returns 130, whatever
55
+ * error ended the review, and writes no result. A review that has already resolved is complete.
56
+ *
57
+ * Everything the CLI writes is inert (invariant I3): each stderr line passes through `inertLine`, and
58
+ * the JSON result through `inertJson`.
59
+ */
60
+ export declare function runCli(io: CliIO): Promise<number>;
61
+ /** The one source of signals the CLI listens to: `process`, or an emitter in a test. */
62
+ export interface SignalSource {
63
+ on: (event: 'SIGINT' | 'SIGTERM', listener: () => void) => unknown;
64
+ }
65
+ /**
66
+ * The signal of one review, aborted by the first SIGINT or SIGTERM. The next one calls `exit(130)`: the
67
+ * way out of a provider that ignores its signal, since no timer waits for it.
68
+ */
69
+ export declare function interruptSignal(source: SignalSource, exit: (code: number) => void): AbortSignal;
70
+ /**
71
+ * The exit code of a finished review: 1 when a kept finding is `high` and its profile gates, 4 when
72
+ * an unreviewed finding or a gap belongs to a gating profile (unless `allowIncomplete` turns it into
73
+ * 0, which it does for every gap but a `request-too-large` one), 0 otherwise. A profile gates
74
+ * unless `meta.profiles` holds it with `gating: false`, so a profile missing from the result counts
75
+ * as gating and a gap never hides.
76
+ *
77
+ * A `request-too-large` gap of a gating profile exits 4 whatever `allowIncomplete` says: a pull
78
+ * request can cause that gap by padding the diff until a request is refused, so no flag lifts it
79
+ * (ADR-0012). The flag lifts every other gap, including gaps a pull request can cause: decoy findings
80
+ * that push a real one past `maxFindings`, or text that trips a hosted voter's content filter. On a
81
+ * gating profile, do not use it for a pull request you do not trust.
82
+ */
83
+ export declare function exitCodeFor(result: QuorumResult, options?: {
84
+ readonly allowIncomplete?: boolean;
85
+ }): number;
86
+ /**
87
+ * The text of a failure, for any value a promise can reject with: an `Error`'s message, else the
88
+ * value's text form, else a fixed text when even that throws, as it does for an object without a
89
+ * prototype. It never throws, so neither do the lines built from it.
90
+ */
91
+ export declare function errorMessage(error: unknown): string;