eutaxy 0.11.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.
@@ -11,10 +11,11 @@ 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 { fileURLToPath, pathToFileURL } from "node:url";
15
14
  import { createHash, randomBytes } from "node:crypto";
15
+ import { fileURLToPath, pathToFileURL } from "node:url";
16
16
  import { Readable } from "node:stream";
17
17
  import { createZstdDecompress, inflateRawSync } from "node:zlib";
18
+ import { createInterface } from "node:readline";
18
19
  // packages/cli/src/args.ts
19
20
  function parseArgs(argv, booleans = []) {
20
21
  const positionals = [];
@@ -4311,6 +4312,9 @@ async function checkLean(toolchain, source, options = {}) {
4311
4312
  }
4312
4313
  }
4313
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: ";
4314
4318
  /** The axioms a supplied proof may rest on: Lean's standard ones. */
4315
4319
  const standardAxioms = /* @__PURE__ */ new Set([
4316
4320
  "propext",
@@ -4432,10 +4436,18 @@ function readSupplied(file, text) {
4432
4436
  file,
4433
4437
  proofs
4434
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);
4435
4445
  return {
4436
4446
  file,
4437
4447
  lemmas: lemmas.join("\n").trim(),
4438
- 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 }
4439
4451
  };
4440
4452
  }
4441
4453
  /** The file refused: none of its proofs is used, and every property it names says why. */
@@ -4474,6 +4486,54 @@ function axiomsOf(messages, line, theorem) {
4474
4486
  function provesExactly(messages, line, theorem) {
4475
4487
  return onlyAt(messages, line) === `${theorem} : s_${theorem}`;
4476
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
+ }
4477
4537
  // packages/prover-lean/src/prove.ts
4478
4538
  /**
4479
4539
  * The engine: a module's functions through the subset reader, the emitter
@@ -4541,7 +4601,11 @@ function prepare$1(input) {
4541
4601
  })));
4542
4602
  const specErrors = specs.errors;
4543
4603
  const proofFile = input.specPath?.replace(/\.ts$/, ".lean");
4544
- const supplied = proofFile !== void 0 && existsSync(proofFile) ? readSupplied(basename(proofFile), readFileSync(proofFile, "utf8")) : void 0;
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
+ }
4545
4609
  try {
4546
4610
  return {
4547
4611
  module,
@@ -4567,6 +4631,17 @@ function prepare$1(input) {
4567
4631
  };
4568
4632
  }
4569
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
+ }
4570
4645
  /**
4571
4646
  * A supplied proof's outcome: given up on when its lemmas or its tactics
4572
4647
  * do not compile, or when it rests on an axiom beyond Lean's standard
@@ -4670,10 +4745,23 @@ async function proveModule$1(input) {
4670
4745
  } : unknown$1("gave_up", `Lean could not close the proof: ${failed[0].message.split("\n")[0]}`)
4671
4746
  });
4672
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
+ }
4673
4760
  return {
4674
4761
  results,
4675
4762
  lean,
4676
- specErrors
4763
+ specErrors,
4764
+ goals
4677
4765
  };
4678
4766
  }
4679
4767
  /** The engine as a `Prover`: available when the pinned toolchain is installed. */
@@ -6083,7 +6171,7 @@ function enginesNamed(names) {
6083
6171
  * module's source, the outcomes folded into the simulator's verdicts.
6084
6172
  * An engine that is not installed proves nothing and says so.
6085
6173
  */
6086
- async function proveSpecs(dir, observed, specs, engines, modules = findSpecModules(dir)) {
6174
+ async function proveSpecs(dir, observed, specs, engines, modules = findSpecModules(dir), onReport) {
6087
6175
  let out = specs;
6088
6176
  for (const m of observed) {
6089
6177
  const key = specKey(m.module);
@@ -6092,16 +6180,20 @@ async function proveSpecs(dir, observed, specs, engines, modules = findSpecModul
6092
6180
  if (!found || withSpecs.length === 0) continue;
6093
6181
  const source = readFileSync(found.path, "utf8");
6094
6182
  const reports = [];
6095
- for (const engine of engines) reports.push({
6096
- engine: engine.name,
6097
- proofs: await engine.prove({
6098
- source,
6099
- specs: found.specs,
6100
- functions: withSpecs,
6101
- modulePath: found.path,
6102
- specPath: found.specPath
6103
- })
6104
- });
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
+ }
6105
6197
  out = aggregate(key, out, reports);
6106
6198
  }
6107
6199
  return out;
@@ -6223,14 +6315,16 @@ async function runCheck(o) {
6223
6315
  }
6224
6316
  specs = await proveSpecs(dir, transport.observed ?? [], specs, named.engines, specModules);
6225
6317
  }
6226
- const printed = o.provers && o.provers.length > 0 ? {
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 = {
6227
6320
  ...transport.report,
6228
- specs
6229
- } : transport.report;
6321
+ ...o.provers && o.provers.length > 0 ? { specs } : {},
6322
+ ...regressionPath === void 0 ? {} : { regressionTest: toPosix(relative(o.cwd, regressionPath) || regressionPath) }
6323
+ };
6230
6324
  if (o.json) o.stdout(`${canonicalJson(printed)}\n`);
6231
6325
  else o.stdout(`${renderText(verdict)}\n${specs.length > 0 ? `\n${renderSpecs(specs)}\n` : ""}`);
6232
- if (verdict.kind === "VIOLATED" && !o.noRegression) {
6233
- const outPath = o.out ? resolve(o.cwd, o.out) : join(dir, `${name}.regression.test.ts`);
6326
+ if (regressionPath !== void 0) {
6327
+ const outPath = regressionPath;
6234
6328
  const outDir = dirname(outPath);
6235
6329
  const schemaPaths = {};
6236
6330
  for (const step of transport.setup) if (step.kind === "d1") schemaPaths[String(step["binding"])] = toPosix(relative(outDir, resolve(dir, String(step["schemaFile"]))));
@@ -6896,6 +6990,31 @@ function testModule(m, seed, budgetMs, stderr) {
6896
6990
  });
6897
6991
  });
6898
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
+ }
6899
7018
  async function runReport(o) {
6900
7019
  const root = resolve(o.cwd, o.dir ?? ".");
6901
7020
  let engines = [];
@@ -6914,10 +7033,22 @@ async function runReport(o) {
6914
7033
  o.stderr(`cannot read ${root}: ${err instanceof Error ? err.message : String(err)}\n`);
6915
7034
  return exitCodes.error;
6916
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
+ }
6917
7044
  if (modules.length === 0) {
6918
7045
  o.stderr(`no spec files (*.props.ts) under ${root}\n`);
6919
7046
  return exitCodes.error;
6920
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
+ }
6921
7052
  const errors = modules.flatMap((m) => m.specs.errors.map((e) => `${m.key}${e.line > 0 ? `:${e.line}` : ""}: ${e.message}`));
6922
7053
  if (errors.length > 0) {
6923
7054
  for (const e of errors) o.stderr(`${e}\n`);
@@ -6925,13 +7056,501 @@ async function runReport(o) {
6925
7056
  }
6926
7057
  let specs = [];
6927
7058
  for (const m of modules) specs = [...specs, ...await testModule(m, o.seed ?? "report", o.moduleBudgetMs ?? 6e4, o.stderr)];
7059
+ const goals = [];
6928
7060
  if (engines.length > 0) specs = await proveSpecs(root, modules.map((m) => ({
6929
7061
  module: m.key,
6930
7062
  functions: m.specs.functions.map((f) => f.name)
6931
- })), specs, engines, modules);
6932
- o.stdout(`${o.json ? renderSpecReportJson(specs) : renderSpecReport(specs)}\n`);
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
+ }
6933
7078
  return specs.some((v) => v.kind === "REFUTED" || v.kind === "CONFLICT") ? exitCodes.VIOLATED : exitCodes.BOUNDED;
6934
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
+ }
6935
7554
  // packages/cli/src/main.ts
6936
7555
  const usage = `eutaxy — deterministic simulation checks and spec verdicts for Cloudflare Workers
6937
7556
 
@@ -6939,6 +7558,7 @@ Usage:
6939
7558
  eutaxy check <scenario.sim.ts> [options]
6940
7559
  eutaxy report [dir] [--prover <names>] [--seed <seed>] [--json]
6941
7560
  eutaxy prover install <lean|smt> [--from <url or directory>] [--json]
7561
+ eutaxy mcp
6942
7562
 
6943
7563
  check options:
6944
7564
  --wrangler <path> wrangler config (default: wrangler.jsonc/json/toml beside the scenario)
@@ -6965,6 +7585,13 @@ downloaded from the upstream GitHub release, or from a mirror or offline directo
6965
7585
  holding the same file (--from), and checked against the engine's SHA-256 before it is
6966
7586
  unpacked. Nothing is downloaded at any other time.
6967
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
+
6968
7595
  Exit codes: 0 BOUNDED, 1 VIOLATED or a REFUTED or CONFLICT spec, 2 UNSUPPORTED, 3 error.
6969
7596
  report: 0, or 1 for a REFUTED or CONFLICT spec, 3 error. prover install: 0, or 3.
6970
7597
  `;
@@ -6975,7 +7602,8 @@ async function main(argv, io) {
6975
7602
  "expect-violation",
6976
7603
  "keep",
6977
7604
  "help",
6978
- "exhaustive"
7605
+ "exhaustive",
7606
+ "goals"
6979
7607
  ]);
6980
7608
  const command = positionals[0];
6981
7609
  if (!command || command === "help" || flags["help"] === true) {
@@ -6996,6 +7624,16 @@ async function main(argv, io) {
6996
7624
  }
6997
7625
  const str = (k) => typeof flags[k] === "string" ? flags[k] : void 0;
6998
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
+ }
6999
7637
  if (command === "prover") {
7000
7638
  const names = Object.keys(toolchains).join("|");
7001
7639
  if (positionals[1] !== "install" || positionals.length !== 3) {
@@ -7028,7 +7666,8 @@ async function main(argv, io) {
7028
7666
  const other = Object.keys(flags).find((k) => ![
7029
7667
  "prover",
7030
7668
  "seed",
7031
- "json"
7669
+ "json",
7670
+ "goals"
7032
7671
  ].includes(k));
7033
7672
  if (other !== void 0) {
7034
7673
  io.stderr(`report does not take --${other}\n`);
@@ -7040,6 +7679,7 @@ async function main(argv, io) {
7040
7679
  ...dir === void 0 ? {} : { dir },
7041
7680
  ...provers.length > 0 ? { provers } : {},
7042
7681
  ...str("seed") ? { seed: str("seed") } : {},
7682
+ ...flags["goals"] === true ? { goals: true } : {},
7043
7683
  json: flags["json"] === true,
7044
7684
  stdout: io.stdout,
7045
7685
  stderr: io.stderr
@@ -11052,4 +11692,4 @@ async function checkInWorkerd(input) {
11052
11692
  }
11053
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 };
11054
11694
 
11055
- //# sourceMappingURL=src-BYm3aLWV.mjs.map
11695
+ //# sourceMappingURL=src-DIG0_CjU.mjs.map