Skip to content

feat(plugins): zero-build TSX/JSX plugins and native auxiliary-window EventRouter - #2291

Open
Hona wants to merge 1 commit into
devfrom
feat/tsx-plugins-and-native-event-router
Open

Hona wants to merge 1 commit into
devfrom
feat/tsx-plugins-and-native-event-router

Conversation

@Hona

@Hona Hona commented Dec 3, 2026

Copy link
Copy Markdown
Member

Adopts anomalyco/rune@6f0df42b84991341134f5dea59aad0ac73bd59ac (PR #3384), replaces @rune/ui JS monkey-patching for auxiliary windows with Rune's native EventRouter, and enables zero-build .tsx/.jsx plugins end to end.

Architecture

flowchart LR
  subgraph Aux["Auxiliary Window Render"]
    R["render_entry(mailbox_key)"] --> T["script.with_event_tag(mailbox_key)"]
    T --> UI["@rune/ui, JSX __rune_jsx, HostNode, virtualList rows"]
  end
  UI -->|Callback fires on aux App| ER["Script EventRouter(tag, RoutedEvent, tx)"]
  ER -->|on_parent = true| SYNC["event.run(tx)"]
  ER -->|on_aux = true| Q["DISPATCH_QUEUE[mailbox_key] + parent.update(...)"]
  Q --> D["drain_dispatched: cx::enter(parent_app) -> event.run(tx) -> carry_out + sync_renders"]
Loading

Changes

  • Rune pin (Cargo.toml, Cargo.lock): bumps all 21 anomalyco/rune pins to 6f0df42b84991341134f5dea59aad0ac73bd59ac (zero-build .tsx/.jsx, deferrable RoutedEvent & EventRouter, emoji caret, AbortSignal.any).
  • Native auxiliary-window event routing (apps/desktop/src/plugin_host/aux_windows/{dispatch,mod}.rs): deletes WRAP_UI_JS, AuxUiWrapCache, WrapState, WrapEvent, WrapEffects, WrapScope, apply_ui_entries, collect_fn_entries, and wrapRow (-452 / +80 lines). Uses Script::set_event_router, Script::with_event_tag(mailbox_key, ...), and owned deferrable RoutedEvent so standard ui.*, JSX __rune_jsx, onDrag, onLink, onScroll, HostNode handlers, and ui.virtualList rows route onto the owning parent App with zero JS wrapping and zero overhead on untagged main-window renders.
  • Zero-build .tsx/.jsx plugin loading (crates/opencode-plugin-runtime/src/{sources,console,hot}.rs, apps/desktop/build.rs, apps/desktop/src/plugin_host/runtime/hot.rs):
    • is_script accepts .js, .jsx, .ts (excluding .d.ts), and .tsx.
    • script_sources falls back init.js -> init.ts -> init.tsx -> init.jsx, skipping .ts/.tsx files when the entry is .js/.jsx.
    • console::location parses .js:, .jsx:, .ts:, and .tsx: source locations.
  • Ambient JSX typings (crates/opencode-plugin-spec/src/codegen/ts.rs, plugins/opencode.d.ts, plugins/tsconfig.json): adds __rune_jsx, __rune_frag, UiLibrary.{h, Fragment}, JSX.IntrinsicElements across all 52 contract UI nodes, and "jsx": "react" / "jsxFactory": "__rune_jsx" / "jsxFragmentFactory": "__rune_frag" in tsconfig.json.
  • TSX scaffolder (scripts/new-plugin.{mjs,ps1,sh}): adds --tsx flag generating a typed init.tsx starter with custom <StatBadge /> component, <icon>code</icon>, ctx.services, task.signal, and strict JSX tsconfig.json.

Usage

bun scripts/new-plugin.mjs my-plugin --tsx
function StatusPill({ label }: { label: string }): UiNode {
  return (
    <row px={6} py={2} radius={4} align="center" fill="accent-subtle" border="border-weak" borderWidth={1}>
      <text size={11} weight="semibold" mono color="text-interactive">
        {label}
      </text>
    </row>
  );
}

Live Rendered Proof

Plugins Settings (tsx-demo Dev, On) Live Zero-Build .tsx Status Bar

tsx-plugin-live

tsx-rendered-ui

… EventRouter

- Pin all 21 `anomalyco/rune` dependencies to `6f0df42b84991341134f5dea59aad0ac73bd59ac`
  (zero-build `.tsx`/`.jsx`, deferrable `RoutedEvent` & `EventRouter`, emoji caret, `AbortSignal.any`).
- Replace `@rune/ui` JS monkey-patching (`WRAP_UI_JS`, `AuxUiWrapCache`, `WrapState`, `WrapScope`)
  in `apps/desktop/src/plugin_host/aux_windows/dispatch.rs` with Rune's native
  `Script::set_event_router`, `Script::with_event_tag`, and owned deferrable `RoutedEvent`
  (-452/+80 lines).
- Support `.tsx` and `.jsx` plugin modules across `opencode-plugin-runtime` (`is_script`,
  `script_sources` fallback `init.js` -> `init.ts` -> `init.tsx` -> `init.jsx`, console source
  locations) and `apps/desktop/build.rs`.
- Add ambient `__rune_jsx`, `__rune_frag`, `UiLibrary.{h,Fragment}`, `JSX.IntrinsicElements`
  for all 52 contract UI nodes, and JSX compiler options in `opencode-plugin-spec` codegen
  (`plugins/opencode.d.ts`, `plugins/tsconfig.json`).
- Add `--tsx` template mode to `scripts/new-plugin.{mjs,ps1,sh}`.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 12:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants