@app-vitals/agent-admin 1.18.0 → 1.20.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.json CHANGED
@@ -2794,6 +2794,120 @@
2794
2794
  ],
2795
2795
  "additionalProperties": false
2796
2796
  },
2797
+ "GithubAccessPreview": {
2798
+ "type": "object",
2799
+ "properties": {
2800
+ "status": {
2801
+ "type": "string",
2802
+ "enum": [
2803
+ "ok",
2804
+ "user_not_found",
2805
+ "unconfigured"
2806
+ ],
2807
+ "description": "`unconfigured` when the installer or lookup App is not set (no GitHub call was made)."
2808
+ },
2809
+ "access": {
2810
+ "type": "object",
2811
+ "properties": {
2812
+ "username": {
2813
+ "type": "string"
2814
+ },
2815
+ "outcome": {
2816
+ "type": "string",
2817
+ "enum": [
2818
+ "ok",
2819
+ "user_not_found"
2820
+ ]
2821
+ },
2822
+ "userVerified": {
2823
+ "type": "boolean"
2824
+ },
2825
+ "orgs": {
2826
+ "type": "array",
2827
+ "items": {
2828
+ "type": "object",
2829
+ "properties": {
2830
+ "org": {
2831
+ "type": "string"
2832
+ },
2833
+ "status": {
2834
+ "type": "string",
2835
+ "enum": [
2836
+ "ok",
2837
+ "lookup_app_not_installed",
2838
+ "rate_limited",
2839
+ "partial",
2840
+ "error"
2841
+ ]
2842
+ },
2843
+ "repos": {
2844
+ "type": "array",
2845
+ "items": {
2846
+ "type": "object",
2847
+ "properties": {
2848
+ "fullName": {
2849
+ "type": "string"
2850
+ },
2851
+ "level": {
2852
+ "type": "string",
2853
+ "enum": [
2854
+ "admin",
2855
+ "maintain",
2856
+ "write",
2857
+ "triage",
2858
+ "read",
2859
+ "none"
2860
+ ]
2861
+ },
2862
+ "canPush": {
2863
+ "type": "boolean"
2864
+ }
2865
+ },
2866
+ "required": [
2867
+ "fullName",
2868
+ "level",
2869
+ "canPush"
2870
+ ]
2871
+ }
2872
+ },
2873
+ "unresolved": {
2874
+ "type": "integer"
2875
+ }
2876
+ },
2877
+ "required": [
2878
+ "org",
2879
+ "status",
2880
+ "repos",
2881
+ "unresolved"
2882
+ ]
2883
+ }
2884
+ },
2885
+ "unresolved": {
2886
+ "type": "integer"
2887
+ },
2888
+ "complete": {
2889
+ "type": "boolean"
2890
+ },
2891
+ "checkedAt": {
2892
+ "type": "string"
2893
+ }
2894
+ },
2895
+ "required": [
2896
+ "username",
2897
+ "outcome",
2898
+ "userVerified",
2899
+ "orgs",
2900
+ "unresolved",
2901
+ "complete",
2902
+ "checkedAt"
2903
+ ],
2904
+ "description": "Resolver output; absent when unconfigured."
2905
+ }
2906
+ },
2907
+ "required": [
2908
+ "status"
2909
+ ]
2910
+ },
2797
2911
  "AgentConfigResponse": {
2798
2912
  "type": "object",
2799
2913
  "properties": {
@@ -6222,6 +6336,85 @@
6222
6336
  }
6223
6337
  }
6224
6338
  },
6339
+ "/agents/{id}/github-access": {
6340
+ "get": {
6341
+ "summary": "Preview the repos the agent's bound GitHub user can reach",
6342
+ "description": "Platform-admin only (session members, ops keys and agent keys get 403): the response lists repo names the bound user can reach. Read-only; nothing is stored. 404 for an unknown agent; 422 when no githubUsername is bound. Returns `status: unconfigured` (not an error, no GitHub call) when the enterprise Apps are not configured, and `status: user_not_found` when the user does not exist on GitHub; otherwise `access` is the resolver output (per-org status, repos with level and canPush, unresolved count, complete flag).",
6343
+ "parameters": [
6344
+ {
6345
+ "schema": {
6346
+ "type": "string",
6347
+ "example": "clx1234567890"
6348
+ },
6349
+ "required": true,
6350
+ "name": "id",
6351
+ "in": "path"
6352
+ }
6353
+ ],
6354
+ "responses": {
6355
+ "200": {
6356
+ "description": "Access preview",
6357
+ "content": {
6358
+ "application/json": {
6359
+ "schema": {
6360
+ "$ref": "#/components/schemas/GithubAccessPreview"
6361
+ }
6362
+ }
6363
+ }
6364
+ },
6365
+ "401": {
6366
+ "description": "Unauthorized",
6367
+ "content": {
6368
+ "application/json": {
6369
+ "schema": {
6370
+ "$ref": "#/components/schemas/Error"
6371
+ }
6372
+ }
6373
+ }
6374
+ },
6375
+ "403": {
6376
+ "description": "Platform admin required",
6377
+ "content": {
6378
+ "application/json": {
6379
+ "schema": {
6380
+ "$ref": "#/components/schemas/Error"
6381
+ }
6382
+ }
6383
+ }
6384
+ },
6385
+ "404": {
6386
+ "description": "Agent not found",
6387
+ "content": {
6388
+ "application/json": {
6389
+ "schema": {
6390
+ "$ref": "#/components/schemas/Error"
6391
+ }
6392
+ }
6393
+ }
6394
+ },
6395
+ "422": {
6396
+ "description": "Agent has no githubUsername",
6397
+ "content": {
6398
+ "application/json": {
6399
+ "schema": {
6400
+ "$ref": "#/components/schemas/Error"
6401
+ }
6402
+ }
6403
+ }
6404
+ },
6405
+ "502": {
6406
+ "description": "GitHub unavailable or refused",
6407
+ "content": {
6408
+ "application/json": {
6409
+ "schema": {
6410
+ "$ref": "#/components/schemas/Error"
6411
+ }
6412
+ }
6413
+ }
6414
+ }
6415
+ }
6416
+ }
6417
+ },
6225
6418
  "/agents/{id}/config": {
6226
6419
  "get": {
6227
6420
  "tags": [
@@ -3146,6 +3146,120 @@
3146
3146
  ],
3147
3147
  "additionalProperties": false
3148
3148
  },
3149
+ "GithubAccessPreview": {
3150
+ "type": "object",
3151
+ "properties": {
3152
+ "status": {
3153
+ "type": "string",
3154
+ "enum": [
3155
+ "ok",
3156
+ "user_not_found",
3157
+ "unconfigured"
3158
+ ],
3159
+ "description": "`unconfigured` when the installer or lookup App is not set (no GitHub call was made)."
3160
+ },
3161
+ "access": {
3162
+ "type": "object",
3163
+ "properties": {
3164
+ "username": {
3165
+ "type": "string"
3166
+ },
3167
+ "outcome": {
3168
+ "type": "string",
3169
+ "enum": [
3170
+ "ok",
3171
+ "user_not_found"
3172
+ ]
3173
+ },
3174
+ "userVerified": {
3175
+ "type": "boolean"
3176
+ },
3177
+ "orgs": {
3178
+ "type": "array",
3179
+ "items": {
3180
+ "type": "object",
3181
+ "properties": {
3182
+ "org": {
3183
+ "type": "string"
3184
+ },
3185
+ "status": {
3186
+ "type": "string",
3187
+ "enum": [
3188
+ "ok",
3189
+ "lookup_app_not_installed",
3190
+ "rate_limited",
3191
+ "partial",
3192
+ "error"
3193
+ ]
3194
+ },
3195
+ "repos": {
3196
+ "type": "array",
3197
+ "items": {
3198
+ "type": "object",
3199
+ "properties": {
3200
+ "fullName": {
3201
+ "type": "string"
3202
+ },
3203
+ "level": {
3204
+ "type": "string",
3205
+ "enum": [
3206
+ "admin",
3207
+ "maintain",
3208
+ "write",
3209
+ "triage",
3210
+ "read",
3211
+ "none"
3212
+ ]
3213
+ },
3214
+ "canPush": {
3215
+ "type": "boolean"
3216
+ }
3217
+ },
3218
+ "required": [
3219
+ "fullName",
3220
+ "level",
3221
+ "canPush"
3222
+ ]
3223
+ }
3224
+ },
3225
+ "unresolved": {
3226
+ "type": "integer"
3227
+ }
3228
+ },
3229
+ "required": [
3230
+ "org",
3231
+ "status",
3232
+ "repos",
3233
+ "unresolved"
3234
+ ]
3235
+ }
3236
+ },
3237
+ "unresolved": {
3238
+ "type": "integer"
3239
+ },
3240
+ "complete": {
3241
+ "type": "boolean"
3242
+ },
3243
+ "checkedAt": {
3244
+ "type": "string"
3245
+ }
3246
+ },
3247
+ "required": [
3248
+ "username",
3249
+ "outcome",
3250
+ "userVerified",
3251
+ "orgs",
3252
+ "unresolved",
3253
+ "complete",
3254
+ "checkedAt"
3255
+ ],
3256
+ "description": "Resolver output; absent when unconfigured."
3257
+ }
3258
+ },
3259
+ "required": [
3260
+ "status"
3261
+ ]
3262
+ },
3149
3263
  "AgentConfigResponse": {
3150
3264
  "type": "object",
3151
3265
  "properties": {
@@ -6686,6 +6800,85 @@
6686
6800
  }
6687
6801
  }
6688
6802
  },
6803
+ "/agents/{id}/github-access": {
6804
+ "get": {
6805
+ "summary": "Preview the repos the agent's bound GitHub user can reach",
6806
+ "description": "Platform-admin only (session members, ops keys and agent keys get 403): the response lists repo names the bound user can reach. Read-only; nothing is stored. 404 for an unknown agent; 422 when no githubUsername is bound. Returns `status: unconfigured` (not an error, no GitHub call) when the enterprise Apps are not configured, and `status: user_not_found` when the user does not exist on GitHub; otherwise `access` is the resolver output (per-org status, repos with level and canPush, unresolved count, complete flag).",
6807
+ "parameters": [
6808
+ {
6809
+ "schema": {
6810
+ "type": "string",
6811
+ "example": "clx1234567890"
6812
+ },
6813
+ "required": true,
6814
+ "name": "id",
6815
+ "in": "path"
6816
+ }
6817
+ ],
6818
+ "responses": {
6819
+ "200": {
6820
+ "description": "Access preview",
6821
+ "content": {
6822
+ "application/json": {
6823
+ "schema": {
6824
+ "$ref": "#/components/schemas/GithubAccessPreview"
6825
+ }
6826
+ }
6827
+ }
6828
+ },
6829
+ "401": {
6830
+ "description": "Unauthorized",
6831
+ "content": {
6832
+ "application/json": {
6833
+ "schema": {
6834
+ "$ref": "#/components/schemas/Error"
6835
+ }
6836
+ }
6837
+ }
6838
+ },
6839
+ "403": {
6840
+ "description": "Platform admin required",
6841
+ "content": {
6842
+ "application/json": {
6843
+ "schema": {
6844
+ "$ref": "#/components/schemas/Error"
6845
+ }
6846
+ }
6847
+ }
6848
+ },
6849
+ "404": {
6850
+ "description": "Agent not found",
6851
+ "content": {
6852
+ "application/json": {
6853
+ "schema": {
6854
+ "$ref": "#/components/schemas/Error"
6855
+ }
6856
+ }
6857
+ }
6858
+ },
6859
+ "422": {
6860
+ "description": "Agent has no githubUsername",
6861
+ "content": {
6862
+ "application/json": {
6863
+ "schema": {
6864
+ "$ref": "#/components/schemas/Error"
6865
+ }
6866
+ }
6867
+ }
6868
+ },
6869
+ "502": {
6870
+ "description": "GitHub unavailable or refused",
6871
+ "content": {
6872
+ "application/json": {
6873
+ "schema": {
6874
+ "$ref": "#/components/schemas/Error"
6875
+ }
6876
+ }
6877
+ }
6878
+ }
6879
+ }
6880
+ }
6881
+ },
6689
6882
  "/agents/{id}/config": {
6690
6883
  "get": {
6691
6884
  "tags": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.18.0",
3
+ "version": "1.20.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@anthropic-ai/sdk": "0.135.0",
45
- "@app-vitals/agent-lib": "1.18.0",
45
+ "@app-vitals/agent-lib": "1.20.0",
46
46
  "@hono/zod-openapi": "^1.0.0",
47
47
  "@prisma/adapter-pg": "^7.10.0",
48
48
  "@prisma/client": "^7.10.0",
package/src/admin-boot.ts CHANGED
@@ -99,7 +99,10 @@ import { CronRunNowService } from "./cron-run-now.ts";
99
99
  import { parseCronRunNowConfig } from "./cron-run-now-config.ts";
100
100
  import { CronRunTranscriptService } from "./cron-run-transcripts.ts";
101
101
  import { isDevAuthAllowed } from "./dev-auth-guard.ts";
102
- import { createGithubEnterpriseApp } from "./github-enterprise-api.ts";
102
+ import {
103
+ createGithubAccessPreview,
104
+ createGithubEnterpriseApp,
105
+ } from "./github-enterprise-api.ts";
103
106
  import { GitHubEnterpriseAppService } from "./github-enterprise-apps.ts";
104
107
  import { HttpGithubAppProvisioningClient } from "./github-app-provisioning-client.ts";
105
108
  import { HttpGoogleAuthClient } from "./google-auth-client.ts";
@@ -457,7 +460,16 @@ export async function startAdmin(
457
460
  // 3. Admin CRUD API — /agents/:id/* — admin key | per-agent bearer | session JWT
458
461
  // Routes are now at /agents/:id/* (same prefix as runtime, different sub-paths).
459
462
  // MUST be mounted before admin-ui (/admin/*) to avoid shadowing.
463
+ // Built before the admin API: GHE-2.4's access preview reads the same Apps.
464
+ // Strict crypto: no plain-text key storage.
465
+ const githubEnterpriseAppService = new GitHubEnterpriseAppService(
466
+ prisma,
467
+ makeStrictTokenCrypto(),
468
+ );
460
469
  const adminApiApp = createAdminApp({
470
+ githubAccessPreview: createGithubAccessPreview({
471
+ appService: githubEnterpriseAppService,
472
+ }),
461
473
  agentService,
462
474
  agentEnvService,
463
475
  agentCronJobService,
@@ -536,7 +548,7 @@ export async function startAdmin(
536
548
  // optional (GHE-1.3). With no rows configured it reports unconfigured
537
549
  // and does nothing else. Strict crypto: no plain-text key storage.
538
550
  const githubEnterpriseApp = createGithubEnterpriseApp({
539
- appService: new GitHubEnterpriseAppService(prisma, makeStrictTokenCrypto()),
551
+ appService: githubEnterpriseAppService,
540
552
  agentService,
541
553
  agentEnvService,
542
554
  sessionSecret,
@@ -611,6 +623,7 @@ export async function startAdmin(
611
623
  })(),
612
624
  githubEnterpriseApi: (path, init) =>
613
625
  githubEnterpriseApp.request(path, init),
626
+ agentsApi: (path, init) => adminApiApp.request(path, init),
614
627
  accountServices: {
615
628
  accounts: new AccountService(prisma),
616
629
  members: new AccountMemberService(prisma),
@@ -0,0 +1,163 @@
1
+ /**
2
+ * admin/src/admin-ui-github-identity-pages.ts
3
+ * Pure renderers for the agent detail page's GitHub identity row and access
4
+ * preview (GHE-2.5). Both are platform-admin only and shown only when the
5
+ * enterprise GitHub apps are configured; the caller decides that. Every
6
+ * dynamic value is escaped. The input is the GHE-2.4 preview, which carries
7
+ * repo names and levels only (no token or key ever reaches this module).
8
+ */
9
+
10
+ import { escapeHtml } from "./admin-ui-styles.ts";
11
+
12
+ export interface GithubAccessRepo {
13
+ fullName: string;
14
+ level: string;
15
+ canPush: boolean;
16
+ }
17
+
18
+ export type GithubAccessOrgStatus =
19
+ | "ok"
20
+ | "lookup_app_not_installed"
21
+ | "rate_limited"
22
+ | "partial"
23
+ | "error";
24
+
25
+ export interface GithubAccessOrg {
26
+ org: string;
27
+ status: GithubAccessOrgStatus;
28
+ repos: GithubAccessRepo[];
29
+ unresolved: number;
30
+ }
31
+
32
+ /** JSON body of GET /agents/:id/github-access. */
33
+ export interface GithubAccessPreviewView {
34
+ status: "ok" | "user_not_found" | "unconfigured";
35
+ access?: {
36
+ username: string;
37
+ outcome: "ok" | "user_not_found";
38
+ userVerified: boolean;
39
+ orgs: GithubAccessOrg[];
40
+ unresolved: number;
41
+ complete: boolean;
42
+ checkedAt: string;
43
+ };
44
+ }
45
+
46
+ const STATUS_BADGES: Record<GithubAccessOrgStatus, [string, string]> = {
47
+ ok: ["badge-green", "ok"],
48
+ lookup_app_not_installed: ["badge-gray", "lookup app not installed"],
49
+ rate_limited: ["badge-warning", "rate-limited"],
50
+ partial: ["badge-warning", "partial"],
51
+ error: ["badge-warning", "error"],
52
+ };
53
+
54
+ function statusBadge(status: string): string {
55
+ const [cls, label] = STATUS_BADGES[status as GithubAccessOrgStatus] ?? [
56
+ "badge-warning",
57
+ status,
58
+ ];
59
+ return `<span class="badge ${cls}">${escapeHtml(label)}</span>`;
60
+ }
61
+
62
+ /** The GitHub username `<tr>` for the "Owner & identities" card. */
63
+ export function renderGithubUsernameRow(
64
+ agentId: string,
65
+ username: string | null | undefined,
66
+ ): string {
67
+ const action = `/admin/agents/${escapeHtml(agentId)}/github-username`;
68
+ const clear = username
69
+ ? `<form method="POST" action="${action}" style="display:inline">
70
+ <input type="hidden" name="githubUsername" value="" />
71
+ <button type="submit" class="btn btn-danger" id="clear-github-username">Clear</button>
72
+ </form>`
73
+ : "";
74
+ return `<tr><td style="color:#6b7280;width:200px">GitHub username</td><td>
75
+ <div style="display:flex;gap:8px;flex-wrap:wrap;align-items:center">
76
+ <form method="POST" action="${action}" id="github-username-form" style="display:flex;gap:8px;align-items:center">
77
+ <input name="githubUsername" type="text" class="form-input mono" maxlength="39" placeholder="GitHub login" value="${escapeHtml(username ?? "")}" required />
78
+ <button type="submit" class="btn btn-primary">Save</button>
79
+ </form>
80
+ ${clear}
81
+ </div>
82
+ </td></tr>`;
83
+ }
84
+
85
+ /** The "Preview access" card; the button loads the fragment from the UI route. */
86
+ export function renderGithubAccessCard(agentId: string): string {
87
+ const url = `/admin/agents/${escapeHtml(agentId)}/github-access`;
88
+ return `<div class="card" id="github-access-card">
89
+ <div class="card-title">Preview access</div>
90
+ <p style="color:#6b7280;font-size:12px;margin:0 0 12px">Shows the repos this agent's GitHub user can reach. Read-only; nothing is stored.</p>
91
+ <button type="button" class="btn btn-primary" id="github-access-btn" data-url="${url}">Preview access</button>
92
+ <div id="github-access-result" style="margin-top:12px"></div>
93
+ <script>
94
+ (function() {
95
+ var btn = document.getElementById('github-access-btn');
96
+ var out = document.getElementById('github-access-result');
97
+ if (!btn || !out) return;
98
+ btn.addEventListener('click', function() {
99
+ btn.disabled = true;
100
+ out.textContent = 'Loading...';
101
+ fetch(btn.getAttribute('data-url'), { credentials: 'same-origin' })
102
+ .then(function(r) { return r.text(); })
103
+ .then(function(t) { out.innerHTML = t; })
104
+ .catch(function() { out.textContent = 'The request failed.'; })
105
+ .then(function() { btn.disabled = false; });
106
+ });
107
+ })();
108
+ </script>
109
+ </div>`;
110
+ }
111
+
112
+ /** Fragment rendered into the preview card; also the body of the UI route. */
113
+ export function renderGithubAccessResult(
114
+ preview: GithubAccessPreviewView,
115
+ ): string {
116
+ if (preview.status === "unconfigured") {
117
+ return `<div class="alert alert-warning">The enterprise GitHub apps are not configured.</div>`;
118
+ }
119
+ const access = preview.access;
120
+ if (
121
+ preview.status === "user_not_found" ||
122
+ access?.outcome === "user_not_found"
123
+ ) {
124
+ const who = access?.username ? ` "${escapeHtml(access.username)}"` : "";
125
+ return `<div class="alert alert-warning">GitHub user${who} was not found.</div>`;
126
+ }
127
+ if (!access) return renderGithubAccessError("No preview was returned.");
128
+
129
+ const orgs = access.orgs;
130
+ const warn =
131
+ !access.complete || orgs.some((o) => o.status !== "ok")
132
+ ? `<div class="alert alert-warning">Partial results: some organizations or repos could not be checked${access.unresolved > 0 ? ` (${access.unresolved} unresolved)` : ""}. Repos that are not listed are unknown, not necessarily inaccessible.</div>`
133
+ : "";
134
+ if (orgs.length === 0) {
135
+ return `${warn}<p class="empty-state">No organizations to check.</p>`;
136
+ }
137
+ const groups = orgs
138
+ .map((o) => {
139
+ const rows =
140
+ o.repos.length === 0
141
+ ? `<tr><td colspan="3" class="empty-state">No repos.</td></tr>`
142
+ : o.repos
143
+ .map(
144
+ (r) =>
145
+ `<tr><td class="mono">${escapeHtml(r.fullName)}</td><td>${escapeHtml(r.level)}</td><td>${r.canPush ? '<span class="badge badge-green" title="Can push">push</span>' : ""}</td></tr>`,
146
+ )
147
+ .join("");
148
+ const unresolved =
149
+ o.unresolved > 0
150
+ ? ` <span style="color:#6b7280;font-size:12px">${o.unresolved} unresolved</span>`
151
+ : "";
152
+ return `<div class="github-access-org" style="margin-bottom:16px">
153
+ <div style="font-weight:600;margin-bottom:6px">${escapeHtml(o.org)} ${statusBadge(o.status)}${unresolved}</div>
154
+ <table class="detail-table"><thead><tr><th>Repo</th><th>Level</th><th>Push</th></tr></thead><tbody>${rows}</tbody></table>
155
+ </div>`;
156
+ })
157
+ .join("");
158
+ return `${warn}${groups}`;
159
+ }
160
+
161
+ export function renderGithubAccessError(message: string): string {
162
+ return `<div class="alert alert-error">${escapeHtml(message)}</div>`;
163
+ }