@app-vitals/agent-admin 1.34.0 → 1.35.1

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 (35) hide show
  1. package/openapi.platform.json +2 -392
  2. package/package.json +2 -2
  3. package/src/admin-boot.ts +1 -12
  4. package/src/admin-extension.ts +3 -3
  5. package/src/admin-ui-github-identity.smoke.test.ts +0 -114
  6. package/src/admin-ui-installation-repos-pages.ts +404 -0
  7. package/src/admin-ui-installation-repos-pages.unit.test.ts +57 -0
  8. package/src/admin-ui-installation-repos.smoke.test.ts +496 -0
  9. package/src/admin-ui-pages.ts +57 -9
  10. package/src/admin-ui.ts +236 -50
  11. package/src/agents-api.smoke.test.ts +2 -352
  12. package/src/agents-api.ts +5 -269
  13. package/src/github-enterprise-isolation.unit.test.ts +4 -4
  14. package/src/{github-reconcile-wiring.ts → github-installation-wiring.ts} +18 -38
  15. package/src/github-installation-wiring.unit.test.ts +111 -0
  16. package/src/github-installation.fixtures.ts +76 -0
  17. package/src/installation-ports.integration.test.ts +89 -0
  18. package/src/installation-ports.ts +207 -0
  19. package/src/installation-ports.unit.test.ts +51 -0
  20. package/src/installation-repos-service.ts +12 -12
  21. package/src/installation-repos-service.unit.test.ts +3 -3
  22. package/src/lost-access-removal.ts +9 -9
  23. package/src/lost-access-removal.unit.test.ts +7 -7
  24. package/src/reconcile-open-work.ts +5 -7
  25. package/src/repo-access-rules.ts +58 -0
  26. package/src/repo-access-rules.unit.test.ts +98 -0
  27. package/src/admin-ui-github-reconcile-pages.ts +0 -208
  28. package/src/admin-ui-github-reconcile-pages.unit.test.ts +0 -222
  29. package/src/github-reconcile-routes.integration.test.ts +0 -206
  30. package/src/github-reconcile-wiring.unit.test.ts +0 -170
  31. package/src/reconcile-apply-service.integration.test.ts +0 -271
  32. package/src/reconcile-apply-service.ts +0 -439
  33. package/src/reconcile-apply-service.unit.test.ts +0 -279
  34. package/src/reconcile-planner.ts +0 -264
  35. package/src/reconcile-planner.unit.test.ts +0 -274
@@ -0,0 +1,496 @@
1
+ /**
2
+ * admin/src/admin-ui-installation-repos.smoke.test.ts
3
+ * Smoke tests (app.request()) for the IRM-1.4 Installation repos card, the
4
+ * lost-access confirm flow, the repo-removal confirm flow (IRM-1.7) and the
5
+ * installation-coverage flag. The agents API is a stubbed seam; no DB, no network.
6
+ */
7
+
8
+ import { beforeAll, describe, expect, it } from "bun:test";
9
+ import {
10
+ AGENT_ID,
11
+ makeMockDeps,
12
+ makeSessionCookie,
13
+ } from "./admin-ui.fixtures.ts";
14
+ import { createAdminUIApp } from "./admin-ui.ts";
15
+ import { resolveDefaultSpecialtyName } from "./specialty-types.ts";
16
+
17
+ const json = (b: unknown, status = 200) =>
18
+ new Response(JSON.stringify(b), {
19
+ status,
20
+ headers: { "Content-Type": "application/json" },
21
+ });
22
+
23
+ type Api = (path: string, init?: RequestInit) => Response;
24
+
25
+ function setup(opts: {
26
+ env?: Record<string, string>;
27
+ username?: string | null;
28
+ repos?: string[];
29
+ agentsApi?: Api;
30
+ }) {
31
+ const calls: { path: string; init?: RequestInit }[] = [];
32
+ const base = makeMockDeps();
33
+ const deps = makeMockDeps({
34
+ agentService: {
35
+ ...base.agentService,
36
+ getDetail: async () => ({
37
+ id: AGENT_ID,
38
+ name: "Test Agent",
39
+ slackId: "U123456",
40
+ selfHosted: false,
41
+ specialty: resolveDefaultSpecialtyName(),
42
+ createdAt: new Date("2024-01-01"),
43
+ updatedAt: new Date("2024-01-01"),
44
+ repos: opts.repos ?? [],
45
+ reviewAuthorAllowlist: [],
46
+ patchAuthorAllowlist: [],
47
+ restrictSlackToMembers: false,
48
+ missingRequiredEnv: [],
49
+ githubUsername: opts.username === undefined ? "octo" : opts.username,
50
+ }),
51
+ },
52
+ agentEnvService: {
53
+ ...base.agentEnvService,
54
+ getByAgentId: async () => ({
55
+ env: opts.env ?? { GH_APP_ID: "123" },
56
+ secretKeys: [],
57
+ }),
58
+ },
59
+ githubEnterpriseApi: () => json({ configured: true }),
60
+ agentsApi: (path: string, init?: RequestInit) => {
61
+ calls.push({ path, init });
62
+ return opts.agentsApi ? opts.agentsApi(path, init) : json({});
63
+ },
64
+ } as never);
65
+ return { app: createAdminUIApp(deps), calls };
66
+ }
67
+
68
+ const INSTALLED = {
69
+ appId: 123,
70
+ orgs: [
71
+ {
72
+ org: "acme",
73
+ repos: [
74
+ { fullName: "acme/api", userCanPush: true },
75
+ { fullName: "acme/web", userCanPush: false },
76
+ { fullName: "acme/docs" },
77
+ ],
78
+ },
79
+ ],
80
+ };
81
+
82
+ describe("admin UI — installation repos card (IRM-1.4)", () => {
83
+ let admin: string;
84
+ let member: string;
85
+ beforeAll(async () => {
86
+ admin = await makeSessionCookie();
87
+ member = await makeSessionCookie(
88
+ undefined,
89
+ "sub-2",
90
+ "other@example.com",
91
+ false,
92
+ );
93
+ });
94
+ const h = (cookie: string) => ({ Cookie: `admin_session=${cookie}` });
95
+ const get = (app: ReturnType<typeof setup>["app"], path: string, c = admin) =>
96
+ app.request(`/admin/agents/${AGENT_ID}${path}`, { headers: h(c) });
97
+ const post = (
98
+ app: ReturnType<typeof setup>["app"],
99
+ path: string,
100
+ body: unknown,
101
+ c = admin,
102
+ ) =>
103
+ app.request(`/admin/agents/${AGENT_ID}${path}`, {
104
+ method: "POST",
105
+ headers: { ...h(c), "content-type": "application/json" },
106
+ body: JSON.stringify(body),
107
+ });
108
+
109
+ describe("card presence", () => {
110
+ it("is present for an agent with GH_APP_ID", async () => {
111
+ const { app } = setup({ agentsApi: () => json(INSTALLED) });
112
+ const html = await (await get(app, "")).text();
113
+ expect(html).toContain('id="github-installation-card"');
114
+ });
115
+
116
+ it("is absent for an agent with no GH_APP_ID", async () => {
117
+ const { app } = setup({ env: { FOO: "bar" } });
118
+ const html = await (await get(app, "")).text();
119
+ expect(html).not.toContain("github-installation-card");
120
+ });
121
+
122
+ it("is absent for a non-admin", async () => {
123
+ const { app } = setup({});
124
+ const html = await (await get(app, "", member)).text();
125
+ expect(html).not.toContain("github-installation-card");
126
+ });
127
+ });
128
+
129
+ describe("body fragment", () => {
130
+ it("lists repos per org with the push hint only when known", async () => {
131
+ const { app, calls } = setup({ agentsApi: () => json(INSTALLED) });
132
+ const res = await get(app, "/github-installation");
133
+ expect(res.status).toBe(200);
134
+ const html = await res.text();
135
+ expect(calls.at(-1)?.path).toBe(
136
+ `/agents/${AGENT_ID}/github-installation/repos`,
137
+ );
138
+ expect(html).toContain('data-org="acme"');
139
+ expect(html).toContain("acme/api");
140
+ expect(html).toContain("user can push");
141
+ expect(html).toContain("user cannot push");
142
+ // acme/docs has no hint: exactly two hint badges
143
+ expect(html.match(/>user can(not)? push</g)?.length).toBe(2);
144
+ expect(html).toContain('data-action="lost-access-preview"');
145
+ });
146
+
147
+ it("shows a distinct reason for an unbound username", async () => {
148
+ const { app } = setup({
149
+ username: null,
150
+ agentsApi: () => json(INSTALLED),
151
+ });
152
+ const html = await (await get(app, "/github-installation")).text();
153
+ expect(html).toContain('data-reason="no-username"');
154
+ expect(html).not.toContain('data-action="lost-access-preview"');
155
+ expect(html).toContain("acme/api");
156
+ });
157
+
158
+ it("shows a distinct reason for an unconfigured installer App", async () => {
159
+ const { app } = setup({
160
+ agentsApi: () => json({ error: "GitHub Apps are not configured" }, 503),
161
+ });
162
+ const res = await get(app, "/github-installation");
163
+ expect(res.status).toBe(503);
164
+ const html = await res.text();
165
+ expect(html).toContain('data-reason="installer-unconfigured"');
166
+ expect(html).not.toContain('data-reason="no-username"');
167
+ });
168
+
169
+ it("is forbidden for a non-admin and makes no call", async () => {
170
+ const { app, calls } = setup({});
171
+ const res = await get(app, "/github-installation", member);
172
+ expect(res.status).toBe(403);
173
+ expect(calls.length).toBe(0);
174
+ });
175
+ });
176
+
177
+ describe("add and remove", () => {
178
+ it("proxies add and renders the audit", async () => {
179
+ const { app, calls } = setup({
180
+ agentsApi: () =>
181
+ json({ status: "applied", auditId: "aud-1", repos: ["acme/new"] }),
182
+ });
183
+ const res = await post(app, "/github-installation/repos/add", {
184
+ repos: ["acme/new", 5],
185
+ });
186
+ const html = await res.text();
187
+ const c = calls.at(-1);
188
+ expect(c?.path).toBe(`/agents/${AGENT_ID}/github-installation/repos`);
189
+ expect(JSON.parse(String(c?.init?.body))).toEqual({
190
+ repos: ["acme/new"],
191
+ });
192
+ expect(html).toContain("Added to the installation");
193
+ expect(html).toContain("aud-1");
194
+ });
195
+
196
+ it("proxies remove and surfaces an API error", async () => {
197
+ const ok = setup({
198
+ agentsApi: () =>
199
+ json({ status: "applied", auditId: "aud-2", repos: ["acme/web"] }),
200
+ });
201
+ const res = await post(ok.app, "/github-installation/repos/remove", {
202
+ repos: ["acme/web"],
203
+ });
204
+ expect(ok.calls.at(-1)?.path).toBe(
205
+ `/agents/${AGENT_ID}/github-installation/repos/remove`,
206
+ );
207
+ expect(await res.text()).toContain("Removed from the installation");
208
+
209
+ const bad = setup({
210
+ agentsApi: () => json({ error: "App not installed on org" }, 409),
211
+ });
212
+ const err = await post(bad.app, "/github-installation/repos/remove", {
213
+ repos: ["x/y"],
214
+ });
215
+ expect(err.status).toBe(409);
216
+ expect(await err.text()).toContain("App not installed on org");
217
+ });
218
+
219
+ it("is forbidden for a non-admin", async () => {
220
+ const { app, calls } = setup({});
221
+ const res = await post(
222
+ app,
223
+ "/github-installation/repos/add",
224
+ { repos: ["a/b"] },
225
+ member,
226
+ );
227
+ expect(res.status).toBe(403);
228
+ expect(calls.length).toBe(0);
229
+ });
230
+ });
231
+
232
+ describe("remove-lost-access confirm flow", () => {
233
+ const work = [
234
+ { id: "acme/api#12", repo: "acme/api", title: "Fix <thing>" },
235
+ { id: "task-9", repo: "acme/api" },
236
+ ];
237
+ const preview = (over: Record<string, unknown> = {}) => ({
238
+ status: "previewed",
239
+ repos: ["acme/api"],
240
+ installationRemoves: ["acme/api"],
241
+ configRemoves: ["acme/api"],
242
+ skippedOrgs: [],
243
+ openWork: work,
244
+ warnings: [],
245
+ ...over,
246
+ });
247
+
248
+ it("lists what will be removed and the affected work, linked", async () => {
249
+ const { app, calls } = setup({ agentsApi: () => json(preview()) });
250
+ const res = await get(app, "/github-lost-access/preview");
251
+ const html = await res.text();
252
+ expect(calls.at(-1)?.path).toBe(
253
+ `/agents/${AGENT_ID}/github-lost-access/preview`,
254
+ );
255
+ expect(html).toContain("These 1 repos will be removed");
256
+ expect(html).toContain('href="https://github.com/acme/api/pull/12"');
257
+ expect(html).toContain("Fix &lt;thing&gt;");
258
+ expect(html).toContain("task-9");
259
+ expect(html).toContain("will be blocked");
260
+ expect(html).toContain('id="github-lost-access-apply-btn"');
261
+ expect(html).not.toContain("github-lost-access-confirm-cap");
262
+ });
263
+
264
+ it("says so when no open work is affected", async () => {
265
+ const { app } = setup({
266
+ agentsApi: () => json(preview({ openWork: [] })),
267
+ });
268
+ const html = await (await get(app, "/github-lost-access/preview")).text();
269
+ expect(html).toContain('data-open-work="none"');
270
+ expect(html).toContain("No open tasks or PRs would be blocked");
271
+ });
272
+
273
+ it("shows a preview warning and skipped orgs", async () => {
274
+ const { app } = setup({
275
+ agentsApi: () =>
276
+ json(
277
+ preview({
278
+ openWork: [],
279
+ warnings: ["open work could not be listed: boom"],
280
+ skippedOrgs: [{ org: "partial-org", reason: "partial listing" }],
281
+ }),
282
+ ),
283
+ });
284
+ const html = await (await get(app, "/github-lost-access/preview")).text();
285
+ expect(html).toContain("open work could not be listed: boom");
286
+ expect(html).toContain("partial-org");
287
+ expect(html).toContain("partial listing");
288
+ });
289
+
290
+ it("asks for the extra confirmation over the cap", async () => {
291
+ const repos = Array.from({ length: 11 }, (_, i) => `acme/r${i}`);
292
+ const { app } = setup({
293
+ agentsApi: () =>
294
+ json(preview({ repos, installationRemoves: repos, openWork: [] })),
295
+ });
296
+ const html = await (await get(app, "/github-lost-access/preview")).text();
297
+ expect(html).toContain('id="github-lost-access-confirm-cap"');
298
+ expect(html).toContain('data-over-cap="true"');
299
+ });
300
+
301
+ it("renders a skipped preview as a reason", async () => {
302
+ const { app } = setup({
303
+ agentsApi: () =>
304
+ json({ status: "skipped", reason: "GitHub user not found" }),
305
+ });
306
+ const html = await (await get(app, "/github-lost-access/preview")).text();
307
+ expect(html).toContain("GitHub user not found");
308
+ expect(html).not.toContain("github-lost-access-apply-btn");
309
+ });
310
+
311
+ it("remove sends the confirmed repos and shows the audit and blocked work", async () => {
312
+ const { app, calls } = setup({
313
+ agentsApi: (_path, init) =>
314
+ init?.method === "POST"
315
+ ? json({
316
+ status: "applied",
317
+ auditId: "aud-7",
318
+ repos: ["acme/api"],
319
+ notRemoved: [{ repo: "acme/web", reason: "still pushable" }],
320
+ warnings: [],
321
+ })
322
+ : json(preview()),
323
+ });
324
+ const res = await post(app, "/github-lost-access/remove", {
325
+ repos: ["acme/api"],
326
+ confirmRemovals: true,
327
+ });
328
+ const html = await res.text();
329
+ const removeCall = calls.find((c) => c.init?.method === "POST");
330
+ expect(removeCall?.path).toBe(
331
+ `/agents/${AGENT_ID}/github-lost-access/remove`,
332
+ );
333
+ expect(JSON.parse(String(removeCall?.init?.body))).toEqual({
334
+ repos: ["acme/api"],
335
+ confirmRemovals: true,
336
+ });
337
+ expect(html).toContain("aud-7");
338
+ expect(html).toContain("were blocked");
339
+ expect(html).toContain('href="https://github.com/acme/api/pull/12"');
340
+ expect(html).toContain("still pushable");
341
+ });
342
+
343
+ it("does not claim work blocked when the block failed", async () => {
344
+ const { app } = setup({
345
+ agentsApi: (_p, init) =>
346
+ init?.method === "POST"
347
+ ? json({
348
+ status: "applied",
349
+ auditId: "aud-8",
350
+ repos: ["acme/api"],
351
+ warnings: ["open work for acme/api was not blocked: boom"],
352
+ })
353
+ : json(preview()),
354
+ });
355
+ const html = await (
356
+ await post(app, "/github-lost-access/remove", { repos: ["acme/api"] })
357
+ ).text();
358
+ expect(html).toContain("No open tasks or PRs were blocked");
359
+ expect(html).toContain("was not blocked: boom");
360
+ });
361
+
362
+ it("surfaces the over-cap 422 from the API", async () => {
363
+ const { app } = setup({
364
+ agentsApi: (_p, init) =>
365
+ init?.method === "POST"
366
+ ? json({ error: "11 repos would be removed" }, 422)
367
+ : json(preview()),
368
+ });
369
+ const res = await post(app, "/github-lost-access/remove", {
370
+ repos: ["acme/api"],
371
+ });
372
+ expect(res.status).toBe(422);
373
+ expect(await res.text()).toContain("11 repos would be removed");
374
+ });
375
+
376
+ it("is forbidden for a non-admin", async () => {
377
+ const { app, calls } = setup({});
378
+ expect(
379
+ (await get(app, "/github-lost-access/preview", member)).status,
380
+ ).toBe(403);
381
+ expect(
382
+ (await post(app, "/github-lost-access/remove", { repos: [] }, member))
383
+ .status,
384
+ ).toBe(403);
385
+ expect(calls.length).toBe(0);
386
+ });
387
+ });
388
+
389
+ describe("agent repos list", () => {
390
+ const api: Api = (path, init) => {
391
+ if (path.endsWith("/removal-preview")) {
392
+ return json({
393
+ repo: "acme/web",
394
+ openWork: [{ id: "acme/web#3", repo: "acme/web", title: "Open PR" }],
395
+ warnings: [],
396
+ });
397
+ }
398
+ if (init?.method === "DELETE") return json({ id: AGENT_ID });
399
+ return json(INSTALLED);
400
+ };
401
+
402
+ it("flags repos the installation does not cover, only as a warning", async () => {
403
+ const { app, calls } = setup({
404
+ repos: ["acme/api", "ACME/Web", "other/gone"],
405
+ agentsApi: api,
406
+ });
407
+ const html = await (await get(app, "")).text();
408
+ expect(html).toContain('id="repos-uncovered-warning"');
409
+ expect(html).toContain("other/gone");
410
+ expect(html.match(/data-uncovered="1"/g)?.length).toBe(1);
411
+ expect(calls.every((c) => c.init?.method !== "DELETE")).toBe(true);
412
+ });
413
+
414
+ it("shows no flag when every repo is covered or coverage is unknown", async () => {
415
+ const covered = setup({ repos: ["acme/api"], agentsApi: api });
416
+ expect(await (await get(covered.app, "")).text()).not.toContain(
417
+ "repos-uncovered-warning",
418
+ );
419
+ const unknown = setup({
420
+ repos: ["other/gone"],
421
+ agentsApi: () => json({ error: "x" }, 502),
422
+ });
423
+ expect(await (await get(unknown.app, "")).text()).not.toContain(
424
+ "repos-uncovered-warning",
425
+ );
426
+ });
427
+
428
+ it("confirm step lists the affected open work", async () => {
429
+ const { app, calls } = setup({ repos: ["acme/web"], agentsApi: api });
430
+ const res = await get(app, "/repos/removal-confirm?repo=acme/web");
431
+ const html = await res.text();
432
+ expect(calls.at(-1)?.path).toBe(
433
+ `/agents/${AGENT_ID}/repos/acme/web/removal-preview`,
434
+ );
435
+ expect(html).toContain('href="https://github.com/acme/web/pull/3"');
436
+ expect(html).toContain("Open PR");
437
+ expect(html).toContain('id="repo-removal-confirm-btn"');
438
+ });
439
+
440
+ it("confirm step with no affected work and with a warning", async () => {
441
+ const none = setup({
442
+ agentsApi: () => json({ repo: "acme/web", openWork: [], warnings: [] }),
443
+ });
444
+ expect(
445
+ await (
446
+ await get(none.app, "/repos/removal-confirm?repo=acme/web")
447
+ ).text(),
448
+ ).toContain('data-open-work="none"');
449
+ const warn = setup({
450
+ agentsApi: () =>
451
+ json({
452
+ repo: "acme/web",
453
+ openWork: [],
454
+ warnings: ["open work could not be listed: boom"],
455
+ }),
456
+ });
457
+ expect(
458
+ await (
459
+ await get(warn.app, "/repos/removal-confirm?repo=acme/web")
460
+ ).text(),
461
+ ).toContain("open work could not be listed: boom");
462
+ });
463
+
464
+ it("rejects an invalid repo without calling the API", async () => {
465
+ const { app, calls } = setup({});
466
+ const res = await get(app, "/repos/removal-confirm?repo=nope");
467
+ expect(res.status).toBe(400);
468
+ expect(calls.length).toBe(0);
469
+ });
470
+
471
+ it("confirmed removal deletes via the API and shows what was blocked", async () => {
472
+ const { app, calls } = setup({ repos: ["acme/web"], agentsApi: api });
473
+ const res = await post(app, "/repos/remove-confirmed", {
474
+ repo: "acme/web",
475
+ });
476
+ const html = await res.text();
477
+ const del = calls.find((c) => c.init?.method === "DELETE");
478
+ expect(del?.path).toBe(`/agents/${AGENT_ID}/repos/acme/web`);
479
+ expect(html).toContain("Removed");
480
+ expect(html).toContain("were blocked");
481
+ expect(html).toContain("acme/web#3");
482
+ });
483
+
484
+ it("confirm routes are forbidden for a non-admin", async () => {
485
+ const { app, calls } = setup({});
486
+ expect(
487
+ (await get(app, "/repos/removal-confirm?repo=a/b", member)).status,
488
+ ).toBe(403);
489
+ expect(
490
+ (await post(app, "/repos/remove-confirmed", { repo: "a/b" }, member))
491
+ .status,
492
+ ).toBe(403);
493
+ expect(calls.length).toBe(0);
494
+ });
495
+ });
496
+ });
@@ -16,7 +16,11 @@ import {
16
16
  renderGithubAccessCard,
17
17
  renderGithubUsernameRow,
18
18
  } from "./admin-ui-github-identity-pages.ts";
19
- import { renderGithubReconcileCard } from "./admin-ui-github-reconcile-pages.ts";
19
+ import {
20
+ renderInstallationReposCard,
21
+ renderUncoveredBadge,
22
+ uncoveredRepos,
23
+ } from "./admin-ui-installation-repos-pages.ts";
20
24
  import { renderAdminPage } from "./admin-ui-layout.ts";
21
25
  import {
22
26
  BREAKPOINT_MOBILE_MAX,
@@ -986,6 +990,11 @@ export function renderAgentDetailPage(
986
990
  * false renders the card without them.
987
991
  */
988
992
  githubEnterpriseConfigured?: boolean;
993
+ /**
994
+ * IRM-1.4: every repo (owner/repo) on the agent App's installation, when it
995
+ * could be listed. Absent means unknown: no coverage warning is shown.
996
+ */
997
+ installationRepos?: readonly string[];
989
998
  },
990
999
  ): string {
991
1000
  // Reference time for relative timestamps — injected by tests for determinism,
@@ -1447,6 +1456,39 @@ export function renderAgentDetailPage(
1447
1456
  </div>`
1448
1457
  : "";
1449
1458
 
1459
+ const showGithubIdentity =
1460
+ isAdmin && opts?.githubEnterpriseConfigured === true;
1461
+ // IRM-1.7: removing a repo first shows the open work it would block.
1462
+ const repoRemovalScript = `<div id="repo-removal-confirm" style="margin-top:12px"></div>
1463
+ <script>
1464
+ (function() {
1465
+ var out = document.getElementById('repo-removal-confirm');
1466
+ if (!out) return;
1467
+ function show(r) { return r.text().then(function(t) { out.innerHTML = t; }); }
1468
+ function fail() { out.textContent = 'The request failed.'; }
1469
+ document.addEventListener('click', function(e) {
1470
+ var t = e.target;
1471
+ if (!t || !t.classList) return;
1472
+ if (t.classList.contains('repo-removal-preview-btn')) {
1473
+ out.textContent = 'Loading...';
1474
+ fetch(t.getAttribute('data-url'), { credentials: 'same-origin' }).then(show).catch(fail);
1475
+ } else if (t.id === 'repo-removal-confirm-btn') {
1476
+ t.disabled = true;
1477
+ fetch(t.getAttribute('data-url'), {
1478
+ method: 'POST',
1479
+ credentials: 'same-origin',
1480
+ headers: { 'content-type': 'application/json' },
1481
+ body: JSON.stringify({ repo: t.getAttribute('data-repo') })
1482
+ }).then(show).catch(fail);
1483
+ }
1484
+ });
1485
+ })();
1486
+ </script>`;
1487
+ const uncovered = new Set(
1488
+ opts?.installationRepos
1489
+ ? uncoveredRepos(agent.repos, opts.installationRepos)
1490
+ : [],
1491
+ );
1450
1492
  const reposSection = `<div class="card">
1451
1493
  <div class="card-title">Repos</div>
1452
1494
  <form method="POST" action="/admin/agents/${escapeHtml(agent.id)}/repos/add" style="margin-bottom:16px">
@@ -1472,13 +1514,15 @@ export function renderAgentDetailPage(
1472
1514
  : agent.repos
1473
1515
  .map(
1474
1516
  (repo) => `<tr>
1475
- <td class="mono">${escapeHtml(repo)}</td>
1476
- <td>
1477
- <form method="POST" action="/admin/agents/${escapeHtml(agent.id)}/repos/delete" style="display:inline">
1517
+ <td class="mono">${escapeHtml(repo)}${uncovered.has(repo) ? renderUncoveredBadge() : ""}</td>
1518
+ <td>${
1519
+ showGithubIdentity
1520
+ ? `<button type="button" class="btn btn-danger repo-removal-preview-btn" style="font-size:11px;padding:3px 8px" data-repo="${escapeHtml(repo)}" data-url="/admin/agents/${escapeHtml(agent.id)}/repos/removal-confirm?repo=${encodeURIComponent(repo)}">Remove</button>`
1521
+ : `<form method="POST" action="/admin/agents/${escapeHtml(agent.id)}/repos/delete" style="display:inline">
1478
1522
  <input type="hidden" name="repo" value="${escapeHtml(repo)}" />
1479
1523
  <button type="submit" class="btn btn-danger" style="font-size:11px;padding:3px 8px">Remove</button>
1480
- </form>
1481
- </td>
1524
+ </form>`
1525
+ }</td>
1482
1526
  </tr>`,
1483
1527
  )
1484
1528
  .join("\n")
@@ -1486,6 +1530,12 @@ export function renderAgentDetailPage(
1486
1530
  </tbody>
1487
1531
  </table>
1488
1532
  </div>
1533
+ ${
1534
+ uncovered.size > 0
1535
+ ? `<div class="alert alert-warning" id="repos-uncovered-warning" style="margin-top:12px">The agent App's installation does not cover ${[...uncovered].map((r) => `<span class="mono">${escapeHtml(r)}</span>`).join(", ")}. Nothing is changed automatically; add them to the installation or remove them here.</div>`
1536
+ : ""
1537
+ }
1538
+ ${showGithubIdentity ? repoRemovalScript : ""}
1489
1539
  </div>`;
1490
1540
 
1491
1541
  const authorAllowlistReviewSection = `<div class="card">
@@ -1789,8 +1839,6 @@ export function renderAgentDetailPage(
1789
1839
 
1790
1840
  // PAI-2.5: read-only trace from this agent to its Anthropic identity. Values
1791
1841
  // are user data (owner email) or provider IDs, so every one is escaped.
1792
- const showGithubIdentity =
1793
- isAdmin && opts?.githubEnterpriseConfigured === true;
1794
1842
  const identityPlaceholder = '<span style="color:#9ca3af">—</span>';
1795
1843
  const identityRow = (
1796
1844
  label: string,
@@ -1807,7 +1855,7 @@ export function renderAgentDetailPage(
1807
1855
  ${identityRow("Federation rule ID", agent.anthropicFederationRuleId, true)}
1808
1856
  ${showGithubIdentity ? renderGithubUsernameRow(agent.id, agent.githubUsername) : ""}
1809
1857
  </tbody></table>
1810
- </div>${showGithubIdentity ? renderGithubAccessCard(agent.id) : ""}${showGithubIdentity && agent.githubUsername ? renderGithubReconcileCard(agent.id) : ""}`;
1858
+ </div>${showGithubIdentity ? renderGithubAccessCard(agent.id) : ""}${showGithubIdentity && "GH_APP_ID" in envVars ? renderInstallationReposCard(agent.id) : ""}`;
1811
1859
 
1812
1860
  // Only agents with a GitHub App can make API-signed commits. Checked state
1813
1861
  // is the SHIPWRIGHT_SIGNED_COMMITS env row; when the box is hidden the field