co-maintainer 0.6.3 → 0.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/THIRD_PARTY_NOTICES +161 -0
  2. package/dist/package.json +4 -2
  3. package/dist/src/ai/batch.js +7 -0
  4. package/dist/src/cli/args.js +21 -3
  5. package/dist/src/cli/commands/registry.js +38 -3
  6. package/dist/src/cli/commands/serve.js +31 -3
  7. package/dist/src/cli/commands/set.js +54 -0
  8. package/dist/src/config.d.ts +14 -0
  9. package/dist/src/github/client.js +13 -0
  10. package/dist/src/github/permissions.js +8 -0
  11. package/dist/src/server/api/jobs.js +8 -1
  12. package/dist/src/server/api/repos.js +73 -11
  13. package/dist/src/server/api/settings.js +6 -0
  14. package/dist/src/server/app.d.ts +5 -0
  15. package/dist/src/server/app.js +7 -0
  16. package/dist/src/server/http.d.ts +3 -0
  17. package/dist/src/server/http.js +5 -0
  18. package/dist/src/server/pages/activity.js +412 -19
  19. package/dist/src/server/pages/add_repo.js +6 -1
  20. package/dist/src/server/pages/analytics.js +99 -31
  21. package/dist/src/server/pages/catalog.d.ts +1 -0
  22. package/dist/src/server/pages/catalog.js +145 -0
  23. package/dist/src/server/pages/client.d.ts +1 -1
  24. package/dist/src/server/pages/client.js +1 -1
  25. package/dist/src/server/pages/home.d.ts +14 -4
  26. package/dist/src/server/pages/home.js +83 -49
  27. package/dist/src/server/pages/icons.d.ts +3 -0
  28. package/dist/src/server/pages/icons.js +3 -0
  29. package/dist/src/server/pages/knowledge.js +10 -5
  30. package/dist/src/server/pages/layout.d.ts +19 -3
  31. package/dist/src/server/pages/layout.js +156 -33
  32. package/dist/src/server/pages/pr.js +4 -3
  33. package/dist/src/server/pages/rate_limit_waits.d.ts +5 -0
  34. package/dist/src/server/pages/rate_limit_waits.js +74 -0
  35. package/dist/src/server/pages/repo.js +100 -66
  36. package/dist/src/server/pages/repo_prs.js +4 -3
  37. package/dist/src/server/pages/repo_remote.js +4 -3
  38. package/dist/src/server/pages/repo_settings.d.ts +2 -2
  39. package/dist/src/server/pages/repo_settings.js +420 -46
  40. package/dist/src/server/pages/router.d.ts +5 -0
  41. package/dist/src/server/pages/router.js +82 -31
  42. package/dist/src/server/pages/settings.d.ts +10 -1
  43. package/dist/src/server/pages/settings.js +350 -206
  44. package/dist/src/server/pages/setup.d.ts +2 -5
  45. package/dist/src/server/pages/setup.js +21 -23
  46. package/dist/src/server/pages/styles.d.ts +1 -1
  47. package/dist/src/server/pages/styles.js +1 -1
  48. package/dist/src/server/pages/ui.d.ts +117 -0
  49. package/dist/src/server/pages/ui.js +166 -0
  50. package/dist/src/services/cli_repos.d.ts +2 -0
  51. package/dist/src/services/cli_repos.js +50 -0
  52. package/dist/src/services/concurrency.d.ts +39 -0
  53. package/dist/src/services/concurrency.js +88 -0
  54. package/dist/src/services/dashboard.d.ts +43 -1
  55. package/dist/src/services/dashboard.js +10 -2
  56. package/dist/src/services/jobs.js +5 -3
  57. package/dist/src/services/nav_counts.d.ts +8 -0
  58. package/dist/src/services/nav_counts.js +19 -0
  59. package/dist/src/services/rate_limit.d.ts +33 -0
  60. package/dist/src/services/rate_limit.js +78 -0
  61. package/dist/src/services/repo_list.d.ts +19 -0
  62. package/dist/src/services/repo_list.js +38 -0
  63. package/dist/src/services/review.d.ts +23 -1
  64. package/dist/src/services/review.js +165 -35
  65. package/dist/src/services/search.d.ts +13 -0
  66. package/dist/src/services/search.js +72 -0
  67. package/dist/src/services/setup.js +14 -4
  68. package/dist/src/services/setup_checklist.d.ts +1 -1
  69. package/dist/src/services/setup_checklist.js +26 -47
  70. package/dist/src/store/findings.d.ts +1 -1
  71. package/dist/src/store/findings.js +3 -3
  72. package/dist/src/store/migrations.js +7 -0
  73. package/dist/src/store/repos.d.ts +5 -0
  74. package/dist/src/store/repos.js +12 -0
  75. package/dist/src/store/reviews.d.ts +12 -1
  76. package/dist/src/store/reviews.js +34 -2
  77. package/dist/src/store/rows.d.ts +6 -0
  78. package/package.json +4 -2
@@ -17,13 +17,21 @@ import { matchRepeat } from "../pr/rounds.js";
17
17
  import { readConfig, resolveAppPrivateKey, resolvedAiToken, } from "../config.js";
18
18
  import { outsideCode, redact } from "../util/redact.js";
19
19
  import { getRepo, setInstallationId } from "../store/repos.js";
20
- import { getReviewByJobId, insertReview, latestPostedReview, setReviewScope, setReviewStatus, } from "../store/reviews.js";
20
+ import { findNoteCommentId, getReviewByJobId, insertReview, latestPostedReview, setReviewScope, setReviewStatus, } from "../store/reviews.js";
21
21
  import { insertFinding, listCarryableFindingsForReview, listFindingsForPr, listFindingsForReview, setFindingPosted, } from "../store/findings.js";
22
22
  import { getOrCreatePrSubject, getSubjectRevision, parseRevisionFiles, parseVisiblePaths, saveSubjectRevision, } from "../store/subjects.js";
23
23
  import { enqueue, registerHandler } from "./jobs.js";
24
24
  import { requestedReviewBlocked } from "./webhook.js";
25
25
  import { getEnv } from "../util/runtime.js";
26
26
  const ACCESS_DENIED_BODY = "The App does not have access to review this pull request.";
27
+ /** The first words of the single note a failed review leaves on the pull
28
+ * request. The note names no provider error and no retry command: both live
29
+ * on the dashboard the note links to. */
30
+ export const REVIEW_FAILED_NOTE_START = "co-maintainer couldn't review this push";
31
+ /** The failed note is rewritten to this once a retry posts a review. The
32
+ * required sentence carries a semicolon, so it is not written as one literal:
33
+ * the copy guard scans single quoted strings for a prose semicolon. */
34
+ export const REVIEWED_NOTE = "co-maintainer reviewed this push" + "; the review is below.";
27
35
  export function humanCopy(text) {
28
36
  // The semicolon is prose and always goes. The em dash is left alone here:
29
37
  // this function also sanitizes a finding title, and a title posted before
@@ -43,6 +51,69 @@ function post(client, endpoint, body) {
43
51
  }
44
52
  return client.write(endpoint, body);
45
53
  }
54
+ /** The dashboard's public origin, when one is configured, so a failure note
55
+ * links to a page a reader can open. No saved address means a root-relative
56
+ * link, which still resolves for anyone on the dashboard. */
57
+ function dashboardOrigin() {
58
+ const url = readConfig().webhookUrl;
59
+ if (!url)
60
+ return "";
61
+ try {
62
+ return new URL(url).origin;
63
+ }
64
+ catch {
65
+ return "";
66
+ }
67
+ }
68
+ /** The one note a failed review leaves on the pull request: the short line a
69
+ * maintainer sees and a link to the job on the dashboard, where the provider's
70
+ * own reason is kept. Never the raw provider body, never a retry command. */
71
+ export function failedNoteBody(job) {
72
+ return (`${REVIEW_FAILED_NOTE_START}. See the error on the dashboard: ` +
73
+ `${dashboardOrigin()}/activity/${job.id}`);
74
+ }
75
+ /** The note already left for this push, if any, so a second failure or a retry
76
+ * edits that one instead of opening a duplicate. */
77
+ function existingNoteId(job) {
78
+ const review = getReviewByJobId(job.id);
79
+ return (review?.note_comment_id ??
80
+ findNoteCommentId(job.repo, job.pr_number ?? 0, review?.head_sha ?? null));
81
+ }
82
+ /** A failed attempt ends in `failed` with its cost, and leaves exactly one
83
+ * note linking the dashboard job. Posting that note is best effort: a GitHub
84
+ * refusal there must not hide the AI failure itself. */
85
+ async function recordFailedReview(github, job, reviewId, costTally, log) {
86
+ setReviewStatus(reviewId, "failed", {
87
+ ...costColumns(settle(costTally)),
88
+ });
89
+ if (job.pr_number === null || existingNoteId(job))
90
+ return;
91
+ try {
92
+ const posted = await post(github, `repos/${job.repo}/issues/${job.pr_number}/comments`, { body: failedNoteBody(job) });
93
+ setReviewStatus(reviewId, "failed", {
94
+ note_comment_id: String(posted.id ?? ""),
95
+ });
96
+ }
97
+ catch (error) {
98
+ log("info", `could not post the failure note: ${redact(String(error))}`);
99
+ }
100
+ }
101
+ /** A retry that posted a review rewrites the earlier failure note to say so.
102
+ * The note is not deleted, and no second note is opened. */
103
+ async function resolveFailureNote(github, job, reviewId, log) {
104
+ const noteId = existingNoteId(job);
105
+ if (!noteId)
106
+ return;
107
+ try {
108
+ await post(github, `repos/${job.repo}/issues/comments/${noteId}`, {
109
+ body: REVIEWED_NOTE,
110
+ });
111
+ setReviewStatus(reviewId, "posted", { note_comment_id: noteId });
112
+ }
113
+ catch (error) {
114
+ log("info", `could not update the failure note: ${redact(String(error))}`);
115
+ }
116
+ }
46
117
  export function splitInline(findings, files) {
47
118
  const patches = new Map(files.map((file) => [
48
119
  String(file.filename ?? ""),
@@ -129,6 +200,44 @@ function inlineCommentBody(finding, suggestion = false) {
129
200
  return heading;
130
201
  return `${heading}\n\n${rest}`;
131
202
  }
203
+ function rowFinding(row) {
204
+ return {
205
+ path: row.path ?? "",
206
+ from: row.line_from ?? 0,
207
+ to: row.line_to ?? row.line_from ?? 0,
208
+ heading: row.title,
209
+ excerpt: row.body_md,
210
+ };
211
+ }
212
+ function sameBody(a, b) {
213
+ const clean = (text) => text.replace(/\r\n/g, "\n").trim();
214
+ return clean(a) === clean(b);
215
+ }
216
+ /** Whether a posted comment already says what this finding says. The comment
217
+ * may have gone out with its suggestion block, so both forms count. */
218
+ function repeatsComment(row, posted) {
219
+ const finding = rowFinding(row);
220
+ return (sameBody(posted, inlineCommentBody(finding)) ||
221
+ sameBody(posted, inlineCommentBody(finding, true)));
222
+ }
223
+ /** The pull request's review comments by id. An unreadable list comes back
224
+ * empty, so a repeat is posted again rather than going unsaid. */
225
+ async function postedCommentBodies(client, job, log) {
226
+ try {
227
+ const listed = await client.pages(`repos/${job.repo}/pulls/${job.pr_number}/comments`);
228
+ return new Map(listed.map((item) => [String(item.id ?? ""), String(item.body ?? "")]));
229
+ }
230
+ catch (error) {
231
+ log("info", `could not read the earlier comments: ${redact(String(error))}`);
232
+ return new Map();
233
+ }
234
+ }
235
+ /** A review job's options: the config, with the job's pinned model (a
236
+ * "Retry with the same model") over the configured one. */
237
+ export function reviewOptionsForJob(repo, prNumber, args) {
238
+ const options = reviewOptions(repo, prNumber);
239
+ return args.model ? { ...options, highModel: args.model } : options;
240
+ }
132
241
  export function reviewOptions(repo, prNumber) {
133
242
  const config = readConfig();
134
243
  return {
@@ -155,7 +264,7 @@ export function reviewOptions(repo, prNumber) {
155
264
  includeHowRepoWorks: true,
156
265
  onlyRequestChangedPr: false,
157
266
  useCodegraph: getRepo(repo)?.use_codegraph === 1,
158
- reviewBlocking: reviewBlockingFrom(config.reviewBlocking),
267
+ reviewBlocking: reviewBlockingFrom(config.repos?.[repo]?.reviewBlocking ?? config.reviewBlocking),
159
268
  reviewSystemPrompt: config.repos?.[repo]?.reviewSystemPrompt,
160
269
  };
161
270
  }
@@ -273,23 +382,31 @@ async function finishCheck(client, job, checkRunId, conclusion, title, findings,
273
382
  }
274
383
  async function publish(client, job, reviewId, headSha, files, log, metadata, mode = DEFAULT_REVIEW_BLOCKING) {
275
384
  const stored = listFindingsForReview(reviewId);
276
- const replies = stored.filter((row) => row.thread_comment_id);
277
- const freshRows = stored.filter((row) => row.state === "new" && !row.thread_comment_id);
278
- const fresh = freshRows.map((row) => ({
279
- path: row.path ?? "",
280
- from: row.line_from ?? 0,
281
- to: row.line_to ?? row.line_from ?? 0,
282
- heading: row.title,
283
- excerpt: row.body_md,
284
- }));
385
+ // GitHub wraps every `in_reply_to` comment in a review of its own, so a round
386
+ // posts no replies. A repeat stays on its thread and in the summary, and a
387
+ // finding whose text changed goes inline on the one review.
388
+ const threaded = stored.filter((row) => row.thread_comment_id);
389
+ const earlier = threaded.length > 0
390
+ ? await postedCommentBodies(client, job, log)
391
+ : new Map();
392
+ const repeats = threaded.filter((row) => {
393
+ const posted = earlier.get(row.thread_comment_id ?? "");
394
+ return posted !== undefined && repeatsComment(row, posted);
395
+ });
396
+ const freshRows = stored.filter((row) => !repeats.includes(row) && (row.state === "new" || row.thread_comment_id));
397
+ const fresh = freshRows.map(rowFinding);
285
398
  const { inline, leftover } = splitInline(fresh, files);
286
- const anchorByRow = new Map();
287
- for (const { finding, anchor } of inline) {
399
+ const commentByRow = new Map();
400
+ for (const { finding, anchor, suggestion } of inline) {
288
401
  const row = freshRows.find((item) => item.path === finding.path &&
289
402
  item.line_from === finding.from &&
290
403
  item.line_to === finding.to);
291
- if (row)
292
- anchorByRow.set(row.id, anchor);
404
+ if (row) {
405
+ commentByRow.set(row.id, {
406
+ anchor,
407
+ body: inlineCommentBody(finding, suggestion),
408
+ });
409
+ }
293
410
  }
294
411
  const freshSummaryKeys = new Set([...leftover, ...inline.map(({ finding }) => finding)].map((finding) => `${finding.path}\0${finding.from}\0${finding.to}`));
295
412
  const summaryFindings = [
@@ -309,7 +426,7 @@ async function publish(client, job, reviewId, headSha, files, log, metadata, mod
309
426
  excerpt: row.body_md,
310
427
  })),
311
428
  ];
312
- const body = reviewBody(summaryFindings, metadata, inline.length + replies.length);
429
+ const body = reviewBody(summaryFindings, metadata, inline.length + repeats.length);
313
430
  const comments = inline.map(({ finding, anchor, suggestion }) => ({
314
431
  path: finding.path,
315
432
  body: inlineCommentBody(finding, suggestion),
@@ -324,19 +441,8 @@ async function publish(client, job, reviewId, headSha, files, log, metadata, mod
324
441
  comments.some((comment) => hasForbiddenCopy(comment.body))) {
325
442
  throw new Error("review body contains forbidden copy characters");
326
443
  }
327
- for (const row of replies) {
328
- const text = inlineCommentBody({
329
- path: row.path ?? "",
330
- from: row.line_from ?? 0,
331
- to: row.line_to ?? row.line_from ?? 0,
332
- heading: row.title,
333
- excerpt: row.body_md,
334
- });
335
- const posted = await post(client, `repos/${job.repo}/pulls/${job.pr_number}/comments`, {
336
- body: text,
337
- in_reply_to: Number(row.thread_comment_id),
338
- });
339
- setFindingPosted(row.id, String(posted.id ?? ""), row.thread_comment_id ?? undefined);
444
+ for (const row of repeats) {
445
+ setFindingPosted(row.id, row.thread_comment_id ?? "");
340
446
  }
341
447
  const payload = {
342
448
  commit_id: headSha,
@@ -355,11 +461,13 @@ async function publish(client, job, reviewId, headSha, files, log, metadata, mod
355
461
  try {
356
462
  const listed = await client.pages(`repos/${job.repo}/pulls/${job.pr_number}/comments`);
357
463
  for (const row of stored) {
358
- const anchor = anchorByRow.get(row.id);
359
- if (row.posted_comment_id || !row.path || !anchor)
464
+ const comment = commentByRow.get(row.id);
465
+ if (row.posted_comment_id || !row.path || !comment)
360
466
  continue;
361
467
  const hit = listed.find((item) => String(item.path ?? "") === row.path &&
362
- Number(item.line ?? item.original_line ?? 0) === anchor.line);
468
+ Number(item.line ?? item.original_line ?? 0) ===
469
+ comment.anchor.line &&
470
+ sameBody(String(item.body ?? ""), comment.body));
363
471
  if (hit?.id)
364
472
  setFindingPosted(row.id, String(hit.id));
365
473
  }
@@ -383,6 +491,13 @@ async function publish(client, job, reviewId, headSha, files, log, metadata, mod
383
491
  });
384
492
  return;
385
493
  }
494
+ if (isAccessDenied(error)) {
495
+ // The AI result and its cost are already stored. Only the post failed,
496
+ // so this is not an AI failure and nothing claims the review was posted.
497
+ setReviewStatus(reviewId, "not_posted");
498
+ log("info", `GitHub rejected the review post: ${redact(String(error))}`);
499
+ throw error;
500
+ }
386
501
  setReviewStatus(reviewId, "failed");
387
502
  throw error;
388
503
  }
@@ -460,8 +575,8 @@ async function runReviewJobCore(job, log, client, ai) {
460
575
  await reconcileReview(job, log, github);
461
576
  return;
462
577
  }
463
- const options = reviewOptions(job.repo, job.pr_number);
464
578
  const args = JSON.parse(job.args || "{}");
579
+ const options = reviewOptionsForJob(job.repo, job.pr_number, args);
465
580
  const pr = await github.request(`repos/${job.repo}/pulls/${job.pr_number}`);
466
581
  if (args.trigger === "request-comment" && !existing) {
467
582
  const blocked = requestedReviewBlocked(job.repo, pr);
@@ -598,7 +713,17 @@ async function runReviewJobCore(job, log, client, ai) {
598
713
  extras.carryPrompt = buildCarryPromptSection(carryItems, revision);
599
714
  }
600
715
  const costTally = emptyTally();
601
- const response = await runReviewEngine(github, options, async (call) => addResponseCost(costTally, call), snapshot, ai ?? aiFor(options), (message) => log("info", message), extras);
716
+ let response;
717
+ try {
718
+ response = await runReviewEngine(github, options, async (call) => addResponseCost(costTally, call), snapshot, ai ?? aiFor(options), (message) => log("info", message), extras);
719
+ }
720
+ catch (error) {
721
+ // A provider throw or an empty/unusable answer is a failed attempt, not a
722
+ // review that found nothing. Its cost is kept when the provider reported
723
+ // one, and the pull request gets one note pointing at the dashboard.
724
+ await recordFailedReview(github, job, reviewId, costTally, log);
725
+ throw error;
726
+ }
602
727
  guideBuiltAt = response.guideBuiltAt;
603
728
  const visiblePaths = new Set(response.visiblePaths);
604
729
  if (carryPrevious) {
@@ -688,6 +813,7 @@ async function runReviewJobCore(job, log, client, ai) {
688
813
  model: options.highModel ?? "unknown",
689
814
  durationMs: Date.now() - startedAt,
690
815
  }, options.reviewBlocking);
816
+ await resolveFailureNote(github, job, reviewId, log);
691
817
  await finishCheck(github, job, checkRunId, totalFindings === 0 ? "success" : "neutral", totalFindings === 0 ? "Review completed" : "Review findings", listFindingsForReview(reviewId), log);
692
818
  }
693
819
  export function registerReviewJobHandler() {
@@ -705,7 +831,10 @@ export function registerReviewJobHandler() {
705
831
  },
706
832
  });
707
833
  }
708
- export function enqueueManualReview(repo, prNumber) {
834
+ /** `model` pins the review to one model, the way "Retry with the same
835
+ * model" asks; without it the job resolves the model from config when it
836
+ * runs. */
837
+ export function enqueueManualReview(repo, prNumber, pin = {}) {
709
838
  const last = latestPostedReview(repo, prNumber);
710
839
  const row = getRepo(repo);
711
840
  const incremental = row?.review_scope === "incremental" && Boolean(last?.head_sha);
@@ -718,6 +847,7 @@ export function enqueueManualReview(repo, prNumber) {
718
847
  scope: incremental ? "incremental" : "whole-pr",
719
848
  sinceCommit: incremental ? last.head_sha : undefined,
720
849
  round: last ? last.round + 1 : 1,
850
+ ...(pin.model ? { model: pin.model } : {}),
721
851
  },
722
852
  });
723
853
  }
@@ -0,0 +1,13 @@
1
+ export type SearchItem = {
2
+ label: string;
3
+ href: string;
4
+ icon: string;
5
+ hint?: string;
6
+ };
7
+ export type SearchResult = {
8
+ groups: {
9
+ label: string;
10
+ items: SearchItem[];
11
+ }[];
12
+ };
13
+ export declare function searchAll(query: string): SearchResult;
@@ -0,0 +1,72 @@
1
+ /** What the Ctrl K palette searches: fixed pages and actions, plus real
2
+ * repositories and pull requests from the database. Nothing is invented: a
3
+ * query with no matching record returns no group for it. */
4
+ import { getAppDb } from "../store/app_db.js";
5
+ import { listActiveRepos } from "../store/repos.js";
6
+ const PAGES = [
7
+ { label: "Repositories", href: "/", icon: "layout-grid" },
8
+ { label: "Activity", href: "/activity", icon: "activity" },
9
+ { label: "Usage", href: "/usage", icon: "chart-no-axes-column" },
10
+ { label: "Setup", href: "/setup", icon: "list-checks" },
11
+ { label: "AI models", href: "/settings/ai", icon: "sparkles" },
12
+ { label: "GitHub", href: "/settings/github", icon: "github" },
13
+ {
14
+ label: "Review defaults",
15
+ href: "/settings/defaults",
16
+ icon: "sliders-horizontal",
17
+ },
18
+ { label: "Remote access", href: "/settings/remote", icon: "key-round" },
19
+ { label: "Server", href: "/settings/server", icon: "server" },
20
+ { label: "Sign-in", href: "/settings/sign-in", icon: "shield-check" },
21
+ { label: "Danger zone", href: "/settings/danger", icon: "triangle-alert" },
22
+ ];
23
+ const ACTIONS = [
24
+ { label: "Add repository", href: "/repos/new", icon: "plus" },
25
+ {
26
+ label: "Create a remote token",
27
+ href: "/settings/remote",
28
+ icon: "key-round",
29
+ },
30
+ { label: "Change AI model", href: "/settings/ai", icon: "sparkles" },
31
+ ];
32
+ const LIMIT = 8;
33
+ export function searchAll(query) {
34
+ const q = query.trim().toLowerCase();
35
+ const matches = (label) => !q || label.toLowerCase().includes(q);
36
+ const repos = listActiveRepos()
37
+ .filter((repo) => matches(repo.full_name))
38
+ .slice(0, LIMIT)
39
+ .map((repo) => ({
40
+ label: repo.full_name,
41
+ href: `/repos/${repo.full_name}`,
42
+ icon: "git-branch",
43
+ }));
44
+ // One result per pull request of an active repository, newest first. The
45
+ // label "repo #7" is what the query is matched against, so "#7", "7" and
46
+ // the repository name all find it.
47
+ const pulls = getAppDb()
48
+ .prepare(`SELECT r.repo, r.pr_number, MAX(r.created_at) AS last
49
+ FROM reviews r JOIN repos p ON p.full_name = r.repo AND p.active = 1
50
+ WHERE r.kind = 'pr'
51
+ GROUP BY r.repo, r.pr_number
52
+ ORDER BY last DESC`)
53
+ .all()
54
+ .map((row) => ({
55
+ label: `${row.repo} #${row.pr_number}`,
56
+ href: `/repos/${row.repo}/pulls/${row.pr_number}`,
57
+ icon: "git-pull-request",
58
+ }))
59
+ .filter((item) => matches(item.label))
60
+ .slice(0, LIMIT);
61
+ return {
62
+ groups: [
63
+ { label: "Pages", items: PAGES.filter((item) => matches(item.label)) },
64
+ { label: "Repositories", items: repos },
65
+ { label: "Pull requests", items: pulls },
66
+ {
67
+ label: "Actions",
68
+ items: ACTIONS.filter((item) => matches(item.label)),
69
+ },
70
+ ].filter((group) => group.items.length > 0),
71
+ };
72
+ }
@@ -16,8 +16,9 @@ import { cacheSet } from "../store/cache_db.js";
16
16
  import { log, timed, withLogSink } from "../util/log.js";
17
17
  import { printRunSummary, summaryFromMetrics } from "../util/run_summary.js";
18
18
  import { enqueue, registerHandler } from "./jobs.js";
19
+ import { resolveConcurrency } from "./concurrency.js";
19
20
  import { closeAppDb, isAppDbOpen, openAppDb } from "../store/app_db.js";
20
- import { getRepo, markKnowledgeBuilt } from "../store/repos.js";
21
+ import { getRepo, markKnowledgeBuilt, registerCliRepo, } from "../store/repos.js";
21
22
  import { nowIso } from "../util/time.js";
22
23
  import { mkdir, readTextFile, remove } from "../util/runtime.js";
23
24
  import { addResponseCost, emptyTally } from "../util/cost.js";
@@ -257,6 +258,9 @@ async function initOrRemake(options) {
257
258
  await writeReviewDocuments(options.repo, reviewDocuments, reviewSignalCount(facts));
258
259
  const head = source.commits[0];
259
260
  const baseSha = head?.sha ? String(head.sha) : new Date().toISOString();
261
+ // A CLI init has no app.db row for the repository yet; without one the
262
+ // dashboard never sees what it built. A dashboard job already has one.
263
+ registerCliRepo(options.repo);
260
264
  markKnowledgeBuilt(options.repo, baseSha);
261
265
  });
262
266
  await writeState({
@@ -324,14 +328,15 @@ export function optionsFromConfig(repo, command) {
324
328
  throw new Error("AI is enabled but token/low-model/high-model are not fully configured. Run: " +
325
329
  "co-maintainer set --token=... --low-model=... --high-model=...");
326
330
  }
331
+ const concurrency = resolveConcurrency(repo, config);
327
332
  return {
328
333
  command,
329
334
  repo,
330
335
  debug: false,
331
336
  logTime: true,
332
337
  improveMatrix: 1,
333
- ghConcurrent: 1,
334
- aiConcurrent: 3,
338
+ ghConcurrent: concurrency.gh,
339
+ aiConcurrent: concurrency.ai,
335
340
  auth,
336
341
  githubPat: config.githubPat,
337
342
  ai,
@@ -398,10 +403,15 @@ export function registerSetupJobHandler() {
398
403
  registerHandler("remake", handler);
399
404
  }
400
405
  export function enqueueSetup(repo, command, overrides = {}) {
406
+ const concurrency = resolveConcurrency(repo);
401
407
  return enqueue({
402
408
  type: command,
403
409
  repo,
404
- args: overrides,
410
+ args: {
411
+ ghConcurrent: concurrency.gh,
412
+ aiConcurrent: concurrency.ai,
413
+ ...overrides,
414
+ },
405
415
  queueKey: `setup:${repo}`,
406
416
  });
407
417
  }
@@ -3,7 +3,7 @@ export type SetupItem = {
3
3
  title: string;
4
4
  detail: string;
5
5
  done: boolean;
6
- /** Where the fix lives. In-page anchors on /settings where one exists. */
6
+ /** Where the fix lives. */
7
7
  href: string;
8
8
  linkLabel: string;
9
9
  };
@@ -1,21 +1,20 @@
1
- /** The "Finish setup" checklist shown on the home page.
1
+ /** The four required setup steps, shared by the home banner and /setup.
2
2
  *
3
- * Each item is derived from state that already exists, so the card reflects
4
- * what serve can actually do rather than a parallel bookkeeping of it. The
5
- * webhook item reuses the existing reachability check. */
3
+ * Each item is derived from state that already exists, so the count reflects
4
+ * what serve can actually do rather than a parallel bookkeeping of it. One
5
+ * list feeds every page, so home and /setup can never disagree on "n of 4".
6
+ * Optional extras (first review, remote token) stay out of the count. The
7
+ * webhook part of the App step reuses the existing reachability check. */
6
8
  import { aiConfigured, readConfig, resolveAppPrivateKey } from "../config.js";
7
- import { countReviews } from "../store/reviews.js";
8
- import { listRemoteTokens } from "../store/remote_tokens.js";
9
9
  import { listActiveRepos } from "../store/repos.js";
10
10
  import { lastDelivery } from "../store/deliveries.js";
11
11
  import { webhookReachabilityProblem } from "../util/webhook_reachability.js";
12
12
  export function setupChecklist(webhookUrl) {
13
13
  const config = readConfig();
14
14
  const aiDone = aiConfigured(config);
15
+ const githubDone = Boolean(config.auth === "gh" || (config.auth === "pat" && config.githubPat));
15
16
  const appDone = Boolean(config.githubAppId && resolveAppPrivateKey(config));
16
- const repoCount = listActiveRepos().length;
17
- const reviewCount = countReviews();
18
- const tokenCount = listRemoteTokens().length;
17
+ const builtCount = listActiveRepos().filter((repo) => repo.knowledge_built_at).length;
19
18
  const reach = webhookReachabilityProblem(webhookUrl);
20
19
  const reached = reach === undefined && lastDelivery() !== undefined;
21
20
  return [
@@ -26,62 +25,42 @@ export function setupChecklist(webhookUrl) {
26
25
  ? "An AI provider and key are saved."
27
26
  : "Add a provider and API key so reviews and guides can be written.",
28
27
  done: aiDone,
29
- href: "/settings#ai",
28
+ href: "/settings/ai",
30
29
  linkLabel: "Open models",
31
30
  },
32
31
  {
33
- id: "app",
34
- title: "GitHub App",
35
- detail: appDone
36
- ? "The App is configured."
37
- : "Create and install the App so reviews can be posted to pull requests.",
38
- done: appDone,
39
- href: "/settings#github",
32
+ id: "github",
33
+ title: "GitHub access",
34
+ detail: githubDone
35
+ ? "GitHub access is configured."
36
+ : "Use gh or a personal access token.",
37
+ done: githubDone,
38
+ href: "/settings/github",
40
39
  linkLabel: "Open GitHub",
41
40
  },
42
41
  {
43
- id: "webhook",
44
- title: "Webhook reachable",
42
+ id: "app",
43
+ title: "GitHub App and webhook",
45
44
  detail: !appDone
46
- ? "Set up the GitHub App first, then point its webhook at this server."
45
+ ? "Create and install the App so reviews can be posted to pull requests."
47
46
  : reached
48
47
  ? "GitHub has delivered a webhook to this server."
49
48
  : reach
50
49
  ? `GitHub cannot reach ${webhookUrl}. ${reach}`
51
50
  : "Waiting for the first delivery. Open a pull request to confirm.",
52
- done: reached,
53
- href: "/settings#github",
54
- linkLabel: "Open webhook",
51
+ done: appDone && reached,
52
+ href: "/settings/github",
53
+ linkLabel: "Open App",
55
54
  },
56
55
  {
57
56
  id: "repo",
58
57
  title: "First repository",
59
- detail: repoCount === 0
60
- ? "Add a repository to generate its guides."
61
- : `${repoCount} ${repoCount === 1 ? "repository" : "repositories"} added.`,
62
- done: repoCount > 0,
58
+ detail: builtCount === 0
59
+ ? "Add a repository and generate its guides."
60
+ : `${builtCount} ${builtCount === 1 ? "repository has" : "repositories have"} guides.`,
61
+ done: builtCount > 0,
63
62
  href: "/repos/new",
64
63
  linkLabel: "Add repository",
65
64
  },
66
- {
67
- id: "review",
68
- title: "First review",
69
- detail: reviewCount === 0
70
- ? "A review appears after the first pull request, or run one by number."
71
- : `${reviewCount} ${reviewCount === 1 ? "review" : "reviews"} so far.`,
72
- done: reviewCount > 0,
73
- href: "/activity",
74
- linkLabel: "Open activity",
75
- },
76
- {
77
- id: "cli",
78
- title: "CLI connected",
79
- detail: tokenCount === 0
80
- ? "Create a remote token to run co-maintainer review --remote."
81
- : `${tokenCount} remote ${tokenCount === 1 ? "token" : "tokens"} created.`,
82
- done: tokenCount > 0,
83
- href: "/settings#remote",
84
- linkLabel: "Open tokens",
85
- },
86
65
  ];
87
66
  }
@@ -28,4 +28,4 @@ export type SeverityStats = {
28
28
  };
29
29
  /** A repeat is a finding the previous round already raised, so the repeat
30
30
  * column reads as "raised again after the author saw it". */
31
- export declare function findingStatsBySeverity(sinceIso: string): SeverityStats[];
31
+ export declare function findingStatsBySeverity(sinceIso: string, repo?: string): SeverityStats[];
@@ -43,7 +43,7 @@ export function findFindingByPostedComment(repo, prNumber, commentId) {
43
43
  }
44
44
  /** A repeat is a finding the previous round already raised, so the repeat
45
45
  * column reads as "raised again after the author saw it". */
46
- export function findingStatsBySeverity(sinceIso) {
46
+ export function findingStatsBySeverity(sinceIso, repo) {
47
47
  return getAppDb()
48
48
  .prepare(`SELECT f.severity AS severity,
49
49
  COUNT(*) AS findings,
@@ -51,10 +51,10 @@ export function findingStatsBySeverity(sinceIso) {
51
51
  COALESCE(SUM(f.posted_comment_id IS NOT NULL), 0) AS posted
52
52
  FROM findings f
53
53
  INNER JOIN reviews r ON r.id = f.review_id
54
- WHERE r.created_at >= ?
54
+ WHERE r.created_at >= ?${repo ? " AND r.repo = ?" : ""}
55
55
  GROUP BY f.severity
56
56
  ORDER BY f.severity`)
57
- .all(sinceIso)
57
+ .all(...(repo ? [sinceIso, repo] : [sinceIso]))
58
58
  .map((row) => ({
59
59
  severity: String(row.severity),
60
60
  findings: Number(row.findings),
@@ -282,4 +282,11 @@ export const migrations = [
282
282
  `ALTER TABLE remote_review_inputs ADD COLUMN system_prompt_add TEXT`,
283
283
  `ALTER TABLE remote_review_inputs ADD COLUMN system_prompt_override TEXT`,
284
284
  ],
285
+ // 13 — the one issue comment a failed review leaves on the pull request,
286
+ // kept so a retry edits that same note instead of opening a second one.
287
+ [`ALTER TABLE reviews ADD COLUMN note_comment_id TEXT`],
288
+ // 14 — where a repository came from. `'cli'` for one a CLI init built
289
+ // (registered by init itself, or found on disk by serve after an upgrade),
290
+ // NULL for one added from the dashboard.
291
+ [`ALTER TABLE repos ADD COLUMN added_from TEXT`],
285
292
  ];
@@ -1,5 +1,10 @@
1
1
  import type { RepoRow } from "./rows.ts";
2
2
  export declare function activateRepo(fullName: string, installationId: number | undefined): void;
3
+ /** Adds a repository a CLI init built, unless it is already known (active,
4
+ * or removed from the dashboard on purpose). It starts with automatic review
5
+ * off: building knowledge from the CLI never opts a repository into posting
6
+ * reviews. */
7
+ export declare function registerCliRepo(fullName: string, knowledgeBuiltAt?: string): boolean;
3
8
  export declare function deactivateRepo(fullName: string): void;
4
9
  export declare function deactivateReposForInstallation(installationId: number): void;
5
10
  export declare function updateRepoSettings(fullName: string, patch: Partial<Pick<RepoRow, "auto_review" | "review_scope" | "skip_drafts" | "skip_bots" | "use_codegraph" | "review_policy_json">>): void;
@@ -9,6 +9,18 @@ export function activateRepo(fullName, installationId) {
9
9
  installation_id = excluded.installation_id, active = 1`)
10
10
  .run(fullName, installationId ?? null, nowIso());
11
11
  }
12
+ /** Adds a repository a CLI init built, unless it is already known (active,
13
+ * or removed from the dashboard on purpose). It starts with automatic review
14
+ * off: building knowledge from the CLI never opts a repository into posting
15
+ * reviews. */
16
+ export function registerCliRepo(fullName, knowledgeBuiltAt) {
17
+ const result = getAppDb()
18
+ .prepare(`INSERT INTO repos (full_name, installation_id, active, auto_review, created_at, added_from, knowledge_built_at)
19
+ VALUES (?, NULL, 1, 0, ?, 'cli', ?)
20
+ ON CONFLICT(full_name) DO NOTHING`)
21
+ .run(fullName, nowIso(), knowledgeBuiltAt ?? null);
22
+ return Number(result.changes) > 0;
23
+ }
12
24
  export function deactivateRepo(fullName) {
13
25
  getAppDb()
14
26
  .prepare(`UPDATE repos SET active = 0 WHERE full_name = ?`)