@oh-my-pi/pi-coding-agent 1.337.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1228 -0
- package/README.md +1041 -0
- package/docs/compaction.md +403 -0
- package/docs/custom-tools.md +541 -0
- package/docs/extension-loading.md +1004 -0
- package/docs/hooks.md +867 -0
- package/docs/rpc.md +1040 -0
- package/docs/sdk.md +994 -0
- package/docs/session-tree-plan.md +441 -0
- package/docs/session.md +240 -0
- package/docs/skills.md +290 -0
- package/docs/theme.md +637 -0
- package/docs/tree.md +197 -0
- package/docs/tui.md +341 -0
- package/examples/README.md +21 -0
- package/examples/custom-tools/README.md +124 -0
- package/examples/custom-tools/hello/index.ts +20 -0
- package/examples/custom-tools/question/index.ts +84 -0
- package/examples/custom-tools/subagent/README.md +172 -0
- package/examples/custom-tools/subagent/agents/planner.md +37 -0
- package/examples/custom-tools/subagent/agents/reviewer.md +35 -0
- package/examples/custom-tools/subagent/agents/scout.md +50 -0
- package/examples/custom-tools/subagent/agents/worker.md +24 -0
- package/examples/custom-tools/subagent/agents.ts +156 -0
- package/examples/custom-tools/subagent/commands/implement-and-review.md +10 -0
- package/examples/custom-tools/subagent/commands/implement.md +10 -0
- package/examples/custom-tools/subagent/commands/scout-and-plan.md +9 -0
- package/examples/custom-tools/subagent/index.ts +1002 -0
- package/examples/custom-tools/todo/index.ts +212 -0
- package/examples/hooks/README.md +56 -0
- package/examples/hooks/auto-commit-on-exit.ts +49 -0
- package/examples/hooks/confirm-destructive.ts +59 -0
- package/examples/hooks/custom-compaction.ts +116 -0
- package/examples/hooks/dirty-repo-guard.ts +52 -0
- package/examples/hooks/file-trigger.ts +41 -0
- package/examples/hooks/git-checkpoint.ts +53 -0
- package/examples/hooks/handoff.ts +150 -0
- package/examples/hooks/permission-gate.ts +34 -0
- package/examples/hooks/protected-paths.ts +30 -0
- package/examples/hooks/qna.ts +119 -0
- package/examples/hooks/snake.ts +343 -0
- package/examples/hooks/status-line.ts +40 -0
- package/examples/sdk/01-minimal.ts +22 -0
- package/examples/sdk/02-custom-model.ts +49 -0
- package/examples/sdk/03-custom-prompt.ts +44 -0
- package/examples/sdk/04-skills.ts +44 -0
- package/examples/sdk/05-tools.ts +90 -0
- package/examples/sdk/06-hooks.ts +61 -0
- package/examples/sdk/07-context-files.ts +36 -0
- package/examples/sdk/08-slash-commands.ts +42 -0
- package/examples/sdk/09-api-keys-and-oauth.ts +55 -0
- package/examples/sdk/10-settings.ts +38 -0
- package/examples/sdk/11-sessions.ts +48 -0
- package/examples/sdk/12-full-control.ts +95 -0
- package/examples/sdk/README.md +154 -0
- package/package.json +81 -0
- package/src/cli/args.ts +246 -0
- package/src/cli/file-processor.ts +72 -0
- package/src/cli/list-models.ts +104 -0
- package/src/cli/plugin-cli.ts +650 -0
- package/src/cli/session-picker.ts +41 -0
- package/src/cli.ts +10 -0
- package/src/commands/init.md +20 -0
- package/src/config.ts +159 -0
- package/src/core/agent-session.ts +1900 -0
- package/src/core/auth-storage.ts +236 -0
- package/src/core/bash-executor.ts +196 -0
- package/src/core/compaction/branch-summarization.ts +343 -0
- package/src/core/compaction/compaction.ts +742 -0
- package/src/core/compaction/index.ts +7 -0
- package/src/core/compaction/utils.ts +154 -0
- package/src/core/custom-tools/index.ts +21 -0
- package/src/core/custom-tools/loader.ts +248 -0
- package/src/core/custom-tools/types.ts +169 -0
- package/src/core/custom-tools/wrapper.ts +28 -0
- package/src/core/exec.ts +129 -0
- package/src/core/export-html/index.ts +211 -0
- package/src/core/export-html/template.css +781 -0
- package/src/core/export-html/template.html +54 -0
- package/src/core/export-html/template.js +1185 -0
- package/src/core/export-html/vendor/highlight.min.js +1213 -0
- package/src/core/export-html/vendor/marked.min.js +6 -0
- package/src/core/hooks/index.ts +16 -0
- package/src/core/hooks/loader.ts +312 -0
- package/src/core/hooks/runner.ts +434 -0
- package/src/core/hooks/tool-wrapper.ts +99 -0
- package/src/core/hooks/types.ts +773 -0
- package/src/core/index.ts +52 -0
- package/src/core/mcp/client.ts +158 -0
- package/src/core/mcp/config.ts +154 -0
- package/src/core/mcp/index.ts +45 -0
- package/src/core/mcp/loader.ts +68 -0
- package/src/core/mcp/manager.ts +181 -0
- package/src/core/mcp/tool-bridge.ts +148 -0
- package/src/core/mcp/transports/http.ts +316 -0
- package/src/core/mcp/transports/index.ts +6 -0
- package/src/core/mcp/transports/stdio.ts +252 -0
- package/src/core/mcp/types.ts +220 -0
- package/src/core/messages.ts +189 -0
- package/src/core/model-registry.ts +317 -0
- package/src/core/model-resolver.ts +393 -0
- package/src/core/plugins/doctor.ts +59 -0
- package/src/core/plugins/index.ts +38 -0
- package/src/core/plugins/installer.ts +189 -0
- package/src/core/plugins/loader.ts +338 -0
- package/src/core/plugins/manager.ts +672 -0
- package/src/core/plugins/parser.ts +105 -0
- package/src/core/plugins/paths.ts +32 -0
- package/src/core/plugins/types.ts +190 -0
- package/src/core/sdk.ts +760 -0
- package/src/core/session-manager.ts +1128 -0
- package/src/core/settings-manager.ts +443 -0
- package/src/core/skills.ts +437 -0
- package/src/core/slash-commands.ts +248 -0
- package/src/core/system-prompt.ts +439 -0
- package/src/core/timings.ts +25 -0
- package/src/core/tools/ask.ts +211 -0
- package/src/core/tools/bash-interceptor.ts +120 -0
- package/src/core/tools/bash.ts +250 -0
- package/src/core/tools/context.ts +32 -0
- package/src/core/tools/edit-diff.ts +475 -0
- package/src/core/tools/edit.ts +208 -0
- package/src/core/tools/exa/company.ts +59 -0
- package/src/core/tools/exa/index.ts +64 -0
- package/src/core/tools/exa/linkedin.ts +59 -0
- package/src/core/tools/exa/logger.ts +56 -0
- package/src/core/tools/exa/mcp-client.ts +368 -0
- package/src/core/tools/exa/render.ts +196 -0
- package/src/core/tools/exa/researcher.ts +90 -0
- package/src/core/tools/exa/search.ts +337 -0
- package/src/core/tools/exa/types.ts +168 -0
- package/src/core/tools/exa/websets.ts +248 -0
- package/src/core/tools/find.ts +261 -0
- package/src/core/tools/grep.ts +555 -0
- package/src/core/tools/index.ts +202 -0
- package/src/core/tools/ls.ts +140 -0
- package/src/core/tools/lsp/client.ts +605 -0
- package/src/core/tools/lsp/config.ts +147 -0
- package/src/core/tools/lsp/edits.ts +101 -0
- package/src/core/tools/lsp/index.ts +804 -0
- package/src/core/tools/lsp/render.ts +447 -0
- package/src/core/tools/lsp/rust-analyzer.ts +145 -0
- package/src/core/tools/lsp/types.ts +463 -0
- package/src/core/tools/lsp/utils.ts +486 -0
- package/src/core/tools/notebook.ts +229 -0
- package/src/core/tools/path-utils.ts +61 -0
- package/src/core/tools/read.ts +240 -0
- package/src/core/tools/renderers.ts +540 -0
- package/src/core/tools/task/agents.ts +153 -0
- package/src/core/tools/task/artifacts.ts +114 -0
- package/src/core/tools/task/bundled-agents/browser.md +71 -0
- package/src/core/tools/task/bundled-agents/explore.md +82 -0
- package/src/core/tools/task/bundled-agents/plan.md +54 -0
- package/src/core/tools/task/bundled-agents/reviewer.md +59 -0
- package/src/core/tools/task/bundled-agents/task.md +53 -0
- package/src/core/tools/task/bundled-commands/architect-plan.md +10 -0
- package/src/core/tools/task/bundled-commands/implement-with-critic.md +11 -0
- package/src/core/tools/task/bundled-commands/implement.md +11 -0
- package/src/core/tools/task/commands.ts +213 -0
- package/src/core/tools/task/discovery.ts +208 -0
- package/src/core/tools/task/executor.ts +367 -0
- package/src/core/tools/task/index.ts +388 -0
- package/src/core/tools/task/model-resolver.ts +115 -0
- package/src/core/tools/task/parallel.ts +38 -0
- package/src/core/tools/task/render.ts +232 -0
- package/src/core/tools/task/types.ts +99 -0
- package/src/core/tools/truncate.ts +265 -0
- package/src/core/tools/web-fetch.ts +2370 -0
- package/src/core/tools/web-search/auth.ts +193 -0
- package/src/core/tools/web-search/index.ts +537 -0
- package/src/core/tools/web-search/providers/anthropic.ts +198 -0
- package/src/core/tools/web-search/providers/exa.ts +302 -0
- package/src/core/tools/web-search/providers/perplexity.ts +195 -0
- package/src/core/tools/web-search/render.ts +182 -0
- package/src/core/tools/web-search/types.ts +180 -0
- package/src/core/tools/write.ts +99 -0
- package/src/index.ts +176 -0
- package/src/main.ts +464 -0
- package/src/migrations.ts +135 -0
- package/src/modes/index.ts +43 -0
- package/src/modes/interactive/components/armin.ts +382 -0
- package/src/modes/interactive/components/assistant-message.ts +86 -0
- package/src/modes/interactive/components/bash-execution.ts +196 -0
- package/src/modes/interactive/components/bordered-loader.ts +41 -0
- package/src/modes/interactive/components/branch-summary-message.ts +42 -0
- package/src/modes/interactive/components/compaction-summary-message.ts +45 -0
- package/src/modes/interactive/components/custom-editor.ts +122 -0
- package/src/modes/interactive/components/diff.ts +147 -0
- package/src/modes/interactive/components/dynamic-border.ts +25 -0
- package/src/modes/interactive/components/footer.ts +381 -0
- package/src/modes/interactive/components/hook-editor.ts +117 -0
- package/src/modes/interactive/components/hook-input.ts +64 -0
- package/src/modes/interactive/components/hook-message.ts +96 -0
- package/src/modes/interactive/components/hook-selector.ts +91 -0
- package/src/modes/interactive/components/model-selector.ts +247 -0
- package/src/modes/interactive/components/oauth-selector.ts +120 -0
- package/src/modes/interactive/components/plugin-settings.ts +479 -0
- package/src/modes/interactive/components/queue-mode-selector.ts +56 -0
- package/src/modes/interactive/components/session-selector.ts +204 -0
- package/src/modes/interactive/components/settings-selector.ts +453 -0
- package/src/modes/interactive/components/show-images-selector.ts +45 -0
- package/src/modes/interactive/components/theme-selector.ts +62 -0
- package/src/modes/interactive/components/thinking-selector.ts +64 -0
- package/src/modes/interactive/components/tool-execution.ts +675 -0
- package/src/modes/interactive/components/tree-selector.ts +866 -0
- package/src/modes/interactive/components/user-message-selector.ts +159 -0
- package/src/modes/interactive/components/user-message.ts +18 -0
- package/src/modes/interactive/components/visual-truncate.ts +50 -0
- package/src/modes/interactive/components/welcome.ts +183 -0
- package/src/modes/interactive/interactive-mode.ts +2516 -0
- package/src/modes/interactive/theme/dark.json +101 -0
- package/src/modes/interactive/theme/light.json +98 -0
- package/src/modes/interactive/theme/theme-schema.json +308 -0
- package/src/modes/interactive/theme/theme.ts +998 -0
- package/src/modes/print-mode.ts +128 -0
- package/src/modes/rpc/rpc-client.ts +527 -0
- package/src/modes/rpc/rpc-mode.ts +483 -0
- package/src/modes/rpc/rpc-types.ts +203 -0
- package/src/utils/changelog.ts +99 -0
- package/src/utils/clipboard.ts +265 -0
- package/src/utils/fuzzy.ts +108 -0
- package/src/utils/mime.ts +30 -0
- package/src/utils/shell.ts +276 -0
- package/src/utils/tools-manager.ts +274 -0
package/docs/theme.md
ADDED
|
@@ -0,0 +1,637 @@
|
|
|
1
|
+
> pi can create themes. Ask it to build one for your use case.
|
|
2
|
+
|
|
3
|
+
# Pi Coding Agent Themes
|
|
4
|
+
|
|
5
|
+
Themes allow you to customize the colors used throughout the coding agent TUI.
|
|
6
|
+
|
|
7
|
+
## Color Tokens
|
|
8
|
+
|
|
9
|
+
Every theme must define all color tokens. There are no optional colors.
|
|
10
|
+
|
|
11
|
+
### Core UI (10 colors)
|
|
12
|
+
|
|
13
|
+
| Token | Purpose | Examples |
|
|
14
|
+
| -------------- | --------------------- | ------------------------------------ |
|
|
15
|
+
| `accent` | Primary accent color | Logo, selected items, cursor (›) |
|
|
16
|
+
| `border` | Normal borders | Selector borders, horizontal lines |
|
|
17
|
+
| `borderAccent` | Highlighted borders | Changelog borders, special panels |
|
|
18
|
+
| `borderMuted` | Subtle borders | Editor borders, secondary separators |
|
|
19
|
+
| `success` | Success states | Success messages, diff additions |
|
|
20
|
+
| `error` | Error states | Error messages, diff deletions |
|
|
21
|
+
| `warning` | Warning states | Warning messages |
|
|
22
|
+
| `muted` | Secondary/dimmed text | Metadata, descriptions, output |
|
|
23
|
+
| `dim` | Very dimmed text | Less important info, placeholders |
|
|
24
|
+
| `text` | Default text color | Main content (usually `""`) |
|
|
25
|
+
| `thinkingText` | Thinking block text | Assistant reasoning traces |
|
|
26
|
+
|
|
27
|
+
### Backgrounds & Content Text (11 colors)
|
|
28
|
+
|
|
29
|
+
| Token | Purpose |
|
|
30
|
+
| -------------------- | ----------------------------------------------------------------- |
|
|
31
|
+
| `selectedBg` | Selected/active line background (e.g., tree selector) |
|
|
32
|
+
| `userMessageBg` | User message background |
|
|
33
|
+
| `userMessageText` | User message text color |
|
|
34
|
+
| `customMessageBg` | Hook custom message background |
|
|
35
|
+
| `customMessageText` | Hook custom message text color |
|
|
36
|
+
| `customMessageLabel` | Hook custom message label/type text |
|
|
37
|
+
| `toolPendingBg` | Tool execution box (pending state) |
|
|
38
|
+
| `toolSuccessBg` | Tool execution box (success state) |
|
|
39
|
+
| `toolErrorBg` | Tool execution box (error state) |
|
|
40
|
+
| `toolTitle` | Tool execution title/heading (e.g., `$ command`, `read file.txt`) |
|
|
41
|
+
| `toolOutput` | Tool execution output text |
|
|
42
|
+
|
|
43
|
+
### Markdown (10 colors)
|
|
44
|
+
|
|
45
|
+
| Token | Purpose |
|
|
46
|
+
| ------------------- | ----------------------------- |
|
|
47
|
+
| `mdHeading` | Heading text (`#`, `##`, etc) |
|
|
48
|
+
| `mdLink` | Link text |
|
|
49
|
+
| `mdLinkUrl` | Link URL (in parentheses) |
|
|
50
|
+
| `mdCode` | Inline code (backticks) |
|
|
51
|
+
| `mdCodeBlock` | Code block content |
|
|
52
|
+
| `mdCodeBlockBorder` | Code block fences (```) |
|
|
53
|
+
| `mdQuote` | Blockquote text |
|
|
54
|
+
| `mdQuoteBorder` | Blockquote border (`│`) |
|
|
55
|
+
| `mdHr` | Horizontal rule (`---`) |
|
|
56
|
+
| `mdListBullet` | List bullets/numbers |
|
|
57
|
+
|
|
58
|
+
### Tool Diffs (3 colors)
|
|
59
|
+
|
|
60
|
+
| Token | Purpose |
|
|
61
|
+
| ----------------- | --------------------------- |
|
|
62
|
+
| `toolDiffAdded` | Added lines in tool diffs |
|
|
63
|
+
| `toolDiffRemoved` | Removed lines in tool diffs |
|
|
64
|
+
| `toolDiffContext` | Context lines in tool diffs |
|
|
65
|
+
|
|
66
|
+
Note: Diff colors are specific to tool execution boxes and must work with tool background colors.
|
|
67
|
+
|
|
68
|
+
### Syntax Highlighting (9 colors)
|
|
69
|
+
|
|
70
|
+
Future-proofing for syntax highlighting support:
|
|
71
|
+
|
|
72
|
+
| Token | Purpose |
|
|
73
|
+
| ------------------- | -------------------------------- |
|
|
74
|
+
| `syntaxComment` | Comments |
|
|
75
|
+
| `syntaxKeyword` | Keywords (`if`, `function`, etc) |
|
|
76
|
+
| `syntaxFunction` | Function names |
|
|
77
|
+
| `syntaxVariable` | Variable names |
|
|
78
|
+
| `syntaxString` | String literals |
|
|
79
|
+
| `syntaxNumber` | Number literals |
|
|
80
|
+
| `syntaxType` | Type names |
|
|
81
|
+
| `syntaxOperator` | Operators (`+`, `-`, etc) |
|
|
82
|
+
| `syntaxPunctuation` | Punctuation (`;`, `,`, etc) |
|
|
83
|
+
|
|
84
|
+
### Thinking Level Borders (6 colors)
|
|
85
|
+
|
|
86
|
+
Editor border colors that indicate the current thinking/reasoning level:
|
|
87
|
+
|
|
88
|
+
| Token | Purpose |
|
|
89
|
+
| ----------------- | ----------------------------------------------------------------- |
|
|
90
|
+
| `thinkingOff` | Border when thinking is off (most subtle) |
|
|
91
|
+
| `thinkingMinimal` | Border for minimal thinking |
|
|
92
|
+
| `thinkingLow` | Border for low thinking |
|
|
93
|
+
| `thinkingMedium` | Border for medium thinking |
|
|
94
|
+
| `thinkingHigh` | Border for high thinking |
|
|
95
|
+
| `thinkingXhigh` | Border for xhigh thinking (most prominent, OpenAI codex-max only) |
|
|
96
|
+
|
|
97
|
+
These create a visual hierarchy: off → minimal → low → medium → high → xhigh
|
|
98
|
+
|
|
99
|
+
### Bash Mode (1 color)
|
|
100
|
+
|
|
101
|
+
| Token | Purpose |
|
|
102
|
+
| ---------- | ------------------------------------------------ |
|
|
103
|
+
| `bashMode` | Editor border color when in bash mode (! prefix) |
|
|
104
|
+
|
|
105
|
+
**Total: 50 color tokens** (all required)
|
|
106
|
+
|
|
107
|
+
### HTML Export Colors (optional)
|
|
108
|
+
|
|
109
|
+
The `export` section is optional and controls colors used when exporting sessions to HTML via `/export`. If not specified, these colors are automatically derived from `userMessageBg` based on luminance detection.
|
|
110
|
+
|
|
111
|
+
| Token | Purpose |
|
|
112
|
+
| -------- | ------------------------------------------------------------- |
|
|
113
|
+
| `pageBg` | Page background color |
|
|
114
|
+
| `cardBg` | Card/container background (headers, stats boxes) |
|
|
115
|
+
| `infoBg` | Info sections background (system prompt, notices, compaction) |
|
|
116
|
+
|
|
117
|
+
Example:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"export": {
|
|
122
|
+
"pageBg": "#18181e",
|
|
123
|
+
"cardBg": "#1e1e24",
|
|
124
|
+
"infoBg": "#3c3728"
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Theme Format
|
|
130
|
+
|
|
131
|
+
Themes are defined in JSON files with the following structure:
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"$schema": "https://raw.githubusercontent.com/badlogic/pi-mono/main/packages/coding-agent/theme-schema.json",
|
|
136
|
+
"name": "my-theme",
|
|
137
|
+
"vars": {
|
|
138
|
+
"blue": "#0066cc",
|
|
139
|
+
"gray": 242,
|
|
140
|
+
"brightCyan": 51
|
|
141
|
+
},
|
|
142
|
+
"colors": {
|
|
143
|
+
"accent": "blue",
|
|
144
|
+
"muted": "gray",
|
|
145
|
+
"thinkingText": "gray",
|
|
146
|
+
"text": "",
|
|
147
|
+
...
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Color Values
|
|
153
|
+
|
|
154
|
+
Four formats are supported:
|
|
155
|
+
|
|
156
|
+
1. **Hex colors**: `"#ff0000"` (6-digit hex RGB)
|
|
157
|
+
2. **256-color palette**: `39` (number 0-255, xterm 256-color palette)
|
|
158
|
+
3. **Color references**: `"blue"` (must be defined in `vars`)
|
|
159
|
+
4. **Terminal default**: `""` (empty string, uses terminal's default color)
|
|
160
|
+
|
|
161
|
+
### The `vars` Section
|
|
162
|
+
|
|
163
|
+
The optional `vars` section allows you to define reusable colors:
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"vars": {
|
|
168
|
+
"nord0": "#2E3440",
|
|
169
|
+
"nord1": "#3B4252",
|
|
170
|
+
"nord8": "#88C0D0",
|
|
171
|
+
"brightBlue": 39
|
|
172
|
+
},
|
|
173
|
+
"colors": {
|
|
174
|
+
"accent": "nord8",
|
|
175
|
+
"muted": "nord1",
|
|
176
|
+
"mdLink": "brightBlue"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Benefits:
|
|
182
|
+
|
|
183
|
+
- Reuse colors across multiple tokens
|
|
184
|
+
- Easier to maintain theme consistency
|
|
185
|
+
- Can reference standard color palettes
|
|
186
|
+
|
|
187
|
+
Variables can be hex colors (`"#ff0000"`), 256-color indices (`42`), or references to other variables.
|
|
188
|
+
|
|
189
|
+
### Terminal Default (empty string)
|
|
190
|
+
|
|
191
|
+
Use `""` (empty string) to inherit the terminal's default foreground/background color:
|
|
192
|
+
|
|
193
|
+
```json
|
|
194
|
+
{
|
|
195
|
+
"colors": {
|
|
196
|
+
"text": "" // Uses terminal's default text color
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
This is useful for:
|
|
202
|
+
|
|
203
|
+
- Main text color (adapts to user's terminal theme)
|
|
204
|
+
- Creating themes that blend with terminal appearance
|
|
205
|
+
|
|
206
|
+
## Built-in Themes
|
|
207
|
+
|
|
208
|
+
Pi comes with two built-in themes:
|
|
209
|
+
|
|
210
|
+
### `dark` (default)
|
|
211
|
+
|
|
212
|
+
Optimized for dark terminal backgrounds with bright, saturated colors.
|
|
213
|
+
|
|
214
|
+
### `light`
|
|
215
|
+
|
|
216
|
+
Optimized for light terminal backgrounds with darker, muted colors.
|
|
217
|
+
|
|
218
|
+
## Selecting a Theme
|
|
219
|
+
|
|
220
|
+
Themes are configured in the settings (accessible via `/settings`):
|
|
221
|
+
|
|
222
|
+
```json
|
|
223
|
+
{
|
|
224
|
+
"theme": "dark"
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Or use the `/theme` command interactively.
|
|
229
|
+
|
|
230
|
+
On first run, Pi detects your terminal's background and sets a sensible default (`dark` or `light`).
|
|
231
|
+
|
|
232
|
+
## Custom Themes
|
|
233
|
+
|
|
234
|
+
### Theme Locations
|
|
235
|
+
|
|
236
|
+
Custom themes are loaded from `~/.pi/agent/themes/*.json`.
|
|
237
|
+
|
|
238
|
+
### Creating a Custom Theme
|
|
239
|
+
|
|
240
|
+
1. **Create theme directory:**
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
mkdir -p ~/.pi/agent/themes
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
2. **Create theme file:**
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
vim ~/.pi/agent/themes/my-theme.json
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
3. **Define all colors:**
|
|
253
|
+
|
|
254
|
+
```json
|
|
255
|
+
{
|
|
256
|
+
"$schema": "https://raw.githubusercontent.com/badlogic/pi-mono/main/packages/coding-agent/theme-schema.json",
|
|
257
|
+
"name": "my-theme",
|
|
258
|
+
"vars": {
|
|
259
|
+
"primary": "#00aaff",
|
|
260
|
+
"secondary": 242,
|
|
261
|
+
"brightGreen": 46
|
|
262
|
+
},
|
|
263
|
+
"colors": {
|
|
264
|
+
"accent": "primary",
|
|
265
|
+
"border": "primary",
|
|
266
|
+
"borderAccent": "#00ffff",
|
|
267
|
+
"borderMuted": "secondary",
|
|
268
|
+
"success": "brightGreen",
|
|
269
|
+
"error": "#ff0000",
|
|
270
|
+
"warning": "#ffff00",
|
|
271
|
+
"muted": "secondary",
|
|
272
|
+
"text": "",
|
|
273
|
+
|
|
274
|
+
"userMessageBg": "#2d2d30",
|
|
275
|
+
"userMessageText": "",
|
|
276
|
+
"toolPendingBg": "#1e1e2e",
|
|
277
|
+
"toolSuccessBg": "#1e2e1e",
|
|
278
|
+
"toolErrorBg": "#2e1e1e",
|
|
279
|
+
"toolText": "",
|
|
280
|
+
|
|
281
|
+
"mdHeading": "#ffaa00",
|
|
282
|
+
"mdLink": "primary",
|
|
283
|
+
"mdCode": "#00ffff",
|
|
284
|
+
"mdCodeBlock": "#00ff00",
|
|
285
|
+
"mdCodeBlockBorder": "secondary",
|
|
286
|
+
"mdQuote": "secondary",
|
|
287
|
+
"mdQuoteBorder": "secondary",
|
|
288
|
+
"mdHr": "secondary",
|
|
289
|
+
"mdListBullet": "#00ffff",
|
|
290
|
+
|
|
291
|
+
"toolDiffAdded": "#00ff00",
|
|
292
|
+
"toolDiffRemoved": "#ff0000",
|
|
293
|
+
"toolDiffContext": "secondary",
|
|
294
|
+
|
|
295
|
+
"syntaxComment": "secondary",
|
|
296
|
+
"syntaxKeyword": "primary",
|
|
297
|
+
"syntaxFunction": "#00aaff",
|
|
298
|
+
"syntaxVariable": "#ffaa00",
|
|
299
|
+
"syntaxString": "#00ff00",
|
|
300
|
+
"syntaxNumber": "#ff00ff",
|
|
301
|
+
"syntaxType": "#00aaff",
|
|
302
|
+
"syntaxOperator": "primary",
|
|
303
|
+
"syntaxPunctuation": "secondary",
|
|
304
|
+
|
|
305
|
+
"thinkingOff": "secondary",
|
|
306
|
+
"thinkingMinimal": "primary",
|
|
307
|
+
"thinkingLow": "#00aaff",
|
|
308
|
+
"thinkingMedium": "#00ffff",
|
|
309
|
+
"thinkingHigh": "#ff00ff"
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
4. **Select your theme:**
|
|
315
|
+
- Use `/settings` command and set `"theme": "my-theme"`
|
|
316
|
+
- Or use `/theme` command interactively
|
|
317
|
+
|
|
318
|
+
## Tips
|
|
319
|
+
|
|
320
|
+
### Light vs Dark Themes
|
|
321
|
+
|
|
322
|
+
**For dark terminals:**
|
|
323
|
+
|
|
324
|
+
- Use bright, saturated colors
|
|
325
|
+
- Higher contrast
|
|
326
|
+
- Example: `#00ffff` (bright cyan)
|
|
327
|
+
|
|
328
|
+
**For light terminals:**
|
|
329
|
+
|
|
330
|
+
- Use darker, muted colors
|
|
331
|
+
- Lower contrast to avoid eye strain
|
|
332
|
+
- Example: `#008888` (dark cyan)
|
|
333
|
+
|
|
334
|
+
### Color Harmony
|
|
335
|
+
|
|
336
|
+
- Start with a base palette (e.g., Nord, Gruvbox, Tokyo Night)
|
|
337
|
+
- Define your palette in `defs`
|
|
338
|
+
- Reference colors consistently
|
|
339
|
+
|
|
340
|
+
### Testing
|
|
341
|
+
|
|
342
|
+
Test your theme with:
|
|
343
|
+
|
|
344
|
+
- Different message types (user, assistant, errors)
|
|
345
|
+
- Tool executions (success and error states)
|
|
346
|
+
- Markdown content (headings, code, lists, etc)
|
|
347
|
+
- Long text that wraps
|
|
348
|
+
|
|
349
|
+
## Color Format Reference
|
|
350
|
+
|
|
351
|
+
### Hex Colors
|
|
352
|
+
|
|
353
|
+
Standard 6-digit hex format:
|
|
354
|
+
|
|
355
|
+
- `"#ff0000"` - Red
|
|
356
|
+
- `"#00ff00"` - Green
|
|
357
|
+
- `"#0000ff"` - Blue
|
|
358
|
+
- `"#808080"` - Gray
|
|
359
|
+
- `"#ffffff"` - White
|
|
360
|
+
- `"#000000"` - Black
|
|
361
|
+
|
|
362
|
+
RGB values: `#RRGGBB` where each component is `00-ff` (0-255)
|
|
363
|
+
|
|
364
|
+
### 256-Color Palette
|
|
365
|
+
|
|
366
|
+
Use numeric indices (0-255) to reference the xterm 256-color palette:
|
|
367
|
+
|
|
368
|
+
**Colors 0-15:** Basic ANSI colors (terminal-dependent, may be themed)
|
|
369
|
+
|
|
370
|
+
- `0` - Black
|
|
371
|
+
- `1` - Red
|
|
372
|
+
- `2` - Green
|
|
373
|
+
- `3` - Yellow
|
|
374
|
+
- `4` - Blue
|
|
375
|
+
- `5` - Magenta
|
|
376
|
+
- `6` - Cyan
|
|
377
|
+
- `7` - White
|
|
378
|
+
- `8-15` - Bright variants
|
|
379
|
+
|
|
380
|
+
**Colors 16-231:** 6×6×6 RGB cube (standardized)
|
|
381
|
+
|
|
382
|
+
- Formula: `16 + 36×R + 6×G + B` where R, G, B are 0-5
|
|
383
|
+
- Example: `39` = bright cyan, `196` = bright red
|
|
384
|
+
|
|
385
|
+
**Colors 232-255:** Grayscale ramp (standardized)
|
|
386
|
+
|
|
387
|
+
- `232` - Darkest gray
|
|
388
|
+
- `255` - Near white
|
|
389
|
+
|
|
390
|
+
Example usage:
|
|
391
|
+
|
|
392
|
+
```json
|
|
393
|
+
{
|
|
394
|
+
"vars": {
|
|
395
|
+
"gray": 242,
|
|
396
|
+
"brightCyan": 51,
|
|
397
|
+
"darkBlue": 18
|
|
398
|
+
},
|
|
399
|
+
"colors": {
|
|
400
|
+
"muted": "gray",
|
|
401
|
+
"accent": "brightCyan"
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
**Benefits:**
|
|
407
|
+
|
|
408
|
+
- Works everywhere (`TERM=xterm-256color`)
|
|
409
|
+
- No truecolor detection needed
|
|
410
|
+
- Standardized RGB cube (16-231) looks the same on all terminals
|
|
411
|
+
|
|
412
|
+
### Terminal Compatibility
|
|
413
|
+
|
|
414
|
+
Pi uses 24-bit RGB colors (`\x1b[38;2;R;G;Bm`). Most modern terminals support this:
|
|
415
|
+
|
|
416
|
+
- ✅ iTerm2, Alacritty, Kitty, WezTerm
|
|
417
|
+
- ✅ Windows Terminal
|
|
418
|
+
- ✅ VS Code integrated terminal
|
|
419
|
+
- ✅ Modern GNOME Terminal, Konsole
|
|
420
|
+
|
|
421
|
+
For older terminals with only 256-color support, Pi automatically falls back to the nearest 256-color approximation.
|
|
422
|
+
|
|
423
|
+
To check if your terminal supports truecolor:
|
|
424
|
+
|
|
425
|
+
```bash
|
|
426
|
+
echo $COLORTERM # Should output "truecolor" or "24bit"
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
## Example Themes
|
|
430
|
+
|
|
431
|
+
See the built-in themes for complete examples:
|
|
432
|
+
|
|
433
|
+
- [Dark theme](../src/themes/dark.json)
|
|
434
|
+
- [Light theme](../src/themes/light.json)
|
|
435
|
+
|
|
436
|
+
## Schema Validation
|
|
437
|
+
|
|
438
|
+
Themes are validated on load using [TypeBox](https://github.com/sinclairzx81/typebox) + [Ajv](https://ajv.js.org/).
|
|
439
|
+
|
|
440
|
+
Invalid themes will show an error with details about what's wrong:
|
|
441
|
+
|
|
442
|
+
```
|
|
443
|
+
Error loading theme 'my-theme':
|
|
444
|
+
- colors.accent: must be string or number
|
|
445
|
+
- colors.mdHeading: required property missing
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
For editor support, the JSON schema is available at:
|
|
449
|
+
|
|
450
|
+
```
|
|
451
|
+
https://raw.githubusercontent.com/badlogic/pi-mono/main/packages/coding-agent/theme-schema.json
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
Add to your theme file for auto-completion and validation:
|
|
455
|
+
|
|
456
|
+
```json
|
|
457
|
+
{
|
|
458
|
+
"$schema": "https://raw.githubusercontent.com/badlogic/pi-mono/main/packages/coding-agent/theme-schema.json",
|
|
459
|
+
...
|
|
460
|
+
}
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
## Implementation
|
|
464
|
+
|
|
465
|
+
### Theme Class
|
|
466
|
+
|
|
467
|
+
Themes are loaded and converted to a `Theme` class that provides type-safe color methods:
|
|
468
|
+
|
|
469
|
+
```typescript
|
|
470
|
+
class Theme {
|
|
471
|
+
// Apply foreground color
|
|
472
|
+
fg(color: ThemeColor, text: string): string;
|
|
473
|
+
|
|
474
|
+
// Apply background color
|
|
475
|
+
bg(color: ThemeBg, text: string): string;
|
|
476
|
+
|
|
477
|
+
// Text attributes (preserve current colors)
|
|
478
|
+
bold(text: string): string;
|
|
479
|
+
italic(text: string): string;
|
|
480
|
+
underline(text: string): string;
|
|
481
|
+
}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### Global Theme Instance
|
|
485
|
+
|
|
486
|
+
The active theme is available as a global singleton in `coding-agent`:
|
|
487
|
+
|
|
488
|
+
```typescript
|
|
489
|
+
// theme.ts
|
|
490
|
+
export let theme: Theme;
|
|
491
|
+
|
|
492
|
+
export function setTheme(name: string) {
|
|
493
|
+
theme = loadTheme(name);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Usage throughout coding-agent
|
|
497
|
+
import { theme } from "./theme.js";
|
|
498
|
+
|
|
499
|
+
theme.fg("accent", "Selected");
|
|
500
|
+
theme.bg("userMessageBg", content);
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
### TUI Component Theming
|
|
504
|
+
|
|
505
|
+
TUI components (like `Markdown`, `SelectList`, `Editor`) are in the `@oh-my-pi/pi-tui` package and don't have direct access to the theme. Instead, they define interfaces for the colors they need:
|
|
506
|
+
|
|
507
|
+
```typescript
|
|
508
|
+
// In @oh-my-pi/pi-tui
|
|
509
|
+
export interface MarkdownTheme {
|
|
510
|
+
heading: (text: string) => string;
|
|
511
|
+
link: (text: string) => string;
|
|
512
|
+
linkUrl: (text: string) => string;
|
|
513
|
+
code: (text: string) => string;
|
|
514
|
+
codeBlock: (text: string) => string;
|
|
515
|
+
codeBlockBorder: (text: string) => string;
|
|
516
|
+
quote: (text: string) => string;
|
|
517
|
+
quoteBorder: (text: string) => string;
|
|
518
|
+
hr: (text: string) => string;
|
|
519
|
+
listBullet: (text: string) => string;
|
|
520
|
+
bold: (text: string) => string;
|
|
521
|
+
italic: (text: string) => string;
|
|
522
|
+
strikethrough: (text: string) => string;
|
|
523
|
+
underline: (text: string) => string;
|
|
524
|
+
}
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
The `coding-agent` provides themed functions when creating components:
|
|
528
|
+
|
|
529
|
+
```typescript
|
|
530
|
+
// In coding-agent
|
|
531
|
+
import { theme } from "./theme.js";
|
|
532
|
+
import { Markdown } from "@oh-my-pi/pi-tui";
|
|
533
|
+
|
|
534
|
+
// Helper to create markdown theme functions
|
|
535
|
+
function getMarkdownTheme(): MarkdownTheme {
|
|
536
|
+
return {
|
|
537
|
+
heading: (text) => theme.fg("mdHeading", text),
|
|
538
|
+
link: (text) => theme.fg("mdLink", text),
|
|
539
|
+
linkUrl: (text) => theme.fg("mdLinkUrl", text),
|
|
540
|
+
code: (text) => theme.fg("mdCode", text),
|
|
541
|
+
codeBlock: (text) => theme.fg("mdCodeBlock", text),
|
|
542
|
+
codeBlockBorder: (text) => theme.fg("mdCodeBlockBorder", text),
|
|
543
|
+
quote: (text) => theme.fg("mdQuote", text),
|
|
544
|
+
quoteBorder: (text) => theme.fg("mdQuoteBorder", text),
|
|
545
|
+
hr: (text) => theme.fg("mdHr", text),
|
|
546
|
+
listBullet: (text) => theme.fg("mdListBullet", text),
|
|
547
|
+
bold: (text) => theme.bold(text),
|
|
548
|
+
italic: (text) => theme.italic(text),
|
|
549
|
+
underline: (text) => theme.underline(text),
|
|
550
|
+
strikethrough: (text) => chalk.strikethrough(text),
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
// Create markdown with theme
|
|
555
|
+
const md = new Markdown(text, 1, 1, { bgColor: theme.bg("userMessageBg") }, getMarkdownTheme());
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
This approach:
|
|
559
|
+
|
|
560
|
+
- Keeps TUI components theme-agnostic (reusable in other projects)
|
|
561
|
+
- Maintains type safety via interfaces
|
|
562
|
+
- Allows components to have sensible defaults if no theme provided
|
|
563
|
+
- Centralizes theme access in `coding-agent`
|
|
564
|
+
|
|
565
|
+
**Example usage:**
|
|
566
|
+
|
|
567
|
+
```typescript
|
|
568
|
+
const theme = loadTheme("dark");
|
|
569
|
+
|
|
570
|
+
// Apply foreground colors
|
|
571
|
+
theme.fg("accent", "Selected");
|
|
572
|
+
theme.fg("success", "✓ Done");
|
|
573
|
+
theme.fg("error", "Failed");
|
|
574
|
+
|
|
575
|
+
// Apply background colors
|
|
576
|
+
theme.bg("userMessageBg", content);
|
|
577
|
+
theme.bg("toolSuccessBg", output);
|
|
578
|
+
|
|
579
|
+
// Combine styles
|
|
580
|
+
theme.bold(theme.fg("accent", "Title"));
|
|
581
|
+
theme.italic(theme.fg("muted", "metadata"));
|
|
582
|
+
|
|
583
|
+
// Nested foreground + background
|
|
584
|
+
const userMsg = theme.bg("userMessageBg", theme.fg("userMessageText", "Hello"));
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
**Color resolution:**
|
|
588
|
+
|
|
589
|
+
1. **Detect terminal capabilities:**
|
|
590
|
+
|
|
591
|
+
- Check `$COLORTERM` env var (`truecolor` or `24bit` → truecolor support)
|
|
592
|
+
- Check `$TERM` env var (`*-256color` → 256-color support)
|
|
593
|
+
- Fallback to 256-color mode if detection fails
|
|
594
|
+
|
|
595
|
+
2. **Load JSON theme file**
|
|
596
|
+
|
|
597
|
+
3. **Resolve `vars` references recursively:**
|
|
598
|
+
|
|
599
|
+
```json
|
|
600
|
+
{
|
|
601
|
+
"vars": {
|
|
602
|
+
"primary": "#0066cc",
|
|
603
|
+
"accent": "primary"
|
|
604
|
+
},
|
|
605
|
+
"colors": {
|
|
606
|
+
"accent": "accent" // → "primary" → "#0066cc"
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
4. **Convert colors to ANSI codes based on terminal capability:**
|
|
612
|
+
|
|
613
|
+
**Truecolor mode (24-bit):**
|
|
614
|
+
|
|
615
|
+
- Hex (`"#ff0000"`) → `\x1b[38;2;255;0;0m`
|
|
616
|
+
- 256-color (`42`) → `\x1b[38;5;42m` (keep as-is)
|
|
617
|
+
- Empty string (`""`) → `\x1b[39m`
|
|
618
|
+
|
|
619
|
+
**256-color mode:**
|
|
620
|
+
|
|
621
|
+
- Hex (`"#ff0000"`) → convert to nearest RGB cube color → `\x1b[38;5;196m`
|
|
622
|
+
- 256-color (`42`) → `\x1b[38;5;42m` (keep as-is)
|
|
623
|
+
- Empty string (`""`) → `\x1b[39m`
|
|
624
|
+
|
|
625
|
+
**Hex to 256-color conversion:**
|
|
626
|
+
|
|
627
|
+
```typescript
|
|
628
|
+
// Convert RGB to 6x6x6 cube (colors 16-231)
|
|
629
|
+
r_index = Math.round((r / 255) * 5);
|
|
630
|
+
g_index = Math.round((g / 255) * 5);
|
|
631
|
+
b_index = Math.round((b / 255) * 5);
|
|
632
|
+
color_index = 16 + 36 * r_index + 6 * g_index + b_index;
|
|
633
|
+
```
|
|
634
|
+
|
|
635
|
+
5. **Cache as `Theme` instance**
|
|
636
|
+
|
|
637
|
+
This ensures themes work correctly regardless of terminal capabilities, with graceful degradation from truecolor to 256-color.
|