@heyhuynhgiabuu/pi-pretty 0.7.0 → 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
@@ -3,6 +3,7 @@
3
3
  */
4
4
 
5
5
  import { readFileSync } from "node:fs";
6
+ import { homedir } from "node:os";
6
7
  import { basename, extname, join } from "node:path";
7
8
 
8
9
  // ---------------------------------------------------------------------------
@@ -81,10 +82,14 @@ export interface WorkingIndicatorConfig {
81
82
  hint?: boolean;
82
83
  /** Tint the indicator with a stable per-session accent color. */
83
84
  sessionAccent?: boolean;
85
+ /** Frame advance interval in ms (>= 33). Higher = cheaper frames while the agent works. */
86
+ intervalMs?: number;
84
87
  }
85
88
 
86
89
  export interface ThinkingIndicatorConfig {
87
90
  enabled?: boolean;
91
+ /** Label refresh interval in ms (>= 33). Higher = cheaper frames while thinking. */
92
+ intervalMs?: number;
88
93
  }
89
94
 
90
95
  export interface FffConfig {
@@ -104,6 +109,9 @@ export interface PrettyConfig {
104
109
  tool?: string;
105
110
  error?: string;
106
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;
107
115
  theme?: string;
108
116
  icons?: string;
109
117
  enableTools?: string[];
@@ -154,6 +162,8 @@ export function loadConfig(agentDir = getConfigDir()): PrettyConfig {
154
162
  }
155
163
  if (typeof parsed.theme === "string" && parsed.theme.trim() !== "") config.theme = parsed.theme;
156
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;
157
167
  if (typeof parsed.icons === "string") config.icons = parsed.icons;
158
168
  const enableTools = normalizeToolList(parsed.enableTools);
159
169
  const disableTools = normalizeToolList(parsed.disableTools);
@@ -191,6 +201,8 @@ export function loadConfig(agentDir = getConfigDir()): PrettyConfig {
191
201
  if (typeof src.bold === "boolean") wi.bold = src.bold;
192
202
  if (typeof src.hint === "boolean") wi.hint = src.hint;
193
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;
194
206
  if (Object.keys(wi).length > 0) config.workingIndicator = wi;
195
207
  }
196
208
  const thinkingIndicator = parsed.thinkingIndicator;
@@ -198,6 +210,8 @@ export function loadConfig(agentDir = getConfigDir()): PrettyConfig {
198
210
  const ti: ThinkingIndicatorConfig = {};
199
211
  const src = thinkingIndicator as Record<string, unknown>;
200
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;
201
215
  if (Object.keys(ti).length > 0) config.thinkingIndicator = ti;
202
216
  }
203
217
  return config;
@@ -206,7 +220,7 @@ export function loadConfig(agentDir = getConfigDir()): PrettyConfig {
206
220
  }
207
221
  }
208
222
 
209
- export function getConfigDir(): string | undefined {
223
+ export function getConfigDir(): string {
210
224
  return process.env.PRETTY_CONFIG_DIR ?? getDefaultAgentDir();
211
225
  }
212
226
 
@@ -465,7 +479,7 @@ export function applyConfig(config: PrettyConfig): void {
465
479
  // Agent directory helpers
466
480
  // ---------------------------------------------------------------------------
467
481
 
468
- export function getDefaultAgentDir(): string | undefined {
469
- const home = process.env.HOME ?? "";
470
- return home ? join(home, ".pi/agent") : undefined;
482
+ /** `HOME` is unset on Windows, where `os.homedir()` resolves `USERPROFILE`. */
483
+ export function getDefaultAgentDir(): string {
484
+ return join(process.env.HOME || homedir(), ".pi/agent");
471
485
  }
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,
@@ -253,9 +256,7 @@ export default async function piPrettyExtension(pi: ExtensionAPI, deps?: PiPrett
253
256
  /** pi persists the thinking-visibility toggle as a top-level settings key. */
254
257
  const thinkingHidden = (): boolean => {
255
258
  try {
256
- const dir = getDefaultAgentDir();
257
- if (!dir) return false;
258
- const parsed = JSON.parse(readFileSync(join(dir, "settings.json"), "utf8")) as {
259
+ const parsed = JSON.parse(readFileSync(join(getDefaultAgentDir(), "settings.json"), "utf8")) as {
259
260
  hideThinkingBlock?: unknown;
260
261
  };
261
262
  return parsed.hideThinkingBlock === true;
@@ -314,6 +315,8 @@ export default async function piPrettyExtension(pi: ExtensionAPI, deps?: PiPrett
314
315
  installClaudeChatGrouping(claudeStyle);
315
316
  installClaudeExternalToolRenderers(hostSdk.ToolExecutionComponent, claudeStyle);
316
317
  installPromptEditor(ctx);
318
+ setUserRail(loadConfig().userRail);
319
+ installUserRail((hostSdk as unknown as { UserMessageComponent?: unknown }).UserMessageComponent);
317
320
  ctx.ui.setToolsExpanded(false);
318
321
  // Per-row hidden-thinking labels: intercept the host's label fan-out so
319
322
  // each row keeps its own duration. Falls back to the global-label
@@ -371,11 +374,13 @@ export default async function piPrettyExtension(pi: ExtensionAPI, deps?: PiPrett
371
374
  pi.on("agent_start", async (_event: unknown, ctx: ExtensionContext) => {
372
375
  if (ctx.mode !== "tui") return;
373
376
  workingStreaming = true;
377
+ setClaudeStyleAgentActive(true);
374
378
  workingController?.start();
375
379
  });
376
380
  const stopStreaming = async (_event: unknown, ctx: ExtensionContext): Promise<void> => {
377
381
  if (ctx.mode !== "tui") return;
378
382
  workingStreaming = false;
383
+ setClaudeStyleAgentActive(false);
379
384
  workingController?.stop();
380
385
  stopThinkingShimmer();
381
386
  };
@@ -468,7 +473,7 @@ export default async function piPrettyExtension(pi: ExtensionAPI, deps?: PiPrett
468
473
  stopThinkingShimmer();
469
474
  notifyThinkingFailure(ctx, error);
470
475
  }
471
- }, WORKING_INTERVAL_MS);
476
+ }, thinkingSettings.intervalMs ?? WORKING_INTERVAL_MS);
472
477
  } catch (error: unknown) {
473
478
  stopThinkingShimmer();
474
479
  notifyThinkingFailure(ctx, error);
@@ -524,6 +529,7 @@ export default async function piPrettyExtension(pi: ExtensionAPI, deps?: PiPrett
524
529
  perRowLabels = undefined;
525
530
  thinkingElapsedMs.clear();
526
531
  workingStreaming = false;
532
+ resetClaudeStyleSessionState();
527
533
  // Intentionally keep the native FFF finder on session shutdown.
528
534
  // Pi can emit shutdown/start during resume or session switching while the
529
535
  // process keeps running. Native teardown, or dropping the JS handle while the
package/src/render.ts CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  FG_LNUM,
24
24
  FG_RULE,
25
25
  FG_YELLOW,
26
+ fileIcon,
26
27
  loadConfig,
27
28
  MAX_HL_CHARS,
28
29
  MAX_PREVIEW_LINES,
@@ -346,32 +347,48 @@ export function renderBashOutput(text: string, indent = TOOL_RESULT_INDENT): str
346
347
  // Ls — tree view with icons
347
348
  // ---------------------------------------------------------------------------
348
349
 
350
+ /** The SDK's `[N entries limit reached…]` / `[50.0KB limit reached]` lines; bracketed filenames are not notices. */
351
+ const LS_NOTICE =
352
+ /^\[(?:\d+ entries limit reached\. Use limit=\d+ for more|\d+(?:\.\d+)?(?:B|KB|MB|GB) limit reached)(?:\. (?:\d+ entries limit reached\. Use limit=\d+ for more|\d+(?:\.\d+)?(?:B|KB|MB|GB) limit reached))*\]$/;
353
+
354
+ export function isLsNotice(line: string): boolean {
355
+ return LS_NOTICE.test(line);
356
+ }
357
+
349
358
  export function renderTree(text: string, _basePath: string): string {
350
- const lines = text.trim().split("\n").filter(Boolean);
359
+ const lines = text
360
+ .trim()
361
+ .split("\n")
362
+ .filter(Boolean)
363
+ .map((line) => line.trim());
351
364
  if (!lines.length) return `${FG_DIM}(empty directory)${RST}`;
352
365
 
366
+ const entries = lines.filter((line) => !isLsNotice(line));
367
+ const notices = lines.filter(isLsNotice);
368
+ if (!entries.length) return notices.map((notice) => `${FG_DIM}${notice}${RST}`).join("\n");
369
+
353
370
  const out: string[] = [];
354
- const total = lines.length;
355
- const show = lines.slice(0, MAX_PREVIEW_LINES);
371
+ const total = entries.length;
372
+ const show = entries.slice(0, MAX_PREVIEW_LINES);
356
373
 
357
374
  for (let i = 0; i < show.length; i++) {
358
- const entry = show[i].trim();
375
+ const entry = show[i];
359
376
  const isLast = i === show.length - 1 && total <= MAX_PREVIEW_LINES;
360
377
  const prefix = isLast ? "└── " : "├── ";
361
378
  const connector = `${FG_RULE}${prefix}${RST}`;
362
379
  const isDir = entry.endsWith("/");
363
380
  const name = isDir ? entry.slice(0, -1) : entry;
364
- const icon = isDir ? dirIcon() : "";
381
+ const icon = isDir ? dirIcon() : fileIcon(name);
365
382
  out.push(`${connector}${icon}${isDir ? `${FG_BLUE}\x1b[1m${name}${RST}` : name}`);
366
383
  }
367
384
 
368
385
  if (total > MAX_PREVIEW_LINES) {
369
386
  out.push(`${FG_RULE}└── ${RST}${FG_DIM}… ${total - MAX_PREVIEW_LINES} more entries${RST}`);
370
387
  }
388
+ for (const notice of notices) out.push(`${FG_DIM}${notice}${RST}`);
371
389
 
372
390
  return out.join("\n");
373
391
  }
374
-
375
392
  // ---------------------------------------------------------------------------
376
393
  // Find — grouped file list (plain, no tree characters or icons)
377
394
  // ---------------------------------------------------------------------------
package/src/tools/ls.ts CHANGED
@@ -6,6 +6,7 @@ import { shortPath } from "../helpers.js";
6
6
  import {
7
7
  fillToolBackground,
8
8
  fillToolBody,
9
+ isLsNotice,
9
10
  rememberToolTitle,
10
11
  renderToolError,
11
12
  renderToolMetrics,
@@ -44,7 +45,12 @@ export function registerLsTool(
44
45
  _type: "lsResult",
45
46
  text: tc,
46
47
  path: String((params as any).path ?? ""),
47
- entryCount: tc ? tc.trim().split("\n").filter(Boolean).length : 0,
48
+ entryCount: tc
49
+ ? tc
50
+ .trim()
51
+ .split("\n")
52
+ .filter((line) => line && !isLsNotice(line.trim())).length
53
+ : 0,
48
54
  } as LsDetails;
49
55
  return result;
50
56
  }),
@@ -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