@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.
Files changed (224) hide show
  1. package/CHANGELOG.md +1228 -0
  2. package/README.md +1041 -0
  3. package/docs/compaction.md +403 -0
  4. package/docs/custom-tools.md +541 -0
  5. package/docs/extension-loading.md +1004 -0
  6. package/docs/hooks.md +867 -0
  7. package/docs/rpc.md +1040 -0
  8. package/docs/sdk.md +994 -0
  9. package/docs/session-tree-plan.md +441 -0
  10. package/docs/session.md +240 -0
  11. package/docs/skills.md +290 -0
  12. package/docs/theme.md +637 -0
  13. package/docs/tree.md +197 -0
  14. package/docs/tui.md +341 -0
  15. package/examples/README.md +21 -0
  16. package/examples/custom-tools/README.md +124 -0
  17. package/examples/custom-tools/hello/index.ts +20 -0
  18. package/examples/custom-tools/question/index.ts +84 -0
  19. package/examples/custom-tools/subagent/README.md +172 -0
  20. package/examples/custom-tools/subagent/agents/planner.md +37 -0
  21. package/examples/custom-tools/subagent/agents/reviewer.md +35 -0
  22. package/examples/custom-tools/subagent/agents/scout.md +50 -0
  23. package/examples/custom-tools/subagent/agents/worker.md +24 -0
  24. package/examples/custom-tools/subagent/agents.ts +156 -0
  25. package/examples/custom-tools/subagent/commands/implement-and-review.md +10 -0
  26. package/examples/custom-tools/subagent/commands/implement.md +10 -0
  27. package/examples/custom-tools/subagent/commands/scout-and-plan.md +9 -0
  28. package/examples/custom-tools/subagent/index.ts +1002 -0
  29. package/examples/custom-tools/todo/index.ts +212 -0
  30. package/examples/hooks/README.md +56 -0
  31. package/examples/hooks/auto-commit-on-exit.ts +49 -0
  32. package/examples/hooks/confirm-destructive.ts +59 -0
  33. package/examples/hooks/custom-compaction.ts +116 -0
  34. package/examples/hooks/dirty-repo-guard.ts +52 -0
  35. package/examples/hooks/file-trigger.ts +41 -0
  36. package/examples/hooks/git-checkpoint.ts +53 -0
  37. package/examples/hooks/handoff.ts +150 -0
  38. package/examples/hooks/permission-gate.ts +34 -0
  39. package/examples/hooks/protected-paths.ts +30 -0
  40. package/examples/hooks/qna.ts +119 -0
  41. package/examples/hooks/snake.ts +343 -0
  42. package/examples/hooks/status-line.ts +40 -0
  43. package/examples/sdk/01-minimal.ts +22 -0
  44. package/examples/sdk/02-custom-model.ts +49 -0
  45. package/examples/sdk/03-custom-prompt.ts +44 -0
  46. package/examples/sdk/04-skills.ts +44 -0
  47. package/examples/sdk/05-tools.ts +90 -0
  48. package/examples/sdk/06-hooks.ts +61 -0
  49. package/examples/sdk/07-context-files.ts +36 -0
  50. package/examples/sdk/08-slash-commands.ts +42 -0
  51. package/examples/sdk/09-api-keys-and-oauth.ts +55 -0
  52. package/examples/sdk/10-settings.ts +38 -0
  53. package/examples/sdk/11-sessions.ts +48 -0
  54. package/examples/sdk/12-full-control.ts +95 -0
  55. package/examples/sdk/README.md +154 -0
  56. package/package.json +81 -0
  57. package/src/cli/args.ts +246 -0
  58. package/src/cli/file-processor.ts +72 -0
  59. package/src/cli/list-models.ts +104 -0
  60. package/src/cli/plugin-cli.ts +650 -0
  61. package/src/cli/session-picker.ts +41 -0
  62. package/src/cli.ts +10 -0
  63. package/src/commands/init.md +20 -0
  64. package/src/config.ts +159 -0
  65. package/src/core/agent-session.ts +1900 -0
  66. package/src/core/auth-storage.ts +236 -0
  67. package/src/core/bash-executor.ts +196 -0
  68. package/src/core/compaction/branch-summarization.ts +343 -0
  69. package/src/core/compaction/compaction.ts +742 -0
  70. package/src/core/compaction/index.ts +7 -0
  71. package/src/core/compaction/utils.ts +154 -0
  72. package/src/core/custom-tools/index.ts +21 -0
  73. package/src/core/custom-tools/loader.ts +248 -0
  74. package/src/core/custom-tools/types.ts +169 -0
  75. package/src/core/custom-tools/wrapper.ts +28 -0
  76. package/src/core/exec.ts +129 -0
  77. package/src/core/export-html/index.ts +211 -0
  78. package/src/core/export-html/template.css +781 -0
  79. package/src/core/export-html/template.html +54 -0
  80. package/src/core/export-html/template.js +1185 -0
  81. package/src/core/export-html/vendor/highlight.min.js +1213 -0
  82. package/src/core/export-html/vendor/marked.min.js +6 -0
  83. package/src/core/hooks/index.ts +16 -0
  84. package/src/core/hooks/loader.ts +312 -0
  85. package/src/core/hooks/runner.ts +434 -0
  86. package/src/core/hooks/tool-wrapper.ts +99 -0
  87. package/src/core/hooks/types.ts +773 -0
  88. package/src/core/index.ts +52 -0
  89. package/src/core/mcp/client.ts +158 -0
  90. package/src/core/mcp/config.ts +154 -0
  91. package/src/core/mcp/index.ts +45 -0
  92. package/src/core/mcp/loader.ts +68 -0
  93. package/src/core/mcp/manager.ts +181 -0
  94. package/src/core/mcp/tool-bridge.ts +148 -0
  95. package/src/core/mcp/transports/http.ts +316 -0
  96. package/src/core/mcp/transports/index.ts +6 -0
  97. package/src/core/mcp/transports/stdio.ts +252 -0
  98. package/src/core/mcp/types.ts +220 -0
  99. package/src/core/messages.ts +189 -0
  100. package/src/core/model-registry.ts +317 -0
  101. package/src/core/model-resolver.ts +393 -0
  102. package/src/core/plugins/doctor.ts +59 -0
  103. package/src/core/plugins/index.ts +38 -0
  104. package/src/core/plugins/installer.ts +189 -0
  105. package/src/core/plugins/loader.ts +338 -0
  106. package/src/core/plugins/manager.ts +672 -0
  107. package/src/core/plugins/parser.ts +105 -0
  108. package/src/core/plugins/paths.ts +32 -0
  109. package/src/core/plugins/types.ts +190 -0
  110. package/src/core/sdk.ts +760 -0
  111. package/src/core/session-manager.ts +1128 -0
  112. package/src/core/settings-manager.ts +443 -0
  113. package/src/core/skills.ts +437 -0
  114. package/src/core/slash-commands.ts +248 -0
  115. package/src/core/system-prompt.ts +439 -0
  116. package/src/core/timings.ts +25 -0
  117. package/src/core/tools/ask.ts +211 -0
  118. package/src/core/tools/bash-interceptor.ts +120 -0
  119. package/src/core/tools/bash.ts +250 -0
  120. package/src/core/tools/context.ts +32 -0
  121. package/src/core/tools/edit-diff.ts +475 -0
  122. package/src/core/tools/edit.ts +208 -0
  123. package/src/core/tools/exa/company.ts +59 -0
  124. package/src/core/tools/exa/index.ts +64 -0
  125. package/src/core/tools/exa/linkedin.ts +59 -0
  126. package/src/core/tools/exa/logger.ts +56 -0
  127. package/src/core/tools/exa/mcp-client.ts +368 -0
  128. package/src/core/tools/exa/render.ts +196 -0
  129. package/src/core/tools/exa/researcher.ts +90 -0
  130. package/src/core/tools/exa/search.ts +337 -0
  131. package/src/core/tools/exa/types.ts +168 -0
  132. package/src/core/tools/exa/websets.ts +248 -0
  133. package/src/core/tools/find.ts +261 -0
  134. package/src/core/tools/grep.ts +555 -0
  135. package/src/core/tools/index.ts +202 -0
  136. package/src/core/tools/ls.ts +140 -0
  137. package/src/core/tools/lsp/client.ts +605 -0
  138. package/src/core/tools/lsp/config.ts +147 -0
  139. package/src/core/tools/lsp/edits.ts +101 -0
  140. package/src/core/tools/lsp/index.ts +804 -0
  141. package/src/core/tools/lsp/render.ts +447 -0
  142. package/src/core/tools/lsp/rust-analyzer.ts +145 -0
  143. package/src/core/tools/lsp/types.ts +463 -0
  144. package/src/core/tools/lsp/utils.ts +486 -0
  145. package/src/core/tools/notebook.ts +229 -0
  146. package/src/core/tools/path-utils.ts +61 -0
  147. package/src/core/tools/read.ts +240 -0
  148. package/src/core/tools/renderers.ts +540 -0
  149. package/src/core/tools/task/agents.ts +153 -0
  150. package/src/core/tools/task/artifacts.ts +114 -0
  151. package/src/core/tools/task/bundled-agents/browser.md +71 -0
  152. package/src/core/tools/task/bundled-agents/explore.md +82 -0
  153. package/src/core/tools/task/bundled-agents/plan.md +54 -0
  154. package/src/core/tools/task/bundled-agents/reviewer.md +59 -0
  155. package/src/core/tools/task/bundled-agents/task.md +53 -0
  156. package/src/core/tools/task/bundled-commands/architect-plan.md +10 -0
  157. package/src/core/tools/task/bundled-commands/implement-with-critic.md +11 -0
  158. package/src/core/tools/task/bundled-commands/implement.md +11 -0
  159. package/src/core/tools/task/commands.ts +213 -0
  160. package/src/core/tools/task/discovery.ts +208 -0
  161. package/src/core/tools/task/executor.ts +367 -0
  162. package/src/core/tools/task/index.ts +388 -0
  163. package/src/core/tools/task/model-resolver.ts +115 -0
  164. package/src/core/tools/task/parallel.ts +38 -0
  165. package/src/core/tools/task/render.ts +232 -0
  166. package/src/core/tools/task/types.ts +99 -0
  167. package/src/core/tools/truncate.ts +265 -0
  168. package/src/core/tools/web-fetch.ts +2370 -0
  169. package/src/core/tools/web-search/auth.ts +193 -0
  170. package/src/core/tools/web-search/index.ts +537 -0
  171. package/src/core/tools/web-search/providers/anthropic.ts +198 -0
  172. package/src/core/tools/web-search/providers/exa.ts +302 -0
  173. package/src/core/tools/web-search/providers/perplexity.ts +195 -0
  174. package/src/core/tools/web-search/render.ts +182 -0
  175. package/src/core/tools/web-search/types.ts +180 -0
  176. package/src/core/tools/write.ts +99 -0
  177. package/src/index.ts +176 -0
  178. package/src/main.ts +464 -0
  179. package/src/migrations.ts +135 -0
  180. package/src/modes/index.ts +43 -0
  181. package/src/modes/interactive/components/armin.ts +382 -0
  182. package/src/modes/interactive/components/assistant-message.ts +86 -0
  183. package/src/modes/interactive/components/bash-execution.ts +196 -0
  184. package/src/modes/interactive/components/bordered-loader.ts +41 -0
  185. package/src/modes/interactive/components/branch-summary-message.ts +42 -0
  186. package/src/modes/interactive/components/compaction-summary-message.ts +45 -0
  187. package/src/modes/interactive/components/custom-editor.ts +122 -0
  188. package/src/modes/interactive/components/diff.ts +147 -0
  189. package/src/modes/interactive/components/dynamic-border.ts +25 -0
  190. package/src/modes/interactive/components/footer.ts +381 -0
  191. package/src/modes/interactive/components/hook-editor.ts +117 -0
  192. package/src/modes/interactive/components/hook-input.ts +64 -0
  193. package/src/modes/interactive/components/hook-message.ts +96 -0
  194. package/src/modes/interactive/components/hook-selector.ts +91 -0
  195. package/src/modes/interactive/components/model-selector.ts +247 -0
  196. package/src/modes/interactive/components/oauth-selector.ts +120 -0
  197. package/src/modes/interactive/components/plugin-settings.ts +479 -0
  198. package/src/modes/interactive/components/queue-mode-selector.ts +56 -0
  199. package/src/modes/interactive/components/session-selector.ts +204 -0
  200. package/src/modes/interactive/components/settings-selector.ts +453 -0
  201. package/src/modes/interactive/components/show-images-selector.ts +45 -0
  202. package/src/modes/interactive/components/theme-selector.ts +62 -0
  203. package/src/modes/interactive/components/thinking-selector.ts +64 -0
  204. package/src/modes/interactive/components/tool-execution.ts +675 -0
  205. package/src/modes/interactive/components/tree-selector.ts +866 -0
  206. package/src/modes/interactive/components/user-message-selector.ts +159 -0
  207. package/src/modes/interactive/components/user-message.ts +18 -0
  208. package/src/modes/interactive/components/visual-truncate.ts +50 -0
  209. package/src/modes/interactive/components/welcome.ts +183 -0
  210. package/src/modes/interactive/interactive-mode.ts +2516 -0
  211. package/src/modes/interactive/theme/dark.json +101 -0
  212. package/src/modes/interactive/theme/light.json +98 -0
  213. package/src/modes/interactive/theme/theme-schema.json +308 -0
  214. package/src/modes/interactive/theme/theme.ts +998 -0
  215. package/src/modes/print-mode.ts +128 -0
  216. package/src/modes/rpc/rpc-client.ts +527 -0
  217. package/src/modes/rpc/rpc-mode.ts +483 -0
  218. package/src/modes/rpc/rpc-types.ts +203 -0
  219. package/src/utils/changelog.ts +99 -0
  220. package/src/utils/clipboard.ts +265 -0
  221. package/src/utils/fuzzy.ts +108 -0
  222. package/src/utils/mime.ts +30 -0
  223. package/src/utils/shell.ts +276 -0
  224. 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.