@yinan_chen/pi-claude-code-ui 0.2.1 → 0.3.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/README.md CHANGED
@@ -26,6 +26,57 @@ pi -e npm:@yinan_chen/pi-claude-code-ui
26
26
  - **工作状态提示** — working message / running effect
27
27
  - **只读工具美化** — read/bash/grep/find/ls 结果渲染
28
28
 
29
+ ## 配置
30
+
31
+ 配置文件:`~/.pi/agent/lean-tidy.json`(不存在时全部使用默认值):
32
+
33
+ ```json
34
+ {
35
+ "profile": "claude",
36
+ "skillRendering": "native",
37
+ "subagentRendering": "claude",
38
+ "detailsBackground": "selectedBg",
39
+ "bashPreviewLines": 0,
40
+ "codePreviewLines": 0,
41
+ "errorPreviewLines": 0,
42
+ "liveThinking": true,
43
+ "thinkingTailLines": 5,
44
+ "foldAnimMs": 240,
45
+ "stickyIncludeCustom": false,
46
+ "skillResumePreview": true,
47
+ "resultPrefix": "└",
48
+ "diff": {
49
+ "diffViewMode": "auto",
50
+ "diffIndicatorMode": "bars",
51
+ "diffSplitMinWidth": 120,
52
+ "editDiffCollapsedLines": 0,
53
+ "writeDiffCollapsedLines": 0,
54
+ "diffWordWrap": true,
55
+ "expandedPreviewMaxLines": 40
56
+ }
57
+ }
58
+ ```
59
+
60
+ | 键 | 默认 | 说明 |
61
+ |---|---|---|
62
+ | `profile` | `"claude"` | 整体风格:`claude` / `native`(pi 原生) |
63
+ | `skillRendering` | `"native"` | skill 块样式:pi 原生折叠行 / `claude` 两行风格 |
64
+ | `subagentRendering` | `"claude"` | 子代理完成通知:`claude` 分支风格 / `native` 保留包内面板 |
65
+ | `detailsBackground` | `"selectedBg"` | 详情背景色(主题色键名,可选 `customMessageBg`/`toolPendingBg`/`toolSuccessBg`/`toolErrorBg`/`""`) |
66
+ | `bash/code/errorPreviewLines` | `0`/`0`/`0` | 三类工具结果的预览行数(0–100;0 = 默认折叠) |
67
+ | `liveThinking` | `true` | 思考过程流式展示 |
68
+ | `thinkingTailLines` | `5` | 思考尾行数 |
69
+ | `foldAnimMs` | `240` | 折叠动画时长(ms,0 关闭) |
70
+ | `stickyIncludeCustom` | `false` | 吸附泡是否包含扩展注入/跨会话转发的旁路消息 |
71
+ | `skillResumePreview` | `true` | `/resume` 列表预览是否折回 `[skill] 名` 单行 |
72
+ | `resultPrefix` | `"└"` | 工具结果行拐角前缀(制表符族,等宽字体最稳;可换 `↳` 或 Claude Code 官方的 `⎿`,后两者在部分字体下会变宽) |
73
+ | `diff.diffViewMode` | `"auto"` | diff 视图:`auto`/`split`/`unified` |
74
+ | `diff.diffIndicatorMode` | `"bars"` | 变更指示条:`bars`/`classic`/`none` |
75
+ | `diff.diffSplitMinWidth` | `120` | 宽于此才用 split 视图 |
76
+ | `diff.edit/writeDiffCollapsedLines` | `0`/`0` | edit/write 默认折叠行数(0 = 默认展开) |
77
+ | `diff.diffWordWrap` | `true` | diff 自动换行 |
78
+ | `diff.expandedPreviewMaxLines` | `40` | 展开后最多显示行数 |
79
+
29
80
  ## 兼容性
30
81
 
31
82
  按 `VERIFIED_PI_VERSION = 1.0.2` 验收;版本不一致时扩展会在 session 启动时提示一次。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yinan_chen/pi-claude-code-ui",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Claude Code-style UI for Pi: transcript view, rich diffs, subagent panels and working-message status.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -3,6 +3,9 @@ import { getLanguageFromPath, highlightCode, keyText } from "@earendil-works/pi-
3
3
  import { truncateToWidth, visibleWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
4
4
  import { homedir } from "node:os";
5
5
 
6
+ /** UI 符号集(lean-tidy.json 可覆盖;见 index.ts loadConfig 的 resultPrefix)。 */
7
+ export const SYMBOLS = { resultPrefix: "└" };
8
+
6
9
  export interface ToolView {
7
10
  name: string;
8
11
  args: Record<string, any>;
@@ -194,12 +197,12 @@ export function summaryOf(v: ToolView, theme: any): string | undefined {
194
197
  export function paintTool(v: ToolView, theme: any, width: number, config: ToolAppearance): PaintedTool {
195
198
  const lines = headerOf(v, theme, width), headerHeight = lines.length;
196
199
  let moreRow: number | undefined;
197
- const result = (s: string) => lines.push(...prefixed(s, width, ` ${fg(theme, "dim", "⎿")} `, " "));
200
+ const result = (s: string) => lines.push(...prefixed(s, width, ` ${fg(theme, "dim", SYMBOLS.resultPrefix)} `, " "));
198
201
  const body = (source: string[], limit: number, full = v.expanded, firstResult = false) => {
199
202
  const shown = full ? source : source.slice(0, limit);
200
203
  let clipped = false;
201
204
  shown.forEach((line, i) => {
202
- const first = firstResult && i === 0 ? ` ${fg(theme, "dim", "⎿")} ` : " ";
205
+ const first = firstResult && i === 0 ? ` ${fg(theme, "dim", SYMBOLS.resultPrefix)} ` : " ";
203
206
  if (full) lines.push(...prefixed(line, width, first, " "));
204
207
  else {
205
208
  const pw = Math.min(6, Math.max(0, width - 1)), bw = Math.max(1, width - pw);
@@ -1,7 +1,7 @@
1
1
  /** Pi-specific transcript adapter. All private component fields are isolated here. */
2
2
  import { Box, Container, Markdown, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
3
3
  import { getMarkdownTheme, keyText } from "@earendil-works/pi-coding-agent";
4
- import { BUILTIN_NAMES, PROCESS_TOOL_NAMES, bold, canExpandTool, expandHint, failedTool, fg, fit, headerOf, isBlank, isImageLine, oneLine, paintBackground, paintTool, prefixed, prefixZones, targetOf, type ToolAppearance, type ToolView } from "./claude-tools.ts";
4
+ import { BUILTIN_NAMES, PROCESS_TOOL_NAMES, bold, canExpandTool, expandHint, failedTool, fg, fit, headerOf, isBlank, isImageLine, oneLine, paintBackground, paintTool, prefixed, prefixZones, SYMBOLS, targetOf, type ToolAppearance, type ToolView } from "./claude-tools.ts";
5
5
  import { animateRunningSummary } from "./running-effect.ts";
6
6
 
7
7
  export interface ClaudeConfig extends ToolAppearance {
@@ -313,7 +313,7 @@ export function createClaudeView(
313
313
  if (raw.length > rowsLeft) { hidden += raw.length - rowsLeft; raw = raw.slice(0, Math.max(0, rowsLeft)); }
314
314
  rowsLeft -= raw.length;
315
315
  const start = lines.length;
316
- for (let i = 0; i < raw.length; i++) lines.push(isImageLine(raw[i]) ? raw[i] : fit(truncateToWidth(start + i === 0 ? ` ${fg(theme(), "dim", "⎿")} ` : " ", indent, "") + raw[i], width));
316
+ for (let i = 0; i < raw.length; i++) lines.push(isImageLine(raw[i]) ? raw[i] : fit(truncateToWidth(start + i === 0 ? ` ${fg(theme(), "dim", SYMBOLS.resultPrefix)} ` : " ", indent, "") + raw[i], width));
317
317
  const proxy = {
318
318
  handleMouse(e: any) {
319
319
  if (e.x < indent) return undefined;
@@ -346,7 +346,7 @@ export function createClaudeView(
346
346
  const last = entries.at(-1);
347
347
  if (last && --last.height <= 0) entries.pop();
348
348
  }
349
- const more = prefixed(fg(theme(), "dim", `… +${hidden} lines`) + expandHint(theme()), width, ` ${fg(theme(), "dim", "⎿")} `, " ");
349
+ const more = prefixed(fg(theme(), "dim", `… +${hidden} lines`) + expandHint(theme()), width, ` ${fg(theme(), "dim", SYMBOLS.resultPrefix)} `, " ");
350
350
  lines.push(...more);
351
351
  entries.push({ component: toggleTool(self), height: more.length });
352
352
  }
@@ -368,7 +368,7 @@ export function createClaudeView(
368
368
  lines = [...head, ...(body?.lines ?? [])];
369
369
  entries = [{ component: toggleTool(self), height: head.length }, ...(body?.entries ?? [])];
370
370
  if (v.partial && !body?.lines.length) {
371
- const pending = prefixed(fg(t, "dim", v.started ? "Running…" : "Waiting…"), width, ` ${fg(t, "dim", "⎿")} `, " ");
371
+ const pending = prefixed(fg(t, "dim", v.started ? "Running…" : "Waiting…"), width, ` ${fg(t, "dim", SYMBOLS.resultPrefix)} `, " ");
372
372
  lines.push(...pending); entries.push({ component: {}, height: pending.length });
373
373
  }
374
374
  } else {
@@ -390,7 +390,7 @@ export function createClaudeView(
390
390
  // The vendored renderer limits body rows and supplies its own remainder hint.
391
391
  // Do not also slice by codePreviewLines: that counts the diff header/frame
392
392
  // against the body and hides almost every changed row.
393
- const prefix = ` ${fg(t, "dim", "⎿")} `;
393
+ const prefix = ` ${fg(t, "dim", SYMBOLS.resultPrefix)} `;
394
394
  // The rich edit header already reports +N/-M; do not repeat
395
395
  // paintTool's "Added N lines, removed M lines" summary above it.
396
396
  const introRows = painted.headerHeight + (v.name === "edit" ? 0 : 1);
@@ -610,7 +610,7 @@ export function createClaudeView(
610
610
  if (active && tools.length) {
611
611
  const focus = [...tools].reverse().find((p) => p.owner.isPartial) ?? tools.at(-1)!;
612
612
  const v = toolView(focus.owner), target = targetOf(v.name, v.args, v.cwd).text;
613
- if (target) rows.push(...prefixed(fg(theme(), "muted", (v.name === "bash" || v.name === "powershell" ? "$ " : "") + target), width, ` ${fg(theme(), "dim", "⎿")} `, " ").slice(0, 2));
613
+ if (target) rows.push(...prefixed(fg(theme(), "muted", (v.name === "bash" || v.name === "powershell" ? "$ " : "") + target), width, ` ${fg(theme(), "dim", SYMBOLS.resultPrefix)} `, " ").slice(0, 2));
614
614
  }
615
615
  append(rows, toggle);
616
616
  // Failures stay folded like the rest: the summary counts them ("N failed")
@@ -700,7 +700,7 @@ export function createClaudeView(
700
700
  return trimmed;
701
701
  }
702
702
  const name = oneLine(self.skillBlock.name), lines = [` ${fg(theme(), "success", "●")} ${bold(theme(), "Skill")}(${name})`];
703
- lines.push(...prefixed(fg(theme(), "muted", "Loaded skill") + (self.expanded ? "" : ` (${keyText("app.tools.expand")} to expand)`), width, ` ${fg(theme(), "dim", "⎿")} `, " "));
703
+ lines.push(...prefixed(fg(theme(), "muted", "Loaded skill") + (self.expanded ? "" : ` (${keyText("app.tools.expand")} to expand)`), width, ` ${fg(theme(), "dim", SYMBOLS.resultPrefix)} `, " "));
704
704
  if (self.expanded) {
705
705
  const md = new Markdown(self.skillBlock.content ?? "", 0, 0, self.markdownTheme ?? getMarkdownTheme());
706
706
  for (const l of md.render(Math.max(1, width - 3))) lines.push(fit(" " + l, width));
package/src/index.ts CHANGED
@@ -29,6 +29,7 @@ import { createClaudeView } from "./claude-view.ts";
29
29
  import registerSubagentPanels from "./subagent-panel.ts";
30
30
  import stickyFirstMessage from "./sticky-first-message.ts";
31
31
  import registerSkillRecollapse from "./skill-block-recollapse.ts";
32
+ import { SYMBOLS } from "./claude-tools.ts";
32
33
  import registerWorkingMessage from "./working-message.ts";
33
34
  // Vendored rich diff (MIT; see vendor/diff/ATTRIBUTION.md).
34
35
  import { renderRichToolResult, WriteExecutionMetadataStore } from "./vendor/diff/index.ts";
@@ -76,6 +77,12 @@ interface Config {
76
77
  liveThinking: boolean;
77
78
  thinkingTailLines: number;
78
79
  foldAnimMs: number;
80
+ /** sticky 吸附池是否含 CustomMessage(扩展注入/跨会话转发),默认 false。 */
81
+ stickyIncludeCustom: boolean;
82
+ /** /resume 列表预览是否折回 [skill] 名,默认 true。 */
83
+ skillResumePreview: boolean;
84
+ /** 工具结果行的拐角前缀符号(默认 └;可换 ↳ 或 Claude Code 官方的 ⎿)。 */
85
+ resultPrefix: string;
79
86
  }
80
87
 
81
88
  function loadConfig(): Config {
@@ -84,12 +91,15 @@ function loadConfig(): Config {
84
91
  skillRendering: "native",
85
92
  subagentRendering: "claude",
86
93
  detailsBackground: "selectedBg",
87
- bashPreviewLines: 1,
88
- codePreviewLines: 3,
89
- errorPreviewLines: 1,
94
+ bashPreviewLines: 0,
95
+ codePreviewLines: 0,
96
+ errorPreviewLines: 0,
90
97
  liveThinking: true,
91
- thinkingTailLines: 3,
98
+ thinkingTailLines: 5,
92
99
  foldAnimMs: 240,
100
+ stickyIncludeCustom: false,
101
+ skillResumePreview: true,
102
+ resultPrefix: "└",
93
103
  };
94
104
  diffDisplayConfig = { ...DEFAULT_TOOL_DISPLAY_CONFIG };
95
105
  try {
@@ -108,6 +118,9 @@ function loadConfig(): Config {
108
118
  config.thinkingTailLines = Math.floor(data.thinkingTailLines);
109
119
  }
110
120
  if (Number.isFinite(data?.foldAnimMs) && data.foldAnimMs >= 0) config.foldAnimMs = Math.floor(data.foldAnimMs);
121
+ if (typeof data?.stickyIncludeCustom === "boolean") config.stickyIncludeCustom = data.stickyIncludeCustom;
122
+ if (typeof data?.skillResumePreview === "boolean") config.skillResumePreview = data.skillResumePreview;
123
+ if (typeof data?.resultPrefix === "string" && data.resultPrefix.trim()) config.resultPrefix = data.resultPrefix;
111
124
  if (data?.diff && typeof data.diff === "object" && !Array.isArray(data.diff)) {
112
125
  diffDisplayConfig = { ...DEFAULT_TOOL_DISPLAY_CONFIG, ...data.diff };
113
126
  }
@@ -367,9 +380,10 @@ async function patchAllCopies(): Promise<ScanInfo> {
367
380
 
368
381
  export default async function leanTidy(pi: ExtensionAPI): Promise<void> {
369
382
  registerWorkingMessage(pi);
370
- await stickyFirstMessage(pi);
371
- registerSkillRecollapse(pi);
372
383
  const config = loadConfig();
384
+ SYMBOLS.resultPrefix = config.resultPrefix;
385
+ await stickyFirstMessage(pi, { includeCustom: config.stickyIncludeCustom });
386
+ registerSkillRecollapse(pi, { resumePreview: config.skillResumePreview });
373
387
  // Subagent 通知接管必须发生在加载期(registerMessageRenderer 仅 factory 内合法):
374
388
  // lean-tidy 先于 npm 包加载,首个命中 customType 的渲染器胜出(一南 2026-02-12)。
375
389
  // redraw 闭包延迟读 LAST_MODE(hookMode 后才看得到 TUI)。
@@ -263,8 +263,11 @@ function patchForkPreview(): boolean {
263
263
  * 不回写 .jsonl。可用 PI_SKILL_RECOLLAPSE_RESUME=0 关闭这一处。
264
264
  * @returns 是否已处于「已打好补丁」状态
265
265
  */
266
+ /** /resume 列表预览改写:json 显式配置(skillResumePreview) > env 兼容 > 默认开启 */
267
+ let RESUME_PREVIEW = true;
268
+
266
269
  function patchResumePreview(): boolean {
267
- if ((process.env.PI_SKILL_RECOLLAPSE_RESUME || "").trim() === "0") return true;
270
+ if (!RESUME_PREVIEW) return true;
268
271
  const cls = SessionManager as unknown as Record<string | symbol, unknown>;
269
272
  if (cls[RESUME_PATCHED]) return true;
270
273
 
@@ -293,7 +296,9 @@ function patchResumePreview(): boolean {
293
296
  return true;
294
297
  }
295
298
 
296
- export default function (pi: ExtensionAPI) {
299
+ export default function (pi: ExtensionAPI, opts?: { resumePreview?: boolean }) {
300
+ // json 配置优先,未提供时回退旧 env 逃生口(PI_SKILL_RECOLLAPSE_RESUME=0),再回退默认 true。
301
+ RESUME_PREVIEW = opts?.resumePreview ?? (process.env.PI_SKILL_RECOLLAPSE_RESUME || "").trim() !== "0";
297
302
  /**
298
303
  * 计划一次「读回编辑器 → 命中则折叠」的补偿。
299
304
  * @param ctx 事件上下文,仅用 ctx.ui 的编辑器读写
@@ -67,7 +67,10 @@ const VERSION = "2.2.1-20260910";
67
67
 
68
68
  const env = (k: string) => (process.env[k] || "").trim();
69
69
  const killed = () => env("PI_STICKY_FIRST_MESSAGE") === "0";
70
- const includeCustom = () => env("PI_STICKY_INCLUDE_CUSTOM") === "1";
70
+ /** 是否吸附 CustomMessage:json 显式配置(stickyIncludeCustom,入口传入) > env 兼容 > 默认不吸附。
71
+ * 每次调用动态求值,json 未提供(undefined)时 env 可随时启停。 */
72
+ let OPTS_INCLUDE_CUSTOM: boolean | undefined;
73
+ const includeCustom = () => OPTS_INCLUDE_CUSTOM ?? env("PI_STICKY_INCLUDE_CUSTOM") === "1";
71
74
  /** 健康日志 + 快照落盘开关;默认关闭,不产生任何文件(状态机仍运行,仅不写盘) */
72
75
  const healthEnabled = () => env("PI_STICKY_HEALTH") === "1";
73
76
 
@@ -1087,7 +1090,9 @@ export const __stickyTest = {
1087
1090
  }),
1088
1091
  };
1089
1092
 
1090
- export default async function stickyFirstMessage(pi: ExtensionAPI): Promise<void> {
1093
+ export default async function stickyFirstMessage(pi: ExtensionAPI, opts?: { includeCustom?: boolean }): Promise<void> {
1094
+ // json 配置优先(undefined = 未配置,回退旧 env 开关 PI_STICKY_INCLUDE_CUSTOM=1,再回退默认 false)。
1095
+ OPTS_INCLUDE_CUSTOM = opts?.includeCustom;
1091
1096
  // 主题探针:零高 widget,只为拿到 (tui, theme) 里的 theme(泡的底色/前景跟随主题)
1092
1097
  pi.on("session_start", async (_e, ctx: any) => {
1093
1098
  if (!ctx?.hasUI || typeof ctx.ui?.setWidget !== "function") return;
@@ -22,7 +22,7 @@
22
22
  * host 驱动,两者 OR 叠加。
23
23
  */
24
24
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
25
- import { bold, expandHint, fg, fit, linesOf, oneLine, prefixed } from "./claude-tools.ts";
25
+ import { bold, expandHint, fg, fit, linesOf, oneLine, prefixed, SYMBOLS } from "./claude-tools.ts";
26
26
 
27
27
  /** 只用到 pi 传入 options 的 expanded;outputPad 由内置 Spacer(1) 承担,忽略。 */
28
28
  interface PanelOptions {
@@ -35,7 +35,7 @@ export interface SubagentPanelHooks {
35
35
  }
36
36
 
37
37
  /** ⎿ 分支前缀,与 claude-view.ts 工具结果/技能块同款(3 空格 + ⎿ + 2 空格,续行 6 空格)。 */
38
- const branch = (theme: any): string => ` ${fg(theme, "dim", "⎿")} `;
38
+ const branch = (theme: any): string => ` ${fg(theme, "dim", SYMBOLS.resultPrefix)} `;
39
39
  const BRANCH_REST = " ";
40
40
 
41
41
  /** 与该包 ui/agent-widget.ts 的 formatTokens 对齐:"33.8k token" / "1.2M token"。 */
@@ -20,7 +20,7 @@ export const DEFAULT_TOOL_DISPLAY_CONFIG: ToolDisplayConfig = {
20
20
  diffViewMode: "auto",
21
21
  diffIndicatorMode: "bars",
22
22
  diffSplitMinWidth: 120,
23
- editDiffCollapsedLines: 24,
23
+ editDiffCollapsedLines: 0,
24
24
  writeDiffCollapsedLines: 0,
25
25
  diffWordWrap: true,
26
26
  expandedPreviewMaxLines: 40,