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

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.0",
3
+ "version": "0.8.2",
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,7 @@ import { Box, Container, Markdown, truncateToWidth, visibleWidth } from "@earend
3
3
  import { getMarkdownTheme, keyText } from "@earendil-works/pi-coding-agent";
4
4
  import { BUILTIN_NAMES, PROCESS_TOOL_NAMES, bold, canExpandTool, expandHint, failedTool, fg, fit, headerOf, isBlank, isImageLine, oneLine, paintBackground, paintTool, prefixed, prefixZones, resultIndent, RESULT_CONT, targetOf, type ToolAppearance, type ToolView } from "./claude-tools.ts";
5
5
  import { animateRunningSummary } from "./running-effect.ts";
6
+ import { normalizeForeignLines } from "./foreign-normalizer.ts";
6
7
 
7
8
  export interface ClaudeConfig extends ToolAppearance {
8
9
  detailsBackground: string;
@@ -727,7 +728,7 @@ export function createClaudeView(
727
728
  const api = {
728
729
  enabled: () => !disabled,
729
730
  fail, hookMode, renderChat, dispose,
730
- toolExecRender: (self: any, orig: Function, width: number) => renderTool(self, orig, width),
731
+ toolExecRender: (self: any, orig: Function, width: number) => normalizeForeignLines(renderTool(self, orig, width)),
731
732
  toolExecHandleMouse: (self: any, orig: Function, event: any) => disabled ? orig.call(self, event) : Container.prototype.handleMouse.call(self, event),
732
733
  assistantRender: renderAssistant,
733
734
  assistantUpdateContent(self: any, orig: Function, message: any, streaming?: boolean) {
@@ -28,10 +28,34 @@ function labelOf(customType: string): string {
28
28
  return tail.charAt(0).toUpperCase() + tail.slice(1);
29
29
  }
30
30
 
31
- /** 内容来源:message.content / entry.data(对象优先取 name/description,否则 JSON)。 */
31
+ /** JSON 内容的智能首行:query/title 等字段优先,数组给条数,否则紧凑化。 */
32
+ function jsonPreview(text: string): string | undefined {
33
+ const trimmed = text.trim();
34
+ if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) return undefined;
35
+ try {
36
+ const parsed = JSON.parse(trimmed);
37
+ if (Array.isArray(parsed)) return `${parsed.length} item${parsed.length === 1 ? "" : "s"}`;
38
+ if (parsed && typeof parsed === "object") {
39
+ for (const key of ["query", "q", "title", "summary", "text", "message"]) {
40
+ const value = (parsed as Record<string, unknown>)[key];
41
+ if (typeof value === "string" && value.trim()) return value;
42
+ }
43
+ const firstString = Object.values(parsed).find((v) => typeof v === "string" && String(v).trim());
44
+ if (firstString !== undefined) return String(firstString);
45
+ return trimmed.replace(/\s+/g, " ").slice(0, 200);
46
+ }
47
+ } catch { /* 非 JSON 或超长,回退原文 */ }
48
+ return undefined;
49
+ }
50
+
51
+ /** 内容来源:message.content / entry.data(对象优先取 name/description,JSON 字符串智能摘要)。 */
32
52
  function bodyOf(payload: any): string {
33
53
  const source = typeof payload?.content === "string" ? payload.content : payload?.data;
34
- if (typeof source === "string") return source;
54
+ if (typeof source === "string") {
55
+ const preview = jsonPreview(source);
56
+ if (preview !== undefined) return preview;
57
+ return source;
58
+ }
35
59
  if (source && typeof source === "object") {
36
60
  const name = typeof source.name === "string" ? source.name : "";
37
61
  const desc = typeof source.description === "string" ? source.description : "";
@@ -75,7 +75,7 @@ export function renderRichToolResult(
75
75
  filePath,
76
76
  previousContent: metadata.previousContent,
77
77
  fileExistedBeforeWrite: metadata.fileExistedBeforeWrite,
78
- collapsedHiddenLines: writeContent !== undefined ? writeContent.split(/\r?\n/).length : undefined,
78
+ collapsedHiddenLines: writeContent !== undefined ? writeContent.replace(/\r?\n$/, "").split(/\r?\n/).length : undefined,
79
79
  isHovered: options?.isHovered,
80
80
  invalidate: () => context?.invalidate?.(),
81
81
  },