pr-shepherd 2.0.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 (194) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +41 -32
  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/classify/standard/dependency-review-no-issues.d.mts +4 -0
  17. package/bin/classify/standard/dependency-review-no-issues.mjs +16 -0
  18. package/bin/classify/standard/index.mjs +8 -0
  19. package/bin/classify/standard/snyk-no-issues.d.mts +7 -0
  20. package/bin/classify/standard/snyk-no-issues.mjs +27 -0
  21. package/bin/classify/standard/socket-reports.d.mts +4 -0
  22. package/bin/classify/standard/socket-reports.mjs +18 -0
  23. package/bin/classify/standard/sonarqube-gate-passed.d.mts +7 -0
  24. package/bin/classify/standard/sonarqube-gate-passed.mjs +41 -0
  25. package/bin/cli/arg-flags.mjs +3 -0
  26. package/bin/cli/clean-handler.mjs +1 -1
  27. package/bin/cli/default-poll.mjs +1 -0
  28. package/bin/cli/handlers.mjs +2 -0
  29. package/bin/cli/help-command-pages.d.mts +5 -4
  30. package/bin/cli/help-command-pages.mjs +2 -1
  31. package/bin/cli/help-iterate-poll-pages.d.mts +3 -3
  32. package/bin/cli/help-iterate-poll-pages.mjs +10 -2
  33. package/bin/cli/help-top-page.d.mts +1 -1
  34. package/bin/cli/help-top-page.mjs +2 -2
  35. package/bin/cli/help.d.mts +6 -5
  36. package/bin/cli/in-progress-run-format.d.mts +3 -0
  37. package/bin/cli/in-progress-run-format.mjs +14 -0
  38. package/bin/cli/iterate-activity-formatter.d.mts +2 -0
  39. package/bin/cli/iterate-activity-formatter.mjs +11 -0
  40. package/bin/cli/iterate-flags.d.mts +3 -0
  41. package/bin/cli/iterate-flags.mjs +18 -1
  42. package/bin/cli/iterate-formatter.mjs +2 -1
  43. package/bin/cli/iterate-lean.mjs +2 -0
  44. package/bin/cli/pending-deployments-format.d.mts +5 -0
  45. package/bin/cli/pending-deployments-format.mjs +19 -0
  46. package/bin/cli/poll-handler.d.mts +1 -1
  47. package/bin/cli/poll-handler.mjs +33 -10
  48. package/bin/cli/poll-targets.mjs +2 -0
  49. package/bin/cli/stack-merge-args.d.mts +10 -0
  50. package/bin/cli/stack-merge-args.mjs +27 -0
  51. package/bin/cli/stack-overview.d.mts +1 -0
  52. package/bin/cli/stack-overview.mjs +5 -1
  53. package/bin/cli/stalled-check-format.d.mts +3 -0
  54. package/bin/cli/stalled-check-format.mjs +23 -0
  55. package/bin/cli/suggestion-renderer.mjs +6 -0
  56. package/bin/cli/triage-formatter.mjs +14 -0
  57. package/bin/commands/check.mjs +7 -2
  58. package/bin/commands/clean.d.mts +1 -1
  59. package/bin/commands/clean.mjs +7 -0
  60. package/bin/commands/iterate/check-follow-up.d.mts +9 -0
  61. package/bin/commands/iterate/check-follow-up.mjs +34 -0
  62. package/bin/commands/iterate/ci-start-stall.d.mts +23 -0
  63. package/bin/commands/iterate/ci-start-stall.mjs +33 -0
  64. package/bin/commands/iterate/duration-approx.d.mts +2 -0
  65. package/bin/commands/iterate/duration-approx.mjs +8 -0
  66. package/bin/commands/iterate/escalate.d.mts +8 -17
  67. package/bin/commands/iterate/escalate.mjs +19 -48
  68. package/bin/commands/iterate/helpers.mjs +1 -0
  69. package/bin/commands/iterate/in-progress-runs.d.mts +10 -0
  70. package/bin/commands/iterate/in-progress-runs.mjs +120 -0
  71. package/bin/commands/iterate/index.mjs +12 -6
  72. package/bin/commands/iterate/merge-plan.d.mts +2 -0
  73. package/bin/commands/iterate/merge-plan.mjs +2 -1
  74. package/bin/commands/iterate/merge-state.d.mts +2 -0
  75. package/bin/commands/iterate/merge-state.mjs +8 -21
  76. package/bin/commands/iterate/native-stack-rebase.d.mts +3 -2
  77. package/bin/commands/iterate/native-stack-rebase.mjs +32 -11
  78. package/bin/commands/iterate/queue-removal.d.mts +19 -0
  79. package/bin/commands/iterate/queue-removal.mjs +64 -0
  80. package/bin/commands/iterate/render.d.mts +2 -1
  81. package/bin/commands/iterate/render.mjs +4 -1
  82. package/bin/commands/iterate/stack-boundary.d.mts +17 -0
  83. package/bin/commands/iterate/stack-boundary.mjs +95 -0
  84. package/bin/commands/iterate/stall-repair.d.mts +17 -0
  85. package/bin/commands/iterate/stall-repair.mjs +25 -0
  86. package/bin/commands/iterate/stall.d.mts +1 -1
  87. package/bin/commands/iterate/stall.mjs +27 -18
  88. package/bin/commands/iterate/state-unavailable.d.mts +8 -0
  89. package/bin/commands/iterate/state-unavailable.mjs +23 -0
  90. package/bin/commands/iterate/triage-loop-instruction.mjs +1 -1
  91. package/bin/commands/iterate/triage.mjs +41 -74
  92. package/bin/commands/iterate/unreported-required.d.mts +5 -2
  93. package/bin/commands/iterate/unreported-required.mjs +13 -8
  94. package/bin/commands/iterate/workflow-files.d.mts +27 -0
  95. package/bin/commands/iterate/workflow-files.mjs +85 -0
  96. package/bin/commands/poll-summary-explicit-instructions.mjs +15 -1
  97. package/bin/commands/poll-summary-instructions.d.mts +4 -3
  98. package/bin/commands/poll-summary-instructions.mjs +60 -22
  99. package/bin/commands/poll-summary.mjs +38 -10
  100. package/bin/commands/poll.mjs +4 -2
  101. package/bin/commands/stack-drain.d.mts +4 -4
  102. package/bin/commands/stack-drain.mjs +19 -113
  103. package/bin/commands/stack-handoffs.d.mts +3 -3
  104. package/bin/commands/stack-handoffs.mjs +8 -8
  105. package/bin/commands/stack-lower-ready-note.d.mts +6 -0
  106. package/bin/commands/stack-lower-ready-note.mjs +35 -0
  107. package/bin/commands/stack-merge-escalations.d.mts +17 -0
  108. package/bin/commands/stack-merge-escalations.mjs +57 -0
  109. package/bin/commands/stack-merge-plan.d.mts +10 -0
  110. package/bin/commands/stack-merge-plan.mjs +132 -0
  111. package/bin/commands/stack-merge-scope.d.mts +42 -0
  112. package/bin/commands/stack-merge-scope.mjs +113 -0
  113. package/bin/commands/stack-ownership.d.mts +25 -0
  114. package/bin/commands/stack-ownership.mjs +85 -0
  115. package/bin/commands/stack-stall.d.mts +2 -0
  116. package/bin/commands/stack-stall.mjs +25 -3
  117. package/bin/commands/stack-targets-error.d.mts +16 -0
  118. package/bin/commands/stack-targets-error.mjs +44 -0
  119. package/bin/commands/stack-targets.d.mts +30 -0
  120. package/bin/commands/stack-targets.mjs +121 -0
  121. package/bin/commands/stack-work.d.mts +4 -3
  122. package/bin/commands/stack-work.mjs +7 -4
  123. package/bin/commands/tick.mjs +14 -2
  124. package/bin/config/renames.mjs +1 -1
  125. package/bin/config/schema.d.mts +4 -0
  126. package/bin/config/schema.mjs +2 -0
  127. package/bin/github/batch-parse-suites.d.mts +4 -1
  128. package/bin/github/batch-parse-suites.mjs +15 -3
  129. package/bin/github/batch-raw-types.d.mts +6 -0
  130. package/bin/github/gql/commit-check-suites.gql +6 -0
  131. package/bin/github/gql/poll-summary-fragment.gql +6 -0
  132. package/bin/github/poll-summary-command.d.mts +15 -1
  133. package/bin/github/poll-summary-command.mjs +39 -3
  134. package/bin/github/poll-summary-projector.d.mts +1 -1
  135. package/bin/github/poll-summary-projector.mjs +1 -4
  136. package/bin/github/poll-summary-raw.d.mts +6 -0
  137. package/bin/github/poll-summary-route.mjs +4 -1
  138. package/bin/github/poll-summary.mjs +10 -3
  139. package/bin/github/rest-batch-read.mjs +17 -6
  140. package/bin/github/rest-batch-snapshot.d.mts +2 -2
  141. package/bin/github/rest-batch-snapshot.mjs +3 -0
  142. package/bin/github/rest-check-read.d.mts +1 -18
  143. package/bin/github/rest-check-read.mjs +1 -2
  144. package/bin/github/rest-stack-read.d.mts +9 -0
  145. package/bin/github/rest-stack-read.mjs +40 -0
  146. package/bin/github/rest-suite-types.d.mts +23 -0
  147. package/bin/github/rest-suite-types.mjs +1 -0
  148. package/bin/github/rest-summary-read.mjs +2 -0
  149. package/bin/mcp/server.mjs +29 -3
  150. package/bin/pr-reference.d.mts +2 -0
  151. package/bin/pr-reference.mjs +1 -1
  152. package/bin/reporters/agent.mjs +3 -0
  153. package/bin/state/check-follow-up.d.mts +30 -0
  154. package/bin/state/check-follow-up.mjs +51 -0
  155. package/bin/state/ci-start-follow-up.d.mts +14 -0
  156. package/bin/state/ci-start-follow-up.mjs +21 -0
  157. package/bin/state/queue-removal-follow-up.d.mts +20 -0
  158. package/bin/state/queue-removal-follow-up.mjs +23 -0
  159. package/bin/state/signature-marker.d.mts +10 -0
  160. package/bin/state/signature-marker.mjs +28 -0
  161. package/bin/state/stack-merge-approval.d.mts +26 -0
  162. package/bin/state/stack-merge-approval.mjs +39 -0
  163. package/bin/state/stall-repair.d.mts +16 -0
  164. package/bin/state/stall-repair.mjs +47 -0
  165. package/bin/types/activity.d.mts +2 -1
  166. package/bin/types/escalate.d.mts +9 -2
  167. package/bin/types/github.d.mts +18 -0
  168. package/bin/types/in-progress-run.d.mts +20 -0
  169. package/bin/types/in-progress-run.mjs +1 -0
  170. package/bin/types/iterate.d.mts +22 -1
  171. package/bin/types/poll-summary.d.mts +18 -1
  172. package/bin/types/report.d.mts +5 -1
  173. package/bin/types.d.mts +1 -0
  174. package/bin/types.mjs +1 -0
  175. package/package.json +2 -2
  176. package/plugins/pr-shepherd/.claude-plugin/plugin.json +1 -1
  177. package/plugins/pr-shepherd/.codex-plugin/plugin.json +1 -1
  178. package/plugins/pr-shepherd/.codex.mcp.json +1 -1
  179. package/plugins/pr-shepherd/.mcp.json +1 -1
  180. package/plugins/pr-shepherd/hooks/poll-guard-args.mjs +49 -0
  181. package/plugins/pr-shepherd/hooks/poll-guard-detect.mjs +134 -26
  182. package/plugins/pr-shepherd/hooks/poll-guard-shell.mjs +192 -0
  183. package/plugins/pr-shepherd/package-lock.json +7 -7
  184. package/plugins/pr-shepherd/package.json +1 -1
  185. package/plugins/pr-shepherd/skills/pr-shepherd/SKILL.md +8 -7
  186. package/plugins/pr-shepherd/skills/pr-shepherd/references/check-follow-up.md +14 -0
  187. package/plugins/pr-shepherd/skills/pr-shepherd/references/ci-failure-triage.md +6 -5
  188. package/plugins/pr-shepherd/skills/pr-shepherd/references/ci-start-stall.md +15 -0
  189. package/plugins/pr-shepherd/skills/pr-shepherd/references/create-a-pr.md +4 -1
  190. package/plugins/pr-shepherd/skills/pr-shepherd/references/mcp-fallback.md +1 -1
  191. package/plugins/pr-shepherd/skills/pr-shepherd/references/merge-queue-ejection.md +6 -5
  192. package/plugins/pr-shepherd/skills/pr-shepherd/references/required-checks-unreported.md +16 -0
  193. package/plugins/pr-shepherd/skills/reduce-pr-noise/references/classifiers.md +1 -1
  194. package/pr-shepherd.schema.json +15 -0
@@ -0,0 +1,47 @@
1
+ /**
2
+ * One repair tick for a stall timer that could not be saved.
3
+ *
4
+ * The per-PR state directory is what failed, so this marker lives beside it in the OS temp
5
+ * directory instead: `<tmpdir>/pr-shepherd-stall-repair-<sha256(state base | scope)>.json`.
6
+ * It records that Shepherd already told the caller to repair the state directory for this
7
+ * reason. The next tick with the same reason escalates `stall-state-unavailable`. A marker
8
+ * older than an hour is ignored, so an old failure does not escalate a new one at once.
9
+ * When even the temp directory is unusable the marker cannot bound the repair tick, so the failure escalates at once.
10
+ */
11
+ import { createHash } from "node:crypto";
12
+ import { readFile, writeFile } from "node:fs/promises";
13
+ import { tmpdir } from "node:os";
14
+ import { join } from "node:path";
15
+ import { resolveStateBase } from "./base.mjs";
16
+ const MAX_AGE_SECONDS = 3600;
17
+ /** The state store names its temporary file with a fresh UUID; it is not part of the failure's identity. */
18
+ function stableReason(reason) {
19
+ return reason.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, "<id>");
20
+ }
21
+ /** `scope` names the timer: `owner/repo#pr` or `owner/repo stack N`. */
22
+ export function stallRepairMarkerPath(scope) {
23
+ const hash = createHash("sha256").update(`${resolveStateBase()}|${scope}`).digest("hex");
24
+ return join(tmpdir(), `pr-shepherd-stall-repair-${hash}.json`);
25
+ }
26
+ /** True when the repair tick for this reason was already presented within the last hour. */
27
+ export async function readStallRepair(scope, reason) {
28
+ try {
29
+ const parsed = JSON.parse(await readFile(stallRepairMarkerPath(scope), "utf8"));
30
+ return (parsed.reason === stableReason(reason) &&
31
+ typeof parsed.at === "number" &&
32
+ Date.now() / 1000 - parsed.at < MAX_AGE_SECONDS);
33
+ }
34
+ catch {
35
+ return false;
36
+ }
37
+ }
38
+ /** False when the marker could not be saved: the repair tick would then repeat, so escalate. */
39
+ export async function writeStallRepair(scope, reason) {
40
+ try {
41
+ await writeFile(stallRepairMarkerPath(scope), JSON.stringify({ reason: stableReason(reason), at: Math.floor(Date.now() / 1000) }));
42
+ return true;
43
+ }
44
+ catch {
45
+ return false;
46
+ }
47
+ }
@@ -1,4 +1,4 @@
1
- import type { AuthorType, CheckStatus, CommentAuthorAssociation } from "./github.mts";
1
+ import type { AuthorType, CheckStatus, CommentAuthorAssociation, PendingDeployment } from "./github.mts";
2
2
  type ReviewActivityKind = "pr-comment" | "review-thread-comment" | "review-summary" | "approved-review" | "changes-requested-review";
3
3
  export interface ReviewActivityItem {
4
4
  kind: ReviewActivityKind;
@@ -26,6 +26,7 @@ export interface ActiveCheck {
26
26
  detailsUrl: string | null;
27
27
  workflowName?: string;
28
28
  summary?: string;
29
+ pendingDeployments?: PendingDeployment[];
29
30
  scope?: "merge_group";
30
31
  commitOid?: string;
31
32
  }
@@ -1,8 +1,14 @@
1
1
  import type { AgentCheck, AgentComment, AgentThread } from "./report.mts";
2
2
  import type { ResolveCommand } from "./iterate.mts";
3
- import type { CheckStatus, Review } from "./github.mts";
3
+ import type { CheckStatus, PendingDeployment, Review } from "./github.mts";
4
4
  import type { MergeQueueRemovalStatus } from "./merge-requirements.mts";
5
- export type EscalateTrigger = "transport-unsupported" | "triage-thrash" | "base-branch-unknown" | "stall-timeout" | "required-checks-unreported" | "stall-state-unavailable" | "check-follow-up-unavailable" | "authorization-required" | "merge-queue-removed" | "merge-method-unavailable";
5
+ export type EscalateTrigger = "transport-unsupported" | "triage-thrash" | "stall-timeout" | "required-checks-unreported" | "stall-state-unavailable" | "check-follow-up-unavailable" | "authorization-required" | "merge-queue-removed" | "merge-method-unavailable" | "unowned-stack-layers" | "unapproved-stack-layer" | "merge-through-target-closed" | "listed-pr-left-stack";
6
+ /**
7
+ * Reasons an aggregate `stack`/PR-set row reports `escalate`. They ride on the row's `reasons`,
8
+ * not on an iterate result's `escalate.triggers`, so they are not `EscalateTrigger` members.
9
+ * Row hand-offs that are triggers (`transport-unsupported`) are listed there.
10
+ */
11
+ export type StackHandoffReason = "closed-unmerged-dependency" | "closed-unmerged-layer" | "mark-ready-authorization-required";
6
12
  export interface AgentStalledCheck {
7
13
  name: string;
8
14
  status: CheckStatus;
@@ -14,6 +20,7 @@ export interface AgentStalledCheck {
14
20
  updatedAtUnix?: number;
15
21
  ageSeconds: number;
16
22
  summary?: string;
23
+ pendingDeployments?: PendingDeployment[];
17
24
  }
18
25
  export interface EscalateDetails {
19
26
  triggers: EscalateTrigger[];
@@ -39,6 +39,20 @@ export interface ViewerAuthorization {
39
39
  }
40
40
  /** Raw relationship between a comment author and the repository, as reported by GitHub. */
41
41
  export type CommentAuthorAssociation = "COLLABORATOR" | "CONTRIBUTOR" | "FIRST_TIMER" | "FIRST_TIME_CONTRIBUTOR" | "MANNEQUIN" | "MEMBER" | "NONE" | "OWNER";
42
+ /** One environment an Actions run is held on, as GitHub's `pending_deployments` endpoint reports it. */
43
+ export interface PendingDeployment {
44
+ /** Environment name (e.g. `"production"`). */
45
+ environment: string;
46
+ /** Raw `current_user_can_approve`: whether the authenticated viewer may approve this deployment. */
47
+ currentUserCanApprove: boolean;
48
+ /** Required reviewers: a user's login or a team's slug. Omitted when GitHub lists none. */
49
+ reviewers?: Array<{
50
+ type: "User" | "Team";
51
+ name: string;
52
+ }>;
53
+ /** Configured wait timer in minutes. Omitted when zero. */
54
+ waitTimerMinutes?: number;
55
+ }
42
56
  export interface CheckRun {
43
57
  /** GitHub node ID for CheckRun contexts. Missing for StatusContext and synthetic checks. */
44
58
  id?: string | null;
@@ -61,6 +75,8 @@ export interface CheckRun {
61
75
  updatedAtUnix?: number;
62
76
  /** One-line status text shown in the GitHub UI (CheckRun.title or first line of summary; StatusContext.description). */
63
77
  summary?: string;
78
+ /** Workflow file of a `startup_failure` check, e.g. `.github/workflows/ci.yml`. */
79
+ workflowPath?: string;
64
80
  /** Workflow display name for GitHub Actions check runs, when GraphQL exposes it. */
65
81
  workflowName?: string;
66
82
  /**
@@ -69,6 +85,8 @@ export interface CheckRun {
69
85
  * suite with a run that is not `COMPLETED` is a stuck check.
70
86
  */
71
87
  suiteStatus?: string;
88
+ /** Environment approvals the run is waiting on. Present only when GitHub lists at least one. */
89
+ pendingDeployments?: PendingDeployment[];
72
90
  workflowId?: string;
73
91
  /** True when GraphQL reported at least one CheckRun annotation. Omitted when false. */
74
92
  hasAnnotations?: boolean;
@@ -0,0 +1,20 @@
1
+ /** One in-progress Actions run on the head, as `triage.inProgressRuns[]` reports it. */
2
+ export interface InProgressRun {
3
+ runId: string;
4
+ workflowName: string;
5
+ /** Raw check status of the run: `WAITING` when any of its checks waits, else the first check's. */
6
+ status: string;
7
+ /**
8
+ * The workflow's top-level `concurrency.cancel-in-progress`, raw: `cancel-in-progress=true`,
9
+ * `cancel-in-progress=${{ ... }}`, `cancel-in-progress=unset`, `none`, or `unreadable (<why>)`.
10
+ */
11
+ concurrency: string;
12
+ /** Failed sibling checks of the same run. Present only with `running`. */
13
+ failed?: string[];
14
+ /** Still-running sibling checks of the same run. Present only with `failed`. */
15
+ running?: string[];
16
+ /** The `checks.never-cancel` pattern that protects this run. */
17
+ neverCancel?: string;
18
+ /** `gh run cancel` for this run. Present only when Shepherd recommends cancelling it. */
19
+ cancelCommand?: string;
20
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -2,7 +2,7 @@ import type { AgentThread, AgentComment, AgentCheck, GlobalOptions, RelevantChec
2
2
  import type { ActiveCheck, PrActivitySummary } from "./activity.mts";
3
3
  import type { BranchProtection, MergeStateStatus, MergedBasePullRequest, ConflictCandidateFiles, Review, ReviewDecision, ReviewThread, ShepherdMergeStatus } from "./github.mts";
4
4
  import type { MergeRequirements } from "./merge-requirements.mts";
5
- import type { EscalateDetails } from "./escalate.mts";
5
+ import type { AgentStalledCheck, EscalateDetails } from "./escalate.mts";
6
6
  import type { MergeCommandPlan } from "./merge-action.mts";
7
7
  import type { ApiUsage, GraphqlQuotaWarning } from "./api-usage.mts";
8
8
  import type { NextCheck } from "./next-check.mts";
@@ -129,6 +129,10 @@ interface TriageDetails {
129
129
  /** APPROVED-state reviews surfaced for visibility (when `iterate.minimize-approvals` is false). */
130
130
  surfacedApprovals: Review[];
131
131
  checks: AgentCheck[];
132
+ /** In-progress Actions runs on the head with their raw `concurrency` and a cancel command where one applies. Omitted when empty. */
133
+ inProgressRuns?: import("./in-progress-run.mts").InProgressRun[];
134
+ /** Checks still unstarted after the CI-start stall timeout, on the one investigation tick. Omitted otherwise. */
135
+ stalledChecks?: AgentStalledCheck[];
132
136
  changesRequestedReviews: Review[];
133
137
  /** Pre-built apply command. Run after committing and pushing. */
134
138
  resolveCommand: ResolveCommand;
@@ -172,7 +176,24 @@ interface IterateResultEscalate extends IterateResultBase {
172
176
  escalate: EscalateDetails;
173
177
  }
174
178
  export type IterateResult = IterateResultWait | IterateResultReady | IterateResultCancel | IterateResultTriage | IterateResultMarkReady | IterateResultMerge | IterateResultEscalate;
179
+ /**
180
+ * One open layer of a native stack as an aggregate `stack` tick saw it, handed to the layer's
181
+ * one-PR session so that session knows which layers the caller owns.
182
+ */
183
+ export interface StackLayerOwnership {
184
+ pr: number;
185
+ position: number;
186
+ owned: boolean;
187
+ /** The layer's head branch. */
188
+ branch: string;
189
+ }
175
190
  export interface IterateCommandOptions extends GlobalOptions {
191
+ /**
192
+ * Every open layer of this PR's native stack, set by a `stack` tick that does not own all of
193
+ * them. The session then never prints a whole-stack rebase or push. Omitted when the caller
194
+ * owns the whole stack.
195
+ */
196
+ stackLayers?: StackLayerOwnership[];
176
197
  readyDelaySeconds?: number;
177
198
  noAutoMarkReady?: boolean;
178
199
  stallTimeoutSeconds?: number;
@@ -67,7 +67,7 @@ export interface PollSummaryItem {
67
67
  url: string;
68
68
  /** GitHub author login, when the summary query returned one. */
69
69
  authorLogin?: string;
70
- /** Author login matches the authenticated viewer. */
70
+ /** Stack rows: the caller declared this layer theirs (every layer when the whole stack is). */
71
71
  owned?: true;
72
72
  /** Conservative routing hint; the selected one-PR poll makes the authoritative decision. */
73
73
  action: ShepherdAction;
@@ -113,6 +113,17 @@ export type PollSummarySelection = {
113
113
  anchor: number;
114
114
  stackNumber: number;
115
115
  stackSize: number;
116
+ /** Set only when the caller listed some PRs: the layers the caller owns. Omitted = the whole stack. */
117
+ owned?: number[];
118
+ };
119
+ /** Which owned layers `stack` may merge: all of them, the ready prefix, or up to one PR. */
120
+ export type StackMergeScope = {
121
+ kind: "all";
122
+ } | {
123
+ kind: "ready";
124
+ } | {
125
+ kind: "through";
126
+ pr: number;
116
127
  };
117
128
  /** Aggregate-only transition; one-PR actions remain unchanged. */
118
129
  export type StackNextAction = "shepherd" | "wait" | "merge" | "cancel" | "escalate";
@@ -131,6 +142,8 @@ export interface PollSummaryResult {
131
142
  stackAncestry?: PollSummaryStackAncestry[];
132
143
  /** Immediate stack transition; human blockers surface in rows while shepherdable work remains. */
133
144
  nextAction?: StackNextAction;
145
+ /** Open in-scope layers that appeared after the merge was requested (whole-stack ownership only). */
146
+ addedLayers?: number[];
134
147
  /** Whether every open layer is independently ready and stack ancestry is linear. */
135
148
  stackMergeable?: boolean;
136
149
  /**
@@ -148,6 +161,10 @@ export interface PollSummaryCommandOptions {
148
161
  transport?: import("../github/transport.mts").GithubTransport;
149
162
  prNumbers?: number[];
150
163
  stackPrNumber?: number;
164
+ /** `stack` only: PRs the caller owns. Omitted when the caller owns every layer. */
165
+ stackOwned?: number[];
166
+ /** `stack` only: which owned layers a merge may land. Set together with `merge`. */
167
+ stackMerge?: StackMergeScope;
151
168
  targetRepository?: {
152
169
  owner: string;
153
170
  name: string;
@@ -1,4 +1,4 @@
1
- import type { AuthorType, ReviewThread, PrComment, Review, MergeStatusResult, ViewerAuthorization, CheckConclusion, CheckStatus, SuggestionBlock } from "./github.mts";
1
+ import type { AuthorType, ReviewThread, PrComment, Review, MergeStatusResult, ViewerAuthorization, CheckConclusion, CheckStatus, SuggestionBlock, PendingDeployment } from "./github.mts";
2
2
  import type { ClassifiedCheck, RelatedFailedJob, TriagedCheck } from "./check-classification.mts";
3
3
  import type { AgentThreadComment } from "./agent-thread.mts";
4
4
  import type { CheckAnnotation } from "./check-annotations.mts";
@@ -198,6 +198,8 @@ export interface AgentCheck {
198
198
  status?: CheckStatus;
199
199
  /** Raw check-suite status (`COMPLETED`), present only with `status` for a stuck check. */
200
200
  suiteStatus?: string;
201
+ /** Workflow file of a `STARTUP_FAILURE` run (e.g. `.github/workflows/ci.yml`). */
202
+ workflowPath?: string;
201
203
  /** Workflow display name (e.g. `"CI"`). Populated on a best-effort basis when available from the jobs API. */
202
204
  workflowName?: string;
203
205
  /** Name of the matched job (e.g. `"tests (ubuntu)"`). Distinct from check name for matrix builds. */
@@ -209,6 +211,8 @@ export interface AgentCheck {
209
211
  logExcerpt?: string;
210
212
  /** Other failed jobs from the same workflow run (not their own check entries), with log tails. */
211
213
  relatedJobs?: RelatedFailedJob[];
214
+ /** Environment approvals the run is held on: environment, required reviewers, viewer capability. */
215
+ pendingDeployments?: PendingDeployment[];
212
216
  /** `gh run rerun` command, present only when the check has a runId and the viewer's repository role grants Actions rerun capability (WRITE+). */
213
217
  rerunCommand?: string;
214
218
  /** Workflow-run attempt number, surfaced only after the initial attempt. */
package/bin/types.d.mts CHANGED
@@ -12,6 +12,7 @@ export * from "./types/merge-requirements.mts";
12
12
  export * from "./types/merge-action.mts";
13
13
  export * from "./types/escalate.mts";
14
14
  export * from "./types/merge-queue.mts";
15
+ export * from "./types/in-progress-run.mts";
15
16
  export * from "./types/api-usage.mts";
16
17
  export * from "./types/poll-summary.mts";
17
18
  export * from "./types/next-check.mts";
package/bin/types.mjs CHANGED
@@ -12,6 +12,7 @@ export * from "./types/merge-requirements.mjs";
12
12
  export * from "./types/merge-action.mjs";
13
13
  export * from "./types/escalate.mjs";
14
14
  export * from "./types/merge-queue.mjs";
15
+ export * from "./types/in-progress-run.mjs";
15
16
  export * from "./types/api-usage.mjs";
16
17
  export * from "./types/poll-summary.mjs";
17
18
  export * from "./types/next-check.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for agentic coding tools",
5
5
  "keywords": [
6
6
  "automation",
@@ -91,7 +91,7 @@
91
91
  "husky": "^9.1.7",
92
92
  "knip": "^6.14.1",
93
93
  "marked": "^18.0.11",
94
- "oxfmt": "^0.75.0",
94
+ "oxfmt": "^0.77.0",
95
95
  "oxlint": "^1.60.0",
96
96
  "typescript": "^7.0.2",
97
97
  "vitest": "^5.0.0"
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
3
  "description": "Autonomous PR CI monitor and review-comment resolver for agentic coding tools",
4
- "version": "2.0.0",
4
+ "version": "2.2.0",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
7
7
  "email": "jonathanrichardong@gmail.com"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for Codex.",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
@@ -2,7 +2,7 @@
2
2
  "mcpServers": {
3
3
  "pr-shepherd": {
4
4
  "command": "npx",
5
- "args": ["--yes", "--package", "pr-shepherd@2.0.0", "pr-shepherd-mcp"]
5
+ "args": ["--yes", "--package", "pr-shepherd@2.2.0", "pr-shepherd-mcp"]
6
6
  }
7
7
  }
8
8
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "pr-shepherd": {
3
3
  "command": "npx",
4
- "args": ["--yes", "--package", "pr-shepherd@2.0.0", "pr-shepherd-mcp"]
4
+ "args": ["--yes", "--package", "pr-shepherd@2.2.0", "pr-shepherd-mcp"]
5
5
  }
6
6
  }
@@ -0,0 +1,49 @@
1
+ // Argument helpers for the poll guard: what a command passes to the program it runs,
2
+ // as opposed to where it sends the output.
3
+
4
+ /**
5
+ * The command's arguments without redirections, so `> "pulls-$i.json"` neither
6
+ * names a PR endpoint nor uses a loop variable.
7
+ */
8
+ export function argText(cmd) {
9
+ const kept = [];
10
+ for (let k = 0; k < cmd.words.length; k++) {
11
+ const raw = cmd.words[k].raw;
12
+ if (/^\d*(?:[<>]|>>|&>)$/.test(raw)) k++;
13
+ else if (!/^\d*(?:[<>]|&>)/.test(raw)) kept.push(raw);
14
+ }
15
+ return kept.join(" ");
16
+ }
17
+
18
+ /**
19
+ * Whether the command's arguments use loop variable `name` as the shell expands
20
+ * it. Single-quoted text, such as a jq program's own `$pr`, is not expanded.
21
+ */
22
+ export function usesLoopVar(cmd, name) {
23
+ const text = expandedText(argText(cmd));
24
+ return new RegExp(`\\$(?:${name}\\b|\\{${name}[}:#%/])`).test(text);
25
+ }
26
+
27
+ /** `text` without its single-quoted spans. An apostrophe inside double quotes is literal. */
28
+ function expandedText(text) {
29
+ let out = "";
30
+ let dq = false;
31
+ for (let i = 0; i < text.length; i++) {
32
+ const c = text[i];
33
+ if (c === "\\") {
34
+ out += text.slice(i, i + 2);
35
+ i++;
36
+ } else if (c === "'" && !dq) {
37
+ const end = text.indexOf("'", i + 1);
38
+ i = end === -1 ? text.length : end;
39
+ } else {
40
+ if (c === '"') dq = !dq;
41
+ out += c;
42
+ }
43
+ }
44
+ return out;
45
+ }
46
+
47
+ /** The arguments of a `curl` command without its output file (`-o F`, `-oF`, `-sSo F`, `--output F`). */
48
+ export const curlArgs = (cmd) =>
49
+ argText(cmd).replace(/(?:^|\s)(?:-[a-zA-Z]*o\s*|--output(?:=|\s+))\S+/g, " ");
@@ -1,22 +1,27 @@
1
- // Detects shell commands that poll GitHub PR or CI state on their own instead of
1
+ // Detects shell commands that wait on GitHub PR state on their own instead of
2
2
  // running one `pr-shepherd … --until-terminal`. Host-independent: the Claude Code
3
3
  // and Codex adapters pass the command text and a script reader.
4
+ //
5
+ // Only waits on a pull request are flagged. A workflow run (`gh run …`) may belong
6
+ // to no PR, such as a `workflow_dispatch` run, so a run wait counts only when a PR
7
+ // command (`gh pr …` or `pr-shepherd`) follows it in the same command.
8
+ // Words inside quotes, comments and heredocs are data, not commands. Anything the
9
+ // scanner cannot classify passes: the guard prefers a miss to a false positive.
4
10
 
5
- // A GitHub read: gh's PR and run reads, `gh api`, curl to the API, or Shepherd.
6
- const GITHUB_READ =
7
- /(?<![\w-])gh\s+(?:pr\s+(?:view|checks|status|list)|run\s+(?:view|list)|api)(?=\s)|api\.github\.com|(?<![\w-])pr-shepherd(?![\w-])/;
11
+ import { argText, curlArgs, usesLoopVar } from "./poll-guard-args.mjs";
12
+ import { leadingQuoted, simpleCommands } from "./poll-guard-shell.mjs";
8
13
 
9
- // Shell keywords and commands that repeat or delay. `(?<![\w-])` keeps flags such
10
- // as `--until-terminal` from matching `until`.
11
- const REPEAT = /(?<![\w./-])(?:while|until|sleep)(?=\s)|(?:^|[;&|(]\s*)watch\s/m;
14
+ const PR_SUBCOMMANDS = new Set(["view", "checks", "status", "list"]);
15
+ const PR_API = /pulls|pullRequest/;
16
+ const SHELLS = new Set(["bash", "sh", "zsh"]);
17
+ // A sleep this long right before a single PR read is a wait, not a settle.
18
+ const MIN_WAIT_SECONDS = 60;
12
19
 
13
- // Watchers that block until CI finishes.
14
- const BUILTIN_WATCHER =
15
- /(?<![\w-])gh\s+run\s+watch(?![\w-])|(?<![\w-])gh\s+pr\s+checks\b[^\n;&|]*\s(?:--watch|-w)(?![\w-])/;
16
-
17
- // `bash path`, `sh path`, `zsh path`, or a path ending in `.sh` in command position.
18
- const SCRIPT_RUN =
19
- /(?:^|[;&|(]\s*|\s)(?:bash|sh|zsh)\s+(?:-\w+\s+)*([^\s;&|<>()]+)|(?:^|[;&|(]\s*)((?:[^\s;&|<>()]+\/)?[^\s;&|<>()/]+\.sh)(?=\s|$|[;&|)])/gm;
20
+ const WATCHER =
21
+ "a blocking CI watcher (`gh pr checks --watch`, or `gh run watch` beside a PR command)";
22
+ const LOOP =
23
+ "a polling loop around a PR read (`gh pr`, `gh api` or `curl` on pull requests, `pr-shepherd`, or `gh run` beside a PR command, repeated with `sleep` or `watch`)";
24
+ const WAIT = `a wait of ${MIN_WAIT_SECONDS} seconds or more before a PR read`;
20
25
 
21
26
  export const LEVELS = ["disabled", "advisory", "fail"];
22
27
 
@@ -27,31 +32,134 @@ export const LEVELS = ["disabled", "advisory", "fail"];
27
32
  */
28
33
  export function detectPoller(command, readScript = () => null) {
29
34
  if (typeof command !== "string" || command.length === 0) return null;
30
- const own = detectInText(command);
35
+ const commands = simpleCommands(command);
36
+ const own = detectIn(commands, true);
31
37
  if (own) return own;
32
- for (const path of scriptPaths(command)) {
38
+ for (const path of scriptPaths(commands)) {
33
39
  const text = readScript(path);
34
40
  if (typeof text !== "string") continue;
35
- const found = detectInText(text);
41
+ const found = detectIn(simpleCommands(text), true);
36
42
  if (found) return `the script \`${path}\` contains ${found}`;
37
43
  }
38
44
  return null;
39
45
  }
40
46
 
41
- function detectInText(text) {
42
- if (BUILTIN_WATCHER.test(text))
43
- return "a blocking CI watcher (`gh run watch` or `gh pr checks --watch`)";
44
- if (GITHUB_READ.test(text) && REPEAT.test(text)) {
45
- return "a polling loop around a GitHub read (`gh pr`/`gh run`/`gh api`/`curl` or `pr-shepherd` with `while`, `until`, `sleep`, or `watch`)";
47
+ function detectIn(commands, nested) {
48
+ const sleeps = [];
49
+ const reads = [];
50
+ const runReads = [];
51
+ let lastPr = -1;
52
+ for (const [index, cmd] of commands.entries()) {
53
+ const words = cmd.words.map((w) => w.word);
54
+ const inner = nested ? quotedCommand(cmd, words) : null;
55
+ if (inner !== null) {
56
+ const innerCommands = simpleCommands(inner);
57
+ const found = detectIn(innerCommands, false);
58
+ if (found) return found;
59
+ // The shell's own loop or `watch` repeats the inner read.
60
+ if (innerCommands.some((c) => isPrRead(c))) {
61
+ if (cmd.watched) return LOOP;
62
+ reads.push({ index, cmd });
63
+ }
64
+ }
65
+ if (words[0] === "sleep") sleeps.push({ index, cmd, seconds: seconds(words.slice(1)) });
66
+ else if (isWatcher(words)) return WATCHER;
67
+ else if (isPrRead(cmd)) {
68
+ if (cmd.watched) return LOOP;
69
+ reads.push({ index, cmd });
70
+ } else if (isRunRead(words)) runReads.push({ index, cmd });
71
+ if (words[0] === "pr-shepherd" || (words[0] === "gh" && words[1] === "pr")) lastPr = index;
72
+ }
73
+ // A workflow run may belong to no PR. A wait on a run followed by Shepherd or a
74
+ // `gh pr` command is a wait on that PR's CI; one after a merge (a publish run) is not.
75
+ const prRuns = runReads.filter((r) => r.index < lastPr);
76
+ if (prRuns.some((r) => r.cmd.words[2].word === "watch")) return WATCHER;
77
+ reads.push(...prRuns);
78
+ for (const read of reads) {
79
+ // A loop polls when it sleeps and re-reads a state that does not depend on its variable.
80
+ const loops = new Set(
81
+ read.cmd.loops.filter((l) => !l.vars.some((v) => usesLoopVar(read.cmd, v))).map((l) => l.id),
82
+ );
83
+ if (sleeps.some((s) => s.cmd.loops.some((l) => loops.has(l.id)))) return LOOP;
84
+ // A long sleep whose very next command is the PR read, outside any loop.
85
+ const waited = sleeps.some(
86
+ (s) =>
87
+ s.index === read.index - 1 && s.cmd.loops.length === 0 && s.seconds >= MIN_WAIT_SECONDS,
88
+ );
89
+ if (waited) return WAIT;
46
90
  }
47
91
  return null;
48
92
  }
49
93
 
50
- function scriptPaths(command) {
94
+ /** `-c`, or combined shell options that include it, such as `-lc` or `-ec`. */
95
+ const isCommandFlag = (word) => /^-[a-z]*c[a-z]*$/i.test(word);
96
+
97
+ const isRunRead = (words) =>
98
+ words[0] === "gh" && words[1] === "run" && ["view", "list", "watch"].includes(words[2]);
99
+
100
+ const isWatcher = (words) =>
101
+ words[0] === "gh" &&
102
+ words[1] === "pr" &&
103
+ words[2] === "checks" &&
104
+ words.some((w) => w === "--watch" || w === "-w");
105
+
106
+ /** The command string run by `bash -c '…'` (or `sh`, `zsh`) or `watch '…'`, or null. */
107
+ function quotedCommand(cmd, words) {
108
+ let at = -1;
109
+ if (cmd.watched) at = cmd.words[0].at;
110
+ else if (SHELLS.has(words[0]) && words.some(isCommandFlag)) {
111
+ at = cmd.words[words.findIndex(isCommandFlag) + 1]?.at ?? -1;
112
+ }
113
+ return at === -1 ? null : leadingQuoted(cmd.text.slice(at - cmd.words[0].at));
114
+ }
115
+
116
+ function isPrRead(cmd) {
117
+ const [first, second, third] = cmd.words.map((w) => w.word);
118
+ if (first === "gh" && second === "pr") return PR_SUBCOMMANDS.has(third);
119
+ if (first === "gh" && second === "api") return PR_API.test(argText(cmd));
120
+ // Quoting does not change an argument's value: `pr-shepherd "42"` is `pr-shepherd 42`.
121
+ if (first === "pr-shepherd") {
122
+ return isShepherdTick(cmd.words.map((w) => w.raw.replace(/^(["'])(.*)\1$/, "$2")));
123
+ }
124
+ const args = curlArgs(cmd);
125
+ return first === "curl" && /api\.github\.com/.test(args) && PR_API.test(args);
126
+ }
127
+
128
+ /**
129
+ * One Shepherd status tick: the default poll, `iterate`, or `stack`, without
130
+ * `--until-terminal`. `apply`, `suggest`, `admin` and other subcommands write or
131
+ * print help, so they are not reads.
132
+ */
133
+ function isShepherdTick(words) {
134
+ if (words.includes("--until-terminal")) return false;
135
+ const target = words[1];
136
+ return (
137
+ target === undefined ||
138
+ target === "iterate" ||
139
+ target === "stack" ||
140
+ /^(?:-|\d|https?:|\$)|[#/]/.test(target)
141
+ );
142
+ }
143
+
144
+ /** Total seconds of `sleep` arguments such as `90`, `2m` or `1h`; NaN unless literal. */
145
+ function seconds(args) {
146
+ const unit = { s: 1, m: 60, h: 3600, d: 86400 };
147
+ return args.reduce((sum, arg) => {
148
+ const m = /^(\d+(?:\.\d+)?)([smhd]?)$/.exec(arg);
149
+ return m ? sum + Number(m[1]) * unit[m[2] || "s"] : Number.NaN;
150
+ }, 0);
151
+ }
152
+
153
+ /** Scripts a command runs: `bash path`, `sh -e path`, or a `.sh` path in command position. */
154
+ function scriptPaths(commands) {
51
155
  const paths = [];
52
- for (const m of command.matchAll(SCRIPT_RUN)) {
53
- const path = m[1] ?? m[2];
54
- if (path && !path.startsWith("-")) paths.push(path);
156
+ for (const { words } of commands) {
157
+ const [first, ...rest] = words;
158
+ if (SHELLS.has(first.word)) {
159
+ if (rest.some((w) => isCommandFlag(w.word))) continue;
160
+ const path = rest.find((w) => !w.word.startsWith("-"));
161
+ if (path) paths.push(path.raw);
162
+ } else if (first.raw.endsWith(".sh")) paths.push(first.raw);
55
163
  }
56
164
  return paths;
57
165
  }