@app-vitals/agent-admin 1.47.0 → 1.49.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.
@@ -128,6 +128,8 @@ export interface AgentDetail {
128
128
  * state.
129
129
  */
130
130
  bakedMarketplaces?: string[];
131
+ /** ATP-2.4: the agent no longer follows its template. */
132
+ templateDetached?: boolean;
131
133
  }
132
134
 
133
135
  export interface CronJobItem {
@@ -141,6 +143,8 @@ export interface CronJobItem {
141
143
  system: boolean;
142
144
  parentCronId: string | null;
143
145
  preCheck?: string | null;
146
+ /** ATP-2.4: `template` (inherited) or `custom`. */
147
+ source?: string;
144
148
  lastRun?: {
145
149
  startedAt: Date;
146
150
  completedAt: Date | null;
@@ -179,6 +183,8 @@ export interface ToolItem {
179
183
  id: string;
180
184
  pattern: string;
181
185
  enabled: boolean;
186
+ /** ATP-2.4: `template` (inherited) or `custom`. */
187
+ source?: string;
182
188
  createdAt: Date;
183
189
  }
184
190
 
@@ -194,6 +200,8 @@ export interface PluginItem {
194
200
  name: string;
195
201
  version: string | null;
196
202
  enabled: boolean;
203
+ /** ATP-2.4: `template` (inherited) or `custom`. */
204
+ source?: string;
197
205
  createdAt: Date;
198
206
  }
199
207
 
@@ -502,6 +510,16 @@ function runtimeSectionsOnchange(display: "" | "none"): string {
502
510
  .join(";");
503
511
  }
504
512
 
513
+ /** ATP-2.4: one template-provided default on the provisioning form. */
514
+ export interface NewAgentTemplateItem {
515
+ kind: string;
516
+ key: string;
517
+ /** Display value (env only; secrets already masked). */
518
+ value?: string;
519
+ /** Human label of the template scope. */
520
+ scope: string;
521
+ }
522
+
505
523
  export function renderNewLocalAgentPage(
506
524
  userName: string,
507
525
  types: SpecialtyOption[],
@@ -516,6 +534,12 @@ export function renderNewLocalAgentPage(
516
534
  * the self-serve specialty (the server forces it regardless).
517
535
  */
518
536
  selfServe?: { remaining: number; max: number; contactEmail: string };
537
+ /**
538
+ * ATP-2.4: present when agent templates are available. Lists the
539
+ * template-provided defaults and adds the opt-out checkbox; `allowEnv`
540
+ * (platform admins) adds the explicit env override box.
541
+ */
542
+ template?: { items: NewAgentTemplateItem[]; allowEnv: boolean };
519
543
  },
520
544
  ): string {
521
545
  const error = opts?.error;
@@ -591,6 +615,46 @@ export function renderNewLocalAgentPage(
591
615
  </ul>
592
616
  </div>`
593
617
  : "";
618
+ const tplOpts = opts?.template;
619
+ const templateFieldsetHtml = tplOpts
620
+ ? `<fieldset id="template-section" style="border:1px solid #e8e8ee;border-radius:8px;padding:16px">
621
+ <legend style="font-size:13px;font-weight:600;padding:0 8px">Agent template</legend>
622
+ ${
623
+ tplOpts.items.length === 0
624
+ ? `<p style="font-size:13px;color:#6b7280;margin-bottom:12px">No template items apply to new agents.</p>`
625
+ : `<p style="font-size:13px;color:#6b7280;margin-bottom:8px">New agents start with these template defaults${tplOpts.allowEnv ? "; anything you enter below overrides them" : ""}:</p>
626
+ <table class="data-table" style="margin-bottom:12px">
627
+ <thead><tr><th>Kind</th><th>Key</th><th>Default</th><th>Applies to</th></tr></thead>
628
+ <tbody>${tplOpts.items
629
+ .map(
630
+ (i) =>
631
+ `<tr><td>${escapeHtml(i.kind)}</td><td class="mono">${escapeHtml(i.key)}</td><td class="mono">${i.value === undefined ? "—" : escapeHtml(i.value)}</td><td>${escapeHtml(i.scope)}</td></tr>`,
632
+ )
633
+ .join("")}</tbody>
634
+ </table>`
635
+ }
636
+ ${
637
+ tplOpts.allowEnv
638
+ ? `<div class="form-group">
639
+ <label class="form-label" for="env">Env overrides (optional)</label>
640
+ <textarea id="env" name="env" class="form-input mono" rows="3" placeholder="KEY=value (one per line)"></textarea>
641
+ <p style="font-size:12px;color:#6b7280;margin-top:4px">
642
+ Values entered here win over the template defaults above and stay fixed when the template changes.
643
+ </p>
644
+ </div>`
645
+ : ""
646
+ }
647
+ <div class="form-group" style="margin-bottom:0">
648
+ <label style="font-size:13px">
649
+ <input type="checkbox" name="templateDetached" value="true" />
650
+ Start without the template (opt out)
651
+ </label>
652
+ <p style="font-size:12px;color:#6b7280;margin-top:4px">
653
+ The agent gets only its built-in defaults and ignores later template changes until you reattach it.
654
+ </p>
655
+ </div>
656
+ </fieldset>`
657
+ : "";
594
658
  const typeFieldHtml = selfServe
595
659
  ? `<input type="hidden" name="type" value="${escapeHtml(getSelfServeSpecialty())}" />`
596
660
  : `<div class="form-group">
@@ -826,6 +890,7 @@ export function renderNewLocalAgentPage(
826
890
  </div>
827
891
  </div>
828
892
  </fieldset>
893
+ ${templateFieldsetHtml}
829
894
  <div>
830
895
  <button type="submit" class="btn btn-primary">Create agent →</button>
831
896
  <a href="/admin/agents" class="btn btn-secondary" style="margin-left:8px">Cancel</a>
@@ -938,7 +1003,12 @@ function renderGroup(name: string, stat: string, bodyHtml: string): string {
938
1003
  export function renderAgentDetailPage(
939
1004
  agent: AgentDetail,
940
1005
  envResult:
941
- | { env: Record<string, string>; secretKeys: string[] }
1006
+ | {
1007
+ env: Record<string, string>;
1008
+ secretKeys: string[];
1009
+ /** ATP-2.4: row source per key. */
1010
+ sources?: Record<string, string>;
1011
+ }
942
1012
  | Record<string, string>,
943
1013
  crons: CronJobItem[],
944
1014
  tools: ToolItem[],
@@ -995,6 +1065,12 @@ export function renderAgentDetailPage(
995
1065
  * could be listed. Absent means unknown: no coverage warning is shown.
996
1066
  */
997
1067
  installationRepos?: readonly string[];
1068
+ /**
1069
+ * ATP-2.4: present when agent templates are available. Turns on the
1070
+ * inherited/custom badges, the detach/reattach toggle and the per-item
1071
+ * reset controls.
1072
+ */
1073
+ template?: { detached: boolean };
998
1074
  },
999
1075
  ): string {
1000
1076
  // Reference time for relative timestamps — injected by tests for determinism,
@@ -1016,19 +1092,66 @@ export function renderAgentDetailPage(
1016
1092
  : [],
1017
1093
  );
1018
1094
 
1095
+ // ATP-2.4: inherited/custom badge, per-item reset and agent-wide controls.
1096
+ const tpl = opts?.template;
1097
+ const agentPath = `/admin/agents/${escapeHtml(agent.id)}`;
1098
+ const sourceBadge = (source: string | undefined): string =>
1099
+ !tpl || (source !== "template" && source !== "custom")
1100
+ ? ""
1101
+ : source === "template"
1102
+ ? ` <span class="badge badge-template" data-source="template" title="Inherited from the agent template">template</span>`
1103
+ : ` <span class="badge badge-custom" data-source="custom" title="Set on this agent; overrides the template">custom</span>`;
1104
+ const resetForm = (
1105
+ source: string | undefined,
1106
+ kind: string,
1107
+ key: string | null | undefined,
1108
+ ): string =>
1109
+ !tpl || tpl.detached || source !== "custom" || !key
1110
+ ? ""
1111
+ : `<form method="POST" action="${agentPath}/template/reset" style="display:inline;margin-left:4px">
1112
+ <input type="hidden" name="kind" value="${kind}" />
1113
+ <input type="hidden" name="key" value="${escapeHtml(key)}" />
1114
+ <button type="submit" class="btn btn-secondary" style="font-size:11px;padding:3px 8px" title="Drop this agent's override and restore the template value">Reset to template</button>
1115
+ </form>`;
1116
+ const envSources =
1117
+ envResult && "sources" in envResult
1118
+ ? ((envResult as { sources?: Record<string, string> }).sources ?? {})
1119
+ : {};
1120
+ const templateCard = tpl
1121
+ ? `<div class="card" id="template">
1122
+ <div class="card-title">Agent template</div>
1123
+ ${
1124
+ tpl.detached
1125
+ ? `<p style="font-size:13px;margin-bottom:12px"><span class="badge badge-gray">Detached from template</span>
1126
+ Template changes no longer reach this agent. Reattaching reconciles it against the template now; your custom rows are kept.</p>
1127
+ <form method="POST" action="${agentPath}/template/reattach">
1128
+ <button type="submit" class="btn btn-primary">Reattach to template</button>
1129
+ </form>`
1130
+ : `<p style="font-size:13px;margin-bottom:12px"><span class="badge badge-template">Following template</span>
1131
+ Rows marked <em>template</em> are managed from Settings &gt; Templates; editing one makes it <em>custom</em>.</p>
1132
+ <form method="POST" action="${agentPath}/template/detach" style="display:inline">
1133
+ <button type="submit" class="btn btn-secondary">Detach from template</button>
1134
+ </form>
1135
+ <form method="POST" action="${agentPath}/template/reset" style="display:inline;margin-left:8px">
1136
+ <button type="submit" class="btn btn-secondary" title="Drop every override of a key the template defines">Reset all to template</button>
1137
+ </form>`
1138
+ }
1139
+ </div>`
1140
+ : "";
1141
+
1019
1142
  const envRows =
1020
1143
  Object.keys(envVars).length === 0
1021
1144
  ? `<tr><td colspan="3" class="empty-state">No env vars set.</td></tr>`
1022
1145
  : Object.entries(envVars)
1023
1146
  .map(
1024
1147
  ([k]) => `<tr>
1025
- <td class="mono">${escapeHtml(k)}${secretKeySet.has(k) ? ' <span title="Secret">🔒</span>' : ""}</td>
1148
+ <td class="mono">${escapeHtml(k)}${secretKeySet.has(k) ? ' <span title="Secret">🔒</span>' : ""}${sourceBadge(envSources[k])}</td>
1026
1149
  <td class="mono" style="color:#6b7280">••••••••</td>
1027
1150
  <td>
1028
1151
  <form method="POST" action="/admin/agents/${escapeHtml(agent.id)}/envs/delete" style="display:inline">
1029
1152
  <input type="hidden" name="key" value="${escapeHtml(k)}" />
1030
1153
  <button type="submit" class="btn btn-danger" style="font-size:11px;padding:3px 8px">Delete</button>
1031
- </form>
1154
+ </form>${resetForm(envSources[k], "env", k)}
1032
1155
  </td>
1033
1156
  </tr>`,
1034
1157
  )
@@ -1232,13 +1355,13 @@ export function renderAgentDetailPage(
1232
1355
 
1233
1356
  return `<tr>
1234
1357
  <td class="mono">${escapeHtml(c.schedule)}</td>
1235
- <td style="max-width:280px;overflow:hidden;text-overflow:ellipsis">${escapeHtml(c.name ? `${c.name}: ${c.prompt}` : c.prompt)}</td>
1358
+ <td style="max-width:280px;overflow:hidden;text-overflow:ellipsis">${escapeHtml(c.name ? `${c.name}: ${c.prompt}` : c.prompt)}${sourceBadge(c.system ? undefined : c.source)}</td>
1236
1359
  <td class="mono" style="font-size:11px;color:#6b7280;max-width:170px;overflow:hidden;text-overflow:ellipsis">${c.preCheck ? escapeHtml(c.preCheck) : "—"}</td>
1237
1360
  <td>${c.channel ? escapeHtml(c.channel) : c.user ? escapeHtml(c.user) : "—"}</td>
1238
1361
  <td><span class="badge ${c.enabled ? "badge-green" : "badge-gray"}">${c.enabled ? "enabled" : "disabled"}</span></td>
1239
1362
  <td style="font-size:11px">${lastRunHtml}</td>
1240
1363
  <td class="col-created">${escapeHtml(new Date(c.createdAt).toLocaleDateString("en-US", { timeZone: timezone }))}</td>
1241
- <td style="white-space:nowrap">${actions}${editForm}</td>
1364
+ <td style="white-space:nowrap">${actions}${resetForm(c.system ? undefined : c.source, "cron", c.name)}${editForm}</td>
1242
1365
  </tr>
1243
1366
  ${nestedPhasesRow}`;
1244
1367
  }
@@ -1259,7 +1382,7 @@ export function renderAgentDetailPage(
1259
1382
  : tools
1260
1383
  .map(
1261
1384
  (t) => `<tr>
1262
- <td class="mono">${escapeHtml(t.pattern)}</td>
1385
+ <td class="mono">${escapeHtml(t.pattern)}${sourceBadge(t.source)}</td>
1263
1386
  <td><span class="badge ${t.enabled ? "badge-green" : "badge-gray"}">${t.enabled ? "enabled" : "disabled"}</span></td>
1264
1387
  <td>${escapeHtml(new Date(t.createdAt).toLocaleDateString("en-US", { timeZone: timezone }))}</td>
1265
1388
  <td style="white-space:nowrap">
@@ -1269,7 +1392,7 @@ export function renderAgentDetailPage(
1269
1392
  </form>
1270
1393
  <form method="POST" action="/admin/agents/${escapeHtml(agent.id)}/tools/${escapeHtml(t.id)}/delete" style="display:inline;margin-left:4px">
1271
1394
  <button type="submit" class="btn btn-danger" style="font-size:11px;padding:3px 8px">Delete</button>
1272
- </form>
1395
+ </form>${resetForm(t.source, "tool", t.pattern)}
1273
1396
  </td>
1274
1397
  </tr>`,
1275
1398
  )
@@ -1301,7 +1424,7 @@ export function renderAgentDetailPage(
1301
1424
  : plugins
1302
1425
  .map(
1303
1426
  (p) => `<tr>
1304
- <td class="mono">${escapeHtml(p.name)}</td>
1427
+ <td class="mono">${escapeHtml(p.name)}${sourceBadge(p.source)}</td>
1305
1428
  <td class="mono">${p.version ? escapeHtml(p.version) : "latest"}</td>
1306
1429
  <td><span class="badge ${p.enabled ? "badge-green" : "badge-gray"}">${p.enabled ? "enabled" : "disabled"}</span></td>
1307
1430
  <td>${escapeHtml(new Date(p.createdAt).toLocaleDateString("en-US", { timeZone: timezone }))}</td>
@@ -1309,7 +1432,7 @@ export function renderAgentDetailPage(
1309
1432
  <form method="POST" action="/admin/agents/${escapeHtml(agent.id)}/plugins/delete" style="display:inline">
1310
1433
  <input type="hidden" name="pluginId" value="${escapeHtml(p.id)}" />
1311
1434
  <button type="submit" class="btn btn-danger" style="font-size:11px;padding:3px 8px">Remove</button>
1312
- </form>
1435
+ </form>${resetForm(p.source, "plugin", p.name)}
1313
1436
  </td>
1314
1437
  </tr>`,
1315
1438
  )
@@ -2019,7 +2142,7 @@ export function renderAgentDetailPage(
2019
2142
  const configurationGroup = renderGroup(
2020
2143
  "Configuration",
2021
2144
  configurationStat,
2022
- `${envVarsSection}${reposSection}${(opts?.configurationCardsHtml ?? []).join("")}${agentPolicySection}`,
2145
+ `${templateCard}${envVarsSection}${reposSection}${(opts?.configurationCardsHtml ?? []).join("")}${agentPolicySection}`,
2023
2146
  );
2024
2147
  const accessGroup = renderGroup(
2025
2148
  "Access",
@@ -99,3 +99,50 @@ export function mergeSettingsNavItems(
99
99
  }
100
100
  return { sections };
101
101
  }
102
+
103
+ export const SETTINGS_GHE_PATH = "/admin/settings/github-enterprise";
104
+ export const SETTINGS_TEMPLATES_PATH = "/admin/settings/templates";
105
+
106
+ export interface BuildSettingsNavOptions {
107
+ /** Include the GitHub Enterprise item (its routes are registered). */
108
+ githubEnterprise?: boolean;
109
+ /** Include the Templates item (its routes are registered). */
110
+ templates?: boolean;
111
+ /** Extension-contributed items (SGL-2.1). */
112
+ extraItems?: readonly SettingsNavContribution[];
113
+ }
114
+
115
+ /**
116
+ * Base settings nav (SGL-2.2): the Platform section plus extension items.
117
+ * Account/Personal sections arrive in SGL-2.3. Empty sections are dropped.
118
+ */
119
+ export function buildSettingsNav(
120
+ opts: BuildSettingsNavOptions = {},
121
+ ): SettingsNav {
122
+ const platform: SettingsNavItem[] = [];
123
+ if (opts.githubEnterprise) {
124
+ platform.push({
125
+ label: "GitHub Enterprise",
126
+ path: SETTINGS_GHE_PATH,
127
+ adminOnly: true,
128
+ });
129
+ }
130
+ if (opts.templates) {
131
+ platform.push({ label: "Templates", path: SETTINGS_TEMPLATES_PATH });
132
+ }
133
+ const base: SettingsNav = {
134
+ sections:
135
+ platform.length > 0 ? [{ label: "Platform", items: platform }] : [],
136
+ };
137
+ return mergeSettingsNavItems(base, [...(opts.extraItems ?? [])]);
138
+ }
139
+
140
+ /** First nav item visible to the viewer, or undefined. */
141
+ export function firstVisibleSettingsItem(
142
+ nav: SettingsNav,
143
+ isAdmin: boolean,
144
+ ): SettingsNavItem | undefined {
145
+ return nav.sections
146
+ .flatMap((s) => s.items)
147
+ .find((i) => isAdmin || !i.adminOnly);
148
+ }
@@ -5,6 +5,8 @@
5
5
 
6
6
  import { describe, expect, test } from "bun:test";
7
7
  import {
8
+ buildSettingsNav,
9
+ firstVisibleSettingsItem,
8
10
  renderSettingsLayout,
9
11
  type SettingsNav,
10
12
  } from "./admin-ui-settings-layout.ts";
@@ -104,3 +106,60 @@ describe("renderSettingsLayout", () => {
104
106
  expect(withPath).toContain("vos-toolbar");
105
107
  });
106
108
  });
109
+
110
+ describe("buildSettingsNav / firstVisibleSettingsItem (SGL-2.2)", () => {
111
+ const both = { githubEnterprise: true, templates: true };
112
+ test("Platform section lists GHE (adminOnly) then Templates", () => {
113
+ expect(buildSettingsNav(both)).toEqual({
114
+ sections: [
115
+ {
116
+ label: "Platform",
117
+ items: [
118
+ {
119
+ label: "GitHub Enterprise",
120
+ path: "/admin/settings/github-enterprise",
121
+ adminOnly: true,
122
+ },
123
+ { label: "Templates", path: "/admin/settings/templates" },
124
+ ],
125
+ },
126
+ ],
127
+ });
128
+ });
129
+ test("omits unregistered features and empty sections", () => {
130
+ expect(buildSettingsNav({})).toEqual({ sections: [] });
131
+ expect(
132
+ buildSettingsNav({ templates: true }).sections[0]?.items.map(
133
+ (i) => i.label,
134
+ ),
135
+ ).toEqual(["Templates"]);
136
+ });
137
+ test("merges extension items into Platform or new sections", () => {
138
+ const nav = buildSettingsNav({
139
+ ...both,
140
+ extraItems: [
141
+ { section: "Platform", label: "A", path: "/a" },
142
+ { section: "Extras", label: "B", path: "/b" },
143
+ ],
144
+ });
145
+ expect(nav.sections.map((s) => s.label)).toEqual(["Platform", "Extras"]);
146
+ expect(nav.sections[0]?.items.map((i) => i.label)).toEqual([
147
+ "GitHub Enterprise",
148
+ "Templates",
149
+ "A",
150
+ ]);
151
+ });
152
+ test("first visible item respects adminOnly", () => {
153
+ const nav = buildSettingsNav(both);
154
+ expect(firstVisibleSettingsItem(nav, true)?.label).toBe(
155
+ "GitHub Enterprise",
156
+ );
157
+ expect(firstVisibleSettingsItem(nav, false)?.label).toBe("Templates");
158
+ expect(
159
+ firstVisibleSettingsItem(
160
+ buildSettingsNav({ githubEnterprise: true }),
161
+ false,
162
+ ),
163
+ ).toBeUndefined();
164
+ });
165
+ });
@@ -0,0 +1,193 @@
1
+ /**
2
+ * admin/src/admin-ui-settings.smoke.test.ts
3
+ * Smoke tests for the settings shell (SGL-2.2): GET /admin/settings redirect,
4
+ * sidebar rendering on GHE + Templates, and the toolbar Settings entry for
5
+ * admins / account members / non-account admins. Via the full admin UI app.
6
+ */
7
+
8
+ import { describe, expect, it } from "bun:test";
9
+ import { makeMockDeps, makeSessionCookie } from "./admin-ui.fixtures.ts";
10
+ import { createAdminUIApp } from "./admin-ui.ts";
11
+
12
+ const ghe = async () =>
13
+ new Response(
14
+ JSON.stringify({ configured: false, installer: null, lookup: null }),
15
+ { status: 200, headers: { "Content-Type": "application/json" } },
16
+ );
17
+ const templateService = {
18
+ list: async () => [],
19
+ replace: async () => {
20
+ throw new Error("unused");
21
+ },
22
+ putItem: async () => {
23
+ throw new Error("unused");
24
+ },
25
+ deleteItem: async () => {},
26
+ delete: async () => {},
27
+ } as never;
28
+
29
+ const adminCookie = async () => `admin_session=${await makeSessionCookie()}`;
30
+ const userCookie = async (email = "m@acme.com") =>
31
+ `admin_session=${await makeSessionCookie(undefined, "u2", email, false)}`;
32
+
33
+ const memberAccounts = (member: string | null) =>
34
+ ({
35
+ accounts: {
36
+ getByMemberEmail: async (e: string) =>
37
+ e === member ? ({ id: "acct-1", name: "Acme" } as never) : null,
38
+ listWithCounts: async () => [{ id: "acct-1", name: "Acme" }],
39
+ getWithCounts: async (id: string) => ({ id, name: "Acme" }),
40
+ },
41
+ members: {},
42
+ }) as never;
43
+
44
+ describe("GET /admin/settings", () => {
45
+ it("redirects an admin to GitHub Enterprise when registered", async () => {
46
+ const app = createAdminUIApp(
47
+ makeMockDeps({ githubEnterpriseApi: ghe, templateService }),
48
+ );
49
+ const res = await app.request("/admin/settings", {
50
+ headers: { cookie: await adminCookie() },
51
+ });
52
+ expect(res.status).toBe(302);
53
+ expect(res.headers.get("location")).toBe(
54
+ "/admin/settings/github-enterprise",
55
+ );
56
+ });
57
+
58
+ it("redirects an admin to Templates when only templates are wired", async () => {
59
+ const app = createAdminUIApp(makeMockDeps({ templateService }));
60
+ const res = await app.request("/admin/settings", {
61
+ headers: { cookie: await adminCookie() },
62
+ });
63
+ expect(res.headers.get("location")).toBe("/admin/settings/templates");
64
+ });
65
+
66
+ it("redirects a non-admin member past the adminOnly item", async () => {
67
+ const app = createAdminUIApp(
68
+ makeMockDeps({
69
+ githubEnterpriseApi: ghe,
70
+ templateService,
71
+ accountServices: memberAccounts("m@acme.com"),
72
+ }),
73
+ );
74
+ const res = await app.request("/admin/settings", {
75
+ headers: { cookie: await userCookie() },
76
+ });
77
+ expect(res.status).toBe(302);
78
+ expect(res.headers.get("location")).toBe("/admin/settings/templates");
79
+ });
80
+
81
+ it("404s a non-admin when only admin-only items exist", async () => {
82
+ const app = createAdminUIApp(makeMockDeps({ githubEnterpriseApi: ghe }));
83
+ const res = await app.request("/admin/settings", {
84
+ headers: { cookie: await userCookie() },
85
+ });
86
+ expect(res.status).toBe(404);
87
+ expect(await res.text()).toContain("No settings");
88
+ });
89
+
90
+ it("is not registered without GHE or templates", async () => {
91
+ const app = createAdminUIApp(makeMockDeps());
92
+ const res = await app.request("/admin/settings", {
93
+ headers: { cookie: await adminCookie() },
94
+ });
95
+ expect(res.status).toBe(404);
96
+ });
97
+
98
+ it("requires a session", async () => {
99
+ const app = createAdminUIApp(makeMockDeps({ templateService }));
100
+ const res = await app.request("/admin/settings");
101
+ expect(res.status).not.toBe(200);
102
+ expect(res.headers.get("location") ?? "").not.toBe(
103
+ "/admin/settings/templates",
104
+ );
105
+ });
106
+ });
107
+
108
+ describe("settings shell pages", () => {
109
+ it("renders GHE in the shell with an active sidebar item and no cross-link button", async () => {
110
+ const app = createAdminUIApp(
111
+ makeMockDeps({ githubEnterpriseApi: ghe, templateService }),
112
+ );
113
+ const html = await (
114
+ await app.request("/admin/settings/github-enterprise", {
115
+ headers: { cookie: await adminCookie() },
116
+ })
117
+ ).text();
118
+ expect(html).toContain("settings-sidebar");
119
+ expect(html).toContain(
120
+ 'href="/admin/settings/github-enterprise" aria-current="page">GitHub Enterprise',
121
+ );
122
+ expect(html).toContain('href="/admin/settings/templates"');
123
+ expect(html).not.toContain('btn btn-secondary">Agent templates');
124
+ expect(html).toContain(
125
+ 'href="/admin/settings" class="vos-nav-link active"',
126
+ );
127
+ });
128
+
129
+ it("renders Templates in the shell and hides the GHE item from members", async () => {
130
+ const app = createAdminUIApp(
131
+ makeMockDeps({
132
+ githubEnterpriseApi: ghe,
133
+ templateService,
134
+ callerScopeResolver: async () => ({
135
+ kind: "scoped" as const,
136
+ accountId: "acct-1",
137
+ agentIds: [],
138
+ }),
139
+ accountServices: memberAccounts("m@acme.com"),
140
+ }),
141
+ );
142
+ const res = await app.request("/admin/settings/templates", {
143
+ headers: { cookie: await userCookie() },
144
+ });
145
+ expect(res.status).toBe(200);
146
+ const html = await res.text();
147
+ expect(html).toContain(
148
+ 'href="/admin/settings/templates" aria-current="page">Templates',
149
+ );
150
+ expect(html).not.toContain(
151
+ 'class="settings-nav-link" href="/admin/settings/github-enterprise"',
152
+ );
153
+ });
154
+
155
+ it("lists extension nav items in the sidebar", async () => {
156
+ const app = createAdminUIApp(
157
+ makeMockDeps({
158
+ templateService,
159
+ settingsNavItems: [
160
+ { section: "Platform", label: "Widgets", path: "/admin/widgets" },
161
+ ],
162
+ }),
163
+ );
164
+ const html = await (
165
+ await app.request("/admin/settings/templates", {
166
+ headers: { cookie: await adminCookie() },
167
+ })
168
+ ).text();
169
+ expect(html).toContain('href="/admin/widgets"');
170
+ });
171
+ });
172
+
173
+ describe("toolbar Settings entry", () => {
174
+ const settingsLink = 'href="/admin/settings"';
175
+ const get = async (app: ReturnType<typeof createAdminUIApp>, c: string) =>
176
+ (await app.request("/admin/agents", { headers: { cookie: c } })).text();
177
+
178
+ it("shows for a non-account admin and for account members, hides for others", async () => {
179
+ const app = createAdminUIApp(
180
+ makeMockDeps({
181
+ templateService,
182
+ accountServices: memberAccounts("m@acme.com"),
183
+ }),
184
+ );
185
+ expect(await get(app, await adminCookie())).toContain(settingsLink);
186
+ expect(await get(app, await userCookie("m@acme.com"))).toContain(
187
+ settingsLink,
188
+ );
189
+ expect(await get(app, await userCookie("x@other.com"))).not.toContain(
190
+ settingsLink,
191
+ );
192
+ });
193
+ });
@@ -326,6 +326,14 @@ export function baseStyles(): string {
326
326
  background: #fde68a;
327
327
  color: #92400e;
328
328
  }
329
+ .badge-template {
330
+ background: #dbeafe;
331
+ color: #1e40af;
332
+ }
333
+ .badge-custom {
334
+ background: #ede9fe;
335
+ color: #5b21b6;
336
+ }
329
337
 
330
338
  /* ─── Scope pills (filter chips) ────────────────────── */
331
339
  .scope-pill {
@@ -9,7 +9,12 @@
9
9
  */
10
10
 
11
11
  import { renderAdminPage } from "./admin-ui-layout.ts";
12
- import { escapeHtml, renderAdminToolbar } from "./admin-ui-styles.ts";
12
+ import { escapeHtml } from "./admin-ui-styles.ts";
13
+ import {
14
+ buildSettingsNav,
15
+ renderSettingsLayout,
16
+ type SettingsNav,
17
+ } from "./admin-ui-settings-layout.ts";
13
18
 
14
19
  export const ADMIN_TEMPLATES_PATH = "/admin/settings/templates";
15
20
 
@@ -28,6 +33,10 @@ export interface TemplateItemRow {
28
33
 
29
34
  export interface TemplatesPageOpts {
30
35
  userEmail: string;
36
+ /** Viewer is an admin (drives adminOnly sidebar items). */
37
+ isAdmin?: boolean;
38
+ /** Settings sidebar nav; defaults to the base Platform nav. */
39
+ nav?: SettingsNav;
31
40
  /** Accounts the caller may pick; the deployment-wide option is included only for admins. */
32
41
  accountOptions: TemplateScopeOption[];
33
42
  specialtyOptions: TemplateScopeOption[];
@@ -140,16 +149,20 @@ export function renderTemplatesPage(o: TemplatesPageOpts): string {
140
149
  : `<p class="help-text">No template exists for this scope yet. Adding an item creates it.</p>`;
141
150
  return renderAdminPage({
142
151
  title: "Templates — Settings — Shipwright Admin",
143
- body: `${renderAdminToolbar(o.userEmail, BASE)}
144
- <div class="vos-page">
145
- <div class="page-header"><h1 class="page-title">Agent templates</h1></div>
146
- ${error}${notice}
152
+ body: renderSettingsLayout({
153
+ userName: o.userEmail,
154
+ title: "Agent templates",
155
+ nav:
156
+ o.nav ?? buildSettingsNav({ githubEnterprise: true, templates: true }),
157
+ active: BASE,
158
+ isAdmin: o.isAdmin ?? false,
159
+ body: `${error}${notice}
147
160
  <div class="card">
148
161
  <p class="help-text">Default env vars, tools, plugins and crons for new agents in a scope. Secret values are masked after saving; leave <code>***</code> to keep the stored value.</p>
149
162
  ${scopePicker(o)}
150
163
  ${del}
151
164
  </div>
152
- ${(["env", "tool", "plugin", "cron"] as const).map((k) => kindCard(o, k)).join("\n")}
153
- </div>`,
165
+ ${(["env", "tool", "plugin", "cron"] as const).map((k) => kindCard(o, k)).join("\n")}`,
166
+ }),
154
167
  });
155
168
  }