@app-vitals/agent-admin 1.124.0 → 1.126.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.
- package/package.json +2 -2
- package/prisma/client/browser.ts +5 -0
- package/prisma/client/client.ts +5 -0
- package/prisma/client/internal/class.ts +14 -4
- package/prisma/client/internal/prismaNamespace.ts +94 -1
- package/prisma/client/internal/prismaNamespaceBrowser.ts +18 -0
- package/prisma/client/models/Agent.ts +306 -0
- package/prisma/client/models/AgentGitHubApp.ts +1605 -0
- package/prisma/client/models.ts +1 -0
- package/prisma/migrations/20261204000000_add_agent_github_app/migration.sql +31 -0
- package/prisma/schema/schema.prisma +32 -2
- package/src/admin-boot.boot-order.unit.test.ts +12 -0
- package/src/admin-boot.ts +18 -2
- package/src/admin-ui-settings-layout.ts +8 -14
- package/src/admin-ui-settings-layout.unit.test.ts +42 -1
- package/src/admin-ui-settings-nav-context.smoke.test.ts +1 -1
- package/src/admin-ui-settings.smoke.test.ts +2 -2
- package/src/agent-github-apps.integration.test.ts +618 -0
- package/src/agent-github-apps.ts +591 -0
- package/src/agent-github-apps.unit.test.ts +266 -0
- package/src/github-enterprise-isolation.unit.test.ts +8 -1
package/prisma/client/models.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type * from './models/SessionFollow.ts'
|
|
|
14
14
|
export type * from './models/SessionAlertState.ts'
|
|
15
15
|
export type * from './models/Agent.ts'
|
|
16
16
|
export type * from './models/AgentEnv.ts'
|
|
17
|
+
export type * from './models/AgentGitHubApp.ts'
|
|
17
18
|
export type * from './models/GitHubEnterpriseApp.ts'
|
|
18
19
|
export type * from './models/AgentCronJob.ts'
|
|
19
20
|
export type * from './models/AgentTool.ts'
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
-- multi-github-apps 1.1: AgentGitHubApp, one row per GitHub App an agent uses.
|
|
2
|
+
-- Additive only: new table, indexes and its FK. Existing GH_APP_* AgentEnv rows
|
|
3
|
+
-- are copied in by an idempotent backfill at admin boot
|
|
4
|
+
-- (backfillAgentGitHubAppsFromEnv), not here: consumers' additive-migration
|
|
5
|
+
-- guards reject INSERT in migration SQL.
|
|
6
|
+
-- CreateTable
|
|
7
|
+
CREATE TABLE "AgentGitHubApp" (
|
|
8
|
+
"id" TEXT NOT NULL,
|
|
9
|
+
"agentId" TEXT NOT NULL,
|
|
10
|
+
"appId" TEXT NOT NULL,
|
|
11
|
+
"slug" TEXT,
|
|
12
|
+
"clientId" TEXT,
|
|
13
|
+
"privateKeyEncrypted" TEXT NOT NULL,
|
|
14
|
+
"clientSecretEncrypted" TEXT,
|
|
15
|
+
"installationId" TEXT,
|
|
16
|
+
"priority" INTEGER NOT NULL DEFAULT 0,
|
|
17
|
+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
18
|
+
"updatedAt" TIMESTAMP(3) NOT NULL,
|
|
19
|
+
|
|
20
|
+
CONSTRAINT "AgentGitHubApp_pkey" PRIMARY KEY ("id")
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
-- CreateIndex
|
|
24
|
+
CREATE INDEX "AgentGitHubApp_agentId_idx" ON "AgentGitHubApp"("agentId");
|
|
25
|
+
|
|
26
|
+
-- CreateIndex
|
|
27
|
+
CREATE UNIQUE INDEX "AgentGitHubApp_agentId_appId_key" ON "AgentGitHubApp"("agentId", "appId");
|
|
28
|
+
|
|
29
|
+
-- AddForeignKey
|
|
30
|
+
ALTER TABLE "AgentGitHubApp" ADD CONSTRAINT "AgentGitHubApp_agentId_fkey" FOREIGN KEY ("agentId") REFERENCES "Agent"("id") ON DELETE CASCADE ON UPDATE CASCADE;
|
|
31
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Shipwright — Admin Service Schema
|
|
2
|
-
// Owns: Agent, AgentEnv, AgentCronJob, AgentTool, AgentToken,
|
|
3
|
-
// AgentMarketplace, AgentTemplate, AgentTemplateItem, SlackConfigToken,
|
|
2
|
+
// Owns: Agent, AgentEnv, AgentGitHubApp, AgentCronJob, AgentTool, AgentToken,
|
|
3
|
+
// AgentPlugin, AgentMarketplace, AgentTemplate, AgentTemplateItem, SlackConfigToken,
|
|
4
4
|
// plus the coding-owned models in coding.prisma (AgentWorkQueueSnapshot,
|
|
5
5
|
// AgentPhaseMethodology, SessionFollow, SessionAlertState).
|
|
6
6
|
// Agent is a first-class model (standalone, not embedded in a User model).
|
|
@@ -97,6 +97,7 @@ model Agent {
|
|
|
97
97
|
updatedAt DateTime @updatedAt
|
|
98
98
|
|
|
99
99
|
envVars AgentEnv[]
|
|
100
|
+
githubApps AgentGitHubApp[]
|
|
100
101
|
cronJobs AgentCronJob[]
|
|
101
102
|
tools AgentTool[]
|
|
102
103
|
tokens AgentToken[]
|
|
@@ -130,6 +131,35 @@ model AgentEnv {
|
|
|
130
131
|
@@unique([agentId, key])
|
|
131
132
|
}
|
|
132
133
|
|
|
134
|
+
// ─── Agent GitHub Apps ────────────────────────────────────────────────────────
|
|
135
|
+
// The agent's own GitHub Apps (multi-github-apps 1.1). An agent may use several
|
|
136
|
+
// apps (a private app can only be installed on its owning account); when two
|
|
137
|
+
// apps are installed on the same owner the lowest priority wins. Rows are
|
|
138
|
+
// backfilled at admin boot from the legacy GH_APP_* AgentEnv rows (see
|
|
139
|
+
// backfillAgentGitHubAppsFromEnv in admin/src/agent-github-apps.ts; the
|
|
140
|
+
// migration itself is additive-only, no INSERT). The private key and client
|
|
141
|
+
// secret are AES-256-GCM encrypted with the same TokenCrypto as AgentEnv and
|
|
142
|
+
// are never returned by a read path. slug/clientId are null for apps entered
|
|
143
|
+
// by manual paste (only id, installation id and key are known).
|
|
144
|
+
|
|
145
|
+
model AgentGitHubApp {
|
|
146
|
+
id String @id @default(cuid())
|
|
147
|
+
agentId String
|
|
148
|
+
agent Agent @relation(fields: [agentId], references: [id], onDelete: Cascade)
|
|
149
|
+
appId String // numeric GitHub App id, stored as text like GH_APP_ID
|
|
150
|
+
slug String?
|
|
151
|
+
clientId String?
|
|
152
|
+
privateKeyEncrypted String // AES-256-GCM; never returned by a read path
|
|
153
|
+
clientSecretEncrypted String? // AES-256-GCM; never returned by a read path
|
|
154
|
+
installationId String? // optional pinned installation (GH_APP_INSTALLATION_ID)
|
|
155
|
+
priority Int @default(0) // lowest wins per owner
|
|
156
|
+
createdAt DateTime @default(now())
|
|
157
|
+
updatedAt DateTime @updatedAt
|
|
158
|
+
|
|
159
|
+
@@unique([agentId, appId])
|
|
160
|
+
@@index([agentId])
|
|
161
|
+
}
|
|
162
|
+
|
|
133
163
|
// ─── GitHub Enterprise Apps ───────────────────────────────────────────────────
|
|
134
164
|
// Optional admin-level GitHub Apps, one per (accountId, role) where role is
|
|
135
165
|
// 'installer' | 'lookup'. accountId null = the deployment-wide pair (at most two
|
|
@@ -48,10 +48,22 @@ describe("admin-boot.ts boot sequence", () => {
|
|
|
48
48
|
"const server = Bun.serve(",
|
|
49
49
|
"const shutdown = registerGracefulShutdown(",
|
|
50
50
|
"void runTemplateSeed(",
|
|
51
|
+
"void backfillAgentGitHubAppsFromEnv(",
|
|
51
52
|
"void runStartupPolicyReconcile(",
|
|
52
53
|
]);
|
|
53
54
|
});
|
|
54
55
|
|
|
56
|
+
it("backfills GitHub Apps from GH_APP_* env after migrations, non-fatal and without blocking serving (multi-github-apps 1.1)", () => {
|
|
57
|
+
assertOrdered([
|
|
58
|
+
"await runMigrations();",
|
|
59
|
+
"const crypto = makeTokenCrypto();",
|
|
60
|
+
"const server = Bun.serve(",
|
|
61
|
+
"void backfillAgentGitHubAppsFromEnv(",
|
|
62
|
+
"[admin] github app backfill failed:",
|
|
63
|
+
]);
|
|
64
|
+
expect(source).not.toContain("await backfillAgentGitHubAppsFromEnv(");
|
|
65
|
+
});
|
|
66
|
+
|
|
55
67
|
it("registers the GitHub repo refresher on its own interval, with env-driven config (GLC-1.4)", () => {
|
|
56
68
|
assertOrdered([
|
|
57
69
|
"resolveRefreshConfig(process.env)",
|
package/src/admin-boot.ts
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* Sentry → migrations → Prisma → platform services → resolve extensions →
|
|
11
11
|
* routes (health, runtime API, admin API, accounts API, extension APIs,
|
|
12
12
|
* admin UI, extension UI) → platform sweepers → extension background
|
|
13
|
-
* passes → Bun.serve → graceful shutdown → template seed →
|
|
14
|
-
* reconcile.
|
|
13
|
+
* passes → Bun.serve → graceful shutdown → template seed → tools-token and
|
|
14
|
+
* GitHub App backfills → startup policy reconcile.
|
|
15
15
|
*
|
|
16
16
|
* Route mount order (important — avoids shadowing):
|
|
17
17
|
* GET /health — liveness check (no auth, DB-independent)
|
|
@@ -80,6 +80,7 @@ import { AgentCronJobService } from "./agent-cron-jobs.ts";
|
|
|
80
80
|
import { AgentCronRunStatsService } from "./agent-cron-run-stats.ts";
|
|
81
81
|
import { AgentCronRunService } from "./agent-cron-runs.ts";
|
|
82
82
|
import { AgentEnvService } from "./agent-envs.ts";
|
|
83
|
+
import { backfillAgentGitHubAppsFromEnv } from "./agent-github-apps.ts";
|
|
83
84
|
import { AgentGitHubInstallationsService } from "./agent-github-installations.ts";
|
|
84
85
|
import { AgentMarketplaceService } from "./agent-marketplaces.ts";
|
|
85
86
|
import { AgentMemberService } from "./agent-members.ts";
|
|
@@ -951,6 +952,21 @@ export async function startAdmin(
|
|
|
951
952
|
),
|
|
952
953
|
);
|
|
953
954
|
|
|
955
|
+
// GitHub App backfill (multi-github-apps 1.1): copies each agent's legacy
|
|
956
|
+
// GH_APP_* env rows into AgentGitHubApp. Runs here, after migrations, not in
|
|
957
|
+
// the migration SQL (consumers' additive-migration guards reject INSERT).
|
|
958
|
+
// Idempotent; skips are logged. Fire-and-forget, never fatal to boot.
|
|
959
|
+
void backfillAgentGitHubAppsFromEnv({
|
|
960
|
+
prisma,
|
|
961
|
+
crypto,
|
|
962
|
+
logger: console,
|
|
963
|
+
}).catch((err) =>
|
|
964
|
+
console.error(
|
|
965
|
+
"[admin] github app backfill failed:",
|
|
966
|
+
err instanceof Error ? err.message : String(err),
|
|
967
|
+
),
|
|
968
|
+
);
|
|
969
|
+
|
|
954
970
|
// Policy-only reconcile (ACP-1.3): a Claude policy change restarts admin via
|
|
955
971
|
// the chart's policy-hash env var, so rolling only the agents whose policy
|
|
956
972
|
// wiring drifted happens here. Runs even with no policy configured so agents
|
|
@@ -145,8 +145,8 @@ export interface BuildSettingsNavOptions {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
|
-
* Base settings nav:
|
|
149
|
-
*
|
|
148
|
+
* Base settings nav: Personal section (Preferences), Account section (Account,
|
|
149
|
+
* admin-only Accounts; SGL-2.3), Platform section (GitHub Enterprise, Templates) plus extension items. Empty
|
|
150
150
|
* sections are dropped.
|
|
151
151
|
*/
|
|
152
152
|
export function buildSettingsNav(
|
|
@@ -175,28 +175,22 @@ export function buildSettingsNav(
|
|
|
175
175
|
ownerOnly: true,
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
178
|
+
const sections: SettingsNavSection[] = [];
|
|
179
|
+
if (opts.preferences) {
|
|
180
|
+
sections.push({
|
|
181
|
+
label: "Personal",
|
|
182
|
+
items: [{ label: "Preferences", path: SETTINGS_PREFERENCES_PATH }],
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
|
-
const sections: SettingsNavSection[] = [];
|
|
186
185
|
if (opts.accounts) {
|
|
187
186
|
sections.push({
|
|
188
187
|
label: "Account",
|
|
189
188
|
items: [
|
|
190
189
|
{ label: "Account", path: SETTINGS_ACCOUNT_PATH, ownerOnly: true },
|
|
190
|
+
{ label: "Accounts", path: SETTINGS_ACCOUNTS_PATH, adminOnly: true },
|
|
191
191
|
],
|
|
192
192
|
});
|
|
193
193
|
}
|
|
194
|
-
if (opts.preferences) {
|
|
195
|
-
const section = sections.find((s) => s.label === "Account");
|
|
196
|
-
const item = { label: "Preferences", path: SETTINGS_PREFERENCES_PATH };
|
|
197
|
-
if (section) section.items.push(item);
|
|
198
|
-
else sections.push({ label: "Account", items: [item] });
|
|
199
|
-
}
|
|
200
194
|
if (platform.length > 0)
|
|
201
195
|
sections.push({ label: "Platform", items: platform });
|
|
202
196
|
const base: SettingsNav = { sections };
|
|
@@ -225,11 +225,11 @@ describe("filterSettingsNavForRole (ACM-7.2)", () => {
|
|
|
225
225
|
test("admin sees every item", () => {
|
|
226
226
|
expect(labels("admin")).toEqual([
|
|
227
227
|
"Account",
|
|
228
|
+
"Accounts",
|
|
228
229
|
"Notifications",
|
|
229
230
|
"GitHub Enterprise",
|
|
230
231
|
"Slack config token",
|
|
231
232
|
"Templates",
|
|
232
|
-
"Accounts",
|
|
233
233
|
"System crons",
|
|
234
234
|
]);
|
|
235
235
|
});
|
|
@@ -259,3 +259,44 @@ describe("filterSettingsNavForRole (ACM-7.2)", () => {
|
|
|
259
259
|
);
|
|
260
260
|
});
|
|
261
261
|
});
|
|
262
|
+
|
|
263
|
+
describe("settings nav reorg: Personal / Account sections", () => {
|
|
264
|
+
const nav = buildSettingsNav({
|
|
265
|
+
preferences: true,
|
|
266
|
+
accounts: true,
|
|
267
|
+
templates: true,
|
|
268
|
+
extraItems: [{ section: "Personal", label: "Profile", path: "/profile" }],
|
|
269
|
+
});
|
|
270
|
+
const section = (n: SettingsNav, label: string) =>
|
|
271
|
+
n.sections.find((s) => s.label === label)?.items.map((i) => i.label);
|
|
272
|
+
|
|
273
|
+
test("Preferences lives under Personal, not Account", () => {
|
|
274
|
+
expect(section(nav, "Personal")).toContain("Preferences");
|
|
275
|
+
expect(section(nav, "Account")).not.toContain("Preferences");
|
|
276
|
+
});
|
|
277
|
+
test("Accounts lives under Account, not Platform", () => {
|
|
278
|
+
expect(section(nav, "Account")).toEqual(["Account", "Accounts"]);
|
|
279
|
+
expect(section(nav, "Platform")).not.toContain("Accounts");
|
|
280
|
+
});
|
|
281
|
+
test("admin sees both Account items; owner sees Account only", () => {
|
|
282
|
+
expect(section(filterSettingsNavForRole(nav, "admin"), "Account")).toEqual([
|
|
283
|
+
"Account",
|
|
284
|
+
"Accounts",
|
|
285
|
+
]);
|
|
286
|
+
expect(section(filterSettingsNavForRole(nav, "owner"), "Account")).toEqual([
|
|
287
|
+
"Account",
|
|
288
|
+
]);
|
|
289
|
+
});
|
|
290
|
+
test("a member's resolved nav has no Account section or Accounts item", () => {
|
|
291
|
+
const member = filterSettingsNavForRole(nav, "member");
|
|
292
|
+
expect(member.sections.map((s) => s.label)).not.toContain("Account");
|
|
293
|
+
const labels = member.sections.flatMap((s) => s.items.map((i) => i.label));
|
|
294
|
+
expect(labels).not.toContain("Account");
|
|
295
|
+
expect(labels).not.toContain("Accounts");
|
|
296
|
+
expect(section(member, "Personal")).toContain("Preferences");
|
|
297
|
+
});
|
|
298
|
+
test("an extension item targeting Personal merges into the Preferences section", () => {
|
|
299
|
+
expect(nav.sections.filter((s) => s.label === "Personal")).toHaveLength(1);
|
|
300
|
+
expect(section(nav, "Personal")).toEqual(["Preferences", "Profile"]);
|
|
301
|
+
});
|
|
302
|
+
});
|
|
@@ -88,9 +88,9 @@ describe("getSettingsNav in extension adminUiRoutes", () => {
|
|
|
88
88
|
);
|
|
89
89
|
expect(paths(nav)).toEqual([
|
|
90
90
|
SETTINGS_ACCOUNT_PATH,
|
|
91
|
+
SETTINGS_ACCOUNTS_PATH,
|
|
91
92
|
SETTINGS_GHE_PATH,
|
|
92
93
|
SETTINGS_TEMPLATES_PATH,
|
|
93
|
-
SETTINGS_ACCOUNTS_PATH,
|
|
94
94
|
"/admin/ext-page",
|
|
95
95
|
]);
|
|
96
96
|
});
|
|
@@ -277,11 +277,11 @@ describe("GET /admin/settings with accounts (SGL-2.3)", () => {
|
|
|
277
277
|
expect(res.headers.get("location")).toBe("/admin/notifications");
|
|
278
278
|
});
|
|
279
279
|
|
|
280
|
-
it("skips Account for an admin without an account", async () => {
|
|
280
|
+
it("skips Account for an admin without an account, landing on Accounts", async () => {
|
|
281
281
|
const res = await build(null).request("/admin/settings", {
|
|
282
282
|
headers: { cookie: await adminCookie() },
|
|
283
283
|
});
|
|
284
284
|
expect(res.status).toBe(302);
|
|
285
|
-
expect(res.headers.get("location")).toBe("/admin/
|
|
285
|
+
expect(res.headers.get("location")).toBe("/admin/accounts");
|
|
286
286
|
});
|
|
287
287
|
});
|