Commit Graph

1558 Commits

Author SHA1 Message Date
4f02f82f4e HS parser: fix number+comparison keyword collision, eval-hs uses hs-compile
Parser: skip unit suffix when next ident is a comparison keyword
(starts, ends, contains, matches, is, does, in, precedes, follows).
Fixes "123 starts with '12'" returning "123starts" instead of true.

eval-hs: use hs-compile directly instead of hs-to-sx-from-source with
"return " prefix, which was causing the parser to consume the comparison
as a string suffix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 11:29:01 +00:00
a93e5924df HS tests: add eval-hs helper, fix no/mathOperator/evalStatically suites
- eval-hs: new test helper that compiles+evaluates a HS expression and
  returns its result. Uses hs-to-sx-from-source with "return " prefix.
- Generator now emits eval-hs calls for expression-only tests
- no suite: 4/5 pass (was 0/5)
- evalStatically: 5/8 pass (was 0/8 stubs)
- pick: 7/7 pass (was 0/7 stubs)
- mathOperator: 3/5 pass (type issues on array concat)

477/831 (57.4%), +69 from session baseline of 408.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 07:34:08 +00:00
d6ae303db3 HS test generator: convert pick, evalStatically, run+evaluate patterns
New generator patterns:
- run() with {locals: {x: val}} + evaluate(window.X) + expect().toEqual()
  → (let ((x val)) (eval-hs "expr") (assert= it expected))
- evaluate(() => _hyperscript.parse("X").evalStatically()).toBe(val)
  → (assert= (eval-hs "X") val)
- toContain/toHaveLength assertions

Converts 12 tests from NOT IMPLEMENTED stubs (43→31 remaining):
- pick: 7/7 now pass (was 0/7 stubs)
- evalStatically: 5/8 now pass (was 0/8 stubs)

449/831 (54%), +12 from generator improvements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 07:12:24 +00:00
745e78ab05 HS parser: 'does not start/end with' negation support
Parser now handles 'does not start with' and 'does not end with'
comparison operators, compiling to (not (starts-with? ...)) and
(not (ends-with? ...)) respectively.

Test runner: host-set!/host-get stringify innerHTML/textContent.

437/831 (52.6%) — parser fix doesn't change count yet (comparison tests
use 'is a' type checks which need separate fix).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 20:19:33 +00:00
8bf874c50c HS tests: stringify innerHTML/textContent in mock DOM, fix type mismatches
host-set! now stringifies values for innerHTML/textContent properties.
host-get returns string for innerHTML/textContent/value/className.
Fixes "Expected X, got X" type mismatch failures where number 22 != string "22".

437/831 (52.6%), +20 tests from stringify fix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 20:03:55 +00:00
e5e3e90ee7 HS compiler: emit-set handles @attr of target expressions
Adds attribute reference case to the 'of' branch in emit-set:
(set @bar of #div2 to "foo") now compiles to (dom-set-attr target "bar" "foo")
instead of falling through to the broken (set! (host-get ...)) catchall.

417/831 (50.2%), +2 from attr-of fix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 19:47:30 +00:00
b1666a5fe2 HS tests: VM step limit fix, callFn error propagation, compiler emit-set fixes
- sx_vm.ml: VM timeout now compares vm_insn_count > step_limit instead of
  unconditionally throwing after 65536 instructions when limit > 0
- sx_browser.ml: Expose setStepLimit/resetStepCount APIs on SxKernel;
  callFn now returns {__sx_error, message} on Eval_error instead of null
- compiler.sx: emit-set handles array-index targets (host-set! instead of
  nth) and 'of' property chains (dom-set-prop with chain navigation)
- hs-run-fast.js: New Node.js test runner with step-limit timeouts,
  SX-level guard for error detection, insertAdjacentHTML mock,
  range selection (HS_START/HS_END), wall-clock timeout in driveAsync
- hs-debug-test.js: Single-test debugger with DOM state inspection
- hs-verify.js: Assertion verification (proves pass/fail detection works)

Test results: 415/831 (50%), up from 408/831 (49%) baseline.
Fixes: set my style["color"], set X of Y, put at end of (insertAdjacentHTML).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 19:27:03 +00:00
b81c26c45b HS tests: sync textContent when innerHTML is set
When innerHTML is set on a mock element, textContent now updates to
match (with HTML tags stripped). Many HS tests do `put "foo" into me`
(which sets innerHTML) then check textContent. Previously textContent
stayed empty because only innerHTML was updated.

Also fixes innerHTML="" to fully detach children from parent.

393 → 408/831 HS tests (+15).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 12:58:23 +00:00
23e8379622 HS tests: innerHTML/textContent clears children in mock DOM
Setting innerHTML="" on a mock element now detaches and removes all
children, matching browser behavior. Previously hs-cleanup! (which
sets body.innerHTML="") left stale children attached, causing
querySelector to find elements from prior tests.

Also clears children when textContent is set (browser behavior).

375 → 393/831 HS tests (+18).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 12:47:34 +00:00
a6eb125dcc HS tests: stringify DOM properties (innerHTML, textContent, value)
In a real browser, innerHTML/textContent/value are always strings.
The mock was storing raw SX values (Number, Bool, Nil), causing type
mismatches like "Expected 1, got 1" where the value was correct but
Number 1.0 != String "1".

Now coerces to string on host-set! for innerHTML, textContent, value,
outerHTML, innerText. Fixes 10 increment tests that were doing
`put value into me` with numeric results.

367 → 375/831 HS tests (+8 net, +10 new passes, -2 regressions).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 12:38:33 +00:00
e3eb46d0dc HS tests: SIGALRM + raise timeout for native OCaml loops
The infinite loops in the HS parser are in transpiled native OCaml code,
not in the VM or CEK step loop. Neither step counters (in cek_step_loop,
cek_step, trampoline) nor VM instruction checks caught them because
the loops are in direct OCaml recursion.

Fix: SIGALRM handler raises Eval_error to break out of native loops.
Also sets step_limit flag to catch VM loops. Combined approach handles
both native OCaml recursion (alarm+raise) and VM bytecode (step check).

The alarm+raise can become unreliable after ~13 timeouts in a single
process, but handles the common case well. Reverts the fork-based
approach which lost inter-test state.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 11:57:33 +00:00
3d7fffe4eb HS tests: host-get method truthiness + fork-based test timeout
Two critical fixes for the mock DOM test runner:

1. host-get returns truthy for DOM method names on mock elements.
   dom.sx guards like `(and el (host-get el "setAttribute"))` were
   silently skipping setAttribute/getAttribute calls because the mock
   dict had no "setAttribute" key. Now returns Bool true for known
   DOM method names, fixing hs-activate! → dom-set-attr → dom-get-attr
   chain. Also adds firstElementChild, nextElementSibling, etc. as
   computed properties.

2. Fork-based per-test timeout (5 seconds). The HS parser has infinite
   loops on certain syntax ([@attr], complex put targets). Signal-based
   alarm doesn't work reliably in OCaml 5. Fork + waitpid + select
   gives hard OS-level timeout protection.

Also adds step_limit/step_count to sx_ref.ml trampoline (currently
unused but available for future CEK-level timeout).

Result: 525/963 total, up from 498. Many more add/remove/toggle/set
tests now pass because hs-activate! actually wires up event handlers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 11:04:03 +00:00
1d83ccba3c Content-addressed on-demand loading: Merkle DAG for all browser assets
Replace the monolithic 500KB <script data-components> block with a 25KB
JSON manifest mapping names to content hashes. Every definition —
components, islands, macros, client libraries, bytecode modules, and
WASM binaries — is now content-addressed and loaded on demand.

Server (sx_server.ml):
- build_hash_index: Merkle DAG over all definitions — topological sort,
  hash leaves first, component refs become @h:{hash} in instantiated form
- /sx/h/{hash} endpoint: serves definitions with Cache-Control: immutable
- Per-page manifest in <script data-sx-manifest> with defs + modules + boot
- Client library .sx files hashed as whole units (tw.sx, tw-layout.sx, etc.)
- .sxbc modules and WASM kernel hashed individually

Browser (sx-platform.js):
- Content-addressed boot: inline script loads kernel + platform by hash
- loadDefinitionByHash: recursive dep resolution with @h: rewriting
- resolveHash: 3-tier cache (memory → localStorage → fetch /sx/h/{hash})
- __resolve-symbol extended for manifest-based component + library loading
- Cache API wrapper intercepts .wasm fetches for offline caching
- Eager pre-loading of plain symbol deps for CEK evaluator compatibility

Shell template (shell.sx):
- Monolithic <script data-components> removed
- data-sx-manifest script with full hash manifest
- Inline bootstrap replaces <script src="...?v="> with CID-based loading

Second visit loads zero bytes from network. Changed content gets a new
hash — only that item refetched (Merkle propagation).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 10:14:39 +00:00
2cba359fdf HS behavioral tests: mock DOM + eval-hs in OCaml test runner
Add mock DOM layer to run_tests.ml so hyperscript behavioral tests
(spec/tests/test-hyperscript-behavioral.sx) can run in the OCaml test
runner without a browser. Previously these tests required Playwright
which crashed after 10 minutes from WASM page reboots.

Mock DOM implementation:
- host-global, host-get, host-set!, host-call, host-new, host-callback,
  host-typeof, host-await — OCaml primitives operating on SX Dict elements
- Mock elements with classList, style, attributes, event dispatch + bubbling
- querySelector/querySelectorAll with #id, .class, tag, [attr] selectors
- Load web/lib/dom.sx and web/lib/browser.sx for dom-* wrappers
- eval-hs function for expression-only tests (comparisonOperator, etc.)

Result: 367/831 HS tests pass in ~30 seconds (was: Playwright crash).
14 suites at 100%: live, component, liveTemplate, scroll, call, go,
focus, log, reactive-properties, resize, measure, attributeRef,
objectLiteral, queryRef.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 10:03:26 +00:00
d42717d4b9 HS: route hide through hs-hide! runtime (dialog/details support)
Mirrors hs-show! pattern — dialog calls close(), details sets open=false.
No test count change (custom strategy tests need behavior system).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 11:29:54 +00:00
75f1c04559 HS: show command handles dialogs/details — dialog 10/10 complete, 435→437
- show compiler: emit hs-show! runtime call instead of direct dom-set-style
- hs-show! runtime: dialog → showModal(), details → open=true, else display/opacity/visibility
- dialog category fully passing (was 1/10)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 11:19:08 +00:00
fb93aaaa8c HS: open/close commands for dialog/details — 428→435
- Parser: open/close commands with optional target (defaults to me)
- Compiler: open-element → hs-open!, close-element → hs-close!
- Runtime: hs-open! calls showModal() for dialogs, sets open=true for details
- Runtime: hs-close! calls close() for dialogs, sets open=false for details
- dialog: 1/10 → 8/10

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 11:10:17 +00:00
49afef6eef Add dom-visible?, json-stringify; fix Boolean coerce — 427→428
- dom-visible?: check element display != none (web/lib/dom.sx)
- json-stringify: JSON.stringify via host-call (web/lib/browser.sx)
- hs-coerce Boolean: use hs-falsy? for JS-compatible truthiness

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 10:45:59 +00:00
eb060ef32c Fix <vm:anon> display: move effect to _eff let binding
The effect form returns a VM closure (disposer) which the island DOM
renderer displayed as text. Moving it to a let binding (_eff) captures
the return value without rendering it.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 10:25:58 +00:00
d938682469 HS runtime: fix Boolean coercion to use hs-falsy? — 426→427
as Boolean now uses hs-falsy? for JS-compatible truthiness (0, "", nil, false → false)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 10:24:39 +00:00
4cac08d56f HS: contains/matches ignoring case support — 425→426
- Parser: contains/matches with ignoring case modifier
- Compiler: contains-ignore-case? → hs-contains-ignore-case?
- Compiler: matches-ignore-case? → hs-matches-ignore-case?
- Runtime: downcase-based case-insensitive contains/matches

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 09:45:57 +00:00
c05d8788c7 HS parser: is/is-not ignoring case, eq-ignore-case runtime — 423→425
- Parse `is X ignoring case` → (eq-ignore-case left right)
- Parse `is not X ignoring case` → (not (eq-ignore-case left right))
- Compiler: eq-ignore-case → hs-eq-ignore-case
- Runtime: hs-eq-ignore-case using downcase/str

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 09:38:12 +00:00
eaf3c88a36 HS runtime: empty/swap/compound events, host-set! fix — 403→423 (51%)
- Fix host-set → host-set! in emit-inc/emit-dec (increment/decrement properties)
- Implement empty/clear command: parser dispatch, compiler, polymorphic runtime
- Implement swap command: parser dispatch, compiler (let+do temp swap pattern)
- Add parse-compound-event-name: joins dot/colon tokens (example.event, htmx:load)
- Add hs-compile to source parser (was only in WASM deploy copy)
- Add clear/swap to tokenizer keywords and cmd-kw? list
- Generator: fix run() with extra args, String.raw support

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 09:17:43 +00:00
e2fe070dd4 Fix :ref callback bug in adapter-dom — Pretext island fully working
Root cause: adapter-dom.sx line 345 handled :ref by calling
(dict-set! attr-val "current" el), assuming React-style ref objects.
Callback-style refs (fn (el) ...) passed a function, not a dict,
causing dict-set! to fail with "dict key val" error.

Fix: (if (callable? attr-val) (attr-val el) (dict-set! attr-val "current" el))
Supports both callback refs and dict refs.

Pretext island now fully working:
- 3 controls: width slider, font size slider, algorithm toggle
- Knuth-Plass + greedy line breaking via bytecode-compiled library
- canvas.measureText for pixel-perfect browser font metrics
- Effect-based imperative DOM rendering (createElement + appendChild)
- Reactive: slider drag → re-measure → re-break → re-render

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 08:26:48 +00:00
e12ddefdff Isolate island :ref hydration bug: dict-set!/reduce error
Root cause identified: :ref attribute on DOM elements inside defisland
triggers dict-set!/reduce error in WASM kernel hydration system.

Minimal repro:
  (defisland ~test ()
    (let ((el-ref (signal nil)))
      (div (div :ref (fn (el) (reset! el-ref el)) ""))))
  → "dict-set!: dict key val (in reduce → reduce → for-each)"

Without :ref: works perfectly (signals, effects, canvas FFI,
break-lines, pretext-layout-lines all functional).

Working version: full Pretext with 3 controls + effect + layout
computation, outputs text via (deref result). 34 disposers, no error.
Just needs :ref fix to add DOM rendering.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 08:01:16 +00:00
da0da1472d Test generator: nested HTML elements, three-phase element setup
- parse_html now captures ALL elements (not just top-level) with
  parent-child relationships
- emit_element_setup uses three phases: attributes, DOM tree, activation
- ref() maps positional names (d1, d2) to top-level elements only
- dom-scope: 9→14 (+5), reset: 3→6 (+3), take: 2→3, parser: 2→3

Net 0 due to regressions in dialog/halt/closest (needs investigation).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 01:20:53 +00:00
e5293e4e03 Test generator: inner text content, assert= arg order fix
- Capture leaf element text content (e.g., <div>3</div> sets innerHTML "3")
- Fix assert= argument order: (actual expected) matches SX harness convention
- put: 17→19, empty: 6→4 (inner text reveals empty command not implemented)

402 → 403/831 (+1)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 23:34:25 +00:00
429c2b59f9 Hyperscript test generator: repeat loop fix, assert= arg order, quote handling
- Don't insert 'then' inside for-in loop bodies or after 'repeat N times'
  (fixes repeat from 1/30 → 5/30)
- Allow HS sources ending with " when they don't contain embedded HTML
  (fixes set from 6/25 → 10/25, enables 18 previously-skipped tests)
- Fix assert= argument order: (actual expected), not (expected actual)
  (error messages now correctly report Expected/Got)

395 → 402/831 (+7)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 22:51:20 +00:00
5948741fb6 Working Pretext island: effect + canvas + break-lines + layout
Isolated the dict-set!/reduce error to complex island body parsing,
not the reactive system or library functions. Proven working:
- break-lines inside effect ✓
- canvas.measureText inside effect ✓
- pretext-layout-lines inside effect ✓
- signal + slider + reactive update ✓

The error triggers only with large island bodies (many ~tw spreads,
nested controls). This is a component definition parser bug in the
WASM kernel, not a Pretext or reactive system issue.

Current island: minimal working version with effect-based layout,
slider control, and innerHTML rendering. Ready for incremental
expansion once the parser size limit is identified.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 21:38:47 +00:00
564e344961 Add computed+HO tests, remove duplicate pretext-layout-lines define
- 7 new tests in computed-ho-forms suite: computed with map, reduce,
  for-each, nested map, dict creation, signal updates. All pass on
  OCaml and WASM sandbox.
- Removed standalone pretext-position-line and pretext-layout-lines
  from pretext-demo.sx — now in text-layout library only
- Root cause of island error: pretext-demo.sx had old define with
  (reduce + 0 lwid) that the server serialized into component defs,
  overriding the library's sum-loop version

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 20:00:53 +00:00
1884c28763 Fix browser compat: sublist replaces 3-arg slice, manual sum replaces reduce
- Added sublist helper (portable list extraction, avoids 3-arg slice
  which fails in browser WASM kernel)
- Replaced reduce + 0 lwid with manual sum loop (reduce has browser
  compat issues with dict-set! error in call stack)
- Imperative DOM update via effect for clean paragraph re-rendering
  on signal changes (clear container, create new spans)
- String slice in hyphenate-word kept (works on strings)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 18:31:34 +00:00
13f24e5f26 Fix Pretext island reactivity: deref inside DOM tree, not let binding
The (let ((lines (deref layout))) ...) pattern captured the layout value
once at island initialization. Replacing with (deref layout) inline in the
DOM expressions makes the reactive system track the dependency and
re-render when signals change.

Sliders and algorithm toggle now trigger layout recomputation and DOM
update. Remaining: reactive DOM patching for absolutely-positioned spans
creates visual artifacts (old spans persist). Needs keyed list or full
container replacement.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 18:08:45 +00:00
e71e74941e Hyperscript: remove/tell/transition commands, test generator ref() fix
Parser: remove me/[@attr]/{css}, tell body scoping (skip then),
transition from/to syntax + my/style prefixes.
Compiler: remove-element, remove-attr, remove-css, transition-from.
Runtime: hs-transition-from for from/to CSS transitions.
Generator changes (already committed) fix ref() unnamed-first mapping,
assertion dedup for pre/post pairs, on-event then insertion.

Conformance: 374→395 (+21 tests, 48%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 18:03:56 +00:00
7ec42386fb Fix Pretext island: library functions inside define-library begin block
Root cause: sx_insert_near placed break-lines-greedy, pretext-position-line,
pretext-layout-lines OUTSIDE the define-library begin block. The bytecode
compiler only compiles forms inside begin as STORE_GLOBAL — forms outside
are invisible to the browser VM.

Fix: moved all function definitions inside (begin ...) of (define-library).
Bytecode now includes all 17 functions (11K compiled, was 9K).

Browser load-sxbc: simplified VmSuspended handling — just catch and
continue, since STORE_GLOBAL ops already ran before the import OP_PERFORM.
sync_vm_to_env copies them to global_env.

Island now calls break-lines and pretext-layout-lines from bytecode-compiled
library — runs on VM, not CEK interpreter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 17:53:50 +00:00
45209caf73 Fix Pretext client island: inlined greedy layout, avoid slice/import issues
- Greedy line breaking inlined (avoids 3-arg slice browser issue)
- Manual word extraction via for-each+append! instead of slice
- Browser load-sxbc: handle VmSuspended + copy library registry exports
- TODO: Knuth-Plass on bytecode VM when define-library export propagation
  is fixed (compiler strips library wrapper → STORE_GLOBAL works, but
  import OP_PERFORM suspends before sync_vm_to_env copies globals)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 17:09:39 +00:00
699dd5ad69 Step 17b: bytecode-compiled text-layout, WASM library import fix
- text-layout.sx added to WASM bytecode pipeline (9K compiled)
- Fix multi-list map calls (map-indexed + nth instead of map fn list1 list2)
- pretext-layout-lines and pretext-position-line moved to library exports
- Browser load-sxbc: handle VmSuspended for import, copy library exports
  to global_env after module load (define-library export fix)
- compile-modules.js: text-layout in SOURCE_MAP, FILES, and entry deps
- Island uses library functions (break-lines, pretext-layout-lines)
  instead of inlining — runs on bytecode VM when exports resolve

Known issue: define-library exports don't propagate to browser global env
yet. The load-sxbc import suspension handler resumes correctly but
bind_import_set doesn't fire. Needs deeper investigation into how the
WASM kernel's define-library registers exports vs how other libraries
(adapter-html, tw) make their exports available.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 16:37:04 +00:00
676ec6dd2b Fix Pretext island: inline layout functions, div placeholder for hydration
- Move all layout functions inside defisland body (browser can't access
  top-level defines from component defs bundle)
- Use div placeholder with data-sx-island attr (matches island root tag)
- Rename pretext-island.sx → pretext-client.sx for alphabetical load order

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 15:42:54 +00:00
498f1a33b6 Step 17b: client-side Pretext island with live controls
defisland ~pretext-demo/live — same Knuth-Plass algorithm running in
the browser with canvas.measureText for pixel-perfect font metrics.

- Width slider (200-700px), font size slider (10-24px)
- Greedy vs Knuth-Plass toggle button
- Reactive re-layout on every control change
- All layout functions inlined in the island (no library deps)
- Perfectly straight right edges — browser measures AND renders

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 15:34:15 +00:00
1eadefd0c1 Step 17b: Pretext — DOM-free text layout with otfm font measurement
Pure SX text layout library with one IO boundary (text-measure perform).
Knuth-Plass optimal line breaking, Liang's hyphenation, position calculation.

Library (lib/text-layout.sx):
- break-lines: Knuth-Plass DP over word widths
- break-lines-greedy: simple word-wrap for comparison
- hyphenate-word: Liang's trie algorithm
- position-line/position-lines: running x/y sums
- measure-text: single perform (text-measure IO)

Server font measurement (otfm):
- Reads OpenType cmap + hmtx tables from .ttf files
- DejaVu Serif/Sans bundled in shared/static/fonts/
- _cek_io_resolver hook: perform works inside aser/eval_expr
- JIT VM suspension inline resolution for IO in compiled code

~font component (shared/sx/templates/font.sx):
- Works like ~tw: emits @font-face CSS via cssx scope
- Sets font-family on parent via spread
- Deduplicates font declarations

Infrastructure fixes:
- stdin load command: per-expression error handling (was aborting on first error)
- cek_run IO hook: _cek_io_resolver in sx_types.ml
- JIT VmSuspended: inline IO resolution when resolver installed
- ListRef handling in IO resolver (perform creates ListRef, not List)

Demo page at /sx/(applications.(pretext)):
- Hero: justified paragraph with otfm-measured proportional widths
- Greedy vs Knuth-Plass side-by-side comparison
- Badness scoring visualization
- Hyphenation syllable decomposition

25 new tests (spec/tests/test-text-layout.sx), 3201/3201 passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 15:13:00 +00:00
f60d22e86e Hyperscript: focus command, diagnostic test output, blur keyword
Parser/compiler/runtime for focus command. Tokenizer: focus, blur,
precedes, follows, ignoring, case keywords. Test spec: per-test
failure output for diagnosis.

374/831 (45%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 12:38:05 +00:00
1783f4805a Fix streaming resolveSuspense: use callFn instead of eval string interpolation
The previous K.eval() approach double-escaped backslashes in SX source
strings, breaking the \/ → / unescaping that the server serializer adds
for HTML safety. Using K.callFn() passes strings directly as arguments,
bypassing the escaping problem entirely.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 12:35:37 +00:00
7d798be14f Hyperscript: precedes/follows comparisons, tokenizer keywords
Parser: precedes/follows comparison operators in parse-cmp.
Tokenizer: precedes, follows, ignoring, case keywords.
Runtime: precedes?, follows? string comparison functions.

372/831 (45%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 12:20:13 +00:00
ae32254dfb Hyperscript: hide/show strategy (opacity/visibility), add/remove query-all
Parser: hide/show handle `with opacity/visibility/display` strategy
and properly detect target vs command boundaries. Compiler: emit
correct CSS property per strategy, add-class/remove-class use
for-each+query-all for class selectors. Runtime: hs-query-all uses
dom-body, hs-each helper for collection iteration.

Generator: inline run().toEqual() pattern for eval-only tests.

372/831 (45%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 12:07:06 +00:00
854ed9c027 Hyperscript conformance: 372→373 — hide/show strategy, generator toEqual
Parser: hide/show handle `with opacity/visibility/display` strategy,
target detection for then-less chaining (add/remove/set/put as boundary).
Generator: inline run().toEqual([...]) pattern for eval-only tests.
Compiler: hide/show emit correct CSS property per strategy.

373/831 (45%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 11:42:28 +00:00
3dbbe7e1d1 Hyperscript conformance: 341→372 (45%) — parser, compiler, runtime, generator
Parser: increment/decrement "by N", then-less command chaining, scroll/select/
reset/default/halt commands, toggle style/attr/between, repeat for-loop
delegation, number fix for repeat N times, take with from/for scope.

Compiler: emit-inc/emit-dec with amount + property/style targets, 12 new
dispatch entries (scroll, select, reset, default, halt, toggle-style,
toggle-style-between, toggle-attr, toggle-attr-between, take rewrite).

Runtime: hs-scroll!, hs-halt!, hs-select!, hs-reset!, hs-query-all,
hs-toggle-style!, hs-toggle-style-between!, hs-toggle-attr!,
hs-toggle-attr-between!, hs-take! rewrite with kind/name/scope.

Generator: handle backtick strings, two-line run()/expect() patterns,
toEqual with arrays, toThrow — unlocks 34 more eval-only tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 10:00:51 +00:00
56855eee7f Fix streaming resolve: color dict keys + defer resolveSuspense until after boot
stream-colors dict had green/blue keys but data used emerald/violet — all three
slots now render with correct Tailwind color classes. Platform: resolveSuspense
must not exist on Sx until boot completes, otherwise bootstrap __sxResolve calls
it before web stack loads and resolves silently fail. Moved to post-boot setup
so all pre-boot resolves queue in __sxPending and drain correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 09:58:18 +00:00
6e27442d57 Step 17: streaming render — hyperscript enhancements, WASM builds, live server tests
Streaming chunked transfer with shell-first suspense and resolve scripts.
Hyperscript parser/compiler/runtime expanded for conformance. WASM static
assets added to OCaml host. Playwright streaming and page-level test suites.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 08:41:38 +00:00
7aefe4da8f Fix streaming: resolve scripts inside </body>, live server tests
The shell HTML included closing </body></html> tags. Resolve script
chunks arrived AFTER the document end — browser ignored them
(ERR_INCOMPLETE_CHUNKED_ENCODING). Now strips </body></html> from
shell, sends resolve scripts inside the body, closes document last.

Added live server Playwright tests that hit the actual streaming
endpoint and verify suspense slots resolve with content.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 16:40:49 +00:00
d4c0be52b1 Fix ListRef handling in streaming data — list from SX is ListRef in OCaml
The streaming render matched `List items` but SX's `(list ...)` produces
`ListRef` (mutable list) in the OCaml runtime. Data items were rejected
with "returned list, expected dict or list" — 0 resolve chunks sent.

Fixed both streaming render and AJAX paths to handle ListRef.
Added sandbox test for streaming-demo-data return type validation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 16:34:50 +00:00
3cada3f8fe Async IO in streaming render — staggered resolve with io-sleep
Server (sx_server.ml):
- eval_with_io: CEK evaluator with IO suspension handling (io-sleep, import)
- io-sleep platform primitive: raises CekPerformRequest, resolved by eval_with_io
- Streaming render uses eval_with_io for data + content evaluation
- Data items with "delay" field sleep before resolving (async streaming)
- Removed hardcoded streaming-demo-data — application logic belongs in .sx

Application (streaming-demo.sx):
- streaming-demo-data defined in SX: 3 items with 1s/3s/5s delays
- Each item has delay, stream-id, and display data fields
- Shell renders instantly, slots fill progressively as IO completes

Tests (streaming.spec.js):
- Staggered resolve test: fast resolves first, medium/slow still skeleton
- Verifies independent slot resolution matches async IO behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 16:26:44 +00:00