@app-vitals/agent-admin 1.17.0 → 1.19.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.17.0",
3
+ "version": "1.19.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.17.0",
45
+ "@app-vitals/agent-lib": "1.19.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,
@@ -6756,3 +6756,147 @@ describe("admin API — PATCH /agents/:id githubUsername (GHE-2.1)", () => {
6756
6756
  }
6757
6757
  });
6758
6758
  });
6759
+
6760
+ // ─── GHE-2.4: GET /agents/:id/github-access ──────────────────────────────────
6761
+
6762
+ describe("admin API — GET /agents/:id/github-access (GHE-2.4)", () => {
6763
+ const OPS = "gha-ops-token";
6764
+ const READER = "gha-read-token";
6765
+ const AGENT_KEY = "gha-agent-token";
6766
+ const ACCESS = {
6767
+ username: "octocat",
6768
+ outcome: "ok" as const,
6769
+ userVerified: true,
6770
+ orgs: [
6771
+ {
6772
+ org: "acme-eng",
6773
+ status: "ok" as const,
6774
+ repos: [
6775
+ { fullName: "acme-eng/api", level: "write" as const, canPush: true },
6776
+ ],
6777
+ unresolved: 0,
6778
+ },
6779
+ ],
6780
+ unresolved: 0,
6781
+ complete: true,
6782
+ checkedAt: "2026-11-09T12:00:00.000Z",
6783
+ };
6784
+
6785
+ function setup(opts: {
6786
+ githubUsername?: string | null;
6787
+ preview?: AdminDeps["githubAccessPreview"];
6788
+ }) {
6789
+ const base = makeMockDeps();
6790
+ const calls: string[] = [];
6791
+ const deps: AdminDeps = {
6792
+ ...base,
6793
+ adminApiKeys: parseAdminApiKeys(
6794
+ `root:${ADMIN_API_KEY}:*,operator:${OPS}:platform.ops,reader:${READER}:platform.read`,
6795
+ ),
6796
+ agentTokenService: {
6797
+ ...base.agentTokenService,
6798
+ validate: async (t: string) =>
6799
+ t === AGENT_KEY ? { agentId: AGENT_ID } : null,
6800
+ },
6801
+ agentService: {
6802
+ ...base.agentService,
6803
+ getDetail: async (id: string) => {
6804
+ const d = await base.agentService.getDetail(id);
6805
+ return d ? { ...d, githubUsername: opts.githubUsername ?? null } : d;
6806
+ },
6807
+ },
6808
+ githubAccessPreview:
6809
+ opts.preview ??
6810
+ (async (u) => {
6811
+ calls.push(u);
6812
+ return { status: "ok", access: ACCESS };
6813
+ }),
6814
+ };
6815
+ return { app: createAdminApp(deps), calls };
6816
+ }
6817
+
6818
+ const get = (
6819
+ app: ReturnType<typeof createAdminApp>,
6820
+ headers: Record<string, string>,
6821
+ id = AGENT_ID,
6822
+ ) => app.request(`/agents/${id}/github-access`, { headers });
6823
+ const asAdmin = { Authorization: `Bearer ${ADMIN_API_KEY}` };
6824
+
6825
+ it("platform admin gets the resolver output unchanged", async () => {
6826
+ const { app, calls } = setup({ githubUsername: "octocat" });
6827
+ const res = await get(app, asAdmin);
6828
+ expect(res.status).toBe(200);
6829
+ expect(await res.json()).toEqual({ status: "ok", access: ACCESS });
6830
+ expect(calls).toEqual(["octocat"]);
6831
+ });
6832
+
6833
+ it("403 for a session member, ops key, read key and agent key", async () => {
6834
+ const { app, calls } = setup({ githubUsername: "octocat" });
6835
+ const memberApp = createAdminApp({
6836
+ ...makeMockDeps(),
6837
+ callerScopeResolver: async () => ({
6838
+ kind: "scoped",
6839
+ accountId: "acct-a",
6840
+ agentIds: [AGENT_ID],
6841
+ }),
6842
+ });
6843
+ const cookie = await sign(
6844
+ {
6845
+ isAdmin: false,
6846
+ userId: "user-acct",
6847
+ email: "owner@acct-a.example.com",
6848
+ iat: Math.floor(Date.now() / 1000),
6849
+ exp: Math.floor(Date.now() / 1000) + 3600,
6850
+ },
6851
+ SESSION_SECRET,
6852
+ "HS256",
6853
+ );
6854
+ expect(
6855
+ (await get(memberApp, { Cookie: `admin_session=${cookie}` })).status,
6856
+ ).toBe(403);
6857
+ for (const key of [OPS, READER, AGENT_KEY]) {
6858
+ const res = await get(app, { Authorization: `Bearer ${key}` });
6859
+ expect(res.status).toBe(403);
6860
+ }
6861
+ expect(calls).toEqual([]);
6862
+ });
6863
+
6864
+ it("404 for an unknown agent", async () => {
6865
+ const { app, calls } = setup({ githubUsername: "octocat" });
6866
+ expect((await get(app, asAdmin, "no-such-agent")).status).toBe(404);
6867
+ expect(calls).toEqual([]);
6868
+ });
6869
+
6870
+ it("422 with a clear message when no githubUsername is bound", async () => {
6871
+ const { app, calls } = setup({ githubUsername: null });
6872
+ const res = await get(app, asAdmin);
6873
+ expect(res.status).toBe(422);
6874
+ expect(((await res.json()) as { error: string }).error).toContain(
6875
+ "githubUsername",
6876
+ );
6877
+ expect(calls).toEqual([]);
6878
+ });
6879
+
6880
+ it("unconfigured is a 200 status, not an error", async () => {
6881
+ const { app } = setup({
6882
+ githubUsername: "octocat",
6883
+ preview: async () => ({ status: "unconfigured" }),
6884
+ });
6885
+ const res = await get(app, asAdmin);
6886
+ expect(res.status).toBe(200);
6887
+ expect(await res.json()).toEqual({ status: "unconfigured" });
6888
+ });
6889
+
6890
+ it("user_not_found is passed through", async () => {
6891
+ const access = { ...ACCESS, outcome: "user_not_found" as const, orgs: [] };
6892
+ const { app } = setup({
6893
+ githubUsername: "ghost",
6894
+ preview: async () => ({ status: "user_not_found", access }),
6895
+ });
6896
+ const res = await get(app, asAdmin);
6897
+ expect(res.status).toBe(200);
6898
+ expect(((await res.json()) as { status: string }).status).toBe(
6899
+ "user_not_found",
6900
+ );
6901
+ });
6902
+ });