pr-shepherd 2.4.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/.claude-plugin/plugin.json +3 -3
  2. package/.grok-plugin/marketplace.json +1 -1
  3. package/README.md +7 -9
  4. package/bin/classify/apply.d.mts +8 -1
  5. package/bin/classify/apply.mjs +37 -47
  6. package/bin/classify/items.d.mts +7 -0
  7. package/bin/classify/items.mjs +57 -0
  8. package/bin/classify/standard/coderabbit-notices.d.mts +2 -1
  9. package/bin/classify/standard/coderabbit-notices.mjs +35 -3
  10. package/bin/classify/standard/index.d.mts +2 -1
  11. package/bin/classify/standard/index.mjs +2 -1
  12. package/bin/classify/types.d.mts +8 -3
  13. package/bin/cli/iterate-lean.mjs +3 -0
  14. package/bin/cli/list-formatters.d.mts +1 -0
  15. package/bin/cli/list-formatters.mjs +3 -1
  16. package/bin/cli/triage-formatter.mjs +6 -1
  17. package/bin/commands/check-activity.mjs +2 -1
  18. package/bin/commands/check-fingerprint.mjs +1 -0
  19. package/bin/commands/check.mjs +39 -9
  20. package/bin/commands/iterate/branch-update.d.mts +19 -0
  21. package/bin/commands/iterate/branch-update.mjs +39 -0
  22. package/bin/commands/iterate/check-instructions.d.mts +3 -1
  23. package/bin/commands/iterate/check-instructions.mjs +26 -6
  24. package/bin/commands/iterate/classify.d.mts +17 -3
  25. package/bin/commands/iterate/classify.mjs +105 -66
  26. package/bin/commands/iterate/escalate.mjs +6 -1
  27. package/bin/commands/iterate/index.mjs +16 -24
  28. package/bin/commands/iterate/native-stack-rebase.d.mts +5 -0
  29. package/bin/commands/iterate/native-stack-rebase.mjs +16 -8
  30. package/bin/commands/iterate/queue-recovery-instructions.mjs +7 -4
  31. package/bin/commands/iterate/queue-removal.mjs +2 -1
  32. package/bin/commands/iterate/render.d.mts +2 -11
  33. package/bin/commands/iterate/render.mjs +10 -19
  34. package/bin/commands/iterate/stall.mjs +3 -0
  35. package/bin/commands/iterate/triage.d.mts +1 -0
  36. package/bin/commands/iterate/triage.mjs +19 -14
  37. package/bin/commands/iterate/unreported-required.mjs +6 -4
  38. package/bin/commands/resolve-mutate.mjs +39 -4
  39. package/bin/commands/resolve-review-guard.d.mts +19 -0
  40. package/bin/commands/resolve-review-guard.mjs +61 -0
  41. package/bin/comments/resolve.mjs +4 -4
  42. package/bin/comments/review-thread-markers.d.mts +1 -1
  43. package/bin/comments/review-thread-markers.mjs +23 -9
  44. package/bin/comments/superseded-approvals.d.mts +28 -0
  45. package/bin/comments/superseded-approvals.mjs +99 -0
  46. package/bin/config/schema.d.mts +10 -0
  47. package/bin/config/schema.mjs +2 -0
  48. package/bin/github/batch-parsers.mjs +31 -0
  49. package/bin/github/batch-raw-types.d.mts +3 -0
  50. package/bin/github/batch-viewer.d.mts +2 -2
  51. package/bin/github/batch.mjs +1 -1
  52. package/bin/github/gql/batch-pr-page.gql +8 -2
  53. package/bin/github/gql/batch-pr.gql +4 -1
  54. package/bin/github/poll-summary-review-helpers.d.mts +20 -0
  55. package/bin/github/poll-summary-review-helpers.mjs +81 -0
  56. package/bin/github/poll-summary-review.mjs +37 -46
  57. package/bin/github/poll-summary-rule-auto-resolve.mjs +1 -0
  58. package/bin/github/poll-summary-rule-items.d.mts +1 -1
  59. package/bin/github/poll-summary-rule-items.mjs +3 -2
  60. package/bin/github/rest-batch-snapshot.mjs +25 -1
  61. package/bin/github/review-unresolved-threads.d.mts +13 -0
  62. package/bin/github/review-unresolved-threads.mjs +152 -0
  63. package/bin/github/stack-handoff-page.mjs +5 -1
  64. package/bin/state/seen-comments.d.mts +3 -1
  65. package/bin/state/seen-comments.mjs +28 -2
  66. package/bin/types/escalate.d.mts +1 -0
  67. package/bin/types/github.d.mts +7 -1
  68. package/bin/types/iterate.d.mts +4 -2
  69. package/bin/types/report.d.mts +8 -0
  70. package/package.json +5 -5
  71. package/plugins/pr-shepherd/.claude-plugin/plugin.json +3 -3
  72. package/plugins/pr-shepherd/.codex-plugin/plugin.json +6 -6
  73. package/plugins/pr-shepherd/skills/pr-shepherd/SKILL.md +1 -1
  74. package/plugins/pr-shepherd/skills/pr-shepherd/references/merge-queue-ejection.md +2 -2
  75. package/plugins/pr-shepherd/skills/pr-shepherd/references/triage-loop.md +1 -1
  76. package/plugins/pr-shepherd/skills/setup-pr-shepherd/SKILL.md +1 -1
  77. package/plugins/pr-shepherd/skills/setup-pr-shepherd/references/classifiers.md +3 -3
  78. package/plugins/pr-shepherd/skills/setup-pr-shepherd/references/upstream-standard-rule.md +2 -2
  79. package/pr-shepherd.schema.json +12 -0
  80. package/src/classify/types.mts +9 -1
@@ -1,5 +1,6 @@
1
1
  import { formatPrUrl } from "../../pr-reference.mjs";
2
2
  import { queueRemovalSignature, readQueueRemovalFollowUp, writeQueueRemovalFollowUp, } from "../../state/queue-removal-follow-up.mjs";
3
+ import { configuredBranchUpdate, NEVER_MERGE_OTHER, updateAndPushClause, } from "./branch-update.mjs";
3
4
  import { playbookPointer } from "../playbook-pointer.mjs";
4
5
  import { buildEscalateHumanMessage, buildEscalateSuggestion } from "./escalate.mjs";
5
6
  import { stateUnavailableResult } from "./state-unavailable.mjs";
@@ -8,7 +9,7 @@ function buildQueueRemovalInstructions(report) {
8
9
  const route = stackRebase(report);
9
10
  const update = route
10
11
  ? `update the stack from the latest base (${route}) and push it`
11
- : "update the PR head from the latest base and push";
12
+ : `${updateAndPushClause(configuredBranchUpdate())}. ${NEVER_MERGE_OTHER}`;
12
13
  return [
13
14
  `GitHub removed PR #${report.pr} from the merge queue, and Shepherd has no failed queue-commit check to triage. The \`**queue removal**\` line above carries the raw reason and actor.`,
14
15
  `Decide from them. If the reason names a merge conflict, an invalid merge commit, or a stack that changed, ${update}. If a person dequeued the PR (the actor is a user, not a bot or \`github-actions\`), make no change and report that. If the reason is missing or unclear, find out why before acting. Never enqueue the PR yourself. ${playbookPointer("Merge queue ejection")}`,
@@ -1,15 +1,6 @@
1
1
  import type { AgentThread, AgentComment, AgentCheck, Review, ResolveCommand, FirstLookThread, FirstLookComment, ReviewThread } from "../../types.mts";
2
2
  import { type QueueEjectionRecovery } from "./queue-recovery-instructions.mts";
3
3
  import type { InstructionStyle } from "../../config/load.mts";
4
- /**
5
- * Render a resolve command as a shell snippet. Appends `--require-sha HEAD` when set: run after
6
- * the push step, the local HEAD is the pushed PR head, and `apply review` rejects the mutations
7
- * if it is not. `apply review` reads that HEAD itself with a read-only `git rev-parse HEAD`.
8
- */
4
+ /** Render a resolve command, appending `--require-sha HEAD` when `requiresHeadSha` is set. */
9
5
  export declare function renderResolveCommand(rc: ResolveCommand): string;
10
- export declare function buildFixInstructions(threads: AgentThread[], actionableComments: AgentComment[], checks: AgentCheck[], changesRequestedReviews: Review[], baseBranch: string, resolveCommand: ResolveCommand, hasConflicts: boolean, prReference: string | number, firstLookThreads?: FirstLookThread[], firstLookComments?: FirstLookComment[], firstLookSummaries?: Review[], editedSummaries?: Review[], resolutionOnlyThreads?: ReviewThread[], resolveOnlyCommand?: ResolveCommand, behindBaseHint?: string, // iterate.behind-base-hint — see buildBehindBaseHintInstruction
11
- isBehind?: boolean, _viewerCanUpdate?: boolean, hasExhaustedWorkflowRerun?: boolean, stackRebase?: string, // native stack layers rebase with gh-stack, not branch by branch
12
- queueEjection?: QueueEjectionRecovery, // current merge-queue removal with failing queue checks
13
- instructionStyle?: InstructionStyle, // see iterate.instructions
14
- dequeueCommand?: string, // a conflicting PR that is still a merge-queue entry
15
- cancelRunsStep?: string): string[];
6
+ export declare function buildFixInstructions(threads: AgentThread[], actionableComments: AgentComment[], checks: AgentCheck[], changesRequestedReviews: Review[], baseBranch: string, resolveCommand: ResolveCommand, hasConflicts: boolean, prReference: string | number, firstLookThreads?: FirstLookThread[], firstLookComments?: FirstLookComment[], firstLookSummaries?: Review[], editedSummaries?: Review[], resolutionOnlyThreads?: ReviewThread[], resolveOnlyCommand?: ResolveCommand, behindBaseHint?: string, isBehind?: boolean, _viewerCanUpdate?: boolean, hasExhaustedWorkflowRerun?: boolean, stackRebase?: string, queueEjection?: QueueEjectionRecovery, instructionStyle?: InstructionStyle, dequeueCommand?: string, cancelRunsStep?: string, dismissReviewsCommand?: ResolveCommand): string[];
@@ -1,27 +1,18 @@
1
1
  import { buildPrShepherdCommand, renderShellCommand } from "../../cli/runner.mjs";
2
- import { buildFailingCheckInstructions, buildCrStaleClause, buildBehindBaseHintInstruction, buildRepeatedWorkflowBranchRecoveryInstructions, buildResolveCommandInstruction, buildFixCompletionInstruction, QUEUED_CONFLICT_CONTINUATION, } from "./check-instructions.mjs";
2
+ import { buildFailingCheckInstructions, buildCrStaleClause, buildBehindBaseHintInstruction, buildRepeatedWorkflowBranchRecoveryInstructions, buildResolveCommandInstruction, buildDismissReviewsCommandInstruction, buildFixCompletionInstruction, QUEUED_CONFLICT_CONTINUATION, } from "./check-instructions.mjs";
3
3
  import { isFailingAgentCheck } from "../../checks/conclusions.mjs";
4
4
  import { buildCommitSuggestionInstruction } from "../commit-suggestion-instruction.mjs";
5
5
  import { partitionFixThreads } from "./fix-instruction-threads.mjs";
6
6
  import { buildBranchPushInstruction, buildConflictInstruction, buildQueuedConflictChoice, } from "./native-stack-rebase.mjs";
7
7
  import { queueEjectionSteps } from "./queue-recovery-instructions.mjs";
8
8
  import { buildPushSteps } from "./triage-loop-instruction.mjs";
9
- /**
10
- * Render a resolve command as a shell snippet. Appends `--require-sha HEAD` when set: run after
11
- * the push step, the local HEAD is the pushed PR head, and `apply review` rejects the mutations
12
- * if it is not. `apply review` reads that HEAD itself with a read-only `git rev-parse HEAD`.
13
- */
9
+ /** Render a resolve command, appending `--require-sha HEAD` when `requiresHeadSha` is set. */
14
10
  export function renderResolveCommand(rc) {
15
11
  const command = renderShellCommand(rc.argv);
16
12
  return rc.requiresHeadSha ? `${command} ${REQUIRE_HEAD_SHA}` : command;
17
13
  }
18
14
  const REQUIRE_HEAD_SHA = "--require-sha HEAD";
19
- export function buildFixInstructions(threads, actionableComments, checks, changesRequestedReviews, baseBranch, resolveCommand, hasConflicts, prReference, firstLookThreads = [], firstLookComments = [], firstLookSummaries = [], editedSummaries = [], resolutionOnlyThreads = [], resolveOnlyCommand, behindBaseHint = "", // iterate.behind-base-hint — see buildBehindBaseHintInstruction
20
- isBehind = false, _viewerCanUpdate = false, hasExhaustedWorkflowRerun = false, stackRebase, // native stack layers rebase with gh-stack, not branch by branch
21
- queueEjection, // current merge-queue removal with failing queue checks
22
- instructionStyle = "inline", // see iterate.instructions
23
- dequeueCommand, // a conflicting PR that is still a merge-queue entry
24
- cancelRunsStep) {
15
+ export function buildFixInstructions(threads, actionableComments, checks, changesRequestedReviews, baseBranch, resolveCommand, hasConflicts, prReference, firstLookThreads = [], firstLookComments = [], firstLookSummaries = [], editedSummaries = [], resolutionOnlyThreads = [], resolveOnlyCommand, behindBaseHint = "", isBehind = false, _viewerCanUpdate = false, hasExhaustedWorkflowRerun = false, stackRebase, queueEjection, instructionStyle = "inline", dequeueCommand, cancelRunsStep, dismissReviewsCommand) {
25
16
  const instructions = [];
26
17
  const { locatedThreads, unlocatedThreads } = partitionFixThreads(threads, resolveCommand, resolveOnlyCommand);
27
18
  const failingChecks = checks.filter((c) => isFailingAgentCheck(c));
@@ -33,20 +24,16 @@ cancelRunsStep) {
33
24
  hasAnnotations ||
34
25
  changesRequestedReviews.length > 0 ||
35
26
  actionableComments.length > 0;
36
- // Start with interpretation. The agent decides what raw feedback warrants a code change.
37
- // A queued conflict offers a wait path that publishes nothing, so fixes, branch updates,
38
- // pushes, and review mutations (which must follow a push) become path (a).
27
+ // A queued conflict offers a wait path that publishes nothing, so mutating steps become path (a).
39
28
  const pathA = (step) => (dequeueCommand ? `If you chose (a): ${step}` : step);
40
29
  if (cancelRunsStep)
41
30
  instructions.push(cancelRunsStep);
42
31
  if (hasNonConflictHints)
43
32
  instructions.push(pathA("Fix each warranted item."));
44
- // A conflicting native stack layer follows the printed gh-stack route, so it omits the hint.
45
33
  const branchUpdateHint = buildBehindBaseHintInstruction(baseBranch, behindBaseHint, {
46
34
  isBehind,
47
35
  hasConflicts: hasConflicts && !stackRebase,
48
36
  }).map(pathA);
49
- // The conflict hint belongs with the conflict step; otherwise it precedes the push step.
50
37
  const hintWithConflictStep = hasConflicts && !hasRepeatedWorkflowBranchRecovery;
51
38
  const branchRecovery = hasConflicts || hasRepeatedWorkflowBranchRecovery;
52
39
  if (hintWithConflictStep)
@@ -89,7 +76,9 @@ cancelRunsStep) {
89
76
  const journalCommand = buildPrShepherdCommand(["apply", "journal", String(prReference)]).text;
90
77
  instructions.push(`Optional: If you reject a code review suggestion, journal why: \`${journalCommand} '- <reason>'\`.`);
91
78
  }
92
- const hasReviewMutations = resolveCommand.hasMutations || resolveOnlyCommand?.hasMutations === true;
79
+ const hasReviewMutations = resolveCommand.hasMutations ||
80
+ resolveOnlyCommand?.hasMutations === true ||
81
+ dismissReviewsCommand?.hasMutations === true;
93
82
  const mutationSuffix = hasReviewMutations ? " before review mutations" : "";
94
83
  const genericPush = !(branchRecovery || queueEjection) && hasNonConflictHints;
95
84
  if (branchRecovery || queueEjection) {
@@ -98,6 +87,8 @@ cancelRunsStep) {
98
87
  instructions.push(...buildPushSteps(instructionStyle, genericPush));
99
88
  if (resolveOnlyCommand?.hasMutations)
100
89
  instructions.push(pathA(`Run: \`${renderResolveCommand(resolveOnlyCommand)}\``));
101
- instructions.push(...buildResolveCommandInstruction(resolveCommand, renderResolveCommand(resolveCommand)).map(pathA), dequeueCommand ? QUEUED_CONFLICT_CONTINUATION : buildFixCompletionInstruction());
90
+ instructions.push(...buildResolveCommandInstruction(resolveCommand, renderResolveCommand(resolveCommand)).map(pathA), ...(dismissReviewsCommand?.hasMutations
91
+ ? buildDismissReviewsCommandInstruction(dismissReviewsCommand, renderResolveCommand(dismissReviewsCommand)).map(pathA)
92
+ : []), dequeueCommand ? QUEUED_CONFLICT_CONTINUATION : buildFixCompletionInstruction());
102
93
  return instructions;
103
94
  }
@@ -17,6 +17,9 @@ function pendingReviewCommandsFromResult(result) {
17
17
  ...(result.triage.resolveCommand.hasMutations && {
18
18
  resolveCommand: result.triage.resolveCommand,
19
19
  }),
20
+ ...(result.triage.dismissReviewsCommand?.hasMutations && {
21
+ dismissReviewsCommand: result.triage.dismissReviewsCommand,
22
+ }),
20
23
  };
21
24
  return Object.keys(pending).length > 0 ? pending : undefined;
22
25
  }
@@ -19,6 +19,7 @@ interface HandleTriageContext {
19
19
  editedSummaries: Review[];
20
20
  surfacedApprovals: Review[];
21
21
  botUsernames: NormalizedBotUsernames;
22
+ blockedReviewIds?: ReadonlySet<string>;
22
23
  /** Failing checks whose external blocker has merged or closed. */
23
24
  releasedCheckNames?: ReadonlySet<string>;
24
25
  /** Released check name → the blocker that merged or closed, shown on the check. */
@@ -59,10 +59,11 @@ function previousFixAttempts(stored, threads) {
59
59
  }
60
60
  return attempts;
61
61
  }
62
- function pendingReviewCommands(resolveCommand, resolveOnlyCommand) {
62
+ function pendingReviewCommands(resolveCommand, resolveOnlyCommand, dismissReviewsCommand) {
63
63
  const pending = {
64
64
  ...(resolveOnlyCommand?.hasMutations && { resolveOnlyCommand }),
65
65
  ...(resolveCommand.hasMutations && { resolveCommand }),
66
+ ...(dismissReviewsCommand?.hasMutations && { dismissReviewsCommand }),
66
67
  };
67
68
  return Object.keys(pending).length > 0 ? pending : undefined;
68
69
  }
@@ -75,7 +76,7 @@ export async function handleTriage(ctx) {
75
76
  return { ...result, escalate: { ...result.escalate, reviewItems } };
76
77
  }
77
78
  async function handleTriageTick(ctx) {
78
- const { base, report, opts, headSha, stallKey, prNumber, stallTimeoutSeconds, repoOwner, repoName, reviewSummaryIds, firstLookSummaries, editedSummaries, surfacedApprovals, botUsernames, releasedCheckNames = EMPTY_RELEASED, releasedCheckBlockers, ruleAutoResolveThreadIds, repairInstructions, } = ctx;
79
+ const { base, report, opts, headSha, stallKey, prNumber, stallTimeoutSeconds, repoOwner, repoName, reviewSummaryIds, firstLookSummaries, editedSummaries, surfacedApprovals, botUsernames, blockedReviewIds, releasedCheckNames = EMPTY_RELEASED, releasedCheckBlockers, ruleAutoResolveThreadIds, repairInstructions, } = ctx;
79
80
  const prReference = formatPrUrl(report.repo, prNumber);
80
81
  const failingChecks = report.checks.failing;
81
82
  const annotatedExtra = checksWithActionableAnnotations(report).filter((c) => c.category !== "failing");
@@ -110,16 +111,17 @@ async function handleTriageTick(ctx) {
110
111
  const changesRequestedReviewsForWork = actionableChangesRequestedReviews.filter((review) => !unauthorizedDismissals.some((candidate) => candidate.id === review.id));
111
112
  const buildReviewCommands = (checks) => buildResolveCommand(report.threads.actionable
112
113
  .filter((thread) => mutationActionableThreads.some((candidate) => candidate.id === thread.id))
113
- .map(toAgentThread), resolutionOnlyThreadsForWork, [
114
- ...(report.comments.minimizeIds ?? report.comments.actionable.map((comment) => comment.id)),
115
- ...reviewSummaryIds,
116
- ], changesRequestedReviewsForWork, checks, prReference, botUsernames, ruleAutoResolveThreadIds, report.viewerAuthorization, allThreads, resolveOtherHumanThreads);
114
+ .map(toAgentThread), resolutionOnlyThreadsForWork, report.comments.minimizeIds ?? report.comments.actionable.map((comment) => comment.id), changesRequestedReviewsForWork, checks, prReference, botUsernames, ruleAutoResolveThreadIds, report.viewerAuthorization, allThreads, resolveOtherHumanThreads, {
115
+ reviewMinimizeIds: reviewSummaryIds,
116
+ blockedReviewIds,
117
+ minimizeComments: loadConfig().iterate["minimize-comments"],
118
+ });
117
119
  const escalateTriggers = countTriageAttempt
118
120
  ? checkEscalateTriggers(retryableActionableThreads, priorThreadAttempts)
119
121
  : { triggers: [], thrashHistory: undefined };
120
122
  if (escalateTriggers.triggers.length > 0) {
121
- const { resolveCommand, resolveOnlyCommand } = buildReviewCommands(toAgentChecks(failingChecks));
122
- const pending = pendingReviewCommands(resolveCommand, resolveOnlyCommand);
123
+ const { resolveCommand, resolveOnlyCommand, dismissReviewsCommand } = buildReviewCommands(toAgentChecks(failingChecks));
124
+ const pending = pendingReviewCommands(resolveCommand, resolveOnlyCommand, dismissReviewsCommand);
123
125
  const escalateBase = {
124
126
  triggers: escalateTriggers.triggers,
125
127
  unresolvedThreads: [...report.threads.actionable, ...report.threads.resolutionOnly].map(toAgentThread),
@@ -189,7 +191,9 @@ async function handleTriageTick(ctx) {
189
191
  annotationOnly: true,
190
192
  }));
191
193
  const checks = [...failingAgentChecks, ...annotatedAgentChecks];
192
- const { changesRequestedReviews } = report;
194
+ const changesRequestedReviews = report.changesRequestedReviews.map((review) => review.staleBotCr && blockedReviewIds?.has(review.id)
195
+ ? { ...review, pendingInlineThreads: true }
196
+ : review);
193
197
  const hasConflicts = report.mergeStatus.status === "CONFLICTS";
194
198
  const queuedConflict = isQueuedConflict(report.mergeQueue?.inQueue, report.mergeStatus.status);
195
199
  const isBehind = report.mergeStatus.status === "BEHIND";
@@ -239,8 +243,8 @@ async function handleTriageTick(ctx) {
239
243
  !hasAutonomousWork &&
240
244
  !investigated;
241
245
  if (terminalChecks.length > 0 && !hasAutonomousWork && investigated) {
242
- const { resolveCommand, resolveOnlyCommand } = buildReviewCommands(failingAgentChecks);
243
- const pending = pendingReviewCommands(resolveCommand, resolveOnlyCommand);
246
+ const { resolveCommand, resolveOnlyCommand, dismissReviewsCommand } = buildReviewCommands(failingAgentChecks);
247
+ const pending = pendingReviewCommands(resolveCommand, resolveOnlyCommand, dismissReviewsCommand);
244
248
  const terminalExhausted = exhaustedAttempts.filter((check) => terminalChecks.includes(check));
245
249
  const checkSuggestion = terminalExhausted.length > 0
246
250
  ? `GitHub reports a later workflow attempt (${terminalExhausted
@@ -285,7 +289,7 @@ async function handleTriageTick(ctx) {
285
289
  }
286
290
  // Push access to the PR head branch is a usage precondition. Build review mutations for
287
291
  // conflict ticks normally so the caller can push and complete the same triage cycle.
288
- const { resolveCommand, resolveOnlyCommand } = buildReviewCommands(failingAgentChecks);
292
+ const { resolveCommand, resolveOnlyCommand, dismissReviewsCommand } = buildReviewCommands(failingAgentChecks);
289
293
  const firstLookThreads = report.threads.firstLook;
290
294
  const firstLookComments = report.comments.firstLook;
291
295
  const stack = report.mergeStatus.mergeRequirements?.stack;
@@ -358,7 +362,7 @@ async function handleTriageTick(ctx) {
358
362
  ? renderShellCommand(buildDequeueCommand(report.nodeId))
359
363
  : undefined;
360
364
  const inProgressRuns = await buildInProgressRuns(report, rerunAuthorized);
361
- const instructions = buildFixInstructions(threads, actionableComments, triageChecks.filter((check) => !releasedCheckNames.has(check.name)), changesRequestedReviews, baseLookup.branch, resolveCommand, hasConflicts, prReference, firstLookThreads, firstLookComments, firstLookSummaries, editedSummaries, resolutionOnlyThreads, resolveOnlyCommand, behindBaseHint, isBehind, canGenerateGithubMutation(report.viewerAuthorization?.viewerCanUpdate, "ready"), exhaustedAttempts.length > 0, stackRebase, queueEjection, opts.instructions ?? configuredInstructions, dequeueCommand, buildCancelRunsInstruction(inProgressRuns));
365
+ const instructions = buildFixInstructions(threads, actionableComments, triageChecks.filter((check) => !releasedCheckNames.has(check.name)), changesRequestedReviews, baseLookup.branch, resolveCommand, hasConflicts, prReference, firstLookThreads, firstLookComments, firstLookSummaries, editedSummaries, resolutionOnlyThreads, resolveOnlyCommand, behindBaseHint, isBehind, canGenerateGithubMutation(report.viewerAuthorization?.viewerCanUpdate, "ready"), exhaustedAttempts.length > 0, stackRebase, queueEjection, opts.instructions ?? configuredInstructions, dequeueCommand, buildCancelRunsInstruction(inProgressRuns), dismissReviewsCommand);
362
366
  if (investigate) {
363
367
  // The failing-checks pointer is replaced: these checks have no excerpt for the CI playbook.
364
368
  const triageStep = instructions.findIndex((step) => step.startsWith("Triage `## Failing checks`."));
@@ -384,7 +388,7 @@ async function handleTriageTick(ctx) {
384
388
  };
385
389
  if (failingAgentChecks.some((check) => releasedCheckNames.has(check.name))) {
386
390
  const completion = instructions.pop();
387
- instructions.push(pathA(buildReleasedBlockerInstruction(prNumber)));
391
+ instructions.push(pathA(buildReleasedBlockerInstruction(prNumber, buildNativeStackLayerRebase(report.repo, { number: prNumber, baseBranch: baseLookup.unusable ? undefined : baseLookup.branch }, stack, trunkConflict, report.stackBottomPr))));
388
392
  if (completion !== undefined)
389
393
  instructions.push(completion);
390
394
  }
@@ -450,6 +454,7 @@ async function handleTriageTick(ctx) {
450
454
  changesRequestedReviews,
451
455
  resolveCommand,
452
456
  ...(resolveOnlyCommand !== undefined ? { resolveOnlyCommand } : undefined),
457
+ ...(dismissReviewsCommand !== undefined ? { dismissReviewsCommand } : undefined),
453
458
  instructions,
454
459
  firstLookThreads,
455
460
  firstLookComments,
@@ -3,7 +3,8 @@ import { formatPrUrl } from "../../pr-reference.mjs";
3
3
  import { readCiRetrigger, sameCiRetrigger, writeCiRetrigger } from "../../state/ci-retrigger.mjs";
4
4
  import { buildFixCompletionInstruction } from "./check-instructions.mjs";
5
5
  import { buildEscalateHumanMessage, buildEscalateSuggestion } from "./escalate.mjs";
6
- import { buildNativeStackRebaseInstruction } from "./native-stack-rebase.mjs";
6
+ import { buildNativeStackRebaseInstruction, stackRebaseAndPush } from "./native-stack-rebase.mjs";
7
+ import { configuredBranchUpdate, NEVER_MERGE_OTHER, pushHeadClause, updateFromBase, } from "./branch-update.mjs";
7
8
  import { playbookPointer } from "../playbook-pointer.mjs";
8
9
  import { getGithubTransport } from "../../github/transport.mjs";
9
10
  /** Rebase when the trunk or the PR base is behind; otherwise close and reopen once. */
@@ -39,12 +40,13 @@ function buildUnreportedRequiredInstructions(input) {
39
40
  `If the cause is within this PR, fix it and push. If the workflows should have run and the PR is fine, retrigger once: ${retrigger}. Otherwise make no change and keep what you found. If the checks are still missing on the next poll, Shepherd escalates with \`required-checks-unreported\`; report that diagnosis then.`,
40
41
  ];
41
42
  }
43
+ const method = configuredBranchUpdate();
42
44
  const rebase = input.stackRebase
43
- ? `${input.stackRebase} Then push the rewritten stack${getGithubTransport() === "rest" ? " using the repository's stack-update procedure" : " with `gh stack push`"}.`
44
- : `Rebase onto \`${input.baseBranch}\` and push.`;
45
+ ? stackRebaseAndPush(input.stackRebase)
46
+ : `${updateFromBase(method, "the branch", input.baseBranch)} and ${pushHeadClause(method)}. ${NEVER_MERGE_OTHER}`;
45
47
  return [
46
48
  facts,
47
- `${rebase} Rebase and push is how these checks start.`,
49
+ `${rebase} Updating and pushing is how these checks start.`,
48
50
  `If that push does not start the checks, find out why nothing started. ${playbook} Shepherd escalates with \`required-checks-unreported\` when the branch is current and this remains the only blocker.`,
49
51
  ];
50
52
  }
@@ -2,7 +2,8 @@ import { getRepoInfo, getCurrentPrNumber } from "../github/client.mjs";
2
2
  import { applyResolveOptions } from "../comments/resolve.mjs";
3
3
  import { fetchReplyThreadTranscripts } from "../github/reply-thread-transcripts.mjs";
4
4
  import { readApplyReviewPreflight, } from "../github/apply-review-preflight.mjs";
5
- import { markReplySeen } from "../state/seen-comments.mjs";
5
+ import { BLOCKED_REVIEW_INSTRUCTION, collectReviewIdsToGuard, formatBlockedReviewErrors, resolveBlockedReviews, } from "./resolve-review-guard.mjs";
6
+ import { markReplySeen, pruneResolvedReviewThreads } from "../state/seen-comments.mjs";
6
7
  import { threadTranscriptBodies } from "../threads/transcript.mjs";
7
8
  import { addPrShepherdMarker } from "../comments/marker.mjs";
8
9
  import { adoptedReplyThreads } from "../comments/uncertain-replies.mjs";
@@ -37,19 +38,50 @@ export async function runResolveMutate(opts) {
37
38
  // the explicit mutation request; GitHub's mutation response is authoritative.
38
39
  }
39
40
  }
41
+ const stateKey = { owner: repo.owner, repo: repo.name, pr: prNumber };
42
+ // Guard: never allow dismissing or hiding a review while any of its inline threads are
43
+ // unresolved — even if those threads are also passed to `--resolve-thread-ids` in the same
44
+ // command. Local markers track each review's unresolved threads across `check` and `apply`,
45
+ // so already-resolved reviews need zero GraphQL calls; GitHub is only queried when local
46
+ // state still has unresolved thread IDs (to check for external resolution) or has no record yet.
47
+ const reviewIdsToCheck = collectReviewIdsToGuard(opts.dismissReviewIds, opts.minimizeCommentIds);
48
+ const blockedByReview = reviewIdsToCheck.length > 0
49
+ ? await resolveBlockedReviews(stateKey, prNumber, repo, reviewIdsToCheck)
50
+ : new Map();
51
+ const blockedErrors = formatBlockedReviewErrors(blockedByReview);
52
+ const allowedDismissReviewIds = opts.dismissReviewIds?.filter((id) => !blockedByReview.has(id));
53
+ const allowedMinimizeCommentIds = opts.minimizeCommentIds?.filter((id) => !blockedByReview.has(id));
54
+ const hasAllowedMutations = (opts.resolveThreadIds?.length ?? 0) > 0 ||
55
+ (opts.replyThreadIds?.length ?? 0) > 0 ||
56
+ (allowedMinimizeCommentIds?.length ?? 0) > 0 ||
57
+ (allowedDismissReviewIds?.length ?? 0) > 0;
58
+ if (!hasAllowedMutations && blockedErrors.length > 0) {
59
+ return {
60
+ repliedThreads: [],
61
+ resolvedThreads: [],
62
+ minimizedComments: [],
63
+ dismissedReviews: [],
64
+ errors: blockedErrors,
65
+ instructions: [BLOCKED_REVIEW_INSTRUCTION],
66
+ };
67
+ }
40
68
  // Iterate capability-checks and routes its generated commands. Direct apply
41
- // requests are user-directed: forward every supplied ID unchanged and let
69
+ // requests are user-directed: forward every remaining supplied ID unchanged and let
42
70
  // GitHub report whether each requested mutation is permitted or applicable.
43
71
  // Only generated durable-state commands carry `--adopt-existing-replies`.
44
72
  const result = await applyResolveOptions(prNumber, repo, {
45
73
  resolveThreadIds: opts.resolveThreadIds,
46
74
  replyThreadIds: opts.replyThreadIds,
47
- minimizeCommentIds: opts.minimizeCommentIds,
48
- dismissReviewIds: opts.dismissReviewIds,
75
+ minimizeCommentIds: allowedMinimizeCommentIds,
76
+ dismissReviewIds: allowedDismissReviewIds,
49
77
  dismissMessage: opts.dismissMessage,
50
78
  requireSha: opts.requireSha,
51
79
  ...(opts.adoptExistingReplies && { adoptExistingReplies: true }),
52
80
  }, ...(preflight ? [preflight] : []));
81
+ if (blockedErrors.length > 0) {
82
+ result.errors.push(...blockedErrors);
83
+ result.instructions = [...(result.instructions ?? []), BLOCKED_REVIEW_INSTRUCTION];
84
+ }
53
85
  const adopted = new Set(adoptedReplyThreads(result));
54
86
  let adoptedTranscripts;
55
87
  if (adopted.size) {
@@ -72,5 +104,8 @@ export async function runResolveMutate(opts) {
72
104
  return markReplySeen({ owner: repo.owner, repo: repo.name, pr: prNumber }, id, previousBody, currentBody ?? threadTranscriptBodies([previousBody, markedMessage]), markedMessage);
73
105
  }));
74
106
  }
107
+ if (result.resolvedThreads.length > 0) {
108
+ await pruneResolvedReviewThreads(stateKey, result.resolvedThreads);
109
+ }
75
110
  return result;
76
111
  }
@@ -0,0 +1,19 @@
1
+ export declare const BLOCKED_REVIEW_INSTRUCTION = "Resolve every unresolved inline thread belonging to the blocked review(s) first, then run a separate `apply review` command to dismiss/hide the review.";
2
+ export declare function collectReviewIdsToGuard(dismissReviewIds?: readonly string[], minimizeCommentIds?: readonly string[]): string[];
3
+ export declare function formatBlockedReviewErrors(blockedByReview: ReadonlyMap<string, string[]>): string[];
4
+ /**
5
+ * Determine which target review IDs still have unresolved inline threads.
6
+ *
7
+ * Uses local seen-marker tracking (`unresolvedInlineThreadIds`) so reviews whose
8
+ * inline threads were already resolved require zero GitHub calls. GitHub is only
9
+ * queried when local state still lists unresolved thread IDs (targeted `nodes(ids:)`
10
+ * lookup to detect out-of-band resolution) or when no local record exists yet.
11
+ */
12
+ export declare function resolveBlockedReviews(stateKey: {
13
+ owner: string;
14
+ repo: string;
15
+ pr: number;
16
+ }, prNumber: number, repo: {
17
+ owner: string;
18
+ name: string;
19
+ }, reviewIds: readonly string[]): Promise<Map<string, string[]>>;
@@ -0,0 +1,61 @@
1
+ import { checkThreadsStillUnresolved, findUnresolvedThreadsByReviewId, isReviewNodeId, } from "../github/review-unresolved-threads.mjs";
2
+ import { loadSeenMap, markReviewUnresolvedThreads } from "../state/seen-comments.mjs";
3
+ export const BLOCKED_REVIEW_INSTRUCTION = "Resolve every unresolved inline thread belonging to the blocked review(s) first, then run a separate `apply review` command to dismiss/hide the review.";
4
+ export function collectReviewIdsToGuard(dismissReviewIds, minimizeCommentIds) {
5
+ return [
6
+ ...new Set([...(dismissReviewIds ?? []), ...(minimizeCommentIds ?? []).filter(isReviewNodeId)]),
7
+ ];
8
+ }
9
+ export function formatBlockedReviewErrors(blockedByReview) {
10
+ return [...blockedByReview.entries()].map(([reviewId, threadIds]) => {
11
+ const noun = threadIds.length === 1 ? "thread remains" : "threads remain";
12
+ return `Refused to dismiss/hide review ${reviewId}: ${threadIds.length} unresolved inline ${noun} (${threadIds.join(", ")}). Resolve all inline threads first, then dismiss/hide the review in a separate command.`;
13
+ });
14
+ }
15
+ /**
16
+ * Determine which target review IDs still have unresolved inline threads.
17
+ *
18
+ * Uses local seen-marker tracking (`unresolvedInlineThreadIds`) so reviews whose
19
+ * inline threads were already resolved require zero GitHub calls. GitHub is only
20
+ * queried when local state still lists unresolved thread IDs (targeted `nodes(ids:)`
21
+ * lookup to detect out-of-band resolution) or when no local record exists yet.
22
+ */
23
+ export async function resolveBlockedReviews(stateKey, prNumber, repo, reviewIds) {
24
+ const seen = await loadSeenMap(stateKey);
25
+ const blocked = new Map();
26
+ const cachedWithUnresolved = new Map();
27
+ const coldReviewIds = [];
28
+ for (const reviewId of reviewIds) {
29
+ const raw = seen.get(reviewId)?.unresolvedInlineThreadIds;
30
+ if (!Array.isArray(raw)) {
31
+ coldReviewIds.push(reviewId);
32
+ continue;
33
+ }
34
+ const pending = raw.filter((id) => typeof id === "string");
35
+ if (pending.length > 0)
36
+ cachedWithUnresolved.set(reviewId, pending);
37
+ // Empty cached array means all inline threads were already resolved — zero GitHub calls.
38
+ }
39
+ if (cachedWithUnresolved.size > 0) {
40
+ const allPending = [...new Set([...cachedWithUnresolved.values()].flat())];
41
+ const stillUnresolved = await checkThreadsStillUnresolved(prNumber, repo, allPending);
42
+ const updates = [];
43
+ for (const [reviewId, pending] of cachedWithUnresolved) {
44
+ const remaining = pending.filter((id) => stillUnresolved.has(id));
45
+ if (remaining.length > 0)
46
+ blocked.set(reviewId, remaining);
47
+ if (remaining.length !== pending.length) {
48
+ updates.push(markReviewUnresolvedThreads(stateKey, reviewId, remaining));
49
+ }
50
+ }
51
+ await Promise.allSettled(updates);
52
+ }
53
+ if (coldReviewIds.length > 0) {
54
+ const coldBlocked = await findUnresolvedThreadsByReviewId(prNumber, repo, coldReviewIds);
55
+ await Promise.allSettled(coldReviewIds.map((reviewId) => markReviewUnresolvedThreads(stateKey, reviewId, coldBlocked.get(reviewId) ?? [])));
56
+ for (const [reviewId, threadIds] of coldBlocked) {
57
+ blocked.set(reviewId, threadIds);
58
+ }
59
+ }
60
+ return blocked;
61
+ }
@@ -134,20 +134,20 @@ function buildBulkMutation(replyIds, resolveIds, minimizeIds, dismissIds, dismis
134
134
  for (let i = 0; i < resolveIds.length; i++) {
135
135
  ops.push(` r${i}: resolveReviewThread(input: { threadId: ${JSON.stringify(resolveIds[i])} }) { thread { isResolved } }`);
136
136
  }
137
- for (let i = 0; i < minimizeIds.length; i++) {
138
- ops.push(` m${i}: minimizeComment(input: { subjectId: ${JSON.stringify(minimizeIds[i])}, classifier: RESOLVED }) { minimizedComment { isMinimized } }`);
139
- }
140
137
  for (let i = 0; i < dismissIds.length; i++) {
141
138
  ops.push(` d${i}: dismissPullRequestReview(input: { pullRequestReviewId: ${JSON.stringify(dismissIds[i])}, message: ${JSON.stringify(dismissMessage)} }) { pullRequestReview { state } }`);
142
139
  }
140
+ for (let i = 0; i < minimizeIds.length; i++) {
141
+ ops.push(` m${i}: minimizeComment(input: { subjectId: ${JSON.stringify(minimizeIds[i])}, classifier: RESOLVED }) { minimizedComment { isMinimized } }`);
142
+ }
143
143
  return `mutation BulkApply {\n${ops.join("\n")}\n}`;
144
144
  }
145
145
  async function bulkApply(replyIds, resolveIds, minimizeIds, dismissIds, dismissMessage, result, context, firstChunkEvidence) {
146
146
  const allOps = [
147
147
  ...replyIds.map((id) => ({ kind: "p", id })),
148
148
  ...resolveIds.map((id) => ({ kind: "r", id })),
149
- ...minimizeIds.map((id) => ({ kind: "m", id })),
150
149
  ...dismissIds.map((id) => ({ kind: "d", id })),
150
+ ...minimizeIds.map((id) => ({ kind: "m", id })),
151
151
  ];
152
152
  for (let i = 0; i < allOps.length; i += BULK_CHUNK_SIZE) {
153
153
  const chunk = allOps.slice(i, i + BULK_CHUNK_SIZE);
@@ -4,5 +4,5 @@ interface StateKey {
4
4
  repo: string;
5
5
  pr: number;
6
6
  }
7
- export declare function markReviewInlineThreadMarkers(key: StateKey, threads: readonly ReviewThread[]): Promise<void>;
7
+ export declare function markReviewInlineThreadMarkers(key: StateKey, threads: readonly ReviewThread[], reviewIds?: readonly string[]): Promise<void>;
8
8
  export {};
@@ -1,18 +1,32 @@
1
- import { markReviewInlineThreads } from "../state/seen-comments.mjs";
2
- function groupInlineThreadIdsByReview(threads) {
1
+ import { markReviewInlineThreads, markReviewUnresolvedThreads } from "../state/seen-comments.mjs";
2
+ function groupInlineThreadsByReview(threads) {
3
3
  const byReview = new Map();
4
4
  for (const thread of threads) {
5
5
  if (thread.reviewId === undefined)
6
6
  continue;
7
- const ids = byReview.get(thread.reviewId) ?? new Set();
8
- ids.add(thread.id);
9
- byReview.set(thread.reviewId, ids);
7
+ const entry = byReview.get(thread.reviewId) ?? {
8
+ all: new Set(),
9
+ unresolved: new Set(),
10
+ };
11
+ entry.all.add(thread.id);
12
+ if (thread.isResolved !== true)
13
+ entry.unresolved.add(thread.id);
14
+ byReview.set(thread.reviewId, entry);
10
15
  }
11
- return new Map([...byReview.entries()].map(([reviewId, ids]) => [
16
+ return new Map([...byReview.entries()].map(([reviewId, entry]) => [
12
17
  reviewId,
13
- [...ids].sort((a, b) => a.localeCompare(b)),
18
+ {
19
+ all: [...entry.all].sort((a, b) => a.localeCompare(b)),
20
+ unresolved: [...entry.unresolved].sort((a, b) => a.localeCompare(b)),
21
+ },
14
22
  ]));
15
23
  }
16
- export async function markReviewInlineThreadMarkers(key, threads) {
17
- await Promise.allSettled([...groupInlineThreadIdsByReview(threads)].map(([reviewId, inlineThreadIds]) => markReviewInlineThreads(key, reviewId, inlineThreadIds)));
24
+ export async function markReviewInlineThreadMarkers(key, threads, reviewIds = []) {
25
+ const grouped = groupInlineThreadsByReview(threads);
26
+ const writes = [...grouped.entries()].map(([reviewId, entry]) => markReviewInlineThreads(key, reviewId, entry.all, entry.unresolved));
27
+ for (const reviewId of new Set(reviewIds)) {
28
+ if (!grouped.has(reviewId))
29
+ writes.push(markReviewUnresolvedThreads(key, reviewId, []));
30
+ }
31
+ await Promise.allSettled(writes);
18
32
  }
@@ -0,0 +1,28 @@
1
+ import type { Review } from "../types.mts";
2
+ export interface ReviewOrderingEntry {
3
+ id: string;
4
+ author: string;
5
+ state: "APPROVED" | "CHANGES_REQUESTED" | "DISMISSED" | "COMMENTED";
6
+ body?: string;
7
+ createdAtUnix?: number;
8
+ }
9
+ /**
10
+ * Return the IDs of `APPROVED` reviews that are no longer the latest review from
11
+ * their author — either because the same author posted a later `APPROVED` review
12
+ * or because they posted a later substantive review (`CHANGES_REQUESTED`,
13
+ * `DISMISSED`, or non-empty `COMMENTED`). Empty-body `COMMENTED` reviews (GitHub's
14
+ * wrapper for inline thread replies) never supersede an approval.
15
+ */
16
+ export declare function findSupersededApprovalIds(input: {
17
+ reviews: readonly ReviewOrderingEntry[];
18
+ latestReviews?: ReadonlyArray<{
19
+ login: string;
20
+ state: string;
21
+ }>;
22
+ precomputedSupersededIds?: ReadonlySet<string>;
23
+ }): Set<string>;
24
+ export declare function reviewOrderingEntriesFromReviews(input: {
25
+ approvedReviews: readonly Review[];
26
+ changesRequestedReviews: readonly Review[];
27
+ reviewSummaries: readonly Review[];
28
+ }): ReviewOrderingEntry[];
@@ -0,0 +1,99 @@
1
+ function normalizeAuthor(author) {
2
+ const normalized = (author ?? "").trim().toLowerCase();
3
+ return normalized === "unknown" ? "" : normalized;
4
+ }
5
+ /**
6
+ * Return the IDs of `APPROVED` reviews that are no longer the latest review from
7
+ * their author — either because the same author posted a later `APPROVED` review
8
+ * or because they posted a later substantive review (`CHANGES_REQUESTED`,
9
+ * `DISMISSED`, or non-empty `COMMENTED`). Empty-body `COMMENTED` reviews (GitHub's
10
+ * wrapper for inline thread replies) never supersede an approval.
11
+ */
12
+ export function findSupersededApprovalIds(input) {
13
+ const superseded = new Set(input.precomputedSupersededIds);
14
+ const approvalsByAuthor = new Map();
15
+ const latestNonApprovalAtByAuthor = new Map();
16
+ input.reviews.forEach((review, order) => {
17
+ const author = normalizeAuthor(review.author);
18
+ if (!author)
19
+ return;
20
+ const createdAtUnix = review.createdAtUnix ?? 0;
21
+ if (review.state === "APPROVED") {
22
+ const list = approvalsByAuthor.get(author) ?? [];
23
+ list.push({ id: review.id, createdAtUnix, order });
24
+ approvalsByAuthor.set(author, list);
25
+ return;
26
+ }
27
+ if (review.state === "COMMENTED" && (review.body ?? "").trim() === "")
28
+ return;
29
+ const prev = latestNonApprovalAtByAuthor.get(author);
30
+ if (prev === undefined || createdAtUnix > prev) {
31
+ latestNonApprovalAtByAuthor.set(author, createdAtUnix);
32
+ }
33
+ });
34
+ const latestOpinionatedState = new Map();
35
+ for (const entry of input.latestReviews ?? []) {
36
+ const author = normalizeAuthor(entry.login);
37
+ if (author)
38
+ latestOpinionatedState.set(author, entry.state);
39
+ }
40
+ for (const [author, approvals] of approvalsByAuthor) {
41
+ const precomputed = input.precomputedSupersededIds;
42
+ const isBetterLatest = (candidate, current) => {
43
+ if (candidate.createdAtUnix !== current.createdAtUnix) {
44
+ return candidate.createdAtUnix > current.createdAtUnix;
45
+ }
46
+ const candPre = precomputed?.has(candidate.id) === true;
47
+ const curPre = precomputed?.has(current.id) === true;
48
+ if (candPre !== curPre)
49
+ return !candPre;
50
+ return candidate.order > current.order;
51
+ };
52
+ let latest = approvals[0];
53
+ for (let i = 1; i < approvals.length; i++) {
54
+ const candidate = approvals[i];
55
+ if (isBetterLatest(candidate, latest)) {
56
+ latest = candidate;
57
+ }
58
+ }
59
+ const latestNonApprovalAt = latestNonApprovalAtByAuthor.get(author);
60
+ const opinionatedState = latestOpinionatedState.get(author);
61
+ const nonApprovalLatest = opinionatedState === "CHANGES_REQUESTED" || opinionatedState === "DISMISSED";
62
+ for (const approval of approvals) {
63
+ if (approval.id !== latest.id) {
64
+ superseded.add(approval.id);
65
+ continue;
66
+ }
67
+ if ((latestNonApprovalAt !== undefined && latestNonApprovalAt > approval.createdAtUnix) ||
68
+ nonApprovalLatest) {
69
+ superseded.add(approval.id);
70
+ }
71
+ }
72
+ }
73
+ return superseded;
74
+ }
75
+ export function reviewOrderingEntriesFromReviews(input) {
76
+ return [
77
+ ...input.approvedReviews.map((r) => ({
78
+ id: r.id,
79
+ author: r.author,
80
+ state: "APPROVED",
81
+ body: r.body,
82
+ createdAtUnix: r.createdAtUnix,
83
+ })),
84
+ ...input.changesRequestedReviews.map((r) => ({
85
+ id: r.id,
86
+ author: r.author,
87
+ state: "CHANGES_REQUESTED",
88
+ body: r.body,
89
+ createdAtUnix: r.createdAtUnix,
90
+ })),
91
+ ...input.reviewSummaries.map((r) => ({
92
+ id: r.id,
93
+ author: r.author,
94
+ state: "COMMENTED",
95
+ body: r.body,
96
+ createdAtUnix: r.createdAtUnix,
97
+ })),
98
+ ];
99
+ }