@heyhuynhgiabuu/pi-pretty 0.7.1 → 0.8.0

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/src/config.ts CHANGED
@@ -82,10 +82,14 @@ export interface WorkingIndicatorConfig {
82
82
  hint?: boolean;
83
83
  /** Tint the indicator with a stable per-session accent color. */
84
84
  sessionAccent?: boolean;
85
+ /** Frame advance interval in ms (>= 33). Higher = cheaper frames while the agent works. */
86
+ intervalMs?: number;
85
87
  }
86
88
 
87
89
  export interface ThinkingIndicatorConfig {
88
90
  enabled?: boolean;
91
+ /** Label refresh interval in ms (>= 33). Higher = cheaper frames while thinking. */
92
+ intervalMs?: number;
89
93
  }
90
94
 
91
95
  export interface FffConfig {
@@ -105,6 +109,9 @@ export interface PrettyConfig {
105
109
  tool?: string;
106
110
  error?: string;
107
111
  };
112
+ /** Left rail bar on user messages: `#rrggbb`, empty/absent disables. Reads as
113
+ * "highlighted but transparent" on acrylic — one-cell bar, not a full-width bg. */
114
+ userRail?: string;
108
115
  theme?: string;
109
116
  icons?: string;
110
117
  enableTools?: string[];
@@ -155,6 +162,8 @@ export function loadConfig(agentDir = getConfigDir()): PrettyConfig {
155
162
  }
156
163
  if (typeof parsed.theme === "string" && parsed.theme.trim() !== "") config.theme = parsed.theme;
157
164
  if (parsed.toolStyle === "default" || parsed.toolStyle === "claudecode") config.toolStyle = parsed.toolStyle;
165
+ if (typeof parsed.userRail === "string" && /^#[0-9a-fA-F]{6}$/.test(parsed.userRail))
166
+ config.userRail = parsed.userRail;
158
167
  if (typeof parsed.icons === "string") config.icons = parsed.icons;
159
168
  const enableTools = normalizeToolList(parsed.enableTools);
160
169
  const disableTools = normalizeToolList(parsed.disableTools);
@@ -192,6 +201,8 @@ export function loadConfig(agentDir = getConfigDir()): PrettyConfig {
192
201
  if (typeof src.bold === "boolean") wi.bold = src.bold;
193
202
  if (typeof src.hint === "boolean") wi.hint = src.hint;
194
203
  if (typeof src.sessionAccent === "boolean") wi.sessionAccent = src.sessionAccent;
204
+ if (typeof src.intervalMs === "number" && Number.isFinite(src.intervalMs) && src.intervalMs >= 33)
205
+ wi.intervalMs = src.intervalMs;
195
206
  if (Object.keys(wi).length > 0) config.workingIndicator = wi;
196
207
  }
197
208
  const thinkingIndicator = parsed.thinkingIndicator;
@@ -199,6 +210,8 @@ export function loadConfig(agentDir = getConfigDir()): PrettyConfig {
199
210
  const ti: ThinkingIndicatorConfig = {};
200
211
  const src = thinkingIndicator as Record<string, unknown>;
201
212
  if (typeof src.enabled === "boolean") ti.enabled = src.enabled;
213
+ if (typeof src.intervalMs === "number" && Number.isFinite(src.intervalMs) && src.intervalMs >= 33)
214
+ ti.intervalMs = src.intervalMs;
202
215
  if (Object.keys(ti).length > 0) config.thinkingIndicator = ti;
203
216
  }
204
217
  return config;
package/src/index.ts CHANGED
@@ -24,6 +24,8 @@ import { createFffAutocompleteProvider } from "./autocomplete.js";
24
24
  import {
25
25
  installClaudeChatGrouping,
26
26
  installClaudeExternalToolRenderers,
27
+ resetClaudeStyleSessionState,
28
+ setClaudeStyleAgentActive,
27
29
  setClaudeStyleTheme,
28
30
  withClaudeToolStyleApi,
29
31
  } from "./claude-style.js";
@@ -43,6 +45,7 @@ import { registerGrepTool } from "./tools/grep.js";
43
45
  import { registerLsTool } from "./tools/ls.js";
44
46
  import { registerReadTool } from "./tools/read.js";
45
47
  import type { PiPrettyDeps, SdkTools } from "./types.js";
48
+ import { installUserRail, setUserRail } from "./user-rail.js";
46
49
  import {
47
50
  createThinkingLabelAnimator,
48
51
  createThinkingTimer,
@@ -312,6 +315,8 @@ export default async function piPrettyExtension(pi: ExtensionAPI, deps?: PiPrett
312
315
  installClaudeChatGrouping(claudeStyle);
313
316
  installClaudeExternalToolRenderers(hostSdk.ToolExecutionComponent, claudeStyle);
314
317
  installPromptEditor(ctx);
318
+ setUserRail(loadConfig().userRail);
319
+ installUserRail((hostSdk as unknown as { UserMessageComponent?: unknown }).UserMessageComponent);
315
320
  ctx.ui.setToolsExpanded(false);
316
321
  // Per-row hidden-thinking labels: intercept the host's label fan-out so
317
322
  // each row keeps its own duration. Falls back to the global-label
@@ -369,11 +374,13 @@ export default async function piPrettyExtension(pi: ExtensionAPI, deps?: PiPrett
369
374
  pi.on("agent_start", async (_event: unknown, ctx: ExtensionContext) => {
370
375
  if (ctx.mode !== "tui") return;
371
376
  workingStreaming = true;
377
+ setClaudeStyleAgentActive(true);
372
378
  workingController?.start();
373
379
  });
374
380
  const stopStreaming = async (_event: unknown, ctx: ExtensionContext): Promise<void> => {
375
381
  if (ctx.mode !== "tui") return;
376
382
  workingStreaming = false;
383
+ setClaudeStyleAgentActive(false);
377
384
  workingController?.stop();
378
385
  stopThinkingShimmer();
379
386
  };
@@ -466,7 +473,7 @@ export default async function piPrettyExtension(pi: ExtensionAPI, deps?: PiPrett
466
473
  stopThinkingShimmer();
467
474
  notifyThinkingFailure(ctx, error);
468
475
  }
469
- }, WORKING_INTERVAL_MS);
476
+ }, thinkingSettings.intervalMs ?? WORKING_INTERVAL_MS);
470
477
  } catch (error: unknown) {
471
478
  stopThinkingShimmer();
472
479
  notifyThinkingFailure(ctx, error);
@@ -522,6 +529,7 @@ export default async function piPrettyExtension(pi: ExtensionAPI, deps?: PiPrett
522
529
  perRowLabels = undefined;
523
530
  thinkingElapsedMs.clear();
524
531
  workingStreaming = false;
532
+ resetClaudeStyleSessionState();
525
533
  // Intentionally keep the native FFF finder on session shutdown.
526
534
  // Pi can emit shutdown/start during resume or session switching while the
527
535
  // process keeps running. Native teardown, or dropping the JS handle while the
@@ -0,0 +1,80 @@
1
+ /* pi-pretty: left rail for user messages — a thin tinted bar instead of a full-width
2
+ * background, so acrylic/translucent terminals keep showing through. ANSI cell
3
+ * backgrounds are always opaque in Windows Terminal, so a full-width bg kills the
4
+ * blur; a one-cell rail reads as "highlighted, still transparent". */
5
+
6
+ /** Host component shape pi-pretty needs (UserMessageComponent). */
7
+ interface RailPatchable {
8
+ prototype: { render?: (width: number) => string[] };
9
+ }
10
+
11
+ const RAIL_PATCH = Symbol.for("pi-pretty.user-rail");
12
+
13
+ interface RailState {
14
+ ansiOpen: string;
15
+ railChar: string;
16
+ width: number;
17
+ }
18
+
19
+ let state: RailState | undefined;
20
+
21
+ export interface UserRailOptions {
22
+ /** `#rrggbb` rail bar background. Empty/undefined disables the rail. */
23
+ color?: string;
24
+ }
25
+
26
+ /** Configure the rail from config resolution. Call once at session start. */
27
+ export function setUserRail(color: string | undefined): void {
28
+ if (!color || !/^#[0-9a-fA-F]{6}$/.test(color)) {
29
+ state = undefined;
30
+ return;
31
+ }
32
+ const r = parseInt(color.slice(1, 3), 16);
33
+ const g = parseInt(color.slice(3, 5), 16);
34
+ const b = parseInt(color.slice(5, 7), 16);
35
+ state = { ansiOpen: `\x1b[48;2;${r};${g};${b}m`, railChar: " ", width: 1 };
36
+ }
37
+
38
+ /** Width the rail adds to every rendered row (0 when disabled). */
39
+ export function userRailWidth(): number {
40
+ return state ? state.width : 0;
41
+ }
42
+
43
+ /**
44
+ * Patch the host's UserMessageComponent so every rendered line carries a one-cell
45
+ * tinted bar. The host render is wrapped, not replaced — expand/collapse and the
46
+ * OSC133 markers are untouched. Pass undefined to remove the rail.
47
+ */
48
+ export function installUserRail(componentClass: unknown): boolean {
49
+ const proto = (componentClass as RailPatchable | undefined)?.prototype;
50
+ const base = proto?.render;
51
+ if (!proto || typeof base !== "function") return false;
52
+
53
+ const existing = (base as { [RAIL_PATCH]?: boolean })[RAIL_PATCH];
54
+ if (existing) return true; // wrapper already installed; setUserRail changes only colors
55
+
56
+ const wrapped = function (this: unknown, width: number): string[] {
57
+ const s = state;
58
+ // The host pads every line to the width it is given, so delegate with the rail's cell
59
+ // already subtracted; adding it afterwards would overflow the row by one cell.
60
+ const lines = base.call(this, s ? Math.max(1, width - s.width) : width) as string[];
61
+ if (!s || lines.length === 0) return lines;
62
+ const out: string[] = [];
63
+ for (let i = 0; i < lines.length; i++) {
64
+ const line = lines[i];
65
+ // OSC133 screen-zone markers stay at position 0 of first/last lines.
66
+ if ((i === 0 || i === lines.length - 1) && line.startsWith("\u001b]133;")) {
67
+ const m = line.match(new RegExp("^(\\u001b\\]133;[A-Z][^\\u0007]*\\u0007)([\\s\\S]*)$"));
68
+ if (m) {
69
+ out.push(`${m[1]}${s.ansiOpen}${s.railChar}\x1b[49m${m[2]}`);
70
+ continue;
71
+ }
72
+ }
73
+ out.push(`${s.ansiOpen}${s.railChar}\x1b[49m${line}`);
74
+ }
75
+ return out;
76
+ };
77
+ (wrapped as { [RAIL_PATCH]?: boolean })[RAIL_PATCH] = true;
78
+ proto.render = wrapped as NonNullable<RailPatchable["prototype"]["render"]>;
79
+ return true;
80
+ }
@@ -64,6 +64,9 @@ export interface WorkingIndicatorSettings {
64
64
  hint: boolean;
65
65
  /** Tint mid/high tiers (and dim the spinner) with a per-session accent color. */
66
66
  sessionAccent: boolean;
67
+ /** Frame advance interval in ms. Default: WORKING_INTERVAL_MS (33). Higher = fewer
68
+ * full-tree renders per second while the agent works. */
69
+ intervalMs?: number;
67
70
  /** True when the user explicitly configured `mid`/`high` — accent then stays off. */
68
71
  tiersCustomized?: boolean;
69
72
  }
@@ -153,6 +156,9 @@ export function resolveWorkingIndicatorSettings(
153
156
  if (typeof config?.bold === "boolean") settings.bold = config.bold;
154
157
  if (typeof config?.hint === "boolean") settings.hint = config.hint;
155
158
  if (typeof config?.sessionAccent === "boolean") settings.sessionAccent = config.sessionAccent;
159
+ const envInterval = Number.parseInt(env.PRETTY_WORKING_INTERVAL_MS ?? "", 10);
160
+ if (Number.isFinite(envInterval) && envInterval >= 33) settings.intervalMs = envInterval;
161
+ else if (typeof config?.intervalMs === "number" && config.intervalMs >= 33) settings.intervalMs = config.intervalMs;
156
162
  settings.tiersCustomized = typeof config?.mid === "string" || typeof config?.high === "string";
157
163
  return settings;
158
164
  }
@@ -463,6 +469,9 @@ export class WorkingWidget {
463
469
 
464
470
  export interface ThinkingIndicatorSettings {
465
471
  enabled: boolean;
472
+ /** Label refresh interval in ms. Default: WORKING_INTERVAL_MS (33). Higher = fewer
473
+ * full-tree renders per second while thinking — the main FPS lever on long sessions. */
474
+ intervalMs?: number;
466
475
  }
467
476
 
468
477
  export const THINKING_INDICATOR_DEFAULTS: ThinkingIndicatorSettings = { enabled: true };
@@ -479,6 +488,9 @@ export function resolveThinkingIndicatorSettings(
479
488
  const envEnabled = envFlag(env.PRETTY_THINKING_INDICATOR);
480
489
  if (envEnabled !== undefined) settings.enabled = envEnabled;
481
490
  else if (typeof config?.enabled === "boolean") settings.enabled = config.enabled;
491
+ const envInterval = Number.parseInt(env.PRETTY_THINKING_INTERVAL_MS ?? "", 10);
492
+ if (Number.isFinite(envInterval) && envInterval >= 33) settings.intervalMs = envInterval;
493
+ else if (typeof config?.intervalMs === "number" && config.intervalMs >= 33) settings.intervalMs = config.intervalMs;
482
494
  return settings;
483
495
  }
484
496
 
@@ -839,6 +851,7 @@ export async function installWorkingIndicator(
839
851
  ansi,
840
852
  bold: settings.bold,
841
853
  spinnerColor,
854
+ intervalMs: settings.intervalMs,
842
855
  });
843
856
  if (frames.length === 0) return noopController;
844
857