pal-code 0.0.15 → 0.0.17

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 (33) hide show
  1. package/bin/pal-code.js +31 -15
  2. package/package.json +2 -2
  3. package/packages/cli/src/agent-panel.ts +1 -1
  4. package/packages/cli/src/commands.ts +1 -1
  5. package/packages/cli/src/components/assistant-body.ts +2 -2
  6. package/packages/cli/src/components/message-box.ts +1 -1
  7. package/packages/cli/src/components/permission-prompt.ts +3 -3
  8. package/packages/cli/src/components/render-history.ts +13 -12
  9. package/packages/cli/src/components/run-view.ts +109 -33
  10. package/packages/cli/src/components/sidebar.ts +73 -12
  11. package/packages/cli/src/components/status-line.ts +3 -3
  12. package/packages/cli/src/config.ts +1 -1
  13. package/packages/cli/src/index.ts +65 -27
  14. package/packages/cli/src/overlays/key-input.ts +2 -1
  15. package/packages/cli/src/overlays/model-picker.ts +2 -1
  16. package/packages/cli/src/overlays/session-picker.ts +3 -2
  17. package/packages/cli/src/state.ts +12 -0
  18. package/packages/cli/src/theme.ts +13 -1
  19. package/packages/cli/src/themes/github-dark.ts +14 -3
  20. package/packages/cli/src/themes/types.ts +26 -2
  21. package/packages/cli/src/themes/vanilla-pi.ts +23 -9
  22. package/packages/cli/src/tui/components/text.ts +102 -0
  23. package/packages/cli/src/tui/render/code-block.ts +325 -0
  24. package/packages/cli/src/{utils → tui/render}/format.ts +31 -24
  25. package/packages/cli/src/{utils → tui/render}/highlight.ts +94 -2
  26. package/packages/cli/src/tui/surface/index.ts +9 -0
  27. package/packages/cli/src/tui/{paint-panel.ts → surface/paint-panel.ts} +1 -1
  28. package/packages/cli/src/tui/theme-types.ts +59 -0
  29. package/packages/cli/src/tui/tty-width.ts +20 -0
  30. package/packages/cli/src/tui/types.ts +53 -0
  31. package/packages/cli/src/turn.ts +21 -11
  32. package/packages/cli/src/utils/permissions.ts +3 -3
  33. package/packages/cli/src/utils/code-block.ts +0 -200
@@ -10,21 +10,8 @@
10
10
  // Imports
11
11
  // ═══════════════════════════════════════════════════════════════════════════════
12
12
 
13
- import {
14
- ProcessTerminal,
15
- TuiMainScreen,
16
- Editor,
17
- Text,
18
- Container,
19
- Spacer,
20
- matchesKey,
21
- Key,
22
- CombinedAutocompleteProvider,
23
- setKeybindings,
24
- KeybindingsManager,
25
- TUI_KEYBINDINGS,
26
- detectCapabilities,
27
- } from '@earendil-works/pi-tui';
13
+ import {Text} from './tui/components/text.js';
14
+ import {ProcessTerminal, TuiMainScreen, Editor, Container, Spacer, matchesKey, Key, CombinedAutocompleteProvider, setKeybindings, KeybindingsManager, TUI_KEYBINDINGS, detectCapabilities} from '@earendil-works/pi-tui';
28
15
  import type {Component, TUI} from '@earendil-works/pi-tui';
29
16
  import {
30
17
  c,
@@ -43,7 +30,7 @@ import {
43
30
  sanitizeTitle,
44
31
  formatMessageTimestamp,
45
32
  subagentStatusText,
46
- } from './utils/format.js';
33
+ } from '././tui/render/format.js';
47
34
  import {MessageBox} from './components/message-box.js';
48
35
  import {renderHistory} from './components/render-history.js';
49
36
  import {AssistantBody} from './components/assistant-body.js';
@@ -54,6 +41,7 @@ import {PermissionPrompt} from './components/permission-prompt.js';
54
41
  import {
55
42
  dequeueMessage,
56
43
  enqueueMessage,
44
+ nextEscAction,
57
45
  queuedStatusText,
58
46
  resetSessionTokenomics,
59
47
  setSessionTokenomics,
@@ -130,7 +118,7 @@ import type {SessionStore as SessionStoreType} from '@pal-code/core';
130
118
  // (see buildModelOptions). Static curated lists live in @pal-code/core PROVIDERS as fallback.
131
119
 
132
120
  // Version synced from version.json via `node scripts/sync-version.js`.
133
- const VERSION = '0.0.15';
121
+ const VERSION = '0.0.17';
134
122
 
135
123
  // ── Canvas sync (OSC 10/11) ──
136
124
  // Raw reply payloads captured after a successful startup query + set, or null
@@ -364,7 +352,7 @@ async function main() {
364
352
  // Fixed sidebar width used by both the overlay compositor and the transcript
365
353
  // layout. Both must agree — if the layout reserves N columns but the overlay
366
354
  // paints at M ≠ N, the sidebar overpaints transcript content.
367
- const SIDEBAR_WIDTH = 30;
355
+ const SIDEBAR_WIDTH = 34;
368
356
  const sidebarWidthFor = (w: number): number => {
369
357
  if (w < 70) return 0; // too narrow — hide the sidebar
370
358
  return SIDEBAR_WIDTH;
@@ -848,8 +836,14 @@ async function main() {
848
836
  // settle). Empty at N=0, so the idle status line stays byte-identical.
849
837
  const queuedText = queuedStatusText(state.pendingMessages.length);
850
838
  const queuedStr = queuedText ? ` ${surface.statusLine.warn}${queuedText}${c.reset}` : '';
839
+ // Only meaningful while a turn is live; once it settles activeAbort is
840
+ // null and the prompt drops on the next repaint without extra wiring.
841
+ const abortStr =
842
+ state.abortArmed && state.activeAbort
843
+ ? ` ${surface.statusLine.warn}Esc again to stop${c.reset}`
844
+ : '';
851
845
  statusLine.setText(
852
- `${modelShort} ${surface.statusLine.dim}${providerName}${agentStr}${subStr}${queuedStr}${c.reset} ${surface.statusLine.dim}/help${c.reset}`,
846
+ `${modelShort} ${surface.statusLine.dim}${providerName}${agentStr}${subStr}${queuedStr}${abortStr}${c.reset} ${surface.statusLine.dim}/help${c.reset}`,
853
847
  );
854
848
  }
855
849
  // A copy flash outranks every other status for its 1500ms window, so a
@@ -861,6 +855,8 @@ async function main() {
861
855
  cachedTokens: state.sessionTokenomics.cachedTokens,
862
856
  cost: state.sessionTokenomics.cost,
863
857
  contextPct,
858
+ ctxTokens,
859
+ contextLimit: config.contextLimit,
864
860
  priced: isPricedModel(config.model),
865
861
  });
866
862
  tui.requestRender();
@@ -1040,10 +1036,36 @@ async function main() {
1040
1036
  return false;
1041
1037
  }
1042
1038
 
1039
+ // Esc needs a second press to stop a run: the first arms a short window
1040
+ // instead of killing the turn, so a stray Esc mid-thought is harmless. Any
1041
+ // other key disarms, and the window closes itself so a forgotten arm cannot
1042
+ // turn the next Esc into an accidental kill.
1043
+ let abortArmTimer: ReturnType<typeof setTimeout> | null = null;
1044
+ const disarmAbort = (): void => {
1045
+ state.abortArmed = false;
1046
+ if (abortArmTimer) {
1047
+ clearTimeout(abortArmTimer);
1048
+ abortArmTimer = null;
1049
+ }
1050
+ };
1051
+ const armAbort = (): void => {
1052
+ disarmAbort();
1053
+ state.abortArmed = true;
1054
+ abortArmTimer = setTimeout(() => {
1055
+ state.abortArmed = false;
1056
+ abortArmTimer = null;
1057
+ updateStatusLine();
1058
+ }, 5000);
1059
+ };
1060
+
1043
1061
  // ── Exit handler: intercept raw Ctrl+C and Ctrl+D via input listener ──
1044
1062
  // pi-tui maps ctrl+c to "copy selection" and ctrl+d to "delete", so we
1045
1063
  // listen at the raw TUI level. On empty editor, these become exit signals.
1046
1064
  tui.addInputListener((data: string) => {
1065
+ if (state.abortArmed && !matchesKey(data, 'escape')) {
1066
+ disarmAbort();
1067
+ updateStatusLine();
1068
+ }
1047
1069
  if (matchesKey(data, 'ctrl+c') || matchesKey(data, 'ctrl+d')) {
1048
1070
  if (editor.getText().trim().length === 0) {
1049
1071
  saveSession();
@@ -1178,10 +1200,16 @@ async function main() {
1178
1200
  cycleAgentRole();
1179
1201
  return {consume: true};
1180
1202
  }
1181
- // Esc aborts a running turn (keeps the session). Only active mid-turn —
1182
- // otherwise Esc falls through to the editor (autocomplete dismissal).
1203
+ // Esc stops a running turn (keeps the session) — but only on a confirmed
1204
+ // second press, so an accidental Esc never kills work in flight.
1183
1205
  if (matchesKey(data, 'escape') && state.activeAbort) {
1184
- state.activeAbort.abort();
1206
+ if (nextEscAction(state.abortArmed).abort) {
1207
+ disarmAbort();
1208
+ state.activeAbort.abort();
1209
+ } else {
1210
+ armAbort();
1211
+ }
1212
+ updateStatusLine();
1185
1213
  return {consume: true};
1186
1214
  }
1187
1215
  if (matchesKey(data, 'ctrl+b')) {
@@ -2006,12 +2034,22 @@ async function main() {
2006
2034
  // `boundary` is a whole-history COUNT; the store speaks in 1-based seqs,
2007
2035
  // and a rolled-back earlier turn can shift them apart, so convert through
2008
2036
  // the same helper the agent uses instead of assuming they're equal.
2009
- if (result.compaction && store && currentSessionId) {
2010
- const from = store.getCompactedUpto(currentSessionId);
2011
- const to = seqToCount(result.compaction.boundary, messages.length);
2012
- if (to > from) {
2013
- store.recordCompaction(currentSessionId, from, to, result.compaction.summary);
2037
+ if (result.compactions.length > 0) {
2038
+ for (const rec of result.compactions) {
2039
+ const from = store && currentSessionId ? store.getCompactedUpto(currentSessionId) : 0;
2040
+ const to = seqToCount(rec.boundary, messages.length);
2041
+ if (store && currentSessionId && to > from) {
2042
+ store.recordCompaction(currentSessionId, from, to, rec.summary);
2043
+ }
2044
+ messagesContainer.addChild(
2045
+ new Text(
2046
+ `${c.green}✓ Context compacted${c.reset} ${c.dim}· ${rec.summarized} messages summarized into a checkpoint (messages ${from + 1}–${to})${c.reset}`,
2047
+ 1,
2048
+ 0,
2049
+ ),
2050
+ );
2014
2051
  }
2052
+ tui.requestRender();
2015
2053
  }
2016
2054
  } catch (err) {
2017
2055
  const msg = err instanceof Error ? err.message : String(err);
@@ -1,6 +1,7 @@
1
1
  /** `/key` overlay — provider picker then paste a key, hot-reload. */
2
2
 
3
- import {Text, Input} from '@earendil-works/pi-tui';
3
+ import {Text} from '../tui/components/text.js';
4
+ import {Input} from '@earendil-works/pi-tui';
4
5
  import type {TUI, Container, Editor} from '@earendil-works/pi-tui';
5
6
  import {PROVIDERS, detectProvider, saveKey, saveSetting} from '@pal-code/core';
6
7
  import type {Config} from '../config.js';
@@ -1,6 +1,7 @@
1
1
  /** Model picker — lists exactly what each configured provider reports. */
2
2
 
3
- import {Text, SelectList} from '@earendil-works/pi-tui';
3
+ import {Text} from '../tui/components/text.js';
4
+ import {SelectList} from '@earendil-works/pi-tui';
4
5
  import type {TUI, Container, Editor, SelectItem} from '@earendil-works/pi-tui';
5
6
  import {PROVIDERS, resolveModelIds, saveSetting} from '@pal-code/core';
6
7
  import type {Provider, ProviderKeys} from '@pal-code/core';
@@ -5,11 +5,12 @@
5
5
  * explicit id or unambiguous prefix.
6
6
  */
7
7
 
8
- import {Text, SelectList} from '@earendil-works/pi-tui';
8
+ import {Text} from '../tui/components/text.js';
9
+ import {SelectList} from '@earendil-works/pi-tui';
9
10
  import type {TUI, Container, Editor, SelectItem} from '@earendil-works/pi-tui';
10
11
 
11
12
  import {c, surface} from '../theme.js';
12
- import {truncate} from '../utils/format.js';
13
+ import {truncate} from '../tui/render/format.js';
13
14
  import type {ConversationMessage as Message, Session, SessionStore} from '@pal-code/core';
14
15
 
15
16
  export function groupByDate(sessions: readonly Session[]): Map<string, Session[]> {
@@ -79,6 +79,8 @@ export interface AppState {
79
79
  activeRun: RunView | null;
80
80
  /** Cancels the in-flight turn (Esc). */
81
81
  activeAbort: AbortController | null;
82
+ /** First Esc armed a stop; a second one inside the window aborts the turn. */
83
+ abortArmed: boolean;
82
84
  /** The most recently collapsed run, for ctrl+o. */
83
85
  lastRun: RunView | null;
84
86
  /** Messages submitted while a turn was running; drained one per settled turn. */
@@ -131,6 +133,7 @@ export const state: AppState = {
131
133
  backgroundAgents: [],
132
134
  activeRun: null,
133
135
  activeAbort: null,
136
+ abortArmed: false,
134
137
  lastRun: null,
135
138
  pendingMessages: [],
136
139
  extensions: [],
@@ -156,6 +159,15 @@ export function enqueueMessage(queue: string[], message: string): number {
156
159
  return queue.length;
157
160
  }
158
161
 
162
+ /**
163
+ * Resolve one Esc press against the two-press stop contract: the first press
164
+ * only arms (so a stray Esc never kills work in flight), the second one inside
165
+ * the arm window aborts. Pure — the caller owns the timer and the controller.
166
+ */
167
+ export function nextEscAction(armed: boolean): {armed: boolean; abort: boolean} {
168
+ return armed ? {armed: false, abort: true} : {armed: true, abort: false};
169
+ }
170
+
159
171
  /**
160
172
  * Take the next message to run when a turn settles — completed, errored, or
161
173
  * aborted alike. Returns null when nothing is queued.
@@ -11,7 +11,7 @@
11
11
  * the pure `resolveTheme()` in themes/index.ts.
12
12
  */
13
13
 
14
- import type {EditorTheme, MarkdownTheme} from '@earendil-works/pi-tui';
14
+ import type {EditorTheme, MarkdownTheme} from './tui/theme-types.js';
15
15
  import type {CColors, CodeboxTokens, SurfaceTokens, SyntaxTokens, Theme} from './themes/types.js';
16
16
  import {themes} from './themes/index.js';
17
17
  import {vanillaPi} from './themes/vanilla-pi.js';
@@ -116,6 +116,15 @@ export const codebox: CodeboxTokens = {
116
116
  get successFg() {
117
117
  return current.codebox.successFg;
118
118
  },
119
+ get gutterFg() {
120
+ return current.codebox.gutterFg;
121
+ },
122
+ get diffDelBg() {
123
+ return current.codebox.diffDelBg;
124
+ },
125
+ get diffAddBg() {
126
+ return current.codebox.diffAddBg;
127
+ },
119
128
  };
120
129
 
121
130
  export const markdownTheme: MarkdownTheme = {
@@ -251,4 +260,7 @@ export const surface: SurfaceTokens = {
251
260
  get messageBox() {
252
261
  return current.surface.messageBox;
253
262
  },
263
+ get runView() {
264
+ return current.surface.runView;
265
+ },
254
266
  };
@@ -6,8 +6,8 @@
6
6
  * `syntax` and `surface` extend it with GitHub Dark syntax colours.
7
7
  */
8
8
 
9
- import type {EditorTheme, MarkdownTheme} from '@earendil-works/pi-tui';
10
- import {highlightCode} from '../utils/highlight.js';
9
+ import type {EditorTheme, MarkdownTheme} from '../tui/theme-types.js';
10
+ import {highlightCode} from '../tui/render/highlight.js';
11
11
  import type {CColors, CodeboxTokens, SurfaceTokens, SyntaxTokens, Theme} from './types.js';
12
12
 
13
13
  const c: CColors = {
@@ -40,6 +40,9 @@ const codebox: CodeboxTokens = {
40
40
  chipFgIdle: '\x1b[38;2;201;209;217m', // #c9d1d9 — GitHub primary text
41
41
  chipFgHover: '\x1b[38;2;240;246;252m', // #f0f6fc — GitHub bright text on hover
42
42
  successFg: '\x1b[38;2;63;185;80m', // #3fb950 — GitHub success green
43
+ gutterFg: '\x1b[38;2;72;79;88m', // #484f58 — dimmer shade of border #30363d
44
+ diffDelBg: '\x1b[48;2;61;26;30m', // #3d1a1e - GitHub red wash behind removed diff lines
45
+ diffAddBg: '\x1b[48;2;26;61;42m', // #1a3d2a - GitHub green wash behind added diff lines
43
46
  };
44
47
 
45
48
  const markdownTheme: MarkdownTheme = {
@@ -129,7 +132,8 @@ const surface: SurfaceTokens = {
129
132
  dim: c.dim, // SGR dim (sidebar.ts:72,85,92,102)
130
133
  },
131
134
  statusLine: {
132
- border: '\x1b[38;2;48;54;61m', // #30363d (reserved)
135
+ bg: '\x1b[48;2;1;4;9m', // #010409 — panel fill (same tone as sidebar)
136
+ border: '\x1b[38;2;48;54;61m', // #30363d — status-line.ts right-edge segment accent
133
137
  flash: c.green, // #3fb950 — index.ts:816
134
138
  error: c.red, // #f85149 (reserved — no error state today)
135
139
  warn: c.yellow, // #d29922 — index.ts:771,775,783,795
@@ -157,6 +161,13 @@ const surface: SurfaceTokens = {
157
161
  dim: c.dim, // SGR dim — format.ts:150,181
158
162
  roleFallback: c.cyan, // #39c5cf — format.ts:94
159
163
  },
164
+ runView: {
165
+ row: c.bright_black, // #8b949e — run-view.ts:111, render-history.ts:90,104
166
+ elapsed: c.bright_black, // #8b949e — run-view.ts:109
167
+ preview: c.bright_black, // #8b949e — run-view.ts:110, render-history.ts:90
168
+ summary: c.bright_black, // #8b949e — run-view.ts:226
169
+ border: c.bright_black, // #8b949e — run-view.ts:88,91,94
170
+ },
160
171
  };
161
172
 
162
173
  export const githubDark: Theme = {
@@ -14,7 +14,7 @@
14
14
  * or is marked `reserved`.
15
15
  */
16
16
 
17
- import type {EditorTheme, MarkdownTheme} from '@earendil-works/pi-tui';
17
+ import type {EditorTheme, MarkdownTheme} from '../tui/theme-types.js';
18
18
 
19
19
  /** The 17 raw ANSI SGR codes every renderer reads through the `c` facade. */
20
20
  export interface CColors {
@@ -47,6 +47,12 @@ export interface CodeboxTokens {
47
47
  chipFgIdle: string;
48
48
  chipFgHover: string;
49
49
  successFg: string;
50
+ /** consumed by utils/code-block.ts (line-number gutter) — dimmer shade of borderFg. */
51
+ gutterFg: string;
52
+ /** Full-row wash behind removed diff lines - utils/highlight.ts diffLineTint. */
53
+ diffDelBg: string;
54
+ /** Full-row wash behind added diff lines - utils/highlight.ts diffLineTint. */
55
+ diffAddBg: string;
50
56
  }
51
57
 
52
58
  /**
@@ -119,7 +125,13 @@ export interface SurfaceTokens {
119
125
  dim: string;
120
126
  };
121
127
  statusLine: {
122
- /** reserved — the status line paints no border (Phase B). */
128
+ /**
129
+ * Panel fill behind the status line via tui/paint-panel.ts —
130
+ * `''` = terminal default (passthrough, zero bytes). Consumed by
131
+ * components/status-line.ts render().
132
+ */
133
+ bg: string;
134
+ /** consumed by components/status-line.ts (right-edge segment accent). */
123
135
  border: string;
124
136
  /** consumed by index.ts:836 (flashCopied confirmation). */
125
137
  flash: string;
@@ -168,6 +180,18 @@ export interface SurfaceTokens {
168
180
  /** consumed by utils/format.ts:94 (unknown-role colour fallback). */
169
181
  roleFallback: string;
170
182
  };
183
+ runView: {
184
+ /** consumed by run-view.ts:111 + render-history.ts:90,104 (tool name / args). */
185
+ row: string;
186
+ /** consumed by run-view.ts:109 (finished-tool elapsed time). */
187
+ elapsed: string;
188
+ /** consumed by run-view.ts:110 + render-history.ts:90 (`→ preview` tail). */
189
+ preview: string;
190
+ /** consumed by run-view.ts:226 (collapsed one-line run summary). */
191
+ summary: string;
192
+ /** consumed by run-view.ts:88,91,94 (round/tool separators, model·secs meta). */
193
+ border: string;
194
+ };
171
195
  }
172
196
 
173
197
  /** A complete, self-contained theme. */
@@ -5,8 +5,8 @@
5
5
  * exactly what shipped before the theme system existed.
6
6
  */
7
7
 
8
- import type {EditorTheme, MarkdownTheme} from '@earendil-works/pi-tui';
9
- import {highlightCode} from '../utils/highlight.js';
8
+ import type {EditorTheme, MarkdownTheme} from '../tui/theme-types.js';
9
+ import {highlightCode} from '../tui/render/highlight.js';
10
10
  import type {CColors, CodeboxTokens, SurfaceTokens, SyntaxTokens, Theme} from './types.js';
11
11
 
12
12
  const c: CColors = {
@@ -29,15 +29,21 @@ const c: CColors = {
29
29
  bright_white: '\x1b[97m',
30
30
  };
31
31
 
32
+ /** Readable mid-gray for code text (#8b949e — github-dark's muted tone). */
33
+ const codeGray = '\x1b[38;2;139;148;158m';
34
+
32
35
  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)
36
+ surfaceBg: '\x1b[48;2;24;27;31m', // subtle dark fill (#181b1f)
37
+ borderFg: c.cyan, // cyan hue kept; faint (SGR 2) removed for contrast
35
38
  langFg: c.cyan, // earlier language-tag color
36
39
  chipBgIdle: '', // no chip rectangle — label is plain fg text
37
40
  chipBgHover: '', // hover = brighter fg instead of a bg change
38
41
  chipFgIdle: c.green, // earlier green copy label
39
42
  chipFgHover: `${c.bold}${c.green}`, // hover: bold green label, still bg-free
40
43
  successFg: c.green, // success label `✓ copied` stays green, bg-free
44
+ gutterFg: '\x1b[38;2;74;118;120m', // muted teal — dimmer shade of cyan border (#4a7678)
45
+ diffDelBg: '\x1b[48;2;61;34;38m', // dark red wash behind removed diff lines (#3d2226)
46
+ diffAddBg: '\x1b[48;2;30;58;42m', // dark green wash behind added diff lines (#1e3a2a)
41
47
  };
42
48
 
43
49
  const markdownTheme: MarkdownTheme = {
@@ -45,8 +51,8 @@ const markdownTheme: MarkdownTheme = {
45
51
  link: (text: string) => `${c.underline}${c.cyan}${text}${c.reset}`,
46
52
  linkUrl: (text: string) => `${c.dim}${text}${c.reset}`,
47
53
  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}`,
54
+ codeBlock: (text: string) => `${codeGray}${text}${c.reset}`,
55
+ codeBlockBorder: (text: string) => `${codeGray}${text}${c.reset}`,
50
56
  quote: (text: string) => `${c.italic}${c.dim}${text}${c.reset}`,
51
57
  quoteBorder: (text: string) => `${c.bold}${c.cyan}${text}${c.reset}`,
52
58
  hr: (text: string) => `${c.dim}${text}${c.reset}`,
@@ -98,14 +104,14 @@ const agentLabels: Record<string, string> = {
98
104
  * unchanged: `keyword` is cyan+bold exactly as `${c.cyan}${c.bold}` painted it.
99
105
  */
100
106
  const syntax: SyntaxTokens = {
101
- comment: c.bright_black, // highlight.ts:268,274,282,286
107
+ comment: codeGray, // highlight.ts:268,274,282,286
102
108
  string: c.green, // highlight.ts:299,352
103
109
  number: c.magenta, // highlight.ts:308,356
104
110
  keyword: `${c.cyan}${c.bold}`, // highlight.ts:320
105
111
  method: c.yellow, // highlight.ts:323
106
112
  jsonKey: c.cyan, // highlight.ts:350
107
113
  jsonPrimitive: c.magenta, // highlight.ts:354
108
- plain: c.bright_black, // highlight.ts:236,248
114
+ plain: codeGray, // highlight.ts:236,248
109
115
  };
110
116
 
111
117
  /** Values equivalent to today's c.* reads in each component (no visual change). */
@@ -130,7 +136,8 @@ const surface: SurfaceTokens = {
130
136
  dim: c.dim, // sidebar.ts:72,85,92,102
131
137
  },
132
138
  statusLine: {
133
- border: c.dim, // reserved — no status-line border
139
+ bg: '\x1b[48;2;32;36;44m', // #20242c — status tier fill, a step lighter than code fill
140
+ border: c.dim, // consumed by status-line.ts right-edge segment accent
134
141
  flash: c.green, // index.ts:816
135
142
  error: c.red, // reserved — no error state today
136
143
  warn: c.yellow, // index.ts:771,775,783,795
@@ -158,6 +165,13 @@ const surface: SurfaceTokens = {
158
165
  dim: c.dim, // format.ts:150,181 timestamp
159
166
  roleFallback: c.cyan, // format.ts:94
160
167
  },
168
+ runView: {
169
+ row: c.dim, // run-view.ts:111, render-history.ts:90,104
170
+ elapsed: c.dim, // run-view.ts:109
171
+ preview: c.dim, // run-view.ts:110, render-history.ts:90
172
+ summary: c.dim, // run-view.ts:226
173
+ border: c.dim, // run-view.ts:88,91,94
174
+ },
161
175
  };
162
176
 
163
177
  export const vanillaPi: Theme = {
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Text — displays multi-line text with word wrapping.
3
+ *
4
+ * pi-tui-free replacement for `Text` from @earendil-works/pi-tui, matching
5
+ * its behaviour exactly: tabs become three spaces, padding shrinks rather than
6
+ * overflow when the viewport is narrow, every emitted line is padded to `width`
7
+ * so the engine's differential renderer sees a stable row width, and an empty
8
+ * or whitespace-only string renders nothing at all.
9
+ */
10
+
11
+ import {applyBackgroundToLine, visibleWidth, wrapTextWithAnsi} from '../tty-width.js';
12
+ import type {Component} from '../types.js';
13
+
14
+ /** Paints a whole line (content + trailing padding) with a background. */
15
+ export type BackgroundFn = (text: string) => string;
16
+
17
+ export class Text implements Component {
18
+ private text: string;
19
+ private paddingX: number;
20
+ private paddingY: number;
21
+ private customBgFn?: BackgroundFn;
22
+
23
+ private cachedText?: string;
24
+ private cachedWidth?: number;
25
+ private cachedLines?: string[];
26
+
27
+ constructor(text = '', paddingX = 1, paddingY = 1, customBgFn?: BackgroundFn) {
28
+ this.text = text;
29
+ this.paddingX = paddingX;
30
+ this.paddingY = paddingY;
31
+ this.customBgFn = customBgFn;
32
+ }
33
+
34
+ setText(text: string): void {
35
+ this.text = text;
36
+ this.invalidate();
37
+ }
38
+
39
+ setCustomBgFn(customBgFn?: BackgroundFn): void {
40
+ this.customBgFn = customBgFn;
41
+ this.invalidate();
42
+ }
43
+
44
+ invalidate(): void {
45
+ this.cachedText = undefined;
46
+ this.cachedWidth = undefined;
47
+ this.cachedLines = undefined;
48
+ }
49
+
50
+ render(width: number): string[] {
51
+ // Repaint only when the text or the viewport actually changed — this is
52
+ // what keeps a live TUI from reflowing on every streaming delta.
53
+ if (this.cachedLines && this.cachedText === this.text && this.cachedWidth === width) {
54
+ return this.cachedLines;
55
+ }
56
+
57
+ // Nothing to show: an empty line would otherwise occupy a row.
58
+ if (!this.text || this.text.trim() === '') {
59
+ const empty: string[] = [];
60
+ this.cachedText = this.text;
61
+ this.cachedWidth = width;
62
+ this.cachedLines = empty;
63
+ return empty;
64
+ }
65
+
66
+ const normalizedText = this.text.replace(/\t/g, ' ');
67
+
68
+ // Shrink the margins rather than let content overflow on a narrow viewport.
69
+ const paddingX = Math.min(this.paddingX, Math.max(0, Math.floor((width - 1) / 2)));
70
+ const contentWidth = Math.max(1, width - paddingX * 2);
71
+
72
+ // Wrap first (preserves ANSI, does not pad), then margin each row.
73
+ const wrappedLines = wrapTextWithAnsi(normalizedText, contentWidth);
74
+ const margin = ' '.repeat(paddingX);
75
+
76
+ const contentLines: string[] = [];
77
+ for (const line of wrappedLines) {
78
+ const withMargins = margin + line + margin;
79
+ if (this.customBgFn) {
80
+ // applyBackgroundToLine also pads to full width.
81
+ contentLines.push(applyBackgroundToLine(withMargins, width, this.customBgFn));
82
+ } else {
83
+ const pad = Math.max(0, width - visibleWidth(withMargins));
84
+ contentLines.push(withMargins + ' '.repeat(pad));
85
+ }
86
+ }
87
+
88
+ const blank = ' '.repeat(width);
89
+ const emptyLines: string[] = [];
90
+ for (let i = 0; i < this.paddingY; i++) {
91
+ emptyLines.push(
92
+ this.customBgFn ? applyBackgroundToLine(blank, width, this.customBgFn) : blank,
93
+ );
94
+ }
95
+
96
+ const result = [...emptyLines, ...contentLines, ...emptyLines];
97
+ this.cachedText = this.text;
98
+ this.cachedWidth = width;
99
+ this.cachedLines = result;
100
+ return result.length > 0 ? result : [''];
101
+ }
102
+ }