@app-vitals/agent-admin 1.87.0 → 1.89.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 (30) hide show
  1. package/openapi.json +253 -0
  2. package/openapi.platform.json +297 -0
  3. package/package.json +2 -2
  4. package/prisma/client/internal/class.ts +4 -4
  5. package/prisma/client/internal/prismaNamespace.ts +1 -0
  6. package/prisma/client/internal/prismaNamespaceBrowser.ts +1 -0
  7. package/prisma/client/models/GitHubRepoSnapshot.ts +33 -1
  8. package/prisma/migrations/20261125000000_add_github_snapshot_repository_selection/migration.sql +2 -0
  9. package/prisma/schema/schema.prisma +2 -0
  10. package/src/admin-boot.ts +11 -0
  11. package/src/agents-api.smoke.test.ts +88 -0
  12. package/src/agents-api.ts +15 -0
  13. package/src/fixtures/github-enterprise-cassette.json +16 -0
  14. package/src/github-agent-installation-crawler.ts +27 -8
  15. package/src/github-agent-installation-crawler.unit.test.ts +76 -1
  16. package/src/github-enterprise-api.integration.test.ts +127 -0
  17. package/src/github-enterprise-api.smoke.test.ts +188 -5
  18. package/src/github-enterprise-api.ts +212 -4
  19. package/src/github-enterprise-client.ts +23 -1
  20. package/src/github-enterprise-client.unit.test.ts +65 -0
  21. package/src/github-installation-selection.integration.test.ts +91 -0
  22. package/src/github-installation-wiring.ts +5 -0
  23. package/src/github-repo-cache.ts +8 -0
  24. package/src/github-sync-switch.integration.test.ts +297 -0
  25. package/src/github-sync-switch.unit.test.ts +467 -0
  26. package/src/github-sync.ts +205 -24
  27. package/src/github-uninstall.ts +70 -0
  28. package/src/github-uninstall.unit.test.ts +78 -0
  29. package/src/installation-ports.ts +43 -0
  30. package/src/installation-repos-service.ts +2 -0
@@ -3580,6 +3580,7 @@ export const GitHubRepoSnapshotScalarFieldEnum = {
3580
3580
  crawlStartedAt: 'crawlStartedAt',
3581
3581
  completedAt: 'completedAt',
3582
3582
  totalCount: 'totalCount',
3583
+ repositorySelection: 'repositorySelection',
3583
3584
  lastError: 'lastError',
3584
3585
  attempts: 'attempts',
3585
3586
  nextAttemptAt: 'nextAttemptAt',
@@ -604,6 +604,7 @@ export const GitHubRepoSnapshotScalarFieldEnum = {
604
604
  crawlStartedAt: 'crawlStartedAt',
605
605
  completedAt: 'completedAt',
606
606
  totalCount: 'totalCount',
607
+ repositorySelection: 'repositorySelection',
607
608
  lastError: 'lastError',
608
609
  attempts: 'attempts',
609
610
  nextAttemptAt: 'nextAttemptAt',
@@ -48,6 +48,7 @@ export type GitHubRepoSnapshotMinAggregateOutputType = {
48
48
  crawlStartedAt: Date | null
49
49
  completedAt: Date | null
50
50
  totalCount: number | null
51
+ repositorySelection: string | null
51
52
  lastError: string | null
52
53
  attempts: number | null
53
54
  nextAttemptAt: Date | null
@@ -69,6 +70,7 @@ export type GitHubRepoSnapshotMaxAggregateOutputType = {
69
70
  crawlStartedAt: Date | null
70
71
  completedAt: Date | null
71
72
  totalCount: number | null
73
+ repositorySelection: string | null
72
74
  lastError: string | null
73
75
  attempts: number | null
74
76
  nextAttemptAt: Date | null
@@ -90,6 +92,7 @@ export type GitHubRepoSnapshotCountAggregateOutputType = {
90
92
  crawlStartedAt: number
91
93
  completedAt: number
92
94
  totalCount: number
95
+ repositorySelection: number
93
96
  lastError: number
94
97
  attempts: number
95
98
  nextAttemptAt: number
@@ -125,6 +128,7 @@ export type GitHubRepoSnapshotMinAggregateInputType = {
125
128
  crawlStartedAt?: true
126
129
  completedAt?: true
127
130
  totalCount?: true
131
+ repositorySelection?: true
128
132
  lastError?: true
129
133
  attempts?: true
130
134
  nextAttemptAt?: true
@@ -146,6 +150,7 @@ export type GitHubRepoSnapshotMaxAggregateInputType = {
146
150
  crawlStartedAt?: true
147
151
  completedAt?: true
148
152
  totalCount?: true
153
+ repositorySelection?: true
149
154
  lastError?: true
150
155
  attempts?: true
151
156
  nextAttemptAt?: true
@@ -167,6 +172,7 @@ export type GitHubRepoSnapshotCountAggregateInputType = {
167
172
  crawlStartedAt?: true
168
173
  completedAt?: true
169
174
  totalCount?: true
175
+ repositorySelection?: true
170
176
  lastError?: true
171
177
  attempts?: true
172
178
  nextAttemptAt?: true
@@ -275,6 +281,7 @@ export type GitHubRepoSnapshotGroupByOutputType = {
275
281
  crawlStartedAt: Date | null
276
282
  completedAt: Date | null
277
283
  totalCount: number | null
284
+ repositorySelection: string | null
278
285
  lastError: string | null
279
286
  attempts: number
280
287
  nextAttemptAt: Date | null
@@ -319,6 +326,7 @@ export type GitHubRepoSnapshotWhereInput = {
319
326
  crawlStartedAt?: Prisma.DateTimeNullableFilter<"GitHubRepoSnapshot"> | Date | string | null
320
327
  completedAt?: Prisma.DateTimeNullableFilter<"GitHubRepoSnapshot"> | Date | string | null
321
328
  totalCount?: Prisma.IntNullableFilter<"GitHubRepoSnapshot"> | number | null
329
+ repositorySelection?: Prisma.StringNullableFilter<"GitHubRepoSnapshot"> | string | null
322
330
  lastError?: Prisma.StringNullableFilter<"GitHubRepoSnapshot"> | string | null
323
331
  attempts?: Prisma.IntFilter<"GitHubRepoSnapshot"> | number
324
332
  nextAttemptAt?: Prisma.DateTimeNullableFilter<"GitHubRepoSnapshot"> | Date | string | null
@@ -341,6 +349,7 @@ export type GitHubRepoSnapshotOrderByWithRelationInput = {
341
349
  crawlStartedAt?: Prisma.SortOrderInput | Prisma.SortOrder
342
350
  completedAt?: Prisma.SortOrderInput | Prisma.SortOrder
343
351
  totalCount?: Prisma.SortOrderInput | Prisma.SortOrder
352
+ repositorySelection?: Prisma.SortOrderInput | Prisma.SortOrder
344
353
  lastError?: Prisma.SortOrderInput | Prisma.SortOrder
345
354
  attempts?: Prisma.SortOrder
346
355
  nextAttemptAt?: Prisma.SortOrderInput | Prisma.SortOrder
@@ -367,6 +376,7 @@ export type GitHubRepoSnapshotWhereUniqueInput = Prisma.AtLeast<{
367
376
  crawlStartedAt?: Prisma.DateTimeNullableFilter<"GitHubRepoSnapshot"> | Date | string | null
368
377
  completedAt?: Prisma.DateTimeNullableFilter<"GitHubRepoSnapshot"> | Date | string | null
369
378
  totalCount?: Prisma.IntNullableFilter<"GitHubRepoSnapshot"> | number | null
379
+ repositorySelection?: Prisma.StringNullableFilter<"GitHubRepoSnapshot"> | string | null
370
380
  lastError?: Prisma.StringNullableFilter<"GitHubRepoSnapshot"> | string | null
371
381
  attempts?: Prisma.IntFilter<"GitHubRepoSnapshot"> | number
372
382
  nextAttemptAt?: Prisma.DateTimeNullableFilter<"GitHubRepoSnapshot"> | Date | string | null
@@ -389,6 +399,7 @@ export type GitHubRepoSnapshotOrderByWithAggregationInput = {
389
399
  crawlStartedAt?: Prisma.SortOrderInput | Prisma.SortOrder
390
400
  completedAt?: Prisma.SortOrderInput | Prisma.SortOrder
391
401
  totalCount?: Prisma.SortOrderInput | Prisma.SortOrder
402
+ repositorySelection?: Prisma.SortOrderInput | Prisma.SortOrder
392
403
  lastError?: Prisma.SortOrderInput | Prisma.SortOrder
393
404
  attempts?: Prisma.SortOrder
394
405
  nextAttemptAt?: Prisma.SortOrderInput | Prisma.SortOrder
@@ -418,6 +429,7 @@ export type GitHubRepoSnapshotScalarWhereWithAggregatesInput = {
418
429
  crawlStartedAt?: Prisma.DateTimeNullableWithAggregatesFilter<"GitHubRepoSnapshot"> | Date | string | null
419
430
  completedAt?: Prisma.DateTimeNullableWithAggregatesFilter<"GitHubRepoSnapshot"> | Date | string | null
420
431
  totalCount?: Prisma.IntNullableWithAggregatesFilter<"GitHubRepoSnapshot"> | number | null
432
+ repositorySelection?: Prisma.StringNullableWithAggregatesFilter<"GitHubRepoSnapshot"> | string | null
421
433
  lastError?: Prisma.StringNullableWithAggregatesFilter<"GitHubRepoSnapshot"> | string | null
422
434
  attempts?: Prisma.IntWithAggregatesFilter<"GitHubRepoSnapshot"> | number
423
435
  nextAttemptAt?: Prisma.DateTimeNullableWithAggregatesFilter<"GitHubRepoSnapshot"> | Date | string | null
@@ -439,6 +451,7 @@ export type GitHubRepoSnapshotCreateInput = {
439
451
  crawlStartedAt?: Date | string | null
440
452
  completedAt?: Date | string | null
441
453
  totalCount?: number | null
454
+ repositorySelection?: string | null
442
455
  lastError?: string | null
443
456
  attempts?: number
444
457
  nextAttemptAt?: Date | string | null
@@ -461,6 +474,7 @@ export type GitHubRepoSnapshotUncheckedCreateInput = {
461
474
  crawlStartedAt?: Date | string | null
462
475
  completedAt?: Date | string | null
463
476
  totalCount?: number | null
477
+ repositorySelection?: string | null
464
478
  lastError?: string | null
465
479
  attempts?: number
466
480
  nextAttemptAt?: Date | string | null
@@ -483,6 +497,7 @@ export type GitHubRepoSnapshotUpdateInput = {
483
497
  crawlStartedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
484
498
  completedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
485
499
  totalCount?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
500
+ repositorySelection?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
486
501
  lastError?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
487
502
  attempts?: Prisma.IntFieldUpdateOperationsInput | number
488
503
  nextAttemptAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
@@ -505,6 +520,7 @@ export type GitHubRepoSnapshotUncheckedUpdateInput = {
505
520
  crawlStartedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
506
521
  completedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
507
522
  totalCount?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
523
+ repositorySelection?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
508
524
  lastError?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
509
525
  attempts?: Prisma.IntFieldUpdateOperationsInput | number
510
526
  nextAttemptAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
@@ -527,6 +543,7 @@ export type GitHubRepoSnapshotCreateManyInput = {
527
543
  crawlStartedAt?: Date | string | null
528
544
  completedAt?: Date | string | null
529
545
  totalCount?: number | null
546
+ repositorySelection?: string | null
530
547
  lastError?: string | null
531
548
  attempts?: number
532
549
  nextAttemptAt?: Date | string | null
@@ -548,6 +565,7 @@ export type GitHubRepoSnapshotUpdateManyMutationInput = {
548
565
  crawlStartedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
549
566
  completedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
550
567
  totalCount?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
568
+ repositorySelection?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
551
569
  lastError?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
552
570
  attempts?: Prisma.IntFieldUpdateOperationsInput | number
553
571
  nextAttemptAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
@@ -569,6 +587,7 @@ export type GitHubRepoSnapshotUncheckedUpdateManyInput = {
569
587
  crawlStartedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
570
588
  completedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
571
589
  totalCount?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
590
+ repositorySelection?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
572
591
  lastError?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
573
592
  attempts?: Prisma.IntFieldUpdateOperationsInput | number
574
593
  nextAttemptAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
@@ -597,6 +616,7 @@ export type GitHubRepoSnapshotCountOrderByAggregateInput = {
597
616
  crawlStartedAt?: Prisma.SortOrder
598
617
  completedAt?: Prisma.SortOrder
599
618
  totalCount?: Prisma.SortOrder
619
+ repositorySelection?: Prisma.SortOrder
600
620
  lastError?: Prisma.SortOrder
601
621
  attempts?: Prisma.SortOrder
602
622
  nextAttemptAt?: Prisma.SortOrder
@@ -624,6 +644,7 @@ export type GitHubRepoSnapshotMaxOrderByAggregateInput = {
624
644
  crawlStartedAt?: Prisma.SortOrder
625
645
  completedAt?: Prisma.SortOrder
626
646
  totalCount?: Prisma.SortOrder
647
+ repositorySelection?: Prisma.SortOrder
627
648
  lastError?: Prisma.SortOrder
628
649
  attempts?: Prisma.SortOrder
629
650
  nextAttemptAt?: Prisma.SortOrder
@@ -645,6 +666,7 @@ export type GitHubRepoSnapshotMinOrderByAggregateInput = {
645
666
  crawlStartedAt?: Prisma.SortOrder
646
667
  completedAt?: Prisma.SortOrder
647
668
  totalCount?: Prisma.SortOrder
669
+ repositorySelection?: Prisma.SortOrder
648
670
  lastError?: Prisma.SortOrder
649
671
  attempts?: Prisma.SortOrder
650
672
  nextAttemptAt?: Prisma.SortOrder
@@ -691,6 +713,7 @@ export type GitHubRepoSnapshotCreateWithoutReposInput = {
691
713
  crawlStartedAt?: Date | string | null
692
714
  completedAt?: Date | string | null
693
715
  totalCount?: number | null
716
+ repositorySelection?: string | null
694
717
  lastError?: string | null
695
718
  attempts?: number
696
719
  nextAttemptAt?: Date | string | null
@@ -712,6 +735,7 @@ export type GitHubRepoSnapshotUncheckedCreateWithoutReposInput = {
712
735
  crawlStartedAt?: Date | string | null
713
736
  completedAt?: Date | string | null
714
737
  totalCount?: number | null
738
+ repositorySelection?: string | null
715
739
  lastError?: string | null
716
740
  attempts?: number
717
741
  nextAttemptAt?: Date | string | null
@@ -749,6 +773,7 @@ export type GitHubRepoSnapshotUpdateWithoutReposInput = {
749
773
  crawlStartedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
750
774
  completedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
751
775
  totalCount?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
776
+ repositorySelection?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
752
777
  lastError?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
753
778
  attempts?: Prisma.IntFieldUpdateOperationsInput | number
754
779
  nextAttemptAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
@@ -770,6 +795,7 @@ export type GitHubRepoSnapshotUncheckedUpdateWithoutReposInput = {
770
795
  crawlStartedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
771
796
  completedAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
772
797
  totalCount?: Prisma.NullableIntFieldUpdateOperationsInput | number | null
798
+ repositorySelection?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
773
799
  lastError?: Prisma.NullableStringFieldUpdateOperationsInput | string | null
774
800
  attempts?: Prisma.IntFieldUpdateOperationsInput | number
775
801
  nextAttemptAt?: Prisma.NullableDateTimeFieldUpdateOperationsInput | Date | string | null
@@ -822,6 +848,7 @@ export type GitHubRepoSnapshotSelect<ExtArgs extends runtime.Types.Extensions.In
822
848
  crawlStartedAt?: boolean
823
849
  completedAt?: boolean
824
850
  totalCount?: boolean
851
+ repositorySelection?: boolean
825
852
  lastError?: boolean
826
853
  attempts?: boolean
827
854
  nextAttemptAt?: boolean
@@ -845,6 +872,7 @@ export type GitHubRepoSnapshotSelectCreateManyAndReturn<ExtArgs extends runtime.
845
872
  crawlStartedAt?: boolean
846
873
  completedAt?: boolean
847
874
  totalCount?: boolean
875
+ repositorySelection?: boolean
848
876
  lastError?: boolean
849
877
  attempts?: boolean
850
878
  nextAttemptAt?: boolean
@@ -866,6 +894,7 @@ export type GitHubRepoSnapshotSelectUpdateManyAndReturn<ExtArgs extends runtime.
866
894
  crawlStartedAt?: boolean
867
895
  completedAt?: boolean
868
896
  totalCount?: boolean
897
+ repositorySelection?: boolean
869
898
  lastError?: boolean
870
899
  attempts?: boolean
871
900
  nextAttemptAt?: boolean
@@ -887,6 +916,7 @@ export type GitHubRepoSnapshotSelectScalar = {
887
916
  crawlStartedAt?: boolean
888
917
  completedAt?: boolean
889
918
  totalCount?: boolean
919
+ repositorySelection?: boolean
890
920
  lastError?: boolean
891
921
  attempts?: boolean
892
922
  nextAttemptAt?: boolean
@@ -898,7 +928,7 @@ export type GitHubRepoSnapshotSelectScalar = {
898
928
  updatedAt?: boolean
899
929
  }
900
930
 
901
- export type GitHubRepoSnapshotOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "accountId" | "appKind" | "appRef" | "org" | "crawlPage" | "crawlStartedAt" | "completedAt" | "totalCount" | "lastError" | "attempts" | "nextAttemptAt" | "rateLimitResetAt" | "leaseHolder" | "leasedUntil" | "lastTickAt" | "createdAt" | "updatedAt", ExtArgs["result"]["gitHubRepoSnapshot"]>
931
+ export type GitHubRepoSnapshotOmit<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = runtime.Types.Extensions.GetOmit<"id" | "accountId" | "appKind" | "appRef" | "org" | "crawlPage" | "crawlStartedAt" | "completedAt" | "totalCount" | "repositorySelection" | "lastError" | "attempts" | "nextAttemptAt" | "rateLimitResetAt" | "leaseHolder" | "leasedUntil" | "lastTickAt" | "createdAt" | "updatedAt", ExtArgs["result"]["gitHubRepoSnapshot"]>
902
932
  export type GitHubRepoSnapshotInclude<ExtArgs extends runtime.Types.Extensions.InternalArgs = runtime.Types.Extensions.DefaultArgs> = {
903
933
  repos?: boolean | Prisma.GitHubRepoSnapshot$reposArgs<ExtArgs>
904
934
  _count?: boolean | Prisma.GitHubRepoSnapshotCountOutputTypeDefaultArgs<ExtArgs>
@@ -921,6 +951,7 @@ export type $GitHubRepoSnapshotPayload<ExtArgs extends runtime.Types.Extensions.
921
951
  crawlStartedAt: Date | null
922
952
  completedAt: Date | null
923
953
  totalCount: number | null
954
+ repositorySelection: string | null
924
955
  lastError: string | null
925
956
  attempts: number
926
957
  nextAttemptAt: Date | null
@@ -1363,6 +1394,7 @@ export interface GitHubRepoSnapshotFieldRefs {
1363
1394
  readonly crawlStartedAt: Prisma.FieldRef<"GitHubRepoSnapshot", 'DateTime'>
1364
1395
  readonly completedAt: Prisma.FieldRef<"GitHubRepoSnapshot", 'DateTime'>
1365
1396
  readonly totalCount: Prisma.FieldRef<"GitHubRepoSnapshot", 'Int'>
1397
+ readonly repositorySelection: Prisma.FieldRef<"GitHubRepoSnapshot", 'String'>
1366
1398
  readonly lastError: Prisma.FieldRef<"GitHubRepoSnapshot", 'String'>
1367
1399
  readonly attempts: Prisma.FieldRef<"GitHubRepoSnapshot", 'Int'>
1368
1400
  readonly nextAttemptAt: Prisma.FieldRef<"GitHubRepoSnapshot", 'DateTime'>
@@ -0,0 +1,2 @@
1
+ -- GIS-1.1: additive nullable column; null = unknown (never treated as "all").
2
+ ALTER TABLE "GitHubRepoSnapshot" ADD COLUMN "repositorySelection" TEXT;
@@ -761,6 +761,8 @@ model GitHubRepoSnapshot {
761
761
  crawlStartedAt DateTime?
762
762
  completedAt DateTime?
763
763
  totalCount Int?
764
+ // Agent App installation on the org: 'all' | 'selected'; null = unknown (never treated as 'all')
765
+ repositorySelection String?
764
766
  lastError String?
765
767
  attempts Int @default(0)
766
768
  nextAttemptAt DateTime?
package/src/admin-boot.ts CHANGED
@@ -97,6 +97,10 @@ import {
97
97
  import { parseChatCredentialConfig } from "./chat-credential-config.ts";
98
98
  import { HttpChatServiceProvisioningClient } from "./chat-service-provisioning-client.ts";
99
99
  import { SystemClock } from "./clock.ts";
100
+ import {
101
+ PrismaInstallationAgents,
102
+ PrismaInstallationAudit,
103
+ } from "./installation-ports.ts";
100
104
  import { CronRunNowService } from "./cron-run-now.ts";
101
105
  import { parseCronRunNowConfig } from "./cron-run-now-config.ts";
102
106
  import { CronRunTranscriptService } from "./cron-run-transcripts.ts";
@@ -635,6 +639,13 @@ export async function startAdmin(
635
639
  },
636
640
  githubEnterprise: {
637
641
  refreshAction: githubRefreshAction,
642
+ uninstall: {
643
+ agents: new PrismaInstallationAgents(prisma, agentEnvService),
644
+ audit: new PrismaInstallationAudit(prisma),
645
+ ...(resolvedExtensions.openWork
646
+ ? { openWork: resolvedExtensions.openWork }
647
+ : {}),
648
+ },
638
649
  appService: githubEnterpriseAppService,
639
650
  agentService,
640
651
  agentEnvService,
@@ -7418,6 +7418,7 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
7418
7418
  "installable_orgs_success",
7419
7419
  [`GET ${INST}`]: "org_installations_success",
7420
7420
  [`GET ${INST}/501/repositories`]: "install_repos_success",
7421
+ [`PATCH ${INST}/501/repositories`]: "install_selection_success",
7421
7422
  [`PATCH ${INST}/501/repositories/add`]: "install_repos_add_success",
7422
7423
  [`PATCH ${INST}/501/repositories/remove`]: "install_repos_remove_success",
7423
7424
  };
@@ -7475,6 +7476,24 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
7475
7476
  { status: 200, headers: { "Content-Type": "application/json" } },
7476
7477
  );
7477
7478
  }
7479
+ if (key === `PATCH ${INST}/501/repositories`) {
7480
+ // GIS-1.2: the "all" to "selected" switch (installation repos become the list).
7481
+ if (entry.status === 200) {
7482
+ const names =
7483
+ (
7484
+ JSON.parse(String(init?.body ?? "{}")) as {
7485
+ repositories?: string[];
7486
+ }
7487
+ ).repositories ?? [];
7488
+ patches.push({ key, names });
7489
+ events.push(["switch", names]);
7490
+ state.installed = names.map((n) => `acme-eng/${n}`);
7491
+ }
7492
+ return new Response(JSON.stringify(entry.body), {
7493
+ status: entry.status,
7494
+ headers: { "Content-Type": "application/json" },
7495
+ });
7496
+ }
7478
7497
  if (key.startsWith("PATCH") && entry.status === 200) {
7479
7498
  const body = JSON.parse(String(init?.body ?? "{}")) as {
7480
7499
  repositories?: string[];
@@ -8117,6 +8136,75 @@ describe("admin API — agent App installation repos and GitHub Sync (IRM-1.2, I
8117
8136
  expect(state.repos).toEqual([]);
8118
8137
  });
8119
8138
 
8139
+ // GIS-1.2: an agent App installed on All repositories is switched to Selected.
8140
+ const allSnapshot = () => [
8141
+ {
8142
+ org: "acme-eng",
8143
+ completedAt: new Date(),
8144
+ totalCount: 2,
8145
+ lastError: null,
8146
+ rateLimitResetAt: null,
8147
+ repositorySelection: "all",
8148
+ repos: [{ fullName: "acme-eng/repo-1" }, { fullName: "acme-eng/repo-2" }],
8149
+ },
8150
+ ];
8151
+
8152
+ it("sync preview lists the selection switch for an 'all' installation", async () => {
8153
+ const { app, events } = setup({ snapshots: allSnapshot() });
8154
+ const res = await app.request(previewUrl, { headers: asAdmin });
8155
+ expect(res.status).toBe(200);
8156
+ const body = (await res.json()) as {
8157
+ selectionSwitches: unknown[];
8158
+ appRemoves: string[];
8159
+ };
8160
+ expect(body.selectionSwitches).toEqual([
8161
+ { org: "acme-eng", repos: ["acme-eng/repo-1"] },
8162
+ ]);
8163
+ expect(body.appRemoves).toEqual(["acme-eng/repo-2"]);
8164
+ // Read-only: only the open-work listing, no GitHub change.
8165
+ expect(events.map((e) => e[0])).toEqual(["list"]);
8166
+ });
8167
+
8168
+ it("sync apply switches before removing, folds the removal and audits once", async () => {
8169
+ const { app, audits, events } = setup({ snapshots: allSnapshot() });
8170
+ const res = await apply(app, {
8171
+ appRemoves: ["acme-eng/repo-2"],
8172
+ agentRemoves: ["acme-eng/repo-2"],
8173
+ });
8174
+ expect(res.status).toBe(200);
8175
+ expect(await res.json()).toMatchObject({
8176
+ status: "applied",
8177
+ appRemoves: ["acme-eng/repo-2"],
8178
+ selectionSwitches: [{ org: "acme-eng", repos: ["acme-eng/repo-1"] }],
8179
+ });
8180
+ expect(events.map((e) => e[0])).toEqual([
8181
+ "switch",
8182
+ "setRepos",
8183
+ "audit",
8184
+ "block",
8185
+ ]);
8186
+ expect(events[0]).toEqual(["switch", ["repo-1"]]);
8187
+ expect(audits[0]?.diff).toMatchObject({
8188
+ installationRemoves: ["acme-eng/repo-2"],
8189
+ selectionSwitches: [{ org: "acme-eng", repos: ["acme-eng/repo-1"] }],
8190
+ });
8191
+ });
8192
+
8193
+ it("sync apply: a 403 on the switch is a 502 naming the missing permission, with a failed audit", async () => {
8194
+ const { app, audits } = setup({
8195
+ snapshots: allSnapshot(),
8196
+ override: { [`PATCH ${INST}/501/repositories`]: "install_selection_403" },
8197
+ });
8198
+ const res = await apply(app, { appRemoves: ["acme-eng/repo-2"] });
8199
+ expect(res.status).toBe(502);
8200
+ expect(JSON.stringify(await res.json())).toContain(
8201
+ "enterprise_organization_installation_repositories",
8202
+ );
8203
+ expect(audits).toHaveLength(1);
8204
+ expect(audits[0]).toMatchObject({ result: { status: "failed" } });
8205
+ expect(audits[0]?.diff).toMatchObject({ installationRemoves: [] });
8206
+ });
8207
+
8120
8208
  it("sync apply: noop when nothing confirmed still applies; 400 for bad names", async () => {
8121
8209
  const { app, audits } = setup();
8122
8210
  const res = await apply(app, { appRemoves: ["acme-eng/repo-1"] });
package/src/agents-api.ts CHANGED
@@ -766,6 +766,13 @@ const SkippedOrgsSchema = z.array(
766
766
  }),
767
767
  );
768
768
 
769
+ const SelectionSwitchesSchema = z
770
+ .array(z.object({ org: z.string(), repos: z.array(z.string()) }))
771
+ .openapi({
772
+ description:
773
+ "Orgs whose agent App installation is on All repositories. Sync switches each to Selected repositories (first 50 repos in the switch, the rest added in batches) before any add or remove; `repos` is the resulting list: the installed repos minus the org's confirmed removals. An org the bound user can push to nothing in is skipped (see `skippedOrgs`) and stays on All repositories.",
774
+ });
775
+
769
776
  const GithubSyncPreviewSchema = z
770
777
  .object({
771
778
  status: z.enum(["previewed", "skipped"]).openapi({
@@ -785,6 +792,7 @@ const GithubSyncPreviewSchema = z
785
792
  description:
786
793
  "Configured agent repos the bound user can no longer push to. The agent's repos are never added to.",
787
794
  }),
795
+ selectionSwitches: SelectionSwitchesSchema.optional(),
788
796
  skippedOrgs: SkippedOrgsSchema.optional().openapi({
789
797
  description:
790
798
  "Orgs whose access listing is missing, partial or failed, whose cached access data is incomplete or stale, or whose lookup App is not installed or installed on selected repositories only; nothing there is added or removed. `reason` says why (for stale data, when it was checked).",
@@ -827,6 +835,7 @@ const GithubSyncApplyResultSchema = z
827
835
  appAdds: z.array(z.string()).optional(),
828
836
  appRemoves: z.array(z.string()).optional(),
829
837
  agentRemoves: z.array(z.string()).optional(),
838
+ selectionSwitches: SelectionSwitchesSchema.optional(),
830
839
  notApplied: z
831
840
  .array(z.object({ repo: z.string(), reason: z.string() }))
832
841
  .optional()
@@ -3589,6 +3598,9 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
3589
3598
  appAdds: plan.appAdds,
3590
3599
  appRemoves: plan.appRemoves,
3591
3600
  agentRemoves: plan.agentRemoves,
3601
+ ...(plan.selectionSwitches?.length
3602
+ ? { selectionSwitches: plan.selectionSwitches }
3603
+ : {}),
3592
3604
  skippedOrgs: plan.skippedOrgs,
3593
3605
  openWork: result.openWork,
3594
3606
  warnings: result.warnings,
@@ -3648,6 +3660,9 @@ export function createAdminApp(deps: AdminDeps): OpenAPIHono<AdminAuthEnv> {
3648
3660
  appAdds: plan.appAdds,
3649
3661
  appRemoves: plan.appRemoves,
3650
3662
  agentRemoves: plan.agentRemoves,
3663
+ ...(plan.selectionSwitches?.length
3664
+ ? { selectionSwitches: plan.selectionSwitches }
3665
+ : {}),
3651
3666
  notApplied: plan.notApplied,
3652
3667
  skippedOrgs: plan.skippedOrgs,
3653
3668
  warnings:
@@ -1587,5 +1587,21 @@
1587
1587
  "body": {
1588
1588
  "message": "Service Unavailable"
1589
1589
  }
1590
+ },
1591
+ "uninstall_success": {
1592
+ "status": 204,
1593
+ "body": null
1594
+ },
1595
+ "uninstall_403": {
1596
+ "status": 403,
1597
+ "body": {
1598
+ "message": "Resource not accessible by integration"
1599
+ }
1600
+ },
1601
+ "uninstall_404": {
1602
+ "status": 404,
1603
+ "body": {
1604
+ "message": "Not Found"
1605
+ }
1590
1606
  }
1591
1607
  }
@@ -55,6 +55,8 @@ export type AgentInstallationClient = Pick<
55
55
  export interface AgentInstallationPageSource extends PageSource {
56
56
  /** The agent App's installation id on the org; throws AppNotInstalledError. Cached. */
57
57
  resolveInstallationId(): Promise<number>;
58
+ /** The installation's repository selection ('all' | 'selected'); null if unknown. Resolves like resolveInstallationId. */
59
+ resolveRepositorySelection?(): Promise<"all" | "selected" | null>;
58
60
  }
59
61
 
60
62
  export interface AgentInstallationSourceOptions {
@@ -78,23 +80,34 @@ export function agentInstallationPageSource(
78
80
  opts: AgentInstallationSourceOptions,
79
81
  ): AgentInstallationPageSource {
80
82
  const { client, org, appId, identity } = opts;
81
- let installationId: Promise<number> | undefined;
82
- const resolveInstallationId = (): Promise<number> => {
83
- installationId ??= client
83
+ let installation:
84
+ | Promise<{ id: number; selection: "all" | "selected" | null }>
85
+ | undefined;
86
+ const resolveInstallation = () => {
87
+ installation ??= client
84
88
  .listOrgInstallations(org, identity?.accountId)
85
89
  .then((installs) => {
86
90
  const found = matchInstallation(installs, appId, identity);
87
91
  if (!found) throw new AppNotInstalledError(appId, org);
88
- return found.id;
92
+ const sel = found.repositorySelection;
93
+ return {
94
+ id: found.id,
95
+ // "none" or an absent value is unknown, never "all".
96
+ selection: sel === "all" || sel === "selected" ? sel : null,
97
+ };
89
98
  });
90
99
  // Do not cache a failure: a later page or run may succeed.
91
- installationId.catch(() => {
92
- installationId = undefined;
100
+ installation.catch(() => {
101
+ installation = undefined;
93
102
  });
94
- return installationId;
103
+ return installation;
95
104
  };
105
+ const resolveInstallationId = async (): Promise<number> =>
106
+ (await resolveInstallation()).id;
96
107
  return {
97
108
  resolveInstallationId,
109
+ resolveRepositorySelection: async () =>
110
+ (await resolveInstallation()).selection,
98
111
  async fetchPage(page: number): Promise<RepoPage> {
99
112
  const id = await resolveInstallationId();
100
113
  const res = await client.listInstallationRepositoriesPage(
@@ -158,8 +171,10 @@ export async function crawlAgentInstallation(
158
171
  appId: agent.appId,
159
172
  identity: identityOf(agent),
160
173
  });
174
+ let selection: "all" | "selected" | null;
161
175
  try {
162
- await source.resolveInstallationId();
176
+ selection = (await source.resolveRepositorySelection?.()) ?? null;
177
+ if (!source.resolveRepositorySelection) await source.resolveInstallationId();
163
178
  } catch (err) {
164
179
  if (!(err instanceof AppNotInstalledError)) {
165
180
  // Let the engine record GitHub failures and rate limits on the snapshot.
@@ -177,10 +192,14 @@ export async function crawlAgentInstallation(
177
192
  nextAttemptAt: null,
178
193
  rateLimitResetAt: null,
179
194
  lastTickAt: now,
195
+ repositorySelection: null,
180
196
  });
181
197
  const swept = await store.sweepGeneration(snap.id);
182
198
  return { outcome: "not_installed", pagesFetched: 0, swept };
183
199
  }
200
+ // Record the selection on every crawl; null clears a stale value. A GitHub
201
+ // failure above returns early and leaves the previous value untouched.
202
+ await store.upsertSnapshot(key, { repositorySelection: selection });
184
203
  return crawlRepos({ ...engineOpts(), key, source });
185
204
 
186
205
  function engineOpts() {
@@ -77,7 +77,13 @@ class MemoryStore implements CrawlStore {
77
77
  }
78
78
 
79
79
  interface FakeClientOpts {
80
- installs?: { id: number; appId?: number; appSlug?: string; clientId?: string }[];
80
+ installs?: {
81
+ id: number;
82
+ appId?: number;
83
+ appSlug?: string;
84
+ clientId?: string;
85
+ repositorySelection?: "all" | "selected" | "none";
86
+ }[];
81
87
  total?: number;
82
88
  perPage?: number;
83
89
  failPage?: (page: number) => Error | undefined;
@@ -376,3 +382,72 @@ describe("lookupAccountKeys", () => {
376
382
  expect(lookupAccountKeys("acct")).not.toContain("");
377
383
  });
378
384
  });
385
+
386
+ describe("crawlAgentInstallation repository selection (GIS-1.1)", () => {
387
+ const run = (store: MemoryStore, client: AgentInstallationClient) =>
388
+ crawlAgentInstallation({
389
+ agent: agent(),
390
+ org: "acme",
391
+ client,
392
+ store,
393
+ clock,
394
+ });
395
+ const selection = (store: MemoryStore) =>
396
+ (store.snap as unknown as Record<string, unknown> | null)
397
+ ?.repositorySelection;
398
+
399
+ it.each(["all", "selected"] as const)("records %s", async (value) => {
400
+ const store = new MemoryStore();
401
+ const { client } = fakeClient({
402
+ installs: [{ id: 501, appId: 777, repositorySelection: value }],
403
+ });
404
+ await run(store, client);
405
+ expect(selection(store)).toBe(value);
406
+ });
407
+
408
+ it("records null when the listing omits it or says none", async () => {
409
+ for (const repositorySelection of [undefined, "none" as const]) {
410
+ const store = new MemoryStore();
411
+ const { client } = fakeClient({
412
+ installs: [{ id: 501, appId: 777, repositorySelection }],
413
+ });
414
+ await run(store, client);
415
+ expect(selection(store)).toBeNull();
416
+ }
417
+ });
418
+
419
+ it("clears a previous value when the App is not installed", async () => {
420
+ const store = new MemoryStore();
421
+ await run(
422
+ store,
423
+ fakeClient({
424
+ installs: [{ id: 501, appId: 777, repositorySelection: "all" }],
425
+ }).client,
426
+ );
427
+ expect(selection(store)).toBe("all");
428
+ const res = await run(store, fakeClient({ installs: [] }).client);
429
+ expect(res.outcome).toBe("not_installed");
430
+ expect(selection(store)).toBeNull();
431
+ });
432
+
433
+ it("keeps the previous value when listing installations fails", async () => {
434
+ const store = new MemoryStore();
435
+ await run(
436
+ store,
437
+ fakeClient({
438
+ installs: [{ id: 501, appId: 777, repositorySelection: "selected" }],
439
+ }).client,
440
+ );
441
+ const failing: AgentInstallationClient = {
442
+ async listOrgInstallations() {
443
+ throw new GithubEnterpriseError("server", "boom");
444
+ },
445
+ async listInstallationRepositoriesPage() {
446
+ throw new GithubEnterpriseError("server", "boom");
447
+ },
448
+ };
449
+ const res = await run(store, failing);
450
+ expect(res.outcome).toBe("failed");
451
+ expect(selection(store)).toBe("selected");
452
+ });
453
+ });