Files
archived-orca/src/shared/plugins/capabilities/plugin-capabilities.ts
T
NeilandClaude 2fb3a0975e feat(plugins): workers can open files and run built-in actions (#37323)
* feat(plugins): add editor.open and commands.run for full-access workers

Both ride the existing plugin view request channel (the one plugin open and
plugin shot use) to the one main window's renderer; headless serve and a
missing window answer unavailable. editor.open takes a path that stays
inside the workspace (Git worktrees and folders) and opens it as a tab
without switching what the person sees. commands.run takes only the built-in
contributes.commands action list and dispatches Orca's own handler, never a
plugin replacement. Both need workspace:write.

workspace.list now also lists project-group folder workspaces.

* fix(plugins): open folder workspaces and host-naming ids through Orca's window

workspace.open of a project-group folder asks the window to show it
(setActiveFolderWorkspace), since the runtime activates Git worktrees only.
editor.open resolves the identity: ids workspace.list now returns. commands.run
documents that it must call the raw built-in, never a replacement wrapper.

* plugins: regenerate the testing bundle and skill guides on the rebased host actions

Generated files only (lint-staged's oxlint refuses a commit with no lintable files).

Co-Authored-By: Claude <noreply@anthropic.com>

* chore(plugins): regenerate the testing bundle on main

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-02 05:47:35 +00:00

94 lines
4.0 KiB
TypeScript

import { z } from 'zod'
import { PLUGIN_ENUM_SINCE_KEY } from '../manifest/plugin-engine-floor-keys'
import {
pluginFieldDoc,
PLUGIN_HOST_ACTIONS_SINCE,
PLUGIN_MANIFEST_V2_SINCE,
PLUGIN_SCHEMA_SINCE_V1
} from '../manifest/plugin-schema-field-docs'
/** Closed v0 capabilities fail unknown kinds instead of silently granting nothing. Consent binds capabilities and worker trust;
* host boundaries enforce them across desktop, headless serve and relay. Scoped kinds remain future work. */
export const PLUGIN_CAPABILITY_KINDS = [
'workspace:read',
'workspace:write',
'agent:read',
'agent:launch',
'terminal:send',
'terminal:read',
'notifications:show',
'storage:own',
'secrets:own',
'settings:own'
] as const
export type PluginCapabilityKind = (typeof PLUGIN_CAPABILITY_KINDS)[number]
/** The release each capability arrived in; engines.orca must cover every one a plugin asks for. */
export const PLUGIN_CAPABILITY_SINCE: Record<PluginCapabilityKind, string> = {
'workspace:read': PLUGIN_SCHEMA_SINCE_V1,
'workspace:write': PLUGIN_HOST_ACTIONS_SINCE,
'agent:read': PLUGIN_MANIFEST_V2_SINCE,
'agent:launch': PLUGIN_HOST_ACTIONS_SINCE,
'terminal:send': PLUGIN_SCHEMA_SINCE_V1,
'terminal:read': PLUGIN_HOST_ACTIONS_SINCE,
'notifications:show': PLUGIN_SCHEMA_SINCE_V1,
'storage:own': PLUGIN_MANIFEST_V2_SINCE,
'secrets:own': PLUGIN_MANIFEST_V2_SINCE,
'settings:own': PLUGIN_SCHEMA_SINCE_V1
}
/** Format 1 capability names and what each now grants. `events:subscribe` split by event domain. */
export const PLUGIN_V1_CAPABILITY_ALIASES: ReadonlyMap<string, readonly PluginCapabilityKind[]> =
new Map([
['storage', ['storage:own']],
['secrets', ['secrets:own']],
['events:subscribe', ['workspace:read', 'agent:read']]
])
// Strict object (not a bare enum) so scoped fields can be added per-kind later
// without changing the manifest shape.
export const pluginCapabilitySchema = z
.object({
kind: z.enum(PLUGIN_CAPABILITY_KINDS).meta({
...pluginFieldDoc('Capability granted on user consent.', PLUGIN_SCHEMA_SINCE_V1),
[PLUGIN_ENUM_SINCE_KEY]: PLUGIN_CAPABILITY_SINCE
})
})
.strict()
.meta({ id: 'Capability', description: 'A host API the plugin may call once the user consents.' })
export type PluginCapability = z.infer<typeof pluginCapabilitySchema>
/** Consent copy shown verbatim; describe only what the host actually enforces. */
export const PLUGIN_CAPABILITY_DESCRIPTIONS: Record<PluginCapabilityKind, string> = {
'workspace:read':
'Read the name, branch, and terminal list of your focused workspace, and get notified when workspaces are created or removed',
'workspace:write': 'Open your workspaces and their files in Orca, and run its built-in commands',
'agent:read': 'Get notified when agent status changes',
'agent:launch': 'Start agents in your workspaces, local and SSH',
'terminal:send': 'Type and run commands in your terminals, local and SSH',
'terminal:read': 'Read the output of your terminals, local and SSH',
'notifications:show': 'Show desktop notifications labeled with the plugin name',
'storage:own': "Store data in the plugin's own storage folder",
'secrets:own': "Store and read secrets in the plugin's own encrypted file",
'settings:own': "Read and change the plugin's own settings"
}
/** Canonicalize order, duplicates and field order so equivalent grants preserve consent across manifest formatting changes. */
export function canonicalizeCapabilitySet(capabilities: readonly PluginCapability[]): string {
return JSON.stringify([...new Set(capabilities.map(canonicalizeCapability))].sort())
}
/** One grant, key-sorted, so a scoped field such as hosts counts as part of what is granted. */
export function canonicalizeCapability(capability: PluginCapability): string {
return JSON.stringify(
Object.fromEntries(Object.entries(capability).sort(([a], [b]) => a.localeCompare(b)))
)
}
export function capabilityKinds(capabilities: readonly PluginCapability[]): PluginCapabilityKind[] {
return [...new Set(capabilities.map((capability) => capability.kind))]
}