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
@@ -0,0 +1,19 @@
1
+ /** The `iterate.branch-update` setting: how a branch is brought up to date with its base. */
2
+ export type BranchUpdateMethod = "rebase" | "merge";
3
+ /** The configured method for a PR outside a native stack. */
4
+ export declare function configuredBranchUpdate(): BranchUpdateMethod;
5
+ /** Appended to every update step, so an agent never pulls an unrelated branch into the PR. */
6
+ declare const NEVER_MERGE_OTHER = "Never merge any other branch into the PR.";
7
+ /** The update itself, as an imperative sentence without its closing period. */
8
+ export declare function updateFromBase(method: BranchUpdateMethod, head?: string, baseBranch?: string): string;
9
+ /** The conflict-resolution step for a PR outside a native stack. */
10
+ export declare function resolveConflictsStep(method: BranchUpdateMethod): string;
11
+ /** The update of a PR head from the latest base, as a lowercase clause. */
12
+ export declare function updateHeadFromLatestBase(method: BranchUpdateMethod): string;
13
+ /** The update and push clause for a PR head after a merge-queue removal. */
14
+ export declare function updateAndPushClause(method: BranchUpdateMethod): string;
15
+ export { NEVER_MERGE_OTHER };
16
+ /** How to push the PR head after the update. */
17
+ export declare function pushHeadClause(method: BranchUpdateMethod): string;
18
+ /** The push after a merge-queue ejection: a rebased head needs a lease, a head only a fix changed does not. */
19
+ export declare function ejectionPushHeadClause(method: BranchUpdateMethod): string;
@@ -0,0 +1,39 @@
1
+ import { loadConfig } from "../../config/load.mjs";
2
+ /** The configured method for a PR outside a native stack. */
3
+ export function configuredBranchUpdate() {
4
+ return loadConfig().iterate["branch-update"];
5
+ }
6
+ /** Appended to every update step, so an agent never pulls an unrelated branch into the PR. */
7
+ const NEVER_MERGE_OTHER = "Never merge any other branch into the PR.";
8
+ /** The update itself, as an imperative sentence without its closing period. */
9
+ export function updateFromBase(method, head = "the branch", baseBranch) {
10
+ const base = baseBranch === undefined ? "the base branch" : `\`${baseBranch}\``;
11
+ return method === "rebase" ? `Rebase ${head} onto ${base}` : `Merge ${base} into ${head}`;
12
+ }
13
+ /** The conflict-resolution step for a PR outside a native stack. */
14
+ export function resolveConflictsStep(method) {
15
+ return `${updateFromBase(method)} and resolve each conflict keeping both sides' changes unless they contradict. ${NEVER_MERGE_OTHER}`;
16
+ }
17
+ /** The update of a PR head from the latest base, as a lowercase clause. */
18
+ export function updateHeadFromLatestBase(method) {
19
+ return method === "rebase"
20
+ ? "rebase the PR head onto the latest base"
21
+ : "merge the latest base into the PR head";
22
+ }
23
+ /** The update and push clause for a PR head after a merge-queue removal. */
24
+ export function updateAndPushClause(method) {
25
+ return `${updateHeadFromLatestBase(method)} and push it${method === "rebase" ? " with `--force-with-lease`" : ""}`;
26
+ }
27
+ export { NEVER_MERGE_OTHER };
28
+ /** How to push the PR head after the update. */
29
+ export function pushHeadClause(method) {
30
+ return method === "rebase"
31
+ ? "push to the PR head branch with `--force-with-lease`"
32
+ : "push to the PR head branch with a normal push";
33
+ }
34
+ /** The push after a merge-queue ejection: a rebased head needs a lease, a head only a fix changed does not. */
35
+ export function ejectionPushHeadClause(method) {
36
+ return method === "rebase"
37
+ ? "push to the PR head branch (`--force-with-lease` if you rebased it, a normal push if only a fix changed it)"
38
+ : pushHeadClause(method);
39
+ }
@@ -39,10 +39,12 @@ export declare function buildRepeatedWorkflowBranchRecoveryInstructions(baseBran
39
39
  * command records each item's disposition either way.
40
40
  */
41
41
  export declare function buildResolveCommandInstruction(resolveCommand: ResolveCommand, rendered: string): string[];
42
+ /** Build the separate review-dismissal / review-hiding step once all inline items are resolved. */
43
+ export declare function buildDismissReviewsCommandInstruction(dismissReviewsCommand: ResolveCommand | undefined, rendered: string): string[];
42
44
  /** One pointer. Conclusion, rerun, and bare-check rules live in the CI playbook. */
43
45
  export declare function buildFailingCheckInstructions(checks: AgentCheck[]): string[];
44
46
  /** Update the PR branch after an external blocker merges or closes. Never rerun that job. */
45
- export declare function buildReleasedBlockerInstruction(prNumber: number): string;
47
+ export declare function buildReleasedBlockerInstruction(prNumber: number, stackRebase?: string): string;
46
48
  /** `iterate.review-output-max-chars` held review items back; the rerun step that follows shows them. */
47
49
  export declare function buildReviewSubsetInstruction(reviewItems: {
48
50
  shown: number;
@@ -1,4 +1,6 @@
1
1
  import { playbookPointer } from "../playbook-pointer.mjs";
2
+ import { stackRebaseAndPush } from "./native-stack-rebase.mjs";
3
+ import { configuredBranchUpdate, NEVER_MERGE_OTHER, pushHeadClause, updateFromBase, } from "./branch-update.mjs";
2
4
  // The `[TRIAGE]` heading and the skill already say the action is non-terminal.
3
5
  export const TRIAGE_CONTINUATION = "Rerun Shepherd now.";
4
6
  /** The final rerun step when a queued conflict offers both paths. */
@@ -48,8 +50,8 @@ export function buildRepeatedWorkflowBranchRecoveryInstructions(baseBranch, hasE
48
50
  ];
49
51
  instructions.push(stackRebase ??
50
52
  (branch.hasConflicts
51
- ? `Rebase or otherwise update the PR branch from \`${baseBranch}\` according to repository conventions, resolving conflicts as part of that update.`
52
- : `Rebase or otherwise update the PR branch from \`${baseBranch}\` according to repository conventions.`));
53
+ ? `${updateFromBase(configuredBranchUpdate(), "the PR branch", baseBranch)}, resolving conflicts as part of that update. ${NEVER_MERGE_OTHER}`
54
+ : `${updateFromBase(configuredBranchUpdate(), "the PR branch", baseBranch)}. ${NEVER_MERGE_OTHER}`));
53
55
  return instructions;
54
56
  }
55
57
  /**
@@ -69,6 +71,20 @@ export function buildResolveCommandInstruction(resolveCommand, rendered) {
69
71
  }
70
72
  return [`Run, even if no code changed: \`${rendered}\``];
71
73
  }
74
+ /** Build the separate review-dismissal / review-hiding step once all inline items are resolved. */
75
+ export function buildDismissReviewsCommandInstruction(dismissReviewsCommand, rendered) {
76
+ if (!dismissReviewsCommand?.hasMutations)
77
+ return [];
78
+ if (dismissReviewsCommand.requiresDismissMessage) {
79
+ const verb = dismissReviewsCommand.argv.includes("--minimize-comment-ids")
80
+ ? "dismiss and hide"
81
+ : "dismiss";
82
+ return [
83
+ `\`$CHANGE_MESSAGE\`: one sentence on what changed. Run even if no code changed to ${verb} resolved reviews: \`${rendered}\``,
84
+ ];
85
+ }
86
+ return [`Run to hide resolved reviews: \`${rendered}\``];
87
+ }
72
88
  /** One pointer. Conclusion, rerun, and bare-check rules live in the CI playbook. */
73
89
  export function buildFailingCheckInstructions(checks) {
74
90
  if (checks.length === 0)
@@ -76,10 +92,14 @@ export function buildFailingCheckInstructions(checks) {
76
92
  return [`Triage \`## Failing checks\`. ${playbookPointer("CI failure triage")}`];
77
93
  }
78
94
  /** Update the PR branch after an external blocker merges or closes. Never rerun that job. */
79
- export function buildReleasedBlockerInstruction(prNumber) {
80
- return getGithubTransport() === "rest"
81
- ? "Update this PR branch from its base using the repository's branch-update procedure. Do not rerun the job; a rerun retests the old merge ref."
82
- : `Update this PR branch from its base with \`gh pr update-branch ${prNumber} --rebase\`. Do not rerun the job; a rerun retests the old merge ref.`;
95
+ export function buildReleasedBlockerInstruction(prNumber, stackRebase) {
96
+ if (stackRebase)
97
+ return `${stackRebaseAndPush(stackRebase)} ${NEVER_MERGE_OTHER} Do not rerun the job; a rerun retests the old merge ref.`;
98
+ const method = configuredBranchUpdate();
99
+ const update = getGithubTransport() === "rest"
100
+ ? `${updateFromBase(method, "this PR branch")} and ${pushHeadClause(method)}`
101
+ : `${updateFromBase(method, "this PR branch")} with \`gh pr update-branch ${prNumber}${method === "rebase" ? " --rebase" : ""}\``;
102
+ return `${update}. ${NEVER_MERGE_OTHER} Do not rerun the job; a rerun retests the old merge ref.`;
83
103
  }
84
104
  /** `iterate.review-output-max-chars` held review items back; the rerun step that follows shows them. */
85
105
  export function buildReviewSubsetInstruction(reviewItems) {
@@ -1,18 +1,32 @@
1
1
  import type { AgentThread, Review, ResolveCommand, AgentCheck, ReviewThread, ViewerAuthorization } from "../../types.mts";
2
2
  import { type NormalizedBotUsernames } from "../../comments/authors.mts";
3
3
  import type { MinimizeCommentsPolicy, ResolveOtherHumanThreads } from "../../config/load.mts";
4
+ export interface ClassifyReviewSummaryOptions {
5
+ minimizeSupersededApprovals?: boolean;
6
+ supersededApprovals?: Review[];
7
+ changesRequestedReviews?: Review[];
8
+ latestReviews?: Array<{
9
+ login: string;
10
+ state: string;
11
+ }>;
12
+ }
4
13
  export declare function classifyReviewSummaries(summaries: {
5
14
  firstLook: Review[];
6
15
  seen: Review[];
7
16
  edited: Review[];
8
- }, approvals: Review[], minimizeApprovals: boolean, minimizeComments?: MinimizeCommentsPolicy | undefined, botUsernames?: NormalizedBotUsernames, unresolvedThreads?: ReadonlyArray<Pick<ReviewThread, "reviewId">>, ruleAutoResolveIds?: string[]): {
17
+ }, approvals: Review[], minimizeApprovals: boolean, minimizeComments?: MinimizeCommentsPolicy | undefined, botUsernames?: NormalizedBotUsernames, unresolvedThreads?: ReadonlyArray<Pick<ReviewThread, "reviewId">>, ruleAutoResolveIds?: string[], options?: ClassifyReviewSummaryOptions): {
9
18
  minimizeIds: string[];
10
- selfMinimizeIds: string[];
11
19
  firstLookSummaries: Review[];
12
20
  editedSummaries: Review[];
13
21
  surfacedApprovals: Review[];
14
22
  };
15
- export declare function buildResolveCommand(threads: AgentThread[], resolutionOnlyThreads: ReviewThread[], allCommentIds: string[], reviews: Review[], checks: AgentCheck[], prReference: string | number, botUsernames?: NormalizedBotUsernames, ruleAutoResolveThreadIds?: string[], viewerAuthorization?: ViewerAuthorization, authorizationThreads?: ReviewThread[], resolveOtherHumanThreads?: ResolveOtherHumanThreads): {
23
+ export interface BuildResolveReviewOptions {
24
+ reviewMinimizeIds?: string[];
25
+ blockedReviewIds?: ReadonlySet<string>;
26
+ minimizeComments?: MinimizeCommentsPolicy;
27
+ }
28
+ export declare function buildResolveCommand(threads: AgentThread[], resolutionOnlyThreads: ReviewThread[], allCommentIds: string[], reviews: Review[], checks: AgentCheck[], prReference: string | number, botUsernames?: NormalizedBotUsernames, ruleAutoResolveThreadIds?: string[], viewerAuthorization?: ViewerAuthorization, authorizationThreads?: ReviewThread[], resolveOtherHumanThreads?: ResolveOtherHumanThreads, reviewOptions?: BuildResolveReviewOptions): {
16
29
  resolveCommand: ResolveCommand;
17
30
  resolveOnlyCommand?: ResolveCommand;
31
+ dismissReviewsCommand?: ResolveCommand;
18
32
  };
@@ -1,5 +1,6 @@
1
1
  import { buildPrShepherdCommand } from "../../cli/runner.mjs";
2
2
  import { shouldMinimizeAuthor } from "../../comments/minimize-policy.mjs";
3
+ import { findSupersededApprovalIds, reviewOrderingEntriesFromReviews, } from "../../comments/superseded-approvals.mjs";
3
4
  import { isConfiguredBotAuthor, isHumanAuthor, } from "../../comments/authors.mjs";
4
5
  import { buildThreadMutationRouting } from "./thread-mutation-routing.mjs";
5
6
  import { canGenerateGithubMutation } from "../../github/mutation-policy.mjs";
@@ -15,38 +16,55 @@ function dedupeIds(ids) {
15
16
  }
16
17
  return out;
17
18
  }
18
- export function classifyReviewSummaries(summaries, approvals, minimizeApprovals, minimizeComments = "all", botUsernames = new Set(), unresolvedThreads = [], ruleAutoResolveIds = []) {
19
+ export function classifyReviewSummaries(summaries, approvals, minimizeApprovals, minimizeComments = "all", botUsernames = new Set(), unresolvedThreads = [], ruleAutoResolveIds = [], options = {}) {
19
20
  const blockedReviewIds = new Set(unresolvedThreads.flatMap((t) => (t.reviewId !== undefined ? [t.reviewId] : [])));
20
21
  const eligible = (r) => canGenerateGithubMutation(r.viewerCanMinimize, "minimize") &&
21
22
  shouldMinimizeAuthor(r.authorType, minimizeComments, r.author, botUsernames) &&
22
23
  !blockedReviewIds.has(r.id);
23
- // First-look summaries still need one tick to surface their body to the agent,
24
- // so their minimize IDs ride in the agent-facing apply command. Seen summaries
25
- // (already surfaced in a prior tick) have no new content to show — the CLI
26
- // self-minimizes them in-process (selfMinimizeIds) instead of routing a
27
- // cosmetic-only mutation through triage (issue #313). Edited summaries are
28
- // excluded entirely: they are already minimized server-side (body changed after
29
- // minimize was applied).
30
- const minimizeIds = summaries.firstLook.filter(eligible).map((r) => r.id);
31
- const selfMinimizeIds = summaries.seen.filter(eligible).map((r) => r.id);
24
+ // Both first-look and already-seen summaries stay in the agent-facing review
25
+ // command once all of their inline threads are resolved — never hidden
26
+ // automatically in-process. Edited summaries are excluded: they are already
27
+ // minimized server-side (body changed after minimize was applied).
28
+ const minimizeIds = dedupeIds([...summaries.firstLook, ...summaries.seen].filter(eligible).map((r) => r.id));
32
29
  // Rule-matched summaries are already suppressed from agent output; bypass normal
33
- // policy gates. Keep the two sets disjoint.
30
+ // policy gates, while still waiting for any unresolved inline threads.
34
31
  for (const id of ruleAutoResolveIds) {
35
- if (!minimizeIds.includes(id) && !selfMinimizeIds.includes(id))
32
+ if (!blockedReviewIds.has(id) && !minimizeIds.includes(id))
36
33
  minimizeIds.push(id);
37
34
  }
38
- if (minimizeApprovals) {
39
- const surfacedApprovals = [];
40
- for (const r of approvals) {
41
- if (canGenerateGithubMutation(r.viewerCanMinimize, "minimize") &&
42
- shouldMinimizeAuthor(r.authorType, minimizeComments, r.author, botUsernames))
43
- minimizeIds.push(r.id);
44
- else
45
- surfacedApprovals.push(r);
35
+ const minimizeSupersededApprovals = options.minimizeSupersededApprovals ?? true;
36
+ const candidateApprovalsById = new Map();
37
+ for (const r of options.supersededApprovals ?? [])
38
+ candidateApprovalsById.set(r.id, r);
39
+ for (const r of approvals) {
40
+ if (!candidateApprovalsById.has(r.id))
41
+ candidateApprovalsById.set(r.id, r);
42
+ }
43
+ const candidateApprovals = [...candidateApprovalsById.values()];
44
+ if (minimizeApprovals || minimizeSupersededApprovals) {
45
+ const precomputed = new Set((options.supersededApprovals ?? []).map((r) => r.id));
46
+ const supersededIds = minimizeApprovals
47
+ ? new Set(candidateApprovals.map((r) => r.id))
48
+ : findSupersededApprovalIds({
49
+ reviews: reviewOrderingEntriesFromReviews({
50
+ approvedReviews: candidateApprovals,
51
+ changesRequestedReviews: options.changesRequestedReviews ?? [],
52
+ reviewSummaries: [...summaries.firstLook, ...summaries.seen, ...summaries.edited],
53
+ }),
54
+ latestReviews: options.latestReviews,
55
+ precomputedSupersededIds: precomputed,
56
+ });
57
+ const minimizedApprovalIds = new Set();
58
+ for (const r of candidateApprovals) {
59
+ if (supersededIds.has(r.id) && eligible(r)) {
60
+ if (!minimizeIds.includes(r.id))
61
+ minimizeIds.push(r.id);
62
+ minimizedApprovalIds.add(r.id);
63
+ }
46
64
  }
65
+ const surfacedApprovals = approvals.filter((r) => !minimizedApprovalIds.has(r.id));
47
66
  return {
48
67
  minimizeIds,
49
- selfMinimizeIds,
50
68
  firstLookSummaries: summaries.firstLook,
51
69
  editedSummaries: summaries.edited,
52
70
  surfacedApprovals,
@@ -54,7 +72,6 @@ export function classifyReviewSummaries(summaries, approvals, minimizeApprovals,
54
72
  }
55
73
  return {
56
74
  minimizeIds,
57
- selfMinimizeIds,
58
75
  firstLookSummaries: summaries.firstLook,
59
76
  editedSummaries: summaries.edited,
60
77
  surfacedApprovals: approvals,
@@ -69,7 +86,7 @@ function pushAdoptExistingReplies(argv, hasReply) {
69
86
  if (hasReply && durableStateRequested())
70
87
  argv.push("--adopt-existing-replies");
71
88
  }
72
- export function buildResolveCommand(threads, resolutionOnlyThreads, allCommentIds, reviews, checks, prReference, botUsernames = new Set(), ruleAutoResolveThreadIds = [], viewerAuthorization, authorizationThreads = [], resolveOtherHumanThreads = "none") {
89
+ export function buildResolveCommand(threads, resolutionOnlyThreads, allCommentIds, reviews, checks, prReference, botUsernames = new Set(), ruleAutoResolveThreadIds = [], viewerAuthorization, authorizationThreads = [], resolveOtherHumanThreads = "none", reviewOptions = {}) {
73
90
  const allThreads = [...threads, ...resolutionOnlyThreads];
74
91
  const routed = buildThreadMutationRouting(allThreads, botUsernames, ruleAutoResolveThreadIds, resolveOtherHumanThreads);
75
92
  const canReply = new Set(authorizationThreads
@@ -86,47 +103,71 @@ export function buildResolveCommand(threads, resolutionOnlyThreads, allCommentId
86
103
  const pairedResolveThreadIds = routed.pairedResolveThreadIds.filter((id) => canReply.has(id) && canResolve.has(id));
87
104
  const standaloneResolveThreadIds = routed.standaloneResolveThreadIds.filter((id) => canResolve.has(id));
88
105
  const resolveThreadIds = dedupeIds([...pairedResolveThreadIds, ...standaloneResolveThreadIds]);
89
- // Bot/non-human CHANGES_REQUESTED reviews are auto-dismissed after the agent pushes a fix.
90
- // Human reviews are left for the reviewer to re-review or dismiss themselves.
91
- const dismissReviewIds = dedupeIds(canGenerateGithubMutation(viewerAuthorization?.viewerCanAdminister, "dismiss")
92
- ? reviews
93
- .filter((r) => !isHumanAuthor(r) || isConfiguredBotAuthor(r, botUsernames))
94
- .map((r) => r.id)
95
- : []);
96
- const hasReply = replyThreadIds.length > 0;
106
+ // Bot/non-human CHANGES_REQUESTED reviews are dismissed and minimized in a separate command
107
+ // only once all of their inline threads are resolved. Human reviews are left for the reviewer.
108
+ const blockedReviewIds = new Set(reviewOptions.blockedReviewIds);
109
+ for (const thread of allThreads) {
110
+ if (thread.reviewId !== undefined)
111
+ blockedReviewIds.add(thread.reviewId);
112
+ }
113
+ const dismissibleReviews = canGenerateGithubMutation(viewerAuthorization?.viewerCanAdminister, "dismiss")
114
+ ? reviews.filter((r) => (!isHumanAuthor(r) || isConfiguredBotAuthor(r, botUsernames)) &&
115
+ !blockedReviewIds.has(r.id))
116
+ : [];
117
+ const dismissReviewIds = dedupeIds(dismissibleReviews.map((r) => r.id));
118
+ const minimizePolicy = reviewOptions.minimizeComments ?? "all";
119
+ const dismissMinimizeIds = dismissibleReviews
120
+ .filter((r) => r.isMinimized !== true &&
121
+ canGenerateGithubMutation(r.viewerCanMinimize, "minimize") &&
122
+ shouldMinimizeAuthor(r.authorType, minimizePolicy, r.author, botUsernames))
123
+ .map((r) => r.id);
124
+ const reviewMinimizeIds = dedupeIds([
125
+ ...dismissMinimizeIds,
126
+ ...(reviewOptions.reviewMinimizeIds ?? []),
127
+ ]);
97
128
  const hasDismiss = dismissReviewIds.length > 0;
98
- // Mutations that require --message: replies (to human threads) and dismissals (of bot CR reviews).
99
- const hasMessageMutations = hasReply || hasDismiss;
129
+ const hasReviewMinimize = reviewMinimizeIds.length > 0;
130
+ let dismissReviewsCommand;
131
+ if (hasDismiss || hasReviewMinimize) {
132
+ const reviewArgv = buildPrShepherdCommand(["apply", "review", String(prReference)]).argv;
133
+ if (hasReviewMinimize) {
134
+ reviewArgv.push("--minimize-comment-ids", reviewMinimizeIds.join(","));
135
+ }
136
+ if (hasDismiss) {
137
+ reviewArgv.push("--dismiss-review-ids", dismissReviewIds.join(","));
138
+ reviewArgv.push("--message", "$CHANGE_MESSAGE");
139
+ }
140
+ dismissReviewsCommand = {
141
+ argv: reviewArgv,
142
+ requiresHeadSha: hasDismiss,
143
+ requiresDismissMessage: hasDismiss,
144
+ ...(hasDismiss ? { dismissReviewIds } : undefined),
145
+ hasMutations: true,
146
+ };
147
+ }
148
+ const hasReply = replyThreadIds.length > 0;
100
149
  const hasResolveOrMinimize = resolveThreadIds.length > 0 || allCommentIds.length > 0;
101
150
  const hasStandaloneResolveOrMinimize = standaloneResolveThreadIds.length > 0 || allCommentIds.length > 0;
102
- if (hasMessageMutations && hasStandaloneResolveOrMinimize) {
103
- // Split: message-bearing mutations plus their paired viewer-authored resolves ride in
104
- // resolveArgv; standalone resolve/minimize mutations go in resolveOnlyArgv so they can
105
- // run without SHA or message.
151
+ if (hasReply && hasStandaloneResolveOrMinimize) {
152
+ // Split: reply mutations plus their paired viewer-authored resolves ride in
153
+ // resolveArgv; standalone resolve/PR-comment minimize mutations go in resolveOnlyArgv so
154
+ // they can run without SHA or message.
106
155
  const resolveArgv = buildPrShepherdCommand(["apply", "review", String(prReference)]).argv;
107
- if (replyThreadIds.length > 0) {
108
- resolveArgv.push("--reply-thread-ids", replyThreadIds.join(","));
109
- }
156
+ resolveArgv.push("--reply-thread-ids", replyThreadIds.join(","));
110
157
  if (pairedResolveThreadIds.length > 0) {
111
158
  resolveArgv.push("--resolve-thread-ids", pairedResolveThreadIds.join(","));
112
159
  }
113
160
  resolveArgv.push("--message", "$CHANGE_MESSAGE");
114
- pushAdoptExistingReplies(resolveArgv, hasReply);
115
- if (hasDismiss) {
116
- resolveArgv.push("--dismiss-review-ids", dismissReviewIds.join(","));
117
- }
118
- // SHA is required when actionable thread fixes or failing checks are being addressed,
119
- // or when bot CR reviews are being dismissed (post-push SHA gate).
120
- const requiresHeadSha = threads.length > 0 || checks.length > 0 || hasDismiss;
161
+ pushAdoptExistingReplies(resolveArgv, true);
162
+ const requiresHeadSha = threads.length > 0 || checks.length > 0;
121
163
  const resolveCommand = {
122
164
  argv: resolveArgv,
123
165
  requiresHeadSha,
124
166
  requiresDismissMessage: true,
125
- ...(replyThreadIds.length > 0 ? { replyThreadIds } : undefined),
167
+ replyThreadIds,
126
168
  ...(pairedResolveThreadIds.length > 0
127
169
  ? { resolveThreadIds: pairedResolveThreadIds }
128
170
  : undefined),
129
- ...(hasDismiss ? { dismissReviewIds } : undefined),
130
171
  hasMutations: true,
131
172
  };
132
173
  const resolveOnlyArgv = buildPrShepherdCommand(["apply", "review", String(prReference)]).argv;
@@ -145,11 +186,15 @@ export function buildResolveCommand(threads, resolutionOnlyThreads, allCommentId
145
186
  : undefined),
146
187
  hasMutations: true,
147
188
  };
148
- return { resolveCommand, resolveOnlyCommand };
189
+ return {
190
+ resolveCommand,
191
+ resolveOnlyCommand,
192
+ ...(dismissReviewsCommand ? { dismissReviewsCommand } : undefined),
193
+ };
149
194
  }
150
- // Single command: all mutations combined (or only one category present).
195
+ // Single command for inline threads and PR comments (or empty when only review mutations exist).
151
196
  const argv = buildPrShepherdCommand(["apply", "review", String(prReference)]).argv;
152
- if (replyThreadIds.length > 0) {
197
+ if (hasReply) {
153
198
  argv.push("--reply-thread-ids", replyThreadIds.join(","));
154
199
  argv.push("--message", "$CHANGE_MESSAGE");
155
200
  pushAdoptExistingReplies(argv, true);
@@ -160,24 +205,18 @@ export function buildResolveCommand(threads, resolutionOnlyThreads, allCommentId
160
205
  if (allCommentIds.length > 0) {
161
206
  argv.push("--minimize-comment-ids", allCommentIds.join(","));
162
207
  }
163
- if (hasDismiss) {
164
- // Add --message when dismissing without a reply (replies already added it above).
165
- if (!hasReply)
166
- argv.push("--message", "$CHANGE_MESSAGE");
167
- argv.push("--dismiss-review-ids", dismissReviewIds.join(","));
168
- }
169
- const hasMutations = hasMessageMutations || hasResolveOrMinimize;
170
- // SHA is required when replying after actionable fixes/checks, or whenever dismissing
171
- // (dismissal is a post-push operation that must race-check against a moving HEAD).
172
- const requiresHeadSha = hasDismiss || (hasReply && (threads.length > 0 || checks.length > 0));
208
+ const hasMutations = hasReply || hasResolveOrMinimize;
209
+ const requiresHeadSha = hasReply && (threads.length > 0 || checks.length > 0);
173
210
  const resolveCommand = {
174
211
  argv,
175
212
  requiresHeadSha,
176
- requiresDismissMessage: hasMessageMutations,
177
- ...(replyThreadIds.length > 0 ? { replyThreadIds } : undefined),
213
+ requiresDismissMessage: hasReply,
214
+ ...(hasReply ? { replyThreadIds } : undefined),
178
215
  ...(resolveThreadIds.length > 0 ? { resolveThreadIds } : undefined),
179
- ...(hasDismiss ? { dismissReviewIds } : undefined),
180
216
  hasMutations,
181
217
  };
182
- return { resolveCommand };
218
+ return {
219
+ resolveCommand,
220
+ ...(dismissReviewsCommand ? { dismissReviewsCommand } : undefined),
221
+ };
183
222
  }
@@ -198,7 +198,9 @@ export function buildEscalateHumanMessage(escalate, pr, opts) {
198
198
  }
199
199
  }
200
200
  const pending = escalate.pendingReviewCommands;
201
- if (pending?.resolveOnlyCommand?.hasMutations || pending?.resolveCommand?.hasMutations) {
201
+ if (pending?.resolveOnlyCommand?.hasMutations ||
202
+ pending?.resolveCommand?.hasMutations ||
203
+ pending?.dismissReviewsCommand?.hasMutations) {
202
204
  lines.push("", "## Pending review commands", "");
203
205
  if (pending.resolveOnlyCommand?.hasMutations) {
204
206
  lines.push(`- resolve-only: \`${renderResolveCommand(pending.resolveOnlyCommand)}\``);
@@ -206,6 +208,9 @@ export function buildEscalateHumanMessage(escalate, pr, opts) {
206
208
  if (pending.resolveCommand?.hasMutations) {
207
209
  lines.push(`- apply review: \`${renderResolveCommand(pending.resolveCommand)}\``);
208
210
  }
211
+ if (pending.dismissReviewsCommand?.hasMutations) {
212
+ lines.push(`- dismiss reviews: \`${renderResolveCommand(pending.dismissReviewsCommand)}\``);
213
+ }
209
214
  }
210
215
  lines.push("");
211
216
  lines.push("---");
@@ -12,7 +12,6 @@ import { clearStallState } from "../../state/iterate-stall.mjs";
12
12
  import { handleTriage } from "./triage.mjs";
13
13
  import { deferQueuedConflictReviewWork } from "./queued-conflict-deferral.mjs";
14
14
  import { normalizeBotUsernames } from "../../comments/authors.mjs";
15
- import { autoMinimizeComments } from "../../comments/resolve.mjs";
16
15
  import { hasCheckDrivenActionableWork, isQueuedConflict } from "../check-annotations.mjs";
17
16
  import { buildReadyMergeOutcome, handleActiveMergeState } from "./merge-state.mjs";
18
17
  import { buildIterateBase } from "./base.mjs";
@@ -111,32 +110,22 @@ async function runIterateCore(opts, tick) {
111
110
  failing: report.checks.failing.filter((check) => !deferredNames.has(check.name)),
112
111
  },
113
112
  };
114
- const { minimizeIds, selfMinimizeIds, firstLookSummaries, editedSummaries, surfacedApprovals } = classifyReviewSummaries({
115
- firstLook: report.firstLookSummaries,
116
- seen: report.reviewSummaries,
117
- edited: report.editedSummaries,
118
- }, report.approvedReviews, config.iterate["minimize-approvals"], config.iterate["minimize-comments"], botUsernames, [
113
+ const blockedThreadRefs = [
119
114
  ...report.threads.actionable,
120
115
  ...report.threads.resolutionOnly,
121
116
  ...(report.heldThreadReviewIds ?? []).map((reviewId) => ({ reviewId })),
122
- ], report.ruleAutoResolveReviewSummaryIds);
123
- // Minimize already-seen review summaries in-process so they never become agent-facing work.
124
- // GitHub can still return a null/error/rate-limit result per ID without
125
- // throwing (autoMinimizeComments reports this via `errors`, not a rejection);
126
- // any ID it did not confirm minimized falls back into the agent-facing set so
127
- // the apply command remains a working fallback instead of silently dropping it.
128
- let reviewSummaryIds = minimizeIds;
129
- if (selfMinimizeIds.length > 0 && readOnly) {
130
- reviewSummaryIds = [...reviewSummaryIds, ...selfMinimizeIds];
131
- }
132
- else if (selfMinimizeIds.length > 0) {
133
- checkContext.invalidateReceiptSummary();
134
- const { minimized } = await autoMinimizeComments(selfMinimizeIds);
135
- const minimizedIds = new Set(minimized);
136
- const unminimized = selfMinimizeIds.filter((id) => !minimizedIds.has(id));
137
- if (unminimized.length > 0)
138
- reviewSummaryIds = [...reviewSummaryIds, ...unminimized];
139
- }
117
+ ...(report.unresolvedThreadReviewIds ?? []).map((reviewId) => ({ reviewId })),
118
+ ];
119
+ const blockedReviewIds = new Set(blockedThreadRefs.flatMap((thread) => (thread.reviewId !== undefined ? [thread.reviewId] : [])));
120
+ const { minimizeIds: reviewSummaryIds, firstLookSummaries, editedSummaries, surfacedApprovals, } = classifyReviewSummaries({
121
+ firstLook: report.firstLookSummaries,
122
+ seen: report.reviewSummaries,
123
+ edited: report.editedSummaries,
124
+ }, report.approvedReviews, config.iterate["minimize-approvals"], config.iterate["minimize-comments"], botUsernames, blockedThreadRefs, report.ruleAutoResolveReviewSummaryIds, {
125
+ minimizeSupersededApprovals: config.iterate["minimize-superseded-approvals"],
126
+ supersededApprovals: report.supersededApprovedReviews,
127
+ changesRequestedReviews: report.changesRequestedReviews,
128
+ });
140
129
  // A first look at an already-minimized comment is only an acknowledgment. Edited PR comments
141
130
  // (report.comments.edited) are neither: they never block readiness or restart the ready delay.
142
131
  // Review items held back by iterate.review-output-max-chars keep the PR out of ready/merge: a
@@ -218,6 +207,7 @@ async function runIterateCore(opts, tick) {
218
207
  repoOwner,
219
208
  repoName,
220
209
  botUsernames,
210
+ blockedReviewIds,
221
211
  releasedCheckNames: blockerGate?.releasedNames,
222
212
  releasedCheckBlockers: blockerGate?.releasedBlockers,
223
213
  ...((unreportedRepair.length > 0 || staleAncestry !== null) && {
@@ -241,6 +231,7 @@ async function runIterateCore(opts, tick) {
241
231
  editedSummaries,
242
232
  surfacedApprovals,
243
233
  botUsernames,
234
+ blockedReviewIds,
244
235
  releasedCheckNames: blockerGate?.releasedNames,
245
236
  releasedCheckBlockers: blockerGate?.releasedBlockers,
246
237
  repairInstructions: [...unreportedRepair, ...staleAncestry.instructions],
@@ -281,6 +272,7 @@ async function runIterateCore(opts, tick) {
281
272
  editedSummaries,
282
273
  surfacedApprovals,
283
274
  botUsernames,
275
+ blockedReviewIds,
284
276
  releasedCheckNames: blockerGate?.releasedNames,
285
277
  releasedCheckBlockers: blockerGate?.releasedBlockers,
286
278
  repairInstructions: [...unreportedRepair, ...staleAncestry.instructions],
@@ -36,6 +36,11 @@ export declare function buildNativeStackLayerRebase(repo: string, pr: {
36
36
  trunk: string;
37
37
  bottomPr?: number;
38
38
  }, stackBottomPr?: number): string | undefined;
39
+ /**
40
+ * The stack rebase followed by its push. An ownership boundary replaces the whole-stack push with
41
+ * the owned branches, or with no push at all when this PR has nothing it can restack alone.
42
+ */
43
+ export declare function stackRebaseAndPush(stackRebase: string): string;
39
44
  /**
40
45
  * Point at the conflicts, and at the stack rebase when the PR is a native stack layer. A queued
41
46
  * conflicting entry cannot form a merge group, so GitHub removes it once the queue reaches it.
@@ -1,6 +1,7 @@
1
1
  import { playbookPointer } from "../playbook-pointer.mjs";
2
2
  import { getGithubTransport } from "../../github/transport.mjs";
3
3
  import { boundedStackPush, boundedStackRebase } from "./stack-boundary.mjs";
4
+ import { configuredBranchUpdate, ejectionPushHeadClause, pushHeadClause, resolveConflictsStep, } from "./branch-update.mjs";
4
5
  /**
5
6
  * One gh-stack rebase step. A native stack layer must not be rebased or merged from its base
6
7
  * branch alone: that rewrites one branch and strands every layer above it.
@@ -70,10 +71,14 @@ export function buildNativeStackLayerRebase(repo, pr, stack, trunkConflict, stac
70
71
  return start && buildNativeStackRebaseInstruction(repo, stack.number, start);
71
72
  }
72
73
  /**
73
- * The branch-update route for a conflicting PR that is not a native stack layer. Rebase versus
74
- * merge is the repository's convention, so the step points at it instead of choosing.
74
+ * The stack rebase followed by its push. An ownership boundary replaces the whole-stack push with
75
+ * the owned branches, or with no push at all when this PR has nothing it can restack alone.
75
76
  */
76
- const RESOLVE_CONFLICTS = "Check the base branch's instructions (such as `AGENTS.md`) only for whether to rebase or merge, update the branch from its base that way, and resolve each conflict keeping both sides' changes unless they contradict.";
77
+ export function stackRebaseAndPush(stackRebase) {
78
+ const push = boundedStackPush() ??
79
+ `push the rewritten stack${getGithubTransport() === "rest" ? " using the repository's stack-update procedure" : " with `gh stack push`"}`;
80
+ return `${stackRebase} Then ${push}.`;
81
+ }
77
82
  /**
78
83
  * Point at the conflicts, and at the stack rebase when the PR is a native stack layer. A queued
79
84
  * conflicting entry cannot form a merge group, so GitHub removes it once the queue reaches it.
@@ -83,7 +88,7 @@ const RESOLVE_CONFLICTS = "Check the base branch's instructions (such as `AGENTS
83
88
  */
84
89
  export function buildConflictInstruction(stackRebase, dequeueCommand) {
85
90
  const pointer = "The branch has merge conflicts (see `**branch**` above).";
86
- const resolve = stackRebase ?? RESOLVE_CONFLICTS;
91
+ const resolve = stackRebase ?? resolveConflictsStep(configuredBranchUpdate());
87
92
  if (!dequeueCommand)
88
93
  return `${pointer} ${resolve}`;
89
94
  return `${pointer} ${buildQueuedConflictChoice(dequeueCommand, resolve, stackRebase !== undefined)}`;
@@ -115,12 +120,15 @@ export function buildBranchPushInstruction(stackRebase, hasConflicts, mutationSu
115
120
  if (ejectionUpdate) {
116
121
  const push = stackRebase
117
122
  ? "commit any remaining changes on the PR head branch and push the rewritten stack with `gh stack push`"
118
- : "commit any remaining changes and push to the PR head branch";
123
+ : `commit any remaining changes and ${ejectionPushHeadClause(configuredBranchUpdate())}`;
119
124
  return `If the base update or a fix changed the head, ${push}${mutationSuffix}. If neither did, do not push.`;
120
125
  }
121
126
  if (stackRebase)
122
127
  return `Commit any remaining changes on the PR head branch and push the rewritten stack with \`gh stack push\`${mutationSuffix}.`;
123
- return hasConflicts
124
- ? `Commit any remaining conflict-resolution changes and push to the PR head branch${mutationSuffix}.`
125
- : "Push the updated PR head branch before iterating immediately.";
128
+ const method = configuredBranchUpdate();
129
+ if (hasConflicts)
130
+ return `Commit any remaining conflict-resolution changes and ${pushHeadClause(method)}${mutationSuffix}.`;
131
+ return method === "rebase"
132
+ ? "Push the updated PR head branch with `--force-with-lease` before iterating immediately."
133
+ : "Push the updated PR head branch with a normal push before iterating immediately.";
126
134
  }
@@ -1,4 +1,5 @@
1
1
  /** Instruction text for a PR that GitHub removed from the merge queue after failed checks. */
2
+ import { configuredBranchUpdate, NEVER_MERGE_OTHER, updateHeadFromLatestBase, } from "./branch-update.mjs";
2
3
  import { playbookPointer } from "../playbook-pointer.mjs";
3
4
  /** The removed queue commit whose failed checks this tick surfaces, if the removal is current. */
4
5
  export function currentEjectionCommit(report, checks) {
@@ -23,14 +24,16 @@ export function queueEjectionSteps(recovery, stackRebase, routePrinted, hasElsew
23
24
  * removal reason, since a person's dequeue must not be undone by a branch update.
24
25
  */
25
26
  function buildQueueEjectionInstruction(recovery, stackRoute, hasElsewhere = false) {
26
- const target = stackRoute ? "the stack" : "the PR head";
27
- const route = stackRoute ? `: ${stackRoute}` : ".";
27
+ const method = configuredBranchUpdate();
28
+ const updateClause = stackRoute
29
+ ? `update the stack from the latest base first: ${stackRoute}`
30
+ : `${updateHeadFromLatestBase(method)} first. ${NEVER_MERGE_OTHER}`;
28
31
  const elsewhere = hasElsewhere
29
32
  ? " Check `Same workflow elsewhere` under `## Failing checks` for recent runs of this workflow on the default branch and other merge-queue entries."
30
33
  : "";
31
34
  const update = recovery === "none"
32
- ? `If the \`**queue removal**\` reason shows GitHub removed the entry itself, update ${target} from the latest base first${route} If a person may have dequeued the PR, skip that update unless a conflict step above requires it.`
33
- : `Update ${target} from the latest base first${route}`;
35
+ ? `If the \`**queue removal**\` reason shows GitHub removed the entry itself, ${updateClause} If a person may have dequeued the PR, skip that update unless a conflict step above requires it.`
36
+ : `${updateClause.charAt(0).toUpperCase()}${updateClause.slice(1)}`;
34
37
  const reproduce = "only if the failure does not reproduce on the updated head, neither the update nor a code change altered the head, and no other blocker remains.";
35
38
  const guard = recovery === "requeue"
36
39
  ? `Run \`requeue:\` ${reproduce} If gh reports auto-merge is disabled, run \`requeue API fallback:\` instead.`