pr-shepherd 2.0.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 +41 -32
- 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/classify/standard/dependency-review-no-issues.d.mts +4 -0
- package/bin/classify/standard/dependency-review-no-issues.mjs +16 -0
- package/bin/classify/standard/index.mjs +8 -0
- package/bin/classify/standard/snyk-no-issues.d.mts +7 -0
- package/bin/classify/standard/snyk-no-issues.mjs +27 -0
- package/bin/classify/standard/socket-reports.d.mts +4 -0
- package/bin/classify/standard/socket-reports.mjs +18 -0
- package/bin/classify/standard/sonarqube-gate-passed.d.mts +7 -0
- package/bin/classify/standard/sonarqube-gate-passed.mjs +41 -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/hooks/poll-guard-args.mjs +49 -0
- package/plugins/pr-shepherd/hooks/poll-guard-detect.mjs +134 -26
- package/plugins/pr-shepherd/hooks/poll-guard-shell.mjs +192 -0
- package/plugins/pr-shepherd/package-lock.json +7 -7
- 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/plugins/pr-shepherd/skills/reduce-pr-noise/references/classifiers.md +1 -1
- package/pr-shepherd.schema.json +15 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { graphql } from "../../github/client.mjs";
|
|
2
|
+
import { GitHubRequestError } from "../../github/errors.mjs";
|
|
3
|
+
import { githubOperation, isGithubReadFallbackError } from "../../github/transport.mjs";
|
|
4
|
+
import { readRest, restObject, restRepoPath } from "../../github/rest-reader-core.mjs";
|
|
5
|
+
import { pollRateLimitRetryAfterMs } from "../poll-quota.mjs";
|
|
6
|
+
const memo = new Map();
|
|
7
|
+
/** Forget remembered files. */
|
|
8
|
+
export function clearWorkflowFileMemo() {
|
|
9
|
+
memo.clear();
|
|
10
|
+
}
|
|
11
|
+
/** Lookup key for a request in the result map. */
|
|
12
|
+
export const workflowFileKey = (request) => `${request.ref}:${request.path}`;
|
|
13
|
+
const memoKey = (repo, request) => `${repo.owner}/${repo.name}\0${workflowFileKey(request)}`;
|
|
14
|
+
function fromBlob(blob) {
|
|
15
|
+
if (blob == null || typeof blob.text !== "string")
|
|
16
|
+
return { unreadable: "404" };
|
|
17
|
+
return blob.isTruncated ? { unreadable: "truncated" } : { text: blob.text };
|
|
18
|
+
}
|
|
19
|
+
async function readGraphql(repo, requests) {
|
|
20
|
+
const declarations = requests.map((_, i) => `, $e${i}: String!`).join("");
|
|
21
|
+
const fields = requests
|
|
22
|
+
.map((_, i) => `w${i}: object(expression: $e${i}) { ... on Blob { text isTruncated } }`)
|
|
23
|
+
.join(" ");
|
|
24
|
+
const query = `query WorkflowFiles($owner: String!, $name: String!${declarations}) { repository(owner: $owner, name: $name) { ${fields} } }`;
|
|
25
|
+
const variables = { owner: repo.owner, name: repo.name };
|
|
26
|
+
requests.forEach((request, i) => {
|
|
27
|
+
variables[`e${i}`] = workflowFileKey(request);
|
|
28
|
+
});
|
|
29
|
+
const { data } = await graphql(query, variables);
|
|
30
|
+
return requests.map((_, i) => fromBlob(data.repository?.[`w${i}`]));
|
|
31
|
+
}
|
|
32
|
+
async function readOneRest(repo, request) {
|
|
33
|
+
const path = request.path.split("/").map(encodeURIComponent).join("/");
|
|
34
|
+
try {
|
|
35
|
+
const body = restObject(await readRest("GET", `${restRepoPath(repo)}/contents/${path}?ref=${encodeURIComponent(request.ref)}`), "workflow file");
|
|
36
|
+
if (body["encoding"] !== "base64" || typeof body["content"] !== "string") {
|
|
37
|
+
return { unreadable: "truncated" };
|
|
38
|
+
}
|
|
39
|
+
return { text: Buffer.from(body["content"], "base64").toString("utf8") };
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (pollRateLimitRetryAfterMs(error) !== null)
|
|
43
|
+
throw error;
|
|
44
|
+
return {
|
|
45
|
+
unreadable: error instanceof GitHubRequestError ? String(error.status) : "request failed",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* One aliased GraphQL read (or one REST `contents` read per file) of the requested workflow
|
|
51
|
+
* files, best-effort: a failure marks the file unreadable, a rate limit propagates. Files read
|
|
52
|
+
* at a commit SHA are remembered for the process, so a `--until-terminal` loop reads each once.
|
|
53
|
+
*/
|
|
54
|
+
export async function readWorkflowFiles(repo, requests) {
|
|
55
|
+
const results = new Map();
|
|
56
|
+
const pending = new Map();
|
|
57
|
+
for (const request of requests) {
|
|
58
|
+
const known = request.pinned ? memo.get(memoKey(repo, request)) : undefined;
|
|
59
|
+
if (known)
|
|
60
|
+
results.set(workflowFileKey(request), known);
|
|
61
|
+
else
|
|
62
|
+
pending.set(workflowFileKey(request), request);
|
|
63
|
+
}
|
|
64
|
+
if (pending.size === 0)
|
|
65
|
+
return results;
|
|
66
|
+
const wanted = [...pending.values()];
|
|
67
|
+
let answers;
|
|
68
|
+
try {
|
|
69
|
+
answers = await githubOperation("WorkflowFiles", () => readGraphql(repo, wanted), () => Promise.all(wanted.map((request) => readOneRest(repo, request))));
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (pollRateLimitRetryAfterMs(error) !== null || isGithubReadFallbackError(error))
|
|
73
|
+
throw error;
|
|
74
|
+
process.stderr.write(`pr-shepherd: workflow files unavailable (ignored): ${error instanceof Error ? error.message : String(error)}\n`);
|
|
75
|
+
answers = wanted.map(() => ({ unreadable: "request failed" }));
|
|
76
|
+
}
|
|
77
|
+
wanted.forEach((request, i) => {
|
|
78
|
+
const answer = answers[i];
|
|
79
|
+
results.set(workflowFileKey(request), answer);
|
|
80
|
+
if (request.pinned && ("text" in answer || answer.unreadable === "404")) {
|
|
81
|
+
memo.set(memoKey(repo, request), answer);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return results;
|
|
85
|
+
}
|
|
@@ -14,6 +14,19 @@ export function onlyDraftVerificationSelection(result) {
|
|
|
14
14
|
}
|
|
15
15
|
/** Rerunning is mandatory while any selected row is non-terminal; a finished one-PR poll is not the end. */
|
|
16
16
|
const KEEP_WATCHING = "Do not end the turn while any selected row is non-terminal: a one-PR poll returning `CANCEL` or `ESCALATE` finishes only that row, and rows that are `CANCEL`, `ESCALATE`, or handed off do not count. If a background exit wakes you, end the turn and continue then.";
|
|
17
|
+
/**
|
|
18
|
+
* A multi-PR poll reads stack layers without verifying them, so `appears-ready` here is not the
|
|
19
|
+
* READY receipt a `stack --merge` requires. Say so once, only when a stack layer looks ready.
|
|
20
|
+
*/
|
|
21
|
+
function stackReceiptNote(result) {
|
|
22
|
+
const layers = result.prs.filter((item) => item.state === "OPEN" && item.stack && item.reasons.includes("appears-ready"));
|
|
23
|
+
if (layers.length === 0)
|
|
24
|
+
return [];
|
|
25
|
+
const names = layers.map((item) => `#${item.pr}`).join(", ");
|
|
26
|
+
return [
|
|
27
|
+
`2. ${names} ${layers.length === 1 ? "is a native stack layer" : "are native stack layers"}: this poll does not record the READY receipt a stack merge needs. If the user asked to merge, run \`pr-shepherd stack\` with \`--merge\` instead; it starts the one-PR sessions that record them.`,
|
|
28
|
+
];
|
|
29
|
+
}
|
|
17
30
|
export function explicitInstructions(result, rerunCommand) {
|
|
18
31
|
const again = rerunCommand ? `\`${rerunCommand}\`` : "this aggregate command";
|
|
19
32
|
if (result.reason === "all_terminal")
|
|
@@ -21,6 +34,7 @@ export function explicitInstructions(result, rerunCommand) {
|
|
|
21
34
|
result.prs.some((item) => item.reasons.includes("draft-auto-mark-ready-disabled"))
|
|
22
35
|
? "1. Stop — every selected PR is complete for this Shepherd run."
|
|
23
36
|
: "1. Stop — every selected PR is terminal.",
|
|
37
|
+
...stackReceiptNote(result),
|
|
24
38
|
];
|
|
25
39
|
if (result.quotaWarning && result.reason !== "actionable") {
|
|
26
40
|
return [
|
|
@@ -33,7 +47,7 @@ export function explicitInstructions(result, rerunCommand) {
|
|
|
33
47
|
const instructions = [
|
|
34
48
|
"1. Choose each non-WAIT, non-CANCEL row that can proceed independently and run or delegate its exact `pollCommand`.",
|
|
35
49
|
"2. Follow each selected one-PR poll's `## Instructions` until it returns `CANCEL` or `ESCALATE`.",
|
|
36
|
-
`3.
|
|
50
|
+
`3. When the selected one-PR polls return, always run ${again} again: its output, not theirs, decides whether this selection is done. One row's \`ESCALATE\` does not stop work on other rows. ${KEEP_WATCHING}`,
|
|
37
51
|
];
|
|
38
52
|
if (result.prs.some((item) => item.action === "escalate") && !isHandedOffSelection(result)) {
|
|
39
53
|
instructions[0] = `${instructions[0]} Report each \`ESCALATE\` row's reasons to the user now and leave that PR alone; keep working on the other rows.`;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { PollSummaryItem, PollSummaryResult } from "../types.mts";
|
|
1
|
+
import type { PollSummaryItem, PollSummaryResult, StackMergeScope } from "../types.mts";
|
|
2
|
+
import { type ApproveCommands } from "./stack-merge-plan.mts";
|
|
2
3
|
/** Keep aggregate JSON, Markdown, and MCP instructions on one projection. */
|
|
3
|
-
export declare function withPollSummaryInstructions(result: PollSummaryResult, mergeRequested: boolean, rerunCommand?: string): PollSummaryResult;
|
|
4
|
+
export declare function withPollSummaryInstructions(result: PollSummaryResult, mergeRequested: boolean, rerunCommand?: string, scope?: StackMergeScope): PollSummaryResult;
|
|
4
5
|
/** The projected summary, plus the idle layers when the stack plan can only wait on them. */
|
|
5
|
-
export declare function planPollSummary(result: PollSummaryResult, mergeRequested: boolean, rerunCommand?: string): {
|
|
6
|
+
export declare function planPollSummary(result: PollSummaryResult, mergeRequested: boolean, rerunCommand?: string, scope?: StackMergeScope | undefined, approve?: ApproveCommands): {
|
|
6
7
|
result: PollSummaryResult;
|
|
7
8
|
idle?: PollSummaryItem[];
|
|
8
9
|
};
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
import { buildQuotaAwareContinuation } from "../quota-warning.mjs";
|
|
3
3
|
import { explicitInstructions } from "./poll-summary-explicit-instructions.mjs";
|
|
4
|
-
import { appendAutonomousInstructions, appendHumanHandoffInstructions, findHumanHandoffs, idleWaitPlan, isStackLayerReady,
|
|
4
|
+
import { appendAutonomousInstructions, hasListedOwnership, appendHumanHandoffInstructions, findHumanHandoffs, idleWaitPlan, isStackLayerReady, retargetWaitPlan, stackPosition, } from "./stack-drain.mjs";
|
|
5
|
+
import { lowerReadyNote } from "./stack-lower-ready-note.mjs";
|
|
6
|
+
import { planStackMerge } from "./stack-merge-plan.mjs";
|
|
7
|
+
import { aboveThroughTarget } from "./stack-merge-scope.mjs";
|
|
8
|
+
import { ownershipBoundaryStep } from "./stack-ownership.mjs";
|
|
5
9
|
import { appendStackRerunInstruction, onlyDraftReadinessVerification, splitStackWork, stackRerunTarget, } from "./stack-work.mjs";
|
|
6
10
|
/** Keep aggregate JSON, Markdown, and MCP instructions on one projection. */
|
|
7
|
-
export function withPollSummaryInstructions(result, mergeRequested, rerunCommand) {
|
|
8
|
-
return planPollSummary(result, mergeRequested, rerunCommand).result;
|
|
11
|
+
export function withPollSummaryInstructions(result, mergeRequested, rerunCommand, scope) {
|
|
12
|
+
return planPollSummary(result, mergeRequested, rerunCommand, scope).result;
|
|
9
13
|
}
|
|
10
14
|
/** The projected summary, plus the idle layers when the stack plan can only wait on them. */
|
|
11
|
-
export function planPollSummary(result, mergeRequested, rerunCommand) {
|
|
15
|
+
export function planPollSummary(result, mergeRequested, rerunCommand, scope = mergeRequested ? { kind: "all" } : undefined, approve) {
|
|
12
16
|
if (result.selection.kind !== "stack") {
|
|
13
17
|
return { result: { ...result, instructions: explicitInstructions(result, rerunCommand) } };
|
|
14
18
|
}
|
|
@@ -45,11 +49,21 @@ export function planPollSummary(result, mergeRequested, rerunCommand) {
|
|
|
45
49
|
reasons: [...layer.reasons, "closed-unmerged-dependency"],
|
|
46
50
|
};
|
|
47
51
|
}
|
|
48
|
-
if (layer.state
|
|
52
|
+
if (layer.state === "CLOSED") {
|
|
49
53
|
return {
|
|
50
54
|
...layer,
|
|
51
55
|
action: "escalate",
|
|
52
|
-
reasons: [...layer.reasons, "
|
|
56
|
+
reasons: [...layer.reasons, "closed-unmerged-layer"],
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
if (layer.state === "UNKNOWN") {
|
|
60
|
+
// A fetch gap, not a human decision: wait and retry under the stack stall timer.
|
|
61
|
+
return {
|
|
62
|
+
...layer,
|
|
63
|
+
action: "wait",
|
|
64
|
+
reasons: layer.reasons.includes("unverified-stack-state")
|
|
65
|
+
? layer.reasons
|
|
66
|
+
: [...layer.reasons, "unverified-stack-state"],
|
|
53
67
|
};
|
|
54
68
|
}
|
|
55
69
|
if (layer.reasons.includes("draft-auto-mark-ready-disabled") &&
|
|
@@ -60,8 +74,21 @@ export function planPollSummary(result, mergeRequested, rerunCommand) {
|
|
|
60
74
|
return layer;
|
|
61
75
|
}),
|
|
62
76
|
};
|
|
63
|
-
const planned = planStack(projected, mergeRequested, rerunCommand);
|
|
77
|
+
const planned = planStack(projected, mergeRequested, rerunCommand, mergeRequested ? scope : undefined, approve);
|
|
64
78
|
const instructions = [...planned.instructions];
|
|
79
|
+
if (planned.action === "shepherd" || planned.action === "wait") {
|
|
80
|
+
const note = lowerReadyNote(projected, scope, rerunCommand);
|
|
81
|
+
if (note)
|
|
82
|
+
instructions.push(`${instructions.length + 1}. ${note}`);
|
|
83
|
+
}
|
|
84
|
+
const boundary = planned.action === "shepherd" || planned.action === "merge"
|
|
85
|
+
? ownershipBoundaryStep(projected)
|
|
86
|
+
: undefined;
|
|
87
|
+
if (boundary) {
|
|
88
|
+
// The rerun step stays last; renumber around the inserted step.
|
|
89
|
+
instructions.splice(Math.max(instructions.length - 1, 0), 0, `0. ${boundary}`);
|
|
90
|
+
instructions.forEach((line, i) => (instructions[i] = line.replace(/^\d+\. /, `${i + 1}. `)));
|
|
91
|
+
}
|
|
65
92
|
if (result.quotaWarning && planned.action === "shepherd") {
|
|
66
93
|
instructions.push(buildQuotaAwareContinuation(result.quotaWarning, `${instructions.length + 1}. After completing the stack action,`));
|
|
67
94
|
}
|
|
@@ -82,32 +109,37 @@ export function planPollSummary(result, mergeRequested, rerunCommand) {
|
|
|
82
109
|
...(planned.idle && { idle: planned.idle }),
|
|
83
110
|
};
|
|
84
111
|
}
|
|
85
|
-
function planStack(result, mergeRequested, rerunCommand) {
|
|
112
|
+
function planStack(result, mergeRequested, rerunCommand, scope, approve) {
|
|
86
113
|
const again = stackRerunTarget(rerunCommand);
|
|
114
|
+
const partial = hasListedOwnership(result);
|
|
87
115
|
const open = result.prs.filter((item) => item.state === "OPEN");
|
|
88
116
|
const gaps = result.stackAncestry ?? [];
|
|
89
117
|
const staleChildren = new Set(gaps.map((gap) => gap.childPr));
|
|
90
|
-
const
|
|
91
|
-
const
|
|
118
|
+
const unverified = result.prs.filter((item) => item.state === "UNKNOWN");
|
|
119
|
+
const stackMergeable = gaps.length === 0 && unverified.length === 0 && open.every(isStackLayerReady);
|
|
120
|
+
const outside = aboveThroughTarget(result, scope);
|
|
121
|
+
const work = splitStackWork(open.filter((item) => (!isStackLayerReady(item) || staleChildren.has(item.pr)) &&
|
|
122
|
+
item.action !== "escalate" &&
|
|
123
|
+
!outside.has(item.pr)), staleChildren);
|
|
92
124
|
const runnableCandidates = work.sessions.filter((item) => item.pollCommand);
|
|
93
125
|
const missingCommands = work.sessions.filter((item) => !item.pollCommand);
|
|
94
126
|
const agentWork = runnableCandidates.length > 0;
|
|
95
127
|
// Only owned work defers a human handoff: rerunning cannot advance another author's layer.
|
|
96
128
|
const ownedWork = runnableCandidates.some((item) => item.owned);
|
|
97
|
-
const drain =
|
|
129
|
+
const drain = planStackMerge(result, scope, rerunCommand, approve);
|
|
98
130
|
if (drain)
|
|
99
131
|
return drain;
|
|
100
132
|
const handoffs = findHumanHandoffs(result);
|
|
101
133
|
if (handoffs) {
|
|
102
134
|
const instructions = [];
|
|
103
|
-
appendAutonomousInstructions(instructions, runnableCandidates);
|
|
135
|
+
appendAutonomousInstructions(instructions, runnableCandidates, partial);
|
|
104
136
|
const stop = !ownedWork;
|
|
105
137
|
appendHumanHandoffInstructions(instructions, handoffs, stop);
|
|
106
138
|
for (const item of missingCommands) {
|
|
107
139
|
instructions.push(`${instructions.length + 1}. PR #${item.pr} needs a one-PR session, but Shepherd could not produce its command. Ask for direction.`);
|
|
108
140
|
}
|
|
109
141
|
if (ownedWork) {
|
|
110
|
-
const rerun = onlyDraftReadinessVerification(work.sessions, work.idle) &&
|
|
142
|
+
const rerun = onlyDraftReadinessVerification(work.sessions, [...work.idle, ...unverified]) &&
|
|
111
143
|
work.sessions.every((item) => item.owned)
|
|
112
144
|
? `If every listed one-PR probe returns \`[CANCEL]\` with reason \`auto-mark-ready-disabled\`, report the human handoff above and stop this \`stack\` command. If any probe returns \`[ESCALATE]\`, report that handoff and stop after the other probes finish. Otherwise follow each probe's instructions and rerun ${again} when that work completes.`
|
|
113
145
|
: `After the listed one-PR sessions, rerun ${again}. Stop for the human handoff only when no autonomous shepherding remains.`;
|
|
@@ -115,7 +147,7 @@ function planStack(result, mergeRequested, rerunCommand) {
|
|
|
115
147
|
}
|
|
116
148
|
return { action: stop ? "escalate" : "shepherd", stackMergeable: false, instructions };
|
|
117
149
|
}
|
|
118
|
-
if (open.length === 0) {
|
|
150
|
+
if (open.length === 0 && unverified.length === 0) {
|
|
119
151
|
return {
|
|
120
152
|
action: "cancel",
|
|
121
153
|
stackMergeable: true,
|
|
@@ -125,7 +157,7 @@ function planStack(result, mergeRequested, rerunCommand) {
|
|
|
125
157
|
if (!stackMergeable) {
|
|
126
158
|
if (missingCommands.length > 0) {
|
|
127
159
|
const instructions = [];
|
|
128
|
-
appendAutonomousInstructions(instructions, runnableCandidates);
|
|
160
|
+
appendAutonomousInstructions(instructions, runnableCandidates, partial);
|
|
129
161
|
for (const item of missingCommands) {
|
|
130
162
|
instructions.push(`${instructions.length + 1}. PR #${item.pr} needs a one-PR session, but Shepherd could not produce its command. ${ownedWork ? "After autonomous shepherding, ask" : "Stop and ask"} for direction.`);
|
|
131
163
|
}
|
|
@@ -135,7 +167,7 @@ function planStack(result, mergeRequested, rerunCommand) {
|
|
|
135
167
|
return { action: ownedWork ? "shepherd" : "escalate", stackMergeable: false, instructions };
|
|
136
168
|
}
|
|
137
169
|
if (!agentWork) {
|
|
138
|
-
if (work.held.length > 0 && work.idle.length === 0) {
|
|
170
|
+
if (work.held.length > 0 && work.idle.length === 0 && unverified.length === 0) {
|
|
139
171
|
return {
|
|
140
172
|
action: "cancel",
|
|
141
173
|
stackMergeable: false,
|
|
@@ -144,17 +176,17 @@ function planStack(result, mergeRequested, rerunCommand) {
|
|
|
144
176
|
],
|
|
145
177
|
};
|
|
146
178
|
}
|
|
147
|
-
return idleWaitPlan(work.idle);
|
|
179
|
+
return idleWaitPlan([...work.idle, ...unverified]);
|
|
148
180
|
}
|
|
149
181
|
const instructions = [];
|
|
150
|
-
appendAutonomousInstructions(instructions, work.sessions);
|
|
151
|
-
if (onlyDraftReadinessVerification(work.sessions, work.idle) &&
|
|
182
|
+
appendAutonomousInstructions(instructions, work.sessions, partial);
|
|
183
|
+
if (onlyDraftReadinessVerification(work.sessions, [...work.idle, ...unverified]) &&
|
|
152
184
|
work.sessions.every((item) => item.owned)) {
|
|
153
185
|
instructions.push(`${instructions.length + 1}. If every listed one-PR probe returns \`[CANCEL]\` with reason \`auto-mark-ready-disabled\`, stop shepherding this stack and leave those drafts unchanged. If any probe returns \`[ESCALATE]\`, report that handoff and stop after the other probes finish. Otherwise follow each probe's instructions and rerun ${again} when that work completes.`);
|
|
154
186
|
return { action: "shepherd", stackMergeable: false, instructions };
|
|
155
187
|
}
|
|
156
188
|
const action = appendStackRerunInstruction(instructions, work.sessions, `After the selected one-PR sessions, rerun ${again}.`);
|
|
157
|
-
return
|
|
189
|
+
return sessionsPlan(action, work.sessions, false, instructions);
|
|
158
190
|
}
|
|
159
191
|
if (open.some((item) => item.isInMergeQueue)) {
|
|
160
192
|
return {
|
|
@@ -176,9 +208,9 @@ function planStack(result, mergeRequested, rerunCommand) {
|
|
|
176
208
|
if (!mergeRequested) {
|
|
177
209
|
const instructions = [];
|
|
178
210
|
const sessions = open.filter((item) => item.action !== "cancel");
|
|
179
|
-
appendAutonomousInstructions(instructions, sessions);
|
|
211
|
+
appendAutonomousInstructions(instructions, sessions, partial);
|
|
180
212
|
const action = appendStackRerunInstruction(instructions, sessions, `After the selected one-PR sessions, rerun ${again}.`);
|
|
181
|
-
return
|
|
213
|
+
return sessionsPlan(action, sessions, stackMergeable, instructions);
|
|
182
214
|
}
|
|
183
215
|
return retargetWaitPlan(open[0]);
|
|
184
216
|
}
|
|
@@ -188,3 +220,9 @@ function closedDependency(items, pr) {
|
|
|
188
220
|
return Boolean(lastOpen &&
|
|
189
221
|
items.some((item) => item.pr === pr && item.state === "CLOSED" && stackPosition(item) < stackPosition(lastOpen)));
|
|
190
222
|
}
|
|
223
|
+
/** Routed sessions, or an idle wait (under the stack stall timer) when every one is another author's. */
|
|
224
|
+
function sessionsPlan(action, layers, stackMergeable, instructions) {
|
|
225
|
+
return action === "wait"
|
|
226
|
+
? { action, stackMergeable, waiting: true, idle: layers, instructions }
|
|
227
|
+
: { action, stackMergeable, instructions };
|
|
228
|
+
}
|
|
@@ -4,7 +4,7 @@ import { ShepherdError } from "../exit-codes.mjs";
|
|
|
4
4
|
import { getRepoInfo } from "../github/client.mjs";
|
|
5
5
|
import { getGithubTransport } from "../github/transport.mjs";
|
|
6
6
|
import { withApiTelemetryScope, summarizeApiTelemetry } from "../github/api-telemetry.mjs";
|
|
7
|
-
import { aggregateRerunCommand } from "../github/poll-summary-command.mjs";
|
|
7
|
+
import { aggregateRerunCommand, stackApprovalCommands } from "../github/poll-summary-command.mjs";
|
|
8
8
|
import { fetchPollSummary } from "../github/poll-summary.mjs";
|
|
9
9
|
import { writeStackHandoffs } from "../github/stack-handoff.mjs";
|
|
10
10
|
import { aggregateQuotaWarning, carryQuotaWarning, quotaPollIntervalMs } from "./poll-quota.mjs";
|
|
@@ -12,7 +12,10 @@ import { aggregateCancelFromPulls, aggregateRateLimitTargets } from "./poll-rate
|
|
|
12
12
|
import { createUntilTerminalRateLimitRetry } from "./poll-rate-limit-wait.mjs";
|
|
13
13
|
import { planPollSummary, withPollSummaryInstructions } from "./poll-summary-instructions.mjs";
|
|
14
14
|
import { summaryStatusSignature } from "./poll-summary-signature.mjs";
|
|
15
|
-
import { applyStackStallGuard } from "./stack-stall.mjs";
|
|
15
|
+
import { applyStackStallGuard, isStackRepairTick } from "./stack-stall.mjs";
|
|
16
|
+
import { applyStackOwnership, listedLayerLeftStack, missingListedLayers, } from "./stack-ownership.mjs";
|
|
17
|
+
import { stackRerunTarget } from "./stack-work.mjs";
|
|
18
|
+
import { requestedMergeScope, stackAddedLayers } from "./stack-merge-scope.mjs";
|
|
16
19
|
import { aggregateDeadline } from "./stall-deadline.mjs";
|
|
17
20
|
import { aggregateTargets, pauseBeforeNextTick, withPollEvents, } from "./poll-events.mjs";
|
|
18
21
|
const MAX_TIMER_MS = 2 ** 31 - 1;
|
|
@@ -50,10 +53,17 @@ async function handOffRoutedLayers(tick) {
|
|
|
50
53
|
}
|
|
51
54
|
async function readPollSummaryTick(opts) {
|
|
52
55
|
const repo = opts.targetRepository ?? (await getRepoInfo());
|
|
53
|
-
const
|
|
56
|
+
const fetchedRaw = await fetchPollSummary(opts, repo);
|
|
57
|
+
const fetched = fetchedRaw.selection.kind === "stack"
|
|
58
|
+
? {
|
|
59
|
+
...fetchedRaw,
|
|
60
|
+
...applyStackOwnership(fetchedRaw.selection, fetchedRaw.prs, opts.stackOwned),
|
|
61
|
+
}
|
|
62
|
+
: fetchedRaw;
|
|
54
63
|
const allTerminal = fetched.prs.every((item) => item.action === "cancel");
|
|
55
64
|
const actionable = fetched.prs.some((item) => item.action !== "wait" && item.action !== "cancel");
|
|
56
|
-
const
|
|
65
|
+
const scope = requestedMergeScope(opts);
|
|
66
|
+
const summary = {
|
|
57
67
|
mode: "summary",
|
|
58
68
|
repo: `${repo.owner}/${repo.name}`,
|
|
59
69
|
selection: fetched.selection,
|
|
@@ -61,7 +71,16 @@ async function readPollSummaryTick(opts) {
|
|
|
61
71
|
prs: fetched.prs,
|
|
62
72
|
...(fetched.stackAncestry?.length && { stackAncestry: fetched.stackAncestry }),
|
|
63
73
|
...(fetched.allowedMergeMethods && { allowedMergeMethods: fetched.allowedMergeMethods }),
|
|
64
|
-
}
|
|
74
|
+
};
|
|
75
|
+
const rerunCommand = aggregateRerunCommand(`${repo.owner}/${repo.name}`, fetched.selection, opts);
|
|
76
|
+
const missing = missingListedLayers(fetchedRaw.prs, opts.stackOwned);
|
|
77
|
+
if (fetchedRaw.selection.kind === "stack" && missing.length > 0) {
|
|
78
|
+
// A teammate removed a listed PR from the stack: the listed ownership no longer matches it.
|
|
79
|
+
const escalated = listedLayerLeftStack(summary, missing, stackRerunTarget(rerunCommand));
|
|
80
|
+
return { result: escalated, repo };
|
|
81
|
+
}
|
|
82
|
+
const addedLayers = await stackAddedLayers(summary, scope, rerunCommand);
|
|
83
|
+
const planned = planPollSummary({ ...summary, ...(addedLayers.length > 0 && { addedLayers }) }, scope !== undefined, rerunCommand, scope, (extra) => stackApprovalCommands(`${repo.owner}/${repo.name}`, fetched.selection, opts, extra));
|
|
65
84
|
const result = await applyStackStallGuard(planned, repo, opts.stallTimeoutSeconds ?? loadConfig().iterate["stall-timeout-minutes"] * 60);
|
|
66
85
|
return { result, repo, ...(fetched.handoffSource && { handoffSource: fetched.handoffSource }) };
|
|
67
86
|
}
|
|
@@ -137,8 +156,9 @@ async function runAggregatePollCore(opts, events) {
|
|
|
137
156
|
? last.nextAction === "cancel"
|
|
138
157
|
: last.prs.every((item) => item.action === "cancel");
|
|
139
158
|
const immediate = last.selection.kind === "stack"
|
|
140
|
-
? (last
|
|
141
|
-
last.
|
|
159
|
+
? isStackRepairTick(last) ||
|
|
160
|
+
((last.nextAction === "escalate" || last.nextAction === "merge") &&
|
|
161
|
+
last.reason !== "waiting")
|
|
142
162
|
: last.prs.some((item) => ["escalate", "merge", "mark_ready"].includes(item.action));
|
|
143
163
|
const hasFix = last.selection.kind === "stack"
|
|
144
164
|
? last.nextAction === "shepherd" && last.reason !== "waiting"
|
|
@@ -226,8 +246,16 @@ function attachUsage(result, opts) {
|
|
|
226
246
|
// A disappeared native stack is an aggregate-level terminal handoff. Keep
|
|
227
247
|
// that explicit escalation intact even when the one-PR fallback contains
|
|
228
248
|
// open orphan rows that would otherwise be re-planned as triage.
|
|
229
|
-
if (enriched.selection.kind === "stack" &&
|
|
230
|
-
|
|
249
|
+
if (enriched.selection.kind === "stack" &&
|
|
250
|
+
(enriched.nextAction === "escalate" || isStackRepairTick(enriched))) {
|
|
251
|
+
return withoutImpliedOwnership(enriched);
|
|
231
252
|
}
|
|
232
|
-
|
|
253
|
+
const scope = requestedMergeScope(opts);
|
|
254
|
+
return withoutImpliedOwnership(withPollSummaryInstructions(enriched, scope !== undefined, aggregateRerunCommand(enriched.repo, enriched.selection, opts), scope));
|
|
255
|
+
}
|
|
256
|
+
/** Whole-stack ownership is the default, so rows say `owned` only when the caller listed PRs. */
|
|
257
|
+
function withoutImpliedOwnership(result) {
|
|
258
|
+
if (result.selection.kind !== "stack" || result.selection.owned)
|
|
259
|
+
return result;
|
|
260
|
+
return { ...result, prs: result.prs.map(({ owned: _owned, ...item }) => item) };
|
|
233
261
|
}
|
package/bin/commands/poll.mjs
CHANGED
|
@@ -112,7 +112,7 @@ async function runPollCore(opts, events) {
|
|
|
112
112
|
}
|
|
113
113
|
break;
|
|
114
114
|
}
|
|
115
|
-
if (lastResult.action === "wait" && !pastDebounce) {
|
|
115
|
+
if (lastResult.action === "wait" && (!pastDebounce || untilTerminal)) {
|
|
116
116
|
if (pendingQuotaWarning === undefined)
|
|
117
117
|
debounceUntil = null;
|
|
118
118
|
const elapsedMs = Date.now() - start;
|
|
@@ -136,7 +136,9 @@ async function runPollCore(opts, events) {
|
|
|
136
136
|
}
|
|
137
137
|
continue;
|
|
138
138
|
}
|
|
139
|
-
if (swallowsMarkReady &&
|
|
139
|
+
if (swallowsMarkReady &&
|
|
140
|
+
lastResult.action === "mark_ready" &&
|
|
141
|
+
(!pastDebounce || untilTerminal)) {
|
|
140
142
|
debounceUntil = null;
|
|
141
143
|
const ready = lastResult;
|
|
142
144
|
const stop = await pause(ready, () => writeRuleAutoResolveProgress(ready));
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { findHumanHandoffs, appendHumanHandoffInstructions } from "./stack-handoffs.mts";
|
|
2
2
|
import type { PollSummaryItem, PollSummaryResult, StackNextAction } from "../types.mts";
|
|
3
|
+
export { isStackLayerReady, stackPosition } from "./stack-merge-scope.mts";
|
|
3
4
|
export interface StackPlan {
|
|
4
5
|
action: StackNextAction;
|
|
5
6
|
stackMergeable: boolean;
|
|
@@ -8,7 +9,6 @@ export interface StackPlan {
|
|
|
8
9
|
idle?: PollSummaryItem[];
|
|
9
10
|
instructions: string[];
|
|
10
11
|
}
|
|
11
|
-
export declare function planPrefixDrain(result: PollSummaryResult, mergeRequested: boolean, rerunCommand?: string): StackPlan | undefined;
|
|
12
12
|
/**
|
|
13
13
|
* A merge-requested, fully ready stack whose bottom open layer still targets
|
|
14
14
|
* the merged layer below it until GitHub retargets it onto the stack base.
|
|
@@ -17,6 +17,6 @@ export declare function retargetWaitPlan(first: PollSummaryItem): StackPlan;
|
|
|
17
17
|
/** Every remaining layer only waits on CI or merge state. */
|
|
18
18
|
export declare function idleWaitPlan(idle: PollSummaryItem[]): StackPlan;
|
|
19
19
|
export declare function describeIdleLayers(idle: PollSummaryItem[]): string;
|
|
20
|
-
|
|
21
|
-
export declare function
|
|
22
|
-
export declare function
|
|
20
|
+
/** True when the caller listed its own PRs, so rows carry `owned` and others are not theirs. */
|
|
21
|
+
export declare function hasListedOwnership(result: PollSummaryResult): boolean;
|
|
22
|
+
export declare function appendAutonomousInstructions(instructions: string[], candidates: PollSummaryItem[], partial?: boolean): void;
|
|
@@ -1,104 +1,9 @@
|
|
|
1
|
-
import { findHumanHandoffs, appendHumanHandoffInstructions } from "./stack-handoffs.mjs";
|
|
2
1
|
export { findHumanHandoffs, appendHumanHandoffInstructions } from "./stack-handoffs.mjs";
|
|
3
|
-
|
|
2
|
+
export { isStackLayerReady, stackPosition } from "./stack-merge-scope.mjs";
|
|
4
3
|
import { stackLayerBlockReason } from "./stack-layer-readiness.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
function readyPrefixTop(result) {
|
|
9
|
-
const layers = [...result.prs].sort((left, right) => stackPosition(left) - stackPosition(right));
|
|
10
|
-
if (layers.some((item) => item.state === "OPEN" && item.isInMergeQueue))
|
|
11
|
-
return undefined;
|
|
12
|
-
const open = layers.filter((item) => item.state === "OPEN");
|
|
13
|
-
const bottom = open[0];
|
|
14
|
-
if (!bottom || !isStackLayer(bottom) || bottom.state !== "OPEN")
|
|
15
|
-
return undefined;
|
|
16
|
-
if (bottom.baseRefName !== bottom.stack.baseRefName)
|
|
17
|
-
return undefined;
|
|
18
|
-
const stale = new Set((result.stackAncestry ?? []).map((gap) => gap.childPr));
|
|
19
|
-
let top;
|
|
20
|
-
for (const item of open) {
|
|
21
|
-
if (!isStackLayer(item))
|
|
22
|
-
break;
|
|
23
|
-
if (item.action === "escalate" || !isStackLayerReady(item) || stale.has(item.pr))
|
|
24
|
-
break;
|
|
25
|
-
if (layers.some((layer) => layer.state === "CLOSED" && stackPosition(layer) < stackPosition(item)))
|
|
26
|
-
break;
|
|
27
|
-
top = item;
|
|
28
|
-
}
|
|
29
|
-
return top;
|
|
30
|
-
}
|
|
31
|
-
export function planPrefixDrain(result, mergeRequested, rerunCommand) {
|
|
32
|
-
if (!mergeRequested)
|
|
33
|
-
return undefined;
|
|
34
|
-
const top = readyPrefixTop(result);
|
|
35
|
-
if (!top)
|
|
36
|
-
return undefined;
|
|
37
|
-
const gaps = result.stackAncestry ?? [];
|
|
38
|
-
const staleChildren = new Set(gaps.map((gap) => gap.childPr));
|
|
39
|
-
const open = result.prs
|
|
40
|
-
.filter((item) => item.state === "OPEN")
|
|
41
|
-
.sort((left, right) => stackPosition(left) - stackPosition(right));
|
|
42
|
-
const above = splitStackWork(open.filter((item) => stackPosition(item) > stackPosition(top) &&
|
|
43
|
-
item.action !== "escalate" &&
|
|
44
|
-
(!isStackLayerReady(item) || staleChildren.has(item.pr))), staleChildren);
|
|
45
|
-
const span = open[0]?.pr === top.pr ? "that layer alone" : `PR #${top.pr} and every unmerged layer below it`;
|
|
46
|
-
const instructions = [];
|
|
47
|
-
if (getGithubTransport() === "rest" || top.transport === "rest") {
|
|
48
|
-
// Upper layers target their parent; the prefix merges into the stack trunk.
|
|
49
|
-
const trunk = result.prs.find((item) => item.baseRefName === top.stack.baseRefName);
|
|
50
|
-
const plan = buildMergeCommandPlan({
|
|
51
|
-
transport: "rest",
|
|
52
|
-
pr: top.pr,
|
|
53
|
-
repo: result.repo,
|
|
54
|
-
nodeId: "",
|
|
55
|
-
headSha: top.headRefOid,
|
|
56
|
-
queue: trunk?.requiresMergeQueue === true,
|
|
57
|
-
queueKnown: trunk?.requiresMergeQueue !== undefined,
|
|
58
|
-
allowedMergeMethods: result.allowedMergeMethods,
|
|
59
|
-
expectedStack: {
|
|
60
|
-
number: top.stack.number,
|
|
61
|
-
baseRefName: top.stack.baseRefName,
|
|
62
|
-
prefix: [...result.prs]
|
|
63
|
-
.sort((left, right) => stackPosition(left) - stackPosition(right))
|
|
64
|
-
.filter((item) => stackPosition(item) <= stackPosition(top))
|
|
65
|
-
.map((item) => ({
|
|
66
|
-
pr: item.pr,
|
|
67
|
-
headRefName: item.headRefName,
|
|
68
|
-
headRefOid: item.headRefOid,
|
|
69
|
-
baseRefName: item.baseRefName,
|
|
70
|
-
})),
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
if ("unavailable" in plan)
|
|
74
|
-
return {
|
|
75
|
-
action: "escalate",
|
|
76
|
-
stackMergeable: false,
|
|
77
|
-
instructions: [`1. ${plan.unavailable}`],
|
|
78
|
-
};
|
|
79
|
-
instructions[0] = `1. PR #${top.pr} is the highest ready layer of native stack #${top.stack.number}. Run \`${renderMergeCommand(plan.command)}\` to request merging ${span}. If status is \`pending\`, rerun that command at the configured cadence to resume its UUID. \`enqueued\` is not merged. Shepherd revalidates every open lower layer's READY receipt before submission.`;
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
const method = stackMergeFlag(result.allowedMergeMethods);
|
|
83
|
-
if ("unavailable" in method)
|
|
84
|
-
return {
|
|
85
|
-
action: "escalate",
|
|
86
|
-
stackMergeable: false,
|
|
87
|
-
instructions: [`1. ${method.unavailable}`],
|
|
88
|
-
};
|
|
89
|
-
instructions[0] = `1. PR #${top.pr} is the highest open layer of stack #${top.stack.number} in \`${result.repo}\` whose open lower layers are all ready. Run \`GH_REPO=${result.repo} gh stack merge ${top.pr} --yes ${method.flag}\` to merge ${span}. If \`gh stack\` is an unknown command, run \`gh extension install github/gh-stack\`, then rerun that merge command. Do not rebase, push, or run \`gh stack push\`.`;
|
|
90
|
-
}
|
|
91
|
-
appendAutonomousInstructions(instructions, above.sessions);
|
|
92
|
-
const handoffs = findHumanHandoffs(result);
|
|
93
|
-
if (handoffs)
|
|
94
|
-
appendHumanHandoffInstructions(instructions, handoffs, false);
|
|
95
|
-
instructions.push(`${instructions.length + 1}. After the merge attempt, rerun ${rerunCommand ? stackRerunTarget(rerunCommand) : "this same `stack --merge` command"}; GitHub retargets the next layer onto \`${top.stack.baseRefName}\`. Shepherd any layer that GitHub rejects or ejects.`);
|
|
96
|
-
return {
|
|
97
|
-
action: "merge",
|
|
98
|
-
stackMergeable: gaps.length === 0 && open.every(isStackLayerReady),
|
|
99
|
-
instructions,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
4
|
+
/** The layer's only blocker is its missing one-PR READY receipt. */
|
|
5
|
+
const onlyLacksReceipt = (item) => item.reasons.includes("ready-receipt-required") &&
|
|
6
|
+
stackLayerBlockReason(item) === "no-ready-receipt";
|
|
102
7
|
/**
|
|
103
8
|
* A merge-requested, fully ready stack whose bottom open layer still targets
|
|
104
9
|
* the merged layer below it until GitHub retargets it onto the stack base.
|
|
@@ -121,7 +26,7 @@ export function idleWaitPlan(idle) {
|
|
|
121
26
|
waiting: true,
|
|
122
27
|
idle,
|
|
123
28
|
instructions: [
|
|
124
|
-
`1. No one-PR session can advance the stack yet: ${describeIdleLayers(idle)}. Recheck at the configured polling cadence.`,
|
|
29
|
+
`1. No one-PR session can advance the stack yet: ${describeIdleLayers(idle)}. Recheck at the configured polling cadence; Shepherd escalates \`stall-timeout\` if the stack does not change.`,
|
|
125
30
|
],
|
|
126
31
|
};
|
|
127
32
|
}
|
|
@@ -135,27 +40,28 @@ function sessionInstruction(item) {
|
|
|
135
40
|
return ` PR #${item.pr} needs a one-PR Shepherd session, but no command was available.`;
|
|
136
41
|
}
|
|
137
42
|
const queueNote = item.queueRemoval
|
|
138
|
-
? " That session fixes failing queue CI, or
|
|
43
|
+
? " That session fixes failing queue CI, or investigates a removal with no failed check once, then escalates if it is unchanged."
|
|
139
44
|
: "";
|
|
140
|
-
|
|
45
|
+
const receiptNote = onlyLacksReceipt(item)
|
|
46
|
+
? " It looks ready, but only its own one-PR session records the READY receipt a stack merge needs."
|
|
47
|
+
: "";
|
|
48
|
+
return `${removal} Run \`${item.pollCommand}\`.${queueNote}${receiptNote}`;
|
|
141
49
|
}
|
|
142
50
|
export function describeIdleLayers(idle) {
|
|
143
51
|
return idle.map((item) => `PR #${item.pr} (${item.reasons.join(", ")})`).join("; ");
|
|
144
52
|
}
|
|
145
|
-
|
|
53
|
+
/** True when the caller listed its own PRs, so rows carry `owned` and others are not theirs. */
|
|
54
|
+
export function hasListedOwnership(result) {
|
|
55
|
+
return result.selection.kind === "stack" && result.selection.owned !== undefined;
|
|
56
|
+
}
|
|
57
|
+
export function appendAutonomousInstructions(instructions, candidates, partial = false) {
|
|
146
58
|
if (candidates.length === 0)
|
|
147
59
|
return;
|
|
148
|
-
|
|
60
|
+
const separate = candidates.some(onlyLacksReceipt)
|
|
61
|
+
? " Run each command as its own session: one multi-PR `pr-shepherd <PR> <PR>` poll records no READY receipts."
|
|
62
|
+
: "";
|
|
63
|
+
instructions.push(`${instructions.length + 1}. ${partial ? "Start one concurrent one-PR session per command below, only for `owned` rows; none for layers without one." : "Start one concurrent one-PR session per command below; none for layers without one."}${separate}`);
|
|
149
64
|
for (const item of candidates) {
|
|
150
65
|
instructions.push(`${instructions.length + 1}.${sessionInstruction(item)}`);
|
|
151
66
|
}
|
|
152
67
|
}
|
|
153
|
-
export function isStackLayerReady(item) {
|
|
154
|
-
return item.stack !== undefined && stackLayerBlockReason(item) === undefined;
|
|
155
|
-
}
|
|
156
|
-
export function stackPosition(item) {
|
|
157
|
-
return item.stack?.position ?? Number.MAX_SAFE_INTEGER;
|
|
158
|
-
}
|
|
159
|
-
function isStackLayer(item) {
|
|
160
|
-
return item.stack !== undefined;
|
|
161
|
-
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { PollSummaryItem, PollSummaryResult } from "../types.mts";
|
|
2
|
-
/** Layers only a human can resolve: a closed
|
|
2
|
+
/** Layers only a human can resolve: a closed layer or an escalation. An unreadable state waits instead. */
|
|
3
3
|
export interface HumanHandoffs {
|
|
4
4
|
closedDependency?: PollSummaryItem;
|
|
5
|
-
|
|
5
|
+
closedLayer?: PollSummaryItem;
|
|
6
6
|
escalated: PollSummaryItem[];
|
|
7
7
|
}
|
|
8
8
|
export declare function findHumanHandoffs(result: PollSummaryResult): HumanHandoffs | undefined;
|
|
9
9
|
/** Name every human handoff; `stop` when no autonomous work precedes it. */
|
|
10
|
-
export declare function appendHumanHandoffInstructions(instructions: string[], { closedDependency,
|
|
10
|
+
export declare function appendHumanHandoffInstructions(instructions: string[], { closedDependency, closedLayer, escalated }: HumanHandoffs, stop: boolean): void;
|