@milkenjoyer/toolchain 0.18.0 → 0.20.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/STARTS.md +5 -13
- package/dist/{compatible-D8n_sQHa.mjs → compatible-D54mCSlT.mjs} +1 -1
- package/dist/{compatible-n7uFGrI3.d.mts → compatible-DIYO9MZf.d.mts} +1 -1
- package/dist/compatible.d.mts +1 -1
- package/dist/compatible.mjs +1 -1
- package/dist/{fmt-BaECz64m.mjs → fmt-C6autuPP.mjs} +1 -1
- package/dist/fmt.mjs +1 -1
- package/dist/formal.mjs +2 -1
- package/dist/{guard-Doqk4Fju.mjs → guard-fFg_0NIp.mjs} +9 -4
- package/dist/guard.d.mts +2 -2
- package/dist/guard.mjs +1 -1
- package/dist/{lint-CfztB4u8.mjs → lint-BJ6SmGk1.mjs} +1 -1
- package/dist/lint.mjs +1 -1
- package/dist/standard.mjs +26 -17
- package/dist/starts.d.mts +1 -110
- package/dist/starts.mjs +1 -349
- package/dist/{versions-C7LKZGr3.mjs → versions-DpRzgSR_.mjs} +12 -12
- package/dist/{versions-D02TrtKw.d.mts → versions-DqZd0jF9.d.mts} +1 -1
- package/dist/versions.d.mts +1 -1
- package/dist/versions.mjs +1 -1
- package/node-version +1 -1
- package/package.json +10 -11
- package/src/fmt.ts +1 -1
- package/src/formal/tla.ts +11 -4
- package/src/lint.ts +1 -1
- package/src/standard/alchemy.ts +26 -29
- package/src/standard/manifest.ts +16 -0
- package/src/standard/toolchain.ts +37 -13
- package/src/starts.ts +0 -100
- package/src/versions.ts +12 -12
- package/src/starts/boat.ts +0 -144
- package/src/starts/budget.ts +0 -224
- package/src/starts/merges.ts +0 -99
|
@@ -2,9 +2,16 @@ import { fileURLToPath } from "node:url";
|
|
|
2
2
|
|
|
3
3
|
import * as Effect from "effect/Effect";
|
|
4
4
|
import { FileSystem } from "effect/FileSystem";
|
|
5
|
+
import * as Option from "effect/Option";
|
|
5
6
|
import * as Schema from "effect/Schema";
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
+
import { versionOf } from "../versions.ts";
|
|
9
|
+
import {
|
|
10
|
+
exactFindings,
|
|
11
|
+
manifestRanges,
|
|
12
|
+
PLAIN,
|
|
13
|
+
resolveCatalog,
|
|
14
|
+
} from "./manifest.ts";
|
|
8
15
|
import { read, type Finding, type Rule } from "./repo.ts";
|
|
9
16
|
|
|
10
17
|
const packageName = "@milkenjoyer/toolchain";
|
|
@@ -16,16 +23,10 @@ export const pin: Rule = (repo) =>
|
|
|
16
23
|
const version =
|
|
17
24
|
groups.get("dependencies")?.[packageName] ??
|
|
18
25
|
groups.get("devDependencies")?.[packageName];
|
|
19
|
-
const name =
|
|
20
|
-
version?.startsWith("catalog:") === true ? version.slice(8) : undefined;
|
|
21
26
|
const resolved =
|
|
22
|
-
|
|
23
|
-
?
|
|
24
|
-
:
|
|
25
|
-
? (groups.get("workspaces.catalog")?.[packageName] ??
|
|
26
|
-
groups.get("catalog")?.[packageName])
|
|
27
|
-
: (groups.get(`workspaces.catalogs.${name}`)?.[packageName] ??
|
|
28
|
-
groups.get(`catalogs.${name}`)?.[packageName]);
|
|
27
|
+
version === undefined
|
|
28
|
+
? undefined
|
|
29
|
+
: resolveCatalog(packageName, version, groups);
|
|
29
30
|
return resolved !== undefined && PLAIN.test(resolved)
|
|
30
31
|
? []
|
|
31
32
|
: [
|
|
@@ -73,13 +74,36 @@ export const renovate: Rule = (repo) =>
|
|
|
73
74
|
});
|
|
74
75
|
export const exact: Rule = (repo) =>
|
|
75
76
|
Effect.gen(function* () {
|
|
77
|
+
const root = yield* read(repo, "package.json", manifestRanges);
|
|
78
|
+
if (!root.ok) return root.findings;
|
|
79
|
+
const groups = new Map(root.value);
|
|
76
80
|
const findings: Finding[] = [];
|
|
77
81
|
for (const file of repo.tracked.filter((f) =>
|
|
78
82
|
/(?:^|\/)package\.json$/u.test(f)
|
|
79
83
|
)) {
|
|
80
|
-
const input = yield* read(repo, file, (text) =>
|
|
81
|
-
exactFindings(file, text)
|
|
82
|
-
|
|
84
|
+
const input = yield* read(repo, file, (text) => [
|
|
85
|
+
...exactFindings(file, text),
|
|
86
|
+
...manifestRanges(text).flatMap(([field, ranges]) =>
|
|
87
|
+
Object.entries(ranges).flatMap(([name, written]) => {
|
|
88
|
+
if (
|
|
89
|
+
name === "alchemy" ||
|
|
90
|
+
name.startsWith("@alchemy.run/") ||
|
|
91
|
+
written.startsWith("workspace:")
|
|
92
|
+
)
|
|
93
|
+
return [];
|
|
94
|
+
const actual = resolveCatalog(name, written, groups);
|
|
95
|
+
return Option.match(versionOf(name), {
|
|
96
|
+
onNone: () => [],
|
|
97
|
+
onSome: (expected) =>
|
|
98
|
+
actual === expected
|
|
99
|
+
? []
|
|
100
|
+
: [
|
|
101
|
+
`${field} ${name}: ${actual} must match the toolchain catalog's ${expected}`,
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
})
|
|
105
|
+
),
|
|
106
|
+
]);
|
|
83
107
|
findings.push(
|
|
84
108
|
...(input.ok
|
|
85
109
|
? input.value.map((message) => ({ file, message }))
|
package/src/starts.ts
CHANGED
|
@@ -1,101 +1 @@
|
|
|
1
|
-
import * as Clock from "effect/Clock";
|
|
2
|
-
import * as Effect from "effect/Effect";
|
|
3
|
-
import * as Schema from "effect/Schema";
|
|
4
|
-
|
|
5
|
-
import { BoatStarts } from "./starts/boat.ts";
|
|
6
|
-
import {
|
|
7
|
-
decide,
|
|
8
|
-
Line,
|
|
9
|
-
pollMillis,
|
|
10
|
-
sharedWindows,
|
|
11
|
-
type StartRequest,
|
|
12
|
-
} from "./starts/budget.ts";
|
|
13
|
-
import { Merges } from "./starts/merges.ts";
|
|
14
|
-
|
|
15
|
-
export { BoatStarts, StartReadError } from "./starts/boat.ts";
|
|
16
|
-
export { decide, Repo, startRepos } from "./starts/budget.ts";
|
|
17
|
-
export { Merges } from "./starts/merges.ts";
|
|
18
|
-
export type {
|
|
19
|
-
Admission,
|
|
20
|
-
Counts,
|
|
21
|
-
MergeCounts,
|
|
22
|
-
PerWindow,
|
|
23
|
-
Plan,
|
|
24
|
-
Priority,
|
|
25
|
-
RepoStarts,
|
|
26
|
-
StartRequest,
|
|
27
|
-
Window,
|
|
28
|
-
} from "./starts/budget.ts";
|
|
29
1
|
export { boatJobFindings, BOAT_JOBS_PER_RUN } from "./starts/policy.ts";
|
|
30
|
-
export type { Line } from "./starts/budget.ts";
|
|
31
|
-
|
|
32
|
-
export class StartHeld extends Schema.TaggedError<
|
|
33
|
-
StartHeld,
|
|
34
|
-
{ readonly brand: unique symbol }
|
|
35
|
-
>()("StartHeld", {
|
|
36
|
-
line: Line,
|
|
37
|
-
}) {}
|
|
38
|
-
|
|
39
|
-
export const admitStart = Effect.fn("Starts.admitStart")(function* <A, E, R>(
|
|
40
|
-
request: StartRequest,
|
|
41
|
-
start: Effect.Effect<A, E, R>,
|
|
42
|
-
{ deadline }: { readonly deadline: number }
|
|
43
|
-
) {
|
|
44
|
-
const boat = yield* BoatStarts;
|
|
45
|
-
const merges = yield* Merges;
|
|
46
|
-
let last: Line = {
|
|
47
|
-
_tag: "Unread",
|
|
48
|
-
reason: "start deadline reached",
|
|
49
|
-
};
|
|
50
|
-
for (;;) {
|
|
51
|
-
const remaining = deadline - (yield* Clock.currentTimeMillis);
|
|
52
|
-
if (!Number.isFinite(remaining) || remaining <= 0)
|
|
53
|
-
return yield* new StartHeld({ line: last });
|
|
54
|
-
const counts = yield* Effect.gen(function* () {
|
|
55
|
-
const plan = yield* boat.plan;
|
|
56
|
-
if (sharedWindows(request, plan).length === 0)
|
|
57
|
-
return { now: yield* Clock.currentTimeMillis, plan };
|
|
58
|
-
const repo = yield* boat
|
|
59
|
-
.repoStarts(request.repo)
|
|
60
|
-
.pipe(Effect.catchTag("StartReadError", () => Effect.undefined));
|
|
61
|
-
const history = yield* merges.counts.pipe(
|
|
62
|
-
Effect.catchTag("StartReadError", () => Effect.undefined)
|
|
63
|
-
);
|
|
64
|
-
return {
|
|
65
|
-
now: yield* Clock.currentTimeMillis,
|
|
66
|
-
plan,
|
|
67
|
-
repo,
|
|
68
|
-
merges: history,
|
|
69
|
-
};
|
|
70
|
-
}).pipe(
|
|
71
|
-
Effect.catchTag("StartReadError", () => Effect.undefined),
|
|
72
|
-
Effect.timeoutOrElse({
|
|
73
|
-
duration: remaining,
|
|
74
|
-
orElse: () => Effect.fail(new StartHeld({ line: last })),
|
|
75
|
-
})
|
|
76
|
-
);
|
|
77
|
-
const now = yield* Clock.currentTimeMillis;
|
|
78
|
-
const decision = decide(request, counts, now);
|
|
79
|
-
if (decision._tag === "Hold")
|
|
80
|
-
return yield* new StartHeld({ line: decision.line });
|
|
81
|
-
if (!Number.isFinite(deadline) || now >= deadline)
|
|
82
|
-
return yield* new StartHeld({
|
|
83
|
-
line:
|
|
84
|
-
decision._tag === "Wait"
|
|
85
|
-
? decision.line
|
|
86
|
-
: { _tag: "Unread", reason: "start deadline reached" },
|
|
87
|
-
});
|
|
88
|
-
if (decision._tag === "Admit") return yield* start;
|
|
89
|
-
last = decision.line;
|
|
90
|
-
const window =
|
|
91
|
-
decision.line._tag === "Account" || decision.line._tag === "Budget"
|
|
92
|
-
? decision.line.window
|
|
93
|
-
: "minute";
|
|
94
|
-
yield* Effect.sleep(
|
|
95
|
-
Math.max(
|
|
96
|
-
0,
|
|
97
|
-
Math.min(decision.until, now + pollMillis[window], deadline) - now
|
|
98
|
-
)
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
});
|
package/src/versions.ts
CHANGED
|
@@ -18,18 +18,18 @@ export type Fixed = {
|
|
|
18
18
|
readonly by: string;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export const nodeVersion = "26.13.
|
|
21
|
+
export const nodeVersion = "26.13.1";
|
|
22
22
|
|
|
23
23
|
export const families: ReadonlyArray<Family> = [
|
|
24
24
|
{
|
|
25
25
|
name: "vite-plus",
|
|
26
|
-
version: "1.
|
|
26
|
+
version: "1.6.0",
|
|
27
27
|
packages: ["vite-plus"],
|
|
28
28
|
scopes: [],
|
|
29
29
|
},
|
|
30
30
|
{
|
|
31
31
|
name: "alchemy",
|
|
32
|
-
version: "2.0.0-beta.
|
|
32
|
+
version: "2.0.0-beta.87",
|
|
33
33
|
packages: [
|
|
34
34
|
"@alchemy.run/domain",
|
|
35
35
|
"alchemy",
|
|
@@ -64,7 +64,7 @@ export const families: ReadonlyArray<Family> = [
|
|
|
64
64
|
},
|
|
65
65
|
{
|
|
66
66
|
name: "effect",
|
|
67
|
-
version: "4.1.
|
|
67
|
+
version: "4.1.4",
|
|
68
68
|
packages: [
|
|
69
69
|
"effect",
|
|
70
70
|
"@effect/platform-browser",
|
|
@@ -77,13 +77,13 @@ export const families: ReadonlyArray<Family> = [
|
|
|
77
77
|
},
|
|
78
78
|
{
|
|
79
79
|
name: "@effect/tsgo",
|
|
80
|
-
version: "0.
|
|
80
|
+
version: "0.69.0",
|
|
81
81
|
packages: ["@effect/tsgo"],
|
|
82
82
|
scopes: [],
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
85
|
name: "ultracite",
|
|
86
|
-
version: "8.
|
|
86
|
+
version: "8.2.1",
|
|
87
87
|
packages: ["ultracite"],
|
|
88
88
|
scopes: [],
|
|
89
89
|
},
|
|
@@ -95,7 +95,7 @@ export const families: ReadonlyArray<Family> = [
|
|
|
95
95
|
},
|
|
96
96
|
{
|
|
97
97
|
name: "effect-oxlint",
|
|
98
|
-
version: "0.
|
|
98
|
+
version: "0.5.1",
|
|
99
99
|
packages: ["effect-oxlint"],
|
|
100
100
|
scopes: [],
|
|
101
101
|
},
|
|
@@ -108,14 +108,14 @@ export const families: ReadonlyArray<Family> = [
|
|
|
108
108
|
];
|
|
109
109
|
|
|
110
110
|
export const fixed: ReadonlyArray<Fixed> = [
|
|
111
|
-
{ name: "oxlint", version: "1.
|
|
112
|
-
{ name: "@oxlint/plugins", version: "1.
|
|
113
|
-
{ name: "oxlint-tsgolint", version: "7.0.
|
|
114
|
-
{ name: "oxfmt", version: "0.
|
|
111
|
+
{ name: "oxlint", version: "1.93.0", by: "vite-plus" },
|
|
112
|
+
{ name: "@oxlint/plugins", version: "1.93.0", by: "vite-plus" },
|
|
113
|
+
{ name: "oxlint-tsgolint", version: "7.0.2006", by: "vite-plus" },
|
|
114
|
+
{ name: "oxfmt", version: "0.78.0", by: "vite-plus" },
|
|
115
115
|
{ name: "vitest", version: "5.1.0", by: "vite-plus" },
|
|
116
116
|
{
|
|
117
117
|
name: "vite",
|
|
118
|
-
version: "npm:@voidzero-dev/vite-plus-core@1.
|
|
118
|
+
version: "npm:@voidzero-dev/vite-plus-core@1.6.0",
|
|
119
119
|
by: "vite-plus",
|
|
120
120
|
},
|
|
121
121
|
];
|
package/src/starts/boat.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import { BoatApi, CiJobState, Configuration } from "@boatdev/sdk";
|
|
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 {
|
|
10
|
-
type Plan,
|
|
11
|
-
type Repo,
|
|
12
|
-
type RepoStarts,
|
|
13
|
-
windowMillis,
|
|
14
|
-
} from "./budget.ts";
|
|
15
|
-
|
|
16
|
-
export class StartReadError extends Schema.TaggedError<
|
|
17
|
-
StartReadError,
|
|
18
|
-
{ readonly brand: unique symbol }
|
|
19
|
-
>()("StartReadError", { reason: Schema.String }) {}
|
|
20
|
-
|
|
21
|
-
const Count = Schema.Number.check(
|
|
22
|
-
Schema.makeFilter((value) => Number.isSafeInteger(value) && value >= 0)
|
|
23
|
-
);
|
|
24
|
-
const Usage = Schema.Struct({ limit: Count, used: Count });
|
|
25
|
-
const Limits = Schema.Struct({
|
|
26
|
-
ok: Schema.Literal(true),
|
|
27
|
-
starts: Schema.Struct({ minute: Usage, hour: Usage, day: Usage }),
|
|
28
|
-
nextStartDollars: Schema.optional(Schema.NullOr(Schema.Finite)),
|
|
29
|
-
});
|
|
30
|
-
const Ci = Schema.Struct({
|
|
31
|
-
ok: Schema.Literal(true),
|
|
32
|
-
jobs: Schema.Array(
|
|
33
|
-
Schema.Struct({
|
|
34
|
-
repo: Schema.String,
|
|
35
|
-
label: Schema.String,
|
|
36
|
-
state: Schema.String.check(Schema.isMinLength(1)),
|
|
37
|
-
queuedAt: Schema.Date,
|
|
38
|
-
runStartedAt: Schema.optional(Schema.NullOr(Schema.Date)),
|
|
39
|
-
finishedAt: Schema.optional(Schema.NullOr(Schema.Date)),
|
|
40
|
-
})
|
|
41
|
-
),
|
|
42
|
-
});
|
|
43
|
-
const settled = new Set<string>([
|
|
44
|
-
CiJobState.Success,
|
|
45
|
-
CiJobState.Failure,
|
|
46
|
-
CiJobState.Cancelled,
|
|
47
|
-
CiJobState.Skipped,
|
|
48
|
-
CiJobState.Failed,
|
|
49
|
-
CiJobState.Refused,
|
|
50
|
-
]);
|
|
51
|
-
|
|
52
|
-
export class BoatStarts extends Context.Service<
|
|
53
|
-
BoatStarts,
|
|
54
|
-
{
|
|
55
|
-
readonly plan: Effect.Effect<Plan, StartReadError>;
|
|
56
|
-
readonly repoStarts: (
|
|
57
|
-
repo: Repo
|
|
58
|
-
) => Effect.Effect<RepoStarts, StartReadError>;
|
|
59
|
-
}
|
|
60
|
-
>()("toolchain/BoatStarts") {
|
|
61
|
-
static readonly layer = (
|
|
62
|
-
key: Redacted.Redacted<string>,
|
|
63
|
-
options: {
|
|
64
|
-
readonly fetch?: (
|
|
65
|
-
url: string | URL | Request,
|
|
66
|
-
init?: RequestInit
|
|
67
|
-
) => Promise<Response>;
|
|
68
|
-
} = {}
|
|
69
|
-
) =>
|
|
70
|
-
Layer.sync(BoatStarts, () => {
|
|
71
|
-
const api = new BoatApi(
|
|
72
|
-
new Configuration({
|
|
73
|
-
accessToken: Redacted.value(key),
|
|
74
|
-
...(options.fetch === undefined ? {} : { fetchApi: options.fetch }),
|
|
75
|
-
})
|
|
76
|
-
);
|
|
77
|
-
const plan = Effect.gen(function* () {
|
|
78
|
-
const response = yield* Effect.tryPromise({
|
|
79
|
-
try: () => api.limits(),
|
|
80
|
-
catch: () =>
|
|
81
|
-
new StartReadError({ reason: "Boat limits request failed" }),
|
|
82
|
-
});
|
|
83
|
-
const limits = yield* Schema.decodeUnknownEffect(Limits)(response).pipe(
|
|
84
|
-
Effect.mapError(
|
|
85
|
-
() => new StartReadError({ reason: "Boat limits unread" })
|
|
86
|
-
)
|
|
87
|
-
);
|
|
88
|
-
return {
|
|
89
|
-
limits: {
|
|
90
|
-
minute: limits.starts.minute.limit,
|
|
91
|
-
hour: limits.starts.hour.limit,
|
|
92
|
-
day: limits.starts.day.limit,
|
|
93
|
-
},
|
|
94
|
-
used: {
|
|
95
|
-
minute: limits.starts.minute.used,
|
|
96
|
-
hour: limits.starts.hour.used,
|
|
97
|
-
day: limits.starts.day.used,
|
|
98
|
-
},
|
|
99
|
-
nextStartDollars: limits.nextStartDollars ?? undefined,
|
|
100
|
-
};
|
|
101
|
-
});
|
|
102
|
-
const repoStarts = Effect.fn("BoatStarts.repoStarts")(function* (
|
|
103
|
-
repo: Repo
|
|
104
|
-
) {
|
|
105
|
-
const response = yield* Effect.tryPromise({
|
|
106
|
-
try: () => api.getCiOverview({ repo, limit: 500 }),
|
|
107
|
-
catch: () => new StartReadError({ reason: "Boat CI request failed" }),
|
|
108
|
-
});
|
|
109
|
-
const now = yield* Clock.currentTimeMillis;
|
|
110
|
-
const { jobs } = yield* Schema.decodeUnknownEffect(Ci)(response).pipe(
|
|
111
|
-
Effect.mapError(
|
|
112
|
-
() => new StartReadError({ reason: "Boat CI history unread" })
|
|
113
|
-
)
|
|
114
|
-
);
|
|
115
|
-
if (jobs.some((job) => job.repo !== repo))
|
|
116
|
-
return yield* new StartReadError({
|
|
117
|
-
reason: "Boat CI history differs from request",
|
|
118
|
-
});
|
|
119
|
-
const oldest = Math.min(
|
|
120
|
-
...jobs.map((job) =>
|
|
121
|
-
Math.max(job.queuedAt.getTime(), job.runStartedAt?.getTime() ?? 0)
|
|
122
|
-
)
|
|
123
|
-
);
|
|
124
|
-
return {
|
|
125
|
-
repo,
|
|
126
|
-
starts: jobs.flatMap((job) => {
|
|
127
|
-
const at =
|
|
128
|
-
job.runStartedAt?.getTime() ??
|
|
129
|
-
(settled.has(job.state) ||
|
|
130
|
-
(job.finishedAt !== undefined && job.finishedAt !== null)
|
|
131
|
-
? undefined
|
|
132
|
-
: now);
|
|
133
|
-
return job.label.split("/")[0]?.startsWith("boat") === true &&
|
|
134
|
-
at !== undefined &&
|
|
135
|
-
at > now - windowMillis.day
|
|
136
|
-
? [Math.min(at, now)]
|
|
137
|
-
: [];
|
|
138
|
-
}),
|
|
139
|
-
complete: jobs.length < 500 || oldest <= now - windowMillis.day,
|
|
140
|
-
};
|
|
141
|
-
});
|
|
142
|
-
return BoatStarts.of({ plan, repoStarts });
|
|
143
|
-
});
|
|
144
|
-
}
|
package/src/starts/budget.ts
DELETED
|
@@ -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
|
-
};
|