pr-shepherd 2.2.5 → 2.2.6

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.5",
4
+ "version": "2.2.6",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
7
7
  "email": "jonathanrichardong@gmail.com"
package/README.md CHANGED
@@ -1,45 +1,42 @@
1
1
  # pr-shepherd
2
2
 
3
- Take pull requests from scratch to merge-ready with a coding agent as a [Code Mode-style](https://code.claude.com/docs/en/code-mode) plugin. It works with Claude Code, Codex, and Grok.
3
+ Take pull requests from scratch to merge-ready with a coding agent, as a [Code Mode-style](https://code.claude.com/docs/en/code-mode) plugin. It works with Claude Code, Codex, and Grok.
4
4
 
5
5
  ## Benefits
6
6
 
7
- - **Better decisions:** across 56 PR states, the agent scores 0.97 with the plugin vs. 0.47 with `gh` + the GitHub MCP server ([outcome evals](evals/README.md), 2026-11-15).
7
+ - **Better decisions:** across 56 PR states, it scores 0.97 with the plugin vs. 0.47 with `gh` + the GitHub MCP server ([outcome evals](evals/README.md), 2026-11-15).
8
8
  - **Lower cost:** modeled cost per PR session is about 36% lower than `gh` and 76% lower than the GitHub MCP server, with 20% / 69% fewer turns ([token bench](evals/tokens/README.md); assumes a warm prompt cache).
9
- - **More PRs on one GitHub quota:** 65% fewer GraphQL points than `gh` per PR session. While CI runs, one 5,000-point hourly budget covers about 80 waiting PRs, vs. about 13 with `gh pr checks --watch` ([GitHub API](docs/github-api.md), [GraphQL usage](docs/graphql-usage.md)). A [GitHub App](docs/github-app.md) and [webhook events](docs/hook-harness.md) cut it further.
10
- - **72 GitHub edge cases handled:** for example, outdated or resolved threads are still shown once, comments edited after the agent read them come back, and conflicts that GraphQL reports as `CLEAN` are caught ([handled cases](docs/handled-cases.md)).
11
- - **Tidy PRs:** bot and outdated comments are triaged and resolved, human reviews get replies, and known bot noise is minimized.
12
- - **Review hygiene:** Shepherd never answers its own replies, skips a denied reply once instead of retrying, hands a repeatedly rejected fix to a human, and never minimizes human comments ([comments and reviews](docs/handled-cases.md#comments-and-reviews)).
13
- - **Less context:** resolved comments and configured bot noise are filtered out before they reach the agent.
14
- - **CI failures, pre-read:** each failing check comes with its failed step, summary, and a log excerpt, so the agent can usually skip fetching logs. Superseded runs, required checks that never started, and approval gates are recognized ([failing checks](docs/actions.md#failing-checks-and-reruns), [CI cases](docs/handled-cases.md#ci-checks)).
15
- - **Cheaper CI:** names the in-progress runs a fix push would cancel anyway, so the agent cancels them early.
16
- - **Why a PR can't merge:** reads branch protection and rulesets and prints the actual requirements, such as `Approvals: None [Required]` ([merge requirements](docs/merge-status.md#merge-requirements)). Merges are pinned to the head the agent checked, review nits wait so a push doesn't eject a queued PR, and a PR a maintainer pulled from the queue is not requeued ([merge and queue](docs/handled-cases.md#merge-and-queue)).
17
- - **Full flow:** from scratch to draft, mergeable, and through the merge queue, including stacked PRs.
18
- - **Review suggestions:** applies suggested changes as commits that credit the reviewer.
19
- - **Safe by construction:** the CLI never mutates git or merges by itself, and human handoff is limited to a [short escalation list](docs/escalations.md).
9
+ - **More PRs on one GitHub quota:** 65% fewer GraphQL points than `gh` per PR session. While CI runs, a 5,000-point hourly budget covers about 80 waiting PRs, vs. about 13 with `gh pr checks --watch` ([GitHub API](docs/github-api.md), [GraphQL usage](docs/graphql-usage.md)). A [GitHub App](docs/github-app.md) and [webhook events](docs/hook-harness.md) cut it more.
10
+ - **72 GitHub edge cases handled:** outdated or resolved threads are still shown once, edited comments come back, and conflicts that GraphQL reports as `CLEAN` are caught ([handled cases](docs/handled-cases.md)).
11
+ - **Tidy PRs, less context:** bot and outdated comments are triaged and resolved, human reviews get replies, and known bot noise is minimized and filtered out before it reaches the agent.
12
+ - **Review hygiene:** it never answers its own replies or minimizes human comments, skips a denied reply once, and hands a repeatedly rejected fix to a human ([comments and reviews](docs/handled-cases.md#comments-and-reviews)).
13
+ - **CI failures, pre-read:** each failing check comes with its failed step, summary, and log excerpt, so the agent rarely fetches logs. Superseded runs, unstarted required checks, and approval gates are recognized ([failing checks](docs/actions.md#failing-checks-and-reruns), [CI cases](docs/handled-cases.md#ci-checks)).
14
+ - **Cheaper CI:** names the in-progress runs a fix push would cancel anyway.
15
+ - **Why a PR can't merge:** prints the actual branch protection and ruleset requirements, such as `Approvals: None [Required]` ([merge requirements](docs/merge-status.md#merge-requirements)). Merges are pinned to the head the agent checked, and a PR a maintainer pulled from the queue is not requeued ([merge and queue](docs/handled-cases.md#merge-and-queue)).
16
+ - **Full flow:** draft to mergeable to merged, through the merge queue and stacks. Suggested changes become commits that credit the reviewer.
17
+ - **Safe by construction:** the CLI never mutates git or merges by itself, and human handoff is limited to a [short list](docs/escalations.md).
20
18
 
21
19
  ## Use cases
22
20
 
23
- - **Autonomous agents.** An agent opens a PR and drives it to merge-ready, or merged when you allow it. Nobody has to watch CI and reviews.
24
- - **Exhaustive AI code review.** Some PRs get many bot reviews (CodeRabbit, Codex, Copilot, and others). Shepherd shows every thread and comment once and tracks first-look, edited, and outdated items. It pre-filters comments, batches the replies, resolves, and minimizes.
25
- - **High-velocity teams.** Supports stacked PRs, merge queues, and merge queue ejections, and directs agents to rebase or stack as needed, so work keeps moving even with many conflicts.
21
+ - **Autonomous agents.** An agent opens a PR and drives it to merge-ready, or merged when you allow it, with nobody watching CI and reviews.
22
+ - **Exhaustive AI code review.** For PRs with many bot reviews (CodeRabbit, Codex, Copilot), Shepherd shows every thread and comment once, tracks first-look, edited, and outdated items, and batches replies, resolves, and minimizes.
23
+ - **High-velocity teams.** Stacked PRs, merge queues, and ejections are supported, and agents are told to rebase or stack as needed, so work keeps moving.
26
24
 
27
25
  ## How to use
28
26
 
29
27
  [Install](#install) the plugin, then ask your agent:
30
28
 
31
- - **"make PRs, /pr-shepherd:pr-shepherd"** makes one PR per change that can be reviewed alone, stacks a PR on an earlier one when it needs that PR's code or edits the same lines, and shepherds every PR until it is mergeable.
32
- - **`/pr-shepherd <PR>`** takes a PR, including a draft, to mergeable. It does not merge. Leave out the PR to use the current branch.
33
- - **`/pr-shepherd <PR1> <PR2>`** shepherds several PRs and returns when any has an actionable step.
29
+ - **"make PRs, /pr-shepherd:pr-shepherd"** makes one PR per separately reviewable change, stacks a PR on an earlier one when it needs that PR's code or edits the same lines, and shepherds every PR until it is mergeable.
30
+ - **`/pr-shepherd <PR>`** takes a PR, including a draft, to mergeable without merging. Omit the PR to use the current branch.
31
+ - **`/pr-shepherd <PR1> <PR2>`** shepherds several PRs, returning when any needs action.
34
32
  - **`/pr-shepherd --merge <PR>`** takes the PR to mergeable and merges it.
35
- - **`/pr-shepherd stack <stack#> --merge`** shepherds a native stack and merges it all at once when it is ready. Use `--merge-through <PR>` instead to merge up to that layer, or `--merge-ready` to merge the bottom layers as they become ready. Listing PR numbers instead of the stack number owns only those layers.
33
+ - **`/pr-shepherd stack <stack#> --merge`** shepherds a native stack and merges it all at once when it is ready. `--merge-through <PR>` merges up to that layer, and `--merge-ready` merges the bottom layers as they become ready. Listing PR numbers instead of the stack number owns only those layers.
36
34
 
37
- In Codex, use `$pr-shepherd`. In a shell or CI, run `pr-shepherd <PR>`. `/goal` is generally not needed.
35
+ In Codex, use `$pr-shepherd`. In a shell or CI, run `pr-shepherd <PR>`.
38
36
 
39
- Then run **`/pr-shepherd:setup-pr-shepherd`** (Codex: `$setup-pr-shepherd`) to scan your recent PRs for recurring bot noise and configure `.pr-shepherdrc.yml` for you, or edit it by hand ([configuration](docs/configuration.md)):
37
+ Then run **`/pr-shepherd:setup-pr-shepherd`** (Codex: `$setup-pr-shepherd`) to scan recent PRs for recurring bot noise and configure `.pr-shepherdrc.yml`, or edit it by hand ([configuration](docs/configuration.md)):
40
38
 
41
- - turn on the bundled classification rules to hide known bot comments;
42
- - add your own [classification rules](examples/classification/);
39
+ - turn on the bundled classification rules to hide known bot comments, or add your own ([examples](examples/classification/));
43
40
  - list code-review workflows in `checks.never-cancel` so they always finish.
44
41
 
45
42
  ```yaml
@@ -52,11 +49,11 @@ checks:
52
49
  - "*review*"
53
50
  ```
54
51
 
55
- Optionally, write your policy ("reply instead of fixing nits", "never merge") into a skill that wraps the shipped one ([skills](docs/skills.md)).
52
+ Optionally, put your policy ("reply instead of fixing nits", "never merge") in a skill that wraps the shipped one ([skills](docs/skills.md)).
56
53
 
57
54
  ## What it does
58
55
 
59
- Shepherd gathers the full PR context (reviews, CI failures, merge requirements) in one call and returns one action with numbered instructions and exact commands. The agent spends fewer reasoning tokens, tool calls, and turns, and rarely has to investigate on its own.
56
+ Shepherd gathers the full PR context (reviews, CI failures, merge requirements) in one call and returns one action with numbered instructions and exact commands, so the agent needs fewer tokens, calls, and turns.
60
57
 
61
58
  ```text
62
59
  $ pr-shepherd 123
@@ -77,7 +74,7 @@ $ pr-shepherd 123
77
74
  4. Rerun Shepherd now.
78
75
  ```
79
76
 
80
- More features are in [docs/features.md](docs/features.md).
77
+ More in [docs/features.md](docs/features.md).
81
78
 
82
79
  ## Install
83
80
 
@@ -99,25 +96,23 @@ grok plugin install pr-shepherd --trust
99
96
  pnpm i -g pr-shepherd
100
97
  ```
101
98
 
102
- Use one package manager for global installs, because a second global copy shadows the first (`which -a pr-shepherd` lists every copy).
99
+ Use one package manager for global installs; a second copy shadows the first (`which -a pr-shepherd` lists them).
103
100
 
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).
101
+ The plugin does not start the MCP server. For why, and to register it yourself, see [docs/mcp.md](docs/mcp.md#why-the-plugin-does-not-start-it).
105
102
 
106
103
  Requirements:
107
104
 
108
- - Node.js >= 22.19.0, Bun, or Deno
109
- - `git`
110
- - A GitHub token or an authenticated `gh` CLI with [the required access](docs/authentication.md)
105
+ - Node.js >= 22.19.0, Bun, or Deno, and `git`
106
+ - A GitHub token or authenticated `gh` CLI with [the required access](docs/authentication.md)
111
107
 
112
108
  ## Documentation
113
109
 
114
110
  [docs/README.md](docs/README.md) indexes every doc. Start with:
115
111
 
116
- - [Features, workflow assumptions, and limits](docs/features.md)
117
- - [CLI commands, flags, stacks, and polling](docs/cli-usage.md)
112
+ - [Features and limits](docs/features.md)
113
+ - [CLI commands and flags](docs/cli-usage.md)
118
114
  - [Actions](docs/actions.md) and [exit codes](docs/exit-codes.md)
119
- - [Configuration and classification rules](docs/configuration.md), with [examples](examples/classification/)
120
- - [Comparison with Cursor, Copilot, CodeRabbit, and others](docs/comparison.md)
115
+ - [Configuration](docs/configuration.md) and [comparison with other tools](docs/comparison.md)
121
116
  - [Upgrading from 0.x](docs/migrating-to-v1.md)
122
117
 
123
118
  ## Harness ecosystem
@@ -1,4 +1,6 @@
1
+ import { relative, isAbsolute } from "node:path";
1
2
  import { GitHubRequestError } from "../github/errors.mjs";
3
+ import { resolveStateBase } from "../state/base.mjs";
2
4
  /** Safe GitHub transport metadata suitable for user-facing structured error output. */
3
5
  export function serializeGitHubRequestErrorDetails(err) {
4
6
  if (!(err instanceof GitHubRequestError))
@@ -17,8 +19,20 @@ export function serializeGitHubRequestErrorDetails(err) {
17
19
  ...(err.authSource !== undefined && { credential: err.authSource }),
18
20
  };
19
21
  }
22
+ /** One-line hint when `err` is a permission failure on a path inside the state directory. */
23
+ function stateDirHint(err) {
24
+ const { code, path } = (err ?? {});
25
+ if ((code !== "EPERM" && code !== "EACCES") || typeof path !== "string")
26
+ return null;
27
+ const base = resolveStateBase();
28
+ const rel = relative(base, path);
29
+ if (rel.startsWith("..") || isAbsolute(rel))
30
+ return null;
31
+ return `state dir ${base} not writable; set PR_SHEPHERD_STATE_DIR to a writable directory or run outside the sandbox`;
32
+ }
20
33
  export function formatCliError(err) {
21
- const message = err instanceof Error ? err.message : String(err);
34
+ const hint = stateDirHint(err);
35
+ const message = (err instanceof Error ? err.message : String(err)) + (hint === null ? "" : `\n${hint}`);
22
36
  const githubDetails = serializeGitHubRequestErrorDetails(err);
23
37
  if (githubDetails === undefined)
24
38
  return message;
@@ -36,7 +36,11 @@ export function formatMutateResult(result) {
36
36
  const rateLimit = formatRateLimit(result);
37
37
  if (rateLimit)
38
38
  lines.push(rateLimit);
39
- const pendingReason = result.sessionRefusal ? "session access" : "rate limit";
39
+ const pendingReason = result.sessionRefusal
40
+ ? "session access"
41
+ : result.rateLimit
42
+ ? "rate limit"
43
+ : "an earlier error";
40
44
  pushIds(lines, `Not replied due to ${pendingReason}`, result.unrepliedThreads);
41
45
  pushIds(lines, `Not resolved due to ${pendingReason}`, result.unresolvedThreads);
42
46
  pushIds(lines, `Not minimized due to ${pendingReason}`, result.unminimizedComments);
@@ -21,6 +21,13 @@ async function paths(context, id, message) {
21
21
  catch { }
22
22
  return [...new Set(identities)].map((identity) => resolvePrStatePath({ owner: context.repo.owner, repo: context.repo.name, pr: context.pr }, "uncertain-replies", `${createHash("sha256").update(`${identity}\n${message}`).digest("hex")}.json`));
23
23
  }
24
+ function uncertainMessage(undecided) {
25
+ return (`Previous GraphQL reply outcome is uncertain for ${undecided.length} thread(s): ${undecided.map((item) => item.id).join(", ")}; no duplicate reply was sent.\n` +
26
+ "1. Inspect each complete thread transcript and verify whether the previous reply was delivered. If it was, rerun the same generated command with `--adopt-existing-replies`.\n" +
27
+ "2. For each thread you verified was not delivered, with no request still in flight, clear only that thread's markers:\n" +
28
+ undecided.map((item) => ` ${item.command}`).join("\n") +
29
+ "\n3. Rerun the original reply command; do not clear all PR state or change the disposition to bypass this check.");
30
+ }
24
31
  export async function assertReplyOutcomeKnown(context, ids, message) {
25
32
  await prepareUnmappedIntents(context, ids, message, paths);
26
33
  const pending = new Map();
@@ -56,6 +63,7 @@ export async function assertReplyOutcomeKnown(context, ids, message) {
56
63
  }
57
64
  return true;
58
65
  });
66
+ const undecided = [];
59
67
  for (let offset = 0; offset < pendingIds.length; offset += 10) {
60
68
  let evidence = new Map();
61
69
  try {
@@ -85,11 +93,8 @@ export async function assertReplyOutcomeKnown(context, ids, message) {
85
93
  ...new Set([...item.paths, ...(await paths(context, record.id, message))]),
86
94
  ];
87
95
  const command = `rm -- ${recoveryPaths.map((path) => `'${path.replaceAll("'", "'\\''")}'`).join(" ")}`;
88
- throw new Error(`Previous GraphQL reply outcome is uncertain for ${id}; no duplicate reply was sent.\n` +
89
- "1. Inspect the complete thread transcript and verify whether the previous reply was delivered.\n" +
90
- "2. If you verified non-delivery and no request remains in flight, clear only this reply's markers and run:\n" +
91
- ` ${command}\n` +
92
- "3. Rerun the original reply command; do not clear all PR state or change the disposition to bypass this check.");
96
+ undecided.push({ id, command });
97
+ continue;
93
98
  }
94
99
  // Keep confirmed outcomes durable: another pending ID or a later resolve can still fail.
95
100
  const outcomePaths = new Set([...item.paths, ...(await paths(context, record.id, message))]);
@@ -98,6 +103,8 @@ export async function assertReplyOutcomeKnown(context, ids, message) {
98
103
  adopted.push(id);
99
104
  }
100
105
  }
106
+ if (undecided.length)
107
+ throw new Error(uncertainMessage(undecided));
101
108
  await prepareUnmappedIntents(context, ids, message, paths);
102
109
  return adopted;
103
110
  }
@@ -1,30 +1,8 @@
1
- import { execFileSync } from "node:child_process";
2
1
  import { accessSync, constants, lstatSync, mkdirSync } from "node:fs";
3
- import { isAbsolute, join } from "node:path";
2
+ import { join } from "node:path";
4
3
  import { tmpdir } from "node:os";
5
4
  import { SAFE_PR_NUMBER, SAFE_SEGMENT } from "../util/path-segment.mjs";
6
5
  import { resolveDurableStateBase } from "./durable-state.mjs";
7
- /** Read once per process; null when the platform or `getconf` offers no per-user temp dir. */
8
- let darwinUserTempDir;
9
- /**
10
- * macOS's per-user temp dir, read from `confstr(_CS_DARWIN_USER_TEMP_DIR)` rather than
11
- * `TMPDIR`. Sandboxed agent shells point `TMPDIR` at their own directory, so the same user's
12
- * sandboxed CLI, unsandboxed CLI, and MCP server would otherwise keep separate state.
13
- */
14
- function readDarwinUserTempDir() {
15
- if (process.platform !== "darwin")
16
- return null;
17
- try {
18
- const dir = execFileSync("/usr/bin/getconf", ["DARWIN_USER_TEMP_DIR"], {
19
- encoding: "utf8",
20
- stdio: ["ignore", "pipe", "ignore"],
21
- }).trim();
22
- return isAbsolute(dir) ? dir : null;
23
- }
24
- catch {
25
- return null;
26
- }
27
- }
28
6
  /** Read once per process; null when the platform is not Linux or the shared base is unusable. */
29
7
  let linuxUserStateBase;
30
8
  /**
@@ -68,9 +46,7 @@ export function resolveStateBase() {
68
46
  linuxUserStateBase = readLinuxUserStateBase();
69
47
  if (linuxUserStateBase)
70
48
  return linuxUserStateBase;
71
- if (darwinUserTempDir === undefined)
72
- darwinUserTempDir = readDarwinUserTempDir();
73
- return join(darwinUserTempDir ?? tmpdir(), "pr-shepherd-state");
49
+ return join(tmpdir(), "pr-shepherd-state");
74
50
  }
75
51
  /**
76
52
  * `$PR_SHEPHERD_STATE_DIR/<owner>/<repo>/<pr>/...parts`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "2.2.5",
3
+ "version": "2.2.6",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for agentic coding tools",
5
5
  "keywords": [
6
6
  "automation",
@@ -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.5",
4
+ "version": "2.2.6",
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.2.5",
3
+ "version": "2.2.6",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for Codex.",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",