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
@@ -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
  })),
@@ -1,23 +1,6 @@
1
1
  import type { RepoInfo } from "./client.mts";
2
2
  import type { RawContextNode } from "./batch-raw-types.mts";
3
- export interface RestSuite {
4
- id: number;
5
- node_id: string;
6
- status: string;
7
- conclusion: string | null;
8
- created_at: string;
9
- updated_at: string;
10
- }
11
- export interface RestWorkflowRun {
12
- id: number;
13
- check_suite_id: number;
14
- event: string;
15
- workflow_id: number;
16
- name: string;
17
- created_at: string;
18
- updated_at: string;
19
- html_url: string;
20
- }
3
+ import type { RestSuite, RestWorkflowRun } from "./rest-suite-types.mts";
21
4
  export declare function readRestCommitChecks(oid: string, repo: RepoInfo, pr?: number): Promise<{
22
5
  nodes: RawContextNode[];
23
6
  suites: RestSuite[];
@@ -1,6 +1,5 @@
1
- import { readRestPages, restRepoPath, restCollection, restString, restNumber, malformedRest, } from "./rest-reader-core.mjs";
1
+ import { readRestPages, restRepoPath, restCollection, restString, restNumber, malformedRest, readRest as rest, } from "./rest-reader-core.mjs";
2
2
  import { recordRestIdentity } from "./rest-identities.mjs";
3
- import { readRest as rest } from "./rest-reader-core.mjs";
4
3
  export async function readRestCommitChecks(oid, repo, pr = 0) {
5
4
  const prefix = restRepoPath(repo);
6
5
  // Suites first: a COMPLETED suite read before the runs means a run still not COMPLETED is stuck.
@@ -18,4 +18,13 @@ export declare function readRestStackMembership(anchor: number, repo: RepoInfo):
18
18
  * (the stack list, the stack, the anchor's pull, `/user`) and the repeat membership read answer 304.
19
19
  */
20
20
  export declare function readRestStackTopology(anchor: number, repo: RepoInfo): Promise<StackRead<StackMemberRefs>>;
21
+ /** A native stack read by its number, or null when GitHub has no such stack (404). */
22
+ export declare function readRestStackByNumber(stack: number, repo: RepoInfo): Promise<{
23
+ number: number;
24
+ members: number[];
25
+ } | null>;
26
+ /** Whether a number names a pull request; a 404 means it may name a stack instead. */
27
+ export declare function restPullExists(pr: number, repo: RepoInfo): Promise<boolean>;
28
+ /** Whether the repository itself is readable: a 404 or 403 there is an access problem. */
29
+ export declare function restRepoReachable(repo: RepoInfo): Promise<boolean>;
21
30
  export {};
@@ -4,6 +4,7 @@ import { readRestPull, restPullRefs } from "./rest-pr-core.mjs";
4
4
  import { mapPool } from "../util/pool.mjs";
5
5
  import { readRestViewerLogin } from "./rest-viewer-read.mjs";
6
6
  import { currentRestConditionalKey, withRestConditionalScope } from "./rest-conditional-scope.mjs";
7
+ import { GitHubRequestError } from "./errors.mjs";
7
8
  /** The official native-stack endpoint is authoritative; missing API access cannot prove standalone membership. */
8
9
  export async function readRestStackMembership(anchor, repo) {
9
10
  const listed = (await readRestPages(`${restRepoPath(repo)}/stacks?pull_request=${anchor}`)).nodes;
@@ -45,3 +46,42 @@ async function readTopology(anchor, repo) {
45
46
  const viewerLogin = await readRestViewerLogin();
46
47
  return { stackNumber: stack.number, stackSize: ordered.length, ordered, viewerLogin };
47
48
  }
49
+ /** A native stack read by its number, or null when GitHub has no such stack (404). */
50
+ export async function readRestStackByNumber(stack, repo) {
51
+ try {
52
+ const body = restObject(await rest("GET", `${restRepoPath(repo)}/stacks/${stack}`), "stack");
53
+ restArray(body.pull_requests, "stack pull_requests");
54
+ const members = body.pull_requests.map((pull) => restNumber(pull.number, "stack member number"));
55
+ return { number: restNumber(body.number, "stack number"), members };
56
+ }
57
+ catch (error) {
58
+ if (error instanceof GitHubRequestError && error.status === 404)
59
+ return null;
60
+ throw error;
61
+ }
62
+ }
63
+ /** Whether a number names a pull request; a 404 means it may name a stack instead. */
64
+ export async function restPullExists(pr, repo) {
65
+ try {
66
+ await rest("GET", `${restRepoPath(repo)}/pulls/${pr}`);
67
+ return true;
68
+ }
69
+ catch (error) {
70
+ if (error instanceof GitHubRequestError && error.status === 404)
71
+ return false;
72
+ throw error;
73
+ }
74
+ }
75
+ /** Whether the repository itself is readable: a 404 or 403 there is an access problem. */
76
+ export async function restRepoReachable(repo) {
77
+ try {
78
+ await rest("GET", restRepoPath(repo));
79
+ return true;
80
+ }
81
+ catch (error) {
82
+ if (error instanceof GitHubRequestError && (error.status === 404 || error.status === 403)) {
83
+ return false;
84
+ }
85
+ throw error;
86
+ }
87
+ }
@@ -0,0 +1,23 @@
1
+ /** REST check suite and workflow run shapes read for a head commit. */
2
+ export interface RestSuite {
3
+ id: number;
4
+ node_id: string;
5
+ status: string;
6
+ conclusion: string | null;
7
+ created_at: string;
8
+ updated_at: string;
9
+ app?: {
10
+ slug?: string | null;
11
+ } | null;
12
+ }
13
+ export interface RestWorkflowRun {
14
+ id: number;
15
+ check_suite_id: number;
16
+ event: string;
17
+ workflow_id: number;
18
+ name: string;
19
+ created_at: string;
20
+ updated_at: string;
21
+ html_url: string;
22
+ path?: string;
23
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -99,6 +99,7 @@ export function restSummary(data, pull, feedback, checks, baseRef) {
99
99
  nodes: checks.suites.map((suite) => ({
100
100
  status: suite.status.toUpperCase(),
101
101
  conclusion: suite.conclusion?.toUpperCase() ?? null,
102
+ app: { slug: suite.app?.slug ?? null },
102
103
  workflowRun: restSuiteWorkflowRun(checks.workflowRuns.find((run) => run.check_suite_id === suite.id)),
103
104
  })),
104
105
  },
@@ -119,5 +120,6 @@ function restSuiteWorkflowRun(run) {
119
120
  event: run.event,
120
121
  url: run.html_url,
121
122
  workflow: { name: run.name },
123
+ file: { path: run.path ?? null },
122
124
  };
123
125
  }
@@ -37,13 +37,31 @@ const iterateInputSchema = z
37
37
  ...tickOptionsSchema,
38
38
  pr: pr.optional(),
39
39
  prs: z.array(pr).min(1).optional(),
40
+ stackLayers: z
41
+ .array(z.object({
42
+ pr: z.number().int().positive(),
43
+ position: z.number().int().positive(),
44
+ owned: z.boolean(),
45
+ branch: z.string().min(1),
46
+ }))
47
+ .min(1)
48
+ .optional()
49
+ .describe("Set by a partly owned `stack` tick: the stack's open layers and which are owned."),
40
50
  })
41
51
  .refine((input) => (input.pr === undefined) !== (input.prs === undefined), {
42
52
  message: "exactly one of pr or prs is required",
43
53
  })
44
54
  .refine((input) => !input.prs ||
45
55
  new Set(input.prs.map((ref) => normalizeRepositoryIdentity(parsePrReference(ref)?.repository ?? ""))).size === 1, { message: "all prs must belong to the same repository" });
46
- const stackInputSchema = z.object({ ...tickOptionsSchema, pr });
56
+ const stackInputSchema = z.object({
57
+ ...tickOptionsSchema,
58
+ refs: z
59
+ .array(pr)
60
+ .min(1)
61
+ .describe("A stack (owner/repo#N, owns every layer) or the PRs of one stack you own."),
62
+ mergeReady: z.boolean().optional().describe("Merge the ready owned prefix."),
63
+ mergeThrough: pr.optional().describe("Merge up to this PR."),
64
+ });
47
65
  const reviewMutationsOperationSchema = z.object({
48
66
  type: z.literal("review_mutations"),
49
67
  resolveThreadIds: ids,
@@ -150,7 +168,7 @@ export function createPrShepherdMcpServer(options = {}) {
150
168
  : formatIterateResult(result, opts), (result) => isPollSummary(result) ? result : projectIterateLean(result, opts));
151
169
  });
152
170
  server.registerTool("stack", {
153
- description: "Inspect the native stack containing one pull request and return one aggregate Shepherd tick.",
171
+ description: "Inspect one native stack and return one aggregate Shepherd tick.",
154
172
  inputSchema: stackInputSchema,
155
173
  annotations: {
156
174
  readOnlyHint: false,
@@ -158,7 +176,7 @@ export function createPrShepherdMcpServer(options = {}) {
158
176
  idempotentHint: false,
159
177
  openWorldHint: true,
160
178
  },
161
- }, async (input) => runTool(() => getShepherd().stack(requireRepositoryQualifiedPr(input)), formatPollSummaryResult, projectStackOverview));
179
+ }, async (input) => runTool(() => getShepherd().stack(requireStackInput(input)), formatPollSummaryResult, projectStackOverview));
162
180
  server.registerTool("apply", {
163
181
  description: "Apply ordered merge, review, file-view, journal, check-blocker, and queue-removal operations after prevalidation; explicit requests rely on GitHub's mutation response.",
164
182
  inputSchema: applyInputSchema,
@@ -238,6 +256,14 @@ function requireRepositoryQualifiedIterate(input) {
238
256
  function isPollSummary(result) {
239
257
  return "mode" in result && result.mode === "summary";
240
258
  }
259
+ /** The stack tool's `refs` are validated here too, so a direct handler call fails like a schema miss. */
260
+ function requireStackInput(input) {
261
+ const parsed = stackInputSchema.safeParse(input);
262
+ if (!parsed.success) {
263
+ throw new PrShepherdValidationError(parsed.error.issues[0]?.message ?? QUALIFIED_PR_ERROR);
264
+ }
265
+ return parsed.data;
266
+ }
241
267
  function requireRepositoryQualifiedPr(input) {
242
268
  if (!isRepositoryQualifiedPrReference(input.pr)) {
243
269
  throw new PrShepherdValidationError(QUALIFIED_PR_ERROR);
@@ -1,6 +1,8 @@
1
1
  export interface ParsedPrReference {
2
2
  number?: number;
3
3
  repository?: string;
4
+ /** A pull-request URL names a PR for certain; a bare number may name a PR or a stack. */
5
+ url?: true;
4
6
  }
5
7
  export interface ResolvedPrTarget {
6
8
  prNumber?: number;
@@ -22,7 +22,7 @@ export function parsePrReference(pr) {
22
22
  parts.length >= 4 &&
23
23
  parts[2] === "pull" &&
24
24
  /^[1-9][0-9]*$/.test(parts[3])) {
25
- return { number: Number(parts[3]), repository: `${parts[0]}/${parts[1]}` };
25
+ return { number: Number(parts[3]), repository: `${parts[0]}/${parts[1]}`, url: true };
26
26
  }
27
27
  }
28
28
  catch {
@@ -63,11 +63,13 @@ export function toAgentCheck(c) {
63
63
  c.suiteStatus !== undefined && { status: c.status, suiteStatus: c.suiteStatus }),
64
64
  ...(c.runAttempt !== undefined && c.runAttempt > 1 && { runAttempt: c.runAttempt }),
65
65
  ...(c.workflowName !== undefined && { workflowName: c.workflowName }),
66
+ ...(c.workflowPath !== undefined && { workflowPath: c.workflowPath }),
66
67
  ...(c.jobName !== undefined && { jobName: c.jobName }),
67
68
  ...(c.failedStep !== undefined && { failedStep: c.failedStep }),
68
69
  ...(c.summary !== undefined && { summary: c.summary }),
69
70
  ...(c.logExcerpt !== undefined && { logExcerpt: c.logExcerpt }),
70
71
  ...(c.relatedJobs !== undefined && { relatedJobs: c.relatedJobs }),
72
+ ...(c.pendingDeployments !== undefined && { pendingDeployments: c.pendingDeployments }),
71
73
  ...(c.annotations !== undefined && { annotations: c.annotations }),
72
74
  ...(c.scope !== undefined && { scope: c.scope }),
73
75
  ...(c.commitOid !== undefined && { commitOid: c.commitOid }),
@@ -87,6 +89,7 @@ export function toAgentStalledCheck(c, nowSeconds) {
87
89
  ...(c.updatedAtUnix !== undefined && { updatedAtUnix: c.updatedAtUnix }),
88
90
  ageSeconds: Math.max(0, nowSeconds - activityAtUnix),
89
91
  ...(c.summary !== undefined && { summary: c.summary }),
92
+ ...(c.pendingDeployments !== undefined && { pendingDeployments: c.pendingDeployments }),
90
93
  };
91
94
  }
92
95
  /**
@@ -0,0 +1,30 @@
1
+ /**
2
+ * One presented investigation tick for failing checks that have no rerun and no usable evidence.
3
+ *
4
+ * `$PR_SHEPHERD_STATE_DIR/<owner>/<repo>/<pr>/check-follow-up.json`
5
+ * This records that Shepherd returned the investigation instruction for this head and check set,
6
+ * not that the caller ran it. The next presented tick with the same head and checks escalates.
7
+ * Internal debounce preview ticks do not write this marker.
8
+ */
9
+ interface CheckFollowUpMarker {
10
+ headSha: string;
11
+ checks: string[];
12
+ }
13
+ interface StateKey {
14
+ owner: string;
15
+ repo: string;
16
+ pr: number;
17
+ }
18
+ /** Stable identity for a failing check: name, run, and attempt. Sorted so order never matters. */
19
+ export declare function checkFollowUpKeys(checks: ReadonlyArray<{
20
+ name: string;
21
+ runId: string | null;
22
+ runAttempt?: number;
23
+ }>): string[];
24
+ /** The stored head and check set, or undefined when no usable marker exists. */
25
+ export declare function readCheckFollowUp(key: StateKey): Promise<CheckFollowUpMarker | undefined>;
26
+ /** Remember that the one investigation instruction was returned for this head and check set. */
27
+ export declare function writeCheckFollowUp(key: StateKey, record: CheckFollowUpMarker): Promise<void>;
28
+ /** True when the investigation instruction was already returned for this head and check set. */
29
+ export declare function sameCheckFollowUp(record: CheckFollowUpMarker | undefined, headSha: string, checks: readonly string[]): boolean;
30
+ export {};
@@ -0,0 +1,51 @@
1
+ /**
2
+ * One presented investigation tick for failing checks that have no rerun and no usable evidence.
3
+ *
4
+ * `$PR_SHEPHERD_STATE_DIR/<owner>/<repo>/<pr>/check-follow-up.json`
5
+ * This records that Shepherd returned the investigation instruction for this head and check set,
6
+ * not that the caller ran it. The next presented tick with the same head and checks escalates.
7
+ * Internal debounce preview ticks do not write this marker.
8
+ */
9
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
10
+ import { dirname } from "node:path";
11
+ import { resolvePrStatePath } from "./base.mjs";
12
+ /** Stable identity for a failing check: name, run, and attempt. Sorted so order never matters. */
13
+ export function checkFollowUpKeys(checks) {
14
+ return checks.map((c) => `${c.name}#${c.runId ?? ""}#${c.runAttempt ?? ""}`).sort();
15
+ }
16
+ /** The stored head and check set, or undefined when no usable marker exists. */
17
+ export async function readCheckFollowUp(key) {
18
+ try {
19
+ const parsed = JSON.parse(await readFile(resolvePrStatePath(key, "check-follow-up.json"), "utf8"));
20
+ if (parsed === null || typeof parsed !== "object")
21
+ return undefined;
22
+ const { headSha, checks } = parsed;
23
+ if (typeof headSha !== "string" || !Array.isArray(checks))
24
+ return undefined;
25
+ if (!checks.every((name) => typeof name === "string"))
26
+ return undefined;
27
+ return { headSha, checks };
28
+ }
29
+ catch {
30
+ return undefined;
31
+ }
32
+ }
33
+ /** Remember that the one investigation instruction was returned for this head and check set. */
34
+ export async function writeCheckFollowUp(key, record) {
35
+ try {
36
+ const path = resolvePrStatePath(key, "check-follow-up.json");
37
+ await mkdir(dirname(path), { recursive: true });
38
+ await writeFile(path, JSON.stringify({ headSha: record.headSha, checks: [...record.checks].sort() }));
39
+ }
40
+ catch {
41
+ // Best-effort: a missing marker only repeats the one investigation tick.
42
+ }
43
+ }
44
+ /** True when the investigation instruction was already returned for this head and check set. */
45
+ export function sameCheckFollowUp(record, headSha, checks) {
46
+ if (!record || record.headSha !== headSha)
47
+ return false;
48
+ const stored = [...record.checks].sort();
49
+ const current = [...checks].sort();
50
+ return stored.length === current.length && stored.every((key, index) => key === current[index]);
51
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * One presented investigation tick for checks that never started.
3
+ *
4
+ * `$PR_SHEPHERD_STATE_DIR/<owner>/<repo>/<pr>/ci-start-follow-up.json`
5
+ * This records that Shepherd returned the investigation instruction for this head and these
6
+ * unstarted checks, not that the caller ran it. The next presented tick with the same head and
7
+ * checks escalates `stall-timeout`. Internal debounce preview ticks do not write this marker.
8
+ */
9
+ import { type StateKey } from "./signature-marker.mts";
10
+ /** Identity of the stalled set: the head plus the sorted names of the unstarted checks. */
11
+ export declare function ciStartSignature(headSha: string, names: readonly string[]): string;
12
+ export declare function readCiStartFollowUp(key: StateKey, signature: string): Promise<boolean>;
13
+ /** The save error, if any, so the caller escalates instead of repeating the investigation. */
14
+ export declare function writeCiStartFollowUp(key: StateKey, signature: string): Promise<string | undefined>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * One presented investigation tick for checks that never started.
3
+ *
4
+ * `$PR_SHEPHERD_STATE_DIR/<owner>/<repo>/<pr>/ci-start-follow-up.json`
5
+ * This records that Shepherd returned the investigation instruction for this head and these
6
+ * unstarted checks, not that the caller ran it. The next presented tick with the same head and
7
+ * checks escalates `stall-timeout`. Internal debounce preview ticks do not write this marker.
8
+ */
9
+ import { readSignatureMarker, writeSignatureMarker } from "./signature-marker.mjs";
10
+ const FILE = "ci-start-follow-up.json";
11
+ /** Identity of the stalled set: the head plus the sorted names of the unstarted checks. */
12
+ export function ciStartSignature(headSha, names) {
13
+ return JSON.stringify([headSha, ...[...names].sort()]);
14
+ }
15
+ export function readCiStartFollowUp(key, signature) {
16
+ return readSignatureMarker(key, FILE, signature);
17
+ }
18
+ /** The save error, if any, so the caller escalates instead of repeating the investigation. */
19
+ export function writeCiStartFollowUp(key, signature) {
20
+ return writeSignatureMarker(key, FILE, signature);
21
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * One presented triage tick for a merge-queue removal Shepherd has no check failure to triage.
3
+ *
4
+ * `$PR_SHEPHERD_STATE_DIR/<owner>/<repo>/<pr>/queue-removal-follow-up.json`
5
+ * This records that Shepherd returned the investigation instruction for this head and removal,
6
+ * not that the caller ran it. The next presented tick with the same head and removal escalates.
7
+ * Internal debounce preview ticks do not write this marker.
8
+ */
9
+ import { type StateKey } from "./signature-marker.mts";
10
+ /** Identity of one removal on one head: a new head or a newer removal is a new situation. */
11
+ export declare function queueRemovalSignature(input: {
12
+ headSha: string;
13
+ createdAtUnix: number;
14
+ beforeCommitOid?: string;
15
+ }): string;
16
+ /** True when the investigation tick was already returned for exactly this removal. */
17
+ export declare function readQueueRemovalFollowUp(key: StateKey, signature: string): Promise<boolean>;
18
+ /** Remember that the one investigation instruction was returned for this removal. */
19
+ /** The save error, if any. */
20
+ export declare function writeQueueRemovalFollowUp(key: StateKey, signature: string): Promise<string | undefined>;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * One presented triage tick for a merge-queue removal Shepherd has no check failure to triage.
3
+ *
4
+ * `$PR_SHEPHERD_STATE_DIR/<owner>/<repo>/<pr>/queue-removal-follow-up.json`
5
+ * This records that Shepherd returned the investigation instruction for this head and removal,
6
+ * not that the caller ran it. The next presented tick with the same head and removal escalates.
7
+ * Internal debounce preview ticks do not write this marker.
8
+ */
9
+ import { readSignatureMarker, writeSignatureMarker } from "./signature-marker.mjs";
10
+ const FILE = "queue-removal-follow-up.json";
11
+ /** Identity of one removal on one head: a new head or a newer removal is a new situation. */
12
+ export function queueRemovalSignature(input) {
13
+ return `${input.headSha}#${input.createdAtUnix}#${input.beforeCommitOid ?? ""}`;
14
+ }
15
+ /** True when the investigation tick was already returned for exactly this removal. */
16
+ export function readQueueRemovalFollowUp(key, signature) {
17
+ return readSignatureMarker(key, FILE, signature);
18
+ }
19
+ /** Remember that the one investigation instruction was returned for this removal. */
20
+ /** The save error, if any. */
21
+ export function writeQueueRemovalFollowUp(key, signature) {
22
+ return writeSignatureMarker(key, FILE, signature);
23
+ }
@@ -0,0 +1,10 @@
1
+ /** A one-field marker file in the PR state directory: "this exact situation was already presented". */
2
+ export interface StateKey {
3
+ owner: string;
4
+ repo: string;
5
+ pr: number;
6
+ }
7
+ /** True when the marker file holds exactly this signature. */
8
+ export declare function readSignatureMarker(key: StateKey, file: string, signature: string): Promise<boolean>;
9
+ /** `undefined` when the marker was saved; otherwise the filesystem error, naming the file. */
10
+ export declare function writeSignatureMarker(key: StateKey, file: string, signature: string): Promise<string | undefined>;
@@ -0,0 +1,28 @@
1
+ /** A one-field marker file in the PR state directory: "this exact situation was already presented". */
2
+ import { mkdir, readFile, writeFile } from "node:fs/promises";
3
+ import { dirname } from "node:path";
4
+ import { resolvePrStatePath } from "./base.mjs";
5
+ /** True when the marker file holds exactly this signature. */
6
+ export async function readSignatureMarker(key, file, signature) {
7
+ try {
8
+ const parsed = JSON.parse(await readFile(resolvePrStatePath(key, file), "utf8"));
9
+ return (parsed !== null &&
10
+ typeof parsed === "object" &&
11
+ parsed.signature === signature);
12
+ }
13
+ catch {
14
+ return false;
15
+ }
16
+ }
17
+ /** `undefined` when the marker was saved; otherwise the filesystem error, naming the file. */
18
+ export async function writeSignatureMarker(key, file, signature) {
19
+ try {
20
+ const path = resolvePrStatePath(key, file);
21
+ await mkdir(dirname(path), { recursive: true });
22
+ await writeFile(path, JSON.stringify({ signature }));
23
+ return undefined;
24
+ }
25
+ catch (error) {
26
+ return `${file}: ${error.message}`;
27
+ }
28
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The open layers a stack merge request covered when it was first seen. A layer that appears later
3
+ * was never approved. Keyed by repo, native stack number, and merge scope, and bound to the one
4
+ * request that wrote it: the record stores that request's command line and write time, and is
5
+ * ignored once the command line differs (a new explicit request is a fresh approval) or the
6
+ * record is older than {@link APPROVAL_TTL_MS}.
7
+ *
8
+ * State lives in `$PR_SHEPHERD_STATE_DIR/<owner>/<repo>/stack-<number>/merge-approval-<scope>.json`.
9
+ * `admin clean stack <number>` removes it.
10
+ */
11
+ export interface StackMergeApprovalKey {
12
+ owner: string;
13
+ repo: string;
14
+ stack: number;
15
+ /** `all`, `ready`, or `through-<pr>`. */
16
+ scope: string;
17
+ }
18
+ /**
19
+ * The recorded layer numbers, or null when none were recorded for this request: no file, an
20
+ * unusable file, another request's command line, or an expired record.
21
+ */
22
+ export declare function readApprovedLayers(key: StackMergeApprovalKey, command: string, now?: number): Promise<number[] | null>;
23
+ /** Record the layers a merge request covered. A write failure surfaces: it must not fail open. */
24
+ export declare function writeApprovedLayers(key: StackMergeApprovalKey, layers: number[], command: string, now?: number): Promise<void>;
25
+ /** Forget the record once every covered layer has merged, so a later request starts fresh. */
26
+ export declare function clearApprovedLayers(key: StackMergeApprovalKey): Promise<void>;
@@ -0,0 +1,39 @@
1
+ import { mkdir, readFile, unlink, writeFile } from "node:fs/promises";
2
+ import { dirname } from "node:path";
3
+ import { resolveStackStatePath } from "./base.mjs";
4
+ /** How long one request's approval lasts; a request outliving it is approved afresh. */
5
+ const APPROVAL_TTL_MS = 24 * 60 * 60 * 1000;
6
+ function approvalPath(key) {
7
+ return resolveStackStatePath(key, `merge-approval-${key.scope}.json`);
8
+ }
9
+ /**
10
+ * The recorded layer numbers, or null when none were recorded for this request: no file, an
11
+ * unusable file, another request's command line, or an expired record.
12
+ */
13
+ export async function readApprovedLayers(key, command, now = Date.now()) {
14
+ try {
15
+ const parsed = JSON.parse(await readFile(approvalPath(key), "utf8"));
16
+ const { layers, writtenAt } = parsed;
17
+ if (parsed.command !== command || typeof writtenAt !== "number")
18
+ return null;
19
+ const age = now - writtenAt;
20
+ if (!(age >= 0 && age <= APPROVAL_TTL_MS))
21
+ return null;
22
+ return Array.isArray(layers) && layers.every((layer) => Number.isSafeInteger(layer))
23
+ ? layers
24
+ : null;
25
+ }
26
+ catch {
27
+ return null;
28
+ }
29
+ }
30
+ /** Record the layers a merge request covered. A write failure surfaces: it must not fail open. */
31
+ export async function writeApprovedLayers(key, layers, command, now = Date.now()) {
32
+ const path = approvalPath(key);
33
+ await mkdir(dirname(path), { recursive: true });
34
+ await writeFile(path, `${JSON.stringify({ layers, command, writtenAt: now })}\n`, "utf8");
35
+ }
36
+ /** Forget the record once every covered layer has merged, so a later request starts fresh. */
37
+ export async function clearApprovedLayers(key) {
38
+ await unlink(approvalPath(key)).catch(() => undefined);
39
+ }
@@ -0,0 +1,16 @@
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
+ /** `scope` names the timer: `owner/repo#pr` or `owner/repo stack N`. */
12
+ export declare function stallRepairMarkerPath(scope: string): string;
13
+ /** True when the repair tick for this reason was already presented within the last hour. */
14
+ export declare function readStallRepair(scope: string, reason: string): Promise<boolean>;
15
+ /** False when the marker could not be saved: the repair tick would then repeat, so escalate. */
16
+ export declare function writeStallRepair(scope: string, reason: string): Promise<boolean>;