pr-shepherd 2.2.2 → 2.2.4

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.
@@ -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.2.2",
4
+ "version": "2.2.4",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
7
7
  "email": "jonathanrichardong@gmail.com"
@@ -11,7 +11,6 @@
11
11
  "license": "MIT",
12
12
  "keywords": ["github", "pull-request", "ci", "code-review", "automation"],
13
13
  "skills": "./plugins/pr-shepherd/skills/",
14
- "mcpServers": "./plugins/pr-shepherd/.mcp.json",
15
14
  "hooks": {
16
15
  "PreToolUse": [
17
16
  {
package/README.md CHANGED
@@ -81,7 +81,7 @@ More features are in [docs/features.md](docs/features.md).
81
81
 
82
82
  ## Install
83
83
 
84
- The plugin starts the version-matched `pr-shepherd-mcp` server automatically.
84
+ The plugin ships the skills, which drive the CLI, so install both.
85
85
 
86
86
  ```bash
87
87
  # Claude Code
@@ -96,10 +96,12 @@ grok plugin marketplace add jonathanong/pr-shepherd
96
96
  grok plugin install pr-shepherd --trust
97
97
 
98
98
  # CLI, for shells and CI
99
- npm install -g pr-shepherd
99
+ pnpm i -g pr-shepherd
100
100
  ```
101
101
 
102
- For the MCP server without the plugin, or a local checkout, see [docs/mcp.md](docs/mcp.md).
102
+ Use one package manager for global installs, because a second global copy shadows the first (`which -a pr-shepherd` lists every copy).
103
+
104
+ The plugin is the CLI plus skills; it does not start the MCP server. For why, and to register the server yourself, see [docs/mcp.md](docs/mcp.md#why-the-plugin-does-not-start-it).
103
105
 
104
106
  Requirements:
105
107
 
@@ -7,3 +7,12 @@ export type CheckFollowUp = "approval" | "investigate";
7
7
  export declare function checkFollowUp(check: AgentCheck): CheckFollowUp | undefined;
8
8
  /** The one investigation tick: raw facts, the playbook, and the bounded outcome. */
9
9
  export declare function buildCheckFollowUpInstructions(checks: AgentCheck[], repo: string, actionsRunIds: ReadonlySet<string>): string[];
10
+ /**
11
+ * A failing check with evidence (an excerpt, or an external details URL) but no rerun and no
12
+ * further automatic path: an external status, a later attempt, or a merge-group failure once the
13
+ * PR left the queue. The caller can fix a cause in the PR; otherwise it gets one investigation
14
+ * tick before `check-follow-up-unavailable`.
15
+ */
16
+ export declare function isEvidenceFollowUpCheck(check: AgentCheck, queued: boolean): boolean;
17
+ /** The investigation step for evidence-bearing checks: the evidence stays in the failing checks. */
18
+ export declare function buildEvidenceFollowUpInstruction(): string;
@@ -32,3 +32,25 @@ export function buildCheckFollowUpInstructions(checks, repo, actionsRunIds) {
32
32
  "If the cause is within this PR, fix it and push. Otherwise make no change and keep what you found; do not rerun or retrigger these checks. If these checks are unchanged on the next poll, Shepherd escalates with `check-follow-up-unavailable`; report that diagnosis then.",
33
33
  ];
34
34
  }
35
+ /**
36
+ * A failing check with evidence (an excerpt, or an external details URL) but no rerun and no
37
+ * further automatic path: an external status, a later attempt, or a merge-group failure once the
38
+ * PR left the queue. The caller can fix a cause in the PR; otherwise it gets one investigation
39
+ * tick before `check-follow-up-unavailable`.
40
+ */
41
+ export function isEvidenceFollowUpCheck(check, queued) {
42
+ if (check.rerunCommand || checkFollowUp(check) !== undefined)
43
+ return false;
44
+ // A still-queued merge-group entry waits for GitHub to report its removal.
45
+ if (check.scope === "merge_group" && queued)
46
+ return false;
47
+ if (check.runId === null)
48
+ return Boolean(check.detailsUrl?.trim());
49
+ if (!hasLogEvidence(check))
50
+ return false;
51
+ return (check.runAttempt ?? 1) > 1 || (check.scope === "merge_group" && !queued);
52
+ }
53
+ /** The investigation step for evidence-bearing checks: the evidence stays in the failing checks. */
54
+ export function buildEvidenceFollowUpInstruction() {
55
+ return `Some checks under \`## Failing checks\` have no rerun Shepherd can offer. ${playbookPointer("Check follow-up")}`;
56
+ }
@@ -216,7 +216,7 @@ export function buildEscalateHumanMessage(escalate, pr, opts) {
216
216
  export function buildEscalateSuggestion(triggers, detail) {
217
217
  if (triggers.includes("check-follow-up-unavailable")) {
218
218
  if (detail === "investigated") {
219
- return "The failing checks below had no rerun and no log excerpt Shepherd could show. After one investigation tick they are unchanged on this head. Report what the investigation found. What remains is a repository, CI-configuration, or workflow-permission change, or waiting out a GitHub incident; each is a human decision.";
219
+ return "The failing checks below have no rerun Shepherd can offer. After one investigation tick they are unchanged on this head. Report what the investigation found. What remains is a repository, CI-configuration, or workflow-permission change, or waiting out a GitHub incident; each is a human decision.";
220
220
  }
221
221
  return "One or more failing checks have no autonomous follow-up available. Use the displayed conclusion, run or URL, and included evidence to handle them manually.";
222
222
  }
@@ -8,7 +8,7 @@ import { buildThreadMutationRouting, threadHasAuthorizedMutation, } from "./thre
8
8
  import { buildFixInstructions } from "./render.mjs";
9
9
  import { buildCancelRunsInstruction, buildInProgressRuns } from "./in-progress-runs.mjs";
10
10
  import { buildRemovedQueueRecovery, buildStackQueueRemovalAcknowledgment } from "./merge.mjs";
11
- import { buildCheckFollowUpInstructions, checkFollowUp } from "./check-follow-up.mjs";
11
+ import { buildCheckFollowUpInstructions, buildEvidenceFollowUpInstruction, checkFollowUp, isEvidenceFollowUpCheck, } from "./check-follow-up.mjs";
12
12
  import { checkFollowUpKeys, readCheckFollowUp, readShownRunFailures, sameCheckFollowUp, writeCheckFollowUp, writeShownRunFailures, } from "../../state/check-follow-up.mjs";
13
13
  import { activeRunFailures, buildRunFailureWait, runFailureKeys, runFailuresShown, } from "./run-failure-wait.mjs";
14
14
  import { currentEjectionCommit, } from "./queue-recovery-instructions.mjs";
@@ -201,7 +201,13 @@ async function handleTriageTick(ctx) {
201
201
  const manualExhaustedAttempts = exhaustedAttempts.filter((check) => manualFollowUpChecks.includes(check));
202
202
  const hasBehindBaseRecovery = isBehind && manualExhaustedAttempts.length > 0;
203
203
  const activeFailures = activeRunFailures(failingAgentChecks, inProgressWorkflowRunIds, releasedCheckNames);
204
+ const evidenceChecks = failingAgentChecks.filter((check) => !releasedCheckNames.has(check.name) &&
205
+ !belongsToActiveWorkflowRun(check) &&
206
+ !activeFailures.includes(check) &&
207
+ isEvidenceFollowUpCheck(check, Boolean(report.mergeQueue?.inQueue)));
204
208
  const hasOtherAutonomousWork = hasConflicts ||
209
+ // The branch-update step is emitted only with a configured hint; uncounted work cannot loop.
210
+ (isBehind && behindBaseHint.trim() !== "" && evidenceChecks.length > 0) ||
205
211
  hasBehindBaseRecovery ||
206
212
  threads.length > 0 ||
207
213
  resolutionOnlyThreads.length > 0 ||
@@ -218,19 +224,24 @@ async function handleTriageTick(ctx) {
218
224
  failingAgentChecks.some((check) => !activeFailures.includes(check) &&
219
225
  (releasedCheckNames.has(check.name) ||
220
226
  belongsToActiveWorkflowRun(check) ||
221
- checkFollowUp(check) === undefined));
227
+ (checkFollowUp(check) === undefined && !evidenceChecks.includes(check))));
222
228
  const hasAutonomousWork = hasOtherAutonomousWork || activeFailures.length > 0;
223
229
  // Only a gate a human must grant escalates at once; every other manual-only check gets one
224
230
  // investigation tick for this head and check set before it escalates.
225
231
  const needsApproval = manualFollowUpChecks.some((check) => checkFollowUp(check) === "approval");
226
- const followUpKeys = checkFollowUpKeys(manualFollowUpChecks);
232
+ const terminalChecks = [...manualFollowUpChecks, ...evidenceChecks];
233
+ const followUpKeys = checkFollowUpKeys(terminalChecks);
227
234
  const investigated = needsApproval || sameCheckFollowUp(await readCheckFollowUp(stallKey), headSha, followUpKeys);
228
- const investigate = manualFollowUpChecks.length > 0 && !hasAutonomousWork && !investigated;
229
- if (manualFollowUpChecks.length > 0 && !hasAutonomousWork && investigated) {
235
+ const investigate = manualFollowUpChecks.length > 0 &&
236
+ evidenceChecks.length === 0 &&
237
+ !hasAutonomousWork &&
238
+ !investigated;
239
+ if (terminalChecks.length > 0 && !hasAutonomousWork && investigated) {
230
240
  const { resolveCommand, resolveOnlyCommand } = buildReviewCommands(failingAgentChecks);
231
241
  const pending = pendingReviewCommands(resolveCommand, resolveOnlyCommand);
232
- const checkSuggestion = manualExhaustedAttempts.length > 0
233
- ? `GitHub reports a later workflow attempt (${manualExhaustedAttempts
242
+ const terminalExhausted = exhaustedAttempts.filter((check) => terminalChecks.includes(check));
243
+ const checkSuggestion = terminalExhausted.length > 0
244
+ ? `GitHub reports a later workflow attempt (${terminalExhausted
234
245
  .map((check) => `${check.runId ?? check.name}: attempt ${check.runAttempt}`)
235
246
  .join(", ")}), so Shepherd's single rerun allowance is exhausted. ${needsApproval ? "Use the included evidence to handle the repeated failure manually before resuming." : buildEscalateSuggestion(["check-follow-up-unavailable"], "investigated")}`
236
247
  : buildEscalateSuggestion(["check-follow-up-unavailable"], needsApproval ? undefined : "investigated");
@@ -241,7 +252,7 @@ async function handleTriageTick(ctx) {
241
252
  changesRequestedReviews,
242
253
  ...(firstLookSummaries.length > 0 && { firstLookSummaries }),
243
254
  ...(editedSummaries.length > 0 && { editedSummaries }),
244
- checks: manualFollowUpChecks,
255
+ checks: terminalChecks,
245
256
  ...(pending && { pendingReviewCommands: pending }),
246
257
  suggestion: checkSuggestion,
247
258
  };
@@ -263,6 +274,8 @@ async function handleTriageTick(ctx) {
263
274
  if (activeFailures.length > 0 &&
264
275
  !hasOtherAutonomousWork &&
265
276
  manualFollowUpChecks.length === 0 &&
277
+ // New evidence checks are shown on a TRIAGE tick; once shown, the run's wait covers them too.
278
+ (evidenceChecks.length === 0 || investigated) &&
266
279
  !isBehind &&
267
280
  !repairInstructions?.length &&
268
281
  runFailuresShown(await readShownRunFailures(stallKey), headSha, shownKeys)) {
@@ -334,6 +347,11 @@ async function handleTriageTick(ctx) {
334
347
  const triageStep = instructions.findIndex((step) => step.startsWith("Triage `## Failing checks`."));
335
348
  instructions.splice(triageStep, 1, ...buildCheckFollowUpInstructions(manualFollowUpChecks, report.repo, actionsRunIds));
336
349
  }
350
+ if (evidenceChecks.length > 0) {
351
+ const triageStep = instructions.findIndex((step) => step.startsWith("Triage `## Failing checks`."));
352
+ if (triageStep >= 0)
353
+ instructions.splice(triageStep + 1, 0, buildEvidenceFollowUpInstruction());
354
+ }
337
355
  if (recovery && "unavailable" in recovery)
338
356
  instructions.unshift(recovery.unavailable);
339
357
  if (acknowledgmentRecovery && "unavailable" in acknowledgmentRecovery)
@@ -425,7 +443,7 @@ async function handleTriageTick(ctx) {
425
443
  const result = await applyStallGuard(stallKey, stallTimeoutSeconds, headSha, base, prNumber, prospectiveResult, report, reviewSummaryIds, undefined, opts.persistSeen !== false);
426
444
  if (result.action === "triage" && opts.persistSeen !== false) {
427
445
  await writeFixAttempts({ owner: repoOwner, repo: repoName, pr: prNumber }, { headSha, threadAttempts, threadBodyHashes });
428
- if (investigate)
446
+ if (investigate || evidenceChecks.length > 0)
429
447
  await writeCheckFollowUp(stallKey, { headSha, checks: followUpKeys });
430
448
  if (activeFailures.length > 0) {
431
449
  await writeShownRunFailures(stallKey, { headSha, checks: shownKeys });
@@ -1,5 +1,6 @@
1
1
  import { EXIT, ShepherdError } from "../exit-codes.mjs";
2
2
  import { GitHubRequestError } from "./errors.mjs";
3
+ import { dropUnreadableSuites } from "./check-suite-nodes.mjs";
3
4
  export function requireRawPr(response, pr, repo) {
4
5
  if (!response?.repository) {
5
6
  throw new GitHubRequestError(`GitHub GraphQL response did not include repository ${repo.owner}/${repo.name} (not found or access denied)`, { status: 200 });
@@ -7,7 +8,9 @@ export function requireRawPr(response, pr, repo) {
7
8
  if (!response.repository.pullRequest) {
8
9
  throw new ShepherdError(`PR #${pr} not found`, EXIT.UNAVAILABLE);
9
10
  }
10
- return response.repository.pullRequest;
11
+ const raw = response.repository.pullRequest;
12
+ dropUnreadableSuites(raw.commits?.nodes[0]?.commit);
13
+ return raw;
11
14
  }
12
15
  export function requireContextNodes(nodes) {
13
16
  const nullIndex = nodes.findIndex((node) => node === null);
@@ -0,0 +1,17 @@
1
+ interface SuiteCommit {
2
+ checkSuites?: {
3
+ pageInfo?: {
4
+ hasNextPage: boolean;
5
+ };
6
+ nodes: unknown[];
7
+ } | null;
8
+ }
9
+ /**
10
+ * GitHub can return `null` in place of a check suite it has not finished
11
+ * creating or cannot read (seen in a PR's first seconds, with no GraphQL error).
12
+ * Nothing is known about such a suite, so it is dropped rather than guessed at,
13
+ * and the page is marked as not fully read: consumers already treat an unread
14
+ * suite page as unverified, which fails readiness closed instead of crashing.
15
+ */
16
+ export declare function dropUnreadableSuites(commit: SuiteCommit | null | undefined): void;
17
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * GitHub can return `null` in place of a check suite it has not finished
3
+ * creating or cannot read (seen in a PR's first seconds, with no GraphQL error).
4
+ * Nothing is known about such a suite, so it is dropped rather than guessed at,
5
+ * and the page is marked as not fully read: consumers already treat an unread
6
+ * suite page as unverified, which fails readiness closed instead of crashing.
7
+ */
8
+ export function dropUnreadableSuites(commit) {
9
+ const suites = commit?.checkSuites;
10
+ if (!suites || !suites.nodes.includes(null))
11
+ return;
12
+ suites.nodes = suites.nodes.filter((node) => node !== null);
13
+ suites.pageInfo = { ...suites.pageInfo, hasNextPage: true };
14
+ }
@@ -1,4 +1,5 @@
1
1
  import { githubOperation } from "./transport.mjs";
2
+ import { dropUnreadableSuites } from "./check-suite-nodes.mjs";
2
3
  import { readRestCommitChecks } from "./rest-check-read.mjs";
3
4
  import { graphqlWithRateLimit } from "./client.mjs";
4
5
  import { POLL_SUMMARY_CHECK_PAGE_QUERY } from "./queries.mjs";
@@ -13,6 +14,7 @@ import { POLL_SUMMARY_CHECK_PAGE_QUERY } from "./queries.mjs";
13
14
  */
14
15
  export async function hydratePollSummaryChecks(raw, repo) {
15
16
  const headCommit = raw.commits.nodes[0]?.commit;
17
+ dropUnreadableSuites(headCommit);
16
18
  if (headCommit)
17
19
  await hydrateCommitContexts(headCommit, repo);
18
20
  const queueCommit = raw.mergeQueueEntry?.headCommit;
@@ -42,6 +42,8 @@ export function summaryComplete(layer, source) {
42
42
  const commit = headCommit(layer);
43
43
  if (!commit || commit.oid !== layer.headRefOid || !commit.checkSuites?.pageInfo)
44
44
  return false;
45
+ if (commit.checkSuites.nodes.includes(null))
46
+ return false;
45
47
  const contexts = commit.statusCheckRollup?.contexts;
46
48
  if (contexts &&
47
49
  (contexts.pageInfo.hasPreviousPage ||
package/bin/index.mjs CHANGED
@@ -10,6 +10,7 @@
10
10
  import { main } from "./cli-parser.mjs";
11
11
  import { errorToExitCode } from "./exit-codes.mjs";
12
12
  import { formatCliError } from "./cli/error-format.mjs";
13
+ import { appendEntry } from "./log/log-file.mjs";
13
14
  function formatCause(cause, seen = new Set(), depth = 0) {
14
15
  if (depth > 5 || seen.has(cause))
15
16
  return "[circular or deep cause chain]";
@@ -23,6 +24,8 @@ function formatCause(cause, seen = new Set(), depth = 0) {
23
24
  }
24
25
  main(process.argv).catch((err) => {
25
26
  const msg = formatCliError(err);
27
+ // The terminal gets the message only; the stack goes to the debug log (a no-op when it is off).
28
+ appendEntry(`## Unhandled error\n\n\`\`\`\n${formatCause(err)}\n\`\`\`\n\n`);
26
29
  const causeStr = err instanceof Error && err.cause != null ? formatCause(err.cause) : null;
27
30
  process.stderr.write(`pr-shepherd error: ${msg}${causeStr !== null ? ` (cause: ${causeStr})` : ""}\n`);
28
31
  process.exit(errorToExitCode(err));
@@ -15,11 +15,17 @@ interface StateKey {
15
15
  repo: string;
16
16
  pr: number;
17
17
  }
18
- /** Stable identity for a failing check: name, run, and attempt. Sorted so order never matters. */
18
+ /**
19
+ * Stable identity for a failing check: name, run, attempt, queue commit, and (for a status with no
20
+ * run) its details URL, so a fresh queue execution or result is not mistaken for an old one.
21
+ * Sorted so order never matters.
22
+ */
19
23
  export declare function checkFollowUpKeys(checks: ReadonlyArray<{
20
24
  name: string;
21
25
  runId: string | null;
22
26
  runAttempt?: number;
27
+ commitOid?: string;
28
+ detailsUrl?: string | null;
23
29
  }>): string[];
24
30
  /** The stored head and check set, or undefined when no usable marker exists. */
25
31
  export declare function readCheckFollowUp(key: StateKey): Promise<CheckFollowUpMarker | undefined>;
@@ -9,9 +9,20 @@
9
9
  import { mkdir, readFile, writeFile } from "node:fs/promises";
10
10
  import { dirname } from "node:path";
11
11
  import { resolvePrStatePath } from "./base.mjs";
12
- /** Stable identity for a failing check: name, run, and attempt. Sorted so order never matters. */
12
+ /**
13
+ * Stable identity for a failing check: name, run, attempt, queue commit, and (for a status with no
14
+ * run) its details URL, so a fresh queue execution or result is not mistaken for an old one.
15
+ * Sorted so order never matters.
16
+ */
13
17
  export function checkFollowUpKeys(checks) {
14
- return checks.map((c) => `${c.name}#${c.runId ?? ""}#${c.runAttempt ?? ""}`).sort();
18
+ return checks
19
+ .map((c) => {
20
+ const base = `${c.name}#${c.runId ?? ""}#${c.runAttempt ?? ""}`;
21
+ const commit = c.commitOid ? `@${c.commitOid}` : "";
22
+ const url = c.runId === null && c.detailsUrl ? `|${c.detailsUrl}` : "";
23
+ return base + commit + url;
24
+ })
25
+ .sort();
15
26
  }
16
27
  /** The stored head and check set, or undefined when no usable marker exists. */
17
28
  export function readCheckFollowUp(key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for agentic coding tools",
5
5
  "keywords": [
6
6
  "automation",
@@ -28,8 +28,6 @@
28
28
  },
29
29
  "files": [
30
30
  "bin/**",
31
- "plugins/**/.mcp.json",
32
- "plugins/**/.codex.mcp.json",
33
31
  "src/classify/types.mts",
34
32
  "plugins/**",
35
33
  "plugins/**/.codex-plugin/**",
@@ -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.2.2",
4
+ "version": "2.2.4",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
7
7
  "email": "jonathanrichardong@gmail.com"
@@ -11,7 +11,6 @@
11
11
  "license": "MIT",
12
12
  "keywords": ["github", "pull-request", "ci", "code-review", "automation"],
13
13
  "skills": "./skills/",
14
- "mcpServers": "./.mcp.json",
15
14
  "userConfig": {
16
15
  "poll_guard": {
17
16
  "type": "string",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "2.2.2",
3
+ "version": "2.2.4",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for Codex.",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
@@ -12,7 +12,6 @@
12
12
  "license": "MIT",
13
13
  "keywords": ["github", "pull-request", "ci", "code-review", "automation", "codex"],
14
14
  "skills": "./skills/",
15
- "mcpServers": "./.codex.mcp.json",
16
15
  "interface": {
17
16
  "displayName": "pr-shepherd",
18
17
  "shortDescription": "Monitor PR CI and review comments from Codex",
@@ -1,6 +1,6 @@
1
1
  # Check follow-up
2
2
 
3
- Apply when a step says `Playbook: "Check follow-up"`. A check failed, was cancelled, or never started, and Shepherd has no rerun or log excerpt to show. Find out why before acting; follow the evidence.
3
+ Apply when a step says `Playbook: "Check follow-up"`. A check failed, was cancelled, or never started, and Shepherd has no rerun to offer. Start from any excerpt or annotations it printed; without them, find out why before acting. Follow the evidence.
4
4
 
5
5
  - The run: `gh run view <runId> -R <owner/repo>` lists its jobs and annotations, which often say why a job never got a runner; add `--log-failed` for logs.
6
6
  - `STARTUP_FAILURE`: workflow syntax, an unresolved reusable workflow or action, missing permissions, secrets or environments.
@@ -1,8 +0,0 @@
1
- {
2
- "mcpServers": {
3
- "pr-shepherd": {
4
- "command": "npx",
5
- "args": ["--yes", "--package", "pr-shepherd@2.2.2", "pr-shepherd-mcp"]
6
- }
7
- }
8
- }
@@ -1,6 +0,0 @@
1
- {
2
- "pr-shepherd": {
3
- "command": "npx",
4
- "args": ["--yes", "--package", "pr-shepherd@2.2.2", "pr-shepherd-mcp"]
5
- }
6
- }