feat(preview): add sandboxed previews with lazy JSX compilation #6

Closed
Athena wants to merge 0 commits from Athena/NexusOS:codex/code-preview into main
Contributor

Summary

  • adds live HTML, SVG, JSX, and TSX fences rendered in an opaque-origin sandbox="allow-scripts" iframe with a restrictive CSP and no network access
  • loads Sucrase dynamically only when a JSX/TSX preview opens, replacing the 686-line hand-written lexer/parser with a maintained parser and preserving actionable compiler errors
  • keeps Preact as the small per-preview runtime and supplies local React/ReactDOM/Preact module shims inside the frame
  • removes the subjective plot/prose/canvas critique heuristics, scaffold/retry grading, render nudge, and forced-fence recovery path; the backend now validates language plus non-empty source, then the browser compiles/renders/reports errors
  • preserves narrow cueing so ordinary chat does not pay for a non-stream tool turn

Review structure

This is the preview half split out of the closed PR #4. Runtime reliability fixes are isolated in #5 and should land first; this branch is otherwise based directly on current main and can be rebased after #5 merges.

Validation

  • frontend lint passed
  • JSX/TSX transform suite: 14/14 passed, including comparison-vs-JSX, Math.sin(t) / 6, TSX generic arrows, imports/exports, malformed JSX, and malformed TypeScript
  • production Vite build passed; Sucrase is emitted as a lazy 200.58 kB / 45.68 kB gzip chunk
  • production dependency audit: 0 vulnerabilities
  • broad Python suite on Windows: 99 passed, 1 skipped, with 4 current-main/merge-order failures deselected (two POSIX file-mode assertions, one Windows path-separator assertion, and the SQLite handle test fixed by #5)
  • manual browser smoke covered HTML, React imports, typed TSX/generics, division expressions, unsupported third-party imports, and malformed JSX error reporting
## Summary - adds live HTML, SVG, JSX, and TSX fences rendered in an opaque-origin `sandbox="allow-scripts"` iframe with a restrictive CSP and no network access - loads Sucrase dynamically only when a JSX/TSX preview opens, replacing the 686-line hand-written lexer/parser with a maintained parser and preserving actionable compiler errors - keeps Preact as the small per-preview runtime and supplies local React/ReactDOM/Preact module shims inside the frame - removes the subjective plot/prose/canvas critique heuristics, scaffold/retry grading, render nudge, and forced-fence recovery path; the backend now validates language plus non-empty source, then the browser compiles/renders/reports errors - preserves narrow cueing so ordinary chat does not pay for a non-stream tool turn ## Review structure This is the preview half split out of the closed PR #4. Runtime reliability fixes are isolated in #5 and should land first; this branch is otherwise based directly on current `main` and can be rebased after #5 merges. ## Validation - frontend lint passed - JSX/TSX transform suite: 14/14 passed, including comparison-vs-JSX, `Math.sin(t) / 6`, TSX generic arrows, imports/exports, malformed JSX, and malformed TypeScript - production Vite build passed; Sucrase is emitted as a lazy 200.58 kB / 45.68 kB gzip chunk - production dependency audit: 0 vulnerabilities - broad Python suite on Windows: 99 passed, 1 skipped, with 4 current-`main`/merge-order failures deselected (two POSIX file-mode assertions, one Windows path-separator assertion, and the SQLite handle test fixed by #5) - manual browser smoke covered HTML, React imports, typed TSX/generics, division expressions, unsupported third-party imports, and malformed JSX error reporting
Athena added 3 commits 2026-08-26 08:41:13 +00:00
Render validated HTML, SVG, JSX, and TSX fences locally while preserving tool context and preventing explanatory JSON from triggering actions.

Co-authored-by: Cursor <cursoragent@cursor.com>
Load Sucrase only when a JSX/TSX preview is opened, remove the hand-written transform, and leave subjective render evaluation to the reader while retaining structural fence validation.
enderofwings closed this pull request 2026-08-26 18:15:27 +00:00
Owner

Closing as superseded by #11: this branch (7262e77, 952ef8a) carried forward as-is, plus a hung-frame watchdog for the preview iframe (a runaway/synchronous-loop script had nothing detecting it) and a fix requiring approval for action-tool calls guessed from content even under the "allow" policy (a content-JSON-recovered call is weaker evidence than a native tool_calls field). Merged onto main.

Thanks for the sandbox work here - the CSP/postMessage/origin-isolation design held up under review with no changes needed.

Closing as superseded by #11: this branch (7262e77, 952ef8a) carried forward as-is, plus a hung-frame watchdog for the preview iframe (a runaway/synchronous-loop script had nothing detecting it) and a fix requiring approval for action-tool calls guessed from `content` even under the "allow" policy (a content-JSON-recovered call is weaker evidence than a native tool_calls field). Merged onto main. Thanks for the sandbox work here - the CSP/postMessage/origin-isolation design held up under review with no changes needed.

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No Reviewers
No labels
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: enderofwings/NexusOS#6