@chernabog/recipes 0.5.0 → 0.7.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/flows/address-review.ts +76 -6
- package/flows/epic.ts +249 -78
- package/flows/human-initiated.ts +2 -1
- package/flows/implement.ts +76 -16
- package/flows/plan.ts +64 -12
- package/flows/post-merge.ts +299 -107
- package/flows/re-review.ts +25 -3
- package/flows/resolve-conflicts.ts +83 -26
- package/flows/review.ts +22 -3
- package/package.json +3 -3
package/flows/implement.ts
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
// An issue an open pull request on another branch already closes is not
|
|
8
8
|
// implemented again: claim adopts that pull request (auto:adopted), and the
|
|
9
9
|
// run waits for CI, fixing red in a worktree on its branch, and hands it off.
|
|
10
|
+
// Its wait for CI parks on the issue's record too, on a phase of its own
|
|
11
|
+
// (awaiting-adopted-ci), which keeps the adopted pull request.
|
|
10
12
|
// A draft waits for its author to mark it ready first. Several, or one on a
|
|
11
13
|
// fork, go to a person.
|
|
12
14
|
//
|
|
@@ -21,6 +23,7 @@
|
|
|
21
23
|
// in flight resumes by, so renaming one restarts that step.
|
|
22
24
|
|
|
23
25
|
import {
|
|
26
|
+
Blocks,
|
|
24
27
|
type CiTimedOut,
|
|
25
28
|
Claims,
|
|
26
29
|
defineFlow,
|
|
@@ -36,19 +39,23 @@ import {
|
|
|
36
39
|
Routing,
|
|
37
40
|
Settings,
|
|
38
41
|
Skip,
|
|
42
|
+
StatusLabels,
|
|
39
43
|
} from "@chernabog/sdk";
|
|
40
44
|
import * as Effect from "effect/Effect";
|
|
41
45
|
import * as Option from "effect/Option";
|
|
42
46
|
import * as Schema from "effect/Schema";
|
|
43
47
|
|
|
44
|
-
// Issues
|
|
48
|
+
// Issues whose run a CI job left waiting on its pull request's CI first, to
|
|
49
|
+
// finish what's started: each is held until the checks are green or red.
|
|
50
|
+
// Then issues labelled auto:eligible, then ones labelled auto:ship, the automated
|
|
45
51
|
// path, whose pull request chernabog merges once it's approved. Oldest first,
|
|
46
52
|
// but a post-merge follow-up, the fix for red CI on the base, before the rest;
|
|
47
53
|
// with a board, only those whose Status is its readyStatus. An issue another
|
|
48
54
|
// open issue blocks waits for it, as the tasks of a plan's epic do, and a task
|
|
49
55
|
// of an epic that an epic run holds is that run's to start; both are held,
|
|
50
|
-
// and `chernabog status` says why. And the issues
|
|
51
|
-
// author marked ready,
|
|
56
|
+
// and `chernabog status` says why. And the issues waiting on an adopted
|
|
57
|
+
// draft whose author marked it ready, or whose wait's time is up: they wake a
|
|
58
|
+
// run still parked on it, or a CI job's ended one is taken up by a new run.
|
|
52
59
|
const trigger = Effect.gen(function* () {
|
|
53
60
|
const github = yield* GitHub;
|
|
54
61
|
const labelNames = yield* Settings.labels;
|
|
@@ -59,13 +66,18 @@ const trigger = Effect.gen(function* () {
|
|
|
59
66
|
(issue) => !eligible.some((queued) => queued.number === issue.number),
|
|
60
67
|
);
|
|
61
68
|
|
|
62
|
-
// A follow-up fixing red CI on the base goes first, ahead of other work.
|
|
69
|
+
// A follow-up fixing red CI on the base goes first, ahead of other new work.
|
|
63
70
|
return [
|
|
71
|
+
...(yield* Implement.awaitingCi),
|
|
64
72
|
...(yield* Implement.queued(Implement.followUpsFirst(eligible))),
|
|
65
73
|
...(yield* Implement.queued(Implement.followUpsFirst(shipping), Option.some(labelNames.ship))),
|
|
66
74
|
...(yield* Implement.readied),
|
|
67
75
|
];
|
|
68
|
-
}).pipe(
|
|
76
|
+
}).pipe(
|
|
77
|
+
// Every record it reads is checked first, as its document's are (ADR 21, decision 5).
|
|
78
|
+
Blocks.checked("issues.queued", "ci.waitAndFix", "ci.waitPreparing", "pr.awaitReady"),
|
|
79
|
+
reportAs("trigger"),
|
|
80
|
+
);
|
|
69
81
|
|
|
70
82
|
// How long an adopted draft waits for its author to mark it ready.
|
|
71
83
|
const READY_WITHIN = "14 days";
|
|
@@ -121,6 +133,46 @@ const flow = defineFlow({
|
|
|
121
133
|
const claimed = yield* Implement.claim(issue, { ...queued, adopt: true });
|
|
122
134
|
const { base, branch } = claimed;
|
|
123
135
|
const adoption = Option.fromUndefinedOr(claimed.adopted);
|
|
136
|
+
const resuming = Implement.resumingCi(item);
|
|
137
|
+
|
|
138
|
+
// A run ended while this issue's pull request's CI ran, and it has
|
|
139
|
+
// finished: wait on from the round the record names (a fix of red CI
|
|
140
|
+
// starts a session of its own), then hand off. The record's phase
|
|
141
|
+
// says which wait it was: awaiting-adopted-ci hands the pull request
|
|
142
|
+
// off as adopted, since no agent implemented it.
|
|
143
|
+
if (Option.isSome(resuming)) {
|
|
144
|
+
const waited = resuming.value;
|
|
145
|
+
const resumedAdoption = Implement.resumedAdoption(waited);
|
|
146
|
+
pullRequest = Option.some(waited.pullRequest);
|
|
147
|
+
|
|
148
|
+
const parking = Option.match(resumedAdoption, {
|
|
149
|
+
onNone: () => Implement.parkOnIssue(issue),
|
|
150
|
+
onSome: (adopted) => Implement.parkOnAdopted(issue, adopted.number),
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
return yield* Effect.gen(function* () {
|
|
154
|
+
yield* Implement.waitForCiMaking(
|
|
155
|
+
waited.pullRequest,
|
|
156
|
+
Implement.prepareWorktree(branch, { base }),
|
|
157
|
+
{ ...Implement.thisRunsSession, branch, base },
|
|
158
|
+
{ ...parking, firstRound: waited.round },
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
return yield* Option.match(resumedAdoption, {
|
|
162
|
+
onNone: () =>
|
|
163
|
+
Implement.handOff(
|
|
164
|
+
issue,
|
|
165
|
+
{ number: waited.pullRequest, url: waited.url },
|
|
166
|
+
Implement.resumedOutcome,
|
|
167
|
+
),
|
|
168
|
+
onSome: (adopted) =>
|
|
169
|
+
Implement.handOff(issue, adopted, Implement.adoptedOutcome(adopted), {
|
|
170
|
+
needsReview: true,
|
|
171
|
+
adoptedBranch: branch,
|
|
172
|
+
}),
|
|
173
|
+
});
|
|
174
|
+
}).pipe(Effect.catchTags(forPerson));
|
|
175
|
+
}
|
|
124
176
|
|
|
125
177
|
if (Option.isSome(adoption)) {
|
|
126
178
|
const adopted = adoption.value;
|
|
@@ -137,7 +189,9 @@ const flow = defineFlow({
|
|
|
137
189
|
});
|
|
138
190
|
}
|
|
139
191
|
|
|
140
|
-
// The worktree is made only for a fix.
|
|
192
|
+
// The worktree is made only for a fix. Still-pending CI parks on
|
|
193
|
+
// the issue's record, which keeps the pull request, and the item
|
|
194
|
+
// comes back through Implement.awaitingCi once CI finishes.
|
|
141
195
|
yield* Implement.waitForCiMaking(
|
|
142
196
|
adopted.number,
|
|
143
197
|
Implement.prepareWorktree(branch, { base }),
|
|
@@ -146,6 +200,7 @@ const flow = defineFlow({
|
|
|
146
200
|
branch,
|
|
147
201
|
base,
|
|
148
202
|
},
|
|
203
|
+
Implement.parkOnAdopted(issue, adopted.number),
|
|
149
204
|
);
|
|
150
205
|
|
|
151
206
|
return yield* Implement.handOff(issue, adopted, Implement.adoptedOutcome(adopted), {
|
|
@@ -169,11 +224,14 @@ const flow = defineFlow({
|
|
|
169
224
|
yield* Implement.push("push", worktree, branch, { base });
|
|
170
225
|
const opened = yield* Implement.openPullRequest(issue, outcome, { ...queued, base });
|
|
171
226
|
pullRequest = Option.some(opened.number);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
227
|
+
// In a CI job, still-pending CI ends the job here, and the item
|
|
228
|
+
// comes back through Implement.awaitingCi once CI finishes.
|
|
229
|
+
yield* Implement.waitForCi(
|
|
230
|
+
opened.number,
|
|
231
|
+
worktree,
|
|
232
|
+
{ ...Implement.thisRunsSession, branch, base },
|
|
233
|
+
Implement.parkOnIssue(issue),
|
|
234
|
+
);
|
|
177
235
|
|
|
178
236
|
return yield* Implement.handOff(issue, opened, outcome);
|
|
179
237
|
}).pipe(Effect.catchTags(forPerson));
|
|
@@ -183,7 +241,7 @@ const flow = defineFlow({
|
|
|
183
241
|
Effect.catchTag("StepFailed", (failed) => toPerson(`${failed.step}: ${failed.message}`)),
|
|
184
242
|
// However the run ends, its claim on the issue goes; the branch and
|
|
185
243
|
// any pull request stay.
|
|
186
|
-
|
|
244
|
+
StatusLabels.releasing(Claims.issue(issue)),
|
|
187
245
|
);
|
|
188
246
|
}).pipe(
|
|
189
247
|
// An issue deleted or transferred under the run leaves nothing to do.
|
|
@@ -192,9 +250,11 @@ const flow = defineFlow({
|
|
|
192
250
|
});
|
|
193
251
|
|
|
194
252
|
// The GitHub events that can change what its trigger finds, so it wakes in CI
|
|
195
|
-
// rather than only on the schedule: an issue labelled to queue it,
|
|
196
|
-
// its author marks ready, which wakes an adopted one's run
|
|
253
|
+
// rather than only on the schedule: an issue labelled to queue it, a draft
|
|
254
|
+
// its author marks ready, which wakes an adopted one's run, and a finished CI
|
|
255
|
+
// run, which frees an issue a CI job left waiting on its pull request's CI.
|
|
256
|
+
// Its trigger reads issues' phases for those, so a phase event wakes it too.
|
|
197
257
|
export default Events.declare(flow, {
|
|
198
|
-
events: [Events.issueLabelled, Events.readyForReview],
|
|
199
|
-
readsPhases:
|
|
258
|
+
events: [Events.issueLabelled, Events.readyForReview, Events.ciCompleted],
|
|
259
|
+
readsPhases: true,
|
|
200
260
|
});
|
package/flows/plan.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// run in flight resumes by, so renaming one restarts that step.
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
|
+
Blocks,
|
|
16
17
|
Claims,
|
|
17
18
|
defineFlow,
|
|
18
19
|
Events,
|
|
@@ -21,9 +22,11 @@ import {
|
|
|
21
22
|
NeedsHuman,
|
|
22
23
|
Plan,
|
|
23
24
|
reportAs,
|
|
25
|
+
Resume,
|
|
24
26
|
Routing,
|
|
25
27
|
Settings,
|
|
26
28
|
Skip,
|
|
29
|
+
StatusLabels,
|
|
27
30
|
type WorkItem,
|
|
28
31
|
} from "@chernabog/sdk";
|
|
29
32
|
import * as Effect from "effect/Effect";
|
|
@@ -36,27 +39,70 @@ const ANSWER_WITHIN = "14 days";
|
|
|
36
39
|
|
|
37
40
|
// Specs labelled auto:plan, oldest first, as work to start; with a board,
|
|
38
41
|
// only those whose Status is its readyStatus, routed by their assignees. Then
|
|
39
|
-
// specs whose posted plan a person has answered,
|
|
42
|
+
// specs whose posted plan a person has answered, or nobody answered within
|
|
43
|
+
// ANSWER_WITHIN: they wake the run still waiting on it, or a CI job's ended
|
|
44
|
+
// one is taken up by a new run, from the spec's record.
|
|
40
45
|
const trigger = Effect.gen(function* () {
|
|
41
46
|
const github = yield* GitHub;
|
|
42
47
|
const queued = yield* github.queuedIssuesLabelled(Plan.LABELS.plan);
|
|
43
|
-
const answered = yield* Plan.
|
|
48
|
+
const answered = yield* Plan.answered(ANSWER_WITHIN);
|
|
44
49
|
|
|
45
50
|
const specs = yield* Effect.forEach(queued, (issue) =>
|
|
46
51
|
Implement.routed(issue, Implement.issueItem(issue, Option.some(Plan.LABELS.plan))),
|
|
47
52
|
);
|
|
48
53
|
|
|
49
54
|
return [...specs, ...answered];
|
|
50
|
-
}).pipe(
|
|
55
|
+
}).pipe(
|
|
56
|
+
// Every record it reads is checked first, as its document's are (ADR 21, decision 5).
|
|
57
|
+
Blocks.checked("plan.queued", "plan.awaitAnswer"),
|
|
58
|
+
reportAs("trigger"),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
// Nobody answered the plan in time: a person's to pick up.
|
|
62
|
+
const unanswered = new NeedsHuman({
|
|
63
|
+
reason: `nobody answered the plan within ${ANSWER_WITHIN}`,
|
|
64
|
+
});
|
|
51
65
|
|
|
52
66
|
// Drafts, checks and proposes the plan, and waits for a person's answer,
|
|
53
67
|
// round after round until they approve it. Returns the run's summary, or,
|
|
54
68
|
// for a spec that needs answers first, the agent's draft with its questions.
|
|
55
|
-
|
|
69
|
+
// A run that takes up an answer to a plan an earlier run posted (`resumed`)
|
|
70
|
+
// acts on it first: makes the approved plan, or drafts the next round.
|
|
71
|
+
const planUntilApproved = (spec: number, resumed: Option.Option<Plan.Resumed>) =>
|
|
56
72
|
Effect.gen(function* () {
|
|
57
73
|
let changes = Option.none<string>();
|
|
74
|
+
let first = 1;
|
|
75
|
+
|
|
76
|
+
if (Option.isSome(resumed)) {
|
|
77
|
+
const { round } = resumed.value;
|
|
78
|
+
|
|
79
|
+
// The answer as the spec's record has it now; none yet, as for a run
|
|
80
|
+
// started before a person answered, which waits again.
|
|
81
|
+
const answer = yield* Plan.answerNow(spec, round, ANSWER_WITHIN).pipe(
|
|
82
|
+
Effect.flatMap(
|
|
83
|
+
Option.match({
|
|
84
|
+
onSome: Effect.succeed,
|
|
85
|
+
onNone: () => Plan.awaitAnswer(spec, round, ANSWER_WITHIN),
|
|
86
|
+
}),
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
if (answer === "timeout") {
|
|
91
|
+
return yield* unanswered;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (answer === "approved") {
|
|
95
|
+
const plan = yield* Plan.posted(spec, round);
|
|
96
|
+
const created = yield* Plan.create(spec, plan);
|
|
58
97
|
|
|
59
|
-
|
|
98
|
+
return yield* Plan.becomeEpic(spec, plan, created);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
changes = Option.some(yield* Plan.changesAsked(spec, round));
|
|
102
|
+
first = round + 1;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for (let round = first; ; round++) {
|
|
60
106
|
const draft = yield* Plan.checkedDraft(spec, round, changes);
|
|
61
107
|
|
|
62
108
|
if (draft.status === "needs-clarification") {
|
|
@@ -64,7 +110,7 @@ const planUntilApproved = (spec: number) =>
|
|
|
64
110
|
}
|
|
65
111
|
|
|
66
112
|
const plan = yield* Plan.propose(spec, round, draft);
|
|
67
|
-
const answer = yield* Plan.awaitAnswer(round, ANSWER_WITHIN);
|
|
113
|
+
const answer = yield* Plan.awaitAnswer(spec, round, ANSWER_WITHIN);
|
|
68
114
|
|
|
69
115
|
if (answer === "approved") {
|
|
70
116
|
const created = yield* Plan.create(spec, plan);
|
|
@@ -73,9 +119,7 @@ const planUntilApproved = (spec: number) =>
|
|
|
73
119
|
}
|
|
74
120
|
|
|
75
121
|
if (answer === "timeout") {
|
|
76
|
-
return yield*
|
|
77
|
-
reason: `nobody answered the plan within ${ANSWER_WITHIN}`,
|
|
78
|
-
});
|
|
122
|
+
return yield* unanswered;
|
|
79
123
|
}
|
|
80
124
|
|
|
81
125
|
changes = Option.some(yield* Plan.changesAsked(spec, round));
|
|
@@ -84,7 +128,15 @@ const planUntilApproved = (spec: number) =>
|
|
|
84
128
|
|
|
85
129
|
const work = (spec: number, item: WorkItem) =>
|
|
86
130
|
Effect.gen(function* () {
|
|
87
|
-
|
|
131
|
+
const resumed = Plan.resuming(item);
|
|
132
|
+
|
|
133
|
+
// A run that takes up a plan an earlier run posted claims the spec again
|
|
134
|
+
// as that run held it, saying nothing new on it; a new spec is claimed.
|
|
135
|
+
if (Option.isSome(resumed)) {
|
|
136
|
+
yield* Resume.claimAgainOn(Claims.issue(spec));
|
|
137
|
+
} else {
|
|
138
|
+
yield* Implement.claim(spec, yield* Implement.queuedBy(item));
|
|
139
|
+
}
|
|
88
140
|
|
|
89
141
|
// Each ending removes the plan's checkout first.
|
|
90
142
|
const toPerson = (reason: string) =>
|
|
@@ -93,7 +145,7 @@ const work = (spec: number, item: WorkItem) =>
|
|
|
93
145
|
Effect.flatMap(Implement.endForPerson),
|
|
94
146
|
);
|
|
95
147
|
|
|
96
|
-
const outcome = yield* planUntilApproved(spec).pipe(
|
|
148
|
+
const outcome = yield* planUntilApproved(spec, resumed).pipe(
|
|
97
149
|
Effect.catchTags({
|
|
98
150
|
NeedsHuman: (needsHuman) => toPerson(needsHuman.reason),
|
|
99
151
|
// Any other failure once the spec is claimed hands it to a person,
|
|
@@ -119,7 +171,7 @@ const workflow = (item: WorkItem) =>
|
|
|
119
171
|
|
|
120
172
|
// However the run ends, its claim on the spec goes; a run waiting on an
|
|
121
173
|
// answer to its plan keeps it.
|
|
122
|
-
return yield* work(spec, item).pipe(
|
|
174
|
+
return yield* work(spec, item).pipe(StatusLabels.releasing(Claims.issue(spec)));
|
|
123
175
|
}).pipe(
|
|
124
176
|
// An issue deleted or transferred under the run leaves nothing to do.
|
|
125
177
|
Effect.catchTag("NotFound", (gone) => Effect.fail(new Skip({ reason: gone.message }))),
|