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.
Files changed (99) 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/ai/oauth/ids.d.ts +10 -0
  5. package/dist/src/ai/oauth/ids.js +10 -0
  6. package/dist/src/ai/oauth/registry.d.ts +33 -0
  7. package/dist/src/ai/oauth/registry.js +40 -0
  8. package/dist/src/ai/oauth/sign-in-with-chatgpt.d.ts +56 -0
  9. package/dist/src/ai/oauth/sign-in-with-chatgpt.js +552 -0
  10. package/dist/src/ai/openai.d.ts +18 -1
  11. package/dist/src/ai/openai.js +68 -5
  12. package/dist/src/ai/provider.d.ts +3 -0
  13. package/dist/src/ai/provider.js +11 -2
  14. package/dist/src/cli/args.js +61 -21
  15. package/dist/src/cli/commands/oauth.d.ts +1 -0
  16. package/dist/src/cli/commands/oauth.js +73 -0
  17. package/dist/src/cli/commands/registry.js +79 -3
  18. package/dist/src/cli/commands/serve.js +31 -3
  19. package/dist/src/cli/commands/set.js +54 -0
  20. package/dist/src/cli/main.js +5 -0
  21. package/dist/src/cli/review_args.js +5 -0
  22. package/dist/src/config.d.ts +14 -0
  23. package/dist/src/github/client.js +13 -0
  24. package/dist/src/github/collect.d.ts +2 -2
  25. package/dist/src/github/collect.js +60 -23
  26. package/dist/src/github/permissions.js +8 -0
  27. package/dist/src/knowledge/types.d.ts +3 -4
  28. package/dist/src/pr/reviewer.js +5 -4
  29. package/dist/src/server/api/jobs.js +8 -1
  30. package/dist/src/server/api/repos.js +73 -11
  31. package/dist/src/server/api/settings.js +6 -0
  32. package/dist/src/server/app.d.ts +5 -0
  33. package/dist/src/server/app.js +7 -0
  34. package/dist/src/server/http.d.ts +3 -0
  35. package/dist/src/server/http.js +5 -0
  36. package/dist/src/server/pages/activity.js +412 -19
  37. package/dist/src/server/pages/add_repo.js +6 -1
  38. package/dist/src/server/pages/analytics.js +99 -31
  39. package/dist/src/server/pages/catalog.d.ts +1 -0
  40. package/dist/src/server/pages/catalog.js +145 -0
  41. package/dist/src/server/pages/client.d.ts +1 -1
  42. package/dist/src/server/pages/client.js +1 -1
  43. package/dist/src/server/pages/home.d.ts +14 -4
  44. package/dist/src/server/pages/home.js +83 -49
  45. package/dist/src/server/pages/icons.d.ts +3 -0
  46. package/dist/src/server/pages/icons.js +3 -0
  47. package/dist/src/server/pages/knowledge.js +10 -5
  48. package/dist/src/server/pages/layout.d.ts +19 -3
  49. package/dist/src/server/pages/layout.js +156 -33
  50. package/dist/src/server/pages/pr.js +4 -3
  51. package/dist/src/server/pages/rate_limit_waits.d.ts +5 -0
  52. package/dist/src/server/pages/rate_limit_waits.js +74 -0
  53. package/dist/src/server/pages/repo.js +100 -66
  54. package/dist/src/server/pages/repo_prs.js +4 -3
  55. package/dist/src/server/pages/repo_remote.js +4 -3
  56. package/dist/src/server/pages/repo_settings.d.ts +2 -2
  57. package/dist/src/server/pages/repo_settings.js +420 -46
  58. package/dist/src/server/pages/router.d.ts +5 -0
  59. package/dist/src/server/pages/router.js +82 -31
  60. package/dist/src/server/pages/settings.d.ts +10 -1
  61. package/dist/src/server/pages/settings.js +351 -207
  62. package/dist/src/server/pages/setup.d.ts +2 -5
  63. package/dist/src/server/pages/setup.js +21 -23
  64. package/dist/src/server/pages/styles.d.ts +1 -1
  65. package/dist/src/server/pages/styles.js +1 -1
  66. package/dist/src/server/pages/ui.d.ts +117 -0
  67. package/dist/src/server/pages/ui.js +166 -0
  68. package/dist/src/services/clear.js +2 -0
  69. package/dist/src/services/cli_repos.d.ts +2 -0
  70. package/dist/src/services/cli_repos.js +50 -0
  71. package/dist/src/services/concurrency.d.ts +39 -0
  72. package/dist/src/services/concurrency.js +88 -0
  73. package/dist/src/services/dashboard.d.ts +43 -1
  74. package/dist/src/services/dashboard.js +10 -2
  75. package/dist/src/services/jobs.js +5 -3
  76. package/dist/src/services/nav_counts.d.ts +8 -0
  77. package/dist/src/services/nav_counts.js +19 -0
  78. package/dist/src/services/rate_limit.d.ts +33 -0
  79. package/dist/src/services/rate_limit.js +78 -0
  80. package/dist/src/services/repo_list.d.ts +19 -0
  81. package/dist/src/services/repo_list.js +38 -0
  82. package/dist/src/services/review.d.ts +23 -1
  83. package/dist/src/services/review.js +104 -5
  84. package/dist/src/services/search.d.ts +13 -0
  85. package/dist/src/services/search.js +72 -0
  86. package/dist/src/services/setup.js +17 -16
  87. package/dist/src/services/setup_checklist.d.ts +1 -1
  88. package/dist/src/services/setup_checklist.js +26 -47
  89. package/dist/src/store/cache_db.js +1 -1
  90. package/dist/src/store/findings.d.ts +1 -1
  91. package/dist/src/store/findings.js +3 -3
  92. package/dist/src/store/migrations.js +7 -0
  93. package/dist/src/store/repos.d.ts +5 -0
  94. package/dist/src/store/repos.js +12 -0
  95. package/dist/src/store/reviews.d.ts +12 -1
  96. package/dist/src/store/reviews.js +34 -2
  97. package/dist/src/store/rows.d.ts +6 -0
  98. package/dist/src/types.d.ts +5 -1
  99. package/package.json +4 -2
@@ -4,6 +4,7 @@
4
4
  import { log } from "../util/log.js";
5
5
  import { networkFailure } from "../cli/error.js";
6
6
  import { missingHint, refusalHint } from "./permissions.js";
7
+ import { recordRateLimitWait } from "../services/rate_limit.js";
7
8
  export class GitHubHttpError extends Error {
8
9
  status;
9
10
  constructor(status, body, hint) {
@@ -109,6 +110,12 @@ export async function githubFetch(url, init) {
109
110
  const retryAfterHeader = response.headers.get("retry-after");
110
111
  const retryAfter = retryAfterHeader === null ? NaN : Number(retryAfterHeader);
111
112
  if (Number.isFinite(retryAfter) && retryAfter >= 0 && attempt < 3) {
113
+ recordRateLimitWait({
114
+ service: "github",
115
+ stage: "GitHub request",
116
+ reason: `secondary rate limit (HTTP ${response.status})`,
117
+ seconds: retryAfter,
118
+ });
112
119
  console.log(`[github] secondary rate limit, waiting ${retryAfter}s (attempt ${attempt} of 3)`);
113
120
  await new Promise((resolve) => setTimeout(resolve, retryAfter * 1000));
114
121
  continue;
@@ -129,6 +136,12 @@ export async function githubFetch(url, init) {
129
136
  spun = true;
130
137
  continue;
131
138
  }
139
+ recordRateLimitWait({
140
+ service: "github",
141
+ stage: "GitHub request",
142
+ reason: `primary rate limit (HTTP ${response?.status ?? 403})`,
143
+ seconds: delay / 1000,
144
+ });
132
145
  spun = false;
133
146
  await waitForRateLimit(exhausted.resetAt, started);
134
147
  }
@@ -1,6 +1,6 @@
1
1
  import type { GitHubClient, Options } from "../types.ts";
2
- import type { PullRequest, Source, State } from "../knowledge/types.ts";
3
- export declare function collectSource(client: GitHubClient, options: Options, previous?: State, progress?: (items: PullRequest[], cache: PullRequest[]) => Promise<void>, codebaseProgress?: (data: {
2
+ import type { Source, State } from "../knowledge/types.ts";
3
+ export declare function collectSource(client: GitHubClient, options: Options, previous?: State, codebaseProgress?: (data: {
4
4
  tree: string[];
5
5
  treeSha: Record<string, string>;
6
6
  files: Record<string, string>;
@@ -1,5 +1,5 @@
1
1
  import { log, startHeartbeat } from "../util/log.js";
2
- import { cacheGet, cacheSet } from "../store/cache_db.js";
2
+ import { cacheGet, cacheSet, cacheValues } from "../store/cache_db.js";
3
3
  function decodeBase64(value) {
4
4
  const binary = atob(value.replaceAll("\n", ""));
5
5
  const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
@@ -244,24 +244,62 @@ async function codebase(client, repo, meta, concurrency, previous, phase, progre
244
244
  });
245
245
  return { tree, treeSha, files };
246
246
  }
247
- async function pullRequests(client, options, previous, phase, progress) {
247
+ /** One pull request's cached evidence, keyed by number. `cacheValues` returns
248
+ * the newest rows first, so a later row for the same number wins. Legacy
249
+ * entries still in the state blob are merged in when their row is missing, so
250
+ * a migration interrupted after the first row resumes instead of treating the
251
+ * rows it wrote as proof that every pull request moved. */
252
+ async function loadPrCache(repo, previous) {
253
+ const cache = new Map();
254
+ for (const raw of await cacheValues("pr", `${repo}:`)) {
255
+ try {
256
+ const pr = JSON.parse(raw);
257
+ if (typeof pr?.number === "number")
258
+ cache.set(pr.number, pr);
259
+ }
260
+ catch {
261
+ // A corrupt row is skipped rather than losing every other row.
262
+ }
263
+ }
264
+ for (const pr of legacyPrCache(previous)) {
265
+ if (cache.has(pr.number))
266
+ continue;
267
+ cache.set(pr.number, pr);
268
+ await savePr(repo, pr);
269
+ }
270
+ return cache;
271
+ }
272
+ /** The single state blob used to hold every decided pull request before they
273
+ * moved to one row per pull request. Read once, then rewritten as rows. */
274
+ function legacyPrCache(previous) {
275
+ const source = previous?.source;
276
+ const byNumber = new Map();
277
+ for (const pr of [
278
+ ...(source?.pullRequestCache ?? []),
279
+ ...(source?.pullRequests ?? []),
280
+ ]) {
281
+ if (!byNumber.has(pr.number))
282
+ byNumber.set(pr.number, pr);
283
+ }
284
+ return [...byNumber.values()];
285
+ }
286
+ async function savePr(repo, pr) {
287
+ await cacheSet("pr", `${repo}:${pr.number}`, JSON.stringify(pr));
288
+ }
289
+ async function pullRequests(client, options, previous, phase) {
248
290
  if (phase)
249
291
  phase.text = "listing pull requests · page 0 · fetched 0";
250
292
  const selected = await listPullRequestPages(client, options, phase);
251
- const keptByNumber = new Map((previous?.source.pullRequests ?? []).map((pr) => [pr.number, pr]));
252
- const cacheByNumber = new Map((previous?.source.pullRequestCache ?? []).map((pr) => [pr.number, pr]));
293
+ const prCache = await loadPrCache(options.repo, previous);
253
294
  const result = new Array(selected.length);
254
- const cache = new Array(selected.length);
255
295
  let completed = 0;
256
- let save = Promise.resolve();
257
296
  if (phase) {
258
297
  phase.text = `pull requests 0/${selected.length} · 0% · concurrency=${options.ghConcurrent}`;
259
298
  }
260
299
  log("fetch", `${selected.length} pull requests · concurrency=${options.ghConcurrent}`);
261
300
  await mapPool(selected, options.ghConcurrent, async (pr, index) => {
262
301
  const number = Number(pr.number);
263
- const full = keptByNumber.get(number);
264
- const cached = full ?? cacheByNumber.get(number);
302
+ const cached = prCache.get(number);
265
303
  const listedAdditions = Number(pr.additions);
266
304
  const listedDeletions = Number(pr.deletions);
267
305
  const listedStatsAvailable = Number.isFinite(listedAdditions) &&
@@ -312,9 +350,9 @@ async function pullRequests(client, options, previous, phase, progress) {
312
350
  current.changesRequested = cached.changesRequested;
313
351
  }
314
352
  const only = options.onlyRequestChangedPr;
315
- const discussionUnchanged = full?.updatedAt === current.updatedAt;
353
+ const discussionUnchanged = cached?.updatedAt === current.updatedAt;
316
354
  const decisionKnown = typeof cached?.changesRequested === "boolean";
317
- const diffUnchanged = full?.headSha === current.headSha && Boolean(full?.diff);
355
+ const diffUnchanged = cached?.headSha === current.headSha && Boolean(cached?.diff);
318
356
  let droppedFromCache = only &&
319
357
  cached?.updatedAt === current.updatedAt &&
320
358
  cached.changesRequested === false;
@@ -406,7 +444,12 @@ async function pullRequests(client, options, previous, phase, progress) {
406
444
  current.diff = "";
407
445
  }
408
446
  }
409
- cache[index] = current;
447
+ const shouldSave = !cached ||
448
+ !discussionUnchanged ||
449
+ !diffUnchanged ||
450
+ (!decisionKnown && typeof current.changesRequested === "boolean");
451
+ if (shouldSave)
452
+ await savePr(options.repo, current);
410
453
  if (!dropped)
411
454
  result[index] = current;
412
455
  completed++;
@@ -414,17 +457,12 @@ async function pullRequests(client, options, previous, phase, progress) {
414
457
  phase.text = `pull requests ${completed}/${selected.length} · ${percent(completed, selected.length)}`;
415
458
  }
416
459
  log("fetch", `PR ${completed}/${selected.length} · ${percent(completed, selected.length)} #${number} · ${discussionStatus} · ${diffStatus}`);
417
- if (progress) {
418
- save = save.then(() => progress(result.filter((item) => !!item), cache.filter((item) => !!item)));
419
- await save;
420
- }
421
460
  });
422
461
  const kept = result.filter((item) => !!item);
423
- const decided = cache.filter((item) => !!item);
424
462
  if (options.onlyRequestChangedPr) {
425
463
  log("fetch", `only request-changed pr · kept ${kept.length} · dropped ${selected.length - kept.length}`);
426
464
  }
427
- return { kept, cache: decided };
465
+ return kept;
428
466
  }
429
467
  function commitLimit(maxCommits) {
430
468
  return maxCommits && maxCommits > 0 ? maxCommits : undefined;
@@ -492,7 +530,7 @@ async function commits(client, options, meta, previous, phase) {
492
530
  }
493
531
  return selected;
494
532
  }
495
- export async function collectSource(client, options, previous, progress, codebaseProgress) {
533
+ export async function collectSource(client, options, previous, codebaseProgress) {
496
534
  const phase = { text: "reading repository metadata" };
497
535
  const stopHeartbeat = startHeartbeat(() => phase.text);
498
536
  try {
@@ -501,9 +539,9 @@ export async function collectSource(client, options, previous, progress, codebas
501
539
  const files = includeCodebase
502
540
  ? await codebase(client, options.repo, repo, options.ghConcurrent, previous?.source, phase, codebaseProgress)
503
541
  : { tree: [], treeSha: {}, files: {} };
504
- const pullRequestData = options.includePullRequests
505
- ? await pullRequests(client, options, previous, phase, progress)
506
- : { kept: [], cache: previous?.source.pullRequestCache ?? [] };
542
+ const selectedPullRequests = options.includePullRequests
543
+ ? await pullRequests(client, options, previous, phase)
544
+ : [];
507
545
  const commitData = options.includeCommitHistory
508
546
  ? await commits(client, options, repo, previous, phase)
509
547
  : [];
@@ -512,8 +550,7 @@ export async function collectSource(client, options, previous, progress, codebas
512
550
  tree: files.tree,
513
551
  treeSha: files.treeSha,
514
552
  files: files.files,
515
- pullRequests: pullRequestData.kept,
516
- pullRequestCache: pullRequestData.cache,
553
+ pullRequests: selectedPullRequests,
517
554
  commits: commitData,
518
555
  };
519
556
  }
@@ -104,6 +104,14 @@ export const ENDPOINTS = [
104
104
  identities: APP_ONLY,
105
105
  feature: "Acknowledge a review request on the pull request",
106
106
  },
107
+ {
108
+ method: "PATCH",
109
+ pattern: "repos/{repo}/issues/comments/{id}",
110
+ permission: "issues",
111
+ level: "write",
112
+ identities: APP_ONLY,
113
+ feature: "Edit the failure note left on a pull request",
114
+ },
107
115
  {
108
116
  method: "POST",
109
117
  pattern: "repos/{repo}/issues/comments/{id}/reactions",
@@ -27,11 +27,10 @@ export type Source = {
27
27
  tree: string[];
28
28
  treeSha: Record<string, string>;
29
29
  files: Record<string, string>;
30
- /** Pull requests selected for facts and the skill. */
30
+ /** Pull requests selected for facts and the skill. Every decided pull
31
+ * request, including ones left out of the skill, is kept per pull request in
32
+ * cache.db, so a `changesRequested: false` result is not downloaded again. */
31
33
  pullRequests: PullRequest[];
32
- /** Every pull request already decided, including ones left out of the skill.
33
- * The next fetch reads this so a `changesRequested: false` result is not downloaded again. */
34
- pullRequestCache?: PullRequest[];
35
34
  commits: Json[];
36
35
  };
37
36
  export type Fact = {
@@ -9,11 +9,12 @@ import { reviewSystemPromptBlock } from "../review/system_prompt.js";
9
9
  import { needsSummary, READ_FULL_DIFF_TOOL, readFullDiff, summarizeDiff, } from "./diff_summary.js";
10
10
  import { numberPatch } from "./hunks.js";
11
11
  import { FINDINGS_JSON_INSTRUCTIONS, FINDINGS_JSON_SCHEMA, findingsMarkdownFromJson, } from "./findings_json.js";
12
+ import { aiProviderName } from "../ai/provider.js";
12
13
  /** One line naming the provider and the two models a review will call, printed
13
14
  * before any AI request so the operator can see what is running. The low model
14
15
  * summarizes large diffs, the high model writes the review. */
15
16
  export function modelSummary(options) {
16
- return (`models · provider=${options.ai} · low=${options.lowModel ?? "unset"} · ` +
17
+ return (`models · provider=${aiProviderName(options)} · low=${options.lowModel ?? "unset"} · ` +
17
18
  `high=${options.highModel ?? "unset"}`);
18
19
  }
19
20
  /** A model id is never guessed here. Models go stale, and a build already
@@ -402,7 +403,7 @@ ${diff}`;
402
403
  console.log(`\n----- INITIAL REVIEW -----\n${response.text}\n`);
403
404
  }
404
405
  if (!response.text.trim()) {
405
- throw new Error(`${options.ai} returned an empty review. The reasoning budget may have been exhausted`);
406
+ throw new Error(`${aiProviderName(options)} returned an empty review. The reasoning budget may have been exhausted`);
406
407
  }
407
408
  // The model returns JSON; we render the Markdown. A reply
408
409
  // that is not usable JSON is retried once and then falls back to the legacy
@@ -434,7 +435,7 @@ ${reviewText}`,
434
435
  report(`AI improvement response · input=${response.tokensIn} tokens · ` +
435
436
  `output=${response.tokensOut} tokens`);
436
437
  if (!response.text.trim()) {
437
- throw new Error(`${options.ai} returned an empty review improvement at pass ${pass - 1}`);
438
+ throw new Error(`${aiProviderName(options)} returned an empty review improvement at pass ${pass - 1}`);
438
439
  }
439
440
  reviewText = await normalizeReviewResponse(provider, improvementRequest, response, extraTools, maxToolRounds, usage, report, options);
440
441
  if (options.debug) {
@@ -557,7 +558,7 @@ ${ownDiff}${unchangedListing}`;
557
558
  if (usage)
558
559
  await usage(response);
559
560
  if (!response.text.trim()) {
560
- throw new Error(`${options.ai} returned an empty review`);
561
+ throw new Error(`${aiProviderName(options)} returned an empty review`);
561
562
  }
562
563
  let reviewText = await normalizeReviewResponse(provider, request, response, extraTools, maxToolRounds, usage, report, options);
563
564
  for (let pass = 2; pass <= matrix; pass++) {
@@ -3,6 +3,7 @@
3
3
  * `Authorization` header, and every other `/api/*` route needs one. */
4
4
  import { errorResponse } from "../errors.js";
5
5
  import { cancel, getLogsSince, subscribeToLogs } from "../../services/jobs.js";
6
+ import { listRateLimitWaits, summarizeRateLimitWaits, } from "../../services/rate_limit.js";
6
7
  import { getJob, listJobs } from "../../store/jobs.js";
7
8
  const ROUTE = /^\/api\/jobs(?:\/([^/]+)(?:\/(logs\/stream|cancel))?)?$/;
8
9
  export function handleJobsRoute(request, url) {
@@ -23,7 +24,13 @@ export function handleJobsRoute(request, url) {
23
24
  const job = getJob(jobId);
24
25
  if (!job)
25
26
  return errorResponse(404, "not_found", "no such job");
26
- return Response.json({ ...job, logs: getLogsSince(jobId).slice(-50) });
27
+ const rateLimitWaits = listRateLimitWaits(jobId);
28
+ return Response.json({
29
+ ...job,
30
+ logs: getLogsSince(jobId).slice(-50),
31
+ rateLimitWaits,
32
+ rateLimitWaitSummary: summarizeRateLimitWaits(rateLimitWaits),
33
+ });
27
34
  }
28
35
  if (jobId && sub === "cancel" && request.method === "POST") {
29
36
  if (!getJob(jobId))
@@ -4,18 +4,26 @@ import { activateRepo, deactivateRepo, getRepo, listActiveRepos, updateRepoSetti
4
4
  import { readConfig, writeRepoConfig } from "../../config.js";
5
5
  import { checkReviewSystemPrompt, reviewSystemPromptLimit, } from "../../review/system_prompt.js";
6
6
  import { parseRemakeCron } from "../../services/remake_cron.js";
7
+ import { MAX_CONCURRENCY, MIN_CONCURRENCY, } from "../../services/concurrency.js";
7
8
  import { parsePolicy, policyToStore, describePolicy, } from "../../services/review_policy.js";
8
9
  import { enqueueSetup } from "../../services/setup.js";
10
+ import { appReady, filterRepoList } from "../../services/repo_list.js";
9
11
  import { enqueueManualReview } from "../../services/review.js";
10
12
  import { probePlan, recommendationPatch } from "../../services/probe.js";
11
13
  import { estimateInit, readJobHistory } from "../../ai/estimate.js";
12
14
  import { loadPrices } from "../../ai/pricing.js";
13
- import { prDetail, repoKnowledge, RepoNotFound, repoOverview, repoPulls, requireActiveRepo, } from "../../services/dashboard.js";
15
+ import { listReposForHome, prDetail, repoKnowledge, RepoNotFound, repoOverview, repoPulls, requireActiveRepo, } from "../../services/dashboard.js";
14
16
  import { clearOneRepo } from "./knowledge.js";
15
17
  const REPO = /^\/api\/repos\/([^/]+)\/([^/]+)(?:\/(remake|knowledge|pulls)(?:\/(\d+)(?:\/(review))?)?)?$/;
16
18
  export async function handleReposRoute(request, url, githubApp) {
17
19
  if (url.pathname === "/api/repos" && request.method === "GET") {
18
- return Response.json({ items: listActiveRepos() });
20
+ const q = url.searchParams.get("q");
21
+ const status = url.searchParams.get("status");
22
+ if (q === null && status === null) {
23
+ return Response.json({ items: listActiveRepos() });
24
+ }
25
+ const items = filterRepoList(listReposForHome(), { q: q ?? undefined, status: status ?? undefined }, appReady());
26
+ return Response.json({ items: items.map((item) => item.repo) });
19
27
  }
20
28
  // The plain sentences shown under the policy editor before it is saved, so
21
29
  // the wording lives in one place and the page never rebuilds it.
@@ -184,15 +192,19 @@ export async function handleReposRoute(request, url, githubApp) {
184
192
  const raw = body.remakeCron;
185
193
  if (raw === null || raw === "") {
186
194
  cronPatch.remakeCron = undefined;
195
+ cronPatch.remakeCronDraft = undefined;
187
196
  }
188
197
  else if (typeof raw === "string") {
189
198
  try {
190
199
  parseRemakeCron(raw);
191
200
  }
192
201
  catch (error) {
202
+ // Keep what was typed only for the form, never as a schedule.
203
+ await writeRepoConfig(fullName, { remakeCronDraft: raw });
193
204
  return errorResponse(422, "invalid_cron", error instanceof Error ? error.message : String(error));
194
205
  }
195
206
  cronPatch.remakeCron = raw.trim();
207
+ cronPatch.remakeCronDraft = undefined;
196
208
  }
197
209
  else {
198
210
  return errorResponse(422, "invalid_cron", "remakeCron must be text or null");
@@ -253,6 +265,36 @@ export async function handleReposRoute(request, url, githubApp) {
253
265
  }
254
266
  patch.review_policy_json = stored.value;
255
267
  }
268
+ const speedPatch = {};
269
+ for (const key of ["ghConcurrent", "aiConcurrent"]) {
270
+ if (!(key in body))
271
+ continue;
272
+ const raw = body[key];
273
+ if (raw === null || raw === "") {
274
+ speedPatch[key] = undefined;
275
+ continue;
276
+ }
277
+ if (typeof raw !== "number" ||
278
+ !Number.isInteger(raw) ||
279
+ raw < MIN_CONCURRENCY ||
280
+ raw > MAX_CONCURRENCY) {
281
+ return errorResponse(422, "invalid_concurrency", `${key} must be an integer between ${MIN_CONCURRENCY} and ${MAX_CONCURRENCY}`);
282
+ }
283
+ speedPatch[key] = raw;
284
+ }
285
+ const blockingPatch = {};
286
+ if ("reviewBlocking" in body) {
287
+ const raw = body.reviewBlocking;
288
+ if (raw === null || raw === "") {
289
+ blockingPatch.reviewBlocking = undefined;
290
+ }
291
+ else if (raw === "model" || raw === "severity") {
292
+ blockingPatch.reviewBlocking = raw;
293
+ }
294
+ else {
295
+ return errorResponse(422, "invalid_review_blocking", "reviewBlocking must be model or severity");
296
+ }
297
+ }
256
298
  if (typeof body.autoReview === "boolean") {
257
299
  patch.auto_review = body.autoReview ? 1 : 0;
258
300
  }
@@ -296,14 +338,15 @@ export async function handleReposRoute(request, url, githubApp) {
296
338
  init[key] = body[key];
297
339
  }
298
340
  }
299
- if (Object.keys(init).length > 0 ||
300
- "remakeCron" in cronPatch ||
301
- Object.keys(promptPatch).length > 0) {
302
- await writeRepoConfig(fullName, {
303
- ...init,
304
- ...cronPatch,
305
- ...promptPatch,
306
- });
341
+ const repoPatch = {
342
+ ...init,
343
+ ...cronPatch,
344
+ ...promptPatch,
345
+ ...speedPatch,
346
+ ...blockingPatch,
347
+ };
348
+ if (Object.keys(repoPatch).length > 0) {
349
+ await writeRepoConfig(fullName, repoPatch);
307
350
  }
308
351
  return Response.json({ ok: true });
309
352
  }
@@ -328,7 +371,26 @@ export async function handleReposRoute(request, url, githubApp) {
328
371
  action === "review" &&
329
372
  request.method === "POST") {
330
373
  requireActiveRepo(fullName);
331
- const { id } = enqueueManualReview(fullName, pr);
374
+ // An optional `{ model }` pins the review to the model a failed one
375
+ // used. No body, or no model, keeps the configured model.
376
+ let body = {};
377
+ try {
378
+ const raw = await request.text();
379
+ if (raw.trim())
380
+ body = JSON.parse(raw);
381
+ }
382
+ catch {
383
+ return errorResponse(400, "bad_request", "expected a JSON body");
384
+ }
385
+ if (body.model !== undefined &&
386
+ (typeof body.model !== "string" ||
387
+ body.model.length === 0 ||
388
+ body.model.length > 200)) {
389
+ return errorResponse(422, "invalid_setting", "model must be a model id of 1 to 200 characters");
390
+ }
391
+ const { id } = enqueueManualReview(fullName, pr, {
392
+ model: body.model,
393
+ });
332
394
  return Response.json({ jobId: id });
333
395
  }
334
396
  if (sub === "pulls" && pr && request.method === "GET") {
@@ -99,6 +99,12 @@ export async function handleSettingsRoute(request, url, webhookUrl, passwords, i
99
99
  text("githubOAuthClientId");
100
100
  text("githubOAuthClientSecret");
101
101
  text("githubOAuthAllowedUser");
102
+ // A key means nothing without the provider it belongs to: saving one
103
+ // with no provider would read "A key is saved" next to "Not set".
104
+ const provider = patch.ai ?? current.ai;
105
+ if (patch.token && (!provider || provider === "none")) {
106
+ return errorResponse(422, "provider_required", "Choose a provider before saving an API key.");
107
+ }
102
108
  const previousAi = savedKeyProvider(current);
103
109
  if (patch.ai &&
104
110
  patch.ai !== "none" &&
@@ -6,6 +6,8 @@ export type AppDeps = {
6
6
  passwordStore?: PasswordStore;
7
7
  webhookUrl?: string;
8
8
  secureCookie?: boolean;
9
+ /** The port `serve` is listening on, shown on the Server page. */
10
+ port?: number;
9
11
  /** Behind a reverse proxy this process trusts, the client address and the
10
12
  * scheme come from `x-forwarded-for` and `x-forwarded-proto`. */
11
13
  trustProxy?: boolean;
@@ -13,6 +15,9 @@ export type AppDeps = {
13
15
  * "printed when serve started" line. */
14
16
  loginHint?: string;
15
17
  inject500?: boolean;
18
+ /** Exposes the internal `/__ui` component gallery. `serve --debug` /
19
+ * `CM_DEBUG=1` sets it. */
20
+ debug?: boolean;
16
21
  /** Defaults to password-only when omitted, matching every caller that
17
22
  * pre-dates GitHub sign-in. */
18
23
  auth?: AuthMethods;
@@ -9,6 +9,9 @@ import { aiConfigured, readConfig, resolveAppPrivateKey } from "../config.js";
9
9
  import { listJobs } from "../store/jobs.js";
10
10
  import { handleJobsRoute } from "./api/jobs.js";
11
11
  import { handleReposRoute } from "./api/repos.js";
12
+ import { searchAll } from "../services/search.js";
13
+ import { navCounts } from "../services/nav_counts.js";
14
+ import { setNavSource } from "./pages/layout.js";
12
15
  import { handleKnowledgeRoute } from "./api/knowledge.js";
13
16
  import { handleInstallationsRoute } from "./api/installations.js";
14
17
  import { handleSettingsRoute } from "./api/settings.js";
@@ -98,6 +101,7 @@ function liveGithubConfig() {
98
101
  }
99
102
  export function createApp(deps) {
100
103
  const passwords = deps.passwordStore ?? memoryPasswordStore(deps.password);
104
+ setNavSource(() => navCounts(deps.webhookUrl ?? ""));
101
105
  return {
102
106
  async fetch(request, socketAddress = "unknown") {
103
107
  const url = new URL(request.url);
@@ -149,6 +153,9 @@ export function createApp(deps) {
149
153
  ...setupStatus(),
150
154
  });
151
155
  }
156
+ if (url.pathname === "/api/search" && request.method === "GET") {
157
+ return Response.json(searchAll(url.searchParams.get("q") ?? ""));
158
+ }
152
159
  if (url.pathname.startsWith("/api/jobs")) {
153
160
  return handleJobsRoute(request, url);
154
161
  }
@@ -3,6 +3,9 @@ export type HttpServer = {
3
3
  port: number;
4
4
  shutdown: () => Promise<void>;
5
5
  finished: Promise<void>;
6
+ /** Settles once the port is bound: rejects with the listen error (a busy
7
+ * port is `EADDRINUSE`), so nothing claims to listen before it does. */
8
+ ready: Promise<void>;
6
9
  };
7
10
  /** Starts an HTTP server that hands each request to `app`. */
8
11
  export declare function serveHttp(app: FetchApp, port: number): HttpServer;
@@ -99,9 +99,14 @@ export function serveHttp(app, port) {
99
99
  }
100
100
  })();
101
101
  });
102
+ const ready = new Promise((resolve, reject) => {
103
+ server.once("listening", () => resolve());
104
+ server.once("error", reject);
105
+ });
102
106
  server.listen(port);
103
107
  return {
104
108
  port,
109
+ ready,
105
110
  shutdown: () => new Promise((resolve) => {
106
111
  // SSE streams never end on their own, so `close()` alone would wait
107
112
  // forever. Tear the connections down, then wait for the close event