@app-vitals/agent-admin 1.49.0 → 1.50.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.
@@ -22,6 +22,7 @@ import {
22
22
  uncoveredRepos,
23
23
  } from "./admin-ui-installation-repos-pages.ts";
24
24
  import { renderAdminPage } from "./admin-ui-layout.ts";
25
+ import { renderSettingsLayout } from "./admin-ui-settings-layout.ts";
25
26
  import {
26
27
  BREAKPOINT_MOBILE_MAX,
27
28
  escapeHtml,
@@ -973,31 +974,99 @@ function renderConnectAction(
973
974
  </details>`;
974
975
  }
975
976
 
977
+ export const AGENT_SECTIONS = [
978
+ "general",
979
+ "automation",
980
+ "configuration",
981
+ "access",
982
+ "extensions",
983
+ ] as const;
984
+ export type AgentSection = (typeof AGENT_SECTIONS)[number];
985
+
986
+ export function isAgentSection(value: string): value is AgentSection {
987
+ return (AGENT_SECTIONS as readonly string[]).includes(value);
988
+ }
989
+
990
+ const AGENT_SECTION_LABELS: Record<AgentSection, string> = {
991
+ general: "General",
992
+ automation: "Automation",
993
+ configuration: "Configuration",
994
+ access: "Access",
995
+ extensions: "Extensions",
996
+ };
997
+
976
998
  /**
977
- * Renders one collapsible accordion section on the agent detail page
978
- * (AGA-1.1) — a `<details class="group">` wrapping a fixed subset of the
979
- * page's existing cards. Always renders collapsed (no `open` attribute),
980
- * including when `agent.missingRequiredEnv` is non-empty — there is no
981
- * auto-open behavior for any group.
982
- *
983
- * `stat` is a short, pre-formatted, trusted (non-user-controlled) string
984
- * (e.g. "5 system · 7 custom") rendered flush-right in the summary row.
985
- * `name` (also trusted/static) is the group title, rendered flush-left.
986
- * The toggle indicator (▸/▾) is a `::before` on the `.group-title` span
987
- * itself — NOT on the flex `.group-summary` — so it stays part of that one
988
- * flex child instead of becoming its own third flex item, which would break
989
- * the flush-left/flush-right 2-sided layout into an uneven 3-way split.
999
+ * Path of one agent detail section (SGL-1.2). General is the bare agent path,
1000
+ * so existing links and redirects to /admin/agents/:id keep landing there.
1001
+ * `query` params (e.g. error / success / warning) are URL-encoded and appended
1002
+ * so post-action redirects keep their banner on the section that owns the card.
990
1003
  */
991
- function renderGroup(name: string, stat: string, bodyHtml: string): string {
992
- return `<details class="group">
993
- <summary class="group-summary">
994
- <span class="group-title">${name}</span>
995
- <span class="group-sub">${stat}</span>
996
- </summary>
997
- <div class="group-body">
998
- ${bodyHtml}
999
- </div>
1000
- </details>`;
1004
+ export function agentSectionPath(
1005
+ agentId: string,
1006
+ section: AgentSection = "general",
1007
+ query?: Record<string, string | undefined>,
1008
+ ): string {
1009
+ const base = `/admin/agents/${encodeURIComponent(agentId)}`;
1010
+ const path = section === "general" ? base : `${base}/${section}`;
1011
+ const qs = Object.entries(query ?? {})
1012
+ .filter((e): e is [string, string] => e[1] !== undefined)
1013
+ .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
1014
+ .join("&");
1015
+ return qs ? `${path}?${qs}` : path;
1016
+ }
1017
+
1018
+ /**
1019
+ * Section each POST /admin/agents/:id/* handler redirects back to (SGL-1.3):
1020
+ * the section whose card renders the handler's form. Keys are the route path
1021
+ * after `/admin/agents/:id`. A unit test scans admin-ui.ts so a new handler
1022
+ * cannot be added without an entry here.
1023
+ */
1024
+ export const AGENT_POST_SECTIONS: Readonly<Record<string, AgentSection>> = {
1025
+ "/github-username": "access",
1026
+ "/github-sync/apply-confirmed": "access",
1027
+ "/repos/remove-confirmed": "configuration",
1028
+ "/envs": "configuration",
1029
+ "/template/detach": "configuration",
1030
+ "/template/reattach": "configuration",
1031
+ "/template/reset": "configuration",
1032
+ "/envs/delete": "configuration",
1033
+ "/repos/add": "configuration",
1034
+ "/repos/delete": "configuration",
1035
+ "/review-author-allowlist/add": "access",
1036
+ "/review-author-allowlist/delete": "access",
1037
+ "/patch-author-allowlist/add": "access",
1038
+ "/patch-author-allowlist/delete": "access",
1039
+ // Shared by the Slack access card (access) and the Agent Policy card
1040
+ // (configuration); see settingsRedirectSection.
1041
+ "/settings": "configuration",
1042
+ "/crons": "automation",
1043
+ "/crons/:cronId/toggle": "automation",
1044
+ "/crons/:cronId/update": "automation",
1045
+ "/crons/:cronId/delete": "automation",
1046
+ "/tools": "extensions",
1047
+ "/tools/:toolId/toggle": "extensions",
1048
+ "/tools/:toolId/delete": "extensions",
1049
+ "/marketplaces": "extensions",
1050
+ "/marketplaces/delete": "extensions",
1051
+ "/plugins": "extensions",
1052
+ "/plugins/delete": "extensions",
1053
+ "/tokens": "access",
1054
+ "/tokens/:tokenId/revoke": "access",
1055
+ "/sync-manifest": "general",
1056
+ "/connect-slack": "access",
1057
+ "/connect-slack/app-token": "access",
1058
+ "/connect-github": "access",
1059
+ "/members": "access",
1060
+ "/members/delete": "access",
1061
+ "/delete": "general",
1062
+ };
1063
+
1064
+ /**
1065
+ * POST /settings serves two forms: Slack access (access section, carries
1066
+ * restrictSlackToMembers) and Agent Policy (configuration section).
1067
+ */
1068
+ export function settingsRedirectSection(formData: FormData): AgentSection {
1069
+ return formData.has("restrictSlackToMembers") ? "access" : "configuration";
1001
1070
  }
1002
1071
 
1003
1072
  export function renderAgentDetailPage(
@@ -1018,6 +1087,8 @@ export function renderAgentDetailPage(
1018
1087
  userName: string,
1019
1088
  isAdmin: boolean,
1020
1089
  opts?: {
1090
+ /** Section to render (SGL-1.2). Defaults to "general". */
1091
+ section?: AgentSection;
1021
1092
  /**
1022
1093
  * SSP-4.3: render the Members / Slack access / Danger Zone cards. Defaults
1023
1094
  * to isAdmin; the caller passes true for agent-access holders when
@@ -2070,8 +2141,8 @@ export function renderAgentDetailPage(
2070
2141
 
2071
2142
  const dangerZoneSection = canManage
2072
2143
  ? `<!-- Danger Zone -->
2073
- <div class="card" style="border:1px solid #fca5a5">
2074
- <div class="card-title" style="color:#dc2626">Danger Zone</div>
2144
+ <div class="settings-danger-zone">
2145
+ <div class="settings-section-title">Danger Zone</div>
2075
2146
  <p style="font-size:13px;color:#6b7280;margin-bottom:16px">
2076
2147
  Deleting this agent permanently removes all its data (env vars, crons, tools, tokens, plugins, members)
2077
2148
  and terminates its pod. This action cannot be undone.
@@ -2091,24 +2162,8 @@ export function renderAgentDetailPage(
2091
2162
  </div>`
2092
2163
  : "";
2093
2164
 
2094
- // ─── Accordion groups (AGA-1.1) ────────────────────────────────────────
2095
- // The cards below are grouped into 4 collapsed-by-default
2096
- // <details class="group"> sections. Grouping is purely presentational —
2097
- // every card's internal markup/ids/form actions are unchanged, they're
2098
- // just composed into a new order. Agent Policy (added after this task was
2099
- // originally scoped) lands in Configuration alongside Env Vars/Repos since
2100
- // it is agent-level configuration, as do extension cards placed there
2101
- // (the coding extension's Phase Methodology card) — this keeps every card
2102
- // inside exactly one of the 4 groups, with no stray bare cards besides
2103
- // Danger Zone.
2104
- const automationStat = `${systemCrons.length} system · ${customCrons.length} custom`;
2105
- const configurationStat = `${Object.keys(envVars).length} env vars · ${agent.repos.length} repos`;
2106
- const activeTokenCount = tokens.filter((t) => !t.revokedAt).length;
2107
- const accessStat = `${members.length} members · ${activeTokenCount} active tokens`;
2108
- const pluginsToolsStat = `${tools.length} tools · ${plugins.length} plugins`;
2109
-
2110
2165
  // ─── Stat strip (AGA-1.2) ──────────────────────────────────────────────
2111
- // 4-tile stat strip rendered above the 4 accordion groups. Each tile
2166
+ // 4-tile stat strip rendered on the General section. Each tile
2112
2167
  // derives its count from parameters already passed into this function.
2113
2168
  const cronsActiveCount = topLevelCrons.filter((c) => c.enabled).length;
2114
2169
  const missingEnvVarsCount = agent.missingRequiredEnv.length;
@@ -2134,64 +2189,15 @@ export function renderAgentDetailPage(
2134
2189
  </div>
2135
2190
  </div>`;
2136
2191
 
2137
- const automationGroup = renderGroup(
2138
- "Automation",
2139
- automationStat,
2140
- cronJobsSection,
2141
- );
2142
- const configurationGroup = renderGroup(
2143
- "Configuration",
2144
- configurationStat,
2145
- `${templateCard}${envVarsSection}${reposSection}${(opts?.configurationCardsHtml ?? []).join("")}${agentPolicySection}`,
2146
- );
2147
- const accessGroup = renderGroup(
2148
- "Access",
2149
- accessStat,
2150
- `${identitySection}${canManage ? membersSection : ""}${authorAllowlistReviewSection}${authorAllowlistPatchSection}${slackAccessSection}${tokensSection}`,
2151
- );
2152
- const pluginsToolsGroup = renderGroup(
2153
- "Plugins &amp; Tools",
2154
- pluginsToolsStat,
2155
- `${toolsSection}${pluginsSection}${marketplacesSection}`,
2156
- );
2157
-
2158
- const expandCollapseControls = `
2159
- <div style="display:flex;gap:8px;margin-bottom:16px">
2160
- <button type="button" class="btn btn-secondary" id="expand-all-btn">Expand all</button>
2161
- <button type="button" class="btn btn-secondary" id="collapse-all-btn">Collapse all</button>
2162
- </div>
2163
- <script>
2164
- (function() {
2165
- var expandBtn = document.getElementById('expand-all-btn');
2166
- var collapseBtn = document.getElementById('collapse-all-btn');
2167
- if (expandBtn) {
2168
- expandBtn.addEventListener('click', function() {
2169
- document.querySelectorAll('.group').forEach(function(el) {
2170
- el.open = true;
2171
- });
2172
- });
2173
- }
2174
- if (collapseBtn) {
2175
- collapseBtn.addEventListener('click', function() {
2176
- document.querySelectorAll('.group').forEach(function(el) {
2177
- el.open = false;
2178
- });
2179
- });
2180
- }
2181
- })();
2182
- </script>
2183
- `;
2192
+ const section = opts?.section ?? "general";
2184
2193
 
2185
- return renderAdminPage({
2186
- title: `${agent.name} — Shipwright Admin`,
2187
- body: `${renderAdminToolbar(userName, "/admin/agents")}
2188
- <div class="vos-page">
2189
- <div class="page-header">
2194
+ const headerInfoHtml = `<div class="page-header">
2190
2195
  <div>
2191
2196
  <a href="/admin/agents" style="font-size:13px;color:#6b7280;text-decoration:none">← Agents</a>
2192
- <h1 class="page-title" style="margin-top:4px">${escapeHtml(agent.name)}</h1>
2193
- <span style="font-size:13px;color:#6b7280">Type: <span class="mono">${escapeHtml(agent.specialty)}</span></span>
2194
- ${agent.slackId ? `<span style="font-size:13px;color:#6b7280">Slack ID: <span class="mono">${escapeHtml(agent.slackId)}</span></span>` : ""}
2197
+ <div style="margin-top:4px">
2198
+ <span style="font-size:13px;color:#6b7280">Type: <span class="mono">${escapeHtml(agent.specialty)}</span></span>
2199
+ ${agent.slackId ? `<span style="font-size:13px;color:#6b7280">Slack ID: <span class="mono">${escapeHtml(agent.slackId)}</span></span>` : ""}
2200
+ </div>
2195
2201
  </div>
2196
2202
  ${
2197
2203
  agent.slackId
@@ -2216,24 +2222,45 @@ export function renderAgentDetailPage(
2216
2222
  </div>`
2217
2223
  : ""
2218
2224
  }
2219
- </div>
2220
- ${errorHtml}
2221
- ${successHtml}
2222
- ${warningHtml}
2223
- ${newTokenHtml}
2225
+ </div>`;
2226
+
2227
+ const sectionBodies: Record<AgentSection, string> = {
2228
+ general: `${headerInfoHtml}
2224
2229
  ${(opts?.extensionCardsHtml ?? []).join("\n ")}
2225
2230
 
2226
2231
  ${statStripHtml}
2227
2232
 
2228
- ${expandCollapseControls}
2229
- ${automationGroup}
2230
- ${configurationGroup}
2231
- ${accessGroup}
2232
- ${pluginsToolsGroup}
2233
-
2234
- ${dangerZoneSection}
2233
+ ${dangerZoneSection}`,
2234
+ automation: cronJobsSection,
2235
+ configuration: `${templateCard}${envVarsSection}${reposSection}${(opts?.configurationCardsHtml ?? []).join("")}${agentPolicySection}`,
2236
+ access: `${identitySection}${canManage ? membersSection : ""}${authorAllowlistReviewSection}${authorAllowlistPatchSection}${slackAccessSection}${tokensSection}`,
2237
+ extensions: `${toolsSection}${pluginsSection}${marketplacesSection}`,
2238
+ };
2235
2239
 
2236
- </div>`,
2240
+ return renderAdminPage({
2241
+ title: `${agent.name} — Shipwright Admin`,
2242
+ body: renderSettingsLayout({
2243
+ userName,
2244
+ title: agent.name,
2245
+ nav: {
2246
+ sections: [
2247
+ {
2248
+ label: "Agent",
2249
+ items: AGENT_SECTIONS.map((k) => ({
2250
+ label: AGENT_SECTION_LABELS[k],
2251
+ path: agentSectionPath(agent.id, k),
2252
+ })),
2253
+ },
2254
+ ],
2255
+ },
2256
+ active: agentSectionPath(agent.id, section),
2257
+ toolbarPath: "/admin/agents",
2258
+ body: `${errorHtml}
2259
+ ${successHtml}
2260
+ ${warningHtml}
2261
+ ${newTokenHtml}
2262
+ ${sectionBodies[section]}`,
2263
+ }),
2237
2264
  });
2238
2265
  }
2239
2266