pal-code 0.0.14 → 0.0.16

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.
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Theme contract for the modular multi-theme system.
3
+ *
4
+ * Every theme is a self-contained palette object: adding a theme means adding
5
+ * one file that implements this interface and registering it in
6
+ * `themes/index.ts`. Nothing else in the CLI changes.
7
+ *
8
+ * Token groups:
9
+ * - `c` / `codebox` / `markdownTheme` / `editorTheme` / `agentColors` /
10
+ * `agentLabels` — the live facade surface re-exported by `../theme.ts`.
11
+ * - `syntax` — highlighter roles read by `../utils/highlight.ts`.
12
+ * - `surface` — per-component roles defined and populated here, wired to the
13
+ * components in a later phase (Phase B). Every key documents its consumer
14
+ * or is marked `reserved`.
15
+ */
16
+
17
+ import type {EditorTheme, MarkdownTheme} from '@earendil-works/pi-tui';
18
+
19
+ /** The 17 raw ANSI SGR codes every renderer reads through the `c` facade. */
20
+ export interface CColors {
21
+ reset: string;
22
+ bold: string;
23
+ dim: string;
24
+ italic: string;
25
+ underline: string;
26
+ blue: string;
27
+ green: string;
28
+ cyan: string;
29
+ yellow: string;
30
+ red: string;
31
+ magenta: string;
32
+ bright_red: string;
33
+ bright_green: string;
34
+ bright_yellow: string;
35
+ bright_cyan: string;
36
+ bright_black: string;
37
+ bright_white: string;
38
+ }
39
+
40
+ /** Code-box roles for the fenced-code box in the transcript. */
41
+ export interface CodeboxTokens {
42
+ surfaceBg: string;
43
+ borderFg: string;
44
+ langFg: string;
45
+ chipBgIdle: string;
46
+ chipBgHover: string;
47
+ chipFgIdle: string;
48
+ chipFgHover: string;
49
+ successFg: string;
50
+ }
51
+
52
+ /**
53
+ * Syntax-highlighter roles — one token per distinct colour ROLE painted by
54
+ * `utils/highlight.ts`. `keyword` carries its own emphasis (vanilla prepends
55
+ * bold) so a theme picks colour and weight together.
56
+ */
57
+ export interface SyntaxTokens {
58
+ /** Line `//`, hash `#` and block `/*` comments — highlight.ts:268,274,282,286. */
59
+ comment: string;
60
+ /** Code string literals + JSON string values — highlight.ts:299,352. */
61
+ string: string;
62
+ /** Numeric literals + JSON numbers — highlight.ts:308,356. */
63
+ number: string;
64
+ /** Reserved words (bold included in vanilla) — highlight.ts:320. */
65
+ keyword: string;
66
+ /** Member access after `.` — highlight.ts:323. */
67
+ method: string;
68
+ /** JSON object keys — highlight.ts:350. */
69
+ jsonKey: string;
70
+ /** JSON `true`/`false`/`null` — highlight.ts:354. */
71
+ jsonPrimitive: string;
72
+ /** No-language / unknown-language block paint — highlight.ts:236,248. */
73
+ plain: string;
74
+ }
75
+
76
+ /**
77
+ * Per-component surface roles. Populated by every theme; components are
78
+ * rewired to read these in Phase B (except the lazy-capture fixes already
79
+ * applied). Keys without a live consumer today are marked `reserved`.
80
+ */
81
+ export interface SurfaceTokens {
82
+ window: {
83
+ /**
84
+ * Terminal default background for OSC 11 canvas sync: hex `'#rrggbb'`,
85
+ * or `''` to leave the terminal default alone (no sync, zero bytes).
86
+ * hex because OSC 10/11 set queries take `#rrggbb` payloads.
87
+ */
88
+ bg: string;
89
+ /**
90
+ * Terminal default foreground for OSC 10 canvas sync: hex `'#rrggbb'`,
91
+ * or `''` to leave the terminal default alone (no sync, zero bytes).
92
+ */
93
+ fg: string;
94
+ /** reserved — window frame SGR sequence (not part of canvas sync). */
95
+ border: string;
96
+ };
97
+ input: {
98
+ /** consumed by editorTheme.borderColor → Editor border (index.ts:280). */
99
+ border: string;
100
+ /** reserved — editor text uses the terminal default foreground (Phase B). */
101
+ fg: string;
102
+ /** reserved — no placeholder paint exists yet (Phase B). */
103
+ placeholder: string;
104
+ };
105
+ sidebar: {
106
+ /** consumed by components/sidebar.ts render() via tui/paint-panel.ts — panel fill ('' = no panel). */
107
+ bg: string;
108
+ /** reserved — the sidebar overlay paints no border (Phase B). */
109
+ border: string;
110
+ /** consumed by components/sidebar.ts:66 (session title, bold+accent). */
111
+ title: string;
112
+ /** consumed by components/sidebar.ts:84,99 (active/connected status dot). */
113
+ item: string;
114
+ /** consumed by components/sidebar.ts:69,78,91,109 (section headers). */
115
+ itemAccent: string;
116
+ /** reserved — no selection state in the sidebar (Phase B). */
117
+ selected: string;
118
+ /** consumed by components/sidebar.ts:80,93,103,113 (empty states / notes). */
119
+ dim: string;
120
+ };
121
+ statusLine: {
122
+ /** reserved — the status line paints no border (Phase B). */
123
+ border: string;
124
+ /** consumed by index.ts:836 (flashCopied confirmation). */
125
+ flash: string;
126
+ /** reserved — no error state today (Phase B). */
127
+ error: string;
128
+ /** consumed by index.ts:791,795,803,815 (agents/subagents/permission/queued). */
129
+ warn: string;
130
+ /** consumed by index.ts:809 (scroll-mode hint). */
131
+ info: string;
132
+ /** consumed by index.ts:817 (provider name + /help hint). */
133
+ dim: string;
134
+ };
135
+ overlay: {
136
+ /** reserved — overlay chrome border (Phase B). */
137
+ border: string;
138
+ /** consumed by overlays/model-picker.ts:66, overlays/session-picker.ts:75. */
139
+ selectedPrefix: string;
140
+ /** consumed by overlays/model-picker.ts:67, overlays/session-picker.ts:76. */
141
+ selectedText: string;
142
+ /** consumed by overlays/model-picker.ts:68, overlays/session-picker.ts:77. */
143
+ description: string;
144
+ /** consumed by overlays/model-picker.ts:69, overlays/session-picker.ts:78. */
145
+ scrollInfo: string;
146
+ /** consumed by overlays/model-picker.ts:70, overlays/session-picker.ts:79. */
147
+ noMatch: string;
148
+ };
149
+ permission: {
150
+ /** consumed by components/permission-prompt.ts:41 (dim+accent box frame). */
151
+ border: string;
152
+ /** consumed by components/permission-prompt.ts tagFull (modal header tag). */
153
+ header: string;
154
+ /** consumed by components/permission-prompt.ts:48 (`[y]` allow once). */
155
+ allow: string;
156
+ /** consumed by components/permission-prompt.ts:49 (`[a]` always allow). */
157
+ always: string;
158
+ /** consumed by components/permission-prompt.ts:50 (`[n]` deny). */
159
+ deny: string;
160
+ /** consumed by components/permission-prompt.ts:51,77 (hint + label). */
161
+ dim: string;
162
+ };
163
+ messageBox: {
164
+ /** consumed by utils/format.ts:98 (dim prefix on role-coloured border). */
165
+ border: string;
166
+ /** consumed by utils/format.ts:151,181 (timestamp). */
167
+ dim: string;
168
+ /** consumed by utils/format.ts:94 (unknown-role colour fallback). */
169
+ roleFallback: string;
170
+ };
171
+ }
172
+
173
+ /** A complete, self-contained theme. */
174
+ export interface Theme {
175
+ /** Registry key used on the command line, e.g. `vanilla-pi`. */
176
+ name: string;
177
+ /** Human-readable name shown by `/theme`. */
178
+ displayName: string;
179
+ c: CColors;
180
+ codebox: CodeboxTokens;
181
+ syntax: SyntaxTokens;
182
+ markdownTheme: MarkdownTheme;
183
+ editorTheme: EditorTheme;
184
+ agentColors: Record<string, string>;
185
+ agentLabels: Record<string, string>;
186
+ surface: SurfaceTokens;
187
+ /**
188
+ * Fallback colour for `colorByName()` when the caller passes none.
189
+ * vanilla-pi keeps the historical `c.cyan`; github-dark uses `c.blue`.
190
+ */
191
+ colorByNameFallback?: string;
192
+ }
@@ -0,0 +1,175 @@
1
+ /**
2
+ * vanilla-pi — the original pal-code palette (16-colour ANSI, Gemini-web
3
+ * code-box identity). DEFAULT theme: byte-for-byte identical to the palette
4
+ * `theme.ts` shipped at baseline HEAD 38e7670, so a fresh config renders
5
+ * exactly what shipped before the theme system existed.
6
+ */
7
+
8
+ import type {EditorTheme, MarkdownTheme} from '@earendil-works/pi-tui';
9
+ import {highlightCode} from '../utils/highlight.js';
10
+ import type {CColors, CodeboxTokens, SurfaceTokens, SyntaxTokens, Theme} from './types.js';
11
+
12
+ const c: CColors = {
13
+ reset: '\x1b[0m',
14
+ bold: '\x1b[1m',
15
+ dim: '\x1b[2m',
16
+ italic: '\x1b[3m',
17
+ underline: '\x1b[4m',
18
+ blue: '\x1b[34m',
19
+ green: '\x1b[32m',
20
+ cyan: '\x1b[36m',
21
+ yellow: '\x1b[33m',
22
+ red: '\x1b[31m',
23
+ magenta: '\x1b[35m',
24
+ bright_red: '\x1b[91m',
25
+ bright_green: '\x1b[92m',
26
+ bright_yellow: '\x1b[93m',
27
+ bright_cyan: '\x1b[96m',
28
+ bright_black: '\x1b[90m',
29
+ bright_white: '\x1b[97m',
30
+ };
31
+
32
+ const codebox: CodeboxTokens = {
33
+ surfaceBg: '', // earlier style: no fill — rows sit on the terminal default
34
+ borderFg: `${c.dim}${c.cyan}`, // earlier two-tier border prefix (087e03e paint)
35
+ langFg: c.cyan, // earlier language-tag color
36
+ chipBgIdle: '', // no chip rectangle — label is plain fg text
37
+ chipBgHover: '', // hover = brighter fg instead of a bg change
38
+ chipFgIdle: c.green, // earlier green copy label
39
+ chipFgHover: `${c.bold}${c.green}`, // hover: bold green label, still bg-free
40
+ successFg: c.green, // success label `✓ copied` stays green, bg-free
41
+ };
42
+
43
+ const markdownTheme: MarkdownTheme = {
44
+ heading: (text: string) => `${c.bold}${c.bright_cyan}${text}${c.reset}`,
45
+ link: (text: string) => `${c.underline}${c.cyan}${text}${c.reset}`,
46
+ linkUrl: (text: string) => `${c.dim}${text}${c.reset}`,
47
+ code: (text: string) => `${c.bold}${c.magenta}${text}${c.reset}`,
48
+ codeBlock: (text: string) => `${c.bright_black}${text}${c.reset}`,
49
+ codeBlockBorder: (text: string) => `${c.dim}${c.bright_black}${text}${c.reset}`,
50
+ quote: (text: string) => `${c.italic}${c.dim}${text}${c.reset}`,
51
+ quoteBorder: (text: string) => `${c.bold}${c.cyan}${text}${c.reset}`,
52
+ hr: (text: string) => `${c.dim}${text}${c.reset}`,
53
+ listBullet: (text: string) => `${c.bold}${c.green}${text}${c.reset}`,
54
+ bold: (text: string) => `${c.bold}${c.bright_white}${text}${c.reset}`,
55
+ italic: (text: string) => `${c.italic}${c.dim}${text}${c.reset}`,
56
+ strikethrough: (text: string) => `${c.dim}${text}${c.reset}`,
57
+ underline: (text: string) => `${c.underline}${text}${c.reset}`,
58
+ highlightCode,
59
+ };
60
+
61
+ const editorTheme: EditorTheme = {
62
+ borderColor: (s) => `${surface.input.border}${s}${c.reset}`,
63
+ selectList: {
64
+ selectedPrefix: (s) => `${c.bold}${c.green}${s}${c.reset}`,
65
+ selectedText: (s) => `${c.bold}${s}${c.reset}`,
66
+ description: (s) => `${c.dim}${s}${c.reset}`,
67
+ scrollInfo: (s) => `${c.dim}${s}${c.reset}`,
68
+ noMatch: (s) => `${c.dim}${s}${c.reset}`,
69
+ },
70
+ };
71
+
72
+ /** Fallback display colours for roles that don't declare one. */
73
+ const agentColors: Record<string, string> = {
74
+ pal: c.cyan,
75
+ plan: c.red,
76
+ planner: c.red,
77
+ explore: c.green,
78
+ build: c.blue,
79
+ review: c.magenta,
80
+ librarian: c.yellow,
81
+ architect: c.bright_cyan,
82
+ };
83
+
84
+ /** Fallback display labels for roles that don't declare one. */
85
+ const agentLabels: Record<string, string> = {
86
+ pal: 'pal',
87
+ plan: 'plan',
88
+ planner: 'planner',
89
+ explore: 'explore',
90
+ build: 'builder',
91
+ review: 'reviewer',
92
+ librarian: 'librarian',
93
+ architect: 'architect',
94
+ };
95
+
96
+ /**
97
+ * Highlighter roles with their current c-based values — the default visual is
98
+ * unchanged: `keyword` is cyan+bold exactly as `${c.cyan}${c.bold}` painted it.
99
+ */
100
+ const syntax: SyntaxTokens = {
101
+ comment: c.bright_black, // highlight.ts:268,274,282,286
102
+ string: c.green, // highlight.ts:299,352
103
+ number: c.magenta, // highlight.ts:308,356
104
+ keyword: `${c.cyan}${c.bold}`, // highlight.ts:320
105
+ method: c.yellow, // highlight.ts:323
106
+ jsonKey: c.cyan, // highlight.ts:350
107
+ jsonPrimitive: c.magenta, // highlight.ts:354
108
+ plain: c.bright_black, // highlight.ts:236,248
109
+ };
110
+
111
+ /** Values equivalent to today's c.* reads in each component (no visual change). */
112
+ const surface: SurfaceTokens = {
113
+ window: {
114
+ bg: '', // terminal default — no canvas sync
115
+ fg: '', // terminal default — no canvas sync
116
+ border: c.dim, // reserved — window frame
117
+ },
118
+ input: {
119
+ border: c.dim, // editorTheme.borderColor prefix (index.ts:263)
120
+ fg: '\x1b[39m', // reserved — terminal default foreground
121
+ placeholder: c.dim, // reserved — no placeholder paint yet
122
+ },
123
+ sidebar: {
124
+ bg: '', // no panel — terminal canvas shows through
125
+ border: c.dim, // reserved — no sidebar border
126
+ title: `${c.bold}${c.cyan}`, // sidebar.ts:58
127
+ item: c.green, // sidebar.ts:76,89 status dot
128
+ itemAccent: `${c.bold}${c.green}`, // sidebar.ts:61,70,83,98 section headers
129
+ selected: c.cyan, // reserved — no selection state
130
+ dim: c.dim, // sidebar.ts:72,85,92,102
131
+ },
132
+ statusLine: {
133
+ border: c.dim, // reserved — no status-line border
134
+ flash: c.green, // index.ts:816
135
+ error: c.red, // reserved — no error state today
136
+ warn: c.yellow, // index.ts:771,775,783,795
137
+ info: c.cyan, // index.ts:789
138
+ dim: c.dim, // index.ts:797
139
+ },
140
+ overlay: {
141
+ border: c.dim, // reserved — overlay chrome border
142
+ selectedPrefix: c.cyan, // model-picker.ts:66, session-picker.ts:75
143
+ selectedText: c.bold, // model-picker.ts:67, session-picker.ts:76
144
+ description: c.dim, // model-picker.ts:68, session-picker.ts:77
145
+ scrollInfo: c.dim, // model-picker.ts:69, session-picker.ts:78
146
+ noMatch: c.dim, // model-picker.ts:70, session-picker.ts:79
147
+ },
148
+ permission: {
149
+ border: `${c.dim}${c.yellow}`, // permission-prompt.ts:41
150
+ header: `${c.bold}${c.yellow}`, // permission-prompt.ts:45,65
151
+ allow: c.green, // permission-prompt.ts:48
152
+ always: c.cyan, // permission-prompt.ts:49
153
+ deny: c.red, // permission-prompt.ts:50
154
+ dim: c.dim, // permission-prompt.ts:51,77
155
+ },
156
+ messageBox: {
157
+ border: c.dim, // format.ts:98 dim prefix on role-coloured border
158
+ dim: c.dim, // format.ts:150,181 timestamp
159
+ roleFallback: c.cyan, // format.ts:94
160
+ },
161
+ };
162
+
163
+ export const vanillaPi: Theme = {
164
+ name: 'vanilla-pi',
165
+ displayName: 'Vanilla Pi',
166
+ c,
167
+ codebox,
168
+ syntax,
169
+ markdownTheme,
170
+ editorTheme,
171
+ agentColors,
172
+ agentLabels,
173
+ surface,
174
+ colorByNameFallback: c.cyan, // HEAD default fallback of colorByName()
175
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Panel fill for fixed-width rows: open `bg` before the line, re-open it
3
+ * after every mid-line `\x1b[0m` (so no cell falls back to the terminal
4
+ * default), pad to `width` while the fill is open, and close with a single
5
+ * trailing reset. `bg === ''` returns `line` untouched — that passthrough
6
+ * is the vanilla byte-identity guarantee, not an optimization. Longer lines
7
+ * are never truncated: painting only adds a background frame and padding.
8
+ */
9
+
10
+ import {visibleWidth} from './tty-width.js';
11
+
12
+ export function paintPanel(bg: string, line: string, width: number): string {
13
+ if (bg === '') return line;
14
+ // keepSurface-style: a full reset mid-line drops the fill, so re-open it
15
+ // immediately after. A reset at the very end stays followed by the fill
16
+ // too — the pad below is painted, and only the trailing reset closes.
17
+ const kept = line.split('\x1b[0m').join(`\x1b[0m${bg}`);
18
+ const pad = width - visibleWidth(line);
19
+ return `${bg}${kept}${pad > 0 ? ' '.repeat(pad) : ''}\x1b[0m`;
20
+ }