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

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.7",
3
+ "version": "0.8.9",
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",
@@ -47,10 +47,12 @@ export function patchRendererDispatch(cls: any): boolean {
47
47
  proto[FLAG] = true;
48
48
  for (const method of ["getMessageRenderer", "getEntryRenderer"]) {
49
49
  const orig = proto[method];
50
+ // kind("getMessageRenderer"/"getEntryRenderer")随转发传给 impl:generic 兜底只挂 message 侧——
51
+ // 原生对无 renderer 的 entry 完全不显示(addCustomEntryToChat 直接 return),entry 侧挖出数据型条目只是噪音。
50
52
  proto[method] = function (customType: string) {
51
53
  const impl = (globalThis as any).__leanTidyImpl;
52
54
  try {
53
- const override = impl?.rendererOverride?.(customType);
55
+ const override = impl?.rendererOverride?.(customType, method);
54
56
  if (override) return override;
55
57
  } catch {}
56
58
  return orig.call(this, customType);
@@ -40,22 +40,42 @@ function firstMeaningfulLine(lines: readonly string[]): string {
40
40
  }
41
41
 
42
42
  /** JSON 内容的智能首行:query/title 等字段优先,数组给条数,否则紧凑化。 */
43
+ /** 无语义键:预览跳过(id/时间戳等对读者无信息量)。 */
44
+ const JSON_PREVIEW_SKIP_KEYS = new Set(["id", "responseId", "requestId", "ts", "timestamp", "createdAt", "updatedAt"]);
45
+
46
+ /** 已 parse 的 JSON 摘要:query/queries/provider 等语义字段优先,数组给条数,否则紧凑化。 */
47
+ function summarizeJson(parsed: unknown): string | undefined {
48
+ if (Array.isArray(parsed)) return `${parsed.length} item${parsed.length === 1 ? "" : "s"}`;
49
+ if (parsed && typeof parsed === "object") {
50
+ const record = parsed as Record<string, unknown>;
51
+ const queries = record.queries;
52
+ if (Array.isArray(queries) && queries.length) return `queries: ${queries.map(String).join("; ")}`;
53
+ for (const key of ["query", "q", "title", "summary", "text", "message", "provider", "providers"]) {
54
+ const value = record[key];
55
+ if (typeof value === "string" && value.trim()) return value;
56
+ if (Array.isArray(value) && value.length && value.every((v) => typeof v === "string")) return value.join("; ");
57
+ }
58
+ const firstString = Object.entries(record).find(([k, v]) => typeof v === "string" && String(v).trim() && !JSON_PREVIEW_SKIP_KEYS.has(k));
59
+ if (firstString !== undefined) return String(firstString[1]);
60
+ return JSON.stringify(record).replace(/\s+/g, " ").slice(0, 200);
61
+ }
62
+ return undefined;
63
+ }
64
+
65
+ /** JSON 智能预览:允许 JSON 外裹文本(markdown 等)——从首个 {/[ 开头行逐行累积 parse,成功即摘要。 */
43
66
  function jsonPreview(text: string): string | undefined {
44
- const trimmed = text.trim();
45
- if (!trimmed.startsWith("{") && !trimmed.startsWith("[")) return undefined;
46
- try {
47
- const parsed = JSON.parse(trimmed);
48
- if (Array.isArray(parsed)) return `${parsed.length} item${parsed.length === 1 ? "" : "s"}`;
49
- if (parsed && typeof parsed === "object") {
50
- for (const key of ["query", "q", "title", "summary", "text", "message"]) {
51
- const value = (parsed as Record<string, unknown>)[key];
52
- if (typeof value === "string" && value.trim()) return value;
53
- }
54
- const firstString = Object.values(parsed).find((v) => typeof v === "string" && String(v).trim());
55
- if (firstString !== undefined) return String(firstString);
56
- return trimmed.replace(/\s+/g, " ").slice(0, 200);
67
+ const lines = text.trim().split("\n");
68
+ for (let i = 0; i < lines.length; i++) {
69
+ const head = lines[i].trim();
70
+ if (!head.startsWith("{") && !head.startsWith("[")) continue;
71
+ let buffer = "";
72
+ for (let j = i; j < lines.length && j - i < 200; j++) {
73
+ buffer += `${lines[j]}\n`;
74
+ try {
75
+ return summarizeJson(JSON.parse(buffer));
76
+ } catch { /* 继续累积 */ }
57
77
  }
58
- } catch { /* 非 JSON 或超长,回退原文 */ }
78
+ }
59
79
  return undefined;
60
80
  }
61
81
 
package/src/index.ts CHANGED
@@ -454,11 +454,12 @@ export default async function leanTidy(pi: ExtensionAPI): Promise<void> {
454
454
  normalizeForeign: (lines: readonly string[]): string[] =>
455
455
  config.normalizeForeignRenderers ? normalizeForeignLines(lines) : (lines as string[]),
456
456
  /** 分发层拦截:内置适配表优先,其余 generic 自动接管,黑名单跳过;不受包加载顺序影响。 */
457
- rendererOverride: (customType: string): any => {
457
+ rendererOverride: (customType: string, via?: "getMessageRenderer" | "getEntryRenderer"): any => {
458
458
  if (config.foreignCardSkip.includes(customType)) return undefined;
459
459
  if (customType === "subagent-notification") return config.subagentRendering === "claude" ? subagentRenderer : undefined;
460
460
  if (customType === "subagents:workflow") return config.workflowRendering === "claude" ? workflowRenderer : undefined;
461
- return config.foreignCardStyle === "generic" ? genericCardRenderer : undefined;
461
+ // generic 兜底仅限 message 分发:entry 侧原生对无 renderer 完全不显示(数据型条目是噪音),回落原生。
462
+ return via !== "getEntryRenderer" && config.foreignCardStyle === "generic" ? genericCardRenderer : undefined;
462
463
  },
463
464
  } as RuntimeImpl;
464
465
  for (const method of IMPL_METHODS) {