pr-shepherd 2.2.13 → 2.2.15

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.13",
4
+ "version": "2.2.15",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
7
7
  "email": "jonathanrichardong@gmail.com"
@@ -29,7 +29,7 @@
29
29
  "poll_guard": {
30
30
  "type": "string",
31
31
  "title": "Poll guard",
32
- "description": "What to do when a shell command polls GitHub PR or CI state instead of running pr-shepherd: disabled, advisory (run it and tell the agent), or fail (block it). The PR_SHEPHERD_POLL_GUARD environment variable overrides this.",
32
+ "description": "What to do when a shell command polls GitHub PR or CI state instead of running pr-shepherd: disabled, advisory (run it and tell the agent), or fail (block it). The PR_SHEPHERD_POLL_GUARD environment variable overrides this. Piped or redirected pr-shepherd output is always blocked, whatever this is set to.",
33
33
  "default": "advisory"
34
34
  }
35
35
  }
package/README.md CHANGED
@@ -82,11 +82,12 @@ The plugin ships the skills, which drive the CLI, so install both.
82
82
 
83
83
  ```bash
84
84
  # Claude Code
85
- claude /plugin marketplace add jonathanong/pr-shepherd
86
- claude /plugin install pr-shepherd
85
+ claude plugin marketplace add jonathanong/harness-plugins
86
+ claude plugin install pr-shepherd@harness-plugins
87
87
 
88
- # Codex (then enable the pr-shepherd plugin)
89
- codex plugin marketplace add jonathanong/pr-shepherd
88
+ # Codex
89
+ codex plugin marketplace add jonathanong/harness-plugins --ref main
90
+ codex plugin add pr-shepherd@harness-plugins
90
91
 
91
92
  # Grok
92
93
  grok plugin marketplace add jonathanong/pr-shepherd
@@ -10,6 +10,7 @@ import snykNoIssues from "./snyk-no-issues.mjs";
10
10
  import socketReports from "./socket-reports.mjs";
11
11
  import sonarqubeGatePassed from "./sonarqube-gate-passed.mjs";
12
12
  import sourceryNotices from "./sourcery-notices.mjs";
13
+ import sourceryReviewGuide from "./sourcery-review-guide.mjs";
13
14
  /**
14
15
  * Bundled classification rules that `classify.standard` can enable by name.
15
16
  * Each rule matches conversation comments (`pr-comment`) only.
@@ -27,5 +28,6 @@ export const STANDARD_RULES = {
27
28
  "socket-reports": socketReports,
28
29
  "sonarqube-gate-passed": sonarqubeGatePassed,
29
30
  "sourcery-notices": sourceryNotices,
31
+ "sourcery-review-guide": sourceryReviewGuide,
30
32
  };
31
33
  export const STANDARD_RULE_NAMES = Object.keys(STANDARD_RULES);
@@ -1,4 +1,4 @@
1
1
  import type { ClassifyRule } from "../types.mts";
2
- /** Complete Sourcery private-repo upsell and weekly rate-limit notices. */
2
+ /** Complete Sourcery private-repo upsell, weekly rate-limit, and review-budget notices. */
3
3
  declare const rule: ClassifyRule;
4
4
  export default rule;
@@ -1,7 +1,11 @@
1
1
  import { isBotItem } from "./author.mjs";
2
2
  const NO_ACCESS = /^Hi @[A-Za-z0-9-]+! 👋\n\nYour private repo does not have access to Sourcery\.\n\nPlease \[upgrade\]\(https:\/\/app\.sourcery\.ai\/[^\s)]*\) to continue using Sourcery ✨$/;
3
3
  const RATE_LIMIT = /^Sorry @[A-Za-z0-9-]+, you have reached your weekly rate limit for Sourcery\. Please try again later\.$/;
4
- /** Complete Sourcery private-repo upsell and weekly rate-limit notices. */
4
+ const WAIT = String.raw `\d+ (?:days? and \d+ hours?|days?|hours? and \d+ minutes?|hours?|minutes?)`;
5
+ const REVIEW_BUDGET = new RegExp(String.raw `^Sorry @[A-Za-z0-9-]+, you've used your own review budget of \d{1,3}(?:,\d{3})* diff characters for the last \d+ days?\.` +
6
+ String.raw `\n\nYou can request another review in ${WAIT} by commenting \`@sourcery-ai review\`\. ` +
7
+ String.raw `\[Upgrade\]\(https:\/\/app\.sourcery\.ai\/[^\s)]*\) to get a review now\.$`);
8
+ /** Complete Sourcery private-repo upsell, weekly rate-limit, and review-budget notices. */
5
9
  const rule = (item) => {
6
10
  if (!isBotItem(item, ["sourcery-ai"], ["pr-comment"]))
7
11
  return null;
@@ -9,7 +13,7 @@ const rule = (item) => {
9
13
  if (NO_ACCESS.test(body)) {
10
14
  return { autoResolve: true, suppress: true, reason: "Sourcery no-access upsell" };
11
15
  }
12
- if (RATE_LIMIT.test(body)) {
16
+ if (RATE_LIMIT.test(body) || REVIEW_BUDGET.test(body)) {
13
17
  return { autoResolve: true, suppress: true, reason: "Sourcery rate-limit notice" };
14
18
  }
15
19
  return null;
@@ -0,0 +1,9 @@
1
+ import type { ClassifyRule } from "../types.mts";
2
+ /**
3
+ * Sourcery's "Reviewer's Guide" conversation comment: a summary of the PR's own diff with a tips
4
+ * section, edited in place on each push. The whole body must be one guide, framed by its start and
5
+ * end markers. Any content outside them, a second guide, or a marker of another kind (such as the
6
+ * linked-issues report, which can list unmet requirements) keeps it visible.
7
+ */
8
+ declare const rule: ClassifyRule;
9
+ export default rule;
@@ -0,0 +1,21 @@
1
+ import { isBotItem } from "./author.mjs";
2
+ const START = "<!-- Generated by sourcery-ai[bot]: start review_guide -->";
3
+ const END = "<!-- Generated by sourcery-ai[bot]: end review_guide -->";
4
+ const ANY_MARKER = /<!-- Generated by sourcery-ai\[bot\]: [^>]*-->/g;
5
+ /**
6
+ * Sourcery's "Reviewer's Guide" conversation comment: a summary of the PR's own diff with a tips
7
+ * section, edited in place on each push. The whole body must be one guide, framed by its start and
8
+ * end markers. Any content outside them, a second guide, or a marker of another kind (such as the
9
+ * linked-issues report, which can list unmet requirements) keeps it visible.
10
+ */
11
+ const rule = (item) => {
12
+ if (!isBotItem(item, ["sourcery-ai"], ["pr-comment"]))
13
+ return null;
14
+ const body = item.body.trim();
15
+ if (!body.startsWith(START) || !body.endsWith(END))
16
+ return null;
17
+ if ([...body.matchAll(ANY_MARKER)].length !== 2)
18
+ return null;
19
+ return { autoResolve: true, suppress: true, reason: "Sourcery Reviewer's Guide" };
20
+ };
21
+ export default rule;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "2.2.13",
3
+ "version": "2.2.15",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for agentic coding tools",
5
5
  "keywords": [
6
6
  "automation",
@@ -33,7 +33,6 @@
33
33
  "plugins/**/.codex-plugin/**",
34
34
  ".claude-plugin/**",
35
35
  ".grok-plugin/**",
36
- ".agents/plugins/marketplace.json",
37
36
  "marketplace.json",
38
37
  "pr-shepherd.schema.json",
39
38
  "README.md",
@@ -66,9 +65,9 @@
66
65
  "knip": "knip",
67
66
  "knip:production": "knip --production",
68
67
  "lint:dead-code": "npm run --silent knip && npm run --silent knip:production",
69
- "lint": "oxlint src/ test-helpers/ fixtures/*.mts test-cases/ plugins/ .agents/plugins/ site/build.mjs site/serve.mjs site/lib/ && npm run --silent lint:dead-code",
70
- "format": "oxfmt src/ test-helpers/ fixtures/*.mts test-cases/*.mts plugins/ .agents/plugins/ docs/ README.md site/build.mjs site/serve.mjs site/lib/",
71
- "format:check": "oxfmt --check src/ test-helpers/ fixtures/*.mts test-cases/*.mts plugins/ .agents/plugins/ docs/ README.md site/build.mjs site/serve.mjs site/lib/",
68
+ "lint": "oxlint src/ test-helpers/ fixtures/*.mts test-cases/ plugins/ site/build.mjs site/serve.mjs site/lib/ && npm run --silent lint:dead-code",
69
+ "format": "oxfmt src/ test-helpers/ fixtures/*.mts test-cases/*.mts plugins/ docs/ README.md site/build.mjs site/serve.mjs site/lib/",
70
+ "format:check": "oxfmt --check src/ test-helpers/ fixtures/*.mts test-cases/*.mts plugins/ docs/ README.md site/build.mjs site/serve.mjs site/lib/",
72
71
  "test": "vitest run",
73
72
  "test:coverage": "vitest run --coverage && node scripts/strip-lcov-branches.mjs",
74
73
  "test:watch": "vitest",
@@ -89,7 +88,7 @@
89
88
  "husky": "^9.1.7",
90
89
  "knip": "^6.14.1",
91
90
  "marked": "^18.0.11",
92
- "oxfmt": "^0.77.0",
91
+ "oxfmt": "^0.78.0",
93
92
  "oxlint": "^1.60.0",
94
93
  "typescript": "^7.0.2",
95
94
  "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.2.13",
4
+ "version": "2.2.15",
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.13",
3
+ "version": "2.2.15",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for Codex.",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
@@ -1,4 +1,6 @@
1
1
  export declare function isBalanced(text: string): boolean;
2
2
  export declare function splitCommands(masked: string): { text: string; term: "pipe" | "flow" }[];
3
3
  export declare function runsShepherd(words: string[]): boolean;
4
+ export declare function parseRedirects(text: string): { words: string[]; stdout: boolean };
5
+ export declare function redirectsStdout(text: string): boolean;
4
6
  export declare function pipesShepherd(command: unknown): boolean;
@@ -1,5 +1,6 @@
1
1
  // A small, conservative shell reader for the pipe guard. It answers one question:
2
- // is a pr-shepherd command's stdout certainly piped into another command? Anything
2
+ // is a pr-shepherd command's stdout certainly piped into another command or
3
+ // redirected to a file (`--help`, `-h`, and `--version` are exempt)? Anything
3
4
  // it cannot read with confidence (unbalanced quotes, odd syntax) answers "no".
4
5
 
5
6
  import { maskShell } from "./poll-guard-shell.mjs";
@@ -102,9 +103,33 @@ export function splitCommands(masked) {
102
103
  return parts;
103
104
  }
104
105
 
106
+ // One redirect: an optional fd, the operator, and its operand (up to the next operator).
107
+ const REDIRECT = /(\d*)(&>>?|>&|>\||>>?|<&|<<<?|<>?)\s*([^\s<>]*)/g;
108
+ const FD_OPERAND = /^[\d-]+$/;
109
+
110
+ /**
111
+ * Splits `text` into its words and redirects. Unquoted operators are separated from
112
+ * the words they touch (`pr-shepherd>out`). `stdout` is true when a redirect sends
113
+ * fd 1 to a file; `2>f`, `2>&1`, `>&2`, `>&-`, and input redirects do not.
114
+ */
115
+ export function parseRedirects(text) {
116
+ let stdout = false;
117
+ const rest = text.replace(REDIRECT, (_match, fd, op, operand, offset) => {
118
+ let prefix = "";
119
+ if (fd && offset > 0 && !/\s/.test(text[offset - 1])) {
120
+ prefix = fd; // digits glued to a word, such as `x1>f`, are not a descriptor
121
+ fd = "";
122
+ }
123
+ const toStdout =
124
+ op === "&>" || op === "&>>" || (op.startsWith(">") && (fd === "" || fd === "1"));
125
+ if (toStdout && !(op === ">&" && FD_OPERAND.test(operand))) stdout = true;
126
+ return `${prefix} `;
127
+ });
128
+ return { words: rest.split(/\s+/).filter(Boolean), stdout };
129
+ }
130
+
105
131
  /** The command's words after leading keywords and `VAR=value` assignments. */
106
- function commandWords(text) {
107
- const words = text.split(/\s+/).filter(Boolean);
132
+ function commandWords(words) {
108
133
  while (words.length > 0 && (ASSIGNMENT.test(words[0]) || LEADING_KEYWORDS.has(words[0]))) {
109
134
  words.shift();
110
135
  }
@@ -129,14 +154,24 @@ export function runsShepherd(words) {
129
154
  return args[0] !== undefined && isShepherd(args[0]);
130
155
  }
131
156
 
132
- /** True when a pr-shepherd invocation in `command` is certainly followed by a pipe. */
157
+ const EXEMPT_FLAGS = new Set(["--help", "-h", "--version"]);
158
+
159
+ /** True when the command text sends stdout to a file. `2>`, `2>&1`, and `>&2` do not. */
160
+ export function redirectsStdout(text) {
161
+ return parseRedirects(text).stdout;
162
+ }
163
+
164
+ /** True when a pr-shepherd invocation in `command` has its stdout piped or redirected to a file. */
133
165
  export function pipesShepherd(command) {
134
166
  if (typeof command !== "string" || !isBalanced(command)) return false;
135
167
  // A backslash-newline joins lines. Blank it (odd backslash runs only) before masking.
136
168
  const joined = command.replace(/(\\+)\n/g, (m, run) =>
137
169
  run.length % 2 === 1 ? `${run.slice(0, -1)} ` : m,
138
170
  );
139
- return splitCommands(maskShell(joined)).some(
140
- ({ text, term }) => term === PIPE && runsShepherd(commandWords(text)),
141
- );
171
+ return splitCommands(maskShell(joined)).some(({ text, term }) => {
172
+ const parsed = parseRedirects(text);
173
+ const words = commandWords(parsed.words);
174
+ if (!runsShepherd(words) || words.some((w) => EXEMPT_FLAGS.has(w))) return false;
175
+ return term === PIPE || parsed.stdout;
176
+ });
142
177
  }
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  // PreToolUse hook for Claude Code and Codex: flags shell commands that poll
3
3
  // GitHub PR or CI state instead of running one `pr-shepherd … --until-terminal`,
4
- // and always blocks a Bash command that certainly pipes pr-shepherd's output.
4
+ // and always blocks a Bash command that certainly pipes pr-shepherd's output or
5
+ // redirects it to a file (`--help`, `-h`, `--version` excepted).
5
6
  //
6
7
  // Level: PR_SHEPHERD_POLL_GUARD, else the Claude Code plugin option `poll_guard`
7
8
  // (CLAUDE_PLUGIN_OPTION_POLL_GUARD): `disabled`, `advisory` (default: the call
@@ -16,20 +17,20 @@ import { detectPoller, expandPath, guardMessage, readLevel } from "./poll-guard-
16
17
  import { pipesShepherd } from "./pipe-guard-parse.mjs";
17
18
 
18
19
  export const PIPE_DENY_REASON =
19
- "Piping pr-shepherd output drops its `## Instructions` section and the IDs you must act on; run pr-shepherd without a pipe and read the full output.";
20
+ "pr-shepherd: piping or redirecting Shepherd's output loses what you must act on: `## Instructions` comes last, the exit code is the action, and review bodies are shown only once. Run it without the pipe or redirect and read the full output; long output is expected.";
20
21
 
21
22
  const MAX_SCRIPT_BYTES = 64 * 1024;
22
23
 
23
24
  /** Decides the hook result for one tool call. Returns { stdout, stderr, code }. */
24
25
  export function runGuard(input, env, readText = readSmallFile) {
25
26
  // A piped pr-shepherd always denies, whatever the poll level. The substring check
26
- // is the cheap prefilter: most Bash commands mention neither `pr-shepherd` nor `|`.
27
+ // is the cheap prefilter: most Bash commands mention neither `pr-shepherd` nor `|` or `>`.
27
28
  const text = input?.tool_input?.command;
28
29
  if (
29
30
  input?.tool_name === "Bash" &&
30
31
  typeof text === "string" &&
31
32
  text.includes("pr-shepherd") &&
32
- text.includes("|") &&
33
+ /[|>]/.test(text) &&
33
34
  pipesShepherd(text)
34
35
  ) {
35
36
  const hookSpecificOutput = {
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: pr-shepherd
3
- description: 'Create, iterate, watch, or merge a GitHub pull request with pr-shepherd. Use for "make a PR and use pr-shepherd", "iterate PR #123", "tell me when #123 merges", and any PR status, CI, merge queue, or ejection question, instead of gh or custom polling scripts.'
3
+ description: 'Create, iterate, watch, or merge a GitHub pull request with pr-shepherd. Use for "make a PR and use pr-shepherd", "iterate PR #123", "tell me when #123 merges", and any PR status, CI, merge queue, or ejection question, instead of gh or custom polling scripts. Also use as soon as a merge or enqueue is refused or blocked (HTTP 405, a failing required check, "merge queue required"), or a PR turns out to have been removed or ejected from the merge queue.'
4
4
  user-invocable: true
5
5
  argument-hint: "[PR | stack PR...] [--merge|--merge-ready|--merge-through PR]"
6
6
  allowed-tools: Bash(npx pr-shepherd:*), Bash(pnpm exec pr-shepherd:*), Bash(pnpm dlx pr-shepherd:*), Bash(bunx pr-shepherd:*), Bash(pr-shepherd:*)
@@ -2,7 +2,7 @@
2
2
 
3
3
  Use a classification rule when the unwanted item has a recognizable author and message pattern. Inspect a representative item first so the rule does not hide other feedback from the same bot. Prefer an existing settings control for polling- or output-wide behavior.
4
4
 
5
- Check the bundled rules first. Under `classify.standard` in the active config file, `all: true` enables every rule, and a named boolean such as `codecov-report: false` overrides `all`. They cover vendor bot notices on conversation comments only: `claude-notices`, `coderabbit-notices`, `codecov-report`, `codex-notices`, `dependabot-notices`, `dependency-review-no-issues`, `gemini-notices`, `kilo-no-issues`, `snyk-no-issues`, `socket-reports`, `sonarqube-gate-passed`, and `sourcery-notices`. They do not match review summaries or inline review comments. Write a custom rule only when no bundled rule fits. If a name here is rejected as unknown, this list is stale for the installed version; trust the error.
5
+ Check the bundled rules first. Under `classify.standard` in the active config file, `all: true` enables every rule, and a named boolean such as `codecov-report: false` overrides `all`. They cover vendor bot notices on conversation comments only: `claude-notices`, `coderabbit-notices`, `codecov-report`, `codex-notices`, `dependabot-notices`, `dependency-review-no-issues`, `gemini-notices`, `kilo-no-issues`, `snyk-no-issues`, `socket-reports`, `sonarqube-gate-passed`, `sourcery-notices`, and `sourcery-review-guide`. They do not match review summaries or inline review comments. Write a custom rule only when no bundled rule fits. If a name here is rejected as unknown, this list is stale for the installed version; trust the error.
6
6
 
7
7
  Place an `.mjs` file in `.pr-shepherd/classification/` in the project. Shepherd uses the first classification directory on the working directory's ancestor chain; it stops at the home directory if reached, otherwise at the filesystem root. A home-level rule directory is not discovered when the project is outside the home tree. Rule directories do not merge. Files ending in `.ts`, `.mts`, `.mjs`, or `.js` load, except names beginning with `_` or `.`. Prefer `.mjs`; an `.mts` rule also works if it uses only erasable TypeScript syntax.
8
8
 
@@ -372,7 +372,8 @@
372
372
  "snyk-no-issues",
373
373
  "socket-reports",
374
374
  "sonarqube-gate-passed",
375
- "sourcery-notices"
375
+ "sourcery-notices",
376
+ "sourcery-review-guide"
376
377
  ]
377
378
  },
378
379
  "additionalProperties": {
@@ -1,20 +0,0 @@
1
- {
2
- "name": "pr-shepherd",
3
- "interface": {
4
- "displayName": "pr-shepherd"
5
- },
6
- "plugins": [
7
- {
8
- "name": "pr-shepherd",
9
- "source": {
10
- "source": "local",
11
- "path": "./plugins/pr-shepherd"
12
- },
13
- "policy": {
14
- "installation": "AVAILABLE",
15
- "authentication": "ON_INSTALL"
16
- },
17
- "category": "Coding"
18
- }
19
- ]
20
- }
@@ -1,18 +0,0 @@
1
- {
2
- "$schema": "https://anthropic.com/claude-code/marketplace.schema.json",
3
- "name": "pr-shepherd",
4
- "description": "Autonomous PR CI monitor and review-comment resolver",
5
- "owner": {
6
- "name": "Jonathan Ong",
7
- "email": "jonathanrichardong@gmail.com"
8
- },
9
- "plugins": [
10
- {
11
- "name": "pr-shepherd",
12
- "description": "Autonomous PR CI monitor and review-comment resolver",
13
- "source": "./plugins/pr-shepherd",
14
- "category": "productivity",
15
- "homepage": "https://github.com/jonathanong/pr-shepherd"
16
- }
17
- ]
18
- }