mirror of
https://github.com/stablyai/orca.git
synced 2026-11-03 02:27:43 +00:00
* plugins: app and terminal theme contributions Manifests can contribute themes (public CSS tokens over a light or dark base) and terminal themes (an ANSI palette), each at most 16 KiB. App themes must set --background and --foreground; omitted tokens are derived from them (surfaces copy the background, muted text, borders and accents mix the foreground into it), and values must be colors (no keywords, lengths, calc, var or url). Both load through the shared artifact-pack registry with the plugin's display name and a content revision, reach the renderer over IPC and are re-validated there. Catalog releases can declare app-theme and terminal-theme, and marketplaces stop hiding theme listings. docs/reference/plugin-themes.md documents the format. * plugins: resolve a selected plugin terminal palette on every host Selecting a plugin terminal theme saves a copy of its palette in settings (terminalPluginPalettes). The shared lookup reads it, so main, headless serve and relays answer terminal color queries and native chat matches the terminal without the plugin loaded; a malformed snapshot falls back to the default theme. * plugins: one Theme list with plugin themes, painted safely Appearance keeps the System/Dark/Light control until a plugin offers a theme; then Theme becomes one list with plugin themes after a divider, labelled with the publisher when names collide. Choosing one stores its base in theme and remembers the earlier built-in choice, which comes back while the plugin is off or after it is uninstalled; a plugin update that changes the base re-syncs theme. It also offers the plugin's terminal colors in one click. The renderer paints only values CSS parses as colors, checks every text/surface pair, ring and border against the effective set (plugin values over this mode's built-ins) and repeats until nothing changes, so dropping one pair cannot expose another. The applied theme is cached with its id and revision, painted before first render, and dropped as soon as settings show it no longer applies. Main bounds the new settings on every write and load, and uninstalling a plugin clears its theme choices and palette copies. Terminal themes appear under Plugins in the picker with the plugin's name and are passed to lookups instead of read from a store. * plugins: type the theme settings normalizer input; let the store own its normalization * fix(plugins): check text contrast on the editor surface and clear terminal overrides when adopting a theme's terminal colors * fix(plugins): reject theme colors the canvas probe silently ignores
115 lines
3.8 KiB
TypeScript
115 lines
3.8 KiB
TypeScript
import { z } from 'zod'
|
|
import {
|
|
pluginExecutionAllows,
|
|
pluginExecutionProfileSchema,
|
|
type PluginExecutionProfile
|
|
} from './plugin-execution-profile'
|
|
import type { PluginManifest } from './plugin-manifest'
|
|
|
|
// Why only installable types: a catalog entry naming any other type fails to parse, so the
|
|
// v2 catalog drops it instead of listing a plugin this client cannot install.
|
|
export const PLUGIN_CATALOG_TYPES = [
|
|
'interface-language',
|
|
'app-theme',
|
|
'terminal-theme',
|
|
'instructions',
|
|
'panel',
|
|
'worker'
|
|
] as const
|
|
|
|
export type PluginCatalogType = (typeof PLUGIN_CATALOG_TYPES)[number]
|
|
|
|
const CATALOG_TYPE_PROFILE: Partial<Record<PluginCatalogType, PluginExecutionProfile>> = {
|
|
instructions: 'instructional',
|
|
panel: 'sandboxed-ui',
|
|
worker: 'trusted-worker'
|
|
}
|
|
|
|
/** The exact release a catalog vouches for. Unknown keys are stripped so a newer catalog
|
|
* can add optional fields without breaking clients that predate them. */
|
|
export const pluginCatalogReleaseSchema = z
|
|
.object({
|
|
version: z.string().min(1).max(128),
|
|
// Why SHA-1 only: plugin materialization rejects SHA-256 repositories.
|
|
commit: z.string().regex(/^[0-9a-f]{40}$/),
|
|
contentHash: z.string().regex(/^[0-9a-f]{64}$/),
|
|
execution: pluginExecutionProfileSchema,
|
|
minimumOrca: z.string().regex(/^\d+\.\d+\.\d+$/),
|
|
types: z
|
|
.array(z.enum(PLUGIN_CATALOG_TYPES))
|
|
.min(1)
|
|
.max(PLUGIN_CATALOG_TYPES.length)
|
|
.refine((types) => new Set(types).size === types.length, 'duplicate contribution type')
|
|
})
|
|
.superRefine((release, ctx) => {
|
|
for (const [index, type] of release.types.entries()) {
|
|
const required = CATALOG_TYPE_PROFILE[type]
|
|
if (required && !pluginExecutionAllows(release.execution, required)) {
|
|
ctx.addIssue({
|
|
code: 'custom',
|
|
path: ['types', index],
|
|
message: `${release.execution} cannot declare ${type}`
|
|
})
|
|
}
|
|
}
|
|
})
|
|
|
|
export type PluginCatalogRelease = z.infer<typeof pluginCatalogReleaseSchema>
|
|
|
|
export function pluginCatalogTypes(manifest: PluginManifest): PluginCatalogType[] {
|
|
const c = manifest.contributes
|
|
const types: PluginCatalogType[] = []
|
|
if (c.languagePacks.length > 0) {
|
|
types.push('interface-language')
|
|
}
|
|
if (c.themes.length > 0) {
|
|
types.push('app-theme')
|
|
}
|
|
if (c.terminalThemes.length > 0) {
|
|
types.push('terminal-theme')
|
|
}
|
|
if (c.commands.length || c.keybindings.length || c.vmRecipes.length || c.agents.length) {
|
|
types.push('instructions')
|
|
}
|
|
if (c.panels.length > 0) {
|
|
types.push('panel')
|
|
}
|
|
if (manifest.main !== undefined) {
|
|
types.push('worker')
|
|
}
|
|
return types
|
|
}
|
|
|
|
/** Why null-or-message: install and preview surface the first mismatch verbatim. */
|
|
export function pluginCatalogReleaseError(input: {
|
|
release: PluginCatalogRelease
|
|
manifest: PluginManifest
|
|
resolvedCommit: string | null
|
|
contentHash: string
|
|
}): string | null {
|
|
const { release, manifest } = input
|
|
if (input.resolvedCommit !== release.commit) {
|
|
return 'plugin source no longer matches the catalog release commit'
|
|
}
|
|
if (input.contentHash !== release.contentHash) {
|
|
return 'plugin bytes do not match the catalog release'
|
|
}
|
|
if (manifest.manifestVersion !== 2) {
|
|
return 'catalog releases require a version 2 manifest'
|
|
}
|
|
if (manifest.version !== release.version) {
|
|
return 'manifest version does not match the catalog release'
|
|
}
|
|
if (manifest.execution !== release.execution) {
|
|
return 'execution profile does not match the catalog release'
|
|
}
|
|
if (manifest.engines.orca !== `>=${release.minimumOrca}`) {
|
|
return 'Orca compatibility does not match the catalog release'
|
|
}
|
|
const declared = [...release.types].sort().join()
|
|
if (pluginCatalogTypes(manifest).sort().join() !== declared) {
|
|
return 'contributions do not match the catalog release'
|
|
}
|
|
return null
|
|
}
|