@chernabog/sdk 0.10.0 → 0.11.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/package.json +1 -1
- package/src/address-review-blocks.ts +510 -0
- package/src/block.ts +466 -0
- package/src/blocks.ts +1051 -0
- package/src/compose.ts +2666 -0
- package/src/epic-blocks.ts +1217 -0
- package/src/human-initiated-blocks.ts +274 -0
- package/src/hybrid.ts +2 -1
- package/src/implement.ts +103 -16
- package/src/index.ts +3 -0
- package/src/plan-blocks.ts +312 -0
- package/src/post-merge-blocks.ts +826 -0
- package/src/pull-request.ts +17 -0
- package/src/re-review-blocks.ts +234 -0
- package/src/resolve-conflicts-blocks.ts +567 -0
- package/src/review.ts +3 -1
- package/src/settings.ts +22 -2
- package/src/suits.ts +156 -0
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// The plan recipe's blocks. A run claims a spec labelled auto:plan, has the
|
|
2
|
+
// agent draft a plan of tasks in a read-only checkout, checks it in code and
|
|
3
|
+
// sends it back to be fixed, posts it on the spec and parks until a person
|
|
4
|
+
// answers. Approved, each task becomes a sub-issue and the spec an epic;
|
|
5
|
+
// changes asked, the next round drafts it again with them.
|
|
6
|
+
//
|
|
7
|
+
// The checks and their fixes are plan.draft's own, with outcomes, rather than
|
|
8
|
+
// logic in a document. What runs only once a run is on its way out (making
|
|
9
|
+
// the issues, the epic, removing the checkout, posting questions) is `last`:
|
|
10
|
+
// in a repeat it takes no round, so its step names are the recipe's.
|
|
11
|
+
|
|
12
|
+
import { Claims, GitHub, NeedsHuman, reportAs, type WorkItem } from "@chernabog/core";
|
|
13
|
+
import * as Effect from "effect/Effect";
|
|
14
|
+
import * as Option from "effect/Option";
|
|
15
|
+
import * as Schema from "effect/Schema";
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
type Days,
|
|
19
|
+
defineBlock,
|
|
20
|
+
defineSource,
|
|
21
|
+
type FailureContext,
|
|
22
|
+
IssueNumber,
|
|
23
|
+
ToPerson,
|
|
24
|
+
} from "./block.ts";
|
|
25
|
+
import * as Implement from "./implement.ts";
|
|
26
|
+
import * as Plan from "./plan.ts";
|
|
27
|
+
import * as Routing from "./routing.ts";
|
|
28
|
+
import * as Settings from "./settings.ts";
|
|
29
|
+
|
|
30
|
+
// That a person approved the plan, which only plan.awaitAnswer gives, so no
|
|
31
|
+
// document makes a plan's issues before a person has said yes.
|
|
32
|
+
export class PlanApproved extends Schema.TaggedClass<
|
|
33
|
+
PlanApproved,
|
|
34
|
+
{ readonly brand: "PlanApproved" }
|
|
35
|
+
>()("PlanApproved", {}) {}
|
|
36
|
+
|
|
37
|
+
// What a person asked to change of the last plan, for the next round's draft:
|
|
38
|
+
// none in the first round.
|
|
39
|
+
export type PlanChanges = Option.Option<string>;
|
|
40
|
+
|
|
41
|
+
// What a plan's rounds start with, by the name a document uses it by.
|
|
42
|
+
export const planLoopStates = {
|
|
43
|
+
"plan.changes": (): PlanChanges => Option.none(),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type Scoped<A, E, R> = (context: FailureContext) => Effect.Effect<A, E, R>;
|
|
47
|
+
|
|
48
|
+
// A spec: an issue to plan. Its failures going to a person remove the plan's
|
|
49
|
+
// checkout, label the spec auto:needs-human and say why, as the recipe's do,
|
|
50
|
+
// and its claim goes however the run ends; a run parked on its plan keeps it.
|
|
51
|
+
export const specSubject = {
|
|
52
|
+
fields: ["issue", "queued"],
|
|
53
|
+
kinds: { issue: "IssueNumber", queued: "how the issue was queued" },
|
|
54
|
+
failureContext: [],
|
|
55
|
+
read: (item: WorkItem) =>
|
|
56
|
+
Effect.gen(function* () {
|
|
57
|
+
return {
|
|
58
|
+
issue: IssueNumber(yield* Implement.issueOf(item)),
|
|
59
|
+
queued: yield* Implement.queuedBy(item),
|
|
60
|
+
};
|
|
61
|
+
}),
|
|
62
|
+
scope: <A, E, R>(
|
|
63
|
+
trigger: { readonly issue: IssueNumber },
|
|
64
|
+
options: { readonly claims: boolean },
|
|
65
|
+
body: Scoped<A, E | ToPerson, R>,
|
|
66
|
+
) => {
|
|
67
|
+
const handled = Effect.suspend(() => body({ pr: Option.none() })).pipe(
|
|
68
|
+
Effect.catchIf(
|
|
69
|
+
(failure): failure is ToPerson => failure instanceof ToPerson,
|
|
70
|
+
(failure) =>
|
|
71
|
+
Plan.doneDrafting(trigger.issue).pipe(
|
|
72
|
+
Effect.andThen(Plan.handToHuman(trigger.issue, failure.reason)),
|
|
73
|
+
Effect.flatMap(Implement.endForPerson),
|
|
74
|
+
),
|
|
75
|
+
),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
if (options.claims) {
|
|
79
|
+
return handled.pipe(Claims.releasing(Claims.issue(trigger.issue)));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return handled;
|
|
83
|
+
},
|
|
84
|
+
stillValid: Option.some(Plan.stillValid),
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export const planSources = {
|
|
88
|
+
"plan.queued": defineSource("plan.queued", "spec", () => ({
|
|
89
|
+
trigger: Effect.gen(function* () {
|
|
90
|
+
const queued = yield* (yield* GitHub).queuedIssuesLabelled(Plan.LABELS.plan);
|
|
91
|
+
|
|
92
|
+
return yield* Effect.forEach(queued, (issue) =>
|
|
93
|
+
Implement.routed(issue, Implement.issueItem(issue, Option.some(Plan.LABELS.plan))),
|
|
94
|
+
);
|
|
95
|
+
}).pipe(reportAs("trigger")),
|
|
96
|
+
contributes: {
|
|
97
|
+
settings: { ...Routing.Settings.fields, ...Settings.Board.fields },
|
|
98
|
+
labels: Plan.flowLabels,
|
|
99
|
+
},
|
|
100
|
+
})),
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// What every plan block suits: each reads or writes the spec's plan, whose
|
|
104
|
+
// checkout only a spec's scope removes when a person must take over.
|
|
105
|
+
const ON_SPEC = ["spec"];
|
|
106
|
+
|
|
107
|
+
export const planBlocks = {
|
|
108
|
+
"plan.draft": defineBlock({
|
|
109
|
+
name: "plan.draft",
|
|
110
|
+
suits: ON_SPEC,
|
|
111
|
+
about:
|
|
112
|
+
"Has the agent read the spec and the code, in a read-only checkout of the base branch, and propose the tasks it splits into: each a title, a body, a kind (auto for an agent, hybrid for a person with an agent, human for a person) and the tasks that block it. The plan is checked in code: at least one task and at most planNodes, keys that are lowercase letters, digits and dashes, no key twice and none named verify, a known kind, a title, blockers that are tasks, and no cycle. A plan that fails goes back to the agent with what's wrong, up to planRounds times, and then to a person. The agent may answer with questions instead. Given what a person asked to change, it drafts the plan again with that.",
|
|
113
|
+
inputKinds: {
|
|
114
|
+
issue: "IssueNumber: the spec",
|
|
115
|
+
round: "the round",
|
|
116
|
+
changes: "what a person asked to change, from plan.changesAsked: state.changes",
|
|
117
|
+
},
|
|
118
|
+
outputKinds: { draft: "the plan, which passed its checks: for plan.propose" },
|
|
119
|
+
outcomeKinds: { "needs-clarification": "the agent's answer, with its questions" },
|
|
120
|
+
opens: ["remove-checkout"],
|
|
121
|
+
inputs: { issue: "required", round: "required", changes: "required" },
|
|
122
|
+
run: (input: {
|
|
123
|
+
readonly issue: IssueNumber;
|
|
124
|
+
readonly round: number;
|
|
125
|
+
readonly changes: PlanChanges;
|
|
126
|
+
}) =>
|
|
127
|
+
Plan.checkedDraft(input.issue, input.round, input.changes).pipe(
|
|
128
|
+
Effect.map((draft) => ({ draft })),
|
|
129
|
+
),
|
|
130
|
+
failures: { NeedsHuman: "person", NotFound: "skip", Skip: "skip", StepFailed: "person" },
|
|
131
|
+
outcomes: {
|
|
132
|
+
"needs-clarification": (drafted: { readonly draft: Plan.PlanDraft }) =>
|
|
133
|
+
Option.liftPredicate(drafted.draft, (draft) => draft.status === "needs-clarification"),
|
|
134
|
+
},
|
|
135
|
+
mustRoute: ["needs-clarification"],
|
|
136
|
+
contributes: {
|
|
137
|
+
settings: { ...Settings.Base.fields, ...Settings.Rules.fields, ...Settings.Plans.fields },
|
|
138
|
+
},
|
|
139
|
+
}),
|
|
140
|
+
|
|
141
|
+
"plan.propose": defineBlock({
|
|
142
|
+
name: "plan.propose",
|
|
143
|
+
suits: ON_SPEC,
|
|
144
|
+
about:
|
|
145
|
+
"Posts the plan on the spec as a comment: its summary, a Mermaid graph of which task blocks which, each task folded, and how to answer it. It adds a verify task last, for a person, blocked by every other, that checks the work against the spec's acceptance criteria. It labels the spec auto:plan-proposed, waiting on a person.",
|
|
146
|
+
inputKinds: {
|
|
147
|
+
issue: "IssueNumber: the spec",
|
|
148
|
+
round: "the round",
|
|
149
|
+
draft: "the plan, from plan.draft",
|
|
150
|
+
},
|
|
151
|
+
outputKinds: { plan: "the plan as posted, with its verify task: for plan.create" },
|
|
152
|
+
outcomeKinds: {},
|
|
153
|
+
before: ["plan.awaitAnswer"],
|
|
154
|
+
inputs: { issue: "required", round: "required", draft: "required" },
|
|
155
|
+
run: (input: {
|
|
156
|
+
readonly issue: IssueNumber;
|
|
157
|
+
readonly round: number;
|
|
158
|
+
readonly draft: Plan.PlanDraft;
|
|
159
|
+
}) =>
|
|
160
|
+
Plan.propose(input.issue, input.round, input.draft).pipe(Effect.map((plan) => ({ plan }))),
|
|
161
|
+
failures: { NeedsHuman: "person", NotFound: "skip", Skip: "skip", StepFailed: "person" },
|
|
162
|
+
outcomes: {},
|
|
163
|
+
mustRoute: [],
|
|
164
|
+
contributes: {},
|
|
165
|
+
}),
|
|
166
|
+
|
|
167
|
+
"plan.awaitAnswer": defineBlock({
|
|
168
|
+
name: "plan.awaitAnswer",
|
|
169
|
+
suits: ON_SPEC,
|
|
170
|
+
fixed: ["within"],
|
|
171
|
+
about:
|
|
172
|
+
"Parks the run until a person answers the posted plan: approved when the spec carries auto:plan-approved, or changes when a member of the repo comments on it. Nobody answering within `within` goes to a person.",
|
|
173
|
+
inputKinds: { round: "the round", within: 'how long, as "14 days"' },
|
|
174
|
+
outputKinds: "approved or changes-requested",
|
|
175
|
+
outcomeKinds: {
|
|
176
|
+
approved: "an object: with as: approval, approval.approved (PlanApproved), for plan.create",
|
|
177
|
+
changes: "nothing: plan.changesAsked reads what to change",
|
|
178
|
+
},
|
|
179
|
+
inputs: { round: "required", within: "required" },
|
|
180
|
+
run: (input: { readonly round: number; readonly within: Days }) =>
|
|
181
|
+
Effect.gen(function* () {
|
|
182
|
+
const answer = yield* Plan.awaitAnswer(input.round, input.within);
|
|
183
|
+
|
|
184
|
+
if (answer === "timeout") {
|
|
185
|
+
return yield* new NeedsHuman({
|
|
186
|
+
reason: `nobody answered the plan within ${input.within}`,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return answer;
|
|
191
|
+
}),
|
|
192
|
+
failures: { NeedsHuman: "person", Skip: "skip", StepFailed: "person" },
|
|
193
|
+
outcomes: {
|
|
194
|
+
approved: (answer: string) =>
|
|
195
|
+
Option.liftPredicate({ approved: new PlanApproved({}) }, () => answer === "approved"),
|
|
196
|
+
changes: (answer: string) => Option.liftPredicate({}, () => answer !== "approved"),
|
|
197
|
+
},
|
|
198
|
+
mustRoute: ["approved", "changes"],
|
|
199
|
+
exhaustive: true,
|
|
200
|
+
waits: true,
|
|
201
|
+
contributes: { wakes: Plan.answers.pipe(reportAs("trigger")) },
|
|
202
|
+
}),
|
|
203
|
+
|
|
204
|
+
"plan.changesAsked": defineBlock({
|
|
205
|
+
name: "plan.changesAsked",
|
|
206
|
+
suits: ON_SPEC,
|
|
207
|
+
about:
|
|
208
|
+
"Reads what a person asked to change of the plan, from the comments of the repo's members since it was posted, and takes auto:plan-proposed off the spec. Its changes go to the next round, with next: { changes: <this step>.changes }.",
|
|
209
|
+
inputKinds: { issue: "IssueNumber: the spec", round: "the round" },
|
|
210
|
+
outputKinds: { changes: "what to change, for the next round's plan.draft" },
|
|
211
|
+
outcomeKinds: {},
|
|
212
|
+
inputs: { issue: "required", round: "required" },
|
|
213
|
+
run: (input: { readonly issue: IssueNumber; readonly round: number }) =>
|
|
214
|
+
Plan.changesAsked(input.issue, input.round).pipe(
|
|
215
|
+
Effect.map((asked) => ({ changes: Option.some(asked) })),
|
|
216
|
+
),
|
|
217
|
+
failures: { NeedsHuman: "person", Skip: "skip", StepFailed: "person" },
|
|
218
|
+
outcomes: {},
|
|
219
|
+
mustRoute: [],
|
|
220
|
+
contributes: {},
|
|
221
|
+
}),
|
|
222
|
+
|
|
223
|
+
"plan.create": defineBlock({
|
|
224
|
+
name: "plan.create",
|
|
225
|
+
suits: ON_SPEC,
|
|
226
|
+
about:
|
|
227
|
+
"Makes each task of the approved plan an issue and a sub-issue of the spec, links each to the tasks that block it, and only then labels them by kind (auto:eligible for auto, auto:needs-human for human, none for hybrid), so no flow picks one up before its blockers are linked. A task's issue made before a crash is found by its marker, not made twice. It runs only on the run's way out.",
|
|
228
|
+
inputKinds: {
|
|
229
|
+
issue: "IssueNumber: the spec",
|
|
230
|
+
plan: "the plan as posted, from plan.propose",
|
|
231
|
+
approved: "PlanApproved: from plan.awaitAnswer",
|
|
232
|
+
},
|
|
233
|
+
outputKinds: { created: "each task's key and issue: for plan.becomeEpic" },
|
|
234
|
+
outcomeKinds: {},
|
|
235
|
+
before: ["plan.becomeEpic"],
|
|
236
|
+
last: true,
|
|
237
|
+
inputs: { issue: "required", plan: "required", approved: "required" },
|
|
238
|
+
run: (input: {
|
|
239
|
+
readonly issue: IssueNumber;
|
|
240
|
+
readonly plan: Plan.Plan;
|
|
241
|
+
readonly approved: PlanApproved;
|
|
242
|
+
}) => Plan.create(input.issue, input.plan).pipe(Effect.map((created) => ({ created }))),
|
|
243
|
+
failures: { NeedsHuman: "person", Skip: "skip", StepFailed: "person" },
|
|
244
|
+
outcomes: {},
|
|
245
|
+
mustRoute: [],
|
|
246
|
+
contributes: {},
|
|
247
|
+
}),
|
|
248
|
+
|
|
249
|
+
"plan.becomeEpic": defineBlock({
|
|
250
|
+
name: "plan.becomeEpic",
|
|
251
|
+
suits: ON_SPEC,
|
|
252
|
+
about:
|
|
253
|
+
"Labels the spec auto:epic, which the epic flow picks up, takes the plan's labels and auto:in-progress off it, deletes its branch, and says which issue each task became. It runs only on the run's way out.",
|
|
254
|
+
inputKinds: {
|
|
255
|
+
issue: "IssueNumber: the spec",
|
|
256
|
+
plan: "the plan as posted, from plan.propose",
|
|
257
|
+
created: "the issues, from plan.create",
|
|
258
|
+
},
|
|
259
|
+
outputKinds: "a summary, for `end`'s summary",
|
|
260
|
+
outcomeKinds: {},
|
|
261
|
+
last: true,
|
|
262
|
+
inputs: { issue: "required", plan: "required", created: "required" },
|
|
263
|
+
run: (input: {
|
|
264
|
+
readonly issue: IssueNumber;
|
|
265
|
+
readonly plan: Plan.Plan;
|
|
266
|
+
readonly created: Plan.Created;
|
|
267
|
+
}) => Plan.becomeEpic(input.issue, input.plan, input.created),
|
|
268
|
+
failures: { NeedsHuman: "person", Skip: "skip", StepFailed: "person" },
|
|
269
|
+
outcomes: {},
|
|
270
|
+
mustRoute: [],
|
|
271
|
+
contributes: {},
|
|
272
|
+
}),
|
|
273
|
+
|
|
274
|
+
"plan.doneDrafting": defineBlock({
|
|
275
|
+
name: "plan.doneDrafting",
|
|
276
|
+
suits: ON_SPEC,
|
|
277
|
+
about:
|
|
278
|
+
"Removes the read-only checkout the agent drafted the plan in, before the run ends: as an epic, or with the agent's questions. A failure going to a person removes it too. It runs only on the run's way out, and a failure of its own fails the run.",
|
|
279
|
+
inputKinds: { issue: "IssueNumber: the spec" },
|
|
280
|
+
outputKinds: "nothing",
|
|
281
|
+
outcomeKinds: {},
|
|
282
|
+
closes: ["remove-checkout"],
|
|
283
|
+
last: true,
|
|
284
|
+
inputs: { issue: "required" },
|
|
285
|
+
run: (input: { readonly issue: IssueNumber }) => Plan.doneDrafting(input.issue),
|
|
286
|
+
failures: { NeedsHuman: "told", Skip: "skip", StepFailed: "fail" },
|
|
287
|
+
outcomes: {},
|
|
288
|
+
mustRoute: [],
|
|
289
|
+
contributes: {},
|
|
290
|
+
}),
|
|
291
|
+
|
|
292
|
+
"plan.askClarification": defineBlock({
|
|
293
|
+
name: "plan.askClarification",
|
|
294
|
+
suits: ON_SPEC,
|
|
295
|
+
about:
|
|
296
|
+
"Posts the agent's questions on the spec, labels it auto:needs-clarification, and says to answer them and apply auto:plan again. Its output is the reason to end with: end: needs-human, and the run lets the claim go. It runs only on the run's way out, and a failure of its own fails the run.",
|
|
297
|
+
inputKinds: {
|
|
298
|
+
issue: "IssueNumber: the spec",
|
|
299
|
+
draft: "the agent's answer, from plan.draft's needs-clarification",
|
|
300
|
+
},
|
|
301
|
+
outputKinds: "the reason, for `end: needs-human`",
|
|
302
|
+
outcomeKinds: {},
|
|
303
|
+
last: true,
|
|
304
|
+
inputs: { issue: "required", draft: "required" },
|
|
305
|
+
run: (input: { readonly issue: IssueNumber; readonly draft: Plan.PlanDraft }) =>
|
|
306
|
+
Plan.askForClarification(input.issue, input.draft),
|
|
307
|
+
failures: { NeedsHuman: "told", Skip: "skip", StepFailed: "fail" },
|
|
308
|
+
outcomes: {},
|
|
309
|
+
mustRoute: [],
|
|
310
|
+
contributes: {},
|
|
311
|
+
}),
|
|
312
|
+
};
|