@app-vitals/agent-admin 1.32.0 → 1.34.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/openapi.platform.json +473 -1
- package/package.json +2 -2
- package/src/admin-boot.ts +12 -0
- package/src/agents-api.smoke.test.ts +496 -0
- package/src/agents-api.ts +314 -3
- package/src/github-reconcile-wiring.ts +22 -0
- package/src/lost-access-removal.ts +333 -0
- package/src/lost-access-removal.unit.test.ts +467 -0
- package/src/reconcile-planner.ts +26 -11
- package/src/repo-removal-open-work.ts +64 -0
- package/src/repo-removal-open-work.unit.test.ts +105 -0
package/src/agents-api.ts
CHANGED
|
@@ -166,7 +166,13 @@ import {
|
|
|
166
166
|
UpsertChatTokenDailyBodySchema,
|
|
167
167
|
} from "./openapi-schemas.ts";
|
|
168
168
|
import type { InstallationReposService } from "./installation-repos-service.ts";
|
|
169
|
+
import type { LostAccessRemovalService } from "./lost-access-removal.ts";
|
|
169
170
|
import type { ReconcileApplyService } from "./reconcile-apply-service.ts";
|
|
171
|
+
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
172
|
+
import {
|
|
173
|
+
blockRepoRemovalWork,
|
|
174
|
+
previewRepoRemovalWork,
|
|
175
|
+
} from "./repo-removal-open-work.ts";
|
|
170
176
|
import type { SelfServeConfig } from "./self-serve-config.ts";
|
|
171
177
|
import type { SpecialtyDefaultsResolver } from "./specialty-defaults.ts";
|
|
172
178
|
import type { SpecialtyTypeResolver } from "./specialty-types.ts";
|
|
@@ -270,6 +276,13 @@ export interface AdminDeps {
|
|
|
270
276
|
* `skipped`.
|
|
271
277
|
*/
|
|
272
278
|
githubReconcile?: Pick<ReconcileApplyService, "planWithOpenWork" | "apply">;
|
|
279
|
+
/**
|
|
280
|
+
* IRM-1.7: optional host-supplied open-work port. When an agent's own repos
|
|
281
|
+
* lose a repo (DELETE /agents/{id}/repos/{owner}/{name} or a PATCH that
|
|
282
|
+
* drops repos) its open work there is blocked; absent means nothing is
|
|
283
|
+
* listed or blocked.
|
|
284
|
+
*/
|
|
285
|
+
openWork?: OpenWorkPort;
|
|
273
286
|
/**
|
|
274
287
|
* IRM-1.2: backs the admin-only /agents/:id/github-installation/repos
|
|
275
288
|
* routes. Optional (additive); absent means the enterprise Apps are not
|
|
@@ -279,6 +292,15 @@ export interface AdminDeps {
|
|
|
279
292
|
InstallationReposService,
|
|
280
293
|
"list" | "add" | "remove"
|
|
281
294
|
>;
|
|
295
|
+
/**
|
|
296
|
+
* IRM-1.3: backs the admin-only /agents/:id/github-lost-access/{preview,remove}
|
|
297
|
+
* routes. Optional (additive); absent means the enterprise Apps are not
|
|
298
|
+
* wired and the routes answer 503.
|
|
299
|
+
*/
|
|
300
|
+
githubLostAccessRemoval?: Pick<
|
|
301
|
+
LostAccessRemovalService,
|
|
302
|
+
"preview" | "remove"
|
|
303
|
+
>;
|
|
282
304
|
/**
|
|
283
305
|
* Retained solely as a pass-through to deleteAgentFully() (DELETE /agents/:id),
|
|
284
306
|
* which has its own internal prisma.agent/prisma.agentEnv access — out of
|
|
@@ -727,6 +749,73 @@ const GithubInstallationReposChangeSchema = z
|
|
|
727
749
|
})
|
|
728
750
|
.openapi("GithubInstallationReposChange");
|
|
729
751
|
|
|
752
|
+
const OpenWorkItemSchema = z.object({
|
|
753
|
+
id: z.string(),
|
|
754
|
+
repo: z.string(),
|
|
755
|
+
title: z.string().optional(),
|
|
756
|
+
});
|
|
757
|
+
|
|
758
|
+
const SkippedOrgsSchema = z.array(
|
|
759
|
+
z.object({ org: z.string(), reason: z.string() }),
|
|
760
|
+
);
|
|
761
|
+
|
|
762
|
+
const GithubLostAccessPreviewSchema = z
|
|
763
|
+
.object({
|
|
764
|
+
status: z.enum(["previewed", "skipped"]).openapi({
|
|
765
|
+
description:
|
|
766
|
+
"`skipped` (not an error) when no GitHub username is bound, the user is not found or unverified, the agent has no GH_APP_ID, or the Apps are not configured; `reason` says why.",
|
|
767
|
+
}),
|
|
768
|
+
reason: z.string().optional(),
|
|
769
|
+
repos: z.array(z.string()).optional().openapi({
|
|
770
|
+
description:
|
|
771
|
+
"Every repo the bound user can no longer push to that would be removed from the installation or the agent's repos.",
|
|
772
|
+
}),
|
|
773
|
+
installationRemoves: z.array(z.string()).optional(),
|
|
774
|
+
configRemoves: z.array(z.string()).optional(),
|
|
775
|
+
skippedOrgs: SkippedOrgsSchema.optional().openapi({
|
|
776
|
+
description:
|
|
777
|
+
"Orgs whose access listing is missing, partial or failed, or whose lookup App is installed on selected repositories only; nothing there is removed.",
|
|
778
|
+
}),
|
|
779
|
+
openWork: z.array(OpenWorkItemSchema).optional().openapi({
|
|
780
|
+
description:
|
|
781
|
+
"The agent's open tasks and PRs on those repos that removing them would block; empty when no open-work port is wired.",
|
|
782
|
+
}),
|
|
783
|
+
warnings: z.array(z.string()).optional(),
|
|
784
|
+
})
|
|
785
|
+
.openapi("GithubLostAccessPreview");
|
|
786
|
+
|
|
787
|
+
const GithubLostAccessRemoveBodySchema = z
|
|
788
|
+
.object({
|
|
789
|
+
repos: z.array(RepoFullNameSchema).min(1).max(100).openapi({
|
|
790
|
+
description:
|
|
791
|
+
"The repos (owner/repo) the admin confirmed from the preview. Each is re-checked; only those the user still cannot push to are removed.",
|
|
792
|
+
}),
|
|
793
|
+
confirmRemovals: z.boolean().optional().openapi({
|
|
794
|
+
description: "Required when more than 10 repos would be removed.",
|
|
795
|
+
}),
|
|
796
|
+
})
|
|
797
|
+
.openapi("GithubLostAccessRemoveBody");
|
|
798
|
+
|
|
799
|
+
const GithubLostAccessRemoveResultSchema = z
|
|
800
|
+
.object({
|
|
801
|
+
status: z.enum(["applied", "noop", "skipped"]),
|
|
802
|
+
reason: z.string().optional(),
|
|
803
|
+
auditId: z.string().optional(),
|
|
804
|
+
repos: z.array(z.string()).optional(),
|
|
805
|
+
installationRemoves: z.array(z.string()).optional(),
|
|
806
|
+
configRemoves: z.array(z.string()).optional(),
|
|
807
|
+
notRemoved: z
|
|
808
|
+
.array(z.object({ repo: z.string(), reason: z.string() }))
|
|
809
|
+
.optional()
|
|
810
|
+
.openapi({
|
|
811
|
+
description:
|
|
812
|
+
"Named repos left alone: the user can still push, the org was skipped, or the repo is on neither the installation nor the agent.",
|
|
813
|
+
}),
|
|
814
|
+
skippedOrgs: SkippedOrgsSchema.optional(),
|
|
815
|
+
warnings: z.array(z.string()).optional(),
|
|
816
|
+
})
|
|
817
|
+
.openapi("GithubLostAccessRemoveResult");
|
|
818
|
+
|
|
730
819
|
// ─── Route definitions ──────────────────────────────────────────────────────────
|
|
731
820
|
|
|
732
821
|
const reconcileAgentsRoute = createRoute({
|
|
@@ -903,7 +992,7 @@ const removeAgentRepoRoute = createRoute({
|
|
|
903
992
|
path: "/agents/{id}/repos/{owner}/{name}",
|
|
904
993
|
summary: "Remove a repo from an agent",
|
|
905
994
|
description:
|
|
906
|
-
"Admin, the agent's own key, or platform.ops. Removes one `owner/name` repo from the agent's `repos`, preserving the order of the rest. 404 when the agent does not have that repo. Returns the full updated agent.",
|
|
995
|
+
"Admin, the agent's own key, or platform.ops. Removes one `owner/name` repo from the agent's `repos`, preserving the order of the rest. The agent's open work on the repo is blocked through the optional open-work port (a failure there is a warning; the removal still succeeds), whoever the caller is; re-adding the repo never unblocks it. 404 when the agent does not have that repo. Returns the full updated agent.",
|
|
907
996
|
request: { params: AgentRepoParamSchema },
|
|
908
997
|
responses: {
|
|
909
998
|
200: {
|
|
@@ -915,6 +1004,37 @@ const removeAgentRepoRoute = createRoute({
|
|
|
915
1004
|
},
|
|
916
1005
|
});
|
|
917
1006
|
|
|
1007
|
+
const repoRemovalPreviewRoute = createRoute({
|
|
1008
|
+
method: "get",
|
|
1009
|
+
path: "/agents/{id}/repos/{owner}/{name}/removal-preview",
|
|
1010
|
+
summary: "Preview the open work blocked by removing a repo from an agent",
|
|
1011
|
+
description:
|
|
1012
|
+
"Admin or session member. Read-only: lists the agent's open tasks and PRs that removing `owner/name` from its repos would block (via the optional open-work port); nothing is changed. `openWork` is empty when no port is wired; a port failure is reported in `warnings`. 404 when the agent does not have that repo.",
|
|
1013
|
+
request: { params: AgentRepoParamSchema },
|
|
1014
|
+
responses: {
|
|
1015
|
+
200: {
|
|
1016
|
+
description: "Open work that would be blocked",
|
|
1017
|
+
content: {
|
|
1018
|
+
"application/json": {
|
|
1019
|
+
schema: z.object({
|
|
1020
|
+
repo: z.string(),
|
|
1021
|
+
openWork: z.array(
|
|
1022
|
+
z.object({
|
|
1023
|
+
id: z.string(),
|
|
1024
|
+
repo: z.string(),
|
|
1025
|
+
title: z.string().optional(),
|
|
1026
|
+
}),
|
|
1027
|
+
),
|
|
1028
|
+
warnings: z.array(z.string()),
|
|
1029
|
+
}),
|
|
1030
|
+
},
|
|
1031
|
+
},
|
|
1032
|
+
},
|
|
1033
|
+
403: { description: "Forbidden", ...jsonError },
|
|
1034
|
+
404: { description: "Agent or repo not found", ...jsonError },
|
|
1035
|
+
},
|
|
1036
|
+
});
|
|
1037
|
+
|
|
918
1038
|
const deleteAgentRoute = createRoute({
|
|
919
1039
|
method: "delete",
|
|
920
1040
|
path: "/agents/{id}",
|
|
@@ -1760,6 +1880,59 @@ const removeInstallationReposRoute = createRoute({
|
|
|
1760
1880
|
},
|
|
1761
1881
|
});
|
|
1762
1882
|
|
|
1883
|
+
const lostAccessErrors = {
|
|
1884
|
+
401: { description: "Unauthorized", ...jsonError },
|
|
1885
|
+
403: { description: "Platform admin required", ...jsonError },
|
|
1886
|
+
404: { description: "Agent not found", ...jsonError },
|
|
1887
|
+
502: { description: "GitHub unavailable or refused", ...jsonError },
|
|
1888
|
+
503: { description: "GitHub Apps are not configured", ...jsonError },
|
|
1889
|
+
};
|
|
1890
|
+
|
|
1891
|
+
const githubLostAccessPreviewRoute = createRoute({
|
|
1892
|
+
method: "get",
|
|
1893
|
+
path: "/agents/{id}/github-lost-access/preview",
|
|
1894
|
+
summary: "Preview removing the repos the bound user can no longer push to",
|
|
1895
|
+
description:
|
|
1896
|
+
"Platform-admin only (session members, ops keys and agent keys get 403). Read-only: nothing is changed or audited. Lists the repos on the agent App's installation or in the agent's repos that the bound githubUsername can no longer push to, and the agent's open tasks and PRs on them (via the optional open-work port; a port failure is a warning). Orgs whose access listing is missing, partial or failed, or whose lookup App is installed on selected repositories only, are skipped and reported. 200 with `status: skipped` when the user is unbound, not found or unverified, the agent has no GH_APP_ID, or the Apps are not configured.",
|
|
1897
|
+
request: { params: AgentIdParamSchema },
|
|
1898
|
+
responses: {
|
|
1899
|
+
200: {
|
|
1900
|
+
description: "Lost-access removal preview",
|
|
1901
|
+
content: {
|
|
1902
|
+
"application/json": { schema: GithubLostAccessPreviewSchema },
|
|
1903
|
+
},
|
|
1904
|
+
},
|
|
1905
|
+
...lostAccessErrors,
|
|
1906
|
+
},
|
|
1907
|
+
});
|
|
1908
|
+
|
|
1909
|
+
const githubLostAccessRemoveRoute = createRoute({
|
|
1910
|
+
method: "post",
|
|
1911
|
+
path: "/agents/{id}/github-lost-access/remove",
|
|
1912
|
+
summary: "Remove the confirmed repos the bound user can no longer push to",
|
|
1913
|
+
description:
|
|
1914
|
+
"Platform-admin only. Never adds repos. Takes the repos the admin confirmed from the preview, re-checks each against the bound user's current access, and removes only those still without push access: first from the agent App's installation, then from the agent's repos; then writes one audit entry (GitHubReconcileAudit, planHash `lost-access:remove`) and blocks the agent's open work on the removed repos through the optional open-work port (a failure there is a warning). Named repos left alone are reported in `notRemoved`. Same skip rules as the preview: a skipped call (200 `status: skipped`) changes and audits nothing; `noop` when nothing named still lacks access. 422 when more than 10 repos would be removed without `confirmRemovals: true`. 502 when GitHub refuses (a failed audit entry records only what landed).",
|
|
1915
|
+
request: {
|
|
1916
|
+
params: AgentIdParamSchema,
|
|
1917
|
+
body: {
|
|
1918
|
+
required: true,
|
|
1919
|
+
content: {
|
|
1920
|
+
"application/json": { schema: GithubLostAccessRemoveBodySchema },
|
|
1921
|
+
},
|
|
1922
|
+
},
|
|
1923
|
+
},
|
|
1924
|
+
responses: {
|
|
1925
|
+
200: {
|
|
1926
|
+
description: "Removal result",
|
|
1927
|
+
content: {
|
|
1928
|
+
"application/json": { schema: GithubLostAccessRemoveResultSchema },
|
|
1929
|
+
},
|
|
1930
|
+
},
|
|
1931
|
+
...lostAccessErrors,
|
|
1932
|
+
422: { description: "Removal cap needs confirmRemovals", ...jsonError },
|
|
1933
|
+
},
|
|
1934
|
+
});
|
|
1935
|
+
|
|
1763
1936
|
/** `from`/`to` ISO datetime bounds shared by the cron-run report routes. */
|
|
1764
1937
|
export const cronRunStatsQuerySchema = z
|
|
1765
1938
|
.object({
|
|
@@ -2233,6 +2406,12 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
|
|
|
2233
2406
|
if (collision) {
|
|
2234
2407
|
throw new BadRequestError(collision);
|
|
2235
2408
|
}
|
|
2409
|
+
const droppedRepos =
|
|
2410
|
+
body.repos !== undefined
|
|
2411
|
+
? ((await agentService.getDetail(agentId))?.repos ?? []).filter(
|
|
2412
|
+
(r) => !body.repos?.includes(r),
|
|
2413
|
+
)
|
|
2414
|
+
: [];
|
|
2236
2415
|
const agent = await agentService
|
|
2237
2416
|
.updateSelfHosted(agentId, {
|
|
2238
2417
|
selfHosted: body.selfHosted,
|
|
@@ -2339,8 +2518,19 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
|
|
|
2339
2518
|
);
|
|
2340
2519
|
}
|
|
2341
2520
|
}
|
|
2521
|
+
const blockWarnings = await blockRepoRemovalWork(
|
|
2522
|
+
deps.openWork,
|
|
2523
|
+
agentId,
|
|
2524
|
+
droppedRepos,
|
|
2525
|
+
);
|
|
2342
2526
|
const warning =
|
|
2343
|
-
[
|
|
2527
|
+
[
|
|
2528
|
+
slackWarning,
|
|
2529
|
+
reconcileWarning,
|
|
2530
|
+
specialtyWarning,
|
|
2531
|
+
podSaWarning,
|
|
2532
|
+
...blockWarnings,
|
|
2533
|
+
]
|
|
2344
2534
|
.filter(Boolean)
|
|
2345
2535
|
.join("; ") || undefined;
|
|
2346
2536
|
return c.json(serializeAgent(agent, warning), 200);
|
|
@@ -2392,7 +2582,32 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
|
|
|
2392
2582
|
selfHosted: current.selfHosted,
|
|
2393
2583
|
repos: current.repos.filter((r) => r !== repo),
|
|
2394
2584
|
});
|
|
2395
|
-
|
|
2585
|
+
const warning =
|
|
2586
|
+
(await blockRepoRemovalWork(deps.openWork, agentId, [repo])).join("; ") ||
|
|
2587
|
+
undefined;
|
|
2588
|
+
return c.json(serializeAgent(agent, warning), 200);
|
|
2589
|
+
});
|
|
2590
|
+
|
|
2591
|
+
// GET /agents/:id/repos/:owner/:name/removal-preview — read-only.
|
|
2592
|
+
app.openapi(repoRemovalPreviewRoute, async (c) => {
|
|
2593
|
+
if (!isAdminOrSessionMember(c)) {
|
|
2594
|
+
throw new ForbiddenError("Admin access required to preview repo removal");
|
|
2595
|
+
}
|
|
2596
|
+
const { id: agentId, owner, name } = c.req.valid("param");
|
|
2597
|
+
const current = await agentService.getDetail(agentId);
|
|
2598
|
+
if (!current) {
|
|
2599
|
+
throw new NotFoundError(`agent ${agentId} not found`);
|
|
2600
|
+
}
|
|
2601
|
+
const repo = `${owner}/${name}`;
|
|
2602
|
+
if (!current.repos.includes(repo)) {
|
|
2603
|
+
throw new NotFoundError(`agent ${agentId} does not have repo ${repo}`);
|
|
2604
|
+
}
|
|
2605
|
+
const { openWork, warnings } = await previewRepoRemovalWork(
|
|
2606
|
+
deps.openWork,
|
|
2607
|
+
agentId,
|
|
2608
|
+
[repo],
|
|
2609
|
+
);
|
|
2610
|
+
return c.json({ repo, openWork, warnings }, 200);
|
|
2396
2611
|
});
|
|
2397
2612
|
|
|
2398
2613
|
// DELETE /agents/:id — delete an agent and tear down its workload (admin only)
|
|
@@ -3431,6 +3646,102 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
|
|
|
3431
3646
|
),
|
|
3432
3647
|
);
|
|
3433
3648
|
|
|
3649
|
+
// /agents/:id/github-lost-access/{preview,remove} — IRM-1.3. Platform admin
|
|
3650
|
+
// only; responses carry repo names and ids, never tokens.
|
|
3651
|
+
const lostAccessService = (c: { get(k: "isAdmin"): boolean | undefined }) => {
|
|
3652
|
+
if (c.get("isAdmin") !== true) {
|
|
3653
|
+
throw new ForbiddenError(
|
|
3654
|
+
"Admin access required to remove repos the bound user lost access to",
|
|
3655
|
+
);
|
|
3656
|
+
}
|
|
3657
|
+
const svc = deps.githubLostAccessRemoval;
|
|
3658
|
+
if (!svc) throw new ApiError(503, GITHUB_RECONCILE_UNCONFIGURED);
|
|
3659
|
+
return svc;
|
|
3660
|
+
};
|
|
3661
|
+
|
|
3662
|
+
app.openapi(githubLostAccessPreviewRoute, async (c) => {
|
|
3663
|
+
const svc = lostAccessService(c);
|
|
3664
|
+
const { id: agentId } = c.req.valid("param");
|
|
3665
|
+
const result = await svc.preview(agentId);
|
|
3666
|
+
if (result.status === "agent_not_found") {
|
|
3667
|
+
throw new NotFoundError(`agent ${agentId} not found`);
|
|
3668
|
+
}
|
|
3669
|
+
if (result.status === "skipped") {
|
|
3670
|
+
return c.json({ status: "skipped" as const, reason: result.reason }, 200);
|
|
3671
|
+
}
|
|
3672
|
+
const { plan } = result;
|
|
3673
|
+
return c.json(
|
|
3674
|
+
{
|
|
3675
|
+
status: "previewed" as const,
|
|
3676
|
+
repos: plan.repos,
|
|
3677
|
+
installationRemoves: plan.installationRemoves,
|
|
3678
|
+
configRemoves: plan.configRemoves,
|
|
3679
|
+
skippedOrgs: plan.skippedOrgs,
|
|
3680
|
+
openWork: result.openWork,
|
|
3681
|
+
warnings: result.warnings,
|
|
3682
|
+
},
|
|
3683
|
+
200,
|
|
3684
|
+
);
|
|
3685
|
+
});
|
|
3686
|
+
|
|
3687
|
+
app.openapi(githubLostAccessRemoveRoute, async (c) => {
|
|
3688
|
+
const svc = lostAccessService(c);
|
|
3689
|
+
const { id: agentId } = c.req.valid("param");
|
|
3690
|
+
const body = c.req.valid("json");
|
|
3691
|
+
const caller = c.get("caller")?.name ?? "anonymous";
|
|
3692
|
+
const result = await svc.remove({
|
|
3693
|
+
agentId,
|
|
3694
|
+
caller,
|
|
3695
|
+
repos: body.repos,
|
|
3696
|
+
confirmRemovals: body.confirmRemovals,
|
|
3697
|
+
});
|
|
3698
|
+
switch (result.status) {
|
|
3699
|
+
case "agent_not_found":
|
|
3700
|
+
throw new NotFoundError(`agent ${agentId} not found`);
|
|
3701
|
+
case "skipped":
|
|
3702
|
+
return c.json(
|
|
3703
|
+
{ status: "skipped" as const, reason: result.reason },
|
|
3704
|
+
200,
|
|
3705
|
+
);
|
|
3706
|
+
case "removal_cap":
|
|
3707
|
+
throw new UnprocessableEntityError(
|
|
3708
|
+
`${result.removals} repos would be removed; resend with confirmRemovals: true to apply`,
|
|
3709
|
+
);
|
|
3710
|
+
case "failed":
|
|
3711
|
+
console.log(
|
|
3712
|
+
`[agents-api] github lost-access removal failed: agent=${agentId} audit=${result.auditId} caller=${caller}`,
|
|
3713
|
+
);
|
|
3714
|
+
throw new BadGatewayError(
|
|
3715
|
+
`GitHub refused the removal; audit ${result.auditId} records the failure: ${result.error}`,
|
|
3716
|
+
);
|
|
3717
|
+
case "noop":
|
|
3718
|
+
case "applied": {
|
|
3719
|
+
const { plan } = result;
|
|
3720
|
+
if (result.status === "applied") {
|
|
3721
|
+
console.log(
|
|
3722
|
+
`[agents-api] github lost-access removal applied: agent=${agentId} audit=${result.auditId} caller=${caller}`,
|
|
3723
|
+
);
|
|
3724
|
+
}
|
|
3725
|
+
return c.json(
|
|
3726
|
+
{
|
|
3727
|
+
status: result.status,
|
|
3728
|
+
...(result.status === "applied" ? { auditId: result.auditId } : {}),
|
|
3729
|
+
repos: plan.repos,
|
|
3730
|
+
installationRemoves: plan.installationRemoves,
|
|
3731
|
+
configRemoves: plan.configRemoves,
|
|
3732
|
+
notRemoved: plan.notRemoved,
|
|
3733
|
+
skippedOrgs: plan.skippedOrgs,
|
|
3734
|
+
warnings:
|
|
3735
|
+
result.status === "applied"
|
|
3736
|
+
? [...plan.warnings, ...result.warnings]
|
|
3737
|
+
: plan.warnings,
|
|
3738
|
+
},
|
|
3739
|
+
200,
|
|
3740
|
+
);
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
});
|
|
3744
|
+
|
|
3434
3745
|
// GET /agents/:id/github-installations — latest snapshot, 404 if none yet
|
|
3435
3746
|
app.openapi(getGitHubInstallationsRoute, async (c) => {
|
|
3436
3747
|
const { id: agentId } = c.req.valid("param");
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
InstallationReposService,
|
|
26
26
|
type InstallationReposPort,
|
|
27
27
|
} from "./installation-repos-service.ts";
|
|
28
|
+
import { LostAccessRemovalService } from "./lost-access-removal.ts";
|
|
28
29
|
import type { OpenWorkPort } from "./reconcile-open-work.ts";
|
|
29
30
|
|
|
30
31
|
export interface GithubReconcileWiringDeps {
|
|
@@ -120,3 +121,24 @@ export function createGithubInstallationRepos(
|
|
|
120
121
|
audit: new PrismaReconcileAudit(deps.prisma),
|
|
121
122
|
});
|
|
122
123
|
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* The `githubLostAccessRemoval` dep for createAdminApp (IRM-1.3): removes the
|
|
127
|
+
* repos the bound user can no longer push to from the agent App's
|
|
128
|
+
* installation and the agent's repos, blocking open work through the
|
|
129
|
+
* optional host OpenWorkPort.
|
|
130
|
+
*/
|
|
131
|
+
export function createGithubLostAccessRemoval(
|
|
132
|
+
deps: InstallationReposWiringDeps,
|
|
133
|
+
): LostAccessRemovalService {
|
|
134
|
+
const client = lazyInstallerClient(deps);
|
|
135
|
+
return new LostAccessRemovalService({
|
|
136
|
+
agents: new PrismaReconcileAgents(deps.prisma, deps.agentEnv),
|
|
137
|
+
access: deps.access,
|
|
138
|
+
installation:
|
|
139
|
+
deps.installationRepos ??
|
|
140
|
+
createInstallationReposPort(createInstallationPort(client), client),
|
|
141
|
+
audit: new PrismaReconcileAudit(deps.prisma),
|
|
142
|
+
...(deps.openWork ? { openWork: deps.openWork } : {}),
|
|
143
|
+
});
|
|
144
|
+
}
|