feat(plugins): Orca plugin system — kernel, content packs, panels, workers, marketplace v0 (experimental) (#8549)
* feat(plugins): Orca plugin system — kernel, content packs, panels, workers, marketplace v0 (experimental) Adds Orca's experimental plugin system behind a settings flag: a supervised kernel, declarative content packs (VM recipes, commands and keybindings, language packs), sandboxed iframe panels, forked worker hosts, and a Git-backed marketplace v0 with consent, provenance and kill-list enforcement. Theme, icon-theme and terminal-theme contributions are deferred to a follow-up pass. * fix(plugins): make unsupported marketplace listings unreachable by key findPlugin() backs preview/install/previewInstalledUpdate via requireListing(), so filtering only listPlugins() hid the catalog card while leaving the dead install path reachable one click later. * fix(plugins): fan Pi session-only status out to plugin subscribers The providerSessionOnly early-return in applyNormalizedStatus emitted to onAgentStatus (main-window fanout) but skipped enrichedStatusListeners, so plugins subscribed to agent.status.changed silently missed every Pi session_start event. Route both emit sites through one helper so a future early return cannot drop the plugin tap again. Co-authored-by: Orca <help@stably.ai> * plugins: drop dead code and hoist duplicated trust-boundary patterns Cleanup pass over the P1 diff, no behavior change: - Delete `readPluginTreeSnapshot`/`readSnapshotFile` and their types, plus the now-vestigial `directories`/`signal` plumbing in `collectFiles`. - Delete `resolveContainedPluginDirectory` (no callers). - Delete `plugin-content-load-pool.ts`; it reimplemented the existing `mapWithConcurrency`, whose index arg also removes the pairing wrapper in `buildPluginList`. - Hoist `PLUGIN_CONTENT_HASH_PATTERN` and `PLUGIN_COMMIT_PATTERN` into the install-lockfile module; 11 sites hand-rolled these identically. - Point the new reliability gate at the PR instead of gitignored docs paths, matching every other gate's link form. * fix(plugins): retry plugin state renames on Windows AV/EPERM locks Six plugin write paths (lockfile, provenance, current pointer, kill list, marketplace cache, staged install dir) did a plain rename, so an antivirus or indexer holding the target open surfaced as a failed install. The repo already retries this hazard for issue #1507, but only through a sync helper; these paths are all async. Adds one bounded async retry + atomic write used by all six, and trims a consent-provenance header that restated its own JSX. * test(plugins): cover the Windows rename retry path The retry loop shipped untested: both existing cases hit the non-retry path, and the temp-cleanup test passed identically with the `finally` removed. Mock `rename` to queue errno codes so CI can exercise locks it cannot provoke. Co-authored-by: Orca <help@stably.ai> * fix(plugins): pin bundled plugin resources to LF Windows CI checks out with autocrlf, so the byte-hashed launch tree arrived as CRLF and verify-packaged-plugin-resources rejected it — the packaged build could never pass on Windows. Reproduced locally: CRLF yields the exact CI error, LF verifies clean. Files are already LF, so nothing renormalizes. Co-authored-by: Orca <help@stably.ai> * test: guard the bundled-plugin LF pin against a CRLF checkout The byte-hash mismatch only surfaced in Windows packaging CI. Assert the .gitattributes pin and that a CRLF tree is rejected, so a regression fails on any platform instead of waiting for a packaged Windows build. Co-authored-by: Orca <help@stably.ai> * ci: trigger packaged-build check on bundled plugin resource changes The launch tree is byte-hashed during packaging, but no trigger path covered it — so the CRLF fix for that check would not have re-run the check. Add the resources, verifier and .gitattributes paths that can break packaging. Co-authored-by: Orca <help@stably.ai> * perf(plugins): rebuild the panel frame only when its baked theme values change The revision keys the panel iframe, so every bump destroys the sandboxed frame and its in-panel state. It counted root attribute mutations, but --workspace-sidebar-live-width is written every rAF of a sidebar drag, so dragging with a panel open blanked it ~60x/sec. Compare the two values the shell actually bakes in instead. Co-authored-by: Orca <help@stably.ai> * test: stop pinning a plugin name in the CRLF guard The CRLF case rewrites every launch file, so the reported mismatch is whichever plugin sorts first. P2 adds theme plugins that sort ahead of orca-navigation-shortcuts, which broke the assertion there. Co-authored-by: Orca <help@stably.ai> * style: drop stray blank lines left by the rebase resolutions Both sides of the agent-hooks and orca-runtime conflicts contributed a trailing blank, which oxfmt rejects. Whitespace only. Co-authored-by: Orca <help@stably.ai> * test(plugins): stop the startup budget failing on machine load P95 runs 16-34ms idle but exceeds the 50ms bound under full-suite parallelism, so the gate flaked. Widen it to catch an order-of-magnitude regression instead; the no-worker/no-plugin-code assertions are the real guarantee. Verified a 400ms regression still fails. Co-authored-by: Orca <help@stably.ai> --------- Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -31,6 +31,7 @@ import { SPEECH_METHODS } from './speech'
|
||||
import { CLIENT_UI_METHODS } from './client-ui'
|
||||
import { CLIENT_EVENT_METHODS } from './client-events'
|
||||
import { WORKSPACE_PORT_METHODS } from './workspace-ports'
|
||||
import { PLUGIN_METHODS } from './plugins'
|
||||
import { SKILL_METHODS } from './skills'
|
||||
import { CLIPBOARD_METHODS } from './clipboard'
|
||||
import { HOST_CAPABILITY_METHODS } from './host-capabilities'
|
||||
@@ -74,6 +75,7 @@ export const ALL_RPC_METHODS: readonly RpcAnyMethod[] = [
|
||||
...SSH_METHODS,
|
||||
...SPEECH_METHODS,
|
||||
...WORKSPACE_PORT_METHODS,
|
||||
...PLUGIN_METHODS,
|
||||
...SKILL_METHODS,
|
||||
...CLIPBOARD_METHODS,
|
||||
...HOST_CAPABILITY_METHODS,
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import type { RpcContext, RpcMethod } from '../core'
|
||||
import type { PluginService } from '../../../plugins/plugin-service'
|
||||
import { PLUGIN_METHODS, setPluginServiceForRpc } from './plugins'
|
||||
|
||||
const SESSION_TOKEN = 's'.repeat(43)
|
||||
|
||||
function method(name: string): RpcMethod {
|
||||
const found = PLUGIN_METHODS.find((entry) => entry.name === name)
|
||||
if (!found) {
|
||||
throw new Error(`missing ${name}`)
|
||||
}
|
||||
if ('stream' in found) {
|
||||
throw new Error(`${name} is streaming`)
|
||||
}
|
||||
return found
|
||||
}
|
||||
|
||||
function context(connectionId?: string): RpcContext {
|
||||
return { runtime: {} as RpcContext['runtime'], connectionId, clientId: 'paired-device' }
|
||||
}
|
||||
|
||||
afterEach(() => setPluginServiceForRpc(null))
|
||||
|
||||
describe('plugin panel serve RPC identity', () => {
|
||||
it('leaves the raw panel envelope for session resolution and admission', () => {
|
||||
const schema = method('plugins.panelAction').params!
|
||||
|
||||
expect(
|
||||
schema.safeParse({
|
||||
pluginId: 'orca-samples.other',
|
||||
unexpected: 'x'.repeat(100_000)
|
||||
}).success
|
||||
).toBe(true)
|
||||
})
|
||||
|
||||
it('binds panel loading and actions to the same runtime connection owner', async () => {
|
||||
const service = {
|
||||
whenReady: vi.fn().mockResolvedValue(undefined),
|
||||
panels: {
|
||||
open: vi.fn().mockResolvedValue({ html: '<p>panel</p>', sessionToken: SESSION_TOKEN }),
|
||||
execute: vi.fn().mockResolvedValue({ ok: true, value: { branch: 'main' } }),
|
||||
bindOwnerSignal: vi.fn(),
|
||||
revokeOwner: vi.fn()
|
||||
}
|
||||
} as unknown as PluginService
|
||||
setPluginServiceForRpc(service)
|
||||
const rpcContext = context('connection-one')
|
||||
|
||||
await expect(
|
||||
method('plugins.readPanelEntry').handler(
|
||||
{ pluginKey: 'orca-samples.demo', panelId: 'dashboard' },
|
||||
rpcContext
|
||||
)
|
||||
).resolves.toEqual({ html: '<p>panel</p>', sessionToken: SESSION_TOKEN })
|
||||
expect(service.panels.open).toHaveBeenCalledWith(
|
||||
'runtime:connection-one',
|
||||
'orca-samples.demo',
|
||||
'dashboard'
|
||||
)
|
||||
|
||||
await expect(
|
||||
method('plugins.panelAction').handler(
|
||||
{ sessionToken: SESSION_TOKEN, action: 'workspace.readContext', params: {} },
|
||||
rpcContext
|
||||
)
|
||||
).resolves.toEqual({ outcome: { ok: true, value: { branch: 'main' } } })
|
||||
expect(service.panels.execute).toHaveBeenCalledWith('runtime:connection-one', {
|
||||
sessionToken: SESSION_TOKEN,
|
||||
action: 'workspace.readContext',
|
||||
params: {}
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,154 @@
|
||||
import { z } from 'zod'
|
||||
import { defineMethod, type RpcContext, type RpcMethod } from '../core'
|
||||
import type { PluginPanelEntry } from '../../../../shared/plugins/plugin-panel-bridge'
|
||||
import { listPluginsForClients } from '../../../ipc/plugins'
|
||||
import type { PluginListEntry } from '../../../plugins/plugin-list-projection'
|
||||
import type { PluginService } from '../../../plugins/plugin-service'
|
||||
import {
|
||||
pluginConsentRequestSchema,
|
||||
type PluginConsentRequest
|
||||
} from '../../../../shared/plugins/plugin-consent-request'
|
||||
import { isQualifiedPluginKey } from '../../../../shared/plugins/plugin-manifest'
|
||||
|
||||
/**
|
||||
* Serve/headless parity surface: the same consent, enablement, panel-action,
|
||||
* and command paths the desktop IPC handlers expose, over runtime RPC. Both
|
||||
* routes execute through PluginService's single chokepoint, so a permission
|
||||
* decision can never differ between a local window and a paired client.
|
||||
*/
|
||||
|
||||
// Why: RpcContext only carries the OrcaRuntimeService, and plugins are a
|
||||
// separate composition-root service — inject via module setter the way the
|
||||
// desktop entry wires it, instead of widening the shared RPC context type.
|
||||
let pluginServiceForRpc: PluginService | null = null
|
||||
// Consent/enablement need the settings Store too, so the entry injects bound
|
||||
// closures instead of the store itself.
|
||||
let pluginConsentForRpc: ((request: PluginConsentRequest) => Promise<void>) | null = null
|
||||
let pluginEnablementForRpc: ((pluginKey: string, enabled: boolean) => Promise<void>) | null = null
|
||||
|
||||
export function setPluginServiceForRpc(
|
||||
service: PluginService | null,
|
||||
writes?: {
|
||||
applyConsent: (request: PluginConsentRequest) => Promise<void>
|
||||
applyEnablement: (pluginKey: string, enabled: boolean) => Promise<void>
|
||||
}
|
||||
): void {
|
||||
pluginServiceForRpc = service
|
||||
pluginConsentForRpc = writes?.applyConsent ?? null
|
||||
pluginEnablementForRpc = writes?.applyEnablement ?? null
|
||||
}
|
||||
|
||||
function requirePluginService(): PluginService {
|
||||
if (!pluginServiceForRpc) {
|
||||
throw new Error('Plugin service is not available on this runtime')
|
||||
}
|
||||
return pluginServiceForRpc
|
||||
}
|
||||
|
||||
const PluginSetEnabledParams = z.object({
|
||||
pluginKey: z.string().refine(isQualifiedPluginKey, 'invalid qualified plugin key'),
|
||||
enabled: z.boolean()
|
||||
})
|
||||
|
||||
const PluginReadPanelEntryParams = z.object({
|
||||
pluginKey: z.string().min(1),
|
||||
panelId: z.string().min(1)
|
||||
})
|
||||
|
||||
const PluginInvokeCommandParams = z.object({
|
||||
pluginKey: z.string().min(1),
|
||||
commandId: z.string().min(1),
|
||||
args: z.unknown().optional()
|
||||
})
|
||||
|
||||
async function listForRpc(): Promise<PluginListEntry[]> {
|
||||
return listPluginsForClients(requirePluginService())
|
||||
}
|
||||
|
||||
function rpcPanelOwner(context: RpcContext): string {
|
||||
// Why: the bearer session must not cross paired-client connections even
|
||||
// when two sockets authenticate as the same device.
|
||||
return `runtime:${context.connectionId ?? context.clientId ?? 'local'}`
|
||||
}
|
||||
|
||||
function bindRpcPanelOwner(service: PluginService, context: RpcContext): string {
|
||||
const ownerKey = rpcPanelOwner(context)
|
||||
service.panels.bindOwnerSignal(ownerKey, context.signal)
|
||||
return ownerKey
|
||||
}
|
||||
|
||||
export const PLUGIN_METHODS: readonly RpcMethod[] = [
|
||||
defineMethod({
|
||||
name: 'plugins.list',
|
||||
params: null,
|
||||
handler: async () => listForRpc()
|
||||
}),
|
||||
defineMethod({
|
||||
// Why: headless serve has no consent dialog — an explicit consent call is
|
||||
// the only way a pending plugin becomes active on a server.
|
||||
name: 'plugins.consent',
|
||||
params: pluginConsentRequestSchema,
|
||||
handler: async (params) => {
|
||||
const service = requirePluginService()
|
||||
await service.whenReady()
|
||||
if (!pluginConsentForRpc) {
|
||||
throw new Error('Plugin consent is not available on this runtime')
|
||||
}
|
||||
await pluginConsentForRpc(params)
|
||||
return listForRpc()
|
||||
}
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'plugins.setEnabled',
|
||||
params: PluginSetEnabledParams,
|
||||
handler: async (params) => {
|
||||
const service = requirePluginService()
|
||||
await service.whenReady()
|
||||
if (!pluginEnablementForRpc) {
|
||||
throw new Error('Plugin enablement is not available on this runtime')
|
||||
}
|
||||
await pluginEnablementForRpc(params.pluginKey, params.enabled)
|
||||
return listForRpc()
|
||||
}
|
||||
}),
|
||||
defineMethod({
|
||||
// Why: headless serve clients relay panel bridge requests over RPC, so
|
||||
// capability enforcement must live behind this method too, not only in
|
||||
// the desktop IPC handler.
|
||||
name: 'plugins.panelAction',
|
||||
// Why: raw admission must run before strict schema parsing so malformed
|
||||
// and oversized traffic cannot bypass the panel budget.
|
||||
params: z.unknown(),
|
||||
handler: async (params, context) => {
|
||||
const service = requirePluginService()
|
||||
await service.whenReady()
|
||||
return {
|
||||
outcome: await service.panels.execute(bindRpcPanelOwner(service, context), params)
|
||||
}
|
||||
}
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'plugins.readPanelEntry',
|
||||
params: PluginReadPanelEntryParams,
|
||||
handler: async (params, context): Promise<PluginPanelEntry | null> => {
|
||||
const service = requirePluginService()
|
||||
await service.whenReady()
|
||||
const ownerKey = bindRpcPanelOwner(service, context)
|
||||
const entry = await service.panels.open(ownerKey, params.pluginKey, params.panelId)
|
||||
if (context.signal?.aborted) {
|
||||
service.panels.revokeOwner(ownerKey)
|
||||
return null
|
||||
}
|
||||
return entry
|
||||
}
|
||||
}),
|
||||
defineMethod({
|
||||
name: 'plugins.invokeCommand',
|
||||
params: PluginInvokeCommandParams,
|
||||
handler: async (params) => {
|
||||
const service = requirePluginService()
|
||||
await service.whenReady()
|
||||
return service.invokeCommand(params.pluginKey, params.commandId, params.args)
|
||||
}
|
||||
})
|
||||
]
|
||||
Reference in New Issue
Block a user