Skip to content

feat(plugins): add live Plugin Inspector modal and 5-second plugin scaffolder - #2286

Merged
Hona merged 2 commits into
devfrom
feat/plugin-devtools-and-scaffolder
Dec 3, 2026
Merged

Hona merged 2 commits into
devfrom
feat/plugin-devtools-and-scaffolder

Conversation

@Hona

@Hona Hona commented Dec 3, 2026

Copy link
Copy Markdown
Member

Summary

Ships two developer quality-of-life features for PsychoScript plugins in OpenCode (Rune):

1. Live Plugin Inspector Modal (Settings › Extensions › Plugins)

  • Inspect entry point (apps/desktop/src/plugin_host/ui/view.rs): Adds an Inspect button beside Reload on every plugin card with localized strings across all 63 crates/opencode-i18n/locales/rune/*.json locale files.
  • Explicit state machine & zero App fields (apps/desktop/src/plugin_host/ui/inspector.rs, apps/desktop/src/plugin_host/feature.rs): Uses InspectorState (Closed / Open(InspectorSession)) + SceneEval (Idle / Pending) inside opencode_kernel::Slot, rendered via opencode_ui::widgets::sized_modal (DialogSize::Large), with Escape dismissal and focus restoration.
  • Live VM telemetry & per-plugin console (apps/desktop/src/plugin_host/mod.rs, crates/opencode-plugin-runtime/src/console.rs):
    • Header with plugin name, version, semantic status badge (On / Off / Error / Dormant / Loading / Reloading / Awaiting approval), Reload, and Close controls.
    • Metrics strip with live heap (split into window + app halves via Plugin::memory_bytes_split()), vm_time (ms), renders, vm_calls, reloads, contract version, and plugin source path.
    • Last fatal/render error banner plus scrollable per-plugin console output (console::lines_for / console::clear_for) with Copy logs and Clear controls.
    • Interactive JavaScript Eval REPL (Enter or Run) executing inside the plugin's live VM and appending > <expr> plus formatted output/error into the log stream.
  • Scene support: Registers --scene plugin-inspector to render the live modal over Settings › Extensions › Plugins.

2. 5-Second Plugin Scaffolder (scripts/new-plugin.{mjs,ps1,sh})

  • Zero-dependency Bun/Node (>= 18) scaffolder with thin PowerShell and Bash wrappers:
    bun scripts/new-plugin.mjs <name> [--ts|--js] [--dir <parent-dir>] [--force]
  • Validates kebab-case plugin IDs, refuses to overwrite existing directories unless --force is passed, and generates:
    • plugin.toml (version = "0.1.0", contract = "1.15", entry = "init.ts" or "init.js")
    • init.ts / init.js — idiomatic ESM starter using import plugin from "@opencode/plugin", import ui from "@opencode/ui", const { Layout, Toast } = ctx.services, task.signal (AbortSignal), setTimeout, ui.rich, and a starter command + panel
    • tsconfig.json (strict config referencing ./opencode.d.ts)
    • Local copy of plugins/opencode.d.ts for out-of-the-box IDE autocomplete and tsc --noEmit

Verification

  • cargo check -p opencode-desktop: passed (0 errors)
  • cargo check -p opencode-web --target wasm32-unknown-unknown: passed (0 errors)
  • bun scripts/web-clock.ts: passed (1215 files in 50 crates)
  • pwsh scripts/guardrails.ps1: 11/11 passed (arch-check, file-size, folder-shape, dialog-size, tables-check across all 63 locales, plugin-props, external-open, net-trust, engine-revision, office-engine-revision, cursor-allow)
  • Live Scaffolder Proof:
    • bun scripts/new-plugin.mjs hello-demo --ts --dir <tmp>/plugins + bunx --bun tsc -p <tmp>/plugins/hello-demo/tsconfig.json --noEmit exited 0 (also verified --js, new-plugin.ps1, new-plugin.sh, invalid-ID rejection, and overwrite protection).
    • Live opencode-desktop --plugin-dir <tmp>/plugins --plugins-eager --plugin-index --scene settings-extensions-plugins booted hello-demo 0.1.0 (contract 1.15, Dev, On) with 0 errors and both panel + command registered.
  • Live Plugin Inspector Proof:
    • Live opencode-desktop --plugins-eager --plugin-index --scene plugin-inspector rendered the DialogSize::Large Plugin Inspector modal over Settings › Extensions › Plugins with live browser metrics (205 KB (185w + 20a), vm_time, renders, vm_calls, reloads, contract), live LOG/WARN entries, and live evaluated REPL JSON output.

…affolder

Adds two developer quality-of-life improvements for OpenCode (Rune) PsychoScript plugins:

1. Live Plugin DevTools / Inspector modal in Settings > Extensions > Plugins:
   - Adds an Inspect button beside Reload on each plugin card with full i18n coverage across all 63 Rune locale files.
   - Implements `apps/desktop/src/plugin_host/ui/inspector.rs` using an explicit `InspectorState` machine in an `opencode_kernel::Slot` (zero new `App` fields), `DialogSize::Large` via `sized_modal`, Escape-layer dismissal, and focus restoration.
   - Displays live metrics (`heap` split across window + app halves, `vm_time` ms, `renders`, `vm_calls`, `reloads`, contract version, and plugin source path), fatal/render error banners, scrollable per-plugin console logs (`lines_for` / `clear_for` in `opencode-plugin-runtime`) with Copy logs and Clear controls, and an interactive JavaScript eval REPL running inside the plugin's live VM.
   - Registers `--scene plugin-inspector` for deterministic visual verification.

2. 5-second zero-dependency plugin scaffolder (`scripts/new-plugin.{mjs,ps1,sh}`):
   - Scaffolds strict TypeScript (`--ts`, default) or JavaScript (`--js`) ESM plugins with `plugin.toml`, `init.ts`/`init.js` (using `ctx.services`, `task.signal` AbortSignal, `ui.rich`, `setTimeout`, and a starter command + panel), `tsconfig.json`, and a local copy of `opencode.d.ts` for immediate IDE autocomplete and `tsc --noEmit`.
Copilot AI balanced review requested due to automatic review settings December 3, 2026 11:29

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.

…nd scaffolder

- Overlay z-order: place `plugin.inspector` above `dialog.move_recovery` and `plugin.dialog` above `plugin.inspector` so dialogs opened from REPL eval or Reload render above the Inspector.
- REPL & focus hygiene: disable `TextInput` and skip autofocus when the plugin cannot evaluate, wake dormant plugins before eval, guard `SubmitRepl` on running state, and remove the dead `Key::Enter` branch in `inspector::key`.
- Live async log redraws: schedule `plugin_host.inspector.poll` after `panels.poll` in `REACT_PANELS` (no-op when closed) tracking `console::version()` so async `setTimeout` logs repaint immediately.
- Non-headless scene boot: call `ensure_plugin_running` / `boot_builtin` before resolving `--scene plugin-inspector` target and update `plugin_id` via `InspectorEvent::Retarget`.
- Scaffolder hardening: mark `scripts/new-plugin.{sh,mjs}` executable (`100755`), reject flag tokens after `--dir`, refuse built-in plugin IDs without `--force`, read `contract` dynamically from `crates/opencode-plugin-spec/contract.json`, use valid `"code"` panel icon, add `requiresSession: true`, validate target is a directory under `--force` and remove the opposite entry file, and quote shell paths safely.
- Perf & UX: enable `.stick_bottom()` on the log scroller, cap console messages at 16 KB (UTF-8 safe), compute Copy logs payload lazily on click, and preserve explicit units on >= 1 MB heap splits.
@Hona
Hona merged commit f7402f3 into dev Dec 3, 2026
8 checks passed
@Hona
Hona deleted the feat/plugin-devtools-and-scaffolder branch December 3, 2026 11:52
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