mirror of
https://github.com/stablyai/orca.git
synced 2026-10-28 00:02:54 +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>
208 lines
6.7 KiB
TypeScript
208 lines
6.7 KiB
TypeScript
import { z } from 'zod'
|
|
import { isAllowedPluginGitUrl } from './plugin-install-lockfile'
|
|
import { isQualifiedPluginKey } from './plugin-manifest'
|
|
|
|
export const PLUGIN_MARKETPLACE_FILENAME = 'orca-marketplace.json'
|
|
export const PLUGIN_MARKETPLACE_ENTRY_LIMIT = 2_048
|
|
export const PLUGIN_MARKETPLACE_CATEGORY_LIMIT = 16
|
|
|
|
export const OFFICIAL_PLUGIN_PUBLISHER = 'stablyai'
|
|
export const OFFICIAL_PLUGIN_ID_PREFIX = 'orca-'
|
|
export const OFFICIAL_MARKETPLACE_OWNER = 'stablyai'
|
|
export const OFFICIAL_MARKETPLACE_REPOSITORY = 'orca-plugins'
|
|
|
|
// Why: theme/icon/skill contributions were deferred, so `contributes` now
|
|
// rejects them and any plugin declaring one fails to install wholesale. The
|
|
// shared marketplace index (which this build does not control) still advertises
|
|
// such packs; hide listings that carry these categories so users never hit a
|
|
// dead "install" path until the marketplace catches up.
|
|
export const UNSUPPORTED_MARKETPLACE_CATEGORIES: readonly string[] = [
|
|
'themes',
|
|
'icons',
|
|
'icon-themes',
|
|
'terminal-themes',
|
|
'skills'
|
|
]
|
|
|
|
export function isMarketplaceListingSupported(categories: readonly string[]): boolean {
|
|
return !categories.some((category) => UNSUPPORTED_MARKETPLACE_CATEGORIES.includes(category))
|
|
}
|
|
|
|
const marketplaceOwnerSchema = z
|
|
.string()
|
|
.min(1)
|
|
.max(128)
|
|
.regex(/^[A-Za-z0-9](?:[A-Za-z0-9._-]*[A-Za-z0-9])?$/, 'invalid marketplace owner')
|
|
|
|
const marketplaceCategorySchema = z
|
|
.string()
|
|
.min(1)
|
|
.max(64)
|
|
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, 'categories must be lowercase slugs')
|
|
|
|
export const pluginMarketplaceGitSourceSchema = z.strictObject({
|
|
kind: z.literal('git'),
|
|
url: z
|
|
.string()
|
|
.trim()
|
|
.min(1)
|
|
.max(32 * 1024)
|
|
.refine(isAllowedPluginGitUrl, 'git URL must use HTTPS or SSH'),
|
|
// Why: marketplace installs must first resolve a named ref to an exact
|
|
// commit; an omitted remote default would make the listing irreproducible.
|
|
ref: z.string().trim().min(1).max(4_096)
|
|
})
|
|
|
|
export const pluginMarketplaceEntrySchema = z
|
|
.strictObject({
|
|
/** Canonical `<publisher>.<id>` identity expected in the source manifest. */
|
|
id: z.string().refine(isQualifiedPluginKey, 'invalid qualified plugin key'),
|
|
source: pluginMarketplaceGitSourceSchema,
|
|
description: z.string().min(1).max(4_096).optional(),
|
|
categories: z
|
|
.array(marketplaceCategorySchema)
|
|
.max(PLUGIN_MARKETPLACE_CATEGORY_LIMIT)
|
|
.default([])
|
|
})
|
|
.superRefine((entry, context) => {
|
|
const seen = new Set<string>()
|
|
for (const [index, category] of entry.categories.entries()) {
|
|
if (seen.has(category)) {
|
|
context.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
path: ['categories', index],
|
|
message: `duplicate category: ${category}`
|
|
})
|
|
}
|
|
seen.add(category)
|
|
}
|
|
})
|
|
|
|
export const pluginMarketplaceSchema = z
|
|
.strictObject({
|
|
name: z.string().min(1).max(256),
|
|
owner: marketplaceOwnerSchema,
|
|
plugins: z.array(pluginMarketplaceEntrySchema).max(PLUGIN_MARKETPLACE_ENTRY_LIMIT)
|
|
})
|
|
.superRefine((marketplace, context) => {
|
|
const seen = new Set<string>()
|
|
for (const [index, plugin] of marketplace.plugins.entries()) {
|
|
if (seen.has(plugin.id)) {
|
|
context.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
path: ['plugins', index, 'id'],
|
|
message: `duplicate plugin id: ${plugin.id}`
|
|
})
|
|
}
|
|
seen.add(plugin.id)
|
|
}
|
|
})
|
|
|
|
/** Host-derived trust metadata. Marketplace JSON cannot self-award either bit. */
|
|
export const pluginMarketplaceTrustMetadataSchema = z
|
|
.strictObject({
|
|
official: z.boolean(),
|
|
bundled: z.boolean()
|
|
})
|
|
.refine((metadata) => !metadata.bundled || metadata.official, {
|
|
message: 'bundled plugins must be official',
|
|
path: ['bundled']
|
|
})
|
|
|
|
export type PluginMarketplace = z.infer<typeof pluginMarketplaceSchema>
|
|
export type PluginMarketplaceEntry = z.infer<typeof pluginMarketplaceEntrySchema>
|
|
export type PluginMarketplaceGitSource = z.infer<typeof pluginMarketplaceGitSourceSchema>
|
|
export type PluginMarketplaceTrustMetadata = z.infer<typeof pluginMarketplaceTrustMetadataSchema>
|
|
|
|
export const OFFICIAL_MARKETPLACE_GIT_SOURCE: PluginMarketplaceGitSource = {
|
|
kind: 'git',
|
|
url: 'https://github.com/stablyai/orca-plugins.git',
|
|
ref: 'main'
|
|
}
|
|
|
|
export function splitQualifiedPluginKey(pluginKey: string): {
|
|
publisher: string
|
|
id: string
|
|
} | null {
|
|
if (!isQualifiedPluginKey(pluginKey)) {
|
|
return null
|
|
}
|
|
const separator = pluginKey.indexOf('.')
|
|
return {
|
|
publisher: pluginKey.slice(0, separator),
|
|
id: pluginKey.slice(separator + 1)
|
|
}
|
|
}
|
|
|
|
export function isReservedPluginIdentity(pluginKey: string): boolean {
|
|
const identity = splitQualifiedPluginKey(pluginKey)
|
|
return (
|
|
identity !== null &&
|
|
(identity.publisher === OFFICIAL_PLUGIN_PUBLISHER ||
|
|
identity.id.startsWith(OFFICIAL_PLUGIN_ID_PREFIX))
|
|
)
|
|
}
|
|
|
|
export function isOfficialPluginIdentity(pluginKey: string): boolean {
|
|
const identity = splitQualifiedPluginKey(pluginKey)
|
|
return (
|
|
identity !== null &&
|
|
identity.publisher === OFFICIAL_PLUGIN_PUBLISHER &&
|
|
identity.id.startsWith(OFFICIAL_PLUGIN_ID_PREFIX)
|
|
)
|
|
}
|
|
|
|
type GitRepositoryIdentity = {
|
|
host: string
|
|
owner: string
|
|
repository: string
|
|
}
|
|
|
|
/** Extracts the host and first owner segment from the HTTPS/SSH Git forms the
|
|
* installer accepts. It is intentionally only a provenance parser. */
|
|
export function parseGitRepositoryIdentity(url: string): GitRepositoryIdentity | null {
|
|
const trimmed = url.trim()
|
|
const scp = /^[^\s@/:]+@([^\s:]+):(.+)$/.exec(trimmed)
|
|
if (scp) {
|
|
return repositoryIdentity(scp[1]!, scp[2]!)
|
|
}
|
|
try {
|
|
const parsed = new URL(trimmed)
|
|
if (parsed.protocol !== 'https:' && parsed.protocol !== 'ssh:') {
|
|
return null
|
|
}
|
|
return repositoryIdentity(parsed.hostname, parsed.pathname)
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
function repositoryIdentity(host: string, repositoryPath: string): GitRepositoryIdentity | null {
|
|
const segments = repositoryPath
|
|
.replace(/^\/+|\/+$/g, '')
|
|
.split('/')
|
|
.filter(Boolean)
|
|
if (segments.length < 2) {
|
|
return null
|
|
}
|
|
const repository = segments.at(-1)!.replace(/\.git$/i, '')
|
|
if (!repository) {
|
|
return null
|
|
}
|
|
return { host: host.toLowerCase(), owner: segments[0]!, repository }
|
|
}
|
|
|
|
export function isOfficialOrganizationGitSource(url: string): boolean {
|
|
const source = parseGitRepositoryIdentity(url)
|
|
return source?.host === 'github.com' && source.owner.toLowerCase() === OFFICIAL_PLUGIN_PUBLISHER
|
|
}
|
|
|
|
export function isOfficialMarketplaceGitSource(url: string): boolean {
|
|
const source = parseGitRepositoryIdentity(url)
|
|
return (
|
|
source?.host === 'github.com' &&
|
|
source.owner.toLowerCase() === OFFICIAL_MARKETPLACE_OWNER &&
|
|
source.repository.toLowerCase() === OFFICIAL_MARKETPLACE_REPOSITORY
|
|
)
|
|
}
|