lemmascript 0.6.7 → 0.6.8

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 CHANGED
@@ -97,6 +97,16 @@ lsc gen --backend=lean src/myModule.ts
97
97
  lake build
98
98
  ```
99
99
 
100
+ ## Sub-packages
101
+
102
+ ### Claimcheck
103
+
104
+ `lsc claimcheck` forwards to [lemmascript-claimcheck](https://github.com/midspiral/lemmascript-claimcheck) to sanity check the natural language `//@ contract` against the formal specifications.
105
+
106
+ ### Runtime precondition checks
107
+
108
+ `lsc guard` forwards to [lemmascript-guard](https://github.com/midspiral/lemmascript-guard) to generate a sibling `*.guarded.ts` module that checks `//@ requires` at runtime. Import its wrappers at application boundaries.
109
+
100
110
  ## Continuous Integration
101
111
 
102
112
  LemmaScript ships a **reusable GitHub Actions workflow** that regenerates your artifacts, verifies them, and fails the build if any committed generated file is out of date. Call it from your own repo's workflow:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lemmascript",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "description": "A verification toolchain for TypeScript — generates Lean 4 or Dafny from annotated TS",
5
5
  "type": "module",
6
6
  "engines": {
@@ -42,5 +42,8 @@
42
42
  "lean4",
43
43
  "dafny",
44
44
  "formal-methods"
45
- ]
45
+ ],
46
+ "optionalDependencies": {
47
+ "lemmascript-guard": "^0.1.0"
48
+ }
46
49
  }
@@ -743,9 +743,10 @@ function extractExpr(node) {
743
743
  // ── Annotation parsing ───────────────────────────────────────
744
744
  const PREFIX = "//@ ";
745
745
  const KEYWORDS = ["requires", "ensures", "contract", "invariant", "decreases", "done_with", "type"];
746
- /** The other directives (SPEC §2.1) besides options, read by keyword elsewhere. */
746
+ /** The other directives (SPEC §2.1) besides options, read by keyword elsewhere.
747
+ * `guarded` is consumed by lemmascript-guard's manifest sweep. */
747
748
  const DIRECTIVES = ["verify", "pure", "impure", "skip", "extern", "havoc", "autohavoc", "assert", "assume",
748
- "ghost", "declare-type", "backend", "lean-module"];
749
+ "ghost", "declare-type", "backend", "lean-module", "guarded"];
749
750
  function parseAnnotation(text) {
750
751
  if (!text.startsWith(PREFIX))
751
752
  return null;
@@ -0,0 +1,36 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { createRequire } from "node:module";
3
+ import { fileURLToPath } from "node:url";
4
+ /** Forward to the packaged guard CLI, using this compiler for extraction. */
5
+ export function runGuard(args) {
6
+ if (Number(process.versions.node.split(".")[0]) < 22) {
7
+ console.error("`lsc guard` requires Node.js 22 or newer.");
8
+ process.exit(1);
9
+ }
10
+ let cli;
11
+ try {
12
+ cli = createRequire(import.meta.url).resolve("lemmascript-guard/dist/guard.js");
13
+ }
14
+ catch {
15
+ console.error("`lsc guard` needs lemmascript-guard >= 0.1.0; reinstall lemmascript with optional dependencies enabled (--include=optional).");
16
+ process.exit(1);
17
+ }
18
+ try {
19
+ execFileSync(process.execPath, [cli, ...args], {
20
+ stdio: "inherit",
21
+ env: {
22
+ ...process.env,
23
+ // A checkout can have another lemmascript version installed as a peer.
24
+ // Use this build by default, while retaining the explicit dev override.
25
+ LEMMASCRIPT: process.env.LEMMASCRIPT || fileURLToPath(new URL("../../", import.meta.url)),
26
+ },
27
+ });
28
+ }
29
+ catch (err) {
30
+ const status = err.status;
31
+ if (typeof status === "number")
32
+ process.exit(status);
33
+ console.error(err instanceof Error ? err.message : String(err));
34
+ process.exit(1);
35
+ }
36
+ }
package/tools/dist/lsc.js CHANGED
@@ -21,6 +21,7 @@ import { leanGen, leanCheck } from "./lean-commands.js";
21
21
  import { runInfo, runTypedInfo } from "./info-command.js";
22
22
  import { RunLog, resolveLogDir, runLogEnabled, safely } from "./run-log.js";
23
23
  import { runRuns } from "./runs-command.js";
24
+ import { runGuard } from "./guard-command.js";
24
25
  import { SourceProjects } from "./source-projects.js";
25
26
  import { loadConfigOptions, parseFileOptions, resolveDafnyArtifactDir, resolveOptions, } from "./config.js";
26
27
  /** Version of the lemmascript package — the root package.json sits two levels
@@ -78,6 +79,11 @@ function main() {
78
79
  }
79
80
  return;
80
81
  }
82
+ // Guard owns its arguments and is backend-neutral, like extraction.
83
+ if (args[0] === "guard") {
84
+ runGuard(args.slice(1));
85
+ return;
86
+ }
81
87
  // `lsc runs` reads the run log and takes its own flags (`--json`, `--config=`),
82
88
  // so it is dispatched before the file commands' flag parsing.
83
89
  if (args[0] === "runs") {
@@ -163,10 +169,17 @@ function main() {
163
169
  console.error(" lsc info --typed <file.ts> (machine-readable Typed IR contract to stdout)");
164
170
  console.error(" lsc <gen|gen-check|check> [--backend=…] [--slow] (no file: batch over LemmaScript-files.txt)");
165
171
  console.error(" lsc claimcheck [<file.ts>] [flags…] (forwards to lemmascript-claimcheck)");
172
+ console.error(" lsc guard <file.ts> (forwards to lemmascript-guard; Node.js >=22)");
166
173
  console.error(" lsc runs [--json] [--config=path] (what verification caught, from .lemmascript/runs.jsonl)");
167
174
  console.error(" lsc version");
168
175
  process.exit(1);
169
176
  }
177
+ // Validate before loading a file or entering batch mode: a backend mismatch
178
+ // must not turn an unknown command into a successful skipped run.
179
+ if (!["gen", "gen-check", "check", "regen", "extract", "info", "config"].includes(cmd)) {
180
+ console.error(`Unknown command: ${cmd}`);
181
+ process.exit(1);
182
+ }
170
183
  if (typedInfo && cmd !== "info") {
171
184
  console.error(`--typed is only valid with the info command (got: ${cmd})`);
172
185
  process.exit(1);