pal-code 0.0.16 → 0.0.18

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 (40) hide show
  1. package/README.md +9 -6
  2. package/SYSTEM.md +17 -2
  3. package/package.json +10 -5
  4. package/packages/cli/src/agent-panel.ts +1 -1
  5. package/packages/cli/src/agent-ui.ts +66 -0
  6. package/packages/cli/src/commands/ext-registry.ts +7 -0
  7. package/packages/cli/src/commands.ts +32 -102
  8. package/packages/cli/src/components/assistant-body.ts +4 -3
  9. package/packages/cli/src/components/message-box.ts +2 -2
  10. package/packages/cli/src/components/permission-prompt.ts +3 -3
  11. package/packages/cli/src/components/render-history.ts +13 -12
  12. package/packages/cli/src/components/run-view.ts +109 -33
  13. package/packages/cli/src/components/sidebar.ts +81 -14
  14. package/packages/cli/src/components/status-line.ts +3 -3
  15. package/packages/cli/src/config.ts +6 -129
  16. package/packages/cli/src/index.ts +194 -69
  17. package/packages/cli/src/overlays/key-input.ts +142 -121
  18. package/packages/cli/src/overlays/model-picker.ts +19 -56
  19. package/packages/cli/src/overlays/select.ts +102 -0
  20. package/packages/cli/src/overlays/session-picker.ts +14 -40
  21. package/packages/cli/src/overlays/wizard.ts +107 -42
  22. package/packages/cli/src/prompt/select.ts +181 -0
  23. package/packages/cli/src/slash-commands.ts +105 -0
  24. package/packages/cli/src/state.ts +32 -74
  25. package/packages/cli/src/theme.ts +13 -1
  26. package/packages/cli/src/themes/github-dark.ts +14 -3
  27. package/packages/cli/src/themes/types.ts +26 -2
  28. package/packages/cli/src/themes/vanilla-pi.ts +23 -9
  29. package/packages/cli/src/tui/components/text.ts +102 -0
  30. package/packages/cli/src/tui/render/code-block.ts +325 -0
  31. package/packages/cli/src/{utils → tui/render}/format.ts +31 -24
  32. package/packages/cli/src/{utils → tui/render}/highlight.ts +94 -2
  33. package/packages/cli/src/tui/render/markdown.ts +529 -0
  34. package/packages/cli/src/tui/surface/index.ts +9 -0
  35. package/packages/cli/src/tui/{paint-panel.ts → surface/paint-panel.ts} +1 -1
  36. package/packages/cli/src/tui/theme-types.ts +59 -0
  37. package/packages/cli/src/tui/tty-width.ts +20 -0
  38. package/packages/cli/src/tui/types.ts +53 -0
  39. package/packages/cli/src/turn.ts +0 -292
  40. package/packages/cli/src/utils/code-block.ts +0 -200
@@ -1,7 +1,7 @@
1
- import {visibleWidth, wrapTextWithAnsi, truncateToWidth} from '../tui/tty-width.js';
1
+ import {visibleWidth, wrapTextWithAnsi, truncateToWidth} from '../tty-width.js';
2
2
 
3
- import {c, agentColors, agentLabels, surface} from '../theme.js';
4
- import type {AgentRole} from '../state.js';
3
+ import {c, agentColors, agentLabels, surface} from '../../theme.js';
4
+ import type {AgentRole} from '../../state.js';
5
5
 
6
6
  /**
7
7
  * Small text helpers shared by the renderers.
@@ -63,19 +63,19 @@ export function wrapText(text: string, maxWidth: number): string[] {
63
63
  }
64
64
 
65
65
  /**
66
- * Wrap a user message in a rounded Unicode box.
66
+ * Wrap a user message in a rounded Unicode box with a role icon column:
67
67
  *
68
- * The role tag sits in the top border (coloured by role, dimmed border); the
69
- * body carries only the message text. Every emitted row is exactly `width`
70
- * visible columns wide, so the box stays aligned at any terminal size:
68
+ * ╭─ [builder] ─── Mon 14:30 ─╮
69
+ * │ ▸ message text here │
70
+ * │ continued line │
71
+ * ╰───────────────────────────╯
71
72
  *
72
- * ╭─ [builder] ─────────╮
73
- * │ message text here │
74
- * │ continued line │
75
- * ╰─────────────────────╯
76
- *
77
- * Narrow terminals degrade cleanly: the tag is dropped once it no longer fits,
78
- * and `width` is clamped to a floor so the borders never collapse.
73
+ * Every body row carries a 2-column icon gutter (role-coloured `▸` on the
74
+ * first row, blanks on continuations) so text starts at one fixed column;
75
+ * the timestamp sits right-aligned in the header in `messageBox.dim`.
76
+ * Narrow terminals degrade cleanly: the icon column is dropped once the text
77
+ * would have fewer than 3 columns, then the timestamp, then the tag, and
78
+ * `width` is clamped to a floor so the borders never collapse.
79
79
  */
80
80
  export function userMessageBox(
81
81
  text: string,
@@ -85,8 +85,7 @@ export function userMessageBox(
85
85
  ): string {
86
86
  // One clamp before anything is derived, so header/body/footer agree.
87
87
  const W = Math.max(6, Math.floor(width));
88
- const inner = W - 4; // columns between "│ " and " │"
89
- const textWidth = Math.max(1, inner - 1); // reserve the last inner column
88
+ const inner = W - 4; // columns between the side walls
90
89
 
91
90
  const label = String(agentLabels[role] ?? role ?? '');
92
91
  const tagText = `[${label}]`;
@@ -99,17 +98,25 @@ export function userMessageBox(
99
98
 
100
99
  const header = buildHeader(W, tagText, tagWidth, roleColor, paint, timestamp);
101
100
 
102
- const body = wrapText(text, textWidth)
103
- .map((line) => {
104
- const safe = truncateToWidth(line.trimEnd(), textWidth, '');
105
- const pad = Math.max(0, inner - visibleWidth(safe));
106
- return `${paint('│')} ${safe}${c.reset}${' '.repeat(pad)} ${paint('│')}`;
107
- })
108
- .join('\n');
101
+ // Icon column: 2 columns (`▸ `), kept only when the code column still has
102
+ // room for readable text. Continuation rows pad it blank so every line's
103
+ // text starts at the same visible column.
104
+ const ICON_W = 2;
105
+ const iconOn = inner - ICON_W >= 4;
106
+ const available = inner - (iconOn ? ICON_W : 0); // text + right pad
107
+ const textWidth = Math.max(1, available - 1); // reserve the last available column
108
+
109
+ const rows: string[] = [];
110
+ wrapText(text, textWidth).forEach((line, i) => {
111
+ const safe = truncateToWidth(line.trimEnd(), textWidth, '');
112
+ const pad = Math.max(0, available - visibleWidth(safe));
113
+ const lead = iconOn ? (i === 0 ? `${roleColor}▸${c.reset} ` : ' ') : '';
114
+ rows.push(`${paint('│')} ${lead}${safe}${c.reset}${' '.repeat(pad)} ${paint('│')}`);
115
+ });
109
116
 
110
117
  const footer = paint(`╰${'─'.repeat(W - 2)}╯`);
111
118
 
112
- return `${header}\n${body}\n${footer}`;
119
+ return `${header}\n${rows.join('\n')}\n${footer}`;
113
120
  }
114
121
 
115
122
  /**
@@ -2,10 +2,10 @@
2
2
  * Lightweight syntax highlighting for terminal code blocks.
3
3
  *
4
4
  * Zero dependencies — keyword + regex based. Covers the most common
5
- * languages well enough for agent output (TS, JS, Python, JSON, Shell, Go, Rust).
5
+ * languages well enough for agent output (TS, JS, Python, JSON, Shell, Go, Rust, diff).
6
6
  */
7
7
 
8
- import {c, syntax} from '../theme.js';
8
+ import {c, codebox, syntax} from '../../theme.js';
9
9
 
10
10
  // Per-language keyword sets
11
11
  const KEYWORDS: Record<string, Set<string> | null> = {
@@ -240,6 +240,13 @@ export function highlightCode(code: string, lang?: string): string[] {
240
240
  // JSON gets special treatment — highlight keys and string values differently
241
241
  if (lang === 'json') return lines.map((l) => highlightJson(l));
242
242
 
243
+ // Unified diffs: infer the code language from the ---/+++ file headers
244
+ // so added/removed lines get real syntax colors, not just role colors.
245
+ if (lang === 'diff' || lang === 'patch') {
246
+ const codeLang = inferDiffCodeLang(lines);
247
+ return lines.map((l) => highlightDiff(l, codeLang));
248
+ }
249
+
243
250
  return lines.map((line) => {
244
251
  if (keywords) {
245
252
  return highlightLine(line, keywords);
@@ -249,6 +256,91 @@ export function highlightCode(code: string, lang?: string): string[] {
249
256
  });
250
257
  }
251
258
 
259
+ /** File extension → highlight language for code inside diff blocks. */
260
+ const DIFF_LANG_BY_EXT: Record<string, string> = {
261
+ ts: 'typescript',
262
+ mts: 'typescript',
263
+ cts: 'typescript',
264
+ tsx: 'typescript',
265
+ js: 'javascript',
266
+ mjs: 'javascript',
267
+ cjs: 'javascript',
268
+ jsx: 'javascript',
269
+ py: 'python',
270
+ rs: 'rust',
271
+ sh: 'shell',
272
+ bash: 'shell',
273
+ zsh: 'shell',
274
+ go: 'go',
275
+ json: 'json',
276
+ };
277
+
278
+ /**
279
+ * Guess the code language of a unified diff from its ---/+++ file headers.
280
+ * Returns null when no header carries a recognized extension — callers then
281
+ * keep role-only colors instead of guessing wrong.
282
+ */
283
+ export function inferDiffCodeLang(lines: readonly string[]): string | null {
284
+ for (const line of lines) {
285
+ const m = /^(?:---|\+\+\+)\s+(?:[ab]\/)?(.+)$/.exec(line.trim());
286
+ if (!m) continue;
287
+ const path = m[1] ?? '';
288
+ const dot = path.lastIndexOf('.');
289
+ if (dot === -1) continue;
290
+ const lang = DIFF_LANG_BY_EXT[path.slice(dot + 1).toLowerCase()];
291
+ if (lang) return lang;
292
+ }
293
+ return null;
294
+ }
295
+
296
+ /**
297
+ * Highlight a unified diff line by role.
298
+ *
299
+ * +++ b/file / --- a/file file headers (bold)
300
+ * @@ -1,3 +1,4 @@ hunk headers (cyan)
301
+ * +added additions (green sign + syntax-colored code)
302
+ * -removed removals (red sign + syntax-colored code)
303
+ * context everything else (plain)
304
+ *
305
+ * The +/- sign carries the role color; the code after it is highlighted
306
+ * with `codeLang` when provided (inferred from the file headers) so
307
+ * keywords/strings/numbers read exactly like a normal code block.
308
+ */
309
+ export function highlightDiff(line: string, codeLang?: string | null): string {
310
+ if (line.startsWith('+++') || line.startsWith('---')) return `${c.bold}${line}${c.reset}`;
311
+ if (line.startsWith('@@')) return `${c.cyan}${line}${c.reset}`;
312
+ if ((line.startsWith('+') || line.startsWith('-')) && codeLang) {
313
+ const role = line.startsWith('+') ? c.green : c.red;
314
+ const rest = highlightCode(line.slice(1), codeLang)[0] ?? '';
315
+ return `${role}${line[0]}${c.reset}${rest}${c.reset}`;
316
+ }
317
+ if (line.startsWith('+')) return `${c.green}${line}${c.reset}`;
318
+ if (line.startsWith('-')) return `${c.red}${line}${c.reset}`;
319
+ return `${syntax.plain}${line}${c.reset}`;
320
+ }
321
+
322
+ /**
323
+ * Wash already-padded row content in a background tint edge-to-edge.
324
+ * Re-opens the tint after every embedded reset (same technique as
325
+ * paintPanel's fill) so syntax colors inside never punch holes in it.
326
+ * Split on the runtime reset value, never a literal escape.
327
+ */
328
+ export function tintLine(text: string, tint: string): string {
329
+ if (!tint) return text;
330
+ return `${tint}${text.split(c.reset).join(`${c.reset}${tint}`)}${c.reset}`;
331
+ }
332
+
333
+ /**
334
+ * Background wash for a raw diff line: deletions get the red tint,
335
+ * additions the green one, everything else none. Prefix-only, so it
336
+ * needs no headers and applies equally to unified and paired rows.
337
+ */
338
+ export function diffLineTint(line: string): string | null {
339
+ if (line.startsWith('+') && !line.startsWith('+++')) return codebox.diffAddBg;
340
+ if (line.startsWith('-') && !line.startsWith('---')) return codebox.diffDelBg;
341
+ return null;
342
+ }
343
+
252
344
  /**
253
345
  * Highlight a single line of code.
254
346
  *