@chernabog/sdk 0.4.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -29
- package/package.json +1 -1
- package/src/claims.ts +169 -0
- package/src/comment.ts +6 -6
- package/src/default-prompts.ts +52 -0
- package/src/errors.ts +209 -20
- package/src/flow.ts +227 -62
- package/src/hybrid.ts +308 -0
- package/src/implement.ts +477 -191
- package/src/index.ts +17 -14
- package/src/issue.ts +2 -2
- package/src/json.ts +7 -4
- package/src/markers.ts +73 -16
- package/src/paths.ts +18 -10
- package/src/plan.ts +762 -0
- package/src/prompt.ts +76 -24
- package/src/pull-request.ts +254 -55
- package/src/review.ts +406 -301
- package/src/roles.ts +15 -8
- package/src/services.ts +239 -51
- package/src/stage.ts +4 -4
package/src/roles.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
// Which adapter a step runs its agent with. A
|
|
2
|
-
//
|
|
3
|
-
//
|
|
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.
|
|
4
6
|
|
|
5
|
-
import * as Effect from
|
|
6
|
-
import * as Option from
|
|
7
|
-
import * as Record from
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as Option from "effect/Option";
|
|
9
|
+
import * as Record from "effect/Record";
|
|
8
10
|
|
|
9
|
-
import { Repo, Run } from
|
|
11
|
+
import { Repo, Run } from "./services.ts";
|
|
10
12
|
|
|
11
13
|
// What a step that runs an agent can be told: the role it plays in the flow.
|
|
12
14
|
export type RoleOptions = { readonly role?: string };
|
|
@@ -17,7 +19,12 @@ export const adapterFor = (role: Option.Option<string>) =>
|
|
|
17
19
|
const repo = yield* Repo;
|
|
18
20
|
const run = yield* Run;
|
|
19
21
|
const roles = Record.get(repo.flowRoleAgents ?? {}, run.flow);
|
|
20
|
-
|
|
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
|
+
);
|
|
21
28
|
|
|
22
29
|
return Option.orElse(forRole, () => Record.get(repo.flowAgents, run.flow));
|
|
23
30
|
});
|
package/src/services.ts
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
// The services a flow, trigger or step can use. Chernabog provides each one;
|
|
2
2
|
// a team can replace any of them with its own layer, and tests can use fakes.
|
|
3
3
|
|
|
4
|
-
import * as Context from
|
|
5
|
-
import type * as Effect from
|
|
6
|
-
import * as Option from
|
|
7
|
-
import * as Schema from
|
|
8
|
-
|
|
9
|
-
import type {
|
|
10
|
-
|
|
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";
|
|
11
20
|
|
|
12
21
|
export const Labels = Schema.Struct({
|
|
13
22
|
eligible: Schema.String,
|
|
@@ -18,22 +27,32 @@ export const Labels = Schema.Struct({
|
|
|
18
27
|
needsHuman: Schema.String,
|
|
19
28
|
needsClarification: Schema.String,
|
|
20
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,
|
|
21
34
|
});
|
|
22
35
|
|
|
23
36
|
export type Labels = typeof Labels.Type;
|
|
24
37
|
|
|
25
38
|
export const DEFAULT_LABELS: Labels = {
|
|
26
|
-
eligible:
|
|
27
|
-
inProgress:
|
|
28
|
-
needsReview:
|
|
29
|
-
changesRequested:
|
|
30
|
-
approved:
|
|
31
|
-
needsHuman:
|
|
32
|
-
needsClarification:
|
|
33
|
-
stale:
|
|
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",
|
|
34
49
|
};
|
|
35
50
|
|
|
36
|
-
export const Board = Schema.Struct({
|
|
51
|
+
export const Board = Schema.Struct({
|
|
52
|
+
projectNumber: Schema.Finite,
|
|
53
|
+
readyStatus: Schema.String,
|
|
54
|
+
inProgressStatus: Schema.String,
|
|
55
|
+
});
|
|
37
56
|
|
|
38
57
|
export type Board = typeof Board.Type;
|
|
39
58
|
|
|
@@ -41,7 +60,7 @@ export type Board = typeof Board.Type;
|
|
|
41
60
|
// oauthTokenEnv names the environment variable holding a Claude login token
|
|
42
61
|
// (from `claude setup-token`), for a host with no login of its own, such as CI.
|
|
43
62
|
// usageGate none launches without reading usage, which such a token cannot.
|
|
44
|
-
export const UsageGateMode = Schema.Literals([
|
|
63
|
+
export const UsageGateMode = Schema.Literals(["usage", "none"]);
|
|
45
64
|
|
|
46
65
|
export type UsageGateMode = typeof UsageGateMode.Type;
|
|
47
66
|
|
|
@@ -66,6 +85,10 @@ export const Limits = Schema.Struct({
|
|
|
66
85
|
staleAfter: Schema.Duration,
|
|
67
86
|
// How long CI may stay pending before a person looks.
|
|
68
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,
|
|
69
92
|
});
|
|
70
93
|
|
|
71
94
|
export type Limits = typeof Limits.Type;
|
|
@@ -74,25 +97,44 @@ const Strings = Schema.Array(Schema.String);
|
|
|
74
97
|
|
|
75
98
|
// A launcher of your own, from machine config: command templates with
|
|
76
99
|
// {command}, {cwd}, {title} and {handle}.
|
|
77
|
-
export const LauncherCommands = Schema.Struct({
|
|
100
|
+
export const LauncherCommands = Schema.Struct({
|
|
101
|
+
start: Strings,
|
|
102
|
+
close: Strings,
|
|
103
|
+
alive: Schema.Option(Strings),
|
|
104
|
+
attach: Schema.Option(Strings),
|
|
105
|
+
});
|
|
78
106
|
|
|
79
107
|
export type LauncherCommands = typeof LauncherCommands.Type;
|
|
80
108
|
|
|
81
109
|
// Where interactive agent sessions run (orca, tmux, a custom one, or headless
|
|
82
110
|
// for none), which config layer chose it, and a custom launcher's commands.
|
|
83
|
-
export const ResolvedLauncher = Schema.Struct({
|
|
111
|
+
export const ResolvedLauncher = Schema.Struct({
|
|
112
|
+
name: Schema.String,
|
|
113
|
+
from: Schema.String,
|
|
114
|
+
custom: Schema.Option(LauncherCommands),
|
|
115
|
+
});
|
|
84
116
|
|
|
85
117
|
export type ResolvedLauncher = typeof ResolvedLauncher.Type;
|
|
86
118
|
|
|
87
|
-
export const HEADLESS: ResolvedLauncher = {
|
|
119
|
+
export const HEADLESS: ResolvedLauncher = {
|
|
120
|
+
name: "headless",
|
|
121
|
+
from: "default",
|
|
122
|
+
custom: Option.none(),
|
|
123
|
+
};
|
|
88
124
|
|
|
89
125
|
// Everything a run knows about the repo it works on, merged from the repo's
|
|
90
|
-
// committed config
|
|
126
|
+
// committed config and the persona's settings in machine config.
|
|
91
127
|
export const RepoSettings = Schema.Struct({
|
|
92
128
|
name: Schema.String,
|
|
93
129
|
slug: Schema.String,
|
|
94
130
|
path: Schema.String,
|
|
95
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),
|
|
96
138
|
account: Account,
|
|
97
139
|
// The adapter that implements, and the account each adapter runs under.
|
|
98
140
|
agent: Schema.String,
|
|
@@ -101,7 +143,12 @@ export const RepoSettings = Schema.Struct({
|
|
|
101
143
|
// The adapter a flow asked for in config (flows.<name>.agent), such as a Codex reviewer.
|
|
102
144
|
flowAgents: Schema.Record(Schema.String, Schema.String),
|
|
103
145
|
// The adapters a flow gave its roles in config (flows.<name>.agents), such as { reviewer: codex }.
|
|
104
|
-
flowRoleAgents: Schema.optionalKey(
|
|
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)),
|
|
105
152
|
labels: Labels,
|
|
106
153
|
install: Schema.Option(Schema.String),
|
|
107
154
|
localGate: Strings,
|
|
@@ -119,7 +166,7 @@ export const RepoSettings = Schema.Struct({
|
|
|
119
166
|
|
|
120
167
|
export type RepoSettings = typeof RepoSettings.Type;
|
|
121
168
|
|
|
122
|
-
export class Repo extends Context.Service<Repo, RepoSettings>()(
|
|
169
|
+
export class Repo extends Context.Service<Repo, RepoSettings>()("@chernabog/sdk/Repo") {}
|
|
123
170
|
|
|
124
171
|
// One thing a flow works on: an issue, a pull request. `key` identifies it
|
|
125
172
|
// across ticks, so it never has two runs at once. `signals` are events the
|
|
@@ -140,11 +187,31 @@ export const WorkItem = Schema.Struct({
|
|
|
140
187
|
|
|
141
188
|
export type WorkItem = typeof WorkItem.Type;
|
|
142
189
|
|
|
143
|
-
export const RunInfo = Schema.Struct({
|
|
190
|
+
export const RunInfo = Schema.Struct({
|
|
191
|
+
flow: Schema.String,
|
|
192
|
+
runId: Schema.String,
|
|
193
|
+
executionId: Schema.String,
|
|
194
|
+
item: WorkItem,
|
|
195
|
+
});
|
|
144
196
|
|
|
145
197
|
export type RunInfo = typeof RunInfo.Type;
|
|
146
198
|
|
|
147
|
-
export class Run extends Context.Service<Run, RunInfo>()(
|
|
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
|
+
) {}
|
|
148
215
|
|
|
149
216
|
export type Issue = {
|
|
150
217
|
readonly number: number;
|
|
@@ -156,17 +223,34 @@ export type Issue = {
|
|
|
156
223
|
readonly assignees: ReadonlyArray<string>;
|
|
157
224
|
};
|
|
158
225
|
|
|
159
|
-
|
|
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
|
+
};
|
|
160
242
|
|
|
161
243
|
// A review summary, or a comment on one line of the diff.
|
|
162
|
-
export type ReviewNote = Comment & {
|
|
244
|
+
export type ReviewNote = Comment & {
|
|
245
|
+
readonly location: Option.Option<{ readonly path: string; readonly line: number }>;
|
|
246
|
+
};
|
|
163
247
|
|
|
164
248
|
export type PullRequest = {
|
|
165
249
|
readonly number: number;
|
|
166
250
|
readonly title: string;
|
|
167
251
|
readonly body: string;
|
|
168
252
|
readonly url: string;
|
|
169
|
-
readonly state:
|
|
253
|
+
readonly state: "open" | "closed" | "merged";
|
|
170
254
|
readonly headRef: string;
|
|
171
255
|
readonly headSha: string;
|
|
172
256
|
readonly baseRef: string;
|
|
@@ -179,19 +263,51 @@ export type PullRequest = {
|
|
|
179
263
|
|
|
180
264
|
export type ReviewComment = { readonly path: string; readonly line: number; readonly body: string };
|
|
181
265
|
|
|
182
|
-
export type NewPullRequest = {
|
|
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
|
+
};
|
|
183
296
|
|
|
184
|
-
export type
|
|
297
|
+
export type RefCommit = { readonly sha: string; readonly message: string };
|
|
185
298
|
|
|
186
|
-
export type MergeMethod =
|
|
299
|
+
export type MergeMethod = "merge" | "squash" | "rebase";
|
|
187
300
|
|
|
188
301
|
// The merge of exactly `sha`: GitHub refuses one whose head has moved since.
|
|
189
302
|
export type MergeRequest = { readonly method: MergeMethod; readonly sha: string };
|
|
190
303
|
|
|
191
|
-
//
|
|
192
|
-
export type
|
|
304
|
+
// The merge commit.
|
|
305
|
+
export type Merged = { readonly sha: string };
|
|
193
306
|
|
|
194
|
-
export type CiState =
|
|
307
|
+
export type CiState =
|
|
308
|
+
| { state: "pending"; waitingOn: Array<string> }
|
|
309
|
+
| { state: "green" }
|
|
310
|
+
| { state: "red"; failedChecks: Array<string> };
|
|
195
311
|
|
|
196
312
|
export class GitHub extends Context.Service<
|
|
197
313
|
GitHub,
|
|
@@ -201,7 +317,20 @@ export class GitHub extends Context.Service<
|
|
|
201
317
|
// Open issues with this label (and ready on the board, when the repo has one), oldest first.
|
|
202
318
|
queuedIssuesLabelled(label: string): Effect.Effect<ReadonlyArray<Issue>, GitHubError>;
|
|
203
319
|
readonly oldestQueued: Effect.Effect<Option.Option<number>, GitHubError>;
|
|
204
|
-
|
|
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>;
|
|
205
334
|
// Comments by the repo's owners, members and collaborators only; anyone can comment on a public repo.
|
|
206
335
|
trustedComments(number: number): Effect.Effect<ReadonlyArray<Comment>, GitHubError>;
|
|
207
336
|
comments(number: number): Effect.Effect<ReadonlyArray<Comment>, GitHubError>;
|
|
@@ -214,26 +343,59 @@ export class GitHub extends Context.Service<
|
|
|
214
343
|
readonly login: Effect.Effect<string, GitHubError>;
|
|
215
344
|
branchSha(branch: string): Effect.Effect<Option.Option<string>, GitHubError>;
|
|
216
345
|
// Whoever creates a branch first owns it: the claim.
|
|
217
|
-
createBranch(
|
|
346
|
+
createBranch(
|
|
347
|
+
branch: string,
|
|
348
|
+
sha: string,
|
|
349
|
+
): Effect.Effect<"created" | "already-exists", GitHubError>;
|
|
218
350
|
deleteBranch(branch: string): Effect.Effect<void, GitHubError>;
|
|
219
|
-
|
|
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>;
|
|
220
360
|
pullRequestForBranch(branch: string): Effect.Effect<Option.Option<PullRequest>, GitHubError>;
|
|
221
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>;
|
|
222
370
|
openPullRequest(pullRequest: NewPullRequest): Effect.Effect<PullRequest, GitHubError>;
|
|
223
371
|
ciState(pullRequest: number): Effect.Effect<CiState, GitHubError>;
|
|
224
372
|
// Changed paths of a pull request, for path rules such as humanOnlyPaths.
|
|
225
373
|
pullRequestFiles(pullRequest: number): Effect.Effect<ReadonlyArray<string>, GitHubError>;
|
|
226
374
|
// Recently closed or merged pull requests carrying the label, newest first.
|
|
227
|
-
closedPullRequestsLabelled(
|
|
228
|
-
|
|
229
|
-
|
|
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>;
|
|
230
384
|
// Review summaries and line comments on a pull request.
|
|
231
385
|
reviewComments(pullRequest: number): Effect.Effect<ReadonlyArray<ReviewNote>, GitHubError>;
|
|
232
|
-
|
|
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>;
|
|
233
391
|
// Any other call, for what the service does not cover.
|
|
234
|
-
request(
|
|
392
|
+
request(
|
|
393
|
+
method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE",
|
|
394
|
+
path: string,
|
|
395
|
+
body: Option.Option<Json>,
|
|
396
|
+
): Effect.Effect<Json, GitHubError>;
|
|
235
397
|
}
|
|
236
|
-
>()(
|
|
398
|
+
>()("@chernabog/sdk/GitHub") {}
|
|
237
399
|
|
|
238
400
|
export class Git extends Context.Service<
|
|
239
401
|
Git,
|
|
@@ -243,11 +405,11 @@ export class Git extends Context.Service<
|
|
|
243
405
|
// Commits on HEAD that origin/<base> does not have.
|
|
244
406
|
commitsAhead(cwd: string, base: string): Effect.Effect<number, GitError>;
|
|
245
407
|
changedFiles(cwd: string, base: string): Effect.Effect<ReadonlyArray<string>, GitError>;
|
|
246
|
-
push(cwd: string, branch: string): Effect.Effect<void, GitError>;
|
|
408
|
+
push(cwd: string, branch: string): Effect.Effect<void, PushRejected | GitError>;
|
|
247
409
|
// Brings the checked-out branch up to its remote, fast-forward only.
|
|
248
410
|
pull(cwd: string, branch: string): Effect.Effect<void, GitError>;
|
|
249
411
|
}
|
|
250
|
-
>()(
|
|
412
|
+
>()("@chernabog/sdk/Git") {}
|
|
251
413
|
|
|
252
414
|
export class Worktree extends Context.Service<
|
|
253
415
|
Worktree,
|
|
@@ -259,7 +421,7 @@ export class Worktree extends Context.Service<
|
|
|
259
421
|
// A detached worktree named `name`, reset to `ref` (fetched first) every call: for reading, such as a review.
|
|
260
422
|
checkout(name: string, ref: string): Effect.Effect<string, GitError>;
|
|
261
423
|
}
|
|
262
|
-
>()(
|
|
424
|
+
>()("@chernabog/sdk/Worktree") {}
|
|
263
425
|
|
|
264
426
|
export type LaunchDecision = { readonly launch: boolean; readonly reason: string };
|
|
265
427
|
|
|
@@ -271,9 +433,13 @@ export class Usage extends Context.Service<
|
|
|
271
433
|
// The account's logged-in identity; fails when it is not the expected one.
|
|
272
434
|
readonly checkAccount: Effect.Effect<string, UsageError>;
|
|
273
435
|
}
|
|
274
|
-
>()(
|
|
436
|
+
>()("@chernabog/sdk/Usage") {}
|
|
275
437
|
|
|
276
|
-
export type AgentResult = {
|
|
438
|
+
export type AgentResult = {
|
|
439
|
+
readonly sessionId: string;
|
|
440
|
+
readonly output: Json;
|
|
441
|
+
readonly costUsd: Option.Option<number>;
|
|
442
|
+
};
|
|
277
443
|
|
|
278
444
|
export type AgentRequest = {
|
|
279
445
|
readonly cwd: string;
|
|
@@ -286,6 +452,14 @@ export type AgentRequest = {
|
|
|
286
452
|
readonly outputSchema: Option.Option<Json>;
|
|
287
453
|
// Another adapter than the repo's own, such as a Codex reviewer.
|
|
288
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;
|
|
289
463
|
};
|
|
290
464
|
|
|
291
465
|
export class Agent extends Context.Service<
|
|
@@ -294,7 +468,21 @@ export class Agent extends Context.Service<
|
|
|
294
468
|
run(request: AgentRequest): Effect.Effect<AgentResult, AgentError>;
|
|
295
469
|
readonly adapters: ReadonlyArray<string>;
|
|
296
470
|
}
|
|
297
|
-
>()(
|
|
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") {}
|
|
298
486
|
|
|
299
487
|
// What this machine knows of a run, by id: whether it is still going, or none
|
|
300
488
|
// for a run it never had, such as one on another machine. Provided by Chernabog
|
|
@@ -304,7 +492,7 @@ export class Runs extends Context.Service<
|
|
|
304
492
|
{
|
|
305
493
|
isActive(runId: string): Effect.Effect<Option.Option<boolean>>;
|
|
306
494
|
}
|
|
307
|
-
>()(
|
|
495
|
+
>()("@chernabog/sdk/Runs") {}
|
|
308
496
|
|
|
309
497
|
// Writes to the run's log file, which `chernabog logs <run>` prints.
|
|
310
498
|
export class RunLog extends Context.Service<
|
|
@@ -314,4 +502,4 @@ export class RunLog extends Context.Service<
|
|
|
314
502
|
step(name: string): Effect.Effect<void>;
|
|
315
503
|
stepDone(name: string): Effect.Effect<void>;
|
|
316
504
|
}
|
|
317
|
-
>()(
|
|
505
|
+
>()("@chernabog/sdk/RunLog") {}
|
package/src/stage.ts
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
// against `output`. A step that crashes partway runs again, so it must be safe
|
|
4
4
|
// to repeat: "claim unless this run already holds it".
|
|
5
5
|
|
|
6
|
-
import type * as Effect from
|
|
7
|
-
import type * as Schema from
|
|
6
|
+
import type * as Effect from "effect/Effect";
|
|
7
|
+
import type * as Schema from "effect/Schema";
|
|
8
8
|
|
|
9
|
-
import type { Json } from
|
|
10
|
-
import type { Agent, Git, GitHub, Repo, Run, RunLog, Usage, Worktree } from
|
|
9
|
+
import type { Json } from "./json.ts";
|
|
10
|
+
import type { Agent, Git, GitHub, Repo, Run, RunLog, Usage, Worktree } from "./services.ts";
|
|
11
11
|
|
|
12
12
|
export type StageServices = Repo | Run | GitHub | Git | Worktree | Usage | Agent | RunLog;
|
|
13
13
|
|