pi-pretty-tui 0.2.5 → 0.2.6

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
@@ -7,13 +7,13 @@ A beautiful, polished TUI for the [Pi coding agent](https://pi.dev/).
7
7
  ## Features
8
8
 
9
9
  - **Collapsible activity timeline:** instead of filling the conversation with individual calls, thoughts, tools, and ordinary `info` notifications share one chronological activity stream. Work appears beneath a single `Running(...)` row and settles into a quiet `Done(...)` row. Parent rows distinguish top-level tool calls, nested calls, and thoughts; expanding one reveals every ordered member with summaries retained above nested details. Thoughts and tools are peers: a turn that calls no tool still gets its own `Running(1 thought)` / `Done(1 thought)` parent row with the Thought as its child, so thinking is never dropped.
10
- - **Live working duration:** in clean mode, elapsed time appears beside `Working` in the prompt editor's top border, using the border's own color. It shares the agent-run clock and duration format with the completion footer, includes automatic retries, and disappears when the run settles. Narrow editors omit the timer when it cannot fit. Expanded `Done` titles and markers use the theme's `success` color; collapsed summaries remain quiet gray.
10
+ - **Live working duration:** in clean mode, elapsed time appears beside `Working` in the prompt editor's top border, using the border's own color. It shares the agent-run clock and duration format with the completion footer, includes automatic retries, and disappears when the run settles. Narrow editors omit the timer when it cannot fit. The clean-mode `Running` parent dot alternates between `accent` and `dim` about every 800 ms; its label and tool dots stay stable, and the pulse stops when the run settles. Expanded `Done` titles and markers use the theme's `success` color; collapsed summaries remain quiet gray.
11
11
  - **Transient UI status:** one line above the editor shows direct Pi UI feedback such as Thinking/tool-output visibility changes. A newer UI status replaces it, and it disappears automatically after ten seconds without entering the transcript or session.
12
12
  - **Durable response footers:** once the complete agent run settles—including tools, retries, and compaction—the final answer ends with one quiet gray divider containing the elapsed-work time and, in fullscreen, a `[Copy]` control. It copies only the final visible answer, excluding thoughts, tools, statuses, and the footer itself; the footer survives reloads and session-tree navigation.
13
13
  - **Useful details on demand:** tool-aware summaries keep paths, commands, results, diffs, file previews, and live shell output concise without removing access to the original content.
14
- - **A cohesive visual finish:** transparent, right-aligned user chat bubbles size themselves to short messages and wrap longer ones at 75% of the terminal width, with an accent-blue rounded border and no redundant `User` label. Together with the rounded prompt input, theme-aware colors, clear Markdown heading hierarchy, cleaner lists, and rounded syntax-highlighted code blocks, they make the entire TUI feel intentional. In fullscreen, each fenced code block also includes a native-feeling `[Copy]` control.
14
+ - **A cohesive visual finish:** transparent, right-aligned user chat bubbles size themselves to short messages and wrap longer ones at 75% of the terminal width, with a rounded border in the theme's link color (`mdLink`) and no redundant `User` label. Together with the rounded prompt input, theme-aware colors, clear Markdown heading hierarchy, cleaner lists, and rounded syntax-highlighted code blocks, they make the entire TUI feel intentional. In fullscreen, each fenced code block also includes a native-feeling `[Copy]` control.
15
15
 
16
- Pi's built-in `read`, `bash`, `edit`, `write`, `grep`, `find`, and `ls` tools receive purpose-built compact views. Third-party tools without nested calls automatically receive a consistent compact row; opening it preserves its native renderer while removing conflicting terminal background colors. User and steering messages, compaction summaries, visible assistant text, warnings, errors, aborted/truncated responses, and displayed custom messages with a registered renderer create hard group boundaries. Pi's cursor, IME, autocomplete, mouse interaction, and tool execution behavior remain intact.
16
+ Pi's built-in `read`, `bash`, `edit`, `write`, `grep`, `find`, and `ls` tools receive purpose-built compact views. Third-party tools without nested calls automatically receive a consistent compact row; opening it preserves its native renderer while removing conflicting terminal background colors. User and steering messages, compaction summaries, visible assistant text, warnings, errors, aborted/truncated responses, and displayed custom messages with a registered renderer create hard group boundaries. Pi's cursor, IME, autocomplete, and tool execution behavior remain intact; fullscreen mouse additions are described below.
17
17
 
18
18
  ## Install
19
19
 
@@ -27,7 +27,7 @@ Pi may warn that built-in tools are being overridden. This is expected: pi-prett
27
27
 
28
28
  ## Working with tool calls
29
29
 
30
- Click a `Running(...)` or `Done(...)` row to keep it as a parent and reveal tools, completed `● thought` entries, and extension updates beneath it. Click an individual tool or thought to reveal nested details without replacing its summary. The last item in each expanded tree, `└─ [↑ Collapse]`, collapses just that group without scrolling back to its parent; clicking the parent also works. Press `Ctrl+O` at any time to use Pi's global expansion control for all tool output and thinking content. The end-of-tree action still collapses only its own group after global expansion. Third-party replacements for `grep` and `find` (such as FFF) use compact tree rows too, with their native details available when expanded. Tool names use each definition's `label` verbatim, falling back to its raw `name`; pi-pretty-tui does not rename or title-case them.
30
+ Click a `Running(...)` or `Done(...)` row to keep it as a parent and reveal tools, completed `● thought` entries, and extension updates beneath it. Click an individual tool or thought to reveal nested details without replacing its summary. The last item in each expanded tree, `└─ [↑ Collapse]`, collapses just that group without scrolling back to its parent; clicking the parent also works. In clean mode, `Ctrl+O` only shows a hint to use these local disclosures; it does not expand or collapse content. Full and compact modes retain Pi's native global tool-output expansion. Third-party replacements for `grep` and `find` (such as FFF) use compact tree rows too, with their native details available when expanded. Compact tool names use bold `text`, parameters use `muted`, and running tool dots use `dim`; success/error dots keep their corresponding theme colors. Thought dots use `mdLink`, titles use bold `text`, and detail body text uses `muted`. Tool names use each definition's `label` verbatim, falling back to its raw `name`; pi-pretty-tui does not rename or title-case them.
31
31
 
32
32
  Extension calls to `ctx.ui.notify(message, "info")` (or with the type omitted) join an existing thought/tool group in chronological order; without existing work they remain independent and never attach to a future group. Warnings and errors stay standalone, use yellow `⚠` and red `✕`, and are hard boundaries. Tool failures remain owned by their tool details. None of these extension notifications or errors appear in the transient UI-status line.
33
33
 
@@ -35,11 +35,11 @@ In clean mode, Pi's native cache-miss notices join the thought/tool group of the
35
35
 
36
36
  Displayed custom messages without their own renderer use one generic accent-coloured `◇` Markdown presentation: they join current thought/tool work when it exists, otherwise remain independent, and preserve their session persistence. Messages with a registered renderer remain completely native and form hard boundaries. These decisions use only Pi's notification type and renderer presence—never extension names, custom message names, or content heuristics.
37
37
 
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` leaves Pi's persisted Thinking setting unchanged and shows a short hint instead: thought details expand only when their own row is clicked, while `Ctrl+O` retains global activity expansion. In full and compact modes, `Ctrl+T` keeps Pi's native behaviour.
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
40
  ## Codemode and nested tools
41
41
 
42
- 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. Successful and failed tool calls consistently use a `●` marker in the theme's success and error colors, respectively. `[Script]` and `[Script output]` are separate disclosures; clicking the parent tool or pressing `Ctrl+O` expands all its details. Calls retain their start order even when they finish in parallel. A handled child failure remains marked as failed even if the script succeeds.
42
+ 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.
43
43
 
44
44
  The group distinguishes, for example, `1 tool call · 3 nested calls`. Internal calls never become phantom transcript members or displace the end-of-tree collapse action. Ownership uses Pi's `parentToolCallId`, not tool names or JavaScript parsing; wrappers other than codemode benefit too. This requires a Pi version with nested execution events (0.99.0 or later); older Pi keeps its existing display. Full and compact modes retain the native tool presentation.
45
45
 
@@ -53,6 +53,12 @@ Run `/pretty-tui` to open the extension settings. The `Enabled` switch persists
53
53
 
54
54
  The extension supports three persistent rendering modes: `clean` (default), `compact`, and `full`. Choose one interactively, or use `/pretty-tui clean`, `/pretty-tui compact`, `/pretty-tui full`, and `/pretty-tui status` directly. Settings are stored in `~/.pi/agent/pretty-tui.json` or under the directory selected by `PI_CODING_AGENT_DIR`.
55
55
 
56
+ In fullscreen, interactive activity rows and copy controls tolerate same-row horizontal pointer jitter of up to two terminal columns. Larger or vertical movement remains a drag; ordinary text selection, links, and Pi's double/triple-click behavior are unchanged.
57
+
58
+ ## Copy user messages
59
+
60
+ In fullscreen mode, left-click a user bubble's body or border to copy its complete original text, preserving Markdown, indentation, and line breaks without the bubble frame. Existing links and code-block `[Copy]` controls retain priority; dragging to select text does not trigger whole-message copy. Pi's native clipboard path provides copy feedback. This copies text, not image attachments. Regular mode keeps terminal-owned mouse selection and copying.
61
+
56
62
  ## Copy code blocks
57
63
 
58
64
  In fullscreen TUI mode, fenced Markdown code blocks in user and assistant transcript messages include a clickable `[Copy]` control in the top rule:
@@ -76,7 +82,7 @@ The suite covers live and restored activity timelines, retries and terminal stat
76
82
 
77
83
  ## Compatibility notice
78
84
 
79
- The current development and regression-test baseline is **Pi 1.0.0**. User chat bubbles support its direct Markdown layout, keeping their transparent background and content-sized width. Nested execution requires Pi 0.99.0 or later; this is a feature requirement, not a promise that every older Pi release is tested.
85
+ The current development and regression-test baseline is **Pi 1.0.1**. User chat bubbles support its direct Markdown layout, keeping their transparent background and content-sized width. Nested execution requires Pi 0.99.0 or later; this is a feature requirement, not a promise that every older Pi release is tested.
80
86
 
81
87
  Tool rendering uses Pi's documented extension APIs. Active-tool state follows Pi's built-in execution transitions through its exported interactive components. Clean-mode thought details use the activity hierarchy's own disclosure state; full and compact modes retain Pi's built-in Thinking visibility control. Rendering native user messages as adaptive chat bubbles, rounding the native prompt editor, changing unordered-list markers, and enhancing fenced code blocks require reload-safe runtime patches because Pi does not currently expose public renderer hooks for those presentation details. Markdown enhancements are activated only while rendering user and assistant messages in the main transcript; Markdown created by extension overlays keeps Pi's native layout. Markdown parsing, syntax highlighting, and terminal semantic zones remain handled by Pi.
82
88
 
package/README.zh-CN.md CHANGED
@@ -8,12 +8,12 @@
8
8
 
9
9
  - **可折叠的活动时间线:** 不再让大量独立调用填满对话。思考、工具和普通 `info` 通知会进入同一条按真实时间排序的活动流;工作进行时显示为 `Running(...)`,结束后变为低调的 `Done(...)`。父级分别统计顶层工具调用、嵌套调用和思考数量;展开后可查看所有有序成员,成员摘要在展开嵌套详情后仍然保留。思考与工具地位相同:没有调用任何工具的那一轮同样会有自己的 `Running(1 thought)` / `Done(1 thought)` 父行,思考作为其子级,内容不会被丢弃。
10
10
  - **可持久化的回答 footer:** 整轮 Agent 工作真正 settled 后(包括工具、自动重试和 compaction),最终回答底部会显示一条低调的灰色分隔线,工作时长与 fullscreen 模式下的 `[Copy]` 控件都嵌在线中。`[Copy]` 只复制最终可见回答,不包含 thought、工具、状态或 footer;reload 和 session tree 切换后仍会保留。
11
- - **实时工作计时:** clean 模式下,耗时显示在输入框顶部边框的 `Working` 右侧,颜色与边框一致。它与完成 footer 共用 Agent 整轮工作的计时起点和时长格式,包含自动重试,工作真正结束后消失;窄输入框放不下时会隐藏计时。展开后的 `Done` 标题和圆点使用主题的 `success` 色,折叠摘要仍保持低调的灰色。
11
+ - **实时工作计时:** clean 模式下,耗时显示在输入框顶部边框的 `Working` 右侧,颜色与边框一致。它与完成 footer 共用 Agent 整轮工作的计时起点和时长格式,包含自动重试,工作真正结束后消失;窄输入框放不下时会隐藏计时。clean 模式下,`Running` 父节点圆点约每 800 ms 在 `accent` 和 `dim` 间切换;文字与工具圆点保持稳定,整轮结束后停止闪烁。展开后的 `Done` 标题和圆点使用主题的 `success` 色,折叠摘要仍保持低调的灰色。
12
12
  - **临时 UI 状态:** 编辑器上方的一行只显示 Pi 直接产生的 UI 操作反馈,例如 Thinking 或工具输出可见性变化。新状态会替换旧状态,并在十秒后自动消失,不进入 transcript 或 session。
13
13
  - **按需查看有效信息:** 针对不同工具设计的摘要,会简洁呈现路径、命令、结果、diff、文件预览和实时 shell 输出,同时保留查看原始完整内容的能力。
14
- - **统一、精致的视觉体验:** 透明、右对齐的用户聊天气泡会根据短消息自适应宽度,长消息则在终端宽度的 75% 处换行;气泡使用 accent 浅蓝色圆角边框,并移除了多余的 `User` 标注。配合圆角输入框、主题感知配色、层级清晰的 Markdown 标题、更清爽的列表,以及带语法高亮的圆角代码块,让整个 TUI 更协调。在 fullscreen 模式下,每个围栏代码块还带有符合原生体验的 `[Copy]` 控件。
14
+ - **统一、精致的视觉体验:** 透明、右对齐的用户聊天气泡会根据短消息自适应宽度,长消息则在终端宽度的 75% 处换行;气泡使用主题链接色(`mdLink`)的圆角边框,并移除了多余的 `User` 标注。配合圆角输入框、主题感知配色、层级清晰的 Markdown 标题、更清爽的列表,以及带语法高亮的圆角代码块,让整个 TUI 更协调。在 fullscreen 模式下,每个围栏代码块还带有符合原生体验的 `[Copy]` 控件。
15
15
 
16
- Pi 内置的 `read`、`bash`、`edit`、`write`、`grep`、`find` 和 `ls` 工具使用专门设计的紧凑视图;没有嵌套调用的第三方工具会自动获得统一的紧凑行,单独展开时继续使用原生 renderer,但会移除与整体冲突的终端背景色。用户与 steer 消息、compaction 摘要、可见 assistant 正文、warning、error、aborted/length 响应,以及注册了专用 renderer 的 displayed custom message 都会形成硬分组边界。同时不会影响 Pi 原有的光标、输入法、自动补全、鼠标交互和工具执行行为。
16
+ Pi 内置的 `read`、`bash`、`edit`、`write`、`grep`、`find` 和 `ls` 工具使用专门设计的紧凑视图;没有嵌套调用的第三方工具会自动获得统一的紧凑行,单独展开时继续使用原生 renderer,但会移除与整体冲突的终端背景色。用户与 steer 消息、compaction 摘要、可见 assistant 正文、warning、error、aborted/length 响应,以及注册了专用 renderer 的 displayed custom message 都会形成硬分组边界。同时不会影响 Pi 原有的光标、输入法、自动补全和工具执行行为;fullscreen 鼠标交互增强见下文。
17
17
 
18
18
  ## 安装
19
19
 
@@ -27,7 +27,7 @@ Pi 可能会提示内置工具被覆盖。这是正常现象:pi-pretty-tui 会
27
27
 
28
28
  ## 使用工具调用
29
29
 
30
- 点击 `Running(...)` 或 `Done(...)` 行,可以保留父级并展开其下方的工具、已完成的 `● thought` 和扩展更新。点击单个工具或思考子项可在保留摘要的同时展开嵌套详情。每棵展开的树末尾都有 `└─ [↑ Collapse]`,无需滚回父级即可只折叠当前分组;再次点击父级也可以折叠。任何时候都可以按 `Ctrl+O`,使用 Pi 的全局展开控制来显示或隐藏全部工具输出和思考内容;全局展开后,树尾操作仍只折叠本组。第三方替换的 `grep`、`find`(如 FFF)也使用紧凑的树节点,展开子项时仍可查看原生详情。工具名称会原样使用定义中的 `label`,没有 `label` 时回退到原始 `name`;pi-pretty-tui 不再重命名或转换大小写。
30
+ 点击 `Running(...)` 或 `Done(...)` 行,可以保留父级并展开其下方的工具、已完成的 `● thought` 和扩展更新。点击单个工具或思考子项可在保留摘要的同时展开嵌套详情。每棵展开的树末尾都有 `└─ [↑ Collapse]`,无需滚回父级即可只折叠当前分组;再次点击父级也可以折叠。clean 模式下,`Ctrl+O` 只提示使用这些局部展开入口,不会展开或收起内容;full 和 compact 模式保留 Pi 原生的工具输出全局展开行为。第三方替换的 `grep`、`find`(如 FFF)也使用紧凑的树节点,展开子项时仍可查看原生详情。紧凑工具名使用 `text` 加粗,参数使用 `muted`,运行中工具圆点使用 `dim`,成功/失败圆点保留对应主题色。思考圆点使用 `mdLink`,标题使用 `text` 加粗,详情正文使用 `muted`。工具名称会原样使用定义中的 `label`,没有 `label` 时回退到原始 `name`;pi-pretty-tui 不再重命名或转换大小写。
31
31
 
32
32
  扩展调用 `ctx.ui.notify(message, "info")`(或省略 type)时,如果当前已有 thought/tool 活动组,通知会按真实时间顺序加入该组;如果没有现有工作,则独立显示,并且不会附着到未来的工具组。warning 和 error 保持独立,分别使用黄色 `⚠` 和红色 `✕`,并形成硬边界。工具失败继续归属于对应工具详情。上述扩展通知和错误都不会进入临时 UI 状态栏。
33
33
 
@@ -35,11 +35,11 @@ Pi 可能会提示内置工具被覆盖。这是正常现象:pi-pretty-tui 会
35
35
 
36
36
  没有自有 renderer 的 displayed custom message 使用统一、accent 配色的 `◇` Markdown 显示:当前存在 thought/tool 工作时加入当前组,否则独立显示,并保留 session 持久化。注册了 renderer 的消息完全保留插件原生显示并形成硬边界。所有判断只依据 Pi 的通知 type 和 renderer 是否存在,不识别扩展名称、custom message 名称,也不根据文本内容推断语义。
37
37
 
38
- Pi 内部直接调用 `showStatus()` 产生的反馈属于临时 UI 状态:它只显示在编辑器上方,新状态替换旧状态,并由十秒 timer 自动清除;它不会进入 transcript 或活动时间线,reload 时也会清除。在 clean 模式下,`Ctrl+T` 不修改 Pi 持久化的 Thinking 设置,只显示一条简短提示;thought 详情仅在点击对应子项时展开,`Ctrl+O` 继续负责全局活动展开。在 full 和 compact 模式下,`Ctrl+T` 保留 Pi 的原生行为。
38
+ Pi 内部直接调用 `showStatus()` 产生的反馈属于临时 UI 状态:它只显示在编辑器上方,新状态替换旧状态,并由十秒 timer 自动清除;它不会进入 transcript 或活动时间线,reload 时也会清除。在 clean 模式下,`Ctrl+T` 和 `Ctrl+O` 都只显示点击对应节点的简短提示,不改变内容可见性或 Pi 的 Thinking 设置。在 full 和 compact 模式下,两者保留 Pi 的原生行为。
39
39
 
40
40
  ## Codemode 与嵌套工具
41
41
 
42
- clean 模式下,通过 Pi 嵌套执行 API 调用其他工具的工具保留自己的父节点。展开活动组后,会显示各内部调用的状态、紧凑参数、耗时和结果摘要;点击某个内部调用,可以独立展开其参数和文本结果;点击展开后的正文可收起该调用,脚本和脚本输出正文也可点击收起各自区块。成功与失败的工具统一使用主题成功色与错误色的 `●` 圆点。`[Script]` 和 `[Script output]` 分别控制脚本与汇总输出;点击父工具或按 `Ctrl+O` 会展开全部详情。并行调用按照启动顺序排列,不会随完成顺序跳动。即使脚本捕获错误后成功,失败的子调用仍会明确标记。
42
+ clean 模式下,通过 Pi 嵌套执行 API 调用其他工具的工具保留自己的父节点。展开活动组后,会显示各内部调用的状态、紧凑参数、耗时和结果摘要;点击某个内部调用,可以独立展开其参数和文本结果;点击展开后的正文可收起该调用,脚本和脚本输出正文也可点击收起各自区块。工具统一使用 `●` 圆点:运行中为主题暗色,成功与失败分别为主题成功色与错误色;工具名使用正文色加粗。`[Script]` 和 `[Script output]` 分别控制脚本与汇总输出;嵌套父工具标题仅用于展示,点击不会展开或折叠详情。各区块或子调用通过自己的入口独立展开/收起,`Ctrl+O` 在 clean 模式下只显示提示。扩展仍可通过 Pi 的 `setToolsExpanded()` API 全局控制,之后也可局部展开/收起;再次调用全局 API 会重置局部状态。并行调用按照启动顺序排列,不会随完成顺序跳动。即使脚本捕获错误后成功,失败的子调用仍会明确标记。
43
43
 
44
44
  活动组会分别统计,例如 `1 tool call · 3 nested calls`。内部调用不会变成不存在的顶层 transcript 成员,也不会挤掉树尾折叠按钮。归属依据 Pi 的 `parentToolCallId`,不依赖工具名或 JavaScript 源码解析,因此其他嵌套调用工具也适用。这需要支持嵌套执行事件的 Pi(0.99.0 及以后);旧版本保持原有显示。full 和 compact 模式保留原生工具展示。
45
45
 
@@ -53,6 +53,12 @@ clean 模式下,通过 Pi 嵌套执行 API 调用其他工具的工具保留
53
53
 
54
54
  扩展支持三种可持久化的渲染模式:`clean`(默认)、`compact` 和 `full`。可交互选择,也可以直接使用 `/pretty-tui clean`、`/pretty-tui compact`、`/pretty-tui full` 和 `/pretty-tui status`。设置会保存到 `~/.pi/agent/pretty-tui.json`,或 `PI_CODING_AGENT_DIR` 指定目录中的对应位置。
55
55
 
56
+ fullscreen 模式下,活动树交互行与复制入口允许同一行左右最多两个终端字符格的鼠标抖动;更大偏移或跨行移动仍按拖动处理。普通文本选择、链接和 Pi 的双击/三击行为保持不变。
57
+
58
+ ## 复制用户消息
59
+
60
+ fullscreen 模式下,左键点击用户气泡的正文或边框,可复制完整原始文本,保留 Markdown、缩进和换行,不包含气泡边框。已有链接和代码块 `[Copy]` 控件保留优先级;拖动选择文本不会触发整条复制。复制使用 Pi 原生剪贴板路径及反馈,只复制文本,不复制图片附件。regular 模式保留终端自身的鼠标选择与复制行为。
61
+
56
62
  ## 复制代码块
57
63
 
58
64
  在 fullscreen TUI 模式下,用户消息与助手回复中的 Markdown 围栏代码块会在顶部边框显示可点击的 `[Copy]` 控件:
@@ -76,7 +82,7 @@ npm test
76
82
 
77
83
  ## 兼容性说明
78
84
 
79
- 当前开发与回归测试基线为 **Pi 1.0.0**。用户气泡已适配该版本直接使用 Markdown 的布局,保留透明背景与按内容自适应的宽度。嵌套执行需要 Pi 0.99.0 及以后;这是功能要求,不代表每个旧版都经过测试。
85
+ 当前开发与回归测试基线为 **Pi 1.0.1**。用户气泡已适配该版本直接使用 Markdown 的布局,保留透明背景与按内容自适应的宽度。嵌套执行需要 Pi 0.99.0 及以后;这是功能要求,不代表每个旧版都经过测试。
80
86
 
81
87
  工具渲染使用 Pi 的公开扩展 API。活动工具状态通过 Pi 导出的交互组件跟随其内置执行状态变化;clean 模式的 thought 详情使用活动时间线自身的展开状态,full 和 compact 模式则保留 Pi 内置的 Thinking 可见性控制。由于 Pi 目前没有为这些展示细节提供公开渲染钩子,自适应的原生用户消息气泡、原生输入编辑器圆角、无序列表标记和围栏代码块增强需要使用可安全重载的运行时补丁。Markdown 增强仅在渲染主 transcript 中的用户消息和助手回复时启用;扩展 overlay 创建的 Markdown 保持 Pi 原生布局。Markdown 解析、语法高亮和终端语义区域仍由 Pi 处理。
82
88
 
@@ -27,6 +27,7 @@ import {
27
27
  type TuiMouseEvent,
28
28
  visibleWidth,
29
29
  wrapTextWithAnsi,
30
+ getOsc8LinkAtColumn,
30
31
  } from "@earendil-works/pi-tui";
31
32
  import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
32
33
  import { join } from "node:path";
@@ -96,6 +97,7 @@ export default function prettyTui(pi: ExtensionAPI) {
96
97
  let cleanToolsExpanded = false;
97
98
  let cleanContextCompacted = false;
98
99
  let fullscreenTui = false;
100
+ const mouseClickHitTests = new WeakMap<object, (event: any) => boolean>();
99
101
  let currentTui: any;
100
102
  let currentExtensionUi: any;
101
103
  let changingAllToolsExpansion = false;
@@ -193,6 +195,7 @@ export default function prettyTui(pi: ExtensionAPI) {
193
195
  };
194
196
  const responseAnswerTexts = new Map<string, string>();
195
197
  let responseRunStartedAt: number | undefined;
198
+ const RUNNING_DOT_INTERVAL_MS = 800;
196
199
  let workingElapsedTimer: ReturnType<typeof setInterval> | undefined;
197
200
  const stopWorkingElapsedTimer = () => {
198
201
  if (workingElapsedTimer) clearInterval(workingElapsedTimer);
@@ -200,7 +203,8 @@ export default function prettyTui(pi: ExtensionAPI) {
200
203
  };
201
204
  const startWorkingElapsedTimer = () => {
202
205
  if (workingElapsedTimer) return;
203
- workingElapsedTimer = setInterval(() => currentTui?.requestRender?.(), 1000);
206
+ // Share one redraw clock between the elapsed label and Running-dot pulse.
207
+ workingElapsedTimer = setInterval(() => currentTui?.requestRender?.(), RUNNING_DOT_INTERVAL_MS);
204
208
  workingElapsedTimer.unref?.();
205
209
  };
206
210
  let responseHasAssistantMessage = false;
@@ -332,7 +336,7 @@ export default function prettyTui(pi: ExtensionAPI) {
332
336
  if (color === "error") return `\x1b[31m${text}\x1b[39m`;
333
337
  if (color === "success") return `\x1b[32m${text}\x1b[39m`;
334
338
  if (color === "syntaxComment") return markdownTheme.codeBlock(text);
335
- if (color === "thinkingLow") return markdownTheme.link(text);
339
+ if (color === "thinkingLow" || color === "mdLink") return markdownTheme.link(text);
336
340
  if (color === "dim" || color === "muted" || color === "thinkingText") {
337
341
  return markdownTheme.quote(text);
338
342
  }
@@ -888,8 +892,9 @@ export default function prettyTui(pi: ExtensionAPI) {
888
892
  };
889
893
  };
890
894
  const border = (text: string) => currentExtensionUi?.theme?.fg
891
- ? currentExtensionUi.theme.fg("accent", text)
892
- : markdownTheme.quoteBorder(text);
895
+ ? currentExtensionUi.theme.fg("mdLink", text)
896
+ : markdownTheme.link(text);
897
+ const userText = typeof this.text === "string" ? this.text : "";
893
898
  const frame: Component = {
894
899
  render(width: number): string[] {
895
900
  const measured = layout(width);
@@ -908,37 +913,51 @@ export default function prettyTui(pi: ExtensionAPI) {
908
913
  return [top, ...body, bottom].map((line: string) => left + line + right);
909
914
  },
910
915
  handleMouse(event: any) {
911
- if (!markdown.handleMouse) return undefined;
912
916
  const measured = layout(event.width);
913
- if (!measured.framed) {
914
- return withTranscriptMarkdown(() => markdown.handleMouse({
917
+ const height = measured.body.length + (measured.framed ? 2 : 0);
918
+ if (
919
+ event.x < measured.leftPad ||
920
+ event.x >= measured.leftPad + measured.frameWidth ||
921
+ event.y < 0 || event.y >= height
922
+ ) return undefined;
923
+
924
+ // Preserve code-block Copy controls before the enclosing bubble action.
925
+ const contentX = measured.leftPad + (measured.framed ? 2 : 0);
926
+ const contentY = measured.framed ? 1 : 0;
927
+ let result;
928
+ if (
929
+ markdown.handleMouse &&
930
+ event.x >= contentX && event.x < contentX + measured.contentWidth &&
931
+ event.y >= contentY && event.y < contentY + measured.body.length
932
+ ) {
933
+ result = withTranscriptMarkdown(() => markdown.handleMouse({
915
934
  ...event,
916
- x: event.x - measured.leftPad,
935
+ x: event.x - contentX,
936
+ y: event.y - contentY,
917
937
  width: measured.contentWidth,
938
+ height: measured.body.length,
918
939
  }));
940
+ if (result?.handled) return result;
919
941
  }
920
- const contentX = measured.leftPad + 2;
921
- if (
922
- event.y <= 0 ||
923
- event.y > measured.body.length ||
924
- event.x < contentX ||
925
- event.x >= contentX + measured.contentWidth
926
- ) {
927
- return undefined;
942
+ if (fullscreenTui && event.type === "click" && event.button === "left" && userText.trim()) {
943
+ copyTranscriptText(userText);
944
+ return { handled: true };
928
945
  }
929
- return withTranscriptMarkdown(() => markdown.handleMouse({
930
- ...event,
931
- x: event.x - contentX,
932
- y: event.y - 1,
933
- width: measured.contentWidth,
934
- height: measured.body.length,
935
- }));
946
+ return result;
936
947
  },
937
948
  invalidate() {
938
949
  markdown.invalidate?.();
939
950
  },
940
951
  };
941
952
 
953
+ const bubbleClickHitTest = (event: any) => {
954
+ if (!fullscreenTui || !userText.trim()) return false;
955
+ const measured = layout(event.width);
956
+ return event.x >= measured.leftPad && event.x < measured.leftPad + measured.frameWidth &&
957
+ event.y >= 0 && event.y < measured.body.length + (measured.framed ? 2 : 0);
958
+ };
959
+ mouseClickHitTests.set(frame, bubbleClickHitTest);
960
+ mouseClickHitTests.set(this, bubbleClickHitTest);
942
961
  this.clear();
943
962
  this.addChild(frame);
944
963
  };
@@ -1150,7 +1169,7 @@ export default function prettyTui(pi: ExtensionAPI) {
1150
1169
  text,
1151
1170
  theme,
1152
1171
  component: new Markdown(text, 0, 0, owner.markdownTheme, {
1153
- color: (line: string) => theme.fg("thinkingText", line),
1172
+ color: (line: string) => theme.fg("muted", line),
1154
1173
  italic: true,
1155
1174
  }),
1156
1175
  };
@@ -1235,11 +1254,15 @@ export default function prettyTui(pi: ExtensionAPI) {
1235
1254
  const terminalLines = terminalMember && visibleLines.length === 0
1236
1255
  ? renderPendingActivityUpdate(terminalMember, width)
1237
1256
  : [];
1238
- const appendTail = (activityLines: string[]) => [
1239
- ...activityLines,
1240
- ...terminalLines,
1241
- ...visibleLines,
1242
- ];
1257
+ const appendTail = (activityLines: string[]) => {
1258
+ mouseClickHitTests.set(this, (event) => renderMode === "clean" &&
1259
+ event.y >= (position.first ? 1 : 0) && event.y < activityLines.length);
1260
+ return [
1261
+ ...activityLines,
1262
+ ...terminalLines,
1263
+ ...visibleLines,
1264
+ ];
1265
+ };
1243
1266
  const revealed = activityGroupRevealed(group);
1244
1267
  if (!revealed) {
1245
1268
  const activityLines = position.first
@@ -1282,8 +1305,8 @@ export default function prettyTui(pi: ExtensionAPI) {
1282
1305
  }
1283
1306
  const stateLabel = this.isStreaming ? "thinking" : "thought";
1284
1307
  const label = truncateToWidth(stateLabel, Math.max(1, childWidth - 2), "…");
1285
- const header = groupTheme.fg("thinkingLow", "● ") +
1286
- groupTheme.fg("toolTitle", groupTheme.bold(label));
1308
+ const header = groupTheme.fg("mdLink", "● ") +
1309
+ groupTheme.fg("text", groupTheme.bold(label));
1287
1310
  let contentLines: string[] = [header];
1288
1311
  if (expanded) {
1289
1312
  contentLines.push(...thinkingDetailLines(
@@ -1486,6 +1509,7 @@ export default function prettyTui(pi: ExtensionAPI) {
1486
1509
  const toolsExpansionPatchKey = Symbol.for("pretty-tui.clean-tool-expansion");
1487
1510
  if (!interactiveModePrototype[toolsExpansionPatchKey]) {
1488
1511
  const originalSetToolsExpanded = interactiveModePrototype.setToolsExpanded;
1512
+ const originalToggleToolOutputExpansion = interactiveModePrototype.toggleToolOutputExpansion;
1489
1513
  const originalRenderSessionEntries = interactiveModePrototype.renderSessionEntries;
1490
1514
  const originalSwitchTuiMode = interactiveModePrototype.switchTuiMode;
1491
1515
  const originalShowExtensionNotify = interactiveModePrototype.showExtensionNotify;
@@ -1504,8 +1528,17 @@ export default function prettyTui(pi: ExtensionAPI) {
1504
1528
  // carry no `this`, so deferred notices need this handle to mount.
1505
1529
  const cacheNoticeHost: { current?: any } = {};
1506
1530
  const cacheNoticeOwners = new WeakMap<object, any>();
1531
+ const patchedToggleToolOutputExpansion = function (this: any) {
1532
+ if (renderMode !== "clean") {
1533
+ return originalToggleToolOutputExpansion.call(this);
1534
+ }
1535
+ this.showStatus(
1536
+ "Activity details expand individually in clean mode\nClick a group, tool, thought, or section to expand/collapse it.",
1537
+ );
1538
+ };
1507
1539
  const patchedSetToolsExpanded = function (this: any, expanded: boolean) {
1508
1540
  cleanToolsExpanded = expanded;
1541
+ nestedTools.clearExpansion();
1509
1542
  collapsedActivityGroups.clear();
1510
1543
  changingAllToolsExpansion = true;
1511
1544
  if (!expanded) {
@@ -1596,9 +1629,9 @@ export default function prettyTui(pi: ExtensionAPI) {
1596
1629
  }
1597
1630
  // Do not change Pi's persisted hideThinkingBlock setting in clean mode.
1598
1631
  // Thought details use the activity hierarchy instead: click one thought,
1599
- // or use Ctrl+O when every member should expand together.
1632
+ // Keyboard visibility toggles only explain these local controls.
1600
1633
  this.showStatus(
1601
- "Thought details expand individually in clean mode\nClick a thought, or use Ctrl+O to expand all.",
1634
+ "Thought details expand individually in clean mode\nClick a thought to expand/collapse its details.",
1602
1635
  );
1603
1636
  };
1604
1637
 
@@ -1785,6 +1818,8 @@ export default function prettyTui(pi: ExtensionAPI) {
1785
1818
  interactiveModePrototype[toolsExpansionPatchKey] = {
1786
1819
  originalSetToolsExpanded,
1787
1820
  patchedSetToolsExpanded,
1821
+ originalToggleToolOutputExpansion,
1822
+ patchedToggleToolOutputExpansion,
1788
1823
  originalRenderSessionEntries,
1789
1824
  patchedRenderSessionEntries,
1790
1825
  originalSwitchTuiMode,
@@ -1807,6 +1842,7 @@ export default function prettyTui(pi: ExtensionAPI) {
1807
1842
  patchedAddMessageToChat,
1808
1843
  };
1809
1844
  interactiveModePrototype.setToolsExpanded = patchedSetToolsExpanded;
1845
+ interactiveModePrototype.toggleToolOutputExpansion = patchedToggleToolOutputExpansion;
1810
1846
  interactiveModePrototype.renderSessionEntries = patchedRenderSessionEntries;
1811
1847
  interactiveModePrototype.switchTuiMode = patchedSwitchTuiMode;
1812
1848
  interactiveModePrototype.showExtensionNotify = patchedShowExtensionNotify;
@@ -1831,6 +1867,9 @@ export default function prettyTui(pi: ExtensionAPI) {
1831
1867
  currentExtensionUi = undefined;
1832
1868
  const patch = interactiveModePrototype[toolsExpansionPatchKey];
1833
1869
  if (!patch) return;
1870
+ if (patch.patchedToggleToolOutputExpansion === interactiveModePrototype.toggleToolOutputExpansion) {
1871
+ interactiveModePrototype.toggleToolOutputExpansion = patch.originalToggleToolOutputExpansion;
1872
+ }
1834
1873
  if (patch.patchedSetToolsExpanded === interactiveModePrototype.setToolsExpanded) {
1835
1874
  interactiveModePrototype.setToolsExpanded = patch.originalSetToolsExpanded;
1836
1875
  }
@@ -1866,6 +1905,7 @@ export default function prettyTui(pi: ExtensionAPI) {
1866
1905
  }
1867
1906
  if (
1868
1907
  interactiveModePrototype.setToolsExpanded === patch.originalSetToolsExpanded &&
1908
+ interactiveModePrototype.toggleToolOutputExpansion === patch.originalToggleToolOutputExpansion &&
1869
1909
  interactiveModePrototype.renderSessionEntries === patch.originalRenderSessionEntries &&
1870
1910
  interactiveModePrototype.switchTuiMode === patch.originalSwitchTuiMode &&
1871
1911
  interactiveModePrototype.showExtensionNotify === patch.originalShowExtensionNotify &&
@@ -1882,24 +1922,70 @@ export default function prettyTui(pi: ExtensionAPI) {
1882
1922
  });
1883
1923
  }
1884
1924
 
1885
- // Fullscreen selection only emits a component click when press and release
1886
- // land on the exact same cell. Give clean group rows a tiny horizontal
1887
- // tolerance so an ordinary click does not turn into an accidental selection.
1925
+ // Allow same-row horizontal jitter only on our interactive regions. Keep
1926
+ // real drags, links, ordinary transcript selection, and multi-click rules native.
1888
1927
  const altScreenPrototype = TuiAltScreen.prototype as any;
1889
1928
  const cleanSummaryClickPatchKey = Symbol.for("pretty-tui.clean-summary-click");
1890
1929
  const cleanSummaryPressKey = Symbol("pretty-tui.clean-summary-press");
1930
+ const cleanControlPressKey = Symbol("pretty-tui.control-press");
1891
1931
  if (!altScreenPrototype[cleanSummaryClickPatchKey]) {
1892
1932
  const originalHandleSelectionMouseEvent = altScreenPrototype.handleSelectionMouseEvent;
1933
+ const originalHandleMouseEvent = altScreenPrototype.handleMouseEvent;
1893
1934
  const summaryAtPoint = (screen: any, x: number, y: number): boolean => {
1894
1935
  const line = stripTerminalSequences(screen.previousScreen?.[y] ?? "");
1895
1936
  const match = /●\s+(?:Done|Running)\([^)]*\)/.exec(line);
1896
- return Boolean(match && x >= match.index && x < match.index + match[0].length);
1937
+ if (match) {
1938
+ const start = visibleWidth(line.slice(0, match.index));
1939
+ if (x >= start && x < start + visibleWidth(match[0])) return true;
1940
+ }
1941
+ const collapse = line.indexOf(collapseLabel);
1942
+ const start = visibleWidth(line.slice(0, collapse));
1943
+ return renderMode === "clean" && collapse >= 0 && x >= start && x < start + visibleWidth(collapseLabel);
1944
+ };
1945
+ const interactiveAtPoint = (screen: any, x: number, y: number): boolean => {
1946
+ if (screen.hasOverlay?.()) return false;
1947
+ if (getOsc8LinkAtColumn(screen.previousScreen?.[y] ?? "", x)) return false;
1948
+ const visit = (box: any): boolean => {
1949
+ if (!box?.rect || !box?.clip || x < box.clip.x || y < box.clip.y ||
1950
+ x >= box.clip.x + box.clip.width || y >= box.clip.y + box.clip.height) return false;
1951
+ if ((box.children ?? []).some(visit)) return true;
1952
+ const hitTest = mouseClickHitTests.get(box.component);
1953
+ return Boolean(hitTest?.({
1954
+ x: x - box.rect.x, y: y - box.rect.y,
1955
+ width: box.rect.width, height: box.rect.height,
1956
+ }));
1957
+ };
1958
+ return visit(screen.currentLayout?.root) || summaryAtPoint(screen, x, y);
1959
+ };
1960
+ const withinTolerance = (press: any, event: any): boolean =>
1961
+ event.y === press.y && Math.abs(event.x - press.x) <= 2;
1962
+ const isUnmodifiedLeftPress = (event: any): boolean =>
1963
+ !event.release && (event.button & (32 | 64 | 4 | 8 | 16)) === 0 && (event.button & 3) === 0;
1964
+ // Copy controls can consume press, bypassing the selection handler entirely.
1965
+ const patchedHandleMouseEvent = function (this: any, event: any) {
1966
+ if (isUnmodifiedLeftPress(event)) {
1967
+ if (interactiveAtPoint(this, event.x, event.y)) this[cleanControlPressKey] = { x: event.x, y: event.y };
1968
+ else delete this[cleanControlPressKey];
1969
+ } else {
1970
+ const press = this[cleanControlPressKey];
1971
+ if (press && this.mousePressTarget && !this.mouseCapture) {
1972
+ if ((event.button & 32) !== 0 && withinTolerance(press, event)) return;
1973
+ if (event.release) {
1974
+ delete this[cleanControlPressKey];
1975
+ if (withinTolerance(press, event)) {
1976
+ return originalHandleMouseEvent.call(this, { ...event, x: press.x });
1977
+ }
1978
+ } else delete this[cleanControlPressKey];
1979
+ }
1980
+ if (event.release || (event.button & 64) !== 0) delete this[cleanControlPressKey];
1981
+ }
1982
+ return originalHandleMouseEvent.call(this, event);
1897
1983
  };
1898
1984
  const patchedHandleSelectionMouseEvent = function (this: any, event: any) {
1899
1985
  const isMotion = (event.button & 32) !== 0;
1900
- const isLeftPress = !event.release && !isMotion && (event.button & 3) === 0;
1986
+ const isLeftPress = isUnmodifiedLeftPress(event);
1901
1987
  if (isLeftPress) {
1902
- if (summaryAtPoint(this, event.x, event.y)) {
1988
+ if (interactiveAtPoint(this, event.x, event.y)) {
1903
1989
  this[cleanSummaryPressKey] = { x: event.x, y: event.y };
1904
1990
  } else {
1905
1991
  delete this[cleanSummaryPressKey];
@@ -1909,8 +1995,7 @@ export default function prettyTui(pi: ExtensionAPI) {
1909
1995
 
1910
1996
  const press = this[cleanSummaryPressKey];
1911
1997
  if (press) {
1912
- const withinClickTolerance =
1913
- event.y === press.y && Math.abs(event.x - press.x) <= 2;
1998
+ const withinClickTolerance = withinTolerance(press, event);
1914
1999
  if (isMotion && withinClickTolerance) {
1915
2000
  return;
1916
2001
  }
@@ -1929,17 +2014,24 @@ export default function prettyTui(pi: ExtensionAPI) {
1929
2014
  altScreenPrototype[cleanSummaryClickPatchKey] = {
1930
2015
  originalHandleSelectionMouseEvent,
1931
2016
  patchedHandleSelectionMouseEvent,
2017
+ originalHandleMouseEvent,
2018
+ patchedHandleMouseEvent,
1932
2019
  };
1933
2020
  altScreenPrototype.handleSelectionMouseEvent = patchedHandleSelectionMouseEvent;
2021
+ altScreenPrototype.handleMouseEvent = patchedHandleMouseEvent;
1934
2022
 
1935
2023
  pi.on("session_shutdown", () => {
1936
2024
  const patch = altScreenPrototype[cleanSummaryClickPatchKey];
2025
+ if (patch?.patchedHandleMouseEvent === altScreenPrototype.handleMouseEvent) {
2026
+ altScreenPrototype.handleMouseEvent = patch.originalHandleMouseEvent;
2027
+ }
1937
2028
  if (patch?.patchedHandleSelectionMouseEvent === altScreenPrototype.handleSelectionMouseEvent) {
1938
2029
  altScreenPrototype.handleSelectionMouseEvent = patch.originalHandleSelectionMouseEvent;
1939
2030
  }
1940
2031
  if (
1941
2032
  patch &&
1942
- altScreenPrototype.handleSelectionMouseEvent === patch.originalHandleSelectionMouseEvent
2033
+ altScreenPrototype.handleSelectionMouseEvent === patch.originalHandleSelectionMouseEvent &&
2034
+ altScreenPrototype.handleMouseEvent === patch.originalHandleMouseEvent
1943
2035
  ) {
1944
2036
  delete altScreenPrototype[cleanSummaryClickPatchKey];
1945
2037
  }
@@ -1968,6 +2060,10 @@ export default function prettyTui(pi: ExtensionAPI) {
1968
2060
 
1969
2061
  const patchedRender = function (this: any, width: number): string[] {
1970
2062
  const scoped = transcriptMarkdownActive();
2063
+ mouseClickHitTests.set(this, (event) => fullscreenTui &&
2064
+ this[transcriptMarkdownStateKey] === true &&
2065
+ (this[codeBlockRegionsKey] ?? []).some((region: any) =>
2066
+ event.y === region.y && event.x >= region.xStart && event.x < region.xEnd));
1971
2067
  if (this[transcriptMarkdownStateKey] !== scoped) {
1972
2068
  delete this[codeBlockCollectionKey];
1973
2069
  delete this[codeBlockRegionsKey];
@@ -2336,9 +2432,9 @@ export default function prettyTui(pi: ExtensionAPI) {
2336
2432
  },
2337
2433
  continuation: " ",
2338
2434
  content:
2339
- theme.fg("accent", theme.bold(name)) +
2435
+ theme.fg("text", theme.bold(name)) +
2340
2436
  theme.fg("dim", "(") +
2341
- theme.fg("text", detail) +
2437
+ theme.fg("muted", detail) +
2342
2438
  theme.fg("dim", ")"),
2343
2439
  });
2344
2440
 
@@ -2604,9 +2700,9 @@ export default function prettyTui(pi: ExtensionAPI) {
2604
2700
  ? "error"
2605
2701
  : component.result && !component.isPartial
2606
2702
  ? "success"
2607
- : "accent";
2703
+ : "dim";
2608
2704
  const title = theme.fg(dotColor, "● ") +
2609
- theme.fg("accent", theme.bold(label)) +
2705
+ theme.fg("text", theme.bold(label)) +
2610
2706
  (args ? theme.fg("muted", `(${args})`) : "");
2611
2707
  const result = thirdPartyResultSummary(component);
2612
2708
  const resultColor = component.result?.isError ? "error" : "muted";
@@ -2775,10 +2871,27 @@ export default function prettyTui(pi: ExtensionAPI) {
2775
2871
  const group = activityTimeline.groupForMember(member.id);
2776
2872
  if (renderMode !== "clean" || !group) return originalToolRender.call(this, width);
2777
2873
  const position = activityMemberPosition(group, member);
2874
+ let renderedHeight = 0;
2875
+ let nestedClickActions: Map<number, string> | undefined;
2876
+ const renderedSummaryHeight = position.first ? renderActivityGroupSummary(group, width).length : 0;
2877
+ mouseClickHitTests.set(this, (event) => {
2878
+ if (renderMode !== "clean") return false;
2879
+ if (event.width !== width) return false;
2880
+ const summaryHeight = renderedSummaryHeight;
2881
+ if (position.first && event.y > 0 && event.y <= summaryHeight) return true;
2882
+ if (!activityGroupRevealed(group)) return false;
2883
+ const height = renderedHeight;
2884
+ if (position.last && event.y === height - 1) {
2885
+ return activityCollapseClicked(group, member, { ...event, type: "click", button: "left" }, height - 1);
2886
+ }
2887
+ const contentY = event.y - (position.first ? summaryHeight + 1 : 0);
2888
+ if (nestedClickActions) return nestedClickActions.has(contentY);
2889
+ return contentY >= 0 && event.y < height - (position.last ? 1 : 0);
2890
+ });
2778
2891
  if (!activityGroupRevealed(group)) {
2779
- return position.first
2780
- ? ["", ...renderActivityGroupSummary(group, width, true)]
2781
- : [];
2892
+ const lines = position.first ? ["", ...renderActivityGroupSummary(group, width, true)] : [];
2893
+ renderedHeight = lines.length;
2894
+ return lines;
2782
2895
  }
2783
2896
 
2784
2897
  const childTheme = cleanThemeForToolCall(this.toolCallId) ?? activityGroupTheme(group);
@@ -2810,7 +2923,9 @@ export default function prettyTui(pi: ExtensionAPI) {
2810
2923
  } else {
2811
2924
  let contentLines: string[];
2812
2925
  if (nestedTools.count(this.toolCallId) > 0) {
2813
- contentLines = nestedTools.render(this, childWidth, childTheme).lines;
2926
+ const projection = nestedTools.render(this, childWidth, childTheme);
2927
+ contentLines = projection.lines;
2928
+ nestedClickActions = projection.actions;
2814
2929
  } else if (thirdParty) {
2815
2930
  const summaryLines = renderThirdPartyCompact(this, childWidth, childTheme);
2816
2931
  if (this.expanded) {
@@ -2859,10 +2974,12 @@ export default function prettyTui(pi: ExtensionAPI) {
2859
2974
  };
2860
2975
  }
2861
2976
  }
2862
- return withActivityCollapse(
2977
+ const lines = withActivityCollapse(
2863
2978
  group, member, width,
2864
2979
  position.first ? ["", ...renderActivityGroupSummary(group, width), ...decoratedContent] : decoratedContent,
2865
2980
  );
2981
+ renderedHeight = lines.length;
2982
+ return lines;
2866
2983
  };
2867
2984
  const patchedToolHandleMouse = function (this: any, event: any) {
2868
2985
  const member = activityTimeline.memberForTool(this.toolCallId);
@@ -2902,13 +3019,11 @@ export default function prettyTui(pi: ExtensionAPI) {
2902
3019
  const contentY = event.y - (position.first ? summaryHeight + 1 : 0);
2903
3020
  const action = projection.actions.get(contentY);
2904
3021
  if (action) {
2905
- nestedTools.toggle(action);
3022
+ nestedTools.toggle(action, Boolean(this.expanded));
2906
3023
  this.updateDisplay?.();
2907
3024
  this.ui?.requestRender?.();
2908
- } else if (contentY === 0) {
2909
- originalSetExpanded.call(this, !this.expanded);
2910
- this.ui?.requestRender?.();
2911
3025
  }
3026
+ // The parent title is informational; only disclosure rows act on clicks.
2912
3027
  // Nested results are UI projections, not native renderer rows.
2913
3028
  return { handled: true };
2914
3029
  }
@@ -3072,9 +3187,11 @@ export default function prettyTui(pi: ExtensionAPI) {
3072
3187
  ): DisplayRow => ({
3073
3188
  prefix: () => {
3074
3189
  const currentActivity = typeof activity === "function" ? activity() : activity;
3190
+ const dimPhase = responseRunStartedAt !== undefined &&
3191
+ Math.floor(Math.max(0, Date.now() - responseRunStartedAt) / RUNNING_DOT_INTERVAL_MS) % 2 === 1;
3075
3192
  const color = currentActivity === "done"
3076
3193
  ? collapsedDone ? "thinkingText" : "success"
3077
- : "accent";
3194
+ : dimPhase ? "dim" : "accent";
3078
3195
  return theme.fg(color, "● ");
3079
3196
  },
3080
3197
  continuation: " ",
@@ -3276,6 +3393,8 @@ export default function prettyTui(pi: ExtensionAPI) {
3276
3393
  return {
3277
3394
  render(width: number): string[] {
3278
3395
  const data = entry.data;
3396
+ mouseClickHitTests.set(this, (event) => fullscreenTui && copyStart >= 0 &&
3397
+ event.y === 0 && event.x >= copyStart && event.x < copyStart + copyWidth);
3279
3398
  if (!data || width <= 0) return [];
3280
3399
  copyStart = -1;
3281
3400
  copyWidth = 0;
@@ -53,9 +53,16 @@ const compactArgs = (value: string): string => {
53
53
  export class NestedTools {
54
54
  private calls = new Map<string, NestedCall>();
55
55
  private incomplete = new Set<string>();
56
- private expanded = new Set<string>();
57
- clear() { this.calls.clear(); this.incomplete.clear(); this.expanded.clear(); }
58
- toggle(key: string) { this.expanded.has(key) ? this.expanded.delete(key) : this.expanded.add(key); }
56
+ // Local overrides can close one disclosure even after global expansion.
57
+ private expanded = new Map<string, boolean>();
58
+ clearExpansion() { this.expanded.clear(); }
59
+ clear() { this.calls.clear(); this.incomplete.clear(); this.clearExpansion(); }
60
+ toggle(key: string, globallyExpanded = false) {
61
+ this.expanded.set(key, !(this.expanded.get(key) ?? globallyExpanded));
62
+ }
63
+ private isExpanded(key: string, globallyExpanded: boolean): boolean {
64
+ return this.expanded.get(key) ?? globallyExpanded;
65
+ }
59
66
  root(id: string): string {
60
67
  const seen = new Set<string>();
61
68
  while (this.calls.has(id) && !seen.has(id)) {
@@ -184,9 +191,9 @@ export class NestedTools {
184
191
  const actions = new Map<number, string>();
185
192
  const count = this.count(rootId);
186
193
  const failed = [...this.calls.values()].filter((call) => this.root(call.id) === rootId && call.status === "error").length;
187
- const color = owner.result?.isError ? "error" : owner.result && !owner.isPartial ? "success" : "accent";
194
+ const color = owner.result?.isError ? "error" : owner.result && !owner.isPartial ? "success" : "dim";
188
195
  const label = owner.toolDefinition?.label ?? owner.toolName;
189
- const lines = [theme.fg(color, "● ") + theme.fg("accent", theme.bold(label)) +
196
+ const lines = [theme.fg(color, "● ") + theme.fg("text", theme.bold(label)) +
190
197
  theme.fg("muted", `(${count} nested ${count === 1 ? "call" : "calls"}${failed ? ` · ${failed} failed` : ""})`)];
191
198
  const detail = (text: string, prefix: string, action?: string) => {
192
199
  const push = (line: string) => {
@@ -207,15 +214,15 @@ export class NestedTools {
207
214
  const visit = (call: NestedCall, indent: string, last: boolean, depth: number) => {
208
215
  const prefix = indent + (last ? "└─ " : "├─ ");
209
216
  const continuation = indent + (last ? " " : "│ ");
210
- const icon = call.status === "running" ? "…" : call.status === "cancelled" ? "⊘" : "●";
211
- const callColor = call.status === "ok" ? "success" : call.status === "error" ? "error" : call.status === "running" ? "accent" : "muted";
217
+ const icon = call.status === "cancelled" ? "⊘" : "●";
218
+ const callColor = call.status === "ok" ? "success" : call.status === "error" ? "error" : call.status === "running" ? "dim" : "muted";
212
219
  actions.set(lines.length, call.id);
213
220
  const duration = call.durationMs === undefined ? "" : ` · ${call.durationMs < 1000 ? `${Math.round(call.durationMs)}ms` : `${(call.durationMs / 1000).toFixed(1)}s`}`;
214
- lines.push(theme.fg("dim", prefix) + theme.fg(callColor, icon + " ") + theme.fg("accent", theme.bold(call.name)) + theme.fg("muted", `(${compactArgs(call.args)})${duration}`));
215
- const expanded = owner.expanded || this.expanded.has(call.id);
221
+ const descendants = this.children(call.id);
222
+ lines.push(theme.fg("dim", prefix) + theme.fg(callColor, icon + " ") + theme.fg("text", theme.bold(call.name)) + theme.fg("muted", `(${compactArgs(call.args)})${duration}`));
223
+ const expanded = this.isExpanded(call.id, Boolean(owner.expanded));
216
224
  const first = call.output?.split("\n").find((line) => line.trim());
217
225
  const summary = first ?? (call.status === "running" ? "Running…" : call.truncated ? "Output omitted by UI size limit" : call.output === undefined ? "Only call metadata retained" : "No text output");
218
- const descendants = this.children(call.id);
219
226
  actions.set(lines.length, call.id);
220
227
  lines.push(theme.fg("dim", continuation + (descendants.length ? "├ " : "└ ")) + theme.fg(call.status === "error" ? "error" : "muted", summary));
221
228
  if (expanded) {
@@ -231,13 +238,13 @@ export class NestedTools {
231
238
  if (code) {
232
239
  const key = `${rootId}:script`;
233
240
  actions.set(lines.length, key); lines.push(theme.fg("dim", " ├─ ") + theme.fg("mdLink", "[Script]"));
234
- if (owner.expanded || this.expanded.has(key)) detail(code, " │ ", key);
241
+ if (this.isExpanded(key, Boolean(owner.expanded))) detail(code, " │ ", key);
235
242
  }
236
243
  items.forEach((call) => visit(call, " ", false, 0));
237
244
  const key = `${rootId}:output`;
238
245
  actions.set(lines.length, key);
239
246
  lines.push(theme.fg("dim", " └─ ") + theme.fg("mdLink", code ? "[Script output]" : "[Output]"));
240
- if (owner.expanded || this.expanded.has(key)) detail(resultText(owner.result) || (owner.isPartial || !owner.result ? "Running…" : "No text output"), " ", key);
247
+ if (this.isExpanded(key, Boolean(owner.expanded))) detail(resultText(owner.result) || (owner.isPartial || !owner.result ? "Running…" : "No text output"), " ", key);
241
248
  if (this.incomplete.has(rootId)) lines.push(theme.fg("warning", " [Nested call record is incomplete or truncated]"));
242
249
  return { lines: lines.map((line) => truncateToWidth(line, Math.max(1, width), "…")), actions };
243
250
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-pretty-tui",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
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>",
@@ -39,8 +39,8 @@
39
39
  "@earendil-works/pi-tui": "*"
40
40
  },
41
41
  "devDependencies": {
42
- "@earendil-works/pi-coding-agent": "1.0.0",
43
- "@earendil-works/pi-tui": "1.0.0",
42
+ "@earendil-works/pi-coding-agent": "1.0.1",
43
+ "@earendil-works/pi-tui": "1.0.1",
44
44
  "@types/node": "^24.0.0",
45
45
  "jiti": "^2.7.0",
46
46
  "typescript": "^5.9.0"