@chernabog/recipes 0.0.0-stage → 0.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/README.md +35 -2
- package/flows/address-review.ts +166 -0
- package/flows/epic.ts +750 -0
- package/flows/human-initiated.ts +106 -0
- package/flows/implement.ts +189 -0
- package/flows/plan.ts +146 -0
- package/flows/re-review.ts +199 -0
- package/flows/resolve-conflicts.ts +265 -0
- package/flows/review.ts +141 -0
- package/package.json +83 -4
- package/prompts/implement.md +70 -0
- package/prompts/plan.md +58 -0
- package/prompts/resolve-conflicts.md +34 -0
- package/prompts/review.md +38 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// The hybrid path: `chernabog start <issue>` hands an issue over, and a
|
|
2
|
+
// person plans and implements it with Claude in a session in front of them.
|
|
3
|
+
// `chernabog open-pr`, run from that session, ends it; then this flow runs the
|
|
4
|
+
// local gate, pushes, opens the pull request (labelled hybrid), waits for CI
|
|
5
|
+
// and asks a reviewer from the pool. review, address-review and re-review take
|
|
6
|
+
// it from there, and a person merges. It has no trigger, so nothing starts it on
|
|
7
|
+
// a schedule.
|
|
8
|
+
//
|
|
9
|
+
// This file is chernabog's human-initiated recipe, and this repo's to change:
|
|
10
|
+
// `chernabog recipes diff` shows how it differs from the recipe's current
|
|
11
|
+
// version. The names of its steps ("claim", "work-with-person") are the keys a
|
|
12
|
+
// run in flight resumes by, so renaming one restarts that step.
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
Claims,
|
|
16
|
+
defineFlow,
|
|
17
|
+
Hybrid,
|
|
18
|
+
Implement,
|
|
19
|
+
Review,
|
|
20
|
+
Settings,
|
|
21
|
+
Skip,
|
|
22
|
+
type WorkItem,
|
|
23
|
+
} from "@chernabog/sdk";
|
|
24
|
+
import * as Effect from "effect/Effect";
|
|
25
|
+
import * as Option from "effect/Option";
|
|
26
|
+
import * as Schema from "effect/Schema";
|
|
27
|
+
|
|
28
|
+
const work = (issue: number) =>
|
|
29
|
+
Effect.gen(function* () {
|
|
30
|
+
// The base the claim settled, the flow's base setting here, which the later steps build on.
|
|
31
|
+
const { base, branch } = yield* Hybrid.claim(issue);
|
|
32
|
+
const worktree = yield* Implement.prepareWorktree(branch, { base });
|
|
33
|
+
// A session the person closes before open-pr fails the run, which lets
|
|
34
|
+
// the claim go and keeps the issue in progress, so chernabog start on the
|
|
35
|
+
// issue again picks the session back up.
|
|
36
|
+
const finished = yield* Hybrid.workWithPerson(issue, worktree, { base });
|
|
37
|
+
let pullRequest = Option.none<number>();
|
|
38
|
+
|
|
39
|
+
const toPerson = (reason: string) =>
|
|
40
|
+
Implement.handToHuman(issue, reason, pullRequest).pipe(
|
|
41
|
+
Effect.flatMap(Implement.endForPerson),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
return yield* Effect.gen(function* () {
|
|
45
|
+
// Fixes for the gate and for red CI go back to the person's session.
|
|
46
|
+
const session = yield* Hybrid.personSession(issue);
|
|
47
|
+
yield* Implement.localGate(worktree, { session });
|
|
48
|
+
// The person watched the change written, so it may touch humanOnlyPaths; a person merges it.
|
|
49
|
+
yield* Implement.push("push", worktree, branch, { base, withPerson: true });
|
|
50
|
+
const opened = yield* Hybrid.openPullRequest(issue, finished, { base });
|
|
51
|
+
pullRequest = Option.some(opened.number);
|
|
52
|
+
yield* Implement.waitForCi(opened.number, worktree, { ...session, branch, base });
|
|
53
|
+
|
|
54
|
+
return yield* Hybrid.handOff(issue, opened, finished);
|
|
55
|
+
}).pipe(
|
|
56
|
+
Effect.catchTags({
|
|
57
|
+
NeedsHuman: (needsHuman) => toPerson(needsHuman.reason),
|
|
58
|
+
StepFailed: (failed) => toPerson(`${failed.step}: ${failed.message}`),
|
|
59
|
+
NothingCommitted: (nothing) =>
|
|
60
|
+
toPerson(`nothing was committed on ${nothing.branch} before open-pr`),
|
|
61
|
+
// Such as a change to .github/workflows/ with a token that lacks the
|
|
62
|
+
// workflow scope: its message says how to fix the token.
|
|
63
|
+
PushRejected: (rejected) => toPerson(rejected.message),
|
|
64
|
+
CiTimedOut: (timedOut) => toPerson(timedOut.message),
|
|
65
|
+
PullRequestClosed: (closed) => toPerson(closed.message),
|
|
66
|
+
}),
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const workflow = (item: WorkItem) =>
|
|
71
|
+
Effect.gen(function* () {
|
|
72
|
+
const issue = yield* Implement.issueOf(item);
|
|
73
|
+
|
|
74
|
+
// However the run ends, its claim on the issue goes; the branch and any
|
|
75
|
+
// pull request stay.
|
|
76
|
+
return yield* work(issue).pipe(Claims.releasing(Claims.issue(issue)));
|
|
77
|
+
}).pipe(
|
|
78
|
+
// An issue deleted or transferred under the run leaves nothing to do.
|
|
79
|
+
Effect.catchTag("NotFound", (gone) => Effect.fail(new Skip({ reason: gone.message }))),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// What config.yaml may set for this flow, under settings: or flows.<name>.settings.
|
|
83
|
+
const settings = Schema.Struct({
|
|
84
|
+
...Settings.Labels.fields,
|
|
85
|
+
...Settings.Base.fields,
|
|
86
|
+
...Settings.Board.fields,
|
|
87
|
+
...Settings.LocalGate.fields,
|
|
88
|
+
...Settings.Rules.fields,
|
|
89
|
+
...Settings.Ci.fields,
|
|
90
|
+
...Settings.Reviewers.fields,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export default defineFlow({
|
|
94
|
+
labels: Settings.declaredLabels,
|
|
95
|
+
settings,
|
|
96
|
+
item: Hybrid.itemFor,
|
|
97
|
+
// The flow `chernabog start <issue>` runs.
|
|
98
|
+
start: true,
|
|
99
|
+
// No trigger finds work for several personas to share: each run is a person's.
|
|
100
|
+
ownWork: true,
|
|
101
|
+
// Doctor warns when no reviewer its pull requests may ask is a persona here.
|
|
102
|
+
doctor: [Review.poolCheck],
|
|
103
|
+
// An issue closed, or claimed by another run, ends the run as superseded.
|
|
104
|
+
stillValid: Implement.stillValid,
|
|
105
|
+
workflow,
|
|
106
|
+
});
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Implements queued issues: claim the oldest one labelled auto:eligible or
|
|
2
|
+
// auto:ship, let the agent implement it in a worktree, run the local gate,
|
|
3
|
+
// open the pull request, wait for CI and hand off for review, which asks one
|
|
4
|
+
// reviewer from the team's pool. An auto:ship issue's pull request carries the
|
|
5
|
+
// label too, so its approving reviewer merges it.
|
|
6
|
+
//
|
|
7
|
+
// An issue an open pull request on another branch already closes is not
|
|
8
|
+
// implemented again: claim adopts that pull request (auto:adopted), and the
|
|
9
|
+
// run waits for CI, fixing red in a worktree on its branch, and hands it off.
|
|
10
|
+
// A draft waits for its author to mark it ready first. Several, or one on a
|
|
11
|
+
// fork, go to a person.
|
|
12
|
+
//
|
|
13
|
+
// Each block is a durable activity from @chernabog/sdk. Reorder them, leave
|
|
14
|
+
// one out, or put a step of your own from .chernabog/stages/ in between with
|
|
15
|
+
// `step("name", input, OutputSchema)`. Side effects belong inside activities or
|
|
16
|
+
// steps, never in the workflow body, which runs again whenever the run resumes.
|
|
17
|
+
//
|
|
18
|
+
// This file is chernabog's implement recipe, and this repo's to change:
|
|
19
|
+
// `chernabog recipes diff` shows how it differs from the recipe's current
|
|
20
|
+
// version. The names of its steps ("claim", "local-gate-1") are the keys a run
|
|
21
|
+
// in flight resumes by, so renaming one restarts that step.
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
type CiTimedOut,
|
|
25
|
+
Claims,
|
|
26
|
+
defineFlow,
|
|
27
|
+
GitHub,
|
|
28
|
+
Implement,
|
|
29
|
+
NeedsHuman,
|
|
30
|
+
type NothingCommitted,
|
|
31
|
+
type PullRequestClosed,
|
|
32
|
+
type PushRejected,
|
|
33
|
+
reportAs,
|
|
34
|
+
Review,
|
|
35
|
+
Routing,
|
|
36
|
+
Settings,
|
|
37
|
+
Skip,
|
|
38
|
+
} from "@chernabog/sdk";
|
|
39
|
+
import * as Effect from "effect/Effect";
|
|
40
|
+
import * as Option from "effect/Option";
|
|
41
|
+
import * as Schema from "effect/Schema";
|
|
42
|
+
|
|
43
|
+
// Issues labelled auto:eligible, then ones labelled auto:ship, the automated
|
|
44
|
+
// path, whose pull request chernabog merges once it's approved. Oldest first;
|
|
45
|
+
// with a board, only those whose Status is its readyStatus. An issue another
|
|
46
|
+
// open issue blocks waits for it, as the tasks of a plan's epic do, and a task
|
|
47
|
+
// of an epic that an epic run holds is that run's to start; both are held,
|
|
48
|
+
// and `chernabog status` says why. And the issues whose adopted draft its
|
|
49
|
+
// author marked ready, which wake their run.
|
|
50
|
+
const trigger = Effect.gen(function* () {
|
|
51
|
+
const github = yield* GitHub;
|
|
52
|
+
const labelNames = yield* Settings.labels;
|
|
53
|
+
|
|
54
|
+
const eligible = yield* github.queuedIssuesLabelled(labelNames.eligible);
|
|
55
|
+
|
|
56
|
+
const shipping = (yield* github.queuedIssuesLabelled(labelNames.ship)).filter(
|
|
57
|
+
(issue) => !eligible.some((queued) => queued.number === issue.number),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
return [
|
|
61
|
+
...(yield* Implement.queued(eligible)),
|
|
62
|
+
...(yield* Implement.queued(shipping, Option.some(labelNames.ship))),
|
|
63
|
+
...(yield* Implement.readied),
|
|
64
|
+
];
|
|
65
|
+
}).pipe(reportAs("trigger"));
|
|
66
|
+
|
|
67
|
+
// How long an adopted draft waits for its author to mark it ready.
|
|
68
|
+
const READY_WITHIN = "14 days";
|
|
69
|
+
|
|
70
|
+
// What config.yaml may set for this flow, under settings: or flows.<name>.settings.
|
|
71
|
+
const settings = Schema.Struct({
|
|
72
|
+
...Routing.Settings.fields,
|
|
73
|
+
...Settings.Labels.fields,
|
|
74
|
+
...Settings.Base.fields,
|
|
75
|
+
...Settings.Board.fields,
|
|
76
|
+
...Settings.LocalGate.fields,
|
|
77
|
+
...Settings.Rules.fields,
|
|
78
|
+
...Settings.Ci.fields,
|
|
79
|
+
...Settings.Reviewers.fields,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
export default defineFlow({
|
|
83
|
+
trigger,
|
|
84
|
+
gate: Implement.gate,
|
|
85
|
+
concurrency: 1,
|
|
86
|
+
labels: Effect.map(Settings.declaredLabels, (set) => [...set, ...Implement.adoptionLabels]),
|
|
87
|
+
settings,
|
|
88
|
+
// Doctor warns when no reviewer its pull requests may ask is a persona here.
|
|
89
|
+
doctor: [Review.poolCheck],
|
|
90
|
+
// An issue closed, or claimed by another run, ends the run as superseded.
|
|
91
|
+
stillValid: Implement.stillValid,
|
|
92
|
+
workflow: (item) =>
|
|
93
|
+
Effect.gen(function* () {
|
|
94
|
+
const issue = yield* Implement.issueOf(item);
|
|
95
|
+
const queued = yield* Implement.queuedBy(item);
|
|
96
|
+
let pullRequest = Option.none<number>();
|
|
97
|
+
|
|
98
|
+
const toPerson = (reason: string) =>
|
|
99
|
+
Implement.handToHuman(issue, reason, pullRequest).pipe(
|
|
100
|
+
Effect.flatMap(Implement.endForPerson),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// Nothing to push, a push the token may not make (its message says the
|
|
104
|
+
// fix), CI that never finishes, or a pull request closed under the run:
|
|
105
|
+
// each is a person's to look into.
|
|
106
|
+
const forPerson = {
|
|
107
|
+
NeedsHuman: (needsHuman: NeedsHuman) => toPerson(needsHuman.reason),
|
|
108
|
+
NothingCommitted: (nothing: NothingCommitted) =>
|
|
109
|
+
toPerson(`the agent finished without committing anything on ${nothing.branch}`),
|
|
110
|
+
PushRejected: (rejected: PushRejected) => toPerson(rejected.message),
|
|
111
|
+
CiTimedOut: (timedOut: CiTimedOut) => toPerson(timedOut.message),
|
|
112
|
+
PullRequestClosed: (closed: PullRequestClosed) => toPerson(closed.message),
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
return yield* Effect.gen(function* () {
|
|
116
|
+
// The base the claim settled, the repo's base branch here, which the
|
|
117
|
+
// later steps build on; for an adopted pull request, its branch and base.
|
|
118
|
+
const claimed = yield* Implement.claim(issue, { ...queued, adopt: true });
|
|
119
|
+
const { base, branch } = claimed;
|
|
120
|
+
const adoption = Option.fromUndefinedOr(claimed.adopted);
|
|
121
|
+
|
|
122
|
+
if (Option.isSome(adoption)) {
|
|
123
|
+
const adopted = adoption.value;
|
|
124
|
+
pullRequest = Option.some(adopted.number);
|
|
125
|
+
|
|
126
|
+
return yield* Effect.gen(function* () {
|
|
127
|
+
// A draft is its author's until they mark it ready.
|
|
128
|
+
if (
|
|
129
|
+
adopted.draft &&
|
|
130
|
+
(yield* Implement.awaitReady(issue, adopted.number, READY_WITHIN)) === "timeout"
|
|
131
|
+
) {
|
|
132
|
+
return yield* new NeedsHuman({
|
|
133
|
+
reason: `#${adopted.number} is still a draft after ${READY_WITHIN}`,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// The worktree is made only for a fix.
|
|
138
|
+
yield* Implement.waitForCiMaking(
|
|
139
|
+
adopted.number,
|
|
140
|
+
Implement.prepareWorktree(branch, { base }),
|
|
141
|
+
{
|
|
142
|
+
...Implement.thisRunsSession,
|
|
143
|
+
branch,
|
|
144
|
+
base,
|
|
145
|
+
},
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
return yield* Implement.handOff(issue, adopted, Implement.adoptedOutcome(adopted), {
|
|
149
|
+
needsReview: true,
|
|
150
|
+
adoptedBranch: branch,
|
|
151
|
+
});
|
|
152
|
+
}).pipe(Effect.catchTags(forPerson));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const worktree = yield* Implement.prepareWorktree(branch, { base });
|
|
156
|
+
const outcome = yield* Implement.implementWithAgent(issue, worktree, { base });
|
|
157
|
+
|
|
158
|
+
if (outcome.status === "needs-clarification") {
|
|
159
|
+
return yield* Implement.askForClarification(issue, outcome, queued).pipe(
|
|
160
|
+
Effect.flatMap(Implement.endForPerson),
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return yield* Effect.gen(function* () {
|
|
165
|
+
yield* Implement.localGate(worktree);
|
|
166
|
+
yield* Implement.push("push", worktree, branch, { base });
|
|
167
|
+
const opened = yield* Implement.openPullRequest(issue, outcome, { ...queued, base });
|
|
168
|
+
pullRequest = Option.some(opened.number);
|
|
169
|
+
yield* Implement.waitForCi(opened.number, worktree, {
|
|
170
|
+
...Implement.thisRunsSession,
|
|
171
|
+
branch,
|
|
172
|
+
base,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return yield* Implement.handOff(issue, opened, outcome);
|
|
176
|
+
}).pipe(Effect.catchTags(forPerson));
|
|
177
|
+
}).pipe(
|
|
178
|
+
// Any other failure once the issue is claimed hands it to a person, rather
|
|
179
|
+
// than leaving it claimed with nobody working on it.
|
|
180
|
+
Effect.catchTag("StepFailed", (failed) => toPerson(`${failed.step}: ${failed.message}`)),
|
|
181
|
+
// However the run ends, its claim on the issue goes; the branch and
|
|
182
|
+
// any pull request stay.
|
|
183
|
+
Claims.releasing(Claims.issue(issue)),
|
|
184
|
+
);
|
|
185
|
+
}).pipe(
|
|
186
|
+
// An issue deleted or transferred under the run leaves nothing to do.
|
|
187
|
+
Effect.catchTag("NotFound", (gone) => Effect.fail(new Skip({ reason: gone.message }))),
|
|
188
|
+
),
|
|
189
|
+
});
|
package/flows/plan.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Turns a spec into a body of work: claim the oldest issue labelled
|
|
2
|
+
// auto:plan, let the agent read it and the code in a read-only checkout and
|
|
3
|
+
// propose the tasks it splits into and which blocks which, check the plan,
|
|
4
|
+
// post it on the issue and wait for a person. Approved (auto:plan-approved),
|
|
5
|
+
// each task becomes a sub-issue of the spec, linked to the tasks that block
|
|
6
|
+
// it and labelled by its kind, and the spec becomes an epic (auto:epic). A
|
|
7
|
+
// comment asking for changes drafts it again. The agent answers with data
|
|
8
|
+
// only: the repo's other flows pick up its tasks by their labels.
|
|
9
|
+
//
|
|
10
|
+
// This file is chernabog's plan recipe, and this repo's to change:
|
|
11
|
+
// `chernabog recipes diff` shows how it differs from the recipe's current
|
|
12
|
+
// version. The names of its steps ("claim", "draft-plan-1") are the keys a
|
|
13
|
+
// run in flight resumes by, so renaming one restarts that step.
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
Claims,
|
|
17
|
+
defineFlow,
|
|
18
|
+
GitHub,
|
|
19
|
+
Implement,
|
|
20
|
+
NeedsHuman,
|
|
21
|
+
Plan,
|
|
22
|
+
reportAs,
|
|
23
|
+
Routing,
|
|
24
|
+
Settings,
|
|
25
|
+
Skip,
|
|
26
|
+
type WorkItem,
|
|
27
|
+
} from "@chernabog/sdk";
|
|
28
|
+
import * as Effect from "effect/Effect";
|
|
29
|
+
import * as Option from "effect/Option";
|
|
30
|
+
import * as Predicate from "effect/Predicate";
|
|
31
|
+
import * as Schema from "effect/Schema";
|
|
32
|
+
|
|
33
|
+
// How long a posted plan waits for a person before the run hands it back.
|
|
34
|
+
const ANSWER_WITHIN = "14 days";
|
|
35
|
+
|
|
36
|
+
// Specs labelled auto:plan, oldest first, as work to start; with a board,
|
|
37
|
+
// only those whose Status is its readyStatus, routed by their assignees. Then
|
|
38
|
+
// specs whose posted plan a person has answered, which wake the run waiting on it.
|
|
39
|
+
const trigger = Effect.gen(function* () {
|
|
40
|
+
const github = yield* GitHub;
|
|
41
|
+
const queued = yield* github.queuedIssuesLabelled(Plan.LABELS.plan);
|
|
42
|
+
const answered = yield* Plan.answers;
|
|
43
|
+
|
|
44
|
+
const specs = yield* Effect.forEach(queued, (issue) =>
|
|
45
|
+
Implement.routed(issue, Implement.issueItem(issue, Option.some(Plan.LABELS.plan))),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
return [...specs, ...answered];
|
|
49
|
+
}).pipe(reportAs("trigger"));
|
|
50
|
+
|
|
51
|
+
// Drafts, checks and proposes the plan, and waits for a person's answer,
|
|
52
|
+
// round after round until they approve it. Returns the run's summary, or,
|
|
53
|
+
// for a spec that needs answers first, the agent's draft with its questions.
|
|
54
|
+
const planUntilApproved = (spec: number) =>
|
|
55
|
+
Effect.gen(function* () {
|
|
56
|
+
let changes = Option.none<string>();
|
|
57
|
+
|
|
58
|
+
for (let round = 1; ; round++) {
|
|
59
|
+
const draft = yield* Plan.checkedDraft(spec, round, changes);
|
|
60
|
+
|
|
61
|
+
if (draft.status === "needs-clarification") {
|
|
62
|
+
return draft;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const plan = yield* Plan.propose(spec, round, draft);
|
|
66
|
+
const answer = yield* Plan.awaitAnswer(round, ANSWER_WITHIN);
|
|
67
|
+
|
|
68
|
+
if (answer === "approved") {
|
|
69
|
+
const created = yield* Plan.create(spec, plan);
|
|
70
|
+
|
|
71
|
+
return yield* Plan.becomeEpic(spec, plan, created);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (answer === "timeout") {
|
|
75
|
+
return yield* new NeedsHuman({
|
|
76
|
+
reason: `nobody answered the plan within ${ANSWER_WITHIN}`,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
changes = Option.some(yield* Plan.changesAsked(spec, round));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
const work = (spec: number, item: WorkItem) =>
|
|
85
|
+
Effect.gen(function* () {
|
|
86
|
+
yield* Implement.claim(spec, yield* Implement.queuedBy(item));
|
|
87
|
+
|
|
88
|
+
// Each ending removes the plan's checkout first.
|
|
89
|
+
const toPerson = (reason: string) =>
|
|
90
|
+
Plan.doneDrafting(spec).pipe(
|
|
91
|
+
Effect.andThen(Plan.handToHuman(spec, reason)),
|
|
92
|
+
Effect.flatMap(Implement.endForPerson),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const outcome = yield* planUntilApproved(spec).pipe(
|
|
96
|
+
Effect.catchTags({
|
|
97
|
+
NeedsHuman: (needsHuman) => toPerson(needsHuman.reason),
|
|
98
|
+
// Any other failure once the spec is claimed hands it to a person,
|
|
99
|
+
// rather than leaving it claimed with nobody working on it.
|
|
100
|
+
StepFailed: (failed) => toPerson(`${failed.step}: ${failed.message}`),
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
yield* Plan.doneDrafting(spec);
|
|
105
|
+
|
|
106
|
+
if (Predicate.isString(outcome)) {
|
|
107
|
+
return outcome;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return yield* Plan.askForClarification(spec, outcome).pipe(
|
|
111
|
+
Effect.flatMap(Implement.endForPerson),
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const workflow = (item: WorkItem) =>
|
|
116
|
+
Effect.gen(function* () {
|
|
117
|
+
const spec = yield* Implement.issueOf(item);
|
|
118
|
+
|
|
119
|
+
// However the run ends, its claim on the spec goes; a run waiting on an
|
|
120
|
+
// answer to its plan keeps it.
|
|
121
|
+
return yield* work(spec, item).pipe(Claims.releasing(Claims.issue(spec)));
|
|
122
|
+
}).pipe(
|
|
123
|
+
// An issue deleted or transferred under the run leaves nothing to do.
|
|
124
|
+
Effect.catchTag("NotFound", (gone) => Effect.fail(new Skip({ reason: gone.message }))),
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
// What config.yaml may set for this flow, under settings: or flows.<name>.settings.
|
|
128
|
+
const settings = Schema.Struct({
|
|
129
|
+
...Routing.Settings.fields,
|
|
130
|
+
...Settings.Labels.fields,
|
|
131
|
+
...Settings.Base.fields,
|
|
132
|
+
...Settings.Board.fields,
|
|
133
|
+
...Settings.Rules.fields,
|
|
134
|
+
...Settings.Plans.fields,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
export default defineFlow({
|
|
138
|
+
trigger,
|
|
139
|
+
gate: Implement.gate,
|
|
140
|
+
concurrency: 1,
|
|
141
|
+
labels: Effect.map(Settings.declaredLabels, (set) => [...set, ...Plan.flowLabels]),
|
|
142
|
+
settings,
|
|
143
|
+
// A spec closed, or claimed by another run, ends the run as superseded.
|
|
144
|
+
stillValid: Plan.stillValid,
|
|
145
|
+
workflow,
|
|
146
|
+
});
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Reviews again when the author asks: a pull request this persona reviewed
|
|
2
|
+
// requests its review once more. It resumes the session of its own review,
|
|
3
|
+
// says which findings are remediated, and approves, which merges an auto:ship
|
|
4
|
+
// pull request when that's safe, or requests changes again and hands the pull
|
|
5
|
+
// request to a person. limits.reviewRounds caps the re-reviews, and a pull
|
|
6
|
+
// request labelled auto:needs-human is left alone.
|
|
7
|
+
//
|
|
8
|
+
// This file is chernabog's re-review recipe, and this repo's to change:
|
|
9
|
+
// `chernabog recipes diff` shows how it differs from the recipe's current
|
|
10
|
+
// version. The names of its steps ("find-review", "review-2") are the keys a
|
|
11
|
+
// run in flight resumes by, so renaming one restarts that step.
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
activity,
|
|
15
|
+
defineFlow,
|
|
16
|
+
GitHub,
|
|
17
|
+
PullRequest,
|
|
18
|
+
Repo,
|
|
19
|
+
reportAs,
|
|
20
|
+
Review,
|
|
21
|
+
Routing,
|
|
22
|
+
Settings,
|
|
23
|
+
Skip,
|
|
24
|
+
type WorkItem,
|
|
25
|
+
} from "@chernabog/sdk";
|
|
26
|
+
import * as Effect from "effect/Effect";
|
|
27
|
+
import * as Option from "effect/Option";
|
|
28
|
+
import * as Schema from "effect/Schema";
|
|
29
|
+
|
|
30
|
+
// Pull requests that ask this persona again after it reviewed them, one item
|
|
31
|
+
// per request, unless a person has them (auto:needs-human): asking again
|
|
32
|
+
// during a dispute doesn't restart the loop. Each is routed by its assignees and reviewers.
|
|
33
|
+
const trigger = Effect.gen(function* () {
|
|
34
|
+
const labelNames = yield* Settings.labels;
|
|
35
|
+
|
|
36
|
+
return yield* Effect.forEach(
|
|
37
|
+
(yield* Review.reviewRequests).filter(
|
|
38
|
+
({ pull, reviewed }) => reviewed > 0 && !pull.labels.includes(labelNames.needsHuman),
|
|
39
|
+
),
|
|
40
|
+
({ pull, reviewed }) =>
|
|
41
|
+
Review.routed(pull, Review.reviewItem(pull, `pr-${pull.number}-review-${reviewed + 1}`)),
|
|
42
|
+
);
|
|
43
|
+
}).pipe(reportAs("trigger"));
|
|
44
|
+
|
|
45
|
+
const MergeState = Schema.Struct({ mergeable_state: Schema.String });
|
|
46
|
+
|
|
47
|
+
// Whether GitHub says the pull request conflicts with its base. Recorded, so
|
|
48
|
+
// a run that resumes takes the same path.
|
|
49
|
+
const conflicts = (pullRequest: number) =>
|
|
50
|
+
activity(
|
|
51
|
+
`conflicts-pr-${pullRequest}`,
|
|
52
|
+
Effect.gen(function* () {
|
|
53
|
+
const repo = yield* Repo;
|
|
54
|
+
|
|
55
|
+
const pull = yield* (yield* GitHub).request(
|
|
56
|
+
"GET",
|
|
57
|
+
`/repos/${repo.slug}/pulls/${pullRequest}`,
|
|
58
|
+
Option.none(),
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return Schema.decodeUnknownOption(MergeState)(pull).pipe(
|
|
62
|
+
Option.exists((state) => state.mergeable_state === "dirty"),
|
|
63
|
+
);
|
|
64
|
+
}),
|
|
65
|
+
Schema.Boolean,
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Chernabog merges only pull requests on the automated path (auto:ship), and
|
|
69
|
+
// only when that's safe; a person merges any other. A layer of a stack waits,
|
|
70
|
+
// approved, for the layer below: the epic run merges it once it is on the
|
|
71
|
+
// base. One refused because it conflicts with its base is left to
|
|
72
|
+
// resolve-conflicts, which merges the base in and asks for this review again.
|
|
73
|
+
const mergeIfShipping = (pullRequest: number) =>
|
|
74
|
+
Effect.gen(function* () {
|
|
75
|
+
if (!(yield* PullRequest.shipping(pullRequest))) {
|
|
76
|
+
return `#${pullRequest} approved; a person merges`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const waiting = yield* PullRequest.waitingOnLayer(pullRequest);
|
|
80
|
+
|
|
81
|
+
if (Option.isSome(waiting)) {
|
|
82
|
+
return `#${pullRequest} approved; ${waiting.value}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return yield* PullRequest.merge(pullRequest, { method: "squash" }).pipe(
|
|
86
|
+
Effect.catchTag("MergeRefused", (refused) =>
|
|
87
|
+
Effect.gen(function* () {
|
|
88
|
+
if (yield* conflicts(pullRequest)) {
|
|
89
|
+
return `#${pullRequest} approved, but it conflicts with its base; resolve-conflicts takes it`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return yield* PullRequest.handToPerson(pullRequest, refused.message);
|
|
93
|
+
}),
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// A first review, for a pull request with no review of this persona's to resume.
|
|
99
|
+
const reviewAfresh = (pullRequest: number) =>
|
|
100
|
+
Effect.gen(function* () {
|
|
101
|
+
const review = yield* Review.round(pullRequest, 1, { role: "reviewer" });
|
|
102
|
+
yield* Review.doneReviewing(pullRequest);
|
|
103
|
+
|
|
104
|
+
if (review.verdict === "approve") {
|
|
105
|
+
return yield* mergeIfShipping(pullRequest);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return `#${pullRequest}: review 1 requested changes`;
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const listed = (findings: ReadonlyArray<Review.Finding>, remediated: boolean) =>
|
|
112
|
+
findings.flatMap((finding) =>
|
|
113
|
+
Option.toArray(
|
|
114
|
+
Option.liftPredicate(`- ${finding.finding}`, () => finding.remediated === remediated),
|
|
115
|
+
),
|
|
116
|
+
);
|
|
117
|
+
|
|
118
|
+
const reReviews = (count: number) => {
|
|
119
|
+
if (count === 1) {
|
|
120
|
+
return "1 re-review";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return `${count} re-reviews`;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const workflow = (item: WorkItem) =>
|
|
127
|
+
Effect.gen(function* () {
|
|
128
|
+
const { rounds } = yield* Settings.reviewers;
|
|
129
|
+
const { pullRequest } = yield* Review.pullRequestOf(item);
|
|
130
|
+
const earlier = yield* Review.latestOwnReview(pullRequest);
|
|
131
|
+
|
|
132
|
+
// No review of its own to resume, as one posted before markers named their reviewer: review afresh.
|
|
133
|
+
if (Option.isNone(earlier) || Option.isNone(Option.fromUndefinedOr(earlier.value.sessionId))) {
|
|
134
|
+
return yield* reviewAfresh(pullRequest);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const round = earlier.value.round ?? 1;
|
|
138
|
+
const done = round - 1;
|
|
139
|
+
|
|
140
|
+
if (done >= rounds) {
|
|
141
|
+
return yield* PullRequest.handToPerson(
|
|
142
|
+
pullRequest,
|
|
143
|
+
`asked to review again after ${reReviews(done)}, and reviewRounds is ${rounds}, so a person decides. Review ${round}'s findings are in its review above.`,
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const rechecked = yield* Review.recheck(pullRequest, earlier.value);
|
|
148
|
+
yield* Review.doneReviewing(pullRequest);
|
|
149
|
+
yield* PullRequest.comment(
|
|
150
|
+
pullRequest,
|
|
151
|
+
[
|
|
152
|
+
`Review ${round}'s findings, re-reviewed.`,
|
|
153
|
+
"",
|
|
154
|
+
"Remediated:",
|
|
155
|
+
...listed(rechecked.findings, true),
|
|
156
|
+
"",
|
|
157
|
+
"Still open:",
|
|
158
|
+
...listed(rechecked.findings, false),
|
|
159
|
+
].join("\n"),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
if (rechecked.verdict === "approve") {
|
|
163
|
+
return yield* mergeIfShipping(pullRequest);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return yield* PullRequest.handToPerson(
|
|
167
|
+
pullRequest,
|
|
168
|
+
`review ${rechecked.round ?? 2} still requests changes after a round of fixes`,
|
|
169
|
+
);
|
|
170
|
+
}).pipe(
|
|
171
|
+
// A pull request closed, or gone, while the review ran leaves nothing to do.
|
|
172
|
+
Effect.catchTags({
|
|
173
|
+
PullRequestClosed: (closed) => Effect.fail(new Skip({ reason: closed.message })),
|
|
174
|
+
NotFound: (gone) => Effect.fail(new Skip({ reason: gone.message })),
|
|
175
|
+
}),
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
// What config.yaml may set for this flow, under settings: or flows.<name>.settings.
|
|
179
|
+
const settings = Schema.Struct({
|
|
180
|
+
...Routing.Settings.fields,
|
|
181
|
+
...Settings.Labels.fields,
|
|
182
|
+
...Settings.Base.fields,
|
|
183
|
+
...Settings.Rules.fields,
|
|
184
|
+
...Settings.Reviewers.fields,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
export default defineFlow({
|
|
188
|
+
labels: Settings.declaredLabels,
|
|
189
|
+
settings,
|
|
190
|
+
trigger,
|
|
191
|
+
concurrency: 1,
|
|
192
|
+
// Its trigger finds only pull requests that ask this persona for a review.
|
|
193
|
+
ownWork: true,
|
|
194
|
+
// Doctor warns when a reviewer this machine acts as doesn't run it.
|
|
195
|
+
doctor: [Review.reviewerCheck],
|
|
196
|
+
// A pull request closed or merged ends the run as superseded.
|
|
197
|
+
stillValid: Review.stillValid,
|
|
198
|
+
workflow,
|
|
199
|
+
});
|