tslaws 0.9.0 → 1.0.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.
Files changed (123) hide show
  1. package/README.md +8 -2
  2. package/bin/tslaws.js +8 -2
  3. package/dist/browser.d.ts +1 -1
  4. package/dist/browser.js +36 -7
  5. package/dist/bundled.js +2 -2
  6. package/dist/bundlerPlugins.d.ts +2 -0
  7. package/dist/bundlerPlugins.js +7 -0
  8. package/dist/certificates.d.ts +139 -0
  9. package/dist/certificates.js +433 -0
  10. package/dist/chc.d.ts +85 -0
  11. package/dist/chc.js +298 -0
  12. package/dist/check.d.ts +13 -1
  13. package/dist/check.js +215 -28
  14. package/dist/cli.d.ts +4 -0
  15. package/dist/cli.js +324 -41
  16. package/dist/compile.d.ts +17 -1
  17. package/dist/compile.js +244 -25
  18. package/dist/coverage.d.ts +55 -3
  19. package/dist/coverage.js +231 -12
  20. package/dist/e2eApi.js +3 -1
  21. package/dist/generators.js +12 -2
  22. package/dist/github.d.ts +49 -5
  23. package/dist/github.js +107 -24
  24. package/dist/githubCli.d.ts +28 -0
  25. package/dist/githubCli.js +1039 -211
  26. package/dist/hints.js +2 -1
  27. package/dist/init.js +42 -0
  28. package/dist/isolate.d.ts +28 -0
  29. package/dist/isolate.js +262 -0
  30. package/dist/isolatedCheck.d.ts +1 -0
  31. package/dist/isolatedCheck.js +16 -0
  32. package/dist/lawHost.d.ts +50 -0
  33. package/dist/lawHost.js +199 -0
  34. package/dist/lawRuntime.d.ts +39 -0
  35. package/dist/lawRuntime.js +242 -0
  36. package/dist/lock.d.ts +49 -9
  37. package/dist/lock.js +132 -21
  38. package/dist/mcp.js +28 -7
  39. package/dist/mutate.d.ts +4 -0
  40. package/dist/mutate.js +7 -1
  41. package/dist/plan.d.ts +1 -0
  42. package/dist/plan.js +4 -0
  43. package/dist/pluginHooks.d.ts +16 -0
  44. package/dist/pluginHooks.js +48 -0
  45. package/dist/pluginHost.d.ts +5 -0
  46. package/dist/pluginHost.js +43 -0
  47. package/dist/pluginWorker.d.ts +1 -0
  48. package/dist/pluginWorker.js +40 -0
  49. package/dist/plural.d.ts +2 -0
  50. package/dist/plural.js +4 -0
  51. package/dist/pool.d.ts +80 -7
  52. package/dist/pool.js +222 -11
  53. package/dist/projects.d.ts +70 -0
  54. package/dist/projects.js +457 -0
  55. package/dist/promote.d.ts +56 -2
  56. package/dist/promote.js +429 -13
  57. package/dist/property.js +13 -2
  58. package/dist/propertyWorker.js +11 -1
  59. package/dist/proposals.d.ts +52 -4
  60. package/dist/proposals.js +484 -21
  61. package/dist/reporters.js +5 -1
  62. package/dist/runtimeEnv.d.ts +32 -0
  63. package/dist/runtimeEnv.js +146 -0
  64. package/dist/sandbox.d.ts +98 -0
  65. package/dist/sandbox.js +673 -0
  66. package/dist/sandboxGuard.d.ts +56 -0
  67. package/dist/sandboxGuard.js +249 -0
  68. package/dist/seal.d.ts +9 -0
  69. package/dist/seal.js +426 -0
  70. package/dist/security/cli.d.ts +6 -0
  71. package/dist/security/cli.js +39 -0
  72. package/dist/security/cwe.d.ts +14 -0
  73. package/dist/security/cwe.js +40 -0
  74. package/dist/security/deps/cache.d.ts +28 -0
  75. package/dist/security/deps/cache.js +107 -0
  76. package/dist/security/deps/config.d.ts +16 -0
  77. package/dist/security/deps/config.js +43 -0
  78. package/dist/security/deps/imports.d.ts +4 -0
  79. package/dist/security/deps/imports.js +33 -0
  80. package/dist/security/deps/lockfiles.d.ts +23 -0
  81. package/dist/security/deps/lockfiles.js +153 -0
  82. package/dist/security/deps/osv.d.ts +66 -0
  83. package/dist/security/deps/osv.js +137 -0
  84. package/dist/security/deps/run.d.ts +54 -0
  85. package/dist/security/deps/run.js +135 -0
  86. package/dist/security/deps/severity.d.ts +26 -0
  87. package/dist/security/deps/severity.js +78 -0
  88. package/dist/security/generators.d.ts +9 -0
  89. package/dist/security/generators.js +36 -0
  90. package/dist/security/index.d.ts +27 -0
  91. package/dist/security/index.js +18 -0
  92. package/dist/security/integers.d.ts +31 -0
  93. package/dist/security/integers.js +105 -0
  94. package/dist/security/law.d.ts +54 -0
  95. package/dist/security/law.js +54 -0
  96. package/dist/security/pathTraversal.d.ts +29 -0
  97. package/dist/security/pathTraversal.js +146 -0
  98. package/dist/security/prototypePollution.d.ts +30 -0
  99. package/dist/security/prototypePollution.js +142 -0
  100. package/dist/security/redirect.d.ts +21 -0
  101. package/dist/security/redirect.js +154 -0
  102. package/dist/security/redos.d.ts +21 -0
  103. package/dist/security/redos.js +93 -0
  104. package/dist/security/validation.d.ts +25 -0
  105. package/dist/security/validation.js +89 -0
  106. package/dist/security/xss.d.ts +21 -0
  107. package/dist/security/xss.js +90 -0
  108. package/dist/settings.d.ts +20 -0
  109. package/dist/settings.js +32 -0
  110. package/dist/smt.d.ts +29 -1
  111. package/dist/smt.js +239 -107
  112. package/dist/smtWorker.d.ts +1 -0
  113. package/dist/smtWorker.js +26 -0
  114. package/dist/solvers.d.ts +9 -0
  115. package/dist/solvers.js +11 -5
  116. package/dist/symbolic.d.ts +54 -1
  117. package/dist/symbolic.js +239 -13
  118. package/dist/tsconfigResolve.d.ts +28 -0
  119. package/dist/tsconfigResolve.js +141 -0
  120. package/dist/types.d.ts +28 -0
  121. package/env.d.ts +17 -0
  122. package/hooks/claude-hook.mjs +2 -0
  123. package/package.json +22 -6
package/README.md CHANGED
@@ -167,14 +167,18 @@ See [docs/laws.md](../../docs/laws.md#the-dashboard).
167
167
  `tslaws mutate [files...] [--max N] [--seed N] [--json]` mutation-tests the laws: it mutates the covered code, re-runs the laws against each mutant, and lists the survivors no law caught. It handles `.tsx`/`.jsx` and projects with a lock, and takes the run flags of `check`. See [docs/laws.md](../../docs/laws.md#mutation-testing).
168
168
 
169
169
  - **Other source formats:** `tslaws.json` `bundlerPlugins` lists esbuild plugin modules (paths relative to the file) that teach the browser bundler formats like `.tsrx`. See [docs/laws.md](../../docs/laws.md#bundler-plugins).
170
+ - **Bundler-style source:** `import.meta.env` works in laws, in the code they reach and in browser pages (`tslaws.json` `env` adds or overrides entries), and a TypeScript dependency may import its own files without extensions. See [docs/laws.md](../../docs/laws.md#source-written-for-a-bundler).
170
171
  - **Settings:** `tslaws.json` `runs`, `bound`, `proofTimeoutMs` and `propertyTimeoutMs` set the run defaults; a command line flag beats them. `"solvers": ["z3", "cvc5"]` makes cvc5 confirm every Z3 proof (set `TSLAWS_CVC5` to its path, or put it on the PATH). See [docs/laws.md](../../docs/laws.md#settings).
171
172
 
172
173
  ## Agents cannot move the goalposts
173
174
 
174
- `tsc-laws.lock` holds a hash of every law declaration and the list of coverage exemptions. A change, an added law, a removed
175
+ `tsc-laws.lock` holds a hash of every law and the list of coverage exemptions. A law's hash covers its declaration, the helpers,
176
+ generators and top-level code of its file that it reaches, every module the file imports (a registry package by name and
177
+ version), and the whole effective `tslaws.json` apart from `github`, `security` and `levels`, so weakening a helper or setting
178
+ `runs: 1` reads as tampering too; comments, layout and edits no law reaches do not. A change, an added law, a removed
175
179
  law or a new `@tslaws-exempt` fails the check until a person runs `tslaws accept`, which refuses to run without a terminal,
176
180
  under `CI`, or with `TSLAWS_AGENT` set, unless a person has lent it for a limited time with `tslaws delegate grant`. Agents propose laws in `*.proposed.laws.ts` files (or optionally in `.tslaws/proposals/`, outside the tree and git-ignored; `tslaws propose` or the MCP tool) and try them with `tslaws check
177
- --proposed` (no lock, no coverage gate); a person moves one into the tree with `tslaws promote` and accepts. Every laws file in the tree must be in the lock.
181
+ --proposed` (no lock, no coverage gate); a person moves one into the tree with `tslaws promote` and accepts. Every laws file in the tree must be in the lock. A project that accepts laws on GitHub (a `github` section in `tslaws.json`) still lets a person run `tslaws accept` by hand, and a maintainer can run the workflow on demand; set `github.local` to false to leave the lock to the workflow alone. See [docs/github.md](../../docs/github.md).
178
182
 
179
183
  `hooks/claude-hook.mjs` is a Claude Code hook that blocks `git commit` and sends an agent back to work when the check fails;
180
184
  `hooks/claude-settings.example.json` wires it up and `hooks/AGENTS.snippet.md` tells the agent the rules.
@@ -191,6 +195,8 @@ tslaws check [files...] [--json] [--summary] [--watch] [--runs N] [--seed N] [--
191
195
  [--proof-timeout MS] [--property-timeout MS] [--proposed] [--compiler PATH]
192
196
  ```
193
197
 
198
+ - `check <files>` and `accept <files>` work on the named laws files only: the lock is compared only for their laws, so a locked law in
199
+ another file is not reported as removed, and `accept` keeps the lock entries of the other files. A law removed from a named file is still reported.
194
200
  - `init` scaffolds `tslaws.json`, the `.tslaws` ignore entry, the agent rules in `AGENTS.md`, the Claude Code hook in
195
201
  `.claude/settings.json`, and a starter law if none exists. It never writes the lock; a person then runs `accept`.
196
202
  - `accept` records the laws and the `@tslaws-exempt` functions in `tsc-laws.lock`. It refuses to run without a terminal,
package/bin/tslaws.js CHANGED
@@ -1,5 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import { main } from '../dist/cli.js';
3
3
 
4
- // Z3's worker threads would keep the process alive.
5
- process.exit(await main(process.argv.slice(2)));
4
+ // Let the process end by itself once `main` returns: every worker the CLI starts is unref'd. `process.exit()` skips
5
+ // the teardown of the JavaScript engine, and it can deadlock: it joins V8's background threads first, and a thread
6
+ // that is compiling code and needs a garbage collection waits for the main thread, which is now waiting for it. The
7
+ // report is already printed and the process never ends. Ending by itself tears the engine down properly.
8
+ process.exitCode = await main(process.argv.slice(2));
9
+
10
+ // Only if a handle somewhere would still hold the process open after that: end it anyway, a few seconds later.
11
+ setTimeout(() => process.exit(), 5000).unref();
package/dist/browser.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Browser } from 'playwright-core';
1
+ import type { Browser } from 'playwright-core';
2
2
  import type * as fc from 'fast-check';
3
3
  import { type PropertyOutcome } from './property.ts';
4
4
  import type { CheckOptions } from './types.ts';
package/dist/browser.js CHANGED
@@ -2,11 +2,13 @@
2
2
  // each input is sent to a page where the compiled law and the code it checks run against a live DOM.
3
3
  import { existsSync } from 'node:fs';
4
4
  import { mkdirSync } from 'node:fs';
5
+ import { createRequire } from 'node:module';
5
6
  import { delimiter, join, relative as pathRelative, resolve, sep } from 'node:path';
6
7
  import { build as bundleWith } from 'esbuild';
7
8
  import { explainBundleError, loadBundlerPlugins } from "./bundlerPlugins.js";
8
- import { readConfig } from "./coverage.js";
9
- import { chromium, firefox, webkit } from 'playwright-core';
9
+ import { lawEnv, readConfig } from "./coverage.js";
10
+ import { compiledDirOf } from "./lawRuntime.js";
11
+ import { importMetaEnvGlobal } from "./runtimeEnv.js";
10
12
  import { toWire } from "./generators.js";
11
13
  import { runProperty, summarise } from "./property.js";
12
14
  function findBrowser() {
@@ -31,13 +33,19 @@ function findBrowser() {
31
33
  }
32
34
  }
33
35
  try {
34
- candidates.push(chromium.executablePath());
36
+ candidates.push(engineType('chromium').executablePath());
35
37
  }
36
38
  catch {
37
39
  // Playwright has no browser of its own installed.
38
40
  }
39
41
  return candidates.find((c) => existsSync(c));
40
42
  }
43
+ /**
44
+ * Playwright, loaded when a browser law needs it. It probes the machine when it loads (for WSL, by reading `/proc` and
45
+ * `/run`), which a law process in the sandbox may not do, and a node law has no use for it.
46
+ */
47
+ let playwright;
48
+ const engineType = (engine) => (playwright ??= createRequire(import.meta.url)('playwright-core'))[engine];
41
49
  const engines = ['chromium', 'firefox', 'webkit'];
42
50
  /** The engine to use: the requested one, else `TSLAWS_BROWSER_ENGINE`, else chromium. Throws on an unknown name. */
43
51
  export function resolveEngine(requested, env = process.env) {
@@ -63,7 +71,7 @@ export function engineExecutable(engine, env = process.env) {
63
71
  let path = fromEnv !== undefined && fromEnv !== '' ? fromEnv : undefined;
64
72
  if (path === undefined) {
65
73
  try {
66
- path = (engine === 'firefox' ? firefox : webkit).executablePath();
74
+ path = engineType(engine).executablePath();
67
75
  }
68
76
  catch {
69
77
  // Playwright has no such browser installed.
@@ -77,7 +85,7 @@ const browsers = new Map();
77
85
  export function launch(engine) {
78
86
  let open = browsers.get(engine);
79
87
  if (open === undefined) {
80
- const type = { chromium, firefox, webkit }[engine];
88
+ const type = engineType(engine);
81
89
  open = (async () => type.launch({ executablePath: engineExecutable(engine), headless: true }))();
82
90
  open.catch(() => browsers.delete(engine));
83
91
  browsers.set(engine, open);
@@ -158,6 +166,8 @@ function projectModulesPlugin(cwd) {
158
166
  // template, a stylesheet, an image) would look for it there. Such an import resolves to the file beside the source.
159
167
  function sourceFilesPlugin(cwd) {
160
168
  const out = join(cwd, '.tslaws', 'out');
169
+ // The project's own output may sit below `out` (when sources outside it were compiled too); paths map from there.
170
+ const project = compiledDirOf(cwd);
161
171
  return {
162
172
  name: 'tslaws-source-files',
163
173
  setup(build) {
@@ -167,7 +177,7 @@ function sourceFilesPlugin(cwd) {
167
177
  const inOut = resolve(args.resolveDir, args.path);
168
178
  if (existsSync(inOut))
169
179
  return undefined;
170
- const source = join(cwd, pathRelative(out, inOut));
180
+ const source = join(cwd, pathRelative(project, inOut));
171
181
  return existsSync(source) && !source.endsWith('.js') ? { path: source } : undefined;
172
182
  });
173
183
  },
@@ -188,6 +198,16 @@ const assetExtensions = [
188
198
  '.otf',
189
199
  '.eot',
190
200
  ];
201
+ /**
202
+ * esbuild reads the nearest tsconfig.json by itself (paths, baseUrl, extends); this carries the tslaws.json setting over:
203
+ * a named file, or none for `"tsconfig": false`.
204
+ */
205
+ function bundlerTsconfig(cwd) {
206
+ const setting = readConfig(cwd).tsconfig;
207
+ if (setting === false)
208
+ return { tsconfigRaw: '{}' };
209
+ return setting === undefined ? {} : { tsconfig: resolve(cwd, setting) };
210
+ }
191
211
  /** The project's `bundlerPlugins` from tslaws.json come first, so they can claim a format before the built-in resolver. */
192
212
  async function bundleOf(jsFile, cwd) {
193
213
  const projectPlugins = await loadBundlerPlugins(cwd, readConfig(cwd).bundlerPlugins);
@@ -206,8 +226,14 @@ async function bundleOf(jsFile, cwd) {
206
226
  platform: 'browser',
207
227
  target: 'es2022',
208
228
  absWorkingDir: cwd,
229
+ ...bundlerTsconfig(cwd),
209
230
  logLevel: 'silent',
210
- define: { 'process.env.NODE_ENV': '"development"', global: 'globalThis' },
231
+ // A dependency's `import.meta.env` reads the same global the compiled laws do; the page sets it before the bundle.
232
+ define: {
233
+ 'process.env.NODE_ENV': '"development"',
234
+ global: 'globalThis',
235
+ 'import.meta.env': `globalThis.${importMetaEnvGlobal}`,
236
+ },
211
237
  });
212
238
  const emitted = (extension) => result.outputFiles
213
239
  .filter((file) => file.path.endsWith(extension))
@@ -266,6 +292,9 @@ export async function runBrowserLaw(law, options) {
266
292
  // The stylesheet goes in before the script runs, as a linked one would.
267
293
  if (css !== '')
268
294
  await page.addStyleTag({ content: css });
295
+ await page.addScriptTag({
296
+ content: `globalThis.${importMetaEnvGlobal} = ${JSON.stringify(lawEnv(options.cwd, 'browser'))};`,
297
+ });
269
298
  await page.addScriptTag({ content: code });
270
299
  await page.addScriptTag({ content: harness });
271
300
  const call = async (...args) => {
package/dist/bundled.js CHANGED
@@ -1,8 +1,8 @@
1
1
  // The compiler that npm installs with tslaws: one optional dependency per platform, `tslaws-compiler-<platform>`, holding
2
2
  // the native executable and the TypeScript lib files beside it.
3
3
  import { existsSync, readFileSync } from 'node:fs';
4
- import { createRequire } from 'node:module';
5
4
  import { dirname, join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
6
  export const platforms = [
7
7
  { name: 'darwin-arm64', os: 'darwin', cpu: 'arm64' },
8
8
  { name: 'darwin-x64', os: 'darwin', cpu: 'x64' },
@@ -36,7 +36,7 @@ export function bundledCompiler() {
36
36
  if (platform === undefined)
37
37
  return undefined;
38
38
  try {
39
- const manifest = createRequire(import.meta.url).resolve(`${packageName(platform)}/package.json`);
39
+ const manifest = fileURLToPath(import.meta.resolve(`${packageName(platform)}/package.json`));
40
40
  const executable = join(dirname(manifest), 'lib', executableName());
41
41
  return existsSync(executable) ? executable : undefined;
42
42
  }
@@ -18,3 +18,5 @@ export declare function loadBundlerPlugins(cwd: string, paths: readonly string[]
18
18
  * sign that a `bundlerPlugins` entry is missing). Other messages pass through unchanged.
19
19
  */
20
20
  export declare function explainBundleError(error: Error): Error;
21
+ /** The error for a file a node law loads that no `bundlerPlugins` entry handles (and esbuild has no loader for). */
22
+ export declare function explainNodeLoadError(file: string, esbuildMessage: string): Error;
@@ -69,3 +69,10 @@ export function explainBundleError(error) {
69
69
  `JavaScript (see "Bundler plugins" in docs/laws.md)`;
70
70
  return new Error(`${advice}. esbuild said: ${error.message.split('\n')[0]}`);
71
71
  }
72
+ /** The error for a file a node law loads that no `bundlerPlugins` entry handles (and esbuild has no loader for). */
73
+ export function explainNodeLoadError(file, esbuildMessage) {
74
+ const extension = /No loader is configured for "(\.[^"]+)" files/.exec(esbuildMessage)?.[1] ?? file;
75
+ return new Error(`cannot load "${file}": no bundler plugin handles "${extension}" files. Add one in tslaws.json ` +
76
+ `"${bundlerPluginsSetting}" (an esbuild plugin whose onLoad returns JavaScript for the extension); node laws use ` +
77
+ `the same plugins as browser laws (see "Bundler plugins" in docs/laws.md)`);
78
+ }
@@ -0,0 +1,139 @@
1
+ import { type HornCertification } from './chc.ts';
2
+ import { cvc5Text } from './solvers.ts';
3
+ /** `certify` in tslaws.json: off (absent or false), on, or `"require"`, where a law without a certificate is an error. */
4
+ export type CertifyMode = boolean | 'require';
5
+ export type CertificateStatus = 'certified' | 'uncertified' | 'unavailable';
6
+ /** What certifying one proof produced. The hashes are set only for `certified`. */
7
+ export interface Certificate {
8
+ status: CertificateStatus;
9
+ /** Why the proof is not certified: what cvc5 or Carcara said, or which syntax cannot be certified. */
10
+ reason?: string;
11
+ /** SHA-256 of the SMT-LIB problem both tools read. */
12
+ problemHash?: string;
13
+ /**
14
+ * For a proof by loop invariants: SHA-256 of the Horn text the invariants are for. The problem holds the invariants
15
+ * Z3 found, which can differ from run to run, so the law is bound to this text (which the code alone yields) instead.
16
+ */
17
+ systemHash?: string;
18
+ /** SHA-256 of the Alethe proof. */
19
+ proofHash?: string;
20
+ /** SHA-256 of the checker's verdict bound to the problem and proof it checked. */
21
+ checkerHash?: string;
22
+ /** Project-relative path of the saved proof, when a directory was given. */
23
+ proofFile?: string;
24
+ }
25
+ /** What is wrong with a `certify` value from tslaws.json, or undefined when it is valid. */
26
+ export declare function certifyProblem(value: unknown): string | undefined;
27
+ /** `certified`, or `uncertified (reason)` or `unavailable (reason)`: the line a report shows for a law. */
28
+ export declare function certificateLabel(certificate: Certificate): string;
29
+ /** Whether a certificate satisfies the mode: with `require`, only a certified proof does. */
30
+ export declare function certificateFailure(mode: CertifyMode | undefined, certificate: Certificate): string | undefined;
31
+ /**
32
+ * What cvc5's Alethe proofs cannot cover. Alethe has no rules for floating point or for strings and regular
33
+ * expressions, so a query that uses them has no proof Carcara could check. Returns the reason, or undefined when the
34
+ * query is in the fragment cvc5 can prove in Alethe.
35
+ */
36
+ export declare function uncertifiable(query: string): string | undefined;
37
+ /**
38
+ * The problem cvc5 and Carcara both read: the query as `cvc5Text` renders it (no Z3 timeout, no `(get-model)`, a logic
39
+ * set), so the proof is checked against exactly the text cvc5 proved.
40
+ */
41
+ export declare const problemText: typeof cvc5Text;
42
+ /**
43
+ * Options that make cvc5 print an Alethe proof Carcara can check.
44
+ *
45
+ * `--no-proof-alethe-res-pivots` matters: with pivots on, cvc5 names the pivot of each `resolution` step, and for a clause
46
+ * that repeats a literal (every integer range obligation does: `a` is bounded once per use) the named pivot is not found
47
+ * in the clause, so Carcara fails with "pivot was not found" on a proof that is sound. Without them Carcara finds each
48
+ * pivot itself. cvc5's own regression tests check Alethe proofs with this option off.
49
+ */
50
+ export declare const cvc5ProofArgs: readonly string[];
51
+ /** Carcara's arguments after `check <proof> <problem>`: the options cvc5's proofs need. */
52
+ export declare const carcaraArgs: readonly string[];
53
+ export declare const hashOf: (text: string) => string;
54
+ export interface CertifyOptions {
55
+ /** Wall-clock budget for each tool, in milliseconds. */
56
+ timeoutMs: number;
57
+ /** Where to keep the problem and proof (`<name>.smt2`, `<name>.alethe`); without it they are removed after the check. */
58
+ keep?: {
59
+ dir: string;
60
+ name: string;
61
+ root: string;
62
+ };
63
+ /** Set when the query is a loop proof made by `certificationProblem`: the text it came from, kept beside the proof. */
64
+ horn?: HornCertification;
65
+ }
66
+ /** The names of the RARE rewrite rules an Alethe proof applies. */
67
+ export declare function rareRulesOf(proof: string): string[];
68
+ /**
69
+ * The RARE rule declarations for `names`, in the form Carcara reads. cvc5 itself prints its database of rewrite rules, so
70
+ * the rules a proof may lean on come from the same binary that wrote the proof and never from a file beside the proof;
71
+ * the few rules in `aletheRareRules` are the exception, because the binary's own text for them cannot be checked.
72
+ */
73
+ export declare function rareDeclarations(names: string[], work: string, budget: number): Promise<{
74
+ text: string;
75
+ } | {
76
+ status: 'uncertified' | 'unavailable';
77
+ reason: string;
78
+ }>;
79
+ /**
80
+ * Certifies the `unsat` answer of a query: cvc5 proves it again in Alethe, Carcara checks the proof. Never throws for a
81
+ * missing or failing tool; the outcome is in the certificate's status.
82
+ */
83
+ export declare function certify(query: string, options: CertifyOptions): Promise<Certificate>;
84
+ /**
85
+ * Certifies a proof by loop invariants. The invariants Z3's Spacer found are put back into the clauses
86
+ * (`certificationProblem`), and the problem that results is an ordinary query, refuted by cvc5 and checked by Carcara
87
+ * like any other: a certificate says that the invariants hold at entry, are kept by every pass of the body, and imply the
88
+ * law, and Spacer needs no more trust than a guess does.
89
+ */
90
+ export declare function certifyHorn(certification: HornCertification, options: CertifyOptions): Promise<Certificate>;
91
+ /**
92
+ * One certified law as the lock records it. `law` is the law's lock hash, so a later edit voids the record, and
93
+ * `problemHash` is the hash of the exact SMT-LIB problem that was proved, so a change to code the law calls (which the
94
+ * law's own hash does not cover) voids it too: a record is made only from a proof this run produced.
95
+ */
96
+ export interface CertificateRecord {
97
+ law: string;
98
+ problemHash: string;
99
+ /** For a proof by loop invariants: the hash of the Horn text, which is what the code determines (see `Certificate`). */
100
+ systemHash?: string;
101
+ proofHash: string;
102
+ checkerHash: string;
103
+ }
104
+ /** What binds a record to the code: the Horn text for a loop proof, the problem itself for any other. */
105
+ export declare const bindingOf: (hashes: {
106
+ problemHash?: string;
107
+ systemHash?: string;
108
+ }) => string | undefined;
109
+ /** The file name a law's problem and proof are kept under, beside `.tslaws/certificates/`. */
110
+ export declare function certificateName(key: string): string;
111
+ /** Where `tslaws check` keeps the problems and proofs of the laws it certified. */
112
+ export declare const certificatesDir: (cwd: string) => string;
113
+ /**
114
+ * Where `tslaws check` leaves the records of the laws it certified, for `tslaws accept` to consider. Anyone can write this
115
+ * file, so accept trusts none of it: see `verifyRecord`.
116
+ */
117
+ export declare const recordsPath: (cwd: string) => string;
118
+ export declare function readRecords(cwd: string): Record<string, CertificateRecord>;
119
+ /**
120
+ * Updates the records after a check: each law that was proved or bounded has its record replaced by the new one when it
121
+ * is certified and removed when it is not (a law that did not run keeps what it had).
122
+ */
123
+ export declare function writeRecords(cwd: string, updates: Map<string, CertificateRecord | undefined>): void;
124
+ /**
125
+ * Whether a record from the sidecar may enter the lock, or why not. Nothing in the sidecar is trusted. The record must
126
+ * be for the law as it is now (`lawNow`) and for a problem the law still yields (`problems`, the hashes of the problems
127
+ * `tslaws accept` rebuilt from the code); the saved problem and proof must exist and hash as the record says; and
128
+ * Carcara must accept them again, here and now. With Carcara missing nothing is kept.
129
+ */
130
+ export declare function verifyRecord(cwd: string, key: string, record: unknown, lawNow: string, problems: ReadonlySet<string>, timeoutMs?: number): Promise<string | undefined>;
131
+ /** The record for a certified certificate, or undefined for any other. */
132
+ export declare function recordOf(lawHash: string, certificate: Certificate): CertificateRecord | undefined;
133
+ /** The certificate a proved or bounded law gets when certifying is on but no proof was checked. */
134
+ export declare const noCertificate: Certificate;
135
+ /**
136
+ * Whether a lock record still describes what a run just proved: the same problem. A law with no record, or a run
137
+ * that did not certify it, has nothing to compare.
138
+ */
139
+ export declare function staleRecord(record: CertificateRecord | undefined, certificate: Certificate): boolean;