@open-cr-agent/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # @open-cr-agent/cli
2
+
3
+ `ocra` is the command line of [Open-CR-Agent](https://github.com/jma49/Open-CR-Agent), an open-source multi-agent code reviewer for local changes and GitHub pull requests. Deterministic code selects and bundles the files, matches rules and anchors comments; LLM reviewers make the judgment calls, and a verification pass checks what they report.
4
+
5
+ This is an early 0.x release: options and output may change between minor versions. What the reviews find and miss is measured on the [quality page](https://ocra.majincheng.com/en/docs/quality).
6
+
7
+ ## Install
8
+
9
+ Requires Node.js 22.19 or newer and Git.
10
+
11
+ ```bash
12
+ npm install -g @open-cr-agent/cli
13
+ ocra --version
14
+ ```
15
+
16
+ ## First review
17
+
18
+ ocra runs its agents on [OpenCode](https://opencode.ai), which is installed with it, using the models you choose for three tiers: `standard` reviews, `light` does helper work, and `top` judges the findings. A comma-separated list is a failback chain. With Google Gemini:
19
+
20
+ ```bash
21
+ export GEMINI_API_KEY="your-key"
22
+ export OCRA_MODEL_TOP=google/gemini-3.1-pro-preview
23
+ export OCRA_MODEL_STANDARD=google/gemini-3.5-flash,google/gemini-flash-lite-latest
24
+ export OCRA_MODEL_LIGHT=google/gemini-flash-lite-latest
25
+
26
+ cd your-repository
27
+ ocra review --plan # what a review would do; calls no model
28
+ ocra review # uncommitted changes, including untracked files
29
+ ocra review --from main # this branch since it diverged from main
30
+ ocra review --max-cost-usd 1 # a spend limit for the run, in dollars
31
+ ```
32
+
33
+ Pull requests can also be reviewed by the GitHub Action: inline comments, one summary, and re-reviews of only what changed since the last push.
34
+
35
+ ## Documentation
36
+
37
+ - [Quickstart](https://ocra.majincheng.com/en/docs/quickstart) and the manual, in [English](https://ocra.majincheng.com/en/docs) and [中文](https://ocra.majincheng.com/zh/docs)
38
+ - [GitHub pull requests](https://ocra.majincheng.com/en/docs/github)
39
+ - [Changelog](https://github.com/jma49/Open-CR-Agent/blob/main/CHANGELOG.md) and [issues](https://github.com/jma49/Open-CR-Agent/issues)
40
+
41
+ ## License
42
+
43
+ Apache-2.0
@@ -0,0 +1,2 @@
1
+ export { run } from "./run.js";
2
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { run } from "./run.js";
2
+ //# sourceMappingURL=index.js.map
package/dist/main.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=main.d.ts.map
package/dist/main.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { run } from "./run.js";
3
+ process.exitCode = await run(process.argv.slice(2), process.stdout, process.stderr);
4
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1,4 @@
1
+ import type { Output } from "./review/progress.js";
2
+ export declare const MEMORY_USAGE = "Usage: ocra memory <command>\n\nRemember findings the team accepts, so ocra stops reporting them.\nEntries live in .ocra/memory.json; commit it to share them.\n\nCommands:\n list Show remembered findings\n add <id> --reason <text> Remember a finding from the last review\n [--session <dir>] (default: the newest session in .ocra/sessions)\n";
3
+ export declare function memoryCommand(argv: string[], out: Output, cwd: string, now?: Date): Promise<number>;
4
+ //# sourceMappingURL=memory.d.ts.map
package/dist/memory.js ADDED
@@ -0,0 +1,116 @@
1
+ import { constants, existsSync } from "node:fs";
2
+ import { lstat, mkdir, open, readdir, readFile } from "node:fs/promises";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { parseArgs } from "node:util";
5
+ import { MEMORY_PATH, parseMemory, serializeMemory, } from "@open-cr-agent/core";
6
+ import { findRepositoryRoot } from "@open-cr-agent/vcs-local";
7
+ import { UsageError } from "./review/args.js";
8
+ import { SESSIONS_DIR } from "./review/command.js";
9
+ import { forTerminal } from "./review/terminal.js";
10
+ export const MEMORY_USAGE = `Usage: ocra memory <command>
11
+
12
+ Remember findings the team accepts, so ocra stops reporting them.
13
+ Entries live in ${MEMORY_PATH}; commit it to share them.
14
+
15
+ Commands:
16
+ list Show remembered findings
17
+ add <id> --reason <text> Remember a finding from the last review
18
+ [--session <dir>] (default: the newest session in ${SESSIONS_DIR})
19
+ `;
20
+ export async function memoryCommand(argv, out, cwd, now = new Date()) {
21
+ const { values, positionals } = parseArgs({
22
+ args: argv,
23
+ allowPositionals: true,
24
+ strict: true,
25
+ options: {
26
+ reason: { type: "string" },
27
+ session: { type: "string" },
28
+ help: { type: "boolean", short: "h" },
29
+ },
30
+ });
31
+ const [command, id] = positionals;
32
+ if (values.help || command === undefined) {
33
+ out.write(MEMORY_USAGE);
34
+ return 0;
35
+ }
36
+ const root = await findRepositoryRoot(cwd);
37
+ const memory = await readMemory(root);
38
+ if (command === "list") {
39
+ if (memory.length === 0)
40
+ out.write("No remembered findings.\n");
41
+ for (const e of memory) {
42
+ out.write(forTerminal(`${e.fingerprint.slice(0, 8)} ${e.file} ${e.title}\n ${e.reason}\n`));
43
+ }
44
+ return 0;
45
+ }
46
+ if (command !== "add")
47
+ throw new UsageError(`Unknown memory command: ${command}`);
48
+ if (!id || id.length < 6)
49
+ throw new UsageError("ocra memory add needs a finding id of at least 6 characters");
50
+ if (!values.reason?.trim())
51
+ throw new UsageError("ocra memory add needs --reason");
52
+ const report = values.session ? resolve(cwd, values.session) : await newestSession(root);
53
+ const finding = await findFinding(join(report, "report.json"), id);
54
+ if (memory.some((e) => e.fingerprint === finding.fingerprint)) {
55
+ out.write(`Already remembered: ${forTerminal(finding.title)}\n`);
56
+ return 0;
57
+ }
58
+ const entry = {
59
+ fingerprint: finding.fingerprint,
60
+ file: finding.file,
61
+ title: finding.title,
62
+ reason: values.reason.trim(),
63
+ added: now.toISOString().slice(0, 10),
64
+ };
65
+ await writeRepositoryFile(root, MEMORY_PATH, serializeMemory([...memory, entry]));
66
+ out.write(forTerminal(`Remembered ${finding.fingerprint.slice(0, 8)}: ${finding.title}\nCommit ${MEMORY_PATH} to share it.\n`));
67
+ return 0;
68
+ }
69
+ // The repository may be someone else's clone: a planted symlink at
70
+ // .ocra/memory.json, or at .ocra, must not make ocra write elsewhere.
71
+ async function writeRepositoryFile(root, path, content) {
72
+ const target = join(root, path);
73
+ for (const p of [dirname(target), target]) {
74
+ const stat = await lstat(p).catch(() => undefined);
75
+ if (stat?.isSymbolicLink())
76
+ throw new UsageError(`Refusing to write through the symbolic link ${p}`);
77
+ }
78
+ await mkdir(dirname(target), { recursive: true });
79
+ const handle = await open(target, constants.O_WRONLY | constants.O_CREAT | constants.O_TRUNC | constants.O_NOFOLLOW);
80
+ try {
81
+ await handle.writeFile(content);
82
+ }
83
+ finally {
84
+ await handle.close();
85
+ }
86
+ }
87
+ async function readMemory(root) {
88
+ try {
89
+ return parseMemory(await readFile(join(root, MEMORY_PATH), "utf8"));
90
+ }
91
+ catch (error) {
92
+ if (error.code === "ENOENT")
93
+ return [];
94
+ throw error;
95
+ }
96
+ }
97
+ async function newestSession(root) {
98
+ const dir = join(root, SESSIONS_DIR);
99
+ const sessions = (await readdir(dir).catch(() => [])).filter((n) => !n.startsWith(".")).sort();
100
+ // An interrupted run leaves a session without a report.
101
+ for (const name of sessions.reverse()) {
102
+ if (existsSync(join(dir, name, "report.json")))
103
+ return join(dir, name);
104
+ }
105
+ throw new UsageError(`No finished review in ${SESSIONS_DIR}; run ocra review first`);
106
+ }
107
+ async function findFinding(reportPath, id) {
108
+ const report = JSON.parse(await readFile(reportPath, "utf8"));
109
+ const matches = (report.findings ?? []).filter((f) => f.fingerprint.startsWith(id));
110
+ if (matches.length === 1)
111
+ return matches[0];
112
+ throw new UsageError(matches.length === 0
113
+ ? `No finding ${id} in ${reportPath}`
114
+ : `${id} matches ${matches.length} findings; use more characters`);
115
+ }
116
+ //# sourceMappingURL=memory.js.map
@@ -0,0 +1,24 @@
1
+ import type { LocalTarget } from "@open-cr-agent/vcs-local";
2
+ export type OutputFormat = "text" | "json";
3
+ export interface PullRequestTarget {
4
+ number: number;
5
+ repo?: string;
6
+ publish: boolean;
7
+ }
8
+ export interface ReviewArgs {
9
+ target: LocalTarget;
10
+ pullRequest?: PullRequestTarget;
11
+ format: OutputFormat;
12
+ output?: string;
13
+ ignoreRepoConfig?: true;
14
+ reviewers?: string[];
15
+ maxCostUsd?: number;
16
+ ultra?: true;
17
+ full?: true;
18
+ plan?: true;
19
+ }
20
+ export declare class UsageError extends Error {
21
+ }
22
+ export declare const REVIEW_USAGE = "Usage: ocra review [options]\n\nReviews uncommitted changes by default.\n\nOptions:\n --from <ref> Review changes on --to since it diverged from <ref>\n --to <ref> End of the range (default: HEAD)\n --commit <sha> Review a single commit\n --pr <number> Review a GitHub pull request (needs GITHUB_TOKEN)\n --repo <owner/name> Repository of --pr (default: GITHUB_REPOSITORY or origin)\n --publish With --pr: post the review to the pull request\n --full With --pr: review every file, not only what changed since\n the previous review\n --format <format> text (default) or json\n --output <file> Write the result to a file instead of stdout\n --reviewers <ids> Run only these reviewers (comma-separated)\n --max-cost-usd <n> Spend limit: reviews use 80%, verification and judging the rest\n --plan Show files, bundles, review tasks and prompt sizes; call no model\n --ultra Favor recall: all reviewers at every tier, two samples each (about 2x cost)\n --no-repo-config Ignore .ocra/config.json and its plugins (for untrusted\n code); models come from OCRA_MODEL_* variables\n -h, --help Show help\n";
23
+ export declare function parseReviewArgs(argv: string[]): ReviewArgs | "help";
24
+ //# sourceMappingURL=args.d.ts.map
@@ -0,0 +1,141 @@
1
+ import { parseArgs } from "node:util";
2
+ export class UsageError extends Error {
3
+ }
4
+ export const REVIEW_USAGE = `Usage: ocra review [options]
5
+
6
+ Reviews uncommitted changes by default.
7
+
8
+ Options:
9
+ --from <ref> Review changes on --to since it diverged from <ref>
10
+ --to <ref> End of the range (default: HEAD)
11
+ --commit <sha> Review a single commit
12
+ --pr <number> Review a GitHub pull request (needs GITHUB_TOKEN)
13
+ --repo <owner/name> Repository of --pr (default: GITHUB_REPOSITORY or origin)
14
+ --publish With --pr: post the review to the pull request
15
+ --full With --pr: review every file, not only what changed since
16
+ the previous review
17
+ --format <format> text (default) or json
18
+ --output <file> Write the result to a file instead of stdout
19
+ --reviewers <ids> Run only these reviewers (comma-separated)
20
+ --max-cost-usd <n> Spend limit: reviews use 80%, verification and judging the rest
21
+ --plan Show files, bundles, review tasks and prompt sizes; call no model
22
+ --ultra Favor recall: all reviewers at every tier, two samples each (about 2x cost)
23
+ --no-repo-config Ignore .ocra/config.json and its plugins (for untrusted
24
+ code); models come from OCRA_MODEL_* variables
25
+ -h, --help Show help
26
+ `;
27
+ export function parseReviewArgs(argv) {
28
+ let parsed;
29
+ try {
30
+ parsed = parse(argv);
31
+ }
32
+ catch (error) {
33
+ throw new UsageError(error.message);
34
+ }
35
+ const { values, positionals } = parsed;
36
+ if (values.help)
37
+ return "help";
38
+ if (positionals.length > 0)
39
+ throw new UsageError(`Unexpected argument: ${positionals[0]}`);
40
+ const format = values.format ?? "text";
41
+ if (format !== "text" && format !== "json") {
42
+ throw new UsageError(`--format must be text or json, got ${format}`);
43
+ }
44
+ const args = { target: target(values), format };
45
+ const pullRequest = pullRequestTarget(values);
46
+ if (pullRequest)
47
+ args.pullRequest = pullRequest;
48
+ if (values.output !== undefined)
49
+ args.output = values.output;
50
+ if (values["no-repo-config"])
51
+ args.ignoreRepoConfig = true;
52
+ if (values.ultra)
53
+ args.ultra = true;
54
+ if (values.full) {
55
+ if (!pullRequest)
56
+ throw new UsageError("--full needs --pr");
57
+ args.full = true;
58
+ }
59
+ if (values.plan) {
60
+ if (values.publish)
61
+ throw new UsageError("--plan cannot be combined with --publish");
62
+ args.plan = true;
63
+ }
64
+ if (values["max-cost-usd"] !== undefined) {
65
+ const max = Number(values["max-cost-usd"]);
66
+ if (!(max > 0))
67
+ throw new UsageError(`--max-cost-usd must be a positive number, got ${values["max-cost-usd"]}`);
68
+ args.maxCostUsd = max;
69
+ }
70
+ if (values.reviewers !== undefined) {
71
+ const ids = values.reviewers
72
+ .split(",")
73
+ .map((id) => id.trim())
74
+ .filter((id) => id !== "");
75
+ if (ids.length === 0)
76
+ throw new UsageError("--reviewers needs at least one reviewer id");
77
+ args.reviewers = ids;
78
+ }
79
+ return args;
80
+ }
81
+ function parse(argv) {
82
+ return parseArgs({
83
+ args: argv,
84
+ allowPositionals: true,
85
+ strict: true,
86
+ options: {
87
+ from: { type: "string" },
88
+ to: { type: "string" },
89
+ commit: { type: "string" },
90
+ format: { type: "string" },
91
+ output: { type: "string" },
92
+ "no-repo-config": { type: "boolean" },
93
+ reviewers: { type: "string" },
94
+ "max-cost-usd": { type: "string" },
95
+ ultra: { type: "boolean" },
96
+ full: { type: "boolean" },
97
+ plan: { type: "boolean" },
98
+ pr: { type: "string" },
99
+ repo: { type: "string" },
100
+ publish: { type: "boolean" },
101
+ help: { type: "boolean", short: "h" },
102
+ },
103
+ });
104
+ }
105
+ function pullRequestTarget(values) {
106
+ if (values.pr === undefined) {
107
+ if (values.publish)
108
+ throw new UsageError("--publish requires --pr");
109
+ if (values.repo !== undefined)
110
+ throw new UsageError("--repo requires --pr");
111
+ return undefined;
112
+ }
113
+ if (values.from !== undefined || values.to !== undefined || values.commit !== undefined) {
114
+ throw new UsageError("--pr cannot be combined with --from, --to or --commit");
115
+ }
116
+ const number = Number(values.pr);
117
+ if (!Number.isInteger(number) || number <= 0) {
118
+ throw new UsageError(`--pr must be a pull request number, got ${values.pr}`);
119
+ }
120
+ if (values.repo !== undefined && !/^[\w.-]+\/[\w.-]+$/.test(values.repo)) {
121
+ throw new UsageError(`--repo must be owner/name, got ${values.repo}`);
122
+ }
123
+ const target = { number, publish: values.publish === true };
124
+ if (values.repo !== undefined)
125
+ target.repo = values.repo;
126
+ return target;
127
+ }
128
+ function target(values) {
129
+ if (values.commit !== undefined) {
130
+ if (values.from !== undefined || values.to !== undefined) {
131
+ throw new UsageError("--commit cannot be combined with --from or --to");
132
+ }
133
+ return { mode: "commit", commit: values.commit };
134
+ }
135
+ if (values.from !== undefined)
136
+ return { mode: "range", from: values.from, to: values.to ?? "HEAD" };
137
+ if (values.to !== undefined)
138
+ throw new UsageError("--to requires --from");
139
+ return { mode: "workspace" };
140
+ }
141
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1,27 @@
1
+ import { type OcraPlugin } from "@open-cr-agent/core";
2
+ import type { ReviewArgs } from "./args.js";
3
+ import { type Output } from "./progress.js";
4
+ export declare const SESSIONS_DIR = ".ocra/sessions";
5
+ export declare const EXIT: {
6
+ readonly ok: 0;
7
+ readonly blocking: 1;
8
+ readonly error: 2;
9
+ readonly incomplete: 3;
10
+ readonly interrupted: 130;
11
+ };
12
+ export declare const BUILTIN_PLUGINS: readonly OcraPlugin[];
13
+ export interface ReviewDeps {
14
+ cwd: string;
15
+ env: Readonly<Record<string, string | undefined>>;
16
+ builtinPlugins: readonly OcraPlugin[];
17
+ writeFile(path: string, content: string): Promise<void>;
18
+ now(): number;
19
+ heartbeatMs: number;
20
+ fetch?: typeof fetch;
21
+ onInterrupt?(handler: () => void): () => void;
22
+ }
23
+ export declare function reviewCommand(args: ReviewArgs, io: {
24
+ out: Output;
25
+ err: Output;
26
+ }, deps: ReviewDeps): Promise<number>;
27
+ //# sourceMappingURL=command.d.ts.map