- a draft starting with `?` enters btw mode and submits as `/btw <question>` through the existing slash path; a bare `?` stays a prompt - esc leaves btw mode and ask capture skips it, like bash and python modes - added the required `btwMode` theme color (each bundled theme's accent) with schema, docs and the html export palette - the native composer shows a `btw` mode chip under role `omp.editor.btw-ask` and hides the `?` sigil - added input-controller tests for `?` routing and a bare `?`
17 KiB
Theming Reference
This document describes how theming works in the coding-agent today: schema, loading, runtime behavior, and failure modes.
What the theme system controls
The theme system drives:
- foreground/background color tokens used across the TUI
- markdown styling adapters (
getMarkdownTheme()) - selector/editor/settings list adapters (
getSelectListTheme(),getEditorTheme(),getSettingsListTheme()) - symbol preset + symbol overrides (
unicode,nerd,ascii) - syntax highlighting colors used by native highlighter (
@oh-my-pi/pi-natives) - status line segment colors
- agent name colors in the agent hub, agent tree and Task tool rows
Primary implementation: packages/tui/src/theme/theme.ts.
Theme JSON shape
Custom theme files are JSON objects validated by validateThemeJson() in packages/tui/src/theme/schema-validation.ts (using @oh-my-pi/omptype). Types live in schema.ts; the editor-facing JSON schema is packages/tui/src/theme/theme-schema.json. Embedded built-in themes bypass runtime validation.
Top-level fields:
name(required)colors(required; all tokens exceptthinkingMaxrequired)vars(optional; reusable color variables)export(optional; HTML export colors)symbols(optional)preset(optional:unicode | nerd | ascii)overrides(optional: key/value overrides forSymbolKey)
Color values accept:
- hex string (
"#RRGGBB") - numeric 256-color index (use
0..255; runtime schema accepts numbers without enforcing this range) - variable reference string (resolved through
vars) - empty string (
"") meaning terminal default (\x1b[39mfg,\x1b[49mbg)
Required and optional color tokens
All tokens below are required in colors except thinkingMax (falls back to thinkingXhigh), assistantMessageText (unset/empty keeps the terminal default foreground), mdExtensionLink (unset derives a muted mdLink) and subagent1–subagent6 (unset lets omp pick agent colors from the theme).
Core text and borders (11)
accent, border, borderAccent, borderMuted, success, error, warning, muted, dim, text, thinkingText
Background blocks (7)
selectedBg, userMessageBg, customMessageBg, toolPendingBg, toolSuccessBg, toolErrorBg, statusLineBg
Message/tool text (5 required, 1 optional)
userMessageText, customMessageText, customMessageLabel, toolTitle, toolOutput, optional assistantMessageText
assistantMessageText colors the assistant reply's plain paragraph prose (markdown sub-elements keep their own md* tokens). It is the token that governs assistant prose — text does not: text is applied at explicit theme.fg("text", …) callsites (editor/dialog surfaces), never to assistant message bodies. When assistantMessageText is omitted or set to "", prose renders in the terminal default foreground exactly as before the token existed. An explicitly installed prose color transform (live-command output) still wins over the token.
Markdown (10 required, 1 optional)
mdHeading, mdLink, mdLinkUrl, mdCode, mdCodeBlock, mdCodeBlockBorder, mdQuote, mdQuoteBorder, mdHr, mdListBullet, optional mdExtensionLink
mdExtensionLink colors the label of a link whose scheme an extension registered (for example a link that expands text in place). Such a link opens nothing in the browser, so its color sets it apart from mdLink, which colors links that open a URL. When it is omitted, omp blends mdLink with text (45% link, 55% text). A "" in either token blends as the theme's terminal.foreground and a palette index 0–15 as its terminal.ansi slot. A theme that declares neither gets approximations: a stock palette for indices 0–15 and a guessed default foreground for "". Set the token explicitly when the guess looks wrong. tui.colorfulMarkdown does not change either link color.
With the tui.colorfulMarkdown setting on (the default), headings, **strong**, *emphasis*, inline code and table headers take their colors from the theme's terminal.ansi palette instead of mdHeading/mdCode and plain bold/italic: H1 magenta, H2 yellow, H3–H6 blue, strong/emphasis magenta, inline code green, table headers yellow. All hues come from one palette so they stay distinct. Turning the setting off restores mdHeading for every level, mdCode, and uncolored bold/italic.
Tool diff + syntax highlighting (12)
toolDiffAdded, toolDiffRemoved, toolDiffContext,
syntaxComment, syntaxKeyword, syntaxFunction, syntaxVariable, syntaxString, syntaxNumber, syntaxType, syntaxOperator, syntaxPunctuation
Mode/thinking borders (9 required, 1 optional)
thinkingOff, thinkingMinimal, thinkingLow, thinkingMedium, thinkingHigh, thinkingXhigh, optional thinkingMax, bashMode, pythonMode, btwMode
Status line segment colors (13)
statusLineSep, statusLineModel, statusLinePath, statusLineGitClean, statusLineGitDirty, statusLineContext, statusLineSpend, statusLineStaged, statusLineDirty, statusLineUntracked, statusLineOutput, statusLineCost, statusLineSubagents
Agent name colors (6 optional)
subagent1, subagent2, subagent3, subagent4, subagent5, subagent6
The main agent's name takes accent. Subagents take a color in the order they arrive in the session: the first gets the first subagent color, the seventh reuses it, and an agent keeps its color for the rest of the session. A declared subagentN is used as written. Slots the theme leaves unset are filled, in order, with colors that are at least 3:1 against every surface names are drawn on (terminal.background, else statusLineBg, and the Task card tints toolPendingBg, toolSuccessBg, toolErrorBg) and at least 0.10 apart in OKLab from accent, error and each other: first the theme's own terminal.ansi hues (blue, green, yellow, magenta, cyan, then their bright slots; red is left to errors), then hues derived from accent the way the session color is (each also offered one and two lightness steps further from the background), then a fixed fallback set.
Optional tokens
export section (optional)
Used for HTML export theming helpers:
export.pageBgexport.cardBgexport.infoBg
If omitted, export code derives defaults from resolved theme colors.
terminal section (optional)
Describes the terminal the theme was made for, for hosts that paint the terminal themselves (Tern); omp never sets the terminal's colors. terminal.ansi (exactly 16 entries, ANSI 0–15) is also the palette colorful Markdown paints from; a theme without it falls back to the terminal's own ANSI colors. Agent name colors draw on terminal.ansi first and check contrast against terminal.background.
symbols section (optional)
symbols.presetsets a theme-level default symbol set.symbols.overridescan override individualSymbolKeyvalues.symbols.spinnerFramesoverrides the loading spinner frames. Accepts either a flatstring[](applied to both spinner types) or an object{ "status"?: string[], "activity"?: string[] }to override each type independently. Any type not specified falls back to the symbol preset's default frames.statusdrives the ~12.5fps spinner used by loaders and tool-execution indicators;activitydrives the ~30fps spinner used by markdown progress bars and similar high-frequency UI.
Runtime precedence:
- settings
symbolPresetoverride (if set) - theme JSON
symbols.preset - fallback
"unicode"
In interactive mode, a successful Glyph Protocol handshake upgrades a Unicode preset whose setting provenance is default to Nerd Font icons without changing the saved setting. An explicitly configured preset, including unicode, is not upgraded. A live Tern native surface forces the Nerd preset process-locally and restores the user's preset when it closes.
Invalid override keys are ignored and logged (logger.debug).
Box-drawing borders
All outlined chrome — tool-result frames, overlays, code fences, the editor, the welcome banner — draws with the boxRound.* tokens: rounded corners (╭╮╰╯) plus tee/cross junctions (├┤┬┴┼, which have no rounded Unicode form, so they are sourced from the boxSharp.* tokens). Markdown tables are the sole exception and keep the fully sharp boxSharp.* set (┌┐└┘).
Override behavior follows from that split:
boxRound.{topLeft,topRight,bottomLeft,bottomRight,horizontal,vertical}restyle every border's corners and edges.boxSharp.{cross,teeDown,teeUp,teeRight,teeLeft}restyle dividers/junctions everywhere (rounded frames and tables alike).boxSharp.{topLeft,topRight,bottomLeft,bottomRight}now affect markdown table corners only.
Built-in vs custom theme sources
Theme lookup order (loadThemeJson):
- built-in embedded themes (
dark.json,light.json, and every palette indefaults.json) - custom theme file:
<customThemesDir>/<name>.json
Custom themes directory comes from getCustomThemesDir():
- default:
~/.omp/agent/themes - default-profile override:
PI_CODING_AGENT_DIR($PI_CODING_AGENT_DIR/themes) - named profile:
~/.omp/profiles/<name>/agent/themes(under the configured root); named profiles derive their own agent directory
getAvailableThemes() returns merged built-in + custom names, sorted, with built-ins taking precedence on name collision.
Loading, validation, and resolution
For custom theme files:
- read JSON
- parse JSON
- validate with
validateThemeJson()(required fields and string/number types; spinner frame arrays must be non-empty) - resolve
varsreferences recursively - convert resolved values to ANSI by terminal capability mode
Validation behavior:
- missing required color tokens: explicit grouped error message
- bad token types: runtime schema errors; string color values and variable references are checked during resolution/conversion
- unknown theme file:
Theme not found: <name>
Var reference behavior:
- supports nested references
- throws on missing variable reference
- throws on circular references
Terminal color mode behavior
Color mode detection (detectColorMode in theme/color.ts):
WT_SESSION=> truecolor- otherwise uses
detectTerminalId()andgetTerminalInfo()from the shared terminal capability model, selecting truecolor only whenTerminalInfo.trueColoris true
Conversion behavior:
- hex ->
Bun.color(..., "ansi-16m" | "ansi-256") - numeric ->
38;5/48;5ANSI ""-> default fg/bg reset
Runtime switching behavior
The theme export is a live binding, including in bundled extensions. Read it inside rendering callbacks rather than retaining a theme instance across switches. Extension renderer callbacks may also use their supplied theme argument.
import { theme } from "@oh-my-pi/pi-coding-agent";
const renderStatus = () => theme.fg("accent", "Ready");
Initial theme (initThemeSync / initTheme)
The startup composer initializes its cached theme synchronously before the first paint. main.ts later initializes the authoritative theme with settings:
symbolPresetcolorBlindModetheme.darktheme.light
Auto theme slot selection uses terminal appearance in this order:
- terminal-reported OSC 11 background luminance, unless the macOS/Zellij fallback path is active
COLORFGBGbackground index (< 8=> dark,>= 8=> light)- macOS appearance fallback only for the known-broken macOS/Zellij OSC 11 path
- dark slot fallback
Current defaults (definitions in packages/coding-agent/src/modes/settings.ts):
theme.dark = "titanium"theme.light = "light"symbolPreset = "unicode"colorBlindMode = false
Explicit switching (setTheme)
- loads selected theme
- updates the live
themeexport - optionally starts watcher
- triggers
onThemeChangecallback
On failure:
- falls back to built-in
dark - returns
{ success: false, error }
Preview switching (previewTheme)
- applies the preview to the live
themeexport - does not change persisted settings by itself
- returns success/error without fallback replacement
Settings UI uses this for live preview and restores prior theme on cancel.
Watchers and live reload
When watcher is enabled (setTheme(..., true) / interactive init):
- watches
<customThemesDir>/<currentTheme>.jsononly when that file exists - built-ins are effectively not watched; built-in theme lookup also takes precedence over same-name custom files
- matching file changes schedule a debounced reload; reload errors or temporary file absence keep the last successfully loaded theme
- the watcher does not perform a delete/rename fallback; it waits for a future successful reload or explicit theme switch
Auto mode also reevaluates dark/light slot mapping from terminal appearance changes, SIGWINCH, and the macOS fallback observer when active.
Color-blind mode behavior
colorBlindMode changes only one token at runtime:
toolDiffAddedis HSV-adjusted (green shifted toward blue)- adjustment is applied only when resolved value is a hex string
Other tokens are unchanged. Agent name colors derived from accent steer clear of the theme's hues, toolDiffAdded among them, so the shifted token can move one of those derived colors.
Where theme settings are persisted
Theme-related settings are persisted by Settings to global config YAML:
- path:
<agentDir>/config.yml - default agent dir:
~/.omp/agent - effective default file:
~/.omp/agent/config.yml
Persisted keys:
theme.darktheme.lightsymbolPresetcolorBlindMode
Legacy migration exists: a flat custom theme: "name" is migrated to nested theme.dark or theme.light based on luminance detection. Flat "dark"/"light" values are removed so current defaults apply.
Creating a custom theme (practical)
- Create file in custom themes dir, e.g.
~/.omp/agent/themes/my-theme.json. - Include
name, optionalvars, and all requiredcolorstokens. - Optionally include
symbolsandexport. - Select the theme in Settings (
Appearance -> Dark ThemeorAppearance -> Light Theme) depending on which auto slot you want.
Minimal skeleton:
{
"name": "my-theme",
"vars": {
"accent": "#7aa2f7",
"muted": 244
},
"colors": {
"accent": "accent",
"border": "#4c566a",
"borderAccent": "accent",
"borderMuted": "muted",
"success": "#9ece6a",
"error": "#f7768e",
"warning": "#e0af68",
"muted": "muted",
"dim": 240,
"text": "",
"thinkingText": "muted",
"selectedBg": "#2a2f45",
"userMessageBg": "#1f2335",
"userMessageText": "",
"customMessageBg": "#24283b",
"customMessageText": "",
"customMessageLabel": "accent",
"toolPendingBg": "#1f2335",
"toolSuccessBg": "#1f2d2a",
"toolErrorBg": "#2d1f2a",
"toolTitle": "",
"toolOutput": "muted",
"mdHeading": "accent",
"mdLink": "accent",
"mdLinkUrl": "muted",
"mdCode": "#c0caf5",
"mdCodeBlock": "#c0caf5",
"mdCodeBlockBorder": "muted",
"mdQuote": "muted",
"mdQuoteBorder": "muted",
"mdHr": "muted",
"mdListBullet": "accent",
"toolDiffAdded": "#9ece6a",
"toolDiffRemoved": "#f7768e",
"toolDiffContext": "muted",
"syntaxComment": "#565f89",
"syntaxKeyword": "#bb9af7",
"syntaxFunction": "#7aa2f7",
"syntaxVariable": "#c0caf5",
"syntaxString": "#9ece6a",
"syntaxNumber": "#ff9e64",
"syntaxType": "#2ac3de",
"syntaxOperator": "#89ddff",
"syntaxPunctuation": "#9aa5ce",
"thinkingOff": 240,
"thinkingMinimal": 244,
"thinkingLow": "#7aa2f7",
"thinkingMedium": "#2ac3de",
"thinkingHigh": "#bb9af7",
"thinkingXhigh": "#f7768e",
"thinkingMax": "#ff007c",
"bashMode": "#2ac3de",
"pythonMode": "#bb9af7",
"btwMode": "#7aa2f7",
"statusLineBg": "#16161e",
"statusLineSep": 240,
"statusLineModel": "#bb9af7",
"statusLinePath": "#7aa2f7",
"statusLineGitClean": "#9ece6a",
"statusLineGitDirty": "#e0af68",
"statusLineContext": "#2ac3de",
"statusLineSpend": "#7dcfff",
"statusLineStaged": "#9ece6a",
"statusLineDirty": "#e0af68",
"statusLineUntracked": "#f7768e",
"statusLineOutput": "#c0caf5",
"statusLineCost": "#ff9e64",
"statusLineSubagents": "#bb9af7"
}
}
Testing custom themes
Use this workflow:
- Start interactive mode (watcher enabled from startup).
- Open settings and preview theme values (live
previewTheme). - For custom theme files, edit the JSON while running and confirm auto-reload on save.
- Exercise critical surfaces:
- markdown rendering
- tool blocks (pending/success/error)
- diff rendering (added/removed/context)
- status line readability
- thinking level border changes
- bash/python mode border colors
- Validate both symbol presets if your theme depends on glyph width/appearance.
Real constraints and caveats
- All
colorstokens are required for custom themes except optionalthinkingMax(falls back tothinkingXhigh),assistantMessageText(unset keeps the terminal default foreground),mdExtensionLink(unset blendsmdLinkwithtext) andsubagent1–subagent6(unset lets omp pick agent colors from the theme). exportandsymbolsare optional.$schemain theme JSON is informational; custom-theme runtime validation is enforced by@oh-my-pi/omptypeinpackages/tui/src/theme/schema-validation.ts.setThemefailure falls back todark;previewThemefailure does not replace current theme.- File watcher reload errors or temporary missing files keep the current loaded theme until a successful reload or explicit theme switch.