eutaxy 0.10.0 → 0.12.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 -10
- package/dist/aws.mjs +2 -2
- package/dist/bin.mjs +2 -2
- package/dist/{checksum-DHr5qb3Y.mjs → checksum-DJbbDJA0.mjs} +3 -3
- package/dist/{checksum-DHr5qb3Y.mjs.map → checksum-DJbbDJA0.mjs.map} +1 -1
- package/dist/cli-BFTyLLRF.mjs +2 -0
- package/dist/cli.d.mts.map +1 -1
- package/dist/cli.mjs +2 -2
- package/dist/cloudflare.mjs +1 -1
- package/dist/{event-streams-i8OGzuFN.mjs → event-streams-eH6Jim9p.mjs} +2 -2
- package/dist/{event-streams-i8OGzuFN.mjs.map → event-streams-eH6Jim9p.mjs.map} +1 -1
- package/dist/index.d.mts +14 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/src-CWVQEhTr.mjs.map +1 -1
- package/dist/{src-MX90l1IH.mjs → src-DIG0_CjU.mjs} +1380 -48
- package/dist/src-DIG0_CjU.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/cli-Di86EM3f.mjs +0 -2
- package/dist/src-MX90l1IH.mjs.map +0 -1
|
@@ -4,14 +4,18 @@ import { _ as endpointNumber, a as renderText, b as describeVerdict, c as aggreg
|
|
|
4
4
|
import { n as isSpec } from "./combinators-CVjxodAJ.mjs";
|
|
5
5
|
import { createRequire, registerHooks } from "node:module";
|
|
6
6
|
import { fork, spawn } from "node:child_process";
|
|
7
|
-
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs";
|
|
8
|
-
import { basename, dirname, join, relative, resolve } from "node:path";
|
|
7
|
+
import { chmodSync, closeSync, copyFileSync, createReadStream, existsSync, mkdirSync, mkdtempSync, openSync, readFileSync, readdirSync, renameSync, rmSync, symlinkSync, writeFileSync, writeSync } from "node:fs";
|
|
8
|
+
import { basename, dirname, join, relative, resolve, sep } from "node:path";
|
|
9
9
|
import { InternalSymbolName, ModifierFlags, NodeFlags, SyntaxKind, forEachLeadingCommentRange, forEachTrailingCommentRange } from "typescript/ast";
|
|
10
10
|
import { createFileSystemLayer } from "typescript/fs";
|
|
11
11
|
import { API, DiagnosticCategory, SymbolFlags, TypeFlags, TypeFormatFlags } from "typescript/sync";
|
|
12
12
|
import * as is from "typescript/ast/is";
|
|
13
13
|
import { homedir, tmpdir } from "node:os";
|
|
14
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
14
15
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
16
|
+
import { Readable } from "node:stream";
|
|
17
|
+
import { createZstdDecompress, inflateRawSync } from "node:zlib";
|
|
18
|
+
import { createInterface } from "node:readline";
|
|
15
19
|
// packages/cli/src/args.ts
|
|
16
20
|
function parseArgs(argv, booleans = []) {
|
|
17
21
|
const positionals = [];
|
|
@@ -4019,14 +4023,90 @@ function leanString(value) {
|
|
|
4019
4023
|
}
|
|
4020
4024
|
return `${out}"`;
|
|
4021
4025
|
}
|
|
4026
|
+
// packages/prover/src/toolchain.ts
|
|
4027
|
+
/**
|
|
4028
|
+
* Where a pinned prover toolchain lives on this machine once `eutaxy prover
|
|
4029
|
+
* install` has put it there, and what that command downloads: one upstream
|
|
4030
|
+
* release file per platform, with the checksum the download must match.
|
|
4031
|
+
* Node-side only (`@eutaxy/prover/toolchain`, a subpath so workerd never
|
|
4032
|
+
* loads it): it reads the file system, so this file alone references Node's
|
|
4033
|
+
* types, as the reader alone uses the compiler's. Nothing here downloads or
|
|
4034
|
+
* runs anything; the engines ask `installed` and the command does the rest.
|
|
4035
|
+
*/
|
|
4036
|
+
const platforms = [
|
|
4037
|
+
"linux-x64",
|
|
4038
|
+
"linux-arm64",
|
|
4039
|
+
"darwin-x64",
|
|
4040
|
+
"darwin-arm64",
|
|
4041
|
+
"win32-x64"
|
|
4042
|
+
];
|
|
4043
|
+
function host() {
|
|
4044
|
+
return {
|
|
4045
|
+
platform: process.platform,
|
|
4046
|
+
arch: process.arch,
|
|
4047
|
+
env: process.env,
|
|
4048
|
+
home: homedir()
|
|
4049
|
+
};
|
|
4050
|
+
}
|
|
4051
|
+
function platformOf(h) {
|
|
4052
|
+
const key = `${h.platform}-${h.arch}`;
|
|
4053
|
+
return platforms.includes(key) ? key : void 0;
|
|
4054
|
+
}
|
|
4055
|
+
/**
|
|
4056
|
+
* Eutaxy's cache directory: `EUTAXY_CACHE_DIR`, else the platform's user
|
|
4057
|
+
* cache (`$XDG_CACHE_HOME/eutaxy` or `~/.cache/eutaxy` on Linux,
|
|
4058
|
+
* `~/Library/Caches/eutaxy` on macOS, `%LOCALAPPDATA%\eutaxy\Cache` on
|
|
4059
|
+
* Windows). Always absolute: the engines spawn the executable from a
|
|
4060
|
+
* scratch directory, where a relative path would not resolve.
|
|
4061
|
+
*/
|
|
4062
|
+
function cacheDir(h = host()) {
|
|
4063
|
+
const set = h.env["EUTAXY_CACHE_DIR"];
|
|
4064
|
+
if (set) return resolve(set);
|
|
4065
|
+
if (h.platform === "darwin") return join(h.home, "Library", "Caches", "eutaxy");
|
|
4066
|
+
if (h.platform === "win32") return join(h.env["LOCALAPPDATA"] || join(h.home, "AppData", "Local"), "eutaxy", "Cache");
|
|
4067
|
+
return resolve(h.env["XDG_CACHE_HOME"] || join(h.home, ".cache"), "eutaxy");
|
|
4068
|
+
}
|
|
4069
|
+
/** Where one toolchain's unpacked release lives: `<cache>/toolchains/<name>/<version>`. */
|
|
4070
|
+
function toolchainDir(cache, toolchain) {
|
|
4071
|
+
return join(cache, "toolchains", toolchain.name, toolchain.version);
|
|
4072
|
+
}
|
|
4073
|
+
/** The file the command writes last, so its presence means the install completed. */
|
|
4074
|
+
const markerFile = "eutaxy-toolchain.json";
|
|
4075
|
+
function executableName(toolchain, h) {
|
|
4076
|
+
return h.platform === "win32" ? `${toolchain.executable}.exe` : toolchain.executable;
|
|
4077
|
+
}
|
|
4078
|
+
/**
|
|
4079
|
+
* The toolchain the command put in the cache, if its marker and its
|
|
4080
|
+
* executable are both there and the marker names this toolchain for this
|
|
4081
|
+
* platform (a cache carried to another machine holds the wrong binary).
|
|
4082
|
+
*/
|
|
4083
|
+
function installed(toolchain, h = host()) {
|
|
4084
|
+
const dir = toolchainDir(cacheDir(h), toolchain);
|
|
4085
|
+
const executable = join(dir, executableName(toolchain, h));
|
|
4086
|
+
const markerPath = join(dir, markerFile);
|
|
4087
|
+
if (!existsSync(markerPath) || !existsSync(executable)) return void 0;
|
|
4088
|
+
try {
|
|
4089
|
+
const marker = JSON.parse(readFileSync(markerPath, "utf8"));
|
|
4090
|
+
if (marker.name !== toolchain.name || marker.version !== toolchain.version || marker.platform !== platformOf(h) || typeof marker.file !== "string" || typeof marker.sha256 !== "string" || typeof marker.source !== "string") return void 0;
|
|
4091
|
+
return {
|
|
4092
|
+
dir,
|
|
4093
|
+
executable,
|
|
4094
|
+
marker
|
|
4095
|
+
};
|
|
4096
|
+
} catch {
|
|
4097
|
+
return;
|
|
4098
|
+
}
|
|
4099
|
+
}
|
|
4022
4100
|
// packages/prover-lean/src/lean.ts
|
|
4023
4101
|
/**
|
|
4024
4102
|
* Running Lean over a process boundary. The engine is pinned to one Lean
|
|
4025
|
-
* release
|
|
4026
|
-
*
|
|
4027
|
-
*
|
|
4028
|
-
*
|
|
4029
|
-
*
|
|
4103
|
+
* release, looked for in Eutaxy's cache first (where `eutaxy prover install
|
|
4104
|
+
* lean` puts the upstream release named in `leanDownloads`), then through
|
|
4105
|
+
* `elan` (Lean's toolchain manager), asked for it by name, then as a bare
|
|
4106
|
+
* `lean` that must report that version. Nothing is ever downloaded during
|
|
4107
|
+
* a check; a missing toolchain is `unavailable`, with the command that
|
|
4108
|
+
* installs it. Diagnostics come back as `file:line:col: severity: message`
|
|
4109
|
+
* lines, which the engine maps to theorems.
|
|
4030
4110
|
*/
|
|
4031
4111
|
/**
|
|
4032
4112
|
* The Lean release the engine's contract corpus is checked against. On a
|
|
@@ -4039,7 +4119,33 @@ function leanString(value) {
|
|
|
4039
4119
|
const leanToolchain = "leanprover/lean4:v4.35.0";
|
|
4040
4120
|
const leanVersion = "4.35.0";
|
|
4041
4121
|
/** How to put the pinned toolchain on this machine. */
|
|
4042
|
-
const installHint$1 = `install elan
|
|
4122
|
+
const installHint$1 = `run: eutaxy prover install lean (or install elan, https://elan.lean-lang.org, and run: elan toolchain install ${leanToolchain})`;
|
|
4123
|
+
const leanRelease = `https://github.com/leanprover/lean4/releases/download/v${leanVersion}`;
|
|
4124
|
+
const leanFile = (name, sha256, bytes) => ({
|
|
4125
|
+
file: name,
|
|
4126
|
+
url: `${leanRelease}/${name}`,
|
|
4127
|
+
sha256,
|
|
4128
|
+
bytes
|
|
4129
|
+
});
|
|
4130
|
+
/**
|
|
4131
|
+
* The upstream release files `eutaxy prover install lean` downloads, one per
|
|
4132
|
+
* platform, as published on Lean's GitHub release with the checksums it
|
|
4133
|
+
* reports; the file names carry the version, and a test holds them to
|
|
4134
|
+
* `leanVersion`. The compiler ships its C toolchain, so each is 570 to
|
|
4135
|
+
* 620 MB, the same download elan makes.
|
|
4136
|
+
*/
|
|
4137
|
+
const leanDownloads = {
|
|
4138
|
+
name: "lean",
|
|
4139
|
+
version: leanVersion,
|
|
4140
|
+
executable: "bin/lean",
|
|
4141
|
+
files: {
|
|
4142
|
+
"linux-x64": leanFile("lean-4.35.0-linux.tar.zst", "7289597a44543246c9227b8cae501767e095ce17f6d448b95fc4a8dc97268f6d", 594481375),
|
|
4143
|
+
"linux-arm64": leanFile("lean-4.35.0-linux_aarch64.tar.zst", "c8f0f8a3920e839718b1343e6781fd80a3e9b1024fbcd7078eb30f54e806b028", 594868592),
|
|
4144
|
+
"darwin-x64": leanFile("lean-4.35.0-darwin.tar.zst", "0b43be5c7ecfb36016566a41005ab62bdb04743e6bfd5837e45f796ef4750b4e", 576516478),
|
|
4145
|
+
"darwin-arm64": leanFile("lean-4.35.0-darwin_aarch64.tar.zst", "c0c6f34f35ba1dcc5c4a5fd106fefab9eb5e8469712624dd2c868d51b63177c2", 570422530),
|
|
4146
|
+
"win32-x64": leanFile("lean-4.35.0-windows.tar.zst", "893fde3f52b48c647e3edcf33844cbb61f8ef70fcd88e0536bfc83f29844081e", 622724192)
|
|
4147
|
+
}
|
|
4148
|
+
};
|
|
4043
4149
|
function run$1(command, args, options) {
|
|
4044
4150
|
return new Promise((resolve) => {
|
|
4045
4151
|
let child;
|
|
@@ -4106,15 +4212,29 @@ function candidates$1(name) {
|
|
|
4106
4212
|
return [name, join(home, "bin", name)];
|
|
4107
4213
|
}
|
|
4108
4214
|
/**
|
|
4109
|
-
* The pinned toolchain if it is installed:
|
|
4110
|
-
*
|
|
4111
|
-
*
|
|
4215
|
+
* The pinned toolchain if it is installed: the one `eutaxy prover install
|
|
4216
|
+
* lean` put in the cache, when it answers with the pinned version; else
|
|
4217
|
+
* through `elan run <toolchain>` when elan is present (and only when it
|
|
4218
|
+
* already has the toolchain, so nothing is downloaded); else a bare `lean`
|
|
4219
|
+
* of exactly that version.
|
|
4112
4220
|
*/
|
|
4113
|
-
async function findLean() {
|
|
4221
|
+
async function findLean(h = host()) {
|
|
4222
|
+
let cached;
|
|
4223
|
+
const fromCache = installed(leanDownloads, h);
|
|
4224
|
+
if (fromCache) {
|
|
4225
|
+
const v = await run$1(fromCache.executable, ["--version"], { timeoutMs: 2e4 });
|
|
4226
|
+
const m = /Lean \(version ([^,]+),/.exec(v.stdout);
|
|
4227
|
+
if (v.code === 0 && m?.[1] === "4.35.0") return {
|
|
4228
|
+
command: fromCache.executable,
|
|
4229
|
+
args: [],
|
|
4230
|
+
version: leanVersion
|
|
4231
|
+
};
|
|
4232
|
+
cached = `the toolchain in ${fromCache.dir} did not answer as Lean ${leanVersion} (delete it and run: eutaxy prover install lean)`;
|
|
4233
|
+
}
|
|
4114
4234
|
for (const elan of candidates$1("elan")) {
|
|
4115
4235
|
const list = await run$1(elan, ["toolchain", "list"], { timeoutMs: 2e4 });
|
|
4116
4236
|
if (list.code !== 0) continue;
|
|
4117
|
-
if (!list.stdout.split("\n").some((l) => l.trim().split(" ")[0] === "leanprover/lean4:v4.35.0")) return { unavailable: `elan has no ${leanToolchain};
|
|
4237
|
+
if (!list.stdout.split("\n").some((l) => l.trim().split(" ")[0] === "leanprover/lean4:v4.35.0")) return { unavailable: `elan has no ${leanToolchain}; ${installHint$1}${cached ? `; ${cached}` : ""}` };
|
|
4118
4238
|
return {
|
|
4119
4239
|
command: elan,
|
|
4120
4240
|
args: [
|
|
@@ -4134,9 +4254,9 @@ async function findLean() {
|
|
|
4134
4254
|
args: [],
|
|
4135
4255
|
version: leanVersion
|
|
4136
4256
|
};
|
|
4137
|
-
return { unavailable: `lean ${m?.[1] ?? "of unknown version"} found, but the engine is pinned to ${leanVersion}; ${installHint$1}` };
|
|
4257
|
+
return { unavailable: `lean ${m?.[1] ?? "of unknown version"} found, but the engine is pinned to ${leanVersion}; ${installHint$1}${cached ? `; ${cached}` : ""}` };
|
|
4138
4258
|
}
|
|
4139
|
-
return { unavailable: `no Lean toolchain found; ${installHint$1}` };
|
|
4259
|
+
return { unavailable: `no Lean toolchain found; ${installHint$1}${cached ? `; ${cached}` : ""}` };
|
|
4140
4260
|
}
|
|
4141
4261
|
/** Parse Lean's diagnostics for the one file it was given. */
|
|
4142
4262
|
/**
|
|
@@ -4192,6 +4312,9 @@ async function checkLean(toolchain, source, options = {}) {
|
|
|
4192
4312
|
}
|
|
4193
4313
|
}
|
|
4194
4314
|
// packages/prover-lean/src/supplied.ts
|
|
4315
|
+
/** The lines a goal file carries, and a proof file copied from one keeps, tying the proofs to the files they were written for. */
|
|
4316
|
+
const sourceHashMarker = "-- eutaxy-source-sha256: ";
|
|
4317
|
+
const specHashMarker = "-- eutaxy-spec-sha256: ";
|
|
4195
4318
|
/** The axioms a supplied proof may rest on: Lean's standard ones. */
|
|
4196
4319
|
const standardAxioms = /* @__PURE__ */ new Set([
|
|
4197
4320
|
"propext",
|
|
@@ -4313,10 +4436,18 @@ function readSupplied(file, text) {
|
|
|
4313
4436
|
file,
|
|
4314
4437
|
proofs
|
|
4315
4438
|
}, `${file} uses ${word}, which a supplied proof may not (it could add an axiom, switch a check off, run code while the file is checked or change how the statement reads)`);
|
|
4439
|
+
const hashLine = (marker) => {
|
|
4440
|
+
const hex = lemmas.find((l) => l.startsWith(marker))?.slice(marker.length).trim();
|
|
4441
|
+
return hex !== void 0 && /^[0-9a-f]{64}$/.test(hex) ? hex : void 0;
|
|
4442
|
+
};
|
|
4443
|
+
const sourceSha256 = hashLine(sourceHashMarker);
|
|
4444
|
+
const specSha256 = hashLine(specHashMarker);
|
|
4316
4445
|
return {
|
|
4317
4446
|
file,
|
|
4318
4447
|
lemmas: lemmas.join("\n").trim(),
|
|
4319
|
-
proofs: new Map([...proofs].map(([k, v]) => [k, v.join("\n").replace(/\s+$/, "")]))
|
|
4448
|
+
proofs: new Map([...proofs].map(([k, v]) => [k, v.join("\n").replace(/\s+$/, "")])),
|
|
4449
|
+
...sourceSha256 === void 0 ? {} : { sourceSha256 },
|
|
4450
|
+
...specSha256 === void 0 ? {} : { specSha256 }
|
|
4320
4451
|
};
|
|
4321
4452
|
}
|
|
4322
4453
|
/** The file refused: none of its proofs is used, and every property it names says why. */
|
|
@@ -4355,6 +4486,54 @@ function axiomsOf(messages, line, theorem) {
|
|
|
4355
4486
|
function provesExactly(messages, line, theorem) {
|
|
4356
4487
|
return onlyAt(messages, line) === `${theorem} : s_${theorem}`;
|
|
4357
4488
|
}
|
|
4489
|
+
// packages/prover-lean/src/goals.ts
|
|
4490
|
+
/** The proof file's name beside a spec file: `domain.props.lean` for `domain.props.ts`. */
|
|
4491
|
+
function proofFileFor(specFile) {
|
|
4492
|
+
return specFile.replace(/\.ts$/, ".lean");
|
|
4493
|
+
}
|
|
4494
|
+
/** The goal file's name beside a spec file: `domain.props.goals.lean` for `domain.props.ts`. */
|
|
4495
|
+
function goalFileFor(specFile) {
|
|
4496
|
+
return specFile.replace(/\.ts$/, ".goals.lean");
|
|
4497
|
+
}
|
|
4498
|
+
/** A line of generated commentary: one a proof file may hold, or a note that it was left out. */
|
|
4499
|
+
const commentLine = (text) => refusedIn(text) === void 0 ? text : "-- (a line left out: it held a word a proof file may not use)";
|
|
4500
|
+
const comment = (text) => text.split("\n").map((l) => commentLine(l.length > 0 ? `-- ${l}` : "--")).join("\n");
|
|
4501
|
+
/**
|
|
4502
|
+
* Render the goal file: the header with the hashes, each goal described
|
|
4503
|
+
* in comments (the proof file's lemma area, where comments cost nothing),
|
|
4504
|
+
* then one open `-- proof:` part per goal at the end, since everything
|
|
4505
|
+
* after a `-- proof:` line belongs to that proof. The text avoids every
|
|
4506
|
+
* word a supplied proof may not use, so the file copied as is reads as a
|
|
4507
|
+
* proof file with open proofs: every generated line is checked, and one
|
|
4508
|
+
* that would refuse the file (a reason Lean gave, a file or function name
|
|
4509
|
+
* that is itself a refused word) is left out, with a note in its place.
|
|
4510
|
+
* The function is named by its Lean identifier, as the statement names it.
|
|
4511
|
+
*/
|
|
4512
|
+
function renderGoals(input) {
|
|
4513
|
+
const header = [
|
|
4514
|
+
`-- Open proof goals for ${input.specFile}, written by Eutaxy's Lean engine (Lean ${leanVersion}).`,
|
|
4515
|
+
"-- Each goal below is a property the tactic script could not close, with the statement Eutaxy",
|
|
4516
|
+
"-- emits for it. To supply proofs, copy this file to",
|
|
4517
|
+
`-- ${proofFileFor(input.specFile)} beside the spec file, put lemmas above the \`-- proof:\` lines and`,
|
|
4518
|
+
"-- tactics under each, and run the engine again (eutaxy report --prover lean). The hashes tie the",
|
|
4519
|
+
"-- proofs to these versions of the module and the spec: once either changes, the proofs are stale",
|
|
4520
|
+
"-- until the goals are written again.",
|
|
4521
|
+
`${sourceHashMarker}${input.sourceSha256}`,
|
|
4522
|
+
`${specHashMarker}${input.specSha256}`
|
|
4523
|
+
];
|
|
4524
|
+
const described = input.goals.map((g) => [
|
|
4525
|
+
commentLine(`-- goal: ${g.property}, a property of ${ident$1.fn(g.function)}`),
|
|
4526
|
+
commentLine(`-- Lean said: ${g.reason}`),
|
|
4527
|
+
"-- statement:",
|
|
4528
|
+
comment(g.statement.replace(/^/gm, " "))
|
|
4529
|
+
].join("\n"));
|
|
4530
|
+
const open = input.goals.map((g) => `-- proof: ${g.property}\n -- tactics here`);
|
|
4531
|
+
return `${[
|
|
4532
|
+
header.map(commentLine).join("\n"),
|
|
4533
|
+
...described,
|
|
4534
|
+
...open
|
|
4535
|
+
].join("\n\n")}\n`;
|
|
4536
|
+
}
|
|
4358
4537
|
// packages/prover-lean/src/prove.ts
|
|
4359
4538
|
/**
|
|
4360
4539
|
* The engine: a module's functions through the subset reader, the emitter
|
|
@@ -4422,7 +4601,11 @@ function prepare$1(input) {
|
|
|
4422
4601
|
})));
|
|
4423
4602
|
const specErrors = specs.errors;
|
|
4424
4603
|
const proofFile = input.specPath?.replace(/\.ts$/, ".lean");
|
|
4425
|
-
|
|
4604
|
+
let supplied = proofFile !== void 0 && existsSync(proofFile) ? readSupplied(basename(proofFile), readFileSync(proofFile, "utf8")) : void 0;
|
|
4605
|
+
if (supplied && !supplied.refused) {
|
|
4606
|
+
const stale = staleness(supplied, input);
|
|
4607
|
+
if (stale !== void 0) supplied = refuse(supplied, stale);
|
|
4608
|
+
}
|
|
4426
4609
|
try {
|
|
4427
4610
|
return {
|
|
4428
4611
|
module,
|
|
@@ -4448,6 +4631,17 @@ function prepare$1(input) {
|
|
|
4448
4631
|
};
|
|
4449
4632
|
}
|
|
4450
4633
|
}
|
|
4634
|
+
const sha256 = (text) => createHash("sha256").update(text).digest("hex");
|
|
4635
|
+
/** Why a proof file is stale, when it names the hashes of the files it was written for and either moved. */
|
|
4636
|
+
function staleness(supplied, input) {
|
|
4637
|
+
const moved = [];
|
|
4638
|
+
if (supplied.sourceSha256 !== void 0 && supplied.sourceSha256 !== sha256(input.source)) moved.push("the module");
|
|
4639
|
+
if (supplied.specSha256 !== void 0 && input.specPath !== void 0 && existsSync(input.specPath)) {
|
|
4640
|
+
if (supplied.specSha256 !== sha256(readFileSync(input.specPath, "utf8"))) moved.push("the spec file");
|
|
4641
|
+
}
|
|
4642
|
+
if (moved.length === 0) return void 0;
|
|
4643
|
+
return `${supplied.file} is stale: ${moved.join(" and ")} changed since its proofs were written (the hashes it names no longer match); write the goals again and bring the proofs over`;
|
|
4644
|
+
}
|
|
4451
4645
|
/**
|
|
4452
4646
|
* A supplied proof's outcome: given up on when its lemmas or its tactics
|
|
4453
4647
|
* do not compile, or when it rests on an axiom beyond Lean's standard
|
|
@@ -4551,10 +4745,23 @@ async function proveModule$1(input) {
|
|
|
4551
4745
|
} : unknown$1("gave_up", `Lean could not close the proof: ${failed[0].message.split("\n")[0]}`)
|
|
4552
4746
|
});
|
|
4553
4747
|
}
|
|
4748
|
+
const goals = [];
|
|
4749
|
+
for (const fn of inSubset) for (const property of fn.properties) {
|
|
4750
|
+
if (property.kind !== "forall") continue;
|
|
4751
|
+
const r = results.find((x) => x.function === fn.name && x.property === property.name);
|
|
4752
|
+
if (r?.outcome.kind !== "UNKNOWN" || r.outcome.cause !== "gave_up") continue;
|
|
4753
|
+
goals.push({
|
|
4754
|
+
function: fn.name,
|
|
4755
|
+
property: property.name,
|
|
4756
|
+
statement: stated(property, module).text,
|
|
4757
|
+
reason: r.outcome.reason
|
|
4758
|
+
});
|
|
4759
|
+
}
|
|
4554
4760
|
return {
|
|
4555
4761
|
results,
|
|
4556
4762
|
lean,
|
|
4557
|
-
specErrors
|
|
4763
|
+
specErrors,
|
|
4764
|
+
goals
|
|
4558
4765
|
};
|
|
4559
4766
|
}
|
|
4560
4767
|
/** The engine as a `Prover`: available when the pinned toolchain is installed. */
|
|
@@ -5380,9 +5587,11 @@ function readAnswer(output) {
|
|
|
5380
5587
|
// packages/prover-smt/src/z3.ts
|
|
5381
5588
|
/**
|
|
5382
5589
|
* Running Z3 over a process boundary. The engine is pinned to one Z3
|
|
5383
|
-
* release
|
|
5384
|
-
*
|
|
5385
|
-
*
|
|
5590
|
+
* release, looked for in Eutaxy's cache first (where `eutaxy prover install
|
|
5591
|
+
* smt` puts the upstream release named in `z3Downloads`), then as a `z3`
|
|
5592
|
+
* on the PATH (or in Homebrew's and the usual local prefixes) that must
|
|
5593
|
+
* report that version. Nothing is downloaded during a check; a missing
|
|
5594
|
+
* solver is `unavailable`, with how to install it. Every
|
|
5386
5595
|
* run carries a resource limit, Z3's own machine-independent budget, so
|
|
5387
5596
|
* the same script gives the same outcome on every machine; a wall-clock
|
|
5388
5597
|
* timeout is only the safety net.
|
|
@@ -5390,7 +5599,32 @@ function readAnswer(output) {
|
|
|
5390
5599
|
/** The Z3 release the engine's contract corpus is checked against. */
|
|
5391
5600
|
const z3Version = "5.3.2";
|
|
5392
5601
|
/** How to put the pinned solver on this machine. */
|
|
5393
|
-
const installHint = `install Z3 ${z3Version}
|
|
5602
|
+
const installHint = `run: eutaxy prover install smt (or put Z3 ${z3Version} on the PATH, from https://github.com/Z3Prover/z3/releases/tag/z3-${z3Version} or Homebrew: brew install z3)`;
|
|
5603
|
+
const z3Release = `https://github.com/Z3Prover/z3/releases/download/z3-${z3Version}`;
|
|
5604
|
+
const z3File = (name, sha256, bytes) => ({
|
|
5605
|
+
file: name,
|
|
5606
|
+
url: `${z3Release}/${name}`,
|
|
5607
|
+
sha256,
|
|
5608
|
+
bytes
|
|
5609
|
+
});
|
|
5610
|
+
/**
|
|
5611
|
+
* The upstream release files `eutaxy prover install smt` downloads, one per
|
|
5612
|
+
* platform, as published on Z3's GitHub release with the checksums it
|
|
5613
|
+
* reports; the file names carry the version, and a test holds them to
|
|
5614
|
+
* `z3Version`. The Linux builds need glibc 2.39 (x64) or 2.38 (arm64).
|
|
5615
|
+
*/
|
|
5616
|
+
const z3Downloads = {
|
|
5617
|
+
name: "smt",
|
|
5618
|
+
version: z3Version,
|
|
5619
|
+
executable: "bin/z3",
|
|
5620
|
+
files: {
|
|
5621
|
+
"linux-x64": z3File("z3-5.3.2-x64-glibc-2.39.zip", "26d463cddad3901cbf86e3868c784914539f4e3f9b4de1a0b8dc2969806d60e2", 69479256),
|
|
5622
|
+
"linux-arm64": z3File("z3-5.3.2-arm64-glibc-2.38.zip", "30b6a718a6cfe1b2db056038cc32eda5410f6d02e5937622b5238645347f59d5", 64803341),
|
|
5623
|
+
"darwin-x64": z3File("z3-5.3.2-x64-osx-13.3.zip", "b911dc193f7447a14fba001e8e8a0c2866a544274bb003e76a9e864f03b4d557", 54270076),
|
|
5624
|
+
"darwin-arm64": z3File("z3-5.3.2-arm64-osx-13.3.zip", "524290057c943a044ec3d1372db65a9c93f333d9817d58191154c4719ff7f8ad", 53576249),
|
|
5625
|
+
"win32-x64": z3File("z3-5.3.2-x64-win.zip", "a75aa2b0383a8ee355387a54daad796911d6a965076751eea18d21a27f38e983", 70867398)
|
|
5626
|
+
}
|
|
5627
|
+
};
|
|
5394
5628
|
function run(command, args, options) {
|
|
5395
5629
|
return new Promise((resolve) => {
|
|
5396
5630
|
let child;
|
|
@@ -5445,10 +5679,16 @@ function run(command, args, options) {
|
|
|
5445
5679
|
});
|
|
5446
5680
|
});
|
|
5447
5681
|
}
|
|
5448
|
-
/**
|
|
5449
|
-
|
|
5450
|
-
|
|
5682
|
+
/**
|
|
5683
|
+
* Candidates for the `z3` executable: the one `eutaxy prover install smt`
|
|
5684
|
+
* put in the cache, `EUTAXY_Z3`, the PATH, then the prefixes package
|
|
5685
|
+
* managers install into.
|
|
5686
|
+
*/
|
|
5687
|
+
function candidates(h = host()) {
|
|
5688
|
+
const fromEnv = h.env["EUTAXY_Z3"];
|
|
5689
|
+
const fromCache = installed(z3Downloads, h);
|
|
5451
5690
|
return [
|
|
5691
|
+
...fromCache ? [fromCache.executable] : [],
|
|
5452
5692
|
...fromEnv ? [fromEnv] : [],
|
|
5453
5693
|
"z3",
|
|
5454
5694
|
"/opt/homebrew/bin/z3",
|
|
@@ -5931,7 +6171,7 @@ function enginesNamed(names) {
|
|
|
5931
6171
|
* module's source, the outcomes folded into the simulator's verdicts.
|
|
5932
6172
|
* An engine that is not installed proves nothing and says so.
|
|
5933
6173
|
*/
|
|
5934
|
-
async function proveSpecs(dir, observed, specs, engines, modules = findSpecModules(dir)) {
|
|
6174
|
+
async function proveSpecs(dir, observed, specs, engines, modules = findSpecModules(dir), onReport) {
|
|
5935
6175
|
let out = specs;
|
|
5936
6176
|
for (const m of observed) {
|
|
5937
6177
|
const key = specKey(m.module);
|
|
@@ -5940,16 +6180,20 @@ async function proveSpecs(dir, observed, specs, engines, modules = findSpecModul
|
|
|
5940
6180
|
if (!found || withSpecs.length === 0) continue;
|
|
5941
6181
|
const source = readFileSync(found.path, "utf8");
|
|
5942
6182
|
const reports = [];
|
|
5943
|
-
for (const engine of engines)
|
|
5944
|
-
|
|
5945
|
-
|
|
5946
|
-
|
|
5947
|
-
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
5952
|
-
|
|
6183
|
+
for (const engine of engines) {
|
|
6184
|
+
const report = {
|
|
6185
|
+
engine: engine.name,
|
|
6186
|
+
proofs: await engine.prove({
|
|
6187
|
+
source,
|
|
6188
|
+
specs: found.specs,
|
|
6189
|
+
functions: withSpecs,
|
|
6190
|
+
modulePath: found.path,
|
|
6191
|
+
specPath: found.specPath
|
|
6192
|
+
})
|
|
6193
|
+
};
|
|
6194
|
+
reports.push(report);
|
|
6195
|
+
onReport?.(found, report);
|
|
6196
|
+
}
|
|
5953
6197
|
out = aggregate(key, out, reports);
|
|
5954
6198
|
}
|
|
5955
6199
|
return out;
|
|
@@ -6071,14 +6315,16 @@ async function runCheck(o) {
|
|
|
6071
6315
|
}
|
|
6072
6316
|
specs = await proveSpecs(dir, transport.observed ?? [], specs, named.engines, specModules);
|
|
6073
6317
|
}
|
|
6074
|
-
const
|
|
6318
|
+
const regressionPath = verdict.kind === "VIOLATED" && !o.noRegression ? o.out ? resolve(o.cwd, o.out) : join(dir, `${name}.regression.test.ts`) : void 0;
|
|
6319
|
+
const printed = {
|
|
6075
6320
|
...transport.report,
|
|
6076
|
-
specs
|
|
6077
|
-
|
|
6321
|
+
...o.provers && o.provers.length > 0 ? { specs } : {},
|
|
6322
|
+
...regressionPath === void 0 ? {} : { regressionTest: toPosix(relative(o.cwd, regressionPath) || regressionPath) }
|
|
6323
|
+
};
|
|
6078
6324
|
if (o.json) o.stdout(`${canonicalJson(printed)}\n`);
|
|
6079
6325
|
else o.stdout(`${renderText(verdict)}\n${specs.length > 0 ? `\n${renderSpecs(specs)}\n` : ""}`);
|
|
6080
|
-
if (
|
|
6081
|
-
const outPath =
|
|
6326
|
+
if (regressionPath !== void 0) {
|
|
6327
|
+
const outPath = regressionPath;
|
|
6082
6328
|
const outDir = dirname(outPath);
|
|
6083
6329
|
const schemaPaths = {};
|
|
6084
6330
|
for (const step of transport.setup) if (step.kind === "d1") schemaPaths[String(step["binding"])] = toPosix(relative(outDir, resolve(dir, String(step["schemaFile"]))));
|
|
@@ -6108,6 +6354,514 @@ async function runCheck(o) {
|
|
|
6108
6354
|
});
|
|
6109
6355
|
}
|
|
6110
6356
|
}
|
|
6357
|
+
// packages/cli/src/archive.ts
|
|
6358
|
+
/**
|
|
6359
|
+
* Reading the two archive formats the prover releases come in, with Node's
|
|
6360
|
+
* standard library alone: a tar stream compressed with zstd (Lean) and a zip
|
|
6361
|
+
* (Z3). Entries are written under one destination directory; an entry whose
|
|
6362
|
+
* path would leave it, or a link pointing out of it, is refused, since the
|
|
6363
|
+
* archive is downloaded. The tar is read as it decompresses, so a release
|
|
6364
|
+
* of hundreds of megabytes never sits in memory; a zip is read from its
|
|
6365
|
+
* central directory, entry by entry.
|
|
6366
|
+
*/
|
|
6367
|
+
var ArchiveError = class extends Error {};
|
|
6368
|
+
/** The entry's place under `dest`, refused when it would be outside. */
|
|
6369
|
+
function placeOf(dest, name) {
|
|
6370
|
+
if (name.includes("\0")) throw new ArchiveError("an entry name holds a NUL byte");
|
|
6371
|
+
const target = resolve(dest, name);
|
|
6372
|
+
if (target !== dest && !target.startsWith(dest + sep)) throw new ArchiveError(`entry ${JSON.stringify(name)} would be written outside the toolchain directory`);
|
|
6373
|
+
return target;
|
|
6374
|
+
}
|
|
6375
|
+
/** A symlink's target must stay under `dest` too. */
|
|
6376
|
+
function checkLink(dest, at, linkTo) {
|
|
6377
|
+
const target = resolve(dirname(at), linkTo);
|
|
6378
|
+
if (target !== dest && !target.startsWith(dest + sep)) throw new ArchiveError(`link ${JSON.stringify(linkTo)} would point outside the toolchain directory`);
|
|
6379
|
+
}
|
|
6380
|
+
function ensureDir(dir) {
|
|
6381
|
+
mkdirSync(dir, { recursive: true });
|
|
6382
|
+
}
|
|
6383
|
+
function setMode(path, mode) {
|
|
6384
|
+
if (process.platform === "win32") return;
|
|
6385
|
+
const bits = mode & 511;
|
|
6386
|
+
if (bits !== 0) chmodSync(path, bits | 384);
|
|
6387
|
+
}
|
|
6388
|
+
const text = (block, start, length) => {
|
|
6389
|
+
const slice = block.subarray(start, start + length);
|
|
6390
|
+
const end = slice.indexOf(0);
|
|
6391
|
+
return slice.subarray(0, end < 0 ? slice.length : end).toString("utf8");
|
|
6392
|
+
};
|
|
6393
|
+
/** An octal field, or GNU base-256 when the high bit of the first byte is set. */
|
|
6394
|
+
const numeric = (block, start, length) => {
|
|
6395
|
+
if (block[start] & 128) {
|
|
6396
|
+
let n = 0;
|
|
6397
|
+
for (let i = start + 1; i < start + length; i++) n = n * 256 + block[i];
|
|
6398
|
+
return n;
|
|
6399
|
+
}
|
|
6400
|
+
const t = text(block, start, length).trim();
|
|
6401
|
+
return t.length === 0 ? 0 : Number.parseInt(t, 8);
|
|
6402
|
+
};
|
|
6403
|
+
function parseHeader(block) {
|
|
6404
|
+
const magic = text(block, 257, 6);
|
|
6405
|
+
const name = text(block, 0, 100);
|
|
6406
|
+
const prefix = magic.startsWith("ustar") ? text(block, 345, 155) : "";
|
|
6407
|
+
return {
|
|
6408
|
+
name: prefix.length > 0 ? `${prefix}/${name}` : name,
|
|
6409
|
+
mode: numeric(block, 100, 8),
|
|
6410
|
+
size: numeric(block, 124, 12),
|
|
6411
|
+
type: block[156] === 0 ? "0" : String.fromCharCode(block[156]),
|
|
6412
|
+
linkName: text(block, 157, 100)
|
|
6413
|
+
};
|
|
6414
|
+
}
|
|
6415
|
+
/** `length key=value\n` records of a pax extended header. */
|
|
6416
|
+
function paxRecords(data) {
|
|
6417
|
+
const out = /* @__PURE__ */ new Map();
|
|
6418
|
+
let at = 0;
|
|
6419
|
+
while (at < data.length) {
|
|
6420
|
+
const space = data.indexOf(32, at);
|
|
6421
|
+
if (space < 0) break;
|
|
6422
|
+
const length = Number.parseInt(data.subarray(at, space).toString("latin1"), 10);
|
|
6423
|
+
if (!Number.isInteger(length) || length <= 0) break;
|
|
6424
|
+
const record = data.subarray(space + 1, at + length - 1).toString("utf8");
|
|
6425
|
+
const eq = record.indexOf("=");
|
|
6426
|
+
if (eq > 0) out.set(record.slice(0, eq), record.slice(eq + 1));
|
|
6427
|
+
at += length;
|
|
6428
|
+
}
|
|
6429
|
+
return out;
|
|
6430
|
+
}
|
|
6431
|
+
/**
|
|
6432
|
+
* Reads a tar stream block by block as its chunks arrive. A file entry's
|
|
6433
|
+
* bytes are written to disk as they come; pax and GNU long-name entries are
|
|
6434
|
+
* read into memory (they are small) and apply to the entry that follows.
|
|
6435
|
+
*/
|
|
6436
|
+
var TarReader = class {
|
|
6437
|
+
dest;
|
|
6438
|
+
buffer = Buffer.alloc(0);
|
|
6439
|
+
current;
|
|
6440
|
+
/** Overrides for the next entry from a pax or long-name entry. */
|
|
6441
|
+
next = {};
|
|
6442
|
+
zeroBlocks = 0;
|
|
6443
|
+
ended = false;
|
|
6444
|
+
entries = 0;
|
|
6445
|
+
constructor(dest) {
|
|
6446
|
+
this.dest = dest;
|
|
6447
|
+
}
|
|
6448
|
+
push(chunk) {
|
|
6449
|
+
this.buffer = this.buffer.length === 0 ? chunk : Buffer.concat([this.buffer, chunk]);
|
|
6450
|
+
for (;;) {
|
|
6451
|
+
if (this.ended) return;
|
|
6452
|
+
if (this.current) {
|
|
6453
|
+
const take = Math.min(this.current.remaining, this.buffer.length);
|
|
6454
|
+
if (take > 0) {
|
|
6455
|
+
const part = this.buffer.subarray(0, take);
|
|
6456
|
+
if ("fd" in this.current.sink) writeSync(this.current.sink.fd, part);
|
|
6457
|
+
else if ("chunks" in this.current.sink) this.current.sink.chunks.push(Buffer.from(part));
|
|
6458
|
+
this.buffer = this.buffer.subarray(take);
|
|
6459
|
+
this.current.remaining -= take;
|
|
6460
|
+
}
|
|
6461
|
+
if (this.current.remaining > 0) return;
|
|
6462
|
+
const skip = Math.min(this.current.padding, this.buffer.length);
|
|
6463
|
+
this.buffer = this.buffer.subarray(skip);
|
|
6464
|
+
this.current.padding -= skip;
|
|
6465
|
+
if (this.current.padding > 0) return;
|
|
6466
|
+
this.finish();
|
|
6467
|
+
continue;
|
|
6468
|
+
}
|
|
6469
|
+
if (this.buffer.length < 512) return;
|
|
6470
|
+
const block = this.buffer.subarray(0, 512);
|
|
6471
|
+
this.buffer = this.buffer.subarray(512);
|
|
6472
|
+
if (block.every((b) => b === 0)) {
|
|
6473
|
+
if (++this.zeroBlocks >= 2) this.ended = true;
|
|
6474
|
+
continue;
|
|
6475
|
+
}
|
|
6476
|
+
this.zeroBlocks = 0;
|
|
6477
|
+
this.begin(parseHeader(block));
|
|
6478
|
+
}
|
|
6479
|
+
}
|
|
6480
|
+
begin(header) {
|
|
6481
|
+
const size = this.next.size ?? header.size;
|
|
6482
|
+
const padding = (512 - size % 512) % 512;
|
|
6483
|
+
if (header.type === "x" || header.type === "L") {
|
|
6484
|
+
const kind = header.type === "x" ? "pax" : "longname";
|
|
6485
|
+
this.current = {
|
|
6486
|
+
remaining: size,
|
|
6487
|
+
padding,
|
|
6488
|
+
sink: {
|
|
6489
|
+
chunks: [],
|
|
6490
|
+
kind
|
|
6491
|
+
}
|
|
6492
|
+
};
|
|
6493
|
+
return;
|
|
6494
|
+
}
|
|
6495
|
+
const name = this.next.path ?? header.name;
|
|
6496
|
+
const linkName = this.next.linkpath ?? header.linkName;
|
|
6497
|
+
this.next = {};
|
|
6498
|
+
this.entries++;
|
|
6499
|
+
const at = placeOf(this.dest, name);
|
|
6500
|
+
if (header.type === "0" || header.type === "7") {
|
|
6501
|
+
ensureDir(dirname(at));
|
|
6502
|
+
const fd = openSync(at, "w");
|
|
6503
|
+
this.current = {
|
|
6504
|
+
remaining: size,
|
|
6505
|
+
padding,
|
|
6506
|
+
sink: {
|
|
6507
|
+
fd,
|
|
6508
|
+
at,
|
|
6509
|
+
mode: header.mode
|
|
6510
|
+
}
|
|
6511
|
+
};
|
|
6512
|
+
if (size === 0) this.finish();
|
|
6513
|
+
return;
|
|
6514
|
+
}
|
|
6515
|
+
if (header.type === "5") ensureDir(at);
|
|
6516
|
+
else if (header.type === "2") {
|
|
6517
|
+
checkLink(this.dest, at, linkName);
|
|
6518
|
+
ensureDir(dirname(at));
|
|
6519
|
+
rmSync(at, { force: true });
|
|
6520
|
+
symlinkSync(linkName, at);
|
|
6521
|
+
} else if (header.type === "1") {
|
|
6522
|
+
ensureDir(dirname(at));
|
|
6523
|
+
copyFileSync(placeOf(this.dest, linkName), at);
|
|
6524
|
+
}
|
|
6525
|
+
if (size > 0) this.current = {
|
|
6526
|
+
remaining: size,
|
|
6527
|
+
padding,
|
|
6528
|
+
sink: { skip: true }
|
|
6529
|
+
};
|
|
6530
|
+
}
|
|
6531
|
+
finish() {
|
|
6532
|
+
const current = this.current;
|
|
6533
|
+
this.current = void 0;
|
|
6534
|
+
if ("fd" in current.sink) {
|
|
6535
|
+
closeSync(current.sink.fd);
|
|
6536
|
+
setMode(current.sink.at, current.sink.mode);
|
|
6537
|
+
return;
|
|
6538
|
+
}
|
|
6539
|
+
if (!("chunks" in current.sink)) return;
|
|
6540
|
+
const data = Buffer.concat(current.sink.chunks);
|
|
6541
|
+
if (current.sink.kind === "longname") {
|
|
6542
|
+
this.next.path = text(data, 0, data.length);
|
|
6543
|
+
return;
|
|
6544
|
+
}
|
|
6545
|
+
const records = paxRecords(data);
|
|
6546
|
+
const path = records.get("path");
|
|
6547
|
+
const linkpath = records.get("linkpath");
|
|
6548
|
+
const size = records.get("size");
|
|
6549
|
+
if (path !== void 0) this.next.path = path;
|
|
6550
|
+
if (linkpath !== void 0) this.next.linkpath = linkpath;
|
|
6551
|
+
if (size !== void 0) this.next.size = Number(size);
|
|
6552
|
+
}
|
|
6553
|
+
/** Close the file being written, if any. */
|
|
6554
|
+
release() {
|
|
6555
|
+
if (this.current && "fd" in this.current.sink) closeSync(this.current.sink.fd);
|
|
6556
|
+
}
|
|
6557
|
+
end() {
|
|
6558
|
+
this.release();
|
|
6559
|
+
if (this.current) throw new ArchiveError("the tar stream ended inside an entry; the file is truncated");
|
|
6560
|
+
}
|
|
6561
|
+
};
|
|
6562
|
+
/** Unpack a zstd-compressed tar into `dest`, which must exist and be empty. */
|
|
6563
|
+
async function extractTarZst(file, dest) {
|
|
6564
|
+
const reader = new TarReader(resolve(dest));
|
|
6565
|
+
const source = createReadStream(file).pipe(createZstdDecompress());
|
|
6566
|
+
try {
|
|
6567
|
+
for await (const chunk of source) reader.push(chunk);
|
|
6568
|
+
} catch (err) {
|
|
6569
|
+
reader.release();
|
|
6570
|
+
source.destroy();
|
|
6571
|
+
throw err;
|
|
6572
|
+
}
|
|
6573
|
+
reader.end();
|
|
6574
|
+
return reader.entries;
|
|
6575
|
+
}
|
|
6576
|
+
const ZIP_EOCD = 101010256;
|
|
6577
|
+
const ZIP64_EOCD = 101075792;
|
|
6578
|
+
const ZIP64_LOCATOR = 117853008;
|
|
6579
|
+
const ZIP_CENTRAL = 33639248;
|
|
6580
|
+
const ZIP_LOCAL = 67324752;
|
|
6581
|
+
/** The central directory's position and entry count, through the zip64 records when the plain ones overflow. */
|
|
6582
|
+
function centralDirectory(zip) {
|
|
6583
|
+
const start = Math.max(0, zip.length - 22 - 65535);
|
|
6584
|
+
let eocd = -1;
|
|
6585
|
+
for (let i = zip.length - 22; i >= start; i--) if (zip.readUInt32LE(i) === ZIP_EOCD) {
|
|
6586
|
+
eocd = i;
|
|
6587
|
+
break;
|
|
6588
|
+
}
|
|
6589
|
+
if (eocd < 0) throw new ArchiveError("not a zip file: no end-of-central-directory record");
|
|
6590
|
+
let entries = zip.readUInt16LE(eocd + 10);
|
|
6591
|
+
let offset = zip.readUInt32LE(eocd + 16);
|
|
6592
|
+
if (entries === 65535 || offset === 4294967295) {
|
|
6593
|
+
const locator = eocd - 20;
|
|
6594
|
+
if (locator < 0 || zip.readUInt32LE(locator) !== ZIP64_LOCATOR) throw new ArchiveError("zip64 archive without its locator");
|
|
6595
|
+
const at = Number(zip.readBigUInt64LE(locator + 8));
|
|
6596
|
+
if (zip.readUInt32LE(at) !== ZIP64_EOCD) throw new ArchiveError("zip64 archive without its end record");
|
|
6597
|
+
entries = Number(zip.readBigUInt64LE(at + 32));
|
|
6598
|
+
offset = Number(zip.readBigUInt64LE(at + 48));
|
|
6599
|
+
}
|
|
6600
|
+
return {
|
|
6601
|
+
offset,
|
|
6602
|
+
entries
|
|
6603
|
+
};
|
|
6604
|
+
}
|
|
6605
|
+
/** Sizes and offset of one entry, from its zip64 extra field when the plain ones overflow. */
|
|
6606
|
+
function zip64Fields(extra, plain) {
|
|
6607
|
+
let at = 0;
|
|
6608
|
+
while (at + 4 <= extra.length) {
|
|
6609
|
+
const id = extra.readUInt16LE(at);
|
|
6610
|
+
const size = extra.readUInt16LE(at + 2);
|
|
6611
|
+
if (id === 1) {
|
|
6612
|
+
let p = at + 4;
|
|
6613
|
+
const out = { ...plain };
|
|
6614
|
+
if (out.uncompressed === 4294967295) {
|
|
6615
|
+
out.uncompressed = Number(extra.readBigUInt64LE(p));
|
|
6616
|
+
p += 8;
|
|
6617
|
+
}
|
|
6618
|
+
if (out.compressed === 4294967295) {
|
|
6619
|
+
out.compressed = Number(extra.readBigUInt64LE(p));
|
|
6620
|
+
p += 8;
|
|
6621
|
+
}
|
|
6622
|
+
if (out.offset === 4294967295) out.offset = Number(extra.readBigUInt64LE(p));
|
|
6623
|
+
return out;
|
|
6624
|
+
}
|
|
6625
|
+
at += 4 + size;
|
|
6626
|
+
}
|
|
6627
|
+
return plain;
|
|
6628
|
+
}
|
|
6629
|
+
/** Unpack a zip into `dest`, which must exist and be empty. */
|
|
6630
|
+
function extractZip(file, dest) {
|
|
6631
|
+
const root = resolve(dest);
|
|
6632
|
+
const zip = readFileSync(file);
|
|
6633
|
+
const { offset, entries } = centralDirectory(zip);
|
|
6634
|
+
let at = offset;
|
|
6635
|
+
for (let i = 0; i < entries; i++) {
|
|
6636
|
+
if (zip.readUInt32LE(at) !== ZIP_CENTRAL) throw new ArchiveError("a central directory entry is not where the zip says it is");
|
|
6637
|
+
const madeBy = zip.readUInt16LE(at + 4) >> 8;
|
|
6638
|
+
const method = zip.readUInt16LE(at + 10);
|
|
6639
|
+
const nameLength = zip.readUInt16LE(at + 28);
|
|
6640
|
+
const extraLength = zip.readUInt16LE(at + 30);
|
|
6641
|
+
const commentLength = zip.readUInt16LE(at + 32);
|
|
6642
|
+
const externalAttributes = zip.readUInt32LE(at + 38);
|
|
6643
|
+
const name = zip.subarray(at + 46, at + 46 + nameLength).toString("utf8");
|
|
6644
|
+
const sizes = zip64Fields(zip.subarray(at + 46 + nameLength, at + 46 + nameLength + extraLength), {
|
|
6645
|
+
compressed: zip.readUInt32LE(at + 20),
|
|
6646
|
+
uncompressed: zip.readUInt32LE(at + 24),
|
|
6647
|
+
offset: zip.readUInt32LE(at + 42)
|
|
6648
|
+
});
|
|
6649
|
+
at += 46 + nameLength + extraLength + commentLength;
|
|
6650
|
+
const local = sizes.offset;
|
|
6651
|
+
if (zip.readUInt32LE(local) !== ZIP_LOCAL) throw new ArchiveError(`entry ${JSON.stringify(name)} has no local header where the zip says`);
|
|
6652
|
+
const dataStart = local + 30 + zip.readUInt16LE(local + 26) + zip.readUInt16LE(local + 28);
|
|
6653
|
+
const raw = zip.subarray(dataStart, dataStart + sizes.compressed);
|
|
6654
|
+
const mode = madeBy === 3 ? externalAttributes >>> 16 : 0;
|
|
6655
|
+
const place = placeOf(root, name);
|
|
6656
|
+
if (name.endsWith("/") || (mode & 61440) === 16384) {
|
|
6657
|
+
ensureDir(place);
|
|
6658
|
+
continue;
|
|
6659
|
+
}
|
|
6660
|
+
let data;
|
|
6661
|
+
if (method === 0) data = raw;
|
|
6662
|
+
else if (method === 8) data = inflateRawSync(raw);
|
|
6663
|
+
else throw new ArchiveError(`entry ${JSON.stringify(name)} uses compression method ${method}; only stored and deflated entries are read`);
|
|
6664
|
+
if (data.length !== sizes.uncompressed) throw new ArchiveError(`entry ${JSON.stringify(name)} did not inflate to its declared size`);
|
|
6665
|
+
ensureDir(dirname(place));
|
|
6666
|
+
if ((mode & 61440) === 40960) {
|
|
6667
|
+
const linkTo = data.toString("utf8");
|
|
6668
|
+
checkLink(root, place, linkTo);
|
|
6669
|
+
rmSync(place, { force: true });
|
|
6670
|
+
symlinkSync(linkTo, place);
|
|
6671
|
+
continue;
|
|
6672
|
+
}
|
|
6673
|
+
writeFileSync(place, data);
|
|
6674
|
+
setMode(place, mode);
|
|
6675
|
+
}
|
|
6676
|
+
return entries;
|
|
6677
|
+
}
|
|
6678
|
+
/**
|
|
6679
|
+
* When an archive puts everything under one top-level directory, as the
|
|
6680
|
+
* releases do (`lean-4.35.0-linux/`, `z3-5.3.2-x64-glibc-2.39/`), move
|
|
6681
|
+
* its contents up so the executable is at the path the table names.
|
|
6682
|
+
*/
|
|
6683
|
+
function flattenSingleDirectory(dest) {
|
|
6684
|
+
const entries = readdirSync(dest, { withFileTypes: true });
|
|
6685
|
+
if (entries.length !== 1 || !entries[0].isDirectory()) return;
|
|
6686
|
+
const inner = join(dest, entries[0].name);
|
|
6687
|
+
for (const name of readdirSync(inner)) {
|
|
6688
|
+
const to = join(dest, name);
|
|
6689
|
+
if (existsSync(to)) throw new ArchiveError(`cannot flatten the archive: ${name} exists twice`);
|
|
6690
|
+
renameSync(join(inner, name), to);
|
|
6691
|
+
}
|
|
6692
|
+
rmSync(inner, {
|
|
6693
|
+
recursive: true,
|
|
6694
|
+
force: true
|
|
6695
|
+
});
|
|
6696
|
+
}
|
|
6697
|
+
// packages/cli/src/install.ts
|
|
6698
|
+
/**
|
|
6699
|
+
* `eutaxy prover install <name>`: the pinned release of a prover put in
|
|
6700
|
+
* Eutaxy's cache, where the engines look first. The file for this platform
|
|
6701
|
+
* is downloaded (or copied from a mirror or an offline directory given with
|
|
6702
|
+
* `--from`), its SHA-256 checked against the engine's table before anything
|
|
6703
|
+
* is unpacked, unpacked beside a marker written last, and deleted. A
|
|
6704
|
+
* mismatch or a failed download installs nothing. Nothing is run: the
|
|
6705
|
+
* engines check the version when they look the toolchain up.
|
|
6706
|
+
*/
|
|
6707
|
+
/** The toolchains the command installs, by the engine name it takes. */
|
|
6708
|
+
const toolchains = {
|
|
6709
|
+
lean: leanDownloads,
|
|
6710
|
+
smt: z3Downloads
|
|
6711
|
+
};
|
|
6712
|
+
var InstallError = class extends Error {};
|
|
6713
|
+
const isUrl = (s) => /^https?:\/\//.test(s);
|
|
6714
|
+
/** Write a byte stream to `path`, hashing it as it goes; the hash and the byte count come back. */
|
|
6715
|
+
async function store(bytes, path, progress) {
|
|
6716
|
+
const hash = createHash("sha256");
|
|
6717
|
+
const fd = openSync(path, "w");
|
|
6718
|
+
let written = 0;
|
|
6719
|
+
let reported = 0;
|
|
6720
|
+
try {
|
|
6721
|
+
for await (const chunk of bytes) {
|
|
6722
|
+
writeSync(fd, chunk);
|
|
6723
|
+
hash.update(chunk);
|
|
6724
|
+
written += chunk.byteLength;
|
|
6725
|
+
if (progress && written - reported >= 5e7) {
|
|
6726
|
+
reported = written;
|
|
6727
|
+
progress(written);
|
|
6728
|
+
}
|
|
6729
|
+
}
|
|
6730
|
+
} finally {
|
|
6731
|
+
closeSync(fd);
|
|
6732
|
+
}
|
|
6733
|
+
return {
|
|
6734
|
+
sha256: hash.digest("hex"),
|
|
6735
|
+
bytes: written
|
|
6736
|
+
};
|
|
6737
|
+
}
|
|
6738
|
+
async function installToolchain(options) {
|
|
6739
|
+
const { toolchain } = options;
|
|
6740
|
+
const h = options.host ?? host();
|
|
6741
|
+
const platform = platformOf(h);
|
|
6742
|
+
const release = platform === void 0 ? void 0 : toolchain.files[platform];
|
|
6743
|
+
if (platform === void 0 || release === void 0) throw new InstallError(`no ${toolchain.name} ${toolchain.version} release for ${h.platform}-${h.arch}; the platforms are ${platforms.join(", ")}`);
|
|
6744
|
+
const cache = cacheDir(h);
|
|
6745
|
+
const dir = toolchainDir(cache, toolchain);
|
|
6746
|
+
const already = installed(toolchain, h);
|
|
6747
|
+
if (already) return {
|
|
6748
|
+
name: toolchain.name,
|
|
6749
|
+
version: toolchain.version,
|
|
6750
|
+
platform,
|
|
6751
|
+
file: already.marker.file,
|
|
6752
|
+
source: already.marker.source,
|
|
6753
|
+
sha256: already.marker.sha256,
|
|
6754
|
+
bytes: release.bytes,
|
|
6755
|
+
dir,
|
|
6756
|
+
executable: already.executable,
|
|
6757
|
+
downloaded: false
|
|
6758
|
+
};
|
|
6759
|
+
const source = options.from === void 0 ? release.url : isUrl(options.from) ? `${options.from.replace(/\/+$/, "")}/${release.file}` : join(options.from, release.file);
|
|
6760
|
+
const stamp = `${process.pid}-${randomBytes(4).toString("hex")}`;
|
|
6761
|
+
const downloads = join(cache, "downloads");
|
|
6762
|
+
const archive = join(downloads, `${release.file}.${stamp}.part`);
|
|
6763
|
+
const mb = (n) => `${Math.round(n / 1e6)} MB`;
|
|
6764
|
+
try {
|
|
6765
|
+
mkdirSync(downloads, { recursive: true });
|
|
6766
|
+
let bytes;
|
|
6767
|
+
if (isUrl(source)) {
|
|
6768
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
6769
|
+
let response;
|
|
6770
|
+
try {
|
|
6771
|
+
response = await fetchImpl(source);
|
|
6772
|
+
} catch (err) {
|
|
6773
|
+
throw new InstallError(`could not download ${source}: ${err instanceof Error ? err.message : String(err)}`);
|
|
6774
|
+
}
|
|
6775
|
+
if (!response.ok || response.body === null) throw new InstallError(`could not download ${source}: HTTP ${response.status} ${response.statusText}`);
|
|
6776
|
+
options.progress?.(`downloading ${release.file} (${mb(release.bytes)}) from ${source}`);
|
|
6777
|
+
bytes = Readable.fromWeb(response.body);
|
|
6778
|
+
} else {
|
|
6779
|
+
if (!existsSync(source)) throw new InstallError(`no ${release.file} in ${options.from}`);
|
|
6780
|
+
bytes = createReadStream(source);
|
|
6781
|
+
}
|
|
6782
|
+
let stored;
|
|
6783
|
+
try {
|
|
6784
|
+
stored = await store(bytes, archive, (n) => options.progress?.(`${mb(n)} of ${mb(release.bytes)}`));
|
|
6785
|
+
} catch (err) {
|
|
6786
|
+
throw new InstallError(`could not download ${source}: ${err instanceof Error ? err.message : String(err)}; nothing was installed`);
|
|
6787
|
+
}
|
|
6788
|
+
if (stored.sha256 !== release.sha256) throw new InstallError(`checksum mismatch for ${release.file} from ${source}: expected sha256 ${release.sha256}, got ${stored.sha256} (${stored.bytes} bytes, ${release.bytes} expected); nothing was installed`);
|
|
6789
|
+
const partial = `${dir}.partial-${stamp}`;
|
|
6790
|
+
mkdirSync(partial, { recursive: true });
|
|
6791
|
+
try {
|
|
6792
|
+
options.progress?.(`unpacking ${release.file}`);
|
|
6793
|
+
if (release.file.endsWith(".zip")) extractZip(archive, partial);
|
|
6794
|
+
else if (release.file.endsWith(".tar.zst")) await extractTarZst(archive, partial);
|
|
6795
|
+
else throw new InstallError(`${release.file} is neither a .zip nor a .tar.zst`);
|
|
6796
|
+
flattenSingleDirectory(partial);
|
|
6797
|
+
const executable = executableName(toolchain, h);
|
|
6798
|
+
if (!existsSync(join(partial, executable))) throw new InstallError(`${release.file} holds no ${executable}; nothing was installed`);
|
|
6799
|
+
if (h.platform !== "win32") chmodSync(join(partial, executable), 493);
|
|
6800
|
+
const marker = {
|
|
6801
|
+
name: toolchain.name,
|
|
6802
|
+
version: toolchain.version,
|
|
6803
|
+
platform,
|
|
6804
|
+
file: release.file,
|
|
6805
|
+
sha256: stored.sha256,
|
|
6806
|
+
source
|
|
6807
|
+
};
|
|
6808
|
+
writeFileSync(join(partial, markerFile), `${JSON.stringify(marker, null, 2)}\n`);
|
|
6809
|
+
rmSync(dir, {
|
|
6810
|
+
recursive: true,
|
|
6811
|
+
force: true
|
|
6812
|
+
});
|
|
6813
|
+
renameSync(partial, dir);
|
|
6814
|
+
} catch (err) {
|
|
6815
|
+
rmSync(partial, {
|
|
6816
|
+
recursive: true,
|
|
6817
|
+
force: true
|
|
6818
|
+
});
|
|
6819
|
+
throw err instanceof InstallError ? err : new InstallError(`could not unpack ${release.file}: ${err instanceof Error ? err.message : String(err)}; nothing was installed`);
|
|
6820
|
+
}
|
|
6821
|
+
return {
|
|
6822
|
+
name: toolchain.name,
|
|
6823
|
+
version: toolchain.version,
|
|
6824
|
+
platform,
|
|
6825
|
+
file: release.file,
|
|
6826
|
+
source,
|
|
6827
|
+
sha256: stored.sha256,
|
|
6828
|
+
bytes: stored.bytes,
|
|
6829
|
+
dir,
|
|
6830
|
+
executable: join(dir, executableName(toolchain, h)),
|
|
6831
|
+
downloaded: true
|
|
6832
|
+
};
|
|
6833
|
+
} catch (err) {
|
|
6834
|
+
throw err instanceof InstallError ? err : new InstallError(`could not install ${toolchain.name} ${toolchain.version} in ${cache}: ${err instanceof Error ? err.message : String(err)}`);
|
|
6835
|
+
} finally {
|
|
6836
|
+
try {
|
|
6837
|
+
rmSync(archive, { force: true });
|
|
6838
|
+
} catch {}
|
|
6839
|
+
}
|
|
6840
|
+
}
|
|
6841
|
+
/** The command: the result as text or `--json` on stdout, progress and errors on stderr; exit 0, or 3 on an error. */
|
|
6842
|
+
async function runInstall(options) {
|
|
6843
|
+
try {
|
|
6844
|
+
const result = await installToolchain({
|
|
6845
|
+
toolchain: options.toolchain,
|
|
6846
|
+
...options.host === void 0 ? {} : { host: options.host },
|
|
6847
|
+
...options.fetch === void 0 ? {} : { fetch: options.fetch },
|
|
6848
|
+
...options.from === void 0 ? {} : { from: options.from },
|
|
6849
|
+
progress: (text) => options.stderr(`${text}\n`)
|
|
6850
|
+
});
|
|
6851
|
+
if (options.json) options.stdout(`${JSON.stringify({
|
|
6852
|
+
schemaVersion: 1,
|
|
6853
|
+
command: "prover install",
|
|
6854
|
+
...result
|
|
6855
|
+
}, null, 2)}\n`);
|
|
6856
|
+
else if (result.downloaded) options.stdout(`${result.name} ${result.version} installed in ${result.dir}\n ${result.file} from ${result.source}\n sha256 ${result.sha256}\n`);
|
|
6857
|
+
else options.stdout(`${result.name} ${result.version} already installed in ${result.dir} (${result.file}, sha256 ${result.sha256})\n`);
|
|
6858
|
+
return exitCodes.BOUNDED;
|
|
6859
|
+
} catch (err) {
|
|
6860
|
+
if (!(err instanceof InstallError)) throw err;
|
|
6861
|
+
options.stderr(`${err.message}\n`);
|
|
6862
|
+
return exitCodes.error;
|
|
6863
|
+
}
|
|
6864
|
+
}
|
|
6111
6865
|
// packages/cli/src/report.ts
|
|
6112
6866
|
/**
|
|
6113
6867
|
* `eutaxy report [dir]`: every spec file under a directory through the
|
|
@@ -6236,6 +6990,31 @@ function testModule(m, seed, budgetMs, stderr) {
|
|
|
6236
6990
|
});
|
|
6237
6991
|
});
|
|
6238
6992
|
}
|
|
6993
|
+
/**
|
|
6994
|
+
* Write a module's open Lean goals beside its spec file as
|
|
6995
|
+
* `<spec>.goals.lean`, a proof file with every proof open, and list them.
|
|
6996
|
+
* No open goal removes a goal file left from an earlier run.
|
|
6997
|
+
*/
|
|
6998
|
+
function writeGoals(m, goals, cwd) {
|
|
6999
|
+
const path = goalFileFor(m.specPath);
|
|
7000
|
+
if (goals.length === 0) {
|
|
7001
|
+
rmSync(path, { force: true });
|
|
7002
|
+
return [];
|
|
7003
|
+
}
|
|
7004
|
+
const sha = (text) => createHash("sha256").update(text).digest("hex");
|
|
7005
|
+
writeFileSync(path, renderGoals({
|
|
7006
|
+
specFile: basename(m.specPath),
|
|
7007
|
+
sourceSha256: sha(readFileSync(m.path, "utf8")),
|
|
7008
|
+
specSha256: sha(readFileSync(m.specPath, "utf8")),
|
|
7009
|
+
goals
|
|
7010
|
+
}));
|
|
7011
|
+
const file = relative(cwd, path).split("\\").join("/");
|
|
7012
|
+
return goals.map((g) => ({
|
|
7013
|
+
module: m.key,
|
|
7014
|
+
file,
|
|
7015
|
+
...g
|
|
7016
|
+
}));
|
|
7017
|
+
}
|
|
6239
7018
|
async function runReport(o) {
|
|
6240
7019
|
const root = resolve(o.cwd, o.dir ?? ".");
|
|
6241
7020
|
let engines = [];
|
|
@@ -6254,10 +7033,22 @@ async function runReport(o) {
|
|
|
6254
7033
|
o.stderr(`cannot read ${root}: ${err instanceof Error ? err.message : String(err)}\n`);
|
|
6255
7034
|
return exitCodes.error;
|
|
6256
7035
|
}
|
|
7036
|
+
if (o.only !== void 0) {
|
|
7037
|
+
const spec = resolve(o.cwd, o.only);
|
|
7038
|
+
modules = modules.filter((m) => m.specPath === spec);
|
|
7039
|
+
if (modules.length === 0) {
|
|
7040
|
+
o.stderr(`no spec file ${spec} under ${root}\n`);
|
|
7041
|
+
return exitCodes.error;
|
|
7042
|
+
}
|
|
7043
|
+
}
|
|
6257
7044
|
if (modules.length === 0) {
|
|
6258
7045
|
o.stderr(`no spec files (*.props.ts) under ${root}\n`);
|
|
6259
7046
|
return exitCodes.error;
|
|
6260
7047
|
}
|
|
7048
|
+
if (o.goals && !engines.some((e) => e.name === leanProver.name)) {
|
|
7049
|
+
o.stderr("--goals needs the lean engine among --prover\n");
|
|
7050
|
+
return exitCodes.error;
|
|
7051
|
+
}
|
|
6261
7052
|
const errors = modules.flatMap((m) => m.specs.errors.map((e) => `${m.key}${e.line > 0 ? `:${e.line}` : ""}: ${e.message}`));
|
|
6262
7053
|
if (errors.length > 0) {
|
|
6263
7054
|
for (const e of errors) o.stderr(`${e}\n`);
|
|
@@ -6265,19 +7056,509 @@ async function runReport(o) {
|
|
|
6265
7056
|
}
|
|
6266
7057
|
let specs = [];
|
|
6267
7058
|
for (const m of modules) specs = [...specs, ...await testModule(m, o.seed ?? "report", o.moduleBudgetMs ?? 6e4, o.stderr)];
|
|
7059
|
+
const goals = [];
|
|
6268
7060
|
if (engines.length > 0) specs = await proveSpecs(root, modules.map((m) => ({
|
|
6269
7061
|
module: m.key,
|
|
6270
7062
|
functions: m.specs.functions.map((f) => f.name)
|
|
6271
|
-
})), specs, engines, modules)
|
|
6272
|
-
|
|
7063
|
+
})), specs, engines, modules, o.goals ? (m, report) => {
|
|
7064
|
+
if (report.engine !== leanProver.name) return;
|
|
7065
|
+
if (report.proofs.goals === void 0) return;
|
|
7066
|
+
goals.push(...writeGoals(m, report.proofs.goals, o.cwd));
|
|
7067
|
+
} : void 0);
|
|
7068
|
+
if (o.json) {
|
|
7069
|
+
const json = JSON.parse(renderSpecReportJson(specs));
|
|
7070
|
+
o.stdout(`${canonicalJson({
|
|
7071
|
+
...json,
|
|
7072
|
+
...o.goals ? { goals } : {}
|
|
7073
|
+
})}\n`);
|
|
7074
|
+
} else {
|
|
7075
|
+
o.stdout(`${renderSpecReport(specs)}\n`);
|
|
7076
|
+
if (o.goals) o.stdout(goals.length === 0 ? "\nNo open Lean goals.\n" : `\n${goals.length} open Lean goal${goals.length === 1 ? "" : "s"} written to ${[...new Set(goals.map((g) => g.file))].join(", ")}\n`);
|
|
7077
|
+
}
|
|
6273
7078
|
return specs.some((v) => v.kind === "REFUTED" || v.kind === "CONFLICT") ? exitCodes.VIOLATED : exitCodes.BOUNDED;
|
|
6274
7079
|
}
|
|
7080
|
+
// packages/cli/src/version.ts
|
|
7081
|
+
/** The published package's version, as the MCP server reports it; the release tooling keeps it in step. */
|
|
7082
|
+
const eutaxyVersion = "0.12.0";
|
|
7083
|
+
// packages/cli/src/mcp.ts
|
|
7084
|
+
/**
|
|
7085
|
+
* `eutaxy mcp`: a Model Context Protocol server over stdio, so a coding
|
|
7086
|
+
* agent runs the loop "check, read the report, fix or prove, check again"
|
|
7087
|
+
* through one tool. One JSON-RPC message per line on stdin and stdout,
|
|
7088
|
+
* logs on stderr, exit when stdin closes; written with the standard
|
|
7089
|
+
* library alone. It speaks both eras of the protocol: the stateless
|
|
7090
|
+
* `2026-07-28` revision, every request carrying its version and client
|
|
7091
|
+
* capabilities in `_meta` and `server/discover` answering what is
|
|
7092
|
+
* supported; and the `2025-11-25` revision (and its predecessors) with the
|
|
7093
|
+
* `initialize` handshake today's clients open with. The tools are pure
|
|
7094
|
+
* functions of the repository's files that return the JSON report, as
|
|
7095
|
+
* structured content beside its text; a verdict is a result whatever it
|
|
7096
|
+
* says, and only a command that could not run is a tool error. Eutaxy
|
|
7097
|
+
* never calls a model: every verdict depends only on files.
|
|
7098
|
+
*/
|
|
7099
|
+
/** The protocol revisions served: the stateless one by `_meta`, the handshake ones by `initialize`. */
|
|
7100
|
+
const modernVersions = ["2026-07-28"];
|
|
7101
|
+
const legacyVersions = [
|
|
7102
|
+
"2025-11-25",
|
|
7103
|
+
"2025-06-18",
|
|
7104
|
+
"2025-03-26",
|
|
7105
|
+
"2024-11-05"
|
|
7106
|
+
];
|
|
7107
|
+
const protocolVersionKey = "io.modelcontextprotocol/protocolVersion";
|
|
7108
|
+
const clientCapabilitiesKey = "io.modelcontextprotocol/clientCapabilities";
|
|
7109
|
+
const serverInfoKey = "io.modelcontextprotocol/serverInfo";
|
|
7110
|
+
const serverInfo = {
|
|
7111
|
+
name: "eutaxy",
|
|
7112
|
+
version: eutaxyVersion
|
|
7113
|
+
};
|
|
7114
|
+
const instructions = [
|
|
7115
|
+
"Eutaxy checks Cloudflare Workers by deterministic simulation and proves properties of their pure TypeScript core.",
|
|
7116
|
+
"`check` runs a scenario file (*.sim.ts) and returns the verdict: BOUNDED (no violation within the bounds), VIOLATED (with the shrunk schedule, and a regression test written beside the scenario that replays it), or UNSUPPORTED.",
|
|
7117
|
+
"`report` runs every spec file (*.props.ts) under a directory through the TESTED rung and, with engines named, the PROVEN rung.",
|
|
7118
|
+
"`goals` lists the properties the Lean engine could not prove and writes each module's open goals beside its spec file as <spec>.goals.lean, a proof file with every proof open: copy it to <spec>.lean, add lemmas and tactics, then call `prove` on the spec file. A proof whose source or spec changed since the goals were written is stale, never PROVEN.",
|
|
7119
|
+
"`prover_status` says which proof engines are installed; `eutaxy prover install lean` or `smt` installs one.",
|
|
7120
|
+
"Verdicts depend only on files in the repository; nothing here calls a model."
|
|
7121
|
+
].join("\n");
|
|
7122
|
+
const realRunners = {
|
|
7123
|
+
check: runCheck,
|
|
7124
|
+
report: runReport,
|
|
7125
|
+
status: async () => {
|
|
7126
|
+
const engines = [];
|
|
7127
|
+
for (const [name, engine] of Object.entries(provers)) {
|
|
7128
|
+
const a = await engine.available();
|
|
7129
|
+
engines.push({
|
|
7130
|
+
name,
|
|
7131
|
+
..."unavailable" in a ? {
|
|
7132
|
+
installed: false,
|
|
7133
|
+
reason: a.unavailable
|
|
7134
|
+
} : {
|
|
7135
|
+
installed: true,
|
|
7136
|
+
version: a.version
|
|
7137
|
+
}
|
|
7138
|
+
});
|
|
7139
|
+
}
|
|
7140
|
+
return { engines };
|
|
7141
|
+
}
|
|
7142
|
+
};
|
|
7143
|
+
var ToolError = class extends Error {};
|
|
7144
|
+
/** A command's exit code and what it printed. */
|
|
7145
|
+
async function capture(run) {
|
|
7146
|
+
let stdout = "";
|
|
7147
|
+
let stderr = "";
|
|
7148
|
+
return {
|
|
7149
|
+
code: await run((t) => {
|
|
7150
|
+
stdout += t;
|
|
7151
|
+
}, (t) => {
|
|
7152
|
+
stderr += t;
|
|
7153
|
+
}),
|
|
7154
|
+
stdout,
|
|
7155
|
+
stderr
|
|
7156
|
+
};
|
|
7157
|
+
}
|
|
7158
|
+
/** The report a command printed as JSON, or a tool error with what it said instead. */
|
|
7159
|
+
function reported(what, r) {
|
|
7160
|
+
if (r.code === exitCodes.error) throw new ToolError(`${what} could not run (exit 3): ${r.stderr.trim() || r.stdout.trim()}`);
|
|
7161
|
+
try {
|
|
7162
|
+
return JSON.parse(r.stdout);
|
|
7163
|
+
} catch {
|
|
7164
|
+
throw new ToolError(`${what} printed no JSON report: ${(r.stdout + r.stderr).trim()}`);
|
|
7165
|
+
}
|
|
7166
|
+
}
|
|
7167
|
+
const str = (args, key, required = false) => {
|
|
7168
|
+
const v = args[key];
|
|
7169
|
+
if (v === void 0) {
|
|
7170
|
+
if (required) throw new ToolError(`${key} is required`);
|
|
7171
|
+
return;
|
|
7172
|
+
}
|
|
7173
|
+
if (typeof v !== "string" || v.length === 0) throw new ToolError(`${key} must be a non-empty string`);
|
|
7174
|
+
return v;
|
|
7175
|
+
};
|
|
7176
|
+
const bool = (args, key) => {
|
|
7177
|
+
const v = args[key];
|
|
7178
|
+
if (v === void 0) return void 0;
|
|
7179
|
+
if (typeof v !== "boolean") throw new ToolError(`${key} must be a boolean`);
|
|
7180
|
+
return v;
|
|
7181
|
+
};
|
|
7182
|
+
const positiveInt = (args, key) => {
|
|
7183
|
+
const v = args[key];
|
|
7184
|
+
if (v === void 0) return void 0;
|
|
7185
|
+
if (typeof v !== "number" || !Number.isInteger(v) || v <= 0) throw new ToolError(`${key} must be a positive integer`);
|
|
7186
|
+
return v;
|
|
7187
|
+
};
|
|
7188
|
+
const strings = (args, key) => {
|
|
7189
|
+
const v = args[key];
|
|
7190
|
+
if (v === void 0) return void 0;
|
|
7191
|
+
if (!Array.isArray(v) || !v.every((x) => typeof x === "string" && x.length > 0)) throw new ToolError(`${key} must be an array of non-empty strings`);
|
|
7192
|
+
return v;
|
|
7193
|
+
};
|
|
7194
|
+
const only = (args, allowed) => {
|
|
7195
|
+
const extra = Object.keys(args).find((k) => !allowed.includes(k));
|
|
7196
|
+
if (extra !== void 0) throw new ToolError(`unknown argument ${extra}; the arguments are ${allowed.join(", ")}`);
|
|
7197
|
+
};
|
|
7198
|
+
const engineNames = Object.keys(provers);
|
|
7199
|
+
const proversSchema = {
|
|
7200
|
+
type: "array",
|
|
7201
|
+
items: {
|
|
7202
|
+
type: "string",
|
|
7203
|
+
enum: engineNames
|
|
7204
|
+
},
|
|
7205
|
+
description: `Proof engines for the PROVEN rung: ${engineNames.join(", ")}`
|
|
7206
|
+
};
|
|
7207
|
+
const asResult = (structured, isError = false) => ({
|
|
7208
|
+
structured,
|
|
7209
|
+
text: JSON.stringify(structured, null, 2),
|
|
7210
|
+
...isError ? { isError: true } : {}
|
|
7211
|
+
});
|
|
7212
|
+
const tools = [
|
|
7213
|
+
{
|
|
7214
|
+
name: "check",
|
|
7215
|
+
title: "Check a scenario",
|
|
7216
|
+
description: "Run a scenario file (*.sim.ts) in the simulator and return the JSON report: the verdict (BOUNDED, VIOLATED with the shrunk schedule, or UNSUPPORTED), the spec verdicts, and on a violation the path of the regression test written beside the scenario (regressionTest). Exit code 1 is a violation or a refuted spec, not an error.",
|
|
7217
|
+
inputSchema: {
|
|
7218
|
+
type: "object",
|
|
7219
|
+
properties: {
|
|
7220
|
+
scenario: {
|
|
7221
|
+
type: "string",
|
|
7222
|
+
description: "Path of the scenario file, relative to the working directory"
|
|
7223
|
+
},
|
|
7224
|
+
wrangler: {
|
|
7225
|
+
type: "string",
|
|
7226
|
+
description: "Wrangler config path; default: the one beside the scenario"
|
|
7227
|
+
},
|
|
7228
|
+
seed: {
|
|
7229
|
+
type: "string",
|
|
7230
|
+
description: "Exploration seed; default: the scenario file name"
|
|
7231
|
+
},
|
|
7232
|
+
maxRuns: {
|
|
7233
|
+
type: "integer",
|
|
7234
|
+
minimum: 1,
|
|
7235
|
+
description: "Cap on exploration runs"
|
|
7236
|
+
},
|
|
7237
|
+
budgetMs: {
|
|
7238
|
+
type: "integer",
|
|
7239
|
+
minimum: 1,
|
|
7240
|
+
description: "Time budget in milliseconds, replacing the scenario's"
|
|
7241
|
+
},
|
|
7242
|
+
exhaustive: {
|
|
7243
|
+
type: "boolean",
|
|
7244
|
+
description: "Run every schedule within the bounds once"
|
|
7245
|
+
},
|
|
7246
|
+
provers: proversSchema,
|
|
7247
|
+
regression: {
|
|
7248
|
+
type: "boolean",
|
|
7249
|
+
description: "Write the regression test on a violation; default true"
|
|
7250
|
+
},
|
|
7251
|
+
out: {
|
|
7252
|
+
type: "string",
|
|
7253
|
+
description: "Where to write the regression test"
|
|
7254
|
+
}
|
|
7255
|
+
},
|
|
7256
|
+
required: ["scenario"],
|
|
7257
|
+
additionalProperties: false
|
|
7258
|
+
},
|
|
7259
|
+
async run(args, ctx, runners) {
|
|
7260
|
+
only(args, [
|
|
7261
|
+
"scenario",
|
|
7262
|
+
"wrangler",
|
|
7263
|
+
"seed",
|
|
7264
|
+
"maxRuns",
|
|
7265
|
+
"budgetMs",
|
|
7266
|
+
"exhaustive",
|
|
7267
|
+
"provers",
|
|
7268
|
+
"regression",
|
|
7269
|
+
"out"
|
|
7270
|
+
]);
|
|
7271
|
+
const scenario = str(args, "scenario", true);
|
|
7272
|
+
const wrangler = str(args, "wrangler");
|
|
7273
|
+
const seed = str(args, "seed");
|
|
7274
|
+
const maxRuns = positiveInt(args, "maxRuns");
|
|
7275
|
+
const budgetMs = positiveInt(args, "budgetMs");
|
|
7276
|
+
const engines = strings(args, "provers");
|
|
7277
|
+
const out = str(args, "out");
|
|
7278
|
+
const r = await capture((stdout, stderr) => runners.check({
|
|
7279
|
+
scenario,
|
|
7280
|
+
cwd: ctx.cwd,
|
|
7281
|
+
...wrangler === void 0 ? {} : { wrangler },
|
|
7282
|
+
...seed === void 0 ? {} : { seed },
|
|
7283
|
+
...maxRuns === void 0 ? {} : { maxRuns },
|
|
7284
|
+
...budgetMs === void 0 ? {} : { budgetMs },
|
|
7285
|
+
exhaustive: bool(args, "exhaustive") === true,
|
|
7286
|
+
...engines === void 0 ? {} : { provers: engines },
|
|
7287
|
+
json: true,
|
|
7288
|
+
...out === void 0 ? {} : { out },
|
|
7289
|
+
noRegression: bool(args, "regression") === false,
|
|
7290
|
+
expectViolation: false,
|
|
7291
|
+
keep: false,
|
|
7292
|
+
stdout,
|
|
7293
|
+
stderr
|
|
7294
|
+
}));
|
|
7295
|
+
return asResult({
|
|
7296
|
+
exitCode: r.code,
|
|
7297
|
+
report: reported("check", r)
|
|
7298
|
+
});
|
|
7299
|
+
}
|
|
7300
|
+
},
|
|
7301
|
+
{
|
|
7302
|
+
name: "report",
|
|
7303
|
+
title: "Report on the spec files",
|
|
7304
|
+
description: "Run every spec file (*.props.ts) under a directory through the TESTED rung and, with engines named, the PROVEN rung; return the JSON report of spec verdicts. Exit code 1 is a refuted or conflicting spec, not an error.",
|
|
7305
|
+
inputSchema: {
|
|
7306
|
+
type: "object",
|
|
7307
|
+
properties: {
|
|
7308
|
+
dir: {
|
|
7309
|
+
type: "string",
|
|
7310
|
+
description: "Directory to search; default: the working directory"
|
|
7311
|
+
},
|
|
7312
|
+
provers: proversSchema,
|
|
7313
|
+
seed: {
|
|
7314
|
+
type: "string",
|
|
7315
|
+
description: "Seed for the TESTED rung; default report"
|
|
7316
|
+
}
|
|
7317
|
+
},
|
|
7318
|
+
additionalProperties: false
|
|
7319
|
+
},
|
|
7320
|
+
async run(args, ctx, runners) {
|
|
7321
|
+
only(args, [
|
|
7322
|
+
"dir",
|
|
7323
|
+
"provers",
|
|
7324
|
+
"seed"
|
|
7325
|
+
]);
|
|
7326
|
+
const dir = str(args, "dir");
|
|
7327
|
+
const engines = strings(args, "provers");
|
|
7328
|
+
const seed = str(args, "seed");
|
|
7329
|
+
const r = await capture((stdout, stderr) => runners.report({
|
|
7330
|
+
cwd: ctx.cwd,
|
|
7331
|
+
...dir === void 0 ? {} : { dir },
|
|
7332
|
+
...engines === void 0 ? {} : { provers: engines },
|
|
7333
|
+
...seed === void 0 ? {} : { seed },
|
|
7334
|
+
json: true,
|
|
7335
|
+
stdout,
|
|
7336
|
+
stderr
|
|
7337
|
+
}));
|
|
7338
|
+
return asResult({
|
|
7339
|
+
exitCode: r.code,
|
|
7340
|
+
report: reported("report", r)
|
|
7341
|
+
});
|
|
7342
|
+
}
|
|
7343
|
+
},
|
|
7344
|
+
{
|
|
7345
|
+
name: "goals",
|
|
7346
|
+
title: "List the open proof goals",
|
|
7347
|
+
description: "Run the Lean engine on every spec file under a directory and list the properties it could not prove, each with the statement it tried; write each module's open goals beside its spec file as <spec>.goals.lean, a proof file with every proof open (copy it to <spec>.lean, add lemmas and tactics, then call prove). Needs the lean engine installed.",
|
|
7348
|
+
inputSchema: {
|
|
7349
|
+
type: "object",
|
|
7350
|
+
properties: { dir: {
|
|
7351
|
+
type: "string",
|
|
7352
|
+
description: "Directory to search; default: the working directory"
|
|
7353
|
+
} },
|
|
7354
|
+
additionalProperties: false
|
|
7355
|
+
},
|
|
7356
|
+
async run(args, ctx, runners) {
|
|
7357
|
+
only(args, ["dir"]);
|
|
7358
|
+
const dir = str(args, "dir");
|
|
7359
|
+
const r = await capture((stdout, stderr) => runners.report({
|
|
7360
|
+
cwd: ctx.cwd,
|
|
7361
|
+
...dir === void 0 ? {} : { dir },
|
|
7362
|
+
provers: ["lean"],
|
|
7363
|
+
goals: true,
|
|
7364
|
+
json: true,
|
|
7365
|
+
stdout,
|
|
7366
|
+
stderr
|
|
7367
|
+
}));
|
|
7368
|
+
return asResult({
|
|
7369
|
+
exitCode: r.code,
|
|
7370
|
+
report: reported("goals", r)
|
|
7371
|
+
});
|
|
7372
|
+
}
|
|
7373
|
+
},
|
|
7374
|
+
{
|
|
7375
|
+
name: "prove",
|
|
7376
|
+
title: "Check the proofs supplied for a spec file",
|
|
7377
|
+
description: "Run the Lean engine on one module, the one whose spec file (*.props.ts) is given, with the proofs supplied beside it in <spec>.lean, and return its spec verdicts: PROVEN where a proof closes (Lean's kernel checked it against the statement Eutaxy emitted), UNKNOWN with the reason where it does not, or where the proof file is stale (written for another version of the module or the spec).",
|
|
7378
|
+
inputSchema: {
|
|
7379
|
+
type: "object",
|
|
7380
|
+
properties: { spec: {
|
|
7381
|
+
type: "string",
|
|
7382
|
+
description: "Path of the spec file, relative to the working directory"
|
|
7383
|
+
} },
|
|
7384
|
+
required: ["spec"],
|
|
7385
|
+
additionalProperties: false
|
|
7386
|
+
},
|
|
7387
|
+
async run(args, ctx, runners) {
|
|
7388
|
+
only(args, ["spec"]);
|
|
7389
|
+
const spec = str(args, "spec", true);
|
|
7390
|
+
const r = await capture((stdout, stderr) => runners.report({
|
|
7391
|
+
cwd: ctx.cwd,
|
|
7392
|
+
dir: dirname(spec),
|
|
7393
|
+
only: spec,
|
|
7394
|
+
provers: ["lean"],
|
|
7395
|
+
json: true,
|
|
7396
|
+
stdout,
|
|
7397
|
+
stderr
|
|
7398
|
+
}));
|
|
7399
|
+
return asResult({
|
|
7400
|
+
exitCode: r.code,
|
|
7401
|
+
report: reported("prove", r)
|
|
7402
|
+
});
|
|
7403
|
+
}
|
|
7404
|
+
},
|
|
7405
|
+
{
|
|
7406
|
+
name: "prover_status",
|
|
7407
|
+
title: "Which proof engines are installed",
|
|
7408
|
+
description: "For each proof engine (lean, smt): whether its pinned toolchain is installed and its version, or why not and how to install it (eutaxy prover install <name>).",
|
|
7409
|
+
inputSchema: {
|
|
7410
|
+
type: "object",
|
|
7411
|
+
additionalProperties: false
|
|
7412
|
+
},
|
|
7413
|
+
async run(args, _ctx, runners) {
|
|
7414
|
+
only(args, []);
|
|
7415
|
+
return asResult(await runners.status());
|
|
7416
|
+
}
|
|
7417
|
+
}
|
|
7418
|
+
];
|
|
7419
|
+
const errorResponse = (id, code, message, data) => ({
|
|
7420
|
+
jsonrpc: "2.0",
|
|
7421
|
+
id,
|
|
7422
|
+
error: {
|
|
7423
|
+
code,
|
|
7424
|
+
message,
|
|
7425
|
+
...data === void 0 ? {} : { data }
|
|
7426
|
+
}
|
|
7427
|
+
});
|
|
7428
|
+
/** A result in the requester's era: the stateless one carries `resultType` and the server's identity. */
|
|
7429
|
+
const resultResponse = (req, result) => ({
|
|
7430
|
+
jsonrpc: "2.0",
|
|
7431
|
+
id: req.id,
|
|
7432
|
+
result: req.modern ? {
|
|
7433
|
+
resultType: "complete",
|
|
7434
|
+
...result,
|
|
7435
|
+
_meta: { [serverInfoKey]: serverInfo }
|
|
7436
|
+
} : result
|
|
7437
|
+
});
|
|
7438
|
+
const toolListing = () => tools.map((t) => ({
|
|
7439
|
+
name: t.name,
|
|
7440
|
+
title: t.title,
|
|
7441
|
+
description: t.description,
|
|
7442
|
+
inputSchema: t.inputSchema
|
|
7443
|
+
}));
|
|
7444
|
+
async function callTool(req, ctx) {
|
|
7445
|
+
const name = req.params["name"];
|
|
7446
|
+
const tool = tools.find((t) => t.name === name);
|
|
7447
|
+
if (typeof name !== "string" || !tool) return errorResponse(req.id, -32602, `Unknown tool: ${String(name)}`);
|
|
7448
|
+
const args = req.params["arguments"] ?? {};
|
|
7449
|
+
if (typeof args !== "object" || args === null || Array.isArray(args)) return errorResponse(req.id, -32602, "arguments must be an object");
|
|
7450
|
+
const runners = {
|
|
7451
|
+
...realRunners,
|
|
7452
|
+
...ctx.runners
|
|
7453
|
+
};
|
|
7454
|
+
let result;
|
|
7455
|
+
try {
|
|
7456
|
+
result = await tool.run(args, ctx, runners);
|
|
7457
|
+
} catch (err) {
|
|
7458
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
7459
|
+
result = {
|
|
7460
|
+
structured: { error: message },
|
|
7461
|
+
text: message,
|
|
7462
|
+
isError: true
|
|
7463
|
+
};
|
|
7464
|
+
}
|
|
7465
|
+
return resultResponse(req, {
|
|
7466
|
+
content: [{
|
|
7467
|
+
type: "text",
|
|
7468
|
+
text: result.text
|
|
7469
|
+
}],
|
|
7470
|
+
structuredContent: result.structured,
|
|
7471
|
+
isError: result.isError === true
|
|
7472
|
+
});
|
|
7473
|
+
}
|
|
7474
|
+
/**
|
|
7475
|
+
* One line in, at most one line out: the response to a request, nothing
|
|
7476
|
+
* for a notification. A request of the stateless era whose version is not
|
|
7477
|
+
* served gets the `UnsupportedProtocolVersion` error with what is.
|
|
7478
|
+
*/
|
|
7479
|
+
async function handleLine(line, ctx) {
|
|
7480
|
+
let message;
|
|
7481
|
+
try {
|
|
7482
|
+
message = JSON.parse(line);
|
|
7483
|
+
} catch {
|
|
7484
|
+
return JSON.stringify(errorResponse(null, -32700, "Parse error"));
|
|
7485
|
+
}
|
|
7486
|
+
if (Array.isArray(message)) return JSON.stringify(errorResponse(null, -32600, "Invalid Request: batches are not supported"));
|
|
7487
|
+
if (typeof message !== "object" || message === null) return JSON.stringify(errorResponse(null, -32600, "Invalid Request"));
|
|
7488
|
+
const m = message;
|
|
7489
|
+
const id = m["id"];
|
|
7490
|
+
const idOk = typeof id === "string" || typeof id === "number";
|
|
7491
|
+
if (m["jsonrpc"] !== "2.0" || typeof m["method"] !== "string") return JSON.stringify(errorResponse(idOk ? id : null, -32600, "Invalid Request"));
|
|
7492
|
+
if (id === void 0) return void 0;
|
|
7493
|
+
if (!idOk) return JSON.stringify(errorResponse(null, -32600, "Invalid Request: id must be a string or a number"));
|
|
7494
|
+
const params = typeof m["params"] === "object" && m["params"] !== null ? m["params"] : {};
|
|
7495
|
+
const meta = typeof params["_meta"] === "object" && params["_meta"] !== null ? params["_meta"] : {};
|
|
7496
|
+
const requested = meta[protocolVersionKey];
|
|
7497
|
+
const req = {
|
|
7498
|
+
id,
|
|
7499
|
+
method: m["method"],
|
|
7500
|
+
params,
|
|
7501
|
+
modern: typeof requested === "string"
|
|
7502
|
+
};
|
|
7503
|
+
if (req.modern) {
|
|
7504
|
+
if (!modernVersions.includes(requested)) return JSON.stringify(errorResponse(req.id, -32022, "Unsupported protocol version", {
|
|
7505
|
+
supported: [...modernVersions],
|
|
7506
|
+
requested
|
|
7507
|
+
}));
|
|
7508
|
+
if (typeof meta[clientCapabilitiesKey] !== "object" || meta[clientCapabilitiesKey] === null) return JSON.stringify(errorResponse(req.id, -32602, `Invalid params: _meta.${clientCapabilitiesKey} is required`));
|
|
7509
|
+
}
|
|
7510
|
+
let response;
|
|
7511
|
+
try {
|
|
7512
|
+
response = await dispatch(req, ctx);
|
|
7513
|
+
} catch (err) {
|
|
7514
|
+
response = errorResponse(req.id, -32603, `Internal error: ${err instanceof Error ? err.message : String(err)}`);
|
|
7515
|
+
}
|
|
7516
|
+
return JSON.stringify(response);
|
|
7517
|
+
}
|
|
7518
|
+
async function dispatch(req, ctx) {
|
|
7519
|
+
switch (req.method) {
|
|
7520
|
+
case "initialize": {
|
|
7521
|
+
const asked = req.params["protocolVersion"];
|
|
7522
|
+
const version = typeof asked === "string" && legacyVersions.includes(asked) ? asked : legacyVersions[0];
|
|
7523
|
+
return resultResponse(req, {
|
|
7524
|
+
protocolVersion: version,
|
|
7525
|
+
capabilities: { tools: {} },
|
|
7526
|
+
serverInfo,
|
|
7527
|
+
instructions
|
|
7528
|
+
});
|
|
7529
|
+
}
|
|
7530
|
+
case "ping": return resultResponse(req, {});
|
|
7531
|
+
case "server/discover": return resultResponse(req, {
|
|
7532
|
+
supportedVersions: [...modernVersions],
|
|
7533
|
+
capabilities: { tools: {} },
|
|
7534
|
+
instructions
|
|
7535
|
+
});
|
|
7536
|
+
case "tools/list": return resultResponse(req, { tools: toolListing() });
|
|
7537
|
+
case "tools/call": return callTool(req, ctx);
|
|
7538
|
+
default: return errorResponse(req.id, -32601, `Method not found: ${req.method}`);
|
|
7539
|
+
}
|
|
7540
|
+
}
|
|
7541
|
+
/** Serve on the process's standard streams until stdin closes. Requests are answered one at a time, in order. */
|
|
7542
|
+
async function serveStdio(ctx) {
|
|
7543
|
+
const lines = createInterface({
|
|
7544
|
+
input: process.stdin,
|
|
7545
|
+
crlfDelay: Number.POSITIVE_INFINITY
|
|
7546
|
+
});
|
|
7547
|
+
for await (const line of lines) {
|
|
7548
|
+
if (line.trim().length === 0) continue;
|
|
7549
|
+
const out = await handleLine(line, ctx);
|
|
7550
|
+
if (out !== void 0) process.stdout.write(`${out}\n`);
|
|
7551
|
+
}
|
|
7552
|
+
return exitCodes.BOUNDED;
|
|
7553
|
+
}
|
|
6275
7554
|
// packages/cli/src/main.ts
|
|
6276
7555
|
const usage = `eutaxy — deterministic simulation checks and spec verdicts for Cloudflare Workers
|
|
6277
7556
|
|
|
6278
7557
|
Usage:
|
|
6279
7558
|
eutaxy check <scenario.sim.ts> [options]
|
|
6280
7559
|
eutaxy report [dir] [--prover <names>] [--seed <seed>] [--json]
|
|
7560
|
+
eutaxy prover install <lean|smt> [--from <url or directory>] [--json]
|
|
7561
|
+
eutaxy mcp
|
|
6281
7562
|
|
|
6282
7563
|
check options:
|
|
6283
7564
|
--wrangler <path> wrangler config (default: wrangler.jsonc/json/toml beside the scenario)
|
|
@@ -6298,8 +7579,21 @@ through the TESTED rung, on inputs drawn from the parameter types with the seed
|
|
|
6298
7579
|
(default: report), and the PROVEN rung with --prover. No scenario runs, so nothing
|
|
6299
7580
|
is CHECKED.
|
|
6300
7581
|
|
|
7582
|
+
prover install puts the pinned Lean or Z3 release for this platform in Eutaxy's cache
|
|
7583
|
+
(EUTAXY_CACHE_DIR, else the platform's user cache), where --prover finds it first:
|
|
7584
|
+
downloaded from the upstream GitHub release, or from a mirror or offline directory
|
|
7585
|
+
holding the same file (--from), and checked against the engine's SHA-256 before it is
|
|
7586
|
+
unpacked. Nothing is downloaded at any other time.
|
|
7587
|
+
|
|
7588
|
+
report options: --goals writes each module's open Lean goals beside its spec file as
|
|
7589
|
+
<spec>.goals.lean (a proof file with every proof open) and lists them; needs --prover lean.
|
|
7590
|
+
|
|
7591
|
+
mcp serves the Model Context Protocol over stdio (one JSON-RPC message per line, logs on
|
|
7592
|
+
stderr) for a coding agent: tools check, report, goals, prove and prover_status, each
|
|
7593
|
+
returning the JSON report. Point the agent's MCP configuration at "eutaxy mcp".
|
|
7594
|
+
|
|
6301
7595
|
Exit codes: 0 BOUNDED, 1 VIOLATED or a REFUTED or CONFLICT spec, 2 UNSUPPORTED, 3 error.
|
|
6302
|
-
report: 0, or 1 for a REFUTED or CONFLICT spec, 3 error.
|
|
7596
|
+
report: 0, or 1 for a REFUTED or CONFLICT spec, 3 error. prover install: 0, or 3.
|
|
6303
7597
|
`;
|
|
6304
7598
|
async function main(argv, io) {
|
|
6305
7599
|
const { positionals, flags } = parseArgs(argv, [
|
|
@@ -6308,7 +7602,8 @@ async function main(argv, io) {
|
|
|
6308
7602
|
"expect-violation",
|
|
6309
7603
|
"keep",
|
|
6310
7604
|
"help",
|
|
6311
|
-
"exhaustive"
|
|
7605
|
+
"exhaustive",
|
|
7606
|
+
"goals"
|
|
6312
7607
|
]);
|
|
6313
7608
|
const command = positionals[0];
|
|
6314
7609
|
if (!command || command === "help" || flags["help"] === true) {
|
|
@@ -6321,13 +7616,48 @@ async function main(argv, io) {
|
|
|
6321
7616
|
"max-runs",
|
|
6322
7617
|
"budget-ms",
|
|
6323
7618
|
"prover",
|
|
6324
|
-
"out"
|
|
7619
|
+
"out",
|
|
7620
|
+
"from"
|
|
6325
7621
|
]) if (flags[k] === true) {
|
|
6326
7622
|
io.stderr(`--${k} needs a value\n`);
|
|
6327
7623
|
return exitCodes.error;
|
|
6328
7624
|
}
|
|
6329
7625
|
const str = (k) => typeof flags[k] === "string" ? flags[k] : void 0;
|
|
6330
7626
|
const provers = (str("prover") ?? "").split(",").map((n) => n.trim()).filter((n) => n.length > 0);
|
|
7627
|
+
if (command === "mcp") {
|
|
7628
|
+
if (positionals.length !== 1 || Object.keys(flags).length > 0) {
|
|
7629
|
+
io.stderr(`mcp takes no arguments\n\n${usage}`);
|
|
7630
|
+
return exitCodes.error;
|
|
7631
|
+
}
|
|
7632
|
+
return serveStdio({
|
|
7633
|
+
cwd: io.cwd,
|
|
7634
|
+
log: io.stderr
|
|
7635
|
+
});
|
|
7636
|
+
}
|
|
7637
|
+
if (command === "prover") {
|
|
7638
|
+
const names = Object.keys(toolchains).join("|");
|
|
7639
|
+
if (positionals[1] !== "install" || positionals.length !== 3) {
|
|
7640
|
+
io.stderr(`prover takes: install <${names}>\n\n${usage}`);
|
|
7641
|
+
return exitCodes.error;
|
|
7642
|
+
}
|
|
7643
|
+
const other = Object.keys(flags).find((k) => !["from", "json"].includes(k));
|
|
7644
|
+
if (other !== void 0) {
|
|
7645
|
+
io.stderr(`prover install does not take --${other}\n`);
|
|
7646
|
+
return exitCodes.error;
|
|
7647
|
+
}
|
|
7648
|
+
const toolchain = toolchains[positionals[2]];
|
|
7649
|
+
if (toolchain === void 0) {
|
|
7650
|
+
io.stderr(`unknown engine ${positionals[2]}; the engines are ${names.replaceAll("|", ", ")}\n`);
|
|
7651
|
+
return exitCodes.error;
|
|
7652
|
+
}
|
|
7653
|
+
return runInstall({
|
|
7654
|
+
toolchain,
|
|
7655
|
+
from: str("from"),
|
|
7656
|
+
json: flags["json"] === true,
|
|
7657
|
+
stdout: io.stdout,
|
|
7658
|
+
stderr: io.stderr
|
|
7659
|
+
});
|
|
7660
|
+
}
|
|
6331
7661
|
if (command === "report") {
|
|
6332
7662
|
if (positionals.length > 2) {
|
|
6333
7663
|
io.stderr(`report takes one directory\n\n${usage}`);
|
|
@@ -6336,7 +7666,8 @@ async function main(argv, io) {
|
|
|
6336
7666
|
const other = Object.keys(flags).find((k) => ![
|
|
6337
7667
|
"prover",
|
|
6338
7668
|
"seed",
|
|
6339
|
-
"json"
|
|
7669
|
+
"json",
|
|
7670
|
+
"goals"
|
|
6340
7671
|
].includes(k));
|
|
6341
7672
|
if (other !== void 0) {
|
|
6342
7673
|
io.stderr(`report does not take --${other}\n`);
|
|
@@ -6348,6 +7679,7 @@ async function main(argv, io) {
|
|
|
6348
7679
|
...dir === void 0 ? {} : { dir },
|
|
6349
7680
|
...provers.length > 0 ? { provers } : {},
|
|
6350
7681
|
...str("seed") ? { seed: str("seed") } : {},
|
|
7682
|
+
...flags["goals"] === true ? { goals: true } : {},
|
|
6351
7683
|
json: flags["json"] === true,
|
|
6352
7684
|
stdout: io.stdout,
|
|
6353
7685
|
stderr: io.stderr
|
|
@@ -10360,4 +11692,4 @@ async function checkInWorkerd(input) {
|
|
|
10360
11692
|
}
|
|
10361
11693
|
export { serviceCall as A, r2Op as C, rpc as D, refines as E, snapshotD1 as F, check as I, expectHolds as L, workflow as M, workflowRows as N, rpcResponse as O, workflowStep as P, main as R, r2Bucket as S, references as T, http as _, cron as a, queue as b, d1Rows as c, defineScenario as d, durableObject as f, fetchCall as g, external as h, atLeastOncePerMessage as i, unique as j, service as k, d1Schema as l, everyRow as m, runDifferential as n, d1Param as o, durableObjectRows as p, createCloudflarePlatform as r, d1Read as s, checkInWorkerd as t, d1Write as u, httpResponse as v, r2Rows as w, queueAck as x, implies as y, cloudflareRegressionTest as z };
|
|
10362
11694
|
|
|
10363
|
-
//# sourceMappingURL=src-
|
|
11695
|
+
//# sourceMappingURL=src-DIG0_CjU.mjs.map
|