pud.dev 0.0.0-stage → 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rory McMeekin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,144 @@
1
- # Temporary Holding Version
1
+ [![Pud — Proofs for TypeScript](https://raw.githubusercontent.com/PudHQ/pud/8af89706ff8663c107f92fe49461abbf71f25c6d/press/pud-github-social-card.png)](https://pud.dev)
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Write a property beside a TypeScript function. Pud translates the function and the property into Lean, then checks whether the property holds for every input you describe.
4
+
5
+ [Website](https://pud.dev) · [Worked examples](https://github.com/PudHQ/pud/tree/main/packages/pud/.examples) · [How to read a proof result](https://dex.pud.dev/notes/handbook/engineering/reading-a-proof-result/)
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ bun add -d pud.dev
11
+ ```
12
+
13
+ Pud runs on Bun. With Bun installed, try `npx pud.dev --help` to see the commands. The example below uses Lean 4.19.0. If you use Elan to manage Lean, run `elan override set leanprover/lean4:v4.19.0` in your project. [Install Bun](https://bun.com/docs/installation) · [Install Lean](https://lean-lang.org/install/)
14
+
15
+ ## Configure a proof assistant
16
+
17
+ Create `pud.config.ts` in your project root.
18
+
19
+ ```ts
20
+ import { defineConfig } from "pud.dev";
21
+ import { leanAdapter } from "pud.dev/lean";
22
+
23
+ export default defineConfig({ adapter: leanAdapter() });
24
+ ```
25
+
26
+ ## Prove a rounding rule
27
+
28
+ How should a function round half a cent? JavaScript’s `Math.round` sends ties toward positive infinity, so `12.5` rounds to `13` and `-12.5` rounds to `-12`.
29
+
30
+ ```ts
31
+ // cents.ts
32
+ export function toCents(amount: number): number {
33
+ return Math.round(amount * 100);
34
+ }
35
+ ```
36
+
37
+ Describe the rounding rule in a file beside it.
38
+
39
+ ```ts
40
+ // cents.proof.ts
41
+ import { describe, expect, it, pud } from "pud.dev";
42
+ import { toCents } from "./cents.ts";
43
+
44
+ describe(toCents, () => {
45
+ it("rounds to the nearest cent, with ties toward positive infinity", {
46
+ amount: pud.number(),
47
+ }, ({ amount }) => {
48
+ expect(toCents(amount)).toExactly(
49
+ pud.number().nearestIntegerTo(amount * 100, { ties: "up" }),
50
+ );
51
+ });
52
+ });
53
+ ```
54
+
55
+ ```sh
56
+ npx pud check cents.proof.ts
57
+ ```
58
+
59
+ A `PASS` proves the rule for every JavaScript number in the adapter’s model. The rule rounds the binary64 product `amount * 100`, including any rounding that happened during multiplication. Run `npx pud --emit cents.proof.ts` to read the theorem Lean checked.
60
+
61
+ ## Writing properties
62
+
63
+ With `.toExactly()`, the function must return an answer accepted by the schema, and the schema must exclude every other answer. Change the rule to `.refine(cents => Number.isInteger(cents))` and enable replay. At an amount of zero, Pud shows that both 0 and 1 cent satisfy the weaker rule. The CLI labels exact result claims `[exact result]`.
64
+
65
+ Start with the inputs the caller may actually supply. Each `given()` narrows that promise. Here, requiring an already-integral scaled amount would exclude precisely the fractions that need rounding. Choose the rounding policy independently of the implementation. For example, `toCents(1.005)` returns 100.
66
+
67
+ Use `pud.number()` for ordinary TypeScript numbers. The Lean adapter models binary64 arithmetic, including fractions, overflow and signed zero. Numeric `.eq()` and `toEqual()` use JavaScript strict equality, so the two zeros compare equal and NaN compares unequal to itself. Use `.sameValue(value)` to express `Object.is` equality, including the sign of zero. Exact result schemas use that same distinction when checking uniqueness, and also support bigint and boolean returns. [Motion time conversions](https://github.com/PudHQ/pud/blob/main/packages/pud/.examples/motion/seconds.proof.ts) · [Currency rounding](https://github.com/PudHQ/pud/blob/main/packages/pud/.examples/cents.proof.ts)
68
+
69
+ Use `.to()` for an invariant. For example, `expect(clamp(value, lower, upper)).to(pud.bigint().gte(lower).lte(upper))` guarantees bounds when `lower <= upper`. A clamp that always returns the lower bound also satisfies this property. [Clamp sidecar](https://github.com/PudHQ/pud/blob/main/packages/pud/.examples/clamp.proof.ts)
70
+
71
+ Use `pud.bigint()`, `pud.boolean()`, and `pud.array(item)` for the other supported inputs. Chain bounds such as `.gte()` and `.lte()`, or add a predicate with `.refine(value => …)`. Refinements work on input and result schemas. Use `given()` to relate inputs.
72
+
73
+ ```ts
74
+ expect(arrayContains(values, target)).to(pud.boolean().refine(found =>
75
+ pud.iff(found, pud.exists(values, value => value === target)),
76
+ ));
77
+ ```
78
+
79
+ `pud.exists` and `pud.forall` quantify over the elements of an array or the values admitted by a scalar schema. Compose symbolic predicates with `pud.and`, `pud.or`, `pud.not`, `pud.implies`, and `pud.iff`. Pud translates the callbacks from source. [Supported domains and operators](https://github.com/PudHQ/pud/blob/main/packages/pud/.examples/README.md#sidecar-syntax)
80
+
81
+ Run `pud check cents.proof.ts` to certify the claim or `pud --emit cents.proof.ts` to see the quantified theorem. `pud check --deny-cases` makes CI reject recognized example cases. It flags a parameterless check or literal equalities on every parameter, including simple `given()` and refinement equalities or matching inclusive bounds. A fixed policy threshold, a fixed result or one fixed argument in a larger domain can all belong in a law. The guard recognizes explicit syntax. More complex preconditions can still describe a singleton or an empty domain. `it.todo(title)` records a pending property.
82
+
83
+ The terminal highlights the active property, its elapsed time, and the time for the whole run. A trail marks queued and completed checks. After validating the input snapshots, Pud groups verdicts, timings, and diagnostics by sidecar. Redirected output uses plain rows, and `--json` returns the machine-readable report.
84
+
85
+ ### Check calls and exceptions
86
+
87
+ With the Lean adapter, `describe(encode, …)` supplies the input signature and the observation can compose imported functions.
88
+
89
+ ```ts
90
+ expect(decode(encode(value))).to(pud.bigint().eq(value));
91
+ ```
92
+
93
+ Use `expect(call()).toEqual(reference())` to compare two linked, nonthrowing calls that return the same scalar type. The sidecar can supply input constraints with `given()` before the check. The generated claim links and compares both implementations. [Availability example](https://github.com/PudHQ/pud/blob/main/packages/pud/.examples/availability/README.md)
94
+
95
+ With `leanAdapter({ replay: true })`, an open scalar result predicate or call equality can produce a concrete counterexample. Pud filters candidate inputs through the supported schema and `given()` conditions, runs the frozen TypeScript in Bun, and reports the input and observed result on a violation. Native predicates and quantified assertions are outside replay. Only the proof assistant can establish a pass. Enable replay for source you trust to execute.
96
+
97
+ A property can also assert the exact class of a modeled exception. The callback keeps the throwing call inside the observation.
98
+
99
+ ```ts
100
+ expect(() => divide(numerator, divisor)).toThrow("RangeError");
101
+ ```
102
+
103
+ `.to()` requires a successful return. `.toThrow()` accepts `"Error"`, `"RangeError"`, or `"TypeError"` in Lean suites. [Supported calls, outcomes, and termination](https://github.com/PudHQ/pud/blob/main/packages/pud/.examples/README.md#what-a-pass-establishes)
104
+
105
+ ### Use native proof code
106
+
107
+ Import `pud` from your config when a property needs native code. Both `pud.describe()` and the schema builders carry the selected assistant's type.
108
+
109
+ ```ts
110
+ import pud from "./pud.config";
111
+ import { lean } from "pud.dev/lean";
112
+ import { increment } from "./increment";
113
+
114
+ pud.describe(increment, ({ it, expect }) => {
115
+ it("returns a greater integer", { value: pud.bigint() }, ({ value }) => {
116
+ expect(increment(value)).to(pud.bigint().satisfies(
117
+ lean`fun (result : Int) => ${value} < result`,
118
+ ));
119
+ });
120
+ });
121
+ ```
122
+
123
+ Use `.satisfies()` to add a native predicate to a schema and `.by()` to supply a proof of the whole property. A `lean` template can interpolate TypeScript expressions in scope, and `lean.ref("Namespace.name", ...args)` can name a predicate or theorem. Register a local helper file with `use(lean.module("./helper.lean"))`. [Lean examples and supported types](https://github.com/PudHQ/pud/blob/main/packages/pud/.examples/README.md)
124
+
125
+ ### Use the library
126
+
127
+ ```ts
128
+ import { check, emit } from "pud.dev";
129
+ import { leanAdapter } from "pud.dev/lean";
130
+
131
+ const adapter = leanAdapter();
132
+ const report = await check("clamp.proof.ts", { adapter });
133
+ const unit = await emit("clamp.proof.ts", { adapter, property: "keeps the result within ordered bounds" });
134
+ ```
135
+
136
+ `checkFiles(files, { adapter })` applies the same override to a batch and runs the supplied adapter in the caller’s process. When Pud loads the project config, each `check`, `checkFiles`, or `emit` call starts a fresh Bun process. Suites in one batch share its loaded modules. The next call picks up edits to the config and its imports. Project logs go to stderr so the CLI can pipe a JSON report or an emitted unit through stdout.
137
+
138
+ An adapter implements `ProofAssistant` from `pud.dev` and supplies a stable assistant ID. Its `prepare` method reads the named TypeScript export from the supplied snapshot and returns its signature, an emitter, and a verifier. Pud binds one `ProofClaim` per active property and checks its native term IDs against the adapter. Switch on `claim.kind` to handle a return rule (`"return"`), equality with a reference call (`"equal"`), or an expected exception (`"throw"`). Exact return rules carry `exactResult: true`. For a custom native tag, import `native` from `pud.dev` and declare `const term = native("assistant-id")` at file scope before `pud.describe`. [Adapter contract](https://github.com/PudHQ/pud/blob/main/packages/pud/src/assistant.ts)
139
+
140
+ Use `checkFiles(files, { onProgress })` for a live view. Suite events declare the queue and total item count. Each active property index appears in exactly one `finished` event during a completed run. Its status is at the same position in `statuses`. Pending properties stay out of the count. The `validating` event precedes the input snapshot check. The returned reports carry the final verdicts.
141
+
142
+ ## Development
143
+
144
+ Follow the [workspace setup](https://github.com/PudHQ/pud#workspace) and run `bun run test` from the root. Run `bun run pack:cli` to write the self-contained archive to `dist/`. The archive contains the executable, both public entry points, and their TypeScript declarations.
@@ -0,0 +1,112 @@
1
+ @babel/helper-string-parser@8.1.2
2
+
3
+ MIT License
4
+
5
+ Copyright (c) 2014-present Sebastian McKenzie and other contributors
6
+
7
+ Permission is hereby granted, free of charge, to any person obtaining
8
+ a copy of this software and associated documentation files (the
9
+ "Software"), to deal in the Software without restriction, including
10
+ without limitation the rights to use, copy, modify, merge, publish,
11
+ distribute, sublicense, and/or sell copies of the Software, and to
12
+ permit persons to whom the Software is furnished to do so, subject to
13
+ the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be
16
+ included in all copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
+
26
+
27
+ @babel/helper-validator-identifier@8.0.6
28
+
29
+ MIT License
30
+
31
+ Copyright (c) 2014-present Sebastian McKenzie and other contributors
32
+
33
+ Permission is hereby granted, free of charge, to any person obtaining
34
+ a copy of this software and associated documentation files (the
35
+ "Software"), to deal in the Software without restriction, including
36
+ without limitation the rights to use, copy, modify, merge, publish,
37
+ distribute, sublicense, and/or sell copies of the Software, and to
38
+ permit persons to whom the Software is furnished to do so, subject to
39
+ the following conditions:
40
+
41
+ The above copyright notice and this permission notice shall be
42
+ included in all copies or substantial portions of the Software.
43
+
44
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
45
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
47
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
48
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
49
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
50
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51
+
52
+
53
+ @babel/parser@8.1.2
54
+
55
+ Copyright (C) 2012-2014 by various contributors (see AUTHORS)
56
+
57
+ Permission is hereby granted, free of charge, to any person obtaining a copy
58
+ of this software and associated documentation files (the "Software"), to deal
59
+ in the Software without restriction, including without limitation the rights
60
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
61
+ copies of the Software, and to permit persons to whom the Software is
62
+ furnished to do so, subject to the following conditions:
63
+
64
+ The above copyright notice and this permission notice shall be included in
65
+ all copies or substantial portions of the Software.
66
+
67
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
71
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
73
+ THE SOFTWARE.
74
+
75
+
76
+ @babel/types@8.1.2
77
+
78
+ MIT License
79
+
80
+ Copyright (c) 2014-present Sebastian McKenzie and other contributors
81
+
82
+ Permission is hereby granted, free of charge, to any person obtaining
83
+ a copy of this software and associated documentation files (the
84
+ "Software"), to deal in the Software without restriction, including
85
+ without limitation the rights to use, copy, modify, merge, publish,
86
+ distribute, sublicense, and/or sell copies of the Software, and to
87
+ permit persons to whom the Software is furnished to do so, subject to
88
+ the following conditions:
89
+
90
+ The above copyright notice and this permission notice shall be
91
+ included in all copies or substantial portions of the Software.
92
+
93
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
94
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
95
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
96
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
97
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
98
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
99
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
100
+
101
+
102
+ chalk@6.0.1
103
+
104
+ MIT License
105
+
106
+ Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
107
+
108
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
109
+
110
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
111
+
112
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.