@open-cr-agent/cli 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.
- package/dist/cloud/account-salt.d.ts +6 -0
- package/dist/cloud/account-salt.js +33 -0
- package/dist/cloud/account-settings.d.ts +100 -0
- package/dist/cloud/account-settings.js +107 -0
- package/dist/cloud/browser.d.ts +17 -0
- package/dist/cloud/browser.js +37 -0
- package/dist/cloud/client.d.ts +93 -0
- package/dist/cloud/client.js +221 -0
- package/dist/cloud/credentials.d.ts +18 -0
- package/dist/cloud/credentials.js +52 -0
- package/dist/cloud/deps.d.ts +14 -0
- package/dist/cloud/deps.js +34 -0
- package/dist/cloud/file-lock.d.ts +14 -0
- package/dist/cloud/file-lock.js +77 -0
- package/dist/cloud/findings.d.ts +8 -0
- package/dist/cloud/findings.js +58 -0
- package/dist/cloud/gateway-token.d.ts +18 -0
- package/dist/cloud/gateway-token.js +63 -0
- package/dist/cloud/memory.d.ts +8 -0
- package/dist/cloud/memory.js +68 -0
- package/dist/cloud/private-file.d.ts +8 -0
- package/dist/cloud/private-file.js +46 -0
- package/dist/cloud/providers.d.ts +18 -0
- package/dist/cloud/providers.js +132 -0
- package/dist/cloud/review.d.ts +28 -0
- package/dist/cloud/review.js +76 -0
- package/dist/cloud/settings.d.ts +22 -0
- package/dist/cloud/settings.js +64 -0
- package/dist/cloud/upload.d.ts +20 -0
- package/dist/cloud/upload.js +183 -0
- package/dist/commands/login.d.ts +5 -0
- package/dist/commands/login.js +164 -0
- package/dist/commands/memory.d.ts +3 -0
- package/dist/{memory.js → commands/memory.js} +21 -20
- package/dist/commands/metrics.d.ts +45 -0
- package/dist/{metrics.js → commands/metrics.js} +32 -45
- package/dist/commands/plugins.d.ts +9 -0
- package/dist/commands/plugins.js +159 -0
- package/dist/{review → commands/review}/args.d.ts +7 -10
- package/dist/{review → commands/review}/args.js +11 -16
- package/dist/commands/review/deliver.d.ts +7 -0
- package/dist/commands/review/deliver.js +56 -0
- package/dist/commands/review/deps.d.ts +18 -0
- package/dist/commands/review/deps.js +2 -0
- package/dist/commands/review/execute-run.d.ts +13 -0
- package/dist/commands/review/execute-run.js +97 -0
- package/dist/commands/review/exit-code.d.ts +4 -0
- package/dist/commands/review/exit-code.js +29 -0
- package/dist/commands/review/plan-prices.d.ts +3 -0
- package/dist/commands/review/plan-prices.js +18 -0
- package/dist/{review → commands/review}/plan-render.js +22 -2
- package/dist/commands/review/plan-run.d.ts +5 -0
- package/dist/commands/review/plan-run.js +38 -0
- package/dist/commands/review/plan-schema.d.ts +97 -0
- package/dist/commands/review/plan-schema.js +34 -0
- package/dist/{review → commands/review}/progress.d.ts +3 -5
- package/dist/{review → commands/review}/progress.js +3 -3
- package/dist/{review → commands/review}/provenance.d.ts +4 -2
- package/dist/{review → commands/review}/provenance.js +11 -2
- package/dist/{review → commands/review}/render.js +8 -3
- package/dist/commands/review/resolve-run.d.ts +29 -0
- package/dist/commands/review/resolve-run.js +125 -0
- package/dist/commands/review/review-options.d.ts +6 -0
- package/dist/commands/review/review-options.js +35 -0
- package/dist/{review → commands/review}/runtimes.js +1 -1
- package/dist/{review → commands/review}/sarif-input.d.ts +0 -1
- package/dist/{review → commands/review}/sarif-input.js +5 -5
- package/dist/commands/review/sarif.d.ts +96 -0
- package/dist/{review → commands/review}/sarif.js +29 -7
- package/dist/commands/review/settings-sources.d.ts +17 -0
- package/dist/commands/review/settings-sources.js +30 -0
- package/dist/commands/review/target.d.ts +38 -0
- package/dist/commands/review/target.js +126 -0
- package/dist/commands/review.d.ts +7 -0
- package/dist/commands/review.js +34 -0
- package/dist/config/cli-config.d.ts +41 -0
- package/dist/config/cli-config.js +199 -0
- package/dist/{review/remote-config.d.ts → config/remote.d.ts} +3 -3
- package/dist/{review/remote-config.js → config/remote.js} +5 -23
- package/dist/{review/config.d.ts → config/schema.d.ts} +13 -25
- package/dist/config/schema.js +138 -0
- package/dist/config/settings.d.ts +37 -0
- package/dist/config/settings.js +133 -0
- package/dist/config/user-dir.d.ts +3 -0
- package/dist/config/user-dir.js +10 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -1
- package/dist/internal.d.ts +6 -0
- package/dist/internal.js +7 -0
- package/dist/io/exit.d.ts +9 -0
- package/dist/io/exit.js +12 -0
- package/dist/io/output.d.ts +4 -0
- package/dist/io/output.js +2 -0
- package/dist/io/usage-error.d.ts +5 -0
- package/dist/io/usage-error.js +8 -0
- package/dist/main.js +2 -2
- package/dist/plugins/account.d.ts +23 -0
- package/dist/plugins/account.js +54 -0
- package/dist/plugins/load.d.ts +13 -0
- package/dist/plugins/load.js +78 -0
- package/dist/plugins/npm.d.ts +8 -0
- package/dist/plugins/npm.js +24 -0
- package/dist/plugins/store.d.ts +20 -0
- package/dist/plugins/store.js +85 -0
- package/dist/repository-id.d.ts +12 -0
- package/dist/repository-id.js +72 -0
- package/dist/run.d.ts +2 -2
- package/dist/run.js +32 -10
- package/dist/session/store.d.ts +9 -0
- package/dist/session/store.js +31 -0
- package/package.json +17 -7
- package/dist/cloud.d.ts +0 -32
- package/dist/cloud.js +0 -262
- package/dist/memory.d.ts +0 -4
- package/dist/metrics.d.ts +0 -47
- package/dist/review/cloud-providers.d.ts +0 -12
- package/dist/review/cloud-providers.js +0 -59
- package/dist/review/cloud-upload.d.ts +0 -40
- package/dist/review/cloud-upload.js +0 -135
- package/dist/review/command.d.ts +0 -31
- package/dist/review/command.js +0 -240
- package/dist/review/config.js +0 -280
- package/dist/review/plugins.d.ts +0 -3
- package/dist/review/plugins.js +0 -32
- package/dist/review/sarif.d.ts +0 -4
- package/dist/review/target.d.ts +0 -17
- package/dist/review/target.js +0 -207
- /package/dist/{review → commands/review}/plan-render.d.ts +0 -0
- /package/dist/{review → commands/review}/render.d.ts +0 -0
- /package/dist/{review → commands/review}/runtimes.d.ts +0 -0
- /package/dist/{review → io}/terminal.d.ts +0 -0
- /package/dist/{review → io}/terminal.js +0 -0
package/dist/review/target.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { dirname } from "node:path";
|
|
2
|
-
import { OcraError, } from "@open-cr-agent/core";
|
|
3
|
-
import { DEFAULT_BOT_LOGIN, GitHubApi } from "@open-cr-agent/vcs-github/internal";
|
|
4
|
-
import { GitLabApi } from "@open-cr-agent/vcs-gitlab/internal";
|
|
5
|
-
import { ensureCommits, filesChangedSince, LocalGitAdapter, } from "@open-cr-agent/vcs-local/internal";
|
|
6
|
-
import { ConfigError, loadConfig } from "./config.js";
|
|
7
|
-
import { loadExternalPlugins } from "./plugins.js";
|
|
8
|
-
export async function localTarget(args, cwd, root, env, warn, fetchImpl) {
|
|
9
|
-
const config = await loadConfig(root, env, {
|
|
10
|
-
repository: !args.ignoreRepoConfig,
|
|
11
|
-
...(args.configFile ? { file: args.configFile } : {}),
|
|
12
|
-
warn,
|
|
13
|
-
...(fetchImpl ? { fetch: fetchImpl } : {}),
|
|
14
|
-
});
|
|
15
|
-
return {
|
|
16
|
-
config,
|
|
17
|
-
// Plugins named by the user's own file are resolved from where it is.
|
|
18
|
-
plugins: await loadExternalPlugins(config.plugins, args.configFile ? dirname(args.configFile) : root),
|
|
19
|
-
createVcs: (registry) => registry.createVcs("local", { cwd, target: args.target }),
|
|
20
|
-
...(args.ignoreRepoConfig ? { readTrusted: untrustedTreeReader(args, cwd) } : {}),
|
|
21
|
-
publish: false,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
// --no-repo-config is for code you do not trust, so the files that steer a
|
|
25
|
-
// review (.ocra/memory.json can silence findings, rules and AGENTS.md shape
|
|
26
|
-
// the prompts) are not taken from it either: from the base of a range, which
|
|
27
|
-
// you chose, and otherwise not at all.
|
|
28
|
-
function untrustedTreeReader(args, cwd) {
|
|
29
|
-
if (args.target.mode !== "range")
|
|
30
|
-
return async () => undefined;
|
|
31
|
-
const base = new LocalGitAdapter({ cwd, target: { mode: "commit", commit: args.target.from } });
|
|
32
|
-
return (path) => base.readFile(path);
|
|
33
|
-
}
|
|
34
|
-
// The pull request's own files are untrusted: configuration, guidelines and
|
|
35
|
-
// rules come from its base commit, and repository plugins never load.
|
|
36
|
-
export async function pullRequestTarget(pr, cwd, root, env, warn, fetchImpl, ignoreRepoConfig = false, configFile) {
|
|
37
|
-
const token = env.GITHUB_TOKEN ?? env.GH_TOKEN;
|
|
38
|
-
if (!token) {
|
|
39
|
-
throw new OcraError("CONFIG_CREDENTIALS_MISSING", "--pr needs a GitHub token in GITHUB_TOKEN or GH_TOKEN");
|
|
40
|
-
}
|
|
41
|
-
const [owner = "", repo = ""] = (pr.repo ?? (await repositoryName(root, env))).split("/");
|
|
42
|
-
const apiOptions = { token, ...(env.GITHUB_API_URL ? { baseUrl: env.GITHUB_API_URL } : {}) };
|
|
43
|
-
const api = new GitHubApi({ owner, repo }, fetchImpl ? { ...apiOptions, fetch: fetchImpl } : apiOptions);
|
|
44
|
-
const pull = await api.getPullRequest(pr.number);
|
|
45
|
-
await ensureCommits(root, [pull.base.sha, pull.head.sha], [`pull/${pr.number}/head`]);
|
|
46
|
-
const base = new LocalGitAdapter({ cwd, target: { mode: "commit", commit: pull.base.sha } });
|
|
47
|
-
const readTrusted = (path) => base.readFile(path);
|
|
48
|
-
const config = await loadConfig(root, env, {
|
|
49
|
-
repository: !ignoreRepoConfig,
|
|
50
|
-
read: readTrusted,
|
|
51
|
-
...(configFile ? { file: configFile } : {}),
|
|
52
|
-
warn,
|
|
53
|
-
...(fetchImpl ? { fetch: fetchImpl } : {}),
|
|
54
|
-
});
|
|
55
|
-
if (config.plugins.length > 0) {
|
|
56
|
-
warn("plugins in the configuration are not loaded for pull requests");
|
|
57
|
-
}
|
|
58
|
-
const code = new LocalGitAdapter({
|
|
59
|
-
cwd,
|
|
60
|
-
target: { mode: "range", from: pull.base.sha, to: pull.head.sha },
|
|
61
|
-
});
|
|
62
|
-
return {
|
|
63
|
-
config,
|
|
64
|
-
plugins: [],
|
|
65
|
-
createVcs: (registry) => registry.createVcs("github", {
|
|
66
|
-
owner,
|
|
67
|
-
repo,
|
|
68
|
-
number: pr.number,
|
|
69
|
-
token,
|
|
70
|
-
...(env.GITHUB_API_URL ? { apiUrl: env.GITHUB_API_URL } : {}),
|
|
71
|
-
botLogin: config.github.botLogin ?? DEFAULT_BOT_LOGIN,
|
|
72
|
-
requestChanges: config.github.requestChanges ?? false,
|
|
73
|
-
code,
|
|
74
|
-
snapshot: pull,
|
|
75
|
-
history: {
|
|
76
|
-
filesChangedSince: (from, to) => filesChangedSince(root, from, to),
|
|
77
|
-
},
|
|
78
|
-
...(fetchImpl ? { fetch: fetchImpl } : {}),
|
|
79
|
-
}),
|
|
80
|
-
readTrusted,
|
|
81
|
-
publish: pr.publish,
|
|
82
|
-
publishesTo: "pull request",
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
const GITLAB_API = "https://gitlab.com/api/v4";
|
|
86
|
-
// Like a pull request: configuration, guidelines and rules come from the
|
|
87
|
-
// target branch the merge request was based on, and repository plugins never
|
|
88
|
-
// load. GitLab CI sets CI_API_V4_URL and CI_PROJECT_ID; GITLAB_TOKEN must be
|
|
89
|
-
// a token that may write notes, which CI_JOB_TOKEN may not.
|
|
90
|
-
export async function mergeRequestTarget(mr, cwd, root, env, warn, fetchImpl, ignoreRepoConfig = false, configFile) {
|
|
91
|
-
const token = env.GITLAB_TOKEN;
|
|
92
|
-
if (!token) {
|
|
93
|
-
throw new OcraError("CONFIG_CREDENTIALS_MISSING", "--mr needs a GitLab token in GITLAB_TOKEN with the api scope and the Developer role: a project access token, or on GitLab.com Free a personal access token of a dedicated account (CI_JOB_TOKEN cannot post comments)");
|
|
94
|
-
}
|
|
95
|
-
const origin = await originUrl(root);
|
|
96
|
-
const project = mr.project ?? env.CI_PROJECT_ID ?? gitlabProject(origin);
|
|
97
|
-
const apiUrl = gitlabApi(env.CI_API_V4_URL, remoteHost(origin), warn);
|
|
98
|
-
const api = new GitLabApi(project, {
|
|
99
|
-
token,
|
|
100
|
-
baseUrl: apiUrl,
|
|
101
|
-
...(fetchImpl ? { fetch: fetchImpl } : {}),
|
|
102
|
-
});
|
|
103
|
-
const merge = await api.getMergeRequest(mr.iid);
|
|
104
|
-
const refs = merge.diff_refs;
|
|
105
|
-
if (!refs) {
|
|
106
|
-
throw new OcraError("VCS_NOT_READY", `merge request !${mr.iid} has no diff yet; try again shortly`);
|
|
107
|
-
}
|
|
108
|
-
await ensureCommits(root, [refs.start_sha, refs.head_sha], [`refs/merge-requests/${mr.iid}/head`]);
|
|
109
|
-
const base = new LocalGitAdapter({ cwd, target: { mode: "commit", commit: refs.start_sha } });
|
|
110
|
-
const readTrusted = (path) => base.readFile(path);
|
|
111
|
-
const config = await loadConfig(root, env, {
|
|
112
|
-
repository: !ignoreRepoConfig,
|
|
113
|
-
read: readTrusted,
|
|
114
|
-
...(configFile ? { file: configFile } : {}),
|
|
115
|
-
warn,
|
|
116
|
-
...(fetchImpl ? { fetch: fetchImpl } : {}),
|
|
117
|
-
});
|
|
118
|
-
if (config.plugins.length > 0) {
|
|
119
|
-
warn("plugins in the configuration are not loaded for merge requests");
|
|
120
|
-
}
|
|
121
|
-
const code = new LocalGitAdapter({
|
|
122
|
-
cwd,
|
|
123
|
-
target: { mode: "range", from: refs.start_sha, to: refs.head_sha },
|
|
124
|
-
});
|
|
125
|
-
return {
|
|
126
|
-
config,
|
|
127
|
-
plugins: [],
|
|
128
|
-
createVcs: (registry) => registry.createVcs("gitlab", {
|
|
129
|
-
project: /^\d+$/.test(project) ? Number(project) : project,
|
|
130
|
-
iid: mr.iid,
|
|
131
|
-
token,
|
|
132
|
-
apiUrl,
|
|
133
|
-
code,
|
|
134
|
-
snapshot: merge,
|
|
135
|
-
history: {
|
|
136
|
-
filesChangedSince: (from, to) => filesChangedSince(root, from, to),
|
|
137
|
-
},
|
|
138
|
-
...(fetchImpl ? { fetch: fetchImpl } : {}),
|
|
139
|
-
}),
|
|
140
|
-
readTrusted,
|
|
141
|
-
publish: mr.publish,
|
|
142
|
-
publishesTo: "merge request",
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function originUrl(root) {
|
|
146
|
-
return new LocalGitAdapter({ cwd: root, target: { mode: "workspace" } })
|
|
147
|
-
.remoteUrl("origin")
|
|
148
|
-
.catch(() => undefined);
|
|
149
|
-
}
|
|
150
|
-
// Where GITLAB_TOKEN goes: to CI_API_V4_URL, which GitLab CI sets, or else
|
|
151
|
-
// to gitlab.com, but only when origin is there too or is no remote host. A
|
|
152
|
-
// token for a self-managed instance must not travel to gitlab.com because
|
|
153
|
-
// the address was left out.
|
|
154
|
-
function gitlabApi(configured, origin, warn) {
|
|
155
|
-
if (configured) {
|
|
156
|
-
const api = remoteHost(configured);
|
|
157
|
-
if (api && origin && site(api) !== site(origin)) {
|
|
158
|
-
warn(`CI_API_V4_URL is on ${api} but origin is on ${origin}; GITLAB_TOKEN goes to ${api}`);
|
|
159
|
-
}
|
|
160
|
-
return configured;
|
|
161
|
-
}
|
|
162
|
-
if (origin && site(origin) !== "gitlab.com") {
|
|
163
|
-
throw new ConfigError(`origin is on ${origin}, not gitlab.com: set CI_API_V4_URL to its API, such as https://${origin}/api/v4, so that GITLAB_TOKEN goes only there`);
|
|
164
|
-
}
|
|
165
|
-
return GITLAB_API;
|
|
166
|
-
}
|
|
167
|
-
// GitLab.com answers on subdomains too, such as altssh.gitlab.com for SSH.
|
|
168
|
-
function site(host) {
|
|
169
|
-
return host === "gitlab.com" || host.endsWith(".gitlab.com") ? "gitlab.com" : host;
|
|
170
|
-
}
|
|
171
|
-
// The host of https://host/…, ssh://user@host:port/… or user@host:path; none
|
|
172
|
-
// for a local path, including C:\ on Windows.
|
|
173
|
-
function remoteHost(url) {
|
|
174
|
-
if (!url)
|
|
175
|
-
return undefined;
|
|
176
|
-
if (/^[\w+.-]+:\/\//.test(url)) {
|
|
177
|
-
try {
|
|
178
|
-
const parsed = new URL(url);
|
|
179
|
-
return parsed.protocol === "file:" ? undefined : parsed.hostname.toLowerCase() || undefined;
|
|
180
|
-
}
|
|
181
|
-
catch {
|
|
182
|
-
return undefined;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
return /^(?:[^@\s/]+@)?([^:/\s\\]+):(?![\\/])/.exec(url)?.[1]?.toLowerCase();
|
|
186
|
-
}
|
|
187
|
-
// The project behind the origin remote: any host, since GitLab runs on many.
|
|
188
|
-
function gitlabProject(url) {
|
|
189
|
-
const match = url && /^(?:[\w+.-]+:\/\/[^/]+\/|[^@\s]+@[^:]+:)(.+?)(?:\.git)?\/?$/.exec(url);
|
|
190
|
-
if (!match?.[1]) {
|
|
191
|
-
throw new ConfigError("Cannot tell which GitLab project this is; pass --project <id|path>");
|
|
192
|
-
}
|
|
193
|
-
return match[1];
|
|
194
|
-
}
|
|
195
|
-
async function repositoryName(root, env) {
|
|
196
|
-
if (env.GITHUB_REPOSITORY)
|
|
197
|
-
return env.GITHUB_REPOSITORY;
|
|
198
|
-
const url = await new LocalGitAdapter({ cwd: root, target: { mode: "workspace" } })
|
|
199
|
-
.remoteUrl("origin")
|
|
200
|
-
.catch(() => undefined);
|
|
201
|
-
const match = url && /github\.com[:/]([\w.-]+\/[\w.-]+?)(?:\.git)?$/.exec(url);
|
|
202
|
-
if (!match?.[1]) {
|
|
203
|
-
throw new ConfigError("Cannot tell which GitHub repository this is; pass --repo owner/name");
|
|
204
|
-
}
|
|
205
|
-
return match[1];
|
|
206
|
-
}
|
|
207
|
-
//# sourceMappingURL=target.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|