Commit Graph

1298 Commits

Author SHA1 Message Date
d2f4ab71d1 Add register-special-form!, collect!, random-int, try-rerender-page
- register-special-form!: guards defhandler/defisland from SX override
- collect!/collected/clear-collected!: scope accumulator primitives
- random-int: deterministic stub (returns lo)
- try-rerender-page: no-op stub for offline tests
- defpage now works via forms.sx (needs make-page-def — separate issue)

1702 → 1710 passing tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 19:08:44 +00:00
f857b3eddb Re-bind render-to-sx after module load to handle string inputs
The OCaml render-to-sx wrapper now correctly overrides the SX version
loaded from adapter-sx.sx: string inputs get parsed → aser evaluated,
AST inputs delegate to the SX version. Fixes ~41 aser test failures.

1661 → 1702 passing tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 19:06:39 +00:00
909ec6e145 Add render-to-sx eval wrapper, preload handler mocks, load forms.sx
- render-to-sx: OCaml wrapper that parses source strings then evaluates
  via aser — unblocks test-aser.sx tests that pass string arguments
- Pre-load test-handlers.sx before test scan so reset-mocks!/helper are
  available to test-examples.sx (fixes 24 reset-mocks! failures)
- forms.sx loaded — provides defpage, stream-chunk-id, normalize-binding-key
- context registered as Sx_primitives primitive (not just env binding)
- cek-call, cek-run, now-ms, regex-find-all stubs added

1578 → 1661 passing tests (+83).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 19:05:13 +00:00
cbd5ad0a52 Add cek-call, context primitive, forms.sx, regex-find-all stubs
- cek-call/cek-run: dispatch through Sx_ref.cek_call for signal tests
- context: registered as both env binding and Sx_primitives primitive
  so signals.sx can resolve it through the primitive table
- forms.sx: loaded before other web modules — provides defpage special
  form, stream-chunk-id, normalize-binding-key, etc.
- regex-find-all: substring-based stub for component scanning
- now-ms: stub returning 1000

1525 → 1578 passing tests (+53).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 18:47:38 +00:00
fb9fe45f71 Load router/deps/orchestration modules, rename render-sx in tests
Load 3 web modules in test runner: router.sx (75 URL/route tests),
deps.sx (40 analysis tests), orchestration.sx (18 cache/offline tests).
Rename render-sx → render-to-sx in test-aser.sx to match actual fn name.

1372 → 1525 passing tests (+153).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 18:34:55 +00:00
e468ca4ef7 Rename render-sx → render-to-sx in aser tests
79 occurrences renamed to match the actual function name in
adapter-sx.sx. Tests still fail because render-to-sx takes an
AST expression, not a source string — needs eval-string wrapper.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 18:33:12 +00:00
5ab45c969c Add swap tests for newly unblocked handlers
7 new suites: inline-edit (edit/save/cancel cycle), row-editing
(form load + save), profile-editing (edit + put), tabs (content +
OOB buttons), loading-indicator (sleep + content), bulk-operations
(activate users), dedup-search. Total: 29 suites, 41 tests.

All example handlers now have swap integration coverage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 18:26:57 +00:00
714538f1b4 Fix defhandler blockers: &key params, multi-body, HTML tags
Three fixes in run_tests.ml defhandler parser:
1. Extract &key param names, store in hdef["params"]. run-handler
   binds them from mock args before evaluating — fixes row-editing,
   tabs, inline-edit, profile-editing handlers.
2. Capture all body forms after params, wrap in (do ...) when
   multiple — fixes ex-slow (sleep before let).
3. Register all HTML tags as native fns via Sx_render.html_tags —
   fixes ex-bulk (tr tag), and enables aser to serialize any tag.

1352 → 1361 passing tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 18:18:13 +00:00
204e527f31 Add swap integration tests for all working handlers
14 new suites covering: dashboard, lazy-load, dialog open/close, keyboard
dispatch, validate (3 branches), validate-submit, dependent-select,
form-reset, swap-modes-log (beforeend + OOB counter), json-echo, retry
(503 pattern), animate, infinite-scroll. Total: 22 suites, 30 tests.

Skipped: ex-slow (multi-body defhandler bug), ex-tabs/ex-bulk (missing
HTML tag symbols), ex-row-editing/ex-inline-edit/ex-profile (need &key
param binding in run-handler).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 18:14:10 +00:00
601ee7d8ab Add infinite-scroll swap integration test
Three tests covering the beforeend pagination pattern: page 1 appends
items with sentinel trigger, page 2 appends more, last page shows
"All items loaded" without sentinel.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 18:04:17 +00:00
b9d30749f7 Fix scopes page: rename &key code param that shadowed HTML <code> tag
The ~geography/scopes-demo-example component had (&key demo code), and
its body used (code code) — the parameter shadowed the HTML tag, causing
"Undefined symbol: code" at render time. Renamed to (&key demo src).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 18:04:06 +00:00
aa508bad77 Implement sx-swap pure tree rewriting and fix handler test infrastructure
Write lib/sx-swap.sx — string-level SX scanner that finds elements by :id
and applies swap operations (innerHTML, outerHTML, beforeend, afterbegin,
beforebegin, afterend, delete, none). Includes OOB extraction via
find-oob-elements/strip-oob/apply-response for out-of-band targeted swaps.

Fix &rest varargs bug in test-handlers.sx helper mock — fn doesn't support
&rest, so change to positional (name a1 a2) with nil defaults. Fix into
branch, add run-handler sx-expr unwrapping.

Add missing primitives to run_tests.ml: scope-peek, callable?, make-sx-expr,
sx-expr-source, sx-expr?, spread?, call-lambda. These unblock aser-based
handler evaluation in tests.

Add algebraic integration tests (test-swap-integration.sx) demonstrating the
sx1 ⊕(mode,target) sx2 = sx3 pattern with real handler execution.

1219 → 1330 passing tests (+111).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 18:00:51 +00:00
f5f58ea47e Fix polling interval leak on SPA navigation
The poll trigger in bind-triggers called set-interval but discarded the
interval ID, so polls continued firing after the element was removed from
the DOM. Now the callback checks el.isConnected each tick and self-clears
when the element is gone (HTMX-style cleanup).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 16:44:57 +00:00
d1b49db057 Fix tag name case in default trigger detection, refactor engine tests
Tag names from dom-tag-name are lowercase (not uppercase) in the WASM
kernel — fix FORM/INPUT/SELECT/TEXTAREA comparisons in get-default-trigger.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 15:22:22 +00:00
84938a1f94 Handler source: highlight as SX not Python
Handler source is now SX (from defhandler forms), not Python.
Default handler-lang changed from "python" to "sx".

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:52:12 +00:00
a5c6d947fd Revert oob-code highlight — aser can't render HTML tags
highlight returns (code (span ...)) elements which render-to-html
handles but aser doesn't. OOB responses go through aser. Plain text
for now — highlighting needs to happen client-side or aser needs
HTML tag support.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:47:57 +00:00
c1c073f26f ~docs/oob-code: highlight source text
Now calls (highlight text) to produce syntax-colored SX output.
OCaml-side aser has full env so code/span tags resolve correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:45:16 +00:00
bdb54d5919 Handler dispatch in OCaml: look up handler dict, aser body directly
Skip the SX api function entirely. The OCaml handler interception
looks up handler:ex-{slug} in the env, extracts the body, and calls
aser directly with the full global env. This avoids the double-eval
problem where eval-expr evaluates HTML tags as function calls and
then tries to call the result.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:42:02 +00:00
3d8e3363ce Use eval-expr not aser in handler dispatch
aser in SX doesn't have access to helper/now/state-get. eval-expr
evaluates the body in the current env, returns the AST. The OCaml
handler interception then calls aser server-side with the full env.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:39:54 +00:00
824f06d3b7 Fix handler eval: use default env for aser, not handler closure
Handler closure env didn't have HTML tags (code, span, div etc.)
causing Undefined symbol errors. aser without explicit env uses
the global env which has all tags registered.

Also reverts oob-code highlight change (code tag not available in
aser context).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:36:15 +00:00
52c8af66b9 ~docs/oob-code: highlight source text with syntax coloring
Was displaying plain text in (code text). Now calls (highlight text)
to produce colored SX output.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:32:13 +00:00
92688215de handler-source: return string, let page template handle highlighting
highlight was double-wrapping in (code ...). Match component-source
pattern — return pretty-printed string, page handles display.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:29:32 +00:00
32001d03eb handler-source: fix keywords, add syntax highlighting
Keywords were printed as strings because list treated :path as kwargs.
Now uses make-keyword to build keyword nodes. Output goes through
highlight for syntax coloring.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:27:20 +00:00
678d96e1ea handler-source reconstructs defhandler form instead of dumping dict
Builds (defhandler name :path ... :method ... params body) from
the handler dict fields and pretty-prints it with syntax highlighting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:24:35 +00:00
5c2fc9b9c0 Fix handler-source and component-source lookups
Both used (env-get name) with one arg which always returned nil.
Now use eval-expr + make-symbol with cek-try fallback, same pattern
as the handler dispatch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:20:48 +00:00
87a48ac2aa Use aser instead of eval-expr for handler body evaluation
Handler bodies contain HTML elements (div, p, span) which need the
render pipeline. eval-expr treats them as function calls. aser
evaluates and serializes HTML to wire format.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:14:43 +00:00
a0f4ff02a1 Fix defhandler: native special form in make_server_env
defhandler was only available via web-forms.sx which had load
dependencies that failed. Now registered as a native special form
in make_server_env, works in both coroutine and HTTP modes.

Key fix: custom special forms receive [List args; Env eval_env],
not flat args. The handler is now bound in the eval env, not the
make_server_env closure env.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:09:14 +00:00
21c3e951ec Fix handler lookup: use eval-expr to resolve handler:ex-* symbols
env-get requires (env-get env name) with two args but dispatch.sx
was calling it with one arg, always returning nil. Now uses
eval-expr + make-symbol to resolve the handler binding in the
current env, with cek-try fallback to nil.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 14:01:37 +00:00
775ab301f6 Fix debug endpoint: use raw_path to preserve query string
The query string was stripped from path for routing but the debug
endpoint needs it to parse ?expr= and ?name= params.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 13:50:17 +00:00
86c67e5955 Auto-restart HTTP server when binary changes
Checks binary mtime every 10 requests. If the binary has been
rebuilt, closes the listen socket and exec's itself. No more
stale server after builds.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 13:45:07 +00:00
46f77c3b1e Adapter fixes, orchestration updates, example content + SPA tests
From other session: adapter-html/sx/dom fixes, orchestration
improvements, examples-content refactoring, SPA navigation test
updates, WASM copies synced.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 13:35:49 +00:00
cd9ebc0cd8 handler-source throws on missing handler, CLAUDE.md dev domains
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 13:35:19 +00:00
ffead559a4 Add 5 server inspection MCP tools
- sx_load_check: validate all .sx files parse cleanly (108 files)
- sx_env: search defined symbols by pattern/type
- sx_handler_list: list registered defhandler forms
- sx_page_list: list page functions from page-functions.sx (41 pages)
- sx_request: HTTP request to running server, returns status + body

These tools help debug silent load failures, missing definitions,
and handler routing issues.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 13:28:31 +00:00
584445a843 SPA navigation, page component refactors, WASM rebuild
Refactor page components (docs, examples, specs, reference, layouts)
and adapters (adapter-sx, boot-helpers, orchestration) across sx/ and
web/ directories. Add Playwright SPA navigation tests. Rebuild WASM
kernel with updated bytecode. Add OCaml primitives for request handling.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 11:00:51 +00:00
9f097026f8 Handler errors throw instead of returning styled divs
api and call-handler now use (error ...) for not-found and method
mismatch, so error boundaries catch them properly instead of
rendering error messages as page content.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 10:05:24 +00:00
4ea43e3659 Handler endpoints bypass page routing, return raw fragments
Paths containing (api.) are intercepted before page routing and
dispatched directly to the api function. The handler result is
rendered to SX wire format and returned without layout wrapping.

This fixes the issue where handler URLs went through page routing,
causing the handler result to be passed as a slug to the page
function, and the response to be wrapped in the full page layout.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 09:50:16 +00:00
8027f51ef3 Playwright tests for all 27 hypermedia handler examples
Comprehensive interaction tests covering GET handlers (click-to-load,
tabs, polling, search, filter, keyboard, lazy-load), POST handlers
(form-submission, inline-validation, reset), mutation handlers
(delete-row, edit-row, inline-edit, bulk-update, put-patch), and
special handlers (dialogs, oob-swaps, animations, progress-bar, retry,
json-encoding, vals-and-headers).

Tests use trackErrors + waitForSxReady. Will pass once server is
restarted with request primitives and handler dispatch.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 00:59:36 +00:00
174260df93 Add request primitive tests (17 passing) + test runner support
Request primitives (now, state-get/set!/clear!, request-form/arg,
into, request-headers-all, etc.) added to test runner environment.
17 new tests covering all primitives with round-trip, default value,
and type assertion checks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 00:57:57 +00:00
461fae269b Request primitives, POST support, handler dispatch
OCaml server:
- Accept POST/PUT/PATCH/DELETE for /sx/ paths (was GET-only)
- Parse request body, query string, set per-request context
- Add 16 request primitives: now, state-get/set!, request-form/arg,
  request-json, request-header(s), request-method/body, into, etc.
- URL-encoded body parser for form submissions

Handler dispatch (sx/sx/handlers/dispatch.sx):
- `api` function routes URL paths like (api "click") to handler:ex-click
- `call-handler` checks HTTP method, binds params, evaluates body
- Handlers defined via defhandler in handlers/examples.sx now reachable

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-01 00:54:12 +00:00
fe6115f2fc Rebuild sx-browser.js with named-let set! fix
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:45:17 +00:00
f8bc1fd12a Fix sx-tools.sx: replace em-dash UTF-8 chars with ASCII
The OCaml parser doesn't handle \xe2\x80\x94 (em-dash). Replaced
with -- throughout.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:42:05 +00:00
9bd03bc26b Load web/page-helpers.sx in HTTP server core files
build-reference-data, build-attr-detail, etc. were undefined because
page-helpers.sx wasn't in the explicit core_files list.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:38:35 +00:00
464c767a19 Add missing reference-data and special-forms-data helpers
These were lost during an earlier sx_replace_node edit. Both use
case expressions to route slugs to the correct data tables.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:36:21 +00:00
c0ded3facb Fix example index: return empty string instead of nil/404
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:29:15 +00:00
b19f5436f6 Fix hypermedia index: return empty string instead of nil/404
Same pattern as tools — passthrough returning nil fell through to
parent geography page. Now returns empty string so layout renders
with correct nav context.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:28:05 +00:00
ba6c5de6e7 Fix tools page: return empty string instead of nil/404
The tools page function returned nil when no child route matched,
causing a 404. Now returns empty string so the layout renders.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:26:40 +00:00
833415b170 Error pages render within layout instead of bare nil/404
Route errors and missing pages now show a styled error message inside
the normal layout (header, nav still work) instead of bare "nil" text
or a raw "Not Found" page. AJAX errors return renderable SX error
fragments instead of "nil" strings.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:20:50 +00:00
b62dfb25e5 Highlight returns SX tree, rendered to HTML/DOM by pipeline
highlight.sx now returns a list of (span :class "..." "text") elements
instead of a string. The rendering pipeline handles the rest:
- Server render-to-html: produces <span class="...">text</span>
- Client render-to-dom: produces DOM span elements
- Aser: serializes spans as SX for client rendering

Key fixes:
- hl-span uses (make-keyword "class") not :class (keywords evaluate
  to strings in list context)
- render-sx-tokens returns flat list of spans (no wrapper)
- hl-escape is identity (no escaping needed for tree values)
- highlight.sx added to browser bundle + platform loader
- ~docs/code renders src directly as child of pre

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 23:12:36 +00:00
609be68c9c ~tw: complete Tailwind implementation in pure SX, split into 3 files
- tw.sx: core engine (HSL color computation, token processor, responsive/
  state prefixes) + visual styles (colors, borders, shadows, ring, opacity,
  transitions, animations, transforms, cursor, decoration)
- tw-layout.sx: spatial arrangement (flex, grid, position, spacing,
  display, sizing, overflow, z-index, aspect-ratio, visibility)
- tw-type.sx: typography (font size/weight/family, line-height, tracking,
  text alignment/transform/wrap, whitespace, word-break, truncate, lists,
  hyphens, font-variant-numeric, antialiasing)

22 color names × infinite shades via HSL computation (not lookup tables).
Full responsive (sm/md/lg/xl/2xl) and state (hover/focus/active/disabled/
first/last/odd/even/visited/checked/before/after) prefix support.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 21:42:32 +00:00
75827b4828 Fix source display: add sxc mount, HTML tag forms, Playwright debug tools
- Add missing ./sx/sxc:/app/sxc:ro volume mount to dev-sx compose —
  container was using stale image copy of docs.sx where ~docs/code had
  (&key code) instead of (&key src), so highlight output was silently
  discarded
- Register HTML tags as special forms in WASM browser kernel so keyword
  attrs are preserved during render-to-dom
- Add trace-boot, hydrate-debug, eval-at modes to sx-inspect.js for
  debugging boot phases and island hydration

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 21:39:32 +00:00