Skip to content

feat(plugins): let a panel invoke its own plugin's worker commands - #25256

Closed
marioser wants to merge 2 commits into
stablyai:mainfrom
marioser:feat/panel-commands-invoke
Closed

marioser wants to merge 2 commits into
stablyai:mainfrom
marioser:feat/panel-commands-invoke

Conversation

@marioser

@marioser marioser commented Oct 4, 2026 •

Copy link
Copy Markdown

ELI5

A plugin's panel is a small sandboxed web page, and its worker is the part that can read files and compute things. Today the page cannot ask its own worker for anything, so a plugin cannot show live data in its panel. This lets the page ask its own worker a question and get the answer back.

What Changed

Before: a panel could only call the three host API rows marked panel: true (workspace.readContext, terminal.sendText, notifications.show). It could not reach its plugin's worker commands, plugin storage or the network, so a plugin whose data lives in the worker could not render it in its panel.

After: a new host API method commands.invoke lets a panel run one of its own plugin's declared worker commands and receive the result. The panel polls it like any other action.

Mechanism:

  • New row in PLUGIN_HOST_API_V0 with strict params { commandId, args? } and result { value } (JSON, capped at 64 KB serialized).
  • Plugin identity comes only from the authenticated panel session, never from params. The call reuses PluginService.invokeCommand (logic moved into invokePluginWorkerCommand to stay under the max-lines ratchet), so the contributes.commands, built-in alias and enablement checks apply unchanged, and the worker is started lazily as for palette commands.
  • capability on host API rows is now PluginCapabilityKind | null (still a required key, so omitting it is a type error). Only commands.invoke is null: the gate skips the capability check for it but still returns consent_required when the plugin is disabled or its consent is stale. No new capability kind, so the consent fingerprint is unchanged.
  • New optional panelOnly flag on rows, enforced by the gate: a worker calling commands.invoke gets a new worker_forbidden code (avoids a worker invoking itself and waiting out the 30 s timeout). panel_forbidden was not reused because its message describes the opposite case.
  • mutation: false: the host cannot know what a command does; any host calls the command makes are gated and audited on their own.
  • Missing, undeclared, alias, disabled, timed-out or oversized-result commands surface as action_failed.
  • examples/plugins/hello-orca/panel.html gains a button that invokes its own hello-ping command.

Why

This is option 1 from #15638: a panel-callable action that invokes the plugin's own worker command (request/response, polled). It keeps the panel bridge request/response only — no new push channel, no new capability, no consent change — and grants the panel no authority the plugin did not already have: the command is declared in the plugin's own manifest and runs in its own worker.

Alternatives considered: reusing an existing capability (e.g. workspace:read) would make the consent copy misleading; a new commands:invoke kind would re-prompt consent for adopting plugins; a host → panel push channel is a larger change to the bridge.

Real use case: a plugin that tracks the prompt-cache lifetime of every agent session (Claude Code, Codex, OpenCode, Pi) from each agent's logs, and warns before the cache expires. With this change its panel shows a live countdown per session; without it the countdown has to live in a separate terminal.

Linked Issue

Fixes #15638

Visual Proof

Before/after screenshots of a plugin panel to be attached (before: the panel shows "not a panel-callable action"; after: live data from the worker).

Testing

Tested on macOS (arm64) with a dev build (pnpm dev) of this branch, rebased on current main:

  • A real plugin's panel polls commands.invoke every 5 s and renders the worker's data; verified the call through the renderer bridge and via window.api.plugins.invokeCommand.
  • Not manually exercised: the hello-orca button (covered by the bridge/controller tests), Linux, Windows, SSH/relay.

Automated:

  • New src/shared/plugins/plugin-capability-gate.test.ts; extended plugin-host-methods.test.ts, plugin-host-conformance.test.ts (13 → 14 methods), plugin-panel-controller.test.ts, plugin-service-reconciliation.test.ts. Cover same-plugin success, undeclared command, alias, disabled plugin, worker caller denied, oversized result, error/timeout → action_failed, and unchanged behaviour of existing rows.

  • pnpm test src/shared/plugins src/main/plugins src/relay src/renderer/src/components/right-sidebar: 4836 passed, 2 failed — both in src/relay/opencode-hook-selection.test.ts, and they fail identically on unmodified main on this machine (environment-dependent, unrelated to this change).

  • pnpm tc:node, oxlint, oxfmt, check:code-quality:changed, check:max-lines-ratchet: pass. Full pnpm test and pnpm build not run locally.

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

AI Disclosure

Written with Claude Code: design and review orchestrated by Claude Opus 5.5, implementation by Claude Sonnet 5.5. The human contributor chose between the design options (capability handling) and verified the result locally in a dev build; the code itself was written and reviewed by the models above.

Review

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: identity from the session only; same-plugin commands only; panel-only; consent and enablement still required; result size capped.
  • Cross-platform / SSH: no platform-specific code; the relay shares PluginHostServices and now requires invokePluginCommand from its policy (type-enforced).
  • Backwards compatibility: additive within pluginApi 1; existing rows keep a required capability.
  • Performance: one IPC round trip per call; existing panel rate limit (30 / 10 s) applies.

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 (or CI will cover; local preferred)

Before: a plugin panel could only call the host API rows marked
`panel: true`, so it had no way to ask its own worker for data: panels
cannot reach worker commands, plugin storage or the network.

After: a new host API method `commands.invoke` lets a sandboxed panel run
one of the same plugin's declared worker commands and receive the result
(request/response, polled by calling again).

- Params are strict `{ commandId, args? }`; plugin identity comes only
  from the authenticated call context, and the call reuses
  PluginService.invokeCommand so contributes.commands, built-in alias and
  enablement checks apply unchanged.
- Results are capped at 64 KB serialized; larger results, timeouts and
  command errors surface as `action_failed`.
- The row has `capability: null` (now an explicit, required-key opt-out
  in the spec type): the gate still requires an enabled, consented
  plugin but no new capability kind, so the consent fingerprint is
  unchanged.
- New `panelOnly` spec flag, honoured by the gate with a distinct
  `worker_forbidden` code, so a worker cannot call it.
- hello-orca panel gains a button that calls hello-ping.

Refs stablyai#15638
@marioser
marioser marked this pull request as ready for review October 4, 2026 15:38
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7046ac18-7b11-4f45-bd10-ac66f216c1f7
📥 Commits

Reviewing files that changed from the base of the PR and between 7ef6c2c and a6634f0.

📒 Files selected for processing (3)
  • config/reliability-gates.jsonc
  • src/main/plugins/plugin-host-method-bindings.ts
  • src/shared/plugins/plugin-host-api.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/plugins/plugin-host-method-bindings.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The plugin host API adds commands.invoke for sandboxed panels. The host checks consent and panel-only access, validates the command, and invokes its registered worker handler. The host returns the result as JSON and rejects results larger than 64 KiB. The hello-orca example adds a button that invokes a worker command and displays its result or error.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to a6634

The change adds a consent-gated panel request/response path to a plugin’s declared worker commands, with bounded JSON results. The supplied implementation and tests cover the key access and dispatch behaviors; no actionable merge-blocking risk remains.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to a6634

Panels gain access to their plugin’s worker commands, so compromised panel code could trigger operations or obtain data previously unavailable to it. Identity, consent, and command-declaration checks constrain this expansion, but its consequences depend on the commands each plugin exposes.

Retained concerns

  • Medium · security · inferred: A compromised panel can now supply arguments to every eligible command declared by its own plugin and receive command results. Declaration and registration checks establish command ownership, not suitability for panel-originated input or disclosure. Sensitive command effects therefore become indirectly panel-reachable without a command-specific exposure decision. This is a conditional design risk, not a verified exploit; current consent and downstream host capability checks remain applicable.
Security review details

Security Blast Radius

  • inferred — The directly addressable scope is the authenticated panel’s own plugin and eligible commands, not arbitrary plugins. Downstream effects and disclosed data inherit those commands’ existing worker authority; plugin-private routing does not itself prove that effects are confined to plugin-private data. Individual handlers were not inspected, so maximum workspace, credential, network, or service exposure is unresolved.

Security Findings and Attack Paths

  • inferred — If an attacker controls code in a valid, approved panel, the new route lets that code select an eligible own-plugin command, supply JSON arguments, and receive its result. A sensitive handler could consequently expose data or perform side effects previously unreachable through the panel. No panel compromise, vulnerable handler, or cross-plugin bypass was verified.

Trust Boundaries and Controls

  • observed — The strongest counterevidence is session-derived identity, owner-bound session resolution, panel/root/manifest binding checks, current consent, and repeated approval checks during worker activation. These controls constrain impersonation and stale activation, but do not distinguish which declared commands should accept panel-originated requests.

Resilience and Maintainability Implications

  • observed — Existing execution assigns separate call IDs and rejects pending requests on worker exit or disconnect. A command timeout removes the pending request but does not cancel worker execution. Session revocation prevents future admission rather than canceling admitted calls; worker deactivation aborts startup and initiates shutdown with a two-second kill grace. These inherited semantics do not provide transactional rollback or deduplication for repeated panel requests.

Hardening Proposals

  • proposed — Consider explicit per-command panel exposure policy, with argument and result contracts for sensitive handlers. Document that timeout and session closure do not undo admitted work, and require command-specific idempotency or confirmation where repeated execution could affect security-relevant state.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Open issue #15638 asks for a host-to-panel channel that delivers worker data to the panel, including audio data for playback. This PR adds a panel-initiated commands.invoke request/response path ins… Implement a host-to-panel delivery path that lets a plugin worker send data to its panel through the panel bridge. Add automated tests for delivery and access controls.
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 12 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: allowing a plugin panel to invoke its own worker commands.
Description check ✅ Passed The description covers the change, rationale, linked issue, testing, and notes. It states that visual proof will be attached, but no screenshots or videos are included, and the checklist leaves that i…
Out of Scope Changes check ✅ Passed The commands.invoke API, command-invocation refactor, capability-gate changes, tests, reliability-gate update, and hello-orca example all relate to exposing a plugin worker command result in that …
Full details: Linked Issues check

Explanation

Open issue #15638 asks for a host-to-panel channel that delivers worker data to the panel, including audio data for playback. This PR adds a panel-initiated commands.invoke request/response path instead. The path supports polling for worker results, but it does not implement the requested worker-to-panel delivery channel. The incremental changes since the previous review clarify documentation and the reliability-gate assertion; they do not change this behavior.

Full details: Docstring Coverage

Explanation

Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 12 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — a few non-blocking notes below.

Reviewed changes

  • New commands.invoke host API row — a sandboxed panel can now run one of its own plugin's declared worker commands; plugin identity comes only from the authenticated panel session, never from params.
  • Gate changes — capability is now PluginCapabilityKind | null (only commands.invoke is null) and a new panelOnly flag returns worker_forbidden for worker callers.
  • Invocation refactor — the worker-start + declared-command logic moved out of PluginService.invokeCommand into invokePluginWorkerCommand and is now shared with the panel path.
  • Result cap + example panel button — PLUGIN_COMMAND_RESULT_MAX_BYTES (64 KB) and a hello-ping button in hello-orca/panel.html, plus new/extended bridge, controller, conformance and reconciliation tests.

The security shape is sound: identity is session-bound, only same-plugin declared worker commands run, enablement/consent still apply, worker callers are denied (no re-entrancy), and the command's own host calls stay capability-gated and audited.

ℹ️ Nitpicks

  • src/shared/plugins/plugin-host-api.ts:128 — the panel field comment still reads "Workers can call every method", which the new panelOnly flag (and commands.invoke) now contradicts. Worth tightening to note that panelOnly rows are panel-only.
  • src/main/plugins/plugin-host-method-bindings.ts:182 — the comment says the result "travels back through one bounded panel message", but PLUGIN_COMMAND_RESULT_MAX_BYTES equals PANEL_MESSAGE_MAX_BYTES and only bounds the inner value; the { value } wrapper plus the result-message envelope push it past that cap, and the outbound lane has no size check. No functional effect today (a value at the cap is delivered), but the stated bounded-message rationale is imprecise.
  • config/reliability-gates.jsonc:19263 — the assertion description still says "all 13 v0 methods succeed with the required consented capability"; the conformance test is now 14 and special-cases the null-capability row. Stale, since the validator only checks structure.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

Addresses review notes on stablyai#25256: the host API row docs now say workers can call every method except panelOnly rows; the result-cap comment states that the 64 KB cap bounds the command value (wrapper and envelope add a few bytes; the outbound lane is not size-checked); the conformance gate description counts 14 methods and the null-capability row.
@marioser

marioser commented Oct 4, 2026

Copy link
Copy Markdown
Author

Thanks for the review. All three notes addressed in a6634f0 (comments/docs only, no behaviour change):

  • plugin-host-api.ts: the panel field doc now says workers can call every method except panelOnly rows.
  • plugin-host-method-bindings.ts: the result-cap comment now states that the 64 KB cap bounds the command's value, that the { value } wrapper and result envelope add a few bytes, and that the outbound lane is not size-checked.
  • config/reliability-gates.jsonc: the conformance assertion now counts 14 methods and mentions the null-capability, panel-only row (check:reliability-gates passes).

@BearMett

BearMett commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

I’d like to build a Git graph plugin that shows progress across branches and worktrees inside Orca. This feature would let the plugin’s worker collect Git data and display it in the panel. Could a maintainer take a look at this PR when convenient? Thanks!

@nwparker

nwparker commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

@marioser Thank you for this, and sorry it sat so long. Panel-to-worker calls landed in #37013 (merged), which takes a slightly different shape: a panel calls plugin.request(name, input) and the worker answers with orca.panels.handle(name, handler). It goes through the host, so it reuses the existing session, consent and capability checks, starts the worker on demand, and works on remote-only worktrees. Docs: docs/reference/plugin-host-api.md; a full example is examples/plugins/hello-worker-panel. Closing this as superseded. Your PR helped shape what we needed, so thanks again.

@nwparker nwparker closed this Nov 7, 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.

Plugin panel can synthesize and play audio, but has no channel to receive data from its worker

3 participants