@app-vitals/agent-admin 1.125.0 → 1.126.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.
- 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/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
|