pr-shepherd 2.2.12 → 2.2.14

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.12",
4
+ "version": "2.2.14",
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
  }
@@ -401,10 +401,6 @@ async function recordReadyReceipt(key, report, context) {
401
401
  let summary;
402
402
  try {
403
403
  raw = await receiptSummaryForReport(key, report, context);
404
- const fresh = fingerprintRawSummaryPr(raw);
405
- if (fresh === null)
406
- return failed("fresh summary has no fingerprint");
407
- fingerprint = fresh;
408
404
  if (raw.state !== "OPEN")
409
405
  return failed(`fresh summary shows PR ${raw.state}, not OPEN`);
410
406
  if (raw.isDraft)
@@ -413,8 +409,13 @@ async function recordReadyReceipt(key, report, context) {
413
409
  return failed(`head moved (report ${short(report.headSha)}, fresh ${short(raw.headRefOid)})`);
414
410
  if (raw.baseRefOid !== report.baseRefOid)
415
411
  return failed(`base moved (report ${short(report.baseRefOid)}, fresh ${short(raw.baseRefOid)})`);
416
- // Summarize hydrates annotation totals onto the snapshot before the stored hash.
412
+ // Summarize hydrates annotation totals onto the snapshot; hash only after,
413
+ // so the stored hash matches the stack side's (which hashes hydrated evidence).
417
414
  summary = await summarizePollSummaryPr(raw, { owner: key.owner, name: key.repo }, { stackPrNumber: report.pr });
415
+ const fresh = fingerprintRawSummaryPr(raw);
416
+ if (fresh === null)
417
+ return failed("fresh summary has no fingerprint");
418
+ fingerprint = fresh;
418
419
  }
419
420
  catch (e) {
420
421
  // The receipt is supplementary evidence. A transient summary fetch failure
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "2.2.12",
3
+ "version": "2.2.14",
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.12",
4
+ "version": "2.2.14",
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.12",
3
+ "version": "2.2.14",
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 = {