@app-vitals/agent-admin 1.35.0 → 1.36.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.
Files changed (36) hide show
  1. package/openapi.platform.json +136 -766
  2. package/package.json +2 -2
  3. package/src/admin-boot.ts +4 -15
  4. package/src/admin-extension.ts +3 -3
  5. package/src/admin-ui-github-identity.smoke.test.ts +24 -116
  6. package/src/admin-ui-installation-repos-pages.ts +198 -231
  7. package/src/admin-ui-installation-repos-pages.unit.test.ts +199 -0
  8. package/src/admin-ui-installation-repos.smoke.test.ts +166 -173
  9. package/src/admin-ui-pages.ts +2 -2
  10. package/src/admin-ui.ts +103 -171
  11. package/src/agents-api.smoke.test.ts +195 -642
  12. package/src/agents-api.ts +86 -477
  13. package/src/github-enterprise-isolation.unit.test.ts +4 -4
  14. package/src/{github-reconcile-wiring.ts → github-installation-wiring.ts} +24 -46
  15. package/src/github-installation-wiring.unit.test.ts +115 -0
  16. package/src/github-installation.fixtures.ts +76 -0
  17. package/src/github-sync.ts +407 -0
  18. package/src/{lost-access-removal.unit.test.ts → github-sync.unit.test.ts} +220 -115
  19. package/src/installation-ports.integration.test.ts +89 -0
  20. package/src/installation-ports.ts +207 -0
  21. package/src/installation-ports.unit.test.ts +51 -0
  22. package/src/installation-repos-service.ts +10 -105
  23. package/src/installation-repos-service.unit.test.ts +5 -90
  24. package/src/reconcile-open-work.ts +5 -7
  25. package/src/repo-access-rules.ts +58 -0
  26. package/src/repo-access-rules.unit.test.ts +98 -0
  27. package/src/admin-ui-github-reconcile-pages.ts +0 -208
  28. package/src/admin-ui-github-reconcile-pages.unit.test.ts +0 -226
  29. package/src/github-reconcile-routes.integration.test.ts +0 -206
  30. package/src/github-reconcile-wiring.unit.test.ts +0 -170
  31. package/src/lost-access-removal.ts +0 -333
  32. package/src/reconcile-apply-service.integration.test.ts +0 -271
  33. package/src/reconcile-apply-service.ts +0 -439
  34. package/src/reconcile-apply-service.unit.test.ts +0 -279
  35. package/src/reconcile-planner.ts +0 -264
  36. package/src/reconcile-planner.unit.test.ts +0 -274
@@ -3260,238 +3260,6 @@
3260
3260
  "status"
3261
3261
  ]
3262
3262
  },
3263
- "GithubReconcilePlanResult": {
3264
- "type": "object",
3265
- "properties": {
3266
- "status": {
3267
- "type": "string",
3268
- "enum": [
3269
- "planned",
3270
- "skipped"
3271
- ],
3272
- "description": "`skipped` (not an error) when no GitHub username is bound or the Apps are not configured; `reason` says why."
3273
- },
3274
- "reason": {
3275
- "type": "string"
3276
- },
3277
- "planHash": {
3278
- "type": "string"
3279
- },
3280
- "empty": {
3281
- "type": "boolean"
3282
- },
3283
- "diff": {
3284
- "type": "object",
3285
- "properties": {
3286
- "installationAdds": {
3287
- "type": "array",
3288
- "items": {
3289
- "type": "string"
3290
- }
3291
- },
3292
- "installationRemoves": {
3293
- "type": "array",
3294
- "items": {
3295
- "type": "string"
3296
- }
3297
- },
3298
- "configAdds": {
3299
- "type": "array",
3300
- "items": {
3301
- "type": "string"
3302
- }
3303
- },
3304
- "configRemoves": {
3305
- "type": "array",
3306
- "items": {
3307
- "type": "string"
3308
- }
3309
- }
3310
- },
3311
- "required": [
3312
- "installationAdds",
3313
- "installationRemoves",
3314
- "configAdds",
3315
- "configRemoves"
3316
- ]
3317
- },
3318
- "skippedOrgs": {
3319
- "type": "array",
3320
- "items": {
3321
- "type": "object",
3322
- "properties": {
3323
- "org": {
3324
- "type": "string"
3325
- },
3326
- "reason": {
3327
- "type": "string"
3328
- }
3329
- },
3330
- "required": [
3331
- "org",
3332
- "reason"
3333
- ]
3334
- }
3335
- },
3336
- "rejectedAdds": {
3337
- "type": "array",
3338
- "items": {
3339
- "type": "object",
3340
- "properties": {
3341
- "repo": {
3342
- "type": "string"
3343
- },
3344
- "reason": {
3345
- "type": "string"
3346
- }
3347
- },
3348
- "required": [
3349
- "repo",
3350
- "reason"
3351
- ]
3352
- }
3353
- },
3354
- "warnings": {
3355
- "type": "array",
3356
- "items": {
3357
- "type": "string"
3358
- }
3359
- },
3360
- "affectedOpenWork": {
3361
- "type": "array",
3362
- "items": {
3363
- "type": "object",
3364
- "properties": {
3365
- "id": {
3366
- "type": "string"
3367
- },
3368
- "repo": {
3369
- "type": "string"
3370
- },
3371
- "title": {
3372
- "type": "string"
3373
- }
3374
- },
3375
- "required": [
3376
- "id",
3377
- "repo"
3378
- ]
3379
- },
3380
- "description": "Open work the removals would block; empty when no open-work port is wired."
3381
- }
3382
- },
3383
- "required": [
3384
- "status"
3385
- ]
3386
- },
3387
- "GithubReconcilePlanBody": {
3388
- "type": "object",
3389
- "properties": {
3390
- "addRepos": {
3391
- "type": "array",
3392
- "items": {
3393
- "type": "string",
3394
- "pattern": "^[^/\\s]+\\/[^/\\s]+$"
3395
- },
3396
- "description": "Repos (owner/repo) to explicitly add to the agent's config and installation."
3397
- }
3398
- }
3399
- },
3400
- "GithubReconcileApplyResult": {
3401
- "type": "object",
3402
- "properties": {
3403
- "status": {
3404
- "type": "string",
3405
- "enum": [
3406
- "applied",
3407
- "failed",
3408
- "noop",
3409
- "skipped"
3410
- ]
3411
- },
3412
- "reason": {
3413
- "type": "string"
3414
- },
3415
- "auditId": {
3416
- "type": "string"
3417
- },
3418
- "planHash": {
3419
- "type": "string"
3420
- },
3421
- "diff": {
3422
- "type": "object",
3423
- "properties": {
3424
- "installationAdds": {
3425
- "type": "array",
3426
- "items": {
3427
- "type": "string"
3428
- }
3429
- },
3430
- "installationRemoves": {
3431
- "type": "array",
3432
- "items": {
3433
- "type": "string"
3434
- }
3435
- },
3436
- "configAdds": {
3437
- "type": "array",
3438
- "items": {
3439
- "type": "string"
3440
- }
3441
- },
3442
- "configRemoves": {
3443
- "type": "array",
3444
- "items": {
3445
- "type": "string"
3446
- }
3447
- }
3448
- },
3449
- "required": [
3450
- "installationAdds",
3451
- "installationRemoves",
3452
- "configAdds",
3453
- "configRemoves"
3454
- ]
3455
- },
3456
- "warnings": {
3457
- "type": "array",
3458
- "items": {
3459
- "type": "string"
3460
- }
3461
- },
3462
- "error": {
3463
- "type": "string"
3464
- }
3465
- },
3466
- "required": [
3467
- "status"
3468
- ]
3469
- },
3470
- "GithubReconcileApplyBody": {
3471
- "type": "object",
3472
- "properties": {
3473
- "planHash": {
3474
- "type": "string",
3475
- "minLength": 1,
3476
- "description": "planHash of the plan the admin reviewed."
3477
- },
3478
- "addRepos": {
3479
- "type": "array",
3480
- "items": {
3481
- "type": "string",
3482
- "pattern": "^[^/\\s]+\\/[^/\\s]+$"
3483
- },
3484
- "description": "Must match the addRepos used when the plan was made."
3485
- },
3486
- "confirmRemovals": {
3487
- "type": "boolean",
3488
- "description": "Required when the plan removes more than 10 repos."
3489
- }
3490
- },
3491
- "required": [
3492
- "planHash"
3493
- ]
3494
- },
3495
3263
  "GithubInstallationReposList": {
3496
3264
  "type": "object",
3497
3265
  "properties": {
@@ -3537,50 +3305,7 @@
3537
3305
  "orgs"
3538
3306
  ]
3539
3307
  },
3540
- "GithubInstallationReposChange": {
3541
- "type": "object",
3542
- "properties": {
3543
- "status": {
3544
- "type": "string",
3545
- "enum": [
3546
- "applied"
3547
- ]
3548
- },
3549
- "auditId": {
3550
- "type": "string"
3551
- },
3552
- "repos": {
3553
- "type": "array",
3554
- "items": {
3555
- "type": "string"
3556
- }
3557
- }
3558
- },
3559
- "required": [
3560
- "status",
3561
- "auditId",
3562
- "repos"
3563
- ]
3564
- },
3565
- "GithubInstallationReposBody": {
3566
- "type": "object",
3567
- "properties": {
3568
- "repos": {
3569
- "type": "array",
3570
- "items": {
3571
- "type": "string",
3572
- "pattern": "^[^/\\s]+\\/[^/\\s]+$"
3573
- },
3574
- "minItems": 1,
3575
- "maxItems": 100,
3576
- "description": "Repos (owner/repo) to change on the agent App's installation."
3577
- }
3578
- },
3579
- "required": [
3580
- "repos"
3581
- ]
3582
- },
3583
- "GithubLostAccessPreview": {
3308
+ "GithubSyncPreview": {
3584
3309
  "type": "object",
3585
3310
  "properties": {
3586
3311
  "status": {
@@ -3594,24 +3319,26 @@
3594
3319
  "reason": {
3595
3320
  "type": "string"
3596
3321
  },
3597
- "repos": {
3322
+ "appAdds": {
3598
3323
  "type": "array",
3599
3324
  "items": {
3600
3325
  "type": "string"
3601
3326
  },
3602
- "description": "Every repo the bound user can no longer push to that would be removed from the installation or the agent's repos."
3327
+ "description": "Repos the bound user can push to, in orgs the agent App is installed on with a complete access listing, that are not on the installation. No cap."
3603
3328
  },
3604
- "installationRemoves": {
3329
+ "appRemoves": {
3605
3330
  "type": "array",
3606
3331
  "items": {
3607
3332
  "type": "string"
3608
- }
3333
+ },
3334
+ "description": "Installation repos the bound user can no longer push to."
3609
3335
  },
3610
- "configRemoves": {
3336
+ "agentRemoves": {
3611
3337
  "type": "array",
3612
3338
  "items": {
3613
3339
  "type": "string"
3614
- }
3340
+ },
3341
+ "description": "Configured agent repos the bound user can no longer push to. The agent's repos are never added to."
3615
3342
  },
3616
3343
  "skippedOrgs": {
3617
3344
  "type": "array",
@@ -3630,7 +3357,7 @@
3630
3357
  "reason"
3631
3358
  ]
3632
3359
  },
3633
- "description": "Orgs whose access listing is missing, partial or failed, or whose lookup App is installed on selected repositories only; nothing there is removed."
3360
+ "description": "Orgs whose access listing is missing, partial or failed, or whose lookup App is not installed or installed on selected repositories only; nothing there is added or removed."
3634
3361
  },
3635
3362
  "openWork": {
3636
3363
  "type": "array",
@@ -3652,7 +3379,7 @@
3652
3379
  "repo"
3653
3380
  ]
3654
3381
  },
3655
- "description": "The agent's open tasks and PRs on those repos that removing them would block; empty when no open-work port is wired."
3382
+ "description": "The agent's open tasks and PRs on the removed repos that the removals would block; empty when no open-work port is wired."
3656
3383
  },
3657
3384
  "warnings": {
3658
3385
  "type": "array",
@@ -3665,7 +3392,7 @@
3665
3392
  "status"
3666
3393
  ]
3667
3394
  },
3668
- "GithubLostAccessRemoveResult": {
3395
+ "GithubSyncApplyResult": {
3669
3396
  "type": "object",
3670
3397
  "properties": {
3671
3398
  "status": {
@@ -3682,25 +3409,25 @@
3682
3409
  "auditId": {
3683
3410
  "type": "string"
3684
3411
  },
3685
- "repos": {
3412
+ "appAdds": {
3686
3413
  "type": "array",
3687
3414
  "items": {
3688
3415
  "type": "string"
3689
3416
  }
3690
3417
  },
3691
- "installationRemoves": {
3418
+ "appRemoves": {
3692
3419
  "type": "array",
3693
3420
  "items": {
3694
3421
  "type": "string"
3695
3422
  }
3696
3423
  },
3697
- "configRemoves": {
3424
+ "agentRemoves": {
3698
3425
  "type": "array",
3699
3426
  "items": {
3700
3427
  "type": "string"
3701
3428
  }
3702
3429
  },
3703
- "notRemoved": {
3430
+ "notApplied": {
3704
3431
  "type": "array",
3705
3432
  "items": {
3706
3433
  "type": "object",
@@ -3717,7 +3444,7 @@
3717
3444
  "reason"
3718
3445
  ]
3719
3446
  },
3720
- "description": "Named repos left alone: the user can still push, the org was skipped, or the repo is on neither the installation nor the agent."
3447
+ "description": "Confirmed repos left alone: access changed since the preview, the org was skipped, or the repo is not where the change expected it."
3721
3448
  },
3722
3449
  "skippedOrgs": {
3723
3450
  "type": "array",
@@ -3748,27 +3475,44 @@
3748
3475
  "status"
3749
3476
  ]
3750
3477
  },
3751
- "GithubLostAccessRemoveBody": {
3478
+ "GithubSyncApplyBody": {
3752
3479
  "type": "object",
3753
3480
  "properties": {
3754
- "repos": {
3481
+ "appAdds": {
3755
3482
  "type": "array",
3756
3483
  "items": {
3757
3484
  "type": "string",
3758
3485
  "pattern": "^[^/\\s]+\\/[^/\\s]+$"
3759
3486
  },
3760
- "minItems": 1,
3761
- "maxItems": 100,
3762
- "description": "The repos (owner/repo) the admin confirmed from the preview. Each is re-checked; only those the user still cannot push to are removed."
3487
+ "maxItems": 500,
3488
+ "default": [],
3489
+ "description": "Repos (owner/repo) the admin confirmed to add to the agent App's installation."
3490
+ },
3491
+ "appRemoves": {
3492
+ "type": "array",
3493
+ "items": {
3494
+ "type": "string",
3495
+ "pattern": "^[^/\\s]+\\/[^/\\s]+$"
3496
+ },
3497
+ "maxItems": 500,
3498
+ "default": [],
3499
+ "description": "Repos the admin confirmed to remove from the agent App's installation."
3500
+ },
3501
+ "agentRemoves": {
3502
+ "type": "array",
3503
+ "items": {
3504
+ "type": "string",
3505
+ "pattern": "^[^/\\s]+\\/[^/\\s]+$"
3506
+ },
3507
+ "maxItems": 500,
3508
+ "default": [],
3509
+ "description": "Repos the admin confirmed to remove from the agent's repos."
3763
3510
  },
3764
3511
  "confirmRemovals": {
3765
3512
  "type": "boolean",
3766
- "description": "Required when more than 10 repos would be removed."
3513
+ "description": "Required when more than 10 distinct repos would be removed."
3767
3514
  }
3768
- },
3769
- "required": [
3770
- "repos"
3771
- ]
3515
+ }
3772
3516
  },
3773
3517
  "AgentConfigResponse": {
3774
3518
  "type": "object",
@@ -7136,261 +6880,7 @@
7136
6880
  "content": {
7137
6881
  "application/json": {
7138
6882
  "schema": {
7139
- "$ref": "#/components/schemas/ChatTokenStats"
7140
- }
7141
- }
7142
- }
7143
- },
7144
- "401": {
7145
- "description": "Unauthorized",
7146
- "content": {
7147
- "application/json": {
7148
- "schema": {
7149
- "$ref": "#/components/schemas/Error"
7150
- }
7151
- }
7152
- }
7153
- },
7154
- "403": {
7155
- "description": "Forbidden",
7156
- "content": {
7157
- "application/json": {
7158
- "schema": {
7159
- "$ref": "#/components/schemas/Error"
7160
- }
7161
- }
7162
- }
7163
- }
7164
- }
7165
- }
7166
- },
7167
- "/agents/{id}/chat-tokens/daily": {
7168
- "post": {
7169
- "summary": "Record daily chat token usage",
7170
- "description": "Atomically accumulates Slack chat token usage into the existing rows for each `(agentId, date, model)` tuple, creating them if absent. Supply a `modelBreakdown` array to split a single day's usage across multiple models. Returns the updated daily rows, one per model.",
7171
- "parameters": [
7172
- {
7173
- "schema": {
7174
- "type": "string",
7175
- "example": "clx1234567890"
7176
- },
7177
- "required": true,
7178
- "name": "id",
7179
- "in": "path"
7180
- }
7181
- ],
7182
- "requestBody": {
7183
- "content": {
7184
- "application/json": {
7185
- "schema": {
7186
- "$ref": "#/components/schemas/UpsertChatTokenDailyBody"
7187
- }
7188
- }
7189
- }
7190
- },
7191
- "responses": {
7192
- "200": {
7193
- "description": "Updated daily chat token usage rows (one per model)",
7194
- "content": {
7195
- "application/json": {
7196
- "schema": {
7197
- "type": "array",
7198
- "items": {
7199
- "$ref": "#/components/schemas/AgentChatTokenUsageDailyByModel"
7200
- }
7201
- }
7202
- }
7203
- }
7204
- },
7205
- "400": {
7206
- "description": "Bad request",
7207
- "content": {
7208
- "application/json": {
7209
- "schema": {
7210
- "$ref": "#/components/schemas/Error"
7211
- }
7212
- }
7213
- }
7214
- },
7215
- "404": {
7216
- "description": "Agent not found",
7217
- "content": {
7218
- "application/json": {
7219
- "schema": {
7220
- "$ref": "#/components/schemas/Error"
7221
- }
7222
- }
7223
- }
7224
- }
7225
- }
7226
- }
7227
- },
7228
- "/agents/{id}/github-installations": {
7229
- "put": {
7230
- "summary": "Replace the agent's GitHub installations snapshot",
7231
- "description": "Upserts the agent's single GitHub App installations snapshot (owner, installation id, state, sanitized lastError), replacing the prior list wholesale — an installation absent from the body is dropped. The body schema is closed: unknown fields (e.g. tokens) are rejected with 400.",
7232
- "parameters": [
7233
- {
7234
- "schema": {
7235
- "type": "string",
7236
- "example": "clx1234567890"
7237
- },
7238
- "required": true,
7239
- "name": "id",
7240
- "in": "path"
7241
- }
7242
- ],
7243
- "requestBody": {
7244
- "content": {
7245
- "application/json": {
7246
- "schema": {
7247
- "$ref": "#/components/schemas/PutGitHubInstallationsBody"
7248
- }
7249
- }
7250
- }
7251
- },
7252
- "responses": {
7253
- "200": {
7254
- "description": "Snapshot replaced",
7255
- "content": {
7256
- "application/json": {
7257
- "schema": {
7258
- "$ref": "#/components/schemas/GitHubInstallationsSnapshotWrapper"
7259
- }
7260
- }
7261
- }
7262
- },
7263
- "400": {
7264
- "description": "Bad request",
7265
- "content": {
7266
- "application/json": {
7267
- "schema": {
7268
- "$ref": "#/components/schemas/Error"
7269
- }
7270
- }
7271
- }
7272
- },
7273
- "401": {
7274
- "description": "Unauthorized",
7275
- "content": {
7276
- "application/json": {
7277
- "schema": {
7278
- "$ref": "#/components/schemas/Error"
7279
- }
7280
- }
7281
- }
7282
- },
7283
- "403": {
7284
- "description": "Forbidden — token does not own this agent",
7285
- "content": {
7286
- "application/json": {
7287
- "schema": {
7288
- "$ref": "#/components/schemas/Error"
7289
- }
7290
- }
7291
- }
7292
- }
7293
- }
7294
- },
7295
- "get": {
7296
- "summary": "Get the latest GitHub installations snapshot",
7297
- "description": "Returns the most recently reported GitHub installations snapshot, or 404 if the agent has never reported one.",
7298
- "parameters": [
7299
- {
7300
- "schema": {
7301
- "type": "string",
7302
- "example": "clx1234567890"
7303
- },
7304
- "required": true,
7305
- "name": "id",
7306
- "in": "path"
7307
- }
7308
- ],
7309
- "responses": {
7310
- "200": {
7311
- "description": "Latest GitHub installations snapshot",
7312
- "content": {
7313
- "application/json": {
7314
- "schema": {
7315
- "$ref": "#/components/schemas/GitHubInstallationsSnapshotWrapper"
7316
- }
7317
- }
7318
- }
7319
- },
7320
- "401": {
7321
- "description": "Unauthorized",
7322
- "content": {
7323
- "application/json": {
7324
- "schema": {
7325
- "$ref": "#/components/schemas/Error"
7326
- }
7327
- }
7328
- }
7329
- },
7330
- "403": {
7331
- "description": "Forbidden — token does not own this agent",
7332
- "content": {
7333
- "application/json": {
7334
- "schema": {
7335
- "$ref": "#/components/schemas/Error"
7336
- }
7337
- }
7338
- }
7339
- },
7340
- "404": {
7341
- "description": "No snapshot reported yet",
7342
- "content": {
7343
- "application/json": {
7344
- "schema": {
7345
- "$ref": "#/components/schemas/Error"
7346
- }
7347
- }
7348
- }
7349
- }
7350
- }
7351
- }
7352
- },
7353
- "/agents/{id}/baked-marketplaces": {
7354
- "put": {
7355
- "summary": "Report the marketplaces baked into the agent's image",
7356
- "description": "Runtime-only report, authenticated with the agent's own key. Overwrites the stored list of baked marketplace names (the image's current state); it is exposed read-only as `bakedMarketplaces` on GET /agents/{id}. Other callers, including another agent's key, get 403.",
7357
- "parameters": [
7358
- {
7359
- "schema": {
7360
- "type": "string",
7361
- "example": "clx1234567890"
7362
- },
7363
- "required": true,
7364
- "name": "id",
7365
- "in": "path"
7366
- }
7367
- ],
7368
- "requestBody": {
7369
- "content": {
7370
- "application/json": {
7371
- "schema": {
7372
- "$ref": "#/components/schemas/PutBakedMarketplacesBody"
7373
- }
7374
- }
7375
- }
7376
- },
7377
- "responses": {
7378
- "200": {
7379
- "description": "Baked marketplaces stored",
7380
- "content": {
7381
- "application/json": {
7382
- "schema": {
7383
- "$ref": "#/components/schemas/BakedMarketplacesResult"
7384
- }
7385
- }
7386
- }
7387
- },
7388
- "400": {
7389
- "description": "Bad request",
7390
- "content": {
7391
- "application/json": {
7392
- "schema": {
7393
- "$ref": "#/components/schemas/Error"
6883
+ "$ref": "#/components/schemas/ChatTokenStats"
7394
6884
  }
7395
6885
  }
7396
6886
  }
@@ -7406,17 +6896,7 @@
7406
6896
  }
7407
6897
  },
7408
6898
  "403": {
7409
- "description": "Forbidden — only the agent's own key may report",
7410
- "content": {
7411
- "application/json": {
7412
- "schema": {
7413
- "$ref": "#/components/schemas/Error"
7414
- }
7415
- }
7416
- }
7417
- },
7418
- "404": {
7419
- "description": "Agent not found",
6899
+ "description": "Forbidden",
7420
6900
  "content": {
7421
6901
  "application/json": {
7422
6902
  "schema": {
@@ -7428,10 +6908,10 @@
7428
6908
  }
7429
6909
  }
7430
6910
  },
7431
- "/agents/{id}/github-access": {
7432
- "get": {
7433
- "summary": "Preview the repos the agent's bound GitHub user can reach",
7434
- "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).",
6911
+ "/agents/{id}/chat-tokens/daily": {
6912
+ "post": {
6913
+ "summary": "Record daily chat token usage",
6914
+ "description": "Atomically accumulates Slack chat token usage into the existing rows for each `(agentId, date, model)` tuple, creating them if absent. Supply a `modelBreakdown` array to split a single day's usage across multiple models. Returns the updated daily rows, one per model.",
7435
6915
  "parameters": [
7436
6916
  {
7437
6917
  "schema": {
@@ -7443,29 +6923,31 @@
7443
6923
  "in": "path"
7444
6924
  }
7445
6925
  ],
7446
- "responses": {
7447
- "200": {
7448
- "description": "Access preview",
7449
- "content": {
7450
- "application/json": {
7451
- "schema": {
7452
- "$ref": "#/components/schemas/GithubAccessPreview"
7453
- }
6926
+ "requestBody": {
6927
+ "content": {
6928
+ "application/json": {
6929
+ "schema": {
6930
+ "$ref": "#/components/schemas/UpsertChatTokenDailyBody"
7454
6931
  }
7455
6932
  }
7456
- },
7457
- "401": {
7458
- "description": "Unauthorized",
6933
+ }
6934
+ },
6935
+ "responses": {
6936
+ "200": {
6937
+ "description": "Updated daily chat token usage rows (one per model)",
7459
6938
  "content": {
7460
6939
  "application/json": {
7461
6940
  "schema": {
7462
- "$ref": "#/components/schemas/Error"
6941
+ "type": "array",
6942
+ "items": {
6943
+ "$ref": "#/components/schemas/AgentChatTokenUsageDailyByModel"
6944
+ }
7463
6945
  }
7464
6946
  }
7465
6947
  }
7466
6948
  },
7467
- "403": {
7468
- "description": "Platform admin required",
6949
+ "400": {
6950
+ "description": "Bad request",
7469
6951
  "content": {
7470
6952
  "application/json": {
7471
6953
  "schema": {
@@ -7483,34 +6965,14 @@
7483
6965
  }
7484
6966
  }
7485
6967
  }
7486
- },
7487
- "422": {
7488
- "description": "Agent has no githubUsername",
7489
- "content": {
7490
- "application/json": {
7491
- "schema": {
7492
- "$ref": "#/components/schemas/Error"
7493
- }
7494
- }
7495
- }
7496
- },
7497
- "502": {
7498
- "description": "GitHub unavailable or refused",
7499
- "content": {
7500
- "application/json": {
7501
- "schema": {
7502
- "$ref": "#/components/schemas/Error"
7503
- }
7504
- }
7505
- }
7506
6968
  }
7507
6969
  }
7508
6970
  }
7509
6971
  },
7510
- "/agents/{id}/github-reconcile/plan": {
7511
- "post": {
7512
- "summary": "Plan a GitHub repo reconcile for the agent",
7513
- "description": "Platform-admin only (session members, ops keys and agent keys get 403). Read-only: nothing is persisted or changed. Returns the diff, warnings, `planHash` and the open work the removals would affect. 200 with `status: skipped` and a `reason` when no githubUsername is bound or the enterprise Apps are not configured. 404 for an unknown agent.",
6972
+ "/agents/{id}/github-installations": {
6973
+ "put": {
6974
+ "summary": "Replace the agent's GitHub installations snapshot",
6975
+ "description": "Upserts the agent's single GitHub App installations snapshot (owner, installation id, state, sanitized lastError), replacing the prior list wholesale — an installation absent from the body is dropped. The body schema is closed: unknown fields (e.g. tokens) are rejected with 400.",
7514
6976
  "parameters": [
7515
6977
  {
7516
6978
  "schema": {
@@ -7523,28 +6985,27 @@
7523
6985
  }
7524
6986
  ],
7525
6987
  "requestBody": {
7526
- "required": false,
7527
6988
  "content": {
7528
6989
  "application/json": {
7529
6990
  "schema": {
7530
- "$ref": "#/components/schemas/GithubReconcilePlanBody"
6991
+ "$ref": "#/components/schemas/PutGitHubInstallationsBody"
7531
6992
  }
7532
6993
  }
7533
6994
  }
7534
6995
  },
7535
6996
  "responses": {
7536
6997
  "200": {
7537
- "description": "Reconcile plan",
6998
+ "description": "Snapshot replaced",
7538
6999
  "content": {
7539
7000
  "application/json": {
7540
7001
  "schema": {
7541
- "$ref": "#/components/schemas/GithubReconcilePlanResult"
7002
+ "$ref": "#/components/schemas/GitHubInstallationsSnapshotWrapper"
7542
7003
  }
7543
7004
  }
7544
7005
  }
7545
7006
  },
7546
- "401": {
7547
- "description": "Unauthorized",
7007
+ "400": {
7008
+ "description": "Bad request",
7548
7009
  "content": {
7549
7010
  "application/json": {
7550
7011
  "schema": {
@@ -7553,8 +7014,8 @@
7553
7014
  }
7554
7015
  }
7555
7016
  },
7556
- "403": {
7557
- "description": "Platform admin required",
7017
+ "401": {
7018
+ "description": "Unauthorized",
7558
7019
  "content": {
7559
7020
  "application/json": {
7560
7021
  "schema": {
@@ -7563,8 +7024,8 @@
7563
7024
  }
7564
7025
  }
7565
7026
  },
7566
- "404": {
7567
- "description": "Agent not found",
7027
+ "403": {
7028
+ "description": "Forbidden — token does not own this agent",
7568
7029
  "content": {
7569
7030
  "application/json": {
7570
7031
  "schema": {
@@ -7574,12 +7035,10 @@
7574
7035
  }
7575
7036
  }
7576
7037
  }
7577
- }
7578
- },
7579
- "/agents/{id}/github-reconcile/apply": {
7580
- "post": {
7581
- "summary": "Apply a reviewed GitHub repo reconcile plan",
7582
- "description": "Platform-admin only (session members, ops keys and agent keys get 403). Re-plans server-side and applies only when the fresh plan still matches `planHash` (409 otherwise). More than 10 removals need `confirmRemovals: true` (422 otherwise). Returns the audit id and result. 200 with `status: skipped` (unbound user or unconfigured Apps) or `status: noop` (nothing to change) is not an error. Open work on removed repos is blocked through the optional open-work port; a failure there is a warning.",
7038
+ },
7039
+ "get": {
7040
+ "summary": "Get the latest GitHub installations snapshot",
7041
+ "description": "Returns the most recently reported GitHub installations snapshot, or 404 if the agent has never reported one.",
7583
7042
  "parameters": [
7584
7043
  {
7585
7044
  "schema": {
@@ -7591,23 +7050,13 @@
7591
7050
  "in": "path"
7592
7051
  }
7593
7052
  ],
7594
- "requestBody": {
7595
- "required": true,
7596
- "content": {
7597
- "application/json": {
7598
- "schema": {
7599
- "$ref": "#/components/schemas/GithubReconcileApplyBody"
7600
- }
7601
- }
7602
- }
7603
- },
7604
7053
  "responses": {
7605
7054
  "200": {
7606
- "description": "Apply result",
7055
+ "description": "Latest GitHub installations snapshot",
7607
7056
  "content": {
7608
7057
  "application/json": {
7609
7058
  "schema": {
7610
- "$ref": "#/components/schemas/GithubReconcileApplyResult"
7059
+ "$ref": "#/components/schemas/GitHubInstallationsSnapshotWrapper"
7611
7060
  }
7612
7061
  }
7613
7062
  }
@@ -7623,7 +7072,7 @@
7623
7072
  }
7624
7073
  },
7625
7074
  "403": {
7626
- "description": "Platform admin required",
7075
+ "description": "Forbidden — token does not own this agent",
7627
7076
  "content": {
7628
7077
  "application/json": {
7629
7078
  "schema": {
@@ -7633,27 +7082,7 @@
7633
7082
  }
7634
7083
  },
7635
7084
  "404": {
7636
- "description": "Agent not found",
7637
- "content": {
7638
- "application/json": {
7639
- "schema": {
7640
- "$ref": "#/components/schemas/Error"
7641
- }
7642
- }
7643
- }
7644
- },
7645
- "409": {
7646
- "description": "Plan hash is stale; re-plan",
7647
- "content": {
7648
- "application/json": {
7649
- "schema": {
7650
- "$ref": "#/components/schemas/Error"
7651
- }
7652
- }
7653
- }
7654
- },
7655
- "422": {
7656
- "description": "Removal cap needs confirmRemovals",
7085
+ "description": "No snapshot reported yet",
7657
7086
  "content": {
7658
7087
  "application/json": {
7659
7088
  "schema": {
@@ -7665,10 +7094,10 @@
7665
7094
  }
7666
7095
  }
7667
7096
  },
7668
- "/agents/{id}/github-installation/repos": {
7669
- "get": {
7670
- "summary": "List the repos on the agent App's installation",
7671
- "description": "Platform-admin only (session members, ops keys and agent keys get 403). Per org the agent's own GitHub App (its GH_APP_ID) is installed on, lists the installation's repos. When the agent has a bound githubUsername, each repo carries `userCanPush` from the access lookup only when that org's lookup result is complete; otherwise the field is omitted (never false). 404 for an unknown agent; 422 when the agent has no GH_APP_ID.",
7097
+ "/agents/{id}/baked-marketplaces": {
7098
+ "put": {
7099
+ "summary": "Report the marketplaces baked into the agent's image",
7100
+ "description": "Runtime-only report, authenticated with the agent's own key. Overwrites the stored list of baked marketplace names (the image's current state); it is exposed read-only as `bakedMarketplaces` on GET /agents/{id}. Other callers, including another agent's key, get 403.",
7672
7101
  "parameters": [
7673
7102
  {
7674
7103
  "schema": {
@@ -7680,39 +7109,28 @@
7680
7109
  "in": "path"
7681
7110
  }
7682
7111
  ],
7683
- "responses": {
7684
- "200": {
7685
- "description": "Installation repos",
7686
- "content": {
7687
- "application/json": {
7688
- "schema": {
7689
- "$ref": "#/components/schemas/GithubInstallationReposList"
7690
- }
7691
- }
7692
- }
7693
- },
7694
- "401": {
7695
- "description": "Unauthorized",
7696
- "content": {
7697
- "application/json": {
7698
- "schema": {
7699
- "$ref": "#/components/schemas/Error"
7700
- }
7112
+ "requestBody": {
7113
+ "content": {
7114
+ "application/json": {
7115
+ "schema": {
7116
+ "$ref": "#/components/schemas/PutBakedMarketplacesBody"
7701
7117
  }
7702
7118
  }
7703
- },
7704
- "403": {
7705
- "description": "Platform admin required",
7119
+ }
7120
+ },
7121
+ "responses": {
7122
+ "200": {
7123
+ "description": "Baked marketplaces stored",
7706
7124
  "content": {
7707
7125
  "application/json": {
7708
7126
  "schema": {
7709
- "$ref": "#/components/schemas/Error"
7127
+ "$ref": "#/components/schemas/BakedMarketplacesResult"
7710
7128
  }
7711
7129
  }
7712
7130
  }
7713
7131
  },
7714
- "404": {
7715
- "description": "Agent not found",
7132
+ "400": {
7133
+ "description": "Bad request",
7716
7134
  "content": {
7717
7135
  "application/json": {
7718
7136
  "schema": {
@@ -7721,8 +7139,8 @@
7721
7139
  }
7722
7140
  }
7723
7141
  },
7724
- "422": {
7725
- "description": "Agent has no GH_APP_ID (its own GitHub App is not set up)",
7142
+ "401": {
7143
+ "description": "Unauthorized",
7726
7144
  "content": {
7727
7145
  "application/json": {
7728
7146
  "schema": {
@@ -7731,8 +7149,8 @@
7731
7149
  }
7732
7150
  }
7733
7151
  },
7734
- "502": {
7735
- "description": "GitHub unavailable or refused",
7152
+ "403": {
7153
+ "description": "Forbidden — only the agent's own key may report",
7736
7154
  "content": {
7737
7155
  "application/json": {
7738
7156
  "schema": {
@@ -7741,8 +7159,8 @@
7741
7159
  }
7742
7160
  }
7743
7161
  },
7744
- "503": {
7745
- "description": "GitHub Apps are not configured",
7162
+ "404": {
7163
+ "description": "Agent not found",
7746
7164
  "content": {
7747
7165
  "application/json": {
7748
7166
  "schema": {
@@ -7752,10 +7170,12 @@
7752
7170
  }
7753
7171
  }
7754
7172
  }
7755
- },
7756
- "post": {
7757
- "summary": "Add repos to the agent App's installation",
7758
- "description": "Platform-admin only. Grants the agent's own GitHub App installation access to the named repos, with no plan step; the agent's configured repos are not changed. Writes one audit entry (GitHubReconcileAudit, planHash `direct:add`) recording the caller and repos. 404 unknown agent; 422 no GH_APP_ID; 409 when the App is not installed on a repo's org (nothing is changed or audited); 502 when GitHub refuses (a failed audit entry is written).",
7173
+ }
7174
+ },
7175
+ "/agents/{id}/github-access": {
7176
+ "get": {
7177
+ "summary": "Preview the repos the agent's bound GitHub user can reach",
7178
+ "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).",
7759
7179
  "parameters": [
7760
7180
  {
7761
7181
  "schema": {
@@ -7767,23 +7187,13 @@
7767
7187
  "in": "path"
7768
7188
  }
7769
7189
  ],
7770
- "requestBody": {
7771
- "required": true,
7772
- "content": {
7773
- "application/json": {
7774
- "schema": {
7775
- "$ref": "#/components/schemas/GithubInstallationReposBody"
7776
- }
7777
- }
7778
- }
7779
- },
7780
7190
  "responses": {
7781
7191
  "200": {
7782
- "description": "Repos added",
7192
+ "description": "Access preview",
7783
7193
  "content": {
7784
7194
  "application/json": {
7785
7195
  "schema": {
7786
- "$ref": "#/components/schemas/GithubInstallationReposChange"
7196
+ "$ref": "#/components/schemas/GithubAccessPreview"
7787
7197
  }
7788
7198
  }
7789
7199
  }
@@ -7818,18 +7228,8 @@
7818
7228
  }
7819
7229
  }
7820
7230
  },
7821
- "409": {
7822
- "description": "Agent App not installed on the org",
7823
- "content": {
7824
- "application/json": {
7825
- "schema": {
7826
- "$ref": "#/components/schemas/Error"
7827
- }
7828
- }
7829
- }
7830
- },
7831
7231
  "422": {
7832
- "description": "Agent has no GH_APP_ID (its own GitHub App is not set up)",
7232
+ "description": "Agent has no githubUsername",
7833
7233
  "content": {
7834
7234
  "application/json": {
7835
7235
  "schema": {
@@ -7847,24 +7247,14 @@
7847
7247
  }
7848
7248
  }
7849
7249
  }
7850
- },
7851
- "503": {
7852
- "description": "GitHub Apps are not configured",
7853
- "content": {
7854
- "application/json": {
7855
- "schema": {
7856
- "$ref": "#/components/schemas/Error"
7857
- }
7858
- }
7859
- }
7860
7250
  }
7861
7251
  }
7862
7252
  }
7863
7253
  },
7864
- "/agents/{id}/github-installation/repos/remove": {
7865
- "post": {
7866
- "summary": "Remove repos from the agent App's installation",
7867
- "description": "Platform-admin only. Revokes the agent's own GitHub App installation access to the named repos, with no plan step; the agent's configured repos are not changed. Writes one audit entry (GitHubReconcileAudit, planHash `direct:remove`) recording the caller and repos. Same errors as the add route.",
7254
+ "/agents/{id}/github-installation/repos": {
7255
+ "get": {
7256
+ "summary": "List the repos on the agent App's installation",
7257
+ "description": "Platform-admin only (session members, ops keys and agent keys get 403). Per org the agent's own GitHub App (its GH_APP_ID) is installed on, lists the installation's repos. When the agent has a bound githubUsername, each repo carries `userCanPush` from the access lookup only when that org's lookup result is complete; otherwise the field is omitted (never false). 404 for an unknown agent; 422 when the agent has no GH_APP_ID.",
7868
7258
  "parameters": [
7869
7259
  {
7870
7260
  "schema": {
@@ -7876,23 +7266,13 @@
7876
7266
  "in": "path"
7877
7267
  }
7878
7268
  ],
7879
- "requestBody": {
7880
- "required": true,
7881
- "content": {
7882
- "application/json": {
7883
- "schema": {
7884
- "$ref": "#/components/schemas/GithubInstallationReposBody"
7885
- }
7886
- }
7887
- }
7888
- },
7889
7269
  "responses": {
7890
7270
  "200": {
7891
- "description": "Repos removed",
7271
+ "description": "Installation repos",
7892
7272
  "content": {
7893
7273
  "application/json": {
7894
7274
  "schema": {
7895
- "$ref": "#/components/schemas/GithubInstallationReposChange"
7275
+ "$ref": "#/components/schemas/GithubInstallationReposList"
7896
7276
  }
7897
7277
  }
7898
7278
  }
@@ -7927,16 +7307,6 @@
7927
7307
  }
7928
7308
  }
7929
7309
  },
7930
- "409": {
7931
- "description": "Agent App not installed on the org",
7932
- "content": {
7933
- "application/json": {
7934
- "schema": {
7935
- "$ref": "#/components/schemas/Error"
7936
- }
7937
- }
7938
- }
7939
- },
7940
7310
  "422": {
7941
7311
  "description": "Agent has no GH_APP_ID (its own GitHub App is not set up)",
7942
7312
  "content": {
@@ -7970,10 +7340,10 @@
7970
7340
  }
7971
7341
  }
7972
7342
  },
7973
- "/agents/{id}/github-lost-access/preview": {
7343
+ "/agents/{id}/github-sync/preview": {
7974
7344
  "get": {
7975
- "summary": "Preview removing the repos the bound user can no longer push to",
7976
- "description": "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.",
7345
+ "summary": "Preview syncing the agent's GitHub access with its bound user",
7346
+ "description": "Platform-admin only (session members, ops keys and agent keys get 403). Read-only: nothing is changed or audited. Lists (1) repos to add to the agent App's installation, (2) installation repos to remove and (3) agent repos to remove, based on what the bound githubUsername can push to, plus the agent's open tasks and PRs the removals would block (via the optional open-work port; a port failure is a warning). The agent's repos are never added to. Orgs whose access listing is missing, partial or failed, or whose lookup App is not installed or installed on selected repositories only, are skipped (adds included) 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.",
7977
7347
  "parameters": [
7978
7348
  {
7979
7349
  "schema": {
@@ -7987,11 +7357,11 @@
7987
7357
  ],
7988
7358
  "responses": {
7989
7359
  "200": {
7990
- "description": "Lost-access removal preview",
7360
+ "description": "Sync preview",
7991
7361
  "content": {
7992
7362
  "application/json": {
7993
7363
  "schema": {
7994
- "$ref": "#/components/schemas/GithubLostAccessPreview"
7364
+ "$ref": "#/components/schemas/GithubSyncPreview"
7995
7365
  }
7996
7366
  }
7997
7367
  }
@@ -8049,10 +7419,10 @@
8049
7419
  }
8050
7420
  }
8051
7421
  },
8052
- "/agents/{id}/github-lost-access/remove": {
7422
+ "/agents/{id}/github-sync/apply": {
8053
7423
  "post": {
8054
- "summary": "Remove the confirmed repos the bound user can no longer push to",
8055
- "description": "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).",
7424
+ "summary": "Apply the confirmed sync changes",
7425
+ "description": "Platform-admin only. Takes the exact lists the admin confirmed from the preview, re-checks each against the bound user's current access, and applies only what still qualifies: installation adds, installation removes, then agent-repo removes. Writes one audit entry (GitHubReconcileAudit, planHash `sync:apply`) and blocks the agent's open work on the removed repos through the optional open-work port (a failure there is a warning). Confirmed repos left alone are reported in `notApplied`. Same skip rules as the preview: a skipped call (200 `status: skipped`) changes and audits nothing; `noop` when nothing confirmed still applies. 422 when more than 10 repos would be removed without `confirmRemovals: true`. 502 when GitHub refuses (a failed audit entry records only what landed).",
8056
7426
  "parameters": [
8057
7427
  {
8058
7428
  "schema": {
@@ -8069,18 +7439,18 @@
8069
7439
  "content": {
8070
7440
  "application/json": {
8071
7441
  "schema": {
8072
- "$ref": "#/components/schemas/GithubLostAccessRemoveBody"
7442
+ "$ref": "#/components/schemas/GithubSyncApplyBody"
8073
7443
  }
8074
7444
  }
8075
7445
  }
8076
7446
  },
8077
7447
  "responses": {
8078
7448
  "200": {
8079
- "description": "Removal result",
7449
+ "description": "Sync result",
8080
7450
  "content": {
8081
7451
  "application/json": {
8082
7452
  "schema": {
8083
- "$ref": "#/components/schemas/GithubLostAccessRemoveResult"
7453
+ "$ref": "#/components/schemas/GithubSyncApplyResult"
8084
7454
  }
8085
7455
  }
8086
7456
  }