@aviaratech/ai-delivery 0.3.34 → 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 (75) hide show
  1. package/README.md +48 -0
  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 +35 -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/github/commandIdentityPolicy.js +1 -0
  27. package/dist/github/commandIdentityPolicy.js.map +1 -1
  28. package/dist/github/discovery.d.ts +2 -0
  29. package/dist/github/discovery.js +17 -3
  30. package/dist/github/discovery.js.map +1 -1
  31. package/dist/github/projectDelivery.d.ts +36 -0
  32. package/dist/github/projectDelivery.js +136 -31
  33. package/dist/github/projectDelivery.js.map +1 -1
  34. package/dist/github/relationships.d.ts +5 -2
  35. package/dist/github/relationships.js +59 -2
  36. package/dist/github/relationships.js.map +1 -1
  37. package/dist/issue.d.ts +66 -1
  38. package/dist/issue.js +259 -62
  39. package/dist/issue.js.map +1 -1
  40. package/dist/issueBatchUpdate.test.js +229 -12
  41. package/dist/issueBatchUpdate.test.js.map +1 -1
  42. package/dist/issueTracking.test.js +436 -11
  43. package/dist/issueTracking.test.js.map +1 -1
  44. package/dist/mcp/index.js +4 -0
  45. package/dist/mcp/index.js.map +1 -1
  46. package/dist/mcp/tools.d.ts +592 -0
  47. package/dist/mcp/tools.js +7 -0
  48. package/dist/mcp/tools.js.map +1 -1
  49. package/dist/pluginInstaller.js +21 -23
  50. package/dist/pluginInstaller.js.map +1 -1
  51. package/dist/pluginInstaller.test.js +121 -1
  52. package/dist/pluginInstaller.test.js.map +1 -1
  53. package/dist/pluginPackaging.test.js +135 -6
  54. package/dist/pluginPackaging.test.js.map +1 -1
  55. package/dist/services/boardReconcileService.d.ts +1204 -0
  56. package/dist/services/boardReconcileService.js +1571 -0
  57. package/dist/services/boardReconcileService.js.map +1 -0
  58. package/dist/services/deliveryAdmission.d.ts +2 -0
  59. package/dist/services/deliveryAdmission.js +2 -2
  60. package/dist/services/deliveryAdmission.js.map +1 -1
  61. package/dist/setup.test.js +299 -28
  62. package/dist/setup.test.js.map +1 -1
  63. package/dist/stdoutRegression.test.js +5 -2
  64. package/dist/stdoutRegression.test.js.map +1 -1
  65. package/dist/verification.js +12 -2
  66. package/dist/verification.js.map +1 -1
  67. package/dist/version.d.ts +6 -0
  68. package/dist/version.js +16 -1
  69. package/dist/version.js.map +1 -1
  70. package/package.json +2 -1
  71. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  72. package/plugins/ai-delivery/plugin.json +1 -1
  73. package/plugins/ai-delivery/runtime/dist/THIRD-PARTY-NOTICES.md +24 -0
  74. package/plugins/ai-delivery/runtime/dist/cli.js +72 -71
  75. package/plugins/ai-delivery/runtime/package.json +1 -1
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
7
  import { NATIVE_ISSUE_API_VERSION, applyNativeIssueDates, prepareNativeIssueDates, parseConfiguredNativeIssueMetadata, clearConfiguredNativeIssuePoints, getConfiguredNativeIssueMetadata, nativeIssueSettingsFromDeliveryConfig, setConfiguredNativeIssueMetadata, } from './github/nativeIssueMetadata.js';
8
- import { getIssueProjectStatus, getProjectDeliveryConfiguration, projectSettingsFromDeliveryConfig, syncIssueProjectStatus, } from './github/projectDelivery.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());
@@ -435,7 +452,7 @@ const ListedIssue = z.object({
435
452
  html_url: z.url(),
436
453
  updated_at: z.iso.datetime({ offset: true }),
437
454
  });
438
- function capacityNextPage(response, page, perPage) {
455
+ export function capacityNextPage(response, page, perPage) {
439
456
  if (!Array.isArray(response.data) || response.data.length > perPage)
440
457
  throw new DeliveryError('WIP capacity pagination returned invalid native data.');
441
458
  const link = response.headers?.link;
@@ -463,8 +480,16 @@ async function issueFieldPages(context, route, parameters, maxPages) {
463
480
  const values = [];
464
481
  const seenPages = new Set();
465
482
  for (let page = 1;; page += 1) {
466
- 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
+ });
467
491
  throw new DeliveryError('WIP capacity native field pagination is incomplete.');
492
+ }
468
493
  const response = await context.clients.rest.request(route, {
469
494
  ...parameters,
470
495
  headers: { 'X-GitHub-Api-Version': NATIVE_ISSUE_API_VERSION },
@@ -485,7 +510,7 @@ async function issueFieldPages(context, route, parameters, maxPages) {
485
510
  async function readIssueFieldCatalog(context, capacityRead = false) {
486
511
  const catalog = z
487
512
  .array(FieldCatalogEntry)
488
- .parse(await issueFieldPages(context, 'GET /orgs/{org}/issue-fields', { org: context.config.native.organization }, capacityRead ? 20 : undefined));
513
+ .parse(await issueFieldPages(context, 'GET /orgs/{org}/issue-fields', { org: context.config.native.organization }, capacityRead ? Math.min(context.readPageLimit ?? 20, 20) : context.readPageLimit));
489
514
  if (new Set(catalog.map((field) => field.name)).size !== catalog.length ||
490
515
  new Set(catalog.map((field) => field.id)).size !== catalog.length)
491
516
  throw new DeliveryError('Native issue field catalog has duplicate identities or names.');
@@ -496,7 +521,7 @@ async function readIssueFields(context, issueNumber, catalog, capacityRead = fal
496
521
  const values = z.array(FieldValueEntry).parse(await issueFieldPages(context, 'GET /repos/{owner}/{repo}/issues/{issue_number}/issue-field-values', {
497
522
  ...context.repo,
498
523
  issue_number: issueNumber,
499
- }, capacityRead ? 20 : undefined));
524
+ }, capacityRead ? Math.min(context.readPageLimit ?? 20, 20) : context.readPageLimit));
500
525
  const observed = new Set();
501
526
  for (const field of values) {
502
527
  const definition = catalog.find((candidate) => candidate.id === field.issue_field_id);
@@ -551,6 +576,10 @@ async function readIssueFields(context, issueNumber, catalog, capacityRead = fal
551
576
  }
552
577
  return { fields, values, catalog };
553
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
+ }
554
583
  async function prepareIssueDates(context, patch) {
555
584
  if (patch.startDate === undefined && patch.targetDate === undefined)
556
585
  return [];
@@ -652,6 +681,7 @@ export async function listIssues(context, input, options = {}) {
652
681
  issueNumber: current.number,
653
682
  repo: context.repo,
654
683
  requireRepositoryIdentity: true,
684
+ ...(context.readPageLimit === undefined ? {} : { maxPages: context.readPageLimit, issueNodeId: current.node_id }),
655
685
  });
656
686
  const localParent = relationships.parentRepository?.toLowerCase() === `${context.repo.owner}/${context.repo.repo}`.toLowerCase()
657
687
  ? relationships.parentNumber
@@ -663,6 +693,9 @@ export async function listIssues(context, input, options = {}) {
663
693
  graphql: context.clients.graphql,
664
694
  issueNodeId: current.node_id,
665
695
  ...(options.capacityRead ? { capacityRead: true, maxPages: 20 } : {}),
696
+ ...(context.readPageLimit === undefined
697
+ ? {}
698
+ : { maxPages: Math.min(context.readPageLimit, options.capacityRead ? 20 : context.readPageLimit) }),
666
699
  org: context.config.native.organization,
667
700
  ...(context.projectConfiguration ? { configuration: context.projectConfiguration } : {}),
668
701
  settings: projectSettingsFromDeliveryConfig(context.config),
@@ -746,6 +779,20 @@ export async function readIssueClosure(context, issueNumber) {
746
779
  : { number: parsed.duplicateOf.number, repository: parsed.duplicateOf.repository.nameWithOwner },
747
780
  };
748
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
+ }
749
796
  function updateProjectStatus(info, input) {
750
797
  return info.state === 'closed' || info.projectStatus === 'Done'
751
798
  ? 'Done'
@@ -884,6 +931,21 @@ async function prepareIssueUpdate(context, input) {
884
931
  const closureBody = closeReason === undefined
885
932
  ? undefined
886
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
+ });
887
949
  return {
888
950
  input,
889
951
  prepared,
@@ -893,6 +955,7 @@ async function prepareIssueUpdate(context, input) {
893
955
  supersedingIssueId,
894
956
  assertClosure,
895
957
  currentContent,
958
+ nativeTarget: { nodeId: target.node_id, url: target.html_url },
896
959
  dateChanges,
897
960
  priorContent,
898
961
  historyBody,
@@ -902,9 +965,10 @@ async function prepareIssueUpdate(context, input) {
902
965
  export async function updateIssue(context, input) {
903
966
  return applyIssueUpdate(context, await prepareIssueUpdate(context, input));
904
967
  }
905
- async function applyIssueUpdate(context, plan) {
968
+ async function applyIssueUpdate(context, plan, changes) {
906
969
  const { clients, config, repo } = context;
907
970
  const { input, prepared, acceptedLabels, beforeAdd, closeReason, supersedingIssueId, assertClosure, priorContent, historyBody, closureBody, } = plan;
971
+ const pending = (key) => changes === undefined || key in changes;
908
972
  const historyComment = historyBody === undefined
909
973
  ? undefined
910
974
  : await commentIssue(context, { issueNumber: input.issueNumber, body: historyBody });
@@ -922,32 +986,35 @@ async function applyIssueUpdate(context, plan) {
922
986
  (current.body ?? '') !== priorContent.body)
923
987
  throw new DeliveryError('Issue content changed after preparation; retry against the current title and body.');
924
988
  }
925
- await clients.rest.issues.update({
926
- issue_number: input.issueNumber,
927
- owner: repo.owner,
928
- repo: repo.repo,
929
- ...(input.body === undefined ? {} : { body: input.body }),
930
- ...(input.issueType === undefined ? {} : { type: input.issueType }),
931
- ...(acceptedLabels === undefined ? {} : { labels: acceptedLabels }),
932
- ...(input.milestone === undefined ? {} : { milestone: input.milestone }),
933
- ...(input.state === undefined ? {} : { state: input.state }),
934
- ...(closeReason === undefined
935
- ? {}
936
- : { state_reason: closeReason, headers: { 'X-GitHub-Api-Version': NATIVE_ISSUE_API_VERSION } }),
937
- ...(closeReason !== 'duplicate' || supersedingIssueId === undefined
938
- ? {}
939
- : { duplicate_issue_id: supersedingIssueId }),
940
- ...(input.title === undefined ? {} : { title: input.title }),
941
- });
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
+ });
942
1009
  const closure = closeReason === undefined ? undefined : await readIssueClosure(context, input.issueNumber);
943
1010
  if (closure !== undefined)
944
1011
  assertClosure(closure);
945
- if (input.points !== undefined || input.priority !== undefined)
1012
+ if ((input.points !== undefined && pending('points')) || (input.priority !== undefined && pending('priority')))
946
1013
  await setConfiguredNativeIssueMetadata({
947
1014
  issueNumber: input.issueNumber,
948
1015
  metadata: {
949
- ...(input.points === undefined ? {} : { points: input.points }),
950
- ...(input.priority === undefined ? {} : { priority: input.priority }),
1016
+ ...(input.points === undefined || !pending('points') ? {} : { points: input.points }),
1017
+ ...(input.priority === undefined || !pending('priority') ? {} : { priority: input.priority }),
951
1018
  },
952
1019
  org: config.native.organization,
953
1020
  owner: repo.owner,
@@ -956,12 +1023,12 @@ async function applyIssueUpdate(context, plan) {
956
1023
  settings: nativeIssueSettingsFromDeliveryConfig(config),
957
1024
  });
958
1025
  await applyNativeIssueDates({
959
- changes: plan.dateChanges,
1026
+ changes: plan.dateChanges.filter((change) => pending(change.name === 'Start date' ? 'startDate' : 'targetDate')),
960
1027
  issueNumber: input.issueNumber,
961
1028
  ...repo,
962
1029
  rest: clients.rest,
963
1030
  });
964
- if (input.parentIssueNumber !== undefined)
1031
+ if (input.parentIssueNumber !== undefined && pending('parentIssueNumber'))
965
1032
  await replaceParentIssue({
966
1033
  graphql: clients.graphql,
967
1034
  issueNumber: input.issueNumber,
@@ -969,7 +1036,7 @@ async function applyIssueUpdate(context, plan) {
969
1036
  repo,
970
1037
  rest: clients.rest,
971
1038
  });
972
- if (input.parentIssueNumber !== undefined && input.parentIssueNumber !== null)
1039
+ if (input.parentIssueNumber !== undefined && input.parentIssueNumber !== null && pending('parentPoints'))
973
1040
  await clearConfiguredNativeIssuePoints({
974
1041
  issueNumber: input.parentIssueNumber,
975
1042
  org: config.native.organization,
@@ -979,7 +1046,7 @@ async function applyIssueUpdate(context, plan) {
979
1046
  settings: nativeIssueSettingsFromDeliveryConfig(config),
980
1047
  });
981
1048
  try {
982
- if (input.blockedBy !== undefined)
1049
+ if (input.blockedBy !== undefined && pending('blockedBy'))
983
1050
  await replaceBlockedBy({
984
1051
  ...(beforeAdd === undefined ? {} : { beforeAdd }),
985
1052
  blockers: input.blockedBy,
@@ -988,7 +1055,7 @@ async function applyIssueUpdate(context, plan) {
988
1055
  repo,
989
1056
  rest: clients.rest,
990
1057
  });
991
- for (const dependent of new Set(input.blocks ?? []))
1058
+ for (const dependent of new Set(pending('blocks') ? (input.blocks ?? []) : []))
992
1059
  await linkBlockedBy({
993
1060
  ...(beforeAdd === undefined ? {} : { beforeAdd }),
994
1061
  blockers: [input.issueNumber],
@@ -1001,18 +1068,98 @@ async function applyIssueUpdate(context, plan) {
1001
1068
  catch (error) {
1002
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.`);
1003
1070
  }
1004
- const info = await issueInfo(context, input.issueNumber);
1005
- const status = updateProjectStatus(info, input);
1006
- const issue = (await clients.rest.issues.get({ issue_number: input.issueNumber, ...repo })).data;
1007
- await syncIssueProjectStatus({
1008
- graphql: clients.graphql,
1009
- issueNodeId: issue.node_id,
1010
- org: config.native.organization,
1011
- ...(context.projectConfiguration ? { configuration: context.projectConfiguration } : {}),
1012
- settings: projectSettingsFromDeliveryConfig(config),
1013
- status,
1014
- });
1015
- 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
+ }
1016
1163
  if ((input.title !== undefined && readback.title !== input.title) ||
1017
1164
  (input.body !== undefined && readback.body !== input.body) ||
1018
1165
  (input.state !== undefined && readback.state !== input.state) ||
@@ -1060,9 +1207,9 @@ async function hasUpdateComment(context, issueNumber, body) {
1060
1207
  await readAuthoredIssueComment(context, issueNumber, matches[0], body, actor);
1061
1208
  return true;
1062
1209
  }
1063
- async function updateProjection(context, plan) {
1210
+ async function updateProjection(context, plan, nativeOnly = false) {
1064
1211
  const { input } = plan;
1065
- const readback = await issueInfo(context, input.issueNumber);
1212
+ const { info: readback } = await readIssueInfo(context, input.issueNumber, !nativeOnly, nativeOnly ? plan.nativeTarget : undefined);
1066
1213
  const values = { ...readback };
1067
1214
  const relationships = async (issueNumber) => {
1068
1215
  const native = await getNativeBlockerRelationships({
@@ -1113,6 +1260,8 @@ async function updateProjection(context, plan) {
1113
1260
  }
1114
1261
  if (plan.closeReason !== undefined) {
1115
1262
  const closure = await readIssueClosure(context, input.issueNumber);
1263
+ if (nativeOnly)
1264
+ plan.assertClosure(closure);
1116
1265
  values.closeReason = closure.closeReason;
1117
1266
  if (plan.closeReason === 'duplicate' && input.supersededBy !== undefined)
1118
1267
  values.supersededBy = closure.duplicateOf?.number ?? null;
@@ -1232,6 +1381,7 @@ function localBatchFailureReason(error) {
1232
1381
  'Native parent changed during batch readback; reconcile the current state.',
1233
1382
  'Native issue changed during batch preparation; reconcile the current state.',
1234
1383
  'Native batch readback disagrees with the requested outcomes.',
1384
+ 'The issue delivery Project item is archived and cannot be updated.',
1235
1385
  ].includes(message))
1236
1386
  return message;
1237
1387
  if (message.startsWith('Unknown repository label(s): '))
@@ -1294,7 +1444,7 @@ export async function batchUpdateIssues(context, input, signal) {
1294
1444
  await applyIssueUpdate(context, {
1295
1445
  ...plan,
1296
1446
  priorContent: { title: before.readback.title, body: before.readback.body },
1297
- });
1447
+ }, changes);
1298
1448
  phase = 'readback';
1299
1449
  const after = await updateProjection(context, plan);
1300
1450
  if (Object.keys(pendingUpdateValues(desired, after.values)).length)
@@ -1309,7 +1459,10 @@ export async function batchUpdateIssues(context, input, signal) {
1309
1459
  }
1310
1460
  catch (error) {
1311
1461
  const observed = context.clients.rateLimitObservation?.();
1312
- 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);
1313
1466
  if (limit !== undefined) {
1314
1467
  limited = true;
1315
1468
  rateLimits.push(limit);
@@ -1324,6 +1477,7 @@ export async function batchUpdateIssues(context, input, signal) {
1324
1477
  : (localBatchFailureReason(error) ??
1325
1478
  `Issue update ${phase} failed; inspect native readback before retrying.`),
1326
1479
  ...(diagnostics === undefined ? {} : { diagnostics }),
1480
+ ...(incomplete === undefined ? {} : { incomplete }),
1327
1481
  };
1328
1482
  if (!limited && !signal?.aborted) {
1329
1483
  try {
@@ -1362,21 +1516,38 @@ export async function resumeCreatedIssue(context, input) {
1362
1516
  // Tracking recovery must not trigger an unrelated first render omission and change the retry intent.
1363
1517
  return updateIssue(context, { ...input, preserveHistory: input.preserveHistory ?? false });
1364
1518
  }
1365
- export async function issueInfo(context, issueNumber) {
1519
+ async function readIssueInfo(context, issueNumber, includeProject = true, expectedTarget) {
1366
1520
  const { clients, config, repo } = context;
1367
1521
  const issue = (await clients.rest.issues.get({ issue_number: issueNumber, owner: repo.owner, repo: repo.repo })).data;
1368
1522
  if ('pull_request' in issue)
1369
1523
  throw new DeliveryError('Requested issue number is a pull request.');
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.');
1370
1531
  const [nativeFields, relationships, project] = await Promise.all([
1371
- readIssueFieldCatalog(context).then((catalog) => readIssueFields(context, issueNumber, catalog)),
1372
- getNativeBlockerRelationships({ graphql: clients.graphql, issueNumber, repo }),
1373
- getIssueProjectStatus({
1532
+ readIssueNativeFields(context, issueNumber),
1533
+ getNativeBlockerRelationships({
1374
1534
  graphql: clients.graphql,
1375
- issueNodeId: issue.node_id,
1376
- org: config.native.organization,
1377
- ...(context.projectConfiguration ? { configuration: context.projectConfiguration } : {}),
1378
- settings: projectSettingsFromDeliveryConfig(config),
1535
+ issueNumber,
1536
+ repo,
1537
+ ...(context.readPageLimit === undefined
1538
+ ? {}
1539
+ : { maxPages: context.readPageLimit, requireRepositoryIdentity: true, issueNodeId: issue.node_id }),
1379
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),
1380
1551
  ]);
1381
1552
  const metadata = parseConfiguredNativeIssueMetadata(nativeFields.values, nativeIssueSettingsFromDeliveryConfig(config));
1382
1553
  const info = {
@@ -1404,7 +1575,10 @@ export async function issueInfo(context, issueNumber) {
1404
1575
  url: issue.html_url,
1405
1576
  worktree: null,
1406
1577
  };
1407
- 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;
1408
1582
  }
1409
1583
  /** Invalid canonical content stays inspectable; omitted state is unknown, never an assertion of undeferred. */
1410
1584
  function deferralReadback(body, title) {
@@ -1430,9 +1604,16 @@ export async function listIssueSubissues(context, issueNumber) {
1430
1604
  });
1431
1605
  return children.map((child) => child.number).sort((left, right) => left - right);
1432
1606
  }
1433
- export async function readyCheck(context, issueNumber) {
1434
- const info = await issueInfo(context, issueNumber);
1435
- 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 });
1436
1617
  return evaluateAgentReadiness({
1437
1618
  blockedBy: info.blockedBy,
1438
1619
  body: info.body,
@@ -1447,7 +1628,8 @@ export async function linkedIssueBranches(context, issueNumber) {
1447
1628
  const branches = [];
1448
1629
  const cursors = new Set();
1449
1630
  let cursor = null;
1450
- for (let page = 0; page < 20; page++) {
1631
+ const limit = Math.min(context.readPageLimit ?? 20, 20);
1632
+ for (let page = 0; page < limit; page++) {
1451
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 });
1452
1634
  const connection = response.repository?.issue?.linkedBranches;
1453
1635
  if (!connection || !Array.isArray(connection.nodes) || typeof connection.pageInfo?.hasNextPage !== 'boolean')
@@ -1467,6 +1649,13 @@ export async function linkedIssueBranches(context, issueNumber) {
1467
1649
  cursors.add(next);
1468
1650
  cursor = next;
1469
1651
  }
1652
+ if (context.readPageLimit !== undefined)
1653
+ throw new CollectionLimitError({
1654
+ collection: 'linked-branches',
1655
+ pagesRequested: limit,
1656
+ rowsObserved: branches.length,
1657
+ limit,
1658
+ });
1470
1659
  throw new DeliveryError('GitHub linked issue branches exceed the bounded readback window.');
1471
1660
  }
1472
1661
  export async function issueBranch(context, issueNumber, selected) {
@@ -1551,6 +1740,7 @@ export async function assertIssueStartCapacity(context, issueNumber, overrideRea
1551
1740
  graphql: context.clients.graphql,
1552
1741
  org: context.config.native.organization,
1553
1742
  settings: projectSettingsFromDeliveryConfig(context.config),
1743
+ ...(context.readPageLimit === undefined ? {} : { maxPages: context.readPageLimit }),
1554
1744
  }));
1555
1745
  const capacityContext = { ...context, projectConfiguration: configuration };
1556
1746
  const reason = overrideReason === undefined ? undefined : OverrideReason.parse(overrideReason);
@@ -1565,6 +1755,13 @@ export async function assertIssueStartCapacity(context, issueNumber, overrideRea
1565
1755
  const rows = [];
1566
1756
  const seen = new Set();
1567
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
+ });
1568
1765
  if (page > 20)
1569
1766
  throw new DeliveryError('WIP capacity issue pagination is incomplete.');
1570
1767
  const batch = await listIssues(capacityContext, { state: 'open', page, perPage: 100 }, { capacityRead: true });