@milkenjoyer/toolchain 0.14.1 → 0.16.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 +17 -17
- package/STARTS.md +11 -0
- package/dist/effect-plugin-BsrW5_nI.mjs +79 -0
- package/dist/effect-plugin.d.mts +2 -3966
- package/dist/effect-plugin.mjs +1 -1
- package/dist/fmt-BaECz64m.mjs +8 -0
- package/dist/fmt.mjs +1 -8
- package/dist/formal.mjs +1 -1
- package/dist/guard-Doqk4Fju.mjs +143 -0
- package/dist/guard.mjs +1 -96
- package/dist/{lint-IhmtnBbx.mjs → lint-CfztB4u8.mjs} +1 -1
- package/dist/lint.mjs +1 -1
- package/dist/standard.mjs +557 -4
- package/dist/starts.d.mts +100 -0
- package/dist/starts.mjs +385 -0
- package/package.json +11 -9
- package/src/arithmetic.ts +60 -0
- package/src/compatible.ts +512 -0
- package/src/conformance.ts +56 -0
- package/src/effect-plugin.ts +24 -0
- package/src/effect-tsgo.ts +44 -0
- package/src/exceptions.ts +17 -0
- package/src/fmt.ts +13 -0
- package/src/foldkit-plugin.ts +51 -0
- package/src/guard.ts +307 -0
- package/src/hooks.ts +205 -0
- package/src/index.ts +1 -0
- package/src/knip.ts +25 -0
- package/src/lint.ts +170 -0
- package/src/plugin.ts +21 -0
- package/src/rules/no-comments.ts +36 -0
- package/src/rules/no-process-env.ts +68 -0
- package/src/rules/prefer-accessible-scene-locators.ts +227 -0
- package/src/rules/require-command-answer-names.ts +144 -0
- package/src/rules/require-past-tense-messages.ts +201 -0
- package/src/rules/use-temp-file-scoped.ts +132 -0
- package/src/rules.ts +121 -0
- package/src/shared/foldkit-api.ts +51 -0
- package/src/shared/member-path.ts +106 -0
- package/src/shared/syntax.ts +47 -0
- package/src/standard/alchemy.ts +70 -0
- package/src/standard/checks.ts +10 -1
- package/src/standard/config.ts +84 -0
- package/src/standard/domain-rules.ts +204 -0
- package/src/standard/domain.ts +296 -0
- package/src/standard/infra.ts +486 -0
- package/src/starts/boat.ts +140 -0
- package/src/starts/budget.ts +151 -0
- package/src/starts/policy.ts +171 -0
- package/src/starts.ts +84 -0
- package/src/versions.ts +221 -0
- package/dist/effect-plugin-BXUx9PPu.mjs +0 -3561
- package/dist/manifest-xQwgnYI1.mjs +0 -53
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Context from "effect/Context";
|
|
5
|
+
import * as Redacted from "effect/Redacted";
|
|
6
|
+
export declare const Repo: Schema.brand<Schema.String, "Repo">;
|
|
7
|
+
export type Repo = typeof Repo.Type;
|
|
8
|
+
type Window = "minute" | "hour" | "day";
|
|
9
|
+
type PerWindow<A> = { readonly [W in Window]: A; };
|
|
10
|
+
type Share = {
|
|
11
|
+
readonly repo: Repo;
|
|
12
|
+
readonly share: number;
|
|
13
|
+
};
|
|
14
|
+
type Plan = {
|
|
15
|
+
readonly limits: PerWindow<number>;
|
|
16
|
+
readonly used: PerWindow<number>;
|
|
17
|
+
readonly nextStartDollars: number | undefined;
|
|
18
|
+
};
|
|
19
|
+
type RepoStarts = {
|
|
20
|
+
readonly repo: Repo;
|
|
21
|
+
readonly starts: ReadonlyArray<number>;
|
|
22
|
+
readonly complete: boolean;
|
|
23
|
+
};
|
|
24
|
+
type Counts = {
|
|
25
|
+
readonly now: number;
|
|
26
|
+
readonly plan: Plan;
|
|
27
|
+
readonly repo: RepoStarts;
|
|
28
|
+
};
|
|
29
|
+
type StartRequest = {
|
|
30
|
+
readonly repo: Repo;
|
|
31
|
+
readonly jobs: number;
|
|
32
|
+
};
|
|
33
|
+
declare const Line: Schema.Union<readonly [Schema.TaggedStruct<"Unread", {
|
|
34
|
+
readonly reason: Schema.String;
|
|
35
|
+
}>, Schema.TaggedStruct<"Paid", {
|
|
36
|
+
readonly nextStartDollars: Schema.UndefinedOr<Schema.Number>;
|
|
37
|
+
}>, Schema.TaggedStruct<"Account", {
|
|
38
|
+
readonly window: Schema.Literals<readonly ["minute", "hour", "day"]>;
|
|
39
|
+
readonly used: Schema.Number;
|
|
40
|
+
readonly line: Schema.Number;
|
|
41
|
+
}>, Schema.TaggedStruct<"Budget", {
|
|
42
|
+
readonly repo: Schema.brand<Schema.String, "Repo">;
|
|
43
|
+
readonly window: Schema.Literals<readonly ["minute", "hour", "day"]>;
|
|
44
|
+
readonly used: Schema.Number;
|
|
45
|
+
readonly budget: Schema.Number;
|
|
46
|
+
}>]>;
|
|
47
|
+
type Line = typeof Line.Type;
|
|
48
|
+
type Admission = {
|
|
49
|
+
readonly _tag: "Admit";
|
|
50
|
+
} | {
|
|
51
|
+
readonly _tag: "Wait";
|
|
52
|
+
readonly until: number;
|
|
53
|
+
readonly line: Line;
|
|
54
|
+
} | {
|
|
55
|
+
readonly _tag: "Hold";
|
|
56
|
+
readonly line: Line;
|
|
57
|
+
};
|
|
58
|
+
export declare const startShares: ReadonlyArray<Share>;
|
|
59
|
+
export declare const decide: (request: StartRequest, counts: Counts | undefined, now: number) => Admission;
|
|
60
|
+
declare const StartReadError_base: Schema.Class<StartReadError, Schema.TaggedStruct<"StartReadError", {
|
|
61
|
+
readonly reason: Schema.String;
|
|
62
|
+
}>, import("effect/Cause").YieldableError & {
|
|
63
|
+
readonly brand: unique symbol;
|
|
64
|
+
}>;
|
|
65
|
+
export declare class StartReadError extends StartReadError_base {}
|
|
66
|
+
declare const BoatStarts_base: Context.ServiceClass<BoatStarts, "toolchain/BoatStarts", {
|
|
67
|
+
readonly plan: Effect.Effect<Plan, StartReadError>;
|
|
68
|
+
readonly repoStarts: (repo: Repo) => Effect.Effect<RepoStarts, StartReadError>;
|
|
69
|
+
}>;
|
|
70
|
+
export declare class BoatStarts extends BoatStarts_base {
|
|
71
|
+
static readonly layer: (key: Redacted.Redacted<string>, options?: {
|
|
72
|
+
readonly fetch?: (url: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
73
|
+
}) => Layer.Layer<BoatStarts, never, never>;
|
|
74
|
+
}
|
|
75
|
+
export declare const BOAT_JOBS_PER_RUN = 2;
|
|
76
|
+
type WorkflowFile = readonly [path: string, text: string];
|
|
77
|
+
export declare const boatJobFindings: (files: ReadonlyArray<WorkflowFile>) => ReadonlyArray<string>;
|
|
78
|
+
declare const StartHeld_base: Schema.Class<StartHeld, Schema.TaggedStruct<"StartHeld", {
|
|
79
|
+
readonly line: Schema.Union<readonly [Schema.TaggedStruct<"Unread", {
|
|
80
|
+
readonly reason: Schema.String;
|
|
81
|
+
}>, Schema.TaggedStruct<"Paid", {
|
|
82
|
+
readonly nextStartDollars: Schema.UndefinedOr<Schema.Number>;
|
|
83
|
+
}>, Schema.TaggedStruct<"Account", {
|
|
84
|
+
readonly window: Schema.Literals<readonly ["minute", "hour", "day"]>;
|
|
85
|
+
readonly used: Schema.Number;
|
|
86
|
+
readonly line: Schema.Number;
|
|
87
|
+
}>, Schema.TaggedStruct<"Budget", {
|
|
88
|
+
readonly repo: Schema.brand<Schema.String, "Repo">;
|
|
89
|
+
readonly window: Schema.Literals<readonly ["minute", "hour", "day"]>;
|
|
90
|
+
readonly used: Schema.Number;
|
|
91
|
+
readonly budget: Schema.Number;
|
|
92
|
+
}>]>;
|
|
93
|
+
}>, import("effect/Cause").YieldableError & {
|
|
94
|
+
readonly brand: unique symbol;
|
|
95
|
+
}>;
|
|
96
|
+
export declare class StartHeld extends StartHeld_base {}
|
|
97
|
+
export declare const admitStart: <A, E, R>(request: StartRequest, start: Effect.Effect<A, E, R>, args_2: {
|
|
98
|
+
readonly deadline: number;
|
|
99
|
+
}) => Effect.Effect<A, E | StartHeld, R | BoatStarts>;
|
|
100
|
+
export type { Admission, Counts, Line, PerWindow, Plan, RepoStarts, Share, StartRequest, Window };
|
package/dist/starts.mjs
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import * as Schema from "effect/Schema";
|
|
2
|
+
import * as Effect from "effect/Effect";
|
|
3
|
+
import * as Layer from "effect/Layer";
|
|
4
|
+
import * as Clock from "effect/Clock";
|
|
5
|
+
import * as Context from "effect/Context";
|
|
6
|
+
import * as Redacted from "effect/Redacted";
|
|
7
|
+
import { BoatApi, CiJobState, Configuration } from "@boatdev/sdk";
|
|
8
|
+
import { parse } from "yaml";
|
|
9
|
+
// src/starts/budget.ts
|
|
10
|
+
const Repo = Schema.String.check(Schema.isPattern(/^[\w.-]+\/[\w.-]+$/u)).pipe(Schema.brand("Repo"));
|
|
11
|
+
const Window = Schema.Literals([
|
|
12
|
+
"minute",
|
|
13
|
+
"hour",
|
|
14
|
+
"day"
|
|
15
|
+
]);
|
|
16
|
+
const Line = Schema.Union([
|
|
17
|
+
Schema.TaggedStruct("Unread", { reason: Schema.String }),
|
|
18
|
+
Schema.TaggedStruct("Paid", { nextStartDollars: Schema.UndefinedOr(Schema.Number) }),
|
|
19
|
+
Schema.TaggedStruct("Account", {
|
|
20
|
+
window: Window,
|
|
21
|
+
used: Schema.Number,
|
|
22
|
+
line: Schema.Number
|
|
23
|
+
}),
|
|
24
|
+
Schema.TaggedStruct("Budget", {
|
|
25
|
+
repo: Repo,
|
|
26
|
+
window: Window,
|
|
27
|
+
used: Schema.Number,
|
|
28
|
+
budget: Schema.Number
|
|
29
|
+
})
|
|
30
|
+
]);
|
|
31
|
+
const windows = [
|
|
32
|
+
"minute",
|
|
33
|
+
"hour",
|
|
34
|
+
"day"
|
|
35
|
+
];
|
|
36
|
+
const windowMillis = {
|
|
37
|
+
minute: 6e4,
|
|
38
|
+
hour: 36e5,
|
|
39
|
+
day: 864e5
|
|
40
|
+
};
|
|
41
|
+
const pollMillis = {
|
|
42
|
+
minute: 15e3,
|
|
43
|
+
hour: 6e4,
|
|
44
|
+
day: 3e5
|
|
45
|
+
};
|
|
46
|
+
const startShares = [
|
|
47
|
+
{
|
|
48
|
+
repo: Repo.make("birbprophet/agent-kit"),
|
|
49
|
+
share: .1
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
repo: Repo.make("siglata/siglata"),
|
|
53
|
+
share: .2
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
repo: Repo.make("optionhouse-xyz/optionhouse"),
|
|
57
|
+
share: .25
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
repo: Repo.make("birbprophet/vibebattler"),
|
|
61
|
+
share: .25
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
repo: Repo.make("birbprophet/secrets"),
|
|
65
|
+
share: 0
|
|
66
|
+
}
|
|
67
|
+
];
|
|
68
|
+
const count = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
69
|
+
const unread = (reason) => ({
|
|
70
|
+
_tag: "Hold",
|
|
71
|
+
line: {
|
|
72
|
+
_tag: "Unread",
|
|
73
|
+
reason
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const decide = (request, counts, now) => {
|
|
77
|
+
const share = startShares.find(({ repo }) => repo === request.repo);
|
|
78
|
+
if (share === void 0) return unread("repo has no start budget");
|
|
79
|
+
if (!count(request.jobs) || request.jobs === 0) return unread("jobs must be a positive safe integer");
|
|
80
|
+
if (!Number.isFinite(now)) return unread("start time unread");
|
|
81
|
+
if (counts === void 0) return {
|
|
82
|
+
_tag: "Wait",
|
|
83
|
+
until: now + pollMillis.minute,
|
|
84
|
+
line: {
|
|
85
|
+
_tag: "Unread",
|
|
86
|
+
reason: "start plan unread"
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
if (!Number.isFinite(counts.now) || !windows.every((window) => count(counts.plan.limits[window]) && count(counts.plan.used[window]))) return unread("start plan unread");
|
|
90
|
+
if (counts.repo.repo !== request.repo || !counts.repo.starts.every((at) => Number.isFinite(at) && at <= counts.now)) return unread("repo start history incomplete");
|
|
91
|
+
if (!counts.repo.complete) return {
|
|
92
|
+
_tag: "Wait",
|
|
93
|
+
until: now + pollMillis.minute,
|
|
94
|
+
line: {
|
|
95
|
+
_tag: "Unread",
|
|
96
|
+
reason: "repo start history incomplete"
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const { plan } = counts;
|
|
100
|
+
if (plan.nextStartDollars !== 0) return {
|
|
101
|
+
_tag: "Wait",
|
|
102
|
+
until: now + pollMillis.minute,
|
|
103
|
+
line: {
|
|
104
|
+
_tag: "Paid",
|
|
105
|
+
nextStartDollars: plan.nextStartDollars
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
for (const window of windows) {
|
|
109
|
+
const used = plan.used[window];
|
|
110
|
+
const line = plan.limits[window] - 20;
|
|
111
|
+
if (used + request.jobs > line) return window === "day" ? {
|
|
112
|
+
_tag: "Hold",
|
|
113
|
+
line: {
|
|
114
|
+
_tag: "Account",
|
|
115
|
+
window,
|
|
116
|
+
used,
|
|
117
|
+
line
|
|
118
|
+
}
|
|
119
|
+
} : {
|
|
120
|
+
_tag: "Wait",
|
|
121
|
+
until: now + pollMillis[window],
|
|
122
|
+
line: {
|
|
123
|
+
_tag: "Account",
|
|
124
|
+
window,
|
|
125
|
+
used,
|
|
126
|
+
line
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
for (const window of windows) {
|
|
131
|
+
const starts = counts.repo.starts.filter((at) => at > now - windowMillis[window]).toSorted((left, right) => left - right);
|
|
132
|
+
const used = starts.length;
|
|
133
|
+
const budget = Math.floor(share.share * plan.limits[window]);
|
|
134
|
+
if (used + request.jobs <= budget) continue;
|
|
135
|
+
const line = {
|
|
136
|
+
_tag: "Budget",
|
|
137
|
+
repo: request.repo,
|
|
138
|
+
window,
|
|
139
|
+
used,
|
|
140
|
+
budget
|
|
141
|
+
};
|
|
142
|
+
const expires = starts[used + request.jobs - budget - 1];
|
|
143
|
+
return request.jobs > budget || expires === void 0 ? {
|
|
144
|
+
_tag: "Hold",
|
|
145
|
+
line
|
|
146
|
+
} : {
|
|
147
|
+
_tag: "Wait",
|
|
148
|
+
until: expires + windowMillis[window],
|
|
149
|
+
line
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return { _tag: "Admit" };
|
|
153
|
+
};
|
|
154
|
+
// src/starts/boat.ts
|
|
155
|
+
var StartReadError = class extends Schema.TaggedError()("StartReadError", { reason: Schema.String }) {};
|
|
156
|
+
const Count = Schema.Number.check(Schema.makeFilter((value) => Number.isSafeInteger(value) && value >= 0));
|
|
157
|
+
const Usage = Schema.Struct({
|
|
158
|
+
limit: Count,
|
|
159
|
+
used: Count
|
|
160
|
+
});
|
|
161
|
+
const Limits = Schema.Struct({
|
|
162
|
+
ok: Schema.Literal(true),
|
|
163
|
+
starts: Schema.Struct({
|
|
164
|
+
minute: Usage,
|
|
165
|
+
hour: Usage,
|
|
166
|
+
day: Usage
|
|
167
|
+
}),
|
|
168
|
+
nextStartDollars: Schema.optional(Schema.NullOr(Schema.Finite))
|
|
169
|
+
});
|
|
170
|
+
const Ci = Schema.Struct({
|
|
171
|
+
ok: Schema.Literal(true),
|
|
172
|
+
jobs: Schema.Array(Schema.Struct({
|
|
173
|
+
repo: Schema.String,
|
|
174
|
+
label: Schema.String,
|
|
175
|
+
state: Schema.String.check(Schema.isMinLength(1)),
|
|
176
|
+
queuedAt: Schema.Date,
|
|
177
|
+
runStartedAt: Schema.optional(Schema.NullOr(Schema.Date))
|
|
178
|
+
}))
|
|
179
|
+
});
|
|
180
|
+
const settled = /* @__PURE__ */ new Set([
|
|
181
|
+
CiJobState.Success,
|
|
182
|
+
CiJobState.Failure,
|
|
183
|
+
CiJobState.Cancelled,
|
|
184
|
+
CiJobState.Skipped,
|
|
185
|
+
CiJobState.Failed,
|
|
186
|
+
CiJobState.Refused
|
|
187
|
+
]);
|
|
188
|
+
var BoatStarts = class BoatStarts extends Context.Service()("toolchain/BoatStarts") {
|
|
189
|
+
static layer = (key, options = {}) => Layer.sync(BoatStarts, () => {
|
|
190
|
+
const api = new BoatApi(new Configuration({
|
|
191
|
+
accessToken: Redacted.value(key),
|
|
192
|
+
...options.fetch === void 0 ? {} : { fetchApi: options.fetch }
|
|
193
|
+
}));
|
|
194
|
+
const plan = Effect.gen(function* () {
|
|
195
|
+
const response = yield* Effect.tryPromise({
|
|
196
|
+
try: () => api.limits(),
|
|
197
|
+
catch: () => new StartReadError({ reason: "Boat limits request failed" })
|
|
198
|
+
});
|
|
199
|
+
const limits = yield* Schema.decodeUnknownEffect(Limits)(response).pipe(Effect.mapError(() => new StartReadError({ reason: "Boat limits unread" })));
|
|
200
|
+
return {
|
|
201
|
+
limits: {
|
|
202
|
+
minute: limits.starts.minute.limit,
|
|
203
|
+
hour: limits.starts.hour.limit,
|
|
204
|
+
day: limits.starts.day.limit
|
|
205
|
+
},
|
|
206
|
+
used: {
|
|
207
|
+
minute: limits.starts.minute.used,
|
|
208
|
+
hour: limits.starts.hour.used,
|
|
209
|
+
day: limits.starts.day.used
|
|
210
|
+
},
|
|
211
|
+
nextStartDollars: limits.nextStartDollars ?? void 0
|
|
212
|
+
};
|
|
213
|
+
});
|
|
214
|
+
const repoStarts = Effect.fn("BoatStarts.repoStarts")(function* (repo) {
|
|
215
|
+
const response = yield* Effect.tryPromise({
|
|
216
|
+
try: () => api.getCiOverview({
|
|
217
|
+
repo,
|
|
218
|
+
limit: 500
|
|
219
|
+
}),
|
|
220
|
+
catch: () => new StartReadError({ reason: "Boat CI request failed" })
|
|
221
|
+
});
|
|
222
|
+
const now = yield* Clock.currentTimeMillis;
|
|
223
|
+
const { jobs } = yield* Schema.decodeUnknownEffect(Ci)(response).pipe(Effect.mapError(() => new StartReadError({ reason: "Boat CI history unread" })));
|
|
224
|
+
if (jobs.some((job) => job.repo !== repo)) return yield* new StartReadError({ reason: "Boat CI history differs from request" });
|
|
225
|
+
const oldest = Math.min(...jobs.map((job) => Math.max(job.queuedAt.getTime(), job.runStartedAt?.getTime() ?? 0)));
|
|
226
|
+
return {
|
|
227
|
+
repo,
|
|
228
|
+
starts: jobs.flatMap((job) => {
|
|
229
|
+
const at = job.runStartedAt?.getTime() ?? (settled.has(job.state) ? void 0 : now);
|
|
230
|
+
return job.label.split("/")[0]?.startsWith("boat") === true && at !== void 0 && at > now - windowMillis.day ? [Math.min(at, now)] : [];
|
|
231
|
+
}),
|
|
232
|
+
complete: jobs.length < 500 || oldest <= now - windowMillis.day
|
|
233
|
+
};
|
|
234
|
+
});
|
|
235
|
+
return BoatStarts.of({
|
|
236
|
+
plan,
|
|
237
|
+
repoStarts
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
// src/starts/policy.ts
|
|
242
|
+
const BOAT_JOBS_PER_RUN = 2;
|
|
243
|
+
const Matrix = Schema.Record(Schema.String, Schema.Array(Schema.Unknown));
|
|
244
|
+
const Workflow = Schema.Struct({
|
|
245
|
+
name: Schema.optionalKey(Schema.String),
|
|
246
|
+
on: Schema.optionalKey(Schema.Union([
|
|
247
|
+
Schema.String,
|
|
248
|
+
Schema.Array(Schema.String),
|
|
249
|
+
Schema.Record(Schema.String, Schema.Unknown)
|
|
250
|
+
])),
|
|
251
|
+
jobs: Schema.Record(Schema.String, Schema.Struct({
|
|
252
|
+
"runs-on": Schema.optionalKey(Schema.Union([Schema.String, Schema.Array(Schema.String)])),
|
|
253
|
+
uses: Schema.optionalKey(Schema.String),
|
|
254
|
+
strategy: Schema.optionalKey(Schema.Struct({ matrix: Schema.optionalKey(Schema.Union([Schema.String, Matrix])) }))
|
|
255
|
+
}))
|
|
256
|
+
});
|
|
257
|
+
const Descendant = Schema.Struct({ workflow_run: Schema.Struct({
|
|
258
|
+
workflows: Schema.Union([Schema.String, Schema.Array(Schema.String)]),
|
|
259
|
+
types: Schema.optionalKey(Schema.Union([Schema.String, Schema.Array(Schema.String)]))
|
|
260
|
+
}) });
|
|
261
|
+
const dynamic = (value) => {
|
|
262
|
+
try {
|
|
263
|
+
return JSON.stringify(value).includes("${{");
|
|
264
|
+
} catch {
|
|
265
|
+
return true;
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
const boatJobFindings = (files) => {
|
|
269
|
+
const findings = [];
|
|
270
|
+
const workflows = [];
|
|
271
|
+
for (const [path, text] of files) try {
|
|
272
|
+
workflows.push({
|
|
273
|
+
path,
|
|
274
|
+
workflow: Schema.decodeUnknownSync(Workflow)(parse(text))
|
|
275
|
+
});
|
|
276
|
+
} catch {
|
|
277
|
+
findings.push(`${path}: workflow unread`);
|
|
278
|
+
}
|
|
279
|
+
const after = (entry) => {
|
|
280
|
+
const events = entry.workflow.on;
|
|
281
|
+
if (!Schema.is(Descendant)(events)) {
|
|
282
|
+
if (typeof events === "object" && "workflow_run" in events) findings.push(`${entry.path}: workflow_run unread`);
|
|
283
|
+
return {
|
|
284
|
+
names: [],
|
|
285
|
+
copies: 0
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
const names = events.workflow_run.workflows;
|
|
289
|
+
const selectors = typeof names === "string" ? [names] : names;
|
|
290
|
+
if (selectors.some((name) => /[*!?[\]]/u.test(name))) findings.push(`${entry.path}: workflow_run pattern unresolved`);
|
|
291
|
+
const types = events.workflow_run.types;
|
|
292
|
+
if (types !== void 0 && dynamic(types)) findings.push(`${entry.path}: dynamic workflow_run types`);
|
|
293
|
+
return {
|
|
294
|
+
names: selectors,
|
|
295
|
+
copies: types === void 0 ? 3 : new Set(typeof types === "string" ? [types] : types).size
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
const count = (entry, parents, descendants) => {
|
|
299
|
+
if (parents.includes(entry.path)) {
|
|
300
|
+
findings.push(`${entry.path}: workflow cycle`);
|
|
301
|
+
return 0;
|
|
302
|
+
}
|
|
303
|
+
const stack = [...parents, entry.path];
|
|
304
|
+
let total = 0;
|
|
305
|
+
for (const [name, job] of Object.entries(entry.workflow.jobs)) {
|
|
306
|
+
const label = `${entry.path} ${name}`;
|
|
307
|
+
const matrix = job.strategy?.matrix;
|
|
308
|
+
let copies = 1;
|
|
309
|
+
if (matrix !== void 0) {
|
|
310
|
+
if (typeof matrix === "string" || dynamic(matrix)) findings.push(`${label}: dynamic matrix`);
|
|
311
|
+
else {
|
|
312
|
+
const axes = Object.entries(matrix).filter(([axis]) => axis !== "include" && axis !== "exclude");
|
|
313
|
+
copies = (axes.length === 0 ? 0 : axes.reduce((product, [, values]) => product * values.length, 1)) + (matrix.include?.length ?? 0);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
if (job.uses !== void 0) {
|
|
317
|
+
if (!/^\.\/\.github\/workflows\/[^/]+\.ya?ml$/u.test(job.uses)) {
|
|
318
|
+
findings.push(`${label}: remote or unresolved reusable workflow`);
|
|
319
|
+
continue;
|
|
320
|
+
}
|
|
321
|
+
const target = job.uses.slice(2);
|
|
322
|
+
const called = workflows.find(({ path }) => path === target || `.github/workflows/${path}` === target);
|
|
323
|
+
if (called === void 0) findings.push(`${label}: reusable workflow ${target} unread`);
|
|
324
|
+
else total += copies * count(called, stack, false);
|
|
325
|
+
} else if (job["runs-on"] === void 0 || dynamic(job["runs-on"])) findings.push(`${label}: dynamic or unread runs-on`);
|
|
326
|
+
else {
|
|
327
|
+
const runners = job["runs-on"];
|
|
328
|
+
if ((typeof runners === "string" ? [runners] : runners).some((runner) => runner.split("/")[0]?.startsWith("boat") === true)) total += copies;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (descendants) for (const child of workflows) {
|
|
332
|
+
const { names, copies } = after(child);
|
|
333
|
+
if (dynamic(names)) findings.push(`${child.path}: dynamic workflow_run`);
|
|
334
|
+
const file = entry.path.split("/").at(-1) ?? entry.path;
|
|
335
|
+
if ((entry.workflow.name === void 0 ? [
|
|
336
|
+
entry.path,
|
|
337
|
+
file,
|
|
338
|
+
`.github/workflows/${file}`
|
|
339
|
+
] : [entry.workflow.name]).some((name) => names.includes(name))) total += copies * count(child, stack, true);
|
|
340
|
+
}
|
|
341
|
+
return total;
|
|
342
|
+
};
|
|
343
|
+
for (const entry of workflows) {
|
|
344
|
+
const total = count(entry, [], true);
|
|
345
|
+
if (total > 2) findings.push(`${entry.path}: closure starts ${total} Boat jobs, limit 2`);
|
|
346
|
+
}
|
|
347
|
+
return [...new Set(findings)];
|
|
348
|
+
};
|
|
349
|
+
// src/starts.ts
|
|
350
|
+
var StartHeld = class extends Schema.TaggedError()("StartHeld", { line: Line }) {};
|
|
351
|
+
const admitStart = Effect.fn("Starts.admitStart")(function* (request, start, { deadline }) {
|
|
352
|
+
const boat = yield* BoatStarts;
|
|
353
|
+
let last = {
|
|
354
|
+
_tag: "Unread",
|
|
355
|
+
reason: "start deadline reached"
|
|
356
|
+
};
|
|
357
|
+
for (;;) {
|
|
358
|
+
const remaining = deadline - (yield* Clock.currentTimeMillis);
|
|
359
|
+
if (!Number.isFinite(remaining) || remaining <= 0) return yield* new StartHeld({ line: last });
|
|
360
|
+
const counts = yield* Effect.gen(function* () {
|
|
361
|
+
const plan = yield* boat.plan;
|
|
362
|
+
const repo = yield* boat.repoStarts(request.repo);
|
|
363
|
+
return {
|
|
364
|
+
now: yield* Clock.currentTimeMillis,
|
|
365
|
+
plan,
|
|
366
|
+
repo
|
|
367
|
+
};
|
|
368
|
+
}).pipe(Effect.catchTag("StartReadError", () => Effect.undefined), Effect.timeoutOrElse({
|
|
369
|
+
duration: remaining,
|
|
370
|
+
orElse: () => Effect.fail(new StartHeld({ line: last }))
|
|
371
|
+
}));
|
|
372
|
+
const now = yield* Clock.currentTimeMillis;
|
|
373
|
+
const decision = decide(request, counts, now);
|
|
374
|
+
if (decision._tag === "Hold") return yield* new StartHeld({ line: decision.line });
|
|
375
|
+
if (!Number.isFinite(deadline) || now >= deadline) return yield* new StartHeld({ line: decision._tag === "Wait" ? decision.line : {
|
|
376
|
+
_tag: "Unread",
|
|
377
|
+
reason: "start deadline reached"
|
|
378
|
+
} });
|
|
379
|
+
if (decision._tag === "Admit") return yield* start;
|
|
380
|
+
last = decision.line;
|
|
381
|
+
const window = decision.line._tag === "Account" || decision.line._tag === "Budget" ? decision.line.window : "minute";
|
|
382
|
+
yield* Effect.sleep(Math.max(0, Math.min(decision.until, now + pollMillis[window], deadline) - now));
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
export { BOAT_JOBS_PER_RUN, BoatStarts, Repo, StartHeld, StartReadError, admitStart, boatJobFindings, decide, startShares };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkenjoyer/toolchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/birbprophet/agent-kit.git",
|
|
@@ -15,16 +15,11 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"dist",
|
|
18
|
+
"STARTS.md",
|
|
18
19
|
"licenses",
|
|
19
20
|
"node-version",
|
|
20
21
|
"renovate.json",
|
|
21
|
-
"src
|
|
22
|
-
"src/formal/",
|
|
23
|
-
"src/proof.ts",
|
|
24
|
-
"src/standard.ts",
|
|
25
|
-
"src/standard/",
|
|
26
|
-
"src/verdict.ts",
|
|
27
|
-
"src/verification.ts",
|
|
22
|
+
"src",
|
|
28
23
|
"tsconfig.base.json",
|
|
29
24
|
"vscode/extensions.json",
|
|
30
25
|
"vscode/settings.json"
|
|
@@ -87,6 +82,10 @@
|
|
|
87
82
|
"types": "./dist/rules.d.mts",
|
|
88
83
|
"default": "./dist/rules.mjs"
|
|
89
84
|
},
|
|
85
|
+
"./starts": {
|
|
86
|
+
"types": "./dist/starts.d.mts",
|
|
87
|
+
"default": "./dist/starts.mjs"
|
|
88
|
+
},
|
|
90
89
|
"./versions": {
|
|
91
90
|
"types": "./dist/versions.d.mts",
|
|
92
91
|
"default": "./dist/versions.mjs"
|
|
@@ -108,20 +107,23 @@
|
|
|
108
107
|
"prepack": "vp pack"
|
|
109
108
|
},
|
|
110
109
|
"dependencies": {
|
|
110
|
+
"@boatdev/sdk": "1.13.0",
|
|
111
111
|
"@effect/platform-node": "4.1.2",
|
|
112
112
|
"@effect/tsgo": "0.67.3",
|
|
113
113
|
"@foldkit/oxlint-plugin": "0.15.4",
|
|
114
|
+
"@mpsuesser/oxlint-plugin-effect": "0.6.0",
|
|
114
115
|
"@octokit/rest": "22.0.1",
|
|
115
116
|
"effect": "4.1.2",
|
|
116
117
|
"effect-oxlint": "0.4.0",
|
|
118
|
+
"oxc-parser": "0.157.0",
|
|
117
119
|
"semver": "7.8.6",
|
|
118
120
|
"ultracite": "8.1.1",
|
|
121
|
+
"yaml": "2.9.1",
|
|
119
122
|
"z3-solver": "5.3.3"
|
|
120
123
|
},
|
|
121
124
|
"devDependencies": {
|
|
122
125
|
"@birbprophet/test-kit": "0.0.0",
|
|
123
126
|
"@effect/vitest": "4.1.2",
|
|
124
|
-
"@mpsuesser/oxlint-plugin-effect": "0.6.0",
|
|
125
127
|
"@types/semver": "7.8.0",
|
|
126
128
|
"jsonata": "2.2.2",
|
|
127
129
|
"knip": "6.44.1",
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type * as Schema from "effect/Schema";
|
|
2
|
+
import type { Arith, BitVec, Bool, Context } from "z3-solver";
|
|
3
|
+
|
|
4
|
+
type IntSchema = Schema.Top & { readonly Type: number };
|
|
5
|
+
type Literal =
|
|
6
|
+
| { readonly kind: "int"; readonly min: number; readonly max: number }
|
|
7
|
+
| { readonly kind: "uint"; readonly bits: number };
|
|
8
|
+
type Sym<D> = D extends { readonly kind: "uint" }
|
|
9
|
+
? BitVec<number, "main">
|
|
10
|
+
: Arith<"main">;
|
|
11
|
+
type Syms<I> = { readonly [K in keyof I]: Sym<I[K]> };
|
|
12
|
+
type Values<I> = {
|
|
13
|
+
readonly [K in keyof I]: I[K] extends IntSchema ? I[K]["Type"] : number;
|
|
14
|
+
};
|
|
15
|
+
type Term = Arith<"main"> | BitVec<number, "main"> | Bool<"main">;
|
|
16
|
+
type Output = Term | { readonly [key: string]: Term };
|
|
17
|
+
type Concrete<O> =
|
|
18
|
+
O extends Bool<"main">
|
|
19
|
+
? boolean
|
|
20
|
+
: O extends Term
|
|
21
|
+
? number
|
|
22
|
+
: { readonly [K in keyof O]: Concrete<O[K]> };
|
|
23
|
+
export type Every<I extends Record<string, IntSchema>> = {
|
|
24
|
+
readonly kind: "every";
|
|
25
|
+
readonly inputs: I;
|
|
26
|
+
readonly holds: (values: Values<I>) => boolean;
|
|
27
|
+
};
|
|
28
|
+
export type Z3Proof<
|
|
29
|
+
I extends Record<string, IntSchema | Literal>,
|
|
30
|
+
O extends Output,
|
|
31
|
+
> = {
|
|
32
|
+
readonly kind: "z3";
|
|
33
|
+
readonly inputs: I;
|
|
34
|
+
readonly assume?: (s: Syms<I>, Z3: Context<"main">) => Bool<"main">;
|
|
35
|
+
readonly model: (s: Syms<I>, Z3: Context<"main">) => O;
|
|
36
|
+
readonly code: (values: Values<I>) => Concrete<O>;
|
|
37
|
+
readonly holds: (s: Syms<I>, out: O, Z3: Context<"main">) => Bool<"main">;
|
|
38
|
+
};
|
|
39
|
+
export const every = <I extends Record<string, IntSchema>>(
|
|
40
|
+
proof: Omit<Every<I>, "kind">
|
|
41
|
+
): Every<I> => ({ kind: "every", ...proof });
|
|
42
|
+
export const z3 = <
|
|
43
|
+
I extends Record<string, IntSchema | Literal>,
|
|
44
|
+
O extends Output,
|
|
45
|
+
>(
|
|
46
|
+
proof: Omit<Z3Proof<I, O>, "kind">
|
|
47
|
+
): Z3Proof<I, O> => ({ kind: "z3", ...proof });
|
|
48
|
+
export const int = (
|
|
49
|
+
min: number,
|
|
50
|
+
max: number
|
|
51
|
+
): Extract<Literal, { kind: "int" }> => {
|
|
52
|
+
if (!Number.isSafeInteger(min) || !Number.isSafeInteger(max) || min > max)
|
|
53
|
+
throw new Error("int needs safe integer bounds with min <= max");
|
|
54
|
+
return { kind: "int", min, max };
|
|
55
|
+
};
|
|
56
|
+
export const uint = (bits: number): Extract<Literal, { kind: "uint" }> => {
|
|
57
|
+
if (!Number.isInteger(bits) || bits < 1 || bits > 53)
|
|
58
|
+
throw new Error("uint needs a bit width from 1 to 53");
|
|
59
|
+
return { kind: "uint", bits };
|
|
60
|
+
};
|