From 9e2052853542eef9d275ff4a03162afe812abd86 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Thu, 3 Dec 2026 20:36:05 +1000 Subject: [PATCH 1/2] feat(plugins): adopt rune-psychoscript DX (zero-build TS/ESM, strict props, heap telemetry) Bump all 21 anomalyco/rune workspace pins to 3845da27466cc649437e1543cb51b8ec115df99c (Track A: zero-build .ts + ESM, AbortController/AbortSignal/task.signal, rich 5-line source-snippet error cards, ScriptOptions::strict_props) and adopt the new DX across opencode-plugin-runtime, opencode-plugin-spec, opencode-desktop, and built-in plugins: - Enable zero-build .ts + ESM external plugins in opencode-plugin-runtime (sources.rs & hot.rs): include .ts (skipping .d.ts) in kept() and script_sources(), and fall back from default init.js to init.ts when init.js is absent. - Enable ScriptOptions::strict_props in desktop plugin VMs for debug builds, --plugin-hot, and all non-bundled plugins so UI prop typos fail loudly even in release builds. - Migrate all 48 require("@self/...") calls across built-in plugins to relative "./..." and strip all 164 redundant view.Handler/v.Handler wrappers while keeping view.Handler in runtime and .d.ts for backwards compatibility. - Upgrade opencode-plugin-spec TS codegen and regenerate all 15 contract artifacts: add AbortController, AbortSignal, and task.signal globals, export UI prop/type aliases (BoxProps, TextProps, RichItem, RichSegment, Point, Event, Size, Color, Handler, etc.) directly on declare module "@opencode/ui" and "@rune/ui", and include .ts globs in plugins/tsconfig.json. - Surface live per-plugin heap usage (KB / MB) on Settings > Extensions > Plugins cards. - Clean up PR #2262 review leftovers in aux_windows/dispatch.rs (restore window_id from nearest active frame on WrapEvent::Exit), opencode-plugin-runtime/src/js.rs (verify ctx.is_fn in async_method and update JsArgs doc comment), and extra blank lines in services/mod.rs and native/mod.rs. --- Cargo.lock | 70 +++---- Cargo.toml | 42 ++--- .../src/plugin_host/aux_windows/dispatch.rs | 5 +- apps/desktop/src/plugin_host/mod.rs | 5 + apps/desktop/src/plugin_host/native/mod.rs | 2 - apps/desktop/src/plugin_host/runtime/hot.rs | 2 +- apps/desktop/src/plugin_host/runtime/vm.rs | 4 + apps/desktop/src/plugin_host/services/mod.rs | 3 - apps/desktop/src/plugin_host/ui/view.rs | 17 +- crates/opencode-plugin-runtime/src/hot.rs | 6 +- crates/opencode-plugin-runtime/src/js.rs | 5 +- crates/opencode-plugin-runtime/src/sources.rs | 33 +++- crates/opencode-plugin-spec/src/codegen/ts.rs | 72 ++++++- plugins/browser/device.js | 24 +-- plugins/browser/extensions.js | 64 +++---- plugins/browser/failure.js | 12 +- plugins/browser/find.js | 12 +- plugins/browser/init.js | 30 +-- plugins/browser/options.js | 16 +- plugins/browser/panel.js | 44 ++--- plugins/browser/refusal.js | 8 +- plugins/browser/settings.js | 84 ++++----- plugins/browser/signins.js | 28 +-- plugins/browser/site.js | 16 +- plugins/btw/init.js | 4 +- plugins/btw/panel.js | 12 +- plugins/context/indicator.js | 12 +- plugins/context/init.js | 4 +- plugins/context/tab.js | 8 +- plugins/debug/console.js | 12 +- plugins/debug/init.js | 46 ++--- plugins/details/init.js | 10 +- plugins/details/lists.js | 32 ++-- plugins/details/mcp.js | 24 +-- plugins/file/init.js | 2 +- plugins/goal/init.js | 6 +- plugins/microsoft-office/init.js | 4 +- plugins/microsoft-office/view.js | 4 +- plugins/opencode.d.ts | 178 ++++++++++++++++++ plugins/pairing/init.js | 46 ++--- plugins/review/init.js | 4 +- plugins/review/panel.js | 24 +-- plugins/sources/init.js | 2 +- plugins/sources/panel.js | 12 +- plugins/ssh/cover.js | 4 +- plugins/ssh/dialog.js | 8 +- plugins/ssh/init.js | 8 +- plugins/ssh/row.js | 8 +- plugins/tsconfig.json | 4 +- plugins/types/ui.d.ts | 1 + plugins/updater/init.js | 8 +- plugins/updater/view.js | 20 +- plugins/usage/init.js | 16 +- plugins/wsl/init.js | 8 +- plugins/wsl/row.js | 8 +- plugins/wsl/view.js | 34 ++-- 56 files changed, 729 insertions(+), 448 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19cf1cfc9..d3d864946 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,7 +26,7 @@ dependencies = [ [[package]] name = "accesskit_atspi_common" version = "0.21.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "accesskit", "accesskit_consumer", @@ -49,7 +49,7 @@ dependencies = [ [[package]] name = "accesskit_macos" version = "0.27.2" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "accesskit", "accesskit_consumer", @@ -80,7 +80,7 @@ dependencies = [ [[package]] name = "accesskit_windows" version = "0.35.2" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "accesskit", "accesskit_consumer", @@ -2502,7 +2502,7 @@ checksum = "743fb55ba31b18fb1ecef6bdc9aa2743314978ac084044301a7eee33fb99a20d" [[package]] name = "naga" version = "30.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "arrayvec", "bit-set", @@ -4263,7 +4263,7 @@ checksum = "9c4482d912d7671a7cd2089794f90ef3bb5f5f8c738230fb0fcd50fa020f0ed3" [[package]] name = "parley_engine" version = "0.12.0" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "fontique", "harfrust", @@ -4566,7 +4566,7 @@ dependencies = [ [[package]] name = "procwatch" version = "0.1.0" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "libc", ] @@ -4955,7 +4955,7 @@ dependencies = [ [[package]] name = "rune" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "accesskit", "accesskit_android", @@ -5031,7 +5031,7 @@ dependencies = [ [[package]] name = "rune-core" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "js-sys", "libc", @@ -5061,7 +5061,7 @@ dependencies = [ [[package]] name = "rune-edit" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "js-sys", "parley", @@ -5075,7 +5075,7 @@ dependencies = [ [[package]] name = "rune-gpu" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "blake3", "bytemuck", @@ -5103,7 +5103,7 @@ dependencies = [ [[package]] name = "rune-highlights" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "unicode-ident", "wasmparser 0.245.1", @@ -5112,7 +5112,7 @@ dependencies = [ [[package]] name = "rune-i18n" version = "0.1.0" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "fixed_decimal", "icu_decimal", @@ -5132,7 +5132,7 @@ dependencies = [ [[package]] name = "rune-image" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "avif-parse", "blake3", @@ -5154,7 +5154,7 @@ dependencies = [ [[package]] name = "rune-kit" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "icu_normalizer", "js-sys", @@ -5175,7 +5175,7 @@ dependencies = [ [[package]] name = "rune-knobs" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "rune", ] @@ -5183,7 +5183,7 @@ dependencies = [ [[package]] name = "rune-mac" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "objc2 0.6.5", "rune-notify", @@ -5192,7 +5192,7 @@ dependencies = [ [[package]] name = "rune-media" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "ash", "blake3", @@ -5223,7 +5223,7 @@ dependencies = [ [[package]] name = "rune-mermaid" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "rune", ] @@ -5231,12 +5231,12 @@ dependencies = [ [[package]] name = "rune-motion" version = "0.1.0" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" [[package]] name = "rune-notify" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "async-channel", "async-io", @@ -5259,7 +5259,7 @@ dependencies = [ [[package]] name = "rune-perf" version = "0.1.0" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "procwatch", "serde_json", @@ -5268,9 +5268,15 @@ dependencies = [ [[package]] name = "rune-psychoscript" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "notify", + "oxc_allocator", + "oxc_ast", + "oxc_ast_visit", + "oxc_parser", + "oxc_span", + "oxc_syntax", "psychoscript", "rune", "rustc-hash 2.1.3", @@ -5281,7 +5287,7 @@ dependencies = [ [[package]] name = "rune-register" version = "0.1.0" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "linkme", ] @@ -5289,7 +5295,7 @@ dependencies = [ [[package]] name = "rune-spell" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "objc2-app-kit 0.3.2", "objc2-foundation 0.3.2", @@ -5302,7 +5308,7 @@ dependencies = [ [[package]] name = "rune-staging" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "wgpu", "windows", @@ -5311,7 +5317,7 @@ dependencies = [ [[package]] name = "rune-taffy" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "stacker", "taffy", @@ -5320,7 +5326,7 @@ dependencies = [ [[package]] name = "rune-text" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "bytemuck", "fontique", @@ -5349,7 +5355,7 @@ dependencies = [ [[package]] name = "rune-theme-opencode" version = "0.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "rune", "rune-kit", @@ -5359,7 +5365,7 @@ dependencies = [ [[package]] name = "rune-tiny-skia-path" version = "0.11.4" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "arrayref", "bytemuck", @@ -5601,7 +5607,7 @@ dependencies = [ [[package]] name = "sctk-adwaita" version = "0.10.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "log", "smithay-client-toolkit", @@ -7101,7 +7107,7 @@ dependencies = [ [[package]] name = "wgpu-hal" version = "30.0.1" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "android_system_properties", "arrayvec", @@ -7501,7 +7507,7 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winit" version = "0.30.13" -source = "git+https://github.com/anomalyco/rune?rev=24332dc9070adc35cdbaf2aaca8bdde9d6879793#24332dc9070adc35cdbaf2aaca8bdde9d6879793" +source = "git+https://github.com/anomalyco/rune?rev=3845da27466cc649437e1543cb51b8ec115df99c#3845da27466cc649437e1543cb51b8ec115df99c" dependencies = [ "ahash", "android-activity", diff --git a/Cargo.toml b/Cargo.toml index c4a11ef72..bda84cb33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,19 +76,19 @@ license = "MIT" # Rune's default features less two the app doesn't use: `embedded-fonts` (the app registers its own # faces, so Rune's bundled Inter was 1.25 MB nobody drew with) and `ogg-audio` (Ogg and Opus audio # for macOS video, which apps/desktop turns on for macOS alone). -rune = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793", default-features = false, features = ["accessibility", "dbus", "metal-backend", "svg", "x11"] } -rune-kit = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } -rune-mermaid = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } -rune-theme-opencode = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } -rune-fx = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } -rune-i18n = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } -procwatch = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } -rune-knobs = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } -rune-mac = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } -rune-notify = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } -rune-perf = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } -rune-register = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } -rune-psychoscript = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } +rune = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c", default-features = false, features = ["accessibility", "dbus", "metal-backend", "svg", "x11"] } +rune-kit = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } +rune-mermaid = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } +rune-theme-opencode = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } +rune-fx = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } +rune-i18n = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } +procwatch = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } +rune-knobs = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } +rune-mac = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } +rune-notify = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } +rune-perf = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } +rune-register = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } +rune-psychoscript = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } base64 = "0.22" polling = "3.11" # Objects keep their keys in the order they arrive, as JavaScript's do: a tool's arguments list as @@ -106,31 +106,31 @@ libmimalloc-sys = { path = "vendor/libmimalloc-sys" } # Rune's wgpu-hal (wgpu-hal as published plus `dx12::Instance::expose_adapter`, partial presents, and # removed-device fence handling, `vendor/wgpu-hal` in the Rune repo), at the Rune rev pinned above. # Keep the rev equal to the `rune` rev. -wgpu-hal = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } +wgpu-hal = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } # Rune's winit (winit 0.30 as published plus `vendor/winit.patch`: a new Windows window isn't added again # to the taskbar it's already on, which cost CoInitializeEx and a TaskbarList COM object on the UI # thread before the first frame, and Wayland `content_corner_radius`). Keep the rev equal to the `rune` rev. -winit = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } +winit = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } # Rune's sctk-adwaita (as published plus `vendor/sctk-adwaita.patch`: rounded bottom corners on Wayland # client-side frames and `AdwaitaFrame::content_corner_radius`). Keep the rev equal to the `rune` rev. -sctk-adwaita = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } +sctk-adwaita = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } # Rune's accesskit_windows (0.35.2 as published plus `vendor/accesskit_windows.patch`: headings and # landmarks reach UI Automation; a field past 64 KiB keeps its text pattern). At the same rev as `rune`. -accesskit_windows = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } +accesskit_windows = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } # Rune's accesskit_macos (0.27.2 as published plus `vendor/accesskit_macos.patch`: headings reach # VoiceOver as AppKit's AXHeading with their level; a field past 64 KiB keeps its line ranges). At the same # rev as `rune`. -accesskit_macos = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } +accesskit_macos = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } # Rune's parley_engine (0.12.0 as published plus `vendor/parley_engine.patch`: UAX #9 rule L1 at a # paragraph's end, so Unicode's BidiTest.txt passes whole; segmenters and font metrics made once, # not for every text and run). Keep the rev equal to the `rune` rev. -parley_engine = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } +parley_engine = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } # Rune's naga (30.0.1 as published plus `vendor/naga.patch`: constant-folding an expression to an earlier # handle neither stretches nor inverts an `Emit` range, gfx-rs/wgpu#7793; rune#1815). Keep the rev equal to the `rune` rev. -naga = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } +naga = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } # Rune's accesskit_atspi_common (0.21.1 as published plus `vendor/accesskit_atspi_common.patch`: item roles read their # own `size_of_set`; rune#1819). Keep the rev equal to the `rune` rev. -accesskit_atspi_common = { git = "https://github.com/anomalyco/rune", rev = "24332dc9070adc35cdbaf2aaca8bdde9d6879793" } +accesskit_atspi_common = { git = "https://github.com/anomalyco/rune", rev = "3845da27466cc649437e1543cb51b8ec115df99c" } # Keep dependencies lean in dev (opt-level = 1 cuts cold build time, RAM, and target/ size # across Windows/macOS/Linux), while keeping full -O3 on the small set of CPU-hot crates diff --git a/apps/desktop/src/plugin_host/aux_windows/dispatch.rs b/apps/desktop/src/plugin_host/aux_windows/dispatch.rs index 581a6881d..9a5711470 100644 --- a/apps/desktop/src/plugin_host/aux_windows/dispatch.rs +++ b/apps/desktop/src/plugin_host/aux_windows/dispatch.rs @@ -87,8 +87,9 @@ impl WrapState { WrapEffects { patch: UiPatch::Unwrap, window_id: Some(String::new()) } } else { let window_id = frames - .last() - .and_then(Option::as_ref) + .iter() + .rev() + .find_map(Option::as_ref) .map(|t| t.window_id.clone()) .unwrap_or_default(); *self = Self::Wrapped { frames }; diff --git a/apps/desktop/src/plugin_host/mod.rs b/apps/desktop/src/plugin_host/mod.rs index fa2303ccb..4758b75b8 100644 --- a/apps/desktop/src/plugin_host/mod.rs +++ b/apps/desktop/src/plugin_host/mod.rs @@ -140,6 +140,11 @@ impl Plugin { self.life.script() } + /// Live VM heap usage in bytes (`0` when the plugin has no running script). + pub fn memory_bytes(&self) -> usize { + self.script().map_or(0, Script::memory) + } + /// The window half's script when `half.contribs` belongs to its current VM, preventing /// cross-VM `JsFn` calls if a VM swap has not been adopted yet. pub fn adopted_script(&self) -> Option<&Script> { diff --git a/apps/desktop/src/plugin_host/native/mod.rs b/apps/desktop/src/plugin_host/native/mod.rs index f16cb7d9b..182cc0a35 100644 --- a/apps/desktop/src/plugin_host/native/mod.rs +++ b/apps/desktop/src/plugin_host/native/mod.rs @@ -105,5 +105,3 @@ pub fn build(ctx: &mut HostCtx<'_>, vmx: &Rc, name: &str, obj: Val) -> JsRe _ => Ok(()), } } - - diff --git a/apps/desktop/src/plugin_host/runtime/hot.rs b/apps/desktop/src/plugin_host/runtime/hot.rs index 88dc6ce57..b0f61e124 100644 --- a/apps/desktop/src/plugin_host/runtime/hot.rs +++ b/apps/desktop/src/plugin_host/runtime/hot.rs @@ -4,7 +4,7 @@ pub use opencode_plugin_runtime::hot::{Prepared, Watcher, prepare}; use std::path::PathBuf; -/// Watches `dirs` (plugin index, folder) for `.js`, `.toml`, `.json`, and `.svg` saves. +/// Watches `dirs` (plugin index, folder) for `.js`, `.ts`, `.toml`, `.json`, and `.svg` saves. pub fn spawn(dirs: Vec<(usize, PathBuf)>, waker: Option) -> Option { Watcher::spawn(dirs, waker) } diff --git a/apps/desktop/src/plugin_host/runtime/vm.rs b/apps/desktop/src/plugin_host/runtime/vm.rs index e81565e42..414d760f0 100644 --- a/apps/desktop/src/plugin_host/runtime/vm.rs +++ b/apps/desktop/src/plugin_host/runtime/vm.rs @@ -77,9 +77,13 @@ pub fn invoke_in_vm(vm_id: u64, f: &JsFn, args: &[Data]) -> Result /// The options every plugin half's script runs with. pub fn options(half: Rc) -> ScriptOptions { let kind = half.kind; + let strict_props = cfg!(debug_assertions) + || crate::flag("--plugin-hot") + || half.tier != crate::plugin_host::Tier::Bundled; let log_half = half.clone(); let around_half = half.clone(); let mut options = ScriptOptions::new() + .strict_props(strict_props) .palette(Rc::new(palette)) .shadows(Rc::new(shadows)) .text(TextStyle::new(13.0, 440.0), [440.0, 530.0, 600.0, 700.0]) diff --git a/apps/desktop/src/plugin_host/services/mod.rs b/apps/desktop/src/plugin_host/services/mod.rs index a9da1f20b..deee04448 100644 --- a/apps/desktop/src/plugin_host/services/mod.rs +++ b/apps/desktop/src/plugin_host/services/mod.rs @@ -62,8 +62,6 @@ pub use store::store_version; pub use watch::{fire_watched, sync_editor_watches}; pub(crate) use watch::SessionInputs; - - pub use opencode_plugin_runtime::contribs::Held; /// Per-VM cache of built host service objects, stored in `Session` user data. @@ -235,7 +233,6 @@ pub fn lazy_signals( Ok(()) } - /// `ctx.CreateEditor(initial)`: the n-th editor this setup made is the window's n-th text field /// of the plugin, its text and caret kept across reloads. pub fn create_editor( diff --git a/apps/desktop/src/plugin_host/ui/view.rs b/apps/desktop/src/plugin_host/ui/view.rs index a3984e062..a305b72cb 100644 --- a/apps/desktop/src/plugin_host/ui/view.rs +++ b/apps/desktop/src/plugin_host/ui/view.rs @@ -23,13 +23,28 @@ pub fn settings_section(s: &App, p: &Pal) -> Option { } fn status(lp: &Plugin) -> String { - let mut parts = vec![format!("{} · JS {} · {}", lp.tier.label(), lp.manifest.contract, lp.life.label())]; + let mut meta = format!("{} · JS {} · {}", lp.tier.label(), lp.manifest.contract, lp.life.label()); + let mem = lp.memory_bytes(); + if mem > 0 { + meta.push_str(" · "); + meta.push_str(&format_memory(mem)); + } + let mut parts = vec![meta]; parts.extend(lp.manifest.description.clone().filter(|d| !d.is_empty())); parts.extend(lp.life.why().map(str::to_owned)); parts.push(lp.origin.describe()); parts.join("\n") } +fn format_memory(bytes: usize) -> String { + let kb = (bytes as f64 / 1024.0).round() as u64; + if kb >= 1024 { + format!("{:.1} MB", bytes as f64 / (1024.0 * 1024.0)) + } else { + format!("{} KB", kb.max(1)) + } +} + fn controls(p: &Pal, lp: &Plugin) -> El { let id = lp.manifest.id.clone(); let switchable = matches!(lp.life, Life::Running(_) | Life::Reloading(_) | Life::Disabled | Life::Errored { .. } | Life::AwaitingTrust | Life::Dormant); diff --git a/crates/opencode-plugin-runtime/src/hot.rs b/crates/opencode-plugin-runtime/src/hot.rs index b16a49385..be80550b7 100644 --- a/crates/opencode-plugin-runtime/src/hot.rs +++ b/crates/opencode-plugin-runtime/src/hot.rs @@ -1,5 +1,5 @@ -//! Save-to-reload: a watcher over every PsychoScript plugin folder (`.js`, `.toml`, `.json`, -//! `.svg`). Its thread rereads the files a save changed and validates/compiles the modules among +//! Save-to-reload: a watcher over every PsychoScript plugin folder (`.js`, `.ts`, `.toml`, +//! `.json`, `.svg`). Its thread rereads the files a save changed and validates/compiles the modules among //! them off the UI thread; meanwhile the UI thread builds the next VM's base (`Script::prewarm`), //! and the poll after the compile only swaps the VM. @@ -49,7 +49,7 @@ pub struct Watcher { } impl Watcher { - /// Watches `dirs` (plugin index, folder) for `.js`, `.toml`, `.json`, and `.svg` saves. + /// Watches `dirs` (plugin index, folder) for `.js`, `.ts`, `.toml`, `.json`, and `.svg` saves. pub fn spawn(dirs: Vec<(usize, PathBuf)>, waker: Option) -> Option { #[cfg(target_arch = "wasm32")] { diff --git a/crates/opencode-plugin-runtime/src/js.rs b/crates/opencode-plugin-runtime/src/js.rs index 95a91e362..6058c7299 100644 --- a/crates/opencode-plugin-runtime/src/js.rs +++ b/crates/opencode-plugin-runtime/src/js.rs @@ -14,7 +14,7 @@ use crate::machines::{Item, Items, Ticket}; // ---- Argument access abstraction -------------------------------------------------------------- -/// Uniform read-only argument list shared by sync (`DirectArgs`) and async (`&[Val]`) callbacks. +/// Uniform read-only argument list shared by direct (`DirectArgs`) and slice (`&[Val]`) callbacks. pub trait JsArgs { fn arg(&self, index: usize) -> Val; fn arg_len(&self) -> usize; @@ -72,6 +72,9 @@ pub fn async_method( f: impl Fn(&mut HostCtx<'_>, DirectArgs<'_>, Completer) -> JsResult<()> + 'static, ) -> JsResult<()> { let func = ctx.async_fn(name, move |ctx, args, done| f(ctx, args, done).map_err(|e| e.to_val(ctx))); + if !ctx.is_fn(func) { + return Err(JsError::runtime("failed to wrap async host function")); + } ctx.obj_set_str(obj, name, func); Ok(()) } diff --git a/crates/opencode-plugin-runtime/src/sources.rs b/crates/opencode-plugin-runtime/src/sources.rs index 5b61b3d80..d5aa75c72 100644 --- a/crates/opencode-plugin-runtime/src/sources.rs +++ b/crates/opencode-plugin-runtime/src/sources.rs @@ -191,7 +191,7 @@ fn unreachable_manifest() -> Manifest { } impl Origin { - /// Assembles [`rune_psychoscript::Sources`] for the half starting at `entry` (default `init.js`). + /// Assembles [`rune_psychoscript::Sources`] for the half starting at `entry` (default `init.js` or `init.ts`). pub fn scripts( &self, files: &[(String, String)], @@ -276,9 +276,14 @@ pub fn relative(root: &Path, path: &Path) -> Option { Some(rel.join("/")) } -/// Whether a plugin runs from the file at `rel`: its manifest, JS modules (`.js`), JSON data -/// and `locales/*.json` catalogs (plus `locales/fill/*.json`, see [`Catalogs`]), and `icons/*.svg` -/// icons, outside hidden folders. +/// Whether `path` is a runnable JavaScript or TypeScript module (skipping `.d.ts` declarations). +pub fn is_script(path: &str) -> bool { + path.ends_with(".js") || (path.ends_with(".ts") && !path.ends_with(".d.ts")) +} + +/// Whether a plugin runs from the file at `rel`: its manifest, JS/TS modules (`.js`, `.ts`, +/// excluding `.d.ts`), JSON data and `locales/*.json` catalogs (plus `locales/fill/*.json`, see +/// [`Catalogs`]), and `icons/*.svg` icons, outside hidden folders. pub fn kept(rel: &str) -> bool { let mut parts: Vec<&str> = rel.split('/').collect(); let Some(name) = parts.pop() else { @@ -288,7 +293,7 @@ pub fn kept(rel: &str) -> bool { return false; } let under = |dir: &str, ext: &str| parts.last() == Some(&dir) && name.ends_with(ext); - name.ends_with(".js") + is_script(name) || name == "plugin.toml" || name.ends_with(".json") || under("icons", ".svg") @@ -307,20 +312,30 @@ pub fn intern_icons(plugin: &str, files: &[(String, String)]) -> Vec<(String, St crate::icons::replace_plugin(plugin, &entries) } -/// The script sources of the half that starts at `entry` (defaults to `init.js` when empty). +/// The script sources of the half that starts at `entry` (defaults to `init.js`, falling back +/// to `init.ts` when `init.js` is absent). pub fn script_sources( files: &[(String, String)], folder: &str, entry: &str, ) -> rune_psychoscript::Sources { - let entry = if entry.is_empty() { - rune_psychoscript::ENTRY + let has = |p: &str| files.iter().any(|(path, _)| path == p); + let entry = if entry.is_empty() + || (entry == rune_psychoscript::ENTRY && !has(entry) && has(rune_psychoscript::ENTRY_TS)) + { + if has(rune_psychoscript::ENTRY) { + rune_psychoscript::ENTRY + } else if has(rune_psychoscript::ENTRY_TS) { + rune_psychoscript::ENTRY_TS + } else { + rune_psychoscript::ENTRY + } } else { entry }; files .iter() - .filter(|(p, _)| p.ends_with(".js") || p.ends_with(".json")) + .filter(|(p, _)| is_script(p) || p.ends_with(".json")) .fold(rune_psychoscript::Sources::new(), |s, (p, text)| { s.with(p, text.as_str()) }) diff --git a/crates/opencode-plugin-spec/src/codegen/ts.rs b/crates/opencode-plugin-spec/src/codegen/ts.rs index 3c56777a5..bf53332ad 100644 --- a/crates/opencode-plugin-spec/src/codegen/ts.rs +++ b/crates/opencode-plugin-spec/src/codegen/ts.rs @@ -112,6 +112,10 @@ pub fn definitions(c: &Contract) -> Result { let lib_name = format!("{}Library", pascal_first(&g.name)); jsdoc(&mut o, 0, &g.doc, None, None); o.line(&format!("interface {lib_name} {{")); + if g.name == "task" { + jsdoc(&mut o, 1, "Per-VM disposal signal, aborted automatically on hot reload or plugin teardown.", None, None); + o.line(" readonly signal: AbortSignal;"); + } for m in &g.members { member(&mut o, m, false)?; } @@ -148,6 +152,46 @@ pub fn definitions(c: &Contract) -> Result { o.line("/** Cancels a repeating timer scheduled by `setInterval` (or `setTimeout`). */"); o.line("declare function clearInterval(id?: number | null): void;"); o.blank(); + o.line("/** Event delivered to `AbortSignal` listeners when aborted. */"); + o.line("interface AbortEvent {"); + o.line(" readonly type: \"abort\";"); + o.line(" readonly target: AbortSignal;"); + o.line(" readonly currentTarget: AbortSignal;"); + o.line("}"); + o.blank(); + o.line("type AbortListener ="); + o.line(" | ((this: AbortSignal, event: AbortEvent) => unknown)"); + o.line(" | { handleEvent(event: AbortEvent): unknown };"); + o.blank(); + o.line("/** Standard cancellation signal provided by `AbortController`, `AbortSignal.*`, and `task.signal`. */"); + o.line("interface AbortSignal {"); + o.line(" readonly aborted: boolean;"); + o.line(" readonly reason: any;"); + o.line(" onabort: ((this: AbortSignal, event: AbortEvent) => unknown) | null;"); + o.line(" addEventListener(type: \"abort\", listener: AbortListener, options?: { once?: boolean }): void;"); + o.line(" removeEventListener(type: \"abort\", listener: AbortListener): void;"); + o.line(" throwIfAborted(): void;"); + o.line("}"); + o.blank(); + o.line("declare var AbortSignal: {"); + o.line(" readonly prototype: AbortSignal;"); + o.line(" new (): never;"); + o.line(" abort(reason?: any): AbortSignal;"); + o.line(" timeout(milliseconds: number): AbortSignal;"); + o.line(" any(signals: Iterable): AbortSignal;"); + o.line("};"); + o.blank(); + o.line("/** Standard controller whose `abort(reason?)` triggers its paired `AbortSignal`. */"); + o.line("interface AbortController {"); + o.line(" readonly signal: AbortSignal;"); + o.line(" abort(reason?: any): void;"); + o.line("}"); + o.blank(); + o.line("declare var AbortController: {"); + o.line(" readonly prototype: AbortController;"); + o.line(" new (): AbortController;"); + o.line("};"); + o.blank(); o.line("/** CommonJS module object for plugin entrypoints and local modules. */"); o.line("declare var module: { exports: any };"); o.line("declare var exports: any;"); @@ -165,11 +209,13 @@ pub fn definitions(c: &Contract) -> Result { o.line("}"); o.blank(); o.line("declare module \"@opencode/ui\" {"); + write_ui_namespace(&mut o, c, 1, false); o.line(" const ui: UiLibrary;"); o.line(" export = ui;"); o.line("}"); o.blank(); o.line("declare module \"@rune/ui\" {"); + write_ui_namespace(&mut o, c, 1, false); o.line(" const ui: UiLibrary;"); o.line(" export = ui;"); o.line("}"); @@ -310,17 +356,25 @@ fn pascal_first(s: &str) -> String { } } -/// `plugins/types/ui.d.ts`: re-exports the `Ui*` types without their prefix (`ui.Node`). -pub fn ui_stub(c: &Contract) -> String { - let mut o = stub_head("@opencode/ui"); - o.line("declare namespace ui {"); - o.line(" type Token = SemanticToken;"); +fn write_ui_namespace(o: &mut Out, c: &Contract, indent: usize, declare_kw: bool) { + let pad = " ".repeat(indent); + let inner = " ".repeat(indent + 1); + let prefix = if declare_kw { "declare " } else { "" }; + o.line(&format!("{pad}{prefix}namespace ui {{")); + o.line(&format!("{inner}type Token = SemanticToken;")); + o.line(&format!("{inner}type Color = SemanticToken | HexColor;")); for name in c.types.iter().map(|t| &t.name).chain(c.enums.iter().map(|e| &e.name)) { if let Some(short) = name.strip_prefix("Ui").filter(|s| !s.is_empty()) { - o.line(&format!(" type {short} = {name};")); + o.line(&format!("{inner}type {short} = {name};")); } } - o.line("}"); + o.line(&format!("{pad}}}")); +} + +/// `plugins/types/ui.d.ts`: re-exports the `Ui*` types without their prefix (`ui.Node`). +pub fn ui_stub(c: &Contract) -> String { + let mut o = stub_head("@opencode/ui"); + write_ui_namespace(&mut o, c, 0, true); o.blank(); o.line("declare const ui: UiLibrary;"); o.line("export = ui;"); @@ -362,7 +416,9 @@ pub fn tsconfig() -> String { "opencode.d.ts", "types/**/*.d.ts", "*/*.js", - "*/*/*.js" + "*/*/*.js", + "*/*.ts", + "*/*/*.ts" ] } "# diff --git a/plugins/browser/device.js b/plugins/browser/device.js index aac378096..b48e131f1 100644 --- a/plugins/browser/device.js +++ b/plugins/browser/device.js @@ -271,9 +271,9 @@ module.exports = function (ctx, i18n, popover, refresh) { hover: "surface-hover", press: "surface-press", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { press(); - }), + }, }, children); } @@ -449,7 +449,7 @@ module.exports = function (ctx, i18n, popover, refresh) { press: !zoomed ? "surface-press" : undefined, hoverTransition: "instant", opacity: zoomed ? 0.5 : undefined, - onPress: !zoomed ? view.Handler(() => { + onPress: !zoomed ? () => { popover.Toggle({ id: "viewport-preset", anchorKey: "browser-device-preset", @@ -458,7 +458,7 @@ module.exports = function (ctx, i18n, popover, refresh) { gap: 4, data: { tabId: tab.Id, selected, paneW: props.width }, }); - }) : undefined, + } : undefined, }, [ ui.text(presetLabel, { size: 13, weight: "medium", lineHeight: 16, tracking: -0.04, noWrap: true, color: "text-chrome", truncate: true, shrink: true, minW: 0 }), ui.icon("viewport-chevron", { size: 16, color: "icon-weak" }), @@ -481,7 +481,7 @@ module.exports = function (ctx, i18n, popover, refresh) { press: !zoomed ? "surface-press" : undefined, hoverTransition: "instant", opacity: zoomed ? 0.5 : undefined, - onPress: !zoomed ? view.Handler(() => { + onPress: !zoomed ? () => { popover.Toggle({ id: "viewport-scale", anchorKey: "browser-device-scale", @@ -490,7 +490,7 @@ module.exports = function (ctx, i18n, popover, refresh) { gap: 4, data: { tabId: tab.Id, scale: d ? d.scale : null, autoW: areaW, autoH: areaH }, }); - }) : undefined, + } : undefined, }, [ ui.text(scaleLabel, { size: 13, weight: "regular", lineHeight: 16, tracking: -0.04, noWrap: true, color: "text-faint" }), ui.icon("viewport-chevron", { size: 16, color: "icon-weak" }), @@ -506,7 +506,7 @@ module.exports = function (ctx, i18n, popover, refresh) { help: t("rotate"), helpSide: "top", disabled: !rotateEnabled, - onPress: rotateEnabled ? view.Handler(() => { + onPress: rotateEnabled ? () => { const nextW = validDimension(hStr) ?? hNum; const nextH = validDimension(wStr) ?? wNum; clearDraft(); @@ -515,7 +515,7 @@ module.exports = function (ctx, i18n, popover, refresh) { nextViewport.height = nextH; tab.SetViewport(nextViewport); refresh(); - }) : undefined, + } : undefined, }); function dimBox(key, ed, val, isInvalid, ariaLabel) { @@ -557,10 +557,10 @@ module.exports = function (ctx, i18n, popover, refresh) { : undefined, borderWidth: editing || (isInvalid && !zoomed) ? 1 : undefined, opacity: zoomed ? 0.5 : undefined, - onPress: !zoomed && !editing ? view.Handler(() => { + onPress: !zoomed && !editing ? () => { ed.Focus(); refresh(); - }) : undefined, + } : undefined, }, [body]); } @@ -585,9 +585,9 @@ module.exports = function (ctx, i18n, popover, refresh) { text: i18n.T("zoom.reset"), size: "small", variant: "ghost", - onPress: view.Handler(() => { + onPress: () => { tab.SetZoom("reset"); - }), + }, }), ])); } else if (invalid) { diff --git a/plugins/browser/extensions.js b/plugins/browser/extensions.js index bd84afedb..9b6f139f8 100644 --- a/plugins/browser/extensions.js +++ b/plugins/browser/extensions.js @@ -221,18 +221,18 @@ function renderInstalledRow(env, view, ext) { label: i18n.T("settings.extensions.remove", { name: ext.name }), help: i18n.T("settings.extensions.remove", { name: ext.name }), disabled: env.busy, - onPress: view.Handler(() => { + onPress: () => { env.onRemove(extId); - }), + }, }), ui.switch({ key: `settings-ext-toggle-${extId}`, label: i18n.T("settings.extensions.enable", { name: ext.name }), checked: ext.enabled === true, disabled: env.busy || ext.changed === true, - onChange: view.Handler((event) => { + onChange: (event) => { env.onToggle(extId, event.checked === true); - }), + }, }), ]), ]); @@ -258,9 +258,9 @@ extensions.renderSettingsSection = function (env, view) { size: "small", variant: "neutral", disabled: !env.available, - onPress: view.Handler(() => { + onPress: () => { env.onOpenAdd(); - }), + }, }) )); return ui.col({ key: "settings-browser-extensions-section", w: "full", gap: 16 }, [ @@ -345,9 +345,9 @@ function renderInstallReview(env, view, rev) { text: toggleLabel, size: "small", variant: "ghost-muted", - onPress: view.Handler(() => { + onPress: () => { env.onToggleSites(); - }), + }, })); } body.push(ui.col({ key: "rev-sites-group", w: "full", gap: 4 }, [ @@ -518,9 +518,9 @@ function renderInstallReview(env, view, rev) { variant: "ghost-muted", size: "small", label: i18n.T("common.close"), - onPress: view.Handler(() => { + onPress: () => { env.onClose(); - }), + }, }), ]), ui.col({ @@ -538,9 +538,9 @@ function renderInstallReview(env, view, rev) { text: i18n.T("common.cancel"), variant: "neutral", disabled: blocked, - onPress: view.Handler(() => { + onPress: () => { env.onCancelReview(); - }), + }, }), ui.button({ key: "ext-review-approve", @@ -548,9 +548,9 @@ function renderInstallReview(env, view, rev) { variant: "primary", disabled: blocked || hardBlocked, loading: st.approving, - onPress: view.Handler(() => { + onPress: () => { env.onApprove(token); - }), + }, }), ]), ]); @@ -594,9 +594,9 @@ function candidateRow(env, view, selected, item, blocked) { variant: btnVariant, disabled: blocked || item.installed, loading: st.busy === "install-browser" && st.installingId === extId, - onPress: view.Handler(() => { + onPress: () => { env.onAddFromBrowser(srcId, profId, extId); - }), + }, }), ]); } @@ -626,9 +626,9 @@ extensions.renderAddDialog = function (env, view) { shrink: true, minW: 0, disabled: blocked, - onSubmit: view.Handler(() => { + onSubmit: () => { env.onAddLink(); - }), + }, }), ui.button({ key: "ext-store-add-btn", @@ -637,9 +637,9 @@ extensions.renderAddDialog = function (env, view) { variant: "neutral", disabled: blocked || linkEmpty, loading: st.busy === "install-store", - onPress: view.Handler(() => { + onPress: () => { env.onAddLink(); - }), + }, }), ]), ]; @@ -682,9 +682,9 @@ extensions.renderAddDialog = function (env, view) { press: "surface-press", hoverTransition: "instant", menuTrigger: true, - onPress: view.Handler(() => { + onPress: () => { env.onOpenProfileMenu(); - }), + }, }, [ ui.text(extensions.choiceLabel(selected), PICKED, { shrink: true, minW: 0 }), ui.icon("chevron-down", { size: 16, color: "icon-weak" }), @@ -781,9 +781,9 @@ extensions.renderAddDialog = function (env, view) { variant: "ghost-muted", ml: -11, disabled: blocked, - onPress: view.Handler(() => { + onPress: () => { env.onPickFolder(); - }), + }, }); } @@ -802,9 +802,9 @@ extensions.renderAddDialog = function (env, view) { key: "ext-add-done", text: i18n.T("settings.extensions.done"), variant: "primary", - onPress: view.Handler(() => { + onPress: () => { env.onClose(); - }), + }, }), ]), ]); @@ -830,9 +830,9 @@ extensions.renderProfileMenu = function (choices, selectedKey, view, onSelect) { hover: "surface-hover", press: "surface-press", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { onSelect(key); - }), + }, }, [ ui.text(extensions.choiceLabel(choice), TITLE), ])); @@ -897,9 +897,9 @@ extensions.renderToolbarMenu = function (items, i18n, view, onSelect, onManage) press: enabled ? "surface-press" : undefined, hoverTransition: "instant", onPress: enabled - ? view.Handler(() => { + ? () => { onSelect(item); - }) + } : undefined, }, rowChildren)); } @@ -916,9 +916,9 @@ extensions.renderToolbarMenu = function (items, i18n, view, onSelect, onManage) hover: "surface-hover", press: "surface-press", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { onManage(); - }), + }, }, [ ui.text(i18n.T("extensions.manage"), { size: 13, diff --git a/plugins/browser/failure.js b/plugins/browser/failure.js index 523d9b2b1..27513e028 100644 --- a/plugins/browser/failure.js +++ b/plugins/browser/failure.js @@ -135,9 +135,9 @@ failure.renderPage = function (view, i18n, info, actions) { text: act.label, size: "small", variant: idx === 0 ? "neutral" : "ghost", - onPress: view.Handler(() => { + onPress: () => { act.run(); - }), + }, })); } children.push(ui.row({ mt: 12, gap: 8, align: "center", justify: "center" }, buttons)); @@ -191,9 +191,9 @@ failure.renderActionBar = function (view, i18n, key, words, actionLabel, action, text: actionLabel, size: "small", variant: "neutral", - onPress: view.Handler(() => { + onPress: () => { action(); - }), + }, })); } rowItems.push(ui.iconButton({ @@ -203,9 +203,9 @@ failure.renderActionBar = function (view, i18n, key, words, actionLabel, action, size: "small", label: i18n.T("refused.dismiss"), help: i18n.T("refused.dismiss"), - onPress: view.Handler(() => { + onPress: () => { dismiss(); - }), + }, })); return ui.col({ key, w: "full" }, [ ui.row({ dir: "auto", w: "full", px: 12, py: 8, gap: 12, align: "center", fill: "surface-1" }, rowItems), diff --git a/plugins/browser/find.js b/plugins/browser/find.js index 351e028c7..f7b4e0ab9 100644 --- a/plugins/browser/find.js +++ b/plugins/browser/find.js @@ -86,9 +86,9 @@ find.render = function (view, i18n, editor, current, onPrev, onNext, onClose) { label: i18n.T("find.previous"), help: i18n.T("find.previous"), disabled: !hasQuery, - onPress: hasQuery ? view.Handler(() => { + onPress: hasQuery ? () => { onPrev(); - }) : undefined, + } : undefined, })); items.push(ui.iconButton({ key: "browser-find-next", @@ -98,9 +98,9 @@ find.render = function (view, i18n, editor, current, onPrev, onNext, onClose) { label: i18n.T("find.next"), help: i18n.T("find.next"), disabled: !hasQuery, - onPress: hasQuery ? view.Handler(() => { + onPress: hasQuery ? () => { onNext(); - }) : undefined, + } : undefined, })); items.push(ui.iconButton({ key: "browser-find-close", @@ -109,9 +109,9 @@ find.render = function (view, i18n, editor, current, onPrev, onNext, onClose) { size: "small", label: i18n.T("find.close"), help: i18n.T("find.close"), - onPress: view.Handler(() => { + onPress: () => { onClose(); - }), + }, })); return ui.col({ key: "browser-find-bar", role: "region", label: i18n.T("find.open"), w: "full" }, [ ui.row({ w: "full", h: 35, px: 12, gap: 4, align: "center", fill: "surface-1" }, items), diff --git a/plugins/browser/init.js b/plugins/browser/init.js index 547db9d6a..c8ff480a9 100644 --- a/plugins/browser/init.js +++ b/plugins/browser/init.js @@ -6,21 +6,21 @@ const plugin = require("@opencode/plugin"); const ui = require("@opencode/ui"); -const address = require("@self/address"); -const createDevice = require("@self/device"); -const extensions = require("@self/extensions"); -const failure = require("@self/failure"); -const find = require("@self/find"); -const history = require("@self/history"); -const hostDisplay = require("@self/host_display"); -const mcp = require("@self/mcp"); -const options = require("@self/options"); -const panel = require("@self/panel"); -const refusal = require("@self/refusal"); -const savedTabs = require("@self/saved_tabs"); -const settings = require("@self/settings"); -const signins = require("@self/signins"); -const site = require("@self/site"); +const address = require("./address"); +const createDevice = require("./device"); +const extensions = require("./extensions"); +const failure = require("./failure"); +const find = require("./find"); +const history = require("./history"); +const hostDisplay = require("./host_display"); +const mcp = require("./mcp"); +const options = require("./options"); +const panel = require("./panel"); +const refusal = require("./refusal"); +const savedTabs = require("./saved_tabs"); +const settings = require("./settings"); +const signins = require("./signins"); +const site = require("./site"); // The panel's id: its tabs key as `browser:`, as Desktop's. const PANEL = "main"; diff --git a/plugins/browser/options.js b/plugins/browser/options.js index fd421dba9..228d01c28 100644 --- a/plugins/browser/options.js +++ b/plugins/browser/options.js @@ -35,9 +35,9 @@ function menuItem(view, key, label, enabled, press, commandId, fitWidth) { press: enabled ? "surface-press" : undefined, hoverTransition: "instant", opacity: enabled ? undefined : 0.5, - onPress: enabled ? view.Handler(() => { + onPress: enabled ? () => { press(); - }) : undefined, + } : undefined, }, children); } @@ -79,9 +79,9 @@ options.renderMain = function (cb, view, d) { press: hasUrl ? "surface-press" : undefined, hoverTransition: "instant", opacity: hasUrl ? undefined : 0.5, - onPress: hasUrl ? view.Handler(() => { + onPress: hasUrl ? () => { cb.act("zoom", d.tabId, "out"); - }) : undefined, + } : undefined, }, [ ui.icon("minus", { size: 14, color: "icon-weak" }), ]), @@ -96,9 +96,9 @@ options.renderMain = function (cb, view, d) { hover: zoomed ? "surface-hover" : undefined, press: zoomed ? "surface-press" : undefined, hoverTransition: "instant", - onPress: zoomed ? view.Handler(() => { + onPress: zoomed ? () => { cb.act("zoom", d.tabId, "reset"); - }) : undefined, + } : undefined, }, [ ui.text(pct, { size: 12, weight: "regular", lineHeight: 16, tabular: true, noWrap: true, color: zoomed ? "text-chrome" : "text-muted" }), ]), @@ -114,9 +114,9 @@ options.renderMain = function (cb, view, d) { press: hasUrl ? "surface-press" : undefined, hoverTransition: "instant", opacity: hasUrl ? undefined : 0.5, - onPress: hasUrl ? view.Handler(() => { + onPress: hasUrl ? () => { cb.act("zoom", d.tabId, "in"); - }) : undefined, + } : undefined, }, [ ui.icon("plus", { size: 14, color: "icon-weak" }), ]), diff --git a/plugins/browser/panel.js b/plugins/browser/panel.js index 73ca20446..cb44ffa5f 100644 --- a/plugins/browser/panel.js +++ b/plugins/browser/panel.js @@ -45,9 +45,9 @@ function large(view, key, icon, tip, enabled, press, extra) { disabled: !enabled, }; if (enabled) { - props.onPress = view.Handler((ev) => { + props.onPress = (ev) => { press(ev); - }); + }; } if (extra != null) { for (const [k, v] of Object.entries(extra)) { @@ -109,9 +109,9 @@ function siteButton(view, iconName, tip, expanded, press) { hover: "surface-hover", press: "surface-press", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { press(); - }), + }, }; if (expanded) { props.fill = "surface-press"; @@ -251,9 +251,9 @@ function field(env, view, tab, bar, zoom, fieldWidth) { fill: "surface-2", align: "center", hoverGroup: true, - onPress: view.Handler(() => { + onPress: () => { env.act("zoom", tab, "reset"); - }), + }, }, [ui.text(env.I18n.T("zoom.percent", { percent: Math.floor(zoom * 100 + 0.5) }), { size: 11, weight: "medium", @@ -285,9 +285,9 @@ function field(env, view, tab, bar, zoom, fieldWidth) { hoverTransition: "instant", // A press on the edited field's own box (its padding, its icon) keeps the keyboard in the input // (`panel.tsx:1000-1006`); at rest a press starts the edit. - onPress: view.Handler(() => { + onPress: () => { env.act(bar.editing ? "focus" : "edit", tab); - }), + }, }; if (bar.editing) { rowProps.border = "border-focus"; @@ -321,9 +321,9 @@ function bar(env, view, tab, state, width) { hover: "surface-hover", press: "surface-press", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { tab.Stop(); - }), + }, }, [ui.loader({ size: 16 })]); } else { reload = large(view, "browser-reload", "outline-rotate-clockwise", env.I18n.T("action.reload"), page !== "", (ev) => { @@ -457,9 +457,9 @@ panel.row = function (view, key, visit, query, width, suggestion, selected, open align: "center", hover: "surface-hover", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { open(); - }), + }, }; if (selected) { rowProps.fill = "surface-press"; @@ -550,9 +550,9 @@ function omniboxRow(env, view, tab, n, row, query, width, selected) { align: "center", hover: "surface-hover", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { env.act("go", tab, row.url); - }), + }, }; if (selected) { rowProps.fill = "surface-press"; @@ -580,9 +580,9 @@ function omniboxRow(env, view, tab, n, row, query, width, selected) { align: "center", hover: "surface-hover", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { env.act("go", tab, row.url); - }), + }, }; if (selected) { rowProps.fill = "surface-press"; @@ -624,9 +624,9 @@ function omniboxRow(env, view, tab, n, row, query, width, selected) { align: "center", hover: "surface-hover", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { env.act("go", tab, row.url); - }), + }, }; if (selected) { rowProps.fill = "surface-press"; @@ -646,9 +646,9 @@ function omniboxRow(env, view, tab, n, row, query, width, selected) { size: "small", label: env.I18n.T("common.delete"), help: env.I18n.T("common.delete"), - onPress: view.Handler(() => { + onPress: () => { env.act("forget", tab, row.url); - }), + }, }), ]); } @@ -921,13 +921,13 @@ panel.newTabBar = function (env, view, width, onEdit, onFocus, onGo, onForget) { align: "center", fill: "surface-1", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { if (barState.editing) { onFocus(); } else { onEdit(); } - }), + }, }; if (barState.editing) { addrProps.border = "border-focus"; diff --git a/plugins/browser/refusal.js b/plugins/browser/refusal.js index f6ac787b4..614d06b12 100644 --- a/plugins/browser/refusal.js +++ b/plugins/browser/refusal.js @@ -332,11 +332,11 @@ refusal.renderBar = function (view, i18n, notice, nowMs, held, onAction, onDismi text: actionLabel, size: "small", variant: "neutral", - onPress: view.Handler(() => { + onPress: () => { if (refusal.allowed(notice.shownAtMs, nowMs(), held)) { onAction(); } - }), + }, })); } topItems.push(ui.iconButton({ @@ -346,11 +346,11 @@ refusal.renderBar = function (view, i18n, notice, nowMs, held, onAction, onDismi size: "small", label: i18n.T("refused.dismiss"), help: i18n.T("refused.dismiss"), - onPress: view.Handler(() => { + onPress: () => { if (refusal.allowed(notice.shownAtMs, nowMs(), held)) { onDismiss(); } - }), + }, })); const rows = [ diff --git a/plugins/browser/settings.js b/plugins/browser/settings.js index ceae07b49..450ade8ac 100644 --- a/plugins/browser/settings.js +++ b/plugins/browser/settings.js @@ -232,9 +232,9 @@ settings.create = function (env, refresh) { text: i18n.T("settings.import.open"), size: "small", variant: "neutral", - onPress: view.Handler(() => { + onPress: () => { env.openImport(bid, pid); - }), + }, }) )); } @@ -270,9 +270,9 @@ settings.create = function (env, refresh) { key: "settings-browser-links-switch", label: i18n.T("settings.links.title"), checked: prefs.links, - onChange: view.Handler((event) => { + onChange: (event) => { env.updatePreferences({ links: event != null && event.checked === true }); - }), + }, }) ), ])); @@ -308,12 +308,12 @@ settings.create = function (env, refresh) { gap: 4, radius: 4, align: "center", - onPress: view.Handler(() => { + onPress: () => { const nextOpen = !isAdvanced; closedOver = nextOpen ? null : target; env.updatePreferences({ advanced: nextOpen }); refresh(); - }), + }, }, disclosureItems)); if (isAdvanced) { @@ -333,11 +333,11 @@ settings.create = function (env, refresh) { label: i18n.T("settings.remote.title"), checked: shared === true, disabled: shared == null, - onChange: view.Handler((event) => { + onChange: (event) => { if (env.setRemoteSignIns) { env.setRemoteSignIns(event != null && event.checked === true); } - }), + }, }) )); } @@ -351,9 +351,9 @@ settings.create = function (env, refresh) { key: "settings-browser-agent-pages-switch", label: i18n.T("settings.agentPages.title"), checked: prefs.agentPages, - onChange: view.Handler((event) => { + onChange: (event) => { env.updatePreferences({ agentPages: event != null && event.checked === true }); - }), + }, }) )); sections.push(ui.settingsList({ key: "settings-browser-behavior-section" }, advRows)); @@ -379,11 +379,11 @@ settings.create = function (env, refresh) { variant: "neutral", loading: busy, disabled: busy, - onPress: view.Handler(() => { + onPress: () => { if (env.pickCookieFile) { env.pickCookieFile(); } - }), + }, }), ]), ])); @@ -431,7 +431,7 @@ settings.create = function (env, refresh) { shrink: true, minW: 0, menuTrigger: true, - onPress: view.Handler(async () => { + onPress: async () => { const picked = await env.Menu.OpenAsync({ anchorKey: selectKey, label: selectLabel, @@ -445,7 +445,7 @@ settings.create = function (env, refresh) { if ((picked === "allow" || picked === "block") && picked !== setting) { env.setSitePermission(origin, perm, picked); } - }), + }, }, [ ui.text(setting === "allow" ? allowLabel : blockLabel, { size: 13, @@ -466,9 +466,9 @@ settings.create = function (env, refresh) { size: "small", label: i18n.T("settings.sites.remove", { permission: permLabel, site: host }), help: i18n.T("settings.sites.remove", { permission: permLabel, site: host }), - onPress: view.Handler(() => { + onPress: () => { env.removeSitePermission(origin, perm); - }), + }, }), ]); // `settings.tsx:326-336`: the globe, the site, and the feature under it. @@ -517,12 +517,12 @@ settings.create = function (env, refresh) { size: "small", variant: "danger", loading: env.clearing(), - onPress: view.Handler(() => { + onPress: () => { if (env.clearing()) { return; } env.requestClearBrowsingData(); - }), + }, }) ), ])); @@ -549,18 +549,18 @@ settings.renderClearConfirm = function (i18n, view, onCancel, onConfirm) { size: "small", variant: "ghost", autofocus: true, - onPress: view.Handler(() => { + onPress: () => { onCancel(); - }), + }, }), ui.button({ key: "settings-browser-clear-confirm-btn", text: i18n.T("settings.clear.confirm.action"), size: "small", variant: "danger", - onPress: view.Handler(() => { + onPress: () => { onConfirm(); - }), + }, }), ]), ]); @@ -588,9 +588,9 @@ settings.renderImportDialog = function (i18n, view, title, message, boxes, busy, checked, surface: "base", disabled: busy, - onChange: view.Handler((e) => { + onChange: (e) => { onBox(which, e != null && e.checked === true); - }), + }, }), ]); } @@ -622,11 +622,11 @@ settings.renderImportDialog = function (i18n, view, title, message, boxes, busy, disabled: busy, shrink: true, minW: 0, - onChange: view.Handler((ev) => { + onChange: (ev) => { if (ev != null && typeof ev === "object" && typeof ev.value === "string" && ev.value !== current) { chooser.onProfile(ev.value); } - }), + }, }), ])); } @@ -637,7 +637,7 @@ settings.renderImportDialog = function (i18n, view, title, message, boxes, busy, key: "settings-import-what", w: "full", keys: ["Enter"], - onKey: view.Handler(doImport), + onKey: doImport, }, [ui.col({ key: "settings-import-what-rows", w: "full", gap: 4 }, [ mergeText(i18n.T("import.what"), GROUP_HEADING, { key: "settings-import-what-title", role: "heading" }), box("signins", i18n.T("import.signins"), boxes.signins), @@ -659,9 +659,9 @@ settings.renderImportDialog = function (i18n, view, title, message, boxes, busy, text: i18n.T("sites.every"), checked: chooser.scope === "all", disabled: busy, - onChange: view.Handler(() => { + onChange: () => { chooser.onScope("all"); - }), + }, }), ]; if (chooser.ready) { @@ -682,9 +682,9 @@ settings.renderImportDialog = function (i18n, view, title, message, boxes, busy, text: i18n.T("sites.only"), checked: chooser.scope === "some", disabled: busy, - onChange: view.Handler(() => { + onChange: () => { chooser.onScope("some"); - }), + }, }), ]), ])); @@ -726,9 +726,9 @@ settings.renderImportDialog = function (i18n, view, title, message, boxes, busy, key: "settings-import-cancel", text: i18n.T("common.cancel"), variant: "neutral", - onPress: view.Handler(() => { + onPress: () => { onClose(); - }), + }, }), ui.button({ key: "settings-import-start", @@ -736,7 +736,7 @@ settings.renderImportDialog = function (i18n, view, title, message, boxes, busy, variant: "primary", disabled: !canImport || busy, loading: busy, - onPress: view.Handler(doImport), + onPress: doImport, }), ]), ]); @@ -768,13 +768,13 @@ function siteList(i18n, view, chooser, busy, onImport) { indeterminate: someChosen, surface: "layer-1", disabled: busy || !chooser.ready || shown.length === 0, - onChange: view.Handler(() => { + onChange: () => { if (allChosen) { chooser.onClearShown(); } else { chooser.onSelectShown(); } - }), + }, }), ui.text(count, { key: "settings-import-count", @@ -814,9 +814,9 @@ function siteList(i18n, view, chooser, busy, onImport) { text: i18n.T("common.retry"), size: "small", variant: "neutral", - onPress: view.Handler(() => { + onPress: () => { chooser.onRetry(); - }), + }, })); } inner = ui.col({ key: "settings-import-sites-status", w: "full", px: 24, gap: 12, align: "center", justify: "center" }, statusChildren); @@ -830,9 +830,9 @@ function siteList(i18n, view, chooser, busy, onImport) { label: i18n.T("sites.list"), focusGroup: true, keys: ["Enter"], - onKey: view.Handler(() => { + onKey: () => { onImport(); - }), + }, w: "full", shrink: true, minH: 0, @@ -864,9 +864,9 @@ function siteList(i18n, view, chooser, busy, onImport) { align: "center", hover: "surface-hover", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { chooser.onToggle(site); - }), + }, }, [ ui.checkbox({ key: `settings-import-site-box-${site}`, text: "", checked: chosen, surface: "layer-1", presentation: true }), ui.text(site, { size: 13, weight: "regular", lineHeight: 20, color: "text-base", truncate: true, shrink: true, minW: 0, grow: 1, dir: "ltr" }), diff --git a/plugins/browser/signins.js b/plugins/browser/signins.js index b6a9f41f5..f38eeb1f0 100644 --- a/plugins/browser/signins.js +++ b/plugins/browser/signins.js @@ -82,9 +82,9 @@ function closeButton(env, view, key, label, press) { label, help: label, helpSide: "top", - onPress: view.Handler(() => { + onPress: () => { press(); - }), + }, }); } @@ -119,9 +119,9 @@ function bar(env, view, choices) { variant: "contrast", disabled: blocked, loading: env.importing(first), - onPress: view.Handler(() => { + onPress: () => { env.run(first); - }), + }, }), ui.iconButton({ key: menuKey, @@ -132,7 +132,7 @@ function bar(env, view, choices) { help: env.I18n.T("signins.other"), helpSide: "top", menuTrigger: true, - onPress: view.Handler(async () => { + onPress: async () => { const items = []; for (let i = 1; i < choices.length; i++) { items.push({ id: `choice-${i}`, title: choices[i].label, enabled: !blocked }); @@ -155,7 +155,7 @@ function bar(env, view, choices) { env.run(choice); } } - }), + }, }), closeButton(env, view, "browser-signins-dismiss", env.I18n.T("signins.dismiss"), env.decline), ]), @@ -179,9 +179,9 @@ function card(env, view, choices) { variant: "neutral", disabled: blocked, loading: env.importing(choice), - onPress: view.Handler(() => { + onPress: () => { env.run(choice); - }), + }, }), ])); if (i < choices.length - 1) { @@ -203,27 +203,27 @@ function card(env, view, choices) { size: "small", variant: "ghost", disabled: blocked, - onPress: view.Handler(() => { + onPress: () => { env.choose(choices[0]); - }), + }, }), ui.button({ key: "browser-signins-decline", text: env.I18n.T("signins.dismiss"), size: "small", variant: "ghost", - onPress: view.Handler(() => { + onPress: () => { env.decline(); - }), + }, }), ui.button({ key: "browser-signins-settings", text: env.I18n.T("signins.more"), size: "small", variant: "ghost-muted", - onPress: view.Handler(() => { + onPress: () => { env.more(); - }), + }, }), ])); return ui.col({ key: "browser-signins", role: "region", label: env.I18n.T("signins.title"), w: "full", maxW: 608, px: 24, pt: 48, gap: 12 }, items); diff --git a/plugins/browser/site.js b/plugins/browser/site.js index 1b8fbe2a2..4d7a12785 100644 --- a/plugins/browser/site.js +++ b/plugins/browser/site.js @@ -183,9 +183,9 @@ site.render = function (env, view, url) { hover: "surface-hover", press: "surface-press", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { env.dispatch({ type: "details", shown: true }); - }), + }, }, [ ui.row({ w: 16, h: 20, center: true }, [ui.icon("outline-sliders", { size: 16, color: "icon-weak" })]), ui.text(env.I18n.T("site.settings"), BODY, { grow: 1, shrink: true, minW: 0 }), @@ -213,9 +213,9 @@ site.render = function (env, view, url) { variant: "ghost-muted", size: "small", label: env.I18n.T("site.back"), - onPress: view.Handler(() => { + onPress: () => { env.dispatch({ type: "details", shown: false }); - }), + }, }), ]), ui.text(env.I18n.T("site.settings"), BODY, { noWrap: true }), @@ -238,9 +238,9 @@ site.render = function (env, view, url) { size: "small", variant: "neutral", disabled: !enabled, - onPress: enabled ? view.Handler(() => { + onPress: enabled ? () => { env.dispatch({ type: failed ? "retry" : "clear.clicked" }); - }) : undefined, + } : undefined, }); items.push(row("outline-cookie", env.I18n.T("site.cookies"), detail, clearCookiesBtn)); @@ -253,9 +253,9 @@ site.render = function (env, view, url) { size: "small", variant: "neutral", disabled: !cacheEnabled, - onPress: cacheEnabled ? view.Handler(() => { + onPress: cacheEnabled ? () => { env.dispatch({ type: "clear-cache.clicked" }); - }) : undefined, + } : undefined, }); items.push(row("file-document", env.I18n.T("site.cache"), env.I18n.T("site.clearCache.description"), clearCacheBtn)); } diff --git a/plugins/btw/init.js b/plugins/btw/init.js index e6bb79838..c8e3752ea 100644 --- a/plugins/btw/init.js +++ b/plugins/btw/init.js @@ -5,8 +5,8 @@ // the session's store until the tab closes. const plugin = require("@opencode/plugin"); -const machine = require("@self/machine"); -const panel = require("@self/panel"); +const machine = require("./machine"); +const panel = require("./panel"); const INSTRUCTIONS = "The user is asking a quick side question about the conversation so far. Answer directly and concisely in markdown from what you already know. Do not call any tools and do not take any actions."; diff --git a/plugins/btw/panel.js b/plugins/btw/panel.js index d89724158..32d34179a 100644 --- a/plugins/btw/panel.js +++ b/plugins/btw/panel.js @@ -241,10 +241,10 @@ function prompt(env, view, id, info, agent, model, stamp) { "btw-copy-question", copied, tip, - view.Handler(() => { + () => { env.System.CopyText(question); markCopied(env, id, "question", question); - }) + } ), ]), ]); @@ -279,10 +279,10 @@ function answered(env, view, id, answer, agent, model, duration) { "btw-copy-answer", copied, I18n.T(copied ? "copied" : "copy"), - view.Handler(() => { + () => { env.System.CopyText(answer); markCopied(env, id, "answer", answer); - }) + } ), ]), ]; @@ -320,9 +320,9 @@ function failed(env, view, session, id, failure) { text: I18n.T("retry"), variant: "outline", size: "small", - onPress: view.Handler(() => { + onPress: () => { env.retry(session, id); - }), + }, }), ]), ]); diff --git a/plugins/context/indicator.js b/plugins/context/indicator.js index e0be79d52..5796b638c 100644 --- a/plugins/context/indicator.js +++ b/plugins/context/indicator.js @@ -97,7 +97,7 @@ indicator.header = function (env, view, props) { button( label, [circle], - view.Handler(() => { + () => { env.Popover.Toggle({ id: "usage", anchorKey: "context-usage", @@ -105,7 +105,7 @@ indicator.header = function (env, view, props) { align: "end", gap: 4, }); - }), + }, open ), ]); @@ -153,9 +153,9 @@ indicator.header = function (env, view, props) { button( label, children, - view.Handler(() => { + () => { env.Layout.TogglePanel("main"); - }), + }, false ), ]); @@ -210,10 +210,10 @@ indicator.menu = function (env, view, _props) { radius: 4, hover: "surface-hover", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { env.Popover.Close(); env.Layout.OpenPanel("main"); - }), + }, }, [ ui.text(env.I18n.T("usage.view"), { diff --git a/plugins/context/init.js b/plugins/context/init.js index d4755f230..7f86cb9ac 100644 --- a/plugins/context/init.js +++ b/plugins/context/init.js @@ -4,8 +4,8 @@ // prompt and its raw messages, which it exports. const plugin = require("@opencode/plugin"); -const indicator = require("@self/indicator"); -const tab = require("@self/tab"); +const indicator = require("./indicator"); +const tab = require("./tab"); module.exports = plugin.defineWindow((ctx) => { const I18n = ctx.GetService("I18n"); diff --git a/plugins/context/tab.js b/plugins/context/tab.js index ab8b2f501..42e29ec98 100644 --- a/plugins/context/tab.js +++ b/plugins/context/tab.js @@ -354,9 +354,9 @@ function rawMessages(env, view, sid, raws, generation, exporting, look) { opacity: disabled ? 0.5 : 1, onPress: disabled ? null - : view.Handler(() => { + : () => { startExport(env, sid); - }), + }, }, [ui.icon("download", EXPORT_ICON), ui.text(words, EXPORT_TEXT)] ); @@ -379,7 +379,7 @@ function rawMessages(env, view, sid, raws, generation, exporting, look) { key: `raw-${id}`, label: `${kind} ${id}`, corners: RAW_CORNERS[first ? 1 : 0][last && !isOpen ? 1 : 0], - onPress: view.Handler(() => { + onPress: () => { if (open[id]) { delete open[id]; } else { @@ -387,7 +387,7 @@ function rawMessages(env, view, sid, raws, generation, exporting, look) { } env.state.toggles += 1; env.refresh(); - }), + }, }, [ ui.text(`${kind} `, RAW_KIND), diff --git a/plugins/debug/console.js b/plugins/debug/console.js index dbca75b0f..74c08b99f 100644 --- a/plugins/debug/console.js +++ b/plugins/debug/console.js @@ -47,9 +47,9 @@ function card(env, view, n, l) { role: href ? "link" : null, label: at, onPress: href - ? view.Handler(() => { + ? () => { env.Links.Open({ href }); - }) + } : null, }, [ui.text(at, { size: 12, weight: "regular", lineHeight: 16, color: "text-interactive" })] @@ -158,9 +158,9 @@ console.render = function (env, view, props) { center: true, hover: "surface-hover", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { env.Console.Clear(); - }), + }, }, [ ui.text(env.I18n.T("console.clear"), { @@ -190,11 +190,11 @@ console.render = function (env, view, props) { border: "border-weak", hover: "surface-hover", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { const i = plugins.indexOf(current); env.state.target = plugins.length > 0 ? plugins[(i + 1) % plugins.length] : null; env.refresh(); - }), + }, }, [ ui.text(current, { diff --git a/plugins/debug/init.js b/plugins/debug/init.js index 04625919a..6da1828bc 100644 --- a/plugins/debug/init.js +++ b/plugins/debug/init.js @@ -6,9 +6,9 @@ const plugin = require("@opencode/plugin"); const ui = require("@opencode/ui"); -const machine = require("@self/machine"); -const turn = require("@self/turn"); -const consolePanel = require("@self/console"); +const machine = require("./machine"); +const turn = require("./turn"); +const consolePanel = require("./console"); // The speed cell steps through the common slow-downs, then back to full speed. function nextSpeed(speed) { @@ -431,9 +431,9 @@ module.exports = plugin.defineWindow((ctx) => { center: true, hover: "surface-hover", press: "surface-press", - onPress: v.Handler(() => { + onPress: () => { show(false); - }), + }, }, [ui.icon("close", { size: 16, color: "icon-weak" })] ) @@ -442,11 +442,11 @@ module.exports = plugin.defineWindow((ctx) => { const sessionTip = sid != null ? I18n.T("session.tip", { id: sid }) : I18n.T("session.none"); const copySession = sid != null - ? v.Handler(() => { + ? () => { const id = sid; System.CopyText(id); Toast.Show({ variant: "success", title: I18n.T("common.copied"), description: id }); - }) + } : null; cells.push( copyCell( @@ -480,9 +480,9 @@ module.exports = plugin.defineWindow((ctx) => { I18n.T("direction.tip"), I18n.T(`direction.${direction}`), rtl, - v.Handler(() => { + () => { Diagnostics.Set("direction", rtl ? "ltr" : "rtl"); - }) + } ) ); cells.push( @@ -492,9 +492,9 @@ module.exports = plugin.defineWindow((ctx) => { I18n.T("focus.tip"), I18n.T(focused ? "focus.on" : "focus.off"), focused, - v.Handler(() => { + () => { runFocus({ type: "toggle" }); - }) + } ) ); } @@ -510,7 +510,7 @@ module.exports = plugin.defineWindow((ctx) => { I18n.T(env ? "memory.tipEnv" : "memory.tip"), value, memoryLogActive(logState), - v.Handler(() => { + () => { // The environment's choice lasts for the launch. if (env) { return; @@ -518,7 +518,7 @@ module.exports = plugin.defineWindow((ctx) => { const on = logState !== "on"; memory.Set(on); Diagnostics.Set("memoryLog", on); - }) + } ) ); // A link cell: its name alone. @@ -547,17 +547,17 @@ module.exports = plugin.defineWindow((ctx) => { "debug-bar-console", I18n.T("console.label"), I18n.T("console.tip"), - v.Handler(() => { + () => { Layout.OpenPanel("console"); - }) + } ), link( "debug-bar-components", I18n.T("lab.label"), I18n.T("lab.tip"), - v.Handler(() => { + () => { Diagnostics.Set("components", true); - }) + } ), // Plex Mono draws an x between figures as a multiplication sign. toggle( @@ -566,9 +566,9 @@ module.exports = plugin.defineWindow((ctx) => { I18n.T("speed.tip"), `${speed.toFixed(2)}\u00d7`, Math.abs(speed - 1) > 1e-4, - v.Handler(() => { + () => { Diagnostics.Set("speed", nextSpeed(speed)); - }) + } ), toggle( "debug-bar-slow", @@ -576,9 +576,9 @@ module.exports = plugin.defineWindow((ctx) => { I18n.T("slow.tip"), I18n.T(slow ? "focus.on" : "focus.off"), slow, - v.Handler(() => { + () => { Diagnostics.Set("slow", !slow); - }) + } ), toggle( "debug-bar-knobs", @@ -586,11 +586,11 @@ module.exports = plugin.defineWindow((ctx) => { I18n.T("motion.tip"), I18n.T(knobs ? "focus.on" : "focus.off"), knobs, - v.Handler(() => { + () => { const b = bar.Get(); bar.Set({ visible: b.visible, motion: !knobs }); Diagnostics.Set("knobs", !knobs); - }) + } ), ]; cells.push(ui.spacer()); diff --git a/plugins/details/init.js b/plugins/details/init.js index 962419db3..d3ef649a2 100644 --- a/plugins/details/init.js +++ b/plugins/details/init.js @@ -7,8 +7,8 @@ const plugin = require("@opencode/plugin"); const ui = require("@opencode/ui"); -const lists = require("@self/lists"); -const mcp = require("@self/mcp"); +const lists = require("./lists"); +const mcp = require("./mcp"); // What the app's session header keeps at its end for its popovers to hang from (Desktop's // `Popover.Anchor`, 12 from the end, 10 down, 28 tall). @@ -211,7 +211,7 @@ module.exports = plugin.defineWindow((ctx) => { press: "surface-press", hoverTransition: "instant", fill: open ? "surface-press" : null, - onPress: view.Handler(toggle), + onPress: toggle, }, [ui.icon("window-analytics", { size: 16, color: open ? "icon-base" : "icon-weak" })] ), @@ -356,10 +356,10 @@ module.exports = plugin.defineWindow((ctx) => { radius: 4, hover: "surface-hover", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { state.opens += 1; Layout.OpenDrawerView(I18n.T(service), { service }); - }), + }, }, [ ui.icon(lists.icon(service), { size: 16, color: "icon-weak" }), diff --git a/plugins/details/lists.js b/plugins/details/lists.js index 1254aee62..6c2f1fd49 100644 --- a/plugins/details/lists.js +++ b/plugins/details/lists.js @@ -509,9 +509,9 @@ function mcpDot(env, view, item, directory) { h: 16, m: -5, center: true, - onPress: view.Handler(() => { + onPress: () => { mcp.dispatch(env.mcp, directory, { type: "error.opened", name: item.name, error: failure }); - }), + }, }, [dot(item.status, null)] ); @@ -565,13 +565,13 @@ function mcpRow(env, view, item, directory, key, mt, compact) { status: item.status, }); } - const follow = view.Handler(() => { + const follow = () => { if (failure) { mcp.dispatch(env.mcp, directory, { type: "error.opened", name: item.name, error: failure }); return; } change(item.status === "needs_auth" || disabled); - }); + }; // Below 640 points every MCP row stands 44 tall, 8 in above and below. const props = { key, mt, hover: pending ? null : "surface-hover", onPress: follow }; const trailing = @@ -584,9 +584,9 @@ function mcpRow(env, view, item, directory, key, mt, compact) { key: `details-switch-${item.name}`, checked: !disabled, disabled: pending, - onChange: view.Handler((event) => { + onChange: (event) => { change(event.checked === true); - }), + }, }), ]); return ui.row(compact ? MCP_ROW_COMPACT : MCP_ROW, props, [ @@ -619,14 +619,14 @@ function itemRow(env, view, service, item, directory, placement, first) { key, mt, // A skill opens its SKILL.md in a side tab; the popover closes as it does. - onPress: view.Handler(() => { + onPress: () => { if (item.path) { env.Links.Open({ href: item.path }); } if (placement.kind === "flyout") { env.Popover.Close(); } - }), + }, }, [ui.icon("file-document", ICON), name] ); @@ -647,9 +647,9 @@ function footer(env, view, service, empty, directory, placement) { "plus", env.I18n.T(`setup.${service}`), minH, - view.Handler(() => { + () => { configAction(env, service, directory, true); - }), + }, state != null && state.status === "opening" ) ); @@ -664,9 +664,9 @@ function footer(env, view, service, empty, directory, placement) { glyph, words, minH, - view.Handler(() => { + () => { configAction(env, service, directory, false); - }), + }, config != null && config.status === "opening" ); rows.push( @@ -684,10 +684,10 @@ function footer(env, view, service, empty, directory, placement) { "mcp", env.I18n.T("mcp.manage"), minH, - view.Handler(() => { + () => { env.Popover.Close(); env.Commands.Run("mcp.toggle"); - }) + } ) ); } @@ -728,9 +728,9 @@ function body(env, view, service, load, directory, placement) { radius: 4, hover: "surface-hover", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { env.Server.Invalidate("/api/"); - }), + }, }, [label(env.I18n.T("retry"))] ), diff --git a/plugins/details/mcp.js b/plugins/details/mcp.js index c1cb0492d..4b6322067 100644 --- a/plugins/details/mcp.js +++ b/plugins/details/mcp.js @@ -396,9 +396,9 @@ mcp.renderSignIn = function (env, view) { text: I18n.T("mcp.signIn.openBrowser"), icon: "arrow-up-right", variant: "neutral", - onPress: view.Handler(() => { + onPress: () => { mcp.signInStep(env, { type: "browser.open" }); - }), + }, }) ); } @@ -408,9 +408,9 @@ mcp.renderSignIn = function (env, view) { key: "mcp-sign-in-retry", text: I18n.T("tryAgain"), variant: "neutral", - onPress: view.Handler(() => { + onPress: () => { mcp.signInStep(env, { type: "retry.requested" }); - }), + }, }) ); } @@ -466,9 +466,9 @@ mcp.renderSignIn = function (env, view) { text: I18n.T("continue"), variant: "contrast", disabled: v.locked, - onPress: view.Handler(() => { + onPress: () => { mcp.signInStep(env, { type: "paste.submitted" }); - }), + }, }), ]) ); @@ -545,10 +545,10 @@ mcp.renderError = function (env, view, data, status) { text: I18n.T(current.copied ? "copied" : "mcp.error.copy"), icon: current.copied ? "check" : "copy", variant: "ghost-muted", - onPress: view.Handler(() => { + onPress: () => { env.System.CopyText(I18n.T("mcp.error.details", { name, error })); mcp.dispatch(env, directory, { type: "error.copied", attempt, error }); - }), + }, }), ui.spacer(), ui.button({ @@ -556,18 +556,18 @@ mcp.renderError = function (env, view, data, status) { text: I18n.T("mcp.error.disable"), variant: "ghost", disabled: current.busy, - onPress: view.Handler(() => { + onPress: () => { toggle(false); - }), + }, }), ui.button({ key: "error-details-retry", text: I18n.T("tryAgain"), variant: "neutral", disabled: current.busy, - onPress: view.Handler(() => { + onPress: () => { toggle(true); - }), + }, }), ]), ] diff --git a/plugins/file/init.js b/plugins/file/init.js index ce2e6887d..b2c380982 100644 --- a/plugins/file/init.js +++ b/plugins/file/init.js @@ -5,7 +5,7 @@ // change letters from the review's `review.changes`. const plugin = require("@opencode/plugin"); -const panel = require("@self/panel"); +const panel = require("./panel"); // The panel's id: its tabs key as `file:`, as Desktop's. const PANEL = "main"; diff --git a/plugins/goal/init.js b/plugins/goal/init.js index ed996651c..d2e86c32a 100644 --- a/plugins/goal/init.js +++ b/plugins/goal/init.js @@ -6,7 +6,7 @@ const plugin = require("@opencode/plugin"); const ui = require("@opencode/ui"); -const machine = require("@self/machine"); +const machine = require("./machine"); // The pill and the popover's status line of each goal status (`renderer.tsx`). The glyphs are the // plugin's own `icons/*.svg`, tinted by `tone`. @@ -198,10 +198,10 @@ module.exports = plugin.defineWindow((ctx) => { text: I18n.T(labelKey), size: "small", disabled: busy, - onPress: view.Handler(() => { + onPress: () => { Popover.Close(); dispatch({ type: "command", key: sid, action }); - }), + }, }; if (variant != null) { btnProps.variant = variant; diff --git a/plugins/microsoft-office/init.js b/plugins/microsoft-office/init.js index 071412e69..db14efb51 100644 --- a/plugins/microsoft-office/init.js +++ b/plugins/microsoft-office/init.js @@ -5,8 +5,8 @@ // them out on a thread of their own and draw their pages as vectors at the display's scale. const plugin = require("@opencode/plugin"); -const machine = require("@self/machine"); -const view = require("@self/view"); +const machine = require("./machine"); +const view = require("./view"); module.exports = plugin.defineWindow((ctx) => { const I18n = ctx.GetService("I18n"); diff --git a/plugins/microsoft-office/view.js b/plugins/microsoft-office/view.js index f9b39b91b..33e09ca9e 100644 --- a/plugins/microsoft-office/view.js +++ b/plugins/microsoft-office/view.js @@ -82,9 +82,9 @@ view.workbook = function (services, v, document, active, pick) { center: true, hover: "surface-2", hoverTransition: "instant", - onPress: v.Handler(() => { + onPress: () => { pick(index); - }), + }, }; if (selected) { rowProps.fill = "surface-2"; diff --git a/plugins/opencode.d.ts b/plugins/opencode.d.ts index e3922e1ce..89cec36fd 100644 --- a/plugins/opencode.d.ts +++ b/plugins/opencode.d.ts @@ -11058,6 +11058,8 @@ interface RuneSignalLibrary { /** Cooperative scheduling on the host's frame clock. Waiting costs no CPU. */ interface TaskLibrary { + /** Per-VM disposal signal, aborted automatically on hot reload or plugin teardown. */ + readonly signal: AbortSignal; /** Runs a function now (catching synchronous and Promise errors). */ spawn(callback: (...args: A) => R, ...args: A): TaskHandle; /** Runs a function at the end of the current handler or event batch, before the frame commits. */ @@ -11091,6 +11093,46 @@ declare function setInterval(callback: (...args: A) => /** Cancels a repeating timer scheduled by `setInterval` (or `setTimeout`). */ declare function clearInterval(id?: number | null): void; +/** Event delivered to `AbortSignal` listeners when aborted. */ +interface AbortEvent { + readonly type: "abort"; + readonly target: AbortSignal; + readonly currentTarget: AbortSignal; +} + +type AbortListener = + | ((this: AbortSignal, event: AbortEvent) => unknown) + | { handleEvent(event: AbortEvent): unknown }; + +/** Standard cancellation signal provided by `AbortController`, `AbortSignal.*`, and `task.signal`. */ +interface AbortSignal { + readonly aborted: boolean; + readonly reason: any; + onabort: ((this: AbortSignal, event: AbortEvent) => unknown) | null; + addEventListener(type: "abort", listener: AbortListener, options?: { once?: boolean }): void; + removeEventListener(type: "abort", listener: AbortListener): void; + throwIfAborted(): void; +} + +declare var AbortSignal: { + readonly prototype: AbortSignal; + new (): never; + abort(reason?: any): AbortSignal; + timeout(milliseconds: number): AbortSignal; + any(signals: Iterable): AbortSignal; +}; + +/** Standard controller whose `abort(reason?)` triggers its paired `AbortSignal`. */ +interface AbortController { + readonly signal: AbortSignal; + abort(reason?: any): void; +} + +declare var AbortController: { + readonly prototype: AbortController; + new (): AbortController; +}; + /** CommonJS module object for plugin entrypoints and local modules. */ declare var module: { exports: any }; declare var exports: any; @@ -11108,11 +11150,147 @@ declare module "@opencode/plugin" { } declare module "@opencode/ui" { + namespace ui { + type Token = SemanticToken; + type Color = SemanticToken | HexColor; + type Size = UiSize; + type Node = UiNode; + type Handler = UiHandler; + type Event = UiEvent; + type LayoutProps = UiLayoutProps; + type Pin = UiPin; + type Point = UiPoint; + type RichSegment = UiRichSegment; + type RichItem = UiRichItem; + type BoxProps = UiBoxProps; + type FrameProps = UiFrameProps; + type TextProps = UiTextProps; + type SpacerProps = UiSpacerProps; + type DividerProps = UiDividerProps; + type IconProps = UiIconProps; + type ImageProps = UiImageProps; + type VideoProps = UiVideoProps; + type SurfaceProps = UiSurfaceProps; + type MetricProps = UiMetricProps; + type ButtonProps = UiButtonProps; + type IconButtonProps = UiIconButtonProps; + type SwitchProps = UiSwitchProps; + type CheckboxProps = UiCheckboxProps; + type RadioProps = UiRadioProps; + type FieldProps = UiFieldProps; + type SegmentedItem = UiSegmentedItem; + type ListboxProps = UiListboxProps; + type OptionProps = UiOptionProps; + type SelectOption = UiSelectOption; + type SelectProps = UiSelectProps; + type SegmentedProps = UiSegmentedProps; + type LoaderProps = UiLoaderProps; + type ServerIndicatorProps = UiServerIndicatorProps; + type PillProps = UiPillProps; + type KeybindProps = UiKeybindProps; + type SettingsRowProps = UiSettingsRowProps; + type SettingsListProps = UiSettingsListProps; + type FlyoutRowProps = UiFlyoutRowProps; + type BadgeProps = UiBadgeProps; + type DialogHeaderProps = UiDialogHeaderProps; + type TooltipProps = UiTooltipProps; + type DragItemProps = UiDragItemProps; + type DropZoneProps = UiDropZoneProps; + type SplitPaneProps = UiSplitPaneProps; + type CodeProps = UiCodeProps; + type MarkdownProps = UiMarkdownProps; + type VirtualListProps = UiVirtualListProps; + type TerminalSurfaceProps = UiTerminalSurfaceProps; + type TerminalTabLabelProps = UiTerminalTabLabelProps; + type BrowserSurfaceProps = UiBrowserSurfaceProps; + type CodeViewProps = UiCodeViewProps; + type DiffViewProps = UiDiffViewProps; + type FileTreeProps = UiFileTreeProps; + type PanelSidebarProps = UiPanelSidebarProps; + type OpenInButtonProps = UiOpenInButtonProps; + type OfficePagesProps = UiOfficePagesProps; + type OfficeSheetProps = UiOfficeSheetProps; + type GenUiProps = UiGenUiProps; + type ProgressCircleProps = UiProgressCircleProps; + type EmbedProps = UiEmbedProps; + type Align = UiAlign; + type Justify = UiJustify; + type Direction = UiDirection; + type EventKind = UiEventKind; + } const ui: UiLibrary; export = ui; } declare module "@rune/ui" { + namespace ui { + type Token = SemanticToken; + type Color = SemanticToken | HexColor; + type Size = UiSize; + type Node = UiNode; + type Handler = UiHandler; + type Event = UiEvent; + type LayoutProps = UiLayoutProps; + type Pin = UiPin; + type Point = UiPoint; + type RichSegment = UiRichSegment; + type RichItem = UiRichItem; + type BoxProps = UiBoxProps; + type FrameProps = UiFrameProps; + type TextProps = UiTextProps; + type SpacerProps = UiSpacerProps; + type DividerProps = UiDividerProps; + type IconProps = UiIconProps; + type ImageProps = UiImageProps; + type VideoProps = UiVideoProps; + type SurfaceProps = UiSurfaceProps; + type MetricProps = UiMetricProps; + type ButtonProps = UiButtonProps; + type IconButtonProps = UiIconButtonProps; + type SwitchProps = UiSwitchProps; + type CheckboxProps = UiCheckboxProps; + type RadioProps = UiRadioProps; + type FieldProps = UiFieldProps; + type SegmentedItem = UiSegmentedItem; + type ListboxProps = UiListboxProps; + type OptionProps = UiOptionProps; + type SelectOption = UiSelectOption; + type SelectProps = UiSelectProps; + type SegmentedProps = UiSegmentedProps; + type LoaderProps = UiLoaderProps; + type ServerIndicatorProps = UiServerIndicatorProps; + type PillProps = UiPillProps; + type KeybindProps = UiKeybindProps; + type SettingsRowProps = UiSettingsRowProps; + type SettingsListProps = UiSettingsListProps; + type FlyoutRowProps = UiFlyoutRowProps; + type BadgeProps = UiBadgeProps; + type DialogHeaderProps = UiDialogHeaderProps; + type TooltipProps = UiTooltipProps; + type DragItemProps = UiDragItemProps; + type DropZoneProps = UiDropZoneProps; + type SplitPaneProps = UiSplitPaneProps; + type CodeProps = UiCodeProps; + type MarkdownProps = UiMarkdownProps; + type VirtualListProps = UiVirtualListProps; + type TerminalSurfaceProps = UiTerminalSurfaceProps; + type TerminalTabLabelProps = UiTerminalTabLabelProps; + type BrowserSurfaceProps = UiBrowserSurfaceProps; + type CodeViewProps = UiCodeViewProps; + type DiffViewProps = UiDiffViewProps; + type FileTreeProps = UiFileTreeProps; + type PanelSidebarProps = UiPanelSidebarProps; + type OpenInButtonProps = UiOpenInButtonProps; + type OfficePagesProps = UiOfficePagesProps; + type OfficeSheetProps = UiOfficeSheetProps; + type GenUiProps = UiGenUiProps; + type ProgressCircleProps = UiProgressCircleProps; + type EmbedProps = UiEmbedProps; + type Align = UiAlign; + type Justify = UiJustify; + type Direction = UiDirection; + type EventKind = UiEventKind; + } const ui: UiLibrary; export = ui; } diff --git a/plugins/pairing/init.js b/plugins/pairing/init.js index 35b263afb..8c05c6267 100644 --- a/plugins/pairing/init.js +++ b/plugins/pairing/init.js @@ -7,8 +7,8 @@ const plugin = require("@opencode/plugin"); const ui = require("@opencode/ui"); -const machine = require("@self/machine"); -const copy = require("@self/copy"); +const machine = require("./machine"); +const copy = require("./copy"); // `text-13-regular` as the page's alerts draw it. const ALERT = { @@ -428,9 +428,9 @@ module.exports = plugin.defineWindow((ctx) => { text: I18n.T("pair.open"), variant: "neutral", disabled, - onPress: v.Handler(() => { + onPress: () => { dispatch({ type: "dialog.opened" }); - }), + }, }) ); } @@ -464,9 +464,9 @@ module.exports = plugin.defineWindow((ctx) => { label: I18n.T("remote.title"), checked: view.remoteChecked, disabled: view.remoteDisabled, - onChange: v.Handler((event) => { + onChange: (event) => { dispatch({ type: "toggled", enabled: event.checked === true }); - }), + }, }) ) ); @@ -482,9 +482,9 @@ module.exports = plugin.defineWindow((ctx) => { label: I18n.T("screenActive.title"), checked: view.screenChecked, disabled: view.screenDisabled, - onChange: v.Handler((event) => { + onChange: (event) => { dispatch({ type: "screen.toggled", enabled: event.checked === true }); - }), + }, }) ) ); @@ -502,9 +502,9 @@ module.exports = plugin.defineWindow((ctx) => { text: I18n.T("retry"), variant: "ghost", size: "small", - onPress: v.Handler(() => { + onPress: () => { dispatch({ type: "screen.retry" }); - }), + }, }), ]) ); @@ -585,10 +585,10 @@ module.exports = plugin.defineWindow((ctx) => { text: I18n.T("refresh"), variant: "ghost", disabled, - onPress: v.Handler(() => { + onPress: () => { dispatchCopy({ type: "reset" }); dispatch({ type: "code.refresh" }); - }), + }, }); } function addressEditorView() { @@ -602,7 +602,7 @@ module.exports = plugin.defineWindow((ctx) => { label: I18n.T("address.label"), placeholder: I18n.T("address.placeholder"), invalid, - onSubmit: v.Handler(saveAddress), + onSubmit: saveAddress, }), ]; if (invalid) { @@ -625,17 +625,17 @@ module.exports = plugin.defineWindow((ctx) => { key: "pairing-address-cancel", text: I18n.T("common.cancel"), variant: "ghost", - onPress: v.Handler(() => { + onPress: () => { editing = false; invalid = false; rev.Fire(); - }), + }, }), ui.button({ key: "pairing-address-save", text: I18n.T("address.save"), variant: "neutral", - onPress: v.Handler(saveAddress), + onPress: saveAddress, }), ]) ); @@ -677,7 +677,7 @@ module.exports = plugin.defineWindow((ctx) => { key: "pairing-edit-address", text: I18n.T("edit"), variant: "ghost", - onPress: v.Handler(openEditor), + onPress: openEditor, }), refreshBtn(d.refreshing != null), ui.button({ @@ -686,9 +686,9 @@ module.exports = plugin.defineWindow((ctx) => { icon: copyView.icon, variant: "neutral", disabled: copyView.disabled, - onPress: v.Handler(() => { + onPress: () => { dispatchCopy({ type: "copy.requested", url: d.url }); - }), + }, }), ]), ]) @@ -730,15 +730,15 @@ module.exports = plugin.defineWindow((ctx) => { text: I18n.T("address.use"), variant: "ghost", disabled: editing, - onPress: v.Handler(openEditor), + onPress: openEditor, }), ui.button({ key: "pairing-retry", text: I18n.T("retry"), variant: "neutral", - onPress: v.Handler(() => { + onPress: () => { dispatch({ type: "retry" }); - }), + }, }), ]), ]) @@ -791,7 +791,7 @@ module.exports = plugin.defineWindow((ctx) => { radius: 4, center: true, hover: "surface-hover", - onPress: v.Handler(close), + onPress: close, }, [ui.icon("dialog-close", { size: 16, color: "icon-weak" })] ), diff --git a/plugins/review/init.js b/plugins/review/init.js index e0f1f40f6..e055a57ef 100644 --- a/plugins/review/init.js +++ b/plugins/review/init.js @@ -5,8 +5,8 @@ // details read. The changes themselves come from the host's diff engine (`Diff`). const plugin = require("@opencode/plugin"); -const kinds = require("@self/kinds"); -const panel = require("@self/panel"); +const kinds = require("./kinds"); +const panel = require("./panel"); // The tab's id: its key is `review:changes`, as Desktop's. const TAB = "changes"; diff --git a/plugins/review/panel.js b/plugins/review/panel.js index b64aa4845..1be2881c9 100644 --- a/plugins/review/panel.js +++ b/plugins/review/panel.js @@ -162,7 +162,7 @@ panel.title = function (env, view, sid, key) { shrink: true, minW: 0, menuTrigger: env.menuTrigger, - onPress: view.Handler(async () => { + onPress: async () => { const items = []; for (const mode of sources) { items.push({ id: mode, title: sourceLabel(env, mode), checked: mode === current }); @@ -171,7 +171,7 @@ panel.title = function (env, view, sid, key) { if (picked != null && picked !== current) { panel.setSource(env, sid, picked); } - }), + }, }, [label, chevron] ); @@ -207,9 +207,9 @@ function arrow(env, view, key, icon, help, go) { }; if (go) { props.hover = "surface-hover"; - props.onPress = view.Handler(() => { + props.onPress = () => { go(); - }); + }; } else { props.opacity = 0.35; } @@ -292,9 +292,9 @@ function failed(env, view, doc, why) { hover: "surface-hover", press: "surface-press", hoverTransition: "instant", - onPress: view.Handler(() => { + onPress: () => { doc.Retry(); - }), + }, }, [ui.text(env.I18n.T("common.retry"), { size: 13, weight: "medium", lineHeight: 20, color: "text-base" })] ), @@ -414,14 +414,14 @@ function sidebar(env, view, sid, doc, marks, active, treeVer, side, compact) { kinds: marks, pt: 4, grow: 1, - onSelect: view.Handler((event) => { + onSelect: (event) => { if (event.path) { panel.focus(env, sid, event.path); if (compact && env.Layout.PanelSidebar().opened) { env.Layout.TogglePanelSidebar(); } } - }), + }, }; if (active != null) { treeProps.selectedPath = active; @@ -524,9 +524,9 @@ function toolbar(env, view, sid, doc, order, active, opened, treeVer, side, comp key: "review-collapse-unchanged", }, ], - onChange: view.Handler((event) => { + onChange: (event) => { env.expand.Set({ expandMode: event.value || "collapse" }); - }), + }, }) ); segments.push( @@ -547,9 +547,9 @@ function toolbar(env, view, sid, doc, order, active, opened, treeVer, side, comp key: "review-style-split", }, ], - onChange: view.Handler((event) => { + onChange: (event) => { panel.setStyle(env, event.value || "split"); - }), + }, }) ); // 48 tall with its rule inside (`session-review-v2-toolbar`: `h-12`, border-box). Shut, it diff --git a/plugins/sources/init.js b/plugins/sources/init.js index 07e9e36e0..0b44902cc 100644 --- a/plugins/sources/init.js +++ b/plugins/sources/init.js @@ -5,7 +5,7 @@ // closes them. const plugin = require("@opencode/plugin"); -const panel = require("@self/panel"); +const panel = require("./panel"); // The links the timeline's chip opens: the turn's user message id after it. const LINK = "opencode-sources:"; diff --git a/plugins/sources/panel.js b/plugins/sources/panel.js index 5423cf14d..f55a13aa3 100644 --- a/plugins/sources/panel.js +++ b/plugins/sources/panel.js @@ -224,9 +224,9 @@ function result(env, view, r, mode) { gap: 10, radius: 8, hover: "surface-hover", - onPress: view.Handler(() => { + onPress: () => { env.Links.Open({ href: r.url }); - }), + }, }, [ siteIcon(env, r.site, r.host, mode), @@ -289,10 +289,10 @@ function search(env, view, s, mode) { if (expandable) { const id = s.id; extra.label = `${I18n.T("searched")} ${s.query}`; - extra.onPress = view.Handler(() => { + extra.onPress = () => { env.state.expand[id] = env.state.expand[id] === "open" ? "closed" : "open"; env.refresh(); - }); + }; } const step = [stepRow(`sources-step-${s.id}`, "magnifying-glass", text, count, expandable, extra)]; if (open && expandable) { @@ -339,9 +339,9 @@ function fetchStep(env, view, s) { const row = stepRow(`sources-step-${s.id}`, "window-cursor", text, null, true, { label: `${I18n.T("opened")} ${url}`, help: url, - onPress: view.Handler(() => { + onPress: () => { env.Links.Open({ href: url }); - }), + }, }); return ui.col({ key: `sources-fetch-${s.id}`, w: "full" }, [row]); } diff --git a/plugins/ssh/cover.js b/plugins/ssh/cover.js index 3abd20b2f..b89c57d2d 100644 --- a/plugins/ssh/cover.js +++ b/plugins/ssh/cover.js @@ -81,9 +81,9 @@ cover.render = function render(env, v, props) { variant: "neutral", loading: connecting, disabled: connecting, - onPress: v.Handler(() => { + onPress: () => { env.connect(id); - }), + }, }) ); return ui.col( diff --git a/plugins/ssh/dialog.js b/plugins/ssh/dialog.js index ef3bce676..2ddbdcb34 100644 --- a/plugins/ssh/dialog.js +++ b/plugins/ssh/dialog.js @@ -296,22 +296,22 @@ dialog.render = function render(env, v) { key: "ssh-cancel", text: I18n.T("common.cancel"), variant: "neutral", - onPress: v.Handler(() => { + onPress: () => { env.close(); - }), + }, }), ui.button({ key: "ssh-primary", text: I18n.T(view.primary.label), variant: "contrast", disabled: view.primary.disabled, - onPress: v.Handler(() => { + onPress: () => { if (view.primary.action === "respond") { c.respond(); } else { c.submit(); } - }), + }, }), ]), ]); diff --git a/plugins/ssh/init.js b/plugins/ssh/init.js index 13ca41fd8..e271d2e65 100644 --- a/plugins/ssh/init.js +++ b/plugins/ssh/init.js @@ -5,10 +5,10 @@ // contract. const plugin = require("@opencode/plugin"); -const dialog = require("@self/dialog"); -const row = require("@self/row"); -const cover = require("@self/cover"); -const command = require("@self/command"); +const dialog = require("./dialog"); +const row = require("./row"); +const cover = require("./cover"); +const command = require("./command"); function sshId(key) { if (typeof key !== "string") { diff --git a/plugins/ssh/row.js b/plugins/ssh/row.js index e7411995b..c5e417056 100644 --- a/plugins/ssh/row.js +++ b/plugins/ssh/row.js @@ -65,9 +65,9 @@ row.render = function render(env, v, props) { size: "small", loading: pending, disabled: pending, - onPress: v.Handler(() => { + onPress: () => { env.connect(id); - }), + }, }) ); } @@ -80,7 +80,7 @@ row.render = function render(env, v, props) { size: "small", label: I18n.T("common.moreOptions"), menuTrigger: env.menuTrigger, - onPress: v.Handler(async () => { + onPress: async () => { const now = env.item(id); if (!now) { return; @@ -104,7 +104,7 @@ row.render = function render(env, v, props) { } else if (picked === "delete") { env.forget(id); } - }), + }, }) ); return ui.row({ key: `ssh-row-${id}`, w: "full", gap: 16, align: "center" }, [ diff --git a/plugins/tsconfig.json b/plugins/tsconfig.json index 22e8b5065..096287ed6 100644 --- a/plugins/tsconfig.json +++ b/plugins/tsconfig.json @@ -14,6 +14,8 @@ "opencode.d.ts", "types/**/*.d.ts", "*/*.js", - "*/*/*.js" + "*/*/*.js", + "*/*.ts", + "*/*/*.ts" ] } diff --git a/plugins/types/ui.d.ts b/plugins/types/ui.d.ts index 57ab6bd52..17b5bc375 100644 --- a/plugins/types/ui.d.ts +++ b/plugins/types/ui.d.ts @@ -4,6 +4,7 @@ declare namespace ui { type Token = SemanticToken; + type Color = SemanticToken | HexColor; type Size = UiSize; type Node = UiNode; type Handler = UiHandler; diff --git a/plugins/updater/init.js b/plugins/updater/init.js index d9883f1fd..8b8f4f543 100644 --- a/plugins/updater/init.js +++ b/plugins/updater/init.js @@ -7,10 +7,10 @@ // (`Updater`); this window's own requests follow `machine.js` (`window-machine.ts`). const plugin = require("@opencode/plugin"); -const machine = require("@self/machine"); -const action = require("@self/action"); -const whatsnew = require("@self/whatsnew"); -const view = require("@self/view"); +const machine = require("./machine"); +const action = require("./action"); +const whatsnew = require("./whatsnew"); +const view = require("./view"); module.exports = plugin.defineWindow((ctx) => { const I18n = ctx.GetService("I18n"); diff --git a/plugins/updater/view.js b/plugins/updater/view.js index 0a02c83db..19458df89 100644 --- a/plugins/updater/view.js +++ b/plugins/updater/view.js @@ -19,9 +19,9 @@ view.section = function (i18n, v, input) { key: "release-notes-switch", label: i18n.T("releaseNotes.title"), checked: input.releaseNotes, - onChange: v.Handler((event) => { + onChange: (event) => { input.toggle(event.checked === true); - }), + }, }) ), ]; @@ -38,9 +38,9 @@ view.section = function (i18n, v, input) { label: i18n.T("installOnQuit.title"), disabled: input.installOnQuitDisabled, checked: input.installOnQuitDisabled ? false : input.installOnQuit, - onChange: v.Handler((event) => { + onChange: (event) => { input.toggleInstallOnQuit(event.checked === true); - }), + }, }) ) ); @@ -56,7 +56,7 @@ view.section = function (i18n, v, input) { key: "check-updates-button", text: i18n.T(input.label), disabled: !input.enabled, - onPress: v.Handler(input.run), + onPress: input.run, }) ) ); @@ -87,9 +87,9 @@ view.highlights = function (i18n, v, input) { w: current ? 32 : 12, h: 24, align: "center", - onPress: v.Handler(() => { + onPress: () => { input.go(i); - }), + }, }, [ui.box({ w: "full", h: 2, radius: 1, fill: current ? strong : weak })] ) @@ -131,13 +131,13 @@ view.highlights = function (i18n, v, input) { text: i18n.T(last ? "releaseNotes.action.getStarted" : "releaseNotes.action.next"), size: "large", autofocus: true, - onPress: v.Handler(() => { + onPress: () => { if (last) { input.close(); } else { input.go(index + 1); } - }), + }, }; if (last) { primaryProps.variant = "contrast"; @@ -150,7 +150,7 @@ view.highlights = function (i18n, v, input) { text: i18n.T("releaseNotes.action.hideFuture"), variant: "ghost", size: "small", - onPress: v.Handler(input.disable), + onPress: input.disable, }), ]), ]; diff --git a/plugins/usage/init.js b/plugins/usage/init.js index 43651ffe0..b78fae598 100644 --- a/plugins/usage/init.js +++ b/plugins/usage/init.js @@ -4,9 +4,9 @@ // longer than 15 s, offers Try again; a server not signed in to Console says so. const plugin = require("@opencode/plugin"); -const limits = require("@self/limits"); -const machine = require("@self/machine"); -const view = require("@self/view"); +const limits = require("./limits"); +const machine = require("./machine"); +const view = require("./view"); // Canonical palette slot matching the former `commands::order::USAGE_VIEW`. const PALETTE_ORDER = 560; @@ -393,17 +393,17 @@ module.exports = plugin.defineWindow((ctx) => { return v.Memo("usage-dialog-body", memoVersion, () => { return view.render(I18n, load, model, credits, nowMs, { - onRetry: v.Handler(retry), - onSwitch: v.Handler(() => { + onRetry: retry, + onSwitch: () => { closeState(); Dialog.Close(); Commands.Run("model"); - }), - onDetails: v.Handler(() => { + }, + onDetails: () => { if (usageUrl !== "") { System.OpenExternal(usageUrl); } - }), + }, }); }); }, diff --git a/plugins/wsl/init.js b/plugins/wsl/init.js index 7a1f927e1..ea5d6d68f 100644 --- a/plugins/wsl/init.js +++ b/plugins/wsl/init.js @@ -4,10 +4,10 @@ // answers through the `wsl` contract. const plugin = require("@opencode/plugin"); -const dialog = require("@self/dialog"); -const view = require("@self/view"); -const row = require("@self/row"); -const model = require("@self/model"); +const dialog = require("./dialog"); +const view = require("./view"); +const row = require("./row"); +const model = require("./model"); function wslDistro(key) { if (typeof key !== "string") { diff --git a/plugins/wsl/row.js b/plugins/wsl/row.js index bad97a2d7..74ed647cd 100644 --- a/plugins/wsl/row.js +++ b/plugins/wsl/row.js @@ -52,9 +52,9 @@ row.render = function render(env, v, props) { variant: "neutral", size: "small", disabled: r.button.disabled, - onPress: v.Handler(() => { + onPress: () => { env.run("installOpencode", distro); - }), + }, }) ); } @@ -67,7 +67,7 @@ row.render = function render(env, v, props) { size: "small", label: I18n.T("common.moreOptions"), menuTrigger: env.menuTrigger, - onPress: v.Handler(async () => { + onPress: async () => { const cur = env.api(); const now = model.row(cur ? cur.state : null, distro); const items = [{ kind: "group", title: I18n.T("server.menu.label") }]; @@ -87,7 +87,7 @@ row.render = function render(env, v, props) { } else if (picked === "remove") { env.run("removeServer", `wsl:${distro}`); } - }), + }, }) ); return ui.row({ key: `wsl-row-${distro}`, w: "full", gap: 16, align: "center" }, [ diff --git a/plugins/wsl/view.js b/plugins/wsl/view.js index fb4e7b6a2..3a7015308 100644 --- a/plugins/wsl/view.js +++ b/plugins/wsl/view.js @@ -57,7 +57,7 @@ function radioRow(v, key, label, description, tone, checked, disabled, rule, min label, }; if (!disabled) { - rowProps.onPress = v.Handler(pick); + rowProps.onPress = pick; } const radioProps = { text: label, @@ -105,13 +105,13 @@ function catalogCard(env, v, m) { opacity: m.busy ? 0.5 : 1, }; if (!m.busy) { - cardProps.onPress = v.Handler(() => { + cardProps.onPress = () => { env.controller.dispatch({ type: "catalog.opened", defaultTarget: m.installable.length > 0 ? m.installable[0].name : null, busy: m.busy, }); - }); + }; } return ui.row(cardProps, [ ui.icon("download", { size: 16, color: "icon-base" }), @@ -138,9 +138,9 @@ function mainView(env, v, m) { variant: "ghost-muted", size: "small", disabled: m.busy, - onPress: v.Handler(() => { + onPress: () => { c.dispatch({ type: "distros.refresh.requested", busy: c.model().busy }); - }), + }, }); const section = ui.row({ w: "full", h: 24, pl: 9, gap: 12, align: "center", justify: "between" }, [ ui.text(env.I18n.T("onboarding.installedDistros"), BODY), @@ -202,7 +202,7 @@ function mainView(env, v, m) { variant: pb.variant === "contrast" ? "contrast" : "neutral", loading: pb.loading, disabled: !pb.loading && pb.disabled, - onPress: v.Handler(() => { + onPress: () => { const now = c.model(); const button = now.primary; c.dispatch({ @@ -216,7 +216,7 @@ function mainView(env, v, m) { : null, disabled: button.disabled || button.loading, }); - }), + }, }; if (pb.width !== null && pb.width !== undefined) { primaryProps.w = pb.width; @@ -227,9 +227,9 @@ function mainView(env, v, m) { text: env.I18n.T("common.cancel"), variant: "neutral", disabled: m.adding, - onPress: v.Handler(() => { + onPress: () => { env.close(); - }), + }, }); return [ header(env.I18n.T("server.add")), @@ -287,9 +287,9 @@ function catalogView(env, v, m) { text: env.I18n.T("common.cancel"), variant: "neutral", disabled: m.busy, - onPress: v.Handler(() => { + onPress: () => { c.dispatch({ type: "catalog.closed", busy: c.model().busy }); - }), + }, }); const installing = m.installingCatalog; const install = ui.button({ @@ -299,10 +299,10 @@ function catalogView(env, v, m) { loading: installing, disabled: !installing && (m.busy || m.catalogTarget == null), w: 99, - onPress: v.Handler(() => { + onPress: () => { const now = c.model(); c.dispatch({ type: "catalog.install.requested", distro: now.catalogTarget, busy: now.busy }); - }), + }, }); return [ header(env.I18n.T("onboarding.installDistro")), @@ -372,9 +372,9 @@ function setupCard(env, v, state, err, isInstallable, busy) { text: env.I18n.T("onboarding.installWsl"), variant: "neutral", disabled: busy, - onPress: v.Handler(() => { + onPress: () => { env.controller.dispatch({ type: "wsl.install.requested", busy: env.controller.model().busy }); - }), + }, }) ); } @@ -384,9 +384,9 @@ function setupCard(env, v, state, err, isInstallable, busy) { key: "wsl-close", text: env.I18n.T("common.close"), variant: "neutral", - onPress: v.Handler(() => { + onPress: () => { env.close(); - }), + }, }) ); } From 3492f2a25363a0748140bd2d746a91f53a7079e7 Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Thu, 3 Dec 2026 20:50:35 +1000 Subject: [PATCH 2/2] fix(plugins): address PR #2283 review feedback - Scope ScriptOptions::strict_props to debug builds, --plugin-hot, and Tier::Dev so installed User/Override plugins preserve Compat::NewerMinor forward compatibility in release builds. - Skip unused .ts files in script_sources() when the resolved plugin entry is .js. - Match both .js: and .ts: (earliest occurrence) in opencode-plugin-runtime console::location() for clickable Debug console source links. - Include app-half VM heap memory alongside window-half memory in Plugin::memory_bytes() for Settings > Extensions > Plugins telemetry. - Align WrapState::active_target() with WrapEvent::Exit (nearest active frame) and accept .ts (excluding .d.ts) in desktop build.rs and runtime/sources.rs. --- apps/desktop/build.rs | 8 ++++++-- apps/desktop/src/plugin_host/aux_windows/dispatch.rs | 2 +- apps/desktop/src/plugin_host/mod.rs | 11 +++++++++-- apps/desktop/src/plugin_host/runtime/sources.rs | 4 ++-- apps/desktop/src/plugin_host/runtime/vm.rs | 2 +- crates/opencode-plugin-runtime/src/console.rs | 9 ++++++--- crates/opencode-plugin-runtime/src/sources.rs | 9 ++++++++- 7 files changed, 33 insertions(+), 12 deletions(-) diff --git a/apps/desktop/build.rs b/apps/desktop/build.rs index 2089d7bb0..b1bc2c89d 100644 --- a/apps/desktop/build.rs +++ b/apps/desktop/build.rs @@ -160,7 +160,7 @@ fn embed_js_plugins(manifest_dir: &std::path::Path, out: &std::path::Path) { } let js_sources: Vec = files .iter() - .filter(|(rel, _)| rel.ends_with(".js")) + .filter(|(rel, _)| is_script(rel)) .filter_map(|(_, path)| std::fs::read_to_string(path).ok()) .collect(); let mut kinds: Vec = js_sources @@ -245,6 +245,10 @@ fn embed_js_plugins(manifest_dir: &std::path::Path, out: &std::path::Path) { out } + fn is_script(path: &str) -> bool { + path.ends_with(".js") || (path.ends_with(".ts") && !path.ends_with(".d.ts")) + } + fn walk(root: &std::path::Path, dir: &std::path::Path, out: &mut Vec<(String, std::path::PathBuf)>) { for path in std::fs::read_dir(dir).into_iter().flatten().flatten().map(|e| e.path()) { let name = path.file_name().map(|n| n.to_string_lossy().into_owned()).unwrap_or_default(); @@ -255,7 +259,7 @@ fn embed_js_plugins(manifest_dir: &std::path::Path, out: &std::path::Path) { continue; } let under = |dir: &str, ext: &str| name.ends_with(ext) && path.parent().is_some_and(|p| p.ends_with(dir)); - let keep = name.ends_with(".js") || name == "plugin.toml" || under("locales", ".json") || under("locales/fill", ".json") || under("icons", ".svg"); + let keep = is_script(&name) || name == "plugin.toml" || under("locales", ".json") || under("locales/fill", ".json") || under("icons", ".svg"); if let (true, Ok(rel)) = (keep, path.strip_prefix(root)) { let rel: Vec = rel.components().map(|c| c.as_os_str().to_string_lossy().into_owned()).collect(); out.push((rel.join("/"), path)); diff --git a/apps/desktop/src/plugin_host/aux_windows/dispatch.rs b/apps/desktop/src/plugin_host/aux_windows/dispatch.rs index 9a5711470..7b503bfcc 100644 --- a/apps/desktop/src/plugin_host/aux_windows/dispatch.rs +++ b/apps/desktop/src/plugin_host/aux_windows/dispatch.rs @@ -63,7 +63,7 @@ impl WrapState { fn active_target(&self) -> Option<&AuxTarget> { match self { Self::Unwrapped => None, - Self::Wrapped { frames } => frames.last().and_then(Option::as_ref), + Self::Wrapped { frames } => frames.iter().rev().find_map(Option::as_ref), } } diff --git a/apps/desktop/src/plugin_host/mod.rs b/apps/desktop/src/plugin_host/mod.rs index 4758b75b8..844f822e7 100644 --- a/apps/desktop/src/plugin_host/mod.rs +++ b/apps/desktop/src/plugin_host/mod.rs @@ -140,9 +140,16 @@ impl Plugin { self.life.script() } - /// Live VM heap usage in bytes (`0` when the plugin has no running script). + /// Live VM heap usage in bytes across this plugin's window half and app half (`0` when neither + /// half has a running script). pub fn memory_bytes(&self) -> usize { - self.script().map_or(0, Script::memory) + let window = self.script().map_or(0, Script::memory); + let app: usize = runtime::app_half::each(|a| { + (&*a.half.id == self.manifest.id.as_str()).then(|| a.script.memory()) + }) + .into_iter() + .sum(); + window + app } /// The window half's script when `half.contribs` belongs to its current VM, preventing diff --git a/apps/desktop/src/plugin_host/runtime/sources.rs b/apps/desktop/src/plugin_host/runtime/sources.rs index 75c9fcc6e..3f7aae441 100644 --- a/apps/desktop/src/plugin_host/runtime/sources.rs +++ b/apps/desktop/src/plugin_host/runtime/sources.rs @@ -50,7 +50,7 @@ mod disk { let files = opencode_plugin_runtime::sources::read_files(&dir); let mut kinds: Vec<&'static str> = files .iter() - .filter(|(rel, _)| rel.ends_with(".js")) + .filter(|(rel, _)| opencode_plugin_runtime::sources::is_script(rel)) .flat_map(|(_, src)| { src.split("ctx.Add") .skip(1) @@ -64,7 +64,7 @@ mod disk { kinds.dedup(); let mut sigs: Vec<&'static str> = files .iter() - .filter(|(rel, _)| rel.ends_with(".js")) + .filter(|(rel, _)| opencode_plugin_runtime::sources::is_script(rel)) .flat_map(|(_, src)| extract_signals(src)) .map(|s| &*Box::leak(s.into_boxed_str())) .collect(); diff --git a/apps/desktop/src/plugin_host/runtime/vm.rs b/apps/desktop/src/plugin_host/runtime/vm.rs index 414d760f0..3f9926320 100644 --- a/apps/desktop/src/plugin_host/runtime/vm.rs +++ b/apps/desktop/src/plugin_host/runtime/vm.rs @@ -79,7 +79,7 @@ pub fn options(half: Rc) -> ScriptOptions { let kind = half.kind; let strict_props = cfg!(debug_assertions) || crate::flag("--plugin-hot") - || half.tier != crate::plugin_host::Tier::Bundled; + || half.tier == crate::plugin_host::Tier::Dev; let log_half = half.clone(); let around_half = half.clone(); let mut options = ScriptOptions::new() diff --git a/crates/opencode-plugin-runtime/src/console.rs b/crates/opencode-plugin-runtime/src/console.rs index a6f167be3..3ac6e5c15 100644 --- a/crates/opencode-plugin-runtime/src/console.rs +++ b/crates/opencode-plugin-runtime/src/console.rs @@ -17,7 +17,7 @@ pub struct Line { pub plugin: String, pub level: LogLevel, pub message: String, - /// `file.js:line` from the message, if it names one. + /// `file.js:line` or `file.ts:line` from the message, if it names one. pub at: Option<(String, u32)>, pub count: u32, } @@ -84,9 +84,12 @@ pub fn clear() { VERSION.set(VERSION.get() + 1); } -/// The first `name.js:line` in a message. +/// The first `name.js:line` or `name.ts:line` in a message. fn location(message: &str) -> Option<(String, u32)> { - let at = message.find(".js:")?; + let at = [message.find(".js:"), message.find(".ts:")] + .into_iter() + .flatten() + .min()?; let start = message[..at] .rfind(|c: char| c.is_whitespace() || c == '[' || c == '"' || c == '@' || c == '(') .map_or(0, |i| i + 1); diff --git a/crates/opencode-plugin-runtime/src/sources.rs b/crates/opencode-plugin-runtime/src/sources.rs index d5aa75c72..21c2002f2 100644 --- a/crates/opencode-plugin-runtime/src/sources.rs +++ b/crates/opencode-plugin-runtime/src/sources.rs @@ -333,9 +333,16 @@ pub fn script_sources( } else { entry }; + let entry_is_ts = entry.ends_with(".ts") && !entry.ends_with(".d.ts"); files .iter() - .filter(|(p, _)| is_script(p) || p.ends_with(".json")) + .filter(|(p, _)| { + if entry_is_ts { + is_script(p) || p.ends_with(".json") + } else { + p.ends_with(".js") || p.ends_with(".json") + } + }) .fold(rune_psychoscript::Sources::new(), |s, (p, text)| { s.with(p, text.as_str()) })