@aviaratech/ai-delivery 0.3.33 → 0.3.35

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 (100) hide show
  1. package/README.md +70 -3
  2. package/dist/boardReconcile.test.d.ts +1 -0
  3. package/dist/boardReconcile.test.js +1685 -0
  4. package/dist/boardReconcile.test.js.map +1 -0
  5. package/dist/cli.js +37 -1
  6. package/dist/cli.js.map +1 -1
  7. package/dist/cliResult.js +21 -1
  8. package/dist/cliResult.js.map +1 -1
  9. package/dist/cliResult.test.js +82 -0
  10. package/dist/cliResult.test.js.map +1 -1
  11. package/dist/config/deliveryConfig.d.ts +32 -0
  12. package/dist/config/deliveryConfig.js +5 -0
  13. package/dist/config/deliveryConfig.js.map +1 -1
  14. package/dist/config/deliveryConfig.test.js +67 -0
  15. package/dist/config/deliveryConfig.test.js.map +1 -1
  16. package/dist/currentTrackingScenario.test.js +6 -4
  17. package/dist/currentTrackingScenario.test.js.map +1 -1
  18. package/dist/directoryIndependent.test.js +2 -2
  19. package/dist/directoryIndependent.test.js.map +1 -1
  20. package/dist/dispatch.d.ts +1 -1
  21. package/dist/dispatch.js +33 -1
  22. package/dist/dispatch.js.map +1 -1
  23. package/dist/errors.d.ts +13 -0
  24. package/dist/errors.js +15 -0
  25. package/dist/errors.js.map +1 -1
  26. package/dist/fixtures/inertEntrypoints.js +7 -0
  27. package/dist/fixtures/inertEntrypoints.js.map +1 -1
  28. package/dist/github/commandIdentityPolicy.js +1 -0
  29. package/dist/github/commandIdentityPolicy.js.map +1 -1
  30. package/dist/github/discovery.d.ts +2 -0
  31. package/dist/github/discovery.js +17 -3
  32. package/dist/github/discovery.js.map +1 -1
  33. package/dist/github/nativeIssueMetadata.d.ts +27 -0
  34. package/dist/github/nativeIssueMetadata.js +58 -0
  35. package/dist/github/nativeIssueMetadata.js.map +1 -1
  36. package/dist/github/projectDelivery.d.ts +36 -0
  37. package/dist/github/projectDelivery.js +136 -31
  38. package/dist/github/projectDelivery.js.map +1 -1
  39. package/dist/github/relationships.d.ts +5 -2
  40. package/dist/github/relationships.js +59 -2
  41. package/dist/github/relationships.js.map +1 -1
  42. package/dist/issue.d.ts +72 -3
  43. package/dist/issue.js +354 -117
  44. package/dist/issue.js.map +1 -1
  45. package/dist/issueBatchUpdate.test.js +229 -12
  46. package/dist/issueBatchUpdate.test.js.map +1 -1
  47. package/dist/issueDates.test.d.ts +1 -0
  48. package/dist/issueDates.test.js +253 -0
  49. package/dist/issueDates.test.js.map +1 -0
  50. package/dist/issueTracking.test.js +436 -11
  51. package/dist/issueTracking.test.js.map +1 -1
  52. package/dist/mcp/index.js +4 -0
  53. package/dist/mcp/index.js.map +1 -1
  54. package/dist/mcp/tools.d.ts +598 -0
  55. package/dist/mcp/tools.js +10 -0
  56. package/dist/mcp/tools.js.map +1 -1
  57. package/dist/pluginInstaller.js +21 -23
  58. package/dist/pluginInstaller.js.map +1 -1
  59. package/dist/pluginInstaller.test.js +121 -1
  60. package/dist/pluginInstaller.test.js.map +1 -1
  61. package/dist/pluginPackaging.test.js +135 -6
  62. package/dist/pluginPackaging.test.js.map +1 -1
  63. package/dist/pr.d.ts +7 -0
  64. package/dist/pr.js +104 -99
  65. package/dist/pr.js.map +1 -1
  66. package/dist/pr.test.js +202 -223
  67. package/dist/pr.test.js.map +1 -1
  68. package/dist/prAssociation.test.js +11 -10
  69. package/dist/prAssociation.test.js.map +1 -1
  70. package/dist/review.d.ts +1 -0
  71. package/dist/review.js +7 -6
  72. package/dist/review.js.map +1 -1
  73. package/dist/review.test.js +8 -4
  74. package/dist/review.test.js.map +1 -1
  75. package/dist/services/boardReconcileService.d.ts +1204 -0
  76. package/dist/services/boardReconcileService.js +1571 -0
  77. package/dist/services/boardReconcileService.js.map +1 -0
  78. package/dist/services/deliveryAdmission.d.ts +2 -0
  79. package/dist/services/deliveryAdmission.js +2 -2
  80. package/dist/services/deliveryAdmission.js.map +1 -1
  81. package/dist/setup.test.js +474 -32
  82. package/dist/setup.test.js.map +1 -1
  83. package/dist/stdoutRegression.test.js +27 -2
  84. package/dist/stdoutRegression.test.js.map +1 -1
  85. package/dist/targetPolicyRoutes.test.js +2 -2
  86. package/dist/targetPolicyRoutes.test.js.map +1 -1
  87. package/dist/verification.js +38 -2
  88. package/dist/verification.js.map +1 -1
  89. package/dist/verificationGate.test.js +25 -2
  90. package/dist/verificationGate.test.js.map +1 -1
  91. package/dist/version.d.ts +6 -0
  92. package/dist/version.js +16 -1
  93. package/dist/version.js.map +1 -1
  94. package/package.json +2 -1
  95. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  96. package/plugins/ai-delivery/plugin.json +1 -1
  97. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +24 -0
  98. package/plugins/ai-delivery/runtime/dist/cli.js +68 -67
  99. package/plugins/ai-delivery/runtime/package.json +1 -1
  100. package/plugins/ai-delivery/skills/pr-handoff/SKILL.md +4 -4
package/dist/issue.js CHANGED
@@ -2,10 +2,10 @@ import { types } from 'node:util';
2
2
  import { z } from 'zod';
3
3
  import { loadDeliveryConfig, WipLimits } from './config/deliveryConfig.js';
4
4
  import { digestValue } from './delivery/legacy.js';
5
- import { DeliveryError, getRateLimitDiagnostics, getMachineRequestDiagnostics, } from './errors.js';
5
+ import { CollectionLimitError, DeliveryError, getRateLimitDiagnostics, getMachineRequestDiagnostics, setMachineRequestDiagnostics, } from './errors.js';
6
6
  import { createDeliveryGitHubClients } from './github/client.js';
7
- import { NATIVE_ISSUE_API_VERSION, clearConfiguredNativeIssuePoints, getConfiguredNativeIssueMetadata, nativeIssueSettingsFromDeliveryConfig, setConfiguredNativeIssueMetadata, } from './github/nativeIssueMetadata.js';
8
- import { getIssueProjectStatus, getProjectDeliveryConfiguration, projectSettingsFromDeliveryConfig, syncIssueProjectStatus, } from './github/projectDelivery.js';
7
+ import { NATIVE_ISSUE_API_VERSION, applyNativeIssueDates, prepareNativeIssueDates, parseConfiguredNativeIssueMetadata, clearConfiguredNativeIssuePoints, getConfiguredNativeIssueMetadata, nativeIssueSettingsFromDeliveryConfig, setConfiguredNativeIssueMetadata, } from './github/nativeIssueMetadata.js';
8
+ import { getIssueProjectStatus, assertIssueProjectWritable, getProjectDeliveryConfiguration, projectSettingsFromDeliveryConfig, syncIssueProjectStatus, } from './github/projectDelivery.js';
9
9
  import { getNativeBlockerRelationships, hasNativeSubIssues, linkBlockedBy, replaceBlockedBy, replaceParentIssue, resolveNativeRelationshipTargets, } from './github/relationships.js';
10
10
  import { prepareBlockerGuard, OverrideReason } from './services/blockerGuardService.js';
11
11
  import {} from './github/repo.js';
@@ -103,6 +103,8 @@ export async function journalIssueStart(context, issueNumber) {
103
103
  }
104
104
  export async function loadDeliveryContext(input) {
105
105
  const loaded = await loadDeliveryConfig(input.repoRoot, {
106
+ ...(input.readPageLimit === undefined ? {} : { readPageLimit: input.readPageLimit }),
107
+ ...(input.requireWritableProject === undefined ? {} : { requireWritableProject: input.requireWritableProject }),
106
108
  ...(input.repository === undefined ? {} : { repository: input.repository }),
107
109
  ...(input.personalAuth === undefined ? {} : { personalAuth: input.personalAuth }),
108
110
  ...(input.signal === undefined ? {} : { signal: input.signal }),
@@ -131,7 +133,15 @@ export async function loadDeliveryContext(input) {
131
133
  settings: projectSettingsFromDeliveryConfig(config),
132
134
  writable: true,
133
135
  };
134
- return { clients, config, configuration: loaded, projectConfiguration, repo, root: '' };
136
+ return {
137
+ clients,
138
+ config,
139
+ configuration: loaded,
140
+ ...(input.requireWritableProject === false ? {} : { projectConfiguration }),
141
+ repo,
142
+ root: '',
143
+ ...(input.readPageLimit === undefined ? {} : { readPageLimit: input.readPageLimit }),
144
+ };
135
145
  }
136
146
  async function labels(context, input) {
137
147
  const selected = input ?? [];
@@ -142,6 +152,13 @@ async function labels(context, input) {
142
152
  return [];
143
153
  const available = new Set();
144
154
  for (let page = 1; page <= 100; page++) {
155
+ if (context.readPageLimit !== undefined && page > context.readPageLimit)
156
+ throw new CollectionLimitError({
157
+ collection: 'repository-labels',
158
+ pagesRequested: page - 1,
159
+ rowsObserved: available.size,
160
+ limit: context.readPageLimit,
161
+ });
145
162
  const batch = (await context.clients.rest.issues.listLabelsForRepo({ ...context.repo, page, per_page: 100 })).data;
146
163
  for (const label of batch)
147
164
  available.add(label.name.toLowerCase());
@@ -287,6 +304,7 @@ export async function createIssue(context, input) {
287
304
  if (context.clients.role !== 'author')
288
305
  throw new DeliveryError('Issue writes require the configured author role.');
289
306
  const prepared = prepareIssueWrite(input);
307
+ const dateChanges = await prepareIssueDates(context, input);
290
308
  input = {
291
309
  ...input,
292
310
  title: prepared.issue.title,
@@ -346,6 +364,7 @@ export async function createIssue(context, input) {
346
364
  rest: clients.rest,
347
365
  settings: nativeIssueSettingsFromDeliveryConfig(config),
348
366
  });
367
+ await applyNativeIssueDates({ changes: dateChanges, issueNumber, ...repo, rest: clients.rest });
349
368
  if (input.parentIssueNumber !== undefined)
350
369
  await replaceParentIssue({
351
370
  graphql: clients.graphql,
@@ -433,7 +452,7 @@ const ListedIssue = z.object({
433
452
  html_url: z.url(),
434
453
  updated_at: z.iso.datetime({ offset: true }),
435
454
  });
436
- function capacityNextPage(response, page, perPage) {
455
+ export function capacityNextPage(response, page, perPage) {
437
456
  if (!Array.isArray(response.data) || response.data.length > perPage)
438
457
  throw new DeliveryError('WIP capacity pagination returned invalid native data.');
439
458
  const link = response.headers?.link;
@@ -461,8 +480,16 @@ async function issueFieldPages(context, route, parameters, maxPages) {
461
480
  const values = [];
462
481
  const seenPages = new Set();
463
482
  for (let page = 1;; page += 1) {
464
- if (maxPages !== undefined && page > maxPages)
483
+ if (maxPages !== undefined && page > maxPages) {
484
+ if (context.readPageLimit !== undefined)
485
+ throw new CollectionLimitError({
486
+ collection: route.includes('/orgs/') ? 'native-field-catalog' : 'native-field-values',
487
+ pagesRequested: page - 1,
488
+ rowsObserved: values.length,
489
+ limit: maxPages,
490
+ });
465
491
  throw new DeliveryError('WIP capacity native field pagination is incomplete.');
492
+ }
466
493
  const response = await context.clients.rest.request(route, {
467
494
  ...parameters,
468
495
  headers: { 'X-GitHub-Api-Version': NATIVE_ISSUE_API_VERSION },
@@ -480,6 +507,84 @@ async function issueFieldPages(context, route, parameters, maxPages) {
480
507
  return values;
481
508
  }
482
509
  }
510
+ async function readIssueFieldCatalog(context, capacityRead = false) {
511
+ const catalog = z
512
+ .array(FieldCatalogEntry)
513
+ .parse(await issueFieldPages(context, 'GET /orgs/{org}/issue-fields', { org: context.config.native.organization }, capacityRead ? Math.min(context.readPageLimit ?? 20, 20) : context.readPageLimit));
514
+ if (new Set(catalog.map((field) => field.name)).size !== catalog.length ||
515
+ new Set(catalog.map((field) => field.id)).size !== catalog.length)
516
+ throw new DeliveryError('Native issue field catalog has duplicate identities or names.');
517
+ return catalog;
518
+ }
519
+ async function readIssueFields(context, issueNumber, catalog, capacityRead = false) {
520
+ const fields = Object.fromEntries(catalog.map((field) => [field.name, null]));
521
+ const values = z.array(FieldValueEntry).parse(await issueFieldPages(context, 'GET /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values', {
522
+ ...context.repo,
523
+ issue_number: issueNumber,
524
+ }, capacityRead ? Math.min(context.readPageLimit ?? 20, 20) : context.readPageLimit));
525
+ const observed = new Set();
526
+ for (const field of values) {
527
+ const definition = catalog.find((candidate) => candidate.id === field.issue_field_id);
528
+ if (!definition ||
529
+ definition.name !== field.issue_field_name ||
530
+ definition.data_type !== field.data_type ||
531
+ observed.has(field.issue_field_id))
532
+ throw new DeliveryError('Native issue field readback conflicts with its catalog.');
533
+ observed.add(field.issue_field_id);
534
+ if (capacityRead &&
535
+ (field.data_type === 'single_select'
536
+ ? field.single_select_option === undefined && field.value !== null
537
+ : field.data_type === 'multi_select'
538
+ ? field.multi_select_options === undefined && field.value !== null
539
+ : field.value === undefined))
540
+ throw new DeliveryError('WIP capacity native field value payload is missing.');
541
+ // Existing issue-info metadata accepts configured option names as raw values.
542
+ // Preserve that exact compatibility without treating numeric option IDs as names.
543
+ const configuredOptionName = !capacityRead &&
544
+ field.data_type === 'single_select' &&
545
+ typeof field.value === 'string' &&
546
+ ((field.issue_field_name === context.config.native.points.name &&
547
+ String(field.issue_field_id) === context.config.native.points.databaseId &&
548
+ context.config.native.points.values.includes(field.value)) ||
549
+ (field.issue_field_name === context.config.native.priority.name &&
550
+ String(field.issue_field_id) === context.config.native.priority.databaseId &&
551
+ context.config.native.priority.values.includes(field.value)))
552
+ ? field.value
553
+ : undefined;
554
+ if (((field.data_type === 'single_select' && !field.single_select_option && configuredOptionName === undefined) ||
555
+ (field.data_type === 'multi_select' && field.multi_select_options === undefined)) &&
556
+ field.value !== null &&
557
+ field.value !== undefined)
558
+ throw new DeliveryError('Native select field omitted its named option readback.');
559
+ const value = field.data_type === 'single_select'
560
+ ? (field.single_select_option?.name ?? configuredOptionName ?? null)
561
+ : field.data_type === 'multi_select'
562
+ ? field.multi_select_options?.map((option) => option.name)
563
+ : field.value;
564
+ if (field.data_type === 'date' && value !== null && value !== undefined && !z.iso.date().safeParse(value).success)
565
+ throw new DeliveryError('Native date field has an invalid date value.');
566
+ if (value === null || value === undefined)
567
+ fields[definition.name] = null;
568
+ else if (field.data_type === 'number'
569
+ ? typeof value === 'number' && Number.isFinite(value)
570
+ : field.data_type === 'multi_select'
571
+ ? Array.isArray(value)
572
+ : typeof value === 'string')
573
+ fields[definition.name] = value;
574
+ else
575
+ throw new DeliveryError('Native issue field has an invalid value type.');
576
+ }
577
+ return { fields, values, catalog };
578
+ }
579
+ /** The same native-field composition used by issue-info, without unrelated Project/relationship reads. */
580
+ export async function readIssueNativeFields(context, issueNumber) {
581
+ return readIssueFields(context, issueNumber, await readIssueFieldCatalog(context));
582
+ }
583
+ async function prepareIssueDates(context, patch) {
584
+ if (patch.startDate === undefined && patch.targetDate === undefined)
585
+ return [];
586
+ return prepareNativeIssueDates(patch, await readIssueFieldCatalog(context));
587
+ }
483
588
  /** A bounded GitHub page; local filters can produce an empty page with a nextPage. */
484
589
  export async function listIssues(context, input, options = {}) {
485
590
  const page = input.page ?? 1;
@@ -537,12 +642,7 @@ export async function listIssues(context, input, options = {}) {
537
642
  ? page + 1
538
643
  : null;
539
644
  }
540
- const catalog = z
541
- .array(FieldCatalogEntry)
542
- .parse(await issueFieldPages(context, 'GET /orgs/{org}/issue-fields', { org: context.config.native.organization }, options.capacityRead ? 20 : undefined));
543
- if (new Set(catalog.map((field) => field.name)).size !== catalog.length ||
544
- new Set(catalog.map((field) => field.id)).size !== catalog.length)
545
- throw new DeliveryError('Native issue field catalog has duplicate identities or names.');
645
+ const catalog = await readIssueFieldCatalog(context, options.capacityRead);
546
646
  const issues = [];
547
647
  const seen = new Set();
548
648
  for (const entry of raw) {
@@ -581,6 +681,7 @@ export async function listIssues(context, input, options = {}) {
581
681
  issueNumber: current.number,
582
682
  repo: context.repo,
583
683
  requireRepositoryIdentity: true,
684
+ ...(context.readPageLimit === undefined ? {} : { maxPages: context.readPageLimit, issueNodeId: current.node_id }),
584
685
  });
585
686
  const localParent = relationships.parentRepository?.toLowerCase() === `${context.repo.owner}/${context.repo.repo}`.toLowerCase()
586
687
  ? relationships.parentNumber
@@ -592,56 +693,16 @@ export async function listIssues(context, input, options = {}) {
592
693
  graphql: context.clients.graphql,
593
694
  issueNodeId: current.node_id,
594
695
  ...(options.capacityRead ? { capacityRead: true, maxPages: 20 } : {}),
696
+ ...(context.readPageLimit === undefined
697
+ ? {}
698
+ : { maxPages: Math.min(context.readPageLimit, options.capacityRead ? 20 : context.readPageLimit) }),
595
699
  org: context.config.native.organization,
596
700
  ...(context.projectConfiguration ? { configuration: context.projectConfiguration } : {}),
597
701
  settings: projectSettingsFromDeliveryConfig(context.config),
598
702
  });
599
703
  if (input.projectStatus !== undefined && (project?.status ?? null) !== input.projectStatus)
600
704
  continue;
601
- const fields = Object.fromEntries(catalog.map((field) => [field.name, null]));
602
- const values = z.array(FieldValueEntry).parse(await issueFieldPages(context, 'GET /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values', {
603
- ...context.repo,
604
- issue_number: current.number,
605
- }, options.capacityRead ? 20 : undefined));
606
- const observed = new Set();
607
- for (const field of values) {
608
- const definition = catalog.find((candidate) => candidate.id === field.issue_field_id);
609
- if (!definition ||
610
- definition.name !== field.issue_field_name ||
611
- definition.data_type !== field.data_type ||
612
- observed.has(field.issue_field_id))
613
- throw new DeliveryError('Native issue field readback conflicts with its catalog.');
614
- observed.add(field.issue_field_id);
615
- if (options.capacityRead &&
616
- (field.data_type === 'single_select'
617
- ? field.single_select_option === undefined && field.value !== null
618
- : field.data_type === 'multi_select'
619
- ? field.multi_select_options === undefined && field.value !== null
620
- : field.value === undefined))
621
- throw new DeliveryError('WIP capacity native field value payload is missing.');
622
- if (((field.data_type === 'single_select' && !field.single_select_option) ||
623
- (field.data_type === 'multi_select' && field.multi_select_options === undefined)) &&
624
- field.value !== null &&
625
- field.value !== undefined)
626
- throw new DeliveryError('Native select field omitted its named option readback.');
627
- const value = field.data_type === 'single_select'
628
- ? (field.single_select_option?.name ?? null)
629
- : field.data_type === 'multi_select'
630
- ? field.multi_select_options?.map((option) => option.name)
631
- : field.value;
632
- if (field.data_type === 'date' && value !== null && value !== undefined && !z.iso.date().safeParse(value).success)
633
- throw new DeliveryError('Native date field has an invalid date value.');
634
- if (value === null || value === undefined)
635
- fields[definition.name] = null;
636
- else if (field.data_type === 'number'
637
- ? typeof value === 'number' && Number.isFinite(value)
638
- : field.data_type === 'multi_select'
639
- ? Array.isArray(value)
640
- : typeof value === 'string')
641
- fields[definition.name] = value;
642
- else
643
- throw new DeliveryError('Native issue field has an invalid value type.');
644
- }
705
+ const { fields } = await readIssueFields(context, current.number, catalog, options.capacityRead);
645
706
  issues.push({
646
707
  ...(options.capacityRead
647
708
  ? { nodeId: current.node_id, fieldIds: Object.fromEntries(catalog.map((field) => [field.name, field.id])) }
@@ -718,6 +779,20 @@ export async function readIssueClosure(context, issueNumber) {
718
779
  : { number: parsed.duplicateOf.number, repository: parsed.duplicateOf.repository.nameWithOwner },
719
780
  };
720
781
  }
782
+ const incompleteUpdates = new WeakMap();
783
+ /** Native writes may have committed; this is never an ordinary success or a safe full retry. */
784
+ export class IssueUpdateIncompleteError extends DeliveryError {
785
+ result;
786
+ constructor(result) {
787
+ super('Issue update is incomplete; reconcile native state and only remaining Project work.');
788
+ this.result = result;
789
+ incompleteUpdates.set(this, result);
790
+ }
791
+ }
792
+ /** Identity-bound results do not inspect hostile error proxies or accessors. */
793
+ export function getIncompleteIssueUpdate(error) {
794
+ return typeof error === 'object' && error !== null ? incompleteUpdates.get(error) : undefined;
795
+ }
721
796
  function updateProjectStatus(info, input) {
722
797
  return info.state === 'closed' || info.projectStatus === 'Done'
723
798
  ? 'Done'
@@ -745,6 +820,7 @@ async function prepareIssueUpdate(context, input) {
745
820
  (!Number.isSafeInteger(input.supersededBy) || input.supersededBy <= 0 || input.supersededBy === input.issueNumber))
746
821
  throw new DeliveryError('A superseding issue must be a different positive issue number.');
747
822
  const { clients, config, repo } = context;
823
+ const dateChanges = await prepareIssueDates(context, input);
748
824
  const currentContent = await issueInfo(context, input.issueNumber);
749
825
  const prepared = prepareIssueWrite(input, currentContent);
750
826
  input = {
@@ -855,6 +931,21 @@ async function prepareIssueUpdate(context, input) {
855
931
  const closureBody = closeReason === undefined
856
932
  ? undefined
857
933
  : `Requested closure reason: ${closeReason}.${input.supersededBy === undefined ? '' : `\nSuperseded by ${repo.owner}/${repo.repo}#${String(input.supersededBy)}.`}`;
934
+ const target = (await clients.rest.issues.get({ ...repo, issue_number: input.issueNumber })).data;
935
+ if (target.number !== input.issueNumber ||
936
+ 'pull_request' in target ||
937
+ !target.node_id ||
938
+ target.html_url !== currentContent.url ||
939
+ new URL(target.html_url).pathname.toLowerCase() !==
940
+ `/${repo.owner}/${repo.repo}/issues/${String(input.issueNumber)}`.toLowerCase())
941
+ throw new DeliveryError('History target is not the requested issue.');
942
+ await assertIssueProjectWritable({
943
+ graphql: clients.graphql,
944
+ issueNodeId: target.node_id,
945
+ org: config.native.organization,
946
+ ...(context.projectConfiguration ? { configuration: context.projectConfiguration } : {}),
947
+ settings: projectSettingsFromDeliveryConfig(config),
948
+ });
858
949
  return {
859
950
  input,
860
951
  prepared,
@@ -864,6 +955,8 @@ async function prepareIssueUpdate(context, input) {
864
955
  supersedingIssueId,
865
956
  assertClosure,
866
957
  currentContent,
958
+ nativeTarget: { nodeId: target.node_id, url: target.html_url },
959
+ dateChanges,
867
960
  priorContent,
868
961
  historyBody,
869
962
  closureBody,
@@ -872,9 +965,10 @@ async function prepareIssueUpdate(context, input) {
872
965
  export async function updateIssue(context, input) {
873
966
  return applyIssueUpdate(context, await prepareIssueUpdate(context, input));
874
967
  }
875
- async function applyIssueUpdate(context, plan) {
968
+ async function applyIssueUpdate(context, plan, changes) {
876
969
  const { clients, config, repo } = context;
877
970
  const { input, prepared, acceptedLabels, beforeAdd, closeReason, supersedingIssueId, assertClosure, priorContent, historyBody, closureBody, } = plan;
971
+ const pending = (key) => changes === undefined || key in changes;
878
972
  const historyComment = historyBody === undefined
879
973
  ? undefined
880
974
  : await commentIssue(context, { issueNumber: input.issueNumber, body: historyBody });
@@ -892,32 +986,35 @@ async function applyIssueUpdate(context, plan) {
892
986
  (current.body ?? '') !== priorContent.body)
893
987
  throw new DeliveryError('Issue content changed after preparation; retry against the current title and body.');
894
988
  }
895
- await clients.rest.issues.update({
896
- issue_number: input.issueNumber,
897
- owner: repo.owner,
898
- repo: repo.repo,
899
- ...(input.body === undefined ? {} : { body: input.body }),
900
- ...(input.issueType === undefined ? {} : { type: input.issueType }),
901
- ...(acceptedLabels === undefined ? {} : { labels: acceptedLabels }),
902
- ...(input.milestone === undefined ? {} : { milestone: input.milestone }),
903
- ...(input.state === undefined ? {} : { state: input.state }),
904
- ...(closeReason === undefined
905
- ? {}
906
- : { state_reason: closeReason, headers: { 'X-GitHub-Api-Version': NATIVE_ISSUE_API_VERSION } }),
907
- ...(closeReason !== 'duplicate' || supersedingIssueId === undefined
908
- ? {}
909
- : { duplicate_issue_id: supersedingIssueId }),
910
- ...(input.title === undefined ? {} : { title: input.title }),
911
- });
989
+ if (['body', 'issueType', 'labels', 'milestone', 'state', 'closeReason', 'supersededBy', 'title'].some(pending))
990
+ await clients.rest.issues.update({
991
+ issue_number: input.issueNumber,
992
+ owner: repo.owner,
993
+ repo: repo.repo,
994
+ ...(input.body === undefined || !pending('body') ? {} : { body: input.body }),
995
+ ...(input.issueType === undefined || !pending('issueType') ? {} : { type: input.issueType }),
996
+ ...(acceptedLabels === undefined || !pending('labels') ? {} : { labels: acceptedLabels }),
997
+ ...(input.milestone === undefined || !pending('milestone') ? {} : { milestone: input.milestone }),
998
+ ...(input.state === undefined || !pending('state') ? {} : { state: input.state }),
999
+ ...(closeReason === undefined || (!pending('closeReason') && !pending('state'))
1000
+ ? {}
1001
+ : { state_reason: closeReason, headers: { 'X-GitHub-Api-Version': NATIVE_ISSUE_API_VERSION } }),
1002
+ ...(closeReason !== 'duplicate' ||
1003
+ supersedingIssueId === undefined ||
1004
+ (!pending('supersededBy') && !pending('state'))
1005
+ ? {}
1006
+ : { duplicate_issue_id: supersedingIssueId }),
1007
+ ...(input.title === undefined || !pending('title') ? {} : { title: input.title }),
1008
+ });
912
1009
  const closure = closeReason === undefined ? undefined : await readIssueClosure(context, input.issueNumber);
913
1010
  if (closure !== undefined)
914
1011
  assertClosure(closure);
915
- if (input.points !== undefined || input.priority !== undefined)
1012
+ if ((input.points !== undefined && pending('points')) || (input.priority !== undefined && pending('priority')))
916
1013
  await setConfiguredNativeIssueMetadata({
917
1014
  issueNumber: input.issueNumber,
918
1015
  metadata: {
919
- ...(input.points === undefined ? {} : { points: input.points }),
920
- ...(input.priority === undefined ? {} : { priority: input.priority }),
1016
+ ...(input.points === undefined || !pending('points') ? {} : { points: input.points }),
1017
+ ...(input.priority === undefined || !pending('priority') ? {} : { priority: input.priority }),
921
1018
  },
922
1019
  org: config.native.organization,
923
1020
  owner: repo.owner,
@@ -925,7 +1022,13 @@ async function applyIssueUpdate(context, plan) {
925
1022
  rest: clients.rest,
926
1023
  settings: nativeIssueSettingsFromDeliveryConfig(config),
927
1024
  });
928
- if (input.parentIssueNumber !== undefined)
1025
+ await applyNativeIssueDates({
1026
+ changes: plan.dateChanges.filter((change) => pending(change.name === 'Start date' ? 'startDate' : 'targetDate')),
1027
+ issueNumber: input.issueNumber,
1028
+ ...repo,
1029
+ rest: clients.rest,
1030
+ });
1031
+ if (input.parentIssueNumber !== undefined && pending('parentIssueNumber'))
929
1032
  await replaceParentIssue({
930
1033
  graphql: clients.graphql,
931
1034
  issueNumber: input.issueNumber,
@@ -933,7 +1036,7 @@ async function applyIssueUpdate(context, plan) {
933
1036
  repo,
934
1037
  rest: clients.rest,
935
1038
  });
936
- if (input.parentIssueNumber !== undefined && input.parentIssueNumber !== null)
1039
+ if (input.parentIssueNumber !== undefined && input.parentIssueNumber !== null && pending('parentPoints'))
937
1040
  await clearConfiguredNativeIssuePoints({
938
1041
  issueNumber: input.parentIssueNumber,
939
1042
  org: config.native.organization,
@@ -943,7 +1046,7 @@ async function applyIssueUpdate(context, plan) {
943
1046
  settings: nativeIssueSettingsFromDeliveryConfig(config),
944
1047
  });
945
1048
  try {
946
- if (input.blockedBy !== undefined)
1049
+ if (input.blockedBy !== undefined && pending('blockedBy'))
947
1050
  await replaceBlockedBy({
948
1051
  ...(beforeAdd === undefined ? {} : { beforeAdd }),
949
1052
  blockers: input.blockedBy,
@@ -952,7 +1055,7 @@ async function applyIssueUpdate(context, plan) {
952
1055
  repo,
953
1056
  rest: clients.rest,
954
1057
  });
955
- for (const dependent of new Set(input.blocks ?? []))
1058
+ for (const dependent of new Set(pending('blocks') ? (input.blocks ?? []) : []))
956
1059
  await linkBlockedBy({
957
1060
  ...(beforeAdd === undefined ? {} : { beforeAdd }),
958
1061
  blockers: [input.issueNumber],
@@ -965,18 +1068,98 @@ async function applyIssueUpdate(context, plan) {
965
1068
  catch (error) {
966
1069
  throw new DeliveryError(`Issue #${input.issueNumber} content or metadata may have changed, but dependency tracking did not complete: ${error instanceof Error ? error.message : String(error)}. Inspect native state and resume this existing issue.`);
967
1070
  }
968
- const info = await issueInfo(context, input.issueNumber);
969
- const status = updateProjectStatus(info, input);
970
- const issue = (await clients.rest.issues.get({ issue_number: input.issueNumber, ...repo })).data;
971
- await syncIssueProjectStatus({
972
- graphql: clients.graphql,
973
- issueNodeId: issue.node_id,
974
- org: config.native.organization,
975
- ...(context.projectConfiguration ? { configuration: context.projectConfiguration } : {}),
976
- settings: projectSettingsFromDeliveryConfig(config),
977
- status,
978
- });
979
- const readback = await issueInfo(context, input.issueNumber);
1071
+ let status = updateProjectStatus({ ...plan.currentContent, state: input.state ?? plan.currentContent.state }, input);
1072
+ let readback;
1073
+ let latestProjectStatus = plan.currentContent.projectStatus;
1074
+ const priorRateObservation = clients.rateLimitObservation?.();
1075
+ try {
1076
+ const info = await issueInfo(context, input.issueNumber);
1077
+ latestProjectStatus = info.projectStatus;
1078
+ status = updateProjectStatus(info, input);
1079
+ const target = (await clients.rest.issues.get({ issue_number: input.issueNumber, ...repo })).data;
1080
+ if (target.node_id !== plan.nativeTarget.nodeId ||
1081
+ target.html_url !== plan.nativeTarget.url ||
1082
+ target.number !== input.issueNumber ||
1083
+ 'pull_request' in target)
1084
+ throw new DeliveryError('Native closure readback returned a foreign issue identity.');
1085
+ await syncIssueProjectStatus({
1086
+ graphql: clients.graphql,
1087
+ issueNodeId: target.node_id,
1088
+ org: config.native.organization,
1089
+ ...(context.projectConfiguration ? { configuration: context.projectConfiguration } : {}),
1090
+ settings: projectSettingsFromDeliveryConfig(config),
1091
+ status,
1092
+ });
1093
+ readback = await issueInfo(context, input.issueNumber);
1094
+ if (readback.projectStatus !== status)
1095
+ throw new DeliveryError('Project Status readback disagrees with the requested outcome.');
1096
+ }
1097
+ catch (error) {
1098
+ const observedRate = clients.rateLimitObservation?.();
1099
+ const limit = getRateLimitDiagnostics(error) ?? (observedRate !== priorRateObservation ? observedRate : undefined);
1100
+ const diagnostic = getMachineRequestDiagnostics(error);
1101
+ const cancelled = diagnostic?.code === 'ABORT_ERR' ||
1102
+ (!types.isProxy(error) && error instanceof DOMException && error.name === 'AbortError');
1103
+ const result = {
1104
+ status: 'update-incomplete',
1105
+ ...(limit === undefined ? {} : { rateLimit: limit }),
1106
+ native: {
1107
+ status: 'unknown',
1108
+ repository: `${repo.owner}/${repo.repo}`,
1109
+ issueNumber: input.issueNumber,
1110
+ readback: null,
1111
+ readbackError: limit !== undefined || cancelled
1112
+ ? 'Readback deferred after rate-limit exhaustion or cancellation.'
1113
+ : 'Native issue evidence is unavailable or inconsistent.',
1114
+ },
1115
+ project: {
1116
+ status: localBatchFailureReason(error) === 'The issue delivery Project item is archived and cannot be updated.'
1117
+ ? 'pending'
1118
+ : 'unknown',
1119
+ desiredStatus: input.blockedBy === undefined ? status : null,
1120
+ reason: localBatchFailureReason(error) === 'The issue delivery Project item is archived and cannot be updated.'
1121
+ ? 'archived'
1122
+ : 'unavailable',
1123
+ },
1124
+ recovery: {
1125
+ tool: 'issue_batch_update',
1126
+ instruction: 'Reconcile this existing issue with the original desired fields through issue_batch_update. Do not replay the full issue_update. An archived Project item requires separately authorized restoration before projection-only recovery.',
1127
+ },
1128
+ };
1129
+ if (limit === undefined && !cancelled) {
1130
+ try {
1131
+ const native = await updateProjection(context, plan, true);
1132
+ const desired = await desiredUpdateValues(context, plan);
1133
+ delete desired.projectStatus;
1134
+ if (Object.keys(pendingUpdateValues(desired, native.values)).length)
1135
+ throw new DeliveryError('Issue update readback disagrees with the requested content or state.');
1136
+ if (historyBody !== undefined && !(await hasUpdateComment(context, input.issueNumber, historyBody)))
1137
+ throw new DeliveryError('Issue comment readback disagrees with the authored issue comment.');
1138
+ result.project.desiredStatus = updateProjectStatus({ ...native.readback, projectStatus: latestProjectStatus }, input);
1139
+ result.native = {
1140
+ ...result.native,
1141
+ status: 'confirmed',
1142
+ readback: native.readback,
1143
+ ...(historyComment === undefined ? {} : { historyComment }),
1144
+ ...(closure === undefined || closureComment === undefined
1145
+ ? {}
1146
+ : { closure: { ...closure, supersededBy: input.supersededBy ?? null, comment: closureComment } }),
1147
+ };
1148
+ delete result.native.readbackError;
1149
+ }
1150
+ catch (readbackError) {
1151
+ const latest = clients.rateLimitObservation?.();
1152
+ const readbackLimit = getRateLimitDiagnostics(readbackError) ?? (latest !== priorRateObservation ? latest : undefined);
1153
+ if (readbackLimit !== undefined)
1154
+ result.rateLimit = readbackLimit;
1155
+ /* Missing or contradictory native evidence must remain unknown. */
1156
+ }
1157
+ }
1158
+ const incomplete = new IssueUpdateIncompleteError(result);
1159
+ if (diagnostic !== undefined)
1160
+ setMachineRequestDiagnostics(incomplete, diagnostic);
1161
+ throw incomplete;
1162
+ }
980
1163
  if ((input.title !== undefined && readback.title !== input.title) ||
981
1164
  (input.body !== undefined && readback.body !== input.body) ||
982
1165
  (input.state !== undefined && readback.state !== input.state) ||
@@ -1024,9 +1207,9 @@ async function hasUpdateComment(context, issueNumber, body) {
1024
1207
  await readAuthoredIssueComment(context, issueNumber, matches[0], body, actor);
1025
1208
  return true;
1026
1209
  }
1027
- async function updateProjection(context, plan) {
1210
+ async function updateProjection(context, plan, nativeOnly = false) {
1028
1211
  const { input } = plan;
1029
- const readback = await issueInfo(context, input.issueNumber);
1212
+ const { info: readback } = await readIssueInfo(context, input.issueNumber, !nativeOnly, nativeOnly ? plan.nativeTarget : undefined);
1030
1213
  const values = { ...readback };
1031
1214
  const relationships = async (issueNumber) => {
1032
1215
  const native = await getNativeBlockerRelationships({
@@ -1077,6 +1260,8 @@ async function updateProjection(context, plan) {
1077
1260
  }
1078
1261
  if (plan.closeReason !== undefined) {
1079
1262
  const closure = await readIssueClosure(context, input.issueNumber);
1263
+ if (nativeOnly)
1264
+ plan.assertClosure(closure);
1080
1265
  values.closeReason = closure.closeReason;
1081
1266
  if (plan.closeReason === 'duplicate' && input.supersededBy !== undefined)
1082
1267
  values.supersededBy = closure.duplicateOf?.number ?? null;
@@ -1093,6 +1278,8 @@ async function desiredUpdateValues(context, plan) {
1093
1278
  'issueType',
1094
1279
  'points',
1095
1280
  'priority',
1281
+ 'startDate',
1282
+ 'targetDate',
1096
1283
  'milestone',
1097
1284
  'state',
1098
1285
  'parentIssueNumber',
@@ -1194,6 +1381,7 @@ function localBatchFailureReason(error) {
1194
1381
  'Native parent changed during batch readback; reconcile the current state.',
1195
1382
  'Native issue changed during batch preparation; reconcile the current state.',
1196
1383
  'Native batch readback disagrees with the requested outcomes.',
1384
+ 'The issue delivery Project item is archived and cannot be updated.',
1197
1385
  ].includes(message))
1198
1386
  return message;
1199
1387
  if (message.startsWith('Unknown repository label(s): '))
@@ -1256,7 +1444,7 @@ export async function batchUpdateIssues(context, input, signal) {
1256
1444
  await applyIssueUpdate(context, {
1257
1445
  ...plan,
1258
1446
  priorContent: { title: before.readback.title, body: before.readback.body },
1259
- });
1447
+ }, changes);
1260
1448
  phase = 'readback';
1261
1449
  const after = await updateProjection(context, plan);
1262
1450
  if (Object.keys(pendingUpdateValues(desired, after.values)).length)
@@ -1271,7 +1459,10 @@ export async function batchUpdateIssues(context, input, signal) {
1271
1459
  }
1272
1460
  catch (error) {
1273
1461
  const observed = context.clients.rateLimitObservation?.();
1274
- const limit = getRateLimitDiagnostics(error) ?? (observed !== priorRateObservation ? observed : undefined);
1462
+ const incomplete = getIncompleteIssueUpdate(error);
1463
+ const limit = getRateLimitDiagnostics(error) ??
1464
+ incomplete?.rateLimit ??
1465
+ (observed !== priorRateObservation ? observed : undefined);
1275
1466
  if (limit !== undefined) {
1276
1467
  limited = true;
1277
1468
  rateLimits.push(limit);
@@ -1286,6 +1477,7 @@ export async function batchUpdateIssues(context, input, signal) {
1286
1477
  : (localBatchFailureReason(error) ??
1287
1478
  `Issue update ${phase} failed; inspect native readback before retrying.`),
1288
1479
  ...(diagnostics === undefined ? {} : { diagnostics }),
1480
+ ...(incomplete === undefined ? {} : { incomplete }),
1289
1481
  };
1290
1482
  if (!limited && !signal?.aborted) {
1291
1483
  try {
@@ -1324,28 +1516,40 @@ export async function resumeCreatedIssue(context, input) {
1324
1516
  // Tracking recovery must not trigger an unrelated first render omission and change the retry intent.
1325
1517
  return updateIssue(context, { ...input, preserveHistory: input.preserveHistory ?? false });
1326
1518
  }
1327
- export async function issueInfo(context, issueNumber) {
1519
+ async function readIssueInfo(context, issueNumber, includeProject = true, expectedTarget) {
1328
1520
  const { clients, config, repo } = context;
1329
1521
  const issue = (await clients.rest.issues.get({ issue_number: issueNumber, owner: repo.owner, repo: repo.repo })).data;
1330
1522
  if ('pull_request' in issue)
1331
1523
  throw new DeliveryError('Requested issue number is a pull request.');
1332
- const [metadata, relationships, project] = await Promise.all([
1333
- getConfiguredNativeIssueMetadata({
1334
- issueNumber,
1335
- owner: repo.owner,
1336
- repo: repo.repo,
1337
- rest: clients.rest,
1338
- settings: nativeIssueSettingsFromDeliveryConfig(config),
1339
- }),
1340
- getNativeBlockerRelationships({ graphql: clients.graphql, issueNumber, repo }),
1341
- getIssueProjectStatus({
1524
+ if (!includeProject &&
1525
+ (issue.number !== issueNumber ||
1526
+ issue.node_id !== expectedTarget?.nodeId ||
1527
+ issue.html_url !== expectedTarget?.url ||
1528
+ new URL(issue.html_url).pathname.toLowerCase() !==
1529
+ `/${repo.owner}/${repo.repo}/issues/${String(issueNumber)}`.toLowerCase()))
1530
+ throw new DeliveryError('Native closure readback returned a foreign issue identity.');
1531
+ const [nativeFields, relationships, project] = await Promise.all([
1532
+ readIssueNativeFields(context, issueNumber),
1533
+ getNativeBlockerRelationships({
1342
1534
  graphql: clients.graphql,
1343
- issueNodeId: issue.node_id,
1344
- org: config.native.organization,
1345
- ...(context.projectConfiguration ? { configuration: context.projectConfiguration } : {}),
1346
- settings: projectSettingsFromDeliveryConfig(config),
1535
+ issueNumber,
1536
+ repo,
1537
+ ...(context.readPageLimit === undefined
1538
+ ? {}
1539
+ : { maxPages: context.readPageLimit, requireRepositoryIdentity: true, issueNodeId: issue.node_id }),
1347
1540
  }),
1541
+ includeProject
1542
+ ? getIssueProjectStatus({
1543
+ graphql: clients.graphql,
1544
+ issueNodeId: issue.node_id,
1545
+ org: config.native.organization,
1546
+ ...(context.readPageLimit === undefined ? {} : { maxPages: context.readPageLimit }),
1547
+ ...(context.projectConfiguration ? { configuration: context.projectConfiguration } : {}),
1548
+ settings: projectSettingsFromDeliveryConfig(config),
1549
+ })
1550
+ : Promise.resolve(null),
1348
1551
  ]);
1552
+ const metadata = parseConfiguredNativeIssueMetadata(nativeFields.values, nativeIssueSettingsFromDeliveryConfig(config));
1349
1553
  const info = {
1350
1554
  ...deferralReadback(issue.body, issue.title),
1351
1555
  ...(context.configuration ? { routing: context.configuration.routing } : {}),
@@ -1355,6 +1559,13 @@ export async function issueInfo(context, issueNumber) {
1355
1559
  issueType: issue.type?.name ?? null,
1356
1560
  labels: (issue.labels ?? []).flatMap((label) => typeof label === 'string' ? [label] : label.name === undefined ? [] : [label.name]),
1357
1561
  milestone: issue.milestone?.number ?? null,
1562
+ fields: nativeFields.fields,
1563
+ ...(nativeFields.catalog.some((field) => field.name === 'Start date' && field.data_type === 'date')
1564
+ ? { startDate: nativeFields.fields['Start date'] }
1565
+ : {}),
1566
+ ...(nativeFields.catalog.some((field) => field.name === 'Target date' && field.data_type === 'date')
1567
+ ? { targetDate: nativeFields.fields['Target date'] }
1568
+ : {}),
1358
1569
  parentIssueNumber: relationships.parentNumber,
1359
1570
  ...(metadata.points === undefined ? {} : { points: metadata.points }),
1360
1571
  ...(metadata.priority === undefined ? {} : { priority: metadata.priority }),
@@ -1364,7 +1575,10 @@ export async function issueInfo(context, issueNumber) {
1364
1575
  url: issue.html_url,
1365
1576
  worktree: null,
1366
1577
  };
1367
- return info;
1578
+ return { info, issueNodeId: issue.node_id, issueNumber: issue.number };
1579
+ }
1580
+ export async function issueInfo(context, issueNumber) {
1581
+ return (await readIssueInfo(context, issueNumber)).info;
1368
1582
  }
1369
1583
  /** Invalid canonical content stays inspectable; omitted state is unknown, never an assertion of undeferred. */
1370
1584
  function deferralReadback(body, title) {
@@ -1390,9 +1604,16 @@ export async function listIssueSubissues(context, issueNumber) {
1390
1604
  });
1391
1605
  return children.map((child) => child.number).sort((left, right) => left - right);
1392
1606
  }
1393
- export async function readyCheck(context, issueNumber) {
1394
- const info = await issueInfo(context, issueNumber);
1395
- const trackingParent = await hasNativeSubIssues({ issueNumber, repo: context.repo, rest: context.clients.rest });
1607
+ export async function readyCheck(context, issueNumber, onReadback) {
1608
+ const observation = await readIssueInfo(context, issueNumber);
1609
+ const { info } = observation;
1610
+ const trackingParent = await hasNativeSubIssues({
1611
+ issueNumber,
1612
+ repo: context.repo,
1613
+ rest: context.clients.rest,
1614
+ requireComplete: context.readPageLimit !== undefined,
1615
+ });
1616
+ onReadback?.({ ...observation, trackingParent });
1396
1617
  return evaluateAgentReadiness({
1397
1618
  blockedBy: info.blockedBy,
1398
1619
  body: info.body,
@@ -1407,7 +1628,8 @@ export async function linkedIssueBranches(context, issueNumber) {
1407
1628
  const branches = [];
1408
1629
  const cursors = new Set();
1409
1630
  let cursor = null;
1410
- for (let page = 0; page < 20; page++) {
1631
+ const limit = Math.min(context.readPageLimit ?? 20, 20);
1632
+ for (let page = 0; page < limit; page++) {
1411
1633
  const response = await context.clients.graphql('query DeliveryIssueBranches($owner:String!,$repo:String!,$issue:Int!,$cursor:String){repository(owner:$owner,name:$repo){issue(number:$issue){linkedBranches(first:100,after:$cursor){nodes{ref{name target{oid} repository{nameWithOwner}}} pageInfo{hasNextPage endCursor}}}}}', { owner: context.repo.owner, repo: context.repo.repo, issue: issueNumber, cursor });
1412
1634
  const connection = response.repository?.issue?.linkedBranches;
1413
1635
  if (!connection || !Array.isArray(connection.nodes) || typeof connection.pageInfo?.hasNextPage !== 'boolean')
@@ -1427,6 +1649,13 @@ export async function linkedIssueBranches(context, issueNumber) {
1427
1649
  cursors.add(next);
1428
1650
  cursor = next;
1429
1651
  }
1652
+ if (context.readPageLimit !== undefined)
1653
+ throw new CollectionLimitError({
1654
+ collection: 'linked-branches',
1655
+ pagesRequested: limit,
1656
+ rowsObserved: branches.length,
1657
+ limit,
1658
+ });
1430
1659
  throw new DeliveryError('GitHub linked issue branches exceed the bounded readback window.');
1431
1660
  }
1432
1661
  export async function issueBranch(context, issueNumber, selected) {
@@ -1511,6 +1740,7 @@ export async function assertIssueStartCapacity(context, issueNumber, overrideRea
1511
1740
  graphql: context.clients.graphql,
1512
1741
  org: context.config.native.organization,
1513
1742
  settings: projectSettingsFromDeliveryConfig(context.config),
1743
+ ...(context.readPageLimit === undefined ? {} : { maxPages: context.readPageLimit }),
1514
1744
  }));
1515
1745
  const capacityContext = { ...context, projectConfiguration: configuration };
1516
1746
  const reason = overrideReason === undefined ? undefined : OverrideReason.parse(overrideReason);
@@ -1525,6 +1755,13 @@ export async function assertIssueStartCapacity(context, issueNumber, overrideRea
1525
1755
  const rows = [];
1526
1756
  const seen = new Set();
1527
1757
  for (let page = 1;; page++) {
1758
+ if (context.readPageLimit !== undefined && page > Math.min(context.readPageLimit, 20))
1759
+ throw new CollectionLimitError({
1760
+ collection: 'wip-issues',
1761
+ pagesRequested: page - 1,
1762
+ rowsObserved: rows.length,
1763
+ limit: Math.min(context.readPageLimit, 20),
1764
+ });
1528
1765
  if (page > 20)
1529
1766
  throw new DeliveryError('WIP capacity issue pagination is incomplete.');
1530
1767
  const batch = await listIssues(capacityContext, { state: 'open', page, perPage: 100 }, { capacityRead: true });