@chernabog/sdk 0.7.0 → 0.8.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/README.md +16 -12
- package/index.ts +5 -0
- package/package.json +8 -3
- package/src/ci.ts +82 -0
- package/src/comment.ts +1 -3
- package/src/default-prompts.ts +24 -1
- package/src/epic.ts +568 -0
- package/src/hybrid.ts +67 -53
- package/src/implement.ts +731 -149
- package/src/index.ts +15 -13
- package/src/plan-labels.ts +9 -0
- package/src/plan.ts +48 -39
- package/src/prompt.ts +1 -3
- package/src/pull-request.ts +234 -39
- package/src/review.ts +236 -56
- package/src/routing.ts +113 -0
- package/src/settings.ts +361 -0
- package/src/stack.ts +534 -0
- package/src/still-valid.ts +142 -0
- package/src/claims.ts +0 -169
- package/src/errors.ts +0 -222
- package/src/flow.ts +0 -325
- package/src/json.ts +0 -21
- package/src/markers.ts +0 -103
- package/src/paths.ts +0 -46
- package/src/roles.ts +0 -30
- package/src/services.ts +0 -505
- package/src/stage.ts +0 -25
package/src/flow.ts
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
// Flows and the durable building blocks inside them. A flow's workflow is an
|
|
2
|
-
// Effect that the daemon runs durably: every activity's result is saved, so after
|
|
3
|
-
// a crash or restart the workflow replays the saved results and continues after
|
|
4
|
-
// the last completed one. Side effects belong inside activities, never in the
|
|
5
|
-
// workflow body, because the body runs again on every replay.
|
|
6
|
-
|
|
7
|
-
import * as Context from "effect/Context";
|
|
8
|
-
import * as Duration from "effect/Duration";
|
|
9
|
-
import * as Effect from "effect/Effect";
|
|
10
|
-
import type * as FileSystem from "effect/FileSystem";
|
|
11
|
-
import * as Option from "effect/Option";
|
|
12
|
-
import * as Predicate from "effect/Predicate";
|
|
13
|
-
import type * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";
|
|
14
|
-
import * as Schema from "effect/Schema";
|
|
15
|
-
import type * as Scope from "effect/Scope";
|
|
16
|
-
import * as Activity from "effect/workflow/Activity";
|
|
17
|
-
import * as DurableClock from "effect/workflow/DurableClock";
|
|
18
|
-
import * as DurableDeferred from "effect/workflow/DurableDeferred";
|
|
19
|
-
import type * as WorkflowEngine from "effect/workflow/WorkflowEngine";
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
AgentError,
|
|
23
|
-
GitError,
|
|
24
|
-
GitHubError,
|
|
25
|
-
NeedsHuman,
|
|
26
|
-
type ReportedError,
|
|
27
|
-
Skip,
|
|
28
|
-
StepFailed,
|
|
29
|
-
UsageError,
|
|
30
|
-
WorkError,
|
|
31
|
-
} from "./errors.ts";
|
|
32
|
-
import type { Json } from "./json.ts";
|
|
33
|
-
import {
|
|
34
|
-
type Agent,
|
|
35
|
-
type Git,
|
|
36
|
-
type GitHub,
|
|
37
|
-
type Repo,
|
|
38
|
-
type ReviewerSeat,
|
|
39
|
-
type Run,
|
|
40
|
-
RunLog,
|
|
41
|
-
type Usage,
|
|
42
|
-
type WorkItem,
|
|
43
|
-
type Worktree,
|
|
44
|
-
} from "./services.ts";
|
|
45
|
-
|
|
46
|
-
// Runs a step from .chernabog/stages/ in its own process. Provided by Chernabog.
|
|
47
|
-
export class StepRunner extends Context.Service<
|
|
48
|
-
StepRunner,
|
|
49
|
-
{
|
|
50
|
-
run(name: string, input: Json): Effect.Effect<Json, Skip | StepFailed>;
|
|
51
|
-
}
|
|
52
|
-
>()("@chernabog/sdk/StepRunner") {}
|
|
53
|
-
|
|
54
|
-
// Records that a run waits on a signal, so the next tick's trigger can wake it. Provided by Chernabog.
|
|
55
|
-
export class Signals extends Context.Service<
|
|
56
|
-
Signals,
|
|
57
|
-
{
|
|
58
|
-
register(signal: string, deferred: string, token: string): Effect.Effect<void>;
|
|
59
|
-
}
|
|
60
|
-
>()("@chernabog/sdk/Signals") {}
|
|
61
|
-
|
|
62
|
-
export type TriggerServices =
|
|
63
|
-
| Repo
|
|
64
|
-
| GitHub
|
|
65
|
-
| Git
|
|
66
|
-
| Worktree
|
|
67
|
-
| Usage
|
|
68
|
-
| Agent
|
|
69
|
-
| ReviewerSeat
|
|
70
|
-
| RunLog
|
|
71
|
-
| FileSystem.FileSystem
|
|
72
|
-
| ChildProcessSpawner.ChildProcessSpawner;
|
|
73
|
-
|
|
74
|
-
export type WorkflowServices =
|
|
75
|
-
| TriggerServices
|
|
76
|
-
| Run
|
|
77
|
-
| StepRunner
|
|
78
|
-
| Signals
|
|
79
|
-
| WorkflowEngine.WorkflowEngine
|
|
80
|
-
| WorkflowEngine.WorkflowInstance
|
|
81
|
-
| Scope.Scope;
|
|
82
|
-
|
|
83
|
-
// What a flow's trigger, gate and workflow may fail with: the flow's own
|
|
84
|
-
// outcomes. Any other error must be handled, or mapped to one of these, before
|
|
85
|
-
// the flow compiles: a work error such as PushRejected by deciding what it
|
|
86
|
-
// means for the work, and an error the flow can only report with `reportAs`.
|
|
87
|
-
export type FlowError = Skip | NeedsHuman | StepFailed;
|
|
88
|
-
|
|
89
|
-
// A label a flow triggers on or sets beyond the repo's own, such as auto:ship. `chernabog labels` creates it.
|
|
90
|
-
export type FlowLabel = {
|
|
91
|
-
readonly name: string;
|
|
92
|
-
readonly color?: string;
|
|
93
|
-
readonly description?: string;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// The work item for a key a person names: the issue `chernabog start` hands
|
|
97
|
-
// over, say. None when there is no such item.
|
|
98
|
-
export type ItemLookup = (
|
|
99
|
-
key: string,
|
|
100
|
-
) => Effect.Effect<Option.Option<WorkItem>, FlowError, TriggerServices>;
|
|
101
|
-
|
|
102
|
-
// What every flow has, whether a trigger finds its work or a person names it.
|
|
103
|
-
type FlowCommon = {
|
|
104
|
-
// Checked before each run starts; fail with Skip to hold the run back, such as on usage.
|
|
105
|
-
readonly gate?: Effect.Effect<void, FlowError, TriggerServices>;
|
|
106
|
-
// Runs of this flow in one repo at once. Defaults to 1; machine limits still apply.
|
|
107
|
-
readonly concurrency?: number;
|
|
108
|
-
// Labels of the flow's own, for `chernabog labels` to create.
|
|
109
|
-
readonly labels?: ReadonlyArray<FlowLabel>;
|
|
110
|
-
// Whether the trigger finds only the work of the persona it runs as, as
|
|
111
|
-
// review's does by its review requests, so several personas can run the
|
|
112
|
-
// flow without assignee or reviewRequested to tell them apart.
|
|
113
|
-
readonly ownWork?: boolean;
|
|
114
|
-
// The durable work for one item. Its result, if a string, is the run's summary.
|
|
115
|
-
readonly workflow: (item: WorkItem) => Effect.Effect<string | void, FlowError, WorkflowServices>;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// A flow whose trigger finds its work, on a schedule.
|
|
119
|
-
export type TriggeredFlow = FlowCommon & {
|
|
120
|
-
// The work items in the state this flow acts on, such as issues labelled auto:eligible.
|
|
121
|
-
readonly trigger: Effect.Effect<ReadonlyArray<WorkItem>, FlowError, TriggerServices>;
|
|
122
|
-
// A cron schedule for the trigger, overriding the repo's default.
|
|
123
|
-
readonly schedule?: string;
|
|
124
|
-
// The work item for a key a person names, when the trigger doesn't report it.
|
|
125
|
-
readonly item?: ItemLookup;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
// A flow with no trigger: nothing finds its work, and it runs only when a
|
|
129
|
-
// person names an item, as `chernabog start <issue>` does. It has no schedule.
|
|
130
|
-
export type ManualFlow = FlowCommon & {
|
|
131
|
-
readonly trigger?: never;
|
|
132
|
-
readonly schedule?: never;
|
|
133
|
-
readonly item: ItemLookup;
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
export type Flow = TriggeredFlow | ManualFlow;
|
|
137
|
-
|
|
138
|
-
export const defineFlow = (flow: Flow): Flow => flow;
|
|
139
|
-
|
|
140
|
-
// Whether a person starts each of the flow's runs, by naming its work.
|
|
141
|
-
export const isManual = (flow: Flow): flow is ManualFlow => !Effect.isEffect(flow.trigger);
|
|
142
|
-
|
|
143
|
-
// What the flow's trigger reports; nothing, for a manual flow.
|
|
144
|
-
export const triggerOf = (flow: Flow): TriggeredFlow["trigger"] => {
|
|
145
|
-
if (isManual(flow)) {
|
|
146
|
-
return Effect.succeed([]);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return flow.trigger;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const FlowErrorSchema = Schema.Union([Skip, NeedsHuman, StepFailed]);
|
|
153
|
-
|
|
154
|
-
// What an activity may fail with, as its journal stores it: the flow's outcomes and the work's errors.
|
|
155
|
-
const ActivityError = Schema.Union([...FlowErrorSchema.members, ...WorkError.members]);
|
|
156
|
-
const isActivityError = Schema.is(ActivityError);
|
|
157
|
-
|
|
158
|
-
// An error's message, whatever shape it came in.
|
|
159
|
-
export const describeError = <E>(error: E): string => {
|
|
160
|
-
if (Predicate.hasProperty(error, "step") && Predicate.hasProperty(error, "message")) {
|
|
161
|
-
return `${String(error.step)}: ${String(error.message)}`;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (Predicate.hasProperty(error, "message") && Predicate.isString(error.message)) {
|
|
165
|
-
return error.message;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (Predicate.hasProperty(error, "reason") && Predicate.isString(error.reason)) {
|
|
169
|
-
return error.reason;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return String(error);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
// Keeps the flow's outcomes and the work's errors, and names the activity in any other failure.
|
|
176
|
-
const toActivityError =
|
|
177
|
-
(name: string) =>
|
|
178
|
-
<E>(error: E): FlowError | WorkError => {
|
|
179
|
-
if (isActivityError(error)) {
|
|
180
|
-
return error;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
return new StepFailed({ step: name, message: describeError(error) });
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const isReportedError = Schema.is(Schema.Union([GitHubError, GitError, AgentError, UsageError]));
|
|
187
|
-
|
|
188
|
-
const isReported = <E>(error: E): error is Extract<E, ReportedError> => isReportedError(error);
|
|
189
|
-
|
|
190
|
-
// Turns the errors a flow can only report (GitHubError, GitError, AgentError,
|
|
191
|
-
// UsageError) into StepFailed, named for `step`, and keeps every other error
|
|
192
|
-
// for the flow to handle. For a trigger, or work outside an activity, which
|
|
193
|
-
// does the same for its own.
|
|
194
|
-
export const reportAs =
|
|
195
|
-
(step: string) =>
|
|
196
|
-
<A, E, R>(effect: Effect.Effect<A, E, R>) =>
|
|
197
|
-
Effect.catchIf(
|
|
198
|
-
effect,
|
|
199
|
-
isReported,
|
|
200
|
-
(error) => Effect.fail(new StepFailed({ step, message: error.message })),
|
|
201
|
-
(other) => Effect.fail(other),
|
|
202
|
-
);
|
|
203
|
-
|
|
204
|
-
const withRunLog = (use: (log: RunLog["Service"]) => Effect.Effect<void>) =>
|
|
205
|
-
Effect.serviceOption(RunLog).pipe(
|
|
206
|
-
Effect.flatMap(Option.match({ onNone: () => Effect.void, onSome: use })),
|
|
207
|
-
);
|
|
208
|
-
|
|
209
|
-
// An activity's journal holds any of the flow's outcomes and work errors, but
|
|
210
|
-
// an activity only ever fails with the outcomes and the work errors its own
|
|
211
|
-
// execute raised: toActivityError keeps no others, and a replay reads back
|
|
212
|
-
// what it kept. So a failure that is an activity error is one of E's.
|
|
213
|
-
const raisedBy =
|
|
214
|
-
<E>() =>
|
|
215
|
-
(error: FlowError | WorkError): error is FlowError | Extract<E, WorkError> =>
|
|
216
|
-
isActivityError(error);
|
|
217
|
-
|
|
218
|
-
const narrowed =
|
|
219
|
-
<E>(name: string) =>
|
|
220
|
-
<A, R>(effect: Effect.Effect<A, FlowError | WorkError, R>) =>
|
|
221
|
-
Effect.catchIf(effect, raisedBy<E>(), Effect.fail, (other) =>
|
|
222
|
-
Effect.fail(new StepFailed({ step: name, message: describeError(other) })),
|
|
223
|
-
);
|
|
224
|
-
|
|
225
|
-
// The step an activity is running, for what it calls to know by name: the
|
|
226
|
-
// Agent service gives it to the adapter, so a rehearsal's stand-ins are
|
|
227
|
-
// keyed by step. None outside an activity.
|
|
228
|
-
export const CurrentActivity = Context.Reference<Option.Option<string>>(
|
|
229
|
-
"@chernabog/sdk/CurrentActivity",
|
|
230
|
-
{
|
|
231
|
-
defaultValue: () => Option.none(),
|
|
232
|
-
},
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
// One durable step of a workflow. It runs once; its result is saved, and a
|
|
236
|
-
// replay returns the saved result. Names must be unique within a run, so a
|
|
237
|
-
// step inside a loop carries its round: `fix-ci-2`. `success` is the result's
|
|
238
|
-
// schema, which the journal stores it with; leave it out for a step that
|
|
239
|
-
// returns nothing. It fails with the flow's outcomes and the work's errors
|
|
240
|
-
// it raised, which the flow handles; any other failure is StepFailed.
|
|
241
|
-
export const activity = <S extends Schema.Constraint = typeof Schema.Void, E = never, R = never>(
|
|
242
|
-
name: string,
|
|
243
|
-
execute: Effect.Effect<S["Type"], E, R>,
|
|
244
|
-
success?: S,
|
|
245
|
-
) =>
|
|
246
|
-
narrowed<E>(name)(
|
|
247
|
-
Activity.make({
|
|
248
|
-
name,
|
|
249
|
-
success,
|
|
250
|
-
error: ActivityError,
|
|
251
|
-
execute: withRunLog((log) => log.step(name)).pipe(
|
|
252
|
-
Effect.andThen(Effect.provideService(execute, CurrentActivity, Option.some(name))),
|
|
253
|
-
Effect.ensuring(withRunLog((log) => log.stepDone(name))),
|
|
254
|
-
Effect.mapError(toActivityError(name)),
|
|
255
|
-
),
|
|
256
|
-
}),
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
// Runs .chernabog/stages/<name>.ts (or an executable <name>) in a child
|
|
260
|
-
// process, checks its output against `output`, and saves the result. `id`
|
|
261
|
-
// tells apart two runs of one step in a run.
|
|
262
|
-
export const step = <A>(
|
|
263
|
-
name: string,
|
|
264
|
-
input: Json,
|
|
265
|
-
output: Schema.Codec<A, Json>,
|
|
266
|
-
id: Option.Option<string> = Option.none(),
|
|
267
|
-
) =>
|
|
268
|
-
activity(
|
|
269
|
-
Option.match(id, { onNone: () => name, onSome: (suffix) => `${name}#${suffix}` }),
|
|
270
|
-
StepRunner.use((runner) => runner.run(name, input)).pipe(
|
|
271
|
-
Effect.flatMap((raw) =>
|
|
272
|
-
Schema.decodeEffect(output)(raw).pipe(
|
|
273
|
-
Effect.mapError(
|
|
274
|
-
(issue) => new StepFailed({ step: name, message: `output: ${issue.message}` }),
|
|
275
|
-
),
|
|
276
|
-
),
|
|
277
|
-
),
|
|
278
|
-
),
|
|
279
|
-
output,
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
// A durable pause: it survives restarts, and a timer that came due while the
|
|
283
|
-
// daemon was down fires as soon as it is back.
|
|
284
|
-
export const sleep = (name: string, duration: Duration.Input) =>
|
|
285
|
-
DurableClock.sleep({ name, duration, inMemoryThreshold: Duration.zero });
|
|
286
|
-
|
|
287
|
-
// The durable deferred behind one wait, by name. Chernabog completes it with `true` when the signal comes.
|
|
288
|
-
export const signalDeferred = (name: string) =>
|
|
289
|
-
DurableDeferred.make(name, { success: Schema.Literal(true) });
|
|
290
|
-
|
|
291
|
-
export type Wait = { readonly id: string; readonly timeout: Duration.Input };
|
|
292
|
-
|
|
293
|
-
// Waits for whichever comes first: one of the signals, which a trigger reports
|
|
294
|
-
// for this run's work item (see WorkItem.signals), or the timeout. Returns the
|
|
295
|
-
// signal's name, or "timeout". `id` makes each wait in a loop distinct:
|
|
296
|
-
// `awaitSignal(["pushed", "closed"], { id: "round-2", timeout: "6 hours" })`.
|
|
297
|
-
export const awaitSignal = (signals: ReadonlyArray<string>, wait: Wait) =>
|
|
298
|
-
Effect.gen(function* () {
|
|
299
|
-
const waits = signals.map((signal) => ({
|
|
300
|
-
signal,
|
|
301
|
-
deferred: signalDeferred(`${signal}:${wait.id}`),
|
|
302
|
-
}));
|
|
303
|
-
|
|
304
|
-
for (const pending of waits) {
|
|
305
|
-
const token = yield* DurableDeferred.token(pending.deferred);
|
|
306
|
-
yield* activity(
|
|
307
|
-
`await-${pending.deferred.name}`,
|
|
308
|
-
Signals.use((registry) => registry.register(pending.signal, pending.deferred.name, token)),
|
|
309
|
-
);
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const [first, ...rest] = [
|
|
313
|
-
...waits.map((pending) =>
|
|
314
|
-
DurableDeferred.await(pending.deferred).pipe(Effect.as(pending.signal)),
|
|
315
|
-
),
|
|
316
|
-
sleep(`timeout:${wait.id}`, wait.timeout).pipe(Effect.as("timeout")),
|
|
317
|
-
];
|
|
318
|
-
|
|
319
|
-
return yield* DurableDeferred.raceAll({
|
|
320
|
-
name: `race:${wait.id}`,
|
|
321
|
-
success: Schema.String,
|
|
322
|
-
error: Schema.Never,
|
|
323
|
-
effects: [first, ...rest],
|
|
324
|
-
});
|
|
325
|
-
});
|
package/src/json.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// JSON at the edges: every parse and print goes through a Schema codec, so a
|
|
2
|
-
// value is checked the moment it crosses the boundary.
|
|
3
|
-
|
|
4
|
-
import * as Option from "effect/Option";
|
|
5
|
-
import * as Schema from "effect/Schema";
|
|
6
|
-
|
|
7
|
-
export type Json = Schema.Json;
|
|
8
|
-
|
|
9
|
-
const JsonText = Schema.fromJsonString(Schema.Json);
|
|
10
|
-
|
|
11
|
-
// Text another program wrote, read as JSON; none when it isn't JSON.
|
|
12
|
-
export const parseJson = (text: string): Option.Option<Json> => Schema.decodeOption(JsonText)(text);
|
|
13
|
-
|
|
14
|
-
export const printJson = (value: Json): string => Schema.encodeSync(JsonText)(value);
|
|
15
|
-
|
|
16
|
-
// Each line of a JSON Lines file that the schema accepts; the others are skipped.
|
|
17
|
-
export const decodeJsonLines = <A>(
|
|
18
|
-
schema: Schema.Codec<A, string>,
|
|
19
|
-
text: string,
|
|
20
|
-
): ReadonlyArray<A> =>
|
|
21
|
-
text.split("\n").flatMap((line) => Option.toArray(Schema.decodeOption(schema)(line)));
|
package/src/markers.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// Hidden markers in pull request comments, so a later run can find what an
|
|
2
|
-
// earlier one left: who wrote the pull request, and what each review saw.
|
|
3
|
-
|
|
4
|
-
import * as Arr from "effect/Array";
|
|
5
|
-
import * as Option from "effect/Option";
|
|
6
|
-
import * as Schema from "effect/Schema";
|
|
7
|
-
|
|
8
|
-
import type { Json } from "./json.ts";
|
|
9
|
-
|
|
10
|
-
// The session that wrote a pull request. withPerson: a person worked in it
|
|
11
|
-
// with the agent, on the hybrid path, so answering a review reopens it in
|
|
12
|
-
// front of them.
|
|
13
|
-
export const SessionMarker = Schema.Struct({
|
|
14
|
-
adapter: Schema.String,
|
|
15
|
-
sessionId: Schema.String,
|
|
16
|
-
issue: Schema.Finite,
|
|
17
|
-
branch: Schema.String,
|
|
18
|
-
withPerson: Schema.optionalKey(Schema.Boolean),
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
export type SessionMarker = typeof SessionMarker.Type;
|
|
22
|
-
|
|
23
|
-
// What a review saw and said, and who gave it in which session, so a
|
|
24
|
-
// re-review resumes it. reviewer, sessionId and adapter are optional only so
|
|
25
|
-
// that markers posted before they existed still read back.
|
|
26
|
-
export const ReviewMarker = Schema.Struct({
|
|
27
|
-
sha: Schema.String,
|
|
28
|
-
round: Schema.Finite,
|
|
29
|
-
verdict: Schema.Literals(["approve", "request-changes"]),
|
|
30
|
-
reviewer: Schema.optionalKey(Schema.String),
|
|
31
|
-
sessionId: Schema.optionalKey(Schema.String),
|
|
32
|
-
adapter: Schema.optionalKey(Schema.String),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
export type ReviewMarker = typeof ReviewMarker.Type;
|
|
36
|
-
|
|
37
|
-
const marker = <A>(name: string, schema: Schema.Codec<A, Json>) => {
|
|
38
|
-
const pattern = new RegExp(`<!-- chernabog-${name} (\\{.*?\\}) -->`);
|
|
39
|
-
const codec = Schema.fromJsonString(schema);
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
write: (value: A) => `<!-- chernabog-${name} ${Schema.encodeSync(codec)(value)} -->`,
|
|
43
|
-
read: (body: string): Option.Option<A> =>
|
|
44
|
-
Option.fromNullishOr(body.match(pattern)).pipe(
|
|
45
|
-
Option.flatMap((match) => Schema.decodeOption(codec)(match[1])),
|
|
46
|
-
),
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// withPerson: claimed by a person's `chernabog start`, which another start of
|
|
51
|
-
// the issue may take over. ref: the claim is a claim ref (Claims), which a
|
|
52
|
-
// run of this version always writes; a marker without it is from a run that
|
|
53
|
-
// held the issue by its branch alone.
|
|
54
|
-
export const ClaimMarker = Schema.Struct({
|
|
55
|
-
runId: Schema.String,
|
|
56
|
-
claimedAt: Schema.String,
|
|
57
|
-
branch: Schema.String,
|
|
58
|
-
withPerson: Schema.optionalKey(Schema.Boolean),
|
|
59
|
-
ref: Schema.optionalKey(Schema.Boolean),
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
export type ClaimMarker = typeof ClaimMarker.Type;
|
|
63
|
-
|
|
64
|
-
// A run that owns a pull request, or let it go: the standalone review and fix
|
|
65
|
-
// flows leave a pull request alone while a run of another flow owns it. ref:
|
|
66
|
-
// the run holds the pull request's claim ref (Claims), which decides; a marker
|
|
67
|
-
// without it is from a run that owned it by comment alone.
|
|
68
|
-
export const OwnerMarker = Schema.Struct({
|
|
69
|
-
flow: Schema.String,
|
|
70
|
-
runId: Schema.String,
|
|
71
|
-
released: Schema.Boolean,
|
|
72
|
-
ref: Schema.optionalKey(Schema.Boolean),
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
export type OwnerMarker = typeof OwnerMarker.Type;
|
|
76
|
-
|
|
77
|
-
// A plan proposed on its spec issue, by round, so the run finds the comments
|
|
78
|
-
// a person left on it since.
|
|
79
|
-
export const PlanMarker = Schema.Struct({ round: Schema.Finite });
|
|
80
|
-
|
|
81
|
-
export type PlanMarker = typeof PlanMarker.Type;
|
|
82
|
-
|
|
83
|
-
// An issue a plan made: its spec and its task's key, so a run that resumes
|
|
84
|
-
// finds the issues it made rather than making them twice.
|
|
85
|
-
export const PlanNodeMarker = Schema.Struct({ spec: Schema.Finite, key: Schema.String });
|
|
86
|
-
|
|
87
|
-
export type PlanNodeMarker = typeof PlanNodeMarker.Type;
|
|
88
|
-
|
|
89
|
-
export const claimMarker = marker("claim", ClaimMarker);
|
|
90
|
-
export const sessionMarker = marker("session", SessionMarker);
|
|
91
|
-
export const reviewMarker = marker("review", ReviewMarker);
|
|
92
|
-
export const ownerMarker = marker("owner", OwnerMarker);
|
|
93
|
-
export const planMarker = marker("plan", PlanMarker);
|
|
94
|
-
export const planNodeMarker = marker("plan-node", PlanNodeMarker);
|
|
95
|
-
|
|
96
|
-
// Whether a body carries any of chernabog's markers: a comment chernabog wrote.
|
|
97
|
-
export const hasMarker = (body: string) => /<!-- chernabog-[\w-]+ \{/.test(body);
|
|
98
|
-
|
|
99
|
-
// The newest marker among comment bodies, oldest first.
|
|
100
|
-
export const latestMarker = <A>(
|
|
101
|
-
read: (body: string) => Option.Option<A>,
|
|
102
|
-
bodies: ReadonlyArray<string>,
|
|
103
|
-
): Option.Option<A> => Arr.last(bodies.flatMap((body) => Option.toArray(read(body))));
|
package/src/paths.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// Path rules such as humanOnlyPaths: `.github/**`, `**/package.json`, `RELEASE.md`.
|
|
2
|
-
|
|
3
|
-
const escape = (text: string) => text.replace(/[.+^${}()|[\]\\]/g, "\\$&");
|
|
4
|
-
|
|
5
|
-
const doubleStar = (glob: string, index: number) => {
|
|
6
|
-
if (glob[index + 2] === "/") {
|
|
7
|
-
return { pattern: "(?:.*/)?", skip: 2 };
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return { pattern: ".*", skip: 1 };
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const globToRegExp = (glob: string) => {
|
|
14
|
-
let pattern = "";
|
|
15
|
-
|
|
16
|
-
for (let index = 0; index < glob.length; index++) {
|
|
17
|
-
const char = glob[index];
|
|
18
|
-
|
|
19
|
-
if (char === "*" && glob[index + 1] === "*") {
|
|
20
|
-
const star = doubleStar(glob, index);
|
|
21
|
-
pattern += star.pattern;
|
|
22
|
-
index += star.skip;
|
|
23
|
-
} else if (char === "*") {
|
|
24
|
-
pattern += "[^/]*";
|
|
25
|
-
} else if (char === "?") {
|
|
26
|
-
pattern += "[^/]";
|
|
27
|
-
} else {
|
|
28
|
-
pattern += escape(char);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// A directory rule covers everything under it.
|
|
33
|
-
let rest = "(?:/.*)?";
|
|
34
|
-
|
|
35
|
-
if (glob.endsWith("/")) {
|
|
36
|
-
rest = ".*";
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return new RegExp(`^${pattern}${rest}$`);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const pathsMatching = (paths: ReadonlyArray<string>, globs: ReadonlyArray<string>) => {
|
|
43
|
-
const rules = globs.map(globToRegExp);
|
|
44
|
-
|
|
45
|
-
return paths.filter((path) => rules.some((rule) => rule.test(path)));
|
|
46
|
-
};
|
package/src/roles.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// Which adapter a step runs its agent with. A persona can give a role its own
|
|
2
|
-
// account in machine config (roles: { reviewer: codex-work }), and a flow can
|
|
3
|
-
// name roles in config (flows.<flow>.agents, such as { reviewer: codex }). A
|
|
4
|
-
// step given { role } runs with the persona's pick for it, then the flow's,
|
|
5
|
-
// then the flow's agent, then the repo's.
|
|
6
|
-
|
|
7
|
-
import * as Effect from "effect/Effect";
|
|
8
|
-
import * as Option from "effect/Option";
|
|
9
|
-
import * as Record from "effect/Record";
|
|
10
|
-
|
|
11
|
-
import { Repo, Run } from "./services.ts";
|
|
12
|
-
|
|
13
|
-
// What a step that runs an agent can be told: the role it plays in the flow.
|
|
14
|
-
export type RoleOptions = { readonly role?: string };
|
|
15
|
-
|
|
16
|
-
// The adapter for a role in this run's flow; none means the repo's own agent.
|
|
17
|
-
export const adapterFor = (role: Option.Option<string>) =>
|
|
18
|
-
Effect.gen(function* () {
|
|
19
|
-
const repo = yield* Repo;
|
|
20
|
-
const run = yield* Run;
|
|
21
|
-
const roles = Record.get(repo.flowRoleAgents ?? {}, run.flow);
|
|
22
|
-
|
|
23
|
-
const forRole = Option.flatMap(role, (name) =>
|
|
24
|
-
Option.orElse(Record.get(repo.roleAgents ?? {}, name), () =>
|
|
25
|
-
Option.flatMap(roles, Record.get(name)),
|
|
26
|
-
),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
return Option.orElse(forRole, () => Record.get(repo.flowAgents, run.flow));
|
|
30
|
-
});
|