pr-shepherd 2.5.0 → 2.6.1

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.5.0",
4
+ "version": "2.6.1",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
7
7
  "email": "jonathanrichardong@gmail.com"
@@ -47,12 +47,12 @@ function stripChrome(body) {
47
47
  .replace(/^<!-- review_stack_entry_start -->[\s\S]*?<!-- review_stack_entry_end -->\s*/, "");
48
48
  }
49
49
  /** The "Review info" block that follows a progress notice: it opens with this summary line. */
50
- const REVIEW_INFO_START = /\n<details>\n<summary><strong>(?:<picture>(?:<source [^>\n]*>)*<img [^>\n]*><\/picture> )?Review info<\/strong><\/summary>\n/;
50
+ const REVIEW_INFO_START = /\n<details>\n<summary>(?:<strong>(?:<picture>(?:<source [^>\n]*>)*<img [^>\n]*><\/picture> )?Review info<\/strong>|Review info)<\/summary>\n/;
51
51
  /**
52
52
  * Lines the "Review info" block may hold: layout tags, picture-icon summaries, `- **Key**: value`
53
53
  * settings with CodeRabbit's known keys, file bullets, and the commit-range sentence. Any other line keeps the comment visible.
54
54
  */
55
- const REVIEW_INFO_LINE = /^(?:|<\/?details>|<\/?dl>|<\/?dd>|<br>|<summary><strong>(?:<picture>(?:<source [^>]*>)*<img [^>]*><\/picture> )?(?:Review info|Run configuration|Commits|Files selected for processing: \d+)<\/strong><\/summary>|- \*\*(?:Source mode|Repository|Branch|File|Commit|Layers|Review profile|Plan|Run ID)\*\*: [^<>\n]*|\* `[^`\n]+`|Reviewing files that changed from the base of the PR and between [a-f0-9]+ and [a-f0-9]+\.)$/;
55
+ const REVIEW_INFO_LINE = /^(?:|<\/?details>|<\/?dl>|<\/?dd>|<br>|<summary><strong>(?:<picture>(?:<source [^>]*>)*<img [^>]*><\/picture> )?(?:Review info|Run configuration|Commits|Files selected for processing: \d+)<\/strong><\/summary>|<summary>(?:Review info|Run configuration|Commits|Files selected for processing(?: \(\d+\)|: \d+))<\/summary>|\*\*(?:Run configuration|Commits|Files selected for processing(?: \(\d+\)|: \d+))\*\*|- \*\*(?:Source mode|Repository|Branch|File|Commit|Layers|Review profile|Plan|Run ID|Configuration used)\*\*: [^<>\n]*|\* `[^`\n]+`|Reviewing files that changed from the base of the PR and between [a-f0-9]+ and [a-f0-9]+\.)$/;
56
56
  /** Removes a trailing "Review info" block made only of known metadata lines. */
57
57
  function stripReviewInfo(quoted) {
58
58
  const start = quoted.search(REVIEW_INFO_START);
@@ -0,0 +1,19 @@
1
+ /** The `iterate.branch-update` setting: how a branch is brought up to date with its base. */
2
+ export type BranchUpdateMethod = "rebase" | "merge";
3
+ /** The configured method for a PR outside a native stack. */
4
+ export declare function configuredBranchUpdate(): BranchUpdateMethod;
5
+ /** Appended to every update step, so an agent never pulls an unrelated branch into the PR. */
6
+ declare const NEVER_MERGE_OTHER = "Never merge any other branch into the PR.";
7
+ /** The update itself, as an imperative sentence without its closing period. */
8
+ export declare function updateFromBase(method: BranchUpdateMethod, head?: string, baseBranch?: string): string;
9
+ /** The conflict-resolution step for a PR outside a native stack. */
10
+ export declare function resolveConflictsStep(method: BranchUpdateMethod): string;
11
+ /** The update of a PR head from the latest base, as a lowercase clause. */
12
+ export declare function updateHeadFromLatestBase(method: BranchUpdateMethod): string;
13
+ /** The update and push clause for a PR head after a merge-queue removal. */
14
+ export declare function updateAndPushClause(method: BranchUpdateMethod): string;
15
+ export { NEVER_MERGE_OTHER };
16
+ /** How to push the PR head after the update. */
17
+ export declare function pushHeadClause(method: BranchUpdateMethod): string;
18
+ /** The push after a merge-queue ejection: a rebased head needs a lease, a head only a fix changed does not. */
19
+ export declare function ejectionPushHeadClause(method: BranchUpdateMethod): string;
@@ -0,0 +1,39 @@
1
+ import { loadConfig } from "../../config/load.mjs";
2
+ /** The configured method for a PR outside a native stack. */
3
+ export function configuredBranchUpdate() {
4
+ return loadConfig().iterate["branch-update"];
5
+ }
6
+ /** Appended to every update step, so an agent never pulls an unrelated branch into the PR. */
7
+ const NEVER_MERGE_OTHER = "Never merge any other branch into the PR.";
8
+ /** The update itself, as an imperative sentence without its closing period. */
9
+ export function updateFromBase(method, head = "the branch", baseBranch) {
10
+ const base = baseBranch === undefined ? "the base branch" : `\`${baseBranch}\``;
11
+ return method === "rebase" ? `Rebase ${head} onto ${base}` : `Merge ${base} into ${head}`;
12
+ }
13
+ /** The conflict-resolution step for a PR outside a native stack. */
14
+ export function resolveConflictsStep(method) {
15
+ return `${updateFromBase(method)} and resolve each conflict keeping both sides' changes unless they contradict. ${NEVER_MERGE_OTHER}`;
16
+ }
17
+ /** The update of a PR head from the latest base, as a lowercase clause. */
18
+ export function updateHeadFromLatestBase(method) {
19
+ return method === "rebase"
20
+ ? "rebase the PR head onto the latest base"
21
+ : "merge the latest base into the PR head";
22
+ }
23
+ /** The update and push clause for a PR head after a merge-queue removal. */
24
+ export function updateAndPushClause(method) {
25
+ return `${updateHeadFromLatestBase(method)} and push it${method === "rebase" ? " with `--force-with-lease`" : ""}`;
26
+ }
27
+ export { NEVER_MERGE_OTHER };
28
+ /** How to push the PR head after the update. */
29
+ export function pushHeadClause(method) {
30
+ return method === "rebase"
31
+ ? "push to the PR head branch with `--force-with-lease`"
32
+ : "push to the PR head branch with a normal push";
33
+ }
34
+ /** The push after a merge-queue ejection: a rebased head needs a lease, a head only a fix changed does not. */
35
+ export function ejectionPushHeadClause(method) {
36
+ return method === "rebase"
37
+ ? "push to the PR head branch (`--force-with-lease` if you rebased it, a normal push if only a fix changed it)"
38
+ : pushHeadClause(method);
39
+ }
@@ -44,7 +44,7 @@ export declare function buildDismissReviewsCommandInstruction(dismissReviewsComm
44
44
  /** One pointer. Conclusion, rerun, and bare-check rules live in the CI playbook. */
45
45
  export declare function buildFailingCheckInstructions(checks: AgentCheck[]): string[];
46
46
  /** Update the PR branch after an external blocker merges or closes. Never rerun that job. */
47
- export declare function buildReleasedBlockerInstruction(prNumber: number): string;
47
+ export declare function buildReleasedBlockerInstruction(prNumber: number, stackRebase?: string): string;
48
48
  /** `iterate.review-output-max-chars` held review items back; the rerun step that follows shows them. */
49
49
  export declare function buildReviewSubsetInstruction(reviewItems: {
50
50
  shown: number;
@@ -1,4 +1,6 @@
1
1
  import { playbookPointer } from "../playbook-pointer.mjs";
2
+ import { stackRebaseAndPush } from "./native-stack-rebase.mjs";
3
+ import { configuredBranchUpdate, NEVER_MERGE_OTHER, pushHeadClause, updateFromBase, } from "./branch-update.mjs";
2
4
  // The `[TRIAGE]` heading and the skill already say the action is non-terminal.
3
5
  export const TRIAGE_CONTINUATION = "Rerun Shepherd now.";
4
6
  /** The final rerun step when a queued conflict offers both paths. */
@@ -48,8 +50,8 @@ export function buildRepeatedWorkflowBranchRecoveryInstructions(baseBranch, hasE
48
50
  ];
49
51
  instructions.push(stackRebase ??
50
52
  (branch.hasConflicts
51
- ? `Rebase or otherwise update the PR branch from \`${baseBranch}\` according to repository conventions, resolving conflicts as part of that update.`
52
- : `Rebase or otherwise update the PR branch from \`${baseBranch}\` according to repository conventions.`));
53
+ ? `${updateFromBase(configuredBranchUpdate(), "the PR branch", baseBranch)}, resolving conflicts as part of that update. ${NEVER_MERGE_OTHER}`
54
+ : `${updateFromBase(configuredBranchUpdate(), "the PR branch", baseBranch)}. ${NEVER_MERGE_OTHER}`));
53
55
  return instructions;
54
56
  }
55
57
  /**
@@ -90,10 +92,14 @@ export function buildFailingCheckInstructions(checks) {
90
92
  return [`Triage \`## Failing checks\`. ${playbookPointer("CI failure triage")}`];
91
93
  }
92
94
  /** Update the PR branch after an external blocker merges or closes. Never rerun that job. */
93
- export function buildReleasedBlockerInstruction(prNumber) {
94
- return getGithubTransport() === "rest"
95
- ? "Update this PR branch from its base using the repository's branch-update procedure. Do not rerun the job; a rerun retests the old merge ref."
96
- : `Update this PR branch from its base with \`gh pr update-branch ${prNumber} --rebase\`. Do not rerun the job; a rerun retests the old merge ref.`;
95
+ export function buildReleasedBlockerInstruction(prNumber, stackRebase) {
96
+ if (stackRebase)
97
+ return `${stackRebaseAndPush(stackRebase)} ${NEVER_MERGE_OTHER} Do not rerun the job; a rerun retests the old merge ref.`;
98
+ const method = configuredBranchUpdate();
99
+ const update = getGithubTransport() === "rest"
100
+ ? `${updateFromBase(method, "this PR branch")} and ${pushHeadClause(method)}`
101
+ : `${updateFromBase(method, "this PR branch")} with \`gh pr update-branch ${prNumber}${method === "rebase" ? " --rebase" : ""}\``;
102
+ return `${update}. ${NEVER_MERGE_OTHER} Do not rerun the job; a rerun retests the old merge ref.`;
97
103
  }
98
104
  /** `iterate.review-output-max-chars` held review items back; the rerun step that follows shows them. */
99
105
  export function buildReviewSubsetInstruction(reviewItems) {
@@ -36,6 +36,11 @@ export declare function buildNativeStackLayerRebase(repo: string, pr: {
36
36
  trunk: string;
37
37
  bottomPr?: number;
38
38
  }, stackBottomPr?: number): string | undefined;
39
+ /**
40
+ * The stack rebase followed by its push. An ownership boundary replaces the whole-stack push with
41
+ * the owned branches, or with no push at all when this PR has nothing it can restack alone.
42
+ */
43
+ export declare function stackRebaseAndPush(stackRebase: string): string;
39
44
  /**
40
45
  * Point at the conflicts, and at the stack rebase when the PR is a native stack layer. A queued
41
46
  * conflicting entry cannot form a merge group, so GitHub removes it once the queue reaches it.
@@ -1,6 +1,7 @@
1
1
  import { playbookPointer } from "../playbook-pointer.mjs";
2
2
  import { getGithubTransport } from "../../github/transport.mjs";
3
3
  import { boundedStackPush, boundedStackRebase } from "./stack-boundary.mjs";
4
+ import { configuredBranchUpdate, ejectionPushHeadClause, pushHeadClause, resolveConflictsStep, } from "./branch-update.mjs";
4
5
  /**
5
6
  * One gh-stack rebase step. A native stack layer must not be rebased or merged from its base
6
7
  * branch alone: that rewrites one branch and strands every layer above it.
@@ -70,10 +71,14 @@ export function buildNativeStackLayerRebase(repo, pr, stack, trunkConflict, stac
70
71
  return start && buildNativeStackRebaseInstruction(repo, stack.number, start);
71
72
  }
72
73
  /**
73
- * The branch-update route for a conflicting PR that is not a native stack layer. Rebase versus
74
- * merge is the repository's convention, so the step points at it instead of choosing.
74
+ * The stack rebase followed by its push. An ownership boundary replaces the whole-stack push with
75
+ * the owned branches, or with no push at all when this PR has nothing it can restack alone.
75
76
  */
76
- const RESOLVE_CONFLICTS = "Check the base branch's instructions (such as `AGENTS.md`) only for whether to rebase or merge, update the branch from its base that way, and resolve each conflict keeping both sides' changes unless they contradict.";
77
+ export function stackRebaseAndPush(stackRebase) {
78
+ const push = boundedStackPush() ??
79
+ `push the rewritten stack${getGithubTransport() === "rest" ? " using the repository's stack-update procedure" : " with `gh stack push`"}`;
80
+ return `${stackRebase} Then ${push}.`;
81
+ }
77
82
  /**
78
83
  * Point at the conflicts, and at the stack rebase when the PR is a native stack layer. A queued
79
84
  * conflicting entry cannot form a merge group, so GitHub removes it once the queue reaches it.
@@ -83,7 +88,7 @@ const RESOLVE_CONFLICTS = "Check the base branch's instructions (such as `AGENTS
83
88
  */
84
89
  export function buildConflictInstruction(stackRebase, dequeueCommand) {
85
90
  const pointer = "The branch has merge conflicts (see `**branch**` above).";
86
- const resolve = stackRebase ?? RESOLVE_CONFLICTS;
91
+ const resolve = stackRebase ?? resolveConflictsStep(configuredBranchUpdate());
87
92
  if (!dequeueCommand)
88
93
  return `${pointer} ${resolve}`;
89
94
  return `${pointer} ${buildQueuedConflictChoice(dequeueCommand, resolve, stackRebase !== undefined)}`;
@@ -115,12 +120,15 @@ export function buildBranchPushInstruction(stackRebase, hasConflicts, mutationSu
115
120
  if (ejectionUpdate) {
116
121
  const push = stackRebase
117
122
  ? "commit any remaining changes on the PR head branch and push the rewritten stack with `gh stack push`"
118
- : "commit any remaining changes and push to the PR head branch";
123
+ : `commit any remaining changes and ${ejectionPushHeadClause(configuredBranchUpdate())}`;
119
124
  return `If the base update or a fix changed the head, ${push}${mutationSuffix}. If neither did, do not push.`;
120
125
  }
121
126
  if (stackRebase)
122
127
  return `Commit any remaining changes on the PR head branch and push the rewritten stack with \`gh stack push\`${mutationSuffix}.`;
123
- return hasConflicts
124
- ? `Commit any remaining conflict-resolution changes and push to the PR head branch${mutationSuffix}.`
125
- : "Push the updated PR head branch before iterating immediately.";
128
+ const method = configuredBranchUpdate();
129
+ if (hasConflicts)
130
+ return `Commit any remaining conflict-resolution changes and ${pushHeadClause(method)}${mutationSuffix}.`;
131
+ return method === "rebase"
132
+ ? "Push the updated PR head branch with `--force-with-lease` before iterating immediately."
133
+ : "Push the updated PR head branch with a normal push before iterating immediately.";
126
134
  }
@@ -1,4 +1,5 @@
1
1
  /** Instruction text for a PR that GitHub removed from the merge queue after failed checks. */
2
+ import { configuredBranchUpdate, NEVER_MERGE_OTHER, updateHeadFromLatestBase, } from "./branch-update.mjs";
2
3
  import { playbookPointer } from "../playbook-pointer.mjs";
3
4
  /** The removed queue commit whose failed checks this tick surfaces, if the removal is current. */
4
5
  export function currentEjectionCommit(report, checks) {
@@ -23,14 +24,16 @@ export function queueEjectionSteps(recovery, stackRebase, routePrinted, hasElsew
23
24
  * removal reason, since a person's dequeue must not be undone by a branch update.
24
25
  */
25
26
  function buildQueueEjectionInstruction(recovery, stackRoute, hasElsewhere = false) {
26
- const target = stackRoute ? "the stack" : "the PR head";
27
- const route = stackRoute ? `: ${stackRoute}` : ".";
27
+ const method = configuredBranchUpdate();
28
+ const updateClause = stackRoute
29
+ ? `update the stack from the latest base first: ${stackRoute}`
30
+ : `${updateHeadFromLatestBase(method)} first. ${NEVER_MERGE_OTHER}`;
28
31
  const elsewhere = hasElsewhere
29
32
  ? " Check `Same workflow elsewhere` under `## Failing checks` for recent runs of this workflow on the default branch and other merge-queue entries."
30
33
  : "";
31
34
  const update = recovery === "none"
32
- ? `If the \`**queue removal**\` reason shows GitHub removed the entry itself, update ${target} from the latest base first${route} If a person may have dequeued the PR, skip that update unless a conflict step above requires it.`
33
- : `Update ${target} from the latest base first${route}`;
35
+ ? `If the \`**queue removal**\` reason shows GitHub removed the entry itself, ${updateClause} If a person may have dequeued the PR, skip that update unless a conflict step above requires it.`
36
+ : `${updateClause.charAt(0).toUpperCase()}${updateClause.slice(1)}`;
34
37
  const reproduce = "only if the failure does not reproduce on the updated head, neither the update nor a code change altered the head, and no other blocker remains.";
35
38
  const guard = recovery === "requeue"
36
39
  ? `Run \`requeue:\` ${reproduce} If gh reports auto-merge is disabled, run \`requeue API fallback:\` instead.`
@@ -1,5 +1,6 @@
1
1
  import { formatPrUrl } from "../../pr-reference.mjs";
2
2
  import { queueRemovalSignature, readQueueRemovalFollowUp, writeQueueRemovalFollowUp, } from "../../state/queue-removal-follow-up.mjs";
3
+ import { configuredBranchUpdate, NEVER_MERGE_OTHER, updateAndPushClause, } from "./branch-update.mjs";
3
4
  import { playbookPointer } from "../playbook-pointer.mjs";
4
5
  import { buildEscalateHumanMessage, buildEscalateSuggestion } from "./escalate.mjs";
5
6
  import { stateUnavailableResult } from "./state-unavailable.mjs";
@@ -8,7 +9,7 @@ function buildQueueRemovalInstructions(report) {
8
9
  const route = stackRebase(report);
9
10
  const update = route
10
11
  ? `update the stack from the latest base (${route}) and push it`
11
- : "update the PR head from the latest base and push";
12
+ : `${updateAndPushClause(configuredBranchUpdate())}. ${NEVER_MERGE_OTHER}`;
12
13
  return [
13
14
  `GitHub removed PR #${report.pr} from the merge queue, and Shepherd has no failed queue-commit check to triage. The \`**queue removal**\` line above carries the raw reason and actor.`,
14
15
  `Decide from them. If the reason names a merge conflict, an invalid merge commit, or a stack that changed, ${update}. If a person dequeued the PR (the actor is a user, not a bot or \`github-actions\`), make no change and report that. If the reason is missing or unclear, find out why before acting. Never enqueue the PR yourself. ${playbookPointer("Merge queue ejection")}`,
@@ -1,5 +1,6 @@
1
1
  import { readStackTopology, stackAncestryGaps } from "../../github/stack-read.mjs";
2
2
  import { buildNativeStackRebaseInstruction } from "./native-stack-rebase.mjs";
3
+ import { boundedStackPush } from "./stack-boundary.mjs";
3
4
  import { getGithubTransport } from "../../github/transport.mjs";
4
5
  /**
5
6
  * Find a stale immediate parent boundary for one PR.
@@ -32,13 +33,17 @@ export async function findStaleNativeStackAncestry(report, repo, context) {
32
33
  }
33
34
  /** Build the one-PR repair guidance after a stale boundary was verified. */
34
35
  function buildStaleNativeStackAncestryInstructions(repo, stackNumber, ancestry) {
36
+ // An ownership boundary forbids `gh stack push`, which would publish unowned layers.
37
+ const bounded = boundedStackPush();
35
38
  return [
36
39
  `PR #${ancestry.childPr} records base \`${ancestry.childBaseRefName}\` at \`${ancestry.childBaseRefOid}\`, but its open parent PR #${ancestry.parentPr} currently ends at \`${ancestry.parentHeadRefName}\` \`${ancestry.parentHeadRefOid}\`.`,
37
40
  buildNativeStackRebaseInstruction(`${repo.owner}/${repo.name}`, stackNumber, {
38
41
  parentBranch: ancestry.parentHeadRefName,
39
42
  }),
40
- getGithubTransport() === "rest"
41
- ? "Push every affected stack branch using the repository's stack-update procedure."
42
- : "Push the rewritten stack with `gh stack push`.",
43
+ bounded !== undefined
44
+ ? `${bounded.charAt(0).toUpperCase()}${bounded.slice(1)}.`
45
+ : getGithubTransport() === "rest"
46
+ ? "Push every affected stack branch using the repository's stack-update procedure."
47
+ : "Push the rewritten stack with `gh stack push`.",
43
48
  ];
44
49
  }
@@ -388,7 +388,7 @@ async function handleTriageTick(ctx) {
388
388
  };
389
389
  if (failingAgentChecks.some((check) => releasedCheckNames.has(check.name))) {
390
390
  const completion = instructions.pop();
391
- instructions.push(pathA(buildReleasedBlockerInstruction(prNumber)));
391
+ instructions.push(pathA(buildReleasedBlockerInstruction(prNumber, buildNativeStackLayerRebase(report.repo, { number: prNumber, baseBranch: baseLookup.unusable ? undefined : baseLookup.branch }, stack, trunkConflict, report.stackBottomPr))));
392
392
  if (completion !== undefined)
393
393
  instructions.push(completion);
394
394
  }
@@ -3,7 +3,8 @@ import { formatPrUrl } from "../../pr-reference.mjs";
3
3
  import { readCiRetrigger, sameCiRetrigger, writeCiRetrigger } from "../../state/ci-retrigger.mjs";
4
4
  import { buildFixCompletionInstruction } from "./check-instructions.mjs";
5
5
  import { buildEscalateHumanMessage, buildEscalateSuggestion } from "./escalate.mjs";
6
- import { buildNativeStackRebaseInstruction } from "./native-stack-rebase.mjs";
6
+ import { buildNativeStackRebaseInstruction, stackRebaseAndPush } from "./native-stack-rebase.mjs";
7
+ import { configuredBranchUpdate, NEVER_MERGE_OTHER, pushHeadClause, updateFromBase, } from "./branch-update.mjs";
7
8
  import { playbookPointer } from "../playbook-pointer.mjs";
8
9
  import { getGithubTransport } from "../../github/transport.mjs";
9
10
  /** Rebase when the trunk or the PR base is behind; otherwise close and reopen once. */
@@ -39,12 +40,13 @@ function buildUnreportedRequiredInstructions(input) {
39
40
  `If the cause is within this PR, fix it and push. If the workflows should have run and the PR is fine, retrigger once: ${retrigger}. Otherwise make no change and keep what you found. If the checks are still missing on the next poll, Shepherd escalates with \`required-checks-unreported\`; report that diagnosis then.`,
40
41
  ];
41
42
  }
43
+ const method = configuredBranchUpdate();
42
44
  const rebase = input.stackRebase
43
- ? `${input.stackRebase} Then push the rewritten stack${getGithubTransport() === "rest" ? " using the repository's stack-update procedure" : " with `gh stack push`"}.`
44
- : `Rebase onto \`${input.baseBranch}\` and push.`;
45
+ ? stackRebaseAndPush(input.stackRebase)
46
+ : `${updateFromBase(method, "the branch", input.baseBranch)} and ${pushHeadClause(method)}. ${NEVER_MERGE_OTHER}`;
45
47
  return [
46
48
  facts,
47
- `${rebase} Rebase and push is how these checks start.`,
49
+ `${rebase} Updating and pushing is how these checks start.`,
48
50
  `If that push does not start the checks, find out why nothing started. ${playbook} Shepherd escalates with \`required-checks-unreported\` when the branch is current and this remains the only blocker.`,
49
51
  ];
50
52
  }
@@ -31,6 +31,10 @@ export declare const configSchema: z.ZodObject<{
31
31
  none: "none";
32
32
  }>>;
33
33
  "behind-base-hint": z.ZodDefault<z.ZodString>;
34
+ "branch-update": z.ZodDefault<z.ZodEnum<{
35
+ merge: "merge";
36
+ rebase: "rebase";
37
+ }>>;
34
38
  "review-output-max-chars": z.ZodDefault<z.ZodNumber>;
35
39
  "resolve-other-human-threads": z.ZodDefault<z.ZodEnum<{
36
40
  always: "always";
@@ -122,6 +126,10 @@ export declare const configFileSchema: z.ZodObject<{
122
126
  none: "none";
123
127
  }>>;
124
128
  "behind-base-hint": z.ZodDefault<z.ZodString>;
129
+ "branch-update": z.ZodDefault<z.ZodEnum<{
130
+ merge: "merge";
131
+ rebase: "rebase";
132
+ }>>;
125
133
  "review-output-max-chars": z.ZodDefault<z.ZodNumber>;
126
134
  "resolve-other-human-threads": z.ZodDefault<z.ZodEnum<{
127
135
  always: "always";
@@ -120,6 +120,7 @@ export const configSchema = z.strictObject({
120
120
  "minimize-superseded-approvals": z.boolean().default(true),
121
121
  "minimize-comments": z.enum(["all", "bots", "none"]).default("bots"),
122
122
  "behind-base-hint": z.string().default(""),
123
+ "branch-update": z.enum(["rebase", "merge"]).default("rebase"),
123
124
  "review-output-max-chars": z.number().int().nonnegative().default(50000),
124
125
  "resolve-other-human-threads": z.enum(["none", "outdated", "always"]).default("none"),
125
126
  instructions: z.enum(["inline", "playbook"]).default("inline"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "2.5.0",
3
+ "version": "2.6.1",
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.5.0",
4
+ "version": "2.6.1",
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.5.0",
3
+ "version": "2.6.1",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for Codex.",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
@@ -15,7 +15,7 @@ allowed-tools: Bash(npx pr-shepherd:*), Bash(pnpm exec pr-shepherd:*), Bash(pnpm
15
15
  - `$ARGUMENTS`: PR numbers, PR URLs, or `'owner/repo#N'` (quoted), or `stack PR...` / `stack owner/repo#N` (the number owns all layers), plus one optional merge flag: `--merge`, `--merge-ready`, `--merge-through PR`; reject anything else. Use `stack` only when asked or routed. With no PR, pass none. A qualified PR picks the GitHub target; this checkout supplies git and config.
16
16
  - Add a merge flag only when the user asks to merge, land, enqueue, or requeue. A stack or PR named with no such request ("the stack", "#N", a URL) gets no merge flag: shepherd it to ready, report, and leave the merge to them. A merge flag, or a request to merge, land, enqueue, or requeue after an ejection, allows the printed merge/enqueue/dequeue commands. Run Shepherd first: never merge, enqueue or retarget with `gh` or a GitHub MCP tool before Shepherd prints that step. Run them without asking again; escalate only when the host requires it.
17
17
  - Only when asked to merge: "merge the stack" -> `stack owner/repo#N --merge` (given only a PR, `stack PR --merge`, then on `unowned-stack-layers` run its printed stack-number command); "merge them as they're ready"/"drain" -> `--merge-ready`; "merge #N" -> one-PR `--merge`, but if they claim other layers or say "up to #N" -> `stack <claimed PRs incl. N> --merge-through N`; "ship it" -> ask.
18
- - Follow printed branch-update steps without asking: rebase or merge the base, resolve conflicts, push your own PR head with `--force-with-lease`.
18
+ - Follow printed branch-update steps without asking: update the branch the way the step names (a rebase, or a merge of the base when the repository configured `iterate.branch-update: merge`), resolve conflicts, push your own PR head (`--force-with-lease` after a rebase, a normal push after a merge). Never merge any other branch into the PR.
19
19
  - Run `pr-shepherd [PR ...]` or `pr-shepherd stack PR...`, plus any merge flag, with `--until-terminal` in the background only if its exit wakes you, else in the foreground ([Waiting](references/waiting.md)). Requeue commands print only under `--merge`. PRs with the same flags share one command; if the set changes, stop and rerun with the new list. Do not run `pr-shepherd iterate`, except once for a one-time status question.
20
20
  - Print the full result and follow every `## Instructions` step with every ID it lists. When a step says `Playbook: "<name>"`, read that playbook once.
21
21
 
@@ -2,12 +2,12 @@
2
2
 
3
3
  Apply when a step says `Playbook: "Merge queue ejection"`. The `**queue removal**` header names the queue commit. That commit combined the PR head with the base and any entries queued ahead of it, so a failure there may come from this PR, the base, another entry, or a flake. Do not requeue without triage. After triage, continue with the remaining numbered steps; iterate only at the final step.
4
4
 
5
- 1. If the step names a failed queue-commit check, inspect any `Same workflow elsewhere` runs under `## Failing checks` first; if the failure is already failing on the base branch itself, follow step 4 instead of updating the head. Otherwise, update the PR head from the latest base following the repository's branch-update convention (on a native stack, use the printed stack update route instead) and reproduce the failing step on the updated head.
5
+ 1. If the step names a failed queue-commit check, inspect any `Same workflow elsewhere` runs under `## Failing checks` first; if the failure is already failing on the base branch itself, follow step 4 instead of updating the head. Otherwise, update the PR head from the latest base the way the step names, rebase or merge (on a native stack, use the printed stack update route instead) and reproduce the failing step on the updated head.
6
6
  2. If the failure belongs to this PR, fix it. The printed push step commits and pushes the fix.
7
7
  3. If the failure does not reproduce and the update changed the head, the printed push step pushes it (`gh stack push` on a native stack). Never run a printed `requeue:` or `acknowledge queue removal:` command after a push. Shepherd prints a fresh queue command once the new head is READY.
8
8
  4. If the failure comes from the base itself, do not requeue or acknowledge it. Make no change. The unchanged failure escalates through the stall timeout.
9
9
  5. If the removal reason suggests a person dequeued the PR, skip the step 1 update unless a conflict step requires it. Fix a failure that belongs to this PR; otherwise make no change. Never enqueue.
10
- 6. If the step names a removal with no failed queue-commit check, the `**queue removal**` header carries the raw reason and actor. A conflict-style reason (`merge_conflict`, `invalid_merge_commit`, `stack_invalidated`) means update the head from the base following the same branch-update convention (printed stack route on a native stack) and push. A person's dequeue means make no change and report it. Otherwise find out why before acting. Never enqueue. If the head is unchanged on the next poll, Shepherd escalates.
10
+ 6. If the step names a removal with no failed queue-commit check, the `**queue removal**` header carries the raw reason and actor. A conflict-style reason (`merge_conflict`, `invalid_merge_commit`, `stack_invalidated`) means update the head from the base the same way (printed stack route on a native stack) and push. A person's dequeue means make no change and report it. Otherwise find out why before acting. Never enqueue. If the head is unchanged on the next poll, Shepherd escalates.
11
11
  7. If the step says no queue command was printed, never enqueue. A failure that does not reproduce follows step 4. Shepherd prints no queue command once the same head was already removed before (`removals on this head` in the header), so a flaky failure is not retried indefinitely.
12
12
  8. Otherwise, run the printed `requeue:` or `acknowledge queue removal:` command exactly as printed, and only if all of these hold:
13
13
  - the head did not change;
@@ -3,7 +3,7 @@
3
3
  Apply when a step says `Playbook: "Triage loop"`. It replaces the commit and push procedure that `--instructions=inline` prints on every `[TRIAGE]` tick. Run the numbered steps in `## Instructions` in order; this is the one that names it.
4
4
 
5
5
  - Review and fix first. Decide per item whether it needs a code change; the reply and resolve mutations are generated either way.
6
- - Commit and push. If you changed any files (code, docs, or config), commit them and push to the PR head branch. If you did not, do not commit. The repository's pre-push hooks and `AGENTS.md` own lint, typecheck, and format, and its conventions own rebase style and push flags.
6
+ - Commit and push. If you changed any files (code, docs, or config), commit them and push to the PR head branch. If you did not, do not commit. The repository's pre-push hooks and `AGENTS.md` own lint, typecheck, and format, and the printed branch-update step owns whether to rebase or merge and the push flags.
7
7
  - The `apply review` step stays inline because it needs `$CHANGE_MESSAGE` substitution. Push first: its `--require-sha HEAD` must read the pushed SHA.
8
8
  - `[TRIAGE]` is non-terminal. After the last step, iterate again immediately with the same options. Only `[ESCALATE]` hands work to a human, and `[CANCEL]` ends polling.
9
9
  - Playbooks named by other steps (`Playbook: "<name>"`) ship with the package. Without the skill, print one with `pr-shepherd playbook "<name>"`.
@@ -140,6 +140,14 @@
140
140
  "default": "",
141
141
  "type": "string"
142
142
  },
143
+ "branch-update": {
144
+ "default": "rebase",
145
+ "type": "string",
146
+ "enum": [
147
+ "rebase",
148
+ "merge"
149
+ ]
150
+ },
143
151
  "review-output-max-chars": {
144
152
  "default": 50000,
145
153
  "type": "integer",