pr-shepherd 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/graphql-http.mjs +8 -6
- package/bin/github/graphql-tolerated-errors.d.mts +3 -0
- package/bin/github/graphql-tolerated-errors.mjs +20 -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
|
@@ -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;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { stackPosition } from "./stack-
|
|
1
|
+
import { stackPosition } from "./stack-merge-scope.mjs";
|
|
2
2
|
export function findHumanHandoffs(result) {
|
|
3
3
|
const lastOpen = result.prs.filter((item) => item.state === "OPEN").at(-1);
|
|
4
4
|
const closedDependency = result.prs.find((item) => item.state === "CLOSED" && lastOpen && stackPosition(item) < stackPosition(lastOpen));
|
|
5
|
-
const
|
|
5
|
+
const closedLayer = result.prs.find((item) => item.state === "CLOSED");
|
|
6
6
|
const escalated = result.prs.filter((item) => item.action === "escalate");
|
|
7
|
-
return closedDependency ||
|
|
8
|
-
? { closedDependency,
|
|
7
|
+
return closedDependency || closedLayer || escalated.length > 0
|
|
8
|
+
? { closedDependency, closedLayer, escalated }
|
|
9
9
|
: undefined;
|
|
10
10
|
}
|
|
11
11
|
/** Name every human handoff; `stop` when no autonomous work precedes it. */
|
|
12
|
-
export function appendHumanHandoffInstructions(instructions, { closedDependency,
|
|
12
|
+
export function appendHumanHandoffInstructions(instructions, { closedDependency, closedLayer, escalated }, stop) {
|
|
13
13
|
const ask = stop ? "Stop and ask" : "After autonomous shepherding, ask";
|
|
14
14
|
if (closedDependency) {
|
|
15
15
|
instructions.push(`${instructions.length + 1}. PR #${closedDependency.pr} was closed without merging below an open layer. ${ask} the stack owner whether to restore that dependency or rebuild the upper branches.`);
|
|
16
16
|
}
|
|
17
|
-
if (
|
|
18
|
-
instructions.push(`${instructions.length + 1}. PR #${
|
|
17
|
+
if (closedLayer && closedLayer.pr !== closedDependency?.pr) {
|
|
18
|
+
instructions.push(`${instructions.length + 1}. PR #${closedLayer.pr} was closed without merging. ${ask} the stack owner to reconcile this layer before declaring the stack complete.`);
|
|
19
19
|
}
|
|
20
20
|
for (const item of escalated) {
|
|
21
|
-
if (item.pr === closedDependency?.pr || item.pr ===
|
|
21
|
+
if (item.pr === closedDependency?.pr || item.pr === closedLayer?.pr)
|
|
22
22
|
continue;
|
|
23
23
|
instructions.push(`${instructions.length + 1}. PR #${item.pr} requires human action (${item.reasons.join(", ")}). ${stop ? "Stop for that decision." : "Keep shepherding other PRs before the handoff."}`);
|
|
24
24
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { PollSummaryResult, StackMergeScope } from "../types.mts";
|
|
2
|
+
/**
|
|
3
|
+
* `--merge` or `--merge-through` found owned layers ready at the bottom while a higher owned layer
|
|
4
|
+
* is not: nothing merges. Name the lagging layers' raw state and the explicit opt-in to drain.
|
|
5
|
+
*/
|
|
6
|
+
export declare function lowerReadyNote(result: PollSummaryResult, scope: StackMergeScope | undefined, rerunCommand?: string): string | undefined;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { mergeReadyCommand } from "../github/poll-summary-command.mjs";
|
|
2
|
+
import { formatPrUrl } from "../pr-reference.mjs";
|
|
3
|
+
import { mergeScopeLayers, readyPrefix } from "./stack-merge-scope.mjs";
|
|
4
|
+
const list = (items) => items.map((i) => `#${i.pr}`).join(", ");
|
|
5
|
+
/**
|
|
6
|
+
* `--merge` or `--merge-through` found owned layers ready at the bottom while a higher owned layer
|
|
7
|
+
* is not: nothing merges. Name the lagging layers' raw state and the explicit opt-in to drain.
|
|
8
|
+
*/
|
|
9
|
+
export function lowerReadyNote(result, scope, rerunCommand) {
|
|
10
|
+
if (!scope || scope.kind === "ready")
|
|
11
|
+
return undefined;
|
|
12
|
+
const { inScope, target } = mergeScopeLayers(result, scope);
|
|
13
|
+
const prefix = readyPrefix(result, false).filter((item) => inScope.includes(item));
|
|
14
|
+
if (!target || prefix.length === 0 || prefix.some((item) => item.pr === target.pr))
|
|
15
|
+
return undefined;
|
|
16
|
+
const lagging = inScope.filter((item) => !prefix.includes(item));
|
|
17
|
+
// `--merge-through N` approves only layers at or below N, so the drain lists exactly those.
|
|
18
|
+
const scoped = scope.kind === "through" ? inScope.map((item) => formatPrUrl(result.repo, item.pr)) : undefined;
|
|
19
|
+
const drain = rerunCommand
|
|
20
|
+
? `\`${mergeReadyCommand(rerunCommand, scoped)}\``
|
|
21
|
+
: "`stack` with `--merge-ready`";
|
|
22
|
+
return `Owned ${prefix.length === 1 ? "layer" : "layers"} ${list(prefix)} ${prefix.length === 1 ? "is" : "are"} ready, but ${lagging.map(describeLagging).join("; ")} ${lagging.length === 1 ? "is" : "are"} not. Nothing was merged because \`${scope.kind === "all" ? "--merge" : "--merge-through"}\` lands every layer in scope together. Tell the user the lower layers are ready. Only if the user asked to merge layers as they become ready, rerun ${drain}; otherwise keep shepherding.`;
|
|
23
|
+
}
|
|
24
|
+
function describeLagging(item) {
|
|
25
|
+
const facts = [
|
|
26
|
+
`action ${item.action}`,
|
|
27
|
+
item.reasons.length > 0 ? `reasons ${item.reasons.join(", ")}` : undefined,
|
|
28
|
+
item.isDraft ? "draft" : undefined,
|
|
29
|
+
item.reviewDecision ? `review ${item.reviewDecision}` : undefined,
|
|
30
|
+
item.checks?.failing ? `${item.checks.failing} failing checks` : undefined,
|
|
31
|
+
item.checks?.inProgress ? `${item.checks.inProgress} checks in progress` : undefined,
|
|
32
|
+
item.review?.actionable ? `${item.review.actionable} actionable review items` : undefined,
|
|
33
|
+
].filter((fact) => fact !== undefined);
|
|
34
|
+
return `#${item.pr} (${facts.join("; ")})`;
|
|
35
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PollSummaryItem, PollSummaryResult, StackMergeScope } from "../types.mts";
|
|
2
|
+
import type { StackPlan } from "./stack-drain.mts";
|
|
3
|
+
/** Commands that approve unlisted layers: list them as well, or name the stack number. */
|
|
4
|
+
export type ApproveCommands = (extra: number[]) => {
|
|
5
|
+
listed: string;
|
|
6
|
+
whole: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The escalation for a merge that would land layers the caller did not list. It names each layer
|
|
10
|
+
* with its author and title, says what merging would do, and prints the commands that approve.
|
|
11
|
+
*/
|
|
12
|
+
export declare function unlistedEscalation(target: PollSummaryItem, unlisted: PollSummaryItem[], rerunCommand: string | undefined, approve: ApproveCommands | undefined): StackPlan;
|
|
13
|
+
export declare const list: (items: PollSummaryItem[]) => string;
|
|
14
|
+
/** Layers that joined the stack after the merge was requested: the request never covered them. */
|
|
15
|
+
export declare function addedLayersEscalation(result: PollSummaryResult, open: PollSummaryItem[], scope: StackMergeScope, rerunCommand?: string): StackPlan | undefined;
|
|
16
|
+
export declare function scopeDone(open: PollSummaryItem[]): StackPlan;
|
|
17
|
+
export declare function escalation(text: string): StackPlan;
|