co-maintainer 0.6.8 → 0.6.10
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/package.json +1 -1
- package/dist/src/ai/fake.d.ts +10 -1
- package/dist/src/ai/fake.js +39 -4
- package/dist/src/cli/args.js +2 -0
- package/dist/src/cli/command_json.d.ts +6 -0
- package/dist/src/cli/command_json.js +1 -0
- package/dist/src/cli/commands/probe.js +25 -0
- package/dist/src/cli/commands/registry.js +11 -0
- package/dist/src/cli/commands/review.js +5 -1
- package/dist/src/cli/commands/serve.js +10 -0
- package/dist/src/cli/commands/set.js +23 -2
- package/dist/src/cli/review_args.d.ts +9 -0
- package/dist/src/cli/review_args.js +36 -1
- package/dist/src/cli/review_github.js +6 -2
- package/dist/src/cli/review_result.js +6 -5
- package/dist/src/github/app.d.ts +4 -0
- package/dist/src/github/app.js +10 -1
- package/dist/src/github/permissions.js +40 -0
- package/dist/src/local/git_ops.js +3 -2
- package/dist/src/local/git_revision.d.ts +5 -2
- package/dist/src/local/git_revision.js +17 -10
- package/dist/src/pr/checkout.js +14 -5
- package/dist/src/pr/codegraph_tools.js +5 -3
- package/dist/src/pr/reviewer.d.ts +2 -0
- package/dist/src/pr/reviewer.js +1 -1
- package/dist/src/remote/client.js +14 -4
- package/dist/src/remote/push_client.d.ts +7 -0
- package/dist/src/remote/push_client.js +287 -0
- package/dist/src/remote/server/body.d.ts +11 -0
- package/dist/src/remote/server/body.js +14 -5
- package/dist/src/remote/server/routes.d.ts +1 -0
- package/dist/src/remote/server/routes.js +61 -4
- package/dist/src/remote/server/sync.js +11 -3
- package/dist/src/remote/validate.js +17 -0
- package/dist/src/server/api/repos.js +13 -2
- package/dist/src/server/app.js +5 -6
- package/dist/src/server/http.js +5 -0
- package/dist/src/server/pages/layout.js +1 -0
- package/dist/src/server/pages/repo.d.ts +3 -1
- package/dist/src/server/pages/repo.js +4 -1
- package/dist/src/server/pages/repo_pushes.d.ts +7 -0
- package/dist/src/server/pages/repo_pushes.js +144 -0
- package/dist/src/server/pages/repo_settings.js +45 -1
- package/dist/src/server/pages/router.js +34 -5
- package/dist/src/server/pages/settings.js +1 -1
- package/dist/src/server/webhook/index.js +24 -7
- package/dist/src/services/dashboard.d.ts +46 -0
- package/dist/src/services/dashboard.js +24 -0
- package/dist/src/services/jobs.js +18 -3
- package/dist/src/services/push_review.d.ts +51 -0
- package/dist/src/services/push_review.js +878 -0
- package/dist/src/services/setup.js +21 -0
- package/dist/src/services/watch_comments.d.ts +10 -0
- package/dist/src/services/watch_comments.js +179 -0
- package/dist/src/services/watch_issues.d.ts +70 -0
- package/dist/src/services/watch_issues.js +266 -0
- package/dist/src/services/watch_notes.d.ts +8 -0
- package/dist/src/services/watch_notes.js +80 -0
- package/dist/src/services/watch_status.d.ts +25 -0
- package/dist/src/services/watch_status.js +101 -0
- package/dist/src/services/webhook.js +107 -3
- package/dist/src/store/migrations.js +63 -0
- package/dist/src/store/repos.d.ts +1 -1
- package/dist/src/store/rows.d.ts +6 -0
- package/dist/src/store/sessions.d.ts +3 -0
- package/dist/src/store/sessions.js +5 -0
- package/dist/src/store/watch.d.ts +108 -0
- package/dist/src/store/watch.js +186 -0
- package/dist/src/types.d.ts +2 -0
- package/dist/src/util/repo_name.d.ts +2 -0
- package/dist/src/util/repo_name.js +56 -0
- package/dist/src/util/runtime.js +7 -0
- package/dist/src/util/sanitize.d.ts +6 -0
- package/dist/src/util/sanitize.js +10 -0
- package/package.json +1 -1
package/dist/package.json
CHANGED
package/dist/src/ai/fake.d.ts
CHANGED
|
@@ -3,5 +3,14 @@ export declare const FAKE_REVIEW_MARKDOWN = "## Findings\n\n### [P2 \u00B7 non-b
|
|
|
3
3
|
export declare class FakeAiProvider implements AiProvider {
|
|
4
4
|
private readonly text;
|
|
5
5
|
constructor(text?: string);
|
|
6
|
-
|
|
6
|
+
/** `CM_FAKE_AI_DIR/<job>.txt`, when it exists, answers that one job, so a
|
|
7
|
+
* smoke test can give the comment classifier and the review different
|
|
8
|
+
* answers. It is read on every call, so a test can change it between
|
|
9
|
+
* pushes. */
|
|
10
|
+
private jobText;
|
|
11
|
+
/** With `CM_FAKE_AI_DIR`, each request is appended to `requests.jsonl` so a
|
|
12
|
+
* smoke test can read what was asked, and `delay_ms` slows every answer so
|
|
13
|
+
* it can catch a review while it runs. */
|
|
14
|
+
private record;
|
|
15
|
+
complete(request: AiRequest): Promise<AiResponse>;
|
|
7
16
|
}
|
package/dist/src/ai/fake.js
CHANGED
|
@@ -27,14 +27,49 @@ export class FakeAiProvider {
|
|
|
27
27
|
constructor(text = fakeReviewText()) {
|
|
28
28
|
this.text = text;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
/** `CM_FAKE_AI_DIR/<job>.txt`, when it exists, answers that one job, so a
|
|
31
|
+
* smoke test can give the comment classifier and the review different
|
|
32
|
+
* answers. It is read on every call, so a test can change it between
|
|
33
|
+
* pushes. */
|
|
34
|
+
jobText(job) {
|
|
35
|
+
const dir = getEnv("CM_FAKE_AI_DIR");
|
|
36
|
+
if (!dir || !/^[a-z_]+$/.test(job))
|
|
37
|
+
return undefined;
|
|
38
|
+
try {
|
|
39
|
+
return readTextFileSync(`${dir}/${job}.txt`);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/** With `CM_FAKE_AI_DIR`, each request is appended to `requests.jsonl` so a
|
|
46
|
+
* smoke test can read what was asked, and `delay_ms` slows every answer so
|
|
47
|
+
* it can catch a review while it runs. */
|
|
48
|
+
async record(request) {
|
|
49
|
+
const dir = getEnv("CM_FAKE_AI_DIR");
|
|
50
|
+
if (!dir)
|
|
51
|
+
return;
|
|
52
|
+
const { appendFileSync } = await import("node:fs");
|
|
53
|
+
appendFileSync(`${dir}/requests.jsonl`, `${JSON.stringify({ job: request.job, system: request.system ?? "", prompt: request.prompt })}\n`);
|
|
54
|
+
let delay = 0;
|
|
55
|
+
try {
|
|
56
|
+
delay = Number(readTextFileSync(`${dir}/delay_ms`).trim()) || 0;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// no delay
|
|
60
|
+
}
|
|
61
|
+
if (delay > 0)
|
|
62
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
63
|
+
}
|
|
64
|
+
async complete(request) {
|
|
65
|
+
await this.record(request);
|
|
66
|
+
return {
|
|
67
|
+
text: this.jobText(request.job) ?? this.text,
|
|
33
68
|
tokensIn: 10,
|
|
34
69
|
tokensOut: 20,
|
|
35
70
|
cost: 0,
|
|
36
71
|
model: "fake",
|
|
37
72
|
provider: "openrouter",
|
|
38
|
-
}
|
|
73
|
+
};
|
|
39
74
|
}
|
|
40
75
|
}
|
package/dist/src/cli/args.js
CHANGED
|
@@ -6,6 +6,7 @@ import { die } from "./error.js";
|
|
|
6
6
|
import { AI_PROVIDERS, providerKeyEnv, rejectRetiredProvider, } from "../ai/provider.js";
|
|
7
7
|
import { availableModelSlugs } from "../ai/oauth/sign-in-with-chatgpt.js";
|
|
8
8
|
import { detectRemoteRepo } from "../local/git_ops.js";
|
|
9
|
+
import { canonicalRepoName } from "../util/repo_name.js";
|
|
9
10
|
import { reviewBlockingFrom } from "../review/blocking.js";
|
|
10
11
|
import { renderCommandHelp, renderGlobalHelp, unknownCommandMessage, unknownOptionMessage, } from "./commands/registry.js";
|
|
11
12
|
function numberOption(value, name) {
|
|
@@ -66,6 +67,7 @@ export async function parseArgs(args) {
|
|
|
66
67
|
if (!repoName || !/^[^/]+\/[^/]+$/.test(repoName)) {
|
|
67
68
|
die("Repository must look like owner/repo");
|
|
68
69
|
}
|
|
70
|
+
repoName = canonicalRepoName(repoName);
|
|
69
71
|
const { config, envPath } = prepareConfig(args);
|
|
70
72
|
const env = (name) => getEnv(name);
|
|
71
73
|
const configDefault = config.defaults ?? {};
|
|
@@ -24,6 +24,12 @@ export type ProbeJsonInput = {
|
|
|
24
24
|
/** The prose cost line, kept so a missing dollar range still says why. */
|
|
25
25
|
costNote: string;
|
|
26
26
|
durationMs: number;
|
|
27
|
+
/** Commit watch through the GitHub App. Left out when this machine has no
|
|
28
|
+
* App configured, since nothing can be said then. */
|
|
29
|
+
commitWatch?: {
|
|
30
|
+
app: "on" | "off";
|
|
31
|
+
branch: string | null;
|
|
32
|
+
};
|
|
27
33
|
};
|
|
28
34
|
export declare function buildProbeJson(input: ProbeJsonInput): string;
|
|
29
35
|
export type SetupJsonInput = {
|
|
@@ -5,6 +5,7 @@ import { estimateCostLine, estimateInit, readJobHistory, } from "../../ai/estima
|
|
|
5
5
|
import { loadPrices } from "../../ai/pricing.js";
|
|
6
6
|
import { cacheSet } from "../../store/cache_db.js";
|
|
7
7
|
import { buildProbeJson } from "../command_json.js";
|
|
8
|
+
import { appPushStateWithoutDb } from "../../services/watch_status.js";
|
|
8
9
|
export async function runProbe(options) {
|
|
9
10
|
// With `--json` stdout carries the one document, so progress moves to stderr.
|
|
10
11
|
if (options.json)
|
|
@@ -48,6 +49,7 @@ async function probe(options) {
|
|
|
48
49
|
history,
|
|
49
50
|
});
|
|
50
51
|
const costLine = estimateCostLine(estimate, options.ai, needsPrices && prices.source === "unavailable");
|
|
52
|
+
const commitWatch = await commitWatchState(client, options.repo);
|
|
51
53
|
if (options.json) {
|
|
52
54
|
stopHeartbeat();
|
|
53
55
|
console.log(buildProbeJson({
|
|
@@ -66,6 +68,7 @@ async function probe(options) {
|
|
|
66
68
|
estimate,
|
|
67
69
|
costNote: costLine,
|
|
68
70
|
durationMs: Math.round(performance.now() - operationStarted),
|
|
71
|
+
commitWatch,
|
|
69
72
|
}));
|
|
70
73
|
return;
|
|
71
74
|
}
|
|
@@ -84,6 +87,11 @@ async function probe(options) {
|
|
|
84
87
|
console.log(` basis: ${estimate.basis === "history"
|
|
85
88
|
? "this repository's recorded jobs"
|
|
86
89
|
: "the cm-dx-lab calibration"}; an estimate, not a bill`);
|
|
90
|
+
if (commitWatch) {
|
|
91
|
+
console.log(`\ncommit watch ${commitWatch.app === "on"
|
|
92
|
+
? "✓ App (push event on)"
|
|
93
|
+
: "○ App (push event off)"} ${commitWatch.branch ?? ""}`.trimEnd());
|
|
94
|
+
}
|
|
87
95
|
console.log("\nnext");
|
|
88
96
|
console.log(` ${command}`);
|
|
89
97
|
console.log(` or run it now: co-maintainer probe ${options.repo} --run`);
|
|
@@ -100,6 +108,23 @@ async function probe(options) {
|
|
|
100
108
|
await runInitOrRemake(options);
|
|
101
109
|
}
|
|
102
110
|
}
|
|
111
|
+
/** Commit watch through the App, when this machine has the App configured.
|
|
112
|
+
* Without it there is nothing to say and the line is left out. */
|
|
113
|
+
async function commitWatchState(client, repo) {
|
|
114
|
+
const app = await appPushStateWithoutDb(repo);
|
|
115
|
+
if (!app)
|
|
116
|
+
return undefined;
|
|
117
|
+
let branch = null;
|
|
118
|
+
try {
|
|
119
|
+
const info = await client.request(`repos/${repo}`);
|
|
120
|
+
branch =
|
|
121
|
+
typeof info.default_branch === "string" ? info.default_branch : null;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// The line still says whether the App watches.
|
|
125
|
+
}
|
|
126
|
+
return { app, branch };
|
|
127
|
+
}
|
|
103
128
|
/** `120-190` for a token range, rounded to whole tokens. */
|
|
104
129
|
function range([low, high]) {
|
|
105
130
|
const round = (value) => Math.round(value).toLocaleString("en-US");
|
|
@@ -419,6 +419,16 @@ export const COMMANDS = [
|
|
|
419
419
|
value: "PATH",
|
|
420
420
|
description: "Replace the repository's review instructions with this file for this run only. The built-in instructions are kept.",
|
|
421
421
|
},
|
|
422
|
+
{
|
|
423
|
+
name: "range",
|
|
424
|
+
value: "BEFORE..AFTER",
|
|
425
|
+
description: "With --remote: review a push (commit watch). The server keeps the review going if this run stops waiting.",
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
name: "timeout-minutes",
|
|
429
|
+
value: "N",
|
|
430
|
+
description: "With --range: stop waiting after N minutes and leave the result to the dashboard. Default 10.",
|
|
431
|
+
},
|
|
422
432
|
],
|
|
423
433
|
},
|
|
424
434
|
AI_FLAGS,
|
|
@@ -433,6 +443,7 @@ export const COMMANDS = [
|
|
|
433
443
|
"co-maintainer review --remote --remote-host=https://review.example.com --remote-token=cmr_...",
|
|
434
444
|
"co-maintainer review --remote --remote-byok --json",
|
|
435
445
|
"co-maintainer review --remote --output=github",
|
|
446
|
+
"co-maintainer review --remote --range=abc1234..def5678 --output=github",
|
|
436
447
|
"co-maintainer review owner/repo 42 --system-prompt-file=extra.md",
|
|
437
448
|
"co-maintainer review --system-prompt-override-file=strict.md",
|
|
438
449
|
],
|
|
@@ -8,6 +8,7 @@ import { GhClient } from "../../github/gh.js";
|
|
|
8
8
|
import { log, startHeartbeat, timed, withCliLogsToStderr, } from "../../util/log.js";
|
|
9
9
|
import { runLocalReview } from "../../local/review_local.js";
|
|
10
10
|
import { runRemoteReview } from "../../remote/client.js";
|
|
11
|
+
import { runRemotePushReview } from "../../remote/push_client.js";
|
|
11
12
|
import { reviewExitCode } from "../review_output.js";
|
|
12
13
|
import { buildPrReviewJson, resolvedFromFirstReview, reviewExitCodeFromResolved, } from "../review_result.js";
|
|
13
14
|
import { parseFindings } from "../../pr/findings.js";
|
|
@@ -22,7 +23,10 @@ export async function runReviewFromCli(args) {
|
|
|
22
23
|
return;
|
|
23
24
|
}
|
|
24
25
|
if (parsed.mode === "remote") {
|
|
25
|
-
|
|
26
|
+
if (parsed.range)
|
|
27
|
+
await runRemotePushReview(parsed);
|
|
28
|
+
else
|
|
29
|
+
await runRemoteReview(parsed);
|
|
26
30
|
return;
|
|
27
31
|
}
|
|
28
32
|
await runReviewPr(parsed.options, parsed);
|
|
@@ -10,8 +10,11 @@ import { registerReviewJobHandler } from "../../services/review.js";
|
|
|
10
10
|
import { recoverReplyRequests, registerReplyJobHandler, } from "../../services/replies.js";
|
|
11
11
|
import { startRemakeScheduler, stopRemakeScheduler, } from "../../services/remake_cron.js";
|
|
12
12
|
import { registerRemoteReviewHandler } from "../../services/remote_review.js";
|
|
13
|
+
import { registerPushReviewHandlers } from "../../services/push_review.js";
|
|
14
|
+
import { registerWatchCommentHandler } from "../../services/watch_comments.js";
|
|
13
15
|
import { startRemoteWatchdog } from "../../remote/server/sessions.js";
|
|
14
16
|
import { passwordProblem } from "../../util/password.js";
|
|
17
|
+
import { deleteAllSessions } from "../../store/sessions.js";
|
|
15
18
|
import { serveHttp } from "../../server/http.js";
|
|
16
19
|
import { currentPlatform, getEnv } from "../../util/runtime.js";
|
|
17
20
|
import { die } from "../error.js";
|
|
@@ -159,6 +162,11 @@ export async function runServe(args) {
|
|
|
159
162
|
console.log(`[serve] warning: ${warning}`);
|
|
160
163
|
await openAppDb();
|
|
161
164
|
console.log(`[serve] app.db ready at ${appDbPath()}`);
|
|
165
|
+
if (args.some((arg) => arg.startsWith("--password="))) {
|
|
166
|
+
// A password reset on the command line revokes every existing session, so a
|
|
167
|
+
// leaked cookie cannot outlive it.
|
|
168
|
+
deleteAllSessions();
|
|
169
|
+
}
|
|
162
170
|
const fromCli = await discoverCliRepos();
|
|
163
171
|
if (fromCli.length > 0) {
|
|
164
172
|
console.log(`[serve] added ${fromCli.length} repositor${fromCli.length === 1 ? "y" : "ies"} built from the CLI: ${fromCli.join(", ")}`);
|
|
@@ -167,6 +175,8 @@ export async function runServe(args) {
|
|
|
167
175
|
registerReviewJobHandler();
|
|
168
176
|
registerRemoteReviewHandler();
|
|
169
177
|
registerReplyJobHandler();
|
|
178
|
+
registerPushReviewHandlers();
|
|
179
|
+
registerWatchCommentHandler();
|
|
170
180
|
const recovered = await recoverOrphans();
|
|
171
181
|
if (recovered > 0) {
|
|
172
182
|
console.log(`[serve] recovered ${recovered} orphaned job(s) from a previous run`);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { readConfig, configPath, savedKeyProvider, writeRepoConfig, writeUserConfig, } from "../../config.js";
|
|
2
2
|
import { checkReviewSystemPrompt, reviewSystemPromptLimit, } from "../../review/system_prompt.js";
|
|
3
|
+
import { canonicalRepoName } from "../../util/repo_name.js";
|
|
3
4
|
import { hashPassword, passwordProblem } from "../../util/password.js";
|
|
5
|
+
import { deleteAllSessions } from "../../store/sessions.js";
|
|
6
|
+
import { appDbPath, closeAppDb, openAppDb } from "../../store/app_db.js";
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
4
8
|
import { readTextFile } from "../../util/runtime.js";
|
|
5
9
|
import { verifyAnthropic, verifyOpenAi, verifyOpenRouter, } from "../../ai/verify.js";
|
|
6
10
|
import { verifyOpenCode } from "../../ai/opencode.js";
|
|
@@ -351,6 +355,22 @@ export async function runSet(args) {
|
|
|
351
355
|
}
|
|
352
356
|
}
|
|
353
357
|
await writeUserConfig(patch);
|
|
358
|
+
// A changed password, allowed user, or sign-in method must not leave old
|
|
359
|
+
// dashboard sessions valid. Only touch the session store if it already
|
|
360
|
+
// exists (a server has run); never create it just to clear it.
|
|
361
|
+
const credentialChanged = patch.dashboardPasswordHash !== undefined ||
|
|
362
|
+
patch.passwordAuthDisabled !== undefined ||
|
|
363
|
+
patch.githubAuthEnabled !== undefined ||
|
|
364
|
+
patch.githubOAuthAllowedUser !== undefined;
|
|
365
|
+
if (credentialChanged && existsSync(appDbPath())) {
|
|
366
|
+
await openAppDb();
|
|
367
|
+
try {
|
|
368
|
+
deleteAllSessions();
|
|
369
|
+
}
|
|
370
|
+
finally {
|
|
371
|
+
await closeAppDb();
|
|
372
|
+
}
|
|
373
|
+
}
|
|
354
374
|
const summary = Object.entries(patch).map(([key, value]) => value === undefined
|
|
355
375
|
? `${key} (unset)`
|
|
356
376
|
: `${key}=${secretFields.has(key) ? "•".repeat(8) : value}`);
|
|
@@ -383,9 +403,10 @@ const REPO_SCOPED_UNSET = new Set([
|
|
|
383
403
|
/** `set --repo=owner/repo [--review-system-prompt=... | --review-system-prompt-max-chars=N | --unset=name]`
|
|
384
404
|
* writes the repository-scoped settings to `repos[owner/repo]` in config.json
|
|
385
405
|
* instead of the global config. */
|
|
386
|
-
async function runSetRepo(
|
|
387
|
-
if (!/^[^/]+\/[^/]+$/.test(
|
|
406
|
+
async function runSetRepo(typed, args) {
|
|
407
|
+
if (!/^[^/]+\/[^/]+$/.test(typed))
|
|
388
408
|
die("--repo must look like owner/repo");
|
|
409
|
+
const repo = canonicalRepoName(typed);
|
|
389
410
|
for (const arg of args) {
|
|
390
411
|
if (!arg.startsWith("--"))
|
|
391
412
|
continue;
|
|
@@ -26,6 +26,15 @@ type ReviewFlags = {
|
|
|
26
26
|
/** `--system-prompt-override-file`: a file whose contents replace the
|
|
27
27
|
* repository's custom review section for this run only. */
|
|
28
28
|
systemPromptOverrideFile?: string;
|
|
29
|
+
/** `--range=<before>..<after>`: review a push instead of the working tree
|
|
30
|
+
* (commit watch). Only with `--remote`. */
|
|
31
|
+
range?: {
|
|
32
|
+
before: string;
|
|
33
|
+
after: string;
|
|
34
|
+
};
|
|
35
|
+
/** `--timeout-minutes`: how long a `--range` review waits for the server
|
|
36
|
+
* before it leaves the result to the dashboard. */
|
|
37
|
+
timeoutMinutes?: number;
|
|
29
38
|
};
|
|
30
39
|
export type ReviewCliArgs = ({
|
|
31
40
|
mode: "pr";
|
|
@@ -3,6 +3,28 @@ import { die } from "./error.js";
|
|
|
3
3
|
import { readConfig } from "../config.js";
|
|
4
4
|
import { readTextFile } from "../util/runtime.js";
|
|
5
5
|
import { checkReviewSystemPrompt, reviewSystemPromptLimit, } from "../review/system_prompt.js";
|
|
6
|
+
/** `before..after`. Each side is any revision git can resolve. */
|
|
7
|
+
function parseRange(value) {
|
|
8
|
+
if (value === undefined)
|
|
9
|
+
return undefined;
|
|
10
|
+
// A side may hold single dots (v0.6.9), never two in a row, so `..` splits
|
|
11
|
+
// once and `a...b` is refused.
|
|
12
|
+
const sides = value.split("..");
|
|
13
|
+
const valid = (side) => Boolean(side) && /^[^\s-][^\s]*$/.test(side) && !/^\.|\.$/.test(side);
|
|
14
|
+
if (sides.length !== 2 || !valid(sides[0]) || !valid(sides[1])) {
|
|
15
|
+
die("--range must look like <before>..<after>");
|
|
16
|
+
}
|
|
17
|
+
return { before: sides[0], after: sides[1] };
|
|
18
|
+
}
|
|
19
|
+
function parseTimeout(value) {
|
|
20
|
+
if (value === undefined)
|
|
21
|
+
return undefined;
|
|
22
|
+
const minutes = Number(value);
|
|
23
|
+
if (!Number.isFinite(minutes) || minutes <= 0 || minutes > 360) {
|
|
24
|
+
die("--timeout-minutes must be a number of minutes between 1 and 360");
|
|
25
|
+
}
|
|
26
|
+
return minutes;
|
|
27
|
+
}
|
|
6
28
|
function reviewFlags(rest) {
|
|
7
29
|
const text = (name) => rest.find((item) => item.startsWith(`--${name}=`))?.slice(name.length + 3);
|
|
8
30
|
// `--remake-before-review` is the 0.4.13 spelling; both names mean the same
|
|
@@ -44,6 +66,8 @@ function reviewFlags(rest) {
|
|
|
44
66
|
output,
|
|
45
67
|
systemPromptFile: text("system-prompt-file"),
|
|
46
68
|
systemPromptOverrideFile: text("system-prompt-override-file"),
|
|
69
|
+
range: parseRange(text("range")),
|
|
70
|
+
timeoutMinutes: parseTimeout(text("timeout-minutes")),
|
|
47
71
|
};
|
|
48
72
|
}
|
|
49
73
|
const LOCAL_ONLY_FLAGS = new Set([
|
|
@@ -69,7 +93,9 @@ export function filterReviewConfigArgs(raw) {
|
|
|
69
93
|
arg.startsWith("--remote-token=") ||
|
|
70
94
|
arg.startsWith("--output=") ||
|
|
71
95
|
arg.startsWith("--system-prompt-file=") ||
|
|
72
|
-
arg.startsWith("--system-prompt-override-file=")
|
|
96
|
+
arg.startsWith("--system-prompt-override-file=") ||
|
|
97
|
+
arg.startsWith("--range=") ||
|
|
98
|
+
arg.startsWith("--timeout-minutes=")) {
|
|
73
99
|
return false;
|
|
74
100
|
}
|
|
75
101
|
return true;
|
|
@@ -122,6 +148,15 @@ export async function parseReviewArgs(args) {
|
|
|
122
148
|
if (flags.remoteByok !== undefined && !flags.remote) {
|
|
123
149
|
die("--remote-byok requires --remote");
|
|
124
150
|
}
|
|
151
|
+
if (flags.range && !flags.remote) {
|
|
152
|
+
die("--range requires --remote");
|
|
153
|
+
}
|
|
154
|
+
if (flags.timeoutMinutes !== undefined && !flags.range) {
|
|
155
|
+
die("--timeout-minutes requires --range");
|
|
156
|
+
}
|
|
157
|
+
if (flags.range && (flags.fresh || flags.toBranch)) {
|
|
158
|
+
die("--range cannot be used with --fresh or --to-branch");
|
|
159
|
+
}
|
|
125
160
|
// `--json` must never prompt. `parseArgs` only receives the
|
|
126
161
|
// filtered args, and `--json` is stripped before it sees them, so the flag
|
|
127
162
|
// has to be applied here rather than after the parse returns.
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* end the step's commands. Every finding is one escaped line, and nothing else
|
|
11
11
|
* from the review is printed to stdout in this mode. */
|
|
12
12
|
import { appendFileSync } from "node:fs";
|
|
13
|
+
import { stripControlChars } from "../util/sanitize.js";
|
|
13
14
|
import { formatRunSummary } from "../util/run_summary.js";
|
|
14
15
|
import { humanShortTitle, sortHumanFindings, } from "./review_result.js";
|
|
15
16
|
/** GitHub shows at most this many error and this many warning annotations per
|
|
@@ -91,7 +92,7 @@ export function githubSummary(input) {
|
|
|
91
92
|
const text = [short, row.body.split("\n")[0] ?? ""]
|
|
92
93
|
.filter(Boolean)
|
|
93
94
|
.join(": ");
|
|
94
|
-
lines.push(`| ${cell(row.severity, 10)}${row.blocking ? " (blocking)" : ""} | ${row.state} | ${where(row)} | ${cell(text || row.title)} |`);
|
|
95
|
+
lines.push(`| ${cell(row.severity, 10)}${row.blocking ? " (blocking)" : ""} | ${stripControlChars(row.state)} | ${where(row)} | ${cell(text || row.title)} |`);
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
lines.push("", `**Summary:** ${rows.filter((r) => r.state === "new").length} new · ${rows.filter((r) => r.state === "open").length} open · ${closed} closed · ${blocking} blocking`);
|
|
@@ -121,9 +122,12 @@ export function emitGithubOutput(input) {
|
|
|
121
122
|
* printed on stderr, and the runner reads workflow commands from stderr too.
|
|
122
123
|
* A line that would start one is given a prefix so it stays plain text. */
|
|
123
124
|
export function neutralizeCommands(text) {
|
|
124
|
-
// The runner also ends a line at a bare carriage return.
|
|
125
|
+
// The runner also ends a line at a bare carriage return. Split first so a
|
|
126
|
+
// `\r` still ends a line, then strip any other control characters (ESC/OSC)
|
|
127
|
+
// from each line before neutralising a leading `::` workflow command.
|
|
125
128
|
return text
|
|
126
129
|
.split(/\r\n|\r|\n/)
|
|
130
|
+
.map((line) => stripControlChars(line))
|
|
127
131
|
.map((line) => (line.trimStart().startsWith("::") ? `[log] ${line}` : line))
|
|
128
132
|
.join("\n");
|
|
129
133
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { parseFindings } from "../pr/findings.js";
|
|
2
2
|
import { readSuggestion, stripSuggestion } from "../pr/suggestion.js";
|
|
3
|
+
import { stripControlChars } from "../util/sanitize.js";
|
|
3
4
|
import { anchorTextFromPatch, } from "../review/carry_over.js";
|
|
4
5
|
import { DEFAULT_REVIEW_BLOCKING, isBlocking, } from "../review/blocking.js";
|
|
5
6
|
import { humanCopy } from "../services/review.js";
|
|
@@ -219,23 +220,23 @@ export function formatHumanReview(input) {
|
|
|
219
220
|
any = true;
|
|
220
221
|
lines.push(`${group.label} (${rows.length})`);
|
|
221
222
|
for (const row of rows) {
|
|
222
|
-
const loc = humanLocation(row);
|
|
223
|
+
const loc = stripControlChars(humanLocation(row));
|
|
223
224
|
const label = `[${row.severity} · ${row.blocking ? "blocking" : "non-blocking"}]`;
|
|
224
|
-
const short = humanShortTitle(row);
|
|
225
|
+
const short = stripControlChars(humanShortTitle(row));
|
|
225
226
|
const head = `${group.bullet} ${loc} ${label}${short ? ` \`${short}\`` : ""}`;
|
|
226
227
|
lines.push(` ${head}`);
|
|
227
228
|
if (row.state === "closed")
|
|
228
229
|
continue;
|
|
229
230
|
if (row.body) {
|
|
230
231
|
for (const part of row.body.split("\n"))
|
|
231
|
-
lines.push(` ${part}`);
|
|
232
|
+
lines.push(` ${stripControlChars(part)}`);
|
|
232
233
|
}
|
|
233
234
|
if (row.suggestion && row.path) {
|
|
234
235
|
const { lineFrom, lineTo, text } = row.suggestion;
|
|
235
|
-
lines.push(` Suggested replacement for ${row.path}:${lineFrom}${lineTo !== lineFrom ? `-${lineTo}` : ""}`);
|
|
236
|
+
lines.push(` Suggested replacement for ${stripControlChars(row.path)}:${lineFrom}${lineTo !== lineFrom ? `-${lineTo}` : ""}`);
|
|
236
237
|
lines.push(" ```");
|
|
237
238
|
for (const part of text.split("\n"))
|
|
238
|
-
lines.push(` ${part}`);
|
|
239
|
+
lines.push(` ${stripControlChars(part)}`);
|
|
239
240
|
lines.push(" ```");
|
|
240
241
|
}
|
|
241
242
|
}
|
package/dist/src/github/app.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export type Installation = {
|
|
|
7
7
|
} | null;
|
|
8
8
|
suspended_at: string | null;
|
|
9
9
|
permissions?: Record<string, string>;
|
|
10
|
+
/** The webhook events this installation receives. `push` is here only when
|
|
11
|
+
* the owner turned it on in the App's settings. */
|
|
12
|
+
events?: string[];
|
|
10
13
|
};
|
|
11
14
|
/** App-level calls: list installations, mint an installation access token.
|
|
12
15
|
* Not scoped to one installation — `AppClient` below is. */
|
|
@@ -27,6 +30,7 @@ export declare class AppClient implements GitHubClient {
|
|
|
27
30
|
request<T>(endpoint: string): Promise<T>;
|
|
28
31
|
pages<T>(endpoint: string, limit?: number, progress?: (page: number, fetched: number) => void): Promise<T[]>;
|
|
29
32
|
write<T>(endpoint: string, body: unknown): Promise<T>;
|
|
33
|
+
patch<T>(endpoint: string, body: unknown): Promise<T>;
|
|
30
34
|
createCheckRun<T>(endpoint: string, body: unknown): Promise<T>;
|
|
31
35
|
updateCheckRun<T>(endpoint: string, body: unknown): Promise<T>;
|
|
32
36
|
}
|
package/dist/src/github/app.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { githubFetch, httpError, paginate } from "./client.js";
|
|
2
2
|
import { importAppPrivateKey, signAppJwt } from "./jwt.js";
|
|
3
|
-
|
|
3
|
+
import { getEnv } from "../util/runtime.js";
|
|
4
|
+
/** `CM_GITHUB_API_URL` points the App at a fake GitHub in the smoke tests. */
|
|
5
|
+
const API = (getEnv("CM_GITHUB_API_URL") ?? "https://api.github.com").replace(/\/+$/, "");
|
|
4
6
|
function headers(token) {
|
|
5
7
|
return {
|
|
6
8
|
Accept: "application/vnd.github+json",
|
|
@@ -82,6 +84,13 @@ export class AppClient {
|
|
|
82
84
|
body: JSON.stringify(body),
|
|
83
85
|
});
|
|
84
86
|
}
|
|
87
|
+
async patch(endpoint, body) {
|
|
88
|
+
return await call(endpoint, await this.app.installationToken(this.installationId), {
|
|
89
|
+
method: "PATCH",
|
|
90
|
+
headers: { "content-type": "application/json" },
|
|
91
|
+
body: JSON.stringify(body),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
85
94
|
async createCheckRun(endpoint, body) {
|
|
86
95
|
return await this.write(endpoint, body);
|
|
87
96
|
}
|
|
@@ -96,6 +96,46 @@ export const ENDPOINTS = [
|
|
|
96
96
|
identities: APP_ONLY,
|
|
97
97
|
feature: "Post a conversation comment",
|
|
98
98
|
},
|
|
99
|
+
{
|
|
100
|
+
method: "POST",
|
|
101
|
+
pattern: "repos/{repo}/issues",
|
|
102
|
+
permission: "issues",
|
|
103
|
+
level: "write",
|
|
104
|
+
identities: APP_ONLY,
|
|
105
|
+
feature: "Open an issue for a P0 or P1 commit watch finding",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
method: "GET",
|
|
109
|
+
pattern: "repos/{repo}/issues/{n}",
|
|
110
|
+
permission: "issues",
|
|
111
|
+
level: "read",
|
|
112
|
+
identities: APP_ONLY,
|
|
113
|
+
feature: "See whether a commit watch issue was closed",
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
method: "GET",
|
|
117
|
+
pattern: "repos/{repo}/collaborators/{name}/permission",
|
|
118
|
+
permission: "metadata",
|
|
119
|
+
level: "read",
|
|
120
|
+
identities: APP_ONLY,
|
|
121
|
+
feature: "Check a commenter on a commit watch issue has write access",
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
method: "PATCH",
|
|
125
|
+
pattern: "repos/{repo}/issues/{n}",
|
|
126
|
+
permission: "issues",
|
|
127
|
+
level: "write",
|
|
128
|
+
identities: APP_ONLY,
|
|
129
|
+
feature: "Close a commit watch issue once its finding is fixed",
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
method: "POST",
|
|
133
|
+
pattern: "repos/{repo}/labels",
|
|
134
|
+
permission: "issues",
|
|
135
|
+
level: "write",
|
|
136
|
+
identities: APP_ONLY,
|
|
137
|
+
feature: "Create the co-maintainer and cm-P0 / cm-P1 labels",
|
|
138
|
+
},
|
|
99
139
|
{
|
|
100
140
|
method: "POST",
|
|
101
141
|
pattern: "repos/{repo}/issues/{n}/reactions",
|
|
@@ -2,6 +2,7 @@ import { runCommand } from "../pr/checkout.js";
|
|
|
2
2
|
import { normalizeGithubRemote } from "./git_parse.js";
|
|
3
3
|
import { stat } from "../util/runtime.js";
|
|
4
4
|
import { CliError, EXIT_USAGE } from "../cli/error.js";
|
|
5
|
+
import { canonicalRepoName } from "../util/repo_name.js";
|
|
5
6
|
export async function gitRoot(cwd, run = runCommand) {
|
|
6
7
|
const result = await run("git", ["rev-parse", "--show-toplevel"], cwd);
|
|
7
8
|
if (result.code !== 0) {
|
|
@@ -58,7 +59,7 @@ export async function detectRemoteRepo(cwd, override, run = runCommand) {
|
|
|
58
59
|
if (!/^[^/]+\/[^/]+$/.test(override)) {
|
|
59
60
|
throw new ReviewCliError("usage", "Repository must look like owner/repo");
|
|
60
61
|
}
|
|
61
|
-
return override;
|
|
62
|
+
return canonicalRepoName(override);
|
|
62
63
|
}
|
|
63
64
|
const remotes = await run("git", ["remote"], cwd);
|
|
64
65
|
const names = remotes.stdout
|
|
@@ -78,7 +79,7 @@ export async function detectRemoteRepo(cwd, override, run = runCommand) {
|
|
|
78
79
|
if (!normalized.ok) {
|
|
79
80
|
throw new ReviewCliError("unsupported_host", "Only github.com remotes are supported for local review.");
|
|
80
81
|
}
|
|
81
|
-
return normalized.fullName;
|
|
82
|
+
return canonicalRepoName(normalized.fullName);
|
|
82
83
|
}
|
|
83
84
|
export async function currentBranch(cwd, override, run = runCommand) {
|
|
84
85
|
if (override)
|
|
@@ -2,7 +2,7 @@ import type { Run } from "../pr/checkout.ts";
|
|
|
2
2
|
import { type Revision } from "../review/revision.ts";
|
|
3
3
|
import { type UntrackedWarning } from "./git_untracked.ts";
|
|
4
4
|
/** Single-file unified patch when bulk `git diff` did not map a path. */
|
|
5
|
-
export declare function perFileUnifiedPatch(cwd: string, base: string, path: string, run: Run): Promise<string>;
|
|
5
|
+
export declare function perFileUnifiedPatch(cwd: string, base: string, path: string, run: Run, to?: string): Promise<string>;
|
|
6
6
|
export declare function mergeBase(cwd: string, baseRef: string, remote: string, run: Run): Promise<string>;
|
|
7
7
|
export declare function resolveBaseRef(cwd: string, remote: string, toBranch: string | undefined, run: Run): Promise<{
|
|
8
8
|
ref: string;
|
|
@@ -12,4 +12,7 @@ export type LocalRevisionBuild = {
|
|
|
12
12
|
revision: Revision;
|
|
13
13
|
warnings: UntrackedWarning[];
|
|
14
14
|
};
|
|
15
|
-
|
|
15
|
+
/** The diff from `mergeBaseSha` to the working tree, untracked files
|
|
16
|
+
* included. With `to`, the diff between two commits instead, which is what a
|
|
17
|
+
* push review sends: nothing in the working tree is part of a push. */
|
|
18
|
+
export declare function buildLocalRevision(cwd: string, mergeBaseSha: string, baseLabel: string, run: Run, to?: string): Promise<LocalRevisionBuild>;
|