pi-cc-extensions 1.0.7 → 1.0.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.en.md CHANGED
@@ -98,6 +98,8 @@ Renderer snapshots for `on` / `compact` modes: [default](./docs/tool-render-exam
98
98
 
99
99
  > [!TIP]
100
100
  > **Fullscreen**: click `click to show more` to expand tool cards, thinking, Skill, and compact summaries. An expanded diff always shows every line; when expanded Input/Output exceeds the line cap, the footer `… +N more lines · click to show more` opens a full preview. Click to collapse.
101
+ >
102
+ > Both `scrollButtonMode` values show the same `Back to bottom` / `N new message(s)` text: `dock` draws it in a dedicated row, `native` in Pi’s floating overlay.
101
103
 
102
104
  > [!NOTE]
103
105
  > **Mermaid rendering**: set `markdown.mermaid` to `final` via `~/.pi/agent/settings.json` or the Mermaid diagrams option in `/settings`. Default `streaming` redraws per frame; `final` renders once at completion.
@@ -116,10 +118,11 @@ pi -e . # one run, does not edit settings.json
116
118
 
117
119
  ## Recommended companions
118
120
 
119
- | Extension | Purpose |
120
- | ------------------------ | ----------------------------------------------------------- |
121
- | `npm:pi-web-access` | Web search, URL fetching, GitHub cloning, PDF/video parsing |
122
- | `npm:@narumitw/pi-usage` | Current-account usage for Codex / Copilot / OpenRouter |
121
+ | Extension | Purpose |
122
+ | ---------------------------------------- | ----------------------------------------------------------- |
123
+ | `npm:pi-web-access` | Web search, URL fetching, GitHub cloning, PDF/video parsing |
124
+ | `npm:@narumitw/pi-usage` | Current-account usage for Codex / Copilot / OpenRouter |
125
+ | `npm:@juicesharp/rpiv-ask-user-question` | Multiple-choice questionnaire the model can ask you |
123
126
 
124
127
  ## Credits
125
128
 
package/README.md CHANGED
@@ -98,6 +98,8 @@ pi install git:github.com/minuque/pi-cc-extensions
98
98
 
99
99
  > [!TIP]
100
100
  > **全屏模式**:单击 `click to show more` 展开工具卡、思考、Skill 和 compact 摘要;工具卡展开态 diff 全量显示,Input/Output 超行时末行 `… +N more lines · click to show more` 打开全量预览,单击收起。
101
+ >
102
+ > `scrollButtonMode` 两种模式文案相同(`Back to bottom` / `N new message(s)`):`dock` 画在独占行,`native` 画在 Pi 原生浮层。
101
103
 
102
104
  > [!NOTE]
103
105
  > **Mermaid 渲染**:建议把 `markdown.mermaid` 设为 `final`(`~/.pi/agent/settings.json` 或 `/settings` 面板的 Mermaid diagrams 选项)。默认 `streaming` 逐帧重绘,`final` 渲染最终版更稳定。
@@ -120,6 +122,7 @@ pi -e . # 只跑一次,不改 settings.json
120
122
  | ---------------------------------------- | ------------------------------------------------ |
121
123
  | `npm:pi-web-access` | 网页搜索、URL 抓取、GitHub 克隆、PDF/视频解析 |
122
124
  | `npm:@narumitw/pi-usage` | 查看当前账号用量(Codex / Copilot / OpenRouter) |
125
+ | `npm:@juicesharp/rpiv-ask-user-question` | 模型拿不准时向你提问的选择题面板 |
123
126
 
124
127
  ## 致谢
125
128
 
@@ -66,7 +66,7 @@ export type Config = {
66
66
  showStartupHeader: boolean;
67
67
  /** fullscreen:userMessage 正文首行滚出视口上沿后钉住,直到下一条指令接手。 */
68
68
  stickyUserMessage: boolean;
69
- /** fullscreen 回到底部按钮:扩展 dock 行,或 Pi 原生浮层。 */
69
+ /** fullscreen 回到底部按钮:扩展 dock 行,或 Pi 原生浮层;两者文案相同。 */
70
70
  scrollButtonMode: ScrollButtonMode;
71
71
  enableSessionReference: boolean;
72
72
  enableSubagentAutocomplete: boolean;
@@ -604,11 +604,11 @@ export async function showCcstylePanel(
604
604
  };
605
605
  const scrollButtonSetting = {
606
606
  id: "scrollButtonMode",
607
- label: "Scroll to bottom",
607
+ label: "Scroll button mode",
608
608
  description:
609
609
  config.scrollButtonMode === "dock"
610
610
  ? "Fullscreen: show the extension's dedicated Back to bottom row."
611
- : "Fullscreen: use Pi's native floating Jump to latest overlay.",
611
+ : "Fullscreen: show the same Back to bottom text in Pi's native floating overlay.",
612
612
  currentValue: config.scrollButtonMode,
613
613
  values: [...SCROLL_BUTTON_MODES],
614
614
  };
@@ -1020,7 +1020,7 @@ export async function showCcstylePanel(
1020
1020
  scrollButtonSetting.description =
1021
1021
  config.scrollButtonMode === "dock"
1022
1022
  ? "Fullscreen: show the extension's dedicated Back to bottom row."
1023
- : "Fullscreen: use Pi's native floating Jump to latest overlay.";
1023
+ : "Fullscreen: show the same Back to bottom text in Pi's native floating overlay.";
1024
1024
  break;
1025
1025
  }
1026
1026
  case "showStartupHeader": {
@@ -7,9 +7,11 @@
7
7
  * 与 `editDiffCollapsedLines` / `writeDiffCollapsedLines` / `expandedPreviewMaxLines`。
8
8
  * Agent/Task 族:调用只进摘要计数,tool 卡始终折叠(避免 pending→完成高度闪动)。
9
9
  * edit/write 与 ask_user_question 留在外层:不进摘要计数,折叠态也单独成行。
10
+ * 外层行一旦在消息里出现,当前回合就地完结(不计静默期),后续消息另起回合:
11
+ * 摘要行因此只折叠连续的一段工具调用,展开/收起不再跨外层行搬位置。
10
12
  * 用户消息是回合的硬边界:steer 消息插进回合中间、或上一回合没正文就收尾时,回合
11
- * 就地收口、后续消息另起一回合,区间里的用户消息不会被当成外来行挪走(摘要行、
12
- * 展开面板因此留在自己回合的位置上)。
13
+ * 就地收口、后续消息另起一回合。custom 通知/summary 类组件既不是成员也不算外来行,
14
+ * 原地留在两段之间,不打断统计也不被挪位。
13
15
  * 底部 Agents/Tasks 面板由 pi-subagents/pi-tasks 独立 widget 负责,不经 tool 卡外置。
14
16
  *
15
17
  * live 围观态(回合进行中 / 收尾静默期):正文跟折叠态同形;摘要行与单一槽位卡
@@ -30,6 +32,7 @@
30
32
  */
31
33
  import {
32
34
  AssistantMessageComponent,
35
+ CustomMessageComponent,
33
36
  SkillInvocationMessageComponent,
34
37
  ToolExecutionComponent,
35
38
  UserMessageComponent,
@@ -385,6 +388,9 @@ function layoutExpandedToolCard(
385
388
  ): { lines: string[]; hits: Array<{ child: any; start: number; end: number }> } {
386
389
  const slot = aggregateToolCardBgSlot(children.map((child) => child?.__ccTool).filter(Boolean));
387
390
  const toolBgAnsi = darkenBgAnsi(theme, slot);
391
+ // 展开面板外卡底色随组内工具状态聚合(与 default 模式分组卡同口径):
392
+ // 有一个失败用失败底色、没有失败但有进行中用进行中底色、全成功用成功底色。
393
+ const outerSlot = slot;
388
394
  /** live 每行前面的标记宽度(首行 `↳ `,其余对齐空格)。 */
389
395
  const markerWidth = live ? 2 : 0;
390
396
  const innerWidth = Math.max(0, width - 2 - markerWidth);
@@ -399,7 +405,7 @@ function layoutExpandedToolCard(
399
405
  // 面板 pad 1 是唯一左边距:剥掉子行 collapsed 态自带的 1 格 lead,
400
406
  // 否则标题行偏到 2、↳ 行偏到 4,左右不再对称。
401
407
  const line = raw.replace(/^((?:\x1b\[[0-?]*[ -/]*[@-~])*) /, "$1");
402
- lines.push(paddedBackgroundRow(theme, slot, line, width));
408
+ lines.push(paddedBackgroundRow(theme, outerSlot, line, width));
403
409
  return;
404
410
  }
405
411
  // 槽位里不重复展开入口(见 SLOT_HINT_PATTERNS)。
@@ -420,14 +426,13 @@ function layoutExpandedToolCard(
420
426
  };
421
427
  const pushBlank = () => {
422
428
  if (live || lastBlank) return;
423
- lines.push(paddedBackgroundRow(theme, slot, "", width));
429
+ lines.push(paddedBackgroundRow(theme, outerSlot, "", width));
424
430
  lastBlank = true;
425
431
  };
426
432
  for (let childIndex = 0; childIndex < children.length; childIndex++) {
427
433
  const child = children[childIndex];
428
434
  const painted = paints?.[childIndex];
429
435
  const childLines = Array.isArray(painted) ? painted : child.render(innerWidth);
430
- // live 不留空行、也不叠深色内卡:槽位没有边框。
431
436
  const innerCard = !live && isThinkingPreview(child) && child.expanded === true;
432
437
  let first = -1;
433
438
  let last = -1;
@@ -440,7 +445,7 @@ function layoutExpandedToolCard(
440
445
  if (first < 0) {
441
446
  if (live) continue;
442
447
  for (const line of childLines) {
443
- lines.push(paddedBackgroundRow(theme, slot, line, width));
448
+ lines.push(paddedBackgroundRow(theme, outerSlot, line, width));
444
449
  lastBlank = !hasVisibleText(line);
445
450
  }
446
451
  continue;
@@ -502,6 +507,7 @@ function compactRoundCard(
502
507
  | undefined;
503
508
  const layout = (width: number) => {
504
509
  const theme = themeOf();
510
+ // 与 default 模式分组卡同口径:外卡底色随组内工具聚合,子卡状态变了要重绘。
505
511
  const bgSlot = aggregateToolCardBgSlot(
506
512
  children.map((child) => child?.__ccTool).filter(Boolean),
507
513
  );
@@ -1320,6 +1326,16 @@ export function installCompactMode(deps: CompactModeInstallDeps): CompactModeHoo
1320
1326
  }, FOLD_SETTLE_MS);
1321
1327
  };
1322
1328
 
1329
+ /**
1330
+ * 外层行(edit/write/ask)切出的段落封口:跳过静默期直接定稿。
1331
+ * 静默期是为"正文 token 先于 toolCall 到达"的双重转场准备的;外层边界
1332
+ * 出现时摘要段内容已完整,立即收拢让 Ran for 当场落位,槽位卡一并撤走。
1333
+ */
1334
+ const sealRound = (round: CompactRound, endTimestamp?: number): void => {
1335
+ finalizeRound(round, endTimestamp);
1336
+ renderRound(round);
1337
+ };
1338
+
1323
1339
  /** 新回合接替时立即收掉还在静默期的回合,把两次转场并成一次。 */
1324
1340
  const flushSettle = (): void => {
1325
1341
  for (const round of [...pendingFoldRounds]) {
@@ -1460,6 +1476,13 @@ export function installCompactMode(deps: CompactModeInstallDeps): CompactModeHoo
1460
1476
  const isUserMessageComponent = (value: any): boolean =>
1461
1477
  value instanceof UserMessageComponent || value instanceof SkillInvocationMessageComponent;
1462
1478
 
1479
+ /**
1480
+ * 回合内的透明行:custom 通知(系统提示、extension 注入)既不是成员也不算外来行。
1481
+ * 它落在两个成员之间时原地保留——不打断统计、不被搬到摘要行下方。
1482
+ * 硬边界仍只有用户消息;summary/compaction 块由各自的 message 边界收口。
1483
+ */
1484
+ const isTransparentComponent = (value: any): boolean => value instanceof CustomMessageComponent;
1485
+
1463
1486
  /**
1464
1487
  * 新组件与回合已有成员之间是否隔着一条用户消息。隔着就说明这是下一回合的内容:
1465
1488
  * steer 消息插进了回合中间,或上一回合没有正文就收尾、用户又问了新问题。
@@ -1599,7 +1622,14 @@ export function installCompactMode(deps: CompactModeInstallDeps): CompactModeHoo
1599
1622
  const intruders: any[] = [];
1600
1623
  for (let i = last - 1; i > first; i--) {
1601
1624
  // 用户消息永远留在原地:挪走会把别人的消息挪到用户消息下面去。
1602
- if (isMember(children[i]) || isUserMessageComponent(children[i])) continue;
1625
+ // custom 通知同理:它是回合内的透明行,不被统计也不挪位。
1626
+ if (
1627
+ isMember(children[i]) ||
1628
+ isUserMessageComponent(children[i]) ||
1629
+ isTransparentComponent(children[i])
1630
+ ) {
1631
+ continue;
1632
+ }
1603
1633
  intruders.unshift(children.splice(i, 1)[0]);
1604
1634
  }
1605
1635
  if (lastMember) last = children.indexOf(lastMember);
@@ -1759,22 +1789,24 @@ export function installCompactMode(deps: CompactModeInstallDeps): CompactModeHoo
1759
1789
 
1760
1790
  const thinkingKids: any[] = [];
1761
1791
  for (const [component, message] of round.messages) {
1762
- if (component !== previewComponent) {
1792
+ if (component === previewComponent) {
1793
+ passThroughAssistant(component, message);
1794
+ const kids = Array.isArray(component.contentContainer?.children)
1795
+ ? [...component.contentContainer.children]
1796
+ : [];
1763
1797
  component.contentContainer?.clear?.();
1764
- continue;
1765
- }
1766
- passThroughAssistant(component, message);
1767
- const kids = Array.isArray(component.contentContainer?.children)
1768
- ? [...component.contentContainer.children]
1769
- : [];
1770
- component.contentContainer?.clear?.();
1771
- // 只摘思考预览块进槽位;已收尾的思考回收进摘要行。
1772
- for (const kid of kids) {
1773
- if (typeof kid?.setHintHovered === "function") thinkingKids.push(kid);
1798
+ // 只摘思考预览块进槽位;已收尾的思考回收进摘要行。
1799
+ for (const kid of kids) {
1800
+ if (typeof kid?.setHintHovered === "function") thinkingKids.push(kid);
1801
+ }
1774
1802
  }
1803
+ // text 在各消息自己的位置渲染,不随回合折叠态;非 anchor 成员的
1804
+ // 中止/错误状态仍汇总在 anchor 外层,不在成员处重复成行。
1805
+ renderAssistantWithoutThinking(
1806
+ component,
1807
+ component === round.anchor ? message : { ...message, stopReason: "stop" },
1808
+ );
1775
1809
  }
1776
- // 正文照折叠态渲染(不含 thinking):live 与收尾后同形,收尾只剩槽位卡消失。
1777
- renderAssistantWithoutThinking(round.anchor, round.messages.get(round.anchor));
1778
1810
 
1779
1811
  const toolsById = new Map<string, any>();
1780
1812
  for (const tool of trackedToolComponents) {
@@ -1900,10 +1932,14 @@ export function installCompactMode(deps: CompactModeInstallDeps): CompactModeHoo
1900
1932
  // 否则消息内容里的 thinking([thinking, text, toolCall])会盖到文本上面。
1901
1933
  const anchorChildren: any[] = [];
1902
1934
  let cardItems: Array<{ child?: any; tool?: any }> = [];
1903
- const flushPanel = () => {
1935
+ // 纯 spacer 串拆不开面板,还给它所在消息的组件(通常是上一个
1936
+ // text 块的前导空行)。
1937
+ const flushPanel = (spacerOwner: any = round.anchor) => {
1904
1938
  if (cardItems.length === 0) return;
1905
1939
  if (cardItems.every((item) => !item.tool && isSpacerComponent(item.child))) {
1906
- for (const item of cardItems) anchorChildren.push(item.child);
1940
+ for (const item of cardItems) {
1941
+ spacerOwner?.contentContainer?.addChild?.(item.child);
1942
+ }
1907
1943
  } else {
1908
1944
  // 面板上沿留 1 行卡外空行:面板底色与 userMessage 同色,
1909
1945
  // 贴在一起会看成一个块;卡内顶部再加 1 行 padding 保持上下对称。
@@ -1920,13 +1956,15 @@ export function installCompactMode(deps: CompactModeInstallDeps): CompactModeHoo
1920
1956
  }
1921
1957
  cardItems = [];
1922
1958
  };
1923
- const takeChild = (child: any, outside: boolean) => {
1959
+ // outside 的块(text 及其前导空行)留在各自组件上原位渲染:展开态下
1960
+ // 助手文本不跨消息搬家;它不切断面板——cardItems 跨消息延续,回合的
1961
+ // thinking/工具统一汇成末尾的一张共享面板,混排 text 不再把卡撕成几段。
1962
+ const takeChild = (component: any, child: any, outside: boolean) => {
1924
1963
  if (!outside) {
1925
1964
  cardItems.push({ child });
1926
1965
  return;
1927
1966
  }
1928
- flushPanel();
1929
- anchorChildren.push(child);
1967
+ component.contentContainer?.addChild?.(child);
1930
1968
  };
1931
1969
  const placedToolIds = new Set<string>();
1932
1970
  const placeTool = (id: string, fallbackName?: string) => {
@@ -1972,11 +2010,11 @@ export function installCompactMode(deps: CompactModeInstallDeps): CompactModeHoo
1972
2010
  }
1973
2011
  }
1974
2012
  while (cursor.i < kids.length) local.push({ outside: false, child: kids[cursor.i++] });
1975
- for (const entry of local) if (entry.outside) takeChild(entry.child, true);
2013
+ for (const entry of local) if (entry.outside) takeChild(component, entry.child, true);
1976
2014
  for (const entry of local) {
1977
2015
  if (entry.outside) continue;
1978
2016
  if (entry.toolId) placeTool(entry.toolId, entry.toolName);
1979
- else takeChild(entry.child, false);
2017
+ else takeChild(component, entry.child, false);
1980
2018
  }
1981
2019
  }
1982
2020
  for (const message of round.detachedMessages) {
@@ -2001,15 +2039,10 @@ export function installCompactMode(deps: CompactModeInstallDeps): CompactModeHoo
2001
2039
  !explicitRoundToolIds.has(String(tool.toolCallId ?? "")),
2002
2040
  );
2003
2041
  flushPanel();
2042
+ // anchorChildren 只剩面板件(spacer+panelBoundSpacer 都是 childAtRow 组件):
2043
+ // 面板挂回摘要行原位,text 已在各自组件上。
2004
2044
  if (mounted) {
2005
- // 正文留在各自的 assistant 消息上,面板挂回摘要行原位。
2006
- const outside: any[] = [];
2007
- const panel: any[] = [];
2008
- for (const child of anchorChildren) {
2009
- (typeof child?.childAtRow === "function" ? panel : outside).push(child);
2010
- }
2011
- for (const child of outside) round.anchor.contentContainer.addChild(child);
2012
- if (panel.length > 0) mountRoundTail(round, () => panel);
2045
+ if (anchorChildren.length > 0) mountRoundTail(round, () => anchorChildren);
2013
2046
  else unmountRoundTail(round);
2014
2047
  } else {
2015
2048
  unmountRoundTail(round);
@@ -2041,7 +2074,8 @@ export function installCompactMode(deps: CompactModeInstallDeps): CompactModeHoo
2041
2074
  // 折叠时工具行被隐藏:abort/error/length 必须挂在摘要外层。
2042
2075
  appendStopStatus(component, stopStatus);
2043
2076
  } else {
2044
- component.contentContainer?.clear?.();
2077
+ // 成员的 text 同样留在自己组件上;中止状态只在 anchor 外层报一次。
2078
+ renderAssistantWithoutThinking(component, { ...message, stopReason: "stop" });
2045
2079
  }
2046
2080
  }
2047
2081
  };
@@ -2143,6 +2177,15 @@ export function installCompactMode(deps: CompactModeInstallDeps): CompactModeHoo
2143
2177
 
2144
2178
  const content = Array.isArray(message?.content) ? message.content : [];
2145
2179
  const hasToolCalls = content.some((item: any) => item?.type === "toolCall");
2180
+ const hasOuterToolCall = content.some(
2181
+ (item: any) => item?.type === "toolCall" && OUTER_TOOLS.has(String(item?.name ?? "")),
2182
+ );
2183
+ const hasInnerToolCall = content.some(
2184
+ (item: any) => item?.type === "toolCall" && !OUTER_TOOLS.has(String(item?.name ?? "")),
2185
+ );
2186
+ const hasThinkingContent = content.some(
2187
+ (item: any) => item?.type === "thinking" && String(item?.thinking ?? "").trim(),
2188
+ );
2146
2189
  const hasText = content.some(
2147
2190
  (item: any) => item?.type === "text" && typeof item.text === "string" && item.text.trim(),
2148
2191
  );
@@ -2150,13 +2193,54 @@ export function installCompactMode(deps: CompactModeInstallDeps): CompactModeHoo
2150
2193
 
2151
2194
  if (hasToolCalls) {
2152
2195
  let round = roundByComponent.get(this);
2196
+ const previousMessage = round?.messages.get(this);
2197
+ const previousHadOuter = Array.isArray(previousMessage?.content)
2198
+ ? previousMessage.content.some(
2199
+ (item: any) => item?.type === "toolCall" && OUTER_TOOLS.has(String(item?.name ?? "")),
2200
+ )
2201
+ : false;
2153
2202
  if (!round) {
2154
- // 本条消息是否带 text 不是回合边界:pi 流式协议里同一条
2155
- // assistant 消息会以 text+toolCall、toolCall-only 反复到达。
2156
- // 只在「组件未挂进任何回合」时并入 activeRound;被用户消息
2157
- // 隔开(steer/上回合没正文)时由 joinOrCreateRound 收尾另起。
2158
- round = joinOrCreateRound(this, message);
2159
- roundByComponent.set(this, round);
2203
+ // 外层行打断摘要段:本条消息带外层调用且可并入的活动回合已有内容时,
2204
+ // 旧回合就地完结(不走静默期)。本条消息自己含 inner 调用或思考才另起一段;
2205
+ // 外层独段(edit-only 消息)不建回合——没有可汇总内容,建段只会挂空摘要行。
2206
+ const joinable = joinableActiveRound(this);
2207
+ if (joinable && hasOuterToolCall) {
2208
+ sealRound(joinable, message?.timestamp);
2209
+ if (hasInnerToolCall || hasThinkingContent) {
2210
+ round = createRound(this, message);
2211
+ roundByComponent.set(this, round);
2212
+ round.messages.set(this, message);
2213
+ if (isUsableTimestamp(message.timestamp) && message.timestamp < round.startedAt) {
2214
+ round.startedAt = message.timestamp;
2215
+ }
2216
+ renderRound(round);
2217
+ return undefined;
2218
+ }
2219
+ // 外层独段:text/thinking 照原生渲染,edit 行由 tool render 外置,没有摘要行。
2220
+ return passThroughAssistant(this, message);
2221
+ }
2222
+ if (hasInnerToolCall || hasThinkingContent) {
2223
+ // 本条消息是否带 text 不是回合边界:pi 流式协议里同一条
2224
+ // assistant 消息会以 text+toolCall、toolCall-only 反复到达。
2225
+ // 只在「组件未挂进任何回合」时并入 activeRound;被用户消息
2226
+ // 隔开(steer/上回合没正文)时由 joinOrCreateRound 收尾另起。
2227
+ round = joinOrCreateRound(this, message);
2228
+ roundByComponent.set(this, round);
2229
+ round.messages.set(this, message);
2230
+ if (isUsableTimestamp(message.timestamp) && message.timestamp < round.startedAt) {
2231
+ round.startedAt = message.timestamp;
2232
+ }
2233
+ renderRound(round);
2234
+ return undefined;
2235
+ }
2236
+ // 外层独段、又没有可并入的活动回合:不建回合,text/工具各归其位。
2237
+ if (activeRound) finishRound(activeRound, message?.timestamp);
2238
+ return passThroughAssistant(this, message);
2239
+ }
2240
+ if (hasOuterToolCall && !previousHadOuter && roundLive(round)) {
2241
+ // 消息入段后流式增长才冒出外层调用(先 thinking 后 toolCall):
2242
+ // 就地封口所在段,本条消息按消息级归属留在原段,后续消息另起一段。
2243
+ sealRound(round, message?.timestamp);
2160
2244
  }
2161
2245
  round.messages.set(this, message);
2162
2246
  if (isUsableTimestamp(message.timestamp) && message.timestamp < round.startedAt) {
@@ -50,8 +50,8 @@ import {
50
50
  hideScrollButton,
51
51
  dockScrollButtonActive,
52
52
  restoreOfficialScrollToEnd,
53
+ restoreNativeScrollIndicatorText,
53
54
  syncOfficialScrollToEnd,
54
- isScrollBottomInput,
55
55
  renderScrollButton,
56
56
  resetScrollButtonState,
57
57
  scheduleScrollButtonSync,
@@ -78,6 +78,7 @@ import {
78
78
  } from "./hover.ts";
79
79
  import {
80
80
  handleStickyPromptClick,
81
+ stickyBarHit,
81
82
  resetStickyPromptState,
82
83
  updateStickyPromptHover,
83
84
  } from "./sticky-prompt.ts";
@@ -613,6 +614,18 @@ function packetInsideOverlay(tui: any, packet: SgrMousePacket): boolean {
613
614
  return false;
614
615
  }
615
616
 
617
+ /** 原生指示器优先于工具卡;覆盖它的粘性行仍保留原有点击优先级。 */
618
+ function packetOnNativeIndicator(tui: any, packet: SgrMousePacket): boolean {
619
+ const rect = tui.scrollToEndIndicatorRect;
620
+ return Boolean(
621
+ rect &&
622
+ packet.row - 1 === rect.row &&
623
+ packet.col - 1 >= rect.column &&
624
+ packet.col - 1 < rect.column + rect.width &&
625
+ !stickyBarHit(tui, packet),
626
+ );
627
+ }
628
+
616
629
  /**
617
630
  * 实例级包装 TuiAltScreen.handleViewportInput(惰性 Proxy 安全):
618
631
  * 原型方法取 original(绕开 proxy 函数包装),实例 own property 装 wrapper
@@ -636,6 +649,13 @@ function patchFullscreenViewportInput(tui: any): void {
636
649
  // dispatchMouseToOverlay → overlay.handleMouse;overlay 外的包仍
637
650
  // 走扩展收起/展开/hover。两条路径各管各的。
638
651
  if (packets) {
652
+ const nativePacket = packets.find((packet) => packetOnNativeIndicator(tui, packet));
653
+ if (nativePacket) {
654
+ clearPendingCollapsePress();
655
+ applyFullscreenHover(tui, null);
656
+ updateStickyPromptHover(tui, nativePacket);
657
+ return Reflect.apply(original, this, [data]);
658
+ }
639
659
  // 布局还没出来或仍是上一帧:不要把点击收成工具展开。返回 undefined
640
660
  // 让焦点 overlay 的 handleInput 拿到原始 SGR;官方链也靠这份布局,调它会消费且打到 transcript。
641
661
  if (tui.hasOverlay?.() && !overlayLayoutsCurrent(tui)) return undefined;
@@ -985,13 +1005,9 @@ function handleToolMouseInput(data: string): { consume: true } | undefined {
985
1005
  if (!getToolMouseTui()) return undefined;
986
1006
  // 惰性 Proxy fullscreen:鼠标由 handleViewportInput 包装消费(官方链之前),
987
1007
  // 此处只处理键盘(鼠标事件在官方 listener 已被 consume,到不了这里)。
1008
+ // 回底键归 Pi viewport(tui.altScreen.bottom,overlay 聚焦时让给 overlay),不在此重复处理。
988
1009
  if (fullscreenLazyTui(getToolMouseTui())) {
989
1010
  scheduleScrollButtonSync(getToolMouseTui(), data);
990
- if (isScrollBottomInput(data)) {
991
- getToolMouseTui().scrollToBottom?.();
992
- hideScrollButton(getToolMouseTui());
993
- return { consume: true };
994
- }
995
1011
  return undefined;
996
1012
  }
997
1013
  updateScrollButtonFromInput(getToolMouseTui(), data);
@@ -1080,6 +1096,7 @@ export function resetToolHoverState(): void {
1080
1096
  setScrollButtonVisible(false);
1081
1097
  setScrollButtonHovered(false);
1082
1098
  resetStickyPromptState();
1099
+ restoreNativeScrollIndicatorText();
1083
1100
  restoreOfficialScrollToEnd(getToolMouseTui());
1084
1101
  releaseFullscreenToolMouseMotion(getToolMouseTui());
1085
1102
  }
@@ -1172,6 +1189,7 @@ export function installToolMouseInteraction(
1172
1189
  return renderScrollButton(width, theme);
1173
1190
  },
1174
1191
  invalidate() {},
1192
+ dispose: restoreNativeScrollIndicatorText,
1175
1193
  });
1176
1194
  return getScrollButtonWidget();
1177
1195
  }
@@ -17,7 +17,7 @@ import {
17
17
 
18
18
  const ZENTUI_PAGE_UP_INPUT = /^\x1b\[5;9(?::[12])?~$|^\x1b\[57421;9(?::[12])?u$|^\x1b\[1;6A$/;
19
19
  const ZENTUI_PAGE_DOWN_INPUT = /^\x1b\[6;9(?::[12])?~$|^\x1b\[57422;9(?::[12])?u$|^\x1b\[1;6B$/;
20
- const SCROLL_BOTTOM_SHORTCUT = "ctrl+end";
20
+ const SCROLL_BOTTOM_KEYBINDING = "tui.altScreen.bottom";
21
21
 
22
22
  patchRegistry.ensure(TOOL_MOUSE_TUI_SLOT, () => null);
23
23
  export function getToolMouseTui(): any {
@@ -68,6 +68,14 @@ export function setScrollButtonVisible(visible: boolean): void {
68
68
  export function noteNewTranscriptItem(): void {
69
69
  const state = scrollButtonState();
70
70
  const tui = getToolMouseTui();
71
+ if (nativeScrollTextEnabled(tui)) {
72
+ syncOfficialScrollToEnd(tui);
73
+ if (nativeScrollTextPatch && !isFullscreenAtBottom(tui)) {
74
+ state.newCount += 1;
75
+ tui.requestRender?.();
76
+ }
77
+ return;
78
+ }
71
79
  if (!dockScrollButtonActive() || !state.visible || !tui) return;
72
80
  // 提交新消息时官方可能直接跳回底部(不经过滚动输入):先按实时跟随状态校正,
73
81
  // 否则跟随期间的内容会被当成“离开底部时的新消息”计入。
@@ -137,34 +145,78 @@ export function restoreOfficialScrollToEnd(tui: any): void {
137
145
  tui[OFFICIAL_SCROLL_TO_END_KEY] = undefined;
138
146
  }
139
147
 
140
- /** dock 模式替换官方浮层;native 或 ccstyle off 时保留 Pi 原生 Jump to latest。 */
148
+ /** dock 模式替换官方浮层;native 保留 Pi 原生浮层并换上 dock 文案;ccstyle off 还原 Pi 原样。 */
141
149
  export function syncOfficialScrollToEnd(tui: any): void {
150
+ if (!nativeScrollTextEnabled(tui)) restoreNativeScrollIndicatorText();
142
151
  if (dockScrollButtonActive()) {
143
152
  disableOfficialScrollToEnd(tui);
144
153
  return;
145
154
  }
146
155
  restoreOfficialScrollToEnd(tui);
156
+ if (nativeScrollTextEnabled(tui)) {
157
+ // 离开 dock 时清零一次;native 的后续渲染保留共享计数。
158
+ if (getScrollButtonVisible()) setScrollButtonVisible(false);
159
+ setScrollButtonHovered(false);
160
+ syncNativeScrollIndicatorText(tui);
161
+ return;
162
+ }
147
163
  setScrollButtonVisible(false);
148
164
  setScrollButtonHovered(false);
149
165
  }
150
166
 
167
+ /** 只记录文案补丁;dock 的显隐、快捷键和原生浮层开关仍走原路径。 */
168
+ let nativeScrollTextPatch: { renderer: any; original: () => string } | undefined;
169
+
170
+ function nativeScrollTextEnabled(tui: any): boolean {
171
+ return (
172
+ toolMouseInteractionActive() && config.scrollButtonMode === "native" && fullscreenLazyTui(tui)
173
+ );
174
+ }
175
+
176
+ /** widget 销毁或离开 native 模式时还原 Pi 的原始回调。 */
177
+ export function restoreNativeScrollIndicatorText(): void {
178
+ if (!nativeScrollTextPatch) return;
179
+ const { renderer, original } = nativeScrollTextPatch;
180
+ renderer.scrollToEndIndicator = original;
181
+ nativeScrollTextPatch = undefined;
182
+ scrollButtonState().newCount = 0;
183
+ }
184
+
185
+ function syncNativeScrollIndicatorText(tui: any): void {
186
+ // Pi 的稳定 Proxy 会重绑捕获的方法;文案回调必须从真实 renderer 上取得。
187
+ const renderer = tui.valueOf();
188
+ if (nativeScrollTextPatch?.renderer !== renderer) restoreNativeScrollIndicatorText();
189
+ if (!nativeScrollTextPatch) {
190
+ const original = renderer.scrollToEndIndicator;
191
+ if (typeof original !== "function") return;
192
+ nativeScrollTextPatch = { renderer, original };
193
+ renderer.scrollToEndIndicator = () =>
194
+ original.call(renderer).replace("Jump to latest message", scrollButtonText());
195
+ }
196
+ if (isFullscreenAtBottom(renderer)) scrollButtonState().newCount = 0;
197
+ }
198
+
151
199
  /** 官方 fullscreen:是否已跟随 transcript 底部(按钮隐藏条件)。 */
152
200
  export function isFullscreenAtBottom(tui: any): boolean {
153
201
  const following = tui.isFollowingOutput ?? tui.getPrimaryScrollView?.()?.isFollowingEnd ?? true;
154
202
  return Boolean(following);
155
203
  }
156
204
 
157
- function formatShortcut(shortcut: string): string {
158
- return shortcut
159
- .split("+")
160
- .map((part) =>
161
- part.length <= 1 ? part.toUpperCase() : `${part[0]?.toUpperCase() ?? ""}${part.slice(1)}`,
205
+ /** 与 Pi 原生浮层同源(keyDisplayText):用户实际绑定,首字母大写,macOS 上 alt 显示为 option。 */
206
+ function scrollBottomShortcutText(): string {
207
+ return getKeybindings()
208
+ .getKeys(SCROLL_BOTTOM_KEYBINDING)
209
+ .map((key) =>
210
+ key
211
+ .split("+")
212
+ .map((part) => {
213
+ const display =
214
+ process.platform === "darwin" && part.toLowerCase() === "alt" ? "option" : part;
215
+ return display.charAt(0).toUpperCase() + display.slice(1);
216
+ })
217
+ .join("+"),
162
218
  )
163
- .join("+");
164
- }
165
-
166
- export function isScrollBottomInput(data: string): boolean {
167
- return matchesKey(data, SCROLL_BOTTOM_SHORTCUT);
219
+ .join("/");
168
220
  }
169
221
 
170
222
  function isScrollNavigationInput(data: string): boolean {
@@ -251,9 +303,8 @@ export function updateScrollButtonFromInput(tui: any, data: string): void {
251
303
  /** 无新内容时提示原文案;有新内容时换成累计条数。 */
252
304
  function scrollButtonText(): string {
253
305
  const count = getScrollButtonNewCount();
254
- const shortcut = formatShortcut(SCROLL_BOTTOM_SHORTCUT);
255
- if (count <= 0) return `Back to bottom · ${shortcut}`;
256
- return `${count} new message${count === 1 ? "" : "s"} · ${shortcut}`;
306
+ if (count <= 0) return "Back to bottom";
307
+ return `${count} new message${count === 1 ? "" : "s"}`;
257
308
  }
258
309
 
259
310
  export function renderScrollButton(width: number, theme: any): string[] {
@@ -263,9 +314,11 @@ export function renderScrollButton(width: number, theme: any): string[] {
263
314
  !fullscreenLazyTui(getToolMouseTui())
264
315
  )
265
316
  return [];
317
+ // 未绑定时与 Pi 原生一样省略快捷键段。
318
+ const shortcut = scrollBottomShortcutText();
266
319
  const label = theme.fg(
267
320
  getScrollButtonHovered() ? "text" : "accent",
268
- `[ ↓ ${scrollButtonText()} ]`,
321
+ `[ ↓ ${scrollButtonText()}${shortcut ? ` · ${shortcut}` : ""} ]`,
269
322
  );
270
323
  const leftPad = Math.max(0, Math.floor((width - visibleWidth(label)) / 2));
271
324
  return [`${" ".repeat(leftPad)}${truncateToWidth(label, width, "…")}`];
@@ -296,7 +296,7 @@ export function renderStickyPromptScreen(
296
296
  }
297
297
 
298
298
  /** 行与列都落在本帧画出的粘性条内。滚动条那一列在条外。 */
299
- function stickyBarHit(tui: any, packet: SgrMousePacket): boolean {
299
+ export function stickyBarHit(tui: any, packet: SgrMousePacket): boolean {
300
300
  const state = stickyState();
301
301
  if (!stickyPromptActive() || !state.visible || state.layout !== tui?.currentLayout) return false;
302
302
  if (packet.row - 1 !== state.row) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cc-extensions",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "license": "MIT",
5
5
  "description": "Claude Code-style TUI output with some personal touches and handy utilities.",
6
6
  "type": "module",