@ohtaman/washi 0.9.0-rc.1 → 0.9.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.
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: washi
3
- description: Formulate, inspect, solve, and verify mathematical optimization (LP, MILP/MIP, convex QP, CP/LCG, column generation, Benders decomposition) and SMT satisfiability or unsat-core models in TypeScript and JavaScript using @ohtaman/washi (HiGHS, Pumpkin, Z3, GLPK) for shift scheduling, timetabling, resource allocation, bin packing, routing, portfolio optimization, and rule conflict diagnosis.
3
+ description: Formulate, inspect, solve, verify, and package mathematical optimization (LP, MILP/MIP, convex QP, CP/LCG, column generation, Benders decomposition) and SMT satisfiability or unsat-core models in TypeScript, JavaScript, and offline single-file HTML apps using @ohtaman/washi (HiGHS, Pumpkin, Z3, GLPK) for shift scheduling, timetabling, resource allocation, bin packing, routing, portfolio optimization, and rule conflict diagnosis.
4
4
  ---
5
5
 
6
6
  # WaSHI Modeling & Verification Skill
@@ -26,8 +26,8 @@ Select the solver engine and execution method that match the problem class:
26
26
  - **HiGHS** and **Pumpkin** load bundled `.wasm` and Worker assets relative to the bundle (no external CDN fallback; `useWorker: false` by default on opaque origins such as `file://`).
27
27
  - **HiGHS**, **Pumpkin**, and **GLPK** all run without `COOP`/`COEP` headers (**GLPK** is an optional peer dependency that rejects `useWorker: true`).
28
28
  - **Z3** uses `SharedArrayBuffer` pthreads and requires `window.isSecureContext === true` and `window.crossOriginIsolated === true` (`Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`).
29
- - **Single-file / CSP-restricted pages (blocked `fetch()`)**: Environments such as published Claude.ai artifacts or restricted HTML previews allow CDN scripts (`script-src`) while blocking `fetch()` (`connect-src 'none'`). Load the zero-build self-registering CDN inline WASM packs (`solvers/highs-inline.js` / `solvers/pumpkin-inline.js` — usable in both ESM and classic `<script>`) before the first `solve()` / `check()` call (see Recipe 5 below).
30
- - **Single-file offline HTML + npm packages (`file://`)**: To bundle `@ohtaman/washi` (HiGHS and/or Pumpkin) alongside arbitrary third-party npm packages (React, Chart.js, KaTeX, Tailwind) into one zero-network, double-clickable offline `file://` HTML file using Vite + `vite-plugin-singlefile` + gzipped WASM, follow the **`washi-single-html`** skill (`skills/washi-single-html/SKILL.md`).
29
+ - **Single-file / CSP-restricted AI sandboxes (blocked `fetch()`)**: Environments such as Claude.ai Artifacts (edit & published links), ChatGPT inline visualizations, and Codex inline visualizations allow CDN scripts (`script-src`) while blocking `fetch()` (`connect-src 'none'`) and Web Workers (`worker-src`). Prefer **ESM `<script type="module">` + `solvers/highs-inline.js` / `solvers/pumpkin-inline.js` + `{ useWorker: false }`** (with a `timeLimit` on non-trivial solves) before the first `solve()` / `check()` call (see Recipe 5 below). Note that embedded previews omitting `'wasm-unsafe-eval'` from `script-src` (such as Antigravity's HTML artifact preview) cannot compile WebAssembly; export `.html` and open in Chrome/Safari or via a local server.
30
+ - **Single-file offline HTML + npm packages (`file://`)**: To bundle `@ohtaman/washi` (HiGHS and/or Pumpkin) alongside arbitrary third-party npm packages (React, Chart.js, KaTeX, Tailwind) into one zero-network, double-clickable offline `file://` HTML file using Vite + `vite-plugin-singlefile` + gzipped WASM, follow [`references/single-html.md`](./references/single-html.md) (`node_modules/@ohtaman/washi/skills/washi/references/single-html.md`).
31
31
 
32
32
  ---
33
33
 
@@ -72,10 +72,10 @@ For full examples, see [`docs/guide/decomposition.md`](https://github.com/ohtama
72
72
 
73
73
  ## 3. Model Inspection (`toLpString`)
74
74
 
75
- Before solving or when debugging formulation bugs:
75
+ `m.solve()` and `m.check()` already run model integrity validation automatically (variable ownership across `Model` instances, `lb <= ub`, finite `initialValue` within bounds/integrality tolerance `1e-6`, and finite coefficients), so `m.toLpString()` is an **optional debugging utility** rather than a routine step in every solve:
76
76
 
77
- - **Integrity check & LP export**: `m.toLpString()` validates model integrity (variable ownership across `Model` instances, `lb <= ub`, finite `initialValue` within bounds/integrality tolerance `1e-6`, and finite coefficients) and exports the numeric LP / MIP / QP formulation in CPLEX LP format (`Maximize` / `Minimize`, `Subject To`, `Bounds`, `General`, `Binary`, `End`).
78
- - **What to check**: Inspect the exported text to confirm objective sense, signs, coefficients, and right-hand sides match the mathematical specification.
77
+ - **Avoid dumping large models**: Do **not** print `m.toLpString()` to stdout or return `lpText` unconditionally on realistic or large models (hundreds or thousands of variables/constraints)—full LP dumps bloat your context window. For production-sized models, read the TypeScript modeling code directly and rely on `m.verify()` and `m.check()`.
78
+ - **Targeted debugging on small reproductions**: Use `m.toLpString()` selectively on a **small toy reproduction** (or write it to a file and inspect specific lines) when diagnosing subtle objective sense, sign, coefficient, or RHS bugs via CPLEX LP format (`Maximize` / `Minimize`, `Subject To`, `Bounds`, `General`, `Binary`, `End`).
79
79
  - **Scope caveat**: Propositional `BoolVar`s and logical/CP constraints (`BoolExpr`) are omitted from CPLEX LP output.
80
80
 
81
81
  ---
@@ -99,7 +99,7 @@ Never report a model solution as final without executing the verification step:
99
99
 
100
100
  ## 5. Executable Workflow Recipes
101
101
 
102
- ### Recipe 1: MIP Formulation, `toLpString()` Inspection & `verify()` Verification
102
+ ### Recipe 1: MIP Formulation & `verify()` Verification
103
103
 
104
104
  ```ts
105
105
  import { Model, expr, dot, sum, maximize } from "@ohtaman/washi";
@@ -122,18 +122,14 @@ export async function solveAndVerifyMip() {
122
122
  name: "closed_line_zero_output",
123
123
  });
124
124
 
125
- // 1. Pre-solve integrity validation & LP formulation inspection
126
- const lpText = m.toLpString();
127
-
128
- // 2. Solve with default HiGHS solver
125
+ // 1. Solve with default HiGHS solver (runs integrity checks automatically)
129
126
  const status = await m.solve();
130
127
 
131
- // 3. Mandatory independent solution verification
128
+ // 2. Mandatory independent solution verification
132
129
  const report = m.verify();
133
130
 
134
131
  return {
135
132
  status,
136
- lpText,
137
133
  objectiveValue: m.objectiveValue,
138
134
  quantities: { desk: qty.desk.value, chair: qty.chair.value },
139
135
  lineOpen: lineOpen.value,
@@ -156,13 +152,11 @@ export async function solveAndVerifyQp() {
156
152
  m.objective(minimize(expr`${x}^2 + ${y}^2`));
157
153
  m.constraint(expr`${x} + ${y} >= 4`, "target_total");
158
154
 
159
- const lpText = m.toLpString();
160
155
  const status = await m.solve();
161
156
  const report = m.verify();
162
157
 
163
158
  return {
164
159
  status,
165
- lpText,
166
160
  objectiveValue: m.objectiveValue,
167
161
  x: x.value,
168
162
  y: y.value,
@@ -263,14 +257,15 @@ export async function solveAndDiagnoseWithPumpkin() {
263
257
  }
264
258
  ```
265
259
 
266
- ### Recipe 5: Single-File HTML & CSP-Restricted Environments (No `fetch`)
260
+ ### Recipe 5: Single-File HTML & CSP-Restricted AI Sandboxes (No `fetch`)
267
261
 
268
- Some hosted single-file environments (for example, published Claude.ai artifacts or restricted HTML previews) allow CDN scripts (`script-src`) while blocking `fetch()` via `connect-src 'none'`. In that setup, default `.wasm` loading fails because HiGHS and Pumpkin fetch their `.wasm` files at startup.
262
+ Hosted AI preview environments—including **Claude.ai Artifacts** (edit and published links), **ChatGPT inline visualizations**, and **Codex inline visualizations**—allow CDN scripts (`script-src`) while blocking `.wasm` `fetch()` (`connect-src 'none'`) and Web Workers (`worker-src`). Meanwhile, **Gemini Canvas** and **Google Sites** allow both `fetch()` and Web Workers, while embedded previews that omit `'wasm-unsafe-eval'` from `script-src` (such as Antigravity's HTML artifact preview) cannot run WebAssembly at all.
269
263
 
270
264
  Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtaman/washi/browser/solvers/highs-inline` and `solvers/pumpkin-inline.js` / `@ohtaman/washi/browser/solvers/pumpkin-inline`) **before** the first `solve()`, `check()`, or `warmup*()` call—no manual base64 decoding or binary setters are needed, and the same `*-inline.js` file works in both ESM and classic `<script>` mode:
271
265
 
272
266
  ```html
273
- <!-- ESM (<script type="module">) -->
267
+ <!-- Recommended: ESM (<script type="module">) + { useWorker: false } -->
268
+ <!-- Works across Claude Artifacts, ChatGPT/Codex inline visualizations, Gemini Canvas, Google Sites & file:// -->
274
269
  <script type="module">
275
270
  import { Model, expr, maximize } from "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.js";
276
271
  import "https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/highs-inline.js";
@@ -282,15 +277,15 @@ Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtam
282
277
  m.objective(maximize(expr`30 * ${x} + 50 * ${y}`));
283
278
  m.constraint(expr`${x} + 2 * ${y} <= 40`, "wood");
284
279
  m.constraint(expr`2 * ${x} + ${y} <= 50`, "labor");
285
- await m.solve(); // Works in both main-thread and Web Worker mode without fetch()
280
+ await m.solve({ useWorker: false, timeLimit: 5 });
286
281
 
287
282
  const cp = new Model("CspSafeCP", { solver: "pumpkin" });
288
283
  const k = cp.integer("k", { lb: 0, ub: 6 });
289
284
  cp.objective(maximize(expr`10 * ${k}`));
290
- await cp.solve(); // Works without fetch() as well
285
+ await cp.solve({ useWorker: false, timeLimit: 5 });
291
286
  </script>
292
287
 
293
- <!-- Classic <script> (works even with worker-src 'none' when useWorker: false) -->
288
+ <!-- Classic <script> fallback (prefer ESM above: dynamically injected sandboxes can race external <script src> tags) -->
294
289
  <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
295
290
  <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/highs-inline.js"></script>
296
291
  <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/pumpkin-inline.js"></script>
@@ -301,12 +296,14 @@ Load the self-registering inline WASM packs (`solvers/highs-inline.js` / `@ohtam
301
296
  const x = m.integer("x", { lb: 0 });
302
297
  m.objective(maximize(x));
303
298
  m.constraint(expr`${x} <= 10`, "cap");
304
- await m.solve({ useWorker: false }); // Zero fetch(), zero Blob URLs, zero Workers
299
+ await m.solve({ useWorker: false, timeLimit: 5 }); // Zero fetch(), zero Blob URLs, zero Workers
305
300
  })();
306
301
  </script>
307
302
  ```
308
303
 
309
- - **Initialization & Worker behavior without `fetch()`**: Load `*-inline.js` before the first `solve()`, `check()`, or `warmup*()` (order between core and `*-inline.js` before init does not matter; late registration after first init is ignored to keep main-thread and Worker behavior consistent). In Web Worker mode (`useWorker: true`), WaSHI passes the embedded bytes to the Web Worker via `postMessage` once per Worker instance—no `.wasm` `fetch()` occurs inside the Worker. If `worker-src` blocks `blob:` or Workers, or on opaque origins (`window.origin === "null"`), pass `{ useWorker: false }` (opaque origins fall back to the main thread automatically).
304
+ - **Why ESM (`<script type="module">`) is recommended over Classic `<script>`**: In dynamically injected sandboxes (such as ChatGPT inline visualizations), classic `<script src="...">` tags may race with subsequent inline `<script>` blocks or miss `window` `load`, whereas ESM `import` strictly awaits all module dependencies before running.
305
+ - **`useWorker: true` vs. `useWorker: false` trade-off**: WaSHI keeps `useWorker: true` as the default on standard `http(s):` origins (including regular web apps, Gemini Canvas, and Google Sites) because Web Workers keep the UI responsive, support immediate `AbortSignal` termination, allow live `onProgress` repainting, and isolate crashes. Pass `{ useWorker: false }` (and set a `timeLimit` to prevent long UI freezes) only in Worker-restricted sandboxes (Claude Artifacts, ChatGPT/Codex inline visualizations, or `file://`).
306
+ - **Initialization semantics without `fetch()`**: Load `*-inline.js` before the first `solve()`, `check()`, or `warmup*()` (order between core and `*-inline.js` before init does not matter; late registration after first init is ignored to keep main-thread and Worker behavior consistent). In Web Worker mode (`useWorker: true`), WaSHI passes the embedded bytes via `postMessage` once per Worker instance without calling `fetch()`.
310
307
  - **Other solvers**: **GLPK** (`solvers/glpk.js`) already embeds its WASM inline and requires no extra setup (GPL-3.0). **Z3** requires `SharedArrayBuffer` / `COOP`+`COEP` headers and is out of scope for standalone CSP-restricted artifacts.
311
308
 
312
309
  ---
@@ -1,15 +1,10 @@
1
- ---
2
- name: washi-single-html
3
- description: This skill should be used when building a single-file, offline-ready HTML web application using @ohtaman/washi (alongside arbitrary third-party npm packages such as React, Chart.js, KaTeX, or Tailwind) that opens directly via file:// with zero network requests and zero extra assets.
4
- ---
5
-
6
- # WaSHI Single-File Offline HTML App Skill
1
+ # WaSHI Single-File Offline HTML App Guide
7
2
 
8
3
  Build self-contained, single-file `index.html` applications that bundle `@ohtaman/washi` (HiGHS and Pumpkin WASM solvers) together with any third-party npm UI, charting, or math libraries so end users can double-click the file (`file://`) offline with zero local servers, zero external CDN requests, and zero extra asset files.
9
4
 
10
5
  ## Architecture Overview
11
6
 
12
- > **When to use `washi-single-html` vs. `*-inline.js`**: Use **`washi-single-html`** when Vite-bundling a zero-network, double-clickable offline `file://` HTML app with gzipped WASM and third-party npm UI libraries (`react`, `katex`, `chart.js`, `tailwindcss`). For zero-build HTML snippets hosted inside CSP-restricted sandboxes (`connect-src 'none'`, such as ChatGPT HTML previews or published Claude.ai artifacts), use WaSHI's CDN `solvers/highs-inline.js` / `solvers/pumpkin-inline.js` packs instead (see `skills/washi/SKILL.md`).
7
+ > **When to use this offline Vite guide vs. `*-inline.js`**: Use **`references/single-html.md`** when Vite-bundling a zero-network, double-clickable offline `file://` HTML app with gzipped WASM and third-party npm UI libraries (`react`, `katex`, `chart.js`, `tailwindcss`). For zero-build HTML snippets hosted inside CSP-restricted AI sandboxes (`connect-src 'none'`, such as Claude.ai Artifacts, ChatGPT/Codex inline visualizations, or Gemini Canvas / Google Sites), use WaSHI's CDN `solvers/highs-inline.js` / `solvers/pumpkin-inline.js` packs with ESM `<script type="module">` instead (see [`../SKILL.md`](../SKILL.md)). Note that embedded previews whose CSP omits `'wasm-unsafe-eval'` (such as Antigravity's HTML artifact preview) cannot compile WebAssembly; open the exported `dist/index.html` directly in Chrome/Safari or via a local server.
13
8
 
14
9
  A standard `vite-plugin-singlefile` build already inlines JS modules, CSS, web fonts, and images from any npm dependency (`react`, `katex`, `chart.js`, `tailwindcss`, etc.) into one HTML file. WaSHI adds three extra single-file constraints that standard plugins do not handle alone:
15
10
 
@@ -293,7 +288,7 @@ export function hydrateOfflineWashiSolvers(
293
288
 
294
289
  ## Step 4: Model, Solve with `{ useWorker: false }`, and Verify
295
290
 
296
- Always call `await hydrateOfflineWashiSolvers(...)` once before solving, pass `{ useWorker: false }` in every `solve()` / `check()` call, and assert `m.verify().valid` (never hardcode solver answers in UI state):
291
+ Always call `await hydrateOfflineWashiSolvers(...)` once before solving, pass `{ useWorker: false }` in every `solve()` / `check()` call, and assert `m.verify().valid` (never hardcode solver answers in UI state). Because `{ useWorker: false }` runs on the browser main thread, set a sensible `timeLimit` (e.g. `{ useWorker: false, timeLimit: 5 }`) for non-trivial MIP/CP models so the UI does not appear frozen and always yields a frame before displaying loading indicators:
297
292
 
298
293
  ```ts
299
294
  import katex from "katex";