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
@@ -1,6 +1,11 @@
1
- import { empty, html, layout, skSlot, text, when } from "./layout.js";
1
+ import { empty, html, layout, money, skSlot, text, when } from "./layout.js";
2
2
  import { formatCost } from "./cost.js";
3
+ import { crumb, icon, pageHeader } from "./ui.js";
4
+ import { readConfig, resolveAppPrivateKey } from "../../config.js";
3
5
  import { getLogsSince } from "../../services/jobs.js";
6
+ import { listRateLimitWaits, summarizeRateLimitWaits, } from "../../services/rate_limit.js";
7
+ import { getReviewByJobId } from "../../store/reviews.js";
8
+ import { rateLimitWaitDetails, rateLimitWaitNotice, } from "./rate_limit_waits.js";
4
9
  /** True for the skips a policy left waiting on a maintainer's request. */
5
10
  export function isWaitingForRequest(reason) {
6
11
  return Boolean(reason?.endsWith("waiting for a maintainer request."));
@@ -35,6 +40,20 @@ export function jobLabel(job) {
35
40
  }
36
41
  return job.type;
37
42
  }
43
+ /** The job page title, "Init · widgets": the kind of job, then the
44
+ * repository's short name. */
45
+ function jobTitle(job) {
46
+ const kind = job.type === "init"
47
+ ? "Init"
48
+ : job.type === "remake"
49
+ ? "Sync"
50
+ : job.type === "review"
51
+ ? job.pr_number
52
+ ? `Review #${job.pr_number}`
53
+ : "Review"
54
+ : job.type;
55
+ return `${kind} · ${job.repo.split("/").pop() ?? job.repo}`;
56
+ }
38
57
  function cancelReasonLabel(reason) {
39
58
  switch (reason) {
40
59
  case "dashboard_canceled":
@@ -78,6 +97,343 @@ function logBlock(logs, emptyText) {
78
97
  .map((line) => `<span class="t">${when(line.at)}</span> ${text(line.message)}`)
79
98
  .join("\n") || text(emptyText)}</div>`;
80
99
  }
100
+ function parseJobArgs(job) {
101
+ try {
102
+ const parsed = JSON.parse(job.args || "{}");
103
+ return parsed && typeof parsed === "object"
104
+ ? parsed
105
+ : {};
106
+ }
107
+ catch {
108
+ return {};
109
+ }
110
+ }
111
+ function asNumber(value) {
112
+ const n = typeof value === "number" ? value : Number(value);
113
+ return Number.isFinite(n) ? n : undefined;
114
+ }
115
+ function asString(value) {
116
+ return typeof value === "string" && value.trim() ? value : undefined;
117
+ }
118
+ function asArray(value) {
119
+ return Array.isArray(value) ? value : [];
120
+ }
121
+ function stagesOf(args) {
122
+ return asArray(args.stages).flatMap((raw) => {
123
+ if (!raw || typeof raw !== "object")
124
+ return [];
125
+ const row = raw;
126
+ const name = asString(row.name);
127
+ if (!name)
128
+ return [];
129
+ return [
130
+ {
131
+ name,
132
+ state: asString(row.state) ?? "pending",
133
+ detail: asString(row.detail),
134
+ percent: asNumber(row.percent),
135
+ },
136
+ ];
137
+ });
138
+ }
139
+ function estimateSeconds(args) {
140
+ const direct = asArray(args.estimateSeconds)
141
+ .map(asNumber)
142
+ .filter((n) => n !== undefined);
143
+ if (direct.length)
144
+ return direct;
145
+ const estimate = args.estimate;
146
+ if (!estimate || typeof estimate !== "object")
147
+ return [];
148
+ return asArray(estimate.seconds)
149
+ .map(asNumber)
150
+ .filter((n) => n !== undefined);
151
+ }
152
+ function estimateUsd(args) {
153
+ const estimate = args.estimate;
154
+ if (!estimate || typeof estimate !== "object")
155
+ return [];
156
+ return asArray(estimate.usd)
157
+ .map(asNumber)
158
+ .filter((n) => n !== undefined);
159
+ }
160
+ function runningEstimateUsd(args) {
161
+ return asNumber(args.estimate);
162
+ }
163
+ function jobDurationMs(job, args, review) {
164
+ const fromArgs = asNumber(args.durationMs);
165
+ if (fromArgs !== undefined)
166
+ return fromArgs;
167
+ if (review &&
168
+ review.duration_ms !== null &&
169
+ review.duration_ms !== undefined) {
170
+ return review.duration_ms;
171
+ }
172
+ if (job.started_at && job.finished_at) {
173
+ const start = Date.parse(job.started_at);
174
+ const end = Date.parse(job.finished_at);
175
+ if (Number.isFinite(start) && Number.isFinite(end) && end >= start) {
176
+ return end - start;
177
+ }
178
+ }
179
+ return undefined;
180
+ }
181
+ function jobCost(args, review) {
182
+ const fromArgs = asNumber(args.cost);
183
+ if (fromArgs !== undefined)
184
+ return fromArgs;
185
+ if (review &&
186
+ (review.cost_status === "known" ||
187
+ (review.cost_status === null && review.cost !== null))) {
188
+ return review.cost ?? undefined;
189
+ }
190
+ return undefined;
191
+ }
192
+ function jobDuration(ms) {
193
+ if (ms === undefined || !Number.isFinite(ms) || ms <= 0)
194
+ return "n/a";
195
+ const seconds = Math.round(ms / 1000);
196
+ if (seconds < 60)
197
+ return `${seconds}s`;
198
+ const minutes = Math.floor(seconds / 60);
199
+ const rest = seconds % 60;
200
+ return rest === 0 ? `${minutes} min` : `${minutes} min ${rest}s`;
201
+ }
202
+ function minutesRange(values) {
203
+ if (!values.length)
204
+ return "";
205
+ const minutes = values.map((value) => Math.round(value / 60));
206
+ const low = Math.min(...minutes);
207
+ const high = Math.max(...minutes);
208
+ return low === high ? `${low} min` : `${low} to ${high} min`;
209
+ }
210
+ function moneyRange(values) {
211
+ if (!values.length)
212
+ return "";
213
+ const low = Math.min(...values);
214
+ const high = Math.max(...values);
215
+ return low === high ? money(low) : `${money(low)} to ${money(high)}`;
216
+ }
217
+ function clock(iso) {
218
+ const date = new Date(iso);
219
+ if (Number.isNaN(date.getTime()))
220
+ return "--:--:--";
221
+ return date.toTimeString().slice(0, 8);
222
+ }
223
+ function logLevel(level) {
224
+ return ["info", "dim", "ok", "warn", "error"].includes(level)
225
+ ? level
226
+ : "info";
227
+ }
228
+ function logLines(logs) {
229
+ return logs
230
+ .map((line) => `<div class="line lv-${logLevel(line.level)}" data-seq="${line.seq}"><span class="t">${clock(line.at)}</span><span class="msg">${text(line.message)}</span></div>`)
231
+ .join("");
232
+ }
233
+ function logPanel(job, logs, live, status, kind) {
234
+ const count = `${logs.length} line${logs.length === 1 ? "" : "s"}`;
235
+ const lastSeq = logs.length ? logs[logs.length - 1].seq : 0;
236
+ const emptyLog = logs.length === 0
237
+ ? `<p class="log-empty">No log lines yet. New lines appear here as the job runs.</p>`
238
+ : "";
239
+ return `<div class="logpanel" data-log="${text(job.id)}" data-job="${text(job.id)}" data-live="${live ? "1" : "0"}" data-status="${text(status)}" data-seq="${lastSeq}">
240
+ <div class="lhd"><span class="st ${kind}">${text(status)}</span><h3>Log</h3><span class="cnt" role="status" aria-live="polite">${count}</span><button class="btn out" type="button" data-log-pause>Pause</button><button class="btn out" type="button" data-log-clear>Clear</button></div>
241
+ <div class="logerr" data-log-error hidden></div>
242
+ <div class="logwrap"><div class="log" tabindex="0" role="log" aria-live="off">${logLines(logs)}${emptyLog}</div><button class="jump" type="button" data-log-jump hidden>Jump to latest <span></span></button></div>
243
+ </div>`;
244
+ }
245
+ function stagesBlock(stages) {
246
+ if (!stages.length)
247
+ return "";
248
+ const rows = stages
249
+ .map((stage) => {
250
+ const state = ["done", "current", "pending", "skipped"].includes(stage.state)
251
+ ? stage.state
252
+ : "pending";
253
+ const tone = state === "done" ? "b-em" : state === "current" ? "b-sky" : "";
254
+ const mark = state === "done"
255
+ ? icon("check")
256
+ : state === "current"
257
+ ? icon("loader", "spin")
258
+ : icon("circle");
259
+ const percent = stage.percent === undefined
260
+ ? ""
261
+ : `<div class="prog" style="margin-top:6px"><i style="width:${Math.max(0, Math.min(100, stage.percent))}%"></i></div>`;
262
+ const detail = stage.detail
263
+ ? `<div class="muted" style="font-size:13px">${text(stage.detail)}</div>`
264
+ : "";
265
+ return `<li data-stage-state="${state}"><span class="ic ${tone}">${mark}</span><div style="flex:1;min-width:0"><div class="${state === "pending" ? "muted" : "strong"}">${text(stage.name)}</div>${detail}${percent}</div></li>`;
266
+ })
267
+ .join("");
268
+ return `<ul class="timeline">${rows}</ul>`;
269
+ }
270
+ function runningBody(job, args, logs) {
271
+ const spent = asNumber(args.spent);
272
+ const estimate = runningEstimateUsd(args);
273
+ const seconds = estimateSeconds(args);
274
+ const spentText = spent === undefined
275
+ ? ""
276
+ : `${money(spent)}${estimate === undefined ? "" : ` of ~${money(estimate)}`}`;
277
+ const details = [
278
+ spentText
279
+ ? `<div><dt>Spent so far</dt><dd class="tnum">${spentText}</dd></div>`
280
+ : "",
281
+ seconds.length
282
+ ? `<div><dt>Estimated time</dt><dd>${minutesRange(seconds)} left</dd></div>`
283
+ : "",
284
+ ].join("");
285
+ return `<div class="card"><div class="bd">
286
+ <div class="notice bad" data-job-refresh-error hidden></div>
287
+ <div data-job-progress>
288
+ ${stagesBlock(stagesOf(args))}
289
+ ${details ? `<dl class="dl" style="margin-top:8px">${details}</dl>` : ""}
290
+ </div>
291
+ ${logPanel(job, logs, true, job.status === "queued" ? "Queued" : "Running", "run")}
292
+ </div></div>`;
293
+ }
294
+ function producedOf(args, job, review) {
295
+ const raw = args.produced;
296
+ if (raw && typeof raw === "object") {
297
+ const row = raw;
298
+ const label = asString(row.label);
299
+ const detail = asString(row.detail);
300
+ if (label || detail) {
301
+ return { label: label ?? "Done", detail: detail ?? "" };
302
+ }
303
+ }
304
+ if (review) {
305
+ const count = review.findings_count;
306
+ return {
307
+ label: `${count} finding${count === 1 ? "" : "s"}`,
308
+ detail: `from the review of ${job.repo}#${job.pr_number ?? ""}`,
309
+ };
310
+ }
311
+ if (job.type === "init" || job.type === "remake") {
312
+ return {
313
+ label: "No guide yet",
314
+ detail: "There is not enough review history to learn from yet. Once this repository has a few reviewed pull requests, run the sync again.",
315
+ };
316
+ }
317
+ return {
318
+ label: "Knowledge updated",
319
+ detail: `from ${job.repo}`,
320
+ };
321
+ }
322
+ function defaultNextAction(job, appConfigured) {
323
+ if (job.type === "review") {
324
+ return "Open the pull request to read the review.";
325
+ }
326
+ if (job.type === "init" || job.type === "remake") {
327
+ return appConfigured
328
+ ? "Open a pull request on the repository. It will be reviewed automatically."
329
+ : "Open a pull request on the repository. Connect the GitHub App first so pull requests get reviewed.";
330
+ }
331
+ return "Open the repository to see what changed.";
332
+ }
333
+ function doneBody(job, args, logs, review) {
334
+ const config = readConfig();
335
+ const appConfigured = Boolean(config.githubAppId && resolveAppPrivateKey(config));
336
+ const produced = producedOf(args, job, review);
337
+ const durationMs = jobDurationMs(job, args, review);
338
+ const cost = jobCost(args, review);
339
+ const seconds = estimateSeconds(args);
340
+ const usd = estimateUsd(args);
341
+ const tookDetail = seconds.length
342
+ ? `estimate was ${minutesRange(seconds)}`
343
+ : "";
344
+ const costDetail = usd.length ? `estimate was ${moneyRange(usd)}` : "";
345
+ const providedNext = asString(args.nextAction);
346
+ const promisedAutomatic = providedNext !== undefined &&
347
+ /reviewed automatically|review automatically|will be reviewed/i.test(providedNext);
348
+ const next = !appConfigured && promisedAutomatic
349
+ ? defaultNextAction(job, false)
350
+ : (providedNext ?? defaultNextAction(job, appConfigured));
351
+ const appLink = !appConfigured && (job.type === "init" || job.type === "remake")
352
+ ? `<a class="btn out" href="/settings/github">Connect the GitHub App</a>`
353
+ : "";
354
+ return `<div class="stats three">
355
+ <div class="stat"><div class="top">Learned</div><div class="v">${text(produced.label)}</div><div class="h">${text(produced.detail)}</div></div>
356
+ <div class="stat"><div class="top">Took</div><div class="v tnum">${jobDuration(durationMs)}</div><div class="h">${text(tookDetail)}</div></div>
357
+ <div class="stat"><div class="top">Cost</div><div class="v tnum">${cost === undefined ? "unknown" : money(cost)}</div><div class="h">${text(costDetail)}</div></div>
358
+ </div>
359
+ <div class="card"><div class="bd">
360
+ <h2>Next</h2>
361
+ <p>${text(next)}</p>
362
+ <div style="display:flex;gap:8px;flex-wrap:wrap;margin-bottom:14px">
363
+ <a class="btn primary" href="/repos/${text(job.repo)}/knowledge">See the guides</a>
364
+ <a class="btn out" href="/repos/${text(job.repo)}/pulls">Review an open PR</a>
365
+ ${appLink}
366
+ </div>
367
+ ${logPanel(job, logs, false, "Done", "done")}
368
+ </div></div>`;
369
+ }
370
+ function noteStatus(review) {
371
+ if (!review)
372
+ return "";
373
+ return review.note_comment_id
374
+ ? "a note was left on the pull request"
375
+ : "could not post a note on the pull request";
376
+ }
377
+ function failureExplanation(error) {
378
+ const value = (error ?? "").toLowerCase();
379
+ if (/empty (answer|review)|returned an empty/.test(value)) {
380
+ return "The model returned an empty answer, so no review was written.";
381
+ }
382
+ if (/\b403\b|resource not accessible|access denied|forbidden/.test(value)) {
383
+ return "GitHub denied the request with a 403. The GitHub App may be missing a permission.";
384
+ }
385
+ if (/\b429\b|too many requests|rate limit/.test(value)) {
386
+ return "GitHub rate limit reached with a 429. Wait a moment and retry.";
387
+ }
388
+ if (/timed out|timeout/.test(value)) {
389
+ return "The request timed out. The provider did not answer in time.";
390
+ }
391
+ return "";
392
+ }
393
+ /** The model a failed job ran with. A manual or webhook review does not put
394
+ * the model in its job args; the review row records the one it resolved.
395
+ * "unknown" is what a review stores when no model was set. */
396
+ function failedModel(args, review) {
397
+ const fromReview = review?.model && review.model !== "unknown" ? review.model : undefined;
398
+ return fromReview ?? asString(args.model);
399
+ }
400
+ function failedBody(job, args, logs, review) {
401
+ const provider = asString(args.provider);
402
+ const model = failedModel(args, review);
403
+ const note = noteStatus(review);
404
+ const durationMs = jobDurationMs(job, args, review);
405
+ const cost = jobCost(args, review);
406
+ const explanation = failureExplanation(job.error);
407
+ const rows = [
408
+ provider ? `<div><dt>Provider</dt><dd>${text(provider)}</dd></div>` : "",
409
+ model
410
+ ? `<div><dt>Model</dt><dd class="mono">${text(model)}</dd></div>`
411
+ : "",
412
+ note ? `<div><dt>Pull request note</dt><dd>${text(note)}</dd></div>` : "",
413
+ durationMs !== undefined
414
+ ? `<div><dt>Duration</dt><dd class="tnum">${jobDuration(durationMs)}</dd></div>`
415
+ : "",
416
+ cost !== undefined
417
+ ? `<div><dt>Cost</dt><dd class="tnum">${money(cost)}</dd></div>`
418
+ : "",
419
+ ].join("");
420
+ return `<div class="card"><div class="bd">
421
+ ${rows ? `<dl class="dl">${rows}</dl>` : ""}
422
+ ${explanation
423
+ ? `<div class="notice bad"><div class="txt">${text(explanation)}</div></div>`
424
+ : ""}
425
+ ${logPanel(job, logs, false, "Failed", "failed")}
426
+ </div></div>`;
427
+ }
428
+ function otherBody(job, logs) {
429
+ const status = job.status === "canceled"
430
+ ? "Canceled"
431
+ : job.status === "queued"
432
+ ? "Queued"
433
+ : job.status;
434
+ const kind = job.status === "canceled" ? "warn" : "run";
435
+ return `<div class="card"><div class="bd">${logPanel(job, logs, false, status, kind)}</div></div>`;
436
+ }
81
437
  function liveCard(job) {
82
438
  const logs = getLogsSince(job.id).slice(-24);
83
439
  return `<div class="card" data-async>
@@ -149,7 +505,7 @@ export function renderActivity(username, running, feed, skipped) {
149
505
  return html(layout({
150
506
  title: "Activity · co-maintainer",
151
507
  username,
152
- active: "activity",
508
+ active: "/activity",
153
509
  body: `<div class="wrap" id="activity-root">
154
510
  <div class="pagehead">
155
511
  <div><h1>Activity</h1>
@@ -171,6 +527,12 @@ export function renderActivity(username, running, feed, skipped) {
171
527
  }));
172
528
  }
173
529
  export function renderJob(username, job, logs) {
530
+ const args = parseJobArgs(job);
531
+ const review = getReviewByJobId(job.id);
532
+ const waits = listRateLimitWaits(job.id);
533
+ const waitSummary = summarizeRateLimitWaits(waits);
534
+ const waitNotice = rateLimitWaitNotice(waits, waitSummary, "Rate-limit waits");
535
+ const waitDetails = rateLimitWaitDetails(waits);
174
536
  const live = job.status === "queued" || job.status === "running";
175
537
  const failed = job.status === "failed";
176
538
  const error = job.error
@@ -179,35 +541,66 @@ export function renderJob(username, job, logs) {
179
541
  const canceled = job.status === "canceled" && job.cancel_reason
180
542
  ? `<div class="notice warn"><div class="txt">${text(cancelReasonLabel(job.cancel_reason))}</div></div>`
181
543
  : "";
544
+ // A queued job has not started a step yet: it waits, and can be cancelled
545
+ // outright rather than stopped after a step.
546
+ const queued = job.status === "queued";
182
547
  const stop = live
183
- ? `<button class="btn sm" data-cancel="${text(job.id)}">Stop</button>`
548
+ ? `<button class="btn out" type="button" data-cancel="${text(job.id)}">${icon("square")}${queued ? "Cancel" : "Stop after this step"}</button>`
184
549
  : "";
550
+ const left = live ? minutesRange(estimateSeconds(args)) : "";
551
+ const lead = queued
552
+ ? `Queued ${when(job.created_at)} · waiting for a worker`
553
+ : live
554
+ ? `Started ${when(job.started_at ?? job.created_at)}${left ? ` · about ${left} left` : ""}`
555
+ : `<a href="/repos/${text(job.repo)}">${text(job.repo)}</a> · ${text(job.status)}`;
556
+ const retryModel = failedModel(args, review);
185
557
  let retry = "";
186
558
  if (failed && (job.type === "init" || job.type === "remake")) {
187
- retry = `<button class="primary" data-post="/api/repos/${text(job.repo)}/remake">Retry</button>`;
559
+ retry = `<button class="primary" type="button" data-post="/api/repos/${text(job.repo)}/remake">Retry</button>`;
188
560
  }
189
561
  else if (failed && job.type === "review" && job.pr_number) {
190
- retry = `<button class="primary" data-post="/api/repos/${text(job.repo)}/pulls/${job.pr_number}/review">Retry</button>`;
562
+ // The model travels with the retry, so a config change since the
563
+ // failure does not swap it for another one.
564
+ retry = `<button class="primary" type="button" data-post="/api/repos/${text(job.repo)}/pulls/${job.pr_number}/review"${retryModel
565
+ ? ` data-body="${text(JSON.stringify({ model: retryModel }))}"`
566
+ : ""}>Retry with the same model</button>`;
567
+ }
568
+ const changeModel = failed
569
+ ? `<a class="btn out" href="/settings/ai">Change default model</a>`
570
+ : "";
571
+ let body;
572
+ if (live) {
573
+ body = runningBody(job, args, logs);
574
+ }
575
+ else if (job.status === "done") {
576
+ body = doneBody(job, args, logs, review);
577
+ }
578
+ else if (failed) {
579
+ body = failedBody(job, args, logs, review);
580
+ }
581
+ else {
582
+ body = otherBody(job, logs);
191
583
  }
192
584
  return html(layout({
193
585
  title: `${jobLabel(job)} · co-maintainer`,
194
586
  username,
195
- active: "activity",
196
- body: `<div class="wrap" id="activity-root" style="max-width:760px">
197
- <div class="crumbs"><a href="/activity">Activity</a> / ${text(jobLabel(job))}</div>
198
- <div class="pagehead">
199
- <div>
200
- <h1>${text(jobLabel(job))}</h1>
201
- <p class="lead"><a href="/repos/${text(job.repo)}">${text(job.repo)}</a> · ${text(job.status)}</p>
202
- </div>
203
- <div class="actions">${stop}${retry}</div>
204
- </div>
587
+ active: "/activity",
588
+ body: `<div class="wrap narrow" id="activity-root">
589
+ ${pageHeader({
590
+ title: jobTitle(job),
591
+ leadHtml: lead,
592
+ crumb: crumb([
593
+ { label: "Activity", href: "/activity" },
594
+ { label: jobLabel(job) },
595
+ ]),
596
+ actions: `${stop}${retry}${changeModel}`,
597
+ })}
205
598
  ${error}${canceled}
206
- <div class="card" data-async>
599
+ <div data-async>
207
600
  ${skSlot()}
208
- <div class="hd"><h2>Log</h2>
209
- <span class="muted" style="margin-left:auto;font-size:13px">${logs.length} lines</span></div>
210
- <div class="bd">${logBlock(logs, "No log lines were written.")}</div>
601
+ ${waitNotice}
602
+ ${body}
603
+ ${waitDetails}
211
604
  </div>
212
605
  </div>`,
213
606
  }));
@@ -45,7 +45,8 @@ export function renderAddRepo(username, picker) {
45
45
  return html(layout({
46
46
  title: "Add repository · co-maintainer",
47
47
  username,
48
- body: `<div class="wrap" style="max-width:760px">
48
+ active: "/",
49
+ body: `<div class="wrap narrow">
49
50
  <div class="crumbs"><a href="/">Repositories</a> / Add</div>
50
51
  <div class="pagehead">
51
52
  <div><h1>Add repository</h1>
@@ -63,6 +64,10 @@ export function renderAddRepo(username, picker) {
63
64
  <button class="primary" id="preview"${canAdd ? "" : " disabled"}>Preview</button>
64
65
  </div>
65
66
  <div id="plan" hidden></div>
67
+ <details class="cli" id="cli-equivalent">
68
+ <summary>CLI equivalent</summary>
69
+ <p class="mono" style="word-break:break-all">co-maintainer init owner/repo</p>
70
+ </details>
66
71
  </div></div>
67
72
  </div>
68
73
  <script>
@@ -1,8 +1,55 @@
1
1
  import { bars, count, delta, duration, empty, html, layout, money, text, } from "./layout.js";
2
2
  import { formatCostTotal } from "./cost.js";
3
3
  import { listJobs } from "../../store/jobs.js";
4
+ import { pageHeader, segmented, statCard } from "./ui.js";
4
5
  export function renderAnalytics(username, range, data) {
5
6
  const failed = listJobs({ status: "failed" }).slice(0, 5);
7
+ const current = ["7d", "30d", "90d"].includes(range) ? range : "30d";
8
+ const kind = (name) => data.byKind.find((row) => row.kind === name);
9
+ // Every review kind costs money, so Spent sums all of them, not only the
10
+ // posted pull request reviews.
11
+ const spent = data.byKind.reduce((sum, row) => ({
12
+ cost: sum.cost + row.cost,
13
+ knownCount: sum.knownCount + row.knownCount,
14
+ unknownCount: sum.unknownCount + row.unknownCount,
15
+ byokUsd: sum.byokUsd + row.byokUsd,
16
+ byokKnownCount: sum.byokKnownCount + row.byokKnownCount,
17
+ byokUnknownCount: sum.byokUnknownCount + row.byokUnknownCount,
18
+ }), {
19
+ cost: 0,
20
+ knownCount: 0,
21
+ unknownCount: 0,
22
+ byokUsd: 0,
23
+ byokKnownCount: 0,
24
+ byokUnknownCount: 0,
25
+ });
26
+ const kindRows = [
27
+ ["init / sync", String(data.setupRuns), "Not recorded"],
28
+ [
29
+ "Pull request reviews",
30
+ String(kind("posted").runs),
31
+ formatCostTotal(kind("posted")),
32
+ ],
33
+ [
34
+ "Not posted reviews",
35
+ String(kind("not_posted").runs),
36
+ formatCostTotal(kind("not_posted")),
37
+ ],
38
+ [
39
+ "Failed attempts",
40
+ String(kind("failed").runs),
41
+ formatCostTotal(kind("failed")),
42
+ ],
43
+ ["CLI reviews", String(kind("cli").runs), formatCostTotal(kind("cli"))],
44
+ ];
45
+ const byKind = `<table>
46
+ <thead><tr><th>Kind</th><th class="num">Runs</th><th class="num">Cost</th></tr></thead>
47
+ <tbody>
48
+ ${kindRows
49
+ .map(([label, runs, cost]) => `<tr><td>${text(label)}</td><td class="num">${runs}</td><td class="num">${text(cost)}</td></tr>`)
50
+ .join("")}
51
+ </tbody>
52
+ </table>`;
6
53
  const totalFindings = data.bySeverity.reduce((sum, row) => sum + row.findings, 0);
7
54
  const byRepo = data.byRepo.length === 0
8
55
  ? empty("No usage yet", "Cost and findings show up after reviews run.")
@@ -100,33 +147,61 @@ export function renderAnalytics(username, range, data) {
100
147
  return html(layout({
101
148
  title: "Usage · co-maintainer",
102
149
  username,
103
- active: "analytics",
150
+ active: "/usage",
104
151
  body: `<div class="wrap">
105
- <div class="pagehead">
106
- <div><h1>Usage</h1>
107
- <p class="lead">Last ${data.days} days</p></div>
108
- <div class="actions">
109
- <select id="range" style="width:150px">
110
- <option value="7d"${range === "7d" ? " selected" : ""}>Last 7 days</option>
111
- <option value="30d"${range === "30d" ? " selected" : ""}>Last 30 days</option>
112
- <option value="90d"${range === "90d" ? " selected" : ""}>Last 90 days</option>
113
- </select>
114
- </div>
152
+ ${pageHeader({
153
+ title: "Usage",
154
+ lead: `Last ${data.days} days`,
155
+ actions: segmented(["7d", "30d", "90d"].map((value) => ({
156
+ label: value,
157
+ href: `/usage?range=${value}`,
158
+ on: value === current,
159
+ }))),
160
+ })}
161
+ <div class="stats">
162
+ ${statCard({
163
+ label: "Spent",
164
+ value: formatCostTotal(spent),
165
+ hint: `${count(data.totals.tokensIn + data.totals.tokensOut)} tokens · ${count(data.totals.tokensIn)} in and ${count(data.totals.tokensOut)} out${delta(data.change.cost, data.days, true)}`,
166
+ icon: "coins",
167
+ })}
168
+ ${statCard({
169
+ label: "Reviews",
170
+ value: String(kind("posted").runs + kind("not_posted").runs),
171
+ hint: [
172
+ kind("failed").runs > 0
173
+ ? `${kind("failed").runs} failed ${kind("failed").runs === 1 ? "attempt" : "attempts"}`
174
+ : "",
175
+ kind("not_posted").runs > 0
176
+ ? `${kind("not_posted").runs} not posted`
177
+ : "",
178
+ ]
179
+ .filter(Boolean)
180
+ .join(" · ") || undefined,
181
+ icon: "git-pull-request",
182
+ })}
183
+ ${statCard({
184
+ label: "Findings",
185
+ value: String(data.totals.findings),
186
+ hint: `${data.totals.pullRequests} pull requests${delta(data.change.findings, data.days)}`,
187
+ icon: "flag",
188
+ })}
189
+ ${statCard({
190
+ label: "Avg. review",
191
+ value: duration(data.totals.avgDurationMs),
192
+ icon: "timer",
193
+ })}
115
194
  </div>
116
- <div class="card"><div class="bd">
117
- <div class="kfig wrap4">
118
- <div><div class="k">Pull requests reviewed</div><div class="big">${data.totals.pullRequests}</div>${delta(data.change.pullRequests, data.days)}</div>
119
- <div><div class="k">Findings</div><div class="big">${data.totals.findings}</div>${delta(data.change.findings, data.days)}</div>
120
- <div><div class="k">Cost</div><div class="big">${formatCostTotal(data.totals)}</div>${delta(data.change.cost, data.days, true)}</div>
121
- <div><div class="k">Tokens</div><div class="big">${count(data.totals.tokensIn + data.totals.tokensOut)}</div><div class="trend">${count(data.totals.tokensIn)} in and ${count(data.totals.tokensOut)} out</div></div>
122
- <div><div class="k">Average review</div><div class="big">${duration(data.totals.avgDurationMs)}</div></div>
123
- <div><div class="k">Rounds per pull request</div><div class="big">${data.totals.pullRequests
124
- ? (data.totals.reviews / data.totals.pullRequests).toFixed(1)
125
- : "0"}</div>${data.totals.failed
126
- ? `<div class="trend down">${data.totals.failed} failed</div>`
127
- : ""}</div>
195
+ <div class="cols c11">
196
+ <div class="card">
197
+ <div class="hd"><h2>By kind</h2></div>
198
+ <div class="bd flush">${byKind}</div>
199
+ </div>
200
+ <div class="card">
201
+ <div class="hd"><h2>By model</h2></div>
202
+ <div class="bd flush">${byModel}</div>
128
203
  </div>
129
- </div></div>
204
+ </div>
130
205
  <div class="card">
131
206
  <div class="hd"><h2>Cost per day</h2></div>
132
207
  <div class="bd">
@@ -143,10 +218,6 @@ export function renderAnalytics(username, range, data) {
143
218
  <div class="hd"><h2>By repository</h2></div>
144
219
  <div class="bd flush">${byRepo}</div>
145
220
  </div>
146
- <div class="card">
147
- <div class="hd"><h2>By model</h2></div>
148
- <div class="bd flush">${byModel}</div>
149
- </div>
150
221
  <div class="card">
151
222
  <div class="hd"><h2>By remote token</h2></div>
152
223
  <div class="bd flush">${byRemoteToken}</div>
@@ -161,9 +232,6 @@ export function renderAnalytics(username, range, data) {
161
232
  </div>
162
233
  </div>
163
234
  <script>
164
- document.getElementById("range").addEventListener("change", function() {
165
- location.href = "/analytics?range=" + this.value;
166
- });
167
235
  (function() {
168
236
  var key = "co-maintainer:dismissed-worth";
169
237
  var read = function() {
@@ -0,0 +1 @@
1
+ export declare function renderCatalog(): Response;