pal-code 0.0.14 → 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.
@@ -1,88 +1,254 @@
1
1
  /**
2
- * Colours (raw ANSI — no chalk dependency) and the two pi-tui themes.
2
+ * Live theme facade.
3
3
  *
4
- * Pure: no state, no I/O. Every renderer in the CLI pulls from here so the
5
- * palette stays consistent.
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
- import type {EditorTheme} from '@earendil-works/pi-tui';
9
- import {highlightCode} from './utils/highlight.js';
35
+ /** The active Theme object. */
36
+ export function activeTheme(): Theme {
37
+ return current;
38
+ }
10
39
 
11
- export const c = {
12
- reset: '\x1b[0m',
13
- bold: '\x1b[1m',
14
- dim: '\x1b[2m',
15
- italic: '\x1b[3m',
16
- underline: '\x1b[4m',
17
- blue: '\x1b[34m',
18
- green: '\x1b[32m',
19
- cyan: '\x1b[36m',
20
- yellow: '\x1b[33m',
21
- red: '\x1b[31m',
22
- magenta: '\x1b[35m',
23
- bright_red: '\x1b[91m',
24
- bright_green: '\x1b[92m',
25
- bright_yellow: '\x1b[93m',
26
- bright_cyan: '\x1b[96m',
27
- bright_black: '\x1b[90m',
28
- bright_white: '\x1b[97m',
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 markdownTheme = {
32
- heading: (text: string) => `${c.bold}${c.bright_cyan}${text}${c.reset}`,
33
- link: (text: string) => `${c.underline}${c.cyan}${text}${c.reset}`,
34
- linkUrl: (text: string) => `${c.dim}${text}${c.reset}`,
35
- code: (text: string) => `${c.bold}${c.magenta}${text}${c.reset}`,
36
- codeBlock: (text: string) => `${c.bright_black}${text}${c.reset}`,
37
- codeBlockBorder: (text: string) => `${c.dim}${c.bright_black}${text}${c.reset}`,
38
- quote: (text: string) => `${c.italic}${c.dim}${text}${c.reset}`,
39
- quoteBorder: (text: string) => `${c.bold}${c.cyan}${text}${c.reset}`,
40
- hr: (text: string) => `${c.dim}${text}${c.reset}`,
41
- listBullet: (text: string) => `${c.bold}${c.green}${text}${c.reset}`,
42
- bold: (text: string) => `${c.bold}${c.bright_white}${text}${c.reset}`,
43
- italic: (text: string) => `${c.italic}${c.dim}${text}${c.reset}`,
44
- strikethrough: (text: string) => `${c.dim}${text}${c.reset}`,
45
- underline: (text: string) => `${c.underline}${text}${c.reset}`,
46
- highlightCode,
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
- /** Fallback display colours for roles that don't declare one. */
50
- export const agentColors: Record<string, string> = {
51
- pal: c.cyan,
52
- plan: c.red,
53
- planner: c.red,
54
- explore: c.green,
55
- build: c.blue,
56
- review: c.magenta,
57
- librarian: c.yellow,
58
- architect: c.bright_cyan,
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
- /** Fallback display labels for roles that don't declare one. */
62
- export const agentLabels: Record<string, string> = {
63
- pal: 'pal',
64
- plan: 'plan',
65
- planner: 'planner',
66
- explore: 'explore',
67
- build: 'builder',
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
- /** Resolve a theme colour by its key name (e.g. 'cyan'), or the default. */
74
- export function colorByName(name: string | undefined, fallback = c.cyan): string {
75
- if (!name) return fallback;
76
- return (c as Record<string, string>)[name] ?? fallback;
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
- export const editorTheme: EditorTheme = {
80
- borderColor: (s) => `${c.dim}${s}${c.reset}`,
81
- selectList: {
82
- selectedPrefix: (s) => `${c.bold}${c.green}${s}${c.reset}`,
83
- selectedText: (s) => `${c.bold}${s}${c.reset}`,
84
- description: (s) => `${c.dim}${s}${c.reset}`,
85
- scrollInfo: (s) => `${c.dim}${s}${c.reset}`,
86
- noMatch: (s) => `${c.dim}${s}${c.reset}`,
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
+ }