Files
improvise/crates/improvise-worker-server/Cargo.toml
T
Edward Langley bdce1636bb feat(worker-server): the whole App in a Web Worker, over postMessage + OPFS
improvise-9x6: the server half of the standalone static-web deployment
(epic improvise-tm6). `improvise-worker-server` hosts the authoritative
`App`, the command pipeline, the projection layer and VFS persistence behind
`self.onmessage`/`self.postMessage`.

It is small because everything it needs already existed: the frames are
`improvise_protocol::frame`'s (improvise-xks6), the session loop is
`Host` (previous commit), the basis check is `Sessions::apply`/`Checked`
(improvise-ondj), and persistence is `Storage` + `OpfsFs` (improvise-6mq,
i34). What is genuinely new is three things.

`vfs.rs` — how a document gets INTO a browser's empty filesystem. Loading is
unchanged: it is `persistence::load_from` on a `Storage`, the same call the
native binary makes. Seeding is the new problem, and it is a
`Storage::write`, so a fetched demo, an upload and a saved document take the
same parse path and a seed never clobbers an edit. `list` is the document
picker a browser has no OS file manager for.

`worker.rs` — the loop: one port, one client, the `Viewport` handshake
(dropped rather than closed, since there is no connection to close), and the
filter from `Addressed`. Every decision is here and every test points at it.

`bindings.rs` — `cfg(wasm32)`, decision-free, and the only part no test here
can reach: it awaits `OpfsFs::open`/`attach`/`refresh`/`commit_deletes` and
forwards strings.

Two gaps found and reported rather than papered over. No client on any
transport can ask its host to save — `effect::Save` is `ViewOnly`, so the
wire vocabulary derived from the model effects cannot name it — and a wire
`ModelCommand::SetCell` never sets `model_state.dirty`, because dirtiness is
raised by a separate `MarkDirty` effect the key path emits. So the worker
persists on its own behalf, keyed off the command variant rather than off a
flag that is never set; `touches_document` carries the argument.

`ClientFrame::Key` is still answered with nothing. A worker CAN call
`reduce_key` — it holds the `App` — but nothing in the projection stream
carries the host's own `ViewState`, so a half-wired arm diverges rather than
under-delivers. `a_key_resolved_on_the_host_moves_state_no_client_can_hear`
demonstrates it against a real `App` and `Sessions` (improvise-bpq2).

22 tests, all host-side: 16 in the crate and 6 in `tests/post_message.rs`,
which drives the worker with nothing but the JSON a `MessagePort` carries.
Bundle: 1,334,892 bytes raw, 496,965 gzipped — 485 KB against a 3 MB budget.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EoW5BB87ZZdm96SvBTWawH
2026-09-19 19:08:19 -07:00

39 lines
1.7 KiB
TOML

[package]
name = "improvise-worker-server"
version = "0.1.0-rc2"
edition = "2024"
description = "Worker-hosted improvise server: the authoritative App in a browser Web Worker, over postMessage + OPFS"
license = "Apache-2.0"
repository = "https://github.com/fiddlerwoaroof/improvise"
publish = false
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
improvise-core = { path = "../improvise-core" }
improvise-io = { path = "../improvise-io" }
improvise-protocol = { path = "../improvise-protocol" }
improvise-command = { path = "../improvise-command" }
anyhow = "1"
serde_json = "1"
# The browser half. Only the wasm build pulls these in, so `cargo test` on the
# host builds and drives `worker.rs`/`vfs.rs` with no JS anywhere near them —
# which is the whole reason the decisions live there and not in `bindings.rs`.
[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"
# `#[wasm_bindgen] pub async fn` expands to a `future_to_promise`, so the
# generated code names this crate even though nothing here does.
wasm-bindgen-futures = "0.4"
# The bundled `wasm-opt` predates two features being enabled by default, while
# LLVM emits both regardless, so the validator rejects the module unless each
# is named. `bulk-memory` is the one improvise-wasm-client already needs
# (`memory.copy`). This bundle needs a second: it carries the whole `App`, and
# so chrono's date arithmetic, which compiles to `i64.trunc_sat_f64_u` —
# `nontrapping-float-to-int`. Naming them keeps the optimizer in the loop
# rather than turning it off, which matters here: it is 22% of this bundle.
[package.metadata.wasm-pack.profile.release]
wasm-opt = ["-O", "--enable-bulk-memory", "--enable-nontrapping-float-to-int"]