@app-vitals/agent-admin 1.35.1 → 1.36.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/openapi.platform.json +55 -295
- package/package.json +2 -2
- package/src/admin-boot.ts +3 -3
- package/src/admin-extension.ts +1 -1
- package/src/admin-ui-github-identity.smoke.test.ts +24 -2
- package/src/admin-ui-installation-repos-pages.ts +198 -231
- package/src/admin-ui-installation-repos-pages.unit.test.ts +199 -0
- package/src/admin-ui-installation-repos.smoke.test.ts +166 -172
- package/src/admin-ui-pages.ts +2 -2
- package/src/admin-ui.ts +103 -89
- package/src/agents-api.smoke.test.ts +193 -290
- package/src/agents-api.ts +83 -210
- package/src/fixtures/enterprise-org-installations.json +26 -0
- package/src/github-enterprise-api.ts +1 -3
- package/src/github-enterprise-client.ts +9 -4
- package/src/github-installation-wiring.ts +10 -12
- package/src/github-installation-wiring.unit.test.ts +13 -9
- package/src/github-installation.fixtures.ts +1 -1
- package/src/github-sync.ts +414 -0
- package/src/{lost-access-removal.unit.test.ts → github-sync.unit.test.ts} +214 -109
- package/src/installation-ports-fixture.integration.test.ts +78 -0
- package/src/installation-ports.ts +84 -13
- package/src/installation-ports.unit.test.ts +66 -14
- package/src/installation-repos-service.ts +25 -102
- package/src/installation-repos-service.unit.test.ts +5 -90
- package/src/reconcile-open-work.ts +1 -1
- package/src/repo-access-rules.ts +1 -1
- package/src/lost-access-removal.ts +0 -333
package/src/admin-ui-pages.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
renderGithubUsernameRow,
|
|
18
18
|
} from "./admin-ui-github-identity-pages.ts";
|
|
19
19
|
import {
|
|
20
|
-
|
|
20
|
+
renderGithubSyncCard,
|
|
21
21
|
renderUncoveredBadge,
|
|
22
22
|
uncoveredRepos,
|
|
23
23
|
} from "./admin-ui-installation-repos-pages.ts";
|
|
@@ -1855,7 +1855,7 @@ export function renderAgentDetailPage(
|
|
|
1855
1855
|
${identityRow("Federation rule ID", agent.anthropicFederationRuleId, true)}
|
|
1856
1856
|
${showGithubIdentity ? renderGithubUsernameRow(agent.id, agent.githubUsername) : ""}
|
|
1857
1857
|
</tbody></table>
|
|
1858
|
-
</div>${showGithubIdentity ? renderGithubAccessCard(agent.id) : ""}${showGithubIdentity
|
|
1858
|
+
</div>${showGithubIdentity ? renderGithubAccessCard(agent.id) : ""}${showGithubIdentity ? renderGithubSyncCard(agent.id, { hasAppId: "GH_APP_ID" in envVars, githubUsername: agent.githubUsername }) : ""}`;
|
|
1859
1859
|
|
|
1860
1860
|
// Only agents with a GitHub App can make API-signed commits. Checked state
|
|
1861
1861
|
// is the SHIPWRIGHT_SIGNED_COMMITS env row; when the box is hidden the field
|
package/src/admin-ui.ts
CHANGED
|
@@ -59,16 +59,15 @@ import {
|
|
|
59
59
|
} from "./admin-ui-github-identity-pages.ts";
|
|
60
60
|
import {
|
|
61
61
|
actuallyBlockedWork,
|
|
62
|
+
type GithubSyncApplyView,
|
|
63
|
+
type GithubSyncPreviewView,
|
|
62
64
|
type InstallationReposView,
|
|
63
|
-
type LostAccessPreviewView,
|
|
64
|
-
type LostAccessRemoveView,
|
|
65
65
|
type OpenWorkView,
|
|
66
66
|
type RepoRemovalPreviewView,
|
|
67
|
-
renderInstallationChangeResult,
|
|
68
67
|
renderInstallationReposBody,
|
|
69
68
|
renderInstallationReposError,
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
renderSyncConfirm,
|
|
70
|
+
renderSyncResult,
|
|
72
71
|
renderRepoRemovalConfirm,
|
|
73
72
|
renderRepoRemovalResult,
|
|
74
73
|
} from "./admin-ui-installation-repos-pages.ts";
|
|
@@ -1829,8 +1828,10 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1829
1828
|
}
|
|
1830
1829
|
};
|
|
1831
1830
|
|
|
1832
|
-
// True only for a platform admin when the
|
|
1833
|
-
// configured (GHE-1.3 status) and the agents API
|
|
1831
|
+
// True only for a platform admin when BOTH the installer and the lookup
|
|
1832
|
+
// enterprise GitHub Apps are configured (GHE-1.3 status) and the agents API
|
|
1833
|
+
// seam is wired. One role alone is not enough: the access preview and Sync
|
|
1834
|
+
// both need the pair.
|
|
1834
1835
|
const githubEnterpriseConfigured = async (
|
|
1835
1836
|
c: Context<AdminUIEnv>,
|
|
1836
1837
|
): Promise<boolean> => {
|
|
@@ -1842,8 +1843,15 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1842
1843
|
);
|
|
1843
1844
|
if (!res?.ok) return false;
|
|
1844
1845
|
try {
|
|
1846
|
+
const status = (await res.json()) as {
|
|
1847
|
+
configured?: unknown;
|
|
1848
|
+
installer?: unknown;
|
|
1849
|
+
lookup?: unknown;
|
|
1850
|
+
};
|
|
1845
1851
|
return (
|
|
1846
|
-
|
|
1852
|
+
status.configured === true &&
|
|
1853
|
+
status.installer != null &&
|
|
1854
|
+
status.lookup != null
|
|
1847
1855
|
);
|
|
1848
1856
|
} catch {
|
|
1849
1857
|
return false;
|
|
@@ -1918,8 +1926,8 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1918
1926
|
);
|
|
1919
1927
|
});
|
|
1920
1928
|
|
|
1921
|
-
// IRM-1.4: thin proxies over the installation repos (IRM-1.2) and
|
|
1922
|
-
//
|
|
1929
|
+
// IRM-1.4: thin proxies over the installation repos list (IRM-1.2) and
|
|
1930
|
+
// the repo-removal preview (IRM-1.7).
|
|
1923
1931
|
// They return HTML fragments for the Installation repos card and the agent's
|
|
1924
1932
|
// repos list; the agents API enforces platform-admin too.
|
|
1925
1933
|
const apiErrorFragment = async (res: Response | null, fallback: string) => {
|
|
@@ -1944,14 +1952,6 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1944
1952
|
}
|
|
1945
1953
|
return {} as Record<string, unknown>;
|
|
1946
1954
|
};
|
|
1947
|
-
const stringList = (v: unknown): string[] =>
|
|
1948
|
-
Array.isArray(v) ? v.filter((r): r is string => typeof r === "string") : [];
|
|
1949
|
-
const postJson = (c: Context<AdminUIEnv>, path: string, body: unknown) =>
|
|
1950
|
-
callApi(c, agentsApi as NonNullable<typeof agentsApi>, path, {
|
|
1951
|
-
method: "POST",
|
|
1952
|
-
headers: { "content-type": "application/json" },
|
|
1953
|
-
body: JSON.stringify(body),
|
|
1954
|
-
});
|
|
1955
1955
|
const apiId = (c: Context<AdminUIEnv>) =>
|
|
1956
1956
|
encodeURIComponent(c.req.param("id") ?? "");
|
|
1957
1957
|
|
|
@@ -1959,7 +1959,6 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1959
1959
|
if (!c.var.isAdmin || !agentsApi) {
|
|
1960
1960
|
return new Response("Forbidden", { status: 403 });
|
|
1961
1961
|
}
|
|
1962
|
-
const agentId = c.req.param("id") ?? "";
|
|
1963
1962
|
const res = await callApi(
|
|
1964
1963
|
c,
|
|
1965
1964
|
agentsApi,
|
|
@@ -1968,101 +1967,116 @@ export function createAdminUIApp(deps: AdminUIDeps): Hono<AdminUIEnv> {
|
|
|
1968
1967
|
if (!res?.ok) {
|
|
1969
1968
|
return apiErrorFragment(res, "Could not load the installation repos.");
|
|
1970
1969
|
}
|
|
1971
|
-
const
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
);
|
|
1978
|
-
});
|
|
1979
|
-
|
|
1980
|
-
for (const kind of ["add", "remove"] as const) {
|
|
1981
|
-
app.post(
|
|
1982
|
-
`/admin/agents/:id/github-installation/repos/${kind}`,
|
|
1983
|
-
requireAuth,
|
|
1984
|
-
async (c) => {
|
|
1985
|
-
if (!c.var.isAdmin || !agentsApi) {
|
|
1986
|
-
return new Response("Forbidden", { status: 403 });
|
|
1987
|
-
}
|
|
1988
|
-
const repos = stringList((await readBody(c)).repos);
|
|
1989
|
-
const res = await postJson(
|
|
1990
|
-
c,
|
|
1991
|
-
`/agents/${apiId(c)}/github-installation/repos${kind === "add" ? "" : "/remove"}`,
|
|
1992
|
-
{ repos },
|
|
1993
|
-
);
|
|
1994
|
-
if (!res?.ok) {
|
|
1995
|
-
return apiErrorFragment(res, `Could not ${kind} the repos.`);
|
|
1996
|
-
}
|
|
1997
|
-
return html(
|
|
1998
|
-
renderInstallationChangeResult(
|
|
1999
|
-
kind,
|
|
2000
|
-
(await res.json()) as { auditId?: string; repos?: string[] },
|
|
2001
|
-
),
|
|
2002
|
-
);
|
|
2003
|
-
},
|
|
2004
|
-
);
|
|
2005
|
-
}
|
|
2006
|
-
|
|
2007
|
-
app.get(
|
|
2008
|
-
"/admin/agents/:id/github-lost-access/preview",
|
|
2009
|
-
requireAuth,
|
|
2010
|
-
async (c) => {
|
|
2011
|
-
if (!c.var.isAdmin || !agentsApi) {
|
|
2012
|
-
return new Response("Forbidden", { status: 403 });
|
|
2013
|
-
}
|
|
2014
|
-
const res = await callApi(
|
|
1970
|
+
const view = (await res.json()) as InstallationReposView;
|
|
1971
|
+
// No installation matched the numeric GH_APP_ID. If the agent still has an
|
|
1972
|
+
// installation by slug (the Installations card), the id is probably wrong.
|
|
1973
|
+
let appIdMismatch = false;
|
|
1974
|
+
if (view.orgs.length === 0) {
|
|
1975
|
+
const snap = await callApi(
|
|
2015
1976
|
c,
|
|
2016
1977
|
agentsApi,
|
|
2017
|
-
`/agents/${apiId(c)}/github-
|
|
1978
|
+
`/agents/${apiId(c)}/github-installations`,
|
|
2018
1979
|
);
|
|
2019
|
-
if (
|
|
2020
|
-
|
|
1980
|
+
if (snap?.ok) {
|
|
1981
|
+
try {
|
|
1982
|
+
const j = (await snap.json()) as {
|
|
1983
|
+
snapshot?: { installations?: unknown[] };
|
|
1984
|
+
};
|
|
1985
|
+
appIdMismatch = (j.snapshot?.installations?.length ?? 0) > 0;
|
|
1986
|
+
} catch {
|
|
1987
|
+
// unknown: not reported as a mismatch
|
|
1988
|
+
}
|
|
2021
1989
|
}
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
)
|
|
1990
|
+
}
|
|
1991
|
+
return html(renderInstallationReposBody(view, { appIdMismatch }));
|
|
1992
|
+
});
|
|
1993
|
+
|
|
1994
|
+
// IRM-3.2: the single Sync confirm (over the IRM-3.1 preview) and its apply.
|
|
1995
|
+
app.get("/admin/agents/:id/github-sync/confirm", requireAuth, async (c) => {
|
|
1996
|
+
if (!c.var.isAdmin || !agentsApi) {
|
|
1997
|
+
return new Response("Forbidden", { status: 403 });
|
|
1998
|
+
}
|
|
1999
|
+
const res = await callApi(
|
|
2000
|
+
c,
|
|
2001
|
+
agentsApi,
|
|
2002
|
+
`/agents/${apiId(c)}/github-sync/preview`,
|
|
2003
|
+
);
|
|
2004
|
+
if (!res?.ok) return apiErrorFragment(res, "Could not preview the sync.");
|
|
2005
|
+
return html(
|
|
2006
|
+
renderSyncConfirm(
|
|
2007
|
+
c.req.param("id") ?? "",
|
|
2008
|
+
(await res.json()) as GithubSyncPreviewView,
|
|
2009
|
+
),
|
|
2010
|
+
);
|
|
2011
|
+
});
|
|
2027
2012
|
|
|
2028
2013
|
app.post(
|
|
2029
|
-
"/admin/agents/:id/github-
|
|
2014
|
+
"/admin/agents/:id/github-sync/apply-confirmed",
|
|
2030
2015
|
requireAuth,
|
|
2031
2016
|
async (c) => {
|
|
2032
2017
|
if (!c.var.isAdmin || !agentsApi) {
|
|
2033
2018
|
return new Response("Forbidden", { status: 403 });
|
|
2034
2019
|
}
|
|
2035
2020
|
const body = await readBody(c);
|
|
2036
|
-
const
|
|
2037
|
-
|
|
2038
|
-
|
|
2021
|
+
const list = (v: unknown): string[] | null =>
|
|
2022
|
+
v === undefined
|
|
2023
|
+
? []
|
|
2024
|
+
: Array.isArray(v) &&
|
|
2025
|
+
v.every((r) => typeof r === "string" && isOrgRepo(r))
|
|
2026
|
+
? (v as string[])
|
|
2027
|
+
: null;
|
|
2028
|
+
const appAdds = list(body.appAdds);
|
|
2029
|
+
const appRemoves = list(body.appRemoves);
|
|
2030
|
+
const agentRemoves = list(body.agentRemoves);
|
|
2031
|
+
if (!appAdds || !appRemoves || !agentRemoves) {
|
|
2032
|
+
return html(renderInstallationReposError(400, "Invalid repo list."), {
|
|
2033
|
+
status: 400,
|
|
2034
|
+
});
|
|
2035
|
+
}
|
|
2036
|
+
// The open work seen now, to report what the removals blocked.
|
|
2039
2037
|
let seen: OpenWorkView[] = [];
|
|
2040
2038
|
const pre = await callApi(
|
|
2041
2039
|
c,
|
|
2042
2040
|
agentsApi,
|
|
2043
|
-
`/agents/${apiId(c)}/github-
|
|
2041
|
+
`/agents/${apiId(c)}/github-sync/preview`,
|
|
2044
2042
|
);
|
|
2045
2043
|
if (pre?.ok) {
|
|
2046
2044
|
try {
|
|
2047
|
-
seen = ((await pre.json()) as
|
|
2045
|
+
seen = ((await pre.json()) as GithubSyncPreviewView).openWork ?? [];
|
|
2048
2046
|
} catch {
|
|
2049
2047
|
// no preview: nothing is claimed as blocked
|
|
2050
2048
|
}
|
|
2051
2049
|
}
|
|
2052
|
-
const res = await
|
|
2050
|
+
const res = await callApi(
|
|
2053
2051
|
c,
|
|
2054
|
-
|
|
2055
|
-
{
|
|
2052
|
+
agentsApi,
|
|
2053
|
+
`/agents/${apiId(c)}/github-sync/apply`,
|
|
2054
|
+
{
|
|
2055
|
+
method: "POST",
|
|
2056
|
+
headers: { "content-type": "application/json" },
|
|
2057
|
+
body: JSON.stringify({
|
|
2058
|
+
appAdds,
|
|
2059
|
+
appRemoves,
|
|
2060
|
+
agentRemoves,
|
|
2061
|
+
...(body.confirmRemovals === true ? { confirmRemovals: true } : {}),
|
|
2062
|
+
}),
|
|
2063
|
+
},
|
|
2064
|
+
);
|
|
2065
|
+
if (!res?.ok) return apiErrorFragment(res, "Could not apply the sync.");
|
|
2066
|
+
const result = (await res.json()) as GithubSyncApplyView;
|
|
2067
|
+
const warnings = result.warnings ?? [];
|
|
2068
|
+
return html(
|
|
2069
|
+
renderSyncResult(
|
|
2070
|
+
result,
|
|
2071
|
+
result.status === "applied"
|
|
2072
|
+
? actuallyBlockedWork(
|
|
2073
|
+
seen,
|
|
2074
|
+
[...(result.appRemoves ?? []), ...(result.agentRemoves ?? [])],
|
|
2075
|
+
warnings,
|
|
2076
|
+
)
|
|
2077
|
+
: [],
|
|
2078
|
+
),
|
|
2056
2079
|
);
|
|
2057
|
-
if (!res?.ok) {
|
|
2058
|
-
return apiErrorFragment(res, "Could not remove the repos.");
|
|
2059
|
-
}
|
|
2060
|
-
const result = (await res.json()) as LostAccessRemoveView;
|
|
2061
|
-
const blocked =
|
|
2062
|
-
result.status === "applied"
|
|
2063
|
-
? actuallyBlockedWork(seen, result.repos ?? [], result.warnings ?? [])
|
|
2064
|
-
: [];
|
|
2065
|
-
return html(renderLostAccessResult(result, blocked));
|
|
2066
2080
|
},
|
|
2067
2081
|
);
|
|
2068
2082
|
|