pr-shepherd 2.1.0 → 2.2.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 +1 -1
- package/README.md +28 -22
- package/bin/api.d.mts +10 -2
- package/bin/api.mjs +30 -6
- package/bin/checks/pending-deployments.d.mts +10 -0
- package/bin/checks/pending-deployments.mjs +66 -0
- package/bin/checks/run-workflow-paths.d.mts +7 -0
- package/bin/checks/run-workflow-paths.mjs +19 -0
- package/bin/checks/triage.mjs +3 -2
- package/bin/checks/unreported-required.d.mts +11 -1
- package/bin/checks/unreported-required.mjs +8 -3
- package/bin/checks/workflow-concurrency.d.mts +9 -0
- package/bin/checks/workflow-concurrency.mjs +84 -0
- package/bin/checks/workflow-path.d.mts +2 -0
- package/bin/checks/workflow-path.mjs +4 -0
- package/bin/cli/arg-flags.mjs +3 -0
- package/bin/cli/clean-handler.mjs +1 -1
- package/bin/cli/default-poll.mjs +1 -0
- package/bin/cli/handlers.mjs +2 -0
- package/bin/cli/help-command-pages.d.mts +5 -4
- package/bin/cli/help-command-pages.mjs +2 -1
- package/bin/cli/help-iterate-poll-pages.d.mts +3 -3
- package/bin/cli/help-iterate-poll-pages.mjs +10 -2
- package/bin/cli/help-top-page.d.mts +1 -1
- package/bin/cli/help-top-page.mjs +2 -2
- package/bin/cli/help.d.mts +6 -5
- package/bin/cli/in-progress-run-format.d.mts +3 -0
- package/bin/cli/in-progress-run-format.mjs +14 -0
- package/bin/cli/iterate-activity-formatter.d.mts +2 -0
- package/bin/cli/iterate-activity-formatter.mjs +11 -0
- package/bin/cli/iterate-flags.d.mts +3 -0
- package/bin/cli/iterate-flags.mjs +18 -1
- package/bin/cli/iterate-formatter.mjs +2 -1
- package/bin/cli/iterate-lean.mjs +2 -0
- package/bin/cli/pending-deployments-format.d.mts +5 -0
- package/bin/cli/pending-deployments-format.mjs +19 -0
- package/bin/cli/poll-handler.d.mts +1 -1
- package/bin/cli/poll-handler.mjs +33 -10
- package/bin/cli/poll-targets.mjs +2 -0
- package/bin/cli/stack-merge-args.d.mts +10 -0
- package/bin/cli/stack-merge-args.mjs +27 -0
- package/bin/cli/stack-overview.d.mts +1 -0
- package/bin/cli/stack-overview.mjs +5 -1
- package/bin/cli/stalled-check-format.d.mts +3 -0
- package/bin/cli/stalled-check-format.mjs +23 -0
- package/bin/cli/suggestion-renderer.mjs +6 -0
- package/bin/cli/triage-formatter.mjs +14 -0
- package/bin/commands/check.mjs +7 -2
- package/bin/commands/clean.d.mts +1 -1
- package/bin/commands/clean.mjs +7 -0
- package/bin/commands/iterate/check-follow-up.d.mts +9 -0
- package/bin/commands/iterate/check-follow-up.mjs +34 -0
- package/bin/commands/iterate/ci-start-stall.d.mts +23 -0
- package/bin/commands/iterate/ci-start-stall.mjs +33 -0
- package/bin/commands/iterate/duration-approx.d.mts +2 -0
- package/bin/commands/iterate/duration-approx.mjs +8 -0
- package/bin/commands/iterate/escalate.d.mts +8 -17
- package/bin/commands/iterate/escalate.mjs +19 -48
- package/bin/commands/iterate/helpers.mjs +1 -0
- package/bin/commands/iterate/in-progress-runs.d.mts +10 -0
- package/bin/commands/iterate/in-progress-runs.mjs +120 -0
- package/bin/commands/iterate/index.mjs +12 -6
- package/bin/commands/iterate/merge-plan.d.mts +2 -0
- package/bin/commands/iterate/merge-plan.mjs +2 -1
- package/bin/commands/iterate/merge-state.d.mts +2 -0
- package/bin/commands/iterate/merge-state.mjs +8 -21
- package/bin/commands/iterate/native-stack-rebase.d.mts +3 -2
- package/bin/commands/iterate/native-stack-rebase.mjs +32 -11
- package/bin/commands/iterate/queue-removal.d.mts +19 -0
- package/bin/commands/iterate/queue-removal.mjs +64 -0
- package/bin/commands/iterate/render.d.mts +2 -1
- package/bin/commands/iterate/render.mjs +4 -1
- package/bin/commands/iterate/stack-boundary.d.mts +17 -0
- package/bin/commands/iterate/stack-boundary.mjs +95 -0
- package/bin/commands/iterate/stall-repair.d.mts +17 -0
- package/bin/commands/iterate/stall-repair.mjs +25 -0
- package/bin/commands/iterate/stall.d.mts +1 -1
- package/bin/commands/iterate/stall.mjs +27 -18
- package/bin/commands/iterate/state-unavailable.d.mts +8 -0
- package/bin/commands/iterate/state-unavailable.mjs +23 -0
- package/bin/commands/iterate/triage-loop-instruction.mjs +1 -1
- package/bin/commands/iterate/triage.mjs +41 -74
- package/bin/commands/iterate/unreported-required.d.mts +5 -2
- package/bin/commands/iterate/unreported-required.mjs +13 -8
- package/bin/commands/iterate/workflow-files.d.mts +27 -0
- package/bin/commands/iterate/workflow-files.mjs +85 -0
- package/bin/commands/poll-summary-explicit-instructions.mjs +15 -1
- package/bin/commands/poll-summary-instructions.d.mts +4 -3
- package/bin/commands/poll-summary-instructions.mjs +60 -22
- package/bin/commands/poll-summary.mjs +38 -10
- package/bin/commands/poll.mjs +4 -2
- package/bin/commands/stack-drain.d.mts +4 -4
- package/bin/commands/stack-drain.mjs +19 -113
- package/bin/commands/stack-handoffs.d.mts +3 -3
- package/bin/commands/stack-handoffs.mjs +8 -8
- package/bin/commands/stack-lower-ready-note.d.mts +6 -0
- package/bin/commands/stack-lower-ready-note.mjs +35 -0
- package/bin/commands/stack-merge-escalations.d.mts +17 -0
- package/bin/commands/stack-merge-escalations.mjs +57 -0
- package/bin/commands/stack-merge-plan.d.mts +10 -0
- package/bin/commands/stack-merge-plan.mjs +132 -0
- package/bin/commands/stack-merge-scope.d.mts +42 -0
- package/bin/commands/stack-merge-scope.mjs +113 -0
- package/bin/commands/stack-ownership.d.mts +25 -0
- package/bin/commands/stack-ownership.mjs +85 -0
- package/bin/commands/stack-stall.d.mts +2 -0
- package/bin/commands/stack-stall.mjs +25 -3
- package/bin/commands/stack-targets-error.d.mts +16 -0
- package/bin/commands/stack-targets-error.mjs +44 -0
- package/bin/commands/stack-targets.d.mts +30 -0
- package/bin/commands/stack-targets.mjs +121 -0
- package/bin/commands/stack-work.d.mts +4 -3
- package/bin/commands/stack-work.mjs +7 -4
- package/bin/commands/tick.mjs +14 -2
- package/bin/config/renames.mjs +1 -1
- package/bin/config/schema.d.mts +4 -0
- package/bin/config/schema.mjs +2 -0
- package/bin/github/batch-parse-suites.d.mts +4 -1
- package/bin/github/batch-parse-suites.mjs +15 -3
- package/bin/github/batch-raw-types.d.mts +6 -0
- package/bin/github/gql/commit-check-suites.gql +6 -0
- package/bin/github/gql/poll-summary-fragment.gql +6 -0
- package/bin/github/poll-summary-command.d.mts +15 -1
- package/bin/github/poll-summary-command.mjs +39 -3
- package/bin/github/poll-summary-projector.d.mts +1 -1
- package/bin/github/poll-summary-projector.mjs +1 -4
- package/bin/github/poll-summary-raw.d.mts +6 -0
- package/bin/github/poll-summary-route.mjs +4 -1
- package/bin/github/poll-summary.mjs +10 -3
- package/bin/github/rest-batch-read.mjs +17 -6
- package/bin/github/rest-batch-snapshot.d.mts +2 -2
- package/bin/github/rest-batch-snapshot.mjs +3 -0
- package/bin/github/rest-check-read.d.mts +1 -18
- package/bin/github/rest-check-read.mjs +1 -2
- package/bin/github/rest-stack-read.d.mts +9 -0
- package/bin/github/rest-stack-read.mjs +40 -0
- package/bin/github/rest-suite-types.d.mts +23 -0
- package/bin/github/rest-suite-types.mjs +1 -0
- package/bin/github/rest-summary-read.mjs +2 -0
- package/bin/mcp/server.mjs +29 -3
- package/bin/pr-reference.d.mts +2 -0
- package/bin/pr-reference.mjs +1 -1
- package/bin/reporters/agent.mjs +3 -0
- package/bin/state/check-follow-up.d.mts +30 -0
- package/bin/state/check-follow-up.mjs +51 -0
- package/bin/state/ci-start-follow-up.d.mts +14 -0
- package/bin/state/ci-start-follow-up.mjs +21 -0
- package/bin/state/queue-removal-follow-up.d.mts +20 -0
- package/bin/state/queue-removal-follow-up.mjs +23 -0
- package/bin/state/signature-marker.d.mts +10 -0
- package/bin/state/signature-marker.mjs +28 -0
- package/bin/state/stack-merge-approval.d.mts +26 -0
- package/bin/state/stack-merge-approval.mjs +39 -0
- package/bin/state/stall-repair.d.mts +16 -0
- package/bin/state/stall-repair.mjs +47 -0
- package/bin/types/activity.d.mts +2 -1
- package/bin/types/escalate.d.mts +9 -2
- package/bin/types/github.d.mts +18 -0
- package/bin/types/in-progress-run.d.mts +20 -0
- package/bin/types/in-progress-run.mjs +1 -0
- package/bin/types/iterate.d.mts +22 -1
- package/bin/types/poll-summary.d.mts +18 -1
- package/bin/types/report.d.mts +5 -1
- package/bin/types.d.mts +1 -0
- package/bin/types.mjs +1 -0
- package/package.json +2 -2
- package/plugins/pr-shepherd/.claude-plugin/plugin.json +1 -1
- 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/package-lock.json +4 -4
- package/plugins/pr-shepherd/package.json +1 -1
- package/plugins/pr-shepherd/skills/pr-shepherd/SKILL.md +8 -7
- package/plugins/pr-shepherd/skills/pr-shepherd/references/check-follow-up.md +14 -0
- package/plugins/pr-shepherd/skills/pr-shepherd/references/ci-failure-triage.md +6 -5
- package/plugins/pr-shepherd/skills/pr-shepherd/references/ci-start-stall.md +15 -0
- package/plugins/pr-shepherd/skills/pr-shepherd/references/create-a-pr.md +4 -1
- package/plugins/pr-shepherd/skills/pr-shepherd/references/mcp-fallback.md +1 -1
- package/plugins/pr-shepherd/skills/pr-shepherd/references/merge-queue-ejection.md +6 -5
- package/plugins/pr-shepherd/skills/pr-shepherd/references/required-checks-unreported.md +16 -0
- package/pr-shepherd.schema.json +11 -0
package/bin/cli/poll-targets.mjs
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { StackMergeFlag } from "../commands/stack-targets.mts";
|
|
2
|
+
import { type ParsedPrReference } from "../pr-reference.mts";
|
|
3
|
+
/**
|
|
4
|
+
* The stack merge scope flags: `--merge`, `--merge-ready`, and `--merge-through <ref>` are
|
|
5
|
+
* mutually exclusive. Returns null after printing a usage error.
|
|
6
|
+
*/
|
|
7
|
+
export declare function parseStackMerge(extra: string[]): {
|
|
8
|
+
flag?: StackMergeFlag;
|
|
9
|
+
through?: ParsedPrReference;
|
|
10
|
+
} | null;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EXIT } from "../exit-codes.mjs";
|
|
2
|
+
import { parseCliPrReference } from "../pr-reference.mjs";
|
|
3
|
+
import { getFlag, hasFlag } from "./args.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* The stack merge scope flags: `--merge`, `--merge-ready`, and `--merge-through <ref>` are
|
|
6
|
+
* mutually exclusive. Returns null after printing a usage error.
|
|
7
|
+
*/
|
|
8
|
+
export function parseStackMerge(extra) {
|
|
9
|
+
const through = getFlag(extra, "--merge-through");
|
|
10
|
+
const flags = [
|
|
11
|
+
...(hasFlag(extra, "--merge") ? ["merge"] : []),
|
|
12
|
+
...(hasFlag(extra, "--merge-ready") ? ["ready"] : []),
|
|
13
|
+
...(hasFlag(extra, "--merge-through") || through !== null ? ["through"] : []),
|
|
14
|
+
];
|
|
15
|
+
const fail = (message) => {
|
|
16
|
+
process.stderr.write(`pr-shepherd: stack: ${message}\n`);
|
|
17
|
+
process.exitCode = EXIT.USAGE;
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
if (flags.length > 1) {
|
|
21
|
+
return fail("--merge, --merge-ready, and --merge-through are mutually exclusive.");
|
|
22
|
+
}
|
|
23
|
+
if (flags[0] !== "through")
|
|
24
|
+
return flags[0] ? { flag: flags[0] } : {};
|
|
25
|
+
const ref = through === null ? null : parseCliPrReference(through);
|
|
26
|
+
return ref ? { flag: "through", through: ref } : fail("--merge-through requires a PR reference.");
|
|
27
|
+
}
|
|
@@ -24,6 +24,7 @@ export function projectStackOverview(result) {
|
|
|
24
24
|
...(result.nextAction && { nextAction: result.nextAction }),
|
|
25
25
|
prs: result.prs.map((item) => projectLayer(item, stale.has(item.pr))),
|
|
26
26
|
...(result.stackAncestry?.length && { stackAncestry: result.stackAncestry }),
|
|
27
|
+
...(result.addedLayers?.length && { addedLayers: result.addedLayers }),
|
|
27
28
|
...(result.instructions?.length && { instructions: result.instructions }),
|
|
28
29
|
...(result.apiUsage && { apiUsage: result.apiUsage }),
|
|
29
30
|
...(result.quotaWarning && { quotaWarning: result.quotaWarning }),
|
|
@@ -111,6 +112,9 @@ export function formatStackOverview(overview) {
|
|
|
111
112
|
lines.push(`- PR #${gap.childPr} base \`${gap.childBaseRefName}\` at \`${gap.childBaseRefOid}\` differs from parent PR #${gap.parentPr} head \`${gap.parentHeadRefName}\` at \`${gap.parentHeadRefOid}\`.`);
|
|
112
113
|
}
|
|
113
114
|
}
|
|
115
|
+
const added = overview.addedLayers?.map((pr) => `#${pr}`).join(", ");
|
|
116
|
+
if (added)
|
|
117
|
+
lines.push("", `Layers added after approval: ${added}`);
|
|
114
118
|
if (overview.instructions?.length) {
|
|
115
119
|
lines.push("", "## Instructions", "", ...overview.instructions);
|
|
116
120
|
}
|
|
@@ -130,7 +134,7 @@ function formatLayerLines(layer, index, overview) {
|
|
|
130
134
|
layer.mergeable === undefined
|
|
131
135
|
? undefined
|
|
132
136
|
: layer.mergeable
|
|
133
|
-
?
|
|
137
|
+
? `mergeable${layer.shepherded ? "" : ", no READY receipt yet"}`
|
|
134
138
|
: `not mergeable (\`${layer.blocker ?? "unknown"}\`)`,
|
|
135
139
|
layer.author ? `owner \`@${layer.author}\`` : undefined,
|
|
136
140
|
layer.owned ? "owned" : undefined,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { formatDurationApprox } from "../commands/iterate/duration-approx.mjs";
|
|
2
|
+
import { renderPendingDeploymentLines } from "./pending-deployments-format.mjs";
|
|
3
|
+
/** Names and URLs come from check providers: keep each inside one code span on one line. */
|
|
4
|
+
function inline(text) {
|
|
5
|
+
return text.replace(/[`\r\n]+/g, " ");
|
|
6
|
+
}
|
|
7
|
+
/** One unstarted check as raw data: a bullet, its summary as a blockquote, and any approvals. */
|
|
8
|
+
export function renderStalledCheckLines(check) {
|
|
9
|
+
const target = check.runId
|
|
10
|
+
? `run \`${inline(check.runId)}\``
|
|
11
|
+
: check.detailsUrl
|
|
12
|
+
? `external \`${inline(check.detailsUrl)}\``
|
|
13
|
+
: "no run ID";
|
|
14
|
+
const lines = [
|
|
15
|
+
`- check \`${inline(check.name)}\` — ${check.status} ${check.source}, ${target}, waiting ${formatDurationApprox(check.ageSeconds)}`,
|
|
16
|
+
];
|
|
17
|
+
if (check.summary) {
|
|
18
|
+
for (const line of check.summary.split(/\r?\n/))
|
|
19
|
+
lines.push(` > ${line}`);
|
|
20
|
+
}
|
|
21
|
+
lines.push(...renderPendingDeploymentLines(check.pendingDeployments, " "));
|
|
22
|
+
return lines;
|
|
23
|
+
}
|
|
@@ -15,6 +15,11 @@ export function renderSuggestionBlock(s, indent = " ") {
|
|
|
15
15
|
: s.lines.length === 1 && s.lines[0] === ""
|
|
16
16
|
? `Replaces ${rangeLabel} with a blank line:`
|
|
17
17
|
: `Replaces ${rangeLabel}:`;
|
|
18
|
+
const note = /`{3,}/.test(content)
|
|
19
|
+
? [
|
|
20
|
+
`${indent}Replacement contains backtick runs of 3 or more; \`suggest\` builds the exact patch.`,
|
|
21
|
+
]
|
|
22
|
+
: [];
|
|
18
23
|
return [
|
|
19
24
|
`${indent}${label}`,
|
|
20
25
|
`${indent}${fence}`,
|
|
@@ -27,5 +32,6 @@ export function renderSuggestionBlock(s, indent = " ") {
|
|
|
27
32
|
.join("\n"),
|
|
28
33
|
]),
|
|
29
34
|
`${indent}${fence}`,
|
|
35
|
+
...note,
|
|
30
36
|
].join("\n");
|
|
31
37
|
}
|
|
@@ -6,6 +6,9 @@ import { BODY_TRUNCATE_MAX_CHARS } from "./body-truncate.mjs";
|
|
|
6
6
|
import { numberInstructions } from "./iterate-instructions.mjs";
|
|
7
7
|
import { renderCheckAnnotation } from "./triage-formatter-extra.mjs";
|
|
8
8
|
import { renderRelatedJobLines } from "./related-jobs-format.mjs";
|
|
9
|
+
import { renderPendingDeploymentLines } from "./pending-deployments-format.mjs";
|
|
10
|
+
import { renderStalledCheckLines } from "./stalled-check-format.mjs";
|
|
11
|
+
import { renderInProgressRun } from "./in-progress-run-format.mjs";
|
|
9
12
|
import { isFailingAgentCheck } from "../checks/conclusions.mjs";
|
|
10
13
|
import { renderMergeCommand } from "../commands/iterate/merge.mjs";
|
|
11
14
|
import { partitionFixThreads } from "../commands/iterate/fix-instruction-threads.mjs";
|
|
@@ -96,6 +99,8 @@ export function formatTriageResult(header, result, opts = {}) {
|
|
|
96
99
|
const lines = [
|
|
97
100
|
`- ${locator} — \`${workflowPrefix}${jobLabel}\`${conclusionTag}${attemptTag}${blockerTag}${scopeTag}`,
|
|
98
101
|
];
|
|
102
|
+
if (ch.workflowPath)
|
|
103
|
+
lines.push(` workflow file: \`${ch.workflowPath}\``);
|
|
99
104
|
if (ch.conclusion !== "CANCELLED") {
|
|
100
105
|
if (ch.failedStep)
|
|
101
106
|
lines.push(` > ${ch.failedStep}`);
|
|
@@ -105,6 +110,7 @@ export function formatTriageResult(header, result, opts = {}) {
|
|
|
105
110
|
lines.push(indentBlockquote(ch.logExcerpt, " "));
|
|
106
111
|
lines.push(...renderRelatedJobLines(ch.relatedJobs));
|
|
107
112
|
}
|
|
113
|
+
lines.push(...renderPendingDeploymentLines(ch.pendingDeployments));
|
|
108
114
|
if (ch.rerunCommand && ch.runId && !seenRerunRunIds.has(ch.runId)) {
|
|
109
115
|
seenRerunRunIds.add(ch.runId);
|
|
110
116
|
lines.push(` rerun: \`${ch.rerunCommand}\``);
|
|
@@ -135,6 +141,14 @@ export function formatTriageResult(header, result, opts = {}) {
|
|
|
135
141
|
sections.push(rendered.join("\n\n"));
|
|
136
142
|
}
|
|
137
143
|
}
|
|
144
|
+
if (result.triage.stalledChecks) {
|
|
145
|
+
sections.push("## Unstarted checks");
|
|
146
|
+
sections.push(result.triage.stalledChecks.flatMap(renderStalledCheckLines).join("\n"));
|
|
147
|
+
}
|
|
148
|
+
if (result.triage.inProgressRuns) {
|
|
149
|
+
sections.push("## In-progress runs");
|
|
150
|
+
sections.push(result.triage.inProgressRuns.map(renderInProgressRun).join("\n\n"));
|
|
151
|
+
}
|
|
138
152
|
if (result.triage.changesRequestedReviews.length > 0) {
|
|
139
153
|
sections.push("## Changes-requested reviews");
|
|
140
154
|
for (const r of result.triage.changesRequestedReviews) {
|
package/bin/commands/check.mjs
CHANGED
|
@@ -11,8 +11,10 @@ import { collectUnreportedRequired, refreshCachedUnreported } from "./check-unre
|
|
|
11
11
|
import { getRepoInfo, getCurrentPrNumber } from "../github/client.mjs";
|
|
12
12
|
import { classifyChecks, getCiVerdict } from "../checks/classify.mjs";
|
|
13
13
|
import { mergeStartupFailureChecks } from "../checks/startup-failures.mjs";
|
|
14
|
+
import { withRunWorkflowPaths } from "../checks/run-workflow-paths.mjs";
|
|
14
15
|
import { fetchStartupFailureChecks, triageFailingChecks } from "../checks/triage.mjs";
|
|
15
16
|
import { TriageBudget } from "../checks/triage-budget.mjs";
|
|
17
|
+
import { attachPendingDeployments } from "../checks/pending-deployments.mjs";
|
|
16
18
|
import { deriveMergeStatus } from "../merge-status/derive.mjs";
|
|
17
19
|
import { loadConfig } from "../config/load.mjs";
|
|
18
20
|
import { classifyVisibleComments } from "../comments/visible-comments.mjs";
|
|
@@ -119,7 +121,7 @@ async function runScopedCheck(opts, context, repo, prNumber, stateKey) {
|
|
|
119
121
|
const startupFailureChecks = result.checkSuitesComplete && !startupFailuresNeedAttempt
|
|
120
122
|
? []
|
|
121
123
|
: await fetchStartupFailureChecks(repo, batchData.headRefOid, prNumber, stateKey, triageBudget);
|
|
122
|
-
const allChecks = mergeStartupFailureChecks(batchData.checks, startupFailureChecks);
|
|
124
|
+
const allChecks = withRunWorkflowPaths(mergeStartupFailureChecks(batchData.checks, startupFailureChecks), result.headWorkflowSuites ?? []);
|
|
123
125
|
const unreported = await collectUnreportedRequired({
|
|
124
126
|
batchData,
|
|
125
127
|
checks: allChecks,
|
|
@@ -180,7 +182,10 @@ async function runScopedCheck(opts, context, repo, prNumber, stateKey) {
|
|
|
180
182
|
additionalRelevantEvents: ["merge_group"],
|
|
181
183
|
requiredContexts: unreported.requiredContexts,
|
|
182
184
|
});
|
|
183
|
-
const
|
|
185
|
+
const classifiedBaseChecks = [...classifiedPrChecks, ...classifiedQueueChecks];
|
|
186
|
+
const classifiedChecks = opts.skipTriage
|
|
187
|
+
? classifiedBaseChecks
|
|
188
|
+
: await attachPendingDeployments(classifiedBaseChecks, repo, stateKey, triageBudget);
|
|
184
189
|
const verdict = getCiVerdict(classifiedChecks);
|
|
185
190
|
const passing = classifiedChecks.filter((c) => c.category === "passed");
|
|
186
191
|
const failing = classifiedChecks.filter((c) => c.category === "failing");
|
package/bin/commands/clean.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type CleanVariant = "pr" | "branch" | "current" | "repo" | "all";
|
|
1
|
+
export type CleanVariant = "pr" | "stack" | "branch" | "current" | "repo" | "all";
|
|
2
2
|
interface CleanOptions {
|
|
3
3
|
variant: CleanVariant;
|
|
4
4
|
/** PR number string (for "pr") or branch name (for "branch"). Defaults to current. */
|
package/bin/commands/clean.mjs
CHANGED
|
@@ -116,6 +116,13 @@ async function resolveTarget(base, opts) {
|
|
|
116
116
|
}
|
|
117
117
|
return repoDir;
|
|
118
118
|
}
|
|
119
|
+
if (variant === "stack") {
|
|
120
|
+
const n = value === undefined ? NaN : parseInt(value, 10);
|
|
121
|
+
if (!Number.isFinite(n) || n <= 0 || String(n) !== value.trim()) {
|
|
122
|
+
throw new Error(`"clean stack" needs a native stack number; got ${value ?? "none"}`);
|
|
123
|
+
}
|
|
124
|
+
return join(repoDir, `stack-${n}`);
|
|
125
|
+
}
|
|
119
126
|
let prNumber;
|
|
120
127
|
if (variant === "pr") {
|
|
121
128
|
if (value !== undefined) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AgentCheck } from "../../types.mts";
|
|
2
|
+
/**
|
|
3
|
+
* What a failing check with no authorized rerun needs next.
|
|
4
|
+
* `approval`: a gate only a human can grant. `investigate`: the agent can find out why.
|
|
5
|
+
*/
|
|
6
|
+
export type CheckFollowUp = "approval" | "investigate";
|
|
7
|
+
export declare function checkFollowUp(check: AgentCheck): CheckFollowUp | undefined;
|
|
8
|
+
/** The one investigation tick: raw facts, the playbook, and the bounded outcome. */
|
|
9
|
+
export declare function buildCheckFollowUpInstructions(checks: AgentCheck[], repo: string, actionsRunIds: ReadonlySet<string>): string[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { playbookPointer } from "../playbook-pointer.mjs";
|
|
2
|
+
import { hasLogEvidence } from "./check-evidence.mjs";
|
|
3
|
+
export function checkFollowUp(check) {
|
|
4
|
+
if (check.rerunCommand)
|
|
5
|
+
return undefined;
|
|
6
|
+
if (check.conclusion === "ACTION_REQUIRED")
|
|
7
|
+
return "approval";
|
|
8
|
+
if (check.conclusion === "CANCELLED" || check.conclusion === "STARTUP_FAILURE") {
|
|
9
|
+
return "investigate";
|
|
10
|
+
}
|
|
11
|
+
// A later attempt cannot be rerun automatically, but its included log can still identify a
|
|
12
|
+
// fix. Without evidence the agent can fetch the log itself.
|
|
13
|
+
if (check.runAttempt !== undefined && check.runAttempt > 1) {
|
|
14
|
+
return hasLogEvidence(check) ? undefined : "investigate";
|
|
15
|
+
}
|
|
16
|
+
// An external check's direct URL is actionable evidence: the agent can inspect the provider.
|
|
17
|
+
if (check.runId === null)
|
|
18
|
+
return check.detailsUrl?.trim() ? undefined : "investigate";
|
|
19
|
+
return hasLogEvidence(check) ? undefined : "investigate";
|
|
20
|
+
}
|
|
21
|
+
/** The one investigation tick: raw facts, the playbook, and the bounded outcome. */
|
|
22
|
+
export function buildCheckFollowUpInstructions(checks, repo, actionsRunIds) {
|
|
23
|
+
// Only confirmed Actions runs: an external check's details-URL run id is not one.
|
|
24
|
+
const runIds = [
|
|
25
|
+
...new Set(checks.flatMap((check) => check.runId && actionsRunIds.has(check.runId) ? [check.runId] : [])),
|
|
26
|
+
];
|
|
27
|
+
const start = runIds.length
|
|
28
|
+
? ` Start with ${runIds.map((id) => `\`gh run view ${id} -R ${repo}\``).join(", ")}: it lists the run's jobs and annotations.`
|
|
29
|
+
: "";
|
|
30
|
+
return [
|
|
31
|
+
`Shepherd has no rerun to offer and no log excerpt to show for the checks under \`## Failing checks\`, so it cannot tell from GitHub's data why they failed or what would fix them. Find out before acting.${start} ${playbookPointer("Check follow-up")}`,
|
|
32
|
+
"If the cause is within this PR, fix it and push. Otherwise make no change and keep what you found; do not rerun or retrigger these checks. If these checks are unchanged on the next poll, Shepherd escalates with `check-follow-up-unavailable`; report that diagnosis then.",
|
|
33
|
+
];
|
|
34
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AgentStalledCheck, IterateResult, IterateResultBase, ShepherdReport } from "../../types.mts";
|
|
2
|
+
type StateKey = {
|
|
3
|
+
owner: string;
|
|
4
|
+
repo: string;
|
|
5
|
+
pr: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* One bounded investigation `triage` the first time unstarted checks stall on a head; `undefined`
|
|
9
|
+
* (escalate) once the same checks on the same head were already presented, or at once when a
|
|
10
|
+
* stalled check waits on a deployment-environment approval.
|
|
11
|
+
*/
|
|
12
|
+
export declare function planCiStartInvestigation(input: {
|
|
13
|
+
base: IterateResultBase;
|
|
14
|
+
report: ShepherdReport;
|
|
15
|
+
stallKey: StateKey;
|
|
16
|
+
headSha: string;
|
|
17
|
+
stalledChecks: readonly AgentStalledCheck[];
|
|
18
|
+
/** Internal preview ticks must not consume the one investigation tick. */
|
|
19
|
+
persistState: boolean;
|
|
20
|
+
/** The escalation when the investigation marker cannot be saved. */
|
|
21
|
+
stateUnavailable: (reason: string) => IterateResult;
|
|
22
|
+
}): Promise<IterateResult | undefined>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ciStartSignature, readCiStartFollowUp, writeCiStartFollowUp, } from "../../state/ci-start-follow-up.mjs";
|
|
2
|
+
import { playbookPointer } from "../playbook-pointer.mjs";
|
|
3
|
+
import { buildUnreportedFixResult } from "./unreported-required.mjs";
|
|
4
|
+
/** Constant text: the checks' names, URLs and summaries are data under `## Unstarted checks`. */
|
|
5
|
+
const CI_START_INSTRUCTIONS = [
|
|
6
|
+
`The checks under \`## Unstarted checks\` have not started after the stall timeout, and Shepherd cannot tell from GitHub's data why. Find out before acting. ${playbookPointer("CI start stall")}`,
|
|
7
|
+
"If the cause is within this PR, fix it and push. Otherwise make no change and keep what you found. If the same checks are still not started on the next poll, Shepherd escalates with `stall-timeout`; report your diagnosis then.",
|
|
8
|
+
];
|
|
9
|
+
/**
|
|
10
|
+
* One bounded investigation `triage` the first time unstarted checks stall on a head; `undefined`
|
|
11
|
+
* (escalate) once the same checks on the same head were already presented, or at once when a
|
|
12
|
+
* stalled check waits on a deployment-environment approval.
|
|
13
|
+
*/
|
|
14
|
+
export async function planCiStartInvestigation(input) {
|
|
15
|
+
const { base, report, stallKey, headSha, stalledChecks, persistState } = input;
|
|
16
|
+
// A deployment-environment approval is a known human gate: nothing to investigate.
|
|
17
|
+
if (stalledChecks.some((check) => check.pendingDeployments?.length))
|
|
18
|
+
return undefined;
|
|
19
|
+
const signature = ciStartSignature(headSha, stalledChecks.map((check) => check.name));
|
|
20
|
+
if (await readCiStartFollowUp(stallKey, signature))
|
|
21
|
+
return undefined;
|
|
22
|
+
// A reused cached report is re-run by the poll before it is shown, so it must not spend the one
|
|
23
|
+
// investigation tick the caller never sees. A marker that cannot be saved would repeat the
|
|
24
|
+
// investigation forever, so that escalates with the save error.
|
|
25
|
+
if (persistState && report.fingerprintReused !== true) {
|
|
26
|
+
const saveError = await writeCiStartFollowUp(stallKey, signature);
|
|
27
|
+
if (saveError)
|
|
28
|
+
return input.stateUnavailable(saveError);
|
|
29
|
+
}
|
|
30
|
+
return buildUnreportedFixResult(base, report, CI_START_INSTRUCTIONS, {
|
|
31
|
+
stalledChecks: [...stalledChecks],
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** A rough human duration: whole seconds under a minute, else whole minutes. */
|
|
2
|
+
export function formatDurationApprox(seconds) {
|
|
3
|
+
const s = Math.max(0, Math.floor(seconds));
|
|
4
|
+
if (s < 60)
|
|
5
|
+
return `${s} second${s === 1 ? "" : "s"}`;
|
|
6
|
+
const mins = Math.floor(s / 60);
|
|
7
|
+
return `${mins} minute${mins === 1 ? "" : "s"}`;
|
|
8
|
+
}
|
|
@@ -4,30 +4,21 @@ interface EscalateCheck {
|
|
|
4
4
|
thrashHistory?: EscalateDetails["thrashHistory"];
|
|
5
5
|
}
|
|
6
6
|
export declare function checkEscalateTriggers(actionableThreads: ReviewThread[], threadAttempts: Record<string, number>): EscalateCheck;
|
|
7
|
+
export { formatDurationApprox } from "./duration-approx.mts";
|
|
7
8
|
interface BaseBranchLookup {
|
|
9
|
+
/** The validated name, or a placeholder when `unusable` is set. */
|
|
8
10
|
branch: string;
|
|
9
|
-
/** True when
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
/** Populated when `isFallback`; one-line reason shown in escalate output. */
|
|
13
|
-
failureReason?: string;
|
|
11
|
+
/** True when the name is empty or outside `[A-Za-z0-9._/-]`. A name outside that set is never
|
|
12
|
+
* interpolated into a printed command; the caller reads the base from the PR instead. */
|
|
13
|
+
unusable: boolean;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* Validate the base branch name from the GraphQL batch (`report.baseBranch`)
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* `[A-Za-z0-9._/-]` to prevent shell injection.
|
|
16
|
+
* Validate the base branch name from the GraphQL batch (`report.baseBranch`). The branch is
|
|
17
|
+
* interpolated into printed shell commands, so a name outside `[A-Za-z0-9._/-]` (or an empty
|
|
18
|
+
* one) is `unusable`: callers omit the command and tell the agent to read the base from the PR.
|
|
20
19
|
*/
|
|
21
|
-
/**
|
|
22
|
-
* Render a seconds count as an approximate human duration: "8 seconds" below one minute,
|
|
23
|
-
* otherwise whole minutes ("166 minutes", "60 minutes") — matching the precision the
|
|
24
|
-
* generic stall timer has always reported, just adding a seconds tier for sub-minute ages
|
|
25
|
-
* instead of always flooring to "0 minutes".
|
|
26
|
-
*/
|
|
27
|
-
export declare function formatDurationApprox(seconds: number): string;
|
|
28
20
|
export declare function validateBaseBranch(raw: string): BaseBranchLookup;
|
|
29
21
|
export declare function buildEscalateHumanMessage(escalate: Omit<EscalateDetails, "humanMessage">, pr: string | number, opts?: {
|
|
30
22
|
merge?: boolean;
|
|
31
23
|
}): string;
|
|
32
24
|
export declare function buildEscalateSuggestion(triggers: EscalateTrigger[], detail?: string): string;
|
|
33
|
-
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
import { renderReviewCommitTag } from "../../cli/list-formatters.mjs";
|
|
3
3
|
import { renderRelatedJobLines } from "../../cli/related-jobs-format.mjs";
|
|
4
|
+
import { renderPendingDeploymentLines } from "../../cli/pending-deployments-format.mjs";
|
|
5
|
+
import { renderStalledCheckLines } from "../../cli/stalled-check-format.mjs";
|
|
4
6
|
import { loadConfig } from "../../config/load.mjs";
|
|
5
7
|
import { renderResolveCommand } from "./render.mjs";
|
|
6
8
|
function renderEscalateAuthor(item) {
|
|
@@ -58,6 +60,7 @@ function renderEscalateCheck(check) {
|
|
|
58
60
|
if (check.logExcerpt)
|
|
59
61
|
lines.push(...renderBlockquoteLines(check.logExcerpt, " "));
|
|
60
62
|
lines.push(...renderRelatedJobLines(check.relatedJobs));
|
|
63
|
+
lines.push(...renderPendingDeploymentLines(check.pendingDeployments));
|
|
61
64
|
if (check.rerunCommand)
|
|
62
65
|
lines.push(` rerun: \`${check.rerunCommand}\``);
|
|
63
66
|
for (const annotation of check.annotations ?? []) {
|
|
@@ -80,42 +83,19 @@ export function checkEscalateTriggers(actionableThreads, threadAttempts) {
|
|
|
80
83
|
: undefined,
|
|
81
84
|
};
|
|
82
85
|
}
|
|
86
|
+
export { formatDurationApprox } from "./duration-approx.mjs";
|
|
87
|
+
/** Stands in for a base branch name that failed validation, in prose only. */
|
|
88
|
+
const UNKNOWN_BASE_BRANCH = "<base branch>";
|
|
83
89
|
/**
|
|
84
|
-
* Validate the base branch name from the GraphQL batch (`report.baseBranch`)
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* `[A-Za-z0-9._/-]` to prevent shell injection.
|
|
90
|
+
* Validate the base branch name from the GraphQL batch (`report.baseBranch`). The branch is
|
|
91
|
+
* interpolated into printed shell commands, so a name outside `[A-Za-z0-9._/-]` (or an empty
|
|
92
|
+
* one) is `unusable`: callers omit the command and tell the agent to read the base from the PR.
|
|
88
93
|
*/
|
|
89
|
-
/**
|
|
90
|
-
* Render a seconds count as an approximate human duration: "8 seconds" below one minute,
|
|
91
|
-
* otherwise whole minutes ("166 minutes", "60 minutes") — matching the precision the
|
|
92
|
-
* generic stall timer has always reported, just adding a seconds tier for sub-minute ages
|
|
93
|
-
* instead of always flooring to "0 minutes".
|
|
94
|
-
*/
|
|
95
|
-
export function formatDurationApprox(seconds) {
|
|
96
|
-
const s = Math.max(0, Math.floor(seconds));
|
|
97
|
-
if (s < 60)
|
|
98
|
-
return `${s} second${s === 1 ? "" : "s"}`;
|
|
99
|
-
const mins = Math.floor(s / 60);
|
|
100
|
-
return `${mins} minute${mins === 1 ? "" : "s"}`;
|
|
101
|
-
}
|
|
102
94
|
export function validateBaseBranch(raw) {
|
|
103
95
|
const trimmed = raw.trim();
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
isFallback: true,
|
|
108
|
-
failureReason: "GraphQL batch returned an empty base branch name",
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
if (!/^[A-Za-z0-9._/-]+$/.test(trimmed)) {
|
|
112
|
-
return {
|
|
113
|
-
branch: "main",
|
|
114
|
-
isFallback: true,
|
|
115
|
-
failureReason: `base branch ${JSON.stringify(trimmed)} contains unsafe characters`,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
return { branch: trimmed, isFallback: false };
|
|
96
|
+
return /^[A-Za-z0-9._/-]+$/.test(trimmed)
|
|
97
|
+
? { branch: trimmed, unusable: false }
|
|
98
|
+
: { branch: UNKNOWN_BASE_BRANCH, unusable: true };
|
|
119
99
|
}
|
|
120
100
|
export function buildEscalateHumanMessage(escalate, pr, opts) {
|
|
121
101
|
const lines = [];
|
|
@@ -135,16 +115,8 @@ export function buildEscalateHumanMessage(escalate, pr, opts) {
|
|
|
135
115
|
lines.push("");
|
|
136
116
|
lines.push("## Items needing attention");
|
|
137
117
|
lines.push("");
|
|
138
|
-
for (const c of escalate.stalledChecks ?? [])
|
|
139
|
-
|
|
140
|
-
? `run \`${c.runId}\``
|
|
141
|
-
: c.detailsUrl
|
|
142
|
-
? `external \`${c.detailsUrl}\``
|
|
143
|
-
: "no run ID";
|
|
144
|
-
lines.push(`- check \`${c.name}\` — ${c.status} ${c.source}, ${target}, waiting ${formatDurationApprox(c.ageSeconds)}`);
|
|
145
|
-
if (c.summary)
|
|
146
|
-
lines.push(` > ${c.summary}`);
|
|
147
|
-
}
|
|
118
|
+
for (const c of escalate.stalledChecks ?? [])
|
|
119
|
+
lines.push(...renderStalledCheckLines(c));
|
|
148
120
|
if ((escalate.stalledChecks?.length ?? 0) > 0)
|
|
149
121
|
lines.push("");
|
|
150
122
|
for (const check of escalate.checks ?? []) {
|
|
@@ -243,6 +215,9 @@ export function buildEscalateHumanMessage(escalate, pr, opts) {
|
|
|
243
215
|
}
|
|
244
216
|
export function buildEscalateSuggestion(triggers, detail) {
|
|
245
217
|
if (triggers.includes("check-follow-up-unavailable")) {
|
|
218
|
+
if (detail === "investigated") {
|
|
219
|
+
return "The failing checks below had no rerun and no log excerpt Shepherd could show. After one investigation tick they are unchanged on this head. Report what the investigation found. What remains is a repository, CI-configuration, or workflow-permission change, or waiting out a GitHub incident; each is a human decision.";
|
|
220
|
+
}
|
|
246
221
|
return "One or more failing checks have no autonomous follow-up available. Use the displayed conclusion, run or URL, and included evidence to handle them manually.";
|
|
247
222
|
}
|
|
248
223
|
if (triggers.includes("authorization-required")) {
|
|
@@ -250,7 +225,7 @@ export function buildEscalateSuggestion(triggers, detail) {
|
|
|
250
225
|
}
|
|
251
226
|
if (triggers.includes("merge-queue-removed")) {
|
|
252
227
|
const reason = detail ? ` GitHub reason: ${detail}.` : "";
|
|
253
|
-
return `The PR left the merge queue without an actionable check failure.${reason} Confirm the removal was not intentional before adding it again.`;
|
|
228
|
+
return `The PR left the merge queue without an actionable check failure, and the removal was unchanged after one investigation tick.${reason} Report what the investigation found. Confirm the removal was not intentional before adding it again.`;
|
|
254
229
|
}
|
|
255
230
|
if (triggers.includes("stall-timeout")) {
|
|
256
231
|
const duration = detail ?? "60 minutes";
|
|
@@ -258,16 +233,12 @@ export function buildEscalateSuggestion(triggers, detail) {
|
|
|
258
233
|
}
|
|
259
234
|
if (triggers.includes("required-checks-unreported")) {
|
|
260
235
|
const names = detail ? ` (${detail})` : "";
|
|
261
|
-
return `Required checks are still unreported${names}
|
|
236
|
+
return `Required checks are still unreported${names}: no CI ran on this head after the investigation tick and one retrigger, and no CI is running. Report what the investigation found. What remains is a repository, CI-configuration, or branch-policy change, or waiting out a GitHub incident; each is a human decision.`;
|
|
262
237
|
}
|
|
263
238
|
if (triggers.includes("stall-state-unavailable")) {
|
|
264
239
|
const reason = detail ?? "unknown error";
|
|
265
240
|
return `The stall timer could not be saved (${reason}). Fix PR_SHEPHERD_STATE_DIR or the directory permissions, then resume. Automated polling is paused because a stuck loop would not be detected.`;
|
|
266
241
|
}
|
|
267
|
-
if (triggers.includes("base-branch-unknown")) {
|
|
268
|
-
const reason = detail ? ` (${detail})` : "";
|
|
269
|
-
return `Could not determine the PR's base branch${reason} — automated rebases are paused because branch safety is unclear. Run the rebase manually against the PR's real target branch.`;
|
|
270
|
-
}
|
|
271
242
|
if (triggers.includes("triage-thrash")) {
|
|
272
243
|
const attempts = loadConfig().iterate["triage-attempts-per-thread"];
|
|
273
244
|
return `The same thread(s) remain unresolved after their pending review commands were returned for ${attempts} TRIAGE ticks. Automated iteration is paused for a manual decision.`;
|
|
@@ -106,6 +106,7 @@ export function buildActiveChecks(report) {
|
|
|
106
106
|
detailsUrl: c.detailsUrl || null,
|
|
107
107
|
...(c.workflowName !== undefined && { workflowName: c.workflowName }),
|
|
108
108
|
...(c.summary !== undefined && { summary: c.summary }),
|
|
109
|
+
...(c.pendingDeployments !== undefined && { pendingDeployments: c.pendingDeployments }),
|
|
109
110
|
...(c.scope !== undefined && { scope: c.scope }),
|
|
110
111
|
...(c.commitOid !== undefined && { commitOid: c.commitOid }),
|
|
111
112
|
}));
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { InProgressRun, ShepherdReport } from "../../types.mts";
|
|
2
|
+
/**
|
|
3
|
+
* In-progress Actions runs on the head, with each workflow's raw `cancel-in-progress` and a
|
|
4
|
+
* `gh run cancel` command only for a run that sets it to the literal `true`. Empty when the
|
|
5
|
+
* feature is off or the PR is in the merge queue (a push would eject it). Reads each workflow
|
|
6
|
+
* file once per call, through one aliased GraphQL read.
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildInProgressRuns(report: ShepherdReport, rerunAuthorized: boolean): Promise<InProgressRun[]>;
|
|
9
|
+
/** The first fix step: cancel the superseded runs before editing, only when one has a command. */
|
|
10
|
+
export declare function buildCancelRunsInstruction(runs: readonly InProgressRun[]): string | undefined;
|