swactor/big-feature-phase/notes/state.md

48 lines
2.4 KiB
Markdown
Raw Normal View History

## Current Task
Stage 1 — Platform Abstraction Layer
Step: Complete
Attempt: 1 of 3
## Key Files (read these first on resume)
- `big-feature-phase/TASK.md` — workflow rules
- `big-feature-phase/notes/constraints.md` — guardrails
- `big-feature-phase/notes/feature-stages/02-single-worker-browser.md` — Stage 2 spec
- `Cargo.toml` — `wasm` feature flag, `web-time` dep (lines 23, 30)
- `src/lib.rs` — platform-aware `Instant` re-export (lines 20-24)
- `src/runtime.rs` — cfg-gated `run()` (line 340) and `RuntimeHandle` (line 73)
- `crates/wasm/Cargo.toml` — now uses `features = ["wasm"]`
- `docs/development_history/in-browser/PLATFORM_ABSTRACTION.md` — what was done
## Last Action & Result
Completed Stage 1 (Platform Abstraction Layer):
- Added `web-time` dep + `wasm` feature (`no_random` + `web-time`)
- Replaced `std::time::Instant` → `crate::Instant` in runtime.rs, worker.rs
- cfg-gated `Runtime::run()` and `RuntimeHandle` for `not(target_arch = "wasm32")`
- Removed unused `Mutex` import from worker.rs
- Updated `crates/wasm/` to use `wasm` feature
- Key finding: most std::sync/thread primitives work on wasm32 with atomics; only `thread::spawn` needed gating
- All native tests pass, wasm32 compilation succeeds
## Next Action
Begin Stage 2 (Single-Worker Browser Runtime) — `notes/feature-stages/02-single-worker-browser.md`:
1. Create `crates/wasm-browser/` crate structure
2. Implement `BrowserRuntime` wasm-bindgen API (spawn, send, tick, try_recv, stats)
3. Actor registration macro/pattern for JS-accessible spawning
4. Auto-scheduling via setTimeout(0) loop
5. Message serialization across JS↔Wasm boundary
6. Tests (wasm-pack test or Node.js)
## Completed This Session
- [x] Cycle 0 research artifacts (constraints.md, research_synthesis.md, 6 stage docs)
- [x] Stage 1: `web-time` dep + `wasm` feature flag in Cargo.toml
- [x] Stage 1: Platform-aware `Instant` re-export in src/lib.rs
- [x] Stage 1: cfg-gated `Runtime::run()` and `RuntimeHandle` in src/runtime.rs
- [x] Stage 1: Updated crates/wasm/ to use `wasm` feature
- [x] Stage 1: Validated wasm32 compilation and native tests
- [x] Stage 1: Development history doc
## Open Questions / Blockers
- Stage 2: Need to decide on message serialization (serde-wasm-bindgen vs raw bytes)
- Stage 2: Actor registration pattern — macro vs manual factory map
- Stage 3: Web Worker thread state initialization needs investigation (does std::thread::current() work in a Web Worker context?)