eutaxy 0.10.0 → 0.11.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.
@@ -4,14 +4,17 @@ 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
14
  import { fileURLToPath, pathToFileURL } from "node:url";
15
+ import { createHash, randomBytes } from "node:crypto";
16
+ import { Readable } from "node:stream";
17
+ import { createZstdDecompress, inflateRawSync } from "node:zlib";
15
18
  // packages/cli/src/args.ts
16
19
  function parseArgs(argv, booleans = []) {
17
20
  const positionals = [];
@@ -4019,14 +4022,90 @@ function leanString(value) {
4019
4022
  }
4020
4023
  return `${out}"`;
4021
4024
  }
4025
+ // packages/prover/src/toolchain.ts
4026
+ /**
4027
+ * Where a pinned prover toolchain lives on this machine once `eutaxy prover
4028
+ * install` has put it there, and what that command downloads: one upstream
4029
+ * release file per platform, with the checksum the download must match.
4030
+ * Node-side only (`@eutaxy/prover/toolchain`, a subpath so workerd never
4031
+ * loads it): it reads the file system, so this file alone references Node's
4032
+ * types, as the reader alone uses the compiler's. Nothing here downloads or
4033
+ * runs anything; the engines ask `installed` and the command does the rest.
4034
+ */
4035
+ const platforms = [
4036
+ "linux-x64",
4037
+ "linux-arm64",
4038
+ "darwin-x64",
4039
+ "darwin-arm64",
4040
+ "win32-x64"
4041
+ ];
4042
+ function host() {
4043
+ return {
4044
+ platform: process.platform,
4045
+ arch: process.arch,
4046
+ env: process.env,
4047
+ home: homedir()
4048
+ };
4049
+ }
4050
+ function platformOf(h) {
4051
+ const key = `${h.platform}-${h.arch}`;
4052
+ return platforms.includes(key) ? key : void 0;
4053
+ }
4054
+ /**
4055
+ * Eutaxy's cache directory: `EUTAXY_CACHE_DIR`, else the platform's user
4056
+ * cache (`$XDG_CACHE_HOME/eutaxy` or `~/.cache/eutaxy` on Linux,
4057
+ * `~/Library/Caches/eutaxy` on macOS, `%LOCALAPPDATA%\eutaxy\Cache` on
4058
+ * Windows). Always absolute: the engines spawn the executable from a
4059
+ * scratch directory, where a relative path would not resolve.
4060
+ */
4061
+ function cacheDir(h = host()) {
4062
+ const set = h.env["EUTAXY_CACHE_DIR"];
4063
+ if (set) return resolve(set);
4064
+ if (h.platform === "darwin") return join(h.home, "Library", "Caches", "eutaxy");
4065
+ if (h.platform === "win32") return join(h.env["LOCALAPPDATA"] || join(h.home, "AppData", "Local"), "eutaxy", "Cache");
4066
+ return resolve(h.env["XDG_CACHE_HOME"] || join(h.home, ".cache"), "eutaxy");
4067
+ }
4068
+ /** Where one toolchain's unpacked release lives: `<cache>/toolchains/<name>/<version>`. */
4069
+ function toolchainDir(cache, toolchain) {
4070
+ return join(cache, "toolchains", toolchain.name, toolchain.version);
4071
+ }
4072
+ /** The file the command writes last, so its presence means the install completed. */
4073
+ const markerFile = "eutaxy-toolchain.json";
4074
+ function executableName(toolchain, h) {
4075
+ return h.platform === "win32" ? `${toolchain.executable}.exe` : toolchain.executable;
4076
+ }
4077
+ /**
4078
+ * The toolchain the command put in the cache, if its marker and its
4079
+ * executable are both there and the marker names this toolchain for this
4080
+ * platform (a cache carried to another machine holds the wrong binary).
4081
+ */
4082
+ function installed(toolchain, h = host()) {
4083
+ const dir = toolchainDir(cacheDir(h), toolchain);
4084
+ const executable = join(dir, executableName(toolchain, h));
4085
+ const markerPath = join(dir, markerFile);
4086
+ if (!existsSync(markerPath) || !existsSync(executable)) return void 0;
4087
+ try {
4088
+ const marker = JSON.parse(readFileSync(markerPath, "utf8"));
4089
+ 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;
4090
+ return {
4091
+ dir,
4092
+ executable,
4093
+ marker
4094
+ };
4095
+ } catch {
4096
+ return;
4097
+ }
4098
+ }
4022
4099
  // packages/prover-lean/src/lean.ts
4023
4100
  /**
4024
4101
  * Running Lean over a process boundary. The engine is pinned to one Lean
4025
- * release: `elan` (Lean's toolchain manager) is asked for it by name, and a
4026
- * `lean` found without `elan` must report that version. Nothing is ever
4027
- * downloaded during a check; a missing toolchain is `unavailable`, with the
4028
- * command that installs it. Diagnostics come back as `file:line:col:
4029
- * severity: message` lines, which the engine maps to theorems.
4102
+ * release, looked for in Eutaxy's cache first (where `eutaxy prover install
4103
+ * lean` puts the upstream release named in `leanDownloads`), then through
4104
+ * `elan` (Lean's toolchain manager), asked for it by name, then as a bare
4105
+ * `lean` that must report that version. Nothing is ever downloaded during
4106
+ * a check; a missing toolchain is `unavailable`, with the command that
4107
+ * installs it. Diagnostics come back as `file:line:col: severity: message`
4108
+ * lines, which the engine maps to theorems.
4030
4109
  */
4031
4110
  /**
4032
4111
  * The Lean release the engine's contract corpus is checked against. On a
@@ -4039,7 +4118,33 @@ function leanString(value) {
4039
4118
  const leanToolchain = "leanprover/lean4:v4.35.0";
4040
4119
  const leanVersion = "4.35.0";
4041
4120
  /** How to put the pinned toolchain on this machine. */
4042
- const installHint$1 = `install elan (https://elan.lean-lang.org) and run: elan toolchain install ${leanToolchain}`;
4121
+ const installHint$1 = `run: eutaxy prover install lean (or install elan, https://elan.lean-lang.org, and run: elan toolchain install ${leanToolchain})`;
4122
+ const leanRelease = `https://github.com/leanprover/lean4/releases/download/v${leanVersion}`;
4123
+ const leanFile = (name, sha256, bytes) => ({
4124
+ file: name,
4125
+ url: `${leanRelease}/${name}`,
4126
+ sha256,
4127
+ bytes
4128
+ });
4129
+ /**
4130
+ * The upstream release files `eutaxy prover install lean` downloads, one per
4131
+ * platform, as published on Lean's GitHub release with the checksums it
4132
+ * reports; the file names carry the version, and a test holds them to
4133
+ * `leanVersion`. The compiler ships its C toolchain, so each is 570 to
4134
+ * 620 MB, the same download elan makes.
4135
+ */
4136
+ const leanDownloads = {
4137
+ name: "lean",
4138
+ version: leanVersion,
4139
+ executable: "bin/lean",
4140
+ files: {
4141
+ "linux-x64": leanFile("lean-4.35.0-linux.tar.zst", "7289597a44543246c9227b8cae501767e095ce17f6d448b95fc4a8dc97268f6d", 594481375),
4142
+ "linux-arm64": leanFile("lean-4.35.0-linux_aarch64.tar.zst", "c8f0f8a3920e839718b1343e6781fd80a3e9b1024fbcd7078eb30f54e806b028", 594868592),
4143
+ "darwin-x64": leanFile("lean-4.35.0-darwin.tar.zst", "0b43be5c7ecfb36016566a41005ab62bdb04743e6bfd5837e45f796ef4750b4e", 576516478),
4144
+ "darwin-arm64": leanFile("lean-4.35.0-darwin_aarch64.tar.zst", "c0c6f34f35ba1dcc5c4a5fd106fefab9eb5e8469712624dd2c868d51b63177c2", 570422530),
4145
+ "win32-x64": leanFile("lean-4.35.0-windows.tar.zst", "893fde3f52b48c647e3edcf33844cbb61f8ef70fcd88e0536bfc83f29844081e", 622724192)
4146
+ }
4147
+ };
4043
4148
  function run$1(command, args, options) {
4044
4149
  return new Promise((resolve) => {
4045
4150
  let child;
@@ -4106,15 +4211,29 @@ function candidates$1(name) {
4106
4211
  return [name, join(home, "bin", name)];
4107
4212
  }
4108
4213
  /**
4109
- * The pinned toolchain if it is installed: through `elan run <toolchain>`
4110
- * when elan is present (and only when it already has the toolchain, so
4111
- * nothing is downloaded), else a bare `lean` of exactly that version.
4214
+ * The pinned toolchain if it is installed: the one `eutaxy prover install
4215
+ * lean` put in the cache, when it answers with the pinned version; else
4216
+ * through `elan run <toolchain>` when elan is present (and only when it
4217
+ * already has the toolchain, so nothing is downloaded); else a bare `lean`
4218
+ * of exactly that version.
4112
4219
  */
4113
- async function findLean() {
4220
+ async function findLean(h = host()) {
4221
+ let cached;
4222
+ const fromCache = installed(leanDownloads, h);
4223
+ if (fromCache) {
4224
+ const v = await run$1(fromCache.executable, ["--version"], { timeoutMs: 2e4 });
4225
+ const m = /Lean \(version ([^,]+),/.exec(v.stdout);
4226
+ if (v.code === 0 && m?.[1] === "4.35.0") return {
4227
+ command: fromCache.executable,
4228
+ args: [],
4229
+ version: leanVersion
4230
+ };
4231
+ cached = `the toolchain in ${fromCache.dir} did not answer as Lean ${leanVersion} (delete it and run: eutaxy prover install lean)`;
4232
+ }
4114
4233
  for (const elan of candidates$1("elan")) {
4115
4234
  const list = await run$1(elan, ["toolchain", "list"], { timeoutMs: 2e4 });
4116
4235
  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}; run: elan toolchain install ${leanToolchain}` };
4236
+ 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
4237
  return {
4119
4238
  command: elan,
4120
4239
  args: [
@@ -4134,9 +4253,9 @@ async function findLean() {
4134
4253
  args: [],
4135
4254
  version: leanVersion
4136
4255
  };
4137
- return { unavailable: `lean ${m?.[1] ?? "of unknown version"} found, but the engine is pinned to ${leanVersion}; ${installHint$1}` };
4256
+ return { unavailable: `lean ${m?.[1] ?? "of unknown version"} found, but the engine is pinned to ${leanVersion}; ${installHint$1}${cached ? `; ${cached}` : ""}` };
4138
4257
  }
4139
- return { unavailable: `no Lean toolchain found; ${installHint$1}` };
4258
+ return { unavailable: `no Lean toolchain found; ${installHint$1}${cached ? `; ${cached}` : ""}` };
4140
4259
  }
4141
4260
  /** Parse Lean's diagnostics for the one file it was given. */
4142
4261
  /**
@@ -5380,9 +5499,11 @@ function readAnswer(output) {
5380
5499
  // packages/prover-smt/src/z3.ts
5381
5500
  /**
5382
5501
  * Running Z3 over a process boundary. The engine is pinned to one Z3
5383
- * release: a `z3` on the PATH (or in Homebrew's and the usual local
5384
- * prefixes) must report that version. Nothing is downloaded during a
5385
- * check; a missing solver is `unavailable`, with how to install it. Every
5502
+ * release, looked for in Eutaxy's cache first (where `eutaxy prover install
5503
+ * smt` puts the upstream release named in `z3Downloads`), then as a `z3`
5504
+ * on the PATH (or in Homebrew's and the usual local prefixes) that must
5505
+ * report that version. Nothing is downloaded during a check; a missing
5506
+ * solver is `unavailable`, with how to install it. Every
5386
5507
  * run carries a resource limit, Z3's own machine-independent budget, so
5387
5508
  * the same script gives the same outcome on every machine; a wall-clock
5388
5509
  * timeout is only the safety net.
@@ -5390,7 +5511,32 @@ function readAnswer(output) {
5390
5511
  /** The Z3 release the engine's contract corpus is checked against. */
5391
5512
  const z3Version = "5.3.2";
5392
5513
  /** How to put the pinned solver on this machine. */
5393
- const installHint = `install Z3 ${z3Version} (https://github.com/Z3Prover/z3/releases/tag/z3-${z3Version}; Homebrew: brew install z3) so that z3 is on the PATH`;
5514
+ 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)`;
5515
+ const z3Release = `https://github.com/Z3Prover/z3/releases/download/z3-${z3Version}`;
5516
+ const z3File = (name, sha256, bytes) => ({
5517
+ file: name,
5518
+ url: `${z3Release}/${name}`,
5519
+ sha256,
5520
+ bytes
5521
+ });
5522
+ /**
5523
+ * The upstream release files `eutaxy prover install smt` downloads, one per
5524
+ * platform, as published on Z3's GitHub release with the checksums it
5525
+ * reports; the file names carry the version, and a test holds them to
5526
+ * `z3Version`. The Linux builds need glibc 2.39 (x64) or 2.38 (arm64).
5527
+ */
5528
+ const z3Downloads = {
5529
+ name: "smt",
5530
+ version: z3Version,
5531
+ executable: "bin/z3",
5532
+ files: {
5533
+ "linux-x64": z3File("z3-5.3.2-x64-glibc-2.39.zip", "26d463cddad3901cbf86e3868c784914539f4e3f9b4de1a0b8dc2969806d60e2", 69479256),
5534
+ "linux-arm64": z3File("z3-5.3.2-arm64-glibc-2.38.zip", "30b6a718a6cfe1b2db056038cc32eda5410f6d02e5937622b5238645347f59d5", 64803341),
5535
+ "darwin-x64": z3File("z3-5.3.2-x64-osx-13.3.zip", "b911dc193f7447a14fba001e8e8a0c2866a544274bb003e76a9e864f03b4d557", 54270076),
5536
+ "darwin-arm64": z3File("z3-5.3.2-arm64-osx-13.3.zip", "524290057c943a044ec3d1372db65a9c93f333d9817d58191154c4719ff7f8ad", 53576249),
5537
+ "win32-x64": z3File("z3-5.3.2-x64-win.zip", "a75aa2b0383a8ee355387a54daad796911d6a965076751eea18d21a27f38e983", 70867398)
5538
+ }
5539
+ };
5394
5540
  function run(command, args, options) {
5395
5541
  return new Promise((resolve) => {
5396
5542
  let child;
@@ -5445,10 +5591,16 @@ function run(command, args, options) {
5445
5591
  });
5446
5592
  });
5447
5593
  }
5448
- /** Candidates for the `z3` executable: `EUTAXY_Z3`, the PATH, then the prefixes package managers install into. */
5449
- function candidates() {
5450
- const fromEnv = process.env["EUTAXY_Z3"];
5594
+ /**
5595
+ * Candidates for the `z3` executable: the one `eutaxy prover install smt`
5596
+ * put in the cache, `EUTAXY_Z3`, the PATH, then the prefixes package
5597
+ * managers install into.
5598
+ */
5599
+ function candidates(h = host()) {
5600
+ const fromEnv = h.env["EUTAXY_Z3"];
5601
+ const fromCache = installed(z3Downloads, h);
5451
5602
  return [
5603
+ ...fromCache ? [fromCache.executable] : [],
5452
5604
  ...fromEnv ? [fromEnv] : [],
5453
5605
  "z3",
5454
5606
  "/opt/homebrew/bin/z3",
@@ -6108,6 +6260,514 @@ async function runCheck(o) {
6108
6260
  });
6109
6261
  }
6110
6262
  }
6263
+ // packages/cli/src/archive.ts
6264
+ /**
6265
+ * Reading the two archive formats the prover releases come in, with Node's
6266
+ * standard library alone: a tar stream compressed with zstd (Lean) and a zip
6267
+ * (Z3). Entries are written under one destination directory; an entry whose
6268
+ * path would leave it, or a link pointing out of it, is refused, since the
6269
+ * archive is downloaded. The tar is read as it decompresses, so a release
6270
+ * of hundreds of megabytes never sits in memory; a zip is read from its
6271
+ * central directory, entry by entry.
6272
+ */
6273
+ var ArchiveError = class extends Error {};
6274
+ /** The entry's place under `dest`, refused when it would be outside. */
6275
+ function placeOf(dest, name) {
6276
+ if (name.includes("\0")) throw new ArchiveError("an entry name holds a NUL byte");
6277
+ const target = resolve(dest, name);
6278
+ if (target !== dest && !target.startsWith(dest + sep)) throw new ArchiveError(`entry ${JSON.stringify(name)} would be written outside the toolchain directory`);
6279
+ return target;
6280
+ }
6281
+ /** A symlink's target must stay under `dest` too. */
6282
+ function checkLink(dest, at, linkTo) {
6283
+ const target = resolve(dirname(at), linkTo);
6284
+ if (target !== dest && !target.startsWith(dest + sep)) throw new ArchiveError(`link ${JSON.stringify(linkTo)} would point outside the toolchain directory`);
6285
+ }
6286
+ function ensureDir(dir) {
6287
+ mkdirSync(dir, { recursive: true });
6288
+ }
6289
+ function setMode(path, mode) {
6290
+ if (process.platform === "win32") return;
6291
+ const bits = mode & 511;
6292
+ if (bits !== 0) chmodSync(path, bits | 384);
6293
+ }
6294
+ const text = (block, start, length) => {
6295
+ const slice = block.subarray(start, start + length);
6296
+ const end = slice.indexOf(0);
6297
+ return slice.subarray(0, end < 0 ? slice.length : end).toString("utf8");
6298
+ };
6299
+ /** An octal field, or GNU base-256 when the high bit of the first byte is set. */
6300
+ const numeric = (block, start, length) => {
6301
+ if (block[start] & 128) {
6302
+ let n = 0;
6303
+ for (let i = start + 1; i < start + length; i++) n = n * 256 + block[i];
6304
+ return n;
6305
+ }
6306
+ const t = text(block, start, length).trim();
6307
+ return t.length === 0 ? 0 : Number.parseInt(t, 8);
6308
+ };
6309
+ function parseHeader(block) {
6310
+ const magic = text(block, 257, 6);
6311
+ const name = text(block, 0, 100);
6312
+ const prefix = magic.startsWith("ustar") ? text(block, 345, 155) : "";
6313
+ return {
6314
+ name: prefix.length > 0 ? `${prefix}/${name}` : name,
6315
+ mode: numeric(block, 100, 8),
6316
+ size: numeric(block, 124, 12),
6317
+ type: block[156] === 0 ? "0" : String.fromCharCode(block[156]),
6318
+ linkName: text(block, 157, 100)
6319
+ };
6320
+ }
6321
+ /** `length key=value\n` records of a pax extended header. */
6322
+ function paxRecords(data) {
6323
+ const out = /* @__PURE__ */ new Map();
6324
+ let at = 0;
6325
+ while (at < data.length) {
6326
+ const space = data.indexOf(32, at);
6327
+ if (space < 0) break;
6328
+ const length = Number.parseInt(data.subarray(at, space).toString("latin1"), 10);
6329
+ if (!Number.isInteger(length) || length <= 0) break;
6330
+ const record = data.subarray(space + 1, at + length - 1).toString("utf8");
6331
+ const eq = record.indexOf("=");
6332
+ if (eq > 0) out.set(record.slice(0, eq), record.slice(eq + 1));
6333
+ at += length;
6334
+ }
6335
+ return out;
6336
+ }
6337
+ /**
6338
+ * Reads a tar stream block by block as its chunks arrive. A file entry's
6339
+ * bytes are written to disk as they come; pax and GNU long-name entries are
6340
+ * read into memory (they are small) and apply to the entry that follows.
6341
+ */
6342
+ var TarReader = class {
6343
+ dest;
6344
+ buffer = Buffer.alloc(0);
6345
+ current;
6346
+ /** Overrides for the next entry from a pax or long-name entry. */
6347
+ next = {};
6348
+ zeroBlocks = 0;
6349
+ ended = false;
6350
+ entries = 0;
6351
+ constructor(dest) {
6352
+ this.dest = dest;
6353
+ }
6354
+ push(chunk) {
6355
+ this.buffer = this.buffer.length === 0 ? chunk : Buffer.concat([this.buffer, chunk]);
6356
+ for (;;) {
6357
+ if (this.ended) return;
6358
+ if (this.current) {
6359
+ const take = Math.min(this.current.remaining, this.buffer.length);
6360
+ if (take > 0) {
6361
+ const part = this.buffer.subarray(0, take);
6362
+ if ("fd" in this.current.sink) writeSync(this.current.sink.fd, part);
6363
+ else if ("chunks" in this.current.sink) this.current.sink.chunks.push(Buffer.from(part));
6364
+ this.buffer = this.buffer.subarray(take);
6365
+ this.current.remaining -= take;
6366
+ }
6367
+ if (this.current.remaining > 0) return;
6368
+ const skip = Math.min(this.current.padding, this.buffer.length);
6369
+ this.buffer = this.buffer.subarray(skip);
6370
+ this.current.padding -= skip;
6371
+ if (this.current.padding > 0) return;
6372
+ this.finish();
6373
+ continue;
6374
+ }
6375
+ if (this.buffer.length < 512) return;
6376
+ const block = this.buffer.subarray(0, 512);
6377
+ this.buffer = this.buffer.subarray(512);
6378
+ if (block.every((b) => b === 0)) {
6379
+ if (++this.zeroBlocks >= 2) this.ended = true;
6380
+ continue;
6381
+ }
6382
+ this.zeroBlocks = 0;
6383
+ this.begin(parseHeader(block));
6384
+ }
6385
+ }
6386
+ begin(header) {
6387
+ const size = this.next.size ?? header.size;
6388
+ const padding = (512 - size % 512) % 512;
6389
+ if (header.type === "x" || header.type === "L") {
6390
+ const kind = header.type === "x" ? "pax" : "longname";
6391
+ this.current = {
6392
+ remaining: size,
6393
+ padding,
6394
+ sink: {
6395
+ chunks: [],
6396
+ kind
6397
+ }
6398
+ };
6399
+ return;
6400
+ }
6401
+ const name = this.next.path ?? header.name;
6402
+ const linkName = this.next.linkpath ?? header.linkName;
6403
+ this.next = {};
6404
+ this.entries++;
6405
+ const at = placeOf(this.dest, name);
6406
+ if (header.type === "0" || header.type === "7") {
6407
+ ensureDir(dirname(at));
6408
+ const fd = openSync(at, "w");
6409
+ this.current = {
6410
+ remaining: size,
6411
+ padding,
6412
+ sink: {
6413
+ fd,
6414
+ at,
6415
+ mode: header.mode
6416
+ }
6417
+ };
6418
+ if (size === 0) this.finish();
6419
+ return;
6420
+ }
6421
+ if (header.type === "5") ensureDir(at);
6422
+ else if (header.type === "2") {
6423
+ checkLink(this.dest, at, linkName);
6424
+ ensureDir(dirname(at));
6425
+ rmSync(at, { force: true });
6426
+ symlinkSync(linkName, at);
6427
+ } else if (header.type === "1") {
6428
+ ensureDir(dirname(at));
6429
+ copyFileSync(placeOf(this.dest, linkName), at);
6430
+ }
6431
+ if (size > 0) this.current = {
6432
+ remaining: size,
6433
+ padding,
6434
+ sink: { skip: true }
6435
+ };
6436
+ }
6437
+ finish() {
6438
+ const current = this.current;
6439
+ this.current = void 0;
6440
+ if ("fd" in current.sink) {
6441
+ closeSync(current.sink.fd);
6442
+ setMode(current.sink.at, current.sink.mode);
6443
+ return;
6444
+ }
6445
+ if (!("chunks" in current.sink)) return;
6446
+ const data = Buffer.concat(current.sink.chunks);
6447
+ if (current.sink.kind === "longname") {
6448
+ this.next.path = text(data, 0, data.length);
6449
+ return;
6450
+ }
6451
+ const records = paxRecords(data);
6452
+ const path = records.get("path");
6453
+ const linkpath = records.get("linkpath");
6454
+ const size = records.get("size");
6455
+ if (path !== void 0) this.next.path = path;
6456
+ if (linkpath !== void 0) this.next.linkpath = linkpath;
6457
+ if (size !== void 0) this.next.size = Number(size);
6458
+ }
6459
+ /** Close the file being written, if any. */
6460
+ release() {
6461
+ if (this.current && "fd" in this.current.sink) closeSync(this.current.sink.fd);
6462
+ }
6463
+ end() {
6464
+ this.release();
6465
+ if (this.current) throw new ArchiveError("the tar stream ended inside an entry; the file is truncated");
6466
+ }
6467
+ };
6468
+ /** Unpack a zstd-compressed tar into `dest`, which must exist and be empty. */
6469
+ async function extractTarZst(file, dest) {
6470
+ const reader = new TarReader(resolve(dest));
6471
+ const source = createReadStream(file).pipe(createZstdDecompress());
6472
+ try {
6473
+ for await (const chunk of source) reader.push(chunk);
6474
+ } catch (err) {
6475
+ reader.release();
6476
+ source.destroy();
6477
+ throw err;
6478
+ }
6479
+ reader.end();
6480
+ return reader.entries;
6481
+ }
6482
+ const ZIP_EOCD = 101010256;
6483
+ const ZIP64_EOCD = 101075792;
6484
+ const ZIP64_LOCATOR = 117853008;
6485
+ const ZIP_CENTRAL = 33639248;
6486
+ const ZIP_LOCAL = 67324752;
6487
+ /** The central directory's position and entry count, through the zip64 records when the plain ones overflow. */
6488
+ function centralDirectory(zip) {
6489
+ const start = Math.max(0, zip.length - 22 - 65535);
6490
+ let eocd = -1;
6491
+ for (let i = zip.length - 22; i >= start; i--) if (zip.readUInt32LE(i) === ZIP_EOCD) {
6492
+ eocd = i;
6493
+ break;
6494
+ }
6495
+ if (eocd < 0) throw new ArchiveError("not a zip file: no end-of-central-directory record");
6496
+ let entries = zip.readUInt16LE(eocd + 10);
6497
+ let offset = zip.readUInt32LE(eocd + 16);
6498
+ if (entries === 65535 || offset === 4294967295) {
6499
+ const locator = eocd - 20;
6500
+ if (locator < 0 || zip.readUInt32LE(locator) !== ZIP64_LOCATOR) throw new ArchiveError("zip64 archive without its locator");
6501
+ const at = Number(zip.readBigUInt64LE(locator + 8));
6502
+ if (zip.readUInt32LE(at) !== ZIP64_EOCD) throw new ArchiveError("zip64 archive without its end record");
6503
+ entries = Number(zip.readBigUInt64LE(at + 32));
6504
+ offset = Number(zip.readBigUInt64LE(at + 48));
6505
+ }
6506
+ return {
6507
+ offset,
6508
+ entries
6509
+ };
6510
+ }
6511
+ /** Sizes and offset of one entry, from its zip64 extra field when the plain ones overflow. */
6512
+ function zip64Fields(extra, plain) {
6513
+ let at = 0;
6514
+ while (at + 4 <= extra.length) {
6515
+ const id = extra.readUInt16LE(at);
6516
+ const size = extra.readUInt16LE(at + 2);
6517
+ if (id === 1) {
6518
+ let p = at + 4;
6519
+ const out = { ...plain };
6520
+ if (out.uncompressed === 4294967295) {
6521
+ out.uncompressed = Number(extra.readBigUInt64LE(p));
6522
+ p += 8;
6523
+ }
6524
+ if (out.compressed === 4294967295) {
6525
+ out.compressed = Number(extra.readBigUInt64LE(p));
6526
+ p += 8;
6527
+ }
6528
+ if (out.offset === 4294967295) out.offset = Number(extra.readBigUInt64LE(p));
6529
+ return out;
6530
+ }
6531
+ at += 4 + size;
6532
+ }
6533
+ return plain;
6534
+ }
6535
+ /** Unpack a zip into `dest`, which must exist and be empty. */
6536
+ function extractZip(file, dest) {
6537
+ const root = resolve(dest);
6538
+ const zip = readFileSync(file);
6539
+ const { offset, entries } = centralDirectory(zip);
6540
+ let at = offset;
6541
+ for (let i = 0; i < entries; i++) {
6542
+ if (zip.readUInt32LE(at) !== ZIP_CENTRAL) throw new ArchiveError("a central directory entry is not where the zip says it is");
6543
+ const madeBy = zip.readUInt16LE(at + 4) >> 8;
6544
+ const method = zip.readUInt16LE(at + 10);
6545
+ const nameLength = zip.readUInt16LE(at + 28);
6546
+ const extraLength = zip.readUInt16LE(at + 30);
6547
+ const commentLength = zip.readUInt16LE(at + 32);
6548
+ const externalAttributes = zip.readUInt32LE(at + 38);
6549
+ const name = zip.subarray(at + 46, at + 46 + nameLength).toString("utf8");
6550
+ const sizes = zip64Fields(zip.subarray(at + 46 + nameLength, at + 46 + nameLength + extraLength), {
6551
+ compressed: zip.readUInt32LE(at + 20),
6552
+ uncompressed: zip.readUInt32LE(at + 24),
6553
+ offset: zip.readUInt32LE(at + 42)
6554
+ });
6555
+ at += 46 + nameLength + extraLength + commentLength;
6556
+ const local = sizes.offset;
6557
+ if (zip.readUInt32LE(local) !== ZIP_LOCAL) throw new ArchiveError(`entry ${JSON.stringify(name)} has no local header where the zip says`);
6558
+ const dataStart = local + 30 + zip.readUInt16LE(local + 26) + zip.readUInt16LE(local + 28);
6559
+ const raw = zip.subarray(dataStart, dataStart + sizes.compressed);
6560
+ const mode = madeBy === 3 ? externalAttributes >>> 16 : 0;
6561
+ const place = placeOf(root, name);
6562
+ if (name.endsWith("/") || (mode & 61440) === 16384) {
6563
+ ensureDir(place);
6564
+ continue;
6565
+ }
6566
+ let data;
6567
+ if (method === 0) data = raw;
6568
+ else if (method === 8) data = inflateRawSync(raw);
6569
+ else throw new ArchiveError(`entry ${JSON.stringify(name)} uses compression method ${method}; only stored and deflated entries are read`);
6570
+ if (data.length !== sizes.uncompressed) throw new ArchiveError(`entry ${JSON.stringify(name)} did not inflate to its declared size`);
6571
+ ensureDir(dirname(place));
6572
+ if ((mode & 61440) === 40960) {
6573
+ const linkTo = data.toString("utf8");
6574
+ checkLink(root, place, linkTo);
6575
+ rmSync(place, { force: true });
6576
+ symlinkSync(linkTo, place);
6577
+ continue;
6578
+ }
6579
+ writeFileSync(place, data);
6580
+ setMode(place, mode);
6581
+ }
6582
+ return entries;
6583
+ }
6584
+ /**
6585
+ * When an archive puts everything under one top-level directory, as the
6586
+ * releases do (`lean-4.35.0-linux/`, `z3-5.3.2-x64-glibc-2.39/`), move
6587
+ * its contents up so the executable is at the path the table names.
6588
+ */
6589
+ function flattenSingleDirectory(dest) {
6590
+ const entries = readdirSync(dest, { withFileTypes: true });
6591
+ if (entries.length !== 1 || !entries[0].isDirectory()) return;
6592
+ const inner = join(dest, entries[0].name);
6593
+ for (const name of readdirSync(inner)) {
6594
+ const to = join(dest, name);
6595
+ if (existsSync(to)) throw new ArchiveError(`cannot flatten the archive: ${name} exists twice`);
6596
+ renameSync(join(inner, name), to);
6597
+ }
6598
+ rmSync(inner, {
6599
+ recursive: true,
6600
+ force: true
6601
+ });
6602
+ }
6603
+ // packages/cli/src/install.ts
6604
+ /**
6605
+ * `eutaxy prover install <name>`: the pinned release of a prover put in
6606
+ * Eutaxy's cache, where the engines look first. The file for this platform
6607
+ * is downloaded (or copied from a mirror or an offline directory given with
6608
+ * `--from`), its SHA-256 checked against the engine's table before anything
6609
+ * is unpacked, unpacked beside a marker written last, and deleted. A
6610
+ * mismatch or a failed download installs nothing. Nothing is run: the
6611
+ * engines check the version when they look the toolchain up.
6612
+ */
6613
+ /** The toolchains the command installs, by the engine name it takes. */
6614
+ const toolchains = {
6615
+ lean: leanDownloads,
6616
+ smt: z3Downloads
6617
+ };
6618
+ var InstallError = class extends Error {};
6619
+ const isUrl = (s) => /^https?:\/\//.test(s);
6620
+ /** Write a byte stream to `path`, hashing it as it goes; the hash and the byte count come back. */
6621
+ async function store(bytes, path, progress) {
6622
+ const hash = createHash("sha256");
6623
+ const fd = openSync(path, "w");
6624
+ let written = 0;
6625
+ let reported = 0;
6626
+ try {
6627
+ for await (const chunk of bytes) {
6628
+ writeSync(fd, chunk);
6629
+ hash.update(chunk);
6630
+ written += chunk.byteLength;
6631
+ if (progress && written - reported >= 5e7) {
6632
+ reported = written;
6633
+ progress(written);
6634
+ }
6635
+ }
6636
+ } finally {
6637
+ closeSync(fd);
6638
+ }
6639
+ return {
6640
+ sha256: hash.digest("hex"),
6641
+ bytes: written
6642
+ };
6643
+ }
6644
+ async function installToolchain(options) {
6645
+ const { toolchain } = options;
6646
+ const h = options.host ?? host();
6647
+ const platform = platformOf(h);
6648
+ const release = platform === void 0 ? void 0 : toolchain.files[platform];
6649
+ 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(", ")}`);
6650
+ const cache = cacheDir(h);
6651
+ const dir = toolchainDir(cache, toolchain);
6652
+ const already = installed(toolchain, h);
6653
+ if (already) return {
6654
+ name: toolchain.name,
6655
+ version: toolchain.version,
6656
+ platform,
6657
+ file: already.marker.file,
6658
+ source: already.marker.source,
6659
+ sha256: already.marker.sha256,
6660
+ bytes: release.bytes,
6661
+ dir,
6662
+ executable: already.executable,
6663
+ downloaded: false
6664
+ };
6665
+ const source = options.from === void 0 ? release.url : isUrl(options.from) ? `${options.from.replace(/\/+$/, "")}/${release.file}` : join(options.from, release.file);
6666
+ const stamp = `${process.pid}-${randomBytes(4).toString("hex")}`;
6667
+ const downloads = join(cache, "downloads");
6668
+ const archive = join(downloads, `${release.file}.${stamp}.part`);
6669
+ const mb = (n) => `${Math.round(n / 1e6)} MB`;
6670
+ try {
6671
+ mkdirSync(downloads, { recursive: true });
6672
+ let bytes;
6673
+ if (isUrl(source)) {
6674
+ const fetchImpl = options.fetch ?? fetch;
6675
+ let response;
6676
+ try {
6677
+ response = await fetchImpl(source);
6678
+ } catch (err) {
6679
+ throw new InstallError(`could not download ${source}: ${err instanceof Error ? err.message : String(err)}`);
6680
+ }
6681
+ if (!response.ok || response.body === null) throw new InstallError(`could not download ${source}: HTTP ${response.status} ${response.statusText}`);
6682
+ options.progress?.(`downloading ${release.file} (${mb(release.bytes)}) from ${source}`);
6683
+ bytes = Readable.fromWeb(response.body);
6684
+ } else {
6685
+ if (!existsSync(source)) throw new InstallError(`no ${release.file} in ${options.from}`);
6686
+ bytes = createReadStream(source);
6687
+ }
6688
+ let stored;
6689
+ try {
6690
+ stored = await store(bytes, archive, (n) => options.progress?.(`${mb(n)} of ${mb(release.bytes)}`));
6691
+ } catch (err) {
6692
+ throw new InstallError(`could not download ${source}: ${err instanceof Error ? err.message : String(err)}; nothing was installed`);
6693
+ }
6694
+ 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`);
6695
+ const partial = `${dir}.partial-${stamp}`;
6696
+ mkdirSync(partial, { recursive: true });
6697
+ try {
6698
+ options.progress?.(`unpacking ${release.file}`);
6699
+ if (release.file.endsWith(".zip")) extractZip(archive, partial);
6700
+ else if (release.file.endsWith(".tar.zst")) await extractTarZst(archive, partial);
6701
+ else throw new InstallError(`${release.file} is neither a .zip nor a .tar.zst`);
6702
+ flattenSingleDirectory(partial);
6703
+ const executable = executableName(toolchain, h);
6704
+ if (!existsSync(join(partial, executable))) throw new InstallError(`${release.file} holds no ${executable}; nothing was installed`);
6705
+ if (h.platform !== "win32") chmodSync(join(partial, executable), 493);
6706
+ const marker = {
6707
+ name: toolchain.name,
6708
+ version: toolchain.version,
6709
+ platform,
6710
+ file: release.file,
6711
+ sha256: stored.sha256,
6712
+ source
6713
+ };
6714
+ writeFileSync(join(partial, markerFile), `${JSON.stringify(marker, null, 2)}\n`);
6715
+ rmSync(dir, {
6716
+ recursive: true,
6717
+ force: true
6718
+ });
6719
+ renameSync(partial, dir);
6720
+ } catch (err) {
6721
+ rmSync(partial, {
6722
+ recursive: true,
6723
+ force: true
6724
+ });
6725
+ throw err instanceof InstallError ? err : new InstallError(`could not unpack ${release.file}: ${err instanceof Error ? err.message : String(err)}; nothing was installed`);
6726
+ }
6727
+ return {
6728
+ name: toolchain.name,
6729
+ version: toolchain.version,
6730
+ platform,
6731
+ file: release.file,
6732
+ source,
6733
+ sha256: stored.sha256,
6734
+ bytes: stored.bytes,
6735
+ dir,
6736
+ executable: join(dir, executableName(toolchain, h)),
6737
+ downloaded: true
6738
+ };
6739
+ } catch (err) {
6740
+ throw err instanceof InstallError ? err : new InstallError(`could not install ${toolchain.name} ${toolchain.version} in ${cache}: ${err instanceof Error ? err.message : String(err)}`);
6741
+ } finally {
6742
+ try {
6743
+ rmSync(archive, { force: true });
6744
+ } catch {}
6745
+ }
6746
+ }
6747
+ /** The command: the result as text or `--json` on stdout, progress and errors on stderr; exit 0, or 3 on an error. */
6748
+ async function runInstall(options) {
6749
+ try {
6750
+ const result = await installToolchain({
6751
+ toolchain: options.toolchain,
6752
+ ...options.host === void 0 ? {} : { host: options.host },
6753
+ ...options.fetch === void 0 ? {} : { fetch: options.fetch },
6754
+ ...options.from === void 0 ? {} : { from: options.from },
6755
+ progress: (text) => options.stderr(`${text}\n`)
6756
+ });
6757
+ if (options.json) options.stdout(`${JSON.stringify({
6758
+ schemaVersion: 1,
6759
+ command: "prover install",
6760
+ ...result
6761
+ }, null, 2)}\n`);
6762
+ 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`);
6763
+ else options.stdout(`${result.name} ${result.version} already installed in ${result.dir} (${result.file}, sha256 ${result.sha256})\n`);
6764
+ return exitCodes.BOUNDED;
6765
+ } catch (err) {
6766
+ if (!(err instanceof InstallError)) throw err;
6767
+ options.stderr(`${err.message}\n`);
6768
+ return exitCodes.error;
6769
+ }
6770
+ }
6111
6771
  // packages/cli/src/report.ts
6112
6772
  /**
6113
6773
  * `eutaxy report [dir]`: every spec file under a directory through the
@@ -6278,6 +6938,7 @@ const usage = `eutaxy — deterministic simulation checks and spec verdicts for
6278
6938
  Usage:
6279
6939
  eutaxy check <scenario.sim.ts> [options]
6280
6940
  eutaxy report [dir] [--prover <names>] [--seed <seed>] [--json]
6941
+ eutaxy prover install <lean|smt> [--from <url or directory>] [--json]
6281
6942
 
6282
6943
  check options:
6283
6944
  --wrangler <path> wrangler config (default: wrangler.jsonc/json/toml beside the scenario)
@@ -6298,8 +6959,14 @@ through the TESTED rung, on inputs drawn from the parameter types with the seed
6298
6959
  (default: report), and the PROVEN rung with --prover. No scenario runs, so nothing
6299
6960
  is CHECKED.
6300
6961
 
6962
+ prover install puts the pinned Lean or Z3 release for this platform in Eutaxy's cache
6963
+ (EUTAXY_CACHE_DIR, else the platform's user cache), where --prover finds it first:
6964
+ downloaded from the upstream GitHub release, or from a mirror or offline directory
6965
+ holding the same file (--from), and checked against the engine's SHA-256 before it is
6966
+ unpacked. Nothing is downloaded at any other time.
6967
+
6301
6968
  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.
6969
+ report: 0, or 1 for a REFUTED or CONFLICT spec, 3 error. prover install: 0, or 3.
6303
6970
  `;
6304
6971
  async function main(argv, io) {
6305
6972
  const { positionals, flags } = parseArgs(argv, [
@@ -6321,13 +6988,38 @@ async function main(argv, io) {
6321
6988
  "max-runs",
6322
6989
  "budget-ms",
6323
6990
  "prover",
6324
- "out"
6991
+ "out",
6992
+ "from"
6325
6993
  ]) if (flags[k] === true) {
6326
6994
  io.stderr(`--${k} needs a value\n`);
6327
6995
  return exitCodes.error;
6328
6996
  }
6329
6997
  const str = (k) => typeof flags[k] === "string" ? flags[k] : void 0;
6330
6998
  const provers = (str("prover") ?? "").split(",").map((n) => n.trim()).filter((n) => n.length > 0);
6999
+ if (command === "prover") {
7000
+ const names = Object.keys(toolchains).join("|");
7001
+ if (positionals[1] !== "install" || positionals.length !== 3) {
7002
+ io.stderr(`prover takes: install <${names}>\n\n${usage}`);
7003
+ return exitCodes.error;
7004
+ }
7005
+ const other = Object.keys(flags).find((k) => !["from", "json"].includes(k));
7006
+ if (other !== void 0) {
7007
+ io.stderr(`prover install does not take --${other}\n`);
7008
+ return exitCodes.error;
7009
+ }
7010
+ const toolchain = toolchains[positionals[2]];
7011
+ if (toolchain === void 0) {
7012
+ io.stderr(`unknown engine ${positionals[2]}; the engines are ${names.replaceAll("|", ", ")}\n`);
7013
+ return exitCodes.error;
7014
+ }
7015
+ return runInstall({
7016
+ toolchain,
7017
+ from: str("from"),
7018
+ json: flags["json"] === true,
7019
+ stdout: io.stdout,
7020
+ stderr: io.stderr
7021
+ });
7022
+ }
6331
7023
  if (command === "report") {
6332
7024
  if (positionals.length > 2) {
6333
7025
  io.stderr(`report takes one directory\n\n${usage}`);
@@ -10360,4 +11052,4 @@ async function checkInWorkerd(input) {
10360
11052
  }
10361
11053
  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
11054
 
10363
- //# sourceMappingURL=src-MX90l1IH.mjs.map
11055
+ //# sourceMappingURL=src-BYm3aLWV.mjs.map