pal-code 0.0.13 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/packages/cli/src/components/assistant-body.ts +107 -8
- package/packages/cli/src/components/permission-prompt.ts +35 -19
- package/packages/cli/src/components/sidebar.ts +39 -22
- package/packages/cli/src/index.ts +456 -51
- package/packages/cli/src/overlays/model-picker.ts +6 -6
- package/packages/cli/src/overlays/session-picker.ts +6 -6
- package/packages/cli/src/state.ts +34 -0
- package/packages/cli/src/theme.ts +237 -71
- package/packages/cli/src/themes/github-dark.ts +174 -0
- package/packages/cli/src/themes/index.ts +36 -0
- package/packages/cli/src/themes/types.ts +192 -0
- package/packages/cli/src/themes/vanilla-pi.ts +175 -0
- package/packages/cli/src/tui/paint-panel.ts +20 -0
- package/packages/cli/src/tui/tty-width.ts +973 -0
- package/packages/cli/src/turn.ts +8 -0
- package/packages/cli/src/utils/code-block.ts +90 -13
- package/packages/cli/src/utils/format.ts +11 -7
- package/packages/cli/src/utils/highlight.ts +15 -15
- package/packages/cli/src/utils/osc-canvas.ts +102 -0
- package/packages/cli/src/utils/osc52.ts +32 -3
|
@@ -5,7 +5,7 @@ import type {TUI, Container, Editor, SelectItem} from '@earendil-works/pi-tui';
|
|
|
5
5
|
import {PROVIDERS, resolveModelIds, saveSetting} from '@pal-code/core';
|
|
6
6
|
import type {Provider, ProviderKeys} from '@pal-code/core';
|
|
7
7
|
|
|
8
|
-
import {c} from '../theme.js';
|
|
8
|
+
import {c, surface} from '../theme.js';
|
|
9
9
|
import {state} from '../state.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -63,11 +63,11 @@ export async function showModelSelector(
|
|
|
63
63
|
const options = await buildModelOptions(allKeys);
|
|
64
64
|
|
|
65
65
|
const selectList = new SelectList(options, 14, {
|
|
66
|
-
selectedPrefix: (_text: string) => `${
|
|
67
|
-
selectedText: (text: string) => `${
|
|
68
|
-
description: (text: string) => `${
|
|
69
|
-
scrollInfo: (text: string) => `${
|
|
70
|
-
noMatch: (text: string) => `${
|
|
66
|
+
selectedPrefix: (_text: string) => `${surface.overlay.selectedPrefix}> ${c.reset}`,
|
|
67
|
+
selectedText: (text: string) => `${surface.overlay.selectedText}${text}${c.reset}`,
|
|
68
|
+
description: (text: string) => `${surface.overlay.description}${text}${c.reset}`,
|
|
69
|
+
scrollInfo: (text: string) => `${surface.overlay.scrollInfo}${text}${c.reset}`,
|
|
70
|
+
noMatch: (text: string) => `${surface.overlay.noMatch}${text}${c.reset}`,
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
// Highlight the current model
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import {Text, SelectList} from '@earendil-works/pi-tui';
|
|
9
9
|
import type {TUI, Container, Editor, SelectItem} from '@earendil-works/pi-tui';
|
|
10
10
|
|
|
11
|
-
import {c} from '../theme.js';
|
|
11
|
+
import {c, surface} from '../theme.js';
|
|
12
12
|
import {truncate} from '../utils/format.js';
|
|
13
13
|
import type {ConversationMessage as Message, Session, SessionStore} from '@pal-code/core';
|
|
14
14
|
|
|
@@ -72,11 +72,11 @@ export function showSessionSelector(
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
const selectList = new SelectList(items, 12, {
|
|
75
|
-
selectedPrefix: (_text: string) => `${
|
|
76
|
-
selectedText: (text: string) => `${
|
|
77
|
-
description: (text: string) => ` ${
|
|
78
|
-
scrollInfo: (text: string) => `${
|
|
79
|
-
noMatch: (_text: string) => `${
|
|
75
|
+
selectedPrefix: (_text: string) => `${surface.overlay.selectedPrefix}> ${c.reset}`,
|
|
76
|
+
selectedText: (text: string) => `${surface.overlay.selectedText}${text}${c.reset}`,
|
|
77
|
+
description: (text: string) => ` ${surface.overlay.description}${text}${c.reset}`,
|
|
78
|
+
scrollInfo: (text: string) => `${surface.overlay.scrollInfo}${text}${c.reset}`,
|
|
79
|
+
noMatch: (_text: string) => `${surface.overlay.noMatch} No matching sessions.${c.reset}`,
|
|
80
80
|
});
|
|
81
81
|
|
|
82
82
|
const label = new Text(
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* does belongs in `@pal-code/core` (see SYSTEM.md).
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
import type {SessionTokenomics} from '@pal-code/core';
|
|
19
20
|
import type {RunView} from './components/run-view.js';
|
|
20
21
|
import type {PermissionPrompt} from './components/permission-prompt.js';
|
|
21
22
|
|
|
@@ -109,6 +110,15 @@ export interface AppState {
|
|
|
109
110
|
target: string;
|
|
110
111
|
summary: string;
|
|
111
112
|
}>;
|
|
113
|
+
|
|
114
|
+
// ── Session-scoped tokenomics ──
|
|
115
|
+
/**
|
|
116
|
+
* Accumulated token usage and cost for the *current* session only — the
|
|
117
|
+
* sidebar stats, `/cost`, and `saveSession` all read this single object.
|
|
118
|
+
* Zeroed on `/new`, restored when a session is resumed, and persisted with
|
|
119
|
+
* the session row on every save.
|
|
120
|
+
*/
|
|
121
|
+
sessionTokenomics: SessionTokenomics;
|
|
112
122
|
}
|
|
113
123
|
|
|
114
124
|
export const state: AppState = {
|
|
@@ -133,6 +143,7 @@ export const state: AppState = {
|
|
|
133
143
|
pendingPermission: null,
|
|
134
144
|
permissionPrompt: null,
|
|
135
145
|
permissionQueue: [],
|
|
146
|
+
sessionTokenomics: {inputTokens: 0, outputTokens: 0, cachedTokens: 0, cost: 0},
|
|
136
147
|
};
|
|
137
148
|
|
|
138
149
|
/**
|
|
@@ -157,3 +168,26 @@ export function dequeueMessage(queue: string[]): string | null {
|
|
|
157
168
|
export function queuedStatusText(count: number): string {
|
|
158
169
|
return count > 0 ? `queued (${count})` : '';
|
|
159
170
|
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Zero the current session's token stats — called by `/new` so a fresh
|
|
174
|
+
* session starts from a clean slate instead of inheriting the previous
|
|
175
|
+
* session's lifetime totals.
|
|
176
|
+
*/
|
|
177
|
+
export function resetSessionTokenomics(): void {
|
|
178
|
+
state.sessionTokenomics = {inputTokens: 0, outputTokens: 0, cachedTokens: 0, cost: 0};
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Overwrite the current session's token stats — called on resume so the
|
|
183
|
+
* sidebar and `/cost` show the persisted totals of the session being resumed.
|
|
184
|
+
* Copies the four fields so the state slot never aliases a caller-owned object.
|
|
185
|
+
*/
|
|
186
|
+
export function setSessionTokenomics(t: SessionTokenomics): void {
|
|
187
|
+
state.sessionTokenomics = {
|
|
188
|
+
inputTokens: t.inputTokens,
|
|
189
|
+
outputTokens: t.outputTokens,
|
|
190
|
+
cachedTokens: t.cachedTokens,
|
|
191
|
+
cost: t.cost,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
@@ -1,88 +1,254 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Live theme facade.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Every renderer in the CLI pulls its palette from here, so a theme swap
|
|
5
|
+
* (`setTheme`) is observed by everything that reads at render time. The
|
|
6
|
+
* exports keep the exact names and shapes the existing importers already use;
|
|
7
|
+
* each object delegates to the active Theme via explicit typed getters (no
|
|
8
|
+
* Proxy, no `as any`).
|
|
9
|
+
*
|
|
10
|
+
* Module state only — no I/O. Env/config resolution happens in index.ts via
|
|
11
|
+
* the pure `resolveTheme()` in themes/index.ts.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type {EditorTheme, MarkdownTheme} from '@earendil-works/pi-tui';
|
|
15
|
+
import type {CColors, CodeboxTokens, SurfaceTokens, SyntaxTokens, Theme} from './themes/types.js';
|
|
16
|
+
import {themes} from './themes/index.js';
|
|
17
|
+
import {vanillaPi} from './themes/vanilla-pi.js';
|
|
18
|
+
|
|
19
|
+
export {listThemes, resolveTheme} from './themes/index.js';
|
|
20
|
+
|
|
21
|
+
let current: Theme = vanillaPi;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Swap the active theme. Unknown names return false and keep the current one.
|
|
6
25
|
*/
|
|
26
|
+
export function setTheme(name: string): boolean {
|
|
27
|
+
if (!Object.hasOwn(themes, name)) return false;
|
|
28
|
+
current = themes[name];
|
|
29
|
+
// ESM live bindings: reassignment is visible to `import {agentColors}`.
|
|
30
|
+
agentColors = {...current.agentColors};
|
|
31
|
+
agentLabels = {...current.agentLabels};
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
7
34
|
|
|
8
|
-
|
|
9
|
-
|
|
35
|
+
/** The active Theme object. */
|
|
36
|
+
export function activeTheme(): Theme {
|
|
37
|
+
return current;
|
|
38
|
+
}
|
|
10
39
|
|
|
11
|
-
export const c = {
|
|
12
|
-
reset
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
export const c: CColors = {
|
|
41
|
+
get reset() {
|
|
42
|
+
return current.c.reset;
|
|
43
|
+
},
|
|
44
|
+
get bold() {
|
|
45
|
+
return current.c.bold;
|
|
46
|
+
},
|
|
47
|
+
get dim() {
|
|
48
|
+
return current.c.dim;
|
|
49
|
+
},
|
|
50
|
+
get italic() {
|
|
51
|
+
return current.c.italic;
|
|
52
|
+
},
|
|
53
|
+
get underline() {
|
|
54
|
+
return current.c.underline;
|
|
55
|
+
},
|
|
56
|
+
get blue() {
|
|
57
|
+
return current.c.blue;
|
|
58
|
+
},
|
|
59
|
+
get green() {
|
|
60
|
+
return current.c.green;
|
|
61
|
+
},
|
|
62
|
+
get cyan() {
|
|
63
|
+
return current.c.cyan;
|
|
64
|
+
},
|
|
65
|
+
get yellow() {
|
|
66
|
+
return current.c.yellow;
|
|
67
|
+
},
|
|
68
|
+
get red() {
|
|
69
|
+
return current.c.red;
|
|
70
|
+
},
|
|
71
|
+
get magenta() {
|
|
72
|
+
return current.c.magenta;
|
|
73
|
+
},
|
|
74
|
+
get bright_red() {
|
|
75
|
+
return current.c.bright_red;
|
|
76
|
+
},
|
|
77
|
+
get bright_green() {
|
|
78
|
+
return current.c.bright_green;
|
|
79
|
+
},
|
|
80
|
+
get bright_yellow() {
|
|
81
|
+
return current.c.bright_yellow;
|
|
82
|
+
},
|
|
83
|
+
get bright_cyan() {
|
|
84
|
+
return current.c.bright_cyan;
|
|
85
|
+
},
|
|
86
|
+
get bright_black() {
|
|
87
|
+
return current.c.bright_black;
|
|
88
|
+
},
|
|
89
|
+
get bright_white() {
|
|
90
|
+
return current.c.bright_white;
|
|
91
|
+
},
|
|
29
92
|
};
|
|
30
93
|
|
|
31
|
-
export const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
94
|
+
export const codebox: CodeboxTokens = {
|
|
95
|
+
get surfaceBg() {
|
|
96
|
+
return current.codebox.surfaceBg;
|
|
97
|
+
},
|
|
98
|
+
get borderFg() {
|
|
99
|
+
return current.codebox.borderFg;
|
|
100
|
+
},
|
|
101
|
+
get langFg() {
|
|
102
|
+
return current.codebox.langFg;
|
|
103
|
+
},
|
|
104
|
+
get chipBgIdle() {
|
|
105
|
+
return current.codebox.chipBgIdle;
|
|
106
|
+
},
|
|
107
|
+
get chipBgHover() {
|
|
108
|
+
return current.codebox.chipBgHover;
|
|
109
|
+
},
|
|
110
|
+
get chipFgIdle() {
|
|
111
|
+
return current.codebox.chipFgIdle;
|
|
112
|
+
},
|
|
113
|
+
get chipFgHover() {
|
|
114
|
+
return current.codebox.chipFgHover;
|
|
115
|
+
},
|
|
116
|
+
get successFg() {
|
|
117
|
+
return current.codebox.successFg;
|
|
118
|
+
},
|
|
47
119
|
};
|
|
48
120
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
121
|
+
export const markdownTheme: MarkdownTheme = {
|
|
122
|
+
get heading() {
|
|
123
|
+
return current.markdownTheme.heading;
|
|
124
|
+
},
|
|
125
|
+
get link() {
|
|
126
|
+
return current.markdownTheme.link;
|
|
127
|
+
},
|
|
128
|
+
get linkUrl() {
|
|
129
|
+
return current.markdownTheme.linkUrl;
|
|
130
|
+
},
|
|
131
|
+
get code() {
|
|
132
|
+
return current.markdownTheme.code;
|
|
133
|
+
},
|
|
134
|
+
get codeBlock() {
|
|
135
|
+
return current.markdownTheme.codeBlock;
|
|
136
|
+
},
|
|
137
|
+
get codeBlockBorder() {
|
|
138
|
+
return current.markdownTheme.codeBlockBorder;
|
|
139
|
+
},
|
|
140
|
+
get quote() {
|
|
141
|
+
return current.markdownTheme.quote;
|
|
142
|
+
},
|
|
143
|
+
get quoteBorder() {
|
|
144
|
+
return current.markdownTheme.quoteBorder;
|
|
145
|
+
},
|
|
146
|
+
get hr() {
|
|
147
|
+
return current.markdownTheme.hr;
|
|
148
|
+
},
|
|
149
|
+
get listBullet() {
|
|
150
|
+
return current.markdownTheme.listBullet;
|
|
151
|
+
},
|
|
152
|
+
get bold() {
|
|
153
|
+
return current.markdownTheme.bold;
|
|
154
|
+
},
|
|
155
|
+
get italic() {
|
|
156
|
+
return current.markdownTheme.italic;
|
|
157
|
+
},
|
|
158
|
+
get strikethrough() {
|
|
159
|
+
return current.markdownTheme.strikethrough;
|
|
160
|
+
},
|
|
161
|
+
get underline() {
|
|
162
|
+
return current.markdownTheme.underline;
|
|
163
|
+
},
|
|
164
|
+
get highlightCode() {
|
|
165
|
+
return current.markdownTheme.highlightCode;
|
|
166
|
+
},
|
|
167
|
+
get codeBlockIndent() {
|
|
168
|
+
return current.markdownTheme.codeBlockIndent;
|
|
169
|
+
},
|
|
59
170
|
};
|
|
60
171
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
review: 'reviewer',
|
|
69
|
-
librarian: 'librarian',
|
|
70
|
-
architect: 'architect',
|
|
172
|
+
export const editorTheme: EditorTheme = {
|
|
173
|
+
get borderColor() {
|
|
174
|
+
return current.editorTheme.borderColor;
|
|
175
|
+
},
|
|
176
|
+
get selectList() {
|
|
177
|
+
return current.editorTheme.selectList;
|
|
178
|
+
},
|
|
71
179
|
};
|
|
72
180
|
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
181
|
+
/**
|
|
182
|
+
* Agent role display colours. Plain objects re-bound on every setTheme —
|
|
183
|
+
* ESM live bindings propagate the reassignment to importers.
|
|
184
|
+
*/
|
|
185
|
+
export let agentColors: Record<string, string> = {...vanillaPi.agentColors};
|
|
186
|
+
|
|
187
|
+
/** Agent role display labels (same live-binding semantics as agentColors). */
|
|
188
|
+
export let agentLabels: Record<string, string> = {...vanillaPi.agentLabels};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Resolve a theme colour by its key name (e.g. 'cyan'), or a fallback.
|
|
192
|
+
*
|
|
193
|
+
* The implicit fallback is theme-driven (vanilla-pi: c.cyan, github-dark:
|
|
194
|
+
* c.blue) — it is resolved per call from the active theme, not baked in.
|
|
195
|
+
*/
|
|
196
|
+
export function colorByName(name: string | undefined, fallback?: string): string {
|
|
197
|
+
const fb = fallback ?? current.colorByNameFallback ?? current.c.blue;
|
|
198
|
+
if (!name) return fb;
|
|
199
|
+
const palette: Record<string, string> = {...current.c};
|
|
200
|
+
return palette[name] ?? fb;
|
|
77
201
|
}
|
|
78
202
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
203
|
+
/** Syntax-highlighter roles of the active theme (read by utils/highlight.ts). */
|
|
204
|
+
export const syntax: SyntaxTokens = {
|
|
205
|
+
get comment() {
|
|
206
|
+
return current.syntax.comment;
|
|
207
|
+
},
|
|
208
|
+
get string() {
|
|
209
|
+
return current.syntax.string;
|
|
210
|
+
},
|
|
211
|
+
get number() {
|
|
212
|
+
return current.syntax.number;
|
|
213
|
+
},
|
|
214
|
+
get keyword() {
|
|
215
|
+
return current.syntax.keyword;
|
|
216
|
+
},
|
|
217
|
+
get method() {
|
|
218
|
+
return current.syntax.method;
|
|
219
|
+
},
|
|
220
|
+
get jsonKey() {
|
|
221
|
+
return current.syntax.jsonKey;
|
|
222
|
+
},
|
|
223
|
+
get jsonPrimitive() {
|
|
224
|
+
return current.syntax.jsonPrimitive;
|
|
225
|
+
},
|
|
226
|
+
get plain() {
|
|
227
|
+
return current.syntax.plain;
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/** Per-component surface roles of the active theme (Phase B wiring target). */
|
|
232
|
+
export const surface: SurfaceTokens = {
|
|
233
|
+
get window() {
|
|
234
|
+
return current.surface.window;
|
|
235
|
+
},
|
|
236
|
+
get input() {
|
|
237
|
+
return current.surface.input;
|
|
238
|
+
},
|
|
239
|
+
get sidebar() {
|
|
240
|
+
return current.surface.sidebar;
|
|
241
|
+
},
|
|
242
|
+
get statusLine() {
|
|
243
|
+
return current.surface.statusLine;
|
|
244
|
+
},
|
|
245
|
+
get overlay() {
|
|
246
|
+
return current.surface.overlay;
|
|
247
|
+
},
|
|
248
|
+
get permission() {
|
|
249
|
+
return current.surface.permission;
|
|
250
|
+
},
|
|
251
|
+
get messageBox() {
|
|
252
|
+
return current.surface.messageBox;
|
|
87
253
|
},
|
|
88
254
|
};
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* github-dark — VS Code "GitHub Dark Default" aesthetic (Primer palette).
|
|
3
|
+
*
|
|
4
|
+
* `c` / `codebox` / `markdownTheme` / `editorTheme` / `agentColors` are
|
|
5
|
+
* harvested verbatim from the hand-tuned palette that lived in `theme.ts`;
|
|
6
|
+
* `syntax` and `surface` extend it with GitHub Dark syntax colours.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type {EditorTheme, MarkdownTheme} from '@earendil-works/pi-tui';
|
|
10
|
+
import {highlightCode} from '../utils/highlight.js';
|
|
11
|
+
import type {CColors, CodeboxTokens, SurfaceTokens, SyntaxTokens, Theme} from './types.js';
|
|
12
|
+
|
|
13
|
+
const c: CColors = {
|
|
14
|
+
reset: '\x1b[0m',
|
|
15
|
+
bold: '\x1b[1m',
|
|
16
|
+
dim: '\x1b[2m',
|
|
17
|
+
italic: '\x1b[3m',
|
|
18
|
+
underline: '\x1b[4m',
|
|
19
|
+
// GitHub Dark Truecolor Mapping (Primer Palette)
|
|
20
|
+
blue: '\x1b[38;2;88;166;255m', // #58a6ff — GitHub Links / Accent Blue
|
|
21
|
+
green: '\x1b[38;2;63;185;80m', // #3fb950 — GitHub Success / Green
|
|
22
|
+
cyan: '\x1b[38;2;57;197;207m', // #39c5cf — GitHub Teal / Cyan
|
|
23
|
+
yellow: '\x1b[38;2;210;153;34m', // #d29922 — GitHub Yellow / Warning
|
|
24
|
+
red: '\x1b[38;2;248;81;73m', // #f85149 — GitHub Red / Error
|
|
25
|
+
magenta: '\x1b[38;2;188;140;255m', // #bc8cff — GitHub Purple
|
|
26
|
+
bright_red: '\x1b[38;2;255;123;114m', // #ff7b72 — GitHub Pink/Light Red
|
|
27
|
+
bright_green: '\x1b[38;2;126;231;135m', // #7ee787 — GitHub Light Green
|
|
28
|
+
bright_yellow: '\x1b[38;2;227;179;65m', // #e3b341 — GitHub Light Yellow
|
|
29
|
+
bright_cyan: '\x1b[38;2;112;232;248m', // #70e2f8 — GitHub Light Cyan
|
|
30
|
+
bright_black: '\x1b[38;2;139;148;158m', // #8b949e — GitHub Muted Gray
|
|
31
|
+
bright_white: '\x1b[38;2;240;246;252m', // #f0f6fc — GitHub Bright White Text
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const codebox: CodeboxTokens = {
|
|
35
|
+
surfaceBg: '\x1b[48;2;13;17;23m', // #0d1117 — GitHub dark canvas background
|
|
36
|
+
borderFg: '\x1b[38;2;48;54;61m', // #30363d — GitHub subtle border gray
|
|
37
|
+
langFg: '\x1b[38;2;139;148;158m', // #8b949e — GitHub muted text / language tag
|
|
38
|
+
chipBgIdle: '\x1b[48;2;33;38;45m', // #21262d — GitHub button background (idle)
|
|
39
|
+
chipBgHover: '\x1b[48;2;48;54;61m', // #30363d — GitHub button background (hover)
|
|
40
|
+
chipFgIdle: '\x1b[38;2;201;209;217m', // #c9d1d9 — GitHub primary text
|
|
41
|
+
chipFgHover: '\x1b[38;2;240;246;252m', // #f0f6fc — GitHub bright text on hover
|
|
42
|
+
successFg: '\x1b[38;2;63;185;80m', // #3fb950 — GitHub success green
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const markdownTheme: MarkdownTheme = {
|
|
46
|
+
heading: (text: string) => `${c.bold}${c.blue}${text}${c.reset}`,
|
|
47
|
+
link: (text: string) => `${c.underline}${c.blue}${text}${c.reset}`,
|
|
48
|
+
linkUrl: (text: string) => `${c.bright_black}${text}${c.reset}`,
|
|
49
|
+
code: (text: string) => `${c.bright_red}${text}${c.reset}`, // GitHub inline code
|
|
50
|
+
codeBlock: (text: string) => `${c.bright_white}${text}${c.reset}`,
|
|
51
|
+
codeBlockBorder: (text: string) => `\x1b[38;2;48;54;61m${text}${c.reset}`, // #30363d
|
|
52
|
+
quote: (text: string) => `${c.italic}${c.bright_black}${text}${c.reset}`,
|
|
53
|
+
quoteBorder: (text: string) => `${c.bold}${c.blue}${text}${c.reset}`,
|
|
54
|
+
hr: (text: string) => `${c.bright_black}${text}${c.reset}`,
|
|
55
|
+
listBullet: (text: string) => `${c.bold}${c.green}${text}${c.reset}`,
|
|
56
|
+
bold: (text: string) => `${c.bold}${c.bright_white}${text}${c.reset}`,
|
|
57
|
+
italic: (text: string) => `${c.italic}${c.bright_white}${text}${c.reset}`,
|
|
58
|
+
strikethrough: (text: string) => `${c.bright_black}${text}${c.reset}`,
|
|
59
|
+
underline: (text: string) => `${c.underline}${text}${c.reset}`,
|
|
60
|
+
highlightCode,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const editorTheme: EditorTheme = {
|
|
64
|
+
borderColor: (s) => `${surface.input.border}${s}${c.reset}`, // #30363d GitHub border gray
|
|
65
|
+
selectList: {
|
|
66
|
+
selectedPrefix: (s) => `${c.bold}${c.blue}${s}${c.reset}`,
|
|
67
|
+
selectedText: (s) => `${c.bold}${c.bright_white}${s}${c.reset}`,
|
|
68
|
+
description: (s) => `${c.bright_black}${s}${c.reset}`,
|
|
69
|
+
scrollInfo: (s) => `${c.bright_black}${s}${c.reset}`,
|
|
70
|
+
noMatch: (s) => `${c.bright_black}${s}${c.reset}`,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** GitHub-aligned agent role colors. */
|
|
75
|
+
const agentColors: Record<string, string> = {
|
|
76
|
+
pal: c.cyan,
|
|
77
|
+
plan: c.red,
|
|
78
|
+
planner: c.red,
|
|
79
|
+
explore: c.green,
|
|
80
|
+
build: c.blue,
|
|
81
|
+
review: c.magenta,
|
|
82
|
+
librarian: c.yellow,
|
|
83
|
+
architect: c.bright_cyan,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
/** Fallback display labels for roles that don't declare one. */
|
|
87
|
+
const agentLabels: Record<string, string> = {
|
|
88
|
+
pal: 'pal',
|
|
89
|
+
plan: 'plan',
|
|
90
|
+
planner: 'planner',
|
|
91
|
+
explore: 'explore',
|
|
92
|
+
build: 'builder',
|
|
93
|
+
review: 'reviewer',
|
|
94
|
+
librarian: 'librarian',
|
|
95
|
+
architect: 'architect',
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** VS Code GitHub Dark Default syntax colours (truecolor SGR). */
|
|
99
|
+
const syntax: SyntaxTokens = {
|
|
100
|
+
comment: '\x1b[38;2;139;148;158m', // #8b949e
|
|
101
|
+
string: '\x1b[38;2;165;214;255m', // #a5d6ff
|
|
102
|
+
number: '\x1b[38;2;121;192;255m', // #79c0ff
|
|
103
|
+
keyword: '\x1b[38;2;255;123;114m', // #ff7b72
|
|
104
|
+
method: '\x1b[38;2;210;168;255m', // #d2a8ff
|
|
105
|
+
jsonKey: '\x1b[38;2;121;192;255m', // #79c0ff
|
|
106
|
+
jsonPrimitive: '\x1b[38;2;165;214;255m', // #a5d6ff
|
|
107
|
+
plain: '\x1b[38;2;139;148;158m', // #8b949e
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** GitHub Dark equivalents of each component's palette reads (hex in comments). */
|
|
111
|
+
const surface: SurfaceTokens = {
|
|
112
|
+
window: {
|
|
113
|
+
bg: '#0d1117', // editor.background — main canvas (OSC 11 sync)
|
|
114
|
+
fg: '#e6edf3', // editor.foreground (OSC 10 sync)
|
|
115
|
+
border: '\x1b[38;2;48;54;61m', // #30363d — GitHub border (reserved)
|
|
116
|
+
},
|
|
117
|
+
input: {
|
|
118
|
+
border: '\x1b[38;2;48;54;61m', // #30363d — editor border (editorTheme)
|
|
119
|
+
fg: '\x1b[38;2;201;209;217m', // #c9d1d9 — primary text (reserved)
|
|
120
|
+
placeholder: '\x1b[38;2;110;118;129m', // #6e7681 — muted placeholder (reserved)
|
|
121
|
+
},
|
|
122
|
+
sidebar: {
|
|
123
|
+
bg: '\x1b[48;2;1;4;9m', // #010409 — panel darker than canvas #0d1117
|
|
124
|
+
border: '\x1b[38;2;48;54;61m', // #30363d — border (reserved)
|
|
125
|
+
title: `${c.bold}${c.blue}`, // sidebar.ts:58 — bold #58a6ff
|
|
126
|
+
item: c.green, // sidebar.ts:76,89 — #3fb950 dot
|
|
127
|
+
itemAccent: `${c.bold}${c.green}`, // sidebar.ts:61,70,83,98 — bold #3fb950
|
|
128
|
+
selected: c.blue, // #58a6ff (reserved — no selection state)
|
|
129
|
+
dim: c.dim, // SGR dim (sidebar.ts:72,85,92,102)
|
|
130
|
+
},
|
|
131
|
+
statusLine: {
|
|
132
|
+
border: '\x1b[38;2;48;54;61m', // #30363d (reserved)
|
|
133
|
+
flash: c.green, // #3fb950 — index.ts:816
|
|
134
|
+
error: c.red, // #f85149 (reserved — no error state today)
|
|
135
|
+
warn: c.yellow, // #d29922 — index.ts:771,775,783,795
|
|
136
|
+
info: c.cyan, // #39c5cf — index.ts:789
|
|
137
|
+
dim: c.dim, // SGR dim — index.ts:797
|
|
138
|
+
},
|
|
139
|
+
overlay: {
|
|
140
|
+
border: '\x1b[38;2;48;54;61m', // #30363d (reserved)
|
|
141
|
+
selectedPrefix: c.blue, // #58a6ff — model/session picker prefix
|
|
142
|
+
selectedText: c.bold, // SGR bold — picker selection
|
|
143
|
+
description: c.dim, // SGR dim — picker description (c.dim reads)
|
|
144
|
+
scrollInfo: c.dim, // SGR dim
|
|
145
|
+
noMatch: c.dim, // SGR dim
|
|
146
|
+
},
|
|
147
|
+
permission: {
|
|
148
|
+
border: `${c.dim}${c.yellow}`, // dim + #d29922 — permission-prompt.ts:41
|
|
149
|
+
header: `${c.bold}${c.yellow}`, // bold + #d29922 — permission-prompt.ts:45,65
|
|
150
|
+
allow: c.green, // #3fb950 — permission-prompt.ts:48
|
|
151
|
+
always: c.cyan, // #39c5cf — permission-prompt.ts:49
|
|
152
|
+
deny: c.red, // #f85149 — permission-prompt.ts:50
|
|
153
|
+
dim: c.dim, // SGR dim — permission-prompt.ts:51,77
|
|
154
|
+
},
|
|
155
|
+
messageBox: {
|
|
156
|
+
border: c.dim, // SGR dim prefix — format.ts:98
|
|
157
|
+
dim: c.dim, // SGR dim — format.ts:150,181
|
|
158
|
+
roleFallback: c.cyan, // #39c5cf — format.ts:94
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
export const githubDark: Theme = {
|
|
163
|
+
name: 'github-dark',
|
|
164
|
+
displayName: 'GitHub Dark',
|
|
165
|
+
c,
|
|
166
|
+
codebox,
|
|
167
|
+
syntax,
|
|
168
|
+
markdownTheme,
|
|
169
|
+
editorTheme,
|
|
170
|
+
agentColors,
|
|
171
|
+
agentLabels,
|
|
172
|
+
surface,
|
|
173
|
+
colorByNameFallback: c.blue, // github colorByName() default
|
|
174
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Theme registry — add a theme by creating one file and one entry here.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type {Theme} from './types.js';
|
|
6
|
+
import {githubDark} from './github-dark.js';
|
|
7
|
+
import {vanillaPi} from './vanilla-pi.js';
|
|
8
|
+
|
|
9
|
+
export type {CColors, CodeboxTokens, SurfaceTokens, SyntaxTokens, Theme} from './types.js';
|
|
10
|
+
|
|
11
|
+
/** Registered themes, keyed by the id used on the command line. */
|
|
12
|
+
export const themes: Record<string, Theme> = {
|
|
13
|
+
'vanilla-pi': vanillaPi,
|
|
14
|
+
'github-dark': githubDark,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** The default theme — used whenever no registered name resolves. */
|
|
18
|
+
export const DEFAULT_THEME = 'vanilla-pi';
|
|
19
|
+
|
|
20
|
+
/** Registered theme ids in registration order. */
|
|
21
|
+
export function listThemes(): string[] {
|
|
22
|
+
return Object.keys(themes);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Pure theme-name resolution — no I/O.
|
|
27
|
+
*
|
|
28
|
+
* Priority: `env` (PAL_THEME) when it names a registered theme, then
|
|
29
|
+
* `pal.theme` (the `theme` key of ~/.pal/config.json) when it is a registered
|
|
30
|
+
* string, then DEFAULT_THEME. Unknown values fall through to the next source.
|
|
31
|
+
*/
|
|
32
|
+
export function resolveTheme(pal: {theme?: unknown}, env: string | undefined): string {
|
|
33
|
+
if (typeof env === 'string' && Object.hasOwn(themes, env)) return env;
|
|
34
|
+
if (typeof pal.theme === 'string' && Object.hasOwn(themes, pal.theme)) return pal.theme;
|
|
35
|
+
return DEFAULT_THEME;
|
|
36
|
+
}
|