pr-shepherd 2.1.0 → 2.2.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 (181) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +28 -22
  3. package/bin/api.d.mts +10 -2
  4. package/bin/api.mjs +30 -6
  5. package/bin/checks/pending-deployments.d.mts +10 -0
  6. package/bin/checks/pending-deployments.mjs +66 -0
  7. package/bin/checks/run-workflow-paths.d.mts +7 -0
  8. package/bin/checks/run-workflow-paths.mjs +19 -0
  9. package/bin/checks/triage.mjs +3 -2
  10. package/bin/checks/unreported-required.d.mts +11 -1
  11. package/bin/checks/unreported-required.mjs +8 -3
  12. package/bin/checks/workflow-concurrency.d.mts +9 -0
  13. package/bin/checks/workflow-concurrency.mjs +84 -0
  14. package/bin/checks/workflow-path.d.mts +2 -0
  15. package/bin/checks/workflow-path.mjs +4 -0
  16. package/bin/cli/arg-flags.mjs +3 -0
  17. package/bin/cli/clean-handler.mjs +1 -1
  18. package/bin/cli/default-poll.mjs +1 -0
  19. package/bin/cli/handlers.mjs +2 -0
  20. package/bin/cli/help-command-pages.d.mts +5 -4
  21. package/bin/cli/help-command-pages.mjs +2 -1
  22. package/bin/cli/help-iterate-poll-pages.d.mts +3 -3
  23. package/bin/cli/help-iterate-poll-pages.mjs +10 -2
  24. package/bin/cli/help-top-page.d.mts +1 -1
  25. package/bin/cli/help-top-page.mjs +2 -2
  26. package/bin/cli/help.d.mts +6 -5
  27. package/bin/cli/in-progress-run-format.d.mts +3 -0
  28. package/bin/cli/in-progress-run-format.mjs +14 -0
  29. package/bin/cli/iterate-activity-formatter.d.mts +2 -0
  30. package/bin/cli/iterate-activity-formatter.mjs +11 -0
  31. package/bin/cli/iterate-flags.d.mts +3 -0
  32. package/bin/cli/iterate-flags.mjs +18 -1
  33. package/bin/cli/iterate-formatter.mjs +2 -1
  34. package/bin/cli/iterate-lean.mjs +2 -0
  35. package/bin/cli/pending-deployments-format.d.mts +5 -0
  36. package/bin/cli/pending-deployments-format.mjs +19 -0
  37. package/bin/cli/poll-handler.d.mts +1 -1
  38. package/bin/cli/poll-handler.mjs +33 -10
  39. package/bin/cli/poll-targets.mjs +2 -0
  40. package/bin/cli/stack-merge-args.d.mts +10 -0
  41. package/bin/cli/stack-merge-args.mjs +27 -0
  42. package/bin/cli/stack-overview.d.mts +1 -0
  43. package/bin/cli/stack-overview.mjs +5 -1
  44. package/bin/cli/stalled-check-format.d.mts +3 -0
  45. package/bin/cli/stalled-check-format.mjs +23 -0
  46. package/bin/cli/suggestion-renderer.mjs +6 -0
  47. package/bin/cli/triage-formatter.mjs +14 -0
  48. package/bin/commands/check.mjs +7 -2
  49. package/bin/commands/clean.d.mts +1 -1
  50. package/bin/commands/clean.mjs +7 -0
  51. package/bin/commands/iterate/check-follow-up.d.mts +9 -0
  52. package/bin/commands/iterate/check-follow-up.mjs +34 -0
  53. package/bin/commands/iterate/ci-start-stall.d.mts +23 -0
  54. package/bin/commands/iterate/ci-start-stall.mjs +33 -0
  55. package/bin/commands/iterate/duration-approx.d.mts +2 -0
  56. package/bin/commands/iterate/duration-approx.mjs +8 -0
  57. package/bin/commands/iterate/escalate.d.mts +8 -17
  58. package/bin/commands/iterate/escalate.mjs +19 -48
  59. package/bin/commands/iterate/helpers.mjs +1 -0
  60. package/bin/commands/iterate/in-progress-runs.d.mts +10 -0
  61. package/bin/commands/iterate/in-progress-runs.mjs +120 -0
  62. package/bin/commands/iterate/index.mjs +12 -6
  63. package/bin/commands/iterate/merge-plan.d.mts +2 -0
  64. package/bin/commands/iterate/merge-plan.mjs +2 -1
  65. package/bin/commands/iterate/merge-state.d.mts +2 -0
  66. package/bin/commands/iterate/merge-state.mjs +8 -21
  67. package/bin/commands/iterate/native-stack-rebase.d.mts +3 -2
  68. package/bin/commands/iterate/native-stack-rebase.mjs +32 -11
  69. package/bin/commands/iterate/queue-removal.d.mts +19 -0
  70. package/bin/commands/iterate/queue-removal.mjs +64 -0
  71. package/bin/commands/iterate/render.d.mts +2 -1
  72. package/bin/commands/iterate/render.mjs +4 -1
  73. package/bin/commands/iterate/stack-boundary.d.mts +17 -0
  74. package/bin/commands/iterate/stack-boundary.mjs +95 -0
  75. package/bin/commands/iterate/stall-repair.d.mts +17 -0
  76. package/bin/commands/iterate/stall-repair.mjs +25 -0
  77. package/bin/commands/iterate/stall.d.mts +1 -1
  78. package/bin/commands/iterate/stall.mjs +27 -18
  79. package/bin/commands/iterate/state-unavailable.d.mts +8 -0
  80. package/bin/commands/iterate/state-unavailable.mjs +23 -0
  81. package/bin/commands/iterate/triage-loop-instruction.mjs +1 -1
  82. package/bin/commands/iterate/triage.mjs +41 -74
  83. package/bin/commands/iterate/unreported-required.d.mts +5 -2
  84. package/bin/commands/iterate/unreported-required.mjs +13 -8
  85. package/bin/commands/iterate/workflow-files.d.mts +27 -0
  86. package/bin/commands/iterate/workflow-files.mjs +85 -0
  87. package/bin/commands/poll-summary-explicit-instructions.mjs +15 -1
  88. package/bin/commands/poll-summary-instructions.d.mts +4 -3
  89. package/bin/commands/poll-summary-instructions.mjs +60 -22
  90. package/bin/commands/poll-summary.mjs +38 -10
  91. package/bin/commands/poll.mjs +4 -2
  92. package/bin/commands/stack-drain.d.mts +4 -4
  93. package/bin/commands/stack-drain.mjs +19 -113
  94. package/bin/commands/stack-handoffs.d.mts +3 -3
  95. package/bin/commands/stack-handoffs.mjs +8 -8
  96. package/bin/commands/stack-lower-ready-note.d.mts +6 -0
  97. package/bin/commands/stack-lower-ready-note.mjs +35 -0
  98. package/bin/commands/stack-merge-escalations.d.mts +17 -0
  99. package/bin/commands/stack-merge-escalations.mjs +57 -0
  100. package/bin/commands/stack-merge-plan.d.mts +10 -0
  101. package/bin/commands/stack-merge-plan.mjs +132 -0
  102. package/bin/commands/stack-merge-scope.d.mts +42 -0
  103. package/bin/commands/stack-merge-scope.mjs +113 -0
  104. package/bin/commands/stack-ownership.d.mts +25 -0
  105. package/bin/commands/stack-ownership.mjs +85 -0
  106. package/bin/commands/stack-stall.d.mts +2 -0
  107. package/bin/commands/stack-stall.mjs +25 -3
  108. package/bin/commands/stack-targets-error.d.mts +16 -0
  109. package/bin/commands/stack-targets-error.mjs +44 -0
  110. package/bin/commands/stack-targets.d.mts +30 -0
  111. package/bin/commands/stack-targets.mjs +121 -0
  112. package/bin/commands/stack-work.d.mts +4 -3
  113. package/bin/commands/stack-work.mjs +7 -4
  114. package/bin/commands/tick.mjs +14 -2
  115. package/bin/config/renames.mjs +1 -1
  116. package/bin/config/schema.d.mts +4 -0
  117. package/bin/config/schema.mjs +2 -0
  118. package/bin/github/batch-parse-suites.d.mts +4 -1
  119. package/bin/github/batch-parse-suites.mjs +15 -3
  120. package/bin/github/batch-raw-types.d.mts +6 -0
  121. package/bin/github/gql/commit-check-suites.gql +6 -0
  122. package/bin/github/gql/poll-summary-fragment.gql +6 -0
  123. package/bin/github/poll-summary-command.d.mts +15 -1
  124. package/bin/github/poll-summary-command.mjs +39 -3
  125. package/bin/github/poll-summary-projector.d.mts +1 -1
  126. package/bin/github/poll-summary-projector.mjs +1 -4
  127. package/bin/github/poll-summary-raw.d.mts +6 -0
  128. package/bin/github/poll-summary-route.mjs +4 -1
  129. package/bin/github/poll-summary.mjs +10 -3
  130. package/bin/github/rest-batch-read.mjs +17 -6
  131. package/bin/github/rest-batch-snapshot.d.mts +2 -2
  132. package/bin/github/rest-batch-snapshot.mjs +3 -0
  133. package/bin/github/rest-check-read.d.mts +1 -18
  134. package/bin/github/rest-check-read.mjs +1 -2
  135. package/bin/github/rest-stack-read.d.mts +9 -0
  136. package/bin/github/rest-stack-read.mjs +40 -0
  137. package/bin/github/rest-suite-types.d.mts +23 -0
  138. package/bin/github/rest-suite-types.mjs +1 -0
  139. package/bin/github/rest-summary-read.mjs +2 -0
  140. package/bin/mcp/server.mjs +29 -3
  141. package/bin/pr-reference.d.mts +2 -0
  142. package/bin/pr-reference.mjs +1 -1
  143. package/bin/reporters/agent.mjs +3 -0
  144. package/bin/state/check-follow-up.d.mts +30 -0
  145. package/bin/state/check-follow-up.mjs +51 -0
  146. package/bin/state/ci-start-follow-up.d.mts +14 -0
  147. package/bin/state/ci-start-follow-up.mjs +21 -0
  148. package/bin/state/queue-removal-follow-up.d.mts +20 -0
  149. package/bin/state/queue-removal-follow-up.mjs +23 -0
  150. package/bin/state/signature-marker.d.mts +10 -0
  151. package/bin/state/signature-marker.mjs +28 -0
  152. package/bin/state/stack-merge-approval.d.mts +26 -0
  153. package/bin/state/stack-merge-approval.mjs +39 -0
  154. package/bin/state/stall-repair.d.mts +16 -0
  155. package/bin/state/stall-repair.mjs +47 -0
  156. package/bin/types/activity.d.mts +2 -1
  157. package/bin/types/escalate.d.mts +9 -2
  158. package/bin/types/github.d.mts +18 -0
  159. package/bin/types/in-progress-run.d.mts +20 -0
  160. package/bin/types/in-progress-run.mjs +1 -0
  161. package/bin/types/iterate.d.mts +22 -1
  162. package/bin/types/poll-summary.d.mts +18 -1
  163. package/bin/types/report.d.mts +5 -1
  164. package/bin/types.d.mts +1 -0
  165. package/bin/types.mjs +1 -0
  166. package/package.json +2 -2
  167. package/plugins/pr-shepherd/.claude-plugin/plugin.json +1 -1
  168. package/plugins/pr-shepherd/.codex-plugin/plugin.json +1 -1
  169. package/plugins/pr-shepherd/.codex.mcp.json +1 -1
  170. package/plugins/pr-shepherd/.mcp.json +1 -1
  171. package/plugins/pr-shepherd/package-lock.json +4 -4
  172. package/plugins/pr-shepherd/package.json +1 -1
  173. package/plugins/pr-shepherd/skills/pr-shepherd/SKILL.md +8 -7
  174. package/plugins/pr-shepherd/skills/pr-shepherd/references/check-follow-up.md +14 -0
  175. package/plugins/pr-shepherd/skills/pr-shepherd/references/ci-failure-triage.md +6 -5
  176. package/plugins/pr-shepherd/skills/pr-shepherd/references/ci-start-stall.md +15 -0
  177. package/plugins/pr-shepherd/skills/pr-shepherd/references/create-a-pr.md +4 -1
  178. package/plugins/pr-shepherd/skills/pr-shepherd/references/mcp-fallback.md +1 -1
  179. package/plugins/pr-shepherd/skills/pr-shepherd/references/merge-queue-ejection.md +6 -5
  180. package/plugins/pr-shepherd/skills/pr-shepherd/references/required-checks-unreported.md +16 -0
  181. package/pr-shepherd.schema.json +11 -0
@@ -0,0 +1,121 @@
1
+ import { EXIT, ShepherdError } from "../exit-codes.mjs";
2
+ import { getRepoInfo } from "../github/client.mjs";
3
+ import { readRestStackByNumber, restPullExists, restRepoReachable, } from "../github/rest-stack-read.mjs";
4
+ import { GitHubRequestError } from "../github/errors.mjs";
5
+ import { readStackTopology } from "../github/stack-read.mjs";
6
+ import { normalizeRepositoryIdentity, resolveParsedPrTarget, } from "../pr-reference.mjs";
7
+ import { multiStackError } from "./stack-targets-error.mjs";
8
+ export function stackMergeScope(flag, through) {
9
+ if (flag === "through")
10
+ return { kind: "through", pr: through };
11
+ if (flag === "ready")
12
+ return { kind: "ready" };
13
+ return flag ? { kind: "all" } : undefined;
14
+ }
15
+ function usage(message) {
16
+ throw new ShepherdError(message, EXIT.USAGE);
17
+ }
18
+ /**
19
+ * Resolve `stack` refs to one native stack and the layers the caller owns. A number is a PR when
20
+ * GitHub has one, else a stack number (the two share a sequence). Ownership is declared: a stack
21
+ * number selects and owns every layer, and listed PRs own only themselves, so one PR does not
22
+ * claim the layers around it.
23
+ */
24
+ export async function resolveStackTarget(input) {
25
+ const all = [...input.refs, ...(input.through ? [input.through] : [])];
26
+ const repos = all.flatMap((ref) => resolveParsedPrTarget(ref).targetRepository ?? []);
27
+ const named = repos[0];
28
+ if (repos.some((r) => normalizeRepositoryIdentity(`${r.owner}/${r.name}`) !==
29
+ normalizeRepositoryIdentity(`${named.owner}/${named.name}`))) {
30
+ usage("stack refs must all name one repository.");
31
+ }
32
+ const [only] = input.refs;
33
+ // One PR URL needs no resolution: it selects its stack and owns only itself.
34
+ if (input.refs.length === 1 && only.url === true && !input.through) {
35
+ return {
36
+ anchor: only.number,
37
+ owned: [only.number],
38
+ ...(named && { targetRepository: named }),
39
+ };
40
+ }
41
+ const repo = named ?? (await getRepoInfo());
42
+ const slug = `${repo.owner}/${repo.name}`;
43
+ const numbers = [...new Set(input.refs.map((ref) => ref.number))];
44
+ const refByNumber = new Map(input.refs.map((ref) => [ref.number, ref]));
45
+ const groups = new Map();
46
+ for (const number of numbers) {
47
+ // A number already in a read stack is one of its PRs; PR and stack numbers never collide.
48
+ const member = [...groups.values()].find((group) => group.members.includes(number));
49
+ if (member) {
50
+ member.prs.push(number);
51
+ continue;
52
+ }
53
+ const found = await readRef(number, refByNumber.get(number), repo, slug);
54
+ const isPr = found.isPr;
55
+ const group = groups.get(found.number) ?? { stack: found.number, prs: [], stackRefs: [] };
56
+ (isPr ? group.prs : group.stackRefs).push(number);
57
+ groups.set(found.number, group);
58
+ group.members = found.members;
59
+ }
60
+ if (groups.size > 1) {
61
+ usage(multiStackError(slug, [...groups.values()], input.merge, input.through?.number, input.tool));
62
+ }
63
+ const group = [...groups.values()][0];
64
+ if (group.stackRefs.length > 0 && numbers.length > 1) {
65
+ usage(`stack #${group.stack} is named together with other refs. A stack number already selects every layer; pass either that one stack number or PRs of the stack.`);
66
+ }
67
+ const owned = group.prs.length > 0 ? group.prs : undefined;
68
+ const through = input.through?.number;
69
+ if (through !== undefined) {
70
+ if (!group.members.includes(through)) {
71
+ usage(`--merge-through PR #${through} is not a layer of native stack #${group.stack}.`);
72
+ }
73
+ if (owned && !owned.includes(through)) {
74
+ usage(`--merge-through PR #${through} is not one of the PRs listed as yours.`);
75
+ }
76
+ if (input.through.url !== true &&
77
+ !(await readOrDenied(() => restPullExists(through, repo), slug))) {
78
+ usage(`--merge-through takes a pull request; #${through} is a stack number.`);
79
+ }
80
+ }
81
+ return {
82
+ anchor: group.prs[0] ?? group.members[0],
83
+ ...(owned && { owned }),
84
+ ...(through !== undefined && { through }),
85
+ ...(named && { targetRepository: repo }),
86
+ };
87
+ }
88
+ /** A GitHub 401/403 is an access problem, not a missing PR or stack. */
89
+ async function readOrDenied(read, slug) {
90
+ try {
91
+ return await read();
92
+ }
93
+ catch (error) {
94
+ if (error instanceof GitHubRequestError && (error.status === 401 || error.status === 403)) {
95
+ throw new ShepherdError(`GitHub denied access to ${slug} (HTTP ${error.status}). Check that the token can read pull requests and stacks in that repository; the refs were not resolved.`, EXIT.NOPERM, { cause: error });
96
+ }
97
+ throw error;
98
+ }
99
+ }
100
+ async function readRef(number, ref, repo, slug) {
101
+ const isPr = ref.url === true || (await readOrDenied(() => restPullExists(number, repo), slug));
102
+ const found = isPr
103
+ ? await readOrDenied(() => readPrStack(number, repo), slug)
104
+ : await readStack(number, repo, slug);
105
+ return { ...found, isPr };
106
+ }
107
+ async function readPrStack(pr, repo) {
108
+ const read = await readStackTopology(pr, repo);
109
+ return { number: read.stackNumber, members: read.ordered.map((member) => member.number) };
110
+ }
111
+ async function readStack(number, repo, slug) {
112
+ const stack = await readOrDenied(() => readRestStackByNumber(number, repo), slug);
113
+ if (!stack) {
114
+ // GitHub answers 404 for a repository the token cannot see, too.
115
+ if (!(await readOrDenied(() => restRepoReachable(repo), slug))) {
116
+ throw new ShepherdError(`#${number} could not be resolved: ${slug} is not accessible with the current GitHub credentials (or does not exist). Check the repository and token access.`, EXIT.NOPERM);
117
+ }
118
+ usage(`#${number} is neither a pull request nor a native stack in ${slug}.`);
119
+ }
120
+ return { number: stack.number, members: stack.members };
121
+ }
@@ -20,8 +20,9 @@ export declare function splitStackWork(candidates: PollSummaryItem[], staleChild
20
20
  /** The literal stack command to rerun, or the generic name when the caller's command is unknown. */
21
21
  export declare function stackRerunTarget(command?: string): string;
22
22
  /**
23
- * The closing step after routed sessions: rerun the stack command, or stop when nothing is owned.
24
- * Returns the plan action: a stop is a handoff, so no rerun, quota cadence, or wake-up follows it.
23
+ * The closing step after routed sessions: rerun the stack command, or wait when nothing is owned.
24
+ * Returns the plan action: other authors' layers are not an intervention, so the plan waits under
25
+ * the stack stall timer, with no rerun, quota cadence, or wake-up step.
25
26
  * `keepWatching` is false when a human handoff may end the run before every layer is terminal.
26
27
  */
27
- export declare function appendStackRerunInstruction(instructions: string[], layers: PollSummaryItem[], rerun: string, keepWatching?: boolean): "shepherd" | "escalate";
28
+ export declare function appendStackRerunInstruction(instructions: string[], layers: PollSummaryItem[], rerun: string, keepWatching?: boolean): "shepherd" | "wait";
@@ -37,18 +37,21 @@ function onlyUnownedWork(layers) {
37
37
  }
38
38
  /** The turn must outlive every non-terminal layer; a one-PR session ending does not end the stack. */
39
39
  const STACK_KEEP_WATCHING = "Keep watching until every layer is terminal.";
40
+ /** Work remains, but only on other authors' layers. The stack stall timer escalates if it never moves. */
41
+ const NO_OWNED_SESSION = "No owned layer needs a session. The remaining work belongs to other authors. Recheck at the configured polling cadence; Shepherd escalates `stall-timeout` if the stack does not change.";
40
42
  /** The literal stack command to rerun, or the generic name when the caller's command is unknown. */
41
43
  export function stackRerunTarget(command) {
42
44
  return command ? `\`${command}\`` : "this same `stack` command";
43
45
  }
44
46
  /**
45
- * The closing step after routed sessions: rerun the stack command, or stop when nothing is owned.
46
- * Returns the plan action: a stop is a handoff, so no rerun, quota cadence, or wake-up follows it.
47
+ * The closing step after routed sessions: rerun the stack command, or wait when nothing is owned.
48
+ * Returns the plan action: other authors' layers are not an intervention, so the plan waits under
49
+ * the stack stall timer, with no rerun, quota cadence, or wake-up step.
47
50
  * `keepWatching` is false when a human handoff may end the run before every layer is terminal.
48
51
  */
49
52
  export function appendStackRerunInstruction(instructions, layers, rerun, keepWatching = true) {
50
53
  const stop = onlyUnownedWork(layers);
51
54
  const step = keepWatching ? `${rerun} ${STACK_KEEP_WATCHING}` : rerun;
52
- instructions.push(`${instructions.length + 1}. ${stop ? "No owned layer needs a session. Report this overview and stop." : step}`);
53
- return stop ? "escalate" : "shepherd";
55
+ instructions.push(`${instructions.length + 1}. ${stop ? NO_OWNED_SESSION : step}`);
56
+ return stop ? "wait" : "shepherd";
54
57
  }
@@ -5,6 +5,7 @@ import { isHandedOffSelection, onlyDraftVerificationSelection, } from "./poll-su
5
5
  import { runIterate } from "./iterate/index.mjs";
6
6
  import { earliestDeadline, readStallDeadline } from "./stall-deadline.mjs";
7
7
  import { runsSingleTick } from "./single-tick.mjs";
8
+ import { isDraftReadinessVerification } from "./stack-work.mjs";
8
9
  import { readStackStallDeadline } from "./stack-stall.mjs";
9
10
  import { runPoll } from "./poll.mjs";
10
11
  import { runAggregatePoll, runPollSummary, } from "./poll-summary.mjs";
@@ -70,14 +71,25 @@ async function withAggregateNextCheck(result, opts) {
70
71
  /** The appended tick step owns timing, including pending stack merges. */
71
72
  function withoutPollingCadence(step) {
72
73
  return step
73
- .replace(/ Recheck(?: them)? at the configured polling cadence\./g, "")
74
+ .replace(/ Recheck(?: them)? at the configured polling cadence[.;]/g, "")
74
75
  .replace(" If a background exit wakes you, end the turn and continue then.", "")
75
76
  .replace(/Do not end the turn while any selected row is non-terminal: /g, "Keep watching every non-terminal selected row through the wake-up below: ")
76
77
  .replace("rerun that command at the configured cadence to resume its UUID", "rerun that command after the wake-up below to resume its UUID");
77
78
  }
79
+ /** A stack layer no one-PR probe can advance: unreadable, or another author's draft. */
80
+ function hasUnrunnableLayer(result) {
81
+ const { selection } = result;
82
+ if (selection.kind !== "stack")
83
+ return false;
84
+ // A whole-stack selection omits row ownership: every layer is the caller's.
85
+ const listed = selection.owned !== undefined;
86
+ return result.prs.some((item) => item.state === "UNKNOWN" || (listed && isDraftReadinessVerification(item) && !item.owned));
87
+ }
78
88
  function aggregateNextCheck(result, stallDeadlineSeconds) {
79
89
  if (isHandedOffSelection(result) ||
80
- (onlyDraftVerificationSelection(result) && result.nextAction !== "merge") ||
90
+ (onlyDraftVerificationSelection(result) &&
91
+ !hasUnrunnableLayer(result) &&
92
+ result.nextAction !== "merge") ||
81
93
  result.reason === "all_terminal" ||
82
94
  result.nextAction === "cancel" ||
83
95
  result.nextAction === "escalate") {
@@ -6,7 +6,7 @@ const RENAMED_KEYS = {
6
6
  cliCommand: "cli-command",
7
7
  botUsernames: "bot-usernames",
8
8
  ignoreChecks: "checks.ignore",
9
- "actions.neverCancelRuns": "checks.never-ignore",
9
+ "actions.neverCancelRuns": "checks.never-cancel",
10
10
  "checks.ciTriggerEvents": "checks.ci-trigger-events",
11
11
  "checks.ignoreLogLines": "checks.ignore-log-lines",
12
12
  "iterate.fixAttemptsPerThread": "iterate.triage-attempts-per-thread",
@@ -15,6 +15,7 @@ export declare const configSchema: z.ZodObject<{
15
15
  checks: z.ZodPrefault<z.ZodObject<{
16
16
  ignore: z.ZodDefault<z.ZodArray<z.ZodString>>;
17
17
  "never-ignore": z.ZodDefault<z.ZodArray<z.ZodString>>;
18
+ "never-cancel": z.ZodDefault<z.ZodArray<z.ZodString>>;
18
19
  "ci-trigger-events": z.ZodDefault<z.ZodArray<z.ZodString>>;
19
20
  "ignore-log-lines": z.ZodDefault<z.ZodArray<z.ZodString>>;
20
21
  }, z.core.$strict>>;
@@ -79,6 +80,7 @@ export declare const configSchema: z.ZodObject<{
79
80
  actions: z.ZodPrefault<z.ZodObject<{
80
81
  "auto-minimize-suppressed": z.ZodDefault<z.ZodBoolean>;
81
82
  "work-while-queued": z.ZodDefault<z.ZodBoolean>;
83
+ "cancel-runs-before-push": z.ZodDefault<z.ZodBoolean>;
82
84
  }, z.core.$strict>>;
83
85
  classify: z.ZodPrefault<z.ZodObject<{
84
86
  standard: z.ZodDefault<z.ZodRecord<z.ZodEnum<{
@@ -100,6 +102,7 @@ export declare const configFileSchema: z.ZodObject<{
100
102
  checks: z.ZodPrefault<z.ZodObject<{
101
103
  ignore: z.ZodDefault<z.ZodArray<z.ZodString>>;
102
104
  "never-ignore": z.ZodDefault<z.ZodArray<z.ZodString>>;
105
+ "never-cancel": z.ZodDefault<z.ZodArray<z.ZodString>>;
103
106
  "ci-trigger-events": z.ZodDefault<z.ZodArray<z.ZodString>>;
104
107
  "ignore-log-lines": z.ZodDefault<z.ZodArray<z.ZodString>>;
105
108
  }, z.core.$strict>>;
@@ -164,6 +167,7 @@ export declare const configFileSchema: z.ZodObject<{
164
167
  actions: z.ZodPrefault<z.ZodObject<{
165
168
  "auto-minimize-suppressed": z.ZodDefault<z.ZodBoolean>;
166
169
  "work-while-queued": z.ZodDefault<z.ZodBoolean>;
170
+ "cancel-runs-before-push": z.ZodDefault<z.ZodBoolean>;
167
171
  }, z.core.$strict>>;
168
172
  classify: z.ZodPrefault<z.ZodObject<{
169
173
  standard: z.ZodDefault<z.ZodRecord<z.ZodEnum<{
@@ -106,6 +106,7 @@ export const configSchema = z.strictObject({
106
106
  .strictObject({
107
107
  ignore: strings().default(() => []),
108
108
  "never-ignore": strings().default(() => []),
109
+ "never-cancel": strings().default(() => []),
109
110
  "ci-trigger-events": strings().default(() => ["pull_request", "pull_request_target"]),
110
111
  "ignore-log-lines": z.array(regexPattern).default(() => []),
111
112
  })
@@ -162,6 +163,7 @@ export const configSchema = z.strictObject({
162
163
  .strictObject({
163
164
  "auto-minimize-suppressed": z.boolean().default(true),
164
165
  "work-while-queued": z.boolean().default(false),
166
+ "cancel-runs-before-push": z.boolean().default(true),
165
167
  })
166
168
  .prefault({}),
167
169
  classify: z
@@ -1,4 +1,4 @@
1
- import type { WorkflowSuiteSnapshot } from "../checks/unreported-required.mts";
1
+ import { type WorkflowSuiteSnapshot } from "../checks/unreported-required.mts";
2
2
  import type { CheckRun } from "../types.mts";
3
3
  import type { RawPr } from "./batch-raw-types.mts";
4
4
  export declare function parseCheckSuitesComplete(raw: RawPr): boolean;
@@ -16,6 +16,9 @@ export declare function startupFailureChecksFromSuites(suites: {
16
16
  workflow?: {
17
17
  name: string | null;
18
18
  } | null;
19
+ file?: {
20
+ path: string | null;
21
+ } | null;
19
22
  } | null;
20
23
  }>;
21
24
  } | null | undefined): CheckRun[];
@@ -1,3 +1,5 @@
1
+ import { normalizeWorkflowPath } from "../checks/workflow-path.mjs";
2
+ import { ACTIONS_APP_SLUG } from "../checks/unreported-required.mjs";
1
3
  export function parseCheckSuitesComplete(raw) {
2
4
  return raw.commits.nodes[0]?.commit.checkSuites?.pageInfo.hasNextPage === false;
3
5
  }
@@ -10,13 +12,21 @@ export function parseHeadCheckSuitesEmpty(raw) {
10
12
  function parseHeadWorkflowSuites(raw) {
11
13
  const nodes = raw.commits.nodes[0]?.commit.checkSuites?.nodes ?? [];
12
14
  return nodes.flatMap((node) => {
13
- if (!node.workflowRun)
14
- return [];
15
+ if (!node.workflowRun) {
16
+ // Actions creates its suites before their runs; keep those so a starting workflow is visible.
17
+ if (node.app?.slug !== ACTIONS_APP_SLUG)
18
+ return [];
19
+ return [{ status: node.status ?? null, conclusion: node.conclusion, app: node.app }];
20
+ }
15
21
  return [
16
22
  {
17
23
  status: node.status ?? null,
18
24
  conclusion: node.conclusion,
19
- workflowRun: { event: node.workflowRun.event },
25
+ workflowRun: {
26
+ event: node.workflowRun.event,
27
+ databaseId: node.workflowRun.databaseId,
28
+ path: normalizeWorkflowPath(node.workflowRun.file?.path) ?? null,
29
+ },
20
30
  },
21
31
  ];
22
32
  });
@@ -33,6 +43,7 @@ export function startupFailureChecksFromSuites(suites) {
33
43
  return [];
34
44
  const runId = node.workflowRun.databaseId != null ? String(node.workflowRun.databaseId) : null;
35
45
  const name = node.workflowRun.workflow?.name?.trim() || (runId ? `workflow run ${runId}` : "workflow run");
46
+ const workflowPath = normalizeWorkflowPath(node.workflowRun.file?.path);
36
47
  return [
37
48
  {
38
49
  name,
@@ -42,6 +53,7 @@ export function startupFailureChecksFromSuites(suites) {
42
53
  detailsUrl: node.workflowRun.url ?? "",
43
54
  event: node.workflowRun.event,
44
55
  runId,
56
+ ...(workflowPath !== undefined && { workflowPath }),
45
57
  },
46
58
  ];
47
59
  });
@@ -125,6 +125,9 @@ interface RawCheckSuites {
125
125
  id?: string;
126
126
  status?: string | null;
127
127
  conclusion: string | null;
128
+ app?: {
129
+ slug: string | null;
130
+ } | null;
128
131
  workflowRun: {
129
132
  databaseId: number | null;
130
133
  event: string | null;
@@ -132,6 +135,9 @@ interface RawCheckSuites {
132
135
  workflow: {
133
136
  name: string | null;
134
137
  } | null;
138
+ file?: {
139
+ path: string | null;
140
+ } | null;
135
141
  } | null;
136
142
  }>;
137
143
  }
@@ -7,6 +7,9 @@ fragment CommitCheckSuites on Commit {
7
7
  id
8
8
  status
9
9
  conclusion
10
+ app {
11
+ slug
12
+ }
10
13
  workflowRun {
11
14
  databaseId
12
15
  event
@@ -14,6 +17,9 @@ fragment CommitCheckSuites on Commit {
14
17
  workflow {
15
18
  name
16
19
  }
20
+ file {
21
+ path
22
+ }
17
23
  }
18
24
  }
19
25
  }
@@ -247,6 +247,9 @@ fragment PollSummaryPr on PullRequest {
247
247
  id
248
248
  status
249
249
  conclusion
250
+ app {
251
+ slug
252
+ }
250
253
  workflowRun {
251
254
  databaseId
252
255
  event
@@ -254,6 +257,9 @@ fragment PollSummaryPr on PullRequest {
254
257
  workflow {
255
258
  name
256
259
  }
260
+ file {
261
+ path
262
+ }
257
263
  }
258
264
  }
259
265
  }
@@ -5,4 +5,18 @@ export declare function pollCommandFields(repo: string, pr: number, isDraft: boo
5
5
  * Intervals and timeouts are omitted: they are loop cadence, not selection. Options equal to the
6
6
  * configured defaults are omitted too, since the parser fills them from config.
7
7
  */
8
- export declare function aggregateRerunCommand(repo: string, selection: PollSummarySelection, opts: PollSummaryCommandOptions): string;
8
+ export declare function aggregateRerunCommand(repo: string, selection: PollSummarySelection, opts: PollSummaryCommandOptions, refs?: string[]): string;
9
+ /**
10
+ * The two commands that approve unlisted layers: the same request listing them as well, and the
11
+ * same request naming the stack number, which owns every layer.
12
+ */
13
+ export declare function stackApprovalCommands(repo: string, selection: PollSummarySelection, opts: PollSummaryCommandOptions, extra: number[]): {
14
+ listed: string;
15
+ whole: string;
16
+ };
17
+ /**
18
+ * The same stack command, merging whichever owned prefix is ready instead of the whole scope.
19
+ * `scoped` replaces the listed refs, so a stack number or a listed PR above a `--merge-through`
20
+ * target cannot widen ownership past what the original request approved.
21
+ */
22
+ export declare function mergeReadyCommand(command: string, scoped?: string[]): string;
@@ -29,15 +29,27 @@ export function pollCommandFields(repo, pr, isDraft, opts) {
29
29
  * Intervals and timeouts are omitted: they are loop cadence, not selection. Options equal to the
30
30
  * configured defaults are omitted too, since the parser fills them from config.
31
31
  */
32
- export function aggregateRerunCommand(repo, selection, opts) {
32
+ export function aggregateRerunCommand(repo, selection, opts, refs) {
33
33
  const args = selection.kind === "stack"
34
- ? ["stack", formatPrUrl(repo, selection.anchor), opts.tick ? "--once" : "--until-terminal"]
34
+ ? [
35
+ "stack",
36
+ // Listed PRs name the caller's own layers; otherwise the stack number selects them all.
37
+ ...(refs ??
38
+ (selection.owned
39
+ ? selection.owned.map((pr) => formatPrUrl(repo, pr))
40
+ : [`${repo}#${selection.stackNumber}`])),
41
+ opts.tick ? "--once" : "--until-terminal",
42
+ ]
35
43
  : [
36
44
  ...(opts.tick ? ["iterate"] : []),
37
45
  ...selection.requested.map((pr) => formatPrUrl(repo, pr)),
38
46
  ...(opts.tick ? [] : ["--until-terminal"]),
39
47
  ];
40
- if (opts.merge)
48
+ if (opts.stackMerge?.kind === "ready")
49
+ args.push("--merge-ready");
50
+ else if (opts.stackMerge?.kind === "through")
51
+ args.push("--merge-through", formatPrUrl(repo, opts.stackMerge.pr));
52
+ else if (opts.merge)
41
53
  args.push("--merge");
42
54
  // The parser always fills these from config, so a default value adds nothing to the command.
43
55
  const iterate = loadConfig().iterate;
@@ -53,3 +65,27 @@ export function aggregateRerunCommand(repo, selection, opts) {
53
65
  args.push("--no-auto-mark-ready");
54
66
  return buildPrShepherdCommand(args).text;
55
67
  }
68
+ /**
69
+ * The two commands that approve unlisted layers: the same request listing them as well, and the
70
+ * same request naming the stack number, which owns every layer.
71
+ */
72
+ export function stackApprovalCommands(repo, selection, opts, extra) {
73
+ if (selection.kind !== "stack")
74
+ return { listed: "", whole: "" };
75
+ const listed = [...new Set([...(selection.owned ?? []), ...extra])].sort((a, b) => a - b);
76
+ return {
77
+ listed: aggregateRerunCommand(repo, { ...selection, owned: listed }, opts),
78
+ whole: aggregateRerunCommand(repo, selection, opts, [`${repo}#${selection.stackNumber}`]),
79
+ };
80
+ }
81
+ /**
82
+ * The same stack command, merging whichever owned prefix is ready instead of the whole scope.
83
+ * `scoped` replaces the listed refs, so a stack number or a listed PR above a `--merge-through`
84
+ * target cannot widen ownership past what the original request approved.
85
+ */
86
+ export function mergeReadyCommand(command, scoped) {
87
+ const swapped = command.replace(/ --merge(?:-through \S+)?(?= |$)/, " --merge-ready");
88
+ return scoped
89
+ ? swapped.replace(/ stack (?:[^-\s]\S* )+(?=--)/, ` stack ${scoped.join(" ")} `)
90
+ : swapped;
91
+ }
@@ -1,6 +1,6 @@
1
1
  import type { PollSummaryCommandOptions, PollSummaryItem } from "../types.mts";
2
2
  import type { RepoInfo } from "./client.mts";
3
3
  import type { RawSummaryPr } from "./poll-summary-raw.mts";
4
- export declare function summarizePollSummaryPr(raw: RawSummaryPr, repo: RepoInfo, opts: PollSummaryCommandOptions, viewerCanAdminister?: boolean | undefined, mergeTargetContexts?: readonly string[], viewerLogin?: string | null,
4
+ export declare function summarizePollSummaryPr(raw: RawSummaryPr, repo: RepoInfo, opts: PollSummaryCommandOptions, viewerCanAdminister?: boolean | undefined, mergeTargetContexts?: readonly string[],
5
5
  /** Aggregate polls only: apply rule-driven auto-resolve. Receipt and merge validation reads never mutate. */
6
6
  applyRuleAutoResolve?: boolean): Promise<PollSummaryItem>;
@@ -16,7 +16,7 @@ import { applyPendingWorkflowSuites, applyUnreportedRequiredChecks, summaryRequi
16
16
  import { aliasThreadSeenMarkers } from "./rest-identities.mjs";
17
17
  import { restQueueRequirement } from "./poll-summary-rest-queue.mjs";
18
18
  import { detectBlockingReviewer } from "./poll-summary-blocking-reviewer.mjs";
19
- export async function summarizePollSummaryPr(raw, repo, opts, viewerCanAdminister = undefined, mergeTargetContexts, viewerLogin = null,
19
+ export async function summarizePollSummaryPr(raw, repo, opts, viewerCanAdminister = undefined, mergeTargetContexts,
20
20
  /** Aggregate polls only: apply rule-driven auto-resolve. Receipt and merge validation reads never mutate. */
21
21
  applyRuleAutoResolve = false) {
22
22
  const repoName = `${repo.owner}/${repo.name}`;
@@ -100,9 +100,6 @@ applyRuleAutoResolve = false) {
100
100
  title: raw.title,
101
101
  url: raw.url || formatPrUrl(repoName, raw.number),
102
102
  ...(raw.author?.login && { authorLogin: raw.author.login }),
103
- ...(raw.author?.login &&
104
- viewerLogin !== null &&
105
- raw.author.login.toLowerCase() === viewerLogin.toLowerCase() && { owned: true }),
106
103
  action,
107
104
  reasons,
108
105
  state: normalizePollSummaryState(raw.state),
@@ -94,6 +94,9 @@ export interface RawSummaryCommit {
94
94
  id?: string;
95
95
  status?: string | null;
96
96
  conclusion: string | null;
97
+ app?: {
98
+ slug: string | null;
99
+ } | null;
97
100
  workflowRun: {
98
101
  databaseId?: number | null;
99
102
  event: string | null;
@@ -101,6 +104,9 @@ export interface RawSummaryCommit {
101
104
  workflow?: {
102
105
  name: string | null;
103
106
  } | null;
107
+ file?: {
108
+ path: string | null;
109
+ } | null;
104
110
  } | null;
105
111
  }>;
106
112
  } | null;
@@ -50,7 +50,10 @@ export function routePollSummary(raw, checks, review, opts) {
50
50
  const unsupported = getGithubTransport() === "rest" && raw.viewerCanUpdate !== false && !isCcrTransport();
51
51
  if (unsupported)
52
52
  return { action: "escalate", reasons: ["transport-unsupported"] };
53
- return { action: "escalate", reasons: ["mark-ready-authorization-required"] };
53
+ return {
54
+ action: "escalate",
55
+ reasons: ["mark-ready-authorization-required"],
56
+ };
54
57
  }
55
58
  return { action: "mark_ready", reasons: ["draft-appears-ready"] };
56
59
  }
@@ -1,4 +1,5 @@
1
1
  import { readRestStackSummary } from "./rest-stack-summary.mjs";
2
+ import { requestedMergeScope } from "../commands/stack-merge-scope.mjs";
2
3
  import { githubOperation, getGithubTransport, runWithGithubTransport } from "./transport.mjs";
3
4
  import { readRestExplicitSummary } from "./rest-explicit-summary-read.mjs";
4
5
  import { withRestConditionalScope } from "./rest-conditional-scope.mjs";
@@ -38,7 +39,7 @@ async function fetchSelectedPollSummary(opts, repo) {
38
39
  return {
39
40
  selection: { kind: "prs", requested },
40
41
  // One explicit PR's failed read becomes a row; stack selections stay fail-closed.
41
- prs: await summarizeRowsIsolated(raw, failures, repo, opts, (pr) => summarizePollSummaryPr(pr, repo, opts, viewerCanAdminister, undefined, null, true)),
42
+ prs: await summarizeRowsIsolated(raw, failures, repo, opts, (pr) => summarizePollSummaryPr(pr, repo, opts, viewerCanAdminister, undefined, true)),
42
43
  };
43
44
  }
44
45
  /** Fresh, read-only snapshot used to bind a one-PR READY receipt to stack routing. */
@@ -96,7 +97,7 @@ async function fetchStackSummary(opts, repo) {
96
97
  const hint = graphql ? await loadStackSizeHint(stateKey) : 0;
97
98
  const sizeHint = hint || UNSIZED_STACK_SUMMARY_FIRST;
98
99
  const read = await readStackSummary(anchor, repo, sizeHint);
99
- const { stackNumber, stackSize, viewerLogin, viewerCanAdminister, ordered, allowedMergeMethods } = read;
100
+ const { stackNumber, stackSize, viewerCanAdminister, ordered, allowedMergeMethods } = read;
100
101
  if (graphql && stackSize !== hint)
101
102
  await storeStackSizeHint(stateKey, stackSize);
102
103
  for (const pr of ordered) {
@@ -106,7 +107,13 @@ async function fetchStackSummary(opts, repo) {
106
107
  const handoffSource = getGithubTransport() === "rest" ? undefined : stackHandoffSource(read);
107
108
  const stackAncestry = stackAncestryGaps(ordered);
108
109
  const required = await trunkRequiredContexts(ordered, repo);
109
- const prs = await Promise.all(ordered.map((pr) => summarizePollSummaryPr(pr, repo, opts, viewerCanAdminister, required, viewerLogin, true)));
110
+ // Rule-driven auto-resolve mutates review state, so it runs only on layers the caller owns
111
+ // and, for --merge-through, only through the target: other layers are read, never written.
112
+ const scope = requestedMergeScope(opts);
113
+ const throughIndex = scope?.kind === "through" ? ordered.findIndex((pr) => pr.number === scope.pr) : -1;
114
+ const mayMutate = (pr, index) => (!opts.stackOwned || opts.stackOwned.includes(pr.number)) &&
115
+ (throughIndex < 0 || index <= throughIndex);
116
+ const prs = await Promise.all(ordered.map((pr, index) => summarizePollSummaryPr(pr, repo, opts, viewerCanAdminister, required, mayMutate(pr, index))));
110
117
  if (handoffSource)
111
118
  patchHandoffLayers(handoffSource.layers, prs);
112
119
  return {
@@ -1,3 +1,4 @@
1
+ import { ACTIONS_APP_SLUG } from "../checks/unreported-required.mjs";
1
2
  import { readRestPull, restPullRevision } from "./rest-pr-core.mjs";
2
3
  import { readRestSnapshot } from "./rest-batch-snapshot.mjs";
3
4
  import { isRestPullMerged, restMergedBatchData } from "./rest-terminal-batch.mjs";
@@ -5,6 +6,7 @@ import { restSummary } from "./rest-summary-read.mjs";
5
6
  import { markReadyAnnotationProbeComplete } from "./poll-summary-annotation-probe.mjs";
6
7
  import { hydratePollSummaryChecks } from "./poll-summary-check-hydration.mjs";
7
8
  import { GitHubRequestError } from "./errors.mjs";
9
+ import { normalizeWorkflowPath } from "../checks/workflow-path.mjs";
8
10
  import { EXIT } from "../exit-codes.mjs";
9
11
  /** REST uses multiple resources; retry a moving head/base once rather than combining revisions. */
10
12
  export async function fetchRestPrBatch(pr, repo, opts = {}) {
@@ -29,14 +31,23 @@ export async function fetchRestPrBatch(pr, repo, opts = {}) {
29
31
  ...(snapshot.checks.suites.length === 0 && { headCheckSuitesEmpty: true }),
30
32
  headWorkflowSuites: snapshot.checks.suites.flatMap((suite) => {
31
33
  const run = snapshot.checks.workflowRuns.find((run) => run.check_suite_id === suite.id);
32
- return run
33
- ? [
34
+ const status = suite.status.toUpperCase();
35
+ const conclusion = suite.conclusion?.toUpperCase() ?? null;
36
+ if (run)
37
+ return [
34
38
  {
35
- status: suite.status.toUpperCase(),
36
- conclusion: suite.conclusion?.toUpperCase() ?? null,
37
- workflowRun: { event: run.event },
39
+ status,
40
+ conclusion,
41
+ workflowRun: {
42
+ event: run.event,
43
+ databaseId: run.id,
44
+ path: normalizeWorkflowPath(run.path) ?? null,
45
+ },
38
46
  },
39
- ]
47
+ ];
48
+ // Actions creates its suites before their runs; third-party suites with no run are omitted.
49
+ return suite.app?.slug === ACTIONS_APP_SLUG
50
+ ? [{ status, conclusion, app: { slug: suite.app.slug } }]
40
51
  : [];
41
52
  }),
42
53
  ...(opts.includeReceiptSummary && { receiptSummary }),
@@ -16,8 +16,8 @@ export declare function readRestSnapshot(pull: RestPull, repo: RepoInfo, context
16
16
  };
17
17
  checks: {
18
18
  nodes: import("./batch-raw-types.mts").RawContextNode[];
19
- suites: import("./rest-check-read.mts").RestSuite[];
20
- workflowRuns: import("./rest-check-read.mts").RestWorkflowRun[];
19
+ suites: import("./rest-suite-types.mts").RestSuite[];
20
+ workflowRuns: import("./rest-suite-types.mts").RestWorkflowRun[];
21
21
  rateLimit: import("./http-utils.mts").RateLimitInfo | undefined;
22
22
  };
23
23
  rules: {
@@ -1,3 +1,4 @@
1
+ import { normalizeWorkflowPath } from "../checks/workflow-path.mjs";
1
2
  import { restPullRefs } from "./rest-pr-core.mjs";
2
3
  import { readRestFeedback, restReviewToReview } from "./rest-feedback-read.mjs";
3
4
  import { readRestCommitChecks } from "./rest-check-read.mjs";
@@ -75,6 +76,7 @@ export async function readRestSnapshot(pull, repo, context, knownViewerLogin) {
75
76
  const run = checks.workflowRuns.find((run) => run.check_suite_id === suite.id);
76
77
  if (suite.conclusion?.toUpperCase() !== "STARTUP_FAILURE" || !run)
77
78
  return [];
79
+ const workflowPath = normalizeWorkflowPath(run.path);
78
80
  return [
79
81
  {
80
82
  name: run.name || `workflow run ${run.id}`,
@@ -84,6 +86,7 @@ export async function readRestSnapshot(pull, repo, context, knownViewerLogin) {
84
86
  detailsUrl: run.html_url,
85
87
  event: run.event,
86
88
  runId: String(run.id),
89
+ ...(workflowPath !== undefined && { workflowPath }),
87
90
  },
88
91
  ];
89
92
  })),