@herbertgao/pi-extensions 2026.11.0 → 2026.11.1

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.
Files changed (32) hide show
  1. package/CHANGELOG.md +759 -0
  2. package/README.md +5 -5
  3. package/THIRD_PARTY_NOTICES.md +1 -1
  4. package/extensions/clef.mjs +1 -1
  5. package/node_modules/@herbertgao/pi-agency/CHANGELOG.md +19 -0
  6. package/node_modules/@herbertgao/pi-agency/package.json +4 -2
  7. package/node_modules/@herbertgao/pi-agency/src/index.ts +1 -1
  8. package/node_modules/@herbertgao/pi-bark/CHANGELOG.md +52 -0
  9. package/node_modules/@herbertgao/pi-bark/package.json +2 -1
  10. package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +207 -0
  11. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +7 -5
  12. package/node_modules/@herbertgao/pi-cc-extensions/README.md +10 -7
  13. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +20 -0
  14. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +61 -6
  15. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/agent-summary/core.ts +11 -16
  16. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/agent-summary/index.ts +60 -11
  17. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/compact-thinking.ts +29 -11
  18. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/footer-layout.ts +54 -6
  19. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/footer.ts +23 -5
  20. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/session-tokens.ts +52 -0
  21. package/node_modules/@herbertgao/pi-cc-extensions/package.json +5 -4
  22. package/node_modules/@herbertgao/pi-impeccable/CHANGELOG.md +13 -0
  23. package/node_modules/@herbertgao/pi-impeccable/package.json +2 -1
  24. package/node_modules/@herbertgao/sol-pi/CHANGELOG.md +84 -0
  25. package/node_modules/@herbertgao/sol-pi/README.md +3 -3
  26. package/node_modules/@herbertgao/sol-pi/THIRD_PARTY_NOTICES.md +4 -4
  27. package/node_modules/@herbertgao/sol-pi/agents-install.md +3 -3
  28. package/node_modules/@herbertgao/sol-pi/docs/compatibility.md +1 -1
  29. package/node_modules/@herbertgao/sol-pi/package.json +2 -1
  30. package/node_modules/pi-provider-qoder/dist/index.js +5 -1
  31. package/node_modules/pi-provider-qoder/package.json +1 -1
  32. package/package.json +8 -7
@@ -62,6 +62,8 @@ export type Config = {
62
62
  toolLabelClip: number;
63
63
  useSummaryTitlesAsThinkingTitle: boolean;
64
64
  previewLines: number;
65
+ /** 思考完成后的折叠预览行数;null = 跟随 previewLines(保持旧行为)。 */
66
+ completedPreviewLines: number | null;
65
67
  animationIntervalMs: number;
66
68
  showStartupHeader: boolean;
67
69
  /** fullscreen:userMessage 正文首行滚出视口上沿后钉住,直到下一条指令接手。 */
@@ -85,6 +87,8 @@ export type Config = {
85
87
  footerTokenRateMode: FooterTokenRateMode;
86
88
  /** 速率芯片是否带 TTFT。关则只显示速率。 */
87
89
  footerTokenRateTtft: boolean;
90
+ /** 会话累计 token 芯片(累加会话条目的 usage.totalTokens)。默认关。 */
91
+ footerSessionTokens: boolean;
88
92
  /** ISO 4217 显示币种。USD 时不换算。 */
89
93
  footerCurrency: string;
90
94
  /** 1 单位费用对应的显示币种数量。null 只换符号、不乘倍率。 */
@@ -119,6 +123,8 @@ export const EXPANDED_OUTPUT_MAX_LINES_VALUES = ["10", "20", "40", "80", "120"];
119
123
  /** 工具摘要里 path/command 等输入的折叠字符数;0 = 只按可用宽度截断。 */
120
124
  export const TOOL_LABEL_CLIP_VALUES = ["0", "40", "60", "80", "100", "120", "160"];
121
125
  export const THINKING_PREVIEW_LINES_VALUES = ["0", "1", "3", "5", "10"];
126
+ /** 完成态思考预览预设;follow = 跟随 previewLines。 */
127
+ export const COMPLETED_THINKING_PREVIEW_LINES_VALUES = ["follow", ...THINKING_PREVIEW_LINES_VALUES];
122
128
  export const THINKING_ANIMATION_INTERVAL_VALUES = ["40", "60", "90", "120", "180"];
123
129
  /** Tools commonly toggled in excludeRenderers via the settings panel. */
124
130
  export const EXCLUDE_RENDERER_CANDIDATES = [
@@ -150,6 +156,7 @@ export const DEFAULT_CONFIG: Config = {
150
156
  toolLabelClip: 0,
151
157
  useSummaryTitlesAsThinkingTitle: true,
152
158
  previewLines: 3,
159
+ completedPreviewLines: null,
153
160
  animationIntervalMs: 90,
154
161
  showStartupHeader: true,
155
162
  stickyUserMessage: true,
@@ -166,6 +173,7 @@ export const DEFAULT_CONFIG: Config = {
166
173
  footerTokenRate: true,
167
174
  footerTokenRateMode: "average",
168
175
  footerTokenRateTtft: true,
176
+ footerSessionTokens: false,
169
177
  footerCurrency: "USD",
170
178
  footerCurrencyRate: null,
171
179
  footerNerdIcons: true,
@@ -196,6 +204,13 @@ export function pickPositiveNumber(value: unknown, fallback: number, min = 1): n
196
204
  return Number.isFinite(n) ? Math.max(min, n) : fallback;
197
205
  }
198
206
 
207
+ /** 思考完成后的预览行数。null(缺失/空/非法)= 跟随 previewLines,保持旧配置行为。 */
208
+ export function pickCompletedPreviewLines(value: unknown): number | null {
209
+ if (value === undefined || value === null || value === "") return null;
210
+ const n = typeof value === "number" ? value : typeof value === "string" ? Number(value) : NaN;
211
+ return Number.isFinite(n) ? Math.max(0, Math.floor(n)) : null;
212
+ }
213
+
199
214
  function normalizeCurrency(value: unknown): string {
200
215
  return typeof value === "string" && /^[A-Za-z]{3}$/.test(value.trim())
201
216
  ? value.trim().toUpperCase()
@@ -277,6 +292,7 @@ export function normalizeConfig(input: unknown): Config {
277
292
  0,
278
293
  Number.MAX_SAFE_INTEGER,
279
294
  ),
295
+ completedPreviewLines: pickCompletedPreviewLines(source.completedPreviewLines),
280
296
  animationIntervalMs: pickPositiveNumber(
281
297
  source.animationIntervalMs,
282
298
  DEFAULT_CONFIG.animationIntervalMs,
@@ -304,6 +320,7 @@ export function normalizeConfig(input: unknown): Config {
304
320
  DEFAULT_CONFIG.footerTokenRateMode,
305
321
  ),
306
322
  footerTokenRateTtft: source.footerTokenRateTtft !== false,
323
+ footerSessionTokens: source.footerSessionTokens === true,
307
324
  footerCurrency: normalizeCurrency(source.footerCurrency),
308
325
  footerCurrencyRate: normalizeFooterCurrencyRate(source.footerCurrencyRate),
309
326
  footerNerdIcons: source.footerNerdIcons !== false,
@@ -320,6 +337,7 @@ export function getCompactThinkingConfig(source: Config = config): CompactThinki
320
337
  return {
321
338
  useSummaryTitlesAsThinkingTitle: source.useSummaryTitlesAsThinkingTitle,
322
339
  previewLines: source.previewLines,
340
+ completedPreviewLines: source.completedPreviewLines,
323
341
  animationIntervalMs: source.animationIntervalMs,
324
342
  };
325
343
  }
@@ -393,6 +411,7 @@ export function formatConfigStatus(source: Config = config): string {
393
411
  `toolLabelClip=${source.toolLabelClip}`,
394
412
  `thinkingTitle=${source.useSummaryTitlesAsThinkingTitle ? "summary" : "default"}`,
395
413
  `thinkingPreview=${source.previewLines}`,
414
+ `thinkingPreviewDone=${source.completedPreviewLines ?? "follow"}`,
396
415
  `thinkingAnimation=${source.animationIntervalMs}ms`,
397
416
  `startupHeader=${source.showStartupHeader ? "on" : "off"}`,
398
417
  `stickyUserMessage=${source.stickyUserMessage ? "on" : "off"}`,
@@ -409,6 +428,7 @@ export function formatConfigStatus(source: Config = config): string {
409
428
  `footerTokenRate=${source.footerTokenRate ? "on" : "off"}`,
410
429
  `footerTokenRateMode=${source.footerTokenRateMode}`,
411
430
  `footerTokenRateTtft=${source.footerTokenRateTtft ? "on" : "off"}`,
431
+ `footerSessionTokens=${source.footerSessionTokens ? "on" : "off"}`,
412
432
  `footerCurrency=${source.footerCurrency}`,
413
433
  `footerRate=${source.footerCurrencyRate ?? "-"}`,
414
434
  `footerIcons=${source.footerNerdIcons ? "nerd" : "plain"}`,
@@ -33,6 +33,7 @@ import { applyStartupHeader, clearStartupHeader } from "../feature/shell/startup
33
33
  import type { ToolGroupingHooks } from "../renderer/tool/grouping.ts";
34
34
  import {
35
35
  config,
36
+ COMPLETED_THINKING_PREVIEW_LINES_VALUES,
36
37
  DEFAULT_CONFIG,
37
38
  DIFF_COLLAPSED_LINES_VALUES,
38
39
  DIFF_INDICATOR_MODES,
@@ -45,6 +46,7 @@ import {
45
46
  FOOTER_TOKEN_RATE_MODES,
46
47
  formatExcludeRenderers,
47
48
  getCompactThinkingConfig,
49
+ pickCompletedPreviewLines,
48
50
  pickPositiveInt,
49
51
  pickPositiveNumber,
50
52
  pickToolLabelClip,
@@ -111,6 +113,12 @@ function footerTokenRateTtftDescription(enabled: boolean): string {
111
113
  : "Time to first token hidden. The rate chip shows tok/s only.";
112
114
  }
113
115
 
116
+ function footerSessionTokensDescription(enabled: boolean): string {
117
+ return enabled
118
+ ? "Cumulative tokens used in this conversation, summed from the session's usage.totalTokens. Turn off to hide it."
119
+ : "Conversation token total hidden.";
120
+ }
121
+
114
122
  function footerGitStatsDescription(mode: FooterGitStatsMode): string {
115
123
  return mode === "branch"
116
124
  ? "Net changes since the merge base, including uncommitted edits. Base: origin/HEAD, then local main/master. Untracked files excluded; unavailable stats hidden."
@@ -364,20 +372,28 @@ function buildValueInputSubmenu(
364
372
  };
365
373
  }
366
374
 
367
- /** 数值项:预填当前值,空输入取消,非数字留下错误。 */
375
+ /** 数值项:预填当前值,空输入取消,非法输入留下错误;allowFollow 时额外接受 follow。 */
368
376
  function buildNumberInputSubmenu(
369
377
  theme: any,
370
378
  setting: { label: string; currentValue: string },
371
379
  closeSubmenu: (selected?: string) => void,
380
+ allowFollow = false,
372
381
  ) {
373
382
  return buildValueInputSubmenu(
374
383
  theme,
375
384
  {
376
385
  prompt: ` ${setting.label} — custom value:`,
377
386
  initial: setting.currentValue,
378
- hint: " Enter to apply · Esc to go back",
379
- accept: (raw) => (raw === "" ? undefined : Number.isFinite(Number(raw)) ? raw : null),
380
- invalid: (raw) => `Invalid number: "${raw}"`,
387
+ hint: allowFollow
388
+ ? " Enter to apply · Esc to go back · follow = Preview lines"
389
+ : " Enter to apply · Esc to go back",
390
+ accept: (raw) =>
391
+ raw === ""
392
+ ? undefined
393
+ : (allowFollow && raw === "follow") || Number.isFinite(Number(raw))
394
+ ? raw
395
+ : null,
396
+ invalid: (raw) => `${allowFollow ? "Invalid value" : "Invalid number"}: "${raw}"`,
381
397
  },
382
398
  closeSubmenu,
383
399
  );
@@ -576,12 +592,23 @@ export async function showCcstylePanel(
576
592
  const thinkingPreviewSetting = {
577
593
  id: "previewLines",
578
594
  label: "Preview lines",
579
- description: "Thinking preview lines; 0 hides the preview body.",
595
+ description: "Thinking preview lines while a run is in progress; 0 hides the preview body.",
580
596
  currentValue: String(config.previewLines),
581
597
  values: [...THINKING_PREVIEW_LINES_VALUES],
582
598
  submenu: (_current: string, closeSubmenu: (selected?: string) => void) =>
583
599
  buildNumberInputSubmenu(theme, thinkingPreviewSetting, closeSubmenu),
584
600
  };
601
+ const completedThinkingPreviewSetting = {
602
+ id: "completedPreviewLines",
603
+ label: "Completed preview",
604
+ description:
605
+ "Thinking preview lines once the run finishes; follow = same as Preview lines. Enter to type a custom value or follow.",
606
+ currentValue:
607
+ config.completedPreviewLines === null ? "follow" : String(config.completedPreviewLines),
608
+ values: [...COMPLETED_THINKING_PREVIEW_LINES_VALUES],
609
+ submenu: (_current: string, closeSubmenu: (selected?: string) => void) =>
610
+ buildNumberInputSubmenu(theme, completedThinkingPreviewSetting, closeSubmenu, true),
611
+ };
585
612
  const thinkingAnimationSetting = {
586
613
  id: "animationIntervalMs",
587
614
  label: "Animation interval ms",
@@ -782,6 +809,13 @@ export async function showCcstylePanel(
782
809
  currentValue: config.footerTokenRateTtft ? "on" : "off",
783
810
  values: ["on", "off"],
784
811
  };
812
+ const footerSessionTokensSetting = {
813
+ id: "footerSessionTokens",
814
+ label: "Conversation tokens",
815
+ description: footerSessionTokensDescription(config.footerSessionTokens),
816
+ currentValue: config.footerSessionTokens ? "on" : "off",
817
+ values: ["on", "off"],
818
+ };
785
819
  const pluginChipsSetting = {
786
820
  id: "footerPluginChips",
787
821
  label: "Footer chips",
@@ -880,6 +914,14 @@ export async function showCcstylePanel(
880
914
  ctx.ui.notify(`Updated ${id}: ${value}`, "info");
881
915
  return;
882
916
  }
917
+ if (id === "footerSessionTokens") {
918
+ const enabled = value === "on";
919
+ updateConfig({ footerSessionTokens: enabled });
920
+ footerSessionTokensSetting.currentValue = enabled ? "on" : "off";
921
+ footerSessionTokensSetting.description = footerSessionTokensDescription(enabled);
922
+ ctx.ui.notify(`Updated ${id}: ${value}`, "info");
923
+ return;
924
+ }
883
925
  if (id === "enableEditorPrefix") {
884
926
  const enabled = value === "on";
885
927
  updateConfig({ enableEditorPrefix: enabled });
@@ -1008,6 +1050,13 @@ export async function showCcstylePanel(
1008
1050
  updateConfig({ previewLines: pickPositiveInt(value, DEFAULT_CONFIG.previewLines, 0) });
1009
1051
  thinkingPreviewSetting.currentValue = String(config.previewLines);
1010
1052
  break;
1053
+ case "completedPreviewLines":
1054
+ updateConfig({
1055
+ completedPreviewLines: value === "follow" ? null : pickCompletedPreviewLines(value),
1056
+ });
1057
+ completedThinkingPreviewSetting.currentValue =
1058
+ config.completedPreviewLines === null ? "follow" : String(config.completedPreviewLines);
1059
+ break;
1011
1060
  case "animationIntervalMs":
1012
1061
  updateConfig({
1013
1062
  animationIntervalMs: pickPositiveNumber(value, DEFAULT_CONFIG.animationIntervalMs),
@@ -1095,7 +1144,12 @@ export async function showCcstylePanel(
1095
1144
  {
1096
1145
  id: "thinking",
1097
1146
  label: "Thinking",
1098
- items: [thinkingTitleSetting, thinkingPreviewSetting, thinkingAnimationSetting],
1147
+ items: [
1148
+ thinkingTitleSetting,
1149
+ thinkingPreviewSetting,
1150
+ completedThinkingPreviewSetting,
1151
+ thinkingAnimationSetting,
1152
+ ],
1099
1153
  },
1100
1154
  {
1101
1155
  id: "footer",
@@ -1105,6 +1159,7 @@ export async function showCcstylePanel(
1105
1159
  footerTokenRateSetting,
1106
1160
  footerTokenRateModeSetting,
1107
1161
  footerTokenRateTtftSetting,
1162
+ footerSessionTokensSetting,
1108
1163
  footerCurrencySetting,
1109
1164
  footerCurrencyRateSetting,
1110
1165
  footerNerdIconsSetting,
@@ -5,11 +5,11 @@
5
5
  * 计数:bash/powershell 按调用次数;read/edit/write 按非空 path/file_path 去重;other 按调用次数。
6
6
  * 失败单独累计;另记回合耗时。
7
7
  *
8
- * 呈现:`summaryLine` 纯文本,`summaryMarkdown` Markdown(可 box 引用块)。
8
+ * 呈现:`summarySegments` 分段(文字 + 语义色),渲染层自己拼行并上色。
9
+ * 不要经 Markdown 渲染:pi 的 Markdown 组件会剥掉输入里的终端序列,数字会失去语义色。
9
10
  */
10
11
 
11
12
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
12
- import { formatDuration } from "../../utils/format.ts";
13
13
 
14
14
  /** 工具分类。 */
15
15
  export type AgentToolCategory = "bash" | "read" | "edit" | "write" | "other";
@@ -113,25 +113,20 @@ function summaryParts(data: AgentSummaryData): string[] {
113
113
  return parts;
114
114
  }
115
115
 
116
- export function summaryMarkdown(
117
- data: AgentSummaryData,
118
- colors: { success: string; failed: string } = { success: "", failed: "" },
119
- ): string {
116
+ /** 摘要段:一段文字 + 语义色;数字上色由渲染层完成。 */
117
+ export type SummarySegment = { text: string; tone: "success" | "failed" };
118
+
119
+ export function summarySegments(data: AgentSummaryData): SummarySegment[] {
120
120
  const parts = summaryParts(data);
121
- if (parts.length === 0) return "";
121
+ if (parts.length === 0) return [];
122
122
  const capitalizeFirst = (part: string, first: boolean) => {
123
123
  const verb = part.match(/^[a-z]+/)?.[0] ?? "";
124
124
  return first && verb ? verb[0].toUpperCase() + verb.slice(1) + part.slice(verb.length) : part;
125
125
  };
126
- const paintNumber = (code: string, part: string) =>
127
- code ? part.replace(/(\d+)/, `${code}$1\x1b[0m`) : part;
128
- const text = parts
129
- .map((part, index) => capitalizeFirst(part, index === 0))
130
- .map((part) => paintNumber(part.endsWith("failed") ? colors.failed : colors.success, part))
131
- .join(", ");
132
- const duration = formatDuration(data.durationMs);
133
- const line = duration ? `${text} · ${duration}` : text;
134
- return `> *${line}*`;
126
+ return parts.map((part, index) => ({
127
+ text: capitalizeFirst(part, index === 0),
128
+ tone: part.endsWith("failed") ? "failed" : "success",
129
+ }));
135
130
  }
136
131
 
137
132
  /**
@@ -1,27 +1,76 @@
1
1
  /**
2
2
  * Agent 回合摘要展示:agent_end 时把本回合工具统计写入会话条目,
3
- * 由 entry renderer 渲染为 markdown 引用块 `> [!TIP] *斜体内容*`。
3
+ * 由 entry renderer 渲染成一行引用行 `│ Ran 1 command, wrote 1 file · 15s`。
4
4
  *
5
5
  * 统计复用 ./core.ts(bash|powershell/read/edit/write/other)。
6
6
  * appendEntry 不进 LLM 上下文,只显示在聊天区。
7
- * 引用块文字色取主题 mdQuote(cc 主题下为 muted 灰),内容用 *斜体* 语法。
7
+ *
8
+ * 不走 Markdown:pi 的 Markdown 组件会剥掉输入里的终端序列,
9
+ * 数字的语义色只能由组件自己拼。竖线取 mdQuoteBorder,文字取 mdQuote + 斜体,数字取 success/error。
8
10
  */
9
11
 
10
- import { Markdown } from "@earendil-works/pi-tui";
11
- import { getMarkdownTheme } from "@earendil-works/pi-coding-agent";
12
+ import { wrapTextWithAnsi } from "@earendil-works/pi-tui";
12
13
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
13
- import { bindAgentSummary, summaryMarkdown, type AgentSummaryData } from "./core.ts";
14
+ import { formatDuration } from "../../utils/format.ts";
15
+ import { bindAgentSummary, summarySegments, type SummarySegment } from "./core.ts";
16
+ import type { AgentSummaryData } from "./core.ts";
14
17
 
15
18
  export const AGENT_SUMMARY_ENTRY_TYPE = "agent-summary";
16
19
 
20
+ type SummaryTheme = {
21
+ fg(color: string, text: string): string;
22
+ italic(text: string): string;
23
+ getFgAnsi(color: string): string;
24
+ };
25
+
26
+ /** 取样式函数在正文前产生的 SGR 前缀;行内 reset 之后要靠它把样式续上。 */
27
+ function stylePrefix(style: (text: string) => string): string {
28
+ const sentinel = "\u0000";
29
+ const styled = style(sentinel);
30
+ const index = styled.indexOf(sentinel);
31
+ return index >= 0 ? styled.slice(0, index) : "";
32
+ }
33
+
34
+ /** 只给段内第一个数字上色;没有数字的段原样返回。 */
35
+ function paintNumber(segment: SummarySegment, theme: SummaryTheme): string {
36
+ const match = /(\d+)/.exec(segment.text);
37
+ if (!match) return segment.text;
38
+ const ansi = theme.getFgAnsi(segment.tone === "failed" ? "error" : "success");
39
+ if (!ansi) return segment.text;
40
+ const start = match.index;
41
+ return `${segment.text.slice(0, start)}${ansi}${match[1]}\x1b[0m${segment.text.slice(start + match[1].length)}`;
42
+ }
43
+
44
+ /** 摘要行:左侧 mdQuoteBorder 竖线 + 斜体 mdQuote 正文,数字按成功/失败上色。 */
45
+ class AgentSummaryLine {
46
+ private readonly body: string;
47
+ private readonly border: string;
48
+ private readonly theme: SummaryTheme;
49
+
50
+ constructor(segments: readonly SummarySegment[], duration: string, theme: SummaryTheme) {
51
+ this.theme = theme;
52
+ this.border = theme.fg("mdQuoteBorder", "│");
53
+ const quoteStyle = (text: string) => theme.italic(theme.fg("mdQuote", text));
54
+ const counts = segments.map((segment) => paintNumber(segment, theme)).join(", ");
55
+ const text = duration ? `${counts} · ${duration}` : counts;
56
+ const prefix = stylePrefix(quoteStyle);
57
+ this.body = quoteStyle(prefix ? text.replace(/\x1b\[0m/g, `\x1b[0m${prefix}`) : text);
58
+ }
59
+
60
+ invalidate(): void {}
61
+
62
+ render(width: number): string[] {
63
+ const contentWidth = Math.max(1, width - 4);
64
+ return wrapTextWithAnsi(this.body, contentWidth).map((line) => ` ${this.border} ${line}`);
65
+ }
66
+ }
67
+
17
68
  export default function (pi: ExtensionAPI): void {
18
69
  pi.registerEntryRenderer(AGENT_SUMMARY_ENTRY_TYPE, (entry, _options, theme) => {
19
- const line = summaryMarkdown(entry.data as AgentSummaryData, {
20
- success: theme.getFgAnsi("success"),
21
- failed: theme.getFgAnsi("error"),
22
- });
23
- if (!line) return undefined;
24
- return new Markdown(line, 1, 0, getMarkdownTheme());
70
+ const segments = summarySegments(entry.data as AgentSummaryData);
71
+ if (segments.length === 0) return undefined;
72
+ const duration = formatDuration((entry.data as AgentSummaryData).durationMs);
73
+ return new AgentSummaryLine(segments, duration, theme as unknown as SummaryTheme);
25
74
  });
26
75
 
27
76
  bindAgentSummary(pi, (data) => {
@@ -41,6 +41,8 @@ type AssistantMessageComponentLike = InstanceType<typeof AssistantMessageCompone
41
41
  export type CompactThinkingConfig = {
42
42
  useSummaryTitlesAsThinkingTitle: boolean;
43
43
  previewLines: number;
44
+ /** 思考完成后的折叠预览行数;null = 跟随 previewLines(保持旧行为)。 */
45
+ completedPreviewLines: number | null;
44
46
  animationIntervalMs: number;
45
47
  };
46
48
 
@@ -112,6 +114,7 @@ type PatchedPrototype = typeof AssistantMessageComponent.prototype & {
112
114
  const config: CompactThinkingConfig = {
113
115
  useSummaryTitlesAsThinkingTitle: true,
114
116
  previewLines: 3,
117
+ completedPreviewLines: null,
115
118
  animationIntervalMs: 90,
116
119
  };
117
120
 
@@ -273,11 +276,12 @@ function layoutThinkingPreview(
273
276
  text: string,
274
277
  width: number,
275
278
  padding: number,
279
+ previewLines: number,
276
280
  ): { visible: string[]; hiddenLines: number } {
277
- if (!text || config.previewLines <= 0) return { visible: [], hiddenLines: 0 };
281
+ if (!text || previewLines <= 0) return { visible: [], hiddenLines: 0 };
278
282
  const contentWidth = Math.max(1, width - padding * 2);
279
283
  const budget = Math.max(
280
- width * (config.previewLines + PREVIEW_BUDGET_SLACK_LINES),
284
+ width * (previewLines + PREVIEW_BUDGET_SLACK_LINES),
281
285
  PREVIEW_BUDGET_MIN_CHARS,
282
286
  );
283
287
  let source = text;
@@ -298,8 +302,8 @@ function layoutThinkingPreview(
298
302
  };
299
303
  cachePreview(cacheKey, entry);
300
304
  }
301
- const hiddenLines = entry.hiddenBefore + Math.max(0, entry.lines.length - config.previewLines);
302
- const visible = hiddenLines > 0 ? entry.lines.slice(-config.previewLines) : entry.lines;
305
+ const hiddenLines = entry.hiddenBefore + Math.max(0, entry.lines.length - previewLines);
306
+ const visible = hiddenLines > 0 ? entry.lines.slice(-previewLines) : entry.lines;
303
307
  return { visible, hiddenLines };
304
308
  }
305
309
 
@@ -335,6 +339,8 @@ export class ThinkingPreviewBlock implements Component {
335
339
  private style: (text: string) => string;
336
340
  private theme: Theme | undefined;
337
341
  private hintHovered = false;
342
+ /** 构造时的活动态:活动块用 previewLines,完成块用 completedPreviewLines。 */
343
+ private active: boolean;
338
344
  private collapsedMemo:
339
345
  | {
340
346
  width: number;
@@ -351,8 +357,9 @@ export class ThinkingPreviewBlock implements Component {
351
357
  padding: number,
352
358
  messageTimestamp: number,
353
359
  style: (text: string) => string,
354
- theme?: Theme,
355
- runStartIndex = 0,
360
+ theme: Theme | undefined,
361
+ runStartIndex: number,
362
+ active: boolean,
356
363
  ) {
357
364
  this.heading = heading;
358
365
  this.text = text;
@@ -361,6 +368,14 @@ export class ThinkingPreviewBlock implements Component {
361
368
  this.runStartIndex = runStartIndex;
362
369
  this.style = style;
363
370
  this.theme = theme;
371
+ this.active = active;
372
+ }
373
+
374
+ /** 活动块用 previewLines;完成块用 completedPreviewLines(null 跟随 previewLines)。 */
375
+ private effectivePreviewLines(): number {
376
+ return this.active
377
+ ? config.previewLines
378
+ : (config.completedPreviewLines ?? config.previewLines);
364
379
  }
365
380
 
366
381
  private paint(color: string, text: string): string {
@@ -393,7 +408,7 @@ export class ThinkingPreviewBlock implements Component {
393
408
  private headingLines(width: number, hiddenLines: number, padding: number): string[] {
394
409
  const hint = this.expanded
395
410
  ? undefined
396
- : hiddenPreviewHint(hiddenLines, Boolean(this.text) && config.previewLines <= 0);
411
+ : hiddenPreviewHint(hiddenLines, Boolean(this.text) && this.effectivePreviewLines() <= 0);
397
412
  if (!hint) return new Text(this.heading, padding, 0).render(width);
398
413
  const rawHint = hint.prefix + hint.action + hint.suffix;
399
414
  const contentWidth = Math.max(1, width - padding * 2);
@@ -411,7 +426,7 @@ export class ThinkingPreviewBlock implements Component {
411
426
  }
412
427
 
413
428
  private bodyLines(width: number, padding: number): { lines: string[]; hiddenLines: number } {
414
- if (!this.text || (config.previewLines <= 0 && !this.expanded)) {
429
+ if (!this.text || (this.effectivePreviewLines() <= 0 && !this.expanded)) {
415
430
  return { lines: [], hiddenLines: 0 };
416
431
  }
417
432
  if (this.expanded) {
@@ -420,7 +435,7 @@ export class ThinkingPreviewBlock implements Component {
420
435
  hiddenLines: 0,
421
436
  };
422
437
  }
423
- const preview = layoutThinkingPreview(this.text, width, padding);
438
+ const preview = layoutThinkingPreview(this.text, width, padding, this.effectivePreviewLines());
424
439
  return { lines: preview.visible, hiddenLines: preview.hiddenLines };
425
440
  }
426
441
 
@@ -447,7 +462,7 @@ export class ThinkingPreviewBlock implements Component {
447
462
  const expandAction = thinkingExpandAction();
448
463
  if (
449
464
  this.collapsedMemo?.width === width &&
450
- this.collapsedMemo.previewLines === config.previewLines &&
465
+ this.collapsedMemo.previewLines === this.effectivePreviewLines() &&
451
466
  this.collapsedMemo.hintHovered === this.hintHovered &&
452
467
  this.collapsedMemo.expandAction === expandAction
453
468
  ) {
@@ -464,7 +479,7 @@ export class ThinkingPreviewBlock implements Component {
464
479
  : heading;
465
480
  this.collapsedMemo = {
466
481
  width,
467
- previewLines: config.previewLines,
482
+ previewLines: this.effectivePreviewLines(),
468
483
  hintHovered: this.hintHovered,
469
484
  expandAction,
470
485
  lines,
@@ -715,6 +730,8 @@ function compactThinking(pi: ExtensionAPI) {
715
730
  }
716
731
  const runEndIndex = i - 1;
717
732
  i--;
733
+ // Keep this run-scoped snapshot: a timestamp-only render query would mark
734
+ // earlier thinking runs active when one message alternates text and thinking.
718
735
  const active = isActiveRun(message, runStartIndex, runEndIndex);
719
736
  // OpenAI can spend several seconds reasoning before it emits the first
720
737
  // summary token. Keep an empty active block visible as animated
@@ -759,6 +776,7 @@ function compactThinking(pi: ExtensionAPI) {
759
776
  thinkingStyle,
760
777
  activeTheme,
761
778
  runStartIndex,
779
+ active,
762
780
  ),
763
781
  );
764
782
 
@@ -13,6 +13,8 @@ export const FOOTER_CONTEXT_KEY = "context";
13
13
  export const FOOTER_CACHE_KEY = "cache";
14
14
  export const FOOTER_RATE_KEY = "rate";
15
15
  export const FOOTER_COST_KEY = "cost";
16
+ /** 本次对话累计消耗 token(累加会话条目的 usage.totalTokens)。 */
17
+ export const FOOTER_TOKENS_KEY = "tokens";
16
18
  export const FOOTER_CWD_KEY = "cwd";
17
19
  export const FOOTER_GIT_KEY = "git";
18
20
 
@@ -23,6 +25,7 @@ export const DEFAULT_FOOTER_LINE1_KEYS = [
23
25
  FOOTER_CACHE_KEY,
24
26
  FOOTER_RATE_KEY,
25
27
  FOOTER_COST_KEY,
28
+ FOOTER_TOKENS_KEY,
26
29
  PI_USAGE_KEY,
27
30
  ] as const;
28
31
 
@@ -40,7 +43,18 @@ const LEGACY_FIXED_FOOTER_KEYS = [
40
43
  FOOTER_GIT_KEY,
41
44
  ] as const;
42
45
 
43
- const BUILTIN_FOOTER_KEYS = new Set<string>(LEGACY_FIXED_FOOTER_KEYS);
46
+ /**
47
+ * 后加的内置芯片:老配置里不会出现,读取时补到默认行上 `after` 那个芯片后面。
48
+ * 与 LEGACY_FIXED_FOOTER_KEYS 分开,旧配置的「只排插件芯片」迁移判断才不会误判。
49
+ */
50
+ const ADDED_FOOTER_KEYS: ReadonlyArray<{ key: string; after: string }> = [
51
+ { key: FOOTER_TOKENS_KEY, after: FOOTER_COST_KEY },
52
+ ];
53
+
54
+ const BUILTIN_FOOTER_KEYS = new Set<string>([
55
+ ...LEGACY_FIXED_FOOTER_KEYS,
56
+ ...ADDED_FOOTER_KEYS.map((item) => item.key),
57
+ ]);
44
58
 
45
59
  export function isBuiltinFooterKey(key: string): boolean {
46
60
  return BUILTIN_FOOTER_KEYS.has(key);
@@ -62,9 +76,12 @@ export const DEFAULT_FOOTER_CHIP_LAYOUT: FooterChipLayout = {
62
76
  footerLine3Keys: [],
63
77
  };
64
78
 
65
- /** 别的扩展写的 model 状态与本扩展的模型芯片重名,不当插件芯片接纳。配置里的 model 不受影响。 */
79
+ /**
80
+ * 别的扩展写的 model / tokens 状态与本扩展的内置芯片重名,不当插件芯片接纳。
81
+ * 配置里的同名内置 key 不受影响。
82
+ */
66
83
  export function isSkippedFooterStatusKey(key: string): boolean {
67
- return key === FOOTER_MODEL_KEY;
84
+ return key === FOOTER_MODEL_KEY || key === FOOTER_TOKENS_KEY;
68
85
  }
69
86
 
70
87
  /** 未单独配置时的默认行:内置项按原来的行,usage 类在 line1,其余 line2。不会默认进 line3。 */
@@ -113,7 +130,10 @@ function ensureBuiltinKeys(
113
130
  if (LEGACY_FIXED_FOOTER_KEYS.some((key) => seen.has(key))) {
114
131
  return { footerLine1Keys: line1, footerLine2Keys: line2, footerLine3Keys: line3 };
115
132
  }
116
- const line1Builtins = DEFAULT_FOOTER_LINE1_KEYS.filter((key) => key !== PI_USAGE_KEY);
133
+ // tokens 属于后加芯片,由 ensureAddedBuiltins 负责插入。
134
+ const line1Builtins = DEFAULT_FOOTER_LINE1_KEYS.filter(
135
+ (key) => key !== PI_USAGE_KEY && key !== FOOTER_TOKENS_KEY,
136
+ );
117
137
  const usageAt = line1.indexOf(PI_USAGE_KEY);
118
138
  const footerLine1Keys =
119
139
  usageAt >= 0
@@ -126,6 +146,33 @@ function ensureBuiltinKeys(
126
146
  };
127
147
  }
128
148
 
149
+ function ensureAddedBuiltins(layout: FooterChipLayout): FooterChipLayout {
150
+ const present = new Set([
151
+ ...layout.footerLine1Keys,
152
+ ...layout.footerLine2Keys,
153
+ ...layout.footerLine3Keys,
154
+ ...layout.footerHiddenKeys,
155
+ ]);
156
+ const missing = ADDED_FOOTER_KEYS.filter((item) => !present.has(item.key));
157
+ if (missing.length === 0) return layout;
158
+ const next: FooterChipLayout = {
159
+ ...layout,
160
+ footerLine1Keys: [...layout.footerLine1Keys],
161
+ footerLine2Keys: [...layout.footerLine2Keys],
162
+ footerLine3Keys: [...layout.footerLine3Keys],
163
+ };
164
+ for (const item of missing) {
165
+ // 贴着锚点芯片所在的行放(如 tokens 跟 cost)。
166
+ const line = footerLineOfKey(next, item.after) ?? defaultFooterLine(item.key);
167
+ const keys = keysOnLine(next, line);
168
+ const anchorAt = keys.indexOf(item.after);
169
+ // 锚点被用户删掉时接到该行末尾:芯片留在布局里,面板菜单与开关才管得到。
170
+ // 默认关闭,不渲染就不占位,多出来的 key 不会让底栏多一行。
171
+ keys.splice(anchorAt >= 0 ? anchorAt + 1 : keys.length, 0, item.key);
172
+ }
173
+ return next;
174
+ }
175
+
129
176
  /** 跨行去重(line1 → line2 → line3);旧配置补上内置芯片。 */
130
177
  export function normalizeFooterChipLayout(source: Record<string, unknown>): FooterChipLayout {
131
178
  const hasHidden = Array.isArray(source.footerHiddenKeys);
@@ -144,10 +191,10 @@ export function normalizeFooterChipLayout(source: Record<string, unknown>): Foot
144
191
  const line1 = takeUnique(normalizeFooterKeyList(source.footerLine1Keys), seen);
145
192
  const line2 = takeUnique(normalizeFooterKeyList(source.footerLine2Keys), seen);
146
193
  const line3 = takeUnique(normalizeFooterKeyList(source.footerLine3Keys), seen);
147
- return {
194
+ return ensureAddedBuiltins({
148
195
  footerHiddenKeys: normalizeFooterKeyList(source.footerHiddenKeys),
149
196
  ...ensureBuiltinKeys(line1, line2, line3),
150
- };
197
+ });
151
198
  }
152
199
 
153
200
  const BUILTIN_FOOTER_LABEL: Record<string, string> = {
@@ -156,6 +203,7 @@ const BUILTIN_FOOTER_LABEL: Record<string, string> = {
156
203
  [FOOTER_CACHE_KEY]: "Cache hit rate",
157
204
  [FOOTER_RATE_KEY]: "Output rate",
158
205
  [FOOTER_COST_KEY]: "Session cost",
206
+ [FOOTER_TOKENS_KEY]: "Tokens used in this conversation",
159
207
  [FOOTER_CWD_KEY]: "Working directory and session name",
160
208
  [FOOTER_GIT_KEY]: "Branch and change stats",
161
209
  };