@milkenjoyer/toolchain 0.13.0 → 0.14.1
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 +21 -1
- package/dist/formal.mjs +7 -120
- package/dist/guard.d.mts +2 -2
- package/dist/guard.mjs +1 -46
- package/dist/manifest-xQwgnYI1.mjs +53 -0
- package/dist/specs-file-NsQF4V7X.mjs +135 -0
- package/dist/standard.d.mts +2 -0
- package/dist/standard.mjs +398 -0
- package/package.json +4 -1
- package/src/formal/critical.ts +48 -0
- package/src/formal/proofs.ts +2 -45
- package/src/formal/specs-file.ts +119 -0
- package/src/formal/specs.ts +2 -112
- package/src/formal/z3.ts +18 -1
- package/src/standard/agents.ts +44 -0
- package/src/standard/checks.ts +19 -0
- package/src/standard/config.ts +110 -0
- package/src/standard/formal.ts +93 -0
- package/src/standard/manifest.ts +102 -0
- package/src/standard/plugin-skills.ts +88 -0
- package/src/standard/repo.ts +69 -0
- package/src/standard/toolchain.ts +90 -0
- package/src/standard.ts +71 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
import { n as criticalFindings, t as decode } from "./specs-file-NsQF4V7X.mjs";
|
|
3
|
+
import { n as exactFindings, r as manifestRanges, t as PLAIN } from "./manifest-xQwgnYI1.mjs";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import * as Effect from "effect/Effect";
|
|
6
|
+
import { NodeServices } from "@effect/platform-node";
|
|
7
|
+
import * as Cause from "effect/Cause";
|
|
8
|
+
import * as Console from "effect/Console";
|
|
9
|
+
import * as Exit from "effect/Exit";
|
|
10
|
+
import { ChildProcess } from "effect/process";
|
|
11
|
+
import * as Stream from "effect/Stream";
|
|
12
|
+
import { FileSystem } from "effect/FileSystem";
|
|
13
|
+
import { fileURLToPath } from "node:url";
|
|
14
|
+
import { Path } from "effect/Path";
|
|
15
|
+
// src/standard/plugin-skills.ts
|
|
16
|
+
const pluginSkills = {
|
|
17
|
+
"agent-kit": [
|
|
18
|
+
"alchemy-domain",
|
|
19
|
+
"animation-performance",
|
|
20
|
+
"better-accessibility",
|
|
21
|
+
"break-ui",
|
|
22
|
+
"coordinate",
|
|
23
|
+
"diagnosing-bugs",
|
|
24
|
+
"formal-bug-hunt",
|
|
25
|
+
"interface-review",
|
|
26
|
+
"report-loop",
|
|
27
|
+
"task-agents",
|
|
28
|
+
"testing",
|
|
29
|
+
"writing-for-agents"
|
|
30
|
+
],
|
|
31
|
+
pstack: [
|
|
32
|
+
"architect",
|
|
33
|
+
"arena",
|
|
34
|
+
"automate-me",
|
|
35
|
+
"benchmark-checklist",
|
|
36
|
+
"blast-radius",
|
|
37
|
+
"bro",
|
|
38
|
+
"correct",
|
|
39
|
+
"create-formal-verification-skill",
|
|
40
|
+
"create-verification-skill",
|
|
41
|
+
"figure-it-out",
|
|
42
|
+
"how",
|
|
43
|
+
"in-your-own-words",
|
|
44
|
+
"interrogate",
|
|
45
|
+
"ketchup",
|
|
46
|
+
"ketchup-video",
|
|
47
|
+
"maintain-formal-verification-skill",
|
|
48
|
+
"maintain-verification-skill",
|
|
49
|
+
"make-bot-ui",
|
|
50
|
+
"no-comments",
|
|
51
|
+
"poteto-help",
|
|
52
|
+
"poteto-mode",
|
|
53
|
+
"principle-attack-the-premise",
|
|
54
|
+
"principle-boundary-discipline",
|
|
55
|
+
"principle-build-the-lever",
|
|
56
|
+
"principle-encode-lessons-in-structure",
|
|
57
|
+
"principle-exhaust-the-design-space",
|
|
58
|
+
"principle-experience-first",
|
|
59
|
+
"principle-explain-the-number",
|
|
60
|
+
"principle-fix-root-causes",
|
|
61
|
+
"principle-foundational-thinking",
|
|
62
|
+
"principle-guard-the-context-window",
|
|
63
|
+
"principle-laziness-protocol",
|
|
64
|
+
"principle-make-operations-idempotent",
|
|
65
|
+
"principle-migrate-callers-then-delete-legacy-apis",
|
|
66
|
+
"principle-minimize-reader-load",
|
|
67
|
+
"principle-model-the-domain",
|
|
68
|
+
"principle-never-block-on-the-human",
|
|
69
|
+
"principle-outcome-oriented-execution",
|
|
70
|
+
"principle-prove-it-works",
|
|
71
|
+
"principle-redesign-from-first-principles",
|
|
72
|
+
"principle-separate-before-serializing-shared-state",
|
|
73
|
+
"principle-sequence-verifiable-units",
|
|
74
|
+
"principle-subtract-before-you-add",
|
|
75
|
+
"principle-test-behavior-not-implementation",
|
|
76
|
+
"principle-type-system-discipline",
|
|
77
|
+
"recall",
|
|
78
|
+
"reflect",
|
|
79
|
+
"setup-pstack",
|
|
80
|
+
"sharpen",
|
|
81
|
+
"show-me-your-work",
|
|
82
|
+
"statechart",
|
|
83
|
+
"swarm",
|
|
84
|
+
"tdd",
|
|
85
|
+
"teach",
|
|
86
|
+
"technical-writing",
|
|
87
|
+
"typescript-best-practices",
|
|
88
|
+
"unslop",
|
|
89
|
+
"why"
|
|
90
|
+
],
|
|
91
|
+
tstack: [
|
|
92
|
+
"babysit-pr",
|
|
93
|
+
"council",
|
|
94
|
+
"file-pr",
|
|
95
|
+
"full-send",
|
|
96
|
+
"full-stop",
|
|
97
|
+
"leaving-pr-comments",
|
|
98
|
+
"modernize",
|
|
99
|
+
"sol-loop",
|
|
100
|
+
"takeover"
|
|
101
|
+
],
|
|
102
|
+
effect: ["effect"]
|
|
103
|
+
};
|
|
104
|
+
// src/standard/repo.ts
|
|
105
|
+
var StandardError = class extends Schema.TaggedError()("StandardError", { message: Schema.String }) {};
|
|
106
|
+
const load = Effect.fn("standard.load")(function* (root) {
|
|
107
|
+
const fs = yield* FileSystem;
|
|
108
|
+
const path = yield* Path;
|
|
109
|
+
const git = yield* ChildProcess.make("git", ["ls-files", "-z"], {
|
|
110
|
+
cwd: root,
|
|
111
|
+
stdin: "ignore"
|
|
112
|
+
});
|
|
113
|
+
const [files, code] = yield* Effect.all([git.stdout.pipe(Stream.decodeText, Stream.mkString), git.exitCode], { concurrency: "unbounded" });
|
|
114
|
+
if (Number(code) !== 0) return yield* new StandardError({ message: "git ls-files failed" });
|
|
115
|
+
return {
|
|
116
|
+
root,
|
|
117
|
+
tracked: yield* Effect.filter(files.split("\0").filter(Boolean), (file) => fs.exists(path.join(root, file)))
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
const read = Effect.fn("standard.read")(function* (repo, file, parse) {
|
|
121
|
+
const fs = yield* FileSystem;
|
|
122
|
+
const path = yield* Path;
|
|
123
|
+
const failed = (message) => ({
|
|
124
|
+
ok: false,
|
|
125
|
+
findings: [{
|
|
126
|
+
file,
|
|
127
|
+
message
|
|
128
|
+
}]
|
|
129
|
+
});
|
|
130
|
+
if (!repo.tracked.includes(file)) return failed("track this file");
|
|
131
|
+
return yield* fs.readFileString(path.join(repo.root, file)).pipe(Effect.mapError(() => new StandardError({ message: "this file cannot be read" })), Effect.flatMap((text) => Effect.try({
|
|
132
|
+
try: () => parse(text),
|
|
133
|
+
catch: (error) => new StandardError({ message: `this file does not parse: ${String(error instanceof Error ? error.message : error).split("\n")[0]}` })
|
|
134
|
+
})), Effect.map((value) => ({
|
|
135
|
+
ok: true,
|
|
136
|
+
value
|
|
137
|
+
})), Effect.catchTag("StandardError", (error) => Effect.succeed(failed(error.message))));
|
|
138
|
+
});
|
|
139
|
+
// src/standard/agents.ts
|
|
140
|
+
const taskAgents = (repo) => Effect.gen(function* () {
|
|
141
|
+
const input = yield* read(repo, "AGENTS.md", (text) => text);
|
|
142
|
+
if (!input.ok) return input.findings;
|
|
143
|
+
const lines = input.value.split("\n");
|
|
144
|
+
const start = lines.findIndex((line) => /^## Task agents\s*$/u.test(line));
|
|
145
|
+
const section = [];
|
|
146
|
+
if (start !== -1) for (const line of lines.slice(start + 1)) {
|
|
147
|
+
if (/^#{1,6}\s/u.test(line)) break;
|
|
148
|
+
if (line.trim()) section.push(line.trim());
|
|
149
|
+
}
|
|
150
|
+
return section.length === 1 && section[0]?.includes("`agent-kit:task-agents`") === true ? [] : [{
|
|
151
|
+
file: "AGENTS.md",
|
|
152
|
+
message: "add a ## Task agents section containing only one line pointing to `agent-kit:task-agents`"
|
|
153
|
+
}];
|
|
154
|
+
});
|
|
155
|
+
const skillNames = (repo) => Effect.succeed(repo.tracked.flatMap((file) => {
|
|
156
|
+
const name = /^(?:\.agents|\.claude|\.codex)\/skills\/([^/]+)\/SKILL\.md$/u.exec(file)?.[1];
|
|
157
|
+
return name === void 0 ? [] : Object.entries(pluginSkills).flatMap(([plugin, names]) => names.includes(name) ? [{
|
|
158
|
+
file,
|
|
159
|
+
message: `shares its name with ${plugin}:${name}`
|
|
160
|
+
}] : []);
|
|
161
|
+
}));
|
|
162
|
+
// src/standard/config.ts
|
|
163
|
+
const lintFmt = (repo) => Effect.gen(function* () {
|
|
164
|
+
const path = yield* Path;
|
|
165
|
+
const roots = repo.tracked.filter((file) => /^vite\.config\.(?:ts|mts|js|mjs)$/u.test(file));
|
|
166
|
+
if (!roots.length) return [{
|
|
167
|
+
file: "vite.config.ts",
|
|
168
|
+
message: "track a root vite.config.ts, .mts, .js or .mjs"
|
|
169
|
+
}];
|
|
170
|
+
const pending = [...roots];
|
|
171
|
+
const visited = /* @__PURE__ */ new Set();
|
|
172
|
+
const imports = /* @__PURE__ */ new Set();
|
|
173
|
+
const findings = [];
|
|
174
|
+
const transpiler = new Bun.Transpiler({ loader: "ts" });
|
|
175
|
+
for (const file of pending) {
|
|
176
|
+
if (visited.has(file)) continue;
|
|
177
|
+
visited.add(file);
|
|
178
|
+
const input = yield* read(repo, file, (text) => transpiler.scanImports(text));
|
|
179
|
+
if (!input.ok) {
|
|
180
|
+
findings.push(...input.findings);
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
for (const item of input.value) {
|
|
184
|
+
imports.add(item.path);
|
|
185
|
+
if (!item.path.startsWith(".")) continue;
|
|
186
|
+
const stem = path.normalize(path.join(path.dirname(file), item.path));
|
|
187
|
+
const target = [
|
|
188
|
+
stem,
|
|
189
|
+
stem.replace(/\.(m?)js$/u, ".$1ts"),
|
|
190
|
+
...[
|
|
191
|
+
".ts",
|
|
192
|
+
".mts",
|
|
193
|
+
".js",
|
|
194
|
+
".mjs"
|
|
195
|
+
].map((ext) => stem + ext),
|
|
196
|
+
...[
|
|
197
|
+
"ts",
|
|
198
|
+
"mts",
|
|
199
|
+
"js",
|
|
200
|
+
"mjs"
|
|
201
|
+
].map((ext) => `${stem}/index.${ext}`)
|
|
202
|
+
].find((candidate) => repo.tracked.includes(candidate));
|
|
203
|
+
if (target !== void 0) pending.push(target);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
for (const area of ["lint", "fmt"]) {
|
|
207
|
+
const name = `@milkenjoyer/toolchain/${area}`;
|
|
208
|
+
if (!imports.has(name)) findings.push({
|
|
209
|
+
file: roots[0] ?? "vite.config.ts",
|
|
210
|
+
message: `import ${name} from the root Vite config or its relative imports`
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
return findings;
|
|
214
|
+
});
|
|
215
|
+
const Config = Schema.Struct({ extends: Schema.optionalKey(Schema.Union([Schema.String, Schema.Array(Schema.String)])) });
|
|
216
|
+
const tsconfig = (repo) => Effect.gen(function* () {
|
|
217
|
+
const path = yield* Path;
|
|
218
|
+
const pending = ["tsconfig.json"];
|
|
219
|
+
const visited = /* @__PURE__ */ new Set();
|
|
220
|
+
const findings = [];
|
|
221
|
+
let reached = false;
|
|
222
|
+
for (const file of pending) {
|
|
223
|
+
if (visited.has(file)) continue;
|
|
224
|
+
visited.add(file);
|
|
225
|
+
const input = yield* read(repo, file, (text) => Schema.decodeUnknownSync(Config)(Bun.JSONC.parse(text)));
|
|
226
|
+
if (!input.ok) {
|
|
227
|
+
findings.push(...input.findings);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const parents = typeof input.value.extends === "string" ? [input.value.extends] : input.value.extends ?? [];
|
|
231
|
+
for (const parent of parents) {
|
|
232
|
+
if (parent === "@milkenjoyer/toolchain/tsconfig.base.json") reached = true;
|
|
233
|
+
if (!parent.startsWith(".")) continue;
|
|
234
|
+
const stem = path.normalize(path.join(path.dirname(file), parent));
|
|
235
|
+
const target = [stem, `${stem}.json`].find((candidate) => repo.tracked.includes(candidate));
|
|
236
|
+
if (target !== void 0) pending.push(target);
|
|
237
|
+
else findings.push({
|
|
238
|
+
file: stem,
|
|
239
|
+
message: "track the relative tsconfig extends file"
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (!reached && !findings.length) findings.push({
|
|
244
|
+
file: "tsconfig.json",
|
|
245
|
+
message: "extend @milkenjoyer/toolchain/tsconfig.base.json through the extends chain"
|
|
246
|
+
});
|
|
247
|
+
return findings;
|
|
248
|
+
});
|
|
249
|
+
// src/standard/formal.ts
|
|
250
|
+
const specs = (repo) => Effect.gen(function* () {
|
|
251
|
+
if (!repo.tracked.includes("specs.json")) return [{
|
|
252
|
+
file: "specs.json",
|
|
253
|
+
message: "track specs.json with at least one spec entry"
|
|
254
|
+
}];
|
|
255
|
+
const input = yield* read(repo, "specs.json", decode);
|
|
256
|
+
if (!input.ok) return input.findings;
|
|
257
|
+
const { file, decodeErrors } = input.value;
|
|
258
|
+
if (decodeErrors.length) return decodeErrors.map((message) => ({
|
|
259
|
+
file: "specs.json",
|
|
260
|
+
message
|
|
261
|
+
}));
|
|
262
|
+
return [...Object.keys(file.specs).length ? [] : [{
|
|
263
|
+
file: "specs.json",
|
|
264
|
+
message: "add at least one spec entry"
|
|
265
|
+
}], ...criticalFindings({
|
|
266
|
+
tracked: repo.tracked,
|
|
267
|
+
file
|
|
268
|
+
})];
|
|
269
|
+
});
|
|
270
|
+
const Gates = {
|
|
271
|
+
if: Schema.optionalKey(Schema.Unknown),
|
|
272
|
+
"continue-on-error": Schema.optionalKey(Schema.Unknown)
|
|
273
|
+
};
|
|
274
|
+
const Workflow = Schema.Struct({ jobs: Schema.Record(Schema.String, Schema.Struct({
|
|
275
|
+
...Gates,
|
|
276
|
+
steps: Schema.optionalKey(Schema.Array(Schema.Struct({
|
|
277
|
+
...Gates,
|
|
278
|
+
run: Schema.optionalKey(Schema.String)
|
|
279
|
+
})))
|
|
280
|
+
})) });
|
|
281
|
+
const FALSE = /^\s*(?:\$\{\{\s*false\s*\}\}|false)\s*$/u;
|
|
282
|
+
const enforced = (gates) => gates.if !== false && !(typeof gates.if === "string" && FALSE.test(gates.if)) && (gates["continue-on-error"] === void 0 || gates["continue-on-error"] === false || typeof gates["continue-on-error"] === "string" && FALSE.test(gates["continue-on-error"]));
|
|
283
|
+
const readyFormal = (repo) => Effect.gen(function* () {
|
|
284
|
+
const file = [".github/workflows/ready.yml", ".github/workflows/ready.yaml"].find((name) => repo.tracked.includes(name));
|
|
285
|
+
if (file === void 0) return [{
|
|
286
|
+
file: ".github/workflows/ready.yml",
|
|
287
|
+
message: "track a ready workflow running vp exec formal"
|
|
288
|
+
}];
|
|
289
|
+
const input = yield* read(repo, file, (text) => Schema.decodeUnknownSync(Workflow)(Bun.YAML.parse(text)));
|
|
290
|
+
if (!input.ok) return input.findings;
|
|
291
|
+
return Object.values(input.value.jobs).some((job) => enforced(job) && (job.steps ?? []).some((step) => enforced(step) && (step.run ?? "").split("\n").some((line) => line.trim() === "vp exec formal"))) ? [] : [{
|
|
292
|
+
file,
|
|
293
|
+
message: "add a step with a vp exec formal line that no if: false or continue-on-error skips or ignores"
|
|
294
|
+
}];
|
|
295
|
+
});
|
|
296
|
+
// src/standard/toolchain.ts
|
|
297
|
+
const packageName = "@milkenjoyer/toolchain";
|
|
298
|
+
const pin = (repo) => Effect.gen(function* () {
|
|
299
|
+
const input = yield* read(repo, "package.json", manifestRanges);
|
|
300
|
+
if (!input.ok) return input.findings;
|
|
301
|
+
const groups = new Map(input.value);
|
|
302
|
+
const version = groups.get("dependencies")?.[packageName] ?? groups.get("devDependencies")?.[packageName];
|
|
303
|
+
const name = version?.startsWith("catalog:") === true ? version.slice(8) : void 0;
|
|
304
|
+
const resolved = name === void 0 ? version : name === "" ? groups.get("workspaces.catalog")?.[packageName] ?? groups.get("catalog")?.[packageName] : groups.get(`workspaces.catalogs.${name}`)?.[packageName] ?? groups.get(`catalogs.${name}`)?.[packageName];
|
|
305
|
+
return resolved !== void 0 && PLAIN.test(resolved) ? [] : [{
|
|
306
|
+
file: "package.json",
|
|
307
|
+
message: "pin @milkenjoyer/toolchain to an exact version or an exact catalog entry"
|
|
308
|
+
}];
|
|
309
|
+
});
|
|
310
|
+
const lintPackage = (repo) => Effect.succeed(["packages/lint", "packages/oxlint-standards"].filter((dir) => repo.tracked.some((file) => file.startsWith(`${dir}/`))).map((file) => ({
|
|
311
|
+
file,
|
|
312
|
+
message: "remove this repo-owned lint package"
|
|
313
|
+
})));
|
|
314
|
+
const nodeVersion = (repo) => Effect.gen(function* () {
|
|
315
|
+
const actual = yield* read(repo, ".node-version", (text) => text.trim());
|
|
316
|
+
if (!actual.ok) return actual.findings;
|
|
317
|
+
const expected = yield* (yield* FileSystem).readFileString(fileURLToPath(new URL("../../node-version", import.meta.url)));
|
|
318
|
+
return actual.value === expected.trim() ? [] : [{
|
|
319
|
+
file: ".node-version",
|
|
320
|
+
message: `set Node version to ${expected.trim()}`
|
|
321
|
+
}];
|
|
322
|
+
});
|
|
323
|
+
const Renovate = Schema.Struct({ extends: Schema.Array(Schema.String) });
|
|
324
|
+
const parseRenovate = Schema.decodeUnknownSync(Schema.fromJsonString(Renovate));
|
|
325
|
+
const renovate = (repo) => Effect.gen(function* () {
|
|
326
|
+
const input = yield* read(repo, "renovate.json", parseRenovate);
|
|
327
|
+
if (!input.ok) return input.findings;
|
|
328
|
+
const preset = "https://cdn.jsdelivr.net/npm/@milkenjoyer/toolchain/renovate.json";
|
|
329
|
+
return input.value.extends.includes(preset) ? [] : [{
|
|
330
|
+
file: "renovate.json",
|
|
331
|
+
message: `extend ${preset}`
|
|
332
|
+
}];
|
|
333
|
+
});
|
|
334
|
+
const exact = (repo) => Effect.gen(function* () {
|
|
335
|
+
const findings = [];
|
|
336
|
+
for (const file of repo.tracked.filter((f) => /(?:^|\/)package\.json$/u.test(f))) {
|
|
337
|
+
const input = yield* read(repo, file, (text) => exactFindings(file, text));
|
|
338
|
+
findings.push(...input.ok ? input.value.map((message) => ({
|
|
339
|
+
file,
|
|
340
|
+
message
|
|
341
|
+
})) : input.findings);
|
|
342
|
+
}
|
|
343
|
+
return findings;
|
|
344
|
+
});
|
|
345
|
+
// src/standard/checks.ts
|
|
346
|
+
const rules = {
|
|
347
|
+
"toolchain-pin": pin,
|
|
348
|
+
"lint-package": lintPackage,
|
|
349
|
+
"lint-fmt": lintFmt,
|
|
350
|
+
"tsconfig-base": tsconfig,
|
|
351
|
+
"node-version": nodeVersion,
|
|
352
|
+
"renovate-preset": renovate,
|
|
353
|
+
"exact-versions": exact,
|
|
354
|
+
specs,
|
|
355
|
+
"ready-formal": readyFormal,
|
|
356
|
+
"task-agents": taskAgents,
|
|
357
|
+
"skill-names": skillNames
|
|
358
|
+
};
|
|
359
|
+
// src/standard.ts
|
|
360
|
+
const singleLine = (message) => message.replaceAll(/\s+/gu, " ").trim();
|
|
361
|
+
const standard = Effect.fn("standard")(function* (root) {
|
|
362
|
+
const repo = yield* load(root);
|
|
363
|
+
const findings = [];
|
|
364
|
+
for (const [order, [name, rule]] of Object.entries(rules).entries()) {
|
|
365
|
+
const problems = yield* rule(repo);
|
|
366
|
+
findings.push(...problems.map((problem) => ({
|
|
367
|
+
...problem,
|
|
368
|
+
rule: name,
|
|
369
|
+
order
|
|
370
|
+
})));
|
|
371
|
+
}
|
|
372
|
+
findings.sort((a, b) => a.file.localeCompare(b.file) || a.order - b.order);
|
|
373
|
+
if (findings.length) {
|
|
374
|
+
for (const f of findings) yield* Console.error(`${f.file}: ${f.rule}: ${singleLine(f.message)}`);
|
|
375
|
+
yield* Console.error(`standard: ${findings.length} ${findings.length === 1 ? "finding" : "findings"}`);
|
|
376
|
+
} else yield* Console.log(`standard: ${Object.keys(rules).length} rules, no findings`);
|
|
377
|
+
return findings.length ? 1 : 0;
|
|
378
|
+
});
|
|
379
|
+
if (import.meta.main) {
|
|
380
|
+
if (process.argv.length > 2) {
|
|
381
|
+
process.stderr.write("usage: standard\n");
|
|
382
|
+
process.exitCode = 2;
|
|
383
|
+
} else {
|
|
384
|
+
const exit = await Effect.runPromiseExit(Effect.scoped(Effect.gen(function* () {
|
|
385
|
+
const git = yield* ChildProcess.make("git", ["rev-parse", "--show-toplevel"], { stdin: "ignore" });
|
|
386
|
+
const [root, code] = yield* Effect.all([git.stdout.pipe(Stream.decodeText, Stream.mkString), git.exitCode], { concurrency: "unbounded" });
|
|
387
|
+
if (Number(code) !== 0) return yield* new StandardError({ message: "run standard inside a git repository" });
|
|
388
|
+
return yield* standard(root.trim());
|
|
389
|
+
})).pipe(Effect.provide(NodeServices.layer)));
|
|
390
|
+
if (Exit.isSuccess(exit)) process.exitCode = exit.value;
|
|
391
|
+
else {
|
|
392
|
+
const error = Cause.squash(exit.cause);
|
|
393
|
+
process.stderr.write(`standard: ${singleLine(error instanceof Error ? error.message : String(error))}\n`);
|
|
394
|
+
process.exitCode = 1;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
export { standard };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkenjoyer/toolchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/birbprophet/agent-kit.git",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"bin": {
|
|
10
10
|
"formal": "./src/formal.ts",
|
|
11
11
|
"proof": "./src/proof.ts",
|
|
12
|
+
"standard": "./src/standard.ts",
|
|
12
13
|
"verdict": "./src/verdict.ts",
|
|
13
14
|
"verification": "./src/verification.ts"
|
|
14
15
|
},
|
|
@@ -20,6 +21,8 @@
|
|
|
20
21
|
"src/formal.ts",
|
|
21
22
|
"src/formal/",
|
|
22
23
|
"src/proof.ts",
|
|
24
|
+
"src/standard.ts",
|
|
25
|
+
"src/standard/",
|
|
23
26
|
"src/verdict.ts",
|
|
24
27
|
"src/verification.ts",
|
|
25
28
|
"tsconfig.base.json",
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { SpecsFile } from "./specs-file.ts";
|
|
2
|
+
const matches = (glob: string, file: string) => new Bun.Glob(glob).match(file);
|
|
3
|
+
export const criticalFindings = (repo: {
|
|
4
|
+
readonly tracked: ReadonlyArray<string>;
|
|
5
|
+
readonly file: SpecsFile;
|
|
6
|
+
}) => [
|
|
7
|
+
...repo.file.critical.flatMap((glob) =>
|
|
8
|
+
repo.tracked.some((f) => matches(glob, f))
|
|
9
|
+
? []
|
|
10
|
+
: [
|
|
11
|
+
{
|
|
12
|
+
file: "specs.json",
|
|
13
|
+
message: `critical glob ${glob} matches no tracked file`,
|
|
14
|
+
},
|
|
15
|
+
]
|
|
16
|
+
),
|
|
17
|
+
...Object.entries({
|
|
18
|
+
...repo.file.specs,
|
|
19
|
+
...repo.file.kani,
|
|
20
|
+
...repo.file.proofs,
|
|
21
|
+
}).flatMap(([file, e]) =>
|
|
22
|
+
e.covers.flatMap((glob) =>
|
|
23
|
+
repo.tracked.some((f) => matches(glob, f))
|
|
24
|
+
? []
|
|
25
|
+
: [{ file, message: `covers glob ${glob} matches no tracked file` }]
|
|
26
|
+
)
|
|
27
|
+
),
|
|
28
|
+
...repo.tracked.flatMap((file) => {
|
|
29
|
+
const glob = repo.file.critical.find((g) => matches(g, file));
|
|
30
|
+
return glob !== undefined &&
|
|
31
|
+
!Object.values({
|
|
32
|
+
...repo.file.specs,
|
|
33
|
+
...repo.file.kani,
|
|
34
|
+
...repo.file.proofs,
|
|
35
|
+
}).some(
|
|
36
|
+
(e) =>
|
|
37
|
+
(!("mode" in e) || e.mode !== "library") &&
|
|
38
|
+
e.covers.some((g) => matches(g, file))
|
|
39
|
+
)
|
|
40
|
+
? [
|
|
41
|
+
{
|
|
42
|
+
file,
|
|
43
|
+
message: `matches critical glob ${glob} but no spec covers it`,
|
|
44
|
+
},
|
|
45
|
+
]
|
|
46
|
+
: [];
|
|
47
|
+
}),
|
|
48
|
+
];
|
package/src/formal/proofs.ts
CHANGED
|
@@ -5,55 +5,12 @@ import * as Effect from "effect/Effect";
|
|
|
5
5
|
import { FileSystem } from "effect/FileSystem";
|
|
6
6
|
|
|
7
7
|
import type { Check } from "./checks.ts";
|
|
8
|
+
import { criticalFindings } from "./critical.ts";
|
|
8
9
|
import { Gate } from "./gate.ts";
|
|
9
10
|
import { changes } from "./git.ts";
|
|
10
11
|
import { FormalError } from "./tla.ts";
|
|
11
12
|
import { held, violate } from "./violations.ts";
|
|
12
|
-
const
|
|
13
|
-
export const critical: Check = (repo) =>
|
|
14
|
-
Effect.succeed([
|
|
15
|
-
...repo.file.critical.flatMap((glob) =>
|
|
16
|
-
repo.tracked.some((f) => matches(glob, f))
|
|
17
|
-
? []
|
|
18
|
-
: [
|
|
19
|
-
{
|
|
20
|
-
file: "specs.json",
|
|
21
|
-
message: `critical glob ${glob} matches no tracked file`,
|
|
22
|
-
},
|
|
23
|
-
]
|
|
24
|
-
),
|
|
25
|
-
...Object.entries({
|
|
26
|
-
...repo.file.specs,
|
|
27
|
-
...repo.file.kani,
|
|
28
|
-
...repo.file.proofs,
|
|
29
|
-
}).flatMap(([file, e]) =>
|
|
30
|
-
e.covers.flatMap((glob) =>
|
|
31
|
-
repo.tracked.some((f) => matches(glob, f))
|
|
32
|
-
? []
|
|
33
|
-
: [{ file, message: `covers glob ${glob} matches no tracked file` }]
|
|
34
|
-
)
|
|
35
|
-
),
|
|
36
|
-
...repo.tracked.flatMap((file) => {
|
|
37
|
-
const glob = repo.file.critical.find((g) => matches(g, file));
|
|
38
|
-
return glob !== undefined &&
|
|
39
|
-
!Object.values({
|
|
40
|
-
...repo.file.specs,
|
|
41
|
-
...repo.file.kani,
|
|
42
|
-
...repo.file.proofs,
|
|
43
|
-
}).some(
|
|
44
|
-
(e) =>
|
|
45
|
-
(!("mode" in e) || e.mode !== "library") &&
|
|
46
|
-
e.covers.some((g) => matches(g, file))
|
|
47
|
-
)
|
|
48
|
-
? [
|
|
49
|
-
{
|
|
50
|
-
file,
|
|
51
|
-
message: `matches critical glob ${glob} but no spec covers it`,
|
|
52
|
-
},
|
|
53
|
-
]
|
|
54
|
-
: [];
|
|
55
|
-
}),
|
|
56
|
-
]);
|
|
13
|
+
export const critical: Check = (repo) => Effect.succeed(criticalFindings(repo));
|
|
57
14
|
export const fairness: Check = (repo) =>
|
|
58
15
|
Effect.succeed(
|
|
59
16
|
repo.specs.flatMap((s) =>
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import * as Effect from "effect/Effect";
|
|
2
|
+
import * as Result from "effect/Result";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import * as SchemaIssue from "effect/SchemaIssue";
|
|
5
|
+
|
|
6
|
+
const RepoPath = Schema.String.check(
|
|
7
|
+
Schema.isPattern(/^(?!\/)(?!(?:.*\/)?\.\.(?:\/|$))[^\0\\]+$/u)
|
|
8
|
+
);
|
|
9
|
+
const OperatorName = Schema.String.check(
|
|
10
|
+
Schema.isPattern(/^[A-Za-z_][A-Za-z0-9_]*$/u)
|
|
11
|
+
);
|
|
12
|
+
const Common = {
|
|
13
|
+
synced: Schema.String.check(Schema.isPattern(/^[0-9a-f]{40}$/u)),
|
|
14
|
+
covers: Schema.NonEmptyArray(Schema.NonEmptyString),
|
|
15
|
+
};
|
|
16
|
+
const Runtime = {
|
|
17
|
+
...Common,
|
|
18
|
+
timeoutSeconds: Schema.Int.check(
|
|
19
|
+
Schema.isBetween({ minimum: 1, maximum: 1800 })
|
|
20
|
+
).pipe(Schema.withDecodingDefaultKey(Effect.succeed(60))),
|
|
21
|
+
};
|
|
22
|
+
const Proof = {
|
|
23
|
+
...Runtime,
|
|
24
|
+
witnesses: Schema.NonEmptyArray(OperatorName).check(
|
|
25
|
+
Schema.makeFilter(
|
|
26
|
+
(names) =>
|
|
27
|
+
new Set(names).size === names.length || "witnesses must be unique"
|
|
28
|
+
)
|
|
29
|
+
),
|
|
30
|
+
breaks: Schema.Array(
|
|
31
|
+
Schema.Struct({
|
|
32
|
+
violates: OperatorName,
|
|
33
|
+
find: Schema.NonEmptyString,
|
|
34
|
+
replace: Schema.String,
|
|
35
|
+
file: Schema.optionalKey(RepoPath),
|
|
36
|
+
})
|
|
37
|
+
).pipe(Schema.withDecodingDefaultKey(Effect.succeed([]))),
|
|
38
|
+
};
|
|
39
|
+
export const Entry = Schema.Union([
|
|
40
|
+
Schema.Struct({
|
|
41
|
+
...Proof,
|
|
42
|
+
mode: Schema.Literal("gate"),
|
|
43
|
+
traces: Schema.optionalKey(
|
|
44
|
+
Schema.Struct({
|
|
45
|
+
seed: Schema.Int.check(Schema.isGreaterThanOrEqualTo(0)),
|
|
46
|
+
depth: Schema.Int.check(
|
|
47
|
+
Schema.isBetween({ minimum: 1, maximum: 10000 })
|
|
48
|
+
),
|
|
49
|
+
count: Schema.Int.check(
|
|
50
|
+
Schema.isBetween({ minimum: 1, maximum: 100000 })
|
|
51
|
+
),
|
|
52
|
+
steer: Schema.optionalKey(
|
|
53
|
+
Schema.Record(
|
|
54
|
+
OperatorName,
|
|
55
|
+
Schema.Int.check(Schema.isBetween({ minimum: 2, maximum: 1000 }))
|
|
56
|
+
)
|
|
57
|
+
),
|
|
58
|
+
conformance: RepoPath,
|
|
59
|
+
})
|
|
60
|
+
),
|
|
61
|
+
}),
|
|
62
|
+
Schema.Struct({ ...Proof, mode: Schema.Literal("manual") }),
|
|
63
|
+
Schema.Struct({ ...Common, mode: Schema.Literal("library") }),
|
|
64
|
+
]);
|
|
65
|
+
const ArithmeticCommon = {
|
|
66
|
+
covers: Common.covers,
|
|
67
|
+
timeoutSeconds: Runtime.timeoutSeconds,
|
|
68
|
+
breaks: Schema.NonEmptyArray(
|
|
69
|
+
Schema.Struct({
|
|
70
|
+
file: RepoPath,
|
|
71
|
+
find: Schema.NonEmptyString,
|
|
72
|
+
replace: Schema.String,
|
|
73
|
+
})
|
|
74
|
+
),
|
|
75
|
+
};
|
|
76
|
+
const ArithmeticProof = Schema.Union([
|
|
77
|
+
Schema.Struct({ ...ArithmeticCommon, kind: Schema.Literal("every") }),
|
|
78
|
+
Schema.Struct({
|
|
79
|
+
...ArithmeticCommon,
|
|
80
|
+
kind: Schema.Literal("z3"),
|
|
81
|
+
samples: Schema.Int.check(
|
|
82
|
+
Schema.isBetween({ minimum: 10000, maximum: 1000000 })
|
|
83
|
+
).pipe(Schema.withDecodingDefaultKey(Effect.succeed(10000))),
|
|
84
|
+
}),
|
|
85
|
+
]);
|
|
86
|
+
export const SpecsFile = Schema.Struct({
|
|
87
|
+
critical: Schema.NonEmptyArray(Schema.NonEmptyString),
|
|
88
|
+
arithmetic: Schema.optionalKey(Schema.Array(Schema.NonEmptyString)),
|
|
89
|
+
proofs: Schema.Record(
|
|
90
|
+
RepoPath.check(Schema.isPattern(/\.proof\.ts$/u)),
|
|
91
|
+
ArithmeticProof
|
|
92
|
+
).pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
|
|
93
|
+
specs: Schema.Record(RepoPath.check(Schema.isPattern(/\.tla$/u)), Entry),
|
|
94
|
+
kani: Schema.Record(
|
|
95
|
+
RepoPath.check(Schema.isPattern(/\.rs$/u)),
|
|
96
|
+
Schema.Struct({ ...Runtime, mode: Schema.Literals(["gate", "manual"]) })
|
|
97
|
+
).pipe(Schema.withDecodingDefaultKey(Effect.succeed({}))),
|
|
98
|
+
});
|
|
99
|
+
export type SpecsFile = Omit<typeof SpecsFile.Type, "critical"> & {
|
|
100
|
+
readonly critical: ReadonlyArray<string>;
|
|
101
|
+
};
|
|
102
|
+
export const decode = (raw: string) => {
|
|
103
|
+
let file: SpecsFile = { critical: [], specs: {}, kani: {}, proofs: {} };
|
|
104
|
+
let decodeErrors: ReadonlyArray<string> = [];
|
|
105
|
+
const decoded = Schema.decodeResult(Schema.fromJsonString(SpecsFile))(raw, {
|
|
106
|
+
errors: "all",
|
|
107
|
+
onExcessProperty: "error",
|
|
108
|
+
});
|
|
109
|
+
if (Result.isSuccess(decoded)) file = decoded.success;
|
|
110
|
+
else
|
|
111
|
+
decodeErrors = SchemaIssue.makeFormatterStandardSchemaV1()(
|
|
112
|
+
decoded.failure.issue
|
|
113
|
+
).issues.map(({ message, path: at = [] }) =>
|
|
114
|
+
at.length === 0
|
|
115
|
+
? message
|
|
116
|
+
: `${at.map((key) => `[${JSON.stringify(typeof key === "object" ? key.key : key)}]`).join("")}: ${message}`
|
|
117
|
+
);
|
|
118
|
+
return { file, decodeErrors };
|
|
119
|
+
};
|