@mariozechner/pi-coding-agent 0.49.3 → 0.50.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 (207) hide show
  1. package/CHANGELOG.md +99 -1
  2. package/README.md +310 -1230
  3. package/dist/cli/args.d.ts +5 -0
  4. package/dist/cli/args.d.ts.map +1 -1
  5. package/dist/cli/args.js +57 -23
  6. package/dist/cli/args.js.map +1 -1
  7. package/dist/cli/config-selector.d.ts +14 -0
  8. package/dist/cli/config-selector.d.ts.map +1 -0
  9. package/dist/cli/config-selector.js +31 -0
  10. package/dist/cli/config-selector.js.map +1 -0
  11. package/dist/cli/session-picker.d.ts.map +1 -1
  12. package/dist/cli/session-picker.js +1 -1
  13. package/dist/cli/session-picker.js.map +1 -1
  14. package/dist/core/agent-session.d.ts +53 -34
  15. package/dist/core/agent-session.d.ts.map +1 -1
  16. package/dist/core/agent-session.js +262 -67
  17. package/dist/core/agent-session.js.map +1 -1
  18. package/dist/core/auth-storage.d.ts +8 -18
  19. package/dist/core/auth-storage.d.ts.map +1 -1
  20. package/dist/core/auth-storage.js +39 -55
  21. package/dist/core/auth-storage.js.map +1 -1
  22. package/dist/core/bash-executor.d.ts.map +1 -1
  23. package/dist/core/bash-executor.js +2 -1
  24. package/dist/core/bash-executor.js.map +1 -1
  25. package/dist/core/diagnostics.d.ts +15 -0
  26. package/dist/core/diagnostics.d.ts.map +1 -0
  27. package/dist/core/diagnostics.js +2 -0
  28. package/dist/core/diagnostics.js.map +1 -0
  29. package/dist/core/export-html/template.css +9 -0
  30. package/dist/core/export-html/template.js +6 -4
  31. package/dist/core/extensions/index.d.ts +1 -1
  32. package/dist/core/extensions/index.d.ts.map +1 -1
  33. package/dist/core/extensions/index.js.map +1 -1
  34. package/dist/core/extensions/loader.d.ts +1 -1
  35. package/dist/core/extensions/loader.d.ts.map +1 -1
  36. package/dist/core/extensions/loader.js +10 -1
  37. package/dist/core/extensions/loader.js.map +1 -1
  38. package/dist/core/extensions/runner.d.ts +9 -3
  39. package/dist/core/extensions/runner.d.ts.map +1 -1
  40. package/dist/core/extensions/runner.js +39 -12
  41. package/dist/core/extensions/runner.js.map +1 -1
  42. package/dist/core/extensions/types.d.ts +112 -1
  43. package/dist/core/extensions/types.d.ts.map +1 -1
  44. package/dist/core/extensions/types.js.map +1 -1
  45. package/dist/core/footer-data-provider.d.ts +9 -2
  46. package/dist/core/footer-data-provider.d.ts.map +1 -1
  47. package/dist/core/footer-data-provider.js +13 -0
  48. package/dist/core/footer-data-provider.js.map +1 -1
  49. package/dist/core/model-registry.d.ts +42 -2
  50. package/dist/core/model-registry.d.ts.map +1 -1
  51. package/dist/core/model-registry.js +154 -44
  52. package/dist/core/model-registry.js.map +1 -1
  53. package/dist/core/model-resolver.d.ts.map +1 -1
  54. package/dist/core/model-resolver.js +3 -2
  55. package/dist/core/model-resolver.js.map +1 -1
  56. package/dist/core/package-manager.d.ts +129 -0
  57. package/dist/core/package-manager.d.ts.map +1 -0
  58. package/dist/core/package-manager.js +1148 -0
  59. package/dist/core/package-manager.js.map +1 -0
  60. package/dist/core/prompt-templates.d.ts +6 -0
  61. package/dist/core/prompt-templates.d.ts.map +1 -1
  62. package/dist/core/prompt-templates.js +114 -54
  63. package/dist/core/prompt-templates.js.map +1 -1
  64. package/dist/core/resource-loader.d.ts +160 -0
  65. package/dist/core/resource-loader.d.ts.map +1 -0
  66. package/dist/core/resource-loader.js +604 -0
  67. package/dist/core/resource-loader.js.map +1 -0
  68. package/dist/core/sdk.d.ts +14 -105
  69. package/dist/core/sdk.d.ts.map +1 -1
  70. package/dist/core/sdk.js +52 -304
  71. package/dist/core/sdk.js.map +1 -1
  72. package/dist/core/session-manager.d.ts.map +1 -1
  73. package/dist/core/session-manager.js +45 -1
  74. package/dist/core/session-manager.js.map +1 -1
  75. package/dist/core/settings-manager.d.ts +34 -16
  76. package/dist/core/settings-manager.d.ts.map +1 -1
  77. package/dist/core/settings-manager.js +104 -25
  78. package/dist/core/settings-manager.js.map +1 -1
  79. package/dist/core/skills.d.ts +18 -10
  80. package/dist/core/skills.d.ts.map +1 -1
  81. package/dist/core/skills.js +126 -93
  82. package/dist/core/skills.js.map +1 -1
  83. package/dist/core/system-prompt.d.ts +3 -27
  84. package/dist/core/system-prompt.d.ts.map +1 -1
  85. package/dist/core/system-prompt.js +16 -103
  86. package/dist/core/system-prompt.js.map +1 -1
  87. package/dist/core/tools/bash.d.ts.map +1 -1
  88. package/dist/core/tools/bash.js +2 -1
  89. package/dist/core/tools/bash.js.map +1 -1
  90. package/dist/core/tools/read.d.ts.map +1 -1
  91. package/dist/core/tools/read.js +4 -4
  92. package/dist/core/tools/read.js.map +1 -1
  93. package/dist/index.d.ts +12 -7
  94. package/dist/index.d.ts.map +1 -1
  95. package/dist/index.js +8 -6
  96. package/dist/index.js.map +1 -1
  97. package/dist/main.d.ts.map +1 -1
  98. package/dist/main.js +209 -97
  99. package/dist/main.js.map +1 -1
  100. package/dist/modes/interactive/components/bordered-loader.d.ts +5 -1
  101. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  102. package/dist/modes/interactive/components/bordered-loader.js +29 -9
  103. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  104. package/dist/modes/interactive/components/config-selector.d.ts +71 -0
  105. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -0
  106. package/dist/modes/interactive/components/config-selector.js +468 -0
  107. package/dist/modes/interactive/components/config-selector.js.map +1 -0
  108. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  109. package/dist/modes/interactive/components/footer.js +4 -0
  110. package/dist/modes/interactive/components/footer.js.map +1 -1
  111. package/dist/modes/interactive/components/index.d.ts +1 -0
  112. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  113. package/dist/modes/interactive/components/index.js +1 -0
  114. package/dist/modes/interactive/components/index.js.map +1 -1
  115. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  116. package/dist/modes/interactive/components/oauth-selector.js +3 -4
  117. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  118. package/dist/modes/interactive/components/session-selector.d.ts +18 -1
  119. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  120. package/dist/modes/interactive/components/session-selector.js +195 -87
  121. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  122. package/dist/modes/interactive/components/skill-invocation-message.d.ts +17 -0
  123. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -0
  124. package/dist/modes/interactive/components/skill-invocation-message.js +47 -0
  125. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -0
  126. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  127. package/dist/modes/interactive/components/tool-execution.js +5 -5
  128. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  129. package/dist/modes/interactive/interactive-mode.d.ts +42 -2
  130. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  131. package/dist/modes/interactive/interactive-mode.js +535 -200
  132. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  133. package/dist/modes/interactive/theme/dark.json +1 -1
  134. package/dist/modes/interactive/theme/light.json +1 -1
  135. package/dist/modes/interactive/theme/theme-schema.json +8 -1
  136. package/dist/modes/interactive/theme/theme.d.ts +8 -1
  137. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  138. package/dist/modes/interactive/theme/theme.js +72 -25
  139. package/dist/modes/interactive/theme/theme.js.map +1 -1
  140. package/dist/modes/print-mode.d.ts.map +1 -1
  141. package/dist/modes/print-mode.js +25 -89
  142. package/dist/modes/print-mode.js.map +1 -1
  143. package/dist/modes/rpc/rpc-mode.d.ts.map +1 -1
  144. package/dist/modes/rpc/rpc-mode.js +32 -92
  145. package/dist/modes/rpc/rpc-mode.js.map +1 -1
  146. package/dist/utils/git.d.ts +2 -0
  147. package/dist/utils/git.d.ts.map +1 -0
  148. package/dist/utils/git.js +6 -0
  149. package/dist/utils/git.js.map +1 -0
  150. package/dist/utils/shell.d.ts +1 -0
  151. package/dist/utils/shell.d.ts.map +1 -1
  152. package/dist/utils/shell.js +14 -1
  153. package/dist/utils/shell.js.map +1 -1
  154. package/dist/utils/sleep.d.ts +5 -0
  155. package/dist/utils/sleep.d.ts.map +1 -0
  156. package/dist/utils/sleep.js +17 -0
  157. package/dist/utils/sleep.js.map +1 -0
  158. package/docs/compaction.md +23 -21
  159. package/docs/custom-provider.md +538 -0
  160. package/docs/development.md +69 -0
  161. package/docs/extensions.md +180 -118
  162. package/docs/images/doom-extension.png +0 -0
  163. package/docs/images/interactive-mode.png +0 -0
  164. package/docs/images/tree-view.png +0 -0
  165. package/docs/json.md +79 -0
  166. package/docs/keybindings.md +162 -0
  167. package/docs/models.md +193 -0
  168. package/docs/packages.md +163 -0
  169. package/docs/prompt-templates.md +67 -0
  170. package/docs/providers.md +147 -0
  171. package/docs/sdk.md +111 -178
  172. package/docs/session.md +167 -16
  173. package/docs/settings.md +216 -0
  174. package/docs/shell-aliases.md +13 -0
  175. package/docs/skills.md +111 -202
  176. package/docs/terminal-setup.md +65 -0
  177. package/docs/themes.md +295 -0
  178. package/docs/tui.md +36 -5
  179. package/docs/windows.md +17 -0
  180. package/examples/README.md +1 -0
  181. package/examples/extensions/README.md +22 -2
  182. package/examples/extensions/bookmark.ts +50 -0
  183. package/examples/extensions/custom-provider-anthropic/index.ts +604 -0
  184. package/examples/extensions/custom-provider-anthropic/package-lock.json +24 -0
  185. package/examples/extensions/custom-provider-anthropic/package.json +19 -0
  186. package/examples/extensions/custom-provider-gitlab-duo/index.ts +349 -0
  187. package/examples/extensions/custom-provider-gitlab-duo/package.json +16 -0
  188. package/examples/extensions/custom-provider-gitlab-duo/test.ts +82 -0
  189. package/examples/extensions/doom-overlay/doom/build.sh +1 -1
  190. package/examples/extensions/event-bus.ts +43 -0
  191. package/examples/extensions/message-renderer.ts +59 -0
  192. package/examples/extensions/session-name.ts +27 -0
  193. package/examples/extensions/with-deps/package-lock.json +2 -2
  194. package/examples/extensions/with-deps/package.json +1 -1
  195. package/examples/sdk/02-custom-model.ts +3 -3
  196. package/examples/sdk/03-custom-prompt.ts +20 -9
  197. package/examples/sdk/04-skills.ts +26 -27
  198. package/examples/sdk/06-extensions.ts +15 -6
  199. package/examples/sdk/07-context-files.ts +22 -18
  200. package/examples/sdk/08-prompt-templates.ts +19 -14
  201. package/examples/sdk/09-api-keys-and-oauth.ts +5 -12
  202. package/examples/sdk/10-settings.ts +3 -3
  203. package/examples/sdk/12-full-control.ts +16 -7
  204. package/examples/sdk/README.md +24 -30
  205. package/package.json +4 -4
  206. package/docs/theme.md +0 -617
  207. package/examples/extensions/chalk-logger.ts +0 -26
package/docs/theme.md DELETED
@@ -1,617 +0,0 @@
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
- ```json
119
- {
120
- "export": {
121
- "pageBg": "#18181e",
122
- "cardBg": "#1e1e24",
123
- "infoBg": "#3c3728"
124
- }
125
- }
126
- ```
127
-
128
- ## Theme Format
129
-
130
- Themes are defined in JSON files with the following structure:
131
-
132
- ```json
133
- {
134
- "$schema": "https://raw.githubusercontent.com/badlogic/pi-mono/main/packages/coding-agent/theme-schema.json",
135
- "name": "my-theme",
136
- "vars": {
137
- "blue": "#0066cc",
138
- "gray": 242,
139
- "brightCyan": 51
140
- },
141
- "colors": {
142
- "accent": "blue",
143
- "muted": "gray",
144
- "thinkingText": "gray",
145
- "text": "",
146
- ...
147
- }
148
- }
149
- ```
150
-
151
- ### Color Values
152
-
153
- Four formats are supported:
154
-
155
- 1. **Hex colors**: `"#ff0000"` (6-digit hex RGB)
156
- 2. **256-color palette**: `39` (number 0-255, xterm 256-color palette)
157
- 3. **Color references**: `"blue"` (must be defined in `vars`)
158
- 4. **Terminal default**: `""` (empty string, uses terminal's default color)
159
-
160
- ### The `vars` Section
161
-
162
- The optional `vars` section allows you to define reusable colors:
163
-
164
- ```json
165
- {
166
- "vars": {
167
- "nord0": "#2E3440",
168
- "nord1": "#3B4252",
169
- "nord8": "#88C0D0",
170
- "brightBlue": 39
171
- },
172
- "colors": {
173
- "accent": "nord8",
174
- "muted": "nord1",
175
- "mdLink": "brightBlue"
176
- }
177
- }
178
- ```
179
-
180
- Benefits:
181
- - Reuse colors across multiple tokens
182
- - Easier to maintain theme consistency
183
- - Can reference standard color palettes
184
-
185
- Variables can be hex colors (`"#ff0000"`), 256-color indices (`42`), or references to other variables.
186
-
187
- ### Terminal Default (empty string)
188
-
189
- Use `""` (empty string) to inherit the terminal's default foreground/background color:
190
-
191
- ```json
192
- {
193
- "colors": {
194
- "text": "" // Uses terminal's default text color
195
- }
196
- }
197
- ```
198
-
199
- This is useful for:
200
- - Main text color (adapts to user's terminal theme)
201
- - Creating themes that blend with terminal appearance
202
-
203
- ## Built-in Themes
204
-
205
- Pi comes with two built-in themes:
206
-
207
- ### `dark` (default)
208
-
209
- Optimized for dark terminal backgrounds with bright, saturated colors.
210
-
211
- ### `light`
212
-
213
- Optimized for light terminal backgrounds with darker, muted colors.
214
-
215
- ## Selecting a Theme
216
-
217
- Themes are configured in the settings (accessible via `/settings`):
218
-
219
- ```json
220
- {
221
- "theme": "dark"
222
- }
223
- ```
224
-
225
- Or use the `/theme` command interactively.
226
-
227
- On first run, Pi detects your terminal's background and sets a sensible default (`dark` or `light`).
228
-
229
- ## Custom Themes
230
-
231
- ### Theme Locations
232
-
233
- Custom themes are loaded from `~/.pi/agent/themes/*.json`.
234
-
235
- ### Creating a Custom Theme
236
-
237
- 1. **Create theme directory:**
238
- ```bash
239
- mkdir -p ~/.pi/agent/themes
240
- ```
241
-
242
- 2. **Create theme file:**
243
- ```bash
244
- vim ~/.pi/agent/themes/my-theme.json
245
- ```
246
-
247
- 3. **Define all colors:**
248
- ```json
249
- {
250
- "$schema": "https://raw.githubusercontent.com/badlogic/pi-mono/main/packages/coding-agent/theme-schema.json",
251
- "name": "my-theme",
252
- "vars": {
253
- "primary": "#00aaff",
254
- "secondary": 242,
255
- "brightGreen": 46
256
- },
257
- "colors": {
258
- "accent": "primary",
259
- "border": "primary",
260
- "borderAccent": "#00ffff",
261
- "borderMuted": "secondary",
262
- "success": "brightGreen",
263
- "error": "#ff0000",
264
- "warning": "#ffff00",
265
- "muted": "secondary",
266
- "text": "",
267
-
268
- "userMessageBg": "#2d2d30",
269
- "userMessageText": "",
270
- "toolPendingBg": "#1e1e2e",
271
- "toolSuccessBg": "#1e2e1e",
272
- "toolErrorBg": "#2e1e1e",
273
- "toolText": "",
274
-
275
- "mdHeading": "#ffaa00",
276
- "mdLink": "primary",
277
- "mdCode": "#00ffff",
278
- "mdCodeBlock": "#00ff00",
279
- "mdCodeBlockBorder": "secondary",
280
- "mdQuote": "secondary",
281
- "mdQuoteBorder": "secondary",
282
- "mdHr": "secondary",
283
- "mdListBullet": "#00ffff",
284
-
285
- "toolDiffAdded": "#00ff00",
286
- "toolDiffRemoved": "#ff0000",
287
- "toolDiffContext": "secondary",
288
-
289
- "syntaxComment": "secondary",
290
- "syntaxKeyword": "primary",
291
- "syntaxFunction": "#00aaff",
292
- "syntaxVariable": "#ffaa00",
293
- "syntaxString": "#00ff00",
294
- "syntaxNumber": "#ff00ff",
295
- "syntaxType": "#00aaff",
296
- "syntaxOperator": "primary",
297
- "syntaxPunctuation": "secondary",
298
-
299
- "thinkingOff": "secondary",
300
- "thinkingMinimal": "primary",
301
- "thinkingLow": "#00aaff",
302
- "thinkingMedium": "#00ffff",
303
- "thinkingHigh": "#ff00ff"
304
- }
305
- }
306
- ```
307
-
308
- 4. **Select your theme:**
309
- - Use `/settings` command and set `"theme": "my-theme"`
310
- - Or use `/theme` command interactively
311
-
312
- ## Tips
313
-
314
- ### Light vs Dark Themes
315
-
316
- **For dark terminals:**
317
- - Use bright, saturated colors
318
- - Higher contrast
319
- - Example: `#00ffff` (bright cyan)
320
-
321
- **For light terminals:**
322
- - Use darker, muted colors
323
- - Lower contrast to avoid eye strain
324
- - Example: `#008888` (dark cyan)
325
-
326
- ### Color Harmony
327
-
328
- - Start with a base palette (e.g., Nord, Gruvbox, Tokyo Night)
329
- - Define your palette in `defs`
330
- - Reference colors consistently
331
-
332
- ### Testing
333
-
334
- Test your theme with:
335
- - Different message types (user, assistant, errors)
336
- - Tool executions (success and error states)
337
- - Markdown content (headings, code, lists, etc)
338
- - Long text that wraps
339
-
340
- ## Color Format Reference
341
-
342
- ### Hex Colors
343
-
344
- Standard 6-digit hex format:
345
- - `"#ff0000"` - Red
346
- - `"#00ff00"` - Green
347
- - `"#0000ff"` - Blue
348
- - `"#808080"` - Gray
349
- - `"#ffffff"` - White
350
- - `"#000000"` - Black
351
-
352
- RGB values: `#RRGGBB` where each component is `00-ff` (0-255)
353
-
354
- ### 256-Color Palette
355
-
356
- Use numeric indices (0-255) to reference the xterm 256-color palette:
357
-
358
- **Colors 0-15:** Basic ANSI colors (terminal-dependent, may be themed)
359
- - `0` - Black
360
- - `1` - Red
361
- - `2` - Green
362
- - `3` - Yellow
363
- - `4` - Blue
364
- - `5` - Magenta
365
- - `6` - Cyan
366
- - `7` - White
367
- - `8-15` - Bright variants
368
-
369
- **Colors 16-231:** 6×6×6 RGB cube (standardized)
370
- - Formula: `16 + 36×R + 6×G + B` where R, G, B are 0-5
371
- - Example: `39` = bright cyan, `196` = bright red
372
-
373
- **Colors 232-255:** Grayscale ramp (standardized)
374
- - `232` - Darkest gray
375
- - `255` - Near white
376
-
377
- Example usage:
378
- ```json
379
- {
380
- "vars": {
381
- "gray": 242,
382
- "brightCyan": 51,
383
- "darkBlue": 18
384
- },
385
- "colors": {
386
- "muted": "gray",
387
- "accent": "brightCyan"
388
- }
389
- }
390
- ```
391
-
392
- **Benefits:**
393
- - Works everywhere (`TERM=xterm-256color`)
394
- - No truecolor detection needed
395
- - Standardized RGB cube (16-231) looks the same on all terminals
396
-
397
- ### Terminal Compatibility
398
-
399
- Pi uses 24-bit RGB colors (`\x1b[38;2;R;G;Bm`). Most modern terminals support this:
400
-
401
- - ✅ iTerm2, Alacritty, Kitty, WezTerm
402
- - ✅ Windows Terminal
403
- - ✅ VS Code integrated terminal
404
- - ✅ Modern GNOME Terminal, Konsole
405
-
406
- For older terminals with only 256-color support, Pi automatically falls back to the nearest 256-color approximation.
407
-
408
- To check if your terminal supports truecolor:
409
- ```bash
410
- echo $COLORTERM # Should output "truecolor" or "24bit"
411
- ```
412
-
413
- ## Example Themes
414
-
415
- See the built-in themes for complete examples:
416
- - [Dark theme](../src/themes/dark.json)
417
- - [Light theme](../src/themes/light.json)
418
-
419
- ## Schema Validation
420
-
421
- Themes are validated on load using [TypeBox](https://github.com/sinclairzx81/typebox) + [Ajv](https://ajv.js.org/).
422
-
423
- Invalid themes will show an error with details about what's wrong:
424
- ```
425
- Error loading theme 'my-theme':
426
- - colors.accent: must be string or number
427
- - colors.mdHeading: required property missing
428
- ```
429
-
430
- For editor support, the JSON schema is available at:
431
- ```
432
- https://raw.githubusercontent.com/badlogic/pi-mono/main/packages/coding-agent/theme-schema.json
433
- ```
434
-
435
- Add to your theme file for auto-completion and validation:
436
- ```json
437
- {
438
- "$schema": "https://raw.githubusercontent.com/badlogic/pi-mono/main/packages/coding-agent/theme-schema.json",
439
- ...
440
- }
441
- ```
442
-
443
- ## Implementation
444
-
445
- ### Theme Class
446
-
447
- Themes are loaded and converted to a `Theme` class that provides type-safe color methods:
448
-
449
- ```typescript
450
- class Theme {
451
- // Apply foreground color
452
- fg(color: ThemeColor, text: string): string
453
-
454
- // Apply background color
455
- bg(color: ThemeBg, text: string): string
456
-
457
- // Text attributes (preserve current colors)
458
- bold(text: string): string
459
- italic(text: string): string
460
- underline(text: string): string
461
- }
462
- ```
463
-
464
- ### Global Theme Instance
465
-
466
- The active theme is available as a global singleton in `coding-agent`:
467
-
468
- ```typescript
469
- // theme.ts
470
- export let theme: Theme;
471
-
472
- export function setTheme(name: string) {
473
- theme = loadTheme(name);
474
- }
475
-
476
- // Usage throughout coding-agent
477
- import { theme } from './theme.js';
478
-
479
- theme.fg('accent', 'Selected')
480
- theme.bg('userMessageBg', content)
481
- ```
482
-
483
- ### TUI Component Theming
484
-
485
- TUI components (like `Markdown`, `SelectList`, `Editor`) are in the `@mariozechner/pi-tui` package and don't have direct access to the theme. Instead, they define interfaces for the colors they need:
486
-
487
- ```typescript
488
- // In @mariozechner/pi-tui
489
- export interface MarkdownTheme {
490
- heading: (text: string) => string;
491
- link: (text: string) => string;
492
- linkUrl: (text: string) => string;
493
- code: (text: string) => string;
494
- codeBlock: (text: string) => string;
495
- codeBlockBorder: (text: string) => string;
496
- quote: (text: string) => string;
497
- quoteBorder: (text: string) => string;
498
- hr: (text: string) => string;
499
- listBullet: (text: string) => string;
500
- bold: (text: string) => string;
501
- italic: (text: string) => string;
502
- strikethrough: (text: string) => string;
503
- underline: (text: string) => string;
504
- }
505
- ```
506
-
507
- The `coding-agent` provides themed functions when creating components:
508
-
509
- ```typescript
510
- // In coding-agent
511
- import { theme } from './theme.js';
512
- import { Markdown } from '@mariozechner/pi-tui';
513
-
514
- // Helper to create markdown theme functions
515
- function getMarkdownTheme(): MarkdownTheme {
516
- return {
517
- heading: (text) => theme.fg('mdHeading', text),
518
- link: (text) => theme.fg('mdLink', text),
519
- linkUrl: (text) => theme.fg('mdLinkUrl', text),
520
- code: (text) => theme.fg('mdCode', text),
521
- codeBlock: (text) => theme.fg('mdCodeBlock', text),
522
- codeBlockBorder: (text) => theme.fg('mdCodeBlockBorder', text),
523
- quote: (text) => theme.fg('mdQuote', text),
524
- quoteBorder: (text) => theme.fg('mdQuoteBorder', text),
525
- hr: (text) => theme.fg('mdHr', text),
526
- listBullet: (text) => theme.fg('mdListBullet', text),
527
- bold: (text) => theme.bold(text),
528
- italic: (text) => theme.italic(text),
529
- underline: (text) => theme.underline(text),
530
- strikethrough: (text) => chalk.strikethrough(text),
531
- };
532
- }
533
-
534
- // Create markdown with theme
535
- const md = new Markdown(
536
- text,
537
- 1, 1,
538
- { bgColor: theme.bg('userMessageBg') },
539
- getMarkdownTheme()
540
- );
541
- ```
542
-
543
- This approach:
544
- - Keeps TUI components theme-agnostic (reusable in other projects)
545
- - Maintains type safety via interfaces
546
- - Allows components to have sensible defaults if no theme provided
547
- - Centralizes theme access in `coding-agent`
548
-
549
- **Example usage:**
550
- ```typescript
551
- const theme = loadTheme('dark');
552
-
553
- // Apply foreground colors
554
- theme.fg('accent', 'Selected')
555
- theme.fg('success', '✓ Done')
556
- theme.fg('error', 'Failed')
557
-
558
- // Apply background colors
559
- theme.bg('userMessageBg', content)
560
- theme.bg('toolSuccessBg', output)
561
-
562
- // Combine styles
563
- theme.bold(theme.fg('accent', 'Title'))
564
- theme.italic(theme.fg('muted', 'metadata'))
565
-
566
- // Nested foreground + background
567
- const userMsg = theme.bg('userMessageBg',
568
- theme.fg('userMessageText', 'Hello')
569
- )
570
- ```
571
-
572
- **Color resolution:**
573
-
574
- 1. **Detect terminal capabilities:**
575
- - Check `$COLORTERM` env var (`truecolor` or `24bit` → truecolor support)
576
- - Check `$TERM` env var (`*-256color` → 256-color support)
577
- - Fallback to 256-color mode if detection fails
578
-
579
- 2. **Load JSON theme file**
580
-
581
- 3. **Resolve `vars` references recursively:**
582
- ```json
583
- {
584
- "vars": {
585
- "primary": "#0066cc",
586
- "accent": "primary"
587
- },
588
- "colors": {
589
- "accent": "accent" // → "primary" → "#0066cc"
590
- }
591
- }
592
- ```
593
-
594
- 4. **Convert colors to ANSI codes based on terminal capability:**
595
-
596
- **Truecolor mode (24-bit):**
597
- - Hex (`"#ff0000"`) → `\x1b[38;2;255;0;0m`
598
- - 256-color (`42`) → `\x1b[38;5;42m` (keep as-is)
599
- - Empty string (`""`) → `\x1b[39m`
600
-
601
- **256-color mode:**
602
- - Hex (`"#ff0000"`) → convert to nearest RGB cube color → `\x1b[38;5;196m`
603
- - 256-color (`42`) → `\x1b[38;5;42m` (keep as-is)
604
- - Empty string (`""`) → `\x1b[39m`
605
-
606
- **Hex to 256-color conversion:**
607
- ```typescript
608
- // Convert RGB to 6x6x6 cube (colors 16-231)
609
- r_index = Math.round(r / 255 * 5)
610
- g_index = Math.round(g / 255 * 5)
611
- b_index = Math.round(b / 255 * 5)
612
- color_index = 16 + 36 * r_index + 6 * g_index + b_index
613
- ```
614
-
615
- 5. **Cache as `Theme` instance**
616
-
617
- This ensures themes work correctly regardless of terminal capabilities, with graceful degradation from truecolor to 256-color.
@@ -1,26 +0,0 @@
1
- /**
2
- * Example extension that uses a 3rd party dependency (chalk).
3
- * Tests that jiti can resolve npm modules correctly.
4
- */
5
-
6
- import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
7
- import chalk from "chalk";
8
-
9
- export default function (pi: ExtensionAPI) {
10
- // Log with colors using chalk
11
- console.log(`${chalk.green("✓")} ${chalk.bold("chalk-logger extension loaded")}`);
12
-
13
- pi.on("agent_start", async () => {
14
- console.log(`${chalk.blue("[chalk-logger]")} Agent starting`);
15
- });
16
-
17
- pi.on("tool_call", async (event) => {
18
- console.log(`${chalk.yellow("[chalk-logger]")} Tool: ${chalk.cyan(event.toolName)}`);
19
- return undefined;
20
- });
21
-
22
- pi.on("agent_end", async (event) => {
23
- const count = event.messages.length;
24
- console.log(`${chalk.green("[chalk-logger]")} Done with ${chalk.bold(String(count))} messages`);
25
- });
26
- }