@milkenjoyer/toolchain 0.19.0 → 0.21.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.
Files changed (55) hide show
  1. package/STARTS.md +5 -13
  2. package/dist/ci-budget-B2AuZ3xa.mjs +80 -0
  3. package/dist/ci-budget-cli.d.mts +2 -0
  4. package/dist/ci-budget-cli.mjs +31 -0
  5. package/dist/ci-budget.d.mts +22 -0
  6. package/dist/ci-budget.mjs +1 -0
  7. package/dist/ci-result.d.mts +1 -0
  8. package/dist/ci-result.mjs +12 -0
  9. package/dist/{compatible-DIYO9MZf.d.mts → compatible-BKEJ_p20.d.mts} +1 -1
  10. package/dist/{compatible-D54mCSlT.mjs → compatible-CRaMYpBM.mjs} +2 -2
  11. package/dist/compatible.d.mts +1 -1
  12. package/dist/compatible.mjs +1 -1
  13. package/dist/conformance.mjs +1 -1
  14. package/dist/{effect-plugin-BsrW5_nI.mjs → effect-plugin-BiskbKO9.mjs} +2 -2
  15. package/dist/effect-plugin.mjs +1 -1
  16. package/dist/foldkit-plugin.mjs +2 -2
  17. package/dist/formal.d.mts +1 -1
  18. package/dist/formal.mjs +5 -5
  19. package/dist/{guard-fFg_0NIp.mjs → guard-CAm90ZGy.mjs} +5 -5
  20. package/dist/guard.d.mts +1 -1
  21. package/dist/guard.mjs +1 -1
  22. package/dist/hooks.d.mts +1 -1
  23. package/dist/hooks.mjs +2 -2
  24. package/dist/{lint-BJ6SmGk1.mjs → lint-CiO5Etue.mjs} +3 -3
  25. package/dist/lint.mjs +1 -1
  26. package/dist/{plugin-CwxhPtui.mjs → plugin-DwQM07Ih.mjs} +2 -2
  27. package/dist/plugin.mjs +1 -1
  28. package/dist/proof.mjs +3 -3
  29. package/dist/renovate-ci-BdVmECgm.mjs +73 -0
  30. package/dist/renovate-ci.d.mts +10 -0
  31. package/dist/renovate-ci.mjs +1 -0
  32. package/dist/standard.mjs +6 -6
  33. package/dist/starts.d.mts +1 -110
  34. package/dist/starts.mjs +5 -351
  35. package/dist/verdict.d.mts +1 -1
  36. package/dist/verdict.mjs +2 -2
  37. package/dist/{verification-FgQFU1YN.d.mts → verification-fnhfrxmy.d.mts} +1 -1
  38. package/dist/verification.d.mts +1 -1
  39. package/dist/verification.mjs +1 -1
  40. package/dist/versions.mjs +1 -1
  41. package/package.json +11 -1
  42. package/renovate.json +29 -3
  43. package/src/ci-budget-cli.ts +39 -0
  44. package/src/ci-budget.ts +116 -0
  45. package/src/ci-result.ts +12 -0
  46. package/src/renovate-ci.ts +96 -0
  47. package/src/starts/policy.ts +5 -1
  48. package/src/starts.ts +0 -100
  49. package/src/starts/boat.ts +0 -144
  50. package/src/starts/budget.ts +0 -224
  51. package/src/starts/merges.ts +0 -99
  52. package/dist/{specs-file-NsQF4V7X.mjs → specs-file-Ck9ZOt46.mjs} +1 -1
  53. package/dist/{syntax-CGEOffZK.mjs → syntax-B3n7lDYJ.mjs} +1 -1
  54. package/dist/{verification-oAc1Q6I9.mjs → verification-D4Sn2fh5.mjs} +4 -4
  55. package/dist/{versions-DpRzgSR_.mjs → versions-KbYa8kbF.mjs} +1 -1
@@ -1,224 +0,0 @@
1
- import * as Schema from "effect/Schema";
2
-
3
- export const Repo = Schema.String.check(
4
- Schema.isPattern(/^[\w.-]+\/[\w.-]+$/u)
5
- ).pipe(Schema.brand("Repo"));
6
- export type Repo = typeof Repo.Type;
7
- export type Window = "minute" | "hour" | "day";
8
- export type PerWindow<A> = { readonly [W in Window]: A };
9
- export type Priority = "ordinary" | "p0";
10
- export type MergeCounts = {
11
- readonly repo: Repo;
12
- readonly h6: number;
13
- readonly h24: number;
14
- readonly d7: number;
15
- };
16
- export type Plan = {
17
- readonly limits: PerWindow<number>;
18
- readonly used: PerWindow<number>;
19
- readonly nextStartDollars: number | undefined;
20
- };
21
- export type RepoStarts = {
22
- readonly repo: Repo;
23
- readonly starts: ReadonlyArray<number>;
24
- readonly complete: boolean;
25
- };
26
- export type Counts = {
27
- readonly now: number;
28
- readonly plan: Plan;
29
- readonly repo?: RepoStarts | undefined;
30
- readonly merges?: ReadonlyArray<MergeCounts> | undefined;
31
- };
32
- export type StartRequest = {
33
- readonly repo: Repo;
34
- readonly jobs: number;
35
- readonly priority: Priority;
36
- };
37
-
38
- const Window = Schema.Literals(["minute", "hour", "day"]);
39
- export const Line = Schema.Union([
40
- Schema.TaggedStruct("Unread", { reason: Schema.String }),
41
- Schema.TaggedStruct("Paid", {
42
- nextStartDollars: Schema.UndefinedOr(Schema.Number),
43
- }),
44
- Schema.TaggedStruct("Account", {
45
- window: Window,
46
- used: Schema.Number,
47
- line: Schema.Number,
48
- }),
49
- Schema.TaggedStruct("Budget", {
50
- repo: Repo,
51
- window: Window,
52
- used: Schema.Number,
53
- budget: Schema.Number,
54
- }),
55
- ]);
56
- export type Line = typeof Line.Type;
57
- export type Admission =
58
- | { readonly _tag: "Admit" }
59
- | { readonly _tag: "Wait"; readonly until: number; readonly line: Line }
60
- | { readonly _tag: "Hold"; readonly line: Line };
61
-
62
- const windows: ReadonlyArray<Window> = ["minute", "hour", "day"];
63
- export const windowMillis: PerWindow<number> = {
64
- minute: 60_000,
65
- hour: 3_600_000,
66
- day: 86_400_000,
67
- };
68
- export const pollMillis: PerWindow<number> = {
69
- minute: 15_000,
70
- hour: 60_000,
71
- day: 300_000,
72
- };
73
-
74
- export const startRepos: ReadonlyArray<Repo> = [
75
- Repo.make("birbprophet/agent-kit"),
76
- Repo.make("siglata/siglata"),
77
- Repo.make("optionhouse-xyz/optionhouse"),
78
- Repo.make("birbprophet/vibebattler"),
79
- ];
80
-
81
- const count = (value: number) => Number.isSafeInteger(value) && value >= 0;
82
- const ceiling = (request: StartRequest, plan: Plan, window: Window) =>
83
- Number(
84
- (BigInt(plan.limits[window]) * (request.priority === "p0" ? 95n : 80n)) /
85
- 100n
86
- );
87
-
88
- export const sharedWindows = (
89
- request: StartRequest,
90
- plan: Plan
91
- ): ReadonlyArray<Window> =>
92
- request.priority === "p0" ||
93
- plan.nextStartDollars !== 0 ||
94
- !windows.every(
95
- (window) => count(plan.limits[window]) && count(plan.used[window])
96
- ) ||
97
- windows.some(
98
- (window) =>
99
- plan.used[window] + request.jobs > ceiling(request, plan, window)
100
- )
101
- ? []
102
- : windows.filter((window) => 2 * plan.used[window] >= plan.limits[window]);
103
-
104
- const liveShare = (
105
- repo: Repo,
106
- merges: Counts["merges"]
107
- ): { readonly numerator: bigint; readonly denominator: bigint } | undefined => {
108
- if (
109
- merges === undefined ||
110
- merges.length !== startRepos.length ||
111
- !startRepos.every(
112
- (repo) => merges.filter((row) => row.repo === repo).length === 1
113
- ) ||
114
- !merges.every((row) => [row.h6, row.h24, row.d7].every(count))
115
- )
116
- return undefined;
117
- const weights = merges.map((row) => ({
118
- repo: row.repo,
119
- weight: [7n * BigInt(row.h24), 28n * BigInt(row.h6), BigInt(row.d7)].reduce(
120
- (largest, value) => (value > largest ? value : largest),
121
- 0n
122
- ),
123
- }));
124
- const total = weights.reduce((sum, row) => sum + row.weight, 0n);
125
- const weight = weights.find((row) => row.repo === repo)?.weight;
126
- return weight === undefined
127
- ? undefined
128
- : total === 0n
129
- ? { numerator: 1n, denominator: 4n }
130
- : { numerator: total + 6n * weight, denominator: 10n * total };
131
- };
132
- const unread = (reason: string): Admission => ({
133
- _tag: "Hold",
134
- line: { _tag: "Unread", reason },
135
- });
136
-
137
- export const decide = (
138
- request: StartRequest,
139
- counts: Counts | undefined,
140
- now: number
141
- ): Admission => {
142
- if (!startRepos.includes(request.repo))
143
- return unread("repo has no start budget");
144
- if (!count(request.jobs) || request.jobs === 0)
145
- return unread("jobs must be a positive safe integer");
146
- if (!Number.isFinite(now)) return unread("start time unread");
147
- if (counts === undefined)
148
- return {
149
- _tag: "Wait",
150
- until: now + pollMillis.minute,
151
- line: { _tag: "Unread", reason: "start plan unread" },
152
- };
153
- if (
154
- !Number.isFinite(counts.now) ||
155
- counts.now > now ||
156
- !windows.every(
157
- (window) =>
158
- count(counts.plan.limits[window]) && count(counts.plan.used[window])
159
- )
160
- )
161
- return unread("start plan unread");
162
- const { plan } = counts;
163
- if (plan.nextStartDollars !== 0)
164
- return {
165
- _tag: "Wait",
166
- until: now + pollMillis.minute,
167
- line: { _tag: "Paid", nextStartDollars: plan.nextStartDollars },
168
- };
169
- for (const window of windows) {
170
- const used = plan.used[window];
171
- const line = ceiling(request, plan, window);
172
- if (used + request.jobs > line)
173
- return window === "day"
174
- ? { _tag: "Hold", line: { _tag: "Account", window, used, line } }
175
- : {
176
- _tag: "Wait",
177
- until: now + pollMillis[window],
178
- line: { _tag: "Account", window, used, line },
179
- };
180
- }
181
- const shared = sharedWindows(request, plan);
182
- if (shared.length === 0) return { _tag: "Admit" };
183
- if (counts.repo === undefined || !counts.repo.complete)
184
- return {
185
- _tag: "Wait",
186
- until: now + pollMillis.minute,
187
- line: { _tag: "Unread", reason: "repo start history incomplete" },
188
- };
189
- if (
190
- counts.repo.repo !== request.repo ||
191
- !counts.repo.starts.every((at) => Number.isFinite(at) && at <= counts.now)
192
- )
193
- return unread("repo start history incomplete");
194
- const share = liveShare(request.repo, counts.merges);
195
- if (share === undefined)
196
- return {
197
- _tag: "Wait",
198
- until: now + pollMillis.minute,
199
- line: { _tag: "Unread", reason: "merge history incomplete" },
200
- };
201
- for (const window of shared) {
202
- const starts = counts.repo.starts
203
- .filter((at) => at > now - windowMillis[window])
204
- .toSorted((left, right) => left - right);
205
- const used = starts.length;
206
- const budget = Number(
207
- (share.numerator * 4n * BigInt(plan.limits[window])) /
208
- (share.denominator * 5n)
209
- );
210
- if (used + request.jobs <= budget) continue;
211
- const line: Line = {
212
- _tag: "Budget",
213
- repo: request.repo,
214
- window,
215
- used,
216
- budget,
217
- };
218
- const expires = starts[used + request.jobs - budget - 1];
219
- return request.jobs > budget || expires === undefined
220
- ? { _tag: "Hold", line }
221
- : { _tag: "Wait", until: expires + windowMillis[window], line };
222
- }
223
- return { _tag: "Admit" };
224
- };
@@ -1,99 +0,0 @@
1
- import { Octokit } from "@octokit/rest";
2
- import * as Clock from "effect/Clock";
3
- import * as Context from "effect/Context";
4
- import * as Effect from "effect/Effect";
5
- import * as Layer from "effect/Layer";
6
- import * as Redacted from "effect/Redacted";
7
- import * as Schema from "effect/Schema";
8
-
9
- import { StartReadError } from "./boat.ts";
10
- import { type MergeCounts, startRepos } from "./budget.ts";
11
-
12
- const Count = Schema.Struct({
13
- issueCount: Schema.Number.check(
14
- Schema.makeFilter((value) => Number.isSafeInteger(value) && value >= 0)
15
- ),
16
- });
17
- const windows = { h6: 21_600_000, h24: 86_400_000, d7: 604_800_000 };
18
-
19
- export class Merges extends Context.Service<
20
- Merges,
21
- { readonly counts: Effect.Effect<ReadonlyArray<MergeCounts>, StartReadError> }
22
- >()("toolchain/Merges") {
23
- static readonly layer = (
24
- token: Redacted.Redacted<string>,
25
- options: {
26
- readonly fetch?: (
27
- url: string | URL | Request,
28
- init?: RequestInit
29
- ) => Promise<Response>;
30
- } = {}
31
- ) =>
32
- Layer.sync(Merges, () => {
33
- const api = new Octokit({
34
- auth: Redacted.value(token),
35
- ...(options.fetch === undefined
36
- ? {}
37
- : { request: { fetch: options.fetch } }),
38
- });
39
- const counts = Effect.gen(function* () {
40
- const now = yield* Clock.currentTimeMillis;
41
- const query = `query { ${startRepos
42
- .flatMap((repo, index) => {
43
- const [owner, name] = repo.split("/");
44
- return [
45
- `repo${index}: repository(owner: "${owner}", name: "${name}") { nameWithOwner }`,
46
- ...Object.entries(windows).map(([window, millis]) => {
47
- const since = new Date(now - millis)
48
- .toISOString()
49
- .replace(/\.\d{3}Z$/u, "Z");
50
- return `${window}_${index}: search(type: ISSUE, first: 0, query: "repo:${repo} is:pr is:merged base:main merged:>=${since}") { issueCount }`;
51
- }),
52
- ];
53
- })
54
- .join(" ")} }`;
55
- const response = yield* Effect.tryPromise({
56
- try: () => api.graphql<unknown>(query),
57
- catch: () =>
58
- new StartReadError({ reason: "GitHub merges request failed" }),
59
- });
60
- return yield* Schema.decodeUnknownEffect(
61
- Schema.Record(Schema.String, Schema.Unknown)
62
- )(response).pipe(
63
- Effect.flatMap((data) =>
64
- Effect.forEach(
65
- startRepos,
66
- (repo, index) =>
67
- Schema.decodeUnknownEffect(
68
- Schema.Struct({
69
- repository: Schema.Struct({
70
- nameWithOwner: Schema.Literal(repo),
71
- }),
72
- h6: Count,
73
- h24: Count,
74
- d7: Count,
75
- })
76
- )({
77
- repository: data[`repo${index}`],
78
- h6: data[`h6_${index}`],
79
- h24: data[`h24_${index}`],
80
- d7: data[`d7_${index}`],
81
- }).pipe(
82
- Effect.map((row) => ({
83
- repo,
84
- h6: row.h6.issueCount,
85
- h24: row.h24.issueCount,
86
- d7: row.d7.issueCount,
87
- }))
88
- ),
89
- { concurrency: 1 }
90
- )
91
- ),
92
- Effect.mapError(
93
- () => new StartReadError({ reason: "GitHub merges unread" })
94
- )
95
- );
96
- });
97
- return Merges.of({ counts });
98
- });
99
- }
@@ -1,5 +1,5 @@
1
- import * as Schema from "effect/Schema";
2
1
  import * as Effect from "effect/Effect";
2
+ import * as Schema from "effect/Schema";
3
3
  import * as Result from "effect/Result";
4
4
  import * as SchemaIssue from "effect/SchemaIssue";
5
5
  // src/formal/critical.ts
@@ -1,5 +1,5 @@
1
- import * as Option from "effect/Option";
2
1
  import * as Schema from "effect/Schema";
2
+ import * as Option from "effect/Option";
3
3
  // src/shared/syntax.ts
4
4
  const unwrapExpression = (node) => {
5
5
  if (node.type === "ParenthesizedExpression" || node.type === "ChainExpression" || node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "TSSatisfiesExpression") return unwrapExpression(node.expression);
@@ -1,14 +1,14 @@
1
- import * as Data from "effect/Data";
2
- import * as Schema from "effect/Schema";
3
1
  import * as Config from "effect/Config";
2
+ import * as Console from "effect/Console";
4
3
  import * as Effect from "effect/Effect";
4
+ import * as Redacted from "effect/Redacted";
5
+ import * as Schema from "effect/Schema";
6
+ import * as Data from "effect/Data";
5
7
  import { NodeServices } from "@effect/platform-node";
6
8
  import * as Cause from "effect/Cause";
7
- import * as Console from "effect/Console";
8
9
  import * as Exit from "effect/Exit";
9
10
  import { FileSystem } from "effect/FileSystem";
10
11
  import { Octokit } from "@octokit/rest";
11
- import * as Redacted from "effect/Redacted";
12
12
  // src/verification.ts
13
13
  const exemptions = [{
14
14
  reason: "Renovate PR",
@@ -1,8 +1,8 @@
1
+ import * as Schema from "effect/Schema";
1
2
  import * as Arr from "effect/Array";
2
3
  import { dual } from "effect/Function";
3
4
  import * as Option from "effect/Option";
4
5
  import * as R from "effect/Record";
5
- import * as Schema from "effect/Schema";
6
6
  import * as Str from "effect/String";
7
7
  // src/versions.ts
8
8
  const nodeVersion = "26.13.1";