mirror of
https://github.com/stablyai/orca.git
synced 2026-10-02 08:02:02 +00:00
* 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>
215 lines
7.5 KiB
TypeScript
215 lines
7.5 KiB
TypeScript
import { z } from 'zod'
|
|
import { pluginCapabilitySchema } from './plugin-capabilities'
|
|
import {
|
|
PLUGIN_AGENT_PROFILE_LIMIT,
|
|
PLUGIN_KEYBINDING_LIMIT,
|
|
PLUGIN_LANGUAGE_PACK_LIMIT,
|
|
PLUGIN_VM_RECIPE_LIMIT,
|
|
pluginAgentProfileContributionSchema,
|
|
pluginKeybindingContributionSchema,
|
|
pluginLanguagePackContributionSchema,
|
|
pluginVmRecipeContributionSchema
|
|
} from './plugin-content-pack-contributions'
|
|
import {
|
|
isPluginManifestId,
|
|
isSafePluginId,
|
|
pluginCommandIdSchema,
|
|
pluginIdSchema,
|
|
pluginRelativePathSchema
|
|
} from './plugin-manifest-fields'
|
|
import { validatePluginManifestContributions } from './plugin-manifest-contribution-validation'
|
|
|
|
/**
|
|
* Plugin manifest v1 (`orca-plugin.json` at the plugin root). The
|
|
* `contributes` key names deliberately mirror common Electron-ecosystem
|
|
* manifest conventions so future adapters stay cheap.
|
|
*
|
|
* Lives in `shared` so the desktop app, the headless `orca serve` runtime,
|
|
* the relay, and the CLI validate manifests identically (SSH/remote parity).
|
|
*
|
|
* Everything here is EXPERIMENTAL: no compatibility promises until pluginApi
|
|
* v1 freezes (see the plugin roadmap).
|
|
*/
|
|
|
|
const SEMVER_RE =
|
|
/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*)(?:\.(?:0|[1-9]\d*|\d*[A-Za-z-][0-9A-Za-z-]*))*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/
|
|
export const PLUGIN_PANEL_LIMIT = 64
|
|
export const PLUGIN_COMMAND_LIMIT = 256
|
|
|
|
// Why: v0 supports only the ">=x.y.z" form. A closed grammar keeps the gate
|
|
// predictable; richer ranges can be added without breaking old manifests.
|
|
const orcaEngineRangeSchema = z
|
|
.string()
|
|
.max(64)
|
|
.regex(/^>=\d+\.\d+\.\d+$/, 'must be a ">=x.y.z" version range')
|
|
|
|
const panelContributionSchema = z.object({
|
|
id: pluginIdSchema,
|
|
title: z.string().min(1).max(256),
|
|
/** Lucide icon name rendered in the right-sidebar activity bar. */
|
|
icon: z.string().min(1).max(64).optional(),
|
|
/** HTML entry rendered inside a sandboxed panel frame. */
|
|
entry: pluginRelativePathSchema
|
|
})
|
|
|
|
const commandContributionSchema = z.object({
|
|
id: pluginCommandIdSchema,
|
|
title: z.string().min(1).max(256),
|
|
context: z.enum(['global', 'worktree']).optional(),
|
|
/** Built-in action aliases remain declarative and do not activate a worker. */
|
|
action: pluginCommandIdSchema.optional()
|
|
})
|
|
|
|
/** Domain events a plugin can subscribe to in v0. Closed set: server-side
|
|
* filtering means plugins only ever receive what they subscribed to. */
|
|
export const PLUGIN_EVENT_NAMES = [
|
|
'worktree.created',
|
|
'worktree.removed',
|
|
'agent.status.changed'
|
|
] as const
|
|
export const PLUGIN_EVENT_SUBSCRIPTION_LIMIT = PLUGIN_EVENT_NAMES.length
|
|
|
|
export type PluginEventName = (typeof PLUGIN_EVENT_NAMES)[number]
|
|
|
|
const eventContributionSchema = z.object({
|
|
on: z.enum(PLUGIN_EVENT_NAMES)
|
|
})
|
|
|
|
export const pluginManifestSchema = z
|
|
.object({
|
|
manifestVersion: z.literal(1),
|
|
id: pluginIdSchema,
|
|
/** Publisher slug; canonical identity is `<publisher>.<id>` — bare-id
|
|
* global uniqueness is unverifiable without a registry. */
|
|
publisher: pluginIdSchema,
|
|
name: z.string().min(1).max(256),
|
|
version: z.string().regex(SEMVER_RE, 'must be semver'),
|
|
description: z.string().max(4096).optional(),
|
|
author: z
|
|
.object({ name: z.string().min(1).max(256), url: z.string().max(2048).optional() })
|
|
.optional(),
|
|
repository: z.string().max(2048).optional(),
|
|
icon: pluginRelativePathSchema.optional(),
|
|
/** Minimum host version gate; the host refuses to load below it. */
|
|
engines: z.object({ orca: orcaEngineRangeSchema }),
|
|
/** Host-API major version this plugin targets. */
|
|
pluginApi: z.literal(1),
|
|
/** Node entry executed inside the out-of-process plugin worker. */
|
|
main: pluginRelativePathSchema.optional(),
|
|
contributes: z
|
|
.object({
|
|
panels: z.array(panelContributionSchema).max(PLUGIN_PANEL_LIMIT).default([]),
|
|
commands: z.array(commandContributionSchema).max(PLUGIN_COMMAND_LIMIT).default([]),
|
|
events: z.array(eventContributionSchema).max(PLUGIN_EVENT_SUBSCRIPTION_LIMIT).default([]),
|
|
languagePacks: z
|
|
.array(pluginLanguagePackContributionSchema)
|
|
.max(PLUGIN_LANGUAGE_PACK_LIMIT)
|
|
.default([]),
|
|
keybindings: z
|
|
.array(pluginKeybindingContributionSchema)
|
|
.max(PLUGIN_KEYBINDING_LIMIT)
|
|
.default([]),
|
|
vmRecipes: z
|
|
.array(pluginVmRecipeContributionSchema)
|
|
.max(PLUGIN_VM_RECIPE_LIMIT)
|
|
.default([]),
|
|
agents: z
|
|
.array(pluginAgentProfileContributionSchema)
|
|
.max(PLUGIN_AGENT_PROFILE_LIMIT)
|
|
.default([])
|
|
})
|
|
.strict()
|
|
.default(() => ({
|
|
panels: [],
|
|
commands: [],
|
|
events: [],
|
|
languagePacks: [],
|
|
keybindings: [],
|
|
vmRecipes: [],
|
|
agents: []
|
|
})),
|
|
capabilities: z.array(pluginCapabilitySchema).max(32).default([])
|
|
})
|
|
.superRefine(validatePluginManifestContributions)
|
|
|
|
export type PluginManifest = z.infer<typeof pluginManifestSchema>
|
|
export type PluginPanelContribution = z.infer<typeof panelContributionSchema>
|
|
export type PluginCommandContribution = z.infer<typeof commandContributionSchema>
|
|
export type PluginEventContribution = z.infer<typeof eventContributionSchema>
|
|
|
|
export {
|
|
isSafePluginId,
|
|
PLUGIN_ID_MAX_LENGTH,
|
|
pluginCommandIdSchema
|
|
} from './plugin-manifest-fields'
|
|
|
|
export const PLUGIN_MANIFEST_FILENAME = 'orca-plugin.json'
|
|
|
|
/** Canonical install identity: `<publisher>.<id>` (also the install dir name). */
|
|
export function qualifiedPluginKey(manifest: Pick<PluginManifest, 'publisher' | 'id'>): string {
|
|
return `${manifest.publisher}.${manifest.id}`
|
|
}
|
|
|
|
export function isQualifiedPluginKey(value: string): boolean {
|
|
const parts = value.split('.')
|
|
if (parts.length !== 2) {
|
|
return false
|
|
}
|
|
return isSafePluginId(parts[0]!) && isSafePluginId(parts[1]!)
|
|
}
|
|
|
|
export type PluginManifestParseResult =
|
|
| { ok: true; manifest: PluginManifest }
|
|
| { ok: false; error: string }
|
|
|
|
export function parsePluginManifest(raw: unknown): PluginManifestParseResult {
|
|
const parsed = pluginManifestSchema.safeParse(raw)
|
|
if (parsed.success) {
|
|
return { ok: true, manifest: parsed.data }
|
|
}
|
|
const issue = parsed.error.issues[0]
|
|
const path = issue?.path.join('.') || '(root)'
|
|
return { ok: false, error: `${path}: ${issue?.message ?? 'invalid manifest'}` }
|
|
}
|
|
|
|
/** v0 engines gate: supports the ">=x.y.z" grammar the schema enforces.
|
|
* Prerelease/build suffixes on the host version are ignored for ordering. */
|
|
export function satisfiesOrcaEngineRange(hostVersion: string, range: string): boolean {
|
|
const minimum = range.slice(2)
|
|
const parse = (value: string): number[] =>
|
|
value
|
|
.split(/[-+]/)[0]!
|
|
.split('.')
|
|
.map((part) => Number.parseInt(part, 10) || 0)
|
|
const host = parse(hostVersion)
|
|
const min = parse(minimum)
|
|
for (let i = 0; i < 3; i++) {
|
|
const a = host[i] ?? 0
|
|
const b = min[i] ?? 0
|
|
if (a !== b) {
|
|
return a > b
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
/** Sidebar tab key for a plugin panel: `plugin:<publisher>.<id>/<panelId>`. */
|
|
export function pluginPanelTabKey(qualifiedKey: string, panelId: string): `plugin:${string}` {
|
|
return `plugin:${qualifiedKey}/${panelId}`
|
|
}
|
|
|
|
export function isPluginPanelTabKey(tab: string): tab is `plugin:${string}` {
|
|
if (!tab.startsWith('plugin:')) {
|
|
return false
|
|
}
|
|
const rest = tab.slice('plugin:'.length)
|
|
const [qualifiedKey, panelId, ...extra] = rest.split('/')
|
|
return (
|
|
extra.length === 0 &&
|
|
!!qualifiedKey &&
|
|
!!panelId &&
|
|
isQualifiedPluginKey(qualifiedKey) &&
|
|
isPluginManifestId(panelId)
|
|
)
|
|
}
|