pr-shepherd 1.1.2 → 1.3.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.
- package/.claude-plugin/plugin.json +24 -2
- package/README.md +17 -17
- package/bin/classify/standard/coderabbit-notices.mjs +17 -1
- package/bin/classify/standard/codex-notices.mjs +5 -3
- package/bin/cli/iterate-instructions.mjs +3 -1
- package/bin/cli/iterate-lean.mjs +8 -1
- package/bin/cli/triage-formatter.mjs +5 -1
- package/bin/commands/check-annotations.d.mts +8 -0
- package/bin/commands/check-annotations.mjs +10 -0
- package/bin/commands/check.mjs +15 -11
- package/bin/commands/iterate/check-blocker-gate.d.mts +2 -0
- package/bin/commands/iterate/check-blocker-gate.mjs +3 -1
- package/bin/commands/iterate/check-instructions.d.mts +7 -1
- package/bin/commands/iterate/check-instructions.mjs +10 -3
- package/bin/commands/iterate/index.mjs +17 -7
- package/bin/commands/iterate/merge-plan.d.mts +2 -0
- package/bin/commands/iterate/merge-plan.mjs +5 -0
- package/bin/commands/iterate/merge-state.d.mts +10 -1
- package/bin/commands/iterate/merge-state.mjs +1 -1
- package/bin/commands/iterate/native-stack-rebase.d.mts +13 -2
- package/bin/commands/iterate/native-stack-rebase.mjs +23 -3
- package/bin/commands/iterate/queued-conflict-deferral.d.mts +15 -0
- package/bin/commands/iterate/queued-conflict-deferral.mjs +20 -0
- package/bin/commands/iterate/render.d.mts +2 -1
- package/bin/commands/iterate/render.mjs +18 -12
- package/bin/commands/iterate/rerun-command.d.mts +7 -0
- package/bin/commands/iterate/rerun-command.mjs +22 -0
- package/bin/commands/iterate/run.mjs +2 -1
- package/bin/commands/iterate/triage.d.mts +5 -1
- package/bin/commands/iterate/triage.mjs +32 -11
- package/bin/commands/poll-summary-explicit-instructions.mjs +3 -0
- package/bin/commands/poll-summary-instructions.mjs +1 -1
- package/bin/comments/resolve.d.mts +2 -0
- package/bin/comments/resolve.mjs +7 -0
- package/bin/comments/rest-review-mutations.d.mts +1 -0
- package/bin/comments/rest-review-mutations.mjs +3 -1
- package/bin/types/iterate.d.mts +2 -0
- package/bin/types/report.d.mts +2 -0
- package/package.json +2 -2
- package/plugins/pr-shepherd/.claude-plugin/icon.png +0 -0
- package/plugins/pr-shepherd/.claude-plugin/plugin.json +10 -2
- package/plugins/pr-shepherd/.codex-plugin/plugin.json +1 -1
- package/plugins/pr-shepherd/.codex.mcp.json +1 -1
- package/plugins/pr-shepherd/.mcp.json +1 -1
- package/plugins/pr-shepherd/hooks/hooks.json +16 -0
- package/plugins/pr-shepherd/hooks/poll-guard-detect.d.mts +11 -0
- package/plugins/pr-shepherd/hooks/poll-guard-detect.mjs +84 -0
- package/plugins/pr-shepherd/hooks/poll-guard.d.mts +15 -0
- package/plugins/pr-shepherd/hooks/poll-guard.mjs +76 -0
- package/plugins/pr-shepherd/package-lock.json +1278 -0
- package/plugins/pr-shepherd/package.json +9 -0
- package/plugins/pr-shepherd/skills/pr-shepherd/SKILL.md +10 -7
- package/plugins/pr-shepherd/skills/pr-shepherd/references/branch-update.md +1 -1
- package/plugins/pr-shepherd/skills/pr-shepherd/references/event-loop.md +1 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// PreToolUse hook for Claude Code and Codex: flags shell commands that poll
|
|
3
|
+
// GitHub PR or CI state instead of running one `pr-shepherd … --until-terminal`.
|
|
4
|
+
//
|
|
5
|
+
// Level: PR_SHEPHERD_POLL_GUARD, else the Claude Code plugin option `poll_guard`
|
|
6
|
+
// (CLAUDE_PLUGIN_OPTION_POLL_GUARD): `disabled`, `advisory` (default: the call
|
|
7
|
+
// runs and the agent gets a note), or `fail` (the call is blocked with the reason).
|
|
8
|
+
// Any unexpected error lets the call run.
|
|
9
|
+
|
|
10
|
+
import { readFileSync, statSync } from "node:fs";
|
|
11
|
+
import { isAbsolute, resolve } from "node:path";
|
|
12
|
+
import { pathToFileURL } from "node:url";
|
|
13
|
+
|
|
14
|
+
import { detectPoller, expandPath, guardMessage, readLevel } from "./poll-guard-detect.mjs";
|
|
15
|
+
|
|
16
|
+
const MAX_SCRIPT_BYTES = 64 * 1024;
|
|
17
|
+
|
|
18
|
+
/** Decides the hook result for one tool call. Returns { stdout, stderr, code }. */
|
|
19
|
+
export function runGuard(input, env, readText = readSmallFile) {
|
|
20
|
+
const { level, error } = readLevel({
|
|
21
|
+
PR_SHEPHERD_POLL_GUARD: env.PR_SHEPHERD_POLL_GUARD || env.CLAUDE_PLUGIN_OPTION_POLL_GUARD,
|
|
22
|
+
});
|
|
23
|
+
if (error) return { stdout: "", stderr: `${error}\n`, code: 1 };
|
|
24
|
+
if (level === "disabled") return { stdout: "", stderr: "", code: 0 };
|
|
25
|
+
|
|
26
|
+
const command = input?.tool_input?.command;
|
|
27
|
+
const cwd = typeof input?.cwd === "string" ? input.cwd : process.cwd();
|
|
28
|
+
const readScript = (path) => {
|
|
29
|
+
const expanded = expandPath(path, env);
|
|
30
|
+
return readText(isAbsolute(expanded) ? expanded : resolve(cwd, expanded));
|
|
31
|
+
};
|
|
32
|
+
const found = detectPoller(command, readScript);
|
|
33
|
+
if (!found) return { stdout: "", stderr: "", code: 0 };
|
|
34
|
+
|
|
35
|
+
const message = guardMessage(found);
|
|
36
|
+
const hookSpecificOutput =
|
|
37
|
+
level === "fail"
|
|
38
|
+
? {
|
|
39
|
+
hookEventName: "PreToolUse",
|
|
40
|
+
permissionDecision: "deny",
|
|
41
|
+
permissionDecisionReason: message,
|
|
42
|
+
}
|
|
43
|
+
: { hookEventName: "PreToolUse", additionalContext: message };
|
|
44
|
+
return { stdout: `${JSON.stringify({ hookSpecificOutput })}\n`, stderr: "", code: 0 };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Reads a regular file up to 64 KiB; returns null otherwise. */
|
|
48
|
+
export function readSmallFile(path) {
|
|
49
|
+
try {
|
|
50
|
+
const stat = statSync(path);
|
|
51
|
+
if (!stat.isFile() || stat.size > MAX_SCRIPT_BYTES) return null;
|
|
52
|
+
return readFileSync(path, "utf8");
|
|
53
|
+
} catch {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Parses hook stdin and runs the guard; never throws. */
|
|
59
|
+
export function main(stdinText, env) {
|
|
60
|
+
try {
|
|
61
|
+
return runGuard(JSON.parse(stdinText), env);
|
|
62
|
+
} catch {
|
|
63
|
+
return { stdout: "", stderr: "", code: 0 };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
68
|
+
const chunks = [];
|
|
69
|
+
process.stdin.on("data", (chunk) => chunks.push(chunk));
|
|
70
|
+
process.stdin.on("end", () => {
|
|
71
|
+
const result = main(Buffer.concat(chunks).toString("utf8"), process.env);
|
|
72
|
+
process.stdout.write(result.stdout);
|
|
73
|
+
process.stderr.write(result.stderr);
|
|
74
|
+
process.exitCode = result.code;
|
|
75
|
+
});
|
|
76
|
+
}
|