@yinan_chen/pi-claude-code-ui 0.8.2 → 0.8.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yinan_chen/pi-claude-code-ui",
3
- "version": "0.8.2",
3
+ "version": "0.8.7",
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",
@@ -99,7 +99,7 @@ export function codemodeTarget(code: string): string {
99
99
  }
100
100
  export function targetOf(name: string, a: Record<string, any>, cwd?: string): { text: string; path: boolean } {
101
101
  // codemode 头行括号提示已停用(一南 2026-09-30):注释/行数不再上头行;codemodeTarget 保留备用。
102
- if (name === "codemode") return { text: "", path: false };
102
+ if (name === "codemode") return { text: codemodeTarget(typeof a.code === "string" ? a.code : ""), path: false };
103
103
  if (typeof a.command === "string") return { text: oneLine(a.command), path: false };
104
104
  if ((name === "grep" || name === "find") && a.pattern) return { text: `pattern: ${JSON.stringify(a.pattern)}${a.path ? `, path: ${shortPath(a.path, cwd)}` : ""}`, path: false };
105
105
  if (typeof a.path === "string") {
@@ -110,6 +110,16 @@ export function targetOf(name: string, a: Record<string, any>, cwd?: string): {
110
110
  for (const k of ["url", "urls", "query", "queries", "pattern", "claim", "action", "name", "tool", "search", "describe", "project_id"]) {
111
111
  if (a[k]) return { text: oneLine(Array.isArray(a[k]) ? a[k].join("; ") : a[k]), path: false };
112
112
  }
113
+ // 兜底(一南 2026-10-05):任何工具——含未来未知第三方/MCP——头行都带括号提示;
114
+ // 取首个非空参数做 k=v 摘要,args 完全为空才光头(无参数工具本无信息可显)。
115
+ for (const [k, v] of Object.entries(a)) {
116
+ if (v === undefined || v === null || v === "") continue;
117
+ let text: string;
118
+ if (typeof v === "string") text = v;
119
+ else if (Array.isArray(v)) text = v.join("; ");
120
+ else { try { text = JSON.stringify(v); } catch { text = String(v); } }
121
+ if (text.trim()) return { text: `${k}: ${oneLine(text)}`, path: false };
122
+ }
113
123
  return { text: "", path: false };
114
124
  }
115
125
  export function headerOf(v: ToolView, theme: any, width: number): string[] {
@@ -303,8 +303,15 @@ export function createClaudeView(
303
303
  : 0;
304
304
  for (const native of nativeChildren) {
305
305
  if (!native || typeof native.render !== "function") continue;
306
+ // 第三方子组件 render 可能抛异常或返回非数组(防御:不炸整块,退化为单行错误提示)。
307
+ let raw: string[];
308
+ try {
309
+ const out = native.render(bodyWidth);
310
+ raw = Array.isArray(out) ? blankTrim(out) : [];
311
+ } catch (error) {
312
+ raw = [fg(theme(), "error", `renderer error: ${error instanceof Error ? error.message : String(error)}`)];
313
+ }
306
314
  // pi 的 renderResult 以 "\n" 开头分段;剥掉首尾空行,别让 ⎿ 拐角行空挂。
307
- let raw: string[] = blankTrim(native.render(bodyWidth));
308
315
  if (cmCalls > 0 && rowsLeft !== Infinity) {
309
316
  // calls 段与 stdout 段以一个分段空行相隔(pi renderResult 用 join("\n\n") 分段)。
310
317
  const sep = raw.findIndex(isBlank);
@@ -368,9 +375,11 @@ export function createClaudeView(
368
375
  const head = headerOf(v, t, width), body = foreignBody(self, width, v.expanded);
369
376
  lines = [...head, ...(body?.lines ?? [])];
370
377
  entries = [{ component: toggleTool(self), height: head.length }, ...(body?.entries ?? [])];
371
- if (v.partial && !body?.lines.length) {
372
- const pending = prefixed(fg(t, "dim", v.started ? "Running…" : "Waiting…"), width, resultIndent(t).first, RESULT_CONT());
373
- lines.push(...pending); entries.push({ component: {}, height: pending.length });
378
+ if (!body?.lines.length) {
379
+ // 空 body 占位:运行中(含 result 未回的非流式调用)显示 Running…,完成但无输出显示 (no output),卡片不光杆。
380
+ const label = v.partial || self.result === undefined ? (v.started ? "Running…" : "Waiting…") : "(no output)";
381
+ const placeholder = prefixed(fg(t, "dim", label), width, resultIndent(t).first, RESULT_CONT());
382
+ lines.push(...placeholder); entries.push({ component: {}, height: placeholder.length });
374
383
  }
375
384
  } else {
376
385
  const painted = paintTool(v, t, width, config);
@@ -28,6 +28,17 @@ function labelOf(customType: string): string {
28
28
  return tail.charAt(0).toUpperCase() + tail.slice(1);
29
29
  }
30
30
 
31
+ /** 预览首行:跳过空行与纯标点行({ } [ ] "),取首个有实质内容的行(截 120 列)。 */
32
+ function firstMeaningfulLine(lines: readonly string[]): string {
33
+ for (const line of lines) {
34
+ const text = oneLine(String(line)).trim();
35
+ if (text && !/^[{}\[\]",]*$/.test(text)) {
36
+ return text.length > 120 ? `${text.slice(0, 120)}…` : text;
37
+ }
38
+ }
39
+ return "(empty)";
40
+ }
41
+
31
42
  /** JSON 内容的智能首行:query/title 等字段优先,数组给条数,否则紧凑化。 */
32
43
  function jsonPreview(text: string): string | undefined {
33
44
  const trimmed = text.trim();
@@ -82,8 +93,13 @@ export function createGenericCardRenderer(hooks: GenericCardHooks) {
82
93
  if (expanded) {
83
94
  for (const line of visible) lines.push(...prefixed(fg(theme, "dim", line), width, first, RESULT_CONT()));
84
95
  } else {
85
- const head = oneLine(visible[0]);
86
- lines.push(...prefixed(fg(theme, "muted", head) + expandHint(theme), width, first, RESULT_CONT()));
96
+ // 与工具块/subagent 同构:首行预览独立一行,展开提示独立一行(… +N lines)。
97
+ const head = firstMeaningfulLine(visible);
98
+ lines.push(...prefixed(fg(theme, "muted", head), width, first, RESULT_CONT()));
99
+ if (visible.length > 1) {
100
+ const hidden = visible.length - 1;
101
+ lines.push(...prefixed(fg(theme, "dim", `… +${hidden} line${hidden === 1 ? "" : "s"}`) + expandHint(theme), width, first, RESULT_CONT()));
102
+ }
87
103
  }
88
104
  return lines;
89
105
  },