co-maintainer 0.6.1 → 0.6.4
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/THIRD_PARTY_NOTICES +161 -0
- package/dist/package.json +4 -2
- package/dist/src/ai/batch.js +7 -0
- package/dist/src/ai/oauth/ids.d.ts +10 -0
- package/dist/src/ai/oauth/ids.js +10 -0
- package/dist/src/ai/oauth/registry.d.ts +33 -0
- package/dist/src/ai/oauth/registry.js +40 -0
- package/dist/src/ai/oauth/sign-in-with-chatgpt.d.ts +56 -0
- package/dist/src/ai/oauth/sign-in-with-chatgpt.js +552 -0
- package/dist/src/ai/openai.d.ts +18 -1
- package/dist/src/ai/openai.js +68 -5
- package/dist/src/ai/provider.d.ts +3 -0
- package/dist/src/ai/provider.js +11 -2
- package/dist/src/cli/args.js +61 -21
- package/dist/src/cli/commands/oauth.d.ts +1 -0
- package/dist/src/cli/commands/oauth.js +73 -0
- package/dist/src/cli/commands/registry.js +79 -3
- package/dist/src/cli/commands/serve.js +31 -3
- package/dist/src/cli/commands/set.js +54 -0
- package/dist/src/cli/main.js +5 -0
- package/dist/src/cli/review_args.js +5 -0
- package/dist/src/config.d.ts +14 -0
- package/dist/src/github/client.js +13 -0
- package/dist/src/github/collect.d.ts +2 -2
- package/dist/src/github/collect.js +60 -23
- package/dist/src/github/permissions.js +8 -0
- package/dist/src/knowledge/types.d.ts +3 -4
- package/dist/src/pr/reviewer.js +5 -4
- package/dist/src/server/api/jobs.js +8 -1
- package/dist/src/server/api/repos.js +73 -11
- package/dist/src/server/api/settings.js +6 -0
- package/dist/src/server/app.d.ts +5 -0
- package/dist/src/server/app.js +7 -0
- package/dist/src/server/http.d.ts +3 -0
- package/dist/src/server/http.js +5 -0
- package/dist/src/server/pages/activity.js +412 -19
- package/dist/src/server/pages/add_repo.js +6 -1
- package/dist/src/server/pages/analytics.js +99 -31
- package/dist/src/server/pages/catalog.d.ts +1 -0
- package/dist/src/server/pages/catalog.js +145 -0
- package/dist/src/server/pages/client.d.ts +1 -1
- package/dist/src/server/pages/client.js +1 -1
- package/dist/src/server/pages/home.d.ts +14 -4
- package/dist/src/server/pages/home.js +83 -49
- package/dist/src/server/pages/icons.d.ts +3 -0
- package/dist/src/server/pages/icons.js +3 -0
- package/dist/src/server/pages/knowledge.js +10 -5
- package/dist/src/server/pages/layout.d.ts +19 -3
- package/dist/src/server/pages/layout.js +156 -33
- package/dist/src/server/pages/pr.js +4 -3
- package/dist/src/server/pages/rate_limit_waits.d.ts +5 -0
- package/dist/src/server/pages/rate_limit_waits.js +74 -0
- package/dist/src/server/pages/repo.js +100 -66
- package/dist/src/server/pages/repo_prs.js +4 -3
- package/dist/src/server/pages/repo_remote.js +4 -3
- package/dist/src/server/pages/repo_settings.d.ts +2 -2
- package/dist/src/server/pages/repo_settings.js +420 -46
- package/dist/src/server/pages/router.d.ts +5 -0
- package/dist/src/server/pages/router.js +82 -31
- package/dist/src/server/pages/settings.d.ts +10 -1
- package/dist/src/server/pages/settings.js +351 -207
- package/dist/src/server/pages/setup.d.ts +2 -5
- package/dist/src/server/pages/setup.js +21 -23
- package/dist/src/server/pages/styles.d.ts +1 -1
- package/dist/src/server/pages/styles.js +1 -1
- package/dist/src/server/pages/ui.d.ts +117 -0
- package/dist/src/server/pages/ui.js +166 -0
- package/dist/src/services/clear.js +2 -0
- package/dist/src/services/cli_repos.d.ts +2 -0
- package/dist/src/services/cli_repos.js +50 -0
- package/dist/src/services/concurrency.d.ts +39 -0
- package/dist/src/services/concurrency.js +88 -0
- package/dist/src/services/dashboard.d.ts +43 -1
- package/dist/src/services/dashboard.js +10 -2
- package/dist/src/services/jobs.js +5 -3
- package/dist/src/services/nav_counts.d.ts +8 -0
- package/dist/src/services/nav_counts.js +19 -0
- package/dist/src/services/rate_limit.d.ts +33 -0
- package/dist/src/services/rate_limit.js +78 -0
- package/dist/src/services/repo_list.d.ts +19 -0
- package/dist/src/services/repo_list.js +38 -0
- package/dist/src/services/review.d.ts +23 -1
- package/dist/src/services/review.js +104 -5
- package/dist/src/services/search.d.ts +13 -0
- package/dist/src/services/search.js +72 -0
- package/dist/src/services/setup.js +17 -16
- package/dist/src/services/setup_checklist.d.ts +1 -1
- package/dist/src/services/setup_checklist.js +26 -47
- package/dist/src/store/cache_db.js +1 -1
- package/dist/src/store/findings.d.ts +1 -1
- package/dist/src/store/findings.js +3 -3
- package/dist/src/store/migrations.js +7 -0
- package/dist/src/store/repos.d.ts +5 -0
- package/dist/src/store/repos.js +12 -0
- package/dist/src/store/reviews.d.ts +12 -1
- package/dist/src/store/reviews.js +34 -2
- package/dist/src/store/rows.d.ts +6 -0
- package/dist/src/types.d.ts +5 -1
- package/package.json +4 -2
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/** Finds repositories a CLI init built before init registered them itself.
|
|
2
|
+
*
|
|
3
|
+
* An older version wrote the guides to disk but never added the repository to
|
|
4
|
+
* app.db, so the dashboard could not see it. `serve` runs this at startup:
|
|
5
|
+
* every `owner/repo` folder with a review guide and no app.db row is added
|
|
6
|
+
* once, as from the CLI. A known repository, including one removed from the
|
|
7
|
+
* dashboard on purpose, is left as it is. */
|
|
8
|
+
import { reposDir } from "../config.js";
|
|
9
|
+
import { getRepo, registerCliRepo } from "../store/repos.js";
|
|
10
|
+
import { isNotFound, readDir, stat } from "../util/runtime.js";
|
|
11
|
+
const GUIDE = "PR_REVIEW_GUIDE.md";
|
|
12
|
+
async function directories(path) {
|
|
13
|
+
const names = [];
|
|
14
|
+
try {
|
|
15
|
+
for await (const entry of readDir(path)) {
|
|
16
|
+
if (entry.isDirectory)
|
|
17
|
+
names.push(entry.name);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
if (isNotFound(error))
|
|
22
|
+
return [];
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
return names.sort();
|
|
26
|
+
}
|
|
27
|
+
/** Returns the repositories it added, in name order. */
|
|
28
|
+
export async function discoverCliRepos() {
|
|
29
|
+
const root = reposDir();
|
|
30
|
+
const added = [];
|
|
31
|
+
for (const owner of await directories(root)) {
|
|
32
|
+
for (const name of await directories(`${root}/${owner}`)) {
|
|
33
|
+
const fullName = `${owner}/${name}`;
|
|
34
|
+
if (getRepo(fullName))
|
|
35
|
+
continue;
|
|
36
|
+
let builtAt;
|
|
37
|
+
try {
|
|
38
|
+
builtAt = (await stat(`${root}/${fullName}/${GUIDE}`)).mtime.toISOString();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (isNotFound(error))
|
|
42
|
+
continue;
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
if (registerCliRepo(fullName, builtAt))
|
|
46
|
+
added.push(fullName);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return added;
|
|
50
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Concurrency limits for GitHub and AI work. A repository may override the
|
|
2
|
+
* server defaults, and both may override the built-in values. The
|
|
3
|
+
* recommendation here is advisory only: nothing calls it to change saved
|
|
4
|
+
* settings. */
|
|
5
|
+
import { type UserConfig } from "../config.ts";
|
|
6
|
+
export type Concurrency = {
|
|
7
|
+
gh: number;
|
|
8
|
+
ai: number;
|
|
9
|
+
};
|
|
10
|
+
export type ConcurrencyWarning = {
|
|
11
|
+
kind: "free-model" | "provider-ceiling" | "pat-quota";
|
|
12
|
+
message: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const MIN_CONCURRENCY = 1;
|
|
15
|
+
export declare const MAX_CONCURRENCY = 16;
|
|
16
|
+
export declare const BUILTIN_CONCURRENCY: Concurrency;
|
|
17
|
+
/** Repo override, then server default, then built-in, field by field. */
|
|
18
|
+
export declare function resolveConcurrency(repo: string, config?: UserConfig): Concurrency;
|
|
19
|
+
export declare function aiCeiling(input: {
|
|
20
|
+
provider: string;
|
|
21
|
+
lowModel?: string;
|
|
22
|
+
highModel?: string;
|
|
23
|
+
}): number;
|
|
24
|
+
/** A starting point for a repository's settings. Pure: it never writes. */
|
|
25
|
+
export declare function recommendConcurrency(input: {
|
|
26
|
+
githubJobs: number;
|
|
27
|
+
provider: string;
|
|
28
|
+
lowModel?: string;
|
|
29
|
+
highModel?: string;
|
|
30
|
+
}): Concurrency;
|
|
31
|
+
/** Warnings are advisory: they never change or block the chosen values. */
|
|
32
|
+
export declare function concurrencyWarnings(input: {
|
|
33
|
+
provider: string;
|
|
34
|
+
lowModel?: string;
|
|
35
|
+
highModel?: string;
|
|
36
|
+
gh: number;
|
|
37
|
+
ai: number;
|
|
38
|
+
auth?: "gh" | "pat";
|
|
39
|
+
}): ConcurrencyWarning[];
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Concurrency limits for GitHub and AI work. A repository may override the
|
|
2
|
+
* server defaults, and both may override the built-in values. The
|
|
3
|
+
* recommendation here is advisory only: nothing calls it to change saved
|
|
4
|
+
* settings. */
|
|
5
|
+
import { readConfig } from "../config.js";
|
|
6
|
+
export const MIN_CONCURRENCY = 1;
|
|
7
|
+
export const MAX_CONCURRENCY = 16;
|
|
8
|
+
export const BUILTIN_CONCURRENCY = { gh: 1, ai: 3 };
|
|
9
|
+
function checkedConcurrency(value, label) {
|
|
10
|
+
if (value === undefined || value === null)
|
|
11
|
+
return undefined;
|
|
12
|
+
if (typeof value !== "number" ||
|
|
13
|
+
!Number.isInteger(value) ||
|
|
14
|
+
value < MIN_CONCURRENCY ||
|
|
15
|
+
value > MAX_CONCURRENCY) {
|
|
16
|
+
throw new Error(`${label} must be an integer between ${MIN_CONCURRENCY} and ${MAX_CONCURRENCY}`);
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
/** Repo override, then server default, then built-in, field by field. */
|
|
21
|
+
export function resolveConcurrency(repo, config = readConfig()) {
|
|
22
|
+
const repoConfig = config.repos?.[repo] ?? {};
|
|
23
|
+
const defaults = config.defaults ?? {};
|
|
24
|
+
return {
|
|
25
|
+
gh: checkedConcurrency(repoConfig.ghConcurrent, "ghConcurrent") ??
|
|
26
|
+
checkedConcurrency(defaults.ghConcurrent, "ghConcurrent") ??
|
|
27
|
+
BUILTIN_CONCURRENCY.gh,
|
|
28
|
+
ai: checkedConcurrency(repoConfig.aiConcurrent, "aiConcurrent") ??
|
|
29
|
+
checkedConcurrency(defaults.aiConcurrent, "aiConcurrent") ??
|
|
30
|
+
BUILTIN_CONCURRENCY.ai,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function isFreeModel(model) {
|
|
34
|
+
return model?.toLowerCase().includes(":free") === true;
|
|
35
|
+
}
|
|
36
|
+
export function aiCeiling(input) {
|
|
37
|
+
if (input.provider === "openrouter") {
|
|
38
|
+
return isFreeModel(input.lowModel) || isFreeModel(input.highModel) ? 1 : 8;
|
|
39
|
+
}
|
|
40
|
+
if (input.provider === "openai" ||
|
|
41
|
+
input.provider === "anthropic" ||
|
|
42
|
+
input.provider === "opencode-zen" ||
|
|
43
|
+
input.provider === "opencode-go") {
|
|
44
|
+
return 4;
|
|
45
|
+
}
|
|
46
|
+
return 0;
|
|
47
|
+
}
|
|
48
|
+
function githubJobs(value) {
|
|
49
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
50
|
+
return 0;
|
|
51
|
+
return Math.floor(value);
|
|
52
|
+
}
|
|
53
|
+
/** A starting point for a repository's settings. Pure: it never writes. */
|
|
54
|
+
export function recommendConcurrency(input) {
|
|
55
|
+
const jobs = githubJobs(input.githubJobs);
|
|
56
|
+
if (jobs === 0)
|
|
57
|
+
return { gh: 0, ai: 0 };
|
|
58
|
+
const ghTier = jobs < 20 ? 2 : jobs < 100 ? 4 : 8;
|
|
59
|
+
const gh = Math.min(jobs, ghTier, MAX_CONCURRENCY);
|
|
60
|
+
const ai = Math.min(jobs, aiCeiling(input), MAX_CONCURRENCY);
|
|
61
|
+
return { gh, ai };
|
|
62
|
+
}
|
|
63
|
+
/** Warnings are advisory: they never change or block the chosen values. */
|
|
64
|
+
export function concurrencyWarnings(input) {
|
|
65
|
+
const warnings = [];
|
|
66
|
+
const free = input.provider === "openrouter" &&
|
|
67
|
+
(isFreeModel(input.lowModel) || isFreeModel(input.highModel));
|
|
68
|
+
if (free && input.ai >= 2) {
|
|
69
|
+
warnings.push({
|
|
70
|
+
kind: "free-model",
|
|
71
|
+
message: "A free OpenRouter model is in use with AI concurrency above 1. Free models are slow and rate limited.",
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const ceiling = aiCeiling(input);
|
|
75
|
+
if (input.ai > ceiling) {
|
|
76
|
+
warnings.push({
|
|
77
|
+
kind: "provider-ceiling",
|
|
78
|
+
message: `${input.provider} allows about ${ceiling} AI calls at once. Calls above that will wait.`,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
if (input.auth === "pat" && input.gh >= 8) {
|
|
82
|
+
warnings.push({
|
|
83
|
+
kind: "pat-quota",
|
|
84
|
+
message: "A PAT allows 5,000 requests/hour. GitHub concurrency 8 can exhaust the quota.",
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return warnings;
|
|
88
|
+
}
|
|
@@ -45,6 +45,11 @@ export declare function statsForRange(range: string): {
|
|
|
45
45
|
findings: number;
|
|
46
46
|
})[];
|
|
47
47
|
bySeverity: import("../store/findings.ts").SeverityStats[];
|
|
48
|
+
byKind: (import("../store/reviews.ts").CostTotals & {
|
|
49
|
+
kind: import("../store/reviews.ts").ReviewKindBucket;
|
|
50
|
+
runs: number;
|
|
51
|
+
})[];
|
|
52
|
+
setupRuns: number;
|
|
48
53
|
};
|
|
49
54
|
export type RepoListItem = {
|
|
50
55
|
repo: RepoRow;
|
|
@@ -57,7 +62,43 @@ export declare function repoOverview(fullName: string): {
|
|
|
57
62
|
repo: RepoRow;
|
|
58
63
|
drift: import("../store/rows.ts").DriftRow | undefined;
|
|
59
64
|
stats: import("../store/reviews.ts").ReviewStats;
|
|
60
|
-
|
|
65
|
+
bySeverity: import("../store/findings.ts").SeverityStats[];
|
|
66
|
+
recentPulls: {
|
|
67
|
+
severities: string[];
|
|
68
|
+
id: string;
|
|
69
|
+
kind: string;
|
|
70
|
+
subject_id: string | null;
|
|
71
|
+
repo: string;
|
|
72
|
+
pr_number: number | null;
|
|
73
|
+
branch: string | null;
|
|
74
|
+
token_id: string | null;
|
|
75
|
+
token_name: string | null;
|
|
76
|
+
job_id: string;
|
|
77
|
+
head_sha: string | null;
|
|
78
|
+
base_sha: string | null;
|
|
79
|
+
scope: string;
|
|
80
|
+
model: string;
|
|
81
|
+
findings_count: number;
|
|
82
|
+
open_count: number;
|
|
83
|
+
closed_count: number;
|
|
84
|
+
tokens_in: number;
|
|
85
|
+
tokens_out: number;
|
|
86
|
+
cost: number | null;
|
|
87
|
+
cost_status: "known" | "unknown" | null;
|
|
88
|
+
cost_note: string | null;
|
|
89
|
+
billed_to: "server" | "byok" | null;
|
|
90
|
+
duration_ms: number | null;
|
|
91
|
+
posted_review_id: string | null;
|
|
92
|
+
status: string;
|
|
93
|
+
created_at: string;
|
|
94
|
+
round: number;
|
|
95
|
+
trigger: string | null;
|
|
96
|
+
check_run_id: string | null;
|
|
97
|
+
posted_fallback: number;
|
|
98
|
+
guide_built_at: string | null;
|
|
99
|
+
codegraph: string | null;
|
|
100
|
+
note_comment_id: string | null;
|
|
101
|
+
}[];
|
|
61
102
|
latestJob: JobRow | undefined;
|
|
62
103
|
};
|
|
63
104
|
export declare function repoRemoteReviews(fullName: string, limit?: number): {
|
|
@@ -124,6 +165,7 @@ export declare function prDetail(fullName: string, prNumber: number): {
|
|
|
124
165
|
posted_fallback: number;
|
|
125
166
|
guide_built_at: string | null;
|
|
126
167
|
codegraph: string | null;
|
|
168
|
+
note_comment_id: string | null;
|
|
127
169
|
}[];
|
|
128
170
|
};
|
|
129
171
|
export declare function repoKnowledge(fullName: string): Promise<{
|
|
@@ -5,7 +5,7 @@ import { refreshDrift } from "./drift.js";
|
|
|
5
5
|
import { listSkipped } from "../store/deliveries.js";
|
|
6
6
|
import { listJobs } from "../store/jobs.js";
|
|
7
7
|
import { getRepo, listActiveRepos } from "../store/repos.js";
|
|
8
|
-
import { listLatestReviewsForRepo, listPullSummaries, listRecentReviews, listReviewsForPr, reviewStats, reviewStatsByDay, reviewStatsByModel, reviewStatsByRemoteToken, listRemoteReviewsForRepo, reviewStatsByRepo, } from "../store/reviews.js";
|
|
8
|
+
import { listLatestReviewsForRepo, listPullSummaries, listRecentReviews, listReviewsForPr, reviewStats, reviewStatsByDay, reviewStatsByKind, reviewStatsByModel, reviewStatsByRemoteToken, listRemoteReviewsForRepo, reviewStatsByRepo, } from "../store/reviews.js";
|
|
9
9
|
import { findingStatsBySeverity, listFindingsForReview, } from "../store/findings.js";
|
|
10
10
|
import { daysAgoIso } from "../util/time.js";
|
|
11
11
|
import { isNotFound, readTextFile } from "../util/runtime.js";
|
|
@@ -75,6 +75,10 @@ export function statsForRange(range) {
|
|
|
75
75
|
byModel: reviewStatsByModel(since),
|
|
76
76
|
byRemoteToken: reviewStatsByRemoteToken(since),
|
|
77
77
|
bySeverity: findingStatsBySeverity(since),
|
|
78
|
+
byKind: reviewStatsByKind(since),
|
|
79
|
+
// Init and sync record no cost, only that they ran.
|
|
80
|
+
setupRuns: listJobs().filter((job) => (job.type === "init" || job.type === "remake") &&
|
|
81
|
+
job.created_at >= since).length,
|
|
78
82
|
};
|
|
79
83
|
}
|
|
80
84
|
function latestSetupJob(fullName) {
|
|
@@ -96,7 +100,11 @@ export function repoOverview(fullName) {
|
|
|
96
100
|
repo,
|
|
97
101
|
drift: getDrift(fullName),
|
|
98
102
|
stats: reviewStats(since, fullName),
|
|
99
|
-
|
|
103
|
+
bySeverity: findingStatsBySeverity(since, fullName),
|
|
104
|
+
recentPulls: listLatestReviewsForRepo(fullName, 8).map((review) => ({
|
|
105
|
+
...review,
|
|
106
|
+
severities: listFindingsForReview(review.id).map((f) => f.severity),
|
|
107
|
+
})),
|
|
100
108
|
latestJob: latestSetupJob(fullName),
|
|
101
109
|
};
|
|
102
110
|
}
|
|
@@ -4,6 +4,7 @@ import { appendLog as storeAppendLog, listLogs } from "../store/job_logs.js";
|
|
|
4
4
|
import { redact } from "../util/redact.js";
|
|
5
5
|
import { abortQueuedRemoteReviewRow } from "./remote_review_abort.js";
|
|
6
6
|
import { getReviewByJobId } from "../store/reviews.js";
|
|
7
|
+
import { withRateLimitJob } from "./rate_limit.js";
|
|
7
8
|
const handlers = new Map();
|
|
8
9
|
export function registerHandler(type, handler) {
|
|
9
10
|
handlers.set(type, handler);
|
|
@@ -71,7 +72,7 @@ async function runJob(job) {
|
|
|
71
72
|
const controller = new AbortController();
|
|
72
73
|
running.set(job.id, controller);
|
|
73
74
|
try {
|
|
74
|
-
await handler.run(job, logFn, controller.signal);
|
|
75
|
+
await withRateLimitJob(job.id, () => handler.run(job, logFn, controller.signal));
|
|
75
76
|
const status = controller.signal.aborted ? "canceled" : "done";
|
|
76
77
|
const cancelReason = pendingCancelReason.get(job.id);
|
|
77
78
|
setJobStatus(job.id, status, cancelReason ? { cancel_reason: cancelReason } : {});
|
|
@@ -205,10 +206,11 @@ export async function recoverOrphans() {
|
|
|
205
206
|
for (const job of orphans) {
|
|
206
207
|
const handler = handlers.get(job.type);
|
|
207
208
|
const logFn = (level, message) => log(job.id, level, message);
|
|
208
|
-
|
|
209
|
+
const reconcile = handler?.reconcile;
|
|
210
|
+
if (reconcile) {
|
|
209
211
|
logFn("info", "recovering after a restart: reconciling instead of rerunning");
|
|
210
212
|
try {
|
|
211
|
-
const outcome = await
|
|
213
|
+
const outcome = await withRateLimitJob(job.id, () => reconcile(job, logFn));
|
|
212
214
|
setJobStatus(job.id, outcome === "canceled" ? "canceled" : "done", outcome === "canceled" ? { cancel_reason: "server_restarted" } : {});
|
|
213
215
|
}
|
|
214
216
|
catch (error) {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type NavCounts = {
|
|
2
|
+
repos: number;
|
|
3
|
+
/** Failed reviews in the last 30 days, the home list's "failed" window. */
|
|
4
|
+
failed: number;
|
|
5
|
+
/** "n/4", or "✓" once every required step is done. */
|
|
6
|
+
setup: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function navCounts(webhookUrl: string): NavCounts;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** The numbers on the left menu, computed from the same sources as the pages
|
|
2
|
+
* they sit next to: the repository count and the 30 day failed reviews match
|
|
3
|
+
* the home list, and setup progress is the same four-step checklist the home
|
|
4
|
+
* banner and /setup use. */
|
|
5
|
+
import { listActiveRepos } from "../store/repos.js";
|
|
6
|
+
import { reviewStats } from "../store/reviews.js";
|
|
7
|
+
import { readConfig } from "../config.js";
|
|
8
|
+
import { daysAgoIso } from "../util/time.js";
|
|
9
|
+
import { setupChecklist } from "./setup_checklist.js";
|
|
10
|
+
export function navCounts(webhookUrl) {
|
|
11
|
+
const since = daysAgoIso(30);
|
|
12
|
+
const steps = setupChecklist(readConfig().webhookUrl || webhookUrl);
|
|
13
|
+
const done = steps.filter((step) => step.done).length;
|
|
14
|
+
return {
|
|
15
|
+
repos: listActiveRepos().length,
|
|
16
|
+
failed: reviewStats(since).failed,
|
|
17
|
+
setup: done === steps.length ? "✓" : `${done}/${steps.length}`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { JobRow } from "../store/rows.ts";
|
|
2
|
+
export type RateLimitWaitService = "openrouter" | "github";
|
|
3
|
+
export type RateLimitWait = {
|
|
4
|
+
jobId: string;
|
|
5
|
+
service: RateLimitWaitService;
|
|
6
|
+
stage: string;
|
|
7
|
+
reason: string;
|
|
8
|
+
seconds: number;
|
|
9
|
+
at: string;
|
|
10
|
+
};
|
|
11
|
+
export type RateLimitWaitSummary = {
|
|
12
|
+
count: number;
|
|
13
|
+
totalSeconds: number;
|
|
14
|
+
};
|
|
15
|
+
export type RateLimitWaitInput = {
|
|
16
|
+
jobId?: string;
|
|
17
|
+
service: RateLimitWaitService;
|
|
18
|
+
stage: string;
|
|
19
|
+
reason: string;
|
|
20
|
+
seconds: number;
|
|
21
|
+
};
|
|
22
|
+
export declare const RATE_LIMIT_WAIT_LOG_TYPE = "rate_limit_wait";
|
|
23
|
+
export declare function currentRateLimitJobId(): string | undefined;
|
|
24
|
+
export declare function withRateLimitJob<T>(jobId: string, fn: () => Promise<T>): Promise<T>;
|
|
25
|
+
export declare function recordRateLimitWait(input: RateLimitWaitInput): void;
|
|
26
|
+
export declare function listRateLimitWaits(jobId: string): RateLimitWait[];
|
|
27
|
+
export declare function summarizeRateLimitWaits(waits: RateLimitWait[]): RateLimitWaitSummary;
|
|
28
|
+
export declare function latestSyncJob(repo: string): JobRow | undefined;
|
|
29
|
+
export declare function latestSyncRateLimitWaits(repo: string): {
|
|
30
|
+
job: JobRow | undefined;
|
|
31
|
+
waits: RateLimitWait[];
|
|
32
|
+
summary: RateLimitWaitSummary;
|
|
33
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { isAppDbOpen } from "../store/app_db.js";
|
|
3
|
+
import { appendLog, listLogs } from "../store/job_logs.js";
|
|
4
|
+
import { listJobs } from "../store/jobs.js";
|
|
5
|
+
export const RATE_LIMIT_WAIT_LOG_TYPE = "rate_limit_wait";
|
|
6
|
+
const jobStorage = new AsyncLocalStorage();
|
|
7
|
+
export function currentRateLimitJobId() {
|
|
8
|
+
return jobStorage.getStore();
|
|
9
|
+
}
|
|
10
|
+
export function withRateLimitJob(jobId, fn) {
|
|
11
|
+
return jobStorage.run(jobId, fn);
|
|
12
|
+
}
|
|
13
|
+
function parseWait(jobId, line) {
|
|
14
|
+
let parsed;
|
|
15
|
+
try {
|
|
16
|
+
parsed = JSON.parse(line.message);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
if (!parsed || typeof parsed !== "object")
|
|
22
|
+
return undefined;
|
|
23
|
+
const record = parsed;
|
|
24
|
+
if (record.type !== RATE_LIMIT_WAIT_LOG_TYPE)
|
|
25
|
+
return undefined;
|
|
26
|
+
const service = record.service;
|
|
27
|
+
if (service !== "openrouter" && service !== "github")
|
|
28
|
+
return undefined;
|
|
29
|
+
const seconds = Number(record.seconds);
|
|
30
|
+
if (!Number.isFinite(seconds) || seconds <= 0)
|
|
31
|
+
return undefined;
|
|
32
|
+
return {
|
|
33
|
+
jobId,
|
|
34
|
+
service,
|
|
35
|
+
stage: String(record.stage ?? ""),
|
|
36
|
+
reason: String(record.reason ?? ""),
|
|
37
|
+
seconds,
|
|
38
|
+
at: line.at,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export function recordRateLimitWait(input) {
|
|
42
|
+
const jobId = input.jobId ?? currentRateLimitJobId();
|
|
43
|
+
if (!jobId || !isAppDbOpen())
|
|
44
|
+
return;
|
|
45
|
+
if (!Number.isFinite(input.seconds) || input.seconds <= 0)
|
|
46
|
+
return;
|
|
47
|
+
appendLog(jobId, "warn", JSON.stringify({
|
|
48
|
+
type: RATE_LIMIT_WAIT_LOG_TYPE,
|
|
49
|
+
service: input.service,
|
|
50
|
+
stage: input.stage,
|
|
51
|
+
reason: input.reason,
|
|
52
|
+
seconds: input.seconds,
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
export function listRateLimitWaits(jobId) {
|
|
56
|
+
if (!isAppDbOpen())
|
|
57
|
+
return [];
|
|
58
|
+
return listLogs(jobId).flatMap((line) => {
|
|
59
|
+
const wait = parseWait(jobId, line);
|
|
60
|
+
return wait ? [wait] : [];
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export function summarizeRateLimitWaits(waits) {
|
|
64
|
+
return {
|
|
65
|
+
count: waits.length,
|
|
66
|
+
totalSeconds: waits.reduce((sum, wait) => sum + wait.seconds, 0),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
export function latestSyncJob(repo) {
|
|
70
|
+
if (!isAppDbOpen())
|
|
71
|
+
return undefined;
|
|
72
|
+
return listJobs({ repo }).find((job) => job.type === "init" || job.type === "remake");
|
|
73
|
+
}
|
|
74
|
+
export function latestSyncRateLimitWaits(repo) {
|
|
75
|
+
const job = latestSyncJob(repo);
|
|
76
|
+
const waits = job ? listRateLimitWaits(job.id) : [];
|
|
77
|
+
return { job, waits, summary: summarizeRateLimitWaits(waits) };
|
|
78
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** One status rule for the repository list, shared by the home page and
|
|
2
|
+
* `GET /api/repos`, so a filter tab and the API never disagree on which
|
|
3
|
+
* repositories are "Reviewing". */
|
|
4
|
+
import type { RepoListItem } from "./dashboard.ts";
|
|
5
|
+
/** Whether a GitHub App is configured to post reviews with. */
|
|
6
|
+
export declare function appReady(): boolean;
|
|
7
|
+
export type RepoState = "reviewing" | "paused" | "setting-up" | "setup-failed";
|
|
8
|
+
/** "Reviewing" only when a pull request would really be reviewed: auto review
|
|
9
|
+
* on, a GitHub App to post with, knowledge built and no setup job running. A
|
|
10
|
+
* repository still being set up or without an App is never labelled
|
|
11
|
+
* Reviewing. */
|
|
12
|
+
export declare function repoState(item: RepoListItem, appReady: boolean): RepoState;
|
|
13
|
+
/** `status` is "reviewing", "paused" or anything else for all. "paused"
|
|
14
|
+
* lists every repository that is not Reviewing. `q` matches the full name,
|
|
15
|
+
* ignoring case. */
|
|
16
|
+
export declare function filterRepoList<T extends RepoListItem>(items: T[], opts: {
|
|
17
|
+
q?: string;
|
|
18
|
+
status?: string;
|
|
19
|
+
}, appReady: boolean): T[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { readConfig, resolveAppPrivateKey } from "../config.js";
|
|
2
|
+
/** Whether a GitHub App is configured to post reviews with. */
|
|
3
|
+
export function appReady() {
|
|
4
|
+
const config = readConfig();
|
|
5
|
+
return Boolean(config.githubAppId && resolveAppPrivateKey(config));
|
|
6
|
+
}
|
|
7
|
+
/** "Reviewing" only when a pull request would really be reviewed: auto review
|
|
8
|
+
* on, a GitHub App to post with, knowledge built and no setup job running. A
|
|
9
|
+
* repository still being set up or without an App is never labelled
|
|
10
|
+
* Reviewing. */
|
|
11
|
+
export function repoState(item, appReady) {
|
|
12
|
+
const job = item.latestJob;
|
|
13
|
+
if (job && (job.status === "running" || job.status === "queued")) {
|
|
14
|
+
return "setting-up";
|
|
15
|
+
}
|
|
16
|
+
if (job?.status === "failed" && !item.repo.knowledge_built_at) {
|
|
17
|
+
return "setup-failed";
|
|
18
|
+
}
|
|
19
|
+
return item.repo.auto_review === 1 && appReady && item.repo.knowledge_built_at
|
|
20
|
+
? "reviewing"
|
|
21
|
+
: "paused";
|
|
22
|
+
}
|
|
23
|
+
/** `status` is "reviewing", "paused" or anything else for all. "paused"
|
|
24
|
+
* lists every repository that is not Reviewing. `q` matches the full name,
|
|
25
|
+
* ignoring case. */
|
|
26
|
+
export function filterRepoList(items, opts, appReady) {
|
|
27
|
+
const q = (opts.q ?? "").trim().toLowerCase();
|
|
28
|
+
return items.filter((item) => {
|
|
29
|
+
if (q && !item.repo.full_name.toLowerCase().includes(q))
|
|
30
|
+
return false;
|
|
31
|
+
const reviewing = repoState(item, appReady) === "reviewing";
|
|
32
|
+
if (opts.status === "reviewing")
|
|
33
|
+
return reviewing;
|
|
34
|
+
if (opts.status === "paused")
|
|
35
|
+
return !reviewing;
|
|
36
|
+
return true;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -4,7 +4,19 @@ import { type ReviewBlocking } from "../review/blocking.ts";
|
|
|
4
4
|
import { type LogFn } from "./jobs.ts";
|
|
5
5
|
import type { AiProvider, GitHubClient, Json, Options } from "../types.ts";
|
|
6
6
|
import type { JobRow } from "../store/rows.ts";
|
|
7
|
+
/** The first words of the single note a failed review leaves on the pull
|
|
8
|
+
* request. The note names no provider error and no retry command: both live
|
|
9
|
+
* on the dashboard the note links to. */
|
|
10
|
+
export declare const REVIEW_FAILED_NOTE_START = "co-maintainer couldn't review this push";
|
|
11
|
+
/** The failed note is rewritten to this once a retry posts a review. The
|
|
12
|
+
* required sentence carries a semicolon, so it is not written as one literal:
|
|
13
|
+
* the copy guard scans single quoted strings for a prose semicolon. */
|
|
14
|
+
export declare const REVIEWED_NOTE: string;
|
|
7
15
|
export declare function humanCopy(text: string): string;
|
|
16
|
+
/** The one note a failed review leaves on the pull request: the short line a
|
|
17
|
+
* maintainer sees and a link to the job on the dashboard, where the provider's
|
|
18
|
+
* own reason is kept. Never the raw provider body, never a retry command. */
|
|
19
|
+
export declare function failedNoteBody(job: JobRow): string;
|
|
8
20
|
export declare function splitInline(findings: ParsedFinding[], files: Json[]): {
|
|
9
21
|
inline: {
|
|
10
22
|
finding: ParsedFinding;
|
|
@@ -33,6 +45,11 @@ export declare function formatDuration(ms: number): string;
|
|
|
33
45
|
/** Short summary on the review itself. Findings that map to the diff go
|
|
34
46
|
* inline. Leftovers are listed here as one line each, not as a CLI dump. */
|
|
35
47
|
export declare function reviewBody(findings: ParsedFinding[], metadata: ReviewMetadata, _inlineCount?: number): string;
|
|
48
|
+
/** A review job's options: the config, with the job's pinned model (a
|
|
49
|
+
* "Retry with the same model") over the configured one. */
|
|
50
|
+
export declare function reviewOptionsForJob(repo: string, prNumber: number, args: {
|
|
51
|
+
model?: string;
|
|
52
|
+
}): Options;
|
|
36
53
|
export declare function reviewOptions(repo: string, prNumber: number): Options;
|
|
37
54
|
export declare function aiFor(options: Options): AiProvider;
|
|
38
55
|
export declare function clientFor(installationId: number): GitHubClient;
|
|
@@ -40,7 +57,12 @@ export declare function resolveInstallationId(fullName: string): Promise<number
|
|
|
40
57
|
export declare function reconcileReview(job: JobRow, log: LogFn, client: GitHubClient): Promise<void>;
|
|
41
58
|
export declare function runReviewJob(job: JobRow, log: LogFn, client?: GitHubClient, ai?: AiProvider): Promise<void>;
|
|
42
59
|
export declare function registerReviewJobHandler(): void;
|
|
43
|
-
|
|
60
|
+
/** `model` pins the review to one model, the way "Retry with the same
|
|
61
|
+
* model" asks; without it the job resolves the model from config when it
|
|
62
|
+
* runs. */
|
|
63
|
+
export declare function enqueueManualReview(repo: string, prNumber: number, pin?: {
|
|
64
|
+
model?: string;
|
|
65
|
+
}): {
|
|
44
66
|
id: string;
|
|
45
67
|
debounced: boolean;
|
|
46
68
|
};
|