@app-vitals/agent-admin 1.28.0 → 1.30.0

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.
@@ -6,12 +6,12 @@
6
6
  */
7
7
 
8
8
  import { beforeAll, describe, expect, it } from "bun:test";
9
- import { createAdminUIApp } from "./admin-ui.ts";
10
9
  import {
11
10
  AGENT_ID,
12
11
  makeMockDeps,
13
12
  makeSessionCookie,
14
13
  } from "./admin-ui.fixtures.ts";
14
+ import { createAdminUIApp } from "./admin-ui.ts";
15
15
  import { resolveDefaultSpecialtyName } from "./specialty-types.ts";
16
16
 
17
17
  const json = (b: unknown, status = 200) =>
@@ -202,4 +202,118 @@ describe("admin UI — GitHub identity (GHE-2.5)", () => {
202
202
  expect(res.status).toBe(403);
203
203
  expect(calls.length).toBe(0);
204
204
  });
205
+
206
+ it("GHE-3.5: shows the Reconcile card to an admin with a bound username", async () => {
207
+ const { app } = setup({});
208
+ const html = await (await get(app, admin)).text();
209
+ expect(html).toContain('id="github-reconcile-card"');
210
+ });
211
+
212
+ it("GHE-3.5: hides the Reconcile card when the apps are unconfigured", async () => {
213
+ const { app } = setup({ configured: false });
214
+ const html = await (await get(app, admin)).text();
215
+ expect(html).not.toContain("github-reconcile-card");
216
+ });
217
+
218
+ it("GHE-3.5: hides the Reconcile card from a non-admin", async () => {
219
+ const { app } = setup({});
220
+ const html = await (await get(app, member)).text();
221
+ expect(html).not.toContain("github-reconcile-card");
222
+ });
223
+
224
+ it("GHE-3.5: plan route proxies the API and renders the diff", async () => {
225
+ const { app, calls } = setup({
226
+ agentsApi: () =>
227
+ json({
228
+ status: "planned",
229
+ planHash: "h1",
230
+ empty: false,
231
+ diff: {
232
+ installationAdds: [],
233
+ installationRemoves: [],
234
+ configAdds: ["acme/new"],
235
+ configRemoves: [],
236
+ },
237
+ }),
238
+ });
239
+ const res = await app.request(
240
+ `/admin/agents/${AGENT_ID}/github-reconcile/plan`,
241
+ {
242
+ method: "POST",
243
+ headers: {
244
+ Cookie: `admin_session=${admin}`,
245
+ "Content-Type": "application/json",
246
+ },
247
+ body: JSON.stringify({ addRepos: ["acme/new"] }),
248
+ },
249
+ );
250
+ expect(res.status).toBe(200);
251
+ const html = await res.text();
252
+ expect(calls.at(-1)?.path).toBe(
253
+ `/agents/${AGENT_ID}/github-reconcile/plan`,
254
+ );
255
+ expect(JSON.parse(String(calls.at(-1)?.init?.body))).toEqual({
256
+ addRepos: ["acme/new"],
257
+ });
258
+ expect(html).toContain('data-plan-hash="h1"');
259
+ expect(html).toContain('data-add-repos="acme/new"');
260
+ });
261
+
262
+ it("GHE-3.5: apply route forwards the confirmation and renders the result", async () => {
263
+ const { app, calls } = setup({
264
+ agentsApi: () => json({ status: "applied", auditId: "aud-9" }),
265
+ });
266
+ const payload = { planHash: "h1", addRepos: [], confirmRemovals: true };
267
+ const res = await app.request(
268
+ `/admin/agents/${AGENT_ID}/github-reconcile/apply`,
269
+ {
270
+ method: "POST",
271
+ headers: {
272
+ Cookie: `admin_session=${admin}`,
273
+ "Content-Type": "application/json",
274
+ },
275
+ body: JSON.stringify(payload),
276
+ },
277
+ );
278
+ expect(await res.text()).toContain("aud-9");
279
+ expect(JSON.parse(String(calls.at(-1)?.init?.body))).toEqual(payload);
280
+ });
281
+
282
+ it("GHE-3.5: apply surfaces a 409 stale plan error", async () => {
283
+ const { app } = setup({
284
+ agentsApi: () => json({ error: "the plan changed" }, 409),
285
+ });
286
+ const res = await app.request(
287
+ `/admin/agents/${AGENT_ID}/github-reconcile/apply`,
288
+ {
289
+ method: "POST",
290
+ headers: {
291
+ Cookie: `admin_session=${admin}`,
292
+ "Content-Type": "application/json",
293
+ },
294
+ body: JSON.stringify({ planHash: "old" }),
295
+ },
296
+ );
297
+ expect(res.status).toBe(409);
298
+ expect(await res.text()).toContain("the plan changed");
299
+ });
300
+
301
+ it("GHE-3.5: plan and apply routes are forbidden for a non-admin", async () => {
302
+ const { app, calls } = setup({});
303
+ for (const step of ["plan", "apply"]) {
304
+ const res = await app.request(
305
+ `/admin/agents/${AGENT_ID}/github-reconcile/${step}`,
306
+ {
307
+ method: "POST",
308
+ headers: {
309
+ Cookie: `admin_session=${member}`,
310
+ "Content-Type": "application/json",
311
+ },
312
+ body: "{}",
313
+ },
314
+ );
315
+ expect(res.status).toBe(403);
316
+ }
317
+ expect(calls.length).toBe(0);
318
+ });
205
319
  });
@@ -0,0 +1,208 @@
1
+ /**
2
+ * admin/src/admin-ui-github-reconcile-pages.ts
3
+ * Pure renderers for the agent detail page's GitHub Reconcile card (GHE-3.5).
4
+ * Platform-admin only; the caller renders the card only when a GitHub username
5
+ * is bound and the enterprise apps are configured. The card posts to the
6
+ * admin UI's plan/apply proxy routes; these renderers produce the fragments
7
+ * those routes return. Every dynamic value is escaped. Inputs carry repo names
8
+ * and ids only (no token or key ever reaches this module).
9
+ */
10
+
11
+ import { escapeHtml } from "./admin-ui-styles.ts";
12
+
13
+ /** Mirrors MAX_UNCONFIRMED_REMOVALS in reconcile-apply-service.ts. */
14
+ export const RECONCILE_REMOVAL_CAP = 10;
15
+
16
+ export interface GithubReconcileDiffView {
17
+ installationAdds: string[];
18
+ installationRemoves: string[];
19
+ configAdds: string[];
20
+ configRemoves: string[];
21
+ }
22
+
23
+ /** JSON body of POST /agents/:id/github-reconcile/plan. */
24
+ export interface GithubReconcilePlanView {
25
+ status: "planned" | "skipped";
26
+ reason?: string;
27
+ planHash?: string;
28
+ empty?: boolean;
29
+ diff?: GithubReconcileDiffView;
30
+ skippedOrgs?: { org: string; reason: string }[];
31
+ rejectedAdds?: { repo: string; reason: string }[];
32
+ warnings?: string[];
33
+ affectedOpenWork?: { id: string; repo: string; title?: string }[];
34
+ }
35
+
36
+ /** JSON body of POST /agents/:id/github-reconcile/apply. */
37
+ export interface GithubReconcileApplyView {
38
+ status: "applied" | "failed" | "noop" | "skipped";
39
+ reason?: string;
40
+ auditId?: string;
41
+ error?: string;
42
+ warnings?: string[];
43
+ }
44
+
45
+ /** The Reconcile card; the buttons talk to the UI plan/apply routes. */
46
+ export function renderGithubReconcileCard(agentId: string): string {
47
+ const base = `/admin/agents/${escapeHtml(agentId)}/github-reconcile`;
48
+ return `<div class="card" id="github-reconcile-card">
49
+ <div class="card-title">Reconcile</div>
50
+ <p style="color:#6b7280;font-size:12px;margin:0 0 12px">Plans the repo changes needed to match this agent's GitHub user access. Nothing changes until you review the plan and confirm.</p>
51
+ <div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center">
52
+ <input name="addRepos" id="github-reconcile-add" type="text" class="form-input mono" placeholder="Repos to add (owner/repo, comma separated; optional)" style="min-width:320px" />
53
+ <button type="button" class="btn btn-primary" id="github-reconcile-plan-btn" data-plan-url="${base}/plan" data-apply-url="${base}/apply">Plan</button>
54
+ </div>
55
+ <div id="github-reconcile-result" style="margin-top:12px"></div>
56
+ <script>
57
+ (function() {
58
+ var btn = document.getElementById('github-reconcile-plan-btn');
59
+ var out = document.getElementById('github-reconcile-result');
60
+ var input = document.getElementById('github-reconcile-add');
61
+ if (!btn || !out || !input) return;
62
+ function show(r) { return r.text().then(function(t) { out.innerHTML = t; }); }
63
+ function fail() { out.textContent = 'The request failed.'; }
64
+ function adds() {
65
+ return input.value.split(/[\\s,]+/).filter(function(s) { return s; });
66
+ }
67
+ btn.addEventListener('click', function() {
68
+ btn.disabled = true;
69
+ out.textContent = 'Loading...';
70
+ fetch(btn.getAttribute('data-plan-url'), {
71
+ method: 'POST',
72
+ credentials: 'same-origin',
73
+ headers: { 'content-type': 'application/json' },
74
+ body: JSON.stringify({ addRepos: adds() })
75
+ }).then(show).catch(fail).then(function() { btn.disabled = false; });
76
+ });
77
+ function sync() {
78
+ var plan = out.querySelector('#github-reconcile-plan');
79
+ var apply = out.querySelector('#github-reconcile-apply-btn');
80
+ var ok = out.querySelector('#github-reconcile-confirm');
81
+ var cap = out.querySelector('#github-reconcile-confirm-removals');
82
+ if (!plan || !apply || !ok) return;
83
+ apply.disabled = !(ok.checked && (!cap || cap.checked));
84
+ }
85
+ out.addEventListener('change', sync);
86
+ out.addEventListener('click', function(e) {
87
+ var t = e.target;
88
+ if (!t || t.id !== 'github-reconcile-apply-btn') return;
89
+ var plan = out.querySelector('#github-reconcile-plan');
90
+ var cap = out.querySelector('#github-reconcile-confirm-removals');
91
+ var add = plan.getAttribute('data-add-repos');
92
+ t.disabled = true;
93
+ fetch(btn.getAttribute('data-apply-url'), {
94
+ method: 'POST',
95
+ credentials: 'same-origin',
96
+ headers: { 'content-type': 'application/json' },
97
+ body: JSON.stringify({
98
+ planHash: plan.getAttribute('data-plan-hash'),
99
+ addRepos: add ? add.split(',') : [],
100
+ confirmRemovals: !!(cap && cap.checked)
101
+ })
102
+ }).then(show).catch(fail);
103
+ });
104
+ })();
105
+ </script>
106
+ </div>`;
107
+ }
108
+
109
+ function repoList(repos: string[]): string {
110
+ return repos.length === 0
111
+ ? `<span style="color:#9ca3af">none</span>`
112
+ : repos.map((r) => `<div class="mono">${escapeHtml(r)}</div>`).join("");
113
+ }
114
+
115
+ function diffTable(diff: GithubReconcileDiffView): string {
116
+ const row = (label: string, adds: string[], removes: string[]) =>
117
+ `<tr><td style="width:200px">${label}</td><td>${repoList(adds)}</td><td>${repoList(removes)}</td></tr>`;
118
+ return `<table class="detail-table"><thead><tr><th>Change</th><th>Add</th><th>Remove</th></tr></thead><tbody>${row("Installation", diff.installationAdds, diff.installationRemoves)}${row("Agent config", diff.configAdds, diff.configRemoves)}</tbody></table>`;
119
+ }
120
+
121
+ function section(title: string, body: string): string {
122
+ return `<div style="margin-top:12px"><div style="font-weight:600;margin-bottom:6px">${title}</div>${body}</div>`;
123
+ }
124
+
125
+ /**
126
+ * Fragment for the plan result. `addRepos` is the named-add list the plan was
127
+ * made with; apply must resend it, so it rides along on the plan element.
128
+ */
129
+ export function renderGithubReconcilePlanResult(
130
+ plan: GithubReconcilePlanView,
131
+ addRepos: string[],
132
+ ): string {
133
+ if (plan.status === "skipped" || !plan.diff || !plan.planHash) {
134
+ return `<div class="alert alert-warning">Reconcile skipped: ${escapeHtml(plan.reason ?? "no plan was produced")}.</div>`;
135
+ }
136
+ const parts: string[] = [];
137
+ if (plan.skippedOrgs?.length) {
138
+ parts.push(
139
+ `<div class="alert alert-warning">Skipped organizations:<ul style="margin:6px 0 0 18px">${plan.skippedOrgs.map((o) => `<li><span class="mono">${escapeHtml(o.org)}</span>: ${escapeHtml(o.reason)}</li>`).join("")}</ul></div>`,
140
+ );
141
+ }
142
+ if (plan.rejectedAdds?.length) {
143
+ parts.push(
144
+ `<div class="alert alert-warning">Rejected additions:<ul style="margin:6px 0 0 18px">${plan.rejectedAdds.map((r) => `<li><span class="mono">${escapeHtml(r.repo)}</span>: ${escapeHtml(r.reason)}</li>`).join("")}</ul></div>`,
145
+ );
146
+ }
147
+ if (plan.warnings?.length) {
148
+ parts.push(
149
+ `<div class="alert alert-warning">${plan.warnings.map((w) => `<div>${escapeHtml(w)}</div>`).join("")}</div>`,
150
+ );
151
+ }
152
+ if (plan.empty) {
153
+ parts.push(
154
+ `<p class="empty-state">Nothing to change: the agent already matches its GitHub access.</p>`,
155
+ );
156
+ return parts.join("");
157
+ }
158
+ parts.push(diffTable(plan.diff));
159
+ if (plan.affectedOpenWork?.length) {
160
+ const rows = plan.affectedOpenWork
161
+ .map(
162
+ (w) =>
163
+ `<tr><td class="mono">${escapeHtml(w.id)}</td><td class="mono">${escapeHtml(w.repo)}</td><td>${escapeHtml(w.title ?? "")}</td></tr>`,
164
+ )
165
+ .join("");
166
+ parts.push(
167
+ section(
168
+ "Open tasks and PRs affected by the removals",
169
+ `<table class="detail-table"><thead><tr><th>Id</th><th>Repo</th><th>Title</th></tr></thead><tbody>${rows}</tbody></table>`,
170
+ ),
171
+ );
172
+ }
173
+ const removals = plan.diff.configRemoves.length;
174
+ const overCap = removals > RECONCILE_REMOVAL_CAP;
175
+ const capConfirm = overCap
176
+ ? `<label style="display:block;margin-bottom:8px"><input type="checkbox" id="github-reconcile-confirm-removals" /> This plan removes ${removals} repos (more than ${RECONCILE_REMOVAL_CAP}). I confirm the removals.</label>`
177
+ : "";
178
+ parts.push(
179
+ `<div id="github-reconcile-plan" style="margin-top:12px" data-plan-hash="${escapeHtml(plan.planHash)}" data-add-repos="${escapeHtml(addRepos.join(","))}" data-over-cap="${overCap}">
180
+ <label style="display:block;margin-bottom:8px"><input type="checkbox" id="github-reconcile-confirm" /> I have reviewed this plan and want to apply it.</label>
181
+ ${capConfirm}
182
+ <button type="button" class="btn btn-danger" id="github-reconcile-apply-btn" disabled>Apply</button>
183
+ </div>`,
184
+ );
185
+ return parts.join("");
186
+ }
187
+
188
+ /** Fragment for the apply result. */
189
+ export function renderGithubReconcileApplyResult(
190
+ res: GithubReconcileApplyView,
191
+ ): string {
192
+ const audit = res.auditId
193
+ ? ` Audit id: <span class="mono">${escapeHtml(res.auditId)}</span>.`
194
+ : "";
195
+ const warnings = (res.warnings ?? [])
196
+ .map((w) => `<div>${escapeHtml(w)}</div>`)
197
+ .join("");
198
+ switch (res.status) {
199
+ case "applied":
200
+ return `<div class="alert alert-success">Reconcile applied.${audit}${warnings}</div>`;
201
+ case "noop":
202
+ return `<div class="alert alert-warning">Nothing to change.${warnings}</div>`;
203
+ case "failed":
204
+ return `<div class="alert alert-error">Reconcile failed${res.error ? `: ${escapeHtml(res.error)}` : ""}.${audit}${warnings}</div>`;
205
+ default:
206
+ return `<div class="alert alert-warning">Reconcile skipped${res.reason ? `: ${escapeHtml(res.reason)}` : ""}.</div>`;
207
+ }
208
+ }
@@ -0,0 +1,222 @@
1
+ /**
2
+ * admin/src/admin-ui-github-reconcile-pages.unit.test.ts
3
+ * Unit tests for the GHE-3.5 Reconcile card and its plan/apply fragments, and
4
+ * for the card's placement in renderAgentDetailPage (inert, plan, over-cap).
5
+ */
6
+
7
+ import { describe, expect, test } from "bun:test";
8
+ import {
9
+ type GithubReconcilePlanView,
10
+ renderGithubReconcileApplyResult,
11
+ renderGithubReconcileCard,
12
+ renderGithubReconcilePlanResult,
13
+ } from "./admin-ui-github-reconcile-pages.ts";
14
+ import { type AgentDetail, renderAgentDetailPage } from "./admin-ui-pages.ts";
15
+
16
+ const AGENT: AgentDetail = {
17
+ id: "agent-123",
18
+ name: "Test Agent",
19
+ slackId: "U12345",
20
+ selfHosted: false,
21
+ createdAt: new Date("2024-01-01T00:00:00Z"),
22
+ updatedAt: new Date("2024-01-02T00:00:00Z"),
23
+ repos: [],
24
+ authorAllowlist: [],
25
+ patchAuthorAllowlist: [],
26
+ restrictSlackToMembers: false,
27
+ specialty: "coding",
28
+ missingRequiredEnv: [],
29
+ autoPostReviews: true,
30
+ allowSelfReview: false,
31
+ minConfidence: 75,
32
+ maxFindings: 5,
33
+ cleanupMergedWorktrees: true,
34
+ cleanupAfterDays: 14,
35
+ };
36
+
37
+ function page(
38
+ isAdmin: boolean,
39
+ configured: boolean,
40
+ githubUsername: string | null,
41
+ ): string {
42
+ return renderAgentDetailPage(
43
+ { ...AGENT, githubUsername },
44
+ {},
45
+ [],
46
+ [],
47
+ [],
48
+ [],
49
+ [],
50
+ "u@x.com",
51
+ isAdmin,
52
+ { timezone: "UTC", githubEnterpriseConfigured: configured },
53
+ );
54
+ }
55
+
56
+ const plan = (over: Partial<GithubReconcilePlanView> = {}) =>
57
+ ({
58
+ status: "planned",
59
+ planHash: "hash-1",
60
+ empty: false,
61
+ diff: {
62
+ installationAdds: ["acme/new"],
63
+ installationRemoves: ["acme/old"],
64
+ configAdds: ["acme/new"],
65
+ configRemoves: ["acme/old"],
66
+ },
67
+ ...over,
68
+ }) as GithubReconcilePlanView;
69
+
70
+ describe("Reconcile card — inert state", () => {
71
+ test("absent when no username is bound", () => {
72
+ const html = page(true, true, null);
73
+ expect(html).not.toContain("github-reconcile-card");
74
+ expect(html).not.toContain("Reconcile");
75
+ });
76
+
77
+ test("absent when the apps are not configured", () => {
78
+ expect(page(true, false, "octo")).not.toContain("github-reconcile-card");
79
+ });
80
+
81
+ test("absent for a non-admin", () => {
82
+ expect(page(false, true, "octo")).not.toContain("github-reconcile-card");
83
+ });
84
+
85
+ test("present for an admin with a username and configured apps", () => {
86
+ const html = page(true, true, "octo");
87
+ expect(html).toContain('id="github-reconcile-card"');
88
+ expect(html).toContain('id="github-reconcile-plan-btn"');
89
+ expect(html).toContain('name="addRepos"');
90
+ });
91
+
92
+ test("card wires escaped plan and apply URLs and holds no key material", () => {
93
+ const html = renderGithubReconcileCard('a"b');
94
+ expect(html).toContain("/admin/agents/a&quot;b/github-reconcile/plan");
95
+ expect(html).toContain("/admin/agents/a&quot;b/github-reconcile/apply");
96
+ expect(html).not.toMatch(/BEGIN|token|private/i);
97
+ });
98
+ });
99
+
100
+ describe("renderGithubReconcilePlanResult — plan state", () => {
101
+ test("renders the diff table, hash and a confirm gate", () => {
102
+ const html = renderGithubReconcilePlanResult(plan(), []);
103
+ expect(html).toContain("acme/new");
104
+ expect(html).toContain("acme/old");
105
+ expect(html).toContain('data-plan-hash="hash-1"');
106
+ expect(html).toContain('id="github-reconcile-confirm"');
107
+ expect(html).toMatch(/id="github-reconcile-apply-btn"[^>]*disabled/);
108
+ expect(html).not.toContain("github-reconcile-confirm-removals");
109
+ });
110
+
111
+ test("carries the named adds for apply", () => {
112
+ const html = renderGithubReconcilePlanResult(plan(), ["acme/x", "acme/y"]);
113
+ expect(html).toContain('data-add-repos="acme/x,acme/y"');
114
+ });
115
+
116
+ test("renders skip reasons, rejected adds, warnings and open work", () => {
117
+ const html = renderGithubReconcilePlanResult(
118
+ plan({
119
+ skippedOrgs: [{ org: "beta", reason: "lookup app not installed" }],
120
+ rejectedAdds: [{ repo: "zed/q", reason: "not accessible" }],
121
+ warnings: ["careful <b>now</b>"],
122
+ affectedOpenWork: [
123
+ { id: "T-1", repo: "acme/old", title: "Fix <i>it</i>" },
124
+ ],
125
+ }),
126
+ [],
127
+ );
128
+ expect(html).toContain("beta");
129
+ expect(html).toContain("lookup app not installed");
130
+ expect(html).toContain("zed/q");
131
+ expect(html).toContain("careful &lt;b&gt;now&lt;/b&gt;");
132
+ expect(html).toContain("T-1");
133
+ expect(html).toContain("Fix &lt;i&gt;it&lt;/i&gt;");
134
+ expect(html).not.toContain("<b>now</b>");
135
+ });
136
+
137
+ test("empty plan has nothing to apply", () => {
138
+ const html = renderGithubReconcilePlanResult(
139
+ plan({
140
+ empty: true,
141
+ diff: {
142
+ installationAdds: [],
143
+ installationRemoves: [],
144
+ configAdds: [],
145
+ configRemoves: [],
146
+ },
147
+ }),
148
+ [],
149
+ );
150
+ expect(html).toContain("Nothing to change");
151
+ expect(html).not.toContain("github-reconcile-apply-btn");
152
+ });
153
+
154
+ test("skipped plan shows the reason and no apply", () => {
155
+ const html = renderGithubReconcilePlanResult(
156
+ { status: "skipped", reason: "GitHub Apps are not configured" },
157
+ [],
158
+ );
159
+ expect(html).toContain("GitHub Apps are not configured");
160
+ expect(html).not.toContain("github-reconcile-apply-btn");
161
+ });
162
+ });
163
+
164
+ describe("renderGithubReconcilePlanResult — over-cap confirm", () => {
165
+ const many = Array.from({ length: 11 }, (_, i) => `acme/r${i}`);
166
+ const over = plan({
167
+ diff: {
168
+ installationAdds: [],
169
+ installationRemoves: many,
170
+ configAdds: [],
171
+ configRemoves: many,
172
+ },
173
+ });
174
+
175
+ test("more than 10 config removals requires a second confirmation", () => {
176
+ const html = renderGithubReconcilePlanResult(over, []);
177
+ expect(html).toContain('data-over-cap="true"');
178
+ expect(html).toContain('id="github-reconcile-confirm-removals"');
179
+ expect(html).toContain("11 repos");
180
+ });
181
+
182
+ test("exactly 10 removals does not", () => {
183
+ const ten = many.slice(0, 10);
184
+ const html = renderGithubReconcilePlanResult(
185
+ plan({
186
+ diff: {
187
+ installationAdds: [],
188
+ installationRemoves: ten,
189
+ configAdds: [],
190
+ configRemoves: ten,
191
+ },
192
+ }),
193
+ [],
194
+ );
195
+ expect(html).toContain('data-over-cap="false"');
196
+ expect(html).not.toContain("github-reconcile-confirm-removals");
197
+ });
198
+ });
199
+
200
+ describe("renderGithubReconcileApplyResult", () => {
201
+ test.each([
202
+ ["applied", "alert-success"],
203
+ ["noop", "alert-warning"],
204
+ ["failed", "alert-error"],
205
+ ["skipped", "alert-warning"],
206
+ ] as const)("%s", (status, cls) => {
207
+ const html = renderGithubReconcileApplyResult({
208
+ status,
209
+ auditId: "aud-1",
210
+ reason: "r <x>",
211
+ error: "boom <x>",
212
+ });
213
+ expect(html).toContain(cls);
214
+ expect(html).not.toContain("<x>");
215
+ });
216
+
217
+ test("applied shows the audit id", () => {
218
+ expect(
219
+ renderGithubReconcileApplyResult({ status: "applied", auditId: "aud-1" }),
220
+ ).toContain("aud-1");
221
+ });
222
+ });
@@ -16,6 +16,7 @@ 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
20
  import { renderAdminPage } from "./admin-ui-layout.ts";
20
21
  import {
21
22
  BREAKPOINT_MOBILE_MAX,
@@ -1287,7 +1288,7 @@ export function renderAgentDetailPage(
1287
1288
 
1288
1289
  const pluginRows =
1289
1290
  plugins.length === 0
1290
- ? `<tr><td colspan="4" class="empty-state">No plugins installed.</td></tr>`
1291
+ ? `<tr><td colspan="5" class="empty-state">No plugins installed.</td></tr>`
1291
1292
  : plugins
1292
1293
  .map(
1293
1294
  (p) => `<tr>
@@ -1295,6 +1296,12 @@ export function renderAgentDetailPage(
1295
1296
  <td class="mono">${p.version ? escapeHtml(p.version) : "latest"}</td>
1296
1297
  <td><span class="badge ${p.enabled ? "badge-green" : "badge-gray"}">${p.enabled ? "enabled" : "disabled"}</span></td>
1297
1298
  <td>${escapeHtml(new Date(p.createdAt).toLocaleDateString("en-US", { timeZone: timezone }))}</td>
1299
+ <td>
1300
+ <form method="POST" action="/admin/agents/${escapeHtml(agent.id)}/plugins/delete" style="display:inline">
1301
+ <input type="hidden" name="pluginId" value="${escapeHtml(p.id)}" />
1302
+ <button type="submit" class="btn btn-danger" style="font-size:11px;padding:3px 8px">Remove</button>
1303
+ </form>
1304
+ </td>
1298
1305
  </tr>`,
1299
1306
  )
1300
1307
  .join("\n");
@@ -1725,16 +1732,20 @@ export function renderAgentDetailPage(
1725
1732
  </div>
1726
1733
  </div>`;
1727
1734
 
1735
+ const pluginMarketplaceNames = [
1736
+ ...new Set([...marketplaces.map((m) => m.name), ...bakedMarketplaces]),
1737
+ ];
1728
1738
  const pluginsSection = `<div class="card">
1729
1739
  <div class="card-title">Plugins</div>
1730
1740
  <div class="data-table-wrapper">
1731
- <table class="data-table">
1741
+ <table class="data-table" id="plugins-table">
1732
1742
  <thead>
1733
1743
  <tr>
1734
1744
  <th>Package</th>
1735
1745
  <th>Version</th>
1736
1746
  <th>Status</th>
1737
1747
  <th>Created</th>
1748
+ <th></th>
1738
1749
  </tr>
1739
1750
  </thead>
1740
1751
  <tbody>
@@ -1742,6 +1753,11 @@ export function renderAgentDetailPage(
1742
1753
  </tbody>
1743
1754
  </table>
1744
1755
  </div>
1756
+ <form method="POST" action="/admin/agents/${escapeHtml(agent.id)}/plugins" id="add-plugin-form" style="display:flex;gap:8px;flex-wrap:wrap;margin-top:12px">
1757
+ <input name="spec" type="text" class="form-input mono" list="plugin-marketplaces" placeholder="plugin@marketplace (bare name = shipwright)" required />
1758
+ <datalist id="plugin-marketplaces">${pluginMarketplaceNames.map((n) => `<option value="${escapeHtml(n)}"></option>`).join("")}</datalist>
1759
+ <button type="submit" class="btn btn-primary">Add plugin</button>
1760
+ </form>
1745
1761
  </div>`;
1746
1762
 
1747
1763
  const marketplacesSection = `<div class="card">
@@ -1791,7 +1807,7 @@ export function renderAgentDetailPage(
1791
1807
  ${identityRow("Federation rule ID", agent.anthropicFederationRuleId, true)}
1792
1808
  ${showGithubIdentity ? renderGithubUsernameRow(agent.id, agent.githubUsername) : ""}
1793
1809
  </tbody></table>
1794
- </div>${showGithubIdentity ? renderGithubAccessCard(agent.id) : ""}`;
1810
+ </div>${showGithubIdentity ? renderGithubAccessCard(agent.id) : ""}${showGithubIdentity && agent.githubUsername ? renderGithubReconcileCard(agent.id) : ""}`;
1795
1811
 
1796
1812
  // Only agents with a GitHub App can make API-signed commits. Checked state
1797
1813
  // is the SHIPWRIGHT_SIGNED_COMMITS env row; when the box is hidden the field