pr-shepherd 0.46.4 → 0.46.6

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.
Files changed (40) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +5 -2
  3. package/bin/api.d.mts +1 -1
  4. package/bin/checks/triage.mjs +12 -1
  5. package/bin/cli/api-usage-formatter.mjs +1 -1
  6. package/bin/cli/body-truncate.d.mts +12 -0
  7. package/bin/cli/body-truncate.mjs +123 -0
  8. package/bin/cli/fix-formatter-extra.d.mts +2 -1
  9. package/bin/cli/fix-formatter-extra.mjs +18 -3
  10. package/bin/cli/fix-formatter.d.mts +3 -1
  11. package/bin/cli/fix-formatter.mjs +39 -13
  12. package/bin/cli/iterate-checks-formatter.mjs +8 -6
  13. package/bin/cli/iterate-formatter.mjs +10 -9
  14. package/bin/cli/iterate-instructions.mjs +3 -3
  15. package/bin/cli/iterate-lean.mjs +2 -0
  16. package/bin/cli/iterate-merge-formatter.d.mts +3 -1
  17. package/bin/cli/iterate-merge-formatter.mjs +15 -0
  18. package/bin/cli/list-formatters.d.mts +4 -3
  19. package/bin/cli/list-formatters.mjs +22 -14
  20. package/bin/commands/check-annotations.d.mts +15 -0
  21. package/bin/commands/check-annotations.mjs +23 -1
  22. package/bin/commands/check.d.mts +1 -0
  23. package/bin/commands/check.mjs +68 -32
  24. package/bin/commands/iterate/check-instructions.mjs +4 -4
  25. package/bin/commands/iterate/index.mjs +18 -5
  26. package/bin/commands/iterate/merge-state.d.mts +6 -1
  27. package/bin/commands/iterate/merge-state.mjs +42 -1
  28. package/bin/commands/iterate/render.mjs +2 -2
  29. package/bin/config/load.d.mts +10 -0
  30. package/bin/config/load.mjs +17 -1
  31. package/bin/config.json +4 -2
  32. package/bin/mcp/server.mjs +18 -6
  33. package/bin/quota-warning.mjs +1 -1
  34. package/bin/types/iterate.d.mts +10 -0
  35. package/bin/types/merge-queue.d.mts +16 -0
  36. package/package.json +9 -6
  37. package/plugins/pr-shepherd/.codex-plugin/plugin.json +1 -1
  38. package/plugins/pr-shepherd/.codex.mcp.json +1 -1
  39. package/plugins/pr-shepherd/.mcp.json +1 -1
  40. package/plugins/pr-shepherd/skills/pr-shepherd/SKILL.md +11 -11
@@ -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.4",
4
+ "version": "0.46.6",
5
5
  "author": {
6
6
  "name": "Jonathan Ong",
7
7
  "email": "jonathanrichardong@gmail.com"
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Autonomous PR CI monitor and review-comment resolver for agentic coding tools, including Claude Code and Codex.
4
4
 
5
+ **[jongleberry.com/pr-shepherd](https://jongleberry.com/pr-shepherd/)** — the why and the principles behind the design, for humans and agents.
6
+
5
7
  ## Why
6
8
 
7
9
  An agent finishing a PR should think about code, not reconstruct GitHub state or invent a next-step policy each tick. Without Shepherd it fans out across GitHub MCP, `gh`, and GraphQL, then guesses what to do with the result.
@@ -69,12 +71,12 @@ Conversations Resolved: No [Not Required]
69
71
  1. Review each item under `## Review threads` and `## Failing checks` and decide whether it needs a code change.
70
72
  2. Apply every warranted review fix in each file referenced above.
71
73
  3. Triage every failure under `## Failing checks`. See "CI failure triage" in the pr-shepherd skill for read-only inspection rules.
72
- 4. If you changed code, commit any remaining changes and push to the PR head branch, then run 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.
74
+ 4. If you changed code, commit any remaining changes and push to the PR head branch, then run review mutations using the pushed commit SHA and iterate immediately with the same options. If you did not change code, do not commit and continue.
73
75
  5. Run the generated thread IDs unchanged. A latest comment beginning `<!-- pr-shepherd -->` is an earlier Shepherd reply: a marked viewer-authored human thread is emitted resolve-only when authorized, while a marked other-human thread is already acknowledged and has no further mutation.
74
76
  6. If you did not change code, replace `$HEAD_SHA` with `$(git rev-parse HEAD)`, which must equal the current remote PR head. If you changed code, commit and push to the PR head branch first, then replace `$HEAD_SHA` with the pushed commit SHA.
75
77
  7. Replace `$DISMISS_MESSAGE` with one sentence describing what changed.
76
78
  8. Run the `apply review:` command shown above. See "Review-mutation mechanics" in the pr-shepherd skill for dismiss-ID retention.
77
- 9. `[FIX_CODE]` is non-terminal: if you changed code, commit and push to the PR head branch, then run review mutations using the pushed commit SHA and iterate again with the same options; without code changes, complete the authorized review mutations and iterate again.
79
+ 9. `[FIX_CODE]` is non-terminal: if you changed code, commit and push to the PR head branch, then run review mutations using the pushed commit SHA and iterate immediately with the same options; without code changes, complete the authorized review mutations and iterate immediately.
78
80
  ```
79
81
 
80
82
  See [docs/actions.md](docs/actions.md) for the complete output contract and [docs/escalations.md](docs/escalations.md) for the exact finite human-handoff boundary. Iterate/poll PR outcomes use exit codes `0` and `10`–`15`; command and GitHub failures use `sysexits.h` codes — [docs/exit-codes.md](docs/exit-codes.md).
@@ -88,6 +90,7 @@ This system is opinionated and works best with PRs that use required status chec
88
90
  - Shepherd identifies its own latest reply only when that comment begins `<!-- pr-shepherd -->`, not from author equality. A marked viewer-authored thread can be resolved without another reply as a retry.
89
91
  - Every review thread/comment/review summary is surfaced at least once, even if already outdated, resolved, or minimized; edited items re-surface through seen markers.
90
92
  - Draft PRs can be marked ready automatically when clean; disable with `actions.autoMarkReady: false` or `--no-auto-mark-ready`.
93
+ - With `--merge`, actionable review threads/comments/reviews/summaries are held back (`WAIT`, with raw deferred-work counts) while a PR sits in the merge queue, since a Shepherd-initiated push would eject it; set `actions.workWhileQueued: true` to act on them immediately instead. Failing checks and merge conflicts are never deferred.
91
94
  - The CLI never performs git mutations itself — it only emits commit/push instructions for the agent to run. Push access to the PR head is a usage precondition; GitHub viewer fields do not create a separate push-authorization handoff.
92
95
  - Generated iterate mutations and automatic actions are capability-aware and omit unauthorized commands. Explicit `apply` operations honor the caller's intent and surface GitHub's result; semantic human-content protections still apply.
93
96
  - `build_suggestion_patches` turns one or more ordered GitHub suggestion threads into checked patches and commit metadata, but never edits the working tree or git history. Local HEAD may be ahead when the live PR head is its ancestor.
package/bin/api.d.mts CHANGED
@@ -8,7 +8,7 @@ export interface CreatePrShepherdOptions {
8
8
  }
9
9
  /** A positive PR number, GitHub pull-request URL, or owner/repo#number reference. */
10
10
  export type PrReference = number | string;
11
- export type IterateInput = Omit<IterateCommandOptions, "format" | "prNumber" | "targetRepository"> & {
11
+ export type IterateInput = Omit<IterateCommandOptions, "format" | "prNumber" | "targetRepository" | "persistSeen" | "deferQuotaWarning"> & {
12
12
  pr?: PrReference;
13
13
  };
14
14
  export interface ReviewMutationsOperation {
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable max-lines */
2
2
  import { restWithRateLimit, restText } from "../github/http.mjs";
3
3
  import { loadDerived, storeDerived } from "../state/rest-cache.mjs";
4
+ import { loadConfig } from "../config/load.mjs";
4
5
  const STARTUP_FAILURE_STATUS = "startup_failure";
5
6
  const LOG_EXCERPT_CONTEXT_LINES = 16;
6
7
  const LOG_EXCERPT_TAIL_LINES = 28;
@@ -181,10 +182,11 @@ async function fetchJobLogExcerpt(jobId, repo, stateKey, cacheable = false) {
181
182
  }
182
183
  }
183
184
  function buildLogExcerpt(raw) {
185
+ const ignorePatterns = compileIgnoreLogLinePatterns();
184
186
  const lines = raw
185
187
  .split(/\r?\n/)
186
188
  .map(cleanLogLine)
187
- .filter((line) => line.trim() !== "");
189
+ .filter((line) => line.trim() !== "" && !isNoiseLine(line, ignorePatterns));
188
190
  if (lines.length === 0)
189
191
  return undefined;
190
192
  const aggregateExcerpt = buildAggregateJobResultsExcerpt(lines);
@@ -276,6 +278,15 @@ function truncateAnchoredExcerpt(lines, anchorIndex) {
276
278
  return text;
277
279
  return truncateLogExcerpt(`${TRUNCATED_SUFFIX.trim()}\n${lines.slice(anchorIndex).join("\n")}`);
278
280
  }
281
+ // User-configured via `checks.ignoreLogLines` (regex source strings) — empty by
282
+ // default. What counts as noise varies by CI toolchain, so Shepherd ships no
283
+ // built-in patterns; a project opts in via `.pr-shepherdrc.yml`.
284
+ function compileIgnoreLogLinePatterns() {
285
+ return loadConfig().checks.ignoreLogLines.map((pattern) => new RegExp(pattern));
286
+ }
287
+ function isNoiseLine(line, patterns) {
288
+ return patterns.some((re) => re.test(line));
289
+ }
279
290
  function cleanLogLine(line) {
280
291
  return line
281
292
  .replace(/^\uFEFF/, "")
@@ -18,7 +18,7 @@ export function formatQuotaWarning(warning) {
18
18
  `- Reset: ${resetTime(warning.resetAt)}`,
19
19
  `- Recommended poll interval: ${warning.pollIntervalMinutes} minutes`,
20
20
  `- Recommended bounded CLI timeout: ${warning.pollTimeoutMinutes} minutes`,
21
- "- Recommendation: prefer non-GraphQL `gh` CLI commands for PR operations until the reset above, then resume pr-shepherd",
21
+ "- Recommendation: keep polling pr-shepherd at the cadence above; for incidental PR operations prefer REST `gh` (`gh pr view`, `gh pr review`, `gh api`); do not substitute `gh pr checks`/`gh pr watch`",
22
22
  ].join("\n");
23
23
  }
24
24
  export function formatApiUsage(usage) {
@@ -0,0 +1,12 @@
1
+ export declare const BODY_TRUNCATE_MAX_CHARS = 1200;
2
+ export declare const NESTED_BODY_TRUNCATE_MAX_CHARS = 600;
3
+ /**
4
+ * Truncates `body` to roughly `maxChars`, keeping a head and tail portion so an
5
+ * opening question and a trailing summary both survive. Never cuts inside a
6
+ * ``` or ~~~ fence: the cut points snap outward to the nearest fence-safe line
7
+ * boundary — an unbalanced fence here would swallow every section rendered
8
+ * after it in the same tick. A single line too long to fit a budget on its own
9
+ * (headEnd stays -1, or no line fits from the tail) falls back to a
10
+ * character-level slice of that line rather than dropping it entirely.
11
+ */
12
+ export declare function truncateBody(body: string, maxChars: number, url?: string): string;
@@ -0,0 +1,123 @@
1
+ const HEAD_FRACTION = 0.7;
2
+ export const BODY_TRUNCATE_MAX_CHARS = 1200;
3
+ export const NESTED_BODY_TRUNCATE_MAX_CHARS = 600;
4
+ function fenceOpener(trimmed) {
5
+ const char = trimmed[0];
6
+ if (char !== "`" && char !== "~")
7
+ return null;
8
+ let len = 0;
9
+ while (trimmed[len] === char)
10
+ len++;
11
+ return len >= 3 ? { char, len } : null;
12
+ }
13
+ function isFenceCloser(trimmed, fence) {
14
+ return trimmed.length >= fence.len && [...trimmed].every((c) => c === fence.char);
15
+ }
16
+ // Backtick and tilde fences close only against their own kind — a run of one
17
+ // character never closes a fence opened with the other (CommonMark semantics).
18
+ function fenceStatesAfterEachLine(lines) {
19
+ const states = [];
20
+ let fence = null;
21
+ for (const line of lines) {
22
+ const trimmed = line.trim();
23
+ if (fence) {
24
+ if (isFenceCloser(trimmed, fence))
25
+ fence = null;
26
+ }
27
+ else {
28
+ fence = fenceOpener(trimmed);
29
+ }
30
+ states.push(fence !== null);
31
+ }
32
+ return states;
33
+ }
34
+ function cumulativeLengths(lines) {
35
+ const out = [];
36
+ let total = 0;
37
+ for (const line of lines) {
38
+ total += line.length + 1;
39
+ out.push(total);
40
+ }
41
+ return out;
42
+ }
43
+ /** Last line index keepable within `budget`, extended forward past any fence still open at that point. */
44
+ function findHeadEnd(states, cumLens, budget) {
45
+ let end = -1;
46
+ for (let i = 0; i < cumLens.length; i++) {
47
+ if (cumLens[i] > budget)
48
+ break;
49
+ end = i;
50
+ }
51
+ while (end >= 0 && end < states.length - 1 && states[end])
52
+ end++;
53
+ return end;
54
+ }
55
+ /** First line index keepable within `budget` counted from the end, extended backward past any fence open entering it. */
56
+ function findTailStart(states, cumLens, budget) {
57
+ const n = cumLens.length;
58
+ const total = cumLens[n - 1] ?? 0;
59
+ let start = n;
60
+ for (let j = n - 1; j >= 0; j--) {
61
+ const suffixLen = total - (j > 0 ? cumLens[j - 1] : 0);
62
+ if (suffixLen > budget)
63
+ break;
64
+ start = j;
65
+ }
66
+ while (start > 0 && states[start - 1])
67
+ start--;
68
+ return start;
69
+ }
70
+ const REVIEW_COMMENT_URL_RE = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/pull\/\d+#discussion_r(\d+)$/;
71
+ const ISSUE_COMMENT_URL_RE = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/(?:pull|issues)\/\d+#issuecomment-(\d+)$/;
72
+ // An agent can run this directly — no browser round-trip — to read the full body.
73
+ function commentViewCommand(url) {
74
+ const review = REVIEW_COMMENT_URL_RE.exec(url);
75
+ if (review) {
76
+ const [, owner, repo, id] = review;
77
+ return `gh api repos/${owner}/${repo}/pulls/comments/${id}`;
78
+ }
79
+ const issue = ISSUE_COMMENT_URL_RE.exec(url);
80
+ if (issue) {
81
+ const [, owner, repo, id] = issue;
82
+ return `gh api repos/${owner}/${repo}/issues/comments/${id}`;
83
+ }
84
+ return undefined;
85
+ }
86
+ function elisionMarker(charCount, url) {
87
+ const pointer = url ? (commentViewCommand(url) ?? url) : undefined;
88
+ return pointer
89
+ ? `[…${charCount} chars elided — full text: ${pointer}]`
90
+ : `[…${charCount} chars elided]`;
91
+ }
92
+ /**
93
+ * Truncates `body` to roughly `maxChars`, keeping a head and tail portion so an
94
+ * opening question and a trailing summary both survive. Never cuts inside a
95
+ * ``` or ~~~ fence: the cut points snap outward to the nearest fence-safe line
96
+ * boundary — an unbalanced fence here would swallow every section rendered
97
+ * after it in the same tick. A single line too long to fit a budget on its own
98
+ * (headEnd stays -1, or no line fits from the tail) falls back to a
99
+ * character-level slice of that line rather than dropping it entirely.
100
+ */
101
+ export function truncateBody(body, maxChars, url) {
102
+ if (body.length <= maxChars)
103
+ return body;
104
+ const lines = body.split("\n");
105
+ const states = fenceStatesAfterEachLine(lines);
106
+ const cumLens = cumulativeLengths(lines);
107
+ const headBudget = Math.ceil(maxChars * HEAD_FRACTION);
108
+ const tailBudget = maxChars - headBudget;
109
+ const headEnd = findHeadEnd(states, cumLens, headBudget);
110
+ const tailStart = findTailStart(states, cumLens, tailBudget);
111
+ if (tailStart <= headEnd + 1)
112
+ return body;
113
+ const head = headEnd >= 0 ? lines.slice(0, headEnd + 1).join("\n") : lines[0].slice(0, headBudget);
114
+ const tail = tailStart < lines.length
115
+ ? lines.slice(tailStart).join("\n")
116
+ : tailBudget > 0
117
+ ? lines[lines.length - 1].slice(-tailBudget)
118
+ : "";
119
+ const elidedChars = body.length - head.length - tail.length;
120
+ if (elidedChars <= 0)
121
+ return body;
122
+ return [head, elisionMarker(elidedChars, url), tail].join("\n\n");
123
+ }
@@ -1,3 +1,4 @@
1
1
  import type { CheckAnnotation, IterateResultFixCode } from "../types.mts";
2
- export declare function renderCheckAnnotation(a: CheckAnnotation): string;
2
+ /** Returns null when the annotation adds nothing beyond the check's own conclusion tag. */
3
+ export declare function renderCheckAnnotation(a: CheckAnnotation, logExcerpt?: string): string | null;
3
4
  export declare function renderProtectedRun(run: IterateResultFixCode["fix"]["protectedRuns"][number]): string;
@@ -1,15 +1,30 @@
1
1
  import { blockquote } from "./list-formatters.mjs";
2
- export function renderCheckAnnotation(a) {
2
+ // A bare "Process completed with exit code N." on its own carries nothing beyond
3
+ // the check's own [conclusion: FAILURE] tag, so the whole annotation is dropped.
4
+ const TRIVIAL_EXIT_CODE_RE = /^Process completed with exit code \d+\.?$/;
5
+ /** Returns null when the annotation adds nothing beyond the check's own conclusion tag. */
6
+ export function renderCheckAnnotation(a, logExcerpt) {
7
+ const hasRawDetails = a.rawDetails !== undefined && a.rawDetails.trim() !== "";
8
+ const hasTitle = a.title !== undefined && a.title.trim() !== "";
9
+ if (TRIVIAL_EXIT_CODE_RE.test(a.message.trim()) && !hasRawDetails && !hasTitle)
10
+ return null;
3
11
  const loc = `${a.path}:${renderAnnotationRange(a)}`;
4
12
  const link = a.blobUrl ? ` [↗](${a.blobUrl})` : "";
5
13
  const title = a.title ? ` — ${a.title}` : "";
6
14
  const lines = [`- \`${a.id}\`${link} \`${loc}\` [${a.level}]${title}`];
7
- if (a.message.trim() !== "")
15
+ if (a.message.trim() !== "" && !duplicatesLog(a.message, logExcerpt)) {
8
16
  lines.push(blockquote(a.message));
9
- if (a.rawDetails !== undefined && a.rawDetails.trim() !== "")
17
+ }
18
+ if (hasRawDetails && !duplicatesLog(a.rawDetails, logExcerpt)) {
10
19
  lines.push(blockquote(a.rawDetails));
20
+ }
11
21
  return lines.join("\n");
12
22
  }
23
+ // The bullet's path:line + blob link already anchors this text; if the identical
24
+ // text is also in the check's log excerpt, only the blockquote body is redundant.
25
+ function duplicatesLog(text, logExcerpt) {
26
+ return logExcerpt !== undefined && logExcerpt.includes(text.trim());
27
+ }
13
28
  export function renderProtectedRun(run) {
14
29
  const label = run.workflowName
15
30
  ? `${run.workflowName} (${run.checkNames.join(", ")})`
@@ -1,2 +1,4 @@
1
1
  import type { IterateResultFixCode } from "../types.mts";
2
- export declare function formatFixCodeResult(header: string, result: IterateResultFixCode): string;
2
+ export declare function formatFixCodeResult(header: string, result: IterateResultFixCode, opts?: {
3
+ verbose?: boolean;
4
+ }): string;
@@ -3,11 +3,14 @@ import { renderResolveCommand } from "../commands/iterate/render.mjs";
3
3
  import { inlineCode, joinSections } from "../util/markdown.mjs";
4
4
  import { renderSuggestionBlock, renderLineRange } from "./suggestion-renderer.mjs";
5
5
  import { renderThreadBullet, renderReviewBullet, renderThreadResolutionStatusTag, renderAuthor, buildFirstLookBullets, renderThreadConversation, blockquote, } from "./list-formatters.mjs";
6
+ import { BODY_TRUNCATE_MAX_CHARS } from "./body-truncate.mjs";
6
7
  import { numberInstructions } from "./iterate-instructions.mjs";
7
8
  import { renderCheckAnnotation, renderProtectedRun } from "./fix-formatter-extra.mjs";
8
9
  import { isFailingAgentCheck } from "../checks/conclusions.mjs";
9
10
  import { renderMergeCommand } from "../commands/iterate/merge.mjs";
10
- export function formatFixCodeResult(header, result) {
11
+ export function formatFixCodeResult(header, result, opts = {}) {
12
+ const verbose = opts.verbose ?? false;
13
+ const topCap = verbose ? undefined : BODY_TRUNCATE_MAX_CHARS;
11
14
  const sections = [header];
12
15
  const renderThreads = (heading, threads) => {
13
16
  if (threads.length === 0)
@@ -21,7 +24,7 @@ export function formatFixCodeResult(header, result) {
21
24
  const suggestionMarker = t.suggestion ? " [suggestion]" : "";
22
25
  const editedMarker = t.edited ? " [edited since first look]" : "";
23
26
  sections.push(`### ${heading} — ${loc} (${renderAuthor(t.author, t.authorType, t.authorAssociation, t.viewerDidAuthor)})${reviewMarker}${suggestionMarker}${editedMarker}`);
24
- sections.push(renderThreadConversation(t));
27
+ sections.push(renderThreadConversation(t, verbose));
25
28
  if (t.suggestion) {
26
29
  sections.push(renderSuggestionBlock(t.suggestion, ""));
27
30
  }
@@ -34,7 +37,7 @@ export function formatFixCodeResult(header, result) {
34
37
  if (result.fix.resolutionOnlyThreads.length > 0) {
35
38
  sections.push("## Review threads to resolve");
36
39
  sections.push(result.fix.resolutionOnlyThreads
37
- .map((t) => renderThreadBullet(t, { statusTag: renderThreadResolutionStatusTag(t) }))
40
+ .map((t) => renderThreadBullet(t, { statusTag: renderThreadResolutionStatusTag(t), verbose }))
38
41
  .join("\n"));
39
42
  }
40
43
  if (result.fix.actionableComments.length > 0) {
@@ -44,7 +47,7 @@ export function formatFixCodeResult(header, result) {
44
47
  const editedMarker = c.edited ? " [edited since first look]" : "";
45
48
  const authorizationMarker = c.viewerCanMinimize === false ? " [viewer cannot minimize]" : "";
46
49
  sections.push(`### ${heading} (${renderAuthor(c.author, c.authorType, c.authorAssociation)})${authorizationMarker}${editedMarker}`);
47
- sections.push(blockquote(c.body));
50
+ sections.push(blockquote(c.body, topCap, c.url));
48
51
  }
49
52
  }
50
53
  const failingChecks = result.fix.checks.filter((ch) => isFailingAgentCheck(ch));
@@ -87,10 +90,17 @@ export function formatFixCodeResult(header, result) {
87
90
  });
88
91
  sections.push(bullets.join("\n\n"));
89
92
  }
90
- const checksWithAnnotations = result.fix.checks.filter((ch) => (ch.annotations?.length ?? 0) > 0);
91
- if (checksWithAnnotations.length > 0) {
93
+ const annotatedChecks = result.fix.checks
94
+ .map((ch) => ({
95
+ ch,
96
+ rendered: (ch.annotations ?? [])
97
+ .map((a) => renderCheckAnnotation(a, ch.logExcerpt))
98
+ .filter((s) => s !== null),
99
+ }))
100
+ .filter(({ rendered }) => rendered.length > 0);
101
+ if (annotatedChecks.length > 0) {
92
102
  sections.push("## Check annotations");
93
- for (const ch of checksWithAnnotations) {
103
+ for (const { ch, rendered } of annotatedChecks) {
94
104
  const workflowPrefix = ch.workflowName ? `${ch.workflowName} › ` : "";
95
105
  const jobLabel = ch.jobName ? ch.jobName : ch.name;
96
106
  const locator = ch.runId
@@ -99,25 +109,41 @@ export function formatFixCodeResult(header, result) {
99
109
  ? `external \`${ch.detailsUrl}\``
100
110
  : "(no runId)";
101
111
  sections.push(`### ${locator} — \`${workflowPrefix}${jobLabel}\``);
102
- sections.push(ch.annotations.map(renderCheckAnnotation).join("\n\n"));
112
+ sections.push(rendered.join("\n\n"));
103
113
  }
104
114
  }
105
115
  if (result.fix.changesRequestedReviews.length > 0) {
106
116
  sections.push("## Changes-requested reviews");
107
- sections.push(result.fix.changesRequestedReviews.map((r) => renderReviewBullet(r)).join("\n"));
117
+ for (const r of result.fix.changesRequestedReviews) {
118
+ // A stale bot CR that already had its full body surfaced on a prior tick stays a terse
119
+ // one-line reminder (renderReviewBullet's staleBotCr branch) — repeating the full body
120
+ // every tick would be noise, not new content. Every other review (a bot CR's first
121
+ // emission, or any human CR) gets the same H3 + blockquote shape as the sibling
122
+ // review-summary/approval sections below, so the agent actually has a body to read —
123
+ // the bare bullet this replaced only ever rendered the reviewId, never the body.
124
+ if (r.staleBotCr) {
125
+ sections.push(renderReviewBullet(r));
126
+ continue;
127
+ }
128
+ const staleTag = r.staleReview
129
+ ? " [stale — review is on an old commit, all threads resolved; ask reviewer to re-review or dismiss]"
130
+ : "";
131
+ sections.push(`### \`reviewId=${r.id}\` (${renderAuthor(r.author, r.authorType, r.authorAssociation)})${staleTag}`);
132
+ sections.push(r.body.trim() === "" ? "(no review body)" : blockquote(r.body, topCap));
133
+ }
108
134
  }
109
135
  if (result.fix.firstLookSummaries.length > 0) {
110
136
  sections.push("## Review summaries (first look)");
111
137
  for (const r of result.fix.firstLookSummaries) {
112
138
  sections.push(`### \`reviewId=${r.id}\` (${renderAuthor(r.author, r.authorType, r.authorAssociation)})${r.viewerCanMinimize === false ? " [viewer cannot minimize]" : ""}`);
113
- sections.push(r.body.trim() === "" ? "(no review body)" : blockquote(r.body));
139
+ sections.push(r.body.trim() === "" ? "(no review body)" : blockquote(r.body, topCap));
114
140
  }
115
141
  }
116
142
  if (result.fix.editedSummaries.length > 0) {
117
143
  sections.push("## Review summaries (edited since first look — already minimized; do not re-minimize)");
118
144
  for (const r of result.fix.editedSummaries) {
119
145
  sections.push(`### \`reviewId=${r.id}\` (${renderAuthor(r.author, r.authorType, r.authorAssociation)})${r.viewerCanMinimize === false ? " [viewer cannot minimize]" : ""}`);
120
- sections.push(r.body.trim() === "" ? "(no review body)" : blockquote(r.body));
146
+ sections.push(r.body.trim() === "" ? "(no review body)" : blockquote(r.body, topCap));
121
147
  }
122
148
  }
123
149
  const firstLookSummaryIds = new Set(result.fix.firstLookSummaries.map((r) => r.id));
@@ -130,14 +156,14 @@ export function formatFixCodeResult(header, result) {
130
156
  sections.push("## Approvals (surfaced — not minimized)");
131
157
  for (const r of result.fix.surfacedApprovals) {
132
158
  sections.push(`### \`reviewId=${r.id}\` (${renderAuthor(r.author, r.authorType, r.authorAssociation)})${r.viewerCanMinimize === false ? " [viewer cannot minimize]" : ""}`);
133
- sections.push(r.body.trim() === "" ? "(no review body)" : blockquote(r.body));
159
+ sections.push(r.body.trim() === "" ? "(no review body)" : blockquote(r.body, topCap));
134
160
  }
135
161
  }
136
162
  const firstLookTotal = result.fix.firstLookThreads.length + result.fix.firstLookComments.length;
137
163
  if (firstLookTotal > 0) {
138
164
  sections.push(`## First-look items (${firstLookTotal}) — acknowledge status before acting`);
139
165
  const resolutionOnlyIds = new Set(result.fix.resolutionOnlyThreads.map((t) => t.id));
140
- sections.push(buildFirstLookBullets(result.fix.firstLookThreads, resolutionOnlyIds, result.fix.firstLookComments).join("\n"));
166
+ sections.push(buildFirstLookBullets(result.fix.firstLookThreads, resolutionOnlyIds, result.fix.firstLookComments, verbose).join("\n"));
141
167
  }
142
168
  if (result.fix.inProgressRunIds.length > 0) {
143
169
  sections.push("## In-progress runs");
@@ -14,7 +14,7 @@ function formatRelevantCheck(check) {
14
14
  const lines = [`- \`${workflow}${job}\` [conclusion: ${check.conclusion}]`];
15
15
  appendCheckFields(lines, check);
16
16
  appendLogExcerpt(lines, check.logExcerpt);
17
- appendAnnotations(lines, check.annotations);
17
+ appendAnnotations(lines, check.annotations, check.logExcerpt);
18
18
  return lines;
19
19
  }
20
20
  function appendCheckFields(lines, check) {
@@ -43,13 +43,15 @@ function appendLogExcerpt(lines, logExcerpt) {
43
43
  for (const line of logExcerpt.split("\n"))
44
44
  lines.push(` > ${line}`);
45
45
  }
46
- function appendAnnotations(lines, annotations) {
47
- if (!annotations || annotations.length === 0)
46
+ function appendAnnotations(lines, annotations, logExcerpt) {
47
+ const rendered = (annotations ?? [])
48
+ .map((a) => renderCheckAnnotation(a, logExcerpt))
49
+ .filter((s) => s !== null);
50
+ if (rendered.length === 0)
48
51
  return;
49
52
  lines.push(" - annotations:");
50
- for (const annotation of annotations) {
51
- for (const line of renderCheckAnnotation(annotation).split("\n")) {
53
+ for (const text of rendered) {
54
+ for (const line of text.split("\n"))
52
55
  lines.push(` ${line}`);
53
- }
54
56
  }
55
57
  }
@@ -3,7 +3,7 @@ import { formatRelevantChecks } from "./iterate-checks-formatter.mjs";
3
3
  import { joinSections } from "../util/markdown.mjs";
4
4
  import { adaptIterateLog, buildSimpleIterateInstructions, numberInstructions, } from "./iterate-instructions.mjs";
5
5
  import { formatMergeRequirementLines } from "../merge-status/requirements-format.mjs";
6
- import { appendMergeQueueHeader, formatMergeAction } from "./iterate-merge-formatter.mjs";
6
+ import { appendMergeQueueHeader, formatDeferredWorkLine, formatMergeAction, } from "./iterate-merge-formatter.mjs";
7
7
  import { formatApiUsage, formatQuotaWarning } from "./api-usage-formatter.mjs";
8
8
  import { formatActivityLine } from "./iterate-activity-formatter.mjs";
9
9
  /**
@@ -115,13 +115,13 @@ export function formatIterateResult(result, opts) {
115
115
  const verboseChecks = verbose ? formatRelevantChecks(result.checks) : null;
116
116
  const telemetrySections = [quotaWarning, apiUsage, verboseChecks];
117
117
  switch (result.action) {
118
- case "wait":
119
- return joinSections([
120
- header,
121
- ...telemetrySections,
122
- adaptIterateLog(result.log),
123
- `## Instructions\n\n${numberInstructions(buildSimpleIterateInstructions(result))}`,
124
- ]);
118
+ case "wait": {
119
+ const waitLines = [header, ...telemetrySections, adaptIterateLog(result.log)];
120
+ if (result.deferredWork)
121
+ waitLines.push(formatDeferredWorkLine(result.deferredWork));
122
+ waitLines.push(`## Instructions\n\n${numberInstructions(buildSimpleIterateInstructions(result))}`);
123
+ return joinSections(waitLines);
124
+ }
125
125
  case "mark_ready":
126
126
  return joinSections([
127
127
  header,
@@ -147,6 +147,7 @@ export function formatIterateResult(result, opts) {
147
147
  const supersededStr = result.supersededNames.map((n) => "`" + n + "`").join(", ");
148
148
  cancelHeaderLines.push(`**superseded** ${supersededStr}`);
149
149
  }
150
+ appendMergeQueueHeader(cancelHeaderLines, result);
150
151
  if (activityLine)
151
152
  cancelHeaderLines.push(activityLine);
152
153
  return joinSections([
@@ -166,6 +167,6 @@ export function formatIterateResult(result, opts) {
166
167
  `## Instructions\n\n${numberInstructions(buildSimpleIterateInstructions(result))}`,
167
168
  ]);
168
169
  case "fix_code":
169
- return formatFixCodeResult(joinSections([header, ...telemetrySections]), result);
170
+ return formatFixCodeResult(joinSections([header, ...telemetrySections]), result, { verbose });
170
171
  }
171
172
  }
@@ -10,7 +10,7 @@ export function buildSimpleIterateInstructions(result) {
10
10
  ];
11
11
  }
12
12
  return [
13
- "Non-terminal — no action needed this tick. Iterate again with the same options to continue.",
13
+ "Non-terminal — no action needed this tick. Iterate immediately with the same options to continue.",
14
14
  ];
15
15
  case "mark_ready":
16
16
  if (result.quotaWarning) {
@@ -19,7 +19,7 @@ export function buildSimpleIterateInstructions(result) {
19
19
  ];
20
20
  }
21
21
  return [
22
- "The CLI marked the PR ready for review. Iterate again with the same options to continue.",
22
+ "The CLI marked the PR ready for review. Iterate immediately with the same options to continue.",
23
23
  ];
24
24
  case "merge": {
25
25
  const instructions = [
@@ -33,7 +33,7 @@ export function buildSimpleIterateInstructions(result) {
33
33
  }
34
34
  instructions.push(result.quotaWarning
35
35
  ? buildQuotaAwareContinuation(result.quotaWarning, "After running the merge command.")
36
- : "Then iterate again with the same options to monitor until the PR merges or needs work.");
36
+ : "Then iterate immediately with the same options to monitor until the PR merges or needs work.");
37
37
  return instructions;
38
38
  }
39
39
  case "cancel":
@@ -23,6 +23,7 @@ export function projectIterateLean(result, opts) {
23
23
  status: result.status,
24
24
  state: result.state,
25
25
  mergeStateStatus: result.mergeStateStatus,
26
+ ...(result.mergeStatus !== "CLEAN" && { mergeStatus: result.mergeStatus }), // mergeStateStatus alone can't always reconstruct this
26
27
  ...(readyDelaySuffix && { readyDelayOverride: readyDelaySuffix }),
27
28
  ...(result.mergeStatus === "BLOCKED" &&
28
29
  result.reviewDecision !== null && { reviewDecision: result.reviewDecision }),
@@ -70,6 +71,7 @@ export function projectIterateLean(result, opts) {
70
71
  case "wait":
71
72
  return {
72
73
  ...base,
74
+ ...(result.deferredWork && { deferredWork: result.deferredWork }),
73
75
  log: adaptIterateLog(result.log),
74
76
  instructions: simpleInstructions(result),
75
77
  };
@@ -1,3 +1,5 @@
1
- import type { IterateResult, IterateResultMerge } from "../types.mts";
1
+ import type { IterateDeferredWork, IterateResult, IterateResultMerge } from "../types.mts";
2
+ /** One inline rollup line of the non-CI work held back while the PR sits in the merge queue. */
3
+ export declare function formatDeferredWorkLine(dw: IterateDeferredWork): string;
2
4
  export declare function appendMergeQueueHeader(lines: string[], result: IterateResult): void;
3
5
  export declare function formatMergeAction(header: string, result: IterateResultMerge): string;
@@ -1,6 +1,21 @@
1
1
  import { renderMergeCommand } from "../commands/iterate/merge.mjs";
2
2
  import { inlineCode, joinSections } from "../util/markdown.mjs";
3
3
  import { buildSimpleIterateInstructions, numberInstructions } from "./iterate-instructions.mjs";
4
+ /** One inline rollup line of the non-CI work held back while the PR sits in the merge queue. */
5
+ export function formatDeferredWorkLine(dw) {
6
+ const parts = [];
7
+ if (dw.threads > 0)
8
+ parts.push(`${dw.threads} thread${dw.threads === 1 ? "" : "s"}`);
9
+ if (dw.comments > 0)
10
+ parts.push(`${dw.comments} comment${dw.comments === 1 ? "" : "s"}`);
11
+ if (dw.changesRequestedReviews > 0) {
12
+ parts.push(`${dw.changesRequestedReviews} changes-requested review${dw.changesRequestedReviews === 1 ? "" : "s"}`);
13
+ }
14
+ if (dw.reviewSummaries > 0) {
15
+ parts.push(`${dw.reviewSummaries} review summar${dw.reviewSummaries === 1 ? "y" : "ies"}`);
16
+ }
17
+ return `**deferred (in merge queue)** ${parts.join(", ")}`;
18
+ }
4
19
  export function appendMergeQueueHeader(lines, result) {
5
20
  const queue = result.mergeQueue;
6
21
  if (!queue)
@@ -35,9 +35,10 @@ export declare function renderThreadBullet(t: ThreadBulletInput, opts?: {
35
35
  renderSuggestion?: boolean;
36
36
  noBody?: boolean;
37
37
  suppressEditedMarker?: boolean;
38
+ verbose?: boolean;
38
39
  }): string;
39
- export declare function renderThreadConversation(t: ThreadBulletInput): string;
40
- export declare function blockquote(body: string): string;
40
+ export declare function renderThreadConversation(t: ThreadBulletInput, verbose?: boolean): string;
41
+ export declare function blockquote(body: string, maxChars?: number, url?: string): string;
41
42
  export declare function renderCommentBullet(c: {
42
43
  id: string;
43
44
  url?: string;
@@ -74,5 +75,5 @@ export declare function renderReviewListSection(heading: string, items: {
74
75
  * Threads that also appear in resolutionOnlyIds have their body suppressed
75
76
  * (already shown in `## Review threads to resolve`).
76
77
  */
77
- export declare function buildFirstLookBullets(firstLookThreads: FirstLookThread[], resolutionOnlyIds: Set<string>, firstLookComments: FirstLookComment[]): string[];
78
+ export declare function buildFirstLookBullets(firstLookThreads: FirstLookThread[], resolutionOnlyIds: Set<string>, firstLookComments: FirstLookComment[], verbose?: boolean): string[];
78
79
  export {};