pud.dev 0.0.1 → 0.0.2

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 (73) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -27
  3. package/THIRD-PARTY-NOTICES +112 -0
  4. package/chunk-224av1ab.js +10 -0
  5. package/chunk-fstxscck.js +3 -0
  6. package/chunk-h90k6v7w.js +3 -0
  7. package/chunk-k7a83qqm.js +3 -0
  8. package/cli.js +37 -0
  9. package/index.js +2 -0
  10. package/lean/index.js +880 -0
  11. package/package.json +28 -19
  12. package/project-runner.js +2 -0
  13. package/types/assistant.d.ts +200 -0
  14. package/types/check.d.ts +55 -0
  15. package/types/expressions.d.ts +47 -0
  16. package/types/input-scope.d.ts +4 -0
  17. package/types/lean/command.d.ts +14 -0
  18. package/types/lean/index.d.ts +5 -0
  19. package/types/lean/number.d.ts +4 -0
  20. package/types/lean/program.d.ts +26 -0
  21. package/types/lean/replay-predicate.d.ts +5 -0
  22. package/types/lean/replay.d.ts +6 -0
  23. package/types/lean/scalar.d.ts +23 -0
  24. package/types/lean/subject.d.ts +25 -0
  25. package/types/lean/syntax.d.ts +42 -0
  26. package/types/module.d.ts +9 -0
  27. package/types/prover-process.d.ts +7 -0
  28. package/types/run.d.ts +30 -0
  29. package/types/source.d.ts +5 -0
  30. package/types/suite-authoring.d.ts +117 -0
  31. package/types/suite-check.d.ts +10 -0
  32. package/types/suite.d.ts +44 -0
  33. package/CLAUDE.md +0 -106
  34. package/scripts/pack.ts +0 -67
  35. package/scripts/setup-lean.ts +0 -88
  36. package/src/assistant.ts +0 -131
  37. package/src/check.ts +0 -173
  38. package/src/cli.ts +0 -70
  39. package/src/expressions.ts +0 -65
  40. package/src/input-scope.ts +0 -71
  41. package/src/lean/command.ts +0 -40
  42. package/src/lean/index.ts +0 -437
  43. package/src/lean/iteration.lean +0 -145
  44. package/src/lean/lean-assets.d.ts +0 -4
  45. package/src/lean/number.lean +0 -427
  46. package/src/lean/number.ts +0 -25
  47. package/src/lean/program.ts +0 -110
  48. package/src/lean/replay-predicate.ts +0 -95
  49. package/src/lean/replay.ts +0 -136
  50. package/src/lean/scalar.lean +0 -183
  51. package/src/lean/scalar.ts +0 -196
  52. package/src/lean/subject.ts +0 -443
  53. package/src/lean/syntax.ts +0 -287
  54. package/src/module.ts +0 -110
  55. package/src/project-runner.ts +0 -26
  56. package/src/prover-process.ts +0 -16
  57. package/src/reporter.ts +0 -173
  58. package/src/run.ts +0 -60
  59. package/src/source.ts +0 -54
  60. package/src/suite-authoring.ts +0 -135
  61. package/src/suite-check.ts +0 -157
  62. package/src/suite.ts +0 -515
  63. package/src/terminal-progress.ts +0 -145
  64. package/src/terminal.ts +0 -41
  65. package/test/authoring.test.ts +0 -151
  66. package/test/lean.test.ts +0 -394
  67. package/test/module.test.ts +0 -55
  68. package/test/number.test.ts +0 -318
  69. package/test/package.test.ts +0 -170
  70. package/test/suite.test.ts +0 -257
  71. package/tsconfig.json +0 -7
  72. package/tsconfig.pack.json +0 -12
  73. /package/{src/index.ts → types/index.d.ts} +0 -0
@@ -0,0 +1,117 @@
1
+ import type { ProofAssistant, ProofErrorKind } from "./assistant.ts";
2
+ type Value = bigint | number | boolean | string | readonly unknown[];
3
+ type Subject = (...args: never[]) => Value;
4
+ declare const valueType: unique symbol;
5
+ declare const assistantType: unique symbol;
6
+ declare const nativeType: unique symbol;
7
+ declare const propositionType: unique symbol;
8
+ export interface Proposition {
9
+ readonly [propositionType]: true;
10
+ }
11
+ type Predicate = boolean | Proposition;
12
+ export interface Schema<T, Id extends string = never> {
13
+ readonly [valueType]: T;
14
+ readonly [assistantType]: Id;
15
+ refine(predicate: (value: T) => Predicate): this;
16
+ }
17
+ export interface NativeTerm<Id extends string> {
18
+ readonly [nativeType]: {
19
+ kind: "term";
20
+ id: (id: Id) => Id;
21
+ };
22
+ }
23
+ export interface NativeModule<Id extends string> {
24
+ readonly [nativeType]: {
25
+ kind: "module";
26
+ id: (id: Id) => Id;
27
+ };
28
+ readonly path: string;
29
+ }
30
+ export interface NativeSyntax<Id extends string> {
31
+ (parts: TemplateStringsArray, ...args: Value[]): NativeTerm<Id>;
32
+ ref(name: string, ...args: Value[]): NativeTerm<Id>;
33
+ module(path: string): NativeModule<Id>;
34
+ }
35
+ interface NumericSchema<T extends bigint | number, Id extends string> extends Schema<T, Id> {
36
+ eq(value: T): this;
37
+ gt(value: T): this;
38
+ gte(value: T): this;
39
+ lt(value: T): this;
40
+ lte(value: T): this;
41
+ satisfies(term: NativeTerm<Id>): this;
42
+ }
43
+ interface NumberSchema<Id extends string> extends NumericSchema<number, Id> {
44
+ /** ECMAScript SameValue, including NaN and the sign of zero. */
45
+ sameValue(value: number): this;
46
+ /** Nearest whole number, with explicit half ties. Preserve NaN, infinities and the sign of a zero result. */
47
+ nearestIntegerTo(value: number, options: {
48
+ ties: "up" | "down";
49
+ }): this;
50
+ }
51
+ interface BooleanSchema<Id extends string> extends Schema<boolean, Id> {
52
+ eq(value: boolean): BooleanSchema<Id>;
53
+ satisfies(term: NativeTerm<Id>): BooleanSchema<Id>;
54
+ }
55
+ interface ArraySchema<T, Id extends string> extends Schema<readonly T[], Id> {
56
+ satisfies(term: NativeTerm<Id>): ArraySchema<T, Id>;
57
+ }
58
+ interface SchemaBuilders<Id extends string> {
59
+ bigint(): NumericSchema<bigint, Id>;
60
+ number(): NumberSchema<Id>;
61
+ boolean(): BooleanSchema<Id>;
62
+ int(): NumericSchema<bigint, Id>;
63
+ bool(): BooleanSchema<Id>;
64
+ opaque<T>(): Schema<T, Id>;
65
+ array<T>(items: Schema<T, Id>): ArraySchema<T, Id>;
66
+ textOrArray<T>(items: Schema<T, Id>): Schema<string | readonly T[], Id>;
67
+ forall<T extends bigint | number | boolean>(domain: Schema<T, Id> | readonly T[], predicate: (value: T) => Predicate): Proposition;
68
+ exists<T extends bigint | number | boolean>(domain: Schema<T, Id> | readonly T[], predicate: (value: T) => Predicate): Proposition;
69
+ and(left: Predicate, right: Predicate): Proposition;
70
+ or(left: Predicate, right: Predicate): Proposition;
71
+ not(operand: Predicate): Proposition;
72
+ implies(assumption: Predicate, conclusion: Predicate): Proposition;
73
+ iff(left: Predicate, right: Predicate): Proposition;
74
+ length(items: readonly unknown[]): bigint;
75
+ sum(items: readonly bigint[]): bigint;
76
+ modulo(value: bigint, divisor: bigint): bigint;
77
+ quotient(value: bigint, divisor: bigint): bigint;
78
+ }
79
+ interface SuiteAuthoring<Id extends string> {
80
+ pud: SchemaBuilders<Id>;
81
+ it: {
82
+ <D extends Record<string, Schema<Value, Id>>>(name: string, inputs: D, property: (args: {
83
+ [K in keyof D]: D[K][typeof valueType];
84
+ }) => void): {
85
+ by(proof: NativeTerm<Id>): void;
86
+ };
87
+ todo(name: string): void;
88
+ };
89
+ given(condition: Predicate): void;
90
+ expect: {
91
+ <T extends Value>(value: T): {
92
+ to(schema: Schema<NoInfer<T>, Id>): void;
93
+ /** Prove that the schema accepts precisely the observed scalar result for each admitted input. */
94
+ toExactly(schema: [T] extends [number | bigint | boolean] ? Schema<NoInfer<T>, Id> : never): void;
95
+ toEqual(reference: NoInfer<T> & (bigint | number | boolean)): void;
96
+ };
97
+ (call: () => Value): {
98
+ toThrow(error: ProofErrorKind): void;
99
+ };
100
+ };
101
+ use(module: NativeModule<Id>): void;
102
+ }
103
+ export interface PudConfig<Id extends string = string> extends SchemaBuilders<Id> {
104
+ adapter: ProofAssistant<Id>;
105
+ describe(subject: Subject, suite: (helpers: SuiteAuthoring<Id>) => void): void;
106
+ }
107
+ export declare const pud: SchemaBuilders<never>;
108
+ export declare const it: SuiteAuthoring<never>["it"];
109
+ export declare const given: SuiteAuthoring<never>["given"];
110
+ export declare const expect: SuiteAuthoring<never>["expect"];
111
+ export declare const describe: (subject: Subject, suite: () => void) => void;
112
+ /** A static tag for an adapter's native proof text. */
113
+ export declare function native<const Id extends string>(_id: Id): NativeSyntax<Id>;
114
+ export declare function defineConfig<const Id extends string>(config: {
115
+ adapter: ProofAssistant<Id>;
116
+ }): PudConfig<Id>;
117
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { CheckOptions, CheckResult, EmitOptions, ItemProgress } from "./check.ts";
2
+ import { type Suite } from "./suite.ts";
3
+ type Read = (file: string) => {
4
+ canonical: string;
5
+ source: string;
6
+ };
7
+ export declare function findConfig(file: string): string | undefined;
8
+ export declare function checkSuite(suite: Suite, config: string | undefined, options: CheckOptions, read: Read, report?: ItemProgress): Promise<CheckResult[]>;
9
+ export declare function emitSuite(suite: Suite, config: string | undefined, options: EmitOptions, read: Read): Promise<string>;
10
+ export {};
@@ -0,0 +1,44 @@
1
+ import type { CallExpression, Node, Program } from "@babel/types";
2
+ import type { PreparedProofAssistant, ProofClaim } from "./assistant.ts";
3
+ type SuiteProperty = {
4
+ name: string;
5
+ line: number;
6
+ } & ({
7
+ kind: "todo";
8
+ } | {
9
+ kind: "claim";
10
+ call: CallExpression;
11
+ proof?: Node;
12
+ });
13
+ export interface Suite {
14
+ file: string;
15
+ source: string;
16
+ subject: {
17
+ file: string;
18
+ name: string;
19
+ };
20
+ subjects: ReadonlyMap<string, {
21
+ file: string;
22
+ name: string;
23
+ }>;
24
+ binding: string;
25
+ properties: SuiteProperty[];
26
+ modules: {
27
+ assistant: string;
28
+ file: string;
29
+ }[];
30
+ helpers: ReadonlyMap<string, string>;
31
+ schemaBindings: ReadonlySet<string>;
32
+ native: ReadonlyMap<string, string>;
33
+ configured: boolean;
34
+ numberGlobal: boolean;
35
+ imports: {
36
+ path: string;
37
+ resolveAgain: () => string;
38
+ }[];
39
+ }
40
+ export declare function readSuite(file: string, origin: string, source: string, program: Program, config?: string): Suite;
41
+ export declare function bindClaim(suite: Suite, property: Extract<SuiteProperty, {
42
+ kind: "claim";
43
+ }>, subject: PreparedProofAssistant): ProofClaim;
44
+ export {};
package/CLAUDE.md DELETED
@@ -1,106 +0,0 @@
1
-
2
- Default to using Bun instead of Node.js.
3
-
4
- - Use `bun <file>` instead of `node <file>` or `ts-node <file>`
5
- - Use `bun test` instead of `jest` or `vitest`
6
- - Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
7
- - Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
8
- - Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
9
- - Use `bunx <package> <command>` instead of `npx <package> <command>`
10
- - Bun automatically loads .env, so don't use dotenv.
11
-
12
- ## APIs
13
-
14
- - `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
15
- - `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
16
- - `Bun.redis` for Redis. Don't use `ioredis`.
17
- - `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
18
- - `WebSocket` is built-in. Don't use `ws`.
19
- - Prefer `Bun.file` over `node:fs`'s readFile/writeFile
20
- - Bun.$`ls` instead of execa.
21
-
22
- ## Testing
23
-
24
- Use `bun test` to run tests.
25
-
26
- ```ts#index.test.ts
27
- import { test, expect } from "bun:test";
28
-
29
- test("hello world", () => {
30
- expect(1).toBe(1);
31
- });
32
- ```
33
-
34
- ## Frontend
35
-
36
- Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.
37
-
38
- Server:
39
-
40
- ```ts#index.ts
41
- import index from "./index.html"
42
-
43
- Bun.serve({
44
- routes: {
45
- "/": index,
46
- "/api/users/:id": {
47
- GET: (req) => {
48
- return new Response(JSON.stringify({ id: req.params.id }));
49
- },
50
- },
51
- },
52
- // optional websocket support
53
- websocket: {
54
- open: (ws) => {
55
- ws.send("Hello, world!");
56
- },
57
- message: (ws, message) => {
58
- ws.send(message);
59
- },
60
- close: (ws) => {
61
- // handle close
62
- }
63
- },
64
- development: {
65
- hmr: true,
66
- console: true,
67
- }
68
- })
69
- ```
70
-
71
- HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. `<link>` tags can point to stylesheets and Bun's CSS bundler will bundle.
72
-
73
- ```html#index.html
74
- <html>
75
- <body>
76
- <h1>Hello, world!</h1>
77
- <script type="module" src="./frontend.tsx"></script>
78
- </body>
79
- </html>
80
- ```
81
-
82
- With the following `frontend.tsx`:
83
-
84
- ```tsx#frontend.tsx
85
- import React from "react";
86
- import { createRoot } from "react-dom/client";
87
-
88
- // import .css files directly and it works
89
- import './index.css';
90
-
91
- const root = createRoot(document.body);
92
-
93
- export default function Frontend() {
94
- return <h1>Hello, world!</h1>;
95
- }
96
-
97
- root.render(<Frontend />);
98
- ```
99
-
100
- Then, run index.ts
101
-
102
- ```sh
103
- bun --hot ./index.ts
104
- ```
105
-
106
- For more information, read the Bun API docs in `node_modules/bun-types/docs/**.mdx`.
package/scripts/pack.ts DELETED
@@ -1,67 +0,0 @@
1
- import { execFileSync } from "node:child_process";
2
- import { chmod, copyFile, mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises";
3
- import { tmpdir } from "node:os";
4
- import { join, resolve, sep } from "node:path";
5
- import manifest from "../package.json";
6
-
7
- const pud = resolve(import.meta.dir, "..");
8
- const root = resolve(pud, "../..");
9
-
10
- /** Ship the notices of every third-party package actually present in the Bun bundle. */
11
- async function writeNotices(files: string[], target: string) {
12
- const packages = new Set<string>();
13
- for (const file of files) {
14
- const parts = resolve(file).split(sep);
15
- const index = parts.lastIndexOf("node_modules");
16
- if (index < 0) continue;
17
- const scoped = parts[index + 1]!.startsWith("@");
18
- packages.add(parts.slice(0, index + (scoped ? 3 : 2)).join(sep));
19
- }
20
- const notices: string[] = [];
21
- for (const dir of [...packages].sort()) {
22
- const { name, version } = await Bun.file(join(dir, "package.json")).json();
23
- const licenses = (await readdir(dir)).filter(n => /^(licen[cs]e|copying|notice)(?:$|[.-])/i.test(n)).sort();
24
- if (!licenses.length) throw new Error(`Missing license for ${name}@${version}`);
25
- notices.push(`${name}@${version}`, ...await Promise.all(licenses.map(n => readFile(join(dir, n), "utf8"))));
26
- }
27
- await writeFile(target, notices.join("\n\n"));
28
- }
29
-
30
- export async function pack(destination = join(root, "dist")) {
31
- destination = resolve(destination);
32
- const stage = await mkdtemp(join(tmpdir(), "pud-pack-"));
33
- try {
34
- const build = await Bun.build({
35
- entrypoints: ["cli.ts", "index.ts", "lean/index.ts", "project-runner.ts"].map(file => join(pud, "src", file)),
36
- root: join(pud, "src"),
37
- outdir: stage,
38
- target: "bun",
39
- splitting: true,
40
- metafile: true,
41
- minify: { whitespace: true },
42
- });
43
- if (!build.success) throw new AggregateError(build.logs, "Could not bundle Pud");
44
- execFileSync(process.execPath, [
45
- join(root, "node_modules/typescript/bin/tsc"), "-p", join(pud, "tsconfig.pack.json"), "--outDir", join(stage, "types"),
46
- ], { stdio: "inherit" });
47
- await writeNotices(Object.keys(build.metafile!.inputs), join(stage, "THIRD-PARTY-NOTICES"));
48
- await copyFile(join(root, "LICENSE"), join(stage, "LICENSE"));
49
- await chmod(join(stage, "cli.js"), 0o755);
50
- const types = "./types/index.d.ts";
51
- await writeFile(join(stage, "package.json"), JSON.stringify({
52
- name: manifest.name, version: manifest.version, type: "module", license: manifest.license,
53
- exports: {
54
- ".": { types, default: "./index.js" },
55
- "./lean": { types: "./types/lean/index.d.ts", default: "./lean/index.js" },
56
- }, types,
57
- bin: { pud: "./cli.js" },
58
- }, null, 2));
59
- await mkdir(destination, { recursive: true });
60
- const archive = execFileSync(process.execPath, ["pm", "pack", "--destination", destination, "--quiet"], { cwd: stage, encoding: "utf8" }).trim();
61
- return resolve(destination, archive);
62
- } finally {
63
- await rm(stage, { recursive: true, force: true });
64
- }
65
- }
66
-
67
- if (import.meta.main) console.log(await pack(process.argv[2]));
@@ -1,88 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { readFileSync } from "node:fs";
3
- import { mkdir, mkdtemp, rename, rm, writeFile } from "node:fs/promises";
4
- import { basename, dirname, join } from "node:path";
5
- import { fileURLToPath } from "node:url";
6
-
7
- const toolchain = readFileSync(new URL("../.examples/lean-toolchain", import.meta.url), "utf8").trim();
8
- const checkoutElan = fileURLToPath(new URL("../../../.cache/elan", import.meta.url));
9
- const extension = process.platform === "win32" ? ".exe" : "";
10
- const elanVersion = "v4.4.0";
11
-
12
- // https://github.com/leanprover/elan/releases/tag/v4.4.0
13
- const releases: Record<string, { archive: string; sha256: string }> = {
14
- "darwin-arm64": { archive: "aarch64-apple-darwin.tar.gz", sha256: "27af24edeace839730e8c9119783f12d5f694327d4771605021ca09db1ab0a87" },
15
- "darwin-x64": { archive: "x86_64-apple-darwin.tar.gz", sha256: "a5123096d662216ceaf69d68d6bbabb118c024d20d270bf0d639a830dd4ff97e" },
16
- "linux-arm64": { archive: "aarch64-unknown-linux-gnu.tar.gz", sha256: "45cde3006f82f98804c94cf2ca4949d117060a5f3cc8afa62f523759947ee21f" },
17
- "linux-x64": { archive: "x86_64-unknown-linux-gnu.tar.gz", sha256: "0e8250aa2be86c7af929ade68db617af9edc8b9ccf6eaf5ece228250d0d032e2" },
18
- "win32-x64": { archive: "x86_64-pc-windows-msvc.zip", sha256: "63f50605424284927799702347e2bdbd99d017b9d80ae083c65ee2189c4caf75" },
19
- };
20
-
21
- function shim(home: string, name: "lean" | "elan") {
22
- return join(home, "bin", name + extension);
23
- }
24
-
25
- function elanEnv(home: string) {
26
- return { ...process.env, ELAN_HOME: home, ELAN_TOOLCHAIN: toolchain };
27
- }
28
-
29
- async function run(binary: string, args: string[], env = process.env) {
30
- const child = Bun.spawn([binary, ...args], { env, stdout: "inherit", stderr: "inherit" });
31
- const exit = await child.exited;
32
- if (exit !== 0) throw new Error(`${basename(binary)} exited with status ${exit}.`);
33
- }
34
-
35
- async function selectToolchain(home: string) {
36
- await run(shim(home, "elan"), ["default", toolchain], elanEnv(home));
37
- await run(shim(home, "lean"), ["--version"], elanEnv(home));
38
- }
39
-
40
- function hasElan(home: string) {
41
- return Boolean(Bun.which(shim(home, "elan")) && Bun.which(shim(home, "lean")));
42
- }
43
-
44
- async function setupLean() {
45
- if (hasElan(checkoutElan)) {
46
- await selectToolchain(checkoutElan);
47
- return;
48
- }
49
-
50
- const platform = `${process.platform}-${process.arch}`;
51
- const release = releases[platform];
52
- if (!release) throw new Error(`Elan has no bundled installer for ${platform}. Set PUD_LEAN to a working Lean executable.`);
53
-
54
- const cache = dirname(checkoutElan);
55
- await mkdir(cache, { recursive: true });
56
- const stage = await mkdtemp(join(cache, ".elan-install-"));
57
- try {
58
- const archive = join(stage, `elan-${release.archive}`);
59
- const stagedHome = join(stage, "elan-home");
60
- console.log(`Installing Elan ${elanVersion} and ${toolchain} in .cache/elan`);
61
- const response = await fetch(`https://github.com/leanprover/elan/releases/download/${elanVersion}/${basename(archive)}`, {
62
- signal: AbortSignal.timeout(60_000),
63
- });
64
- if (!response.ok) throw new Error(`Elan download returned HTTP ${response.status}.`);
65
- const bytes = new Uint8Array(await response.arrayBuffer());
66
- if (createHash("sha256").update(bytes).digest("hex") !== release.sha256) throw new Error("Elan release checksum mismatch.");
67
- await writeFile(archive, bytes);
68
- await run("tar", ["-xf", archive, "-C", stage]);
69
- await run(join(stage, `elan-init${extension}`), ["-y", "--no-modify-path", "--default-toolchain", "none"], elanEnv(stagedHome));
70
- await selectToolchain(stagedHome);
71
- try {
72
- await rename(stagedHome, checkoutElan);
73
- } catch (error) {
74
- if (!hasElan(checkoutElan)) throw error;
75
- await selectToolchain(checkoutElan);
76
- }
77
- } finally {
78
- await rm(stage, { recursive: true, force: true });
79
- }
80
- }
81
-
82
- if (import.meta.main) {
83
- try { await setupLean(); }
84
- catch (error) {
85
- console.error(`Lean setup failed. ${(error as Error).message}`);
86
- process.exitCode = 1;
87
- }
88
- }
package/src/assistant.ts DELETED
@@ -1,131 +0,0 @@
1
- /** A construct for which the selected frontend or adapter has no semantics. */
2
- export class Unsupported extends Error {}
3
-
4
- export function failure(error: unknown): { status: "unsupported" | "error"; detail: string } {
5
- return { status: error instanceof Unsupported ? "unsupported" : "error", detail: error instanceof Error ? error.message : String(error) };
6
- }
7
-
8
- export interface SubjectSource {
9
- name: string;
10
- file: string;
11
- source: string;
12
- /** Read and track a UTF-8 input relative to the subject's directory or by absolute path. */
13
- readDependency?(path: string): string;
14
- /** Read a linked source and track any import resolution that selected it. */
15
- readModule?(path: string, resolveAgain?: () => string): { canonical: string; source: string };
16
- }
17
-
18
- export interface Counterexample {
19
- summary: string;
20
- input: Record<string, string>;
21
- result: string;
22
- /** A distinct value accepted by an exact result rule for the same input. */
23
- alternative?: string;
24
- difference?: { subject: string; expected: string; received: string };
25
- }
26
-
27
- export type ProofType =
28
- | { kind: "integer" | "number" | "boolean" }
29
- | { kind: "opaque"; name: string }
30
- | { kind: "array" | "textOrArray"; item: ProofType };
31
-
32
- /** A TypeScript expression and its mapping from callback bindings to subject parameters. */
33
- export interface ProofExpression {
34
- file: string;
35
- source: string;
36
- line: number;
37
- column: number;
38
- offset: number;
39
- bindings: ReadonlyMap<string, string>;
40
- /** In-scope references to Pud's specification helpers. */
41
- schemaBindings?: ReadonlySet<string>;
42
- /** The JavaScript Number constructor is in scope in this expression. */
43
- numberGlobal?: boolean;
44
- }
45
-
46
- export type NativeProofTerm = { assistant: string; args: readonly ProofExpression[] } & (
47
- | { kind: "reference"; name: string }
48
- | { kind: "template"; parts: readonly string[] }
49
- );
50
-
51
- export type ProofTarget = { kind: "parameter"; name: string } | { kind: "result" } | { kind: "quantified" };
52
- export type ProofComparison = "eq" | "gt" | "gte" | "lt" | "lte";
53
-
54
- export type ProofPredicate =
55
- | { kind: "boolean"; expression: ProofExpression }
56
- | { kind: "not"; operand: ProofPredicate }
57
- | { kind: "binary"; operator: "and" | "or" | "implies" | "iff"; left: ProofPredicate; right: ProofPredicate }
58
- | {
59
- kind: "quantifier";
60
- quantifier: "forall" | "exists";
61
- variable: string;
62
- domain: { kind: "array"; expression: ProofExpression }
63
- | { kind: "schema"; type: "integer" | "number" | "boolean"; constraints: readonly ProofConstraint[] };
64
- predicate: ProofPredicate;
65
- };
66
-
67
- export type ProofConstraint =
68
- | { kind: "condition"; expression: ProofExpression }
69
- | { kind: "proposition"; predicate: ProofPredicate }
70
- | { kind: "comparison"; target: ProofTarget; operator: ProofComparison; value: ProofExpression }
71
- | { kind: "nearestInteger"; target: ProofTarget; value: ProofExpression; ties: "up" | "down" }
72
- | { kind: "sameValue"; target: ProofTarget; value: ProofExpression }
73
- | { kind: "refinement"; target: ProofTarget; variable: string; predicate: ProofPredicate }
74
- | { kind: "native"; target: ProofTarget; term: NativeProofTerm };
75
-
76
- export type ProofClaim = {
77
- premises: readonly ProofConstraint[];
78
- proof?: NativeProofTerm;
79
- observation?: ProofCall;
80
- } & (
81
- | {
82
- kind: "return";
83
- assertions: readonly ProofConstraint[];
84
- /** The assertions must characterize the observed result uniquely. */
85
- exactResult?: true;
86
- reference?: never;
87
- expectedError?: never;
88
- }
89
- | { kind: "equal"; assertions: readonly []; reference: ProofCall; expectedError?: never; exactResult?: never }
90
- | { kind: "throw"; assertions: readonly []; expectedError: ProofErrorKind; reference?: never; exactResult?: never }
91
- );
92
-
93
- export type ProofErrorKind = "Error" | "RangeError" | "TypeError";
94
-
95
- export interface ProofCall {
96
- kind: "call";
97
- callee: "subject" | { file: string; name: string };
98
- args: readonly (ProofCall | { kind: "parameter"; name: string })[];
99
- }
100
-
101
- export interface ProofModule {
102
- file: string;
103
- source: string;
104
- }
105
-
106
- export type ProofOutcome =
107
- | { status: "proved" }
108
- /** A concrete input witnesses a violated assertion or an ambiguous exact result. */
109
- | { status: "disproved"; counterexample: Counterexample }
110
- | { status: "unproved" | "unsupported" | "error"; detail: string; diagnostic?: string };
111
-
112
- export type ClaimProgress = (index: number, state: "running" | "finished", status?: ProofOutcome["status"]) => void;
113
-
114
- /** The adapter has parsed the exact implementation snapshot and can certify claims about it. */
115
- export interface PreparedProofAssistant {
116
- parameters: readonly { name: string; type: ProofType }[];
117
- result: ProofType;
118
- inspectCall?(call: ProofCall): ProofType;
119
- /** The assistant can compare the observation with a reference call. */
120
- callEquality?: true;
121
- /** The assistant proves both satisfaction and uniqueness for scalar return schemas. */
122
- exactResults?: true;
123
- errors?: readonly ProofErrorKind[];
124
- emit(claim: ProofClaim, modules: readonly ProofModule[]): string | Promise<string>;
125
- verify(claims: readonly ProofClaim[], modules: readonly ProofModule[], onClaim?: ClaimProgress): Promise<readonly ProofOutcome[]>;
126
- }
127
-
128
- export interface ProofAssistant<Id extends string = string> {
129
- readonly id: Id;
130
- prepare(subject: SubjectSource): PreparedProofAssistant | Promise<PreparedProofAssistant>;
131
- }