Commit Graph

634 Commits

Author SHA1 Message Date
03c2115f0d Fix WASM kernel deploy: 3.6MB js_of_ocaml → 68KB wasm_of_ocaml
The deployed sx_browser.bc.wasm.js was actually the js_of_ocaml output
(pure JS), not the wasm_of_ocaml loader. Nothing synced the correct
build output from _build/ to shared/static/wasm/.

- sx_build target=ocaml now auto-syncs WASM kernel + JS fallback + assets
- sx-build-all.sh syncs after dune build
- Correct 68KB WASM loader replaces 3.6MB JS imposter

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 13:10:13 +00:00
e14947cedc Add sx:ready hydration signal, eliminate test sleeps
boot-init now sets data-sx-ready on <html> and dispatches an sx:ready
CustomEvent after all islands are hydrated. Playwright tests use this
instead of networkidle + hard-coded sleeps (50+ seconds eliminated).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 12:47:52 +00:00
fffb5ab0b5 Revert iterative cek_run, restore working WASM kernel
Iterative cek_run broke page-script parsing in browser. Reverted to
recursive — bytecode compilation overflow handled by native Sx_compiler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 11:10:51 +00:00
951b3a6586 Native bytecode compilation in MCP: 108s → 1.9s (57x faster)
Replace Node.js compile-modules.js with direct Sx_compiler.compile_module
calls in mcp_tree.ml. No subprocess, no JIT warm-up, no Node.js.
23 files compile in 1.9 seconds.

Also includes rebuilt WASM kernel (iterative cek_run) and all 23
bytecode modules recompiled with native compiler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 10:45:38 +00:00
1985c648eb Native bytecode compiler: 8x faster, compile-blob command
Rewrite compile-modules.js to use the native OCaml sx_server binary
instead of the js_of_ocaml kernel in Node.js. Compiles 23 modules in
23s (was 3+ minutes). Uses batch epoch protocol with latin1 encoding
to preserve byte positions for multi-byte UTF-8 content.

- Add compile-blob server command: parse source natively, compile via
  SX compile-module, return bytecode dict
- Fix orchestration.sxbc.json and boot.sxbc.json — never compiled
  successfully with the old JS kernel, now work with native compiler
- Auto-copy compiled bytecode to shared/static/wasm/sx/ for serving

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 09:49:28 +00:00
671d19c978 SX request handler + AJAX nav + shared JIT globals + shell cleanup
- Remove prism.js, sweetalert2, body.js, sx-browser.js from shell —
  only WASM kernel (sx_browser.bc.wasm.js + sx-platform.js) loads
- Restore request-handler.sx integration: SX handles routing + AJAX
  detection, OCaml does aser → SSR → shell render pipeline
- AJAX fragment support: SX-Request header returns content fragment
  (~14KB) instead of full page (~858KB), cached with "ajax:" prefix
- Fix language/applications/etc page functions to return empty fragment
  instead of nil (was causing 404s)
- Shared JIT VM globals: env_bind hook mirrors ALL bindings to a single
  shared globals table — eliminates stale-snapshot class of JIT bugs
- Add native `parse` function for components that need SX parsing
- Clean up unused shell params (sx-js-hash, body-js-hash, head-scripts,
  body-scripts, use-wasm) from shell.sx, helpers.py, and server.ml

14/32 Playwright tests pass (navigation, SSR, isomorphic, geography).
Remaining failures are client-side (WASM bytecode 404s block hydration).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-30 03:03:57 +00:00
84a48f0de3 Fix navigation: deep URL routing, back button, render timeout
- request-handler.sx: replace all dots (not just `.(`) and auto-quote
  undefined symbols as strings so 3-level URLs like
  /sx/(geography.(reactive.(examples.counter))) resolve correctly
- sx-platform.js: register popstate handler (was missing from manual
  boot sequence) and fetch full HTML for back/forward navigation
- sx_ref.ml: add CEK step limit (10M steps) checked every 4096 steps
  so runaway renders return 500 instead of blocking the worker forever
- Rename test-runner.sx → runner-placeholder.sx to avoid `test-` skip
- Playwright config: pin testDir, single worker, ignore worktrees

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 17:54:33 +00:00
20b3dfb8a0 Fix island state loss on SX navigation + cache busting
Island markers rendered during SX navigation responses had no
data-sx-state attribute, so hydration found empty kwargs and path
was nil in the copyright display. Now adapter-dom.sx serializes
keyword args into data-sx-state on island markers, matching what
adapter-html.sx does for SSR.

Also fix post-swap to use parent element for outerHTML swaps in
SX responses (was using detached old target). Add SX source file
hashes to wasm_hash for proper browser cache busting — changing
any .sx file now busts the cache. Remove stale .sxbc bytecode
cache files.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 17:36:27 +00:00
a9a0a23437 WASM JIT: remove permanent disable on failure, fix signal-condition rename
WASM kernel (sx_browser.ml): remove jit_failed_sentinel marking on
JIT runtime errors. Functions stay JIT-compiled and retry on next call.
Errors are data-dependent, not JIT bugs.

signal-condition: rename in CEK dispatcher so reactive 'signal' function
works. The conditions system 'signal' special form is now 'signal-condition'.

adapter-html.sx: remove cek-try wrapping island render. Errors propagate.

Island SSR: 4/5 tests pass. Header renders perfectly. Stepper ~cssx/tw
not expanding because component calls in island body aren't evaluated
by render-to-html — they're serialized as text. Needs SX adapter fix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 07:09:31 +00:00
d0c03a7648 Fix island SSR: rename signal special form, remove cek-try swallowing
Root cause: the new conditions system's 'signal' special form shadowed
the reactive 'signal' function. (signal 0) in island bodies raised
'Unhandled condition: 0' instead of creating a signal dict.

Fix: rename condition special form to 'signal-condition' in the CEK
dispatcher. The reactive 'signal' function now works normally.

adapter-html.sx: remove cek-try that swallowed island render errors.
Islands now render directly — errors propagate for debugging.

sx_render.ml: add sx_render_to_html that calls SX adapter via CEK.

Results: 4/5 island SSR tests pass:
- Header island: logo, tagline, styled elements ✓
- Navigation buttons ✓
- Geography content ✓
- Stepper: partially renders (code view OK, ~cssx/tw in heading)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 02:07:24 +00:00
e1ef883339 SX renderer: adapter-html.sx as sole renderer, conditions, pattern matching
Evaluator: conditions/restarts, pattern matching, render-trace support.
adapter-html.sx: full SX-defined HTML renderer replacing native OCaml.
spec/render.sx: updated render mode helpers.
sx_browser.ml: use SX render-to-html instead of native.
sx_ref.ml: evaluator updates for conditions + match.
Bootstrap + transpiler updates for new forms.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 01:28:53 +00:00
f3a437ee87 JIT: use live globals, don't copy — fixes CSSX Not callable: nil
jit_compile_lambda now uses the live globals table directly instead
of Hashtbl.copy. Closure bindings that aren't already in globals are
injected into the live table. This ensures GLOBAL_GET always sees
the latest define values.

Previously: Hashtbl.copy created a stale snapshot. Functions defined
after the copy (like cssx-process-token from cssx.sx) resolved to nil
in JIT-compiled closures.

JIT error test now passes — 0 CSSX errors during navigation.
7/8 navigation tests pass. Remaining: back button content update.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 01:05:48 +00:00
39eb217c15 sx-http: fix homepage (bare symbol → fn call) + auto-quote slugs + resilient SSR
Homepage fix: path_expr "home" was evaluated as a symbol lookup (returning
the Lambda) instead of a function call. Now wraps bare symbols in a list:
home → (home) → calls the page function → returns component call.

Slug routing: auto_quote converts unknown symbols to strings before eval.
(etc (plan sx-host)) → (etc (plan "sx-host")) — resolves nested slug URLs.

Resilient SSR: render_to_buf catches Eval_error per-element and continues
rendering. Partial SSR output preserved even when some elements fail.

WASM kernel rebuilt (define shorthand + island placeholder changes).

Remaining: WASM kernel "Undefined symbol: let" — pre-existing bug in
client-side component-defs parsing. (list let ...) triggers symbol lookup
instead of special form recognition. Affects island hydration on all pages.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 18:41:56 +00:00
90918fb2b1 VM global_env sync + isomorphic nav store primitives
Reverse hook syncs VM GLOBAL_SET mutations back to global_env so CEK reads
see JIT-written values. Isomorphic nav: store primitives, event-bridge,
client? predicate. Browser JS and bytecode rebuilt.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 15:20:12 +00:00
153f02c672 sx-host plan steps 1-2: defhelper + SX config + SXTP spec + nav tools
Step 1 — defhelper: SX-defined page data helpers replace Python helpers.
(defhelper name (params) body) in .sx files, using existing IO primitives
(query, action, service). Loaded into OCaml kernel as pure SX defines.

Step 2 — SX config: app-config.sx replaces app-config.yaml with (defconfig)
form. (env-get "VAR") resolves secrets from environment. Kebab-to-underscore
aliasing ensures backward compatibility with all 174 config consumers.

Also: SXTP protocol spec (applications/sxtp/spec.sx), docs article,
sx_nav move/delete modes, reactive-runtime moved to geography.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 15:18:45 +00:00
9ac2e38c24 Store primitives + event-bridge + client? for isomorphic nav
- def-store/use-store/clear-stores: OCaml primitives with global
  mutable registry. Bypasses env scoping issues that prevented SX-level
  stores from persisting across bytecode module boundaries.

- client? primitive: _is_client ref (false on server, true in browser).
  Registered in primitives table for CALL_PRIM compatibility.

- Event-bridge island: rewritten to use document-level addEventListener
  via effect + host-callback, fixing container-ref timing issue.

- Header island: uses def-store for idx/shade signals when client? is
  true, plain signals when false (SSR compatibility).

- web-signals.sx: SX store definitions removed, OCaml primitives replace.

Isomorphic nav still fixme — client? works from K.eval but the JIT
"Not callable: nil" bug prevents proper primitive resolution during
render-to-dom hydration. Needs JIT investigation.

100 passed, 1 skipped, 0 failed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 11:54:29 +00:00
0cae1fbb6b Fix event-bridge + add client? primitive + header store foundation
- Event-bridge: rewrite island to use document-level addEventListener
  via effect + host-callback, bypassing broken container-ref + schedule-idle.
  Also use host-get for event-detail (WASM host handles).

- Add client? primitive: false on server (sx_primitives._is_client ref),
  true in browser (sx_browser.ml sets ref). Enables SSR-safe conditional
  logic for client-only features like def-store.

- Header island: use def-store for idx/shade signals when client? is true,
  falling back to plain signals on server. Foundation for SPA nav state
  preservation (store registry persistence still needs work).

- Remove unused client? K.eval override from sx-platform.js.

100 passed, 1 skipped (isomorphic nav — store registry resets on SPA nav), 0 failed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 10:05:32 +00:00
919ce927b1 Fix WASM trampoline stub + event-bridge host-get
- sx_browser.ml: use Sx_ref.trampoline instead of Sx_runtime.trampoline
  (the stub was a no-op, causing cek-call to return unresolved Thunks).
  Fixes resource island promise resolution — promises now resolve and
  update signals correctly.

- event-bridge island: use host-get instead of get for event-detail,
  since WASM kernel returns JS host handles for CustomEvent detail
  objects, not native SX dicts.

- Mark event-bridge and isomorphic-nav as test.fixme (deeper issues
  remain: event handler swap! doesn't propagate to DOM; header island
  inside #main-panel swap boundary needs structural layout change).

99 passed, 2 skipped, 0 failed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 09:33:20 +00:00
07fabeb4ed Fix apply primitive for Lambda/VmClosure + Playwright test fixes
The OCaml `apply` primitive only handled NativeFn, causing swap! to
fail in the WASM browser when called with lambda arguments. Extended
to handle all callable types via _sx_call_fn/_sx_trampoline_fn.

Also fixes:
- Pre-existing build errors from int-interned env.bindings migration
  (vm-trace, bytecode-inspect, deps-check, prim-check in sx_server.ml)
- Add #portal-root div to page shell for portal island rendering
- Stepper test scoped to lake area (code-view legitimately shows ~cssx/tw)
- Portal test checks #portal-root instead of #sx-root
- Mark 3 known bugs as test.fixme (event-bridge, resource, isomorphic-nav)

98 passed, 3 skipped, 0 failed.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-28 08:58:48 +00:00
e0070041d6 Add .sxbc s-expression bytecode format
Bytecode modules are now serialized as s-expressions (.sxbc) in addition
to JSON (.sxbc.json). The .sxbc format is the canonical representation —
content-addressable, parseable by the SX parser, and suitable for CID
referencing. Annotation layers (source maps, variable names, tests, docs)
can reference the bytecode CID without polluting the bytecode itself.

Format: (sxbc version hash (code :arity N :bytecode (...) :constants (...)))

The browser loader tries .sxbc first (via load-sxbc kernel primitive),
falls back to .sxbc.json. Caddy needs .sxbc MIME type to serve the new
format (currently 404s, JSON fallback works).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:16:22 +00:00
8d3ab040ef Fix WASM browser: broken links (&rest bytecode) + broken reactive counter (ListRef mutation)
Two bugs fixed:

1. Links: bytecode compiler doesn't handle &rest params — treats them as
   positional, so (first rest) gets a raw string instead of a list.
   Replaced &rest with explicit optional params in all bytecode-compiled
   web SX files (dom-query, dom-add-listener, browser-push-state, etc.).
   The VM already pads missing args with Nil.

2. Reactive counter: signal-remove-sub! used (filter ...) which returns
   immutable List, but signal-add-sub! uses (append!) which only mutates
   ListRef. Subscribers silently vanished after first effect re-run.
   Fixed by adding remove! primitive that mutates ListRef in-place.

Also:
- Added evalVM API to WASM kernel (compile + run through bytecode VM)
- Added scope tracing (scope-push!/pop!/peek/context instrumentation)
- Added Playwright reactive mode for debugging island signal/DOM state
- Replaced cek-call with direct calls in core-signals.sx effect/computed
- Recompiled all 23 bytecode modules

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 14:08:49 +00:00
0699de0144 Fix some primitive: return callback result, not element
List.find returns the element that matched, but SX some should return
the callback's truthy return value. This caused get-verb-info to return
"get" (the verb string) instead of the {method, url} dict.

Also added _active_vm tracking to VM for future HO primitive optimization,
and reverted get-verb-info to use some (no longer needs for-each workaround).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 01:13:52 +00:00
3e6898197d Fix get-verb-info: replace some with for-each to avoid bytecode closure bug
The some HO form passes callbacks through call_sx_fn which creates a new
VM that can't see the enclosing closure's captured variables (el). Replaced
with for-each + mutation which keeps everything in the same VM scope.

Also fixed destructuring param ((verb ...)) → plain param (verb).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 00:52:04 +00:00
c923a34fa8 Fix WASM browser click handlers: 8 bugs, 50 new VM tests
The sx-get links were doing full page refreshes because click handlers
never attached. Root causes: VM frame management bug, missing primitives,
CEK/VM type dispatch mismatch, and silent error swallowing.

Fixes:
- VM frame exhaustion: frames <- [] now properly pops to rest_frames
- length primitive: add alias for len in OCaml primitives
- call_sx_fn: use sx_call directly instead of eval_expr (CEK checks
  for type "lambda" but VmClosure reports "function")
- Boot error surfacing: Sx.init() now has try/catch + failure summary
- Callback error surfacing: catch-all handler for non-Eval_error exceptions
- Silent JIT failures: log before CEK fallback instead of swallowing
- vm→env sync: loadModule now calls sync_vm_to_env()
- sx_build_bytecode MCP tool added for bytecode compilation

Tests: 50 new tests across test-vm.sx and test-vm-primitives.sx covering
nested VM calls, frame integrity, CEK bridge, primitive availability,
cross-module symbol resolution, and callback dispatch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-27 00:37:21 +00:00
00de248ee9 WIP: bytecode module pre-compilation and loading infrastructure
- compile-modules.js: Node.js build tool, all 23 .sx files compile to .sxbc.json
- api_load_module with shared globals (beginModuleLoad/endModuleLoad batch API)
- api_compile_module for runtime compilation
- sx-platform.js: bytecode-first loader with source fallback, JSON deserializer
- Deferred JIT enable (setTimeout after boot)

Known issues:
- WASM browser: loadModule loads but functions not accessible (env writeback
  issue with interned keys)
- WASM browser: compileModule fails ("Not callable: nil" — compile-module
  function from bytecode not working correctly in WASM context)
- Node.js js_of_ocaml: full roundtrip works (compile → load → call)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 17:54:55 +00:00
2802dd99e2 Fix JIT nil-param crash: guard execute-request, restore error logging
- orchestration.sx: add nil guard for verb/url before calling do-fetch
  (prevents "Expected string, got nil" when verb info dict lacks method)
- sx_browser.ml: restore JIT error logging (Eval_error only, not all
  exceptions) so real failures are visible, silence routine fallbacks
- Rebuild WASM bundle with fixes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 17:22:06 +00:00
226c01bbf6 Browser JIT: compile SX lambdas to bytecode VM in WASM kernel
- Wire up jit_call_hook in sx_browser.ml (same pattern as server)
- Deferred JIT: _jit_enabled flag, enabled after boot-init completes
  (prevents "Undefined symbol" errors from compiling during .sx loading)
- enable-jit! native function called by sx-platform.js after boot
- sx-platform.js: async WASM kernel polling + JIT enable after init
- Error logging for JIT compile failures and runtime fallbacks

Performance: 858ms → 431ms (WASM CEK) → 101ms (WASM JIT)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 17:04:39 +00:00
c72a5af04d WIP: pre-existing changes from WASM browser work + test infrastructure
Accumulated changes from WASM browser development sessions:
- sx_runtime.ml: signal subscription + notify, env unwrap tolerance
- sx_browser.bc.js: rebuilt js_of_ocaml browser kernel
- sx_browser.bc.wasm.js + assets: WASM browser kernel build
- sx-platform.js browser tests (test_js, test_platform, test_wasm)
- Playwright sx-inspect.js: interactive page inspector tool
- harness-web.sx: DOM assertion updates
- deploy.sh, Dockerfile, dune-project: build config updates
- test-stepper.sx: stepper unit tests
- reader-macro-demo plan update

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 16:40:38 +00:00
10576f86d1 WASM browser build: interned env keys, async kernel boot, bundled .sx platform
- Symbol interning in sx_types.ml: env lookups use int keys (intern/unintern)
  to avoid repeated string hashing in scope chain walks
- sx-platform.js: poll for SxKernel availability (WASM init is async)
- shell.sx: load sx_browser.bc.wasm.js when SX_USE_WASM=1
- bundle.sh: fix .sx file paths (web-signals.sx rename)
- browser/dune: target byte+js+wasm modes
- Bundle 23 .sx platform files for browser (dom, signals, router, boot, etc.)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 16:37:42 +00:00
5ed984e7e3 Add 5 MCP tools, refactor nav-data, fix deep path bug, fix Playwright failures
Nav refactoring:
- Split nav-data.sx (32 forms) into 6 files: nav-geography, nav-language,
  nav-applications, nav-etc, nav-tools, nav-tree
- Add Tools top-level nav category with SX Tools and Services pages
- New services-tools.sx page documenting the rose-ash-services MCP server

JS build fixes (fixes 5 Playwright failures):
- Wire web/web-signals.sx into JS build (stores, events, resources)
- Add cek-try primitive to JS platform (island hydration error handling)
- Merge PRIMITIVES into getRenderEnv (island env was missing primitives)
- Rename web/signals.sx → web/web-signals.sx to avoid spec/ collision

New MCP tools:
- sx_trace: step-through CEK evaluation showing lookups, calls, returns
- sx_deps: dependency analysis — free symbols + cross-file resolution
- sx_build_manifest: show build contents for JS and OCaml targets
- sx_harness_eval extended: multi-file loading + setup expressions

Deep path bug fix:
- Native OCaml list-replace and navigate bypass CEK callback chain
- Fixes sx_replace_node and sx_read_subtree corruption on paths 6+ deep

Tests: 1478/1478 JS full suite, 91/91 Playwright

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 12:09:22 +00:00
9e079c9c19 Add (cyst) form: isolated reactive subtree that survives parent re-renders
New language feature: (cyst [:key id] body...) creates a DOM container
with its own island scope that persists across parent reactive re-renders.
On first render, the body is evaluated in a fresh with-island-scope and
the resulting DOM is cached. On subsequent renders, the cached DOM node
is returned if still connected to the document.

This solves the fundamental problem of nesting reactive islands inside
other islands' render trees — the child island's DOM (with its event
handlers and signal subscriptions) survives when the parent re-renders.

Implementation: *memo-cache* dict keyed by cyst id. render-dom checks
isConnected before returning cached node. Each cyst gets its own
disposer list via with-island-scope.

Usage in sx-tools: defisland render preview now wrapped in (cyst :key
full-name ...). Real mouse clicks work — counter increments, temperature
converts, computed signals update. Verified on both local and live site.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 08:13:27 +00:00
b53a0fabea Inline test runner: 5/5 temperature converter tests passing
Fixed three fundamental issues:
1. cek-try arg passing: handler was called with raw string instead of
   (List [String msg]), causing "lambda expects 1 args, got N" errors
2. Silent island hydration failures: hydrate-island now wraps body
   render in cek-try, displaying red error box with stack trace instead
   of empty div. No more silent failures.
3. swap! thunk leak: apply result wasn't trampolined, storing thunks
   as signal values instead of evaluated results

Also fixed: assert= uses = instead of equal? for value comparison,
assert-signal-value uses deref instead of signal-value, HTML entity
decoding in script tag test source via host-call replaceAll.

Temperature converter demo page now shows live test results:
  ✓ initial celsius is 20
  ✓ computed fahrenheit = celsius * 1.8 + 32
  ✓ +5 increments celsius
  ✓ fahrenheit updates on celsius change
  ✓ multiple clicks accumulate

1116/1116 OCaml tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 01:51:30 +00:00
b104663481 Split signals: core spec (spec/signals.sx) + web extensions (web/signals.sx)
Core reactive primitives (signal, deref, reset!, swap!, computed, effect,
batch, notify-subscribers, dispose-computed, with-island-scope,
register-in-scope) moved to spec/signals.sx — pure SX, zero platform
dependencies. Usable by any host: web, CLI, embedded, server, harness.

Web extensions (marsh scopes, stores, event bridge, resource) remain in
web/signals.sx, which now depends on spec/signals.sx.

Updated all load paths:
- hosts/ocaml/bin/sx_server.ml — loads spec/signals.sx before web/signals.sx
- hosts/ocaml/bin/run_tests.ml — loads both in order
- hosts/ocaml/browser/bundle.sh + sx-platform.js — loads core-signals.sx first
- shared/sx/ocaml_bridge.py — loads spec/signals.sx before web extensions

1116/1116 OCaml tests pass. Browser reactive island preview works.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-26 00:23:35 +00:00
4b733e71b0 Reactive expressions: auto-wrap deref-containing exprs in computed signals
Added contains-deref? predicate to adapter-dom.sx. When rendering a text
expression that contains (deref ...) inside an island scope, the adapter
now wraps it in (reactive-text (computed (fn () (eval-expr expr env)))).
This tracks signal dependencies through arbitrary expressions like
(str (deref celsius) "°C") and (+ (* (deref celsius) 1.8) 32).

Previously only bare (deref sig) was reactive. Now compound expressions
like string interpolation and arithmetic over signals update in real
time. The temperature converter preview in sx-tools is fully reactive:
clicking +5/-5 updates both °C and °F displays live.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 23:59:03 +00:00
6f96452f70 Fix empty code blocks: rename ~docs/code param, fix batched IO dispatch
Two bugs caused code blocks to render empty across the site:

1. ~docs/code component had parameter named `code` which collided with
   the HTML <code> tag name. Renamed to `src` and updated all 57
   callers. Added font-mono class for explicit monospace.

2. Batched IO dispatch in ocaml_bridge.py only skipped one leading
   number (batch ID) but the format has two (epoch + ID):
   (io-request EPOCH ID "name" args...). Changed to skip all leading
   numbers so the string name is correctly found. This fixes highlight
   and other batchable helpers returning empty results.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 18:08:40 +00:00
1777f631a5 Merge sx-pub branch into ocaml-vm
Brings in sx-pub federated publishing protocol (Phases 1-4):
- DB models, IPFS publishing, federation, anchoring
- Live dashboard UI on the plan page
- Dev infrastructure (docker-compose, dev-pub.sh)

Conflicts: sx-browser.js (kept ocaml-vm rebuild), sx-pub.sx (kept sx-pub version with dashboard)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 16:37:04 +00:00
9f0c541872 Fix component body serialization: capture ALL body expressions
defcomp/defisland with multi-expression bodies (let, letrec,
freeze-scope, effect) had only the LAST expression stored as body.
The browser received a truncated defisland missing let/letrec/signal
bindings, causing "Undefined symbol: code-tokens" on hydration.

Fix: body_exprs = expr[body_start:], wrapped in (begin ...) if
multiple. Also clear stale pickle cache on code changes.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 16:27:33 +00:00
3e80f371da Fix _os → os in jinja_bridge.py hot reload
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 15:56:45 +00:00
31ed8b20f4 Remove click buffer, add CSS cursor:pointer for island controls
The click buffer (capture + stopPropagation + replay) caused more
harm than good: synchronous XHR blocks the main thread during kernel
load, so there's no window where clicks can be captured. The buffer
was eating clicks after hydration due to property name mismatches.

Replace with pure CSS: buttons/links/[role=button] inside islands
get cursor:pointer from SSR. No JS needed, works immediately.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 15:50:12 +00:00
27059c0581 Pending pulse animation for pre-hydration clicks
Buttons clicked before hydration get a subtle pulse animation
(sx-pending class) showing the click was captured. The animation
is removed when the click is replayed after hydration, or cleared
on boot completion as a fallback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 15:49:02 +00:00
8aecbcc094 Fix click buffering: use correct hydration property name
The event buffer script checked _sxBoundislandHydrated (camelCase)
but mark-processed! sets _sxBoundisland-hydrated (with hyphen).
The mismatch meant stopPropagation() fired on EVERY click, killing
all island button handlers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 15:30:57 +00:00
ebbdec8f4c Fix orchestration.sx parse error, add parser line/col diagnostics
The parser was reporting "Unexpected char: )" with no position info.
Added line number, column, and byte position to all parse errors.

Root cause: bind-sse-swap had one extra close paren that naive paren
counting missed because a "(" exists inside a string literal on L1074
(starts-with? trimmed "("). Parse-aware counting (skipping strings
and comments) correctly identified the imbalance.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 15:29:28 +00:00
f0f16d24bc Fix bridge newline escaping, stepper optimization, dom-listen dedup
- ocaml_sync.py: escape newlines in eval/load_source to prevent
  protocol desync (bridge crashed on any multi-line SX)
- Stepper: do-back uses rebuild-preview (O(1) render) instead of
  replaying all steps. Hydration effect same. Cookie save on button
  click only.
- dom.sx: remove duplicate dom-listen (was shadowing the one at
  line 351 that adapter-dom.sx's dom-on wraps)
- orchestration.sx: fix bind-sse-swap close paren count
- safe_eq: Dict equality via __host_handle for DOM node identity

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 15:14:10 +00:00
fb8dbeba9f Fix dom-listen: rename dom-on to dom-listen in dom.sx
adapter-dom.sx defines dom-on as a wrapper around dom-listen (adds
post-render hooks). But dom-listen was never defined — my earlier
dom-on in dom.sx was overwritten by the adapter's version. Rename
to dom-listen so the adapter's dom-on can call it.

This fixes click handlers not firing on island buttons (stepper,
stopwatch, counter, etc.).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 14:56:34 +00:00
0c8c0b6426 Cache-bust .sx files, optimize stepper back/hydration
Platform:
- sx-platform.js: extract ?v= query from script tag URL, append to
  all .sx file XHR requests. Prevents stale cached .sx files.

Stepper performance:
- do-back: use rebuild-preview (pure SX→DOM render) instead of
  replaying every do-step from 0. O(1) instead of O(n).
- Hydration effect: same rebuild-preview instead of step replay.
- Cookie save moved from do-step to button on-click handlers only.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 14:54:43 +00:00
1a3ee40e0d Event buffering during hydration gap
Clicks on island elements before hydration completes are captured
and replayed after boot finishes:

- shell.sx: inline script (capture phase) buffers clicks on
  [data-sx-island] elements that aren't hydrated yet into window._sxQ
- boot.sx: after hydration + process-elements, replays buffered clicks
  by calling target.click() on elements still connected to the DOM

This makes SSR islands feel interactive immediately — the user can
click a button while the SX kernel is still loading/hydrating, and
the action fires as soon as the handler is wired up.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 14:45:04 +00:00
998536f52d Cache-bust wasm scripts, fix orchestration.sx paren balance
- Add wasm_hash (MD5 of sx_browser.bc.js) to shell template
- Script tags: /wasm/sx_browser.bc.js?v={hash}, /wasm/sx-platform.js?v={hash}
- Pass wasm_hash through helpers.py and ocaml_bridge.py
- Fix missing close paren in bind-sse-swap (broke SX parsing)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 14:21:51 +00:00
1e42eb62a2 Fix create-text-node in DOM adapter: host handle Dicts are DOM nodes
The DOM adapter treated all Dict values as empty (create-fragment).
But DOM nodes (text nodes, elements) from create-text-node/host-call
are wrapped as Dict { __host_handle: N } by js_of_ocaml. Now checks
for __host_handle and passes them through as DOM nodes.

Fixes stopwatch button text ("Start") and timer display ("0.0s")
which were missing because create-text-node results were discarded.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 14:10:28 +00:00
eacde62806 Fix navigation: outerHTML swap, island markers, host handle equality, dispose
Navigation pipeline now works end-to-end:
- outerHTML swap uses dom-replace-child instead of morph-node (morph has
  a CEK continuation issue with nested for-each that needs separate fix)
- swap-dom-nodes returns the new element for outerHTML so post-swap
  hydrates the correct (new) DOM, not the detached old element
- sx-render uses marker mode: islands rendered as empty span[data-sx-island]
  markers, hydrated by post-swap. Prevents duplicate content from island
  body expansion + SX response nav rows.
- dispose-island (singular) called on old island before morph, not just
  dispose-islands-in (which only disposes sub-islands)

OCaml runtime:
- safe_eq: Dict equality checks __host_handle for DOM node identity
  (js_to_value creates new Dict wrappers per call, breaking physical ==)
- contains?: same host handle check
- to_string: trampoline thunks (fixes <thunk> display)
- as_number: trampoline thunks (fixes arithmetic on leaked thunks)

DOM platform:
- dom-remove, dom-attr-list (name/value pairs), dom-child-list (SX list),
  dom-is-active-element?, dom-is-input-element?, dom-is-child-of?, dom-on

All 5 reactive-nav Playwright tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 13:19:29 +00:00
07bbcaf1bb OCaml VM browser: safe equality, thunk trampolining, platform functions, nav pipeline
Core runtime fixes:
- Safe equality (=, !=): physical equality for dicts/lambdas/signals,
  structural only for acyclic types. Prevents infinite loops on circular
  signal subscriber chains.
- contains?: same safe comparison (physical first, structural for simple types)
- Thunk trampolining in as_number and to_string: leaked thunks auto-resolve
  instead of showing <thunk> or erroring "Expected number, got thunk"
- Diagnostic first error: shows actual type received

Island hydration fixes:
- adapter-dom.sx: skip scope-emit for spreads inside islands (was tripling classes)
- schedule-idle: wrap callback to absorb requestIdleCallback deadline arg
- home-stepper: remove spread-specific highlighting (all tokens same style per step)

Platform functions (boot-helpers.sx):
- fetch-request: 3-arg interface (config, success-fn, error-fn) with promise chain
- build-request-body: form serialization for GET/POST
- strip-component-scripts / extract-response-css: SX text processing
- Navigation: bind-boost-link, bind-client-route-click via execute-request
- Loading state: show-indicator, disable-elements, clear-loading-state
- DOM extras: dom-remove, dom-attr-list (name/value pairs), dom-child-list (SX list),
  dom-is-active-element?, dom-is-input-element?, dom-is-child-of?, dom-on,
  dom-parse-html-document, dom-body-inner-html, create-script-clone
- All remaining stubs: csrf-token, loaded-component-names, observe-intersection,
  event-source-connect/listen, with-transition, cross-origin?, etc.

Navigation pipeline:
- browser-push-state/replace-state: accept 1-arg (URL only) or 3-arg
- boot.sx: wire popstate listener to handle-popstate
- URL updates working via handle-history + pushState fix

Morph debugging (WIP):
- dom-child-list returns proper SX list (was JS Array)
- dom-query accepts optional root element for scoped queries
- Navigation fetches and renders SX responses, URL updates, but morph
  doesn't replace content div (investigating dom-child-list on new elements)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 12:57:24 +00:00