@ohtaman/washi 0.8.0 → 0.8.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 (81) hide show
  1. package/README.md +32 -34
  2. package/dist/browser/{__vite-browser-external-rTVKos2U.js → solvers/highs-__vite-browser-external-Dn-83hnF.js} +1 -1
  3. package/dist/browser/{browser-runtime-AG5QFtKf.js → solvers/highs-browser-runtime-0Bgq5ksG.js} +1 -1
  4. package/dist/browser/{loader-i3FnqMes.js → solvers/highs-loader-BLY3wzDH.js} +25 -18
  5. package/dist/browser/{highs-worker.js → solvers/highs-worker.js} +1 -1
  6. package/dist/browser/solvers/highs.js +1414 -0
  7. package/dist/browser/washi.js +1090 -1473
  8. package/dist/browser/washi.min.js +4 -4
  9. package/dist/lib/solvers/glpk.js +34 -32
  10. package/dist/lib/{highs-node-runtime.js → solvers/highs-node-runtime.js} +1 -1
  11. package/dist/lib/solvers/highs.js +410 -0
  12. package/dist/lib/solvers/lp-writer-CLScMFbS.js +115 -0
  13. package/dist/lib/solvers/pumpkin-node-runtime.js +1 -1
  14. package/dist/lib/solvers/pumpkin-worker.js +1 -1
  15. package/dist/lib/solvers/pumpkin.js +247 -1146
  16. package/dist/lib/solvers/registry-CrYRRk9q.js +907 -0
  17. package/dist/lib/solvers/types-BGqPkxwu.js +12 -0
  18. package/dist/lib/solvers/z3.js +125 -123
  19. package/dist/lib/washi.js +2426 -1340
  20. package/dist/types/index.d.ts +1 -2
  21. package/dist/types/index.d.ts.map +1 -1
  22. package/dist/types/modeler/index.d.ts +0 -1
  23. package/dist/types/modeler/index.d.ts.map +1 -1
  24. package/dist/types/modeler/model.d.ts +6 -7
  25. package/dist/types/modeler/model.d.ts.map +1 -1
  26. package/dist/types/modeler/solvers/index.d.ts +2 -1
  27. package/dist/types/modeler/solvers/index.d.ts.map +1 -1
  28. package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
  29. package/docs/examples/diet-sensitivity.md +33 -14
  30. package/docs/examples/ecommerce-coupons.md +17 -9
  31. package/docs/examples/index.md +34 -30
  32. package/docs/examples/knapsack.md +11 -5
  33. package/docs/examples/portfolio-qp.md +21 -8
  34. package/docs/examples/production.md +10 -5
  35. package/docs/examples/project-scheduling.md +25 -12
  36. package/docs/examples/shift-scheduling.md +27 -19
  37. package/docs/examples/smt-security.md +27 -12
  38. package/docs/examples/transportation.md +23 -13
  39. package/docs/examples/traveling-salesperson.md +34 -22
  40. package/docs/examples/unsat-core.md +27 -15
  41. package/docs/examples/vehicle-routing.md +74 -28
  42. package/docs/getting-started/ai-agents.md +129 -90
  43. package/docs/getting-started/coding-agents.md +60 -41
  44. package/docs/getting-started/cross-origin.md +27 -14
  45. package/docs/getting-started/index.md +23 -16
  46. package/docs/getting-started/runtimes.md +70 -40
  47. package/docs/guide/constraint-programming.md +74 -44
  48. package/docs/guide/constraints.md +71 -39
  49. package/docs/guide/decomposition.md +72 -42
  50. package/docs/guide/expressions.md +79 -48
  51. package/docs/guide/formulation-tips.md +46 -27
  52. package/docs/guide/objectives.md +55 -31
  53. package/docs/guide/unsat-core.md +56 -53
  54. package/docs/guide/variables.md +61 -28
  55. package/docs/solvers/custom-solver.md +155 -119
  56. package/docs/solvers/glpk.md +58 -17
  57. package/docs/solvers/highs.md +115 -43
  58. package/docs/solvers/index.md +33 -26
  59. package/docs/solvers/pumpkin.md +71 -63
  60. package/docs/solvers/z3.md +63 -25
  61. package/llms-full.txt +1623 -953
  62. package/llms.txt +125 -93
  63. package/package.json +29 -22
  64. package/skills/washi/SKILL.md +43 -22
  65. package/README.ja.md +0 -248
  66. package/README.zh-CN.md +0 -248
  67. package/dist/browser/solvers/pumpkin.min.js +0 -1
  68. package/dist/lib/registry-dx7x4e5c.js +0 -1694
  69. /package/dist/browser/{highs.wasm → solvers/highs.wasm} +0 -0
  70. /package/dist/browser/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
  71. /package/dist/lib/{__vite-browser-external-oLchLuMx.js → solvers/__vite-browser-external-oLchLuMx.js} +0 -0
  72. /package/dist/lib/{highs-assets.js → solvers/highs-assets.js} +0 -0
  73. /package/dist/lib/{highs-browser-runtime.js → solvers/highs-browser-runtime.js} +0 -0
  74. /package/dist/lib/{highs-runtime.js → solvers/highs-runtime.js} +0 -0
  75. /package/dist/lib/{highs-worker-factory.js → solvers/highs-worker-factory.js} +0 -0
  76. /package/dist/lib/{highs-worker.js → solvers/highs-worker.js} +0 -0
  77. /package/dist/lib/{highs.wasm → solvers/highs.wasm} +0 -0
  78. /package/dist/lib/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
  79. /package/dist/lib/{loader-CDpPXN_F.js → solvers/loader-CDpPXN_F.js} +0 -0
  80. /package/dist/lib/solvers/{pumpkin-loader-Ow74Fa1B.js → loader-Ow74Fa1B.js} +0 -0
  81. /package/dist/lib/{rolldown-runtime-DtPi1Y-2.js → solvers/rolldown-runtime-DtPi1Y-2.js} +0 -0
@@ -1,39 +1,36 @@
1
1
  # Coding with AI Agents
2
2
 
3
- This guide shows how to configure AI coding agents (Claude Code, Cursor, Codex, Antigravity, Gemini CLI, Windsurf) to formulate, solve, verify, and package optimization and constraint models with `@ohtaman/washi`.
3
+ This guide explains how to configure AI coding agents to build, verify, and package `@ohtaman/washi` optimization and constraint models. It covers tools such as Claude Code, Cursor, Codex, Antigravity, Gemini CLI, and Windsurf.
4
4
 
5
5
  ---
6
6
 
7
7
  ## 1. Setup
8
8
 
9
- Setting up WaSHI with a coding agent has two separate parts: installing the runtime library in your project, and giving your agent WaSHI's current API and verification workflow.
9
+ Setting up WaSHI with a coding agent has two parts. First, install the runtime library in your project. Second, connect your agent to WaSHI's API reference and verification workflow.
10
10
 
11
11
  ### Install the Runtime Library
12
12
 
13
- Bundled **HiGHS** (LP / MIP / Convex QP) and **Pumpkin** (`@ohtaman/washi/solvers/pumpkin`, CP / LCG) require zero external dependencies:
13
+ Installing `@ohtaman/washi` bundles **HiGHS** for linear, mixed-integer, and convex quadratic programming (`LP`/`MIP`/`QP`), along with **Pumpkin** for Constraint Programming (`CP`), with zero external dependencies:
14
14
 
15
15
  ```bash
16
16
  npm install @ohtaman/washi
17
17
 
18
- # Optional peer dependencies if your model requires SMT continuous logic or GLPK:
18
+ # Optional dependencies for Z3 (SMT / continuous logic) or GLPK:
19
19
  # npm install z3-solver
20
20
  # npm install glpk.js
21
21
  ```
22
22
 
23
23
  ### Connect Your Coding Agent
24
24
 
25
- Choose the setup method that matches your tool:
25
+ Choose the integration method that matches your tool:
26
26
 
27
- - **Agent Skill (Recommended — Claude Code, Cursor, Codex, Antigravity, Gemini CLI)**:
28
- ```bash
29
- npx skills add ohtaman/washi
30
- ```
31
- This installs `skills/washi/SKILL.md` (also included at `node_modules/@ohtaman/washi/skills/washi/SKILL.md`), which guides the agent through solver selection across HiGHS / Pumpkin / Z3 / GLPK, algebraic `expr` modeling, `m.toLpString()` formulation checks, `m.verify()` solution verification, and `m.check()` conflict diagnosis.
32
- - **IDE Documentation Indexing (`@Docs` in Cursor, Windsurf, etc.)**:
33
- - Documentation index: `https://washi.ohtaman.dev/llms.txt`
34
- - Complete single-file API & example reference: `https://washi.ohtaman.dev/llms-full.txt`
35
- - **Context7 MCP**:
36
- - Reference library ID: `/ohtaman/washi`
27
+ | Method | Best For | Setup |
28
+ | --- | --- | --- |
29
+ | **Agent Skill** *(Recommended)* | Claude Code, Cursor, Codex, Antigravity, Gemini CLI | Run `npx skills add ohtaman/washi` |
30
+ | **IDE `@Docs` Index** | Cursor, Windsurf | Add `https://washi.ohtaman.dev/llms.txt` or `https://washi.ohtaman.dev/llms-full.txt` |
31
+ | **Context7 MCP** | MCP-enabled agents | Reference library ID `/ohtaman/washi` |
32
+
33
+ Installing the Agent Skill places `SKILL.md` into your agent's skills directory. It teaches your agent solver selection, `expr` modeling, and debugging with `m.toLpString()`, `m.verify()`, and `m.check()`.
37
34
 
38
35
  ---
39
36
 
@@ -53,17 +50,24 @@ Requirements:
53
50
 
54
51
  When you run this prompt, the agent executes three steps locally:
55
52
 
56
- 1. **Formulates the model**: Creates bounded binary variables (`m.binary`), linear expressions (`` expr`...` ``, `sum`), named constraints (`m.constraint(..., "name")`), and an objective (`m.objective(minimize(...))`).
57
- 2. **Solves in Node.js via WebAssembly**: Executes the script (for example with `npx tsx schedule.ts`) using the bundled HiGHS WebAssembly binary—no Python runtime or native solver installation is needed.
58
- 3. **Independently verifies the solution**: Checks `m.hasPrimalSolution` and calls `m.verify()` so variable bounds, integrality, and constraint residuals are verified before displaying the output.
53
+ 1. **Formulates the model**: Declares 0-1 binary variables with `m.binary()`, linear expressions with `` expr`...` `` and `sum()`, named constraints, and a minimization objective.
54
+ 2. **Solves in Node.js via WebAssembly**: Runs the script (for example via `npx tsx schedule.ts`) using the bundled HiGHS WebAssembly binary. No Python runtime or native solver installation is needed.
55
+ 3. **Independently verifies the solution**: Checks `m.hasPrimalSolution` and calls `m.verify()`. This confirms variable bounds, integrality, and constraint satisfaction before printing results.
59
56
 
60
57
  ---
61
58
 
62
59
  ## 3. Problem Classes & Ready-to-Use Prompts
63
60
 
64
- Each prompt below targets a specific mathematical problem class supported by WaSHI. Adjust the input schema and rules to match your data.
61
+ Match your task to the problem class and solver below, then customize the corresponding prompt template:
62
+
63
+ | Problem Class | Recommended Solver | Key Primitives |
64
+ | --- | --- | --- |
65
+ | Assignment, timetabling, 0-1 selection (`MILP` / `0-1 MIP`) | Bundled **HiGHS** | `m.binary()`, `sum()`, `dot()` |
66
+ | Task scheduling with shared resources (`CP`) | Bundled **Pumpkin** | `disjoint()`, `cumulative()`, `distinct()` |
67
+ | Target balancing & variance minimization (Convex `QP`) | Bundled **HiGHS** | `m.continuous()`, `` expr`...^2` `` |
68
+ | Rule conflict diagnosis (`unsatCore`) | Bundled **Pumpkin** or optional **Z3** | `m.check()` |
65
69
 
66
- ### Event Timetable & Reviewer Assignment (MILP — Bundled HiGHS)
70
+ ### Reviewer Assignment & Load Balancing (MILP — Bundled HiGHS)
67
71
 
68
72
  ```text
69
73
  Using @ohtaman/washi (bundled HiGHS), assign 24 pull-request / RFC submissions to 6 engineers so each submission gets 2 distinct reviewers.
@@ -85,10 +89,10 @@ Rules:
85
89
  - Give every constraint a clear name and confirm m.verify().valid === true.
86
90
  ```
87
91
 
88
- ### Task Scheduling with Precedence & Shared Resources (CP/LCG — Bundled Pumpkin)
92
+ ### Task Scheduling with Precedence & Shared Resources (CP — Bundled Pumpkin)
89
93
 
90
94
  ```text
91
- Using @ohtaman/washi and its bundled CP solver (@ohtaman/washi/solvers/pumpkin), schedule 10 release-pipeline tasks with integer start times (lb: 0, ub: 120) and fixed durations to minimize total makespan.
95
+ Using @ohtaman/washi and its bundled CP solver ({ solver: "pumpkin" }), schedule 10 release-pipeline tasks with integer start times (lb: 0, ub: 120) and fixed durations to minimize total makespan.
92
96
  Rules:
93
97
  - Enforce finish-to-start precedence edges between dependent tasks.
94
98
  - Tasks using the staging benchmark cluster cannot overlap (use disjoint).
@@ -98,10 +102,10 @@ Rules:
98
102
 
99
103
  ### Target-Balancing & Variance Minimization (Convex QP — Bundled HiGHS)
100
104
 
101
- Built-in HiGHS solves convex quadratic objectives over continuous variables (`m.continuous`):
105
+ Built-in HiGHS solves convex quadratic objectives over continuous variables (`m.continuous()`):
102
106
 
103
107
  ```text
104
- Using @ohtaman/washi (bundled HiGHS), allocate a continuous total budget of 1.0 across 5 regional compute pools using m.continuous variables (lb: 0.05, ub: 0.50).
108
+ Using @ohtaman/washi (bundled HiGHS), allocate a continuous total budget of 1.0 across 5 regional compute pools using m.continuous() variables (lb: 0.05, ub: 0.50).
105
109
  Target weights are [0.30, 0.25, 0.20, 0.15, 0.10], plus a policy cap that regions 0 and 1 combined cannot exceed 0.48.
106
110
  Minimize the sum of squared deviations expr`sum((${w} - ${target})^2)` subject to sum(w) == 1.0 and the regional cap, then verify m.verify().valid === true.
107
111
  ```
@@ -109,50 +113,65 @@ Minimize the sum of squared deviations expr`sum((${w} - ${target})^2)` subject t
109
113
  ### Rule & Configuration Conflict Diagnosis (Infeasibility / Unsat Core)
110
114
 
111
115
  ```text
112
- Using @ohtaman/washi and @ohtaman/washi/solvers/pumpkin, check whether a set of deployment and feature-flag rules over bounded integer and boolean variables is satisfiable via await m.check({ solver: "pumpkin" }).
116
+ Using @ohtaman/washi, check whether a set of deployment and feature-flag rules over bounded integer and boolean variables is satisfiable via await m.check({ solver: "pumpkin" }).
113
117
  Include a sample test case with contradictory named rules, print res.status and res.unsatCore (or res.conflicts), and show which named rules conflict with each other.
114
118
  ```
115
119
 
116
120
  > [!NOTE]
117
- > `await m.check()` works out of the box with default **HiGHS** (reporting conflicting constraint names in `res.conflicts` via elastic slack relaxation). Import bundled `@ohtaman/washi/solvers/pumpkin` when you want `res.unsatCore` on bounded integer/boolean models without `COOP`/`COEP` headers, or install `z3-solver` (`@ohtaman/washi/solvers/z3`) when continuous/fractional constraints require exact SMT `unsatCore` extraction.
121
+ > `await m.check()` works with default **HiGHS**, which reports conflicting constraint names in `res.conflicts`.
122
+ >
123
+ > To extract an exact unsatisfiable core (`res.unsatCore`), choose the solver by variable domain:
124
+ > - **Bounded integers and booleans**: Pass `{ solver: "pumpkin" }` (bundled with `@ohtaman/washi`; no extra import or browser `COOP`/`COEP` headers required).
125
+ > - **Continuous or fractional arithmetic**: Install `z3-solver` and import `@ohtaman/washi/solvers/z3`.
118
126
 
119
127
  ---
120
128
 
121
129
  ## 4. Packaging & Deployment Prompts (Browser, Desktop & Mobile)
122
130
 
123
- Once a CLI script produces verified results, you can ask your coding agent to package the same model into a local browser tool or an offline desktop/mobile application.
131
+ Once a CLI script produces verified results, ask your agent to package the same model as a local HTML tool or an offline app.
124
132
 
125
- ### Zero-Server Single-File `.html` Tool (`file://` Double-Click)
133
+ ### Zero-Server Single-File `.html` Tool (Double-Click via `file://`)
126
134
 
127
135
  ```text
128
- Package this @ohtaman/washi optimization model into a single standalone .html file with inline HTML, CSS, and JavaScript so team members can open it directly via file:// by double-clicking.
136
+ Package this @ohtaman/washi optimization model into a standalone .html file with inline HTML, CSS, and JavaScript so team members can open it directly by double-clicking (file://).
129
137
  - Load WaSHI from https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js (global window.Washi).
130
138
  - Provide a textarea / CSV file input, a "Solve" button, a table displaying the optimal assignment, and a conflict report using await m.check() if status is "Infeasible".
131
139
  - Verify every feasible solve with m.verify().
132
140
  ```
133
141
 
134
- - **Runtime notes for `file://`**:
135
- - Opening the `.html` file directly via `file://` (no local HTTP server) works out of the box when loading `washi.min.js` (and `solvers/pumpkin.min.js` when using Pumpkin) from an HTTPS CDN, because WaSHI detects opaque origins (`window.origin === "null"`) and automatically runs HiGHS and Pumpkin on the main thread.
136
- - Self-hosted local `.wasm` files (which browsers block on `file://` under `fetch()` CORS rules) and **Z3** (`SharedArrayBuffer` requiring `COOP`/`COEP` headers) require serving over `http://` or `https://`.
142
+ **`file://` runtime notes**: Loading `washi.min.js` from an HTTPS CDN runs directly on `file://`—under `window.origin === "null"`, WaSHI automatically falls back to main-thread execution. Self-hosted `.wasm` files require `http://` or `https://`, and browser Z3 requires Cross-Origin Isolation; see [Runtime Environments](./runtimes.md) and [Cross-Origin Isolation](./cross-origin.md).
137
143
 
138
144
  ### Offline Desktop & Mobile Apps (Vite + Tauri / Capacitor / PWA)
139
145
 
140
146
  ```text
141
- Wrap this Vite + TypeScript @ohtaman/washi application as an offline desktop/mobile app using bundled HiGHS (or @ohtaman/washi/solvers/pumpkin) with zero backend server and zero native C++ solver compilation.
147
+ Wrap this Vite + TypeScript @ohtaman/washi application as an offline desktop/mobile app using bundled HiGHS (or { solver: "pumpkin" }) with zero backend server and zero native solver compilation.
142
148
  - Keep all solver execution client-side via @ohtaman/washi.
143
149
  - Configure Content Security Policy to allow WebAssembly compilation ('wasm-unsafe-eval' in script-src) and Web Workers (worker-src 'self' blob:).
144
150
  ```
145
151
 
146
- - **Runtime notes for WebViews**: Standard Vite builds bundle `highs.wasm` and `pumpkin.wasm` as static assets that run offline inside Tauri (`tauri://localhost` / `http://tauri.localhost`), Capacitor WebViews, and Service Worker PWAs. See [Runtime Environments](./runtimes.md) for `tauri.conf.json` CSP configuration (`'wasm-unsafe-eval'`).
152
+ **WebView notes**: Standard Vite builds bundle your solver `.wasm` assets for offline execution in Tauri, Capacitor, and PWAs. Allow `'wasm-unsafe-eval'` in `script-src` (plus `worker-src 'self' blob:` for Web Workers); see [Runtime Environments](./runtimes.md) for a `tauri.conf.json` example.
147
153
 
148
154
  ---
149
155
 
150
156
  ## 5. Iterating & Debugging with Your Agent
151
157
 
152
- - **Require named constraints and `m.verify()`**: Always ask your agent to pass a descriptive name as the second argument to `m.constraint(c, "rule_name")` (and `name` in `m.indicator(...)`) and assert `m.verify().valid === true`. Unnamed constraints (`c_0`, `c_1`) make infeasibility reports hard to interpret.
153
- - **Diagnose `"Infeasible"` results with `m.check()`**: When adding new business rules causes `m.solve()` to return `"Infeasible"`, use a follow-up prompt like:
154
- ```text
155
- Adding the new constraints made m.solve() return "Infeasible".
156
- Run await m.check() (or await m.check({ solver: "pumpkin" }) for bounded integer/boolean models), print res.conflicts / res.unsatCore, explain in plain terms which named rules and variable bounds contradict each other, and propose which non-rigid constraints should be converted into soft constraints with non-negative slack penalty variables.
157
- ```
158
- - **Inspect `m.toLpString()` and variable bounds before production**: Ask your agent to dump `m.toLpString()` on a small fixture and review variable `lb` / `ub` bounds (especially on variables referenced inside `m.indicator()`, which require finite bounds when `M` is omitted), objective sense (`Maximize` vs `Minimize`), and constraint signs (`<=` vs `>=`).
158
+ ### Name Every Constraint and Verify Every Solve
159
+
160
+ Ask your agent to pass a descriptive name to `m.constraint(c, "rule_name")` and `m.indicator(b, c, { name: "rule_name" })`, then assert `m.verify().valid === true`. Unnamed constraints default to auto-generated IDs (`c_1`, `c_2` for linear constraints; `lc_1`, `lc_2` for logical constraints), which makes conflict reports harder to read.
161
+
162
+ ### Diagnose `"Infeasible"` Models with `m.check()`
163
+
164
+ When adding a new rule makes `m.solve()` return `"Infeasible"`, send a follow-up prompt like this:
165
+
166
+ ```text
167
+ Adding the new constraints made m.solve() return "Infeasible".
168
+ Run await m.check() (or await m.check({ solver: "pumpkin" }) for bounded integer/boolean models), print res.conflicts / res.unsatCore, explain in plain terms which named rules and variable bounds contradict each other, and propose which non-rigid constraints should be converted into soft constraints with non-negative slack penalty variables.
169
+ ```
170
+
171
+ ### Inspect `m.toLpString()` and Variable Bounds Before Production
172
+
173
+ Have your agent print `m.toLpString()` on a small test fixture before shipping. Confirm three items:
174
+
175
+ - **Finite bounds (`lb` / `ub`)**: Variables inside `m.indicator()` require finite bounds whenever `M` is omitted.
176
+ - **Objective sense**: Check that `Maximize` vs. `Minimize` matches your business goal.
177
+ - **Constraint operators**: Verify that every `<=`, `>=`, and `=` operator and direction matches your intent.
@@ -1,31 +1,39 @@
1
1
  # Cross-Origin Isolation (Z3 & Browsers)
2
2
 
3
- When running the **Z3** solver inside a web browser, Cross-Origin Isolation HTTP headers are required so the browser enables `SharedArrayBuffer`.
3
+ Running the Z3 solver in a browser requires two browser security conditions: a **Secure Context** and **Cross-Origin Isolation**. Together, they enable `SharedArrayBuffer` for Z3's multithreaded WebAssembly build.
4
4
 
5
5
  > [!TIP]
6
- > **Not needed for HiGHS, Pumpkin, GLPK, or Node.js**: Bundled **HiGHS** and **Pumpkin** (`@ohtaman/washi/solvers/pumpkin`), as well as the **GLPK** plugin, run in standard browser contexts without Cross-Origin Isolation or `SharedArrayBuffer` (including Pumpkin CP solving, propositional logic, and `unsatCore` conflict diagnosis). Running Z3 in **Node.js** also requires no HTTP headers. You only need this page when using `@ohtaman/washi/solvers/z3` in the browser.
6
+ > **Not needed for HiGHS, Pumpkin, GLPK, or Node.js**: Bundled HiGHS and Pumpkin, as well as the GLPK plugin, never use `SharedArrayBuffer` and work in standard browser contexts. Running Z3 in Node.js also requires no HTTP headers. You only need this guide when using Z3 in a browser.
7
7
 
8
8
  ---
9
9
 
10
- ## Why is Cross-Origin Isolation Required?
10
+ ## Why Are These Preconditions Required?
11
11
 
12
- Z3's WebAssembly build uses multithreading (pthreads) backed by `SharedArrayBuffer` and Web Workers. Modern browsers (Chrome, Firefox, Safari, Edge) disable `SharedArrayBuffer` by default to mitigate Spectre-style side-channel attacks unless the top-level document opts into **Cross-Origin Isolation** (`window.crossOriginIsolated === true`).
12
+ Z3's WebAssembly binary uses POSIX threads (`pthreads`) backed by `SharedArrayBuffer` and Web Workers. To mitigate Spectre-style side-channel attacks, modern browsers disable `SharedArrayBuffer` by default.
13
+
14
+ Browsers re-enable `SharedArrayBuffer` only when both conditions hold on the top-level document:
15
+
16
+ 1. **Secure Context**: The page must load over `https://` or `http://localhost` (including `127.0.0.1` and `[::1]`) so `window.isSecureContext === true`. Plain `http://` LAN IP addresses do not qualify.
17
+ 2. **Cross-Origin Isolation**: The document must opt into isolation headers so `window.crossOriginIsolated === true`.
13
18
 
14
19
  ---
15
20
 
16
21
  ## Required HTTP Response Headers
17
22
 
18
- Serve the top-level HTML document with:
23
+ Serve the top-level HTML document with these two response headers:
24
+
25
+ - **Cross-Origin-Opener-Policy (`COOP`)**: `same-origin`
26
+ - **Cross-Origin-Embedder-Policy (`COEP`)**: `require-corp`
19
27
 
20
28
  ```http
21
29
  Cross-Origin-Opener-Policy: same-origin
22
30
  Cross-Origin-Embedder-Policy: require-corp
23
31
  ```
24
32
 
25
- If your page loads cross-origin subresources (such as scripts, images, or WASM files from another domain), those responses must also include `Cross-Origin-Resource-Policy: cross-origin` (or CORS headers).
33
+ If your page loads scripts, images, or `.wasm` files from another origin, those responses must include `Cross-Origin-Resource-Policy: cross-origin` (`CORP`) or valid CORS headers (`Access-Control-Allow-Origin`), depending on the request mode.
26
34
 
27
35
  > [!NOTE]
28
- > Chromium and Firefox also support `Cross-Origin-Embedder-Policy: credentialless`, which relaxes subresource CORP requirements, **but Safari (WebKit) does not support `credentialless`**. Use `require-corp` if you support Safari / iOS.
36
+ > Chromium and Firefox also accept `Cross-Origin-Embedder-Policy: credentialless`, which relaxes `CORP` requirements on cross-origin subresources. **Safari (WebKit) does not support `credentialless`**, so use `require-corp` if you support Safari or iOS.
29
37
 
30
38
  ---
31
39
 
@@ -33,7 +41,7 @@ If your page loads cross-origin subresources (such as scripts, images, or WASM f
33
41
 
34
42
  ### 1. Vite (`vite.config.ts`)
35
43
 
36
- Configure both the local dev server (`vite`) and production preview server (`vite preview`):
44
+ Configure both the `vite` dev server and `vite preview` server:
37
45
 
38
46
  ```typescript
39
47
  import { defineConfig } from "vite";
@@ -56,7 +64,7 @@ export default defineConfig({
56
64
 
57
65
  ### 2. Cloudflare Pages / Netlify (`public/_headers`)
58
66
 
59
- Place a `_headers` file in `public/` so it is copied to the root of your build output:
67
+ Place a `_headers` file in `public/` so your build copies it to the site root:
60
68
 
61
69
  ```text
62
70
  /*
@@ -85,7 +93,7 @@ const nextConfig = {
85
93
  module.exports = nextConfig;
86
94
  ```
87
95
 
88
- ### 4. Custom Node.js / Express Server
96
+ ### 4. Express (Custom Node.js Server)
89
97
 
90
98
  ```javascript
91
99
  app.use((req, res, next) => {
@@ -97,19 +105,24 @@ app.use((req, res, next) => {
97
105
 
98
106
  ### 5. Static Hosting without Header Control (e.g., GitHub Pages)
99
107
 
100
- Platforms like GitHub Pages do not allow customizing HTTP response headers directly. You can use **`coi-serviceworker`** to inject the isolation headers via a client-side Service Worker:
108
+ Platforms like GitHub Pages do not let you customize HTTP response headers. You can use **`coi-serviceworker`** to inject `COOP` and `COEP` headers from a client-side Service Worker. Note that Service Workers themselves also require a Secure Context (`https://` or `http://localhost`).
101
109
 
102
- 1. Obtain `coi-serviceworker.js` from [`coi-serviceworker`](https://github.com/gzuidhof/coi-serviceworker) (GitHub / npm) or WaSHI's reference [`public/coi-serviceworker.js`](https://github.com/ohtaman/washi/blob/main/public/coi-serviceworker.js), and place it at your site root.
110
+ 1. Copy `coi-serviceworker.js` from [`coi-serviceworker`](https://github.com/gzuidhof/coi-serviceworker) or WaSHI's reference [`public/coi-serviceworker.js`](https://github.com/ohtaman/washi/blob/main/public/coi-serviceworker.js) to your site root.
103
111
  2. Load it in your HTML `<head>`:
104
112
 
105
113
  ```html
106
114
  <script src="/coi-serviceworker.js"></script>
107
115
  ```
108
116
 
109
- On the first visit, the Service Worker registers and reloads the page once to establish `window.crossOriginIsolated === true`.
117
+ On the first visit, the Service Worker registers and reloads the page once so `window.crossOriginIsolated` becomes `true`.
110
118
 
111
119
  ---
112
120
 
113
121
  ## Runtime Check in WaSHI
114
122
 
115
- WaSHI's Z3 adapter checks `crossOriginIsolated` before initializing Z3 in the browser. If Cross-Origin Isolation is missing, `solve()` / `check()` immediately rejects with an actionable error explaining that COOP/COEP headers or a Service Worker are required, rather than hanging silently.
123
+ Before initializing Z3 in a browser, WaSHI validates both preconditions in order:
124
+
125
+ | Check | Failure Condition | Result |
126
+ | --- | --- | --- |
127
+ | **Secure Context** | `!window.isSecureContext` and hostname is not `localhost`, `127.0.0.1`, or `[::1]` | `solve()` / `check()` immediately rejects with an HTTPS or `localhost` requirement error. |
128
+ | **Cross-Origin Isolation** | `SharedArrayBuffer` is missing or `window.crossOriginIsolated !== true` | `solve()` / `check()` immediately rejects listing the required `COOP` and `COEP` headers instead of hanging. |
@@ -1,12 +1,19 @@
1
1
  # Introduction & Installation
2
2
 
3
- **WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings the algebraic modeling style of Python's **PuLP** to the TypeScript and JavaScript ecosystem. Write expressions naturally with tagged templates (`expr`) and solve mathematical optimization and constraint programming problems directly in **Node.js and the browser** using WebAssembly solvers (**HiGHS**, **Pumpkin**, **Z3**, and **GLPK**).
3
+ **WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings Python PuLP-style algebraic modeling to TypeScript and JavaScript. You can write linear, quadratic, and logical expressions with tagged templates (`expr`) and model mathematical optimization and constraint programming problems directly in **Node.js (18+)** and modern browsers.
4
4
 
5
5
  ---
6
6
 
7
7
  ## 📦 Installation
8
8
 
9
- Both the default **HiGHS** solver (LP / MIP / Convex QP) and the **Pumpkin** CP/LCG solver (`@ohtaman/washi/solvers/pumpkin`) are bundled with zero external dependencies and work out of the box:
9
+ Installing `@ohtaman/washi` bundles two zero-dependency solvers out of the box, with two additional solvers available as optional dependencies:
10
+
11
+ | Solver | Install | Problem Classes & Capabilities |
12
+ | --- | --- | --- |
13
+ | **HiGHS** *(default)* | Bundled in `@ohtaman/washi` (no extra import; subpath `@ohtaman/washi/solvers/highs`) | Linear, mixed-integer, and convex quadratic programming — `LP`, `MIP`, and `QP`. |
14
+ | **Pumpkin** | Bundled in `@ohtaman/washi` (`{ solver: "pumpkin" }`, no extra import; subpath `@ohtaman/washi/solvers/pumpkin`) | Constraint Programming (`CP`) and exact `unsatCore` conflict diagnosis on bounded integers and booleans. |
15
+ | **Z3** | Optional (`z3-solver`) | Satisfiability Modulo Theories (`SMT`), continuous logic, and exact `unsatCore` diagnosis (including continuous variables). |
16
+ | **GLPK** | Optional (`glpk.js`) | Alternative `LP` and `MIP` solver under the GPL-3.0 license. |
10
17
 
11
18
  ::: code-group
12
19
 
@@ -28,20 +35,20 @@ bun add @ohtaman/washi
28
35
 
29
36
  :::
30
37
 
31
- Install optional peer dependencies when you need **Z3** (SMT logic and Unsat Core conflict diagnosis) or **GLPK**:
38
+ Install optional dependencies when you need **Z3** or **GLPK**:
32
39
 
33
40
  ```bash
34
- npm install z3-solver # For SMT logic and Unsat Core conflict diagnosis
35
- npm install glpk.js # For GLPK solver (GPL-3.0)
41
+ npm install z3-solver # Optional: SMT logic and unsatCore diagnosis for models with continuous variables
42
+ npm install glpk.js # Optional: GLPK solver (GPL-3.0)
36
43
  ```
37
44
 
38
- Using an AI coding agent? See [Coding with AI Agents](./coding-agents.md) for `npx skills add ohtaman/washi`, `llms.txt`, and ready-to-use prompt templates.
45
+ In browsers, Z3 requires a Secure Context and Cross-Origin Isolation headers — `Cross-Origin-Opener-Policy` and `Cross-Origin-Embedder-Policy`, abbreviated `COOP`/`COEP`. See [Cross-Origin Isolation](./cross-origin.md) for server setup.
39
46
 
40
47
  ---
41
48
 
42
49
  ## 🚀 Quick Start
43
50
 
44
- Here is a complete production-planning model illustrating the three steps of a typical WaSHI workflow:
51
+ The production-planning model below maximizes profit from desks and chairs under wood and labor limits:
45
52
 
46
53
  ```typescript
47
54
  import { Model, expr, maximize } from "@ohtaman/washi";
@@ -57,7 +64,7 @@ m.objective(maximize(expr`30 * ${desks} + 50 * ${chairs}`));
57
64
  m.constraint(expr`${desks} + 2 * ${chairs} <= 40`, "wood_capacity");
58
65
  m.constraint(expr`2 * ${desks} + ${chairs} <= 50`, "labor_capacity");
59
66
 
60
- // 3. Solve (built-in HiGHS WebAssembly) and verify the solution
67
+ // 3. Solve (bundled HiGHS WebAssembly) and verify the solution
61
68
  const status = await m.solve();
62
69
  if (m.hasPrimalSolution) {
63
70
  const report = m.verify();
@@ -66,9 +73,9 @@ if (m.hasPrimalSolution) {
66
73
  }
67
74
  ```
68
75
 
69
- 1. **Define decision variables (`lb`, `ub`)**: Create variables with `m.continuous()`, `m.integer()`, or `m.binary()`, providing finite `lb` and `ub` bounds when known.
70
- 2. **Describe the objective and constraints (`expr`)**: Formulate equations naturally with `` expr`...` ``, and pass constraint names to make infeasibility debugging straightforward.
71
- 3. **Solve and verify (`solve`, `verify`)**: `await m.solve()` runs the bundled HiGHS WebAssembly solver. Check `m.hasPrimalSolution` before reading `.value`, and call `m.verify()` to independently verify that bounds, integrality, and constraints hold.
76
+ - **Finite bounds**: Supply finite `lb` and `ub` bounds on `m.continuous()` and `m.integer()` variables whenever known; they tighten MIP formulations and are required by `m.indicator()` when `M` is omitted.
77
+ - **Explicit registration & naming**: Constructing an expression with `` expr`...` `` does not attach it to the model until you call `m.objective()` or `m.constraint()`. Passing descriptive constraint names makes `m.check()` conflict reports readable.
78
+ - **Safe reading & verification**: Check `m.hasPrimalSolution` before reading `.value`, then call `m.verify()` to independently confirm bounds, integrality, and constraints.
72
79
 
73
80
  ---
74
81
 
@@ -76,11 +83,11 @@ if (m.hasPrimalSolution) {
76
83
 
77
84
  ### Choose Your Workflow
78
85
 
79
- - **Build with an AI Coding Agent**: [Coding with AI Agents](./coding-agents.md) — Setup with `npx skills add`, `llms.txt` / Context7, ready-to-use prompt examples across problem types and deployment targets, and conflict debugging
80
- - **Write Models Directly in TypeScript**: [Modeling Guide](../guide/variables.md) — Array/dictionary variables, aggregations (`sum`, `dot`), logical constraints, and conflict diagnosis
86
+ - **Build with an AI Coding Agent**: [Coding with AI Agents](./coding-agents.md) — Skill setup via `npx skills add ohtaman/washi`, `llms.txt` / Context7, and ready-to-use prompt templates.
87
+ - **Write Models in TypeScript**: [Modeling Guide](../guide/variables.md) — Variable containers, `sum` and `dot` aggregations, logical constraints, and conflict diagnosis.
81
88
 
82
89
  ### Reference & Examples
83
90
 
84
- - **[Examples & API Finder](../examples/)**: 12 runnable optimization and SMT recipes—from shift scheduling and portfolio QP to vehicle routing
85
- - **[Solvers Overview](../solvers/)**: Compare bundled HiGHS and Pumpkin with optional Z3 and GLPK adapters
86
- - **[Runtime Environments](./runtimes.md)**: Setup details for Node.js, Vite / Next.js bundlers, CDNs, standalone HTML, and desktop/mobile WebViews
91
+ - **[Examples & API Finder](../examples/)**: 12 runnable optimization, CP, and SMT recipes—from shift scheduling to portfolio QP.
92
+ - **[Solvers Overview](../solvers/)**: Side-by-side comparison of bundled HiGHS and Pumpkin against optional Z3 and GLPK.
93
+ - **[Runtime Environments](./runtimes.md)**: Setup details for Node.js, Vite/Next.js, CDNs, standalone HTML, and desktop/mobile WebViews.