pr-shepherd 0.46.3 → 0.46.4

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": "0.46.3",
4
+ "version": "0.46.4",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
7
7
  "email": "jonathanrichardong@gmail.com"
@@ -11,6 +11,15 @@ export declare function buildCrStaleClause(reviews: Review[]): string;
11
11
  * discarding the rest of the user's config.
12
12
  */
13
13
  export declare function buildBehindBaseHintInstruction(baseBranch: string, hint: string, isBehind: boolean): string[];
14
+ /**
15
+ * Give one branch-refresh recovery path after Shepherd's single workflow rerun has failed.
16
+ * The fetched PR base branch is raw context; the caller still owns repository-specific git
17
+ * mechanics and decides whether the base contains a relevant fix.
18
+ */
19
+ export declare function buildRepeatedWorkflowBranchRecoveryInstructions(baseBranch: string, hasExhaustedWorkflowRerun: boolean, branch: {
20
+ isBehind: boolean;
21
+ hasConflicts: boolean;
22
+ }): string[];
14
23
  /**
15
24
  * Build the `Run the apply review: command` instruction. Steps stay here (not in the skill)
16
25
  * whenever the *unmodified, as-printed* command is unsafe without them:
@@ -20,6 +20,23 @@ export function buildBehindBaseHintInstruction(baseBranch, hint, isBehind) {
20
20
  return [];
21
21
  return [`The branch is behind PR base branch \`${baseBranch}\`. ${trimmedHint} before pushing.`];
22
22
  }
23
+ /**
24
+ * Give one branch-refresh recovery path after Shepherd's single workflow rerun has failed.
25
+ * The fetched PR base branch is raw context; the caller still owns repository-specific git
26
+ * mechanics and decides whether the base contains a relevant fix.
27
+ */
28
+ export function buildRepeatedWorkflowBranchRecoveryInstructions(baseBranch, hasExhaustedWorkflowRerun, branch) {
29
+ if (!hasExhaustedWorkflowRerun || (!branch.isBehind && !branch.hasConflicts))
30
+ return [];
31
+ const state = branch.hasConflicts ? "conflicts with" : "is behind";
32
+ const instructions = [
33
+ `The workflow rerun still fails while the branch ${state} PR base branch \`${baseBranch}\`. Inspect the current base branch for an existing fix before choosing a remediation.`,
34
+ ];
35
+ instructions.push(branch.hasConflicts
36
+ ? `Rebase or otherwise update the PR branch from \`${baseBranch}\` according to repository conventions, resolving conflicts as part of that update.`
37
+ : `Rebase or otherwise update the PR branch from \`${baseBranch}\` according to repository conventions.`);
38
+ return instructions;
39
+ }
23
40
  /**
24
41
  * Build the `Run the apply review: command` instruction. Steps stay here (not in the skill)
25
42
  * whenever the *unmodified, as-printed* command is unsafe without them:
@@ -180,7 +180,10 @@ export async function handleFixCode(ctx) {
180
180
  const allCommentIds = [...commentMinimizeIds, ...reviewSummaryIds];
181
181
  const belongsToActiveWorkflowRun = (check) => check.runId !== null && inProgressWorkflowRunIds.has(check.runId);
182
182
  const manualFollowUpChecks = failingAgentChecks.filter((check) => !belongsToActiveWorkflowRun(check) && checkRequiresHumanFollowUp(check));
183
+ const exhaustedAttempts = manualFollowUpChecks.filter((check) => check.runAttempt !== undefined && check.runAttempt > 1);
184
+ const hasBehindBaseRecovery = isBehind && exhaustedAttempts.length > 0;
183
185
  const hasAutonomousWork = hasConflicts ||
186
+ hasBehindBaseRecovery ||
184
187
  threads.length > 0 ||
185
188
  resolutionOnlyThreads.length > 0 ||
186
189
  actionableComments.length > 0 ||
@@ -194,7 +197,6 @@ export async function handleFixCode(ctx) {
194
197
  checks.some((check) => (check.annotations?.length ?? 0) > 0) ||
195
198
  failingAgentChecks.some((check) => belongsToActiveWorkflowRun(check) || !checkRequiresHumanFollowUp(check));
196
199
  if (manualFollowUpChecks.length > 0 && !hasAutonomousWork) {
197
- const exhaustedAttempts = manualFollowUpChecks.filter((check) => check.runAttempt !== undefined && check.runAttempt > 1);
198
200
  const checkSuggestion = exhaustedAttempts.length > 0
199
201
  ? `GitHub reports a later workflow attempt (${exhaustedAttempts
200
202
  .map((check) => `${check.runId ?? check.name}: attempt ${check.runAttempt}`)
@@ -257,7 +259,7 @@ export async function handleFixCode(ctx) {
257
259
  }
258
260
  const firstLookThreads = report.threads.firstLook;
259
261
  const firstLookComments = report.comments.firstLook;
260
- const instructions = buildFixInstructions(threads, actionableComments, checks, changesRequestedReviews, baseLookup.branch, resolveCommand, hasConflicts, prReference, cancelled.length, firstLookThreads, firstLookComments, firstLookSummaries, editedSummaries, inProgressRunIds, resolutionOnlyThreads, resolveOnlyCommand, behindBaseHint, isBehind, report.viewerAuthorization?.viewerCanUpdate === true);
262
+ const instructions = buildFixInstructions(threads, actionableComments, checks, changesRequestedReviews, baseLookup.branch, resolveCommand, hasConflicts, prReference, cancelled.length, firstLookThreads, firstLookComments, firstLookSummaries, editedSummaries, inProgressRunIds, resolutionOnlyThreads, resolveOnlyCommand, behindBaseHint, isBehind, report.viewerAuthorization?.viewerCanUpdate === true, exhaustedAttempts.length > 0);
261
263
  const prospectiveResult = {
262
264
  ...base,
263
265
  baseBranch: baseLookup.branch,
@@ -2,4 +2,4 @@ import type { AgentThread, AgentComment, AgentCheck, Review, ResolveCommand, Fir
2
2
  /** Render a resolve command as a shell snippet. Appends `--require-sha "$HEAD_SHA"` when set. */
3
3
  export declare function renderResolveCommand(rc: ResolveCommand): string;
4
4
  export declare function buildFixInstructions(threads: AgentThread[], actionableComments: AgentComment[], checks: AgentCheck[], changesRequestedReviews: Review[], baseBranch: string, resolveCommand: ResolveCommand, hasConflicts: boolean, prReference: string | number, cancelledCount: number, firstLookThreads?: FirstLookThread[], firstLookComments?: FirstLookComment[], firstLookSummaries?: Review[], editedSummaries?: Review[], inProgressRunIds?: string[], resolutionOnlyThreads?: ReviewThread[], resolveOnlyCommand?: ResolveCommand, behindBaseHint?: string, // iterate.behindBaseHint — see buildBehindBaseHintInstruction
5
- isBehind?: boolean, viewerCanUpdate?: boolean): string[];
5
+ isBehind?: boolean, viewerCanUpdate?: boolean, hasExhaustedWorkflowRerun?: boolean): string[];
@@ -1,5 +1,5 @@
1
1
  import { renderShellCommand } from "../../cli/runner.mjs";
2
- import { buildFailingCheckInstructions, buildCrStaleClause, buildBehindBaseHintInstruction, buildResolveCommandInstruction, buildFixCompletionInstruction, } from "./check-instructions.mjs";
2
+ import { buildFailingCheckInstructions, buildCrStaleClause, buildBehindBaseHintInstruction, buildRepeatedWorkflowBranchRecoveryInstructions, buildResolveCommandInstruction, buildFixCompletionInstruction, } from "./check-instructions.mjs";
3
3
  import { SHEPHERD_JOURNAL_FIRST_LOOK_GUIDANCE, buildShepherdJournalInstruction, } from "../shepherd-journal.mjs";
4
4
  import { isFailingAgentCheck } from "../../checks/conclusions.mjs";
5
5
  import { buildCommitSuggestionInstruction } from "../commit-suggestion-instruction.mjs";
@@ -11,11 +11,16 @@ export function renderResolveCommand(rc) {
11
11
  return renderShellCommand(parts);
12
12
  }
13
13
  export function buildFixInstructions(threads, actionableComments, checks, changesRequestedReviews, baseBranch, resolveCommand, hasConflicts, prReference, cancelledCount, firstLookThreads = [], firstLookComments = [], firstLookSummaries = [], editedSummaries = [], inProgressRunIds = [], resolutionOnlyThreads = [], resolveOnlyCommand, behindBaseHint = "", // iterate.behindBaseHint — see buildBehindBaseHintInstruction
14
- isBehind = false, viewerCanUpdate = false) {
14
+ isBehind = false, viewerCanUpdate = false, hasExhaustedWorkflowRerun = false) {
15
15
  const instructions = [];
16
16
  const locatedThreads = threads.filter((thread) => thread.path !== null && thread.line !== null);
17
17
  const unlocatedThreads = threads.filter((thread) => thread.path === null || thread.line === null);
18
18
  const failingChecks = checks.filter((c) => isFailingAgentCheck(c));
19
+ const repeatedWorkflowBranchRecoveryInstructions = buildRepeatedWorkflowBranchRecoveryInstructions(baseBranch, hasExhaustedWorkflowRerun, {
20
+ isBehind,
21
+ hasConflicts,
22
+ });
23
+ const hasRepeatedWorkflowBranchRecovery = repeatedWorkflowBranchRecoveryInstructions.length > 0;
19
24
  const hasAnnotations = checks.some((c) => (c.annotations?.length ?? 0) > 0);
20
25
  const hasNonConflictHints = threads.length > 0 ||
21
26
  failingChecks.length > 0 ||
@@ -41,7 +46,7 @@ isBehind = false, viewerCanUpdate = false) {
41
46
  const sectionRef = actionableSections.length > 0 ? `under ${actionableSections.join(", ")}` : "above";
42
47
  instructions.push(`Review each item ${sectionRef} and decide whether it needs a code change.`);
43
48
  }
44
- if (hasConflicts) {
49
+ if (hasConflicts && !hasRepeatedWorkflowBranchRecovery) {
45
50
  instructions.push("The branch has merge conflicts (see `**branch**` above). Resolve them before committing.");
46
51
  }
47
52
  const firstLookTotal = firstLookThreads.length + firstLookComments.length;
@@ -76,7 +81,7 @@ isBehind = false, viewerCanUpdate = false) {
76
81
  if (resolutionOnlyThreads.length > 0) {
77
82
  instructions.push('Review the threads under `## Review threads to resolve` before running mutations. Use the generated commands as shown — see "Review-mutation routing" in the pr-shepherd skill for which flag applies to which ID.');
78
83
  }
79
- instructions.push(...buildFailingCheckInstructions(failingChecks));
84
+ instructions.push(...buildFailingCheckInstructions(failingChecks), ...repeatedWorkflowBranchRecoveryInstructions);
80
85
  if (hasAnnotations) {
81
86
  instructions.push("Inspect every referenced range under `## Check annotations` and apply any warranted change.");
82
87
  }
@@ -90,6 +95,9 @@ isBehind = false, viewerCanUpdate = false) {
90
95
  if (hasConflicts) {
91
96
  instructions.push(`Commit any remaining conflict-resolution changes and push to the PR head branch${mutationSuffix}.`);
92
97
  }
98
+ else if (hasRepeatedWorkflowBranchRecovery) {
99
+ instructions.push("Push the updated PR head branch before iterating again.");
100
+ }
93
101
  else if (hasNonConflictHints) {
94
102
  instructions.push("If you changed code, commit any remaining changes and push to the PR head branch, then run the remaining review mutations using the pushed commit SHA and iterate again with the same options. If you did not change code, do not commit and continue with the remaining steps.");
95
103
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "0.46.3",
3
+ "version": "0.46.4",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for agentic coding tools",
5
5
  "keywords": [
6
6
  "automation",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pr-shepherd",
3
- "version": "0.46.3",
3
+ "version": "0.46.4",
4
4
  "description": "Autonomous PR CI monitor and review-comment resolver for Codex.",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
@@ -2,7 +2,7 @@
2
2
  "mcpServers": {
3
3
  "pr-shepherd": {
4
4
  "command": "npx",
5
- "args": ["--yes", "--package", "pr-shepherd@0.46.3", "pr-shepherd-mcp"]
5
+ "args": ["--yes", "--package", "pr-shepherd@0.46.4", "pr-shepherd-mcp"]
6
6
  }
7
7
  }
8
8
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "pr-shepherd": {
3
3
  "command": "npx",
4
- "args": ["--yes", "--package", "pr-shepherd@0.46.3", "pr-shepherd-mcp"]
4
+ "args": ["--yes", "--package", "pr-shepherd@0.46.4", "pr-shepherd-mcp"]
5
5
  }
6
6
  }
@@ -20,11 +20,11 @@ If the requested PR does not exist yet, review and commit the in-scope changes,
20
20
 
21
21
  1. Parse an optional PR number, repository-qualified `owner/repo#N`, or GitHub PR URL and an optional `--merge` flag from `$ARGUMENTS`; otherwise let pr-shepherd infer the current branch PR. Reject any remaining argument. Follow the target repository's local `AGENTS.md` and `CLAUDE.md` standards while making changes.
22
22
 
23
- 2. For the CLI, convert supplied `owner/repo#N` to `https://github.com/owner/repo/pull/N`; otherwise pass the supplied URL or bare number unchanged, then run the poll command `pr-shepherd` with the optional PR argument and forward `--merge` when supplied. A qualified reference may name a fork or upstream repository: it is the GitHub target, while the current checkout continues to supply local git/config/rules context. Do not run `pr-shepherd iterate`. If the CLI is unavailable and the `iterate` MCP tool is available, first obtain a repository-qualified reference: use a supplied GitHub PR URL or `owner/repo#N` unchanged; for a bare number, run `gh pr view <number> --json url --jq .url`; when omitted, run `gh pr view --json url --jq .url`. If that does not produce one qualified PR reference, stop and report that MCP cannot safely determine the PR. Otherwise call `iterate` with that qualified reference, plus `merge: true` when `--merge` was supplied, and print its full result.
23
+ 2. For the CLI, convert supplied `owner/repo#N` to `https://github.com/owner/repo/pull/N`; otherwise pass the supplied URL or bare number unchanged, then run the canonical poll command `pr-shepherd [PR] --until-terminal`, omitting `[PR]` when none was supplied and appending `--merge` when requested. This command keeps ordinary `[WAIT]` and `[MARK_READY]` ticks inside the same invocation; it returns for agent-facing work, a quota warning, `[CANCEL]`, or `[ESCALATE]`. A qualified reference may name a fork or upstream repository: it is the GitHub target, while the current checkout continues to supply local git/config/rules context. Do not run `pr-shepherd iterate`. If the CLI is unavailable and the `iterate` MCP tool is available, first obtain a repository-qualified reference: use a supplied GitHub PR URL or `owner/repo#N` unchanged; for a bare number, run `gh pr view <number> --json url --jq .url`; when omitted, run `gh pr view --json url --jq .url`. If that does not produce one qualified PR reference, stop and report that MCP cannot safely determine the PR. Otherwise call `iterate` with that qualified reference, plus `merge: true` when `--merge` was supplied, and print its full result.
24
24
 
25
25
  3. Print the full result and follow every returned `## Instructions` step exactly. For CLI output, run each printed mutation command when instructed. For MCP output, use MCP `apply` and `build_suggestion_patches` with the same qualified PR reference; do not run a shell `pr-shepherd apply` command.
26
26
 
27
- 4. After completing the returned instructions, repeat step 2 unless the action is `[CANCEL]` or `[ESCALATE]`, or the human directs you to stop. `[FIX_CODE]` is always non-terminal: complete its instructions and rerun the same canonical command without asking whether to continue. Only `[ESCALATE]` hands work to a human.
27
+ 4. After completing the returned instructions, repeat step 2 with the same target and canonical options unless the action is `[CANCEL]` or `[ESCALATE]`, or the human directs you to stop. Preserve `--until-terminal` and any requested `--merge`; apply any polling-cadence adjustment printed by the CLI. Every other action is non-terminal: complete its instructions and rerun without asking whether to continue. `[FIX_CODE]` is always non-terminal, and only `[ESCALATE]` hands work to a human.
28
28
 
29
29
  ## Playbooks
30
30