Files
orca/src/shared/plugins/plugin-content-pack-contributions.ts
T
Neil 5018241866 feat(plugins): app and terminal themes in one Theme list, painted safely (#30719)
* 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
2026-10-28 15:13:10 -07:00

85 lines
2.8 KiB
TypeScript

import { z } from 'zod'
import {
pluginCommandIdSchema,
pluginIdSchema,
pluginRelativePathSchema
} from './plugin-manifest-fields'
import { normalizeKeybinding } from '../keybindings'
export const PLUGIN_LANGUAGE_PACK_LIMIT = 16
export const PLUGIN_KEYBINDING_LIMIT = 256
export const PLUGIN_VM_RECIPE_LIMIT = 64
export const PLUGIN_AGENT_PROFILE_LIMIT = 64
export const PLUGIN_THEME_LIMIT = 64
export const PLUGIN_TERMINAL_THEME_LIMIT = 64
/** True when Intl can parse the tag's grammar, not just its shape. */
function isWellFormedLocaleId(value: string): boolean {
try {
Intl.getCanonicalLocales(value)
return true
} catch {
return false
}
}
// Locale IDs become filenames/i18next keys; a bounded BCP 47 subset excludes path syntax.
// Intl rejects shape-valid, ill-formed tags (`en-US-US`) at install, not silently when formatting.
export const pluginLocaleIdSchema = z
.string()
.min(2)
.max(35)
.regex(/^[A-Za-z]{2,3}(?:-[A-Za-z0-9]{2,8})*$/, 'must be a portable locale identifier')
.refine(isWellFormedLocaleId, 'must be a well-formed locale identifier')
export const pluginLanguagePackContributionSchema = z
.object({
locale: pluginLocaleIdSchema,
path: pluginRelativePathSchema,
// Native-language label for the Settings picker; omitted packs show `{locale} — {pluginKey}`.
displayName: z.string().trim().min(1).max(80).optional()
})
.strict()
export const pluginKeybindingContributionSchema = z
.object({
command: pluginCommandIdSchema,
key: z
.string()
.min(1)
.max(128)
.transform((value, ctx) => {
const normalized = normalizeKeybinding(value)
if (!normalized.ok) {
ctx.addIssue({ code: 'custom', message: normalized.error })
return z.NEVER
}
return normalized.value
}),
when: z.enum(['global', 'worktree']).optional()
})
.strict()
export const pluginVmRecipeContributionSchema = z
.object({ path: pluginRelativePathSchema })
.strict()
export const pluginAgentProfileContributionSchema = z
.object({ path: pluginRelativePathSchema })
.strict()
/** App and terminal themes share one shape: a labelled JSON artifact. */
export const pluginThemeContributionSchema = z
.object({
id: pluginIdSchema,
label: z.string().min(1).max(128),
path: pluginRelativePathSchema
})
.strict()
export type PluginLanguagePackContribution = z.infer<typeof pluginLanguagePackContributionSchema>
export type PluginKeybindingContribution = z.infer<typeof pluginKeybindingContributionSchema>
export type PluginVmRecipeContribution = z.infer<typeof pluginVmRecipeContributionSchema>
export type PluginAgentProfileContribution = z.infer<typeof pluginAgentProfileContributionSchema>
export type PluginThemeContribution = z.infer<typeof pluginThemeContributionSchema>