@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/services.ts
DELETED
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
// The services a flow, trigger or step can use. Chernabog provides each one;
|
|
2
|
-
// a team can replace any of them with its own layer, and tests can use fakes.
|
|
3
|
-
|
|
4
|
-
import * as Context from "effect/Context";
|
|
5
|
-
import type * as Effect from "effect/Effect";
|
|
6
|
-
import * as Option from "effect/Option";
|
|
7
|
-
import * as Schema from "effect/Schema";
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
AgentError,
|
|
11
|
-
GitError,
|
|
12
|
-
GitHubError,
|
|
13
|
-
MergeRefused,
|
|
14
|
-
NotFound,
|
|
15
|
-
PullRequestClosed,
|
|
16
|
-
PushRejected,
|
|
17
|
-
UsageError,
|
|
18
|
-
} from "./errors.ts";
|
|
19
|
-
import type { Json } from "./json.ts";
|
|
20
|
-
|
|
21
|
-
export const Labels = Schema.Struct({
|
|
22
|
-
eligible: Schema.String,
|
|
23
|
-
inProgress: Schema.String,
|
|
24
|
-
needsReview: Schema.String,
|
|
25
|
-
changesRequested: Schema.String,
|
|
26
|
-
approved: Schema.String,
|
|
27
|
-
needsHuman: Schema.String,
|
|
28
|
-
needsClarification: Schema.String,
|
|
29
|
-
stale: Schema.String,
|
|
30
|
-
// The automated path: chernabog merges a pull request only when it carries this.
|
|
31
|
-
ship: Schema.String,
|
|
32
|
-
// The hybrid path, for people reading GitHub: a person started the work. No flow decides anything from it.
|
|
33
|
-
hybrid: Schema.String,
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
export type Labels = typeof Labels.Type;
|
|
37
|
-
|
|
38
|
-
export const DEFAULT_LABELS: Labels = {
|
|
39
|
-
eligible: "auto:eligible",
|
|
40
|
-
inProgress: "auto:in-progress",
|
|
41
|
-
needsReview: "auto:needs-review",
|
|
42
|
-
changesRequested: "auto:changes-requested",
|
|
43
|
-
approved: "auto:approved",
|
|
44
|
-
needsHuman: "auto:needs-human",
|
|
45
|
-
needsClarification: "auto:needs-clarification",
|
|
46
|
-
stale: "auto:stale",
|
|
47
|
-
ship: "auto:ship",
|
|
48
|
-
hybrid: "hybrid",
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const Board = Schema.Struct({
|
|
52
|
-
projectNumber: Schema.Finite,
|
|
53
|
-
readyStatus: Schema.String,
|
|
54
|
-
inProgressStatus: Schema.String,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
export type Board = typeof Board.Type;
|
|
58
|
-
|
|
59
|
-
// configDir none is the agent's default home (~/.claude, ~/.codex).
|
|
60
|
-
// oauthTokenEnv names the environment variable holding a Claude login token
|
|
61
|
-
// (from `claude setup-token`), for a host with no login of its own, such as CI.
|
|
62
|
-
// usageGate none launches without reading usage, which such a token cannot.
|
|
63
|
-
export const UsageGateMode = Schema.Literals(["usage", "none"]);
|
|
64
|
-
|
|
65
|
-
export type UsageGateMode = typeof UsageGateMode.Type;
|
|
66
|
-
|
|
67
|
-
export const Account = Schema.Struct({
|
|
68
|
-
name: Schema.String,
|
|
69
|
-
configDir: Schema.Option(Schema.String),
|
|
70
|
-
expectedEmail: Schema.Option(Schema.String),
|
|
71
|
-
oauthTokenEnv: Schema.Option(Schema.String),
|
|
72
|
-
usageGate: UsageGateMode,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
export type Account = typeof Account.Type;
|
|
76
|
-
|
|
77
|
-
export const Limits = Schema.Struct({
|
|
78
|
-
// Agent attempts to get the local gate passing before a person takes over.
|
|
79
|
-
localGateRounds: Schema.Finite,
|
|
80
|
-
// Pushes to fix red CI before a person takes over.
|
|
81
|
-
ciRounds: Schema.Finite,
|
|
82
|
-
// Review rounds on one pull request before a person takes over.
|
|
83
|
-
reviewRounds: Schema.Finite,
|
|
84
|
-
// How long a pull request waits for its author's push before it is stale.
|
|
85
|
-
staleAfter: Schema.Duration,
|
|
86
|
-
// How long CI may stay pending before a person looks.
|
|
87
|
-
ciTimeout: Schema.Duration,
|
|
88
|
-
// The most tasks one plan may hold, its verify node aside.
|
|
89
|
-
planNodes: Schema.Finite,
|
|
90
|
-
// Times the agent is asked to fix a plan that fails its checks before a person takes over.
|
|
91
|
-
planRounds: Schema.Finite,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
export type Limits = typeof Limits.Type;
|
|
95
|
-
|
|
96
|
-
const Strings = Schema.Array(Schema.String);
|
|
97
|
-
|
|
98
|
-
// A launcher of your own, from machine config: command templates with
|
|
99
|
-
// {command}, {cwd}, {title} and {handle}.
|
|
100
|
-
export const LauncherCommands = Schema.Struct({
|
|
101
|
-
start: Strings,
|
|
102
|
-
close: Strings,
|
|
103
|
-
alive: Schema.Option(Strings),
|
|
104
|
-
attach: Schema.Option(Strings),
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
export type LauncherCommands = typeof LauncherCommands.Type;
|
|
108
|
-
|
|
109
|
-
// Where interactive agent sessions run (orca, tmux, a custom one, or headless
|
|
110
|
-
// for none), which config layer chose it, and a custom launcher's commands.
|
|
111
|
-
export const ResolvedLauncher = Schema.Struct({
|
|
112
|
-
name: Schema.String,
|
|
113
|
-
from: Schema.String,
|
|
114
|
-
custom: Schema.Option(LauncherCommands),
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
export type ResolvedLauncher = typeof ResolvedLauncher.Type;
|
|
118
|
-
|
|
119
|
-
export const HEADLESS: ResolvedLauncher = {
|
|
120
|
-
name: "headless",
|
|
121
|
-
from: "default",
|
|
122
|
-
custom: Option.none(),
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// Everything a run knows about the repo it works on, merged from the repo's
|
|
126
|
-
// committed config and the persona's settings in machine config.
|
|
127
|
-
export const RepoSettings = Schema.Struct({
|
|
128
|
-
name: Schema.String,
|
|
129
|
-
slug: Schema.String,
|
|
130
|
-
path: Schema.String,
|
|
131
|
-
baseBranch: Schema.String,
|
|
132
|
-
// The team's reviewer pool, by GitHub login: a pull request with green CI
|
|
133
|
-
// gets one of them, never its author. None, when the team names no pool.
|
|
134
|
-
reviewers: Schema.optionalKey(Strings),
|
|
135
|
-
// The GitHub login this run acts as, when machine config names personas;
|
|
136
|
-
// absent, it acts as whoever the daemon is.
|
|
137
|
-
persona: Schema.optionalKey(Schema.String),
|
|
138
|
-
account: Account,
|
|
139
|
-
// The adapter that implements, and the account each adapter runs under.
|
|
140
|
-
agent: Schema.String,
|
|
141
|
-
agentAccounts: Schema.Record(Schema.String, Account),
|
|
142
|
-
launcher: ResolvedLauncher,
|
|
143
|
-
// The adapter a flow asked for in config (flows.<name>.agent), such as a Codex reviewer.
|
|
144
|
-
flowAgents: Schema.Record(Schema.String, Schema.String),
|
|
145
|
-
// The adapters a flow gave its roles in config (flows.<name>.agents), such as { reviewer: codex }.
|
|
146
|
-
flowRoleAgents: Schema.optionalKey(
|
|
147
|
-
Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.String)),
|
|
148
|
-
),
|
|
149
|
-
// The adapters a persona's own role picks run with, in every flow: the
|
|
150
|
-
// agent of the account it chose for the role (roles: { reviewer: codex-work }).
|
|
151
|
-
roleAgents: Schema.optionalKey(Schema.Record(Schema.String, Schema.String)),
|
|
152
|
-
labels: Labels,
|
|
153
|
-
install: Schema.Option(Schema.String),
|
|
154
|
-
localGate: Strings,
|
|
155
|
-
humanOnly: Strings,
|
|
156
|
-
humanOnlyPaths: Strings,
|
|
157
|
-
notes: Strings,
|
|
158
|
-
board: Schema.Option(Board),
|
|
159
|
-
reviewTrigger: Schema.Option(Schema.String),
|
|
160
|
-
limits: Limits,
|
|
161
|
-
// Extra environment for commands run in the repo, such as PATH with its pinned Node.
|
|
162
|
-
env: Schema.Record(Schema.String, Schema.String),
|
|
163
|
-
// The trusted copy of the repo's .chernabog/, read from the base branch.
|
|
164
|
-
configDir: Schema.String,
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
export type RepoSettings = typeof RepoSettings.Type;
|
|
168
|
-
|
|
169
|
-
export class Repo extends Context.Service<Repo, RepoSettings>()("@chernabog/sdk/Repo") {}
|
|
170
|
-
|
|
171
|
-
// One thing a flow works on: an issue, a pull request. `key` identifies it
|
|
172
|
-
// across ticks, so it never has two runs at once. `signals` are events the
|
|
173
|
-
// trigger saw for it this tick, such as "pushed", which wake a waiting run.
|
|
174
|
-
export const WorkItem = Schema.Struct({
|
|
175
|
-
key: Schema.String,
|
|
176
|
-
title: Schema.optionalKey(Schema.String),
|
|
177
|
-
url: Schema.optionalKey(Schema.String),
|
|
178
|
-
data: Schema.Json,
|
|
179
|
-
signals: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
180
|
-
// Only wakes a run already waiting on it; never starts one.
|
|
181
|
-
wakeOnly: Schema.optionalKey(Schema.Boolean),
|
|
182
|
-
// GitHub logins assigned to the item, and asked to review it, which
|
|
183
|
-
// flows.<flow>.assignee and reviewRequested match to choose the machines it starts on.
|
|
184
|
-
assignees: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
185
|
-
reviewers: Schema.optionalKey(Schema.Array(Schema.String)),
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
export type WorkItem = typeof WorkItem.Type;
|
|
189
|
-
|
|
190
|
-
export const RunInfo = Schema.Struct({
|
|
191
|
-
flow: Schema.String,
|
|
192
|
-
runId: Schema.String,
|
|
193
|
-
executionId: Schema.String,
|
|
194
|
-
item: WorkItem,
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
export type RunInfo = typeof RunInfo.Type;
|
|
198
|
-
|
|
199
|
-
export class Run extends Context.Service<Run, RunInfo>()("@chernabog/sdk/Run") {}
|
|
200
|
-
|
|
201
|
-
// The recipe package a run's flow is imported from (config.yaml's
|
|
202
|
-
// flows.<name>.from): its name, version, and the directory it's installed in.
|
|
203
|
-
// Its prompts and steps are looked up there after the repo's own, so a repo can
|
|
204
|
-
// override one of them without copying the flow. A flow copied into the repo,
|
|
205
|
-
// or written there, has none.
|
|
206
|
-
export type FlowPackageInfo = {
|
|
207
|
-
readonly name: string;
|
|
208
|
-
readonly version: string;
|
|
209
|
-
readonly dir: string;
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
export class FlowPackage extends Context.Service<FlowPackage, FlowPackageInfo>()(
|
|
213
|
-
"@chernabog/sdk/FlowPackage",
|
|
214
|
-
) {}
|
|
215
|
-
|
|
216
|
-
export type Issue = {
|
|
217
|
-
readonly number: number;
|
|
218
|
-
readonly title: string;
|
|
219
|
-
readonly body: string;
|
|
220
|
-
readonly url: string;
|
|
221
|
-
readonly createdAt: string;
|
|
222
|
-
readonly labels: ReadonlyArray<string>;
|
|
223
|
-
readonly assignees: ReadonlyArray<string>;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
// An issue as GitHub lists it under another: a sub-issue, or a blocker.
|
|
227
|
-
export type LinkedIssue = Issue & { readonly state: "open" | "closed" };
|
|
228
|
-
|
|
229
|
-
export type NewIssue = {
|
|
230
|
-
readonly title: string;
|
|
231
|
-
readonly body: string;
|
|
232
|
-
readonly labels: ReadonlyArray<string>;
|
|
233
|
-
};
|
|
234
|
-
|
|
235
|
-
export type Comment = {
|
|
236
|
-
readonly id: number;
|
|
237
|
-
readonly author: string;
|
|
238
|
-
readonly body: string;
|
|
239
|
-
readonly createdAt: string;
|
|
240
|
-
readonly trusted: boolean;
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
// A review summary, or a comment on one line of the diff.
|
|
244
|
-
export type ReviewNote = Comment & {
|
|
245
|
-
readonly location: Option.Option<{ readonly path: string; readonly line: number }>;
|
|
246
|
-
};
|
|
247
|
-
|
|
248
|
-
export type PullRequest = {
|
|
249
|
-
readonly number: number;
|
|
250
|
-
readonly title: string;
|
|
251
|
-
readonly body: string;
|
|
252
|
-
readonly url: string;
|
|
253
|
-
readonly state: "open" | "closed" | "merged";
|
|
254
|
-
readonly headRef: string;
|
|
255
|
-
readonly headSha: string;
|
|
256
|
-
readonly baseRef: string;
|
|
257
|
-
readonly labels: ReadonlyArray<string>;
|
|
258
|
-
readonly author: string;
|
|
259
|
-
readonly assignees: ReadonlyArray<string>;
|
|
260
|
-
// Users asked to review it who haven't yet; GitHub drops one once they review.
|
|
261
|
-
readonly requestedReviewers: ReadonlyArray<string>;
|
|
262
|
-
};
|
|
263
|
-
|
|
264
|
-
export type ReviewComment = { readonly path: string; readonly line: number; readonly body: string };
|
|
265
|
-
|
|
266
|
-
export type NewPullRequest = {
|
|
267
|
-
readonly head: string;
|
|
268
|
-
readonly base: string;
|
|
269
|
-
readonly title: string;
|
|
270
|
-
readonly body: string;
|
|
271
|
-
};
|
|
272
|
-
|
|
273
|
-
// A review approves, requests changes, or only comments, which is the default.
|
|
274
|
-
export type ReviewEvent = "APPROVE" | "REQUEST_CHANGES" | "COMMENT";
|
|
275
|
-
|
|
276
|
-
export type NewReview = {
|
|
277
|
-
readonly body: string;
|
|
278
|
-
readonly commitSha: string;
|
|
279
|
-
readonly comments: ReadonlyArray<ReviewComment>;
|
|
280
|
-
readonly event?: ReviewEvent;
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
// A review someone submitted: who, its state as GitHub gives it (APPROVED,
|
|
284
|
-
// CHANGES_REQUESTED, COMMENTED, DISMISSED), and the head it saw.
|
|
285
|
-
export type SubmittedReview = {
|
|
286
|
-
readonly author: string;
|
|
287
|
-
readonly state: string;
|
|
288
|
-
readonly commitSha: string;
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
export type NewCommit = {
|
|
292
|
-
readonly message: string;
|
|
293
|
-
readonly tree: string;
|
|
294
|
-
readonly parents: ReadonlyArray<string>;
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
export type RefCommit = { readonly sha: string; readonly message: string };
|
|
298
|
-
|
|
299
|
-
export type MergeMethod = "merge" | "squash" | "rebase";
|
|
300
|
-
|
|
301
|
-
// The merge of exactly `sha`: GitHub refuses one whose head has moved since.
|
|
302
|
-
export type MergeRequest = { readonly method: MergeMethod; readonly sha: string };
|
|
303
|
-
|
|
304
|
-
// The merge commit.
|
|
305
|
-
export type Merged = { readonly sha: string };
|
|
306
|
-
|
|
307
|
-
export type CiState =
|
|
308
|
-
| { state: "pending"; waitingOn: Array<string> }
|
|
309
|
-
| { state: "green" }
|
|
310
|
-
| { state: "red"; failedChecks: Array<string> };
|
|
311
|
-
|
|
312
|
-
export class GitHub extends Context.Service<
|
|
313
|
-
GitHub,
|
|
314
|
-
{
|
|
315
|
-
// Open issues labelled eligible (and ready on the board, when the repo has one), oldest first.
|
|
316
|
-
readonly queuedIssues: Effect.Effect<ReadonlyArray<Issue>, GitHubError>;
|
|
317
|
-
// Open issues with this label (and ready on the board, when the repo has one), oldest first.
|
|
318
|
-
queuedIssuesLabelled(label: string): Effect.Effect<ReadonlyArray<Issue>, GitHubError>;
|
|
319
|
-
readonly oldestQueued: Effect.Effect<Option.Option<number>, GitHubError>;
|
|
320
|
-
// Open issues with this label, whatever their status on the board, oldest first.
|
|
321
|
-
issuesLabelled(label: string): Effect.Effect<ReadonlyArray<Issue>, GitHubError>;
|
|
322
|
-
issue(number: number): Effect.Effect<Issue, NotFound | GitHubError>;
|
|
323
|
-
createIssue(issue: NewIssue): Effect.Effect<Issue, GitHubError>;
|
|
324
|
-
// An epic's tasks, open and closed, in GitHub's order.
|
|
325
|
-
subIssues(parent: number): Effect.Effect<ReadonlyArray<LinkedIssue>, GitHubError>;
|
|
326
|
-
// Makes `child` a sub-issue of `parent`; one already there stays.
|
|
327
|
-
addSubIssue(parent: number, child: number): Effect.Effect<void, GitHubError>;
|
|
328
|
-
// The issues that must close before this one can start, open and closed.
|
|
329
|
-
blockedBy(issue: number): Effect.Effect<ReadonlyArray<LinkedIssue>, GitHubError>;
|
|
330
|
-
// Records that `blocker` blocks `issue`; a link already there stays.
|
|
331
|
-
addBlockedBy(issue: number, blocker: number): Effect.Effect<void, GitHubError>;
|
|
332
|
-
// Removing a link that isn't there is not an error.
|
|
333
|
-
removeBlockedBy(issue: number, blocker: number): Effect.Effect<void, GitHubError>;
|
|
334
|
-
// Comments by the repo's owners, members and collaborators only; anyone can comment on a public repo.
|
|
335
|
-
trustedComments(number: number): Effect.Effect<ReadonlyArray<Comment>, GitHubError>;
|
|
336
|
-
comments(number: number): Effect.Effect<ReadonlyArray<Comment>, GitHubError>;
|
|
337
|
-
comment(number: number, body: string): Effect.Effect<void, GitHubError>;
|
|
338
|
-
addLabel(number: number, label: string): Effect.Effect<void, GitHubError>;
|
|
339
|
-
removeLabel(number: number, label: string): Effect.Effect<void, GitHubError>;
|
|
340
|
-
// Moves an issue to a Status on the repo's project board. Does nothing without a board.
|
|
341
|
-
moveToStatus(number: number, status: string): Effect.Effect<void, GitHubError>;
|
|
342
|
-
assignSelf(number: number): Effect.Effect<void, GitHubError>;
|
|
343
|
-
readonly login: Effect.Effect<string, GitHubError>;
|
|
344
|
-
branchSha(branch: string): Effect.Effect<Option.Option<string>, GitHubError>;
|
|
345
|
-
// Whoever creates a branch first owns it: the claim.
|
|
346
|
-
createBranch(
|
|
347
|
-
branch: string,
|
|
348
|
-
sha: string,
|
|
349
|
-
): Effect.Effect<"created" | "already-exists", GitHubError>;
|
|
350
|
-
deleteBranch(branch: string): Effect.Effect<void, GitHubError>;
|
|
351
|
-
// A commit made through the API, with no worktree: its sha.
|
|
352
|
-
createCommit(commit: NewCommit): Effect.Effect<string, GitHubError>;
|
|
353
|
-
// Any ref, named in full (`refs/chernabog/claims/issue-12`). Whoever creates one first holds it.
|
|
354
|
-
createRef(ref: string, sha: string): Effect.Effect<"created" | "already-exists", GitHubError>;
|
|
355
|
-
// The commit a ref points at, with its message; none for a ref GitHub doesn't have.
|
|
356
|
-
ref(ref: string): Effect.Effect<Option.Option<RefCommit>, GitHubError>;
|
|
357
|
-
// Deleting a ref GitHub doesn't have is not an error.
|
|
358
|
-
deleteRef(ref: string): Effect.Effect<void, GitHubError>;
|
|
359
|
-
pullRequest(number: number): Effect.Effect<PullRequest, NotFound | GitHubError>;
|
|
360
|
-
pullRequestForBranch(branch: string): Effect.Effect<Option.Option<PullRequest>, GitHubError>;
|
|
361
|
-
pullRequestsLabelled(label: string): Effect.Effect<ReadonlyArray<PullRequest>, GitHubError>;
|
|
362
|
-
readonly openPullRequests: Effect.Effect<ReadonlyArray<PullRequest>, GitHubError>;
|
|
363
|
-
// Asks these logins to review the pull request, or to review it again.
|
|
364
|
-
requestReviewers(
|
|
365
|
-
pullRequest: number,
|
|
366
|
-
logins: ReadonlyArray<string>,
|
|
367
|
-
): Effect.Effect<void, PullRequestClosed | GitHubError>;
|
|
368
|
-
// The reviews submitted on a pull request, oldest first.
|
|
369
|
-
reviews(pullRequest: number): Effect.Effect<ReadonlyArray<SubmittedReview>, GitHubError>;
|
|
370
|
-
openPullRequest(pullRequest: NewPullRequest): Effect.Effect<PullRequest, GitHubError>;
|
|
371
|
-
ciState(pullRequest: number): Effect.Effect<CiState, GitHubError>;
|
|
372
|
-
// Changed paths of a pull request, for path rules such as humanOnlyPaths.
|
|
373
|
-
pullRequestFiles(pullRequest: number): Effect.Effect<ReadonlyArray<string>, GitHubError>;
|
|
374
|
-
// Recently closed or merged pull requests carrying the label, newest first.
|
|
375
|
-
closedPullRequestsLabelled(
|
|
376
|
-
label: string,
|
|
377
|
-
): Effect.Effect<ReadonlyArray<PullRequest>, GitHubError>;
|
|
378
|
-
// Posts a review. GitHub won't let an account approve or request changes on
|
|
379
|
-
// its own pull request; such a review is posted as a comment instead.
|
|
380
|
-
review(
|
|
381
|
-
pullRequest: number,
|
|
382
|
-
review: NewReview,
|
|
383
|
-
): Effect.Effect<void, PullRequestClosed | GitHubError>;
|
|
384
|
-
// Review summaries and line comments on a pull request.
|
|
385
|
-
reviewComments(pullRequest: number): Effect.Effect<ReadonlyArray<ReviewNote>, GitHubError>;
|
|
386
|
-
// Refused by GitHub (branch protection, a conflict, a moved head) with its reason.
|
|
387
|
-
merge(
|
|
388
|
-
pullRequest: number,
|
|
389
|
-
merge: MergeRequest,
|
|
390
|
-
): Effect.Effect<Merged, MergeRefused | PullRequestClosed | GitHubError>;
|
|
391
|
-
// Any other call, for what the service does not cover.
|
|
392
|
-
request(
|
|
393
|
-
method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE",
|
|
394
|
-
path: string,
|
|
395
|
-
body: Option.Option<Json>,
|
|
396
|
-
): Effect.Effect<Json, GitHubError>;
|
|
397
|
-
}
|
|
398
|
-
>()("@chernabog/sdk/GitHub") {}
|
|
399
|
-
|
|
400
|
-
export class Git extends Context.Service<
|
|
401
|
-
Git,
|
|
402
|
-
{
|
|
403
|
-
run(args: ReadonlyArray<string>, cwd: string): Effect.Effect<string, GitError>;
|
|
404
|
-
headSha(cwd: string): Effect.Effect<string, GitError>;
|
|
405
|
-
// Commits on HEAD that origin/<base> does not have.
|
|
406
|
-
commitsAhead(cwd: string, base: string): Effect.Effect<number, GitError>;
|
|
407
|
-
changedFiles(cwd: string, base: string): Effect.Effect<ReadonlyArray<string>, GitError>;
|
|
408
|
-
push(cwd: string, branch: string): Effect.Effect<void, PushRejected | GitError>;
|
|
409
|
-
// Brings the checked-out branch up to its remote, fast-forward only.
|
|
410
|
-
pull(cwd: string, branch: string): Effect.Effect<void, GitError>;
|
|
411
|
-
}
|
|
412
|
-
>()("@chernabog/sdk/Git") {}
|
|
413
|
-
|
|
414
|
-
export class Worktree extends Context.Service<
|
|
415
|
-
Worktree,
|
|
416
|
-
{
|
|
417
|
-
// The worktree for a branch, created from origin/<base> the first time and reused after.
|
|
418
|
-
ensure(branch: string): Effect.Effect<string, GitError>;
|
|
419
|
-
pathFor(branch: string): string;
|
|
420
|
-
remove(branch: string): Effect.Effect<void, GitError>;
|
|
421
|
-
// A detached worktree named `name`, reset to `ref` (fetched first) every call: for reading, such as a review.
|
|
422
|
-
checkout(name: string, ref: string): Effect.Effect<string, GitError>;
|
|
423
|
-
}
|
|
424
|
-
>()("@chernabog/sdk/Worktree") {}
|
|
425
|
-
|
|
426
|
-
export type LaunchDecision = { readonly launch: boolean; readonly reason: string };
|
|
427
|
-
|
|
428
|
-
export class Usage extends Context.Service<
|
|
429
|
-
Usage,
|
|
430
|
-
{
|
|
431
|
-
// Whether the repo's account has room for one more task.
|
|
432
|
-
readonly gate: Effect.Effect<LaunchDecision, UsageError>;
|
|
433
|
-
// The account's logged-in identity; fails when it is not the expected one.
|
|
434
|
-
readonly checkAccount: Effect.Effect<string, UsageError>;
|
|
435
|
-
}
|
|
436
|
-
>()("@chernabog/sdk/Usage") {}
|
|
437
|
-
|
|
438
|
-
export type AgentResult = {
|
|
439
|
-
readonly sessionId: string;
|
|
440
|
-
readonly output: Json;
|
|
441
|
-
readonly costUsd: Option.Option<number>;
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
export type AgentRequest = {
|
|
445
|
-
readonly cwd: string;
|
|
446
|
-
readonly prompt: string;
|
|
447
|
-
// A stable id per piece of work, so a rerun after a crash resumes the same session.
|
|
448
|
-
readonly sessionId: string;
|
|
449
|
-
// Sent instead of `prompt` when the session already exists.
|
|
450
|
-
readonly resumePrompt: Option.Option<string>;
|
|
451
|
-
// JSON Schema the agent's final answer must match.
|
|
452
|
-
readonly outputSchema: Option.Option<Json>;
|
|
453
|
-
// Another adapter than the repo's own, such as a Codex reviewer.
|
|
454
|
-
readonly adapter: Option.Option<string>;
|
|
455
|
-
// A person works in the session with the agent, on the hybrid path: it
|
|
456
|
-
// opens in front of them under the launcher, the agent is never sent back
|
|
457
|
-
// to answer, and it is done once its answer is written. Only Claude under
|
|
458
|
-
// a launcher can.
|
|
459
|
-
readonly withPerson?: boolean;
|
|
460
|
-
// The step that asks, such as `implement` or `fix-ci-2`. The Agent service
|
|
461
|
-
// fills it in from the activity it runs in, when the caller leaves it out.
|
|
462
|
-
readonly step?: string;
|
|
463
|
-
};
|
|
464
|
-
|
|
465
|
-
export class Agent extends Context.Service<
|
|
466
|
-
Agent,
|
|
467
|
-
{
|
|
468
|
-
run(request: AgentRequest): Effect.Effect<AgentResult, AgentError>;
|
|
469
|
-
readonly adapters: ReadonlyArray<string>;
|
|
470
|
-
}
|
|
471
|
-
>()("@chernabog/sdk/Agent") {}
|
|
472
|
-
|
|
473
|
-
// The persona's seat in the team's reviewer pool: a login under github:, not
|
|
474
|
-
// the implicit account, that the repo's reviewers list. Every block that
|
|
475
|
-
// reviews requires it, so a flow that reviews does too. Chernabog checks it
|
|
476
|
-
// when it builds the persona's services; a flow that asks for a seat the
|
|
477
|
-
// persona doesn't hold stops there, before its work, and the engine reports
|
|
478
|
-
// why (NotInReviewerPool, PersonaUnavailable). No flow handles that.
|
|
479
|
-
export class ReviewerSeat extends Context.Service<
|
|
480
|
-
ReviewerSeat,
|
|
481
|
-
{
|
|
482
|
-
// The reviewer's login.
|
|
483
|
-
readonly login: Effect.Effect<string>;
|
|
484
|
-
}
|
|
485
|
-
>()("@chernabog/sdk/ReviewerSeat") {}
|
|
486
|
-
|
|
487
|
-
// What this machine knows of a run, by id: whether it is still going, or none
|
|
488
|
-
// for a run it never had, such as one on another machine. Provided by Chernabog
|
|
489
|
-
// to triggers; a trigger reads it with Effect.serviceOption.
|
|
490
|
-
export class Runs extends Context.Service<
|
|
491
|
-
Runs,
|
|
492
|
-
{
|
|
493
|
-
isActive(runId: string): Effect.Effect<Option.Option<boolean>>;
|
|
494
|
-
}
|
|
495
|
-
>()("@chernabog/sdk/Runs") {}
|
|
496
|
-
|
|
497
|
-
// Writes to the run's log file, which `chernabog logs <run>` prints.
|
|
498
|
-
export class RunLog extends Context.Service<
|
|
499
|
-
RunLog,
|
|
500
|
-
{
|
|
501
|
-
log(line: string): Effect.Effect<void>;
|
|
502
|
-
step(name: string): Effect.Effect<void>;
|
|
503
|
-
stepDone(name: string): Effect.Effect<void>;
|
|
504
|
-
}
|
|
505
|
-
>()("@chernabog/sdk/RunLog") {}
|
package/src/stage.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// A step a team writes as Effect code in .chernabog/stages/<name>.ts. It runs
|
|
2
|
-
// in a child process, gets its input checked against `input` and its output
|
|
3
|
-
// against `output`. A step that crashes partway runs again, so it must be safe
|
|
4
|
-
// to repeat: "claim unless this run already holds it".
|
|
5
|
-
|
|
6
|
-
import type * as Effect from "effect/Effect";
|
|
7
|
-
import type * as Schema from "effect/Schema";
|
|
8
|
-
|
|
9
|
-
import type { Json } from "./json.ts";
|
|
10
|
-
import type { Agent, Git, GitHub, Repo, Run, RunLog, Usage, Worktree } from "./services.ts";
|
|
11
|
-
|
|
12
|
-
export type StageServices = Repo | Run | GitHub | Git | Worktree | Usage | Agent | RunLog;
|
|
13
|
-
|
|
14
|
-
export type Stage<I, O, E> = {
|
|
15
|
-
readonly name: string;
|
|
16
|
-
// Both cross a process boundary as JSON.
|
|
17
|
-
readonly input: Schema.Codec<I, Json>;
|
|
18
|
-
readonly output: Schema.Codec<O, Json>;
|
|
19
|
-
readonly run: (input: I) => Effect.Effect<O, E, StageServices>;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const defineStage = <I, O, E>(stage: Stage<I, O, E>): Stage<I, O, E> => stage;
|
|
23
|
-
|
|
24
|
-
// What a step's process says on exit: 0 to continue, 78 to skip, anything else to fail.
|
|
25
|
-
export const STEP_EXIT = { ok: 0, skip: 78 } as const;
|