pi-pretty-tui 0.2.7 → 0.2.8

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
@@ -37,6 +37,10 @@ Displayed custom messages without their own renderer use one generic accent-colo
37
37
 
38
38
  Pi's direct internal `showStatus()` feedback is transient: it appears only in the status line above the editor, a newer status replaces it, and a ten-second timer removes it. It never enters the transcript or activity timeline and is cleared on reload. In clean mode, `Ctrl+T` and `Ctrl+O` only show short hints to click the corresponding disclosure; neither changes visibility or Pi's Thinking setting. In full and compact modes, both shortcuts keep Pi's native behaviour.
39
39
 
40
+ ## Error presentation
41
+
42
+ In clean mode, standalone errors keep their original title and complete text in a compact `✕ Error · reason` layout. Consecutive errors with exactly the same source type, title, and full text share one visible row with a dim `×2` / `×3` count. Other transcript components break the run; errors carrying thought/tool/visible-response content are not folded. This is UI-only: session records and original message components remain unchanged. Long errors wrap without an added preview truncation; full/compact modes keep native presentation.
43
+
40
44
  ## Codemode and nested tools
41
45
 
42
46
  In clean mode, tools that call other tools through Pi's nested execution API keep their own parent node. Expand the activity group to see each internal call, its status, compact arguments, duration, and result summary. Click an internal call to inspect its arguments and text result independently. Click its expanded body to collapse just that call. Script and script-output bodies also collapse their own sections when clicked. Tool calls use a `●` marker: dim while running, success-colored when successful, and error-colored when failed. Tool names use bold theme text. `[Script]` and `[Script output]` are separate disclosures; the nested parent title is informational and clicking it does not expand or collapse details. Use each section or child to expand and collapse its own details; `Ctrl+O` only shows a hint in clean mode. Extensions can still use Pi's `setToolsExpanded()` API for global control; local disclosures remain usable afterward, and another global API call resets the local overrides. Calls retain their start order even when they finish in parallel. A handled child failure remains marked as failed even if the script succeeds.
package/README.zh-CN.md CHANGED
@@ -37,6 +37,10 @@ Pi 可能会提示内置工具被覆盖。这是正常现象:pi-pretty-tui 会
37
37
 
38
38
  Pi 内部直接调用 `showStatus()` 产生的反馈属于临时 UI 状态:它只显示在编辑器上方,新状态替换旧状态,并由十秒 timer 自动清除;它不会进入 transcript 或活动时间线,reload 时也会清除。在 clean 模式下,`Ctrl+T` 和 `Ctrl+O` 都只显示点击对应节点的简短提示,不改变内容可见性或 Pi 的 Thinking 设置。在 full 和 compact 模式下,两者保留 Pi 的原生行为。
39
39
 
40
+ ## 错误展示
41
+
42
+ clean 模式下,独立错误保留原始标题和完整内容,以紧凑的 `✕ Error · 原因` 展示。来源类型、标题及完整内容完全一致的相邻错误合为一条可见行,并使用暗色 `×2` / `×3` 标识次数。其他 transcript 组件会打断计数;包含思考、工具或可见回答的错误不参与合并。合并仅影响 UI,不删除或修改会话记录及原始消息组件。长错误完整换行,不增加预览截断;full/compact 模式保留原生展示。
43
+
40
44
  ## Codemode 与嵌套工具
41
45
 
42
46
  clean 模式下,通过 Pi 嵌套执行 API 调用其他工具的工具保留自己的父节点。展开活动组后,会显示各内部调用的状态、紧凑参数、耗时和结果摘要;点击某个内部调用,可以独立展开其参数和文本结果;点击展开后的正文可收起该调用,脚本和脚本输出正文也可点击收起各自区块。工具统一使用 `●` 圆点:运行中为主题暗色,成功与失败分别为主题成功色与错误色;工具名使用正文色加粗。`[Script]` 和 `[Script output]` 分别控制脚本与汇总输出;嵌套父工具标题仅用于展示,点击不会展开或折叠详情。各区块或子调用通过自己的入口独立展开/收起,`Ctrl+O` 在 clean 模式下只显示提示。扩展仍可通过 Pi 的 `setToolsExpanded()` API 全局控制,之后也可局部展开/收起;再次调用全局 API 会重置局部状态。并行调用按照启动顺序排列,不会随完成顺序跳动。即使脚本捕获错误后成功,失败的子调用仍会明确标记。
@@ -100,6 +100,32 @@ export default function prettyTui(pi: ExtensionAPI) {
100
100
  const mouseClickHitTests = new WeakMap<object, (event: any) => boolean>();
101
101
  let currentTui: any;
102
102
  let currentPromptEditor: any;
103
+ let errorChatContainer: any;
104
+ const runtimeErrorDescriptors = new WeakMap<object, { source: string; title: string; content: string }>();
105
+ const errorDescriptor = (component: any) => {
106
+ const runtime = runtimeErrorDescriptors.get(component);
107
+ if (runtime) return runtime;
108
+ if (!(component instanceof AssistantMessageComponent)) return undefined;
109
+ const message = (component as any).lastMessage;
110
+ if (message?.stopReason !== "error" || (message.content ?? []).some((item: any) =>
111
+ item.type === "toolCall" || item.type === "thinking" || item.type === "text" && item.text?.length)) return undefined;
112
+ return { source: "assistant:error", title: "Error", content: String(message.errorMessage ?? "") };
113
+ };
114
+ const errorRun = (component: any) => {
115
+ const children: any[] = errorChatContainer?.children ?? [];
116
+ const index = children.indexOf(component);
117
+ const descriptor = errorDescriptor(component);
118
+ const same = (other: any) => {
119
+ const value = errorDescriptor(other);
120
+ return descriptor && value && value.source === descriptor.source &&
121
+ value.title === descriptor.title && value.content === descriptor.content;
122
+ };
123
+ if (index < 0 || !descriptor) return { hidden: false, count: 1, compact: false };
124
+ let count = 1;
125
+ while (index + count < children.length && same(children[index + count])) count++;
126
+ return { hidden: index > 0 && Boolean(same(children[index - 1])), count,
127
+ compact: index > 0 && Boolean(errorDescriptor(children[index - 1])) };
128
+ };
103
129
  const runningColor = (theme: any, text: string): string =>
104
130
  typeof currentPromptEditor?.borderColor === "function"
105
131
  ? currentPromptEditor.borderColor(text)
@@ -553,7 +579,31 @@ export default function prettyTui(pi: ExtensionAPI) {
553
579
  );
554
580
  };
555
581
 
556
- const renderPendingActivityUpdate = (member: ActivityMember, width: number): string[] => {
582
+ const renderStandaloneError = (member: ActivityMember, width: number, component?: any): string[] => {
583
+ const run = component ? errorRun(component) : { hidden: false, count: 1, compact: false };
584
+ if (run.hidden) return [];
585
+ const theme = defaultActivityTheme();
586
+ const style = activityUpdateStyle(member, theme);
587
+ const original = component ? errorDescriptor(component) : undefined;
588
+ const title = stripTerminalSequences(original?.title ?? member.updateTitle ?? "Error");
589
+ const content = stripTerminalSequences(original?.content || member.updateContent || "");
590
+ const heading = style.icon + style.title(title);
591
+ const prefix = heading + (content ? theme.fg("dim", " · ") : "");
592
+ const text = prefix + theme.fg("muted", content) + (run.count > 1 ? theme.fg("dim", ` ×${run.count}`) : "");
593
+ // Wrap rather than truncate; all original detail lines remain accessible.
594
+ const continuation = " ".repeat(Math.min(visibleWidth(prefix), Math.max(0, Math.floor(width / 3))));
595
+ const rows: string[] = [];
596
+ for (const line of text.split("\n")) {
597
+ const wrapped = wrapTextWithAnsi(line, Math.max(1, width - visibleWidth(continuation)));
598
+ rows.push(...wrapped.map((row, index) => (rows.length || index ? continuation : "") + row));
599
+ }
600
+ return [...(run.compact ? [] : [""]), ...rows.map((line) => truncateToWidth(line, Math.max(1, width), ""))];
601
+ };
602
+
603
+ const renderPendingActivityUpdate = (member: ActivityMember, width: number, component?: any): string[] => {
604
+ if (member.updateSeverity === "error" && member.updateTitle !== "Response truncated") {
605
+ return renderStandaloneError(member, width, component);
606
+ }
557
607
  const theme = defaultActivityTheme();
558
608
  const title = truncateToWidth(member.updateTitle ?? "Update", Math.max(1, width - 2), "…");
559
609
  const style = activityUpdateStyle(member, theme);
@@ -572,8 +622,9 @@ export default function prettyTui(pi: ExtensionAPI) {
572
622
  group: ActivityGroup,
573
623
  member: ActivityMember,
574
624
  width: number,
625
+ component?: any,
575
626
  ): string[] => {
576
- if (!activityGroupCollapsible(group)) return renderPendingActivityUpdate(member, width);
627
+ if (!activityGroupCollapsible(group)) return renderPendingActivityUpdate(member, width, component);
577
628
  const position = activityMemberPosition(group, member);
578
629
  if (!activityGroupRevealed(group)) {
579
630
  return position.first
@@ -1242,7 +1293,7 @@ export default function prettyTui(pi: ExtensionAPI) {
1242
1293
  const terminalGroup = activityTimeline.groupForMember(terminalMember.id);
1243
1294
  if (!terminalGroup) return originalRender.call(this, width);
1244
1295
  activityUpdateComponents.set(terminalMember.id, this);
1245
- return renderActivityUpdateProjection(terminalGroup, terminalMember, width);
1296
+ return renderActivityUpdateProjection(terminalGroup, terminalMember, width, this);
1246
1297
  }
1247
1298
 
1248
1299
  const key = assistantMessageKey(message);
@@ -1507,10 +1558,14 @@ export default function prettyTui(pi: ExtensionAPI) {
1507
1558
  const group = activityTimeline.groupForMember(member.id);
1508
1559
  if (!group || !mode.chatContainer?.addChild) return false;
1509
1560
  const component: Component = {
1510
- render: (width: number) => renderActivityUpdateProjection(group, member, width),
1561
+ render: (width: number) => renderActivityUpdateProjection(group, member, width, component),
1511
1562
  invalidate() {},
1512
1563
  handleMouse: (event: any) => handleActivityUpdateMouse(group, member, event),
1513
1564
  } as Component;
1565
+ if (severity === "error") runtimeErrorDescriptors.set(component, {
1566
+ source: "runtime:error", title, content,
1567
+ });
1568
+ errorChatContainer = mode.chatContainer;
1514
1569
  activityUpdateComponents.set(member.id, component);
1515
1570
  mode.chatContainer.addChild(component);
1516
1571
  mode.ui?.requestRender?.();
@@ -1569,6 +1624,7 @@ export default function prettyTui(pi: ExtensionAPI) {
1569
1624
 
1570
1625
  const patchedRenderSessionEntries = function (this: any, entries: any[], options?: any) {
1571
1626
  currentTui = this.ui;
1627
+ errorChatContainer = this.chatContainer;
1572
1628
  fullscreenTui = currentTui?.mode === "fullscreen";
1573
1629
  // buildContextEntries() prepends the latest compaction for model context,
1574
1630
  // while Pi's live compaction UI appends it chronologically. Keep reloads
@@ -1674,6 +1730,7 @@ export default function prettyTui(pi: ExtensionAPI) {
1674
1730
  // calling sites, rather than depend on private chat-container children or
1675
1731
  // instanceof checks (these can be wrapped or come from another module).
1676
1732
  const patchedAddMessageToChat = function (this: any, message: any, ...args: any[]) {
1733
+ errorChatContainer = this.chatContainer;
1677
1734
  if (message?.role === "assistant") cacheMessageContexts.set(this, message);
1678
1735
  else cacheMessageContexts.delete(this);
1679
1736
  return originalAddMessageToChat.call(this, message, ...args);
@@ -1874,6 +1931,7 @@ export default function prettyTui(pi: ExtensionAPI) {
1874
1931
 
1875
1932
  pi.on("session_shutdown", () => {
1876
1933
  fullscreenTui = false;
1934
+ errorChatContainer = undefined;
1877
1935
  currentTui = undefined;
1878
1936
  clearLatestActivityStatus();
1879
1937
  currentExtensionUi = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-pretty-tui",
3
- "version": "0.2.7",
3
+ "version": "0.2.8",
4
4
  "description": "A beautiful, polished TUI for the Pi coding agent",
5
5
  "license": "MIT",
6
6
  "author": "Kainan Yang <ykn0309@whu.edu.cn>",