@mariozechner/pi-coding-agent 0.7.29 → 0.8.1

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 (63) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +74 -4
  3. package/dist/main.d.ts.map +1 -1
  4. package/dist/main.js +7 -4
  5. package/dist/main.js.map +1 -1
  6. package/dist/settings-manager.d.ts +3 -0
  7. package/dist/settings-manager.d.ts.map +1 -1
  8. package/dist/settings-manager.js +7 -0
  9. package/dist/settings-manager.js.map +1 -1
  10. package/dist/theme/dark.json +70 -0
  11. package/dist/theme/light.json +69 -0
  12. package/dist/theme/theme-schema.json +246 -0
  13. package/dist/theme/theme.d.ts +33 -0
  14. package/dist/theme/theme.d.ts.map +1 -0
  15. package/dist/theme/theme.js +470 -0
  16. package/dist/theme/theme.js.map +1 -0
  17. package/dist/tui/assistant-message.d.ts.map +1 -1
  18. package/dist/tui/assistant-message.js +7 -7
  19. package/dist/tui/assistant-message.js.map +1 -1
  20. package/dist/tui/dynamic-border.d.ts +1 -0
  21. package/dist/tui/dynamic-border.d.ts.map +1 -1
  22. package/dist/tui/dynamic-border.js +5 -2
  23. package/dist/tui/dynamic-border.js.map +1 -1
  24. package/dist/tui/footer.d.ts +3 -1
  25. package/dist/tui/footer.d.ts.map +1 -1
  26. package/dist/tui/footer.js +20 -5
  27. package/dist/tui/footer.js.map +1 -1
  28. package/dist/tui/model-selector.d.ts.map +1 -1
  29. package/dist/tui/model-selector.js +14 -13
  30. package/dist/tui/model-selector.js.map +1 -1
  31. package/dist/tui/oauth-selector.d.ts.map +1 -1
  32. package/dist/tui/oauth-selector.js +9 -8
  33. package/dist/tui/oauth-selector.js.map +1 -1
  34. package/dist/tui/queue-mode-selector.d.ts.map +1 -1
  35. package/dist/tui/queue-mode-selector.js +3 -10
  36. package/dist/tui/queue-mode-selector.js.map +1 -1
  37. package/dist/tui/session-selector.d.ts +1 -0
  38. package/dist/tui/session-selector.d.ts.map +1 -1
  39. package/dist/tui/session-selector.js +11 -15
  40. package/dist/tui/session-selector.js.map +1 -1
  41. package/dist/tui/theme-selector.d.ts +11 -0
  42. package/dist/tui/theme-selector.d.ts.map +1 -0
  43. package/dist/tui/theme-selector.js +46 -0
  44. package/dist/tui/theme-selector.js.map +1 -0
  45. package/dist/tui/thinking-selector.d.ts.map +1 -1
  46. package/dist/tui/thinking-selector.js +3 -10
  47. package/dist/tui/thinking-selector.js.map +1 -1
  48. package/dist/tui/tool-execution.d.ts.map +1 -1
  49. package/dist/tui/tool-execution.js +30 -111
  50. package/dist/tui/tool-execution.js.map +1 -1
  51. package/dist/tui/tui-renderer.d.ts +3 -1
  52. package/dist/tui/tui-renderer.d.ts.map +1 -1
  53. package/dist/tui/tui-renderer.js +146 -94
  54. package/dist/tui/tui-renderer.js.map +1 -1
  55. package/dist/tui/user-message-selector.d.ts +1 -0
  56. package/dist/tui/user-message-selector.d.ts.map +1 -1
  57. package/dist/tui/user-message-selector.js +12 -20
  58. package/dist/tui/user-message-selector.js.map +1 -1
  59. package/dist/tui/user-message.d.ts +0 -1
  60. package/dist/tui/user-message.d.ts.map +1 -1
  61. package/dist/tui/user-message.js +5 -4
  62. package/dist/tui/user-message.js.map +1 -1
  63. package/package.json +6 -4
@@ -0,0 +1,470 @@
1
+ import * as fs from "node:fs";
2
+ import * as os from "node:os";
3
+ import * as path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { Type } from "@sinclair/typebox";
6
+ import { TypeCompiler } from "@sinclair/typebox/compiler";
7
+ import chalk from "chalk";
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
9
+ // ============================================================================
10
+ // Types & Schema
11
+ // ============================================================================
12
+ const ColorValueSchema = Type.Union([
13
+ Type.String(), // hex "#ff0000", var ref "primary", or empty ""
14
+ Type.Integer({ minimum: 0, maximum: 255 }), // 256-color index
15
+ ]);
16
+ const ThemeJsonSchema = Type.Object({
17
+ $schema: Type.Optional(Type.String()),
18
+ name: Type.String(),
19
+ vars: Type.Optional(Type.Record(Type.String(), ColorValueSchema)),
20
+ colors: Type.Object({
21
+ // Core UI (10 colors)
22
+ accent: ColorValueSchema,
23
+ border: ColorValueSchema,
24
+ borderAccent: ColorValueSchema,
25
+ borderMuted: ColorValueSchema,
26
+ success: ColorValueSchema,
27
+ error: ColorValueSchema,
28
+ warning: ColorValueSchema,
29
+ muted: ColorValueSchema,
30
+ dim: ColorValueSchema,
31
+ text: ColorValueSchema,
32
+ // Backgrounds & Content Text (7 colors)
33
+ userMessageBg: ColorValueSchema,
34
+ userMessageText: ColorValueSchema,
35
+ toolPendingBg: ColorValueSchema,
36
+ toolSuccessBg: ColorValueSchema,
37
+ toolErrorBg: ColorValueSchema,
38
+ toolTitle: ColorValueSchema,
39
+ toolOutput: ColorValueSchema,
40
+ // Markdown (10 colors)
41
+ mdHeading: ColorValueSchema,
42
+ mdLink: ColorValueSchema,
43
+ mdLinkUrl: ColorValueSchema,
44
+ mdCode: ColorValueSchema,
45
+ mdCodeBlock: ColorValueSchema,
46
+ mdCodeBlockBorder: ColorValueSchema,
47
+ mdQuote: ColorValueSchema,
48
+ mdQuoteBorder: ColorValueSchema,
49
+ mdHr: ColorValueSchema,
50
+ mdListBullet: ColorValueSchema,
51
+ // Tool Diffs (3 colors)
52
+ toolDiffAdded: ColorValueSchema,
53
+ toolDiffRemoved: ColorValueSchema,
54
+ toolDiffContext: ColorValueSchema,
55
+ // Syntax Highlighting (9 colors)
56
+ syntaxComment: ColorValueSchema,
57
+ syntaxKeyword: ColorValueSchema,
58
+ syntaxFunction: ColorValueSchema,
59
+ syntaxVariable: ColorValueSchema,
60
+ syntaxString: ColorValueSchema,
61
+ syntaxNumber: ColorValueSchema,
62
+ syntaxType: ColorValueSchema,
63
+ syntaxOperator: ColorValueSchema,
64
+ syntaxPunctuation: ColorValueSchema,
65
+ // Thinking Level Borders (5 colors)
66
+ thinkingOff: ColorValueSchema,
67
+ thinkingMinimal: ColorValueSchema,
68
+ thinkingLow: ColorValueSchema,
69
+ thinkingMedium: ColorValueSchema,
70
+ thinkingHigh: ColorValueSchema,
71
+ }),
72
+ });
73
+ const validateThemeJson = TypeCompiler.Compile(ThemeJsonSchema);
74
+ // ============================================================================
75
+ // Color Utilities
76
+ // ============================================================================
77
+ function detectColorMode() {
78
+ const colorterm = process.env.COLORTERM;
79
+ if (colorterm === "truecolor" || colorterm === "24bit") {
80
+ return "truecolor";
81
+ }
82
+ const term = process.env.TERM || "";
83
+ if (term.includes("256color")) {
84
+ return "256color";
85
+ }
86
+ return "256color";
87
+ }
88
+ function hexToRgb(hex) {
89
+ const cleaned = hex.replace("#", "");
90
+ if (cleaned.length !== 6) {
91
+ throw new Error(`Invalid hex color: ${hex}`);
92
+ }
93
+ const r = parseInt(cleaned.substring(0, 2), 16);
94
+ const g = parseInt(cleaned.substring(2, 4), 16);
95
+ const b = parseInt(cleaned.substring(4, 6), 16);
96
+ if (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {
97
+ throw new Error(`Invalid hex color: ${hex}`);
98
+ }
99
+ return { r, g, b };
100
+ }
101
+ function rgbTo256(r, g, b) {
102
+ const rIndex = Math.round((r / 255) * 5);
103
+ const gIndex = Math.round((g / 255) * 5);
104
+ const bIndex = Math.round((b / 255) * 5);
105
+ return 16 + 36 * rIndex + 6 * gIndex + bIndex;
106
+ }
107
+ function hexTo256(hex) {
108
+ const { r, g, b } = hexToRgb(hex);
109
+ return rgbTo256(r, g, b);
110
+ }
111
+ function fgAnsi(color, mode) {
112
+ if (color === "")
113
+ return "\x1b[39m";
114
+ if (typeof color === "number")
115
+ return `\x1b[38;5;${color}m`;
116
+ if (color.startsWith("#")) {
117
+ if (mode === "truecolor") {
118
+ const { r, g, b } = hexToRgb(color);
119
+ return `\x1b[38;2;${r};${g};${b}m`;
120
+ }
121
+ else {
122
+ const index = hexTo256(color);
123
+ return `\x1b[38;5;${index}m`;
124
+ }
125
+ }
126
+ throw new Error(`Invalid color value: ${color}`);
127
+ }
128
+ function bgAnsi(color, mode) {
129
+ if (color === "")
130
+ return "\x1b[49m";
131
+ if (typeof color === "number")
132
+ return `\x1b[48;5;${color}m`;
133
+ if (color.startsWith("#")) {
134
+ if (mode === "truecolor") {
135
+ const { r, g, b } = hexToRgb(color);
136
+ return `\x1b[48;2;${r};${g};${b}m`;
137
+ }
138
+ else {
139
+ const index = hexTo256(color);
140
+ return `\x1b[48;5;${index}m`;
141
+ }
142
+ }
143
+ throw new Error(`Invalid color value: ${color}`);
144
+ }
145
+ function resolveVarRefs(value, vars, visited = new Set()) {
146
+ if (typeof value === "number" || value === "" || value.startsWith("#")) {
147
+ return value;
148
+ }
149
+ if (visited.has(value)) {
150
+ throw new Error(`Circular variable reference detected: ${value}`);
151
+ }
152
+ if (!(value in vars)) {
153
+ throw new Error(`Variable reference not found: ${value}`);
154
+ }
155
+ visited.add(value);
156
+ return resolveVarRefs(vars[value], vars, visited);
157
+ }
158
+ function resolveThemeColors(colors, vars = {}) {
159
+ const resolved = {};
160
+ for (const [key, value] of Object.entries(colors)) {
161
+ resolved[key] = resolveVarRefs(value, vars);
162
+ }
163
+ return resolved;
164
+ }
165
+ // ============================================================================
166
+ // Theme Class
167
+ // ============================================================================
168
+ export class Theme {
169
+ fgColors;
170
+ bgColors;
171
+ mode;
172
+ constructor(fgColors, bgColors, mode) {
173
+ this.mode = mode;
174
+ this.fgColors = new Map();
175
+ for (const [key, value] of Object.entries(fgColors)) {
176
+ this.fgColors.set(key, fgAnsi(value, mode));
177
+ }
178
+ this.bgColors = new Map();
179
+ for (const [key, value] of Object.entries(bgColors)) {
180
+ this.bgColors.set(key, bgAnsi(value, mode));
181
+ }
182
+ }
183
+ fg(color, text) {
184
+ const ansi = this.fgColors.get(color);
185
+ if (!ansi)
186
+ throw new Error(`Unknown theme color: ${color}`);
187
+ return `${ansi}${text}\x1b[39m`; // Reset only foreground color
188
+ }
189
+ bg(color, text) {
190
+ const ansi = this.bgColors.get(color);
191
+ if (!ansi)
192
+ throw new Error(`Unknown theme background color: ${color}`);
193
+ return `${ansi}${text}\x1b[49m`; // Reset only background color
194
+ }
195
+ bold(text) {
196
+ return chalk.bold(text);
197
+ }
198
+ italic(text) {
199
+ return chalk.italic(text);
200
+ }
201
+ underline(text) {
202
+ return chalk.underline(text);
203
+ }
204
+ getFgAnsi(color) {
205
+ const ansi = this.fgColors.get(color);
206
+ if (!ansi)
207
+ throw new Error(`Unknown theme color: ${color}`);
208
+ return ansi;
209
+ }
210
+ getBgAnsi(color) {
211
+ const ansi = this.bgColors.get(color);
212
+ if (!ansi)
213
+ throw new Error(`Unknown theme background color: ${color}`);
214
+ return ansi;
215
+ }
216
+ getColorMode() {
217
+ return this.mode;
218
+ }
219
+ getThinkingBorderColor(level) {
220
+ // Map thinking levels to dedicated theme colors
221
+ switch (level) {
222
+ case "off":
223
+ return (str) => this.fg("thinkingOff", str);
224
+ case "minimal":
225
+ return (str) => this.fg("thinkingMinimal", str);
226
+ case "low":
227
+ return (str) => this.fg("thinkingLow", str);
228
+ case "medium":
229
+ return (str) => this.fg("thinkingMedium", str);
230
+ case "high":
231
+ return (str) => this.fg("thinkingHigh", str);
232
+ default:
233
+ return (str) => this.fg("thinkingOff", str);
234
+ }
235
+ }
236
+ }
237
+ // ============================================================================
238
+ // Theme Loading
239
+ // ============================================================================
240
+ let BUILTIN_THEMES;
241
+ function getBuiltinThemes() {
242
+ if (!BUILTIN_THEMES) {
243
+ const darkPath = path.join(__dirname, "dark.json");
244
+ const lightPath = path.join(__dirname, "light.json");
245
+ BUILTIN_THEMES = {
246
+ dark: JSON.parse(fs.readFileSync(darkPath, "utf-8")),
247
+ light: JSON.parse(fs.readFileSync(lightPath, "utf-8")),
248
+ };
249
+ }
250
+ return BUILTIN_THEMES;
251
+ }
252
+ function getThemesDir() {
253
+ return path.join(os.homedir(), ".pi", "agent", "themes");
254
+ }
255
+ export function getAvailableThemes() {
256
+ const themes = new Set(Object.keys(getBuiltinThemes()));
257
+ const themesDir = getThemesDir();
258
+ if (fs.existsSync(themesDir)) {
259
+ const files = fs.readdirSync(themesDir);
260
+ for (const file of files) {
261
+ if (file.endsWith(".json")) {
262
+ themes.add(file.slice(0, -5));
263
+ }
264
+ }
265
+ }
266
+ return Array.from(themes).sort();
267
+ }
268
+ function loadThemeJson(name) {
269
+ const builtinThemes = getBuiltinThemes();
270
+ if (name in builtinThemes) {
271
+ return builtinThemes[name];
272
+ }
273
+ const themesDir = getThemesDir();
274
+ const themePath = path.join(themesDir, `${name}.json`);
275
+ if (!fs.existsSync(themePath)) {
276
+ throw new Error(`Theme not found: ${name}`);
277
+ }
278
+ const content = fs.readFileSync(themePath, "utf-8");
279
+ let json;
280
+ try {
281
+ json = JSON.parse(content);
282
+ }
283
+ catch (error) {
284
+ throw new Error(`Failed to parse theme ${name}: ${error}`);
285
+ }
286
+ if (!validateThemeJson.Check(json)) {
287
+ const errors = Array.from(validateThemeJson.Errors(json));
288
+ const errorMessages = errors.map((e) => ` - ${e.path}: ${e.message}`).join("\n");
289
+ throw new Error(`Invalid theme ${name}:\n${errorMessages}`);
290
+ }
291
+ return json;
292
+ }
293
+ function createTheme(themeJson, mode) {
294
+ const colorMode = mode ?? detectColorMode();
295
+ const resolvedColors = resolveThemeColors(themeJson.colors, themeJson.vars);
296
+ const fgColors = {};
297
+ const bgColors = {};
298
+ const bgColorKeys = new Set(["userMessageBg", "toolPendingBg", "toolSuccessBg", "toolErrorBg"]);
299
+ for (const [key, value] of Object.entries(resolvedColors)) {
300
+ if (bgColorKeys.has(key)) {
301
+ bgColors[key] = value;
302
+ }
303
+ else {
304
+ fgColors[key] = value;
305
+ }
306
+ }
307
+ return new Theme(fgColors, bgColors, colorMode);
308
+ }
309
+ function loadTheme(name, mode) {
310
+ const themeJson = loadThemeJson(name);
311
+ return createTheme(themeJson, mode);
312
+ }
313
+ function detectTerminalBackground() {
314
+ const colorfgbg = process.env.COLORFGBG || "";
315
+ if (colorfgbg) {
316
+ const parts = colorfgbg.split(";");
317
+ if (parts.length >= 2) {
318
+ const bg = parseInt(parts[1], 10);
319
+ if (!Number.isNaN(bg)) {
320
+ const result = bg < 8 ? "dark" : "light";
321
+ return result;
322
+ }
323
+ }
324
+ }
325
+ return "dark";
326
+ }
327
+ function getDefaultTheme() {
328
+ return detectTerminalBackground();
329
+ }
330
+ // ============================================================================
331
+ // Global Theme Instance
332
+ // ============================================================================
333
+ export let theme;
334
+ let currentThemeName;
335
+ let themeWatcher;
336
+ let onThemeChangeCallback;
337
+ export function initTheme(themeName) {
338
+ const name = themeName ?? getDefaultTheme();
339
+ currentThemeName = name;
340
+ try {
341
+ theme = loadTheme(name);
342
+ startThemeWatcher();
343
+ }
344
+ catch (error) {
345
+ // Theme is invalid - fall back to dark theme silently
346
+ currentThemeName = "dark";
347
+ theme = loadTheme("dark");
348
+ // Don't start watcher for fallback theme
349
+ }
350
+ }
351
+ export function setTheme(name) {
352
+ currentThemeName = name;
353
+ try {
354
+ theme = loadTheme(name);
355
+ startThemeWatcher();
356
+ return { success: true };
357
+ }
358
+ catch (error) {
359
+ // Theme is invalid - fall back to dark theme
360
+ currentThemeName = "dark";
361
+ theme = loadTheme("dark");
362
+ // Don't start watcher for fallback theme
363
+ return {
364
+ success: false,
365
+ error: error instanceof Error ? error.message : String(error),
366
+ };
367
+ }
368
+ }
369
+ export function onThemeChange(callback) {
370
+ onThemeChangeCallback = callback;
371
+ }
372
+ function startThemeWatcher() {
373
+ // Stop existing watcher if any
374
+ if (themeWatcher) {
375
+ themeWatcher.close();
376
+ themeWatcher = undefined;
377
+ }
378
+ // Only watch if it's a custom theme (not built-in)
379
+ if (!currentThemeName || currentThemeName === "dark" || currentThemeName === "light") {
380
+ return;
381
+ }
382
+ const themesDir = getThemesDir();
383
+ const themeFile = path.join(themesDir, `${currentThemeName}.json`);
384
+ // Only watch if the file exists
385
+ if (!fs.existsSync(themeFile)) {
386
+ return;
387
+ }
388
+ try {
389
+ themeWatcher = fs.watch(themeFile, (eventType) => {
390
+ if (eventType === "change") {
391
+ // Debounce rapid changes
392
+ setTimeout(() => {
393
+ try {
394
+ // Reload the theme
395
+ theme = loadTheme(currentThemeName);
396
+ // Notify callback (to invalidate UI)
397
+ if (onThemeChangeCallback) {
398
+ onThemeChangeCallback();
399
+ }
400
+ }
401
+ catch (error) {
402
+ // Ignore errors (file might be in invalid state while being edited)
403
+ }
404
+ }, 100);
405
+ }
406
+ else if (eventType === "rename") {
407
+ // File was deleted or renamed - fall back to default theme
408
+ setTimeout(() => {
409
+ if (!fs.existsSync(themeFile)) {
410
+ currentThemeName = "dark";
411
+ theme = loadTheme("dark");
412
+ if (themeWatcher) {
413
+ themeWatcher.close();
414
+ themeWatcher = undefined;
415
+ }
416
+ if (onThemeChangeCallback) {
417
+ onThemeChangeCallback();
418
+ }
419
+ }
420
+ }, 100);
421
+ }
422
+ });
423
+ }
424
+ catch (error) {
425
+ // Ignore errors starting watcher
426
+ }
427
+ }
428
+ export function stopThemeWatcher() {
429
+ if (themeWatcher) {
430
+ themeWatcher.close();
431
+ themeWatcher = undefined;
432
+ }
433
+ }
434
+ // ============================================================================
435
+ // TUI Helpers
436
+ // ============================================================================
437
+ export function getMarkdownTheme() {
438
+ return {
439
+ heading: (text) => theme.fg("mdHeading", text),
440
+ link: (text) => theme.fg("mdLink", text),
441
+ linkUrl: (text) => theme.fg("mdLinkUrl", text),
442
+ code: (text) => theme.fg("mdCode", text),
443
+ codeBlock: (text) => theme.fg("mdCodeBlock", text),
444
+ codeBlockBorder: (text) => theme.fg("mdCodeBlockBorder", text),
445
+ quote: (text) => theme.fg("mdQuote", text),
446
+ quoteBorder: (text) => theme.fg("mdQuoteBorder", text),
447
+ hr: (text) => theme.fg("mdHr", text),
448
+ listBullet: (text) => theme.fg("mdListBullet", text),
449
+ bold: (text) => theme.bold(text),
450
+ italic: (text) => theme.italic(text),
451
+ underline: (text) => theme.underline(text),
452
+ strikethrough: (text) => chalk.strikethrough(text),
453
+ };
454
+ }
455
+ export function getSelectListTheme() {
456
+ return {
457
+ selectedPrefix: (text) => theme.fg("accent", text),
458
+ selectedText: (text) => theme.fg("accent", text),
459
+ description: (text) => theme.fg("muted", text),
460
+ scrollInfo: (text) => theme.fg("muted", text),
461
+ noMatch: (text) => theme.fg("muted", text),
462
+ };
463
+ }
464
+ export function getEditorTheme() {
465
+ return {
466
+ borderColor: (text) => theme.fg("borderMuted", text),
467
+ selectList: getSelectListTheme(),
468
+ };
469
+ }
470
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.js","sourceRoot":"","sources":["../../src/theme/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,OAAO,EAAe,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE/D,+EAA+E;AAC/E,iBAAiB;AACjB,+EAA+E;AAE/E,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC;IACnC,IAAI,CAAC,MAAM,EAAE,EAAE,gDAAgD;IAC/D,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,kBAAkB;CAC9D,CAAC,CAAC;AAIH,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC;IACnC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IACrC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;IACnB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AAC,KAAK,CAAC,aAAa,CAAC,IAAI,CAAC;KAC1D,CAAC;AAAA,CACF;AAED,MAAM,UAAU,kBAAkB,GAAoB;IACrD,OAAO;QACN,cAAc,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC;QAC1D,YAAY,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,IAAI,CAAC;QACxD,WAAW,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC;QACtD,UAAU,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC;QACrD,OAAO,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC;KAClD,CAAC;AAAA,CACF;AAED,MAAM,UAAU,cAAc,GAAgB;IAC7C,OAAO;QACN,WAAW,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,aAAa,EAAE,IAAI,CAAC;QAC5D,UAAU,EAAE,kBAAkB,EAAE;KAChC,CAAC;AAAA,CACF","sourcesContent":["import * as fs from \"node:fs\";\nimport * as os from \"node:os\";\nimport * as path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { EditorTheme, MarkdownTheme, SelectListTheme } from \"@mariozechner/pi-tui\";\nimport { type Static, Type } from \"@sinclair/typebox\";\nimport { TypeCompiler } from \"@sinclair/typebox/compiler\";\nimport chalk from \"chalk\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\n// ============================================================================\n// Types & Schema\n// ============================================================================\n\nconst ColorValueSchema = Type.Union([\n\tType.String(), // hex \"#ff0000\", var ref \"primary\", or empty \"\"\n\tType.Integer({ minimum: 0, maximum: 255 }), // 256-color index\n]);\n\ntype ColorValue = Static<typeof ColorValueSchema>;\n\nconst ThemeJsonSchema = Type.Object({\n\t$schema: Type.Optional(Type.String()),\n\tname: Type.String(),\n\tvars: Type.Optional(Type.Record(Type.String(), ColorValueSchema)),\n\tcolors: Type.Object({\n\t\t// Core UI (10 colors)\n\t\taccent: ColorValueSchema,\n\t\tborder: ColorValueSchema,\n\t\tborderAccent: ColorValueSchema,\n\t\tborderMuted: ColorValueSchema,\n\t\tsuccess: ColorValueSchema,\n\t\terror: ColorValueSchema,\n\t\twarning: ColorValueSchema,\n\t\tmuted: ColorValueSchema,\n\t\tdim: ColorValueSchema,\n\t\ttext: ColorValueSchema,\n\t\t// Backgrounds & Content Text (7 colors)\n\t\tuserMessageBg: ColorValueSchema,\n\t\tuserMessageText: ColorValueSchema,\n\t\ttoolPendingBg: ColorValueSchema,\n\t\ttoolSuccessBg: ColorValueSchema,\n\t\ttoolErrorBg: ColorValueSchema,\n\t\ttoolTitle: ColorValueSchema,\n\t\ttoolOutput: ColorValueSchema,\n\t\t// Markdown (10 colors)\n\t\tmdHeading: ColorValueSchema,\n\t\tmdLink: ColorValueSchema,\n\t\tmdLinkUrl: ColorValueSchema,\n\t\tmdCode: ColorValueSchema,\n\t\tmdCodeBlock: ColorValueSchema,\n\t\tmdCodeBlockBorder: ColorValueSchema,\n\t\tmdQuote: ColorValueSchema,\n\t\tmdQuoteBorder: ColorValueSchema,\n\t\tmdHr: ColorValueSchema,\n\t\tmdListBullet: ColorValueSchema,\n\t\t// Tool Diffs (3 colors)\n\t\ttoolDiffAdded: ColorValueSchema,\n\t\ttoolDiffRemoved: ColorValueSchema,\n\t\ttoolDiffContext: ColorValueSchema,\n\t\t// Syntax Highlighting (9 colors)\n\t\tsyntaxComment: ColorValueSchema,\n\t\tsyntaxKeyword: ColorValueSchema,\n\t\tsyntaxFunction: ColorValueSchema,\n\t\tsyntaxVariable: ColorValueSchema,\n\t\tsyntaxString: ColorValueSchema,\n\t\tsyntaxNumber: ColorValueSchema,\n\t\tsyntaxType: ColorValueSchema,\n\t\tsyntaxOperator: ColorValueSchema,\n\t\tsyntaxPunctuation: ColorValueSchema,\n\t\t// Thinking Level Borders (5 colors)\n\t\tthinkingOff: ColorValueSchema,\n\t\tthinkingMinimal: ColorValueSchema,\n\t\tthinkingLow: ColorValueSchema,\n\t\tthinkingMedium: ColorValueSchema,\n\t\tthinkingHigh: ColorValueSchema,\n\t}),\n});\n\ntype ThemeJson = Static<typeof ThemeJsonSchema>;\n\nconst validateThemeJson = TypeCompiler.Compile(ThemeJsonSchema);\n\nexport type ThemeColor =\n\t| \"accent\"\n\t| \"border\"\n\t| \"borderAccent\"\n\t| \"borderMuted\"\n\t| \"success\"\n\t| \"error\"\n\t| \"warning\"\n\t| \"muted\"\n\t| \"dim\"\n\t| \"text\"\n\t| \"userMessageText\"\n\t| \"toolTitle\"\n\t| \"toolOutput\"\n\t| \"mdHeading\"\n\t| \"mdLink\"\n\t| \"mdLinkUrl\"\n\t| \"mdCode\"\n\t| \"mdCodeBlock\"\n\t| \"mdCodeBlockBorder\"\n\t| \"mdQuote\"\n\t| \"mdQuoteBorder\"\n\t| \"mdHr\"\n\t| \"mdListBullet\"\n\t| \"toolDiffAdded\"\n\t| \"toolDiffRemoved\"\n\t| \"toolDiffContext\"\n\t| \"syntaxComment\"\n\t| \"syntaxKeyword\"\n\t| \"syntaxFunction\"\n\t| \"syntaxVariable\"\n\t| \"syntaxString\"\n\t| \"syntaxNumber\"\n\t| \"syntaxType\"\n\t| \"syntaxOperator\"\n\t| \"syntaxPunctuation\"\n\t| \"thinkingOff\"\n\t| \"thinkingMinimal\"\n\t| \"thinkingLow\"\n\t| \"thinkingMedium\"\n\t| \"thinkingHigh\";\n\nexport type ThemeBg = \"userMessageBg\" | \"toolPendingBg\" | \"toolSuccessBg\" | \"toolErrorBg\";\n\ntype ColorMode = \"truecolor\" | \"256color\";\n\n// ============================================================================\n// Color Utilities\n// ============================================================================\n\nfunction detectColorMode(): ColorMode {\n\tconst colorterm = process.env.COLORTERM;\n\tif (colorterm === \"truecolor\" || colorterm === \"24bit\") {\n\t\treturn \"truecolor\";\n\t}\n\tconst term = process.env.TERM || \"\";\n\tif (term.includes(\"256color\")) {\n\t\treturn \"256color\";\n\t}\n\treturn \"256color\";\n}\n\nfunction hexToRgb(hex: string): { r: number; g: number; b: number } {\n\tconst cleaned = hex.replace(\"#\", \"\");\n\tif (cleaned.length !== 6) {\n\t\tthrow new Error(`Invalid hex color: ${hex}`);\n\t}\n\tconst r = parseInt(cleaned.substring(0, 2), 16);\n\tconst g = parseInt(cleaned.substring(2, 4), 16);\n\tconst b = parseInt(cleaned.substring(4, 6), 16);\n\tif (Number.isNaN(r) || Number.isNaN(g) || Number.isNaN(b)) {\n\t\tthrow new Error(`Invalid hex color: ${hex}`);\n\t}\n\treturn { r, g, b };\n}\n\nfunction rgbTo256(r: number, g: number, b: number): number {\n\tconst rIndex = Math.round((r / 255) * 5);\n\tconst gIndex = Math.round((g / 255) * 5);\n\tconst bIndex = Math.round((b / 255) * 5);\n\treturn 16 + 36 * rIndex + 6 * gIndex + bIndex;\n}\n\nfunction hexTo256(hex: string): number {\n\tconst { r, g, b } = hexToRgb(hex);\n\treturn rgbTo256(r, g, b);\n}\n\nfunction fgAnsi(color: string | number, mode: ColorMode): string {\n\tif (color === \"\") return \"\\x1b[39m\";\n\tif (typeof color === \"number\") return `\\x1b[38;5;${color}m`;\n\tif (color.startsWith(\"#\")) {\n\t\tif (mode === \"truecolor\") {\n\t\t\tconst { r, g, b } = hexToRgb(color);\n\t\t\treturn `\\x1b[38;2;${r};${g};${b}m`;\n\t\t} else {\n\t\t\tconst index = hexTo256(color);\n\t\t\treturn `\\x1b[38;5;${index}m`;\n\t\t}\n\t}\n\tthrow new Error(`Invalid color value: ${color}`);\n}\n\nfunction bgAnsi(color: string | number, mode: ColorMode): string {\n\tif (color === \"\") return \"\\x1b[49m\";\n\tif (typeof color === \"number\") return `\\x1b[48;5;${color}m`;\n\tif (color.startsWith(\"#\")) {\n\t\tif (mode === \"truecolor\") {\n\t\t\tconst { r, g, b } = hexToRgb(color);\n\t\t\treturn `\\x1b[48;2;${r};${g};${b}m`;\n\t\t} else {\n\t\t\tconst index = hexTo256(color);\n\t\t\treturn `\\x1b[48;5;${index}m`;\n\t\t}\n\t}\n\tthrow new Error(`Invalid color value: ${color}`);\n}\n\nfunction resolveVarRefs(\n\tvalue: ColorValue,\n\tvars: Record<string, ColorValue>,\n\tvisited = new Set<string>(),\n): string | number {\n\tif (typeof value === \"number\" || value === \"\" || value.startsWith(\"#\")) {\n\t\treturn value;\n\t}\n\tif (visited.has(value)) {\n\t\tthrow new Error(`Circular variable reference detected: ${value}`);\n\t}\n\tif (!(value in vars)) {\n\t\tthrow new Error(`Variable reference not found: ${value}`);\n\t}\n\tvisited.add(value);\n\treturn resolveVarRefs(vars[value], vars, visited);\n}\n\nfunction resolveThemeColors<T extends Record<string, ColorValue>>(\n\tcolors: T,\n\tvars: Record<string, ColorValue> = {},\n): Record<keyof T, string | number> {\n\tconst resolved: Record<string, string | number> = {};\n\tfor (const [key, value] of Object.entries(colors)) {\n\t\tresolved[key] = resolveVarRefs(value, vars);\n\t}\n\treturn resolved as Record<keyof T, string | number>;\n}\n\n// ============================================================================\n// Theme Class\n// ============================================================================\n\nexport class Theme {\n\tprivate fgColors: Map<ThemeColor, string>;\n\tprivate bgColors: Map<ThemeBg, string>;\n\tprivate mode: ColorMode;\n\n\tconstructor(\n\t\tfgColors: Record<ThemeColor, string | number>,\n\t\tbgColors: Record<ThemeBg, string | number>,\n\t\tmode: ColorMode,\n\t) {\n\t\tthis.mode = mode;\n\t\tthis.fgColors = new Map();\n\t\tfor (const [key, value] of Object.entries(fgColors) as [ThemeColor, string | number][]) {\n\t\t\tthis.fgColors.set(key, fgAnsi(value, mode));\n\t\t}\n\t\tthis.bgColors = new Map();\n\t\tfor (const [key, value] of Object.entries(bgColors) as [ThemeBg, string | number][]) {\n\t\t\tthis.bgColors.set(key, bgAnsi(value, mode));\n\t\t}\n\t}\n\n\tfg(color: ThemeColor, text: string): string {\n\t\tconst ansi = this.fgColors.get(color);\n\t\tif (!ansi) throw new Error(`Unknown theme color: ${color}`);\n\t\treturn `${ansi}${text}\\x1b[39m`; // Reset only foreground color\n\t}\n\n\tbg(color: ThemeBg, text: string): string {\n\t\tconst ansi = this.bgColors.get(color);\n\t\tif (!ansi) throw new Error(`Unknown theme background color: ${color}`);\n\t\treturn `${ansi}${text}\\x1b[49m`; // Reset only background color\n\t}\n\n\tbold(text: string): string {\n\t\treturn chalk.bold(text);\n\t}\n\n\titalic(text: string): string {\n\t\treturn chalk.italic(text);\n\t}\n\n\tunderline(text: string): string {\n\t\treturn chalk.underline(text);\n\t}\n\n\tgetFgAnsi(color: ThemeColor): string {\n\t\tconst ansi = this.fgColors.get(color);\n\t\tif (!ansi) throw new Error(`Unknown theme color: ${color}`);\n\t\treturn ansi;\n\t}\n\n\tgetBgAnsi(color: ThemeBg): string {\n\t\tconst ansi = this.bgColors.get(color);\n\t\tif (!ansi) throw new Error(`Unknown theme background color: ${color}`);\n\t\treturn ansi;\n\t}\n\n\tgetColorMode(): ColorMode {\n\t\treturn this.mode;\n\t}\n\n\tgetThinkingBorderColor(level: \"off\" | \"minimal\" | \"low\" | \"medium\" | \"high\"): (str: string) => string {\n\t\t// Map thinking levels to dedicated theme colors\n\t\tswitch (level) {\n\t\t\tcase \"off\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingOff\", str);\n\t\t\tcase \"minimal\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingMinimal\", str);\n\t\t\tcase \"low\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingLow\", str);\n\t\t\tcase \"medium\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingMedium\", str);\n\t\t\tcase \"high\":\n\t\t\t\treturn (str: string) => this.fg(\"thinkingHigh\", str);\n\t\t\tdefault:\n\t\t\t\treturn (str: string) => this.fg(\"thinkingOff\", str);\n\t\t}\n\t}\n}\n\n// ============================================================================\n// Theme Loading\n// ============================================================================\n\nlet BUILTIN_THEMES: Record<string, ThemeJson> | undefined;\n\nfunction getBuiltinThemes(): Record<string, ThemeJson> {\n\tif (!BUILTIN_THEMES) {\n\t\tconst darkPath = path.join(__dirname, \"dark.json\");\n\t\tconst lightPath = path.join(__dirname, \"light.json\");\n\t\tBUILTIN_THEMES = {\n\t\t\tdark: JSON.parse(fs.readFileSync(darkPath, \"utf-8\")) as ThemeJson,\n\t\t\tlight: JSON.parse(fs.readFileSync(lightPath, \"utf-8\")) as ThemeJson,\n\t\t};\n\t}\n\treturn BUILTIN_THEMES;\n}\n\nfunction getThemesDir(): string {\n\treturn path.join(os.homedir(), \".pi\", \"agent\", \"themes\");\n}\n\nexport function getAvailableThemes(): string[] {\n\tconst themes = new Set<string>(Object.keys(getBuiltinThemes()));\n\tconst themesDir = getThemesDir();\n\tif (fs.existsSync(themesDir)) {\n\t\tconst files = fs.readdirSync(themesDir);\n\t\tfor (const file of files) {\n\t\t\tif (file.endsWith(\".json\")) {\n\t\t\t\tthemes.add(file.slice(0, -5));\n\t\t\t}\n\t\t}\n\t}\n\treturn Array.from(themes).sort();\n}\n\nfunction loadThemeJson(name: string): ThemeJson {\n\tconst builtinThemes = getBuiltinThemes();\n\tif (name in builtinThemes) {\n\t\treturn builtinThemes[name];\n\t}\n\tconst themesDir = getThemesDir();\n\tconst themePath = path.join(themesDir, `${name}.json`);\n\tif (!fs.existsSync(themePath)) {\n\t\tthrow new Error(`Theme not found: ${name}`);\n\t}\n\tconst content = fs.readFileSync(themePath, \"utf-8\");\n\tlet json: unknown;\n\ttry {\n\t\tjson = JSON.parse(content);\n\t} catch (error) {\n\t\tthrow new Error(`Failed to parse theme ${name}: ${error}`);\n\t}\n\tif (!validateThemeJson.Check(json)) {\n\t\tconst errors = Array.from(validateThemeJson.Errors(json));\n\t\tconst errorMessages = errors.map((e) => ` - ${e.path}: ${e.message}`).join(\"\\n\");\n\t\tthrow new Error(`Invalid theme ${name}:\\n${errorMessages}`);\n\t}\n\treturn json as ThemeJson;\n}\n\nfunction createTheme(themeJson: ThemeJson, mode?: ColorMode): Theme {\n\tconst colorMode = mode ?? detectColorMode();\n\tconst resolvedColors = resolveThemeColors(themeJson.colors, themeJson.vars);\n\tconst fgColors: Record<ThemeColor, string | number> = {} as Record<ThemeColor, string | number>;\n\tconst bgColors: Record<ThemeBg, string | number> = {} as Record<ThemeBg, string | number>;\n\tconst bgColorKeys: Set<string> = new Set([\"userMessageBg\", \"toolPendingBg\", \"toolSuccessBg\", \"toolErrorBg\"]);\n\tfor (const [key, value] of Object.entries(resolvedColors)) {\n\t\tif (bgColorKeys.has(key)) {\n\t\t\tbgColors[key as ThemeBg] = value;\n\t\t} else {\n\t\t\tfgColors[key as ThemeColor] = value;\n\t\t}\n\t}\n\treturn new Theme(fgColors, bgColors, colorMode);\n}\n\nfunction loadTheme(name: string, mode?: ColorMode): Theme {\n\tconst themeJson = loadThemeJson(name);\n\treturn createTheme(themeJson, mode);\n}\n\nfunction detectTerminalBackground(): \"dark\" | \"light\" {\n\tconst colorfgbg = process.env.COLORFGBG || \"\";\n\tif (colorfgbg) {\n\t\tconst parts = colorfgbg.split(\";\");\n\t\tif (parts.length >= 2) {\n\t\t\tconst bg = parseInt(parts[1], 10);\n\t\t\tif (!Number.isNaN(bg)) {\n\t\t\t\tconst result = bg < 8 ? \"dark\" : \"light\";\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\t}\n\treturn \"dark\";\n}\n\nfunction getDefaultTheme(): string {\n\treturn detectTerminalBackground();\n}\n\n// ============================================================================\n// Global Theme Instance\n// ============================================================================\n\nexport let theme: Theme;\nlet currentThemeName: string | undefined;\nlet themeWatcher: fs.FSWatcher | undefined;\nlet onThemeChangeCallback: (() => void) | undefined;\n\nexport function initTheme(themeName?: string): void {\n\tconst name = themeName ?? getDefaultTheme();\n\tcurrentThemeName = name;\n\ttry {\n\t\ttheme = loadTheme(name);\n\t\tstartThemeWatcher();\n\t} catch (error) {\n\t\t// Theme is invalid - fall back to dark theme silently\n\t\tcurrentThemeName = \"dark\";\n\t\ttheme = loadTheme(\"dark\");\n\t\t// Don't start watcher for fallback theme\n\t}\n}\n\nexport function setTheme(name: string): { success: boolean; error?: string } {\n\tcurrentThemeName = name;\n\ttry {\n\t\ttheme = loadTheme(name);\n\t\tstartThemeWatcher();\n\t\treturn { success: true };\n\t} catch (error) {\n\t\t// Theme is invalid - fall back to dark theme\n\t\tcurrentThemeName = \"dark\";\n\t\ttheme = loadTheme(\"dark\");\n\t\t// Don't start watcher for fallback theme\n\t\treturn {\n\t\t\tsuccess: false,\n\t\t\terror: error instanceof Error ? error.message : String(error),\n\t\t};\n\t}\n}\n\nexport function onThemeChange(callback: () => void): void {\n\tonThemeChangeCallback = callback;\n}\n\nfunction startThemeWatcher(): void {\n\t// Stop existing watcher if any\n\tif (themeWatcher) {\n\t\tthemeWatcher.close();\n\t\tthemeWatcher = undefined;\n\t}\n\n\t// Only watch if it's a custom theme (not built-in)\n\tif (!currentThemeName || currentThemeName === \"dark\" || currentThemeName === \"light\") {\n\t\treturn;\n\t}\n\n\tconst themesDir = getThemesDir();\n\tconst themeFile = path.join(themesDir, `${currentThemeName}.json`);\n\n\t// Only watch if the file exists\n\tif (!fs.existsSync(themeFile)) {\n\t\treturn;\n\t}\n\n\ttry {\n\t\tthemeWatcher = fs.watch(themeFile, (eventType) => {\n\t\t\tif (eventType === \"change\") {\n\t\t\t\t// Debounce rapid changes\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// Reload the theme\n\t\t\t\t\t\ttheme = loadTheme(currentThemeName!);\n\t\t\t\t\t\t// Notify callback (to invalidate UI)\n\t\t\t\t\t\tif (onThemeChangeCallback) {\n\t\t\t\t\t\t\tonThemeChangeCallback();\n\t\t\t\t\t\t}\n\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t// Ignore errors (file might be in invalid state while being edited)\n\t\t\t\t\t}\n\t\t\t\t}, 100);\n\t\t\t} else if (eventType === \"rename\") {\n\t\t\t\t// File was deleted or renamed - fall back to default theme\n\t\t\t\tsetTimeout(() => {\n\t\t\t\t\tif (!fs.existsSync(themeFile)) {\n\t\t\t\t\t\tcurrentThemeName = \"dark\";\n\t\t\t\t\t\ttheme = loadTheme(\"dark\");\n\t\t\t\t\t\tif (themeWatcher) {\n\t\t\t\t\t\t\tthemeWatcher.close();\n\t\t\t\t\t\t\tthemeWatcher = undefined;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (onThemeChangeCallback) {\n\t\t\t\t\t\t\tonThemeChangeCallback();\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}, 100);\n\t\t\t}\n\t\t});\n\t} catch (error) {\n\t\t// Ignore errors starting watcher\n\t}\n}\n\nexport function stopThemeWatcher(): void {\n\tif (themeWatcher) {\n\t\tthemeWatcher.close();\n\t\tthemeWatcher = undefined;\n\t}\n}\n\n// ============================================================================\n// TUI Helpers\n// ============================================================================\n\nexport function getMarkdownTheme(): MarkdownTheme {\n\treturn {\n\t\theading: (text: string) => theme.fg(\"mdHeading\", text),\n\t\tlink: (text: string) => theme.fg(\"mdLink\", text),\n\t\tlinkUrl: (text: string) => theme.fg(\"mdLinkUrl\", text),\n\t\tcode: (text: string) => theme.fg(\"mdCode\", text),\n\t\tcodeBlock: (text: string) => theme.fg(\"mdCodeBlock\", text),\n\t\tcodeBlockBorder: (text: string) => theme.fg(\"mdCodeBlockBorder\", text),\n\t\tquote: (text: string) => theme.fg(\"mdQuote\", text),\n\t\tquoteBorder: (text: string) => theme.fg(\"mdQuoteBorder\", text),\n\t\thr: (text: string) => theme.fg(\"mdHr\", text),\n\t\tlistBullet: (text: string) => theme.fg(\"mdListBullet\", text),\n\t\tbold: (text: string) => theme.bold(text),\n\t\titalic: (text: string) => theme.italic(text),\n\t\tunderline: (text: string) => theme.underline(text),\n\t\tstrikethrough: (text: string) => chalk.strikethrough(text),\n\t};\n}\n\nexport function getSelectListTheme(): SelectListTheme {\n\treturn {\n\t\tselectedPrefix: (text: string) => theme.fg(\"accent\", text),\n\t\tselectedText: (text: string) => theme.fg(\"accent\", text),\n\t\tdescription: (text: string) => theme.fg(\"muted\", text),\n\t\tscrollInfo: (text: string) => theme.fg(\"muted\", text),\n\t\tnoMatch: (text: string) => theme.fg(\"muted\", text),\n\t};\n}\n\nexport function getEditorTheme(): EditorTheme {\n\treturn {\n\t\tborderColor: (text: string) => theme.fg(\"borderMuted\", text),\n\t\tselectList: getSelectListTheme(),\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../src/tui/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAA0B,MAAM,sBAAsB,CAAC;AAGzE;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,gBAAgB,CAAY;IAEpC,YAAY,OAAO,CAAC,EAAE,gBAAgB,EAUrC;IAED,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CA4C7C;CACD","sourcesContent":["import type { AssistantMessage } from \"@mariozechner/pi-ai\";\nimport { Container, Markdown, Spacer, Text } from \"@mariozechner/pi-tui\";\nimport chalk from \"chalk\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\n\tconstructor(message?: AssistantMessage) {\n\t\tsuper();\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\tupdateContent(message: AssistantMessage): void {\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tif (\n\t\t\tmessage.content.length > 0 &&\n\t\t\tmessage.content.some(\n\t\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t\t)\n\t\t) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (const content of message.content) {\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0));\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\t// Thinking traces in dark gray italic\n\t\t\t\t// Use Markdown component with default text style for consistent styling\n\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\tnew Markdown(content.thinking.trim(), 1, 0, {\n\t\t\t\t\t\tcolor: \"gray\",\n\t\t\t\t\t\titalic: true,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t}\n\n\t\t// Check if aborted - show after partial content\n\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tif (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tthis.contentContainer.addChild(new Text(chalk.red(\"\\nAborted\"), 1, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(chalk.red(`Error: ${errorMsg}`), 1, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"assistant-message.d.ts","sourceRoot":"","sources":["../../src/tui/assistant-message.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAA0B,MAAM,sBAAsB,CAAC;AAGzE;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,SAAS;IACvD,OAAO,CAAC,gBAAgB,CAAY;IAEpC,YAAY,OAAO,CAAC,EAAE,gBAAgB,EAUrC;IAED,aAAa,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CA4C7C;CACD","sourcesContent":["import type { AssistantMessage } from \"@mariozechner/pi-ai\";\nimport { Container, Markdown, Spacer, Text } from \"@mariozechner/pi-tui\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.js\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\n\tconstructor(message?: AssistantMessage) {\n\t\tsuper();\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\tupdateContent(message: AssistantMessage): void {\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tif (\n\t\t\tmessage.content.length > 0 &&\n\t\t\tmessage.content.some(\n\t\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t\t)\n\t\t) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (const content of message.content) {\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0, getMarkdownTheme()));\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\t// Thinking traces in muted color, italic\n\t\t\t\t// Use Markdown component with default text style for consistent styling\n\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\tnew Markdown(content.thinking.trim(), 1, 0, getMarkdownTheme(), {\n\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"muted\", text),\n\t\t\t\t\t\titalic: true,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t}\n\n\t\t// Check if aborted - show after partial content\n\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tif (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", \"\\nAborted\"), 1, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), 1, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { Container, Markdown, Spacer, Text } from "@mariozechner/pi-tui";
2
- import chalk from "chalk";
2
+ import { getMarkdownTheme, theme } from "../theme/theme.js";
3
3
  /**
4
4
  * Component that renders a complete assistant message
5
5
  */
@@ -26,13 +26,13 @@ export class AssistantMessageComponent extends Container {
26
26
  if (content.type === "text" && content.text.trim()) {
27
27
  // Assistant text messages with no background - trim the text
28
28
  // Set paddingY=0 to avoid extra spacing before tool executions
29
- this.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0));
29
+ this.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0, getMarkdownTheme()));
30
30
  }
31
31
  else if (content.type === "thinking" && content.thinking.trim()) {
32
- // Thinking traces in dark gray italic
32
+ // Thinking traces in muted color, italic
33
33
  // Use Markdown component with default text style for consistent styling
34
- this.contentContainer.addChild(new Markdown(content.thinking.trim(), 1, 0, {
35
- color: "gray",
34
+ this.contentContainer.addChild(new Markdown(content.thinking.trim(), 1, 0, getMarkdownTheme(), {
35
+ color: (text) => theme.fg("muted", text),
36
36
  italic: true,
37
37
  }));
38
38
  this.contentContainer.addChild(new Spacer(1));
@@ -43,12 +43,12 @@ export class AssistantMessageComponent extends Container {
43
43
  const hasToolCalls = message.content.some((c) => c.type === "toolCall");
44
44
  if (!hasToolCalls) {
45
45
  if (message.stopReason === "aborted") {
46
- this.contentContainer.addChild(new Text(chalk.red("\nAborted"), 1, 0));
46
+ this.contentContainer.addChild(new Text(theme.fg("error", "\nAborted"), 1, 0));
47
47
  }
48
48
  else if (message.stopReason === "error") {
49
49
  const errorMsg = message.errorMessage || "Unknown error";
50
50
  this.contentContainer.addChild(new Spacer(1));
51
- this.contentContainer.addChild(new Text(chalk.red(`Error: ${errorMsg}`), 1, 0));
51
+ this.contentContainer.addChild(new Text(theme.fg("error", `Error: ${errorMsg}`), 1, 0));
52
52
  }
53
53
  }
54
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../src/tui/assistant-message.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;GAEG;AACH,MAAM,OAAO,yBAA0B,SAAQ,SAAS;IAC/C,gBAAgB,CAAY;IAEpC,YAAY,OAA0B,EAAE;QACvC,KAAK,EAAE,CAAC;QAER,sCAAsC;QACtC,IAAI,CAAC,gBAAgB,GAAG,IAAI,SAAS,EAAE,CAAC;QACxC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;QAErC,IAAI,OAAO,EAAE,CAAC;YACb,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;IAAA,CACD;IAED,aAAa,CAAC,OAAyB,EAAQ;QAC9C,0BAA0B;QAC1B,IAAI,CAAC,gBAAgB,CAAC,KAAK,EAAE,CAAC;QAE9B,IACC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC;Y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AO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;QACxE,IAAI,CAAC,YAAY,EAAE,CAAC;YACnB,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;gBACtC,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACxE,CAAC;iBAAM,IAAI,OAAO,CAAC,UAAU,KAAK,OAAO,EAAE,CAAC;gBAC3C,MAAM,QAAQ,GAAG,OAAO,CAAC,YAAY,IAAI,eAAe,CAAC;gBACzD,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9C,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,UAAU,QAAQ,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACjF,CAAC;QACF,CAAC;IAAA,CACD;CACD","sourcesContent":["import type { AssistantMessage } from \"@mariozechner/pi-ai\";\nimport { Container, Markdown, Spacer, Text } from \"@mariozechner/pi-tui\";\nimport chalk from \"chalk\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\n\tconstructor(message?: AssistantMessage) {\n\t\tsuper();\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\tupdateContent(message: AssistantMessage): void {\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tif (\n\t\t\tmessage.content.length > 0 &&\n\t\t\tmessage.content.some(\n\t\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t\t)\n\t\t) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (const content of message.content) {\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0));\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\t// Thinking traces in dark gray italic\n\t\t\t\t// Use Markdown component with default text style for consistent styling\n\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\tnew Markdown(content.thinking.trim(), 1, 0, {\n\t\t\t\t\t\tcolor: \"gray\",\n\t\t\t\t\t\titalic: true,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t}\n\n\t\t// Check if aborted - show after partial content\n\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tif (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tthis.contentContainer.addChild(new Text(chalk.red(\"\\nAborted\"), 1, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(chalk.red(`Error: ${errorMsg}`), 1, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"assistant-message.js","sourceRoot":"","sources":["../../src/tui/assistant-message.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE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AAC,CAAC,CAAC;gBAC9C,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,QAAQ,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACzF,CAAC;QACF,CAAC;IAAA,CACD;CACD","sourcesContent":["import type { AssistantMessage } from \"@mariozechner/pi-ai\";\nimport { Container, Markdown, Spacer, Text } from \"@mariozechner/pi-tui\";\nimport { getMarkdownTheme, theme } from \"../theme/theme.js\";\n\n/**\n * Component that renders a complete assistant message\n */\nexport class AssistantMessageComponent extends Container {\n\tprivate contentContainer: Container;\n\n\tconstructor(message?: AssistantMessage) {\n\t\tsuper();\n\n\t\t// Container for text/thinking content\n\t\tthis.contentContainer = new Container();\n\t\tthis.addChild(this.contentContainer);\n\n\t\tif (message) {\n\t\t\tthis.updateContent(message);\n\t\t}\n\t}\n\n\tupdateContent(message: AssistantMessage): void {\n\t\t// Clear content container\n\t\tthis.contentContainer.clear();\n\n\t\tif (\n\t\t\tmessage.content.length > 0 &&\n\t\t\tmessage.content.some(\n\t\t\t\t(c) => (c.type === \"text\" && c.text.trim()) || (c.type === \"thinking\" && c.thinking.trim()),\n\t\t\t)\n\t\t) {\n\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t}\n\n\t\t// Render content in order\n\t\tfor (const content of message.content) {\n\t\t\tif (content.type === \"text\" && content.text.trim()) {\n\t\t\t\t// Assistant text messages with no background - trim the text\n\t\t\t\t// Set paddingY=0 to avoid extra spacing before tool executions\n\t\t\t\tthis.contentContainer.addChild(new Markdown(content.text.trim(), 1, 0, getMarkdownTheme()));\n\t\t\t} else if (content.type === \"thinking\" && content.thinking.trim()) {\n\t\t\t\t// Thinking traces in muted color, italic\n\t\t\t\t// Use Markdown component with default text style for consistent styling\n\t\t\t\tthis.contentContainer.addChild(\n\t\t\t\t\tnew Markdown(content.thinking.trim(), 1, 0, getMarkdownTheme(), {\n\t\t\t\t\t\tcolor: (text: string) => theme.fg(\"muted\", text),\n\t\t\t\t\t\titalic: true,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t}\n\t\t}\n\n\t\t// Check if aborted - show after partial content\n\t\t// But only if there are no tool calls (tool execution components will show the error)\n\t\tconst hasToolCalls = message.content.some((c) => c.type === \"toolCall\");\n\t\tif (!hasToolCalls) {\n\t\t\tif (message.stopReason === \"aborted\") {\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", \"\\nAborted\"), 1, 0));\n\t\t\t} else if (message.stopReason === \"error\") {\n\t\t\t\tconst errorMsg = message.errorMessage || \"Unknown error\";\n\t\t\t\tthis.contentContainer.addChild(new Spacer(1));\n\t\t\t\tthis.contentContainer.addChild(new Text(theme.fg(\"error\", `Error: ${errorMsg}`), 1, 0));\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -5,6 +5,7 @@ import type { Component } from "@mariozechner/pi-tui";
5
5
  export declare class DynamicBorder implements Component {
6
6
  private color;
7
7
  constructor(color?: (str: string) => string);
8
+ invalidate(): void;
8
9
  render(width: number): string[];
9
10
  }
10
11
  //# sourceMappingURL=dynamic-border.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic-border.d.ts","sourceRoot":"","sources":["../../src/tui/dynamic-border.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD;;GAEG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC9C,OAAO,CAAC,KAAK,CAA0B;IAEvC,YAAY,KAAK,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAmB,EAEtD;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9B;CACD","sourcesContent":["import type { Component } from \"@mariozechner/pi-tui\";\nimport chalk from \"chalk\";\n\n/**\n * Dynamic border component that adjusts to viewport width\n */\nexport class DynamicBorder implements Component {\n\tprivate color: (str: string) => string;\n\n\tconstructor(color: (str: string) => string = chalk.blue) {\n\t\tthis.color = color;\n\t}\n\n\trender(width: number): string[] {\n\t\treturn [this.color(\"─\".repeat(Math.max(1, width)))];\n\t}\n}\n"]}
1
+ {"version":3,"file":"dynamic-border.d.ts","sourceRoot":"","sources":["../../src/tui/dynamic-border.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGtD;;GAEG;AACH,qBAAa,aAAc,YAAW,SAAS;IAC9C,OAAO,CAAC,KAAK,CAA0B;IAEvC,YAAY,KAAK,GAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAyC,EAE5E;IAED,UAAU,IAAI,IAAI,CAEjB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAE9B;CACD","sourcesContent":["import type { Component } from \"@mariozechner/pi-tui\";\nimport { theme } from \"../theme/theme.js\";\n\n/**\n * Dynamic border component that adjusts to viewport width\n */\nexport class DynamicBorder implements Component {\n\tprivate color: (str: string) => string;\n\n\tconstructor(color: (str: string) => string = (str) => theme.fg(\"border\", str)) {\n\t\tthis.color = color;\n\t}\n\n\tinvalidate(): void {\n\t\t// No cached state to invalidate currently\n\t}\n\n\trender(width: number): string[] {\n\t\treturn [this.color(\"─\".repeat(Math.max(1, width)))];\n\t}\n}\n"]}