@aviaratech/ai-delivery 0.3.38 → 0.3.39

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 (170) hide show
  1. package/README.md +14 -18
  2. package/dist/agent.d.ts +0 -4
  3. package/dist/agent.js +1 -8
  4. package/dist/agent.js.map +2 -2
  5. package/dist/cli.js +2 -72
  6. package/dist/cli.js.map +2 -2
  7. package/dist/cliResult.js +2 -14
  8. package/dist/cliResult.js.map +2 -2
  9. package/dist/cliResult.test.js +0 -74
  10. package/dist/cliResult.test.js.map +2 -2
  11. package/dist/config/deliveryConfig.d.ts +0 -6
  12. package/dist/config/deliveryConfig.js +2 -35
  13. package/dist/config/deliveryConfig.js.map +2 -2
  14. package/dist/config/deliveryConfig.test.js +1 -25
  15. package/dist/config/deliveryConfig.test.js.map +2 -2
  16. package/dist/contributorChecks.test.js +0 -1
  17. package/dist/contributorChecks.test.js.map +2 -2
  18. package/dist/delivery/common.d.ts +0 -14
  19. package/dist/delivery/common.js +1 -44
  20. package/dist/delivery/common.js.map +2 -2
  21. package/dist/directoryIndependent.test.js +2 -24
  22. package/dist/directoryIndependent.test.js.map +2 -2
  23. package/dist/dispatch.js +0 -46
  24. package/dist/dispatch.js.map +3 -3
  25. package/dist/fixtures/inertTarget.js +3 -5
  26. package/dist/fixtures/inertTarget.js.map +2 -2
  27. package/dist/fixtures/recordedGitHubFlows.d.ts +0 -72
  28. package/dist/fixtures/recordedGitHubFlows.js +1 -57
  29. package/dist/fixtures/recordedGitHubFlows.js.map +2 -2
  30. package/dist/git.d.ts +0 -6
  31. package/dist/git.js +0 -15
  32. package/dist/git.js.map +2 -2
  33. package/dist/github/client.js +0 -3
  34. package/dist/github/client.js.map +2 -2
  35. package/dist/github/commandIdentityPolicy.js +0 -1
  36. package/dist/github/commandIdentityPolicy.js.map +2 -2
  37. package/dist/github/issueHistory.d.ts +0 -6
  38. package/dist/github/issueHistory.js +0 -39
  39. package/dist/github/issueHistory.js.map +2 -2
  40. package/dist/github/nativeIssueMetadata.d.ts +0 -10
  41. package/dist/github/nativeIssueMetadata.js +1 -33
  42. package/dist/github/nativeIssueMetadata.js.map +3 -3
  43. package/dist/github/projectDelivery.d.ts +0 -34
  44. package/dist/github/projectDelivery.js +0 -211
  45. package/dist/github/projectDelivery.js.map +2 -2
  46. package/dist/github/repo.d.ts +0 -8
  47. package/dist/github/repo.js +0 -72
  48. package/dist/github/repo.js.map +2 -2
  49. package/dist/issue.js +15 -15
  50. package/dist/issue.js.map +2 -2
  51. package/dist/issue63Routes.test.js +1 -72
  52. package/dist/issue63Routes.test.js.map +2 -2
  53. package/dist/issueIntake.test.js +12 -0
  54. package/dist/issueIntake.test.js.map +2 -2
  55. package/dist/issueJournal.d.ts +0 -9
  56. package/dist/issueJournal.js +10 -76
  57. package/dist/issueJournal.js.map +2 -2
  58. package/dist/issueJournal.test.js +1 -108
  59. package/dist/issueJournal.test.js.map +2 -2
  60. package/dist/issueTracking.test.js +0 -48
  61. package/dist/issueTracking.test.js.map +2 -2
  62. package/dist/lifecycle.test.js +12 -48
  63. package/dist/lifecycle.test.js.map +2 -2
  64. package/dist/logger.d.ts +0 -4
  65. package/dist/logger.js +0 -31
  66. package/dist/logger.js.map +2 -2
  67. package/dist/mcp/tools.d.ts +2 -618
  68. package/dist/mcp/tools.js +8 -34
  69. package/dist/mcp/tools.js.map +2 -2
  70. package/dist/pluginAuthProbe.js +0 -3
  71. package/dist/pluginAuthProbe.js.map +2 -2
  72. package/dist/pluginDoctor.test.js +1 -1
  73. package/dist/pluginDoctor.test.js.map +2 -2
  74. package/dist/pluginInstaller.js +0 -3
  75. package/dist/pluginInstaller.js.map +2 -2
  76. package/dist/pluginInstaller.test.js +3 -19
  77. package/dist/pluginInstaller.test.js.map +2 -2
  78. package/dist/pluginPackaging.test.js +1 -118
  79. package/dist/pluginPackaging.test.js.map +2 -2
  80. package/dist/pr.d.ts +2 -73
  81. package/dist/pr.js +27 -220
  82. package/dist/pr.js.map +3 -3
  83. package/dist/pr.test.js +11 -304
  84. package/dist/pr.test.js.map +2 -2
  85. package/dist/prAssociation.test.js +112 -22
  86. package/dist/prAssociation.test.js.map +2 -2
  87. package/dist/prDispatch.test.js +4 -11
  88. package/dist/prDispatch.test.js.map +2 -2
  89. package/dist/releaseWorkflow.test.js +0 -1
  90. package/dist/releaseWorkflow.test.js.map +2 -2
  91. package/dist/review.d.ts +0 -82
  92. package/dist/review.js +3 -94
  93. package/dist/review.js.map +2 -2
  94. package/dist/review.test.js +2 -4
  95. package/dist/review.test.js.map +2 -2
  96. package/dist/services/agentReadinessService.d.ts +0 -1
  97. package/dist/services/agentReadinessService.js.map +2 -2
  98. package/dist/stdoutRegression.test.js +3 -22
  99. package/dist/stdoutRegression.test.js.map +2 -2
  100. package/dist/targetPolicyDiscovery.test.js +0 -86
  101. package/dist/targetPolicyDiscovery.test.js.map +2 -2
  102. package/dist/targetPolicyEntrypoints.test.js +1 -54
  103. package/dist/targetPolicyEntrypoints.test.js.map +2 -2
  104. package/dist/targetRepositoryExecution.test.js +1 -49
  105. package/dist/targetRepositoryExecution.test.js.map +2 -2
  106. package/dist/terminalMessages.d.ts +0 -10
  107. package/dist/terminalMessages.js +1 -31
  108. package/dist/terminalMessages.js.map +2 -2
  109. package/dist/toolOutput.js +0 -2
  110. package/dist/toolOutput.js.map +2 -2
  111. package/dist/toolOutput.test.js +15 -1
  112. package/dist/toolOutput.test.js.map +2 -2
  113. package/dist/verification.d.ts +1 -186
  114. package/dist/verification.js +29 -587
  115. package/dist/verification.js.map +3 -3
  116. package/dist/verificationGate.test.js +4 -90
  117. package/dist/verificationGate.test.js.map +2 -2
  118. package/dist/version.d.ts +0 -6
  119. package/dist/version.js +2 -39
  120. package/dist/version.js.map +2 -2
  121. package/package.json +1 -1
  122. package/plugins/ai-delivery/.claude-plugin/plugin.json +2 -2
  123. package/plugins/ai-delivery/plugin.json +1 -1
  124. package/plugins/ai-delivery/runtime/dist/cli.js +123 -167
  125. package/plugins/ai-delivery/runtime/package.json +1 -1
  126. package/dist/boardReconcile.test.d.ts +0 -1
  127. package/dist/boardReconcile.test.js +0 -1746
  128. package/dist/boardReconcile.test.js.map +0 -7
  129. package/dist/delivery/delivery.test.d.ts +0 -1
  130. package/dist/delivery/delivery.test.js +0 -560
  131. package/dist/delivery/delivery.test.js.map +0 -7
  132. package/dist/delivery/evidence.d.ts +0 -92
  133. package/dist/delivery/evidence.js +0 -139
  134. package/dist/delivery/evidence.js.map +0 -7
  135. package/dist/delivery/legacy.d.ts +0 -8
  136. package/dist/delivery/legacy.js +0 -65
  137. package/dist/delivery/legacy.js.map +0 -7
  138. package/dist/delivery/policy.d.ts +0 -252
  139. package/dist/delivery/policy.js +0 -221
  140. package/dist/delivery/policy.js.map +0 -7
  141. package/dist/delivery/stage.d.ts +0 -179
  142. package/dist/delivery/stage.js +0 -242
  143. package/dist/delivery/stage.js.map +0 -7
  144. package/dist/deliveryBoard.d.ts +0 -74
  145. package/dist/deliveryBoard.js +0 -644
  146. package/dist/deliveryBoard.js.map +0 -7
  147. package/dist/deliveryBoard.test.d.ts +0 -1
  148. package/dist/deliveryBoard.test.js +0 -649
  149. package/dist/deliveryBoard.test.js.map +0 -7
  150. package/dist/deliveryHealth.test.d.ts +0 -1
  151. package/dist/deliveryHealth.test.js +0 -191
  152. package/dist/deliveryHealth.test.js.map +0 -7
  153. package/dist/fixtures/deliveryBoardReplay.d.ts +0 -56
  154. package/dist/fixtures/deliveryBoardReplay.js +0 -617
  155. package/dist/fixtures/deliveryBoardReplay.js.map +0 -7
  156. package/dist/genericCompatibility.test.d.ts +0 -1
  157. package/dist/genericCompatibility.test.js +0 -66
  158. package/dist/genericCompatibility.test.js.map +0 -7
  159. package/dist/services/boardReconcileService.d.ts +0 -1204
  160. package/dist/services/boardReconcileService.js +0 -1445
  161. package/dist/services/boardReconcileService.js.map +0 -7
  162. package/dist/services/deliveryHealthService.d.ts +0 -84
  163. package/dist/services/deliveryHealthService.js +0 -204
  164. package/dist/services/deliveryHealthService.js.map +0 -7
  165. package/dist/services/legacyIssueMigration.d.ts +0 -46
  166. package/dist/services/legacyIssueMigration.js +0 -299
  167. package/dist/services/legacyIssueMigration.js.map +0 -7
  168. package/dist/utils/filesystem.d.ts +0 -1
  169. package/dist/utils/filesystem.js +0 -5
  170. package/dist/utils/filesystem.js.map +0 -7
package/dist/pr.js CHANGED
@@ -3,12 +3,7 @@ import { randomUUID } from "node:crypto";
3
3
  import { DeliveryError } from "./errors.js";
4
4
  import * as githubClients from "./github/client.js";
5
5
  import { issueBranch, linkedIssueBranches, startIssueBranch } from "./issue.js";
6
- import {
7
- parseReviewArtifact,
8
- readRequiredReviewState,
9
- ReviewSubmissionError,
10
- submitReview
11
- } from "./review.js";
6
+ import { parseReviewArtifact, readRequiredReviewState, ReviewSubmissionError, submitReview } from "./review.js";
12
7
  import { parseIssueBody } from "./issueContract.js";
13
8
  const Sha = /^[a-f0-9]{40}$/u;
14
9
  const Branch = /^(?!.*(?:\.\.|@\{|\/\/))[A-Za-z0-9._/-]+$/u;
@@ -134,12 +129,6 @@ function hasDeliveryPrMarker(body) {
134
129
  const active = activeMarkerPositions(body, /<!--\s*ai-delivery:pr@[^\n]*?(?:-->|$)/gmu);
135
130
  return Boolean(prefix.trim()) && active?.length === 1 && active[0] === prefix.length + 2;
136
131
  }
137
- function hasDeliveryMergeTrailer(message) {
138
- const trailer = /\n\nDelivered-by: ai-delivery\n?$/u.exec(message);
139
- if (!trailer || !message.slice(0, trailer.index).trim()) return false;
140
- const active = activeMarkerPositions(message, /^Delivered-by: ai-delivery[ \t]*$/gmu);
141
- return active?.length === 1 && active[0] === trailer.index + 2;
142
- }
143
132
  function publicationBody(body, previous) {
144
133
  function marked(value) {
145
134
  const active = activeMarkerPositions(value, /<!--\s*ai-delivery:pr@[^\n]*?(?:-->|$)/gmu);
@@ -592,7 +581,6 @@ async function readRequiredCheckNames(context, base) {
592
581
  sources
593
582
  );
594
583
  const names = /* @__PURE__ */ new Set();
595
- const required = /* @__PURE__ */ new Map();
596
584
  let complete = true;
597
585
  for (const [index, result] of sources.entries()) {
598
586
  if (index === 1 && (confirmedUnprotected || confirmedRulesetOnly)) continue;
@@ -638,179 +626,10 @@ async function readRequiredCheckNames(context, base) {
638
626
  names.add(check.context);
639
627
  const selected = index === 0 ? check.integration_id : check.app_id;
640
628
  if (selected !== void 0 && selected !== null && selected !== -1 && selected <= 0) complete = false;
641
- const appId = selected === void 0 || selected === null || selected === -1 ? null : selected;
642
- required.set(JSON.stringify([check.context, appId]), { name: check.context, appId });
643
629
  }
644
630
  }
645
631
  }
646
- return { names: [...names].sort(), complete, required: [...required.values()] };
647
- }
648
- async function queueChecks(context, base, sha) {
649
- return readRequiredCheckProof(context, base, sha, false);
650
- }
651
- async function readRequiredCheckProof(context, base, sha, allowEmpty) {
652
- const requirements = await readRequiredCheckNames(context, base);
653
- if (!requirements.complete || !allowEmpty && requirements.required.length === 0)
654
- return { state: "waiting", reason: "Required queue checks are absent or incompletely discovered." };
655
- if (requirements.required.length === 0)
656
- return { state: "passed", reason: "Native requirements are completely observed and empty.", proof: [] };
657
- const [runs, statuses] = await Promise.all([
658
- context.clients.rest.checks.listForRef({ ...context.repo, ref: sha, filter: "latest", per_page: 100 }),
659
- context.clients.rest.repos.getCombinedStatusForRef({ ...context.repo, ref: sha, per_page: 100 })
660
- ]);
661
- if (runs.status !== 200 || statuses.status !== 200 || !runs.headers || !statuses.headers || runs.headers?.link || statuses.headers?.link || runs.data.total_count !== runs.data.check_runs.length || statuses.data.total_count !== statuses.data.statuses.length || statuses.data.sha !== sha || runs.data.check_runs.some((run) => run.head_sha !== sha))
662
- return { state: "waiting", reason: "Queue SHA check/status pagination or identity is incomplete." };
663
- const proof = [];
664
- for (const required of requirements.required) {
665
- const status = statuses.data.statuses.filter((s) => s.context === required.name).sort((a, b) => b.id - a.id)[0];
666
- let waiting;
667
- if (status) {
668
- if (required.appId !== null) waiting = `Queue status ${required.name} required App source cannot be established.`;
669
- else if (!Number.isSafeInteger(status.id) || status.id <= 0)
670
- waiting = `Queue status ${required.name} attempt is unknown.`;
671
- else if (status.state === "failure" || status.state === "error")
672
- return { state: "failed", reason: `Queue status ${required.name} is ${status.state}.` };
673
- else if (status.state !== "success")
674
- waiting = `Queue status ${required.name} is ${status.state === "pending" ? "pending" : "unknown"}.`;
675
- else proof.push({ ...required, id: status.id });
676
- }
677
- const candidates = runs.data.check_runs.filter((run2) => run2.name === required.name && (required.appId === null || run2.app?.id === required.appId)).sort((a, b) => b.id - a.id);
678
- const run = candidates[0];
679
- if (run) {
680
- if (!Number.isSafeInteger(run.id) || run.id <= 0 || !run.app?.id)
681
- return { state: "waiting", reason: `Queue check ${required.name} producer/attempt is unknown.` };
682
- if (run.status !== "completed")
683
- return { state: "waiting", reason: `Queue check ${required.name} is pending.` };
684
- if (run.conclusion !== "success" && !["failure", "cancelled", "timed_out", "action_required", "startup_failure", "stale"].includes(
685
- run.conclusion ?? ""
686
- ))
687
- return {
688
- state: "waiting",
689
- reason: `Queue check ${required.name} conclusion is unknown or not successful.`
690
- };
691
- if (run.conclusion !== "success")
692
- return {
693
- state: "failed",
694
- reason: `Queue check ${required.name} concluded ${run.conclusion ?? "unknown"}.`
695
- };
696
- proof.push({ ...required, id: run.id });
697
- } else if (!status) waiting = `Queue check ${required.name} has not reported from its required source.`;
698
- if (waiting) return { state: "waiting", reason: waiting };
699
- }
700
- return { state: "passed", reason: "Current required queue SHA checks passed.", proof };
701
- }
702
- async function readPrBoardFacts(context, prNumber) {
703
- const repository = `${context.repo.owner}/${context.repo.repo}`;
704
- const pr = (await context.clients.rest.pulls.get({ ...context.repo, pull_number: prNumber })).data;
705
- const baseRepo = pr.base.repo;
706
- const headRepo = pr.head.repo;
707
- if (pr.number !== prNumber || !nativeId(pr.node_id) || pr.html_url?.toLowerCase() !== `https://github.com/${repository}/pull/${prNumber}`.toLowerCase() || typeof pr.title !== "string" || pr.body !== null && typeof pr.body !== "string" || pr.state !== "open" && pr.state !== "closed" || typeof pr.draft !== "boolean" || typeof pr.merged !== "boolean" || !baseRepo || !headRepo || !nativeId(baseRepo.node_id) || !nativeId(headRepo.node_id) || typeof baseRepo.full_name !== "string" || typeof headRepo.full_name !== "string" || baseRepo.full_name.toLowerCase() !== repository.toLowerCase() || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(headRepo.full_name) || typeof pr.head.ref !== "string" || !pr.head.ref || typeof pr.base.ref !== "string" || !pr.base.ref || !validSha(pr.head.sha) || !validSha(pr.base.sha))
708
- throw new DeliveryError("Incomplete native PR identity for board display.");
709
- const baseRepository = { id: baseRepo.node_id, name: baseRepo.full_name };
710
- const headRepository = { id: headRepo.node_id, name: headRepo.full_name };
711
- const closingLinks = { complete: false, issues: [] };
712
- let native = null;
713
- try {
714
- let cursor = null;
715
- const cursors = /* @__PURE__ */ new Set();
716
- const issues = /* @__PURE__ */ new Set();
717
- const issueNumbers = /* @__PURE__ */ new Set();
718
- for (let page = 0; page < 20; page++) {
719
- const data = await context.clients.graphql(
720
- "query DeliveryBoardPr($owner:String!,$repo:String!,$number:Int!,$cursor:String){repository(owner:$owner,name:$repo){id nameWithOwner pullRequest(number:$number){id number state isDraft headRefOid baseRefOid headRefName baseRefName baseRepository{id nameWithOwner} headRepository{id nameWithOwner} mergeable mergeStateStatus closingIssuesReferences(first:100,after:$cursor){nodes{__typename id number repository{id nameWithOwner}} pageInfo{hasNextPage endCursor}}}}}",
721
- { ...context.repo, number: prNumber, cursor }
722
- );
723
- const live = data.repository?.pullRequest;
724
- const links = live?.closingIssuesReferences;
725
- if (data.repository?.id !== baseRepository.id || data.repository.nameWithOwner?.toLowerCase() !== repository.toLowerCase() || live?.id !== pr.node_id || live.number !== prNumber || live.headRefOid !== pr.head.sha || live.baseRefOid !== pr.base.sha || live.headRefName !== pr.head.ref || live.baseRefName !== pr.base.ref || live.baseRepository?.id !== baseRepository.id || live.baseRepository.nameWithOwner?.toLowerCase() !== baseRepository.name.toLowerCase() || live.headRepository?.id !== headRepository.id || live.headRepository.nameWithOwner?.toLowerCase() !== headRepository.name.toLowerCase() || live.state !== (pr.merged ? "MERGED" : pr.state.toUpperCase()) || live.isDraft !== pr.draft || !["MERGEABLE", "CONFLICTING", "UNKNOWN"].includes(live.mergeable) || typeof live.mergeStateStatus !== "string" || native !== null && (native.mergeable !== live.mergeable || native.mergeStateStatus !== live.mergeStateStatus) || !links || !Array.isArray(links.nodes) || links.nodes.length > 100)
726
- throw new DeliveryError("Native PR board snapshot is incomplete or changed.");
727
- native = live;
728
- for (const issue of links.nodes) {
729
- if (issue?.__typename !== "Issue" || !nativeId(issue.id) || !Number.isSafeInteger(issue.number) || issue.number <= 0 || !nativeId(issue.repository?.id) || typeof issue.repository.nameWithOwner !== "string" || !/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u.test(issue.repository.nameWithOwner) || issues.has(issue.id) || issueNumbers.has(`${issue.repository.nameWithOwner.toLowerCase()}#${issue.number}`) || issue.repository.nameWithOwner.toLowerCase() === repository.toLowerCase() && issue.repository.id !== baseRepository.id)
730
- throw new DeliveryError("Native closing-issue board identity is incomplete.");
731
- issues.add(issue.id);
732
- issueNumbers.add(`${issue.repository.nameWithOwner.toLowerCase()}#${issue.number}`);
733
- closingLinks.issues.push({
734
- id: issue.id,
735
- number: issue.number,
736
- repository: { id: issue.repository.id, name: issue.repository.nameWithOwner }
737
- });
738
- }
739
- cursor = pageCursor(links, cursors);
740
- if (cursor === null) {
741
- closingLinks.complete = true;
742
- break;
743
- }
744
- }
745
- } catch {
746
- native = null;
747
- }
748
- const [decision, proof] = await Promise.allSettled([
749
- readRequiredReviewState(context, prNumber, pr.head.sha),
750
- readRequiredCheckProof(context, pr.base.ref, pr.head.sha, true)
751
- ]);
752
- const review = decision.status === "fulfilled" ? { ...decision.value, observed: decision.value.observed === true } : {
753
- observed: false,
754
- reviewDecision: null,
755
- status: "unknown",
756
- submittedReviewAuthorCanPushToRepository: null,
757
- nextAction: "Refresh exact-head native review evidence."
758
- };
759
- const checks = {
760
- ...proof.status === "fulfilled" ? proof.value : { state: "waiting", reason: "Native required-check evidence is unavailable." },
761
- complete: proof.status === "fulfilled" && proof.value.state === "passed"
762
- };
763
- const [current, reread] = await Promise.allSettled([
764
- context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${pr.base.ref}` }),
765
- context.clients.rest.pulls.get({ ...context.repo, pull_number: prNumber })
766
- ]);
767
- const ref = current.status === "fulfilled" ? current.value.data : null;
768
- const currentBaseSha = ref?.ref === `refs/heads/${pr.base.ref}` && ref.object.type === "commit" && validSha(ref.object.sha) ? ref.object.sha : null;
769
- const final = reread.status === "fulfilled" ? reread.value.data : null;
770
- const stable = final !== null && final.node_id === pr.node_id && final.number === pr.number && final.head.sha === pr.head.sha && final.base.sha === pr.base.sha && final.head.ref === pr.head.ref && final.base.ref === pr.base.ref && final.head.repo?.node_id === headRepository.id && final.head.repo.full_name?.toLowerCase() === headRepository.name.toLowerCase() && final.base.repo?.node_id === baseRepository.id && final.base.repo.full_name?.toLowerCase() === baseRepository.name.toLowerCase() && final.state === pr.state && final.merged === pr.merged && final.draft === pr.draft && final.body === pr.body && final.title === pr.title && final.mergeable === pr.mergeable && final.mergeable_state === pr.mergeable_state;
771
- const reference = /^References ([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)#[1-9]\d*(?:\r?\n|$)/u.exec(pr.body ?? "");
772
- const nonClosing = reference?.[1]?.toLowerCase() === repository.toLowerCase();
773
- const reasons = [];
774
- if (pr.state !== "open" || pr.merged) reasons.push("pr-closed");
775
- if (pr.draft) reasons.push("draft");
776
- if (nonClosing) reasons.push("non-closing");
777
- if (!native) reasons.push("native-eligibility-unknown");
778
- else if (native.mergeable !== "MERGEABLE" || native.mergeStateStatus !== "CLEAN" || pr.mergeable !== true || pr.mergeable_state !== "clean")
779
- reasons.push("native-not-clean");
780
- if (!review.observed) reasons.push("review-unknown");
781
- else if (review.reviewDecision !== "APPROVED" && review.reviewDecision !== null)
782
- reasons.push(review.reviewDecision === "CHANGES_REQUESTED" ? "changes-requested" : "review-required");
783
- if (checks.state !== "passed") reasons.push(checks.state === "failed" ? "checks-failed" : "checks-unproven");
784
- if (!closingLinks.complete) reasons.push("closing-links-unknown");
785
- else if (!closingLinks.issues.some(
786
- (issue) => issue.repository.id === baseRepository.id && issue.repository.name.toLowerCase() === repository.toLowerCase()
787
- ))
788
- reasons.push("no-closing-issue");
789
- if (!stable) reasons.push("pr-drift-or-unavailable");
790
- if (currentBaseSha !== pr.base.sha) reasons.push("base-moved-or-unavailable");
791
- return {
792
- repository: baseRepository,
793
- headRepository,
794
- number: pr.number,
795
- url: pr.html_url,
796
- title: pr.title,
797
- state: pr.state,
798
- draft: pr.draft,
799
- nonClosing,
800
- headSha: pr.head.sha,
801
- baseSha: pr.base.sha,
802
- headRef: pr.head.ref,
803
- baseRef: pr.base.ref,
804
- currentBaseSha,
805
- mergeable: native?.mergeable ?? null,
806
- mergeStateStatus: native?.mergeStateStatus ?? null,
807
- review,
808
- checks,
809
- closingLinks,
810
- stable,
811
- ready: reasons.length === 0,
812
- reasons
813
- };
632
+ return { names: [...names].sort(), complete };
814
633
  }
815
634
  async function prChecks(context, prNumber) {
816
635
  const pr = await getPr(context, prNumber);
@@ -1020,17 +839,8 @@ async function preflightReviewRoute(context, base, selectedReviewer, purpose = "
1020
839
  }
1021
840
  async function publishPr(context, input) {
1022
841
  const nonClosing = nonClosingMode(input.nonClosing);
1023
- const reconcileReference = nonClosingMode(input.reconcileNonClosingReference);
1024
- if (reconcileReference) {
1025
- if (context.clients.role !== "author" || context.clients.authSource !== (context.config.roles.author.authSource ?? "app") || !context.clients.authenticatedAuthor)
1026
- throw new DeliveryError("Reference reconciliation requires the configured authenticated author role.");
1027
- if (!nonClosing || input.draft === false || !validSha(input.expectedHeadSha) || !validSha(input.expectedBaseSha) || typeof input.body !== "string" || !input.body.trim())
1028
- throw new DeliveryError(
1029
- "Reference reconciliation requires nonClosing, DRAFT, explicit safe body and exact expected head/base SHAs."
1030
- );
1031
- refuseClosingDirective(input.body);
1032
- } else if (input.expectedHeadSha !== void 0 || input.expectedBaseSha !== void 0)
1033
- throw new DeliveryError("Expected head/base inputs require explicit reconcileNonClosingReference.");
842
+ if (input.expectedHeadSha !== void 0 && !validSha(input.expectedHeadSha))
843
+ throw new DeliveryError("expectedHeadSha must be a full 40-character commit SHA; pass the pushed head or omit it.");
1034
844
  if (input.prNumber !== void 0 && (!Number.isSafeInteger(input.prNumber) || input.prNumber <= 0))
1035
845
  throw new DeliveryError("Existing PR selector must be a positive safe integer.");
1036
846
  const issue = nonClosing ? await openReferenceIssue(context, input.issueNumber) : (await context.clients.rest.issues.get({ ...context.repo, issue_number: input.issueNumber })).data;
@@ -1048,7 +858,7 @@ async function publishPr(context, input) {
1048
858
  if (input.headBranch !== void 0) validBranch(input.headBranch);
1049
859
  const explicit = input.prNumber === void 0 ? void 0 : await getPr(context, input.prNumber);
1050
860
  const explicitPromotion = nonClosing && input.draft === false && input.headBranch !== void 0;
1051
- const selectedMatches = explicitPromotion ? await matchingPrs(context, input.headBranch, base) : void 0;
861
+ const selectedMatches = explicitPromotion ? await matchingPrs(context, input.headBranch, base, "open") : void 0;
1052
862
  const branch = explicit ? explicit.head.ref : nonClosing ? explicitPromotion && selectedMatches.length > 0 ? input.headBranch : await issueBranch(context, input.issueNumber, input.headBranch) : input.headBranch ?? await issueBranch(context, input.issueNumber);
1053
863
  if (input.headBranch !== void 0 && branch !== input.headBranch)
1054
864
  throw new DeliveryError("Explicit PR and head selectors disagree.");
@@ -1056,22 +866,20 @@ async function publishPr(context, input) {
1056
866
  const ref = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${branch}` })).data;
1057
867
  if (ref.ref !== `refs/heads/${branch}` || ref.object.type !== "commit" || !validSha(ref.object.sha))
1058
868
  throw new DeliveryError("Remote issue branch head/ref readback is invalid.");
1059
- const matches = selectedMatches ?? await matchingPrs(context, branch, base, nonClosing ? "all" : "open");
869
+ if (input.expectedHeadSha !== void 0 && ref.object.sha !== input.expectedHeadSha)
870
+ throw new DeliveryError(
871
+ `Branch ${branch} is at ${ref.object.sha}, not expectedHeadSha ${input.expectedHeadSha}; push your commit or pass the current head.`
872
+ );
873
+ const matches = selectedMatches ?? await matchingPrs(context, branch, base, "open");
1060
874
  if (matches.length > 1 || explicit && (matches.length !== 1 || matches[0].number !== explicit.number))
1061
875
  throw new DeliveryError("Remote issue branch has conflicting PR matches.");
1062
876
  let pr = explicit ?? (matches[0] === void 0 ? void 0 : await getPr(context, matches[0].number));
1063
877
  if (pr && input.draft === false && input.headBranch === void 0 && input.prNumber === void 0 && (await linkedIssueBranches(context, input.issueNumber)).filter((entry) => entry.name === branch).length !== 1)
1064
878
  throw new DeliveryError("Select an explicit PR or head after GitHub-linked branch references disappear.");
1065
- if (reconcileReference && pr && !explicit)
879
+ if (nonClosing && !pr && input.draft === false)
1066
880
  throw new DeliveryError(
1067
- "Reference reconciliation of an existing match requires explicit --pr and caller-reconciled authority/attempt receipts."
881
+ "A new non-closing PR opens as a draft until its closing link is removed; omit draft, then call again with draft: false to mark it ready."
1068
882
  );
1069
- if (nonClosing && !pr && !reconcileReference)
1070
- throw new DeliveryError(
1071
- "New linked-branch non-closing publication requires explicitly authorized --reconcile-non-closing-reference --expected-head SHA --expected-base SHA and --body-file PATH; bare --non-closing grants no removal authority."
1072
- );
1073
- if (reconcileReference && ref.object.sha !== input.expectedHeadSha)
1074
- throw new DeliveryError("Reference reconciliation expected head differs from the exact remote linked head.");
1075
883
  const requestedBody = input.body ?? pr?.body ?? (nonClosing ? referenceLine(context, input.issueNumber) : closingBody(issue));
1076
884
  if ((nonClosing || input.body !== void 0) && !requestedBody.trim())
1077
885
  throw new DeliveryError("PR body must contain text.");
@@ -1082,10 +890,11 @@ async function publishPr(context, input) {
1082
890
  const closingRepair = !nonClosing && pr !== void 0 && !hasClosingLink(pr.body, input.issueNumber);
1083
891
  const transition = nonClosing && pr !== void 0 && pr.body !== body;
1084
892
  const referenceUpdate = transition && hasReferenceBody(context, input.issueNumber, pr?.body);
1085
- if (reconcileReference && transition)
1086
- throw new DeliveryError("Reference reconciliation refuses body transition; retain exact original intent.");
1087
- if (transition && (input.prNumber === void 0 || input.body === void 0))
1088
- throw new DeliveryError("Non-closing body transition requires an explicit existing PR number and body.");
893
+ if (transition && input.body === void 0)
894
+ throw new DeliveryError(`PR #${pr?.number} is open with a different body; pass body to make it non-closing.`);
895
+ const reconcileReference = nonClosing && !transition && input.draft !== false && (!pr || pr.draft);
896
+ if (reconcileReference && (context.clients.role !== "author" || context.clients.authSource !== (context.config.roles.author.authSource ?? "app") || !context.clients.authenticatedAuthor))
897
+ throw new DeliveryError("Non-closing PR creation needs the configured author credentials; run it as the author.");
1089
898
  if (pr && (pr.head.sha !== ref.object.sha || pr.head.ref !== branch || pr.base.ref !== base || pr.state !== "open" || pr.merged || !transition && input.body !== void 0 && pr.body !== input.body && pr.body !== body || input.title !== void 0 && pr.title !== input.title))
1090
899
  throw new DeliveryError("Existing remote PR conflicts with the requested branch, intent or state.");
1091
900
  const reviewRoute = nonClosing ? await nonClosingRoute(context, base) : { author: await routeAuthor(context, "publication") };
@@ -1097,6 +906,7 @@ async function publishPr(context, input) {
1097
906
  const creationTitle = input.title ?? issue.title;
1098
907
  let publicationBaseSha;
1099
908
  const existing = pr;
909
+ const expectedBaseSha = () => existing?.base.sha ?? publicationBaseSha;
1100
910
  let pendingTransition = transition;
1101
911
  let pendingClosingRepair = closingRepair;
1102
912
  let expectedBody = pr?.body;
@@ -1108,24 +918,26 @@ async function publishPr(context, input) {
1108
918
  };
1109
919
  const readReconciliation = async (selected) => {
1110
920
  try {
1111
- if (selected.state !== "open" || selected.draft !== true || selected.merged || selected.head.sha !== input.expectedHeadSha || selected.base.sha !== input.expectedBaseSha || selected.head.ref !== branch || selected.base.ref !== base || selected.body !== body || selected.title !== (existing?.title ?? creationTitle) || selected.user.login.toLowerCase() !== reviewRoute.author.actorLogin.toLowerCase())
1112
- throw new DeliveryError("Reference reconciliation DRAFT, exact head/base, message or author drifted.");
921
+ if (selected.state !== "open" || selected.draft !== true || selected.merged || selected.head.sha !== ref.object.sha || selected.base.sha !== expectedBaseSha() || selected.head.ref !== branch || selected.base.ref !== base || selected.body !== body || selected.title !== (existing?.title ?? creationTitle) || selected.user.login.toLowerCase() !== reviewRoute.author.actorLogin.toLowerCase())
922
+ throw new DeliveryError(
923
+ "The draft PR changed state, head, base, body, title or author while it was being opened."
924
+ );
1113
925
  const graph = await readNonClosingReference(context, input.issueNumber, selected);
1114
926
  sameReferenceIssue(issue, graph.issue);
1115
927
  const safe = !graph.closesTarget && !graph.allClosing.length && !graph.manualClosing.length;
1116
928
  if (!safe && !(graph.closesTarget && graph.allClosing.length === 1 && graph.manualClosing.length === 1))
1117
929
  throw new DeliveryError(
1118
- "Reference removal requires only the intended manual closing pair and closing cross-reference."
930
+ "The PR has closing links beyond the one GitHub adds for the linked branch; remove them on GitHub, then call again."
1119
931
  );
1120
932
  const currentHead = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${branch}` })).data;
1121
- if (currentHead.ref !== ref.ref || currentHead.object.type !== "commit" || currentHead.object.sha !== input.expectedHeadSha)
1122
- throw new DeliveryError("Reference reconciliation source head drifted.");
933
+ if (currentHead.ref !== ref.ref || currentHead.object.type !== "commit" || currentHead.object.sha !== ref.object.sha)
934
+ throw new DeliveryError(`Branch ${branch} moved while the PR was being opened; call again.`);
1123
935
  sameReferencePr(selected, await getPr(context, selected.number));
1124
936
  await preserveIssue();
1125
937
  return !safe;
1126
938
  } catch (error) {
1127
939
  throw new DeliveryError(
1128
- `PR #${selected.number}; reference removal ${removalState}. Reconcile read-only; do not retry without caller-established authority and attempt history. ${error instanceof Error ? error.message : "Unknown failure"}`
940
+ `PR #${selected.number} closing-link removal ${removalState}; check it with issue_pr_info before calling again. ${error instanceof Error ? error.message : "Unknown failure"}`
1129
941
  );
1130
942
  }
1131
943
  };
@@ -1182,8 +994,6 @@ async function publishPr(context, input) {
1182
994
  if (publicationBaseSha !== void 0 && publicationBaseSha !== baseRef.object.sha)
1183
995
  throw new DeliveryError("Publication default base drifted before creation.");
1184
996
  publicationBaseSha = baseRef.object.sha;
1185
- if (reconcileReference && publicationBaseSha !== input.expectedBaseSha)
1186
- throw new DeliveryError("Reference reconciliation expected default base differs from the remote base.");
1187
997
  if (nonClosing) await verifyUnpublishedCommits(context, baseRef.object.sha, ref.object.sha);
1188
998
  const afterHead = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${branch}` })).data;
1189
999
  const afterBase = (await context.clients.rest.git.getRef({ ...context.repo, ref: `heads/${base}` })).data;
@@ -1301,7 +1111,7 @@ async function publishPr(context, input) {
1301
1111
  removalState = "acknowledged";
1302
1112
  } catch (error) {
1303
1113
  throw new DeliveryError(
1304
- `PR #${pr.number}; reference removal acknowledgement is uncertain. Reconcile read-only; no automatic retry or rollback. ${error instanceof Error ? error.message : "Unknown failure"}`
1114
+ `PR #${pr.number} closing-link removal acknowledgement is uncertain; check it with issue_pr_info before calling again. ${error instanceof Error ? error.message : "Unknown failure"}`
1305
1115
  );
1306
1116
  }
1307
1117
  }
@@ -1382,15 +1192,12 @@ async function submitFormalReview(context, input) {
1382
1192
  }
1383
1193
  }
1384
1194
  export {
1385
- hasDeliveryMergeTrailer,
1386
1195
  hasDeliveryPrMarker,
1387
1196
  listPrs,
1388
1197
  prChecks,
1389
1198
  prInfo,
1390
1199
  preflightReviewRoute,
1391
1200
  publishPr,
1392
- queueChecks,
1393
- readPrBoardFacts,
1394
1201
  startIssueBranch,
1395
1202
  submitFormalReview
1396
1203
  };