@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/src/index.ts CHANGED
@@ -1,18 +1,21 @@
1
- import * as IssueSteps from './issue.ts';
2
- import * as PullRequestSteps from './pull-request.ts';
3
- import type * as Services from './services.ts';
1
+ import * as IssueSteps from "./issue.ts";
2
+ import * as PullRequestSteps from "./pull-request.ts";
3
+ import type * as Services from "./services.ts";
4
4
 
5
- export * from './errors.ts';
6
- export * from './flow.ts';
7
- export * as Implement from './implement.ts';
8
- export * from './json.ts';
9
- export * from './markers.ts';
10
- export * from './paths.ts';
11
- export * from './prompt.ts';
12
- export * as Review from './review.ts';
13
- export * from './roles.ts';
14
- export * from './services.ts';
15
- export * from './stage.ts';
5
+ export * as Claims from "./claims.ts";
6
+ export * from "./errors.ts";
7
+ export * from "./flow.ts";
8
+ export * as Hybrid from "./hybrid.ts";
9
+ export * as Implement from "./implement.ts";
10
+ export * from "./json.ts";
11
+ export * from "./markers.ts";
12
+ export * from "./paths.ts";
13
+ export * as Plan from "./plan.ts";
14
+ export * from "./prompt.ts";
15
+ export * as Review from "./review.ts";
16
+ export * from "./roles.ts";
17
+ export * from "./services.ts";
18
+ export * from "./stage.ts";
16
19
 
17
20
  // PullRequest and Issue are each both a type and the steps on one.
18
21
  export const PullRequest = PullRequestSteps;
package/src/issue.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  // Steps on an issue that any flow can use.
2
2
 
3
- import { commentStep } from './comment.ts';
3
+ import { commentStep } from "./comment.ts";
4
4
 
5
5
  // Comments on the issue, and does nothing else.
6
- export const comment = (issue: number, body: string) => commentStep('issue', issue, body);
6
+ export const comment = (issue: number, body: string) => commentStep("issue", issue, body);
package/src/json.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  // JSON at the edges: every parse and print goes through a Schema codec, so a
2
2
  // value is checked the moment it crosses the boundary.
3
3
 
4
- import * as Option from 'effect/Option';
5
- import * as Schema from 'effect/Schema';
4
+ import * as Option from "effect/Option";
5
+ import * as Schema from "effect/Schema";
6
6
 
7
7
  export type Json = Schema.Json;
8
8
 
@@ -14,5 +14,8 @@ export const parseJson = (text: string): Option.Option<Json> => Schema.decodeOpt
14
14
  export const printJson = (value: Json): string => Schema.encodeSync(JsonText)(value);
15
15
 
16
16
  // Each line of a JSON Lines file that the schema accepts; the others are skipped.
17
- export const decodeJsonLines = <A>(schema: Schema.Codec<A, string>, text: string): ReadonlyArray<A> =>
18
- text.split('\n').flatMap((line) => Option.toArray(Schema.decodeOption(schema)(line)));
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 CHANGED
@@ -1,17 +1,36 @@
1
1
  // Hidden markers in pull request comments, so a later run can find what an
2
2
  // earlier one left: who wrote the pull request, and what each review saw.
3
3
 
4
- import * as Arr from 'effect/Array';
5
- import * as Option from 'effect/Option';
6
- import * as Schema from 'effect/Schema';
4
+ import * as Arr from "effect/Array";
5
+ import * as Option from "effect/Option";
6
+ import * as Schema from "effect/Schema";
7
7
 
8
- import type { Json } from './json.ts';
8
+ import type { Json } from "./json.ts";
9
9
 
10
- export const SessionMarker = Schema.Struct({ adapter: Schema.String, sessionId: Schema.String, issue: Schema.Finite, branch: Schema.String });
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
+ });
11
20
 
12
21
  export type SessionMarker = typeof SessionMarker.Type;
13
22
 
14
- export const ReviewMarker = Schema.Struct({ sha: Schema.String, round: Schema.Finite, verdict: Schema.Literals(['approve', 'request-changes']) });
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
+ });
15
34
 
16
35
  export type ReviewMarker = typeof ReviewMarker.Type;
17
36
 
@@ -22,25 +41,63 @@ const marker = <A>(name: string, schema: Schema.Codec<A, Json>) => {
22
41
  return {
23
42
  write: (value: A) => `<!-- chernabog-${name} ${Schema.encodeSync(codec)(value)} -->`,
24
43
  read: (body: string): Option.Option<A> =>
25
- Option.fromNullishOr(body.match(pattern)).pipe(Option.flatMap((match) => Schema.decodeOption(codec)(match[1]))),
44
+ Option.fromNullishOr(body.match(pattern)).pipe(
45
+ Option.flatMap((match) => Schema.decodeOption(codec)(match[1])),
46
+ ),
26
47
  };
27
48
  };
28
49
 
29
- export const ClaimMarker = Schema.Struct({ runId: Schema.String, claimedAt: Schema.String, branch: Schema.String });
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
+ });
30
61
 
31
62
  export type ClaimMarker = typeof ClaimMarker.Type;
32
63
 
33
64
  // A run that owns a pull request, or let it go: the standalone review and fix
34
- // flows leave a pull request alone while a run of another flow owns it.
35
- export const OwnerMarker = Schema.Struct({ flow: Schema.String, runId: Schema.String, released: Schema.Boolean });
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
+ });
36
74
 
37
75
  export type OwnerMarker = typeof OwnerMarker.Type;
38
76
 
39
- export const claimMarker = marker('claim', ClaimMarker);
40
- export const sessionMarker = marker('session', SessionMarker);
41
- export const reviewMarker = marker('review', ReviewMarker);
42
- export const ownerMarker = marker('owner', OwnerMarker);
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);
43
98
 
44
99
  // The newest marker among comment bodies, oldest first.
45
- export const latestMarker = <A>(read: (body: string) => Option.Option<A>, bodies: ReadonlyArray<string>): Option.Option<A> =>
46
- Arr.last(bodies.flatMap((body) => Option.toArray(read(body))));
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 CHANGED
@@ -1,32 +1,40 @@
1
1
  // Path rules such as humanOnlyPaths: `.github/**`, `**/package.json`, `RELEASE.md`.
2
2
 
3
- const escape = (text: string) => text.replace(/[.+^${}()|[\]\\]/g, '\\$&');
3
+ const escape = (text: string) => text.replace(/[.+^${}()|[\]\\]/g, "\\$&");
4
4
 
5
5
  const doubleStar = (glob: string, index: number) => {
6
- if (glob[index + 2] === '/') return { pattern: '(?:.*/)?', skip: 2 };
6
+ if (glob[index + 2] === "/") {
7
+ return { pattern: "(?:.*/)?", skip: 2 };
8
+ }
7
9
 
8
- return { pattern: '.*', skip: 1 };
10
+ return { pattern: ".*", skip: 1 };
9
11
  };
10
12
 
11
13
  export const globToRegExp = (glob: string) => {
12
- let pattern = '';
14
+ let pattern = "";
13
15
 
14
16
  for (let index = 0; index < glob.length; index++) {
15
17
  const char = glob[index];
16
18
 
17
- if (char === '*' && glob[index + 1] === '*') {
19
+ if (char === "*" && glob[index + 1] === "*") {
18
20
  const star = doubleStar(glob, index);
19
21
  pattern += star.pattern;
20
22
  index += star.skip;
21
- } else if (char === '*') pattern += '[^/]*';
22
- else if (char === '?') pattern += '[^/]';
23
- else pattern += escape(char);
23
+ } else if (char === "*") {
24
+ pattern += "[^/]*";
25
+ } else if (char === "?") {
26
+ pattern += "[^/]";
27
+ } else {
28
+ pattern += escape(char);
29
+ }
24
30
  }
25
31
 
26
32
  // A directory rule covers everything under it.
27
- let rest = '(?:/.*)?';
33
+ let rest = "(?:/.*)?";
28
34
 
29
- if (glob.endsWith('/')) rest = '.*';
35
+ if (glob.endsWith("/")) {
36
+ rest = ".*";
37
+ }
30
38
 
31
39
  return new RegExp(`^${pattern}${rest}$`);
32
40
  };