Skip to content

plugins: custom editors contribution point, for the official Excalidraw plugin - #34538

Closed
nwparker wants to merge 45 commits into
nwparker/plugins-v2-16-ship-hardeningfrom
nwparker/plugins-v2-18-custom-editors
Closed

nwparker wants to merge 45 commits into
nwparker/plugins-v2-16-ship-hardeningfrom
nwparker/plugins-v2-18-custom-editors

Conversation

@nwparker

@nwparker nwparker commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 139 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4056 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2365 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1691
Prod 282 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6894 $\color{#cf222e}{\Huge{\mathbf{−}}}$​3002 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​3892

ELI5

Plugins can now add their own editor for a kind of file. The first one is Excalidraw: open a .excalidraw file and you get the drawing canvas right in the editor tab, with a toggle to see the raw JSON (Source). Orca still owns the file. The plugin only ever gets the file's text and hands back edited text.

A second official plugin, Spreadsheet Viewer, proves the point also works for binary files: an editor can ask for the file's bytes instead of its text ("contentKind": "bytes"), and open .xlsx, .xlsm, .xlsb, .xls and .ods workbooks read-only, with sheet tabs and a grid that handles 50,000 rows.

What Changed

Before: .excalidraw files opened as plain text, and a plugin had no way to supply an editor for a file type.

After: a plugin with contributes.customEditors (manifest format 2, sandboxed-ui) opens matching files in the editor tab. The header toggle shows <editor title> | Source | Changes. If several plugins match, default priority comes first and the user can pick another one from the toggle. When the plugin is turned off or removed, the file opens in Source.

How it works:

  • Manifest: a new customEditors point: { id, title, fileTypes: ["excalidraw"], entry, priority? }. fileTypes are file-name suffixes without the dot, so excalidraw.json only matches files ending in .excalidraw.json. The point is checked against the format 2 floor (PLUGIN_MANIFEST_V2_SINCE). Duplicate ids or file types are rejected. Schemas and docs are regenerated, and the entry file shares the panel entry's size cap. It is listed as a panel catalog type, and a single-extension type (excalidraw) also feeds the existing "suggest a plugin for this file type" feature.
  • Running it: the editor uses the same sandboxed frame as plugin panels: sandbox="allow-scripts", the host CSP shell (default-src 'none'; connect-src 'none'), the navigation guard and the watchdog. It gets no panel session, so it cannot call any host methods. Its only channel is orca-editor-ready / -document / -edit (full text) / -flush / -flushed. The host checks every message against the frame's window identity and enforces a 16 MiB size cap and a rate limit. It ignores edits on read-only tabs and never echoes an edit back to the frame that sent it.
  • Orca owns the file: edits go into the normal editor buffer, so dirty state, the external-change banner, SSH/remote files and saving all work as they do for every other editor. Keys pressed inside a frame never reach Orca, so the shell forwards modifier chords. When one matches the user's editor.save binding, Orca asks the frame to flush any edit still waiting in its debounce, then saves. Read-only tabs, binary files, load errors and conflicts stay in raw Source, the same as other rich views.
  • Binary files (contentKind: "bytes"): an editor may declare "contentKind": "bytes"; it must then also set "readonly": true, because Orca's save pipeline is text-only. Orca reads the file itself, on the same route that loaded the tab (local, SSH or a paired host), using the existing stat + readChunk calls, so there is no wire change. It refuses files over 16 MiB with " is too large to open in (size; the limit is 16 MB)", re-sends after an outside change, and never applies such an editor's edits. The frame gets the bytes as a transferred ArrayBuffer plus the matched suffix (fileType), never a path. Source on a binary file is the normal "Binary file — cannot display" placeholder.
  • Versioned documents: every document is now { version, readOnly, content: { kind: 'text', text } | { kind: 'bytes', bytes } }. A text edit may name baseVersion; an edit against a document Orca has since replaced gets orca-editor-edit-rejected with error code conflict instead of overwriting the outside change. Text documents keep the old text field and unversioned edits still apply, so the Excalidraw plugin works unchanged. The editor messages stay in one module (plugin-custom-editor-bridge.ts) so a later change can move panels and editors to one envelope.
  • Read-only editors: "readonly": true makes Orca ignore an editor's edits, and the consent then says "Opens .xlsx, … files in Orca" instead of "Opens and edits".
  • Theme without reload: a theme change used to remount panel and editor frames, which reloaded the plugin and lost its state (undo, unsent edits). Orca now posts orca-panel-theme and the shell updates the --orca-* variables and the light/dark class in place.
  • No path in the frame name: the editor frame's name (readable as window.name inside the frame) used to contain the file's absolute path. It is now a random id; the navigation guard needs only the prefix.
  • Suggestions for editors: the "a plugin can open this file type" banner now also appears for a file Orca already shows with a language (an .excalidraw file opens as JSON): "A plugin adds an editor for .excalidraw files: Excalidraw". Only release file types the listing names as custom editors count, and only when no installed plugin's editor handles the type. Binary files such as .xlsx already got the banner through the release's fileTypes.
  • Approval: the consent card adds one line, "Opens and edits .excalidraw and .excalidraw.json files in Orca". An update that adds file types counts as more access.

The official plugins ship separately in stablyai/orca-plugins (catalog-v2): plugins/excalidraw bundles Excalidraw and its Latin fonts into one offline HTML file; plugins/spreadsheet bundles SheetJS Community Edition 0.20.3 (Apache-2.0, licence notices included) the same way. Excalidraw's id is now stablyai.orca-excalidraw: Orca treats a stablyai plugin as official only when its id starts with orca-.

Why

  • Plugin, not core: feat(editor): open .excalidraw files as an editable diagram #27413 built Excalidraw into Orca, which adds a large dependency to every install. A contribution point keeps Orca small, lets other diagram or notebook editors follow, and lets Excalidraw update on its own schedule.
  • Text-only channel, not file-system access: passing text both ways keeps the plugin away from paths and disks, and SSH files work without extra code. Save, dirty state and conflicts then behave exactly as they do in Monaco.
  • Bytes read by Orca, not handed to the plugin as a file: Orca already pages large files on every host for CSV previews and downloads, so reusing that keeps SSH and paired hosts working with no new RPC, and the 16 MiB cap bounds the one structured clone into the frame. Base64 never crosses into the frame.
  • Read-only bytes for now: editable binary files would need byte drafts, binary saves and conflict handling in the save pipeline. The manifest field and the content shape already allow it later without a format change.
  • Same frame as panels: this reuses a sandbox that has already been reviewed (CSP, navigation guard, WebRTC removal, watchdog), so there is no second surface to secure.

Catalog side: stablyai/orca-plugins#16 (catalog-v2 at bd8a0a4: Spreadsheet Viewer listed, Excalidraw renamed; its validator is repinned to this branch's head because it must understand contentKind and readonly).

Huge thanks to @Roughriver74 for #27413 ("open .excalidraw files as an editable diagram"). This PR and the Excalidraw plugin reuse its approach: the Diagram/Source toggle, saving through the existing editor buffer, keeping the scene's original source, and treating the first scene after load as the clean baseline so opening a file never marks it dirty. Both commits credit them as co-author.

Spreadsheet requests from the community shaped the second plugin: #8301 and #20362 (Office files as first-class types), #26514 (a viewer contribution point), and the spreadsheet viewers in #13532 (@SrAlvarado), #20363 (@excellence-wh), #29678 (@nebourocket), #15763 (@ppw-stack), #19741 (@overjt) and #9041 (@siddqamar). The plugin's zip-bomb guard (refuse a workbook that declares over 256 MB uncompressed or 4,000 parts before inflating anything) is adapted from #29678, and that plugin commit credits @nebourocket as co-author. CSV stays with Orca's built-in editable table view.

Linked Issue

N/A (maintainer). Builds on community PR #27413.

Visual Proof

Screenshots from a hidden Electron window, with Excalidraw installed from a local copy of the catalog-v2 catalog:

Before: .excalidraw opened as plain text (no custom editor). After:

Install consent Opened: not dirty
02-install-consent.png 04-opened-diagram.png
Drew a rectangle: dirty Saved, closed, reopened: persisted
05-drew-rectangle-dirty.png 06-reopened-persisted.png
Source toggle (Monaco JSON) Follows dark theme
07-source-view.png 08-dark-theme.png

Spreadsheet Viewer, installed from a local copy of the catalog in a hidden window (multi-sheet workbook with formulas, merged cells, an error cell and a 50,000-row sheet):

Suggestion before install (.xlsx) Install consent: "Opens …"
suggestion-xlsx.png 02-install-consent.png
Opened, not dirty Formula and stored value in the cell bar
04-opened-summary.png 05-formula-detail.png
Row 50,000 with a range selected Dark theme, applied without reloading the frame
07-data-bottom-selection.png 09-dark-summary.png
Source: binary placeholder Over 16 MiB
10-source-binary-placeholder.png 16-too-large.png
Damaged file Password-protected file
14-corrupt.png 15-encrypted.png
Plugin turned off: back to the placeholder Editor suggestion on a highlighted .excalidraw
17-plugin-disabled-fallback.png suggestion-excalidraw.png

Testing

  • I manually tested these changes locally (macOS, hidden window: install from the catalog, open, draw, save, reopen, Source, dark theme)

  • Automated tests added/updated

  • Unit tests: manifest validation, catalog summary and file types, consent binding and update growth (plugin-custom-editor-contribution.test.ts); routing by file type, priority, user choice, plugin turned off, read-only, binary, conflict, Changes and remote files (custom-editor-routing.test.ts); the document channel, covering round-trip, no echo, opening without dirtying, external reload, read-only, size cap, flush-before-save and frame identity (plugin-custom-editor-host.test.ts, PluginCustomEditorFrame.test.tsx); and entry serving, covering the CSP shell, no session, tampered bytes and no path leakage (plugin-custom-editor-entry.test.ts).

  • Bytes editors: manifest rules (bytes needs readonly), routing (binary files, read-only tabs, remote files, no pageable route), the bytes channel (transferred copy, versions, edits ignored), versioned text edits and conflict, the byte reader (local and remote paging within the 256 KiB chunk cap, 16 MiB refusal, older hosts), the bytes surface (too large, retry, reload after an outside change), the in-place theme message and the random frame name. Suggestions: the editor purpose in main and in the banner.

  • E2E, hidden window: a bytes editor receives the file read-only, its edit is ignored, Source shows the placeholder and turning plugins off falls back (plugin-custom-editor.spec.ts); the editor suggestion on .xlsx and .excalidraw, View plugin opens the page without installing, Not now hides it (plugin-editor-file-type-suggestion.spec.ts).

  • Manual, hidden window, the real Spreadsheet Viewer installed from a local catalog copy: open in under 1 s (776–907 ms to the first grid), switching to the 50,000-row sheet about 30 ms, jump to row 50,001, range status (count, sum, average), dark theme without remount, Source, .ods and .xls, damaged, encrypted, too large, plugin off. Plugin suite (npm test in plugins/spreadsheet/build): 63 tests including a headless-browser harness.

  • E2E, hidden window (tests/e2e/plugin-custom-editor.spec.ts): opening does not dirty the file; typing does; a save shortcut pressed inside the frame during the debounce writes the latest text to disk; the frame's fetch to a local server is blocked and the server sees no request; Source and back; turning plugins off falls back to Source. The existing plugin panel, demo, syntax, theme and file-type-suggestion e2e tests also pass.

  • pnpm tc, the changed-code quality gate, oxlint, localization catalog, extraction and coverage checks, and schema regeneration and parity all pass.

  • Known, unrelated: plugin-schema-field-docs.test.ts fails on this stack because tag v1.4.242 exists without v2. The stack bump of PLUGIN_MANIFEST_V2_SINCE to 1.4.243 fixes it.

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: the frame stays an opaque origin with no network, no host methods, no path and no file system. The host forwards only modifier key chords and acts on editor.save alone. A plugin can only edit the text of the file the user opened, and it can do that in Source too.
  • Cross-platform: the save shortcut uses the user's keybinding through the existing matcher (Cmd on macOS, Ctrl elsewhere). Path matching handles both / and \.
  • SSH/remote: no change is needed, because the frame works on buffer text. A routing test covers a remote file.
  • Backwards compatibility: customEditors on the plugin list and the readCustomEditorEntry preload method are optional, so older hosts or preloads simply show Source. Old clients drop the new catalog summary kind (.catch) and their engine floor refuses the plugin.
  • Performance: the frame mounts only for matching files. Edits are debounced by the editor and only the latest full text is kept.
  • Residual: an outside change to an open workbook is covered by unit tests only. In the e2e environment the file watcher reloaded neither a text nor a binary tab, so this could not be shown there.
  • Follow-up: "official" should come from the install's catalog source (the official catalog URL) rather than the orca- id prefix.
  • Residual: an edit still waiting in the debounce when the user switches to Source or closes the tab can be lost. The Excalidraw plugin flushes after 250 ms.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (typecheck, the changed-code gate, touched test suites and the e2e build ran locally; CI covers the full lint and test runs)

@nwparker
nwparker force-pushed the nwparker/plugins-v2-18-custom-editors branch from b4846e0 to 5663c36 Compare October 28, 2026 00:23
@nwparker
nwparker force-pushed the nwparker/plugins-v2-16-ship-hardening branch from 3fb174f to 66f6cb3 Compare October 28, 2026 04:59
@nwparker
nwparker force-pushed the nwparker/plugins-v2-18-custom-editors branch 2 times, most recently from ba5e422 to b48ffe9 Compare October 28, 2026 05:01
@nwparker
nwparker force-pushed the nwparker/plugins-v2-16-ship-hardening branch from 66f6cb3 to dca9872 Compare October 28, 2026 05:31
@nwparker
nwparker force-pushed the nwparker/plugins-v2-18-custom-editors branch from b48ffe9 to de36e57 Compare October 28, 2026 05:32
@nwparker
nwparker force-pushed the nwparker/plugins-v2-16-ship-hardening branch from dca9872 to c58df2c Compare October 28, 2026 05:46
@nwparker
nwparker force-pushed the nwparker/plugins-v2-18-custom-editors branch from de36e57 to 7f05eec Compare October 28, 2026 05:46
nwparker and others added 22 commits October 28, 2026 03:44
A plugin can now declare contributes.customEditors to open files of given
types in the editor tab, beside Source. The editor runs in the same
sandboxed, no-network panel frame and only exchanges the document's text
over a scoped postMessage channel; Orca keeps the buffer, dirty state,
saving, external-change banner, read-only tabs and SSH files.

The Editor | Source toggle and the 'first scene after load is the
baseline' approach follow community PR #27413.

Co-authored-by: Roughriver74 <[email protected]>
…itor frame names

A theme change used to remount panel and custom editor frames, which reloaded
the plugin and lost its state (Excalidraw undo, unsent edits). The host now posts
orca-panel-theme and the shell updates the --orca-* tokens and the html class in
place. Custom editor frames are named with a random id: window.name is readable
inside the frame, and the old name carried the file's absolute path.
A custom editor can now declare "contentKind": "bytes" (with "readonly": true)
to receive the file's raw bytes instead of its text, for formats such as
spreadsheets. Orca pages the bytes from the host that loaded the tab (local,
SSH or a paired runtime, through the existing stat + readChunk calls, so no
wire change), refuses files over 16 MiB with a "too large to open" message,
re-sends on outside changes, and never applies a bytes editor's edits. The frame
gets a transferred ArrayBuffer and the matched suffix, never a path.

Documents are now versioned: { version, readOnly, content: { kind, ... } }.
Text edits may name a baseVersion; an edit against a replaced document is
refused with an orca-editor-edit-rejected conflict. Text documents keep the
legacy text field and unversioned edits still apply, so existing editors work.

"readonly": true on any editor makes the install review say "Opens .x files in
Orca" instead of "Opens and edits".
The file-type suggestion only offered a plugin when a file opened as plain text
or as the binary placeholder. It now also offers a catalog custom editor for a
file Orca shows with a language (an .excalidraw file opens as JSON): the editor
asks main with the `editor` purpose, which matches only release file types the
listing's contributions name as custom editors, and only when no installed
plugin's editor handles the type. Binary files such as .xlsx keep the existing
path, since release fileTypes already include custom-editor types. The banner
reads "A plugin adds an editor for .x files: Name"; Not now and Don't suggest
work per type as before.
…lt, and join Markdown, CSV and notebook view toggles as options
…nd blocks the save instead of vanishing

Rate-limited edits are held and applied before the next save; oversized ones are reported to
the frame and the user. Every save, from any trigger, first flushes plugin editor frames with a
bounded wait and refuses to write while a frame holds edits the buffer lacks.
…only on real key presses

Editors see file contents, so they now run as <webview> guests in their own in-memory partition
instead of iframes of Orca's renderer. The session routes everything through a dead SOCKS proxy
(loopback included), refuses every non-editor request and permission, and each guest gets
disable_non_proxied_udp, no popups and no navigation. An Electron test proves fetch, WebSocket,
images and TURN-over-TCP all fail from the editor and from its srcdoc and javascript: child
frames, while the same page in a plain session reaches every listener. Electron 43 still resolves
<link rel=dns-prefetch> names outside the session; the test pins that residual and the docs say so.

Save chords now come from main's before-input-event on the guest, which page code cannot
synthesize; the shell's keydown forwarder and the orca-editor-keydown message are gone. Guests
also run in their own renderer process.
… tab

Main reads readonly from the installed manifest (bytes editors always count) and drops every
edit such a guest posts before it reaches the renderer. The tab host also refuses them and tells
the editor its document is read-only, even on a writable tab.
… the isolated guest

Bytes editors now post `{ baseVersion, content: { kind: 'bytes', bytes } }` full
replacements (a transferable ArrayBuffer). The tab keeps the unsaved bytes beside
the text drafts, marks itself dirty, and the normal save pipeline (frame flush,
Cmd+S, close prompt) writes them: locally through a new `fs:writeFileBytes`
atomic replace guarded by the loaded bytes' SHA-256, and on SSH-served or paired
hosts by uploading chunks with `files.writeBase64Chunk` and swapping them in with
the new capability-negotiated `files.replaceWithUpload`. Older hosts are refused
before anything is written. A stale baseline is a conflict: the edit stays
unsaved and the external-change banner offers Reload or Overwrite. Source stays
the binary placeholder.

Per the product decision, every custom editor may edit: the `readonly` manifest
field, its main-side enforcement and re-approval rule are gone, and an editor
that only views simply never posts edits. Editors run in the normal sandboxed
plugin frame again instead of a network-isolated webview guest; the frame's save
chord is honored only while it carries real user activation. Consent now reads
"Opens and edits .ext files in Orca. It can read the files it opens."
…t document

Editors that subscribe after their bundle loads (Excalidraw) missed the
document that arrived first and stayed blank.
… past 16 MiB

The cap covers text and bytes on every route; reads and SSH or paired-host
writes are already chunked, so only the shared cap moves. Past 16 MiB the
tab shows a small, non-blocking note that the editor may take a moment.
…erywhere) and drop unused plugin locale keys
…mes, images, capabilities, events, languages, installation and catalog folders
A custom editor may declare an icon; the tab and its hover card show it and the
editor title instead of "Editor", falling back to the plugin icon. contributes.newFiles
declares untitled file types (title, extension, optional UTF-8 template and icon) offered
in the tab bar + menu, its search, the command palette and the plugin page, created at the
workspace root through the Markdown untitled-file flow. The install toast's Try it creates
one for plugins that declare them.
Saved false from the old default flips on once (pluginSystemDefaultedOn guard);
a later deliberate false is respected. The Turn on plugins off-state is gone,
and the official catalog seed is deferred off the startup path (and skipped
offline), seeding on demand when the marketplace is opened.
…images

The official catalog's newest Midnight, Nord, OLED and Dusk & Ember releases
were regenerated without an images block (release-entry only kept images the
author pasted), so their cards fell back to drawn art. A catalog that keeps its
plugins in its own repository now borrows the manifest's images from the
catalog commit, checked like declared images, and the validator's printed
release entry includes them so regenerated catalogs keep their covers.
Full-access (trusted-worker) plugins now need only their own per-plugin
approval: main no longer gates install, consent, enablement or runtime on a
global switch, and the settings menu item, the Turn on in settings card and
page states, and the stored key are gone. The consent now says plainly what
full access means. Kill list, official review and publisher checks are kept;
docs note an enterprise block policy may come later.
@nwparker
nwparker force-pushed the nwparker/plugins-v2-16-ship-hardening branch from c58df2c to 67b5e44 Compare October 28, 2026 10:53
@nwparker
nwparker force-pushed the nwparker/plugins-v2-18-custom-editors branch from d67350f to 6dbe0d0 Compare October 28, 2026 10:53
smwbev added a commit to smwbev/orca-russian that referenced this pull request Oct 28, 2026
stablyai/orca#34538 moves plugin-translatable-chrome.ts into
src/shared/plugins/languages/. build.py used to treat a missing file as an
empty allow-list and would have dropped the 34 allowed settings.plugin*
translations without a word; it now looks in both places and stops when it
finds neither. audit-pack.py does the same. The v5.1.177 catalog builds byte
for byte as before.
Drop tests that asserted CSS classes, DOM structure, internal call counts,
copy, or duplicated coverage; merge overlapping e2e file-type suggestion
specs. Keep security, consent, data-integrity, compatibility and main
journey coverage.
@nwparker
nwparker marked this pull request as ready for review October 28, 2026 12:38
@nwparker nwparker mentioned this pull request Oct 28, 2026
7 of 9 tasks
@nwparker

Copy link
Copy Markdown
Contributor Author

Folded into #35470 (Plugin Alpha), which lands the rest of the plugin stack in one PR.

@nwparker nwparker closed this Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant