Files
orca/src/shared/plugins/view/plugin-view-protocol.ts
T
Neil 1392c8e894 Plugin dev loop: orca plugin open/shot, dev emit, and dogfood fixes (#37008)
* feat(plugins): orca plugin open and shot; dev watch --shot

- orca plugin open <key> [--panel|--editor] shows a panel in the right sidebar or a file in the
  plugin's custom editor, by changing renderer state only (no focus or window raise).
- orca plugin shot <key> [--panel] [--theme] [--width] [--out] [--json] waits for the panel's
  current code to draw, then crops webContents.capturePage to the panel (html guests included),
  with background throttling off while hidden. --width and --theme are temporary in-memory
  overrides; the PNG returns base64 (5 MiB cap), so --environment works.
- dev watch --shot <dir> writes a PNG per panel after the load and each good reload.
- The authoring skill's loop is now dev watch --check --shot → read the PNG → plugin test.

* fix(plugins): shots never disturb a visible Orca

- shot --theme is skipped while the Orca window is on screen (themeApplied: false with a
  themeReason); the override applies only to a hidden or minimized window.
- dev watch --shot opens the first panel (or --shot-panel <id>) once, then shoots it with
  ifShown: if the user moved the sidebar away it emits one shot_skipped instead of switching.

* fix(plugins): dev loop dogfood fixes; orca plugin dev emit

- dev watch: approval re-run command drops watch-only flags and old --approve; a folder added
  by a refused load is owned by the next approved load (Ctrl-C unloads it); check events
  carry the plugin's status (no green while pending/errored); reloaded prints before that
  reload's logs; --json errors are one NDJSON line.
- Errors: log, banner and check share source-mapped positions (a line-1 prelude hands sucrase
  mappings to the components runtime); check dedupes issues and locates syntax errors;
  Orca runtime frames and the error module's bogus location are dropped from logs.
- .orca/types tsconfig sets preserveSymlinks (tsc 7 loaded typings twice under /tmp).
- Templates' READMEs use dev watch.
- orca plugin dev emit <dir|key> <event> [--data] sends a test event to a dev plugin's worker
  through the real delivery rules (plugins.devEmit).

* test(plugins): fixed timestamp in the dev emit test

* fix(plugins): shot captures an html panel's guest itself

On Linux the main window's capturePage leaves a <webview> guest blank. The renderer now reports
the guest's rect, and main captures the guest's own webContents and draws it over the window
capture at that rect (raw bitmaps, nativeImage only). Components panels are drawn by the host,
so the window capture alone stays right for them.

* refactor(plugins): keep plugin-service and main-process-plugins under max-lines

After rebasing onto #37013 both files crossed 300 lines. The guest log sink moves into the
desktop view binding (bindPluginDesktopViews), and plugin-service tightens emitEvent and its
event-delivery imports.
2026-11-01 05:04:51 -08:00

56 lines
2.4 KiB
TypeScript

/**
* Main asks the desktop renderer to show a plugin panel or editor (`orca plugin open`) and, for
* `orca plugin shot`, to report where the drawn panel sits so main can capture that rect. Only
* renderer state changes: nothing here shows, raises or focuses a window.
*/
export const PLUGIN_VIEW_REQUEST_CHANNEL = 'plugins:viewRequest'
export const PLUGIN_VIEW_REPLY_CHANNEL = 'plugins:viewReply'
export type PluginViewColorScheme = 'light' | 'dark'
export type PluginViewCapture = {
/** The guest URL's `rev` the drawn panel must come from; null takes whatever is drawn. */
guestRevision: string | null
/** Panel width in CSS pixels for this capture only. */
width?: number
/** Paint Orca in this mode for this capture only; the setting is not changed. */
colorScheme?: PluginViewColorScheme
/** Capture only if the panel is already the open right-sidebar tab; never open or switch. */
ifShown?: boolean
timeoutMs: number
}
export type PluginViewRequestBody =
| { kind: 'open-panel'; pluginKey: string; panelId: string; capture?: PluginViewCapture }
| { kind: 'open-editor'; pluginKey: string; editorId: string; filePath: string }
/** Puts back the width and theme a capture changed. */
| { kind: 'end-capture' }
export type PluginViewRequest = PluginViewRequestBody & { requestId: string }
export type PluginViewDrawnPanel = {
/** CSS pixels in the window's viewport. */
rect: { x: number; y: number; width: number; height: number }
ui: 'components' | 'html'
guestUrl: string | null
/** An html panel's guest `<webview>`, in the same CSS pixels as `rect`. */
guestRect?: { x: number; y: number; width: number; height: number }
/** The panel's own error banner (a components render or load error), if it shows one. */
issue: string | null
colorScheme: PluginViewColorScheme
themeApplied: boolean
/** False when the wait timed out and the rect shows whatever was drawn by then. */
settled: boolean
}
export type PluginViewReply =
| { requestId: string; ok: true; panel?: PluginViewDrawnPanel }
| { requestId: string; ok: false; code: string; message: string }
/** The renderer could not show the view; `code` is a stable reason callers may branch on. */
export const PLUGIN_VIEW_NO_WORKSPACE_CODE = 'no_workspace'
/** An `ifShown` capture found another tab, a closed sidebar or another view on screen. */
export const PLUGIN_VIEW_NOT_SHOWN_CODE = 'not_shown'