@ohtaman/washi 0.6.0 → 0.8.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 (147) hide show
  1. package/README.ja.md +139 -418
  2. package/README.md +139 -418
  3. package/README.zh-CN.md +139 -418
  4. package/THIRD_PARTY_LICENSES.md +39 -4
  5. package/dist/browser/__vite-browser-external-rTVKos2U.js +7 -0
  6. package/dist/browser/browser-runtime-AG5QFtKf.js +2021 -0
  7. package/dist/browser/highs-worker.js +26 -11
  8. package/dist/browser/highs.wasm +0 -0
  9. package/dist/browser/{loader-DewlSho8.js → loader-i3FnqMes.js} +183 -149
  10. package/dist/browser/solvers/glpk.js +289 -238
  11. package/dist/browser/solvers/glpk.min.js +1 -1
  12. package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +9 -0
  13. package/dist/browser/solvers/pumpkin-loader-CvdaKxf4.js +320 -0
  14. package/dist/browser/solvers/pumpkin-worker.js +45 -0
  15. package/dist/browser/solvers/pumpkin.js +1777 -0
  16. package/dist/browser/solvers/pumpkin.min.js +1 -0
  17. package/dist/browser/solvers/pumpkin.wasm +0 -0
  18. package/dist/browser/solvers/pumpkin.wasm.LICENSE +21 -0
  19. package/dist/browser/solvers/z3.js +1600 -1335
  20. package/dist/browser/solvers/z3.min.js +2 -2
  21. package/dist/browser/washi.js +3828 -1315
  22. package/dist/browser/washi.min.js +5 -3
  23. package/dist/lib/__vite-browser-external-oLchLuMx.js +7 -0
  24. package/dist/lib/highs-browser-runtime.js +1846 -1618
  25. package/dist/lib/highs-runtime.js +16 -2
  26. package/dist/lib/highs-worker.js +26 -11
  27. package/dist/lib/highs.wasm +0 -0
  28. package/dist/lib/{loader-BZUQNvh4.js → loader-CDpPXN_F.js} +138 -116
  29. package/dist/lib/registry-dx7x4e5c.js +1694 -0
  30. package/dist/lib/rolldown-runtime-DtPi1Y-2.js +13 -0
  31. package/dist/lib/solvers/glpk.js +161 -121
  32. package/dist/lib/solvers/pumpkin-assets.js +1 -0
  33. package/dist/lib/solvers/pumpkin-loader-Ow74Fa1B.js +311 -0
  34. package/dist/lib/solvers/pumpkin-node-runtime.js +15 -0
  35. package/dist/lib/solvers/pumpkin-worker-factory.js +1 -0
  36. package/dist/lib/solvers/pumpkin-worker.js +45 -0
  37. package/dist/lib/solvers/pumpkin.js +1767 -0
  38. package/dist/lib/solvers/pumpkin.wasm +0 -0
  39. package/dist/lib/solvers/pumpkin.wasm.LICENSE +21 -0
  40. package/dist/lib/solvers/z3.js +486 -306
  41. package/dist/lib/washi.js +3054 -1202
  42. package/dist/types/decomposition/benders.d.ts.map +1 -1
  43. package/dist/types/index.d.ts +3 -3
  44. package/dist/types/index.d.ts.map +1 -1
  45. package/dist/types/modeler/boolean-expr.d.ts +137 -29
  46. package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
  47. package/dist/types/modeler/constraint.d.ts +40 -4
  48. package/dist/types/modeler/constraint.d.ts.map +1 -1
  49. package/dist/types/modeler/expression.d.ts +176 -28
  50. package/dist/types/modeler/expression.d.ts.map +1 -1
  51. package/dist/types/modeler/index.d.ts +5 -6
  52. package/dist/types/modeler/index.d.ts.map +1 -1
  53. package/dist/types/modeler/linearizer.d.ts +11 -2
  54. package/dist/types/modeler/linearizer.d.ts.map +1 -1
  55. package/dist/types/modeler/lp-writer.d.ts.map +1 -1
  56. package/dist/types/modeler/model.d.ts +97 -130
  57. package/dist/types/modeler/model.d.ts.map +1 -1
  58. package/dist/types/modeler/parser.d.ts +25 -5
  59. package/dist/types/modeler/parser.d.ts.map +1 -1
  60. package/dist/types/modeler/quad-expr.d.ts +8 -2
  61. package/dist/types/modeler/quad-expr.d.ts.map +1 -1
  62. package/dist/types/modeler/solution-validator.d.ts +12 -12
  63. package/dist/types/modeler/solution-validator.d.ts.map +1 -1
  64. package/dist/types/modeler/solvers/glpk/loader.d.ts +4 -0
  65. package/dist/types/modeler/solvers/glpk/loader.d.ts.map +1 -1
  66. package/dist/types/modeler/solvers/glpk/solver.d.ts +2 -2
  67. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  68. package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -1
  69. package/dist/types/modeler/solvers/highs/loader.d.ts +8 -6
  70. package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
  71. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  72. package/dist/types/modeler/solvers/highs/worker-client.d.ts +16 -0
  73. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  74. package/dist/types/modeler/solvers/mock.d.ts +2 -3
  75. package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
  76. package/dist/types/modeler/solvers/pumpkin/assets.d.ts +2 -0
  77. package/dist/types/modeler/solvers/pumpkin/assets.d.ts.map +1 -0
  78. package/dist/types/modeler/solvers/pumpkin/index.d.ts +6 -0
  79. package/dist/types/modeler/solvers/pumpkin/index.d.ts.map +1 -0
  80. package/dist/types/modeler/solvers/pumpkin/loader.d.ts +40 -0
  81. package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -0
  82. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts +3 -0
  83. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts.map +1 -0
  84. package/dist/types/modeler/solvers/pumpkin/solver.d.ts +23 -0
  85. package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -0
  86. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +74 -0
  87. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -0
  88. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts +3 -0
  89. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts.map +1 -0
  90. package/dist/types/modeler/solvers/pumpkin/worker.d.ts +7 -0
  91. package/dist/types/modeler/solvers/pumpkin/worker.d.ts.map +1 -0
  92. package/dist/types/modeler/solvers/pumpkin.d.ts +2 -0
  93. package/dist/types/modeler/solvers/pumpkin.d.ts.map +1 -0
  94. package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
  95. package/dist/types/modeler/solvers/types.d.ts +9 -9
  96. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  97. package/dist/types/modeler/solvers/z3/loader.d.ts +4 -0
  98. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  99. package/dist/types/modeler/solvers/z3/solver.d.ts +2 -15
  100. package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
  101. package/dist/types/modeler/types.d.ts +12 -15
  102. package/dist/types/modeler/types.d.ts.map +1 -1
  103. package/dist/types/modeler/validation.d.ts +26 -2
  104. package/dist/types/modeler/validation.d.ts.map +1 -1
  105. package/dist/types/modeler/variable.d.ts +9 -5
  106. package/dist/types/modeler/variable.d.ts.map +1 -1
  107. package/docs/examples/diet-sensitivity.md +15 -14
  108. package/docs/examples/ecommerce-coupons.md +15 -22
  109. package/docs/examples/index.md +20 -13
  110. package/docs/examples/knapsack.md +8 -7
  111. package/docs/examples/portfolio-qp.md +11 -4
  112. package/docs/examples/production.md +4 -4
  113. package/docs/examples/project-scheduling.md +106 -0
  114. package/docs/examples/shift-scheduling.md +23 -7
  115. package/docs/examples/smt-security.md +17 -4
  116. package/docs/examples/transportation.md +46 -19
  117. package/docs/examples/traveling-salesperson.md +29 -45
  118. package/docs/examples/unsat-core.md +16 -5
  119. package/docs/examples/vehicle-routing.md +10 -8
  120. package/docs/getting-started/ai-agents.md +114 -34
  121. package/docs/getting-started/coding-agents.md +158 -0
  122. package/docs/getting-started/cross-origin.md +56 -28
  123. package/docs/getting-started/index.md +36 -66
  124. package/docs/getting-started/runtimes.md +98 -69
  125. package/docs/guide/constraint-programming.md +141 -0
  126. package/docs/guide/constraints.md +100 -44
  127. package/docs/guide/decomposition.md +141 -273
  128. package/docs/guide/expressions.md +125 -42
  129. package/docs/guide/formulation-tips.md +212 -0
  130. package/docs/guide/objectives.md +70 -64
  131. package/docs/guide/unsat-core.md +44 -23
  132. package/docs/guide/variables.md +56 -48
  133. package/docs/solvers/custom-solver.md +18 -13
  134. package/docs/solvers/highs.md +41 -25
  135. package/docs/solvers/index.md +13 -7
  136. package/docs/solvers/pumpkin.md +163 -0
  137. package/docs/solvers/z3.md +4 -1
  138. package/llms-full.txt +1732 -860
  139. package/llms.txt +59 -36
  140. package/package.json +40 -13
  141. package/skills/washi/SKILL.md +91 -35
  142. package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
  143. package/dist/browser/browser-runtime-TLCY0hkc.js +0 -1793
  144. package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
  145. package/dist/lib/registry-C20sxTwm.js +0 -964
  146. package/docs/ja/getting-started/ai-agents.md +0 -270
  147. package/docs/zh/getting-started/ai-agents.md +0 -270
@@ -0,0 +1,158 @@
1
+ # Coding with AI Agents
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`.
4
+
5
+ ---
6
+
7
+ ## 1. Setup
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.
10
+
11
+ ### Install the Runtime Library
12
+
13
+ Bundled **HiGHS** (LP / MIP / Convex QP) and **Pumpkin** (`@ohtaman/washi/solvers/pumpkin`, CP / LCG) require zero external dependencies:
14
+
15
+ ```bash
16
+ npm install @ohtaman/washi
17
+
18
+ # Optional peer dependencies if your model requires SMT continuous logic or GLPK:
19
+ # npm install z3-solver
20
+ # npm install glpk.js
21
+ ```
22
+
23
+ ### Connect Your Coding Agent
24
+
25
+ Choose the setup method that matches your tool:
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`
37
+
38
+ ---
39
+
40
+ ## 2. Your First End-to-End Run
41
+
42
+ Copy and paste the starter prompt below into your coding agent inside a Node.js / TypeScript project where `@ohtaman/washi` is installed:
43
+
44
+ ```text
45
+ Using @ohtaman/washi, write and run a TypeScript script that schedules 8 internal tech-talk sessions across 2 rooms (Room A, Room B) and 4 time slots.
46
+ Input data: create a sample array of talks with speaker, topic ("infra", "frontend", "data", "security"), and unavailable slots.
47
+ Requirements:
48
+ 1. Assign every talk to exactly one room and one time slot, with at most one talk per room-slot.
49
+ 2. Respect speaker unavailability and prevent any speaker from giving two talks in the same time slot.
50
+ 3. Minimize the number of parallel talks sharing the same topic in the same time slot.
51
+ 4. Give every constraint an explicit descriptive name, solve with bundled HiGHS, check m.hasPrimalSolution, and assert m.verify().valid === true before printing the timetable.
52
+ ```
53
+
54
+ When you run this prompt, the agent executes three steps locally:
55
+
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.
59
+
60
+ ---
61
+
62
+ ## 3. Problem Classes & Ready-to-Use Prompts
63
+
64
+ Each prompt below targets a specific mathematical problem class supported by WaSHI. Adjust the input schema and rules to match your data.
65
+
66
+ ### Event Timetable & Reviewer Assignment (MILP — Bundled HiGHS)
67
+
68
+ ```text
69
+ Using @ohtaman/washi (bundled HiGHS), assign 24 pull-request / RFC submissions to 6 engineers so each submission gets 2 distinct reviewers.
70
+ Rules:
71
+ - Authors cannot review their own submissions, and reviewers must match at least one required domain tag on the submission.
72
+ - Respect each engineer's maximum review cap, and minimize the maximum workload assigned to any single engineer (min-max load balancing).
73
+ - Name every constraint, run the script, and verify m.hasPrimalSolution and m.verify().valid === true.
74
+ ```
75
+
76
+ ### Budget & Project Portfolio Selection (0-1 MIP — Bundled HiGHS)
77
+
78
+ ```text
79
+ Using @ohtaman/washi (bundled HiGHS), select a subset of candidate engineering projects from a JSON list to maximize total expected annual savings.
80
+ Each project has cost, backend_engineers, frontend_engineers, and savings.
81
+ Rules:
82
+ - Stay within a total quarterly budget of 120 and headcount caps of 14 backend and 10 frontend engineers.
83
+ - Dependency: if "billing_v2" is selected, "auth_token_service" must also be selected.
84
+ - Mutual exclusion: select at most one of "legacy_search_tuning" and "vector_search_migration".
85
+ - Give every constraint a clear name and confirm m.verify().valid === true.
86
+ ```
87
+
88
+ ### Task Scheduling with Precedence & Shared Resources (CP/LCG — Bundled Pumpkin)
89
+
90
+ ```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.
92
+ Rules:
93
+ - Enforce finish-to-start precedence edges between dependent tasks.
94
+ - Tasks using the staging benchmark cluster cannot overlap (use disjoint).
95
+ - All running tasks share at most 4 concurrent CI runners at any time (use cumulative).
96
+ - Solve with { solver: "pumpkin" }, verify m.hasPrimalSolution and m.verify().valid === true, and print start/end times for each task.
97
+ ```
98
+
99
+ ### Target-Balancing & Variance Minimization (Convex QP — Bundled HiGHS)
100
+
101
+ Built-in HiGHS solves convex quadratic objectives over continuous variables (`m.continuous`):
102
+
103
+ ```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).
105
+ 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
+ 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
+ ```
108
+
109
+ ### Rule & Configuration Conflict Diagnosis (Infeasibility / Unsat Core)
110
+
111
+ ```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" }).
113
+ 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
+ ```
115
+
116
+ > [!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.
118
+
119
+ ---
120
+
121
+ ## 4. Packaging & Deployment Prompts (Browser, Desktop & Mobile)
122
+
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.
124
+
125
+ ### Zero-Server Single-File `.html` Tool (`file://` Double-Click)
126
+
127
+ ```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.
129
+ - Load WaSHI from https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js (global window.Washi).
130
+ - 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
+ - Verify every feasible solve with m.verify().
132
+ ```
133
+
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://`.
137
+
138
+ ### Offline Desktop & Mobile Apps (Vite + Tauri / Capacitor / PWA)
139
+
140
+ ```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.
142
+ - Keep all solver execution client-side via @ohtaman/washi.
143
+ - Configure Content Security Policy to allow WebAssembly compilation ('wasm-unsafe-eval' in script-src) and Web Workers (worker-src 'self' blob:).
144
+ ```
145
+
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'`).
147
+
148
+ ---
149
+
150
+ ## 5. Iterating & Debugging with Your Agent
151
+
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 `>=`).
@@ -1,47 +1,70 @@
1
1
  # Cross-Origin Isolation (Z3 & Browsers)
2
2
 
3
- When running the **Z3** solver engine inside a web browser, special HTTP headers are required due to browser security models.
3
+ When running the **Z3** solver inside a web browser, Cross-Origin Isolation HTTP headers are required so the browser enables `SharedArrayBuffer`.
4
+
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.
4
7
 
5
8
  ---
6
9
 
7
10
  ## Why is Cross-Origin Isolation Required?
8
11
 
9
- The Z3 WebAssembly engine utilizes multithreading backed by `SharedArrayBuffer` and Web Workers.
10
-
11
- In modern browsers (Chrome, Firefox, Safari, Edge), `SharedArrayBuffer` is disabled by default to mitigate Spectre-style timing side-channel attacks. To re-enable it, the hosting page must be **Cross-Origin Isolated**.
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
13
 
13
14
  ---
14
15
 
15
16
  ## Required HTTP Response Headers
16
17
 
17
- To establish cross-origin isolation, your web server must serve the top-level HTML document with the following HTTP headers:
18
+ Serve the top-level HTML document with:
18
19
 
19
20
  ```http
20
21
  Cross-Origin-Opener-Policy: same-origin
21
22
  Cross-Origin-Embedder-Policy: require-corp
22
23
  ```
23
24
 
24
- In addition, any cross-origin assets (e.g. scripts or WASM files loaded from external domains) must send:
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).
25
26
 
26
- ```http
27
- Cross-Origin-Resource-Policy: cross-origin
28
- ```
27
+ > [!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.
29
29
 
30
30
  ---
31
31
 
32
- ## Solutions by Hosting Environment
32
+ ## Setup by Environment
33
33
 
34
- ### 1. Custom Node.js / Express Server
34
+ ### 1. Vite (`vite.config.ts`)
35
35
 
36
- ```javascript
37
- app.use((req, res, next) => {
38
- res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
39
- res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
40
- next();
36
+ Configure both the local dev server (`vite`) and production preview server (`vite preview`):
37
+
38
+ ```typescript
39
+ import { defineConfig } from "vite";
40
+
41
+ export default defineConfig({
42
+ server: {
43
+ headers: {
44
+ "Cross-Origin-Opener-Policy": "same-origin",
45
+ "Cross-Origin-Embedder-Policy": "require-corp",
46
+ },
47
+ },
48
+ preview: {
49
+ headers: {
50
+ "Cross-Origin-Opener-Policy": "same-origin",
51
+ "Cross-Origin-Embedder-Policy": "require-corp",
52
+ },
53
+ },
41
54
  });
42
55
  ```
43
56
 
44
- ### 2. Next.js (`next.config.js`)
57
+ ### 2. Cloudflare Pages / Netlify (`public/_headers`)
58
+
59
+ Place a `_headers` file in `public/` so it is copied to the root of your build output:
60
+
61
+ ```text
62
+ /*
63
+ Cross-Origin-Opener-Policy: same-origin
64
+ Cross-Origin-Embedder-Policy: require-corp
65
+ ```
66
+
67
+ ### 3. Next.js (`next.config.js`)
45
68
 
46
69
  ```javascript
47
70
  /** @type {import('next').NextConfig} */
@@ -62,26 +85,31 @@ const nextConfig = {
62
85
  module.exports = nextConfig;
63
86
  ```
64
87
 
65
- ### 3. Static Hosting without Header Control (e.g., GitHub Pages)
88
+ ### 4. Custom Node.js / Express Server
89
+
90
+ ```javascript
91
+ app.use((req, res, next) => {
92
+ res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
93
+ res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
94
+ next();
95
+ });
96
+ ```
66
97
 
67
- Platforms like GitHub Pages or preview environments do not allow customizing response headers directly.
98
+ ### 5. Static Hosting without Header Control (e.g., GitHub Pages)
68
99
 
69
- For these environments, you can use **`coi-serviceworker`** (a lightweight Service Worker that injects isolation headers on the client side):
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:
70
101
 
71
- 1. Place `coi-serviceworker.js` in your website root.
72
- 2. In your HTML `<head>`, include:
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.
103
+ 2. Load it in your HTML `<head>`:
73
104
 
74
105
  ```html
75
106
  <script src="/coi-serviceworker.js"></script>
76
107
  ```
77
108
 
78
- When a user visits for the first time, the service worker registers and reloads the page once to establish `window.crossOriginIsolated === true`.
109
+ On the first visit, the Service Worker registers and reloads the page once to establish `window.crossOriginIsolated === true`.
79
110
 
80
111
  ---
81
112
 
82
- ## Graceful Degradation in WaSHI
83
-
84
- WaSHI's Z3 solver adapter automatically inspects the environment at runtime. If Z3 is invoked in a browser lacking cross-origin isolation, it immediately rejects with a clear, informative error message explaining that COOP/COEP headers or a service worker are required, rather than hanging silently.
113
+ ## Runtime Check in WaSHI
85
114
 
86
- > [!TIP]
87
- > The default **HiGHS** solver engine does not require cross-origin isolation or `SharedArrayBuffer`. It works out of the box in standard browser contexts.
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.
@@ -1,19 +1,12 @@
1
1
  # Introduction & Installation
2
2
 
3
- Welcome to **WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface).
4
-
5
- WaSHI brings the algebraic modeling style of Python's **PuLP** and Julia's **JuMP** to the TypeScript and JavaScript ecosystem. You can formulate mathematical optimization problems using algebraic expressions and solve them locally using WebAssembly solvers (**HiGHS**, **Z3**, and **GLPK**)—without a separate Python service or native C/C++ build steps.
6
-
7
- ### Why TypeScript & WebAssembly?
8
-
9
- - **Removing the deployment bottleneck**: In traditional optimization workflows (e.g., Python with PuLP or Pyomo), turning a model into an interactive application requires provisioning a backend service and managing native C/C++ solver binaries. As AI-assisted development accelerates UI and application prototyping, backend infrastructure often becomes the primary bottleneck to shipping. Running both the modeler and WebAssembly solvers on standard Web technologies allows an optimization tool to be deployed as static assets (e.g., on GitHub Pages or Cloudflare Pages, serving the generated JS, Worker, and WASM files; with COOP/COEP headers when using Z3)—and makes it straightforward to pair mathematical optimization with in-browser LLMs (e.g., WebGPU / WebLLM) entirely on the client.
10
- - **Algebraic syntax without operator overloading (`expr`)**: Because JavaScript lacks operator overloading, libraries usually trade off between verbose method chaining (`x.mul(30).add(y.mul(50))`) and untyped strings (`"30 * x + 50 * y"`). WaSHI uses tagged template literals (`` expr`30 * ${x} + 50 * ${y} <= 40` ``) similar to parameterized SQL queries—parsing infix operators while binding `${x}` directly as typed TypeScript object references for static type checking, IDE symbol renaming, and multi-dimensional indexing (`${flow[i][j]}`).
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**).
11
4
 
12
5
  ---
13
6
 
14
7
  ## 📦 Installation
15
8
 
16
- Install WaSHI using your preferred package manager:
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:
17
10
 
18
11
  ::: code-group
19
12
 
@@ -35,82 +28,59 @@ bun add @ohtaman/washi
35
28
 
36
29
  :::
37
30
 
38
- ### Optional Solver Dependencies
39
-
40
- WaSHI ships with **HiGHS** built-in with zero configuration. If you need SMT logic / Unsat Core diagnosis via **Z3**, or compatibility with **GLPK**, install their respective peer dependencies:
31
+ Install optional peer dependencies when you need **Z3** (SMT logic and Unsat Core conflict diagnosis) or **GLPK**:
41
32
 
42
33
  ```bash
43
- # For SMT logic and Unsat Core conflict diagnosis
44
- npm install z3-solver
45
-
46
- # For GLPK solver (GPL-3.0)
47
- npm install glpk.js
34
+ npm install z3-solver # For SMT logic and Unsat Core conflict diagnosis
35
+ npm install glpk.js # For GLPK solver (GPL-3.0)
48
36
  ```
49
37
 
50
- ---
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.
51
39
 
52
- ## 🚀 Quickstart Walkthrough
40
+ ---
53
41
 
54
- Here is a step-by-step example of solving a production allocation problem.
42
+ ## 🚀 Quick Start
55
43
 
56
- ### 1. Import the Core Classes
44
+ Here is a complete production-planning model illustrating the three steps of a typical WaSHI workflow:
57
45
 
58
46
  ```typescript
59
47
  import { Model, expr, maximize } from "@ohtaman/washi";
60
- ```
61
48
 
62
- ### 2. Instantiate a Model
49
+ const m = new Model("production");
63
50
 
64
- ```typescript
65
- const model = new Model("WoodworkingProfit");
66
- ```
51
+ // 1. Define decision variables with realistic finite bounds (lb / ub)
52
+ const desks = m.integer("desks", { lb: 0, ub: 100 });
53
+ const chairs = m.integer("chairs", { lb: 0, ub: 100 });
67
54
 
68
- ### 3. Add Decision Variables
55
+ // 2. Set the objective function and constraints
56
+ m.objective(maximize(expr`30 * ${desks} + 50 * ${chairs}`));
57
+ m.constraint(expr`${desks} + 2 * ${chairs} <= 40`, "wood_capacity");
58
+ m.constraint(expr`2 * ${desks} + ${chairs} <= 50`, "labor_capacity");
69
59
 
70
- Variables represent the unknowns you want to determine. Factory methods (`m.continuous`, `m.integer`, `m.binary`) clearly define their domain:
71
-
72
- ```typescript
73
- const x = model.integer("x", { lb: 0 });
74
- const y = model.integer("y", { lb: 0 });
60
+ // 3. Solve (built-in HiGHS WebAssembly) and verify the solution
61
+ const status = await m.solve();
62
+ if (m.hasPrimalSolution) {
63
+ const report = m.verify();
64
+ console.log(status, report.valid); // "Optimal", true
65
+ console.log(`Profit: ${m.objectiveValue} (desks=${desks.value}, chairs=${chairs.value})`); // 1100 (desks=20, chairs=10)
66
+ }
75
67
  ```
76
68
 
77
- ### 4. Set the Objective Function
78
-
79
- Use the `expr` tagged template literal along with `maximize(...)` or `minimize(...)` to define the goal:
80
-
81
- ```typescript
82
- // Maximize 30*x + 50*y
83
- model.objective(maximize(expr`30 * ${x} + 50 * ${y}`));
84
- ```
85
-
86
- ### 5. Add Constraints
87
-
88
- Use `model.constraint()` with the `expr` tagged template to formulate equality and inequality constraints:
89
-
90
- ```typescript
91
- model.constraint(expr`${x} + 2 * ${y} <= 40`, "wood_capacity");
92
- model.constraint(expr`2 * ${x} + ${y} <= 50`, "labor_capacity");
93
- ```
94
-
95
- ### 6. Solve and Extract Results
96
-
97
- Solve the model asynchronously via WebAssembly (HiGHS by default):
98
-
99
- ```typescript
100
- const status = await model.solve();
101
-
102
- console.log("Status:", status); // "Optimal"
103
- console.log("Optimal Objective Value:", model.objectiveValue); // 1100
104
- console.log(`Solution: x = ${x.value}, y = ${y.value}`); // x = 20, y = 10
105
- ```
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.
106
72
 
107
73
  ---
108
74
 
109
75
  ## 🧭 Next Steps
110
76
 
111
- - Give AI coding agents a concise API & deployment reference with the [AI Coding Agent Quick-Reference Guide](./ai-agents.md).
112
- - Learn how to run WaSHI across different environments in [Runtime Environments](./runtimes.md).
113
- - Understand how to formulate complex expressions in the [Modeling Guide](../guide/expressions.md).
114
- - Explore built-in and pluggable solvers in the [Solvers Matrix](../solvers/).
115
- - Browse 9 runnable optimization and SMT recipes in [Examples & API Finder](../examples/).
77
+ ### Choose Your Workflow
78
+
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
81
+
82
+ ### Reference & Examples
116
83
 
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