co-maintainer 0.6.3 → 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 (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 +104 -5
  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
@@ -2,10 +2,10 @@ import { clearOauthStateCookieHeader, clearSessionCookieHeader, createSession, l
2
2
  import { githubAuthorizeUrl, githubLoginFromCode } from "../../github/oauth.js";
3
3
  import { handleClient, handleLogo, handleStyles } from "../assets.js";
4
4
  import { activityFeed, listReposForHome, prDetail, repoKnowledge, RepoNotFound, repoOverview, repoPulls, repoRemoteReviews, runningJobs, skippedDeliveries, statsForRange, } from "../../services/dashboard.js";
5
- import { escapeHtml, html } from "./layout.js";
5
+ import { escapeHtml, html, notFound } from "./layout.js";
6
6
  import { formatCostTotal } from "./cost.js";
7
- import { readConfig, resolveAppPrivateKey, writeUserConfig, } from "../../config.js";
8
- import { aiConfigured } from "../../config.js";
7
+ import { readConfig, writeUserConfig } from "../../config.js";
8
+ import {} from "../../config.js";
9
9
  import { appNameProblem, beginManifestState, buildAppManifest, consumeManifestState, convertManifest, } from "../../github/app_manifest.js";
10
10
  import { renderHome, renderLogin } from "./home.js";
11
11
  import { renderSetup } from "./setup.js";
@@ -18,12 +18,15 @@ import { renderKnowledge } from "./knowledge.js";
18
18
  import { renderRepoSettings } from "./repo_settings.js";
19
19
  import { renderActivity, renderJob } from "./activity.js";
20
20
  import { renderAnalytics } from "./analytics.js";
21
- import { renderSettings } from "./settings.js";
21
+ import { renderSettings, renderSettingsPage } from "./settings.js";
22
+ import { renderCatalog } from "./catalog.js";
22
23
  import { getRepo } from "../../store/repos.js";
24
+ import { cacheGet } from "../../store/cache_db.js";
23
25
  import { getJob } from "../../store/jobs.js";
24
26
  import { getLogsSince } from "../../services/jobs.js";
25
27
  import { listInstallationsWithRepos, listOpenPulls } from "../../github/app.js";
26
28
  import { setupChecklist } from "../../services/setup_checklist.js";
29
+ import { appReady, filterRepoList, repoState, } from "../../services/repo_list.js";
27
30
  const REPO = /^\/repos\/([^/]+)\/([^/]+)(?:\/(pulls|knowledge|settings|remote)(?:\/(\d+))?)?$/;
28
31
  /** Matches a repository page URL. Only `pulls` is keyed by a number, so a stray
29
32
  * suffix such as `/repos/o/r/remote/7` must fall through to a 404 rather than
@@ -107,17 +110,27 @@ export async function handlePageRequest(request, deps, ip) {
107
110
  }
108
111
  const username = session.username;
109
112
  try {
113
+ if (url.pathname === "/__ui" && request.method === "GET") {
114
+ if (!deps.debug)
115
+ return undefined;
116
+ return renderCatalog();
117
+ }
110
118
  if (url.pathname === "/" && request.method === "GET") {
111
119
  const config = readConfig();
112
- return renderHome(username, listReposForHome().map(toHomeRow), setupChecklist(config.webhookUrl || deps.webhookUrl || ""));
120
+ const all = listReposForHome();
121
+ const ready = appReady();
122
+ const q = url.searchParams.get("q") ?? "";
123
+ const status = url.searchParams.get("status") ?? "all";
124
+ return renderHome(username, filterRepoList(all, { q, status }, ready).map((item) => toHomeRow(item, ready)), setupChecklist(config.webhookUrl || deps.webhookUrl || ""), {
125
+ q,
126
+ status,
127
+ total: all.length,
128
+ reviewing: all.filter((item) => repoState(item, ready) === "reviewing").length,
129
+ });
113
130
  }
114
131
  if (url.pathname === "/setup" && request.method === "GET") {
115
132
  const config = readConfig();
116
- return renderSetup(username, {
117
- ai: aiConfigured(config),
118
- github: Boolean(config.auth === "gh" || (config.auth === "pat" && config.githubPat)),
119
- app: Boolean(config.githubAppId && resolveAppPrivateKey(config)),
120
- });
133
+ return renderSetup(username, setupChecklist(config.webhookUrl || deps.webhookUrl || ""));
121
134
  }
122
135
  if (url.pathname === "/repos/new" && request.method === "GET") {
123
136
  return renderAddRepo(username, await repoPicker(deps.githubApp));
@@ -136,17 +149,31 @@ export async function handlePageRequest(request, deps, ip) {
136
149
  const jobMatch = /^\/activity\/([^/]+)$/.exec(url.pathname);
137
150
  if (jobMatch && request.method === "GET") {
138
151
  const job = getJob(jobMatch[1]);
139
- if (!job)
140
- return new Response("not found", { status: 404 });
152
+ if (!job) {
153
+ return notFound(username, "That job is not on this server.", "/activity");
154
+ }
141
155
  return renderJob(username, job, getLogsSince(job.id));
142
156
  }
143
157
  if (url.pathname === "/analytics" && request.method === "GET") {
158
+ return Response.redirect(`${url.origin}/usage${url.search}`, 303);
159
+ }
160
+ if (url.pathname === "/usage" && request.method === "GET") {
144
161
  const range = url.searchParams.get("range") ?? "30d";
145
162
  return renderAnalytics(username, range, statsForRange(range));
146
163
  }
147
164
  if (url.pathname === "/settings" && request.method === "GET") {
148
165
  const config = readConfig();
149
- return renderSettings(username, config, config.webhookUrl || deps.webhookUrl || "", requestBaseUrl(request, url, Boolean(deps.trustProxy)));
166
+ return renderSettings(username, config, config.webhookUrl || deps.webhookUrl || "", requestBaseUrl(request, url, Boolean(deps.trustProxy)), { port: deps.port, trustProxy: Boolean(deps.trustProxy) });
167
+ }
168
+ const settingsMatch = /^\/settings\/([a-z-]+)$/.exec(url.pathname);
169
+ if (settingsMatch && request.method === "GET") {
170
+ const section = settingsMatch[1];
171
+ const config = readConfig();
172
+ const page = renderSettingsPage(username, config, config.webhookUrl || deps.webhookUrl || "", requestBaseUrl(request, url, Boolean(deps.trustProxy)), section, { port: deps.port, trustProxy: Boolean(deps.trustProxy) });
173
+ if (!page) {
174
+ return notFound(username, `There is no settings page called ${section}.`, undefined);
175
+ }
176
+ return page;
150
177
  }
151
178
  const match = matchRepo(url.pathname);
152
179
  if (match && request.method === "GET") {
@@ -169,34 +196,54 @@ export async function handlePageRequest(request, deps, ip) {
169
196
  return renderRepoRemote(username, fullName, repoRemoteReviews(fullName));
170
197
  }
171
198
  if (sub === "knowledge") {
172
- return renderKnowledge(username, await repoKnowledge(fullName), url.searchParams.get("view") ?? undefined);
199
+ const knowledge = await repoKnowledge(fullName);
200
+ const viewId = url.searchParams.get("view") ?? undefined;
201
+ const doc = viewId
202
+ ? knowledge.docs.find((item) => item.id === viewId)
203
+ : undefined;
204
+ if (viewId && !doc) {
205
+ return notFound(username, "That document is not on this server.", `/repos/${fullName}/knowledge`);
206
+ }
207
+ if (doc && url.searchParams.get("download") === "1") {
208
+ return new Response(doc.text, {
209
+ status: 200,
210
+ headers: {
211
+ "content-type": "text/markdown; charset=utf-8",
212
+ "content-disposition": `attachment; filename="${doc.file}"`,
213
+ },
214
+ });
215
+ }
216
+ return renderKnowledge(username, knowledge, viewId);
173
217
  }
174
218
  if (sub === "settings") {
175
219
  const config = readConfig();
176
- return renderRepoSettings(username, row, config.repos?.[fullName] ?? {});
220
+ let probeReport;
221
+ try {
222
+ const raw = await cacheGet("probe", fullName);
223
+ const parsed = raw ? JSON.parse(raw) : undefined;
224
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
225
+ probeReport = parsed;
226
+ }
227
+ }
228
+ catch {
229
+ // A missing or unreadable probe cache simply means no recommendation.
230
+ }
231
+ return renderRepoSettings(username, row, config.repos?.[fullName] ?? {}, probeReport);
177
232
  }
178
233
  }
179
234
  }
180
235
  catch (error) {
181
236
  if (error instanceof RepoNotFound) {
182
- return new Response("not found", { status: 404 });
237
+ return notFound(username, `That repository is not on this server.`, undefined);
183
238
  }
184
239
  throw error;
185
240
  }
241
+ if (!url.pathname.startsWith("/api/")) {
242
+ return notFound(username, `Nothing is at ${url.pathname}.`, undefined);
243
+ }
186
244
  return undefined;
187
245
  }
188
- function toHomeRow(item) {
189
- const job = item.latestJob;
190
- let statusKind = "ok";
191
- let status = "Active";
192
- if (job && (job.status === "running" || job.status === "queued")) {
193
- statusKind = "run";
194
- status = "Setting up";
195
- }
196
- else if (job?.status === "failed" && !item.repo.knowledge_built_at) {
197
- statusKind = "err";
198
- status = "Setup failed";
199
- }
246
+ function toHomeRow(item, ready) {
200
247
  let knowledge = "Not built";
201
248
  let knowledgeAt;
202
249
  if (item.repo.knowledge_built_at) {
@@ -206,12 +253,13 @@ function toHomeRow(item) {
206
253
  }
207
254
  return {
208
255
  fullName: item.repo.full_name,
209
- statusKind,
210
- status,
256
+ state: repoState(item, ready),
257
+ autoOn: item.repo.auto_review === 1,
258
+ fromCli: item.repo.added_from === "cli",
211
259
  knowledge,
212
260
  knowledgeAt,
213
- autoOn: item.repo.auto_review === 1,
214
261
  reviews: String(item.stats.reviews),
262
+ failed: item.stats.failed,
215
263
  cost: formatCostTotal(item.stats),
216
264
  };
217
265
  }
@@ -251,10 +299,13 @@ async function repoPicker(githubApp) {
251
299
  function isPagePath(pathname) {
252
300
  return (pathname === "/" ||
253
301
  pathname === "/setup" ||
302
+ pathname === "/__ui" ||
254
303
  pathname === "/activity" ||
255
304
  pathname.startsWith("/activity/") ||
256
305
  pathname === "/analytics" ||
306
+ pathname === "/usage" ||
257
307
  pathname === "/settings" ||
308
+ pathname.startsWith("/settings/") ||
258
309
  pathname === "/repos/new" ||
259
310
  pathname.startsWith("/repos/"));
260
311
  }
@@ -1,2 +1,11 @@
1
1
  import type { UserConfig } from "../../config.ts";
2
- export declare function renderSettings(username: string, config: UserConfig, webhookUrl: string, baseUrl: string): Response;
2
+ export type SettingsSection = "ai" | "github" | "defaults" | "remote" | "server" | "sign-in" | "danger";
3
+ export declare const SETTINGS_SECTIONS: readonly SettingsSection[];
4
+ export type RuntimeInfo = {
5
+ port?: number;
6
+ trustProxy?: boolean;
7
+ };
8
+ /** The combined `/settings` landing keeps every card (and the old bookmarks
9
+ * working) while each heading also has its own page. */
10
+ export declare function renderSettings(username: string, config: UserConfig, webhookUrl: string, baseUrl: string, runtime?: RuntimeInfo): Response;
11
+ export declare function renderSettingsPage(username: string, config: UserConfig, webhookUrl: string, baseUrl: string, section: SettingsSection, runtime?: RuntimeInfo): Response | undefined;