@each1024/pi-mini-mode 1.3.11 → 1.3.13
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 +4 -3
- package/README.zh-CN.md +4 -3
- package/extensions/footer-status.ts +231 -117
- package/lib/agent-view.ts +11 -11
- package/lib/file-links.ts +1 -1
- package/lib/minimal-markdown.ts +32 -5
- package/lib/minimal-theme.ts +4 -3
- package/lib/settings-web.ts +119 -0
- package/lib/settings.html +180 -0
- package/lib/sticky-tool.ts +1 -1
- package/lib/transcript-adapter.ts +14 -10
- package/package.json +2 -2
- package/themes/cc-dark.json +1 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { AGENT_STATUS_ENTRY, savedAgentStatuses, retainAgentStatuses, agentChildren, agentCall, agentCallDisplay, agentStatusesByTurn, attachAgentWidgets, isAgentTool, liveAgentView, readAgentStatuses, runningGlyph, type AgentCall } from "../lib/agent-view.ts";
|
|
2
|
-
import { CONFIG_DIR_NAME,
|
|
2
|
+
import { CONFIG_DIR_NAME, getAgentDir, getMarkdownTheme, SettingsManager, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
3
|
import { attachTranscript, type NoticeRows, type TurnNotices } from "../lib/transcript-adapter.ts";
|
|
4
|
-
import { diagramMarkdown, isFencedMarkdown,
|
|
4
|
+
import { diagramMarkdown, isFencedMarkdown, renderMinimalMarkdown } from "../lib/minimal-markdown.ts";
|
|
5
5
|
import { minimalSurface, paintExpandedHeading } from "../lib/minimal-theme.ts";
|
|
6
|
-
import {
|
|
6
|
+
import { Markdown, matchesKey, isKeyRelease, isKeyRepeat, sliceByColumn, type SettingItem, Text, type TuiMouseEvent, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
7
7
|
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
8
8
|
import type { InputEnhancementsCleanup } from "../lib/input-enhancements.ts";
|
|
9
9
|
import { linkMessageFiles } from "../lib/file-links.ts";
|
|
10
10
|
import { homedir } from "node:os";
|
|
11
11
|
import { stripVTControlCharacters } from "node:util";
|
|
12
|
-
import { dirname, join } from "node:path";
|
|
12
|
+
import { basename, dirname, join } from "node:path";
|
|
13
13
|
import attachFooterTidy from "../lib/footer-tidy.ts";
|
|
14
14
|
import attachTitlePlain from "../lib/title-plain.ts";
|
|
15
15
|
|
|
@@ -18,6 +18,8 @@ export const SETTINGS_FILE_NAME = "pi-mini-mode.json";
|
|
|
18
18
|
export interface MiniLensSettings {
|
|
19
19
|
"pi-mini-mode-model-show": boolean;
|
|
20
20
|
"pi-mini-mode-thinking-show": boolean;
|
|
21
|
+
"pi-mini-mode-project-branch-show": boolean;
|
|
22
|
+
"pi-mini-mode-branch-show": boolean;
|
|
21
23
|
"pi-mini-mode-ch-show": boolean;
|
|
22
24
|
"pi-mini-mode-session-tokens-show": boolean;
|
|
23
25
|
"pi-mini-mode-cache-tokens-show": boolean;
|
|
@@ -37,11 +39,14 @@ export interface MiniLensSettings {
|
|
|
37
39
|
"pi-mini-mode-agent-usage-show": boolean;
|
|
38
40
|
"pi-mini-mode-agent-shortcut-show": boolean;
|
|
39
41
|
onboardingCompleted: boolean;
|
|
42
|
+
footerOrder?: string[];
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
export const DEFAULT_SETTINGS: Readonly<MiniLensSettings> = {
|
|
43
46
|
"pi-mini-mode-model-show": true,
|
|
44
47
|
"pi-mini-mode-thinking-show": true,
|
|
48
|
+
"pi-mini-mode-project-branch-show": true,
|
|
49
|
+
"pi-mini-mode-branch-show": false,
|
|
45
50
|
"pi-mini-mode-ch-show": true,
|
|
46
51
|
"pi-mini-mode-session-tokens-show": true,
|
|
47
52
|
"pi-mini-mode-cache-tokens-show": true,
|
|
@@ -63,7 +68,8 @@ export const DEFAULT_SETTINGS: Readonly<MiniLensSettings> = {
|
|
|
63
68
|
onboardingCompleted: false,
|
|
64
69
|
};
|
|
65
70
|
|
|
66
|
-
const SETTING_IDS = Object.keys(DEFAULT_SETTINGS) as Array<keyof MiniLensSettings
|
|
71
|
+
const SETTING_IDS = Object.keys(DEFAULT_SETTINGS) as Array<Exclude<keyof MiniLensSettings, "footerOrder">>;
|
|
72
|
+
export const FOOTER_FIELDS = ["project-branch", "model", "thinking", "branch", "session-tokens", "cache-tokens", "ch", "cost", "mcp", "context", "context-percent", "speed"] as const;
|
|
67
73
|
|
|
68
74
|
const COPY = {
|
|
69
75
|
title: "Pi Mini Mode 设置", preview: "预览(示例数据)", lens: "设置", minimal: "极简输出",
|
|
@@ -71,9 +77,12 @@ const COPY = {
|
|
|
71
77
|
totalDescription: "Total:当前会话分支上的全部 token,含工具上报的 LLM 用量。", cachedDescription: "Cached:累计 cache-read + cache-write token(包含在 Total 中)。", cacheHitDescription: "CH(cache hit):cache-read / (input + cache-read)。Cache write 不计入此比率。",
|
|
72
78
|
enableMinimalDescription: "开启统一折叠思考、工具和技能过程;关闭恢复 Pi 默认会话历史。",
|
|
73
79
|
inputEnhancementsDescription: "原生 Ctrl+V 粘贴图片(Windows/WSL:Alt+V);图片显示为 [image1] 标签,光标移入或全屏悬停可预览。空白后 / 选择技能并在光标处插入。Cmd+点击带下划线的图片标签或消息文件路径,用系统默认应用打开;预览及点击需终端支持。关闭仅恢复原生行为。",
|
|
74
|
-
tuiRequired: "/pi-mini-mode-settings 需要 TUI 模式", saveFailed: "无法保存 Pi Mini Mode 设置", minimalRequired: "/pi-mini-mode-minimal 需要 TUI 模式", minimalUsage: "用法:/pi-mini-mode-minimal [on|off]", minimalState: "Pi Mini Mode 极简输出:", onboarding: "MCP
|
|
80
|
+
tuiRequired: "/pi-mini-mode-settings 需要 TUI 模式", saveFailed: "无法保存 Pi Mini Mode 设置", minimalRequired: "/pi-mini-mode-minimal 需要 TUI 模式", minimalUsage: "用法:/pi-mini-mode-minimal [on|off]", minimalState: "Pi Mini Mode 极简输出:", onboarding: "MCP 数量、点阵样式和仅显示分支默认关闭;项目名称和分支默认开启,与仅显示分支互斥。", keepDefaults: "保留默认", configureNow: "立即配置", applyRecommended: "应用推荐配置", chooseTheme: "选择 Pi Mini Mode 主题(将保存全局主题和全屏模式;重启后生效)", themeSaved: "已保存推荐主题和全屏模式。请重启 Pi;项目设置或命令行参数可能覆盖全局设置。", themeSaveFailed: "无法保存推荐的 Pi 主题和全屏模式;未完成首次配置。", themeApplyFailed: "推荐设置已保存,但当前主题未能立即应用;请重启 Pi。",
|
|
75
81
|
} as const;
|
|
76
82
|
|
|
83
|
+
const RECOMMENDED_THEMES = ["cc-dark", "cc-light"] as const;
|
|
84
|
+
type RecommendedTheme = typeof RECOMMENDED_THEMES[number];
|
|
85
|
+
|
|
77
86
|
export function settingsPath(agentDir = process.env.PI_MINI_MODE_AGENT_DIR ?? join(homedir(), CONFIG_DIR_NAME, "agent")): string {
|
|
78
87
|
return join(agentDir, SETTINGS_FILE_NAME);
|
|
79
88
|
}
|
|
@@ -88,6 +97,12 @@ export function parseSettings(value: unknown): MiniLensSettings {
|
|
|
88
97
|
for (const id of SETTING_IDS) {
|
|
89
98
|
if (isBoolean(candidate[id])) settings[id] = candidate[id];
|
|
90
99
|
}
|
|
100
|
+
if (Array.isArray(candidate.footerOrder)) {
|
|
101
|
+
settings.footerOrder = [...new Set(candidate.footerOrder.filter((id): id is typeof FOOTER_FIELDS[number] =>
|
|
102
|
+
typeof id === "string" && (FOOTER_FIELDS as readonly string[]).includes(id)))];
|
|
103
|
+
for (const id of FOOTER_FIELDS) if (!settings.footerOrder.includes(id)) settings.footerOrder.push(id);
|
|
104
|
+
}
|
|
105
|
+
if (settings["pi-mini-mode-branch-show"]) settings["pi-mini-mode-project-branch-show"] = false;
|
|
91
106
|
// 折叠回复的旧细项已合并进极简输出总开关:旧值不再暗中过滤内容,始终按默认全开。
|
|
92
107
|
for (const id of LEGACY_MINIMAL_SETTING_IDS) settings[id] = true;
|
|
93
108
|
return settings;
|
|
@@ -248,6 +263,11 @@ function plannotatorPlanTag(statuses: ReadonlyMap<string, string> | undefined):
|
|
|
248
263
|
return isPlannotatorPlanningStatus(text) ? planCapsule() : "";
|
|
249
264
|
}
|
|
250
265
|
|
|
266
|
+
function progressBar(percent: number, dots: boolean, width: number): string {
|
|
267
|
+
const filled = Math.round(width * Math.max(0, Math.min(100, percent)) / 100);
|
|
268
|
+
return (dots ? "⣿" : "█").repeat(filled) + (dots ? "⣀" : "░").repeat(width - filled);
|
|
269
|
+
}
|
|
270
|
+
|
|
251
271
|
function renderRight(
|
|
252
272
|
theme: ExtensionContext["ui"]["theme"],
|
|
253
273
|
settings: MiniLensSettings,
|
|
@@ -267,6 +287,7 @@ function renderRight(
|
|
|
267
287
|
}
|
|
268
288
|
|
|
269
289
|
const SETTINGS_PREVIEW_CONTEXT = {
|
|
290
|
+
cwd: "/work/pi-mini-mode",
|
|
270
291
|
model: { id: "deepseek-v4-flash" },
|
|
271
292
|
thinkingLevel: "high",
|
|
272
293
|
getContextUsage: () => ({ tokens: 500, contextWindow: 1_000_000, percent: 1 }),
|
|
@@ -287,7 +308,7 @@ export function settingsPreviewLine(
|
|
|
287
308
|
width = 140,
|
|
288
309
|
highlighted?: keyof MiniLensSettings,
|
|
289
310
|
): string {
|
|
290
|
-
return statusLine(SETTINGS_PREVIEW_CONTEXT, theme, width, SETTINGS_PREVIEW_USAGE, settings, 120, highlighted, 3);
|
|
311
|
+
return statusLine(SETTINGS_PREVIEW_CONTEXT, theme, width, SETTINGS_PREVIEW_USAGE, settings, 120, highlighted, 3, undefined, "main");
|
|
291
312
|
}
|
|
292
313
|
|
|
293
314
|
export function statusLine(
|
|
@@ -300,6 +321,7 @@ export function statusLine(
|
|
|
300
321
|
highlighted?: keyof MiniLensSettings,
|
|
301
322
|
mcpCount?: number,
|
|
302
323
|
statuses?: ReadonlyMap<string, string>,
|
|
324
|
+
gitBranch?: string | null,
|
|
303
325
|
): string {
|
|
304
326
|
if (highlighted === "pi-mini-mode-context-dots-show") highlighted = "pi-mini-mode-context-show";
|
|
305
327
|
const field = (id: keyof MiniLensSettings, color: Parameters<typeof theme.fg>[0], text: string) =>
|
|
@@ -321,7 +343,33 @@ export function statusLine(
|
|
|
321
343
|
const showContext = settings["pi-mini-mode-context-show"] && Boolean(tokenText);
|
|
322
344
|
const mcpText = settings["pi-mini-mode-mcp-show"] && mcpCount !== undefined ? `◇ MCP ${mcpCount}` : "";
|
|
323
345
|
const planTag = plannotatorPlanTag(statuses);
|
|
346
|
+
const branchOnly = settings["pi-mini-mode-branch-show"];
|
|
347
|
+
const branchSetting = branchOnly ? "pi-mini-mode-branch-show" : "pi-mini-mode-project-branch-show";
|
|
348
|
+
const branchText = gitBranch && settings[branchSetting]
|
|
349
|
+
? stripVTControlCharacters(branchOnly ? gitBranch : `${basename(ctx.cwd)}(${gitBranch})`).replace(/[\x00-\x1f\x7f-\x9f]/g, "") : "";
|
|
324
350
|
|
|
351
|
+
if (settings.footerOrder) {
|
|
352
|
+
const values: Record<string, string> = {
|
|
353
|
+
"project-branch": !branchOnly ? branchText : "", branch: branchOnly ? branchText : "",
|
|
354
|
+
model, thinking,
|
|
355
|
+
"session-tokens": usageTotals.totalTokens > 0 ? `${COPY.totalLabel} ${formatTokens(usageTotals.totalTokens)}` : "",
|
|
356
|
+
"cache-tokens": cachedTokens > 0 ? `${COPY.cachedLabel} ${formatTokens(cachedTokens)}` : "",
|
|
357
|
+
ch: hitText, cost: price, mcp: mcpText,
|
|
358
|
+
context: tokenText,
|
|
359
|
+
"context-percent": percentText, speed: speed === undefined ? "" : formatSpeed(speed, settings["pi-mini-mode-speed-unit-show"]),
|
|
360
|
+
};
|
|
361
|
+
const visible = settings.footerOrder.filter(id => settings[`pi-mini-mode-${id}-show` as keyof MiniLensSettings] && values[id]);
|
|
362
|
+
const usedWidth = visibleWidth([planTag, ...visible.map(id => values[id])].filter(Boolean).join(" "));
|
|
363
|
+
const barWidth = Math.max(0, width - usedWidth - 1);
|
|
364
|
+
if (visible.includes("context") && percent !== undefined && barWidth > 0) {
|
|
365
|
+
values.context += ` ${progressBar(percent, settings["pi-mini-mode-context-dots-show"], barWidth)}`;
|
|
366
|
+
}
|
|
367
|
+
return truncateToWidth([planTag, ...settings.footerOrder.map(id => {
|
|
368
|
+
const key = `pi-mini-mode-${id}-show` as keyof MiniLensSettings;
|
|
369
|
+
const color = id === "speed" ? speedColor(speed) : id === "model" || id === "context-percent" ? "accent" : "muted";
|
|
370
|
+
return settings[key] && values[id] ? field(key, color, values[id]) : "";
|
|
371
|
+
})].filter(Boolean).join(" "), width, "…");
|
|
372
|
+
}
|
|
325
373
|
const right = renderRight(theme, settings, percentText, speed, highlighted);
|
|
326
374
|
const rightWidth = visibleWidth(right);
|
|
327
375
|
if (right && width <= rightWidth) {
|
|
@@ -333,8 +381,10 @@ export function statusLine(
|
|
|
333
381
|
|
|
334
382
|
const leftParts = [
|
|
335
383
|
planTag,
|
|
384
|
+
!branchOnly && branchText && field(branchSetting, "muted", branchText),
|
|
336
385
|
settings["pi-mini-mode-model-show"] && model && field("pi-mini-mode-model-show", "accent", model),
|
|
337
386
|
settings["pi-mini-mode-thinking-show"] && thinking && field("pi-mini-mode-thinking-show", "muted", thinking),
|
|
387
|
+
branchOnly && branchText && field(branchSetting, "muted", branchText),
|
|
338
388
|
settings["pi-mini-mode-session-tokens-show"] && usageTotals.totalTokens > 0 && field("pi-mini-mode-session-tokens-show", "text", `${COPY.totalLabel} ${formatTokens(usageTotals.totalTokens)}`),
|
|
339
389
|
settings["pi-mini-mode-cache-tokens-show"] && cachedTokens > 0 && field("pi-mini-mode-cache-tokens-show", "text", `${COPY.cachedLabel} ${formatTokens(cachedTokens)}`),
|
|
340
390
|
settings["pi-mini-mode-ch-show"] && hitText && field("pi-mini-mode-ch-show", "text", hitText),
|
|
@@ -343,8 +393,10 @@ export function statusLine(
|
|
|
343
393
|
].filter((part): part is string => Boolean(part));
|
|
344
394
|
const unstyledLeft = [
|
|
345
395
|
planTag && stripVTControlCharacters(planTag),
|
|
396
|
+
!branchOnly && branchText,
|
|
346
397
|
settings["pi-mini-mode-model-show"] && model,
|
|
347
398
|
settings["pi-mini-mode-thinking-show"] && thinking,
|
|
399
|
+
branchOnly && branchText,
|
|
348
400
|
settings["pi-mini-mode-session-tokens-show"] && usageTotals.totalTokens > 0 && `${COPY.totalLabel} ${formatTokens(usageTotals.totalTokens)}`,
|
|
349
401
|
settings["pi-mini-mode-cache-tokens-show"] && cachedTokens > 0 && `${COPY.cachedLabel} ${formatTokens(cachedTokens)}`,
|
|
350
402
|
settings["pi-mini-mode-ch-show"] && hitText,
|
|
@@ -380,20 +432,15 @@ const LEGACY_MINIMAL_SETTING_IDS = [
|
|
|
380
432
|
"pi-mini-mode-minimal-skills-show", "pi-mini-mode-agent-usage-show", "pi-mini-mode-agent-shortcut-show",
|
|
381
433
|
] as const satisfies ReadonlyArray<keyof MiniLensSettings>;
|
|
382
434
|
|
|
383
|
-
/** 模式总开关:设置列表顶部只展示这两项,旧细分项不再展示但仍保留兼容。 */
|
|
384
|
-
const MODE_SETTING_IDS = ["pi-mini-mode-minimal-show", "pi-mini-mode-input-enhancements"] as const;
|
|
385
|
-
|
|
386
|
-
function isModeSetting(id: string): boolean {
|
|
387
|
-
return (MODE_SETTING_IDS as readonly string[]).includes(id);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
435
|
export function isCollapsedReplyChildSetting(id: string): boolean {
|
|
391
436
|
return (LEGACY_MINIMAL_SETTING_IDS as readonly string[]).includes(id);
|
|
392
437
|
}
|
|
393
438
|
|
|
394
439
|
export function settingsItems(settings: MiniLensSettings): SettingItem[] {
|
|
395
440
|
const values = ["on", "off"];
|
|
396
|
-
const labels: Record<Exclude<keyof MiniLensSettings, "onboardingCompleted">, string> = {
|
|
441
|
+
const labels: Record<Exclude<keyof MiniLensSettings, "onboardingCompleted" | "footerOrder">, string> = {
|
|
442
|
+
"pi-mini-mode-project-branch-show": "显示项目名称和分支(互斥)",
|
|
443
|
+
"pi-mini-mode-branch-show": "仅显示分支(思考等级后,互斥)",
|
|
397
444
|
"pi-mini-mode-model-show": COPY.model, "pi-mini-mode-thinking-show": COPY.thinking, "pi-mini-mode-session-tokens-show": COPY.total, "pi-mini-mode-cache-tokens-show": COPY.cached, "pi-mini-mode-ch-show": COPY.cacheHit, "pi-mini-mode-cost-show": COPY.price, "pi-mini-mode-mcp-show": COPY.mcp, "pi-mini-mode-context-show": COPY.context, "pi-mini-mode-context-dots-show": COPY.dots, "pi-mini-mode-context-percent-show": COPY.percent, "pi-mini-mode-speed-show": COPY.speed, "pi-mini-mode-speed-unit-show": COPY.speedUnit, "pi-mini-mode-minimal-show": COPY.minimal, "pi-mini-mode-input-enhancements": COPY.inputEnhancements, "pi-mini-mode-minimal-thinking-show": COPY.showThinking, "pi-mini-mode-minimal-tools-show": COPY.tools, "pi-mini-mode-minimal-output-show": COPY.output, "pi-mini-mode-minimal-skills-show": COPY.skills, "pi-mini-mode-agent-usage-show": COPY.agentUsage, "pi-mini-mode-agent-shortcut-show": COPY.shortcut,
|
|
398
445
|
};
|
|
399
446
|
return (Object.keys(labels) as Array<keyof typeof labels>).map((id) => ({
|
|
@@ -404,16 +451,23 @@ export function settingsItems(settings: MiniLensSettings): SettingItem[] {
|
|
|
404
451
|
}
|
|
405
452
|
|
|
406
453
|
interface ActiveGeneration {
|
|
407
|
-
|
|
454
|
+
firstTokenAt?: number;
|
|
408
455
|
output: number;
|
|
409
456
|
lastSampleAt: number;
|
|
410
457
|
}
|
|
411
458
|
|
|
412
|
-
|
|
459
|
+
/** Hide sub-100ms bursts (batched usage) and 1-token completions; they are not a decode rate. */
|
|
460
|
+
export const DECODE_SPEED_MIN_ELAPSED_MS = 100;
|
|
461
|
+
export const DECODE_SPEED_MIN_OUTPUT = 2;
|
|
462
|
+
|
|
463
|
+
/** Decode TPS: provider `usage.output` / seconds after the first output token (excludes TTFT). */
|
|
464
|
+
export function outputSpeed(output: unknown, firstTokenAt: number | undefined, endedAt = Date.now()): number | undefined {
|
|
413
465
|
const tokenCount = finiteNumber(output);
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
466
|
+
if (firstTokenAt === undefined || tokenCount === undefined || tokenCount < DECODE_SPEED_MIN_OUTPUT) return undefined;
|
|
467
|
+
const elapsedMs = endedAt - firstTokenAt;
|
|
468
|
+
if (elapsedMs < DECODE_SPEED_MIN_ELAPSED_MS) return undefined;
|
|
469
|
+
const rate = tokenCount / (elapsedMs / 1_000);
|
|
470
|
+
return Number.isFinite(rate) ? rate : undefined;
|
|
417
471
|
}
|
|
418
472
|
|
|
419
473
|
export interface MinimalTurn {
|
|
@@ -579,8 +633,8 @@ function visibleMinimalTurns(settings: MiniLensSettings, turns: MinimalTurn[]):
|
|
|
579
633
|
}
|
|
580
634
|
|
|
581
635
|
export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], getTurns: () => MinimalTurn[], isExpanded: () => boolean = () => false, showShortcut: (turn: MinimalTurn) => boolean = () => true, showUsage: () => boolean = () => true, subAgentsExpanded: () => boolean = () => false, agentDeadlines = new Map<string, number>(), transformText: (text: string) => string = text => text) {
|
|
582
|
-
const markdown = (text: string, width: number, process = false) =>
|
|
583
|
-
{ color: (value) => theme.fg(process ? "muted" : "text", value) },
|
|
636
|
+
const markdown = (text: string, width: number, process = false) => renderMinimalMarkdown(text, width, getMarkdownTheme(), theme.getBgAnsi?.("userMessageBg") ?? "",
|
|
637
|
+
{ color: (value) => theme.fg(process ? "muted" : "text", value) }, (source, available) => transformText(diagramMarkdown(source, available)));
|
|
584
638
|
const surface = (rows: string[], width: number, user: boolean, selected = -1, expanded = false) => {
|
|
585
639
|
const padding = Math.min(2, Math.floor((width - 1) / 2));
|
|
586
640
|
return ["", ...rows, ""].map((row, index) => {
|
|
@@ -789,19 +843,20 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
789
843
|
const body = split < 0 ? "" : text.slice(split + 1);
|
|
790
844
|
const activeThinking = entry.thinking && entry.state === "running";
|
|
791
845
|
const thinkingElapsed = entry.thinking ? theme.fg(activeThinking ? "success" : "muted", ` ${formatElapsed(turn.startedAt)}`) : "";
|
|
792
|
-
const summary = theme.fg("text", theme.bold(label)) + thinkingElapsed + " ";
|
|
793
846
|
const call = turn.agentCalls?.find(call => call.id === entry.id && !isAgentTool(call.tool ?? call.name));
|
|
794
847
|
const controlId = call?.id ?? (entry.thinking ? entry.id : "");
|
|
795
848
|
const open = call ? expandedTools.has(call.id) : !!(entry.thinking && expandedThinking.has(entry.id));
|
|
849
|
+
const identity = open ? "accent" : "text";
|
|
850
|
+
const summary = theme.fg(identity, theme.bold(label)) + thinkingElapsed + " ";
|
|
796
851
|
if (controlId && width >= 4) toolControls.push({ id: controlId, y: lines.length, width, title: text });
|
|
797
852
|
if (hoveredTool?.id === controlId && (hoveredTool.y !== lines.length || hoveredTool.width !== width)) clearHover();
|
|
798
|
-
const status = entry.state === "error" ? "
|
|
853
|
+
const status = entry.state === "error" ? "✕" : entry.state === "running" ? runningGlyph() : "●";
|
|
799
854
|
const arrow = !!controlId && (open || hoveredTool?.id === controlId);
|
|
800
855
|
const keepStatus = entry.state === "running" || (open && entry.state === "error");
|
|
801
|
-
const glyph = arrow ? (open ? "
|
|
856
|
+
const glyph = arrow ? (open ? "▼" : "▶") + (keepStatus ? ` ${status}` : "") : status;
|
|
802
857
|
const glyphColor = entry.state === "error" ? "error" : entry.state === "running" || arrow ? "accent" : "muted";
|
|
803
858
|
const last = row === shown.length - 1 && !agents.rows.length;
|
|
804
|
-
const prefix = theme.fg("dim", last ? "└─ " : "├─ ") + theme.fg(glyphColor, glyph) + " " + summary;
|
|
859
|
+
const prefix = theme.fg(open ? "accent" : "dim", last ? "└─ " : "├─ ") + theme.fg(glyphColor, glyph) + " " + summary;
|
|
805
860
|
if (activeThinking) {
|
|
806
861
|
const renderedBody = markdown(body, Math.max(1, visibleWidth(body) + 1), true).join(" ").replace(/\s+/g, " ").trim();
|
|
807
862
|
const bodyWidth = Math.max(0, width - visibleWidth(prefix));
|
|
@@ -816,18 +871,18 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
816
871
|
lines.push(truncateToWidth(prefix + (wrapped[0] ?? ""), width, ""));
|
|
817
872
|
for (const extra of wrapped.slice(1)) lines.push(truncateToWidth(rail + extra, width, ""));
|
|
818
873
|
} else {
|
|
819
|
-
lines.push(bandHeading(truncateToWidth(prefix + (entry.thinking ? markdown(body, Math.max(1, visibleWidth(body) + 1), true).join(" ").replace(/\s+/g, " ").trim() : theme.fg("muted", body)), width, controlId ? "" : "…"), open));
|
|
874
|
+
lines.push(bandHeading(truncateToWidth(prefix + (entry.thinking ? markdown(body, Math.max(1, visibleWidth(body) + 1), true).join(" ").replace(/\s+/g, " ").trim() : theme.fg(open ? "accent" : "muted", body)), width, controlId ? "" : "…"), open));
|
|
820
875
|
}
|
|
821
876
|
if (open && call && call.id === pinnedToolId) pinnedTool = { id: call.id, y: lines.length - 1, line: lines.at(-1)! };
|
|
822
877
|
if (open && call) {
|
|
823
878
|
// ponytail: saved text only; native view retains images, args and custom renderers.
|
|
824
879
|
const output = stripVTControlCharacters(call.output ?? "").replace(/\r\n?/g, "\n").replace(/[\x00-\x08\x0b-\x1f\x7f]/g, "");
|
|
825
|
-
const rail = width > 5 ? (last ? " " : theme.fg("
|
|
880
|
+
const rail = width > 5 ? (last ? " " : theme.fg("accent", "│ ")) : "";
|
|
826
881
|
const detailWidth = Math.max(1, width - visibleWidth(rail));
|
|
827
882
|
const details = new Text(output || (entry.state === "running" ? "等待工具文本结果…" : "无文本结果"), 0, 0).render(detailWidth);
|
|
828
883
|
lines.push(...details.map(line => truncateToWidth(rail + theme.fg("muted", line), width, "")));
|
|
829
884
|
} else if (open && entry.thinking) {
|
|
830
|
-
const rail = width > 5 ? (last ? " " : theme.fg("
|
|
885
|
+
const rail = width > 5 ? (last ? " " : theme.fg("accent", "│ ")) : "";
|
|
831
886
|
const detailWidth = Math.max(1, width - visibleWidth(rail));
|
|
832
887
|
lines.push(...markdown(entry.detail, detailWidth, true).map(line => truncateToWidth(rail + line, width, "")));
|
|
833
888
|
} else if (expanded && entry.state === "error" && entry.detail) {
|
|
@@ -877,7 +932,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
877
932
|
let promptView: ReturnType<typeof minimalOutputComponent> | undefined;
|
|
878
933
|
let lastAttachMode: string | undefined;
|
|
879
934
|
let remountQueued = false;
|
|
880
|
-
let
|
|
935
|
+
let settingsWeb: Awaited<ReturnType<typeof import("../lib/settings-web.ts").startSettingsWeb>> | undefined;
|
|
936
|
+
let settingsWebOpening: Promise<void> | undefined;
|
|
937
|
+
let settingsWebGeneration = 0;
|
|
881
938
|
const agentDeadlines = new Map<string, number>();
|
|
882
939
|
let minimalTurns: MinimalTurn[] = [];
|
|
883
940
|
let activeMinimalTurn: MinimalTurn | undefined;
|
|
@@ -1030,7 +1087,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1030
1087
|
restoreAgentWidgets?.();
|
|
1031
1088
|
restoreAgentWidgets = undefined;
|
|
1032
1089
|
// Settings overlay replaces the transcript; remount after it closes instead of warning.
|
|
1033
|
-
|
|
1090
|
+
ctx.ui.notify(tui.mode === "regular"
|
|
1034
1091
|
? "Minimal output needs the fullscreen renderer. Quit and restart Pi — /reload does not switch TUI mode. Or set TUI mode to fullscreen in /settings."
|
|
1035
1092
|
: "Pi transcript layout not recognized; minimal mode disabled, native output preserved.", "warning");
|
|
1036
1093
|
}
|
|
@@ -1067,7 +1124,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1067
1124
|
};
|
|
1068
1125
|
const refreshStreamingSpeed = () => {
|
|
1069
1126
|
if (!activeGeneration) return;
|
|
1070
|
-
const nextSpeed = outputSpeed(activeGeneration.output, activeGeneration.
|
|
1127
|
+
const nextSpeed = outputSpeed(activeGeneration.output, activeGeneration.firstTokenAt);
|
|
1071
1128
|
if (nextSpeed !== undefined) speed = nextSpeed;
|
|
1072
1129
|
refresh();
|
|
1073
1130
|
};
|
|
@@ -1083,72 +1140,125 @@ export default function (pi: ExtensionAPI) {
|
|
|
1083
1140
|
.catch(() => ctx.ui.notify(COPY.saveFailed, "error"));
|
|
1084
1141
|
return saveChain;
|
|
1085
1142
|
};
|
|
1086
|
-
const
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1143
|
+
const applyRecommendedHostSettings = async (ctx: ExtensionContext, themeName: RecommendedTheme): Promise<boolean> => {
|
|
1144
|
+
const theme = ctx.ui.getTheme(themeName);
|
|
1145
|
+
if (!theme) {
|
|
1146
|
+
ctx.ui.notify(`找不到主题 ${themeName};请先确认 Pi 已发现本包主题。`, "error");
|
|
1147
|
+
return false;
|
|
1090
1148
|
}
|
|
1091
|
-
settingsOverlayOpen = true;
|
|
1092
1149
|
try {
|
|
1093
|
-
|
|
1094
|
-
const
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
}
|
|
1112
|
-
const
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
const name = text.trimEnd();
|
|
1118
|
-
if (selected) highlighted = items.find((item) => item.label === name)?.id as keyof MiniLensSettings | undefined;
|
|
1119
|
-
if (selected) return theme.bg("selectedBg", theme.fg("accent", theme.bold(text)));
|
|
1120
|
-
return theme.fg("text", text);
|
|
1121
|
-
},
|
|
1122
|
-
value: (text: string, selected: boolean) =>
|
|
1123
|
-
selected ? theme.bg("selectedBg", theme.fg("accent", theme.bold(text))) : theme.fg("muted", text),
|
|
1124
|
-
};
|
|
1125
|
-
const separator: SettingItem = { id: "settings-separator", label: "────────────", currentValue: "" };
|
|
1126
|
-
const modeItems = items.filter((item) => isModeSetting(item.id));
|
|
1127
|
-
const lensItems = items.filter((item) => !isModeSetting(item.id) && !isCollapsedReplyChildSetting(item.id));
|
|
1128
|
-
const settingsList = new SettingsList([...modeItems, separator, ...lensItems], 14, settingsTheme, onChange, () => done(undefined), { enableSearch: true });
|
|
1129
|
-
container.addChild(settingsList);
|
|
1130
|
-
return {
|
|
1131
|
-
render: (width: number) => {
|
|
1132
|
-
// SettingsList exposes selection through its theme callback, including search and mouse navigation.
|
|
1133
|
-
highlighted = undefined;
|
|
1134
|
-
settingsList.render(width);
|
|
1135
|
-
preview.setText(settingsPreviewLine(theme, settings, Math.max(0, width - 2), highlighted));
|
|
1136
|
-
return container.render(width);
|
|
1137
|
-
},
|
|
1138
|
-
invalidate: () => container.invalidate(),
|
|
1139
|
-
handleMouse: (event: TuiMouseEvent) => container.handleMouse(event),
|
|
1140
|
-
handleInput: (data: string) => {
|
|
1141
|
-
settingsList.handleInput(data);
|
|
1142
|
-
tui.requestRender();
|
|
1143
|
-
},
|
|
1144
|
-
};
|
|
1145
|
-
});
|
|
1146
|
-
} finally {
|
|
1147
|
-
settingsOverlayOpen = false;
|
|
1150
|
+
const manager = SettingsManager.create(ctx.cwd, getAgentDir(), { projectTrusted: ctx.isProjectTrusted?.() ?? false });
|
|
1151
|
+
const initialErrors = manager.drainErrors();
|
|
1152
|
+
if (initialErrors.length) {
|
|
1153
|
+
ctx.ui.notify(`${COPY.themeSaveFailed} Pi 设置读取失败:${initialErrors.map(error => error.error.message).join(";")}`, "error");
|
|
1154
|
+
return false;
|
|
1155
|
+
}
|
|
1156
|
+
const projectSettings = manager.getProjectSettings();
|
|
1157
|
+
const projectOverrides = [
|
|
1158
|
+
typeof projectSettings.theme === "string" ? "主题" : undefined,
|
|
1159
|
+
projectSettings.tuiMode !== undefined ? "TUI 模式" : undefined,
|
|
1160
|
+
].filter((value): value is string => value !== undefined);
|
|
1161
|
+
manager.setTheme(themeName);
|
|
1162
|
+
manager.setTuiMode("fullscreen");
|
|
1163
|
+
await manager.flush();
|
|
1164
|
+
const errors = manager.drainErrors();
|
|
1165
|
+
if (errors.length) {
|
|
1166
|
+
ctx.ui.notify(`${COPY.themeSaveFailed} Pi 设置可能已部分保存:${errors.map(error => error.error.message).join(";")}`, "error");
|
|
1167
|
+
return false;
|
|
1168
|
+
}
|
|
1169
|
+
const applied = ctx.ui.setTheme(theme);
|
|
1170
|
+
if (!applied.success) {
|
|
1171
|
+
ctx.ui.notify(`${COPY.themeApplyFailed}${applied.error ? ` ${applied.error}` : ""}`, "warning");
|
|
1172
|
+
return false;
|
|
1173
|
+
}
|
|
1148
1174
|
mountMinimalOutput(ctx);
|
|
1175
|
+
refresh();
|
|
1176
|
+
ctx.ui.notify(projectOverrides.length
|
|
1177
|
+
? `${COPY.themeSaved} 项目设置中的${projectOverrides.join("、")}优先级更高。`
|
|
1178
|
+
: COPY.themeSaved, "info");
|
|
1179
|
+
return true;
|
|
1180
|
+
} catch (error) {
|
|
1181
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
1182
|
+
ctx.ui.notify(`${COPY.themeSaveFailed} ${detail}`, "error");
|
|
1183
|
+
return false;
|
|
1184
|
+
}
|
|
1185
|
+
};
|
|
1186
|
+
const openSettings = async (ctx: ExtensionContext) => {
|
|
1187
|
+
const generation = settingsWebGeneration;
|
|
1188
|
+
if (ctx.mode !== "tui") { ctx.ui.notify(COPY.tuiRequired, "error"); return; }
|
|
1189
|
+
try {
|
|
1190
|
+
if (settingsWeb && !settingsWeb.closed) settingsWeb.touch();
|
|
1191
|
+
else settingsWebOpening ??= (async () => {
|
|
1192
|
+
const { startSettingsWeb } = await import("../lib/settings-web.ts");
|
|
1193
|
+
const server = await startSettingsWeb(() => ({
|
|
1194
|
+
settings, defaults: DEFAULT_SETTINGS, order: FOOTER_FIELDS,
|
|
1195
|
+
items: settingsItems(settings).filter(item => !isCollapsedReplyChildSetting(item.id)),
|
|
1196
|
+
}), async value => {
|
|
1197
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("Invalid settings");
|
|
1198
|
+
const input = value as Record<string, unknown>;
|
|
1199
|
+
for (const [key, entry] of Object.entries(input)) {
|
|
1200
|
+
if (key === "footerOrder") {
|
|
1201
|
+
if (!Array.isArray(entry) || entry.length !== FOOTER_FIELDS.length || new Set(entry).size !== entry.length
|
|
1202
|
+
|| entry.some(id => !(FOOTER_FIELDS as readonly unknown[]).includes(id))) throw new TypeError("Invalid order");
|
|
1203
|
+
} else if (!SETTING_IDS.includes(key as typeof SETTING_IDS[number]) || typeof entry !== "boolean") throw new TypeError("Invalid setting");
|
|
1204
|
+
}
|
|
1205
|
+
const next = parseSettings({ ...settings, ...input, onboardingCompleted: true });
|
|
1206
|
+
await saveSettings(next, configPath);
|
|
1207
|
+
settings = next;
|
|
1208
|
+
cleanupInputEnhancements?.refresh();
|
|
1209
|
+
refresh();
|
|
1210
|
+
mountMinimalOutput(ctx);
|
|
1211
|
+
refreshMinimalOutput();
|
|
1212
|
+
}, { onClose: () => { if (settingsWeb === server) settingsWeb = undefined; } });
|
|
1213
|
+
if (generation !== settingsWebGeneration) { server.close(); return; }
|
|
1214
|
+
settingsWeb = server;
|
|
1215
|
+
})().finally(() => { if (generation === settingsWebGeneration) settingsWebOpening = undefined; });
|
|
1216
|
+
await settingsWebOpening;
|
|
1217
|
+
if (generation !== settingsWebGeneration || !settingsWeb || settingsWeb.closed) return;
|
|
1218
|
+
const url = settingsWeb.url;
|
|
1219
|
+
const result = process.platform === "darwin" ? await pi.exec("open", [url])
|
|
1220
|
+
: process.platform === "win32" ? await pi.exec("rundll32.exe", ["url.dll,FileProtocolHandler", url])
|
|
1221
|
+
: await pi.exec("xdg-open", [url]);
|
|
1222
|
+
if (result.code !== 0) ctx.ui.notify(`请在本机浏览器打开:${url}`, "warning");
|
|
1223
|
+
} catch (error) {
|
|
1224
|
+
if (!settingsWeb) settingsWebOpening = undefined;
|
|
1225
|
+
ctx.ui.notify(`无法打开设置:${error instanceof Error ? error.message : String(error)}${settingsWeb ? `\n${settingsWeb.url}` : ""}`, "error");
|
|
1149
1226
|
}
|
|
1150
1227
|
};
|
|
1151
1228
|
|
|
1229
|
+
const runOnboarding = async (ctx: ExtensionContext) => {
|
|
1230
|
+
if (ctx.mode !== "tui" || !ctx.hasUI) return;
|
|
1231
|
+
let choice: string | undefined;
|
|
1232
|
+
try {
|
|
1233
|
+
choice = await ctx.ui.select(
|
|
1234
|
+
`Pi Mini Mode ${COPY.preview}\n\n deepseek-v4-flash high ${COPY.totalLabel} 45K ${COPY.cachedLabel} 25K ${COPY.cacheHitLabel} 40.0% $0.012 500/1.0M █░░░░░░░░░ 1% 120 tok/s\n\n${COPY.onboarding}`,
|
|
1235
|
+
[COPY.keepDefaults, COPY.configureNow, COPY.applyRecommended],
|
|
1236
|
+
);
|
|
1237
|
+
} catch (error) {
|
|
1238
|
+
ctx.ui.notify(`首次配置未完成:${error instanceof Error ? error.message : String(error)}`, "error");
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
if (!choice) return;
|
|
1242
|
+
if (choice === COPY.applyRecommended) {
|
|
1243
|
+
let themeName: string | undefined;
|
|
1244
|
+
try {
|
|
1245
|
+
const available = RECOMMENDED_THEMES.filter(name => ctx.ui.getTheme(name));
|
|
1246
|
+
if (!available.length) {
|
|
1247
|
+
ctx.ui.notify("未发现 cc-dark 或 cc-light 主题;请确认本包主题已加载。", "error");
|
|
1248
|
+
return;
|
|
1249
|
+
}
|
|
1250
|
+
themeName = await ctx.ui.select(COPY.chooseTheme, available);
|
|
1251
|
+
} catch (error) {
|
|
1252
|
+
ctx.ui.notify(`推荐配置未完成:${error instanceof Error ? error.message : String(error)}`, "error");
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
if (!themeName || !RECOMMENDED_THEMES.includes(themeName as RecommendedTheme)) return;
|
|
1256
|
+
if (!await applyRecommendedHostSettings(ctx, themeName as RecommendedTheme)) return;
|
|
1257
|
+
}
|
|
1258
|
+
settings = { ...settings, onboardingCompleted: true };
|
|
1259
|
+
await persistSettings(ctx);
|
|
1260
|
+
if (choice === COPY.configureNow) await openSettings(ctx);
|
|
1261
|
+
};
|
|
1152
1262
|
pi.registerCommand("pi-mini-mode-minimal", {
|
|
1153
1263
|
description: "Toggle minimal output (off keeps Pi's default conversation history)",
|
|
1154
1264
|
handler: async (args, ctx) => {
|
|
@@ -1173,7 +1283,6 @@ export default function (pi: ExtensionAPI) {
|
|
|
1173
1283
|
ctx.ui.notify(`${COPY.minimalState}${settings["pi-mini-mode-minimal-show"] ? "on" : "off"}`, "info");
|
|
1174
1284
|
},
|
|
1175
1285
|
});
|
|
1176
|
-
|
|
1177
1286
|
pi.registerCommand("pi-mini-mode-prompts", {
|
|
1178
1287
|
description: "Expand or collapse a user prompt in fullscreen minimal output",
|
|
1179
1288
|
handler: async (_args, ctx) => {
|
|
@@ -1206,11 +1315,14 @@ export default function (pi: ExtensionAPI) {
|
|
|
1206
1315
|
if (choice && promptView === view) { view.toggleTool(choice.id); refreshMinimalOutput(); }
|
|
1207
1316
|
},
|
|
1208
1317
|
});
|
|
1209
|
-
|
|
1210
1318
|
pi.registerCommand("pi-mini-mode-settings", {
|
|
1211
|
-
description: "
|
|
1319
|
+
description: "Open HTML settings in the browser",
|
|
1212
1320
|
handler: async (_args, ctx) => openSettings(ctx),
|
|
1213
1321
|
});
|
|
1322
|
+
pi.registerCommand("pi-mini-mode-setup", {
|
|
1323
|
+
description: "Set up Pi Mini Mode theme and fullscreen mode",
|
|
1324
|
+
handler: async (_args, ctx) => runOnboarding(ctx),
|
|
1325
|
+
});
|
|
1214
1326
|
pi.on("session_start", async (_event, ctx) => {
|
|
1215
1327
|
const loaded = await loadSettings(configPath);
|
|
1216
1328
|
settings = loaded.settings;
|
|
@@ -1226,6 +1338,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1226
1338
|
ctx.ui.setFooter((tui, theme, footerData) => {
|
|
1227
1339
|
refreshFooter = () => tui.requestRender();
|
|
1228
1340
|
return {
|
|
1341
|
+
dispose: footerData?.onBranchChange?.(() => tui.requestRender()),
|
|
1229
1342
|
invalidate() {},
|
|
1230
1343
|
render(width: number): string[] {
|
|
1231
1344
|
// switchTuiMode does not re-run setWidget; remount once the live renderer is fullscreen.
|
|
@@ -1237,24 +1350,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
1237
1350
|
mountMinimalOutput(ctx);
|
|
1238
1351
|
});
|
|
1239
1352
|
}
|
|
1240
|
-
return [statusLine(ctx, theme, width, sessionUsage(ctx), settings, speed, undefined, mcpCount, footerData?.getExtensionStatuses?.())];
|
|
1353
|
+
return [statusLine(ctx, theme, width, sessionUsage(ctx), settings, speed, undefined, mcpCount, footerData?.getExtensionStatuses?.(), footerData?.getGitBranch?.())];
|
|
1241
1354
|
},
|
|
1242
1355
|
};
|
|
1243
1356
|
});
|
|
1244
1357
|
refresh();
|
|
1245
|
-
if (!loaded.exists && ctx.mode === "tui" && ctx.hasUI)
|
|
1246
|
-
const choice = await ctx.ui.select(
|
|
1247
|
-
`Pi Mini Mode ${COPY.preview}\n\n deepseek-v4-flash high ${COPY.totalLabel} 45K ${COPY.cachedLabel} 25K ${COPY.cacheHitLabel} 40.0% $0.012 500/1.0M █░░░░░░░░░ 1% 120 tok/s\n\n${COPY.onboarding}`,
|
|
1248
|
-
[COPY.keepDefaults, COPY.configureNow],
|
|
1249
|
-
);
|
|
1250
|
-
settings = { ...settings, onboardingCompleted: true };
|
|
1251
|
-
try {
|
|
1252
|
-
await persistSettings(ctx);
|
|
1253
|
-
} catch {
|
|
1254
|
-
ctx.ui.notify(`${COPY.saveFailed} (${CONFIG_DIR_NAME})`, "error");
|
|
1255
|
-
}
|
|
1256
|
-
if (choice === COPY.configureNow) await openSettings(ctx);
|
|
1257
|
-
}
|
|
1358
|
+
if (!loaded.exists && ctx.mode === "tui" && ctx.hasUI) await runOnboarding(ctx);
|
|
1258
1359
|
});
|
|
1259
1360
|
const syncMinimalBranch = (_event: unknown, ctx: ExtensionContext) => {
|
|
1260
1361
|
minimalTurns = minimalTurnsFromBranch(ctx.sessionManager.getBranch());
|
|
@@ -1321,8 +1422,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
1321
1422
|
pendingMinimalFinal = "";
|
|
1322
1423
|
// Keep the last completed speed visible until this response produces tokens.
|
|
1323
1424
|
// Tool-call-only assistant messages therefore cannot erase a useful rate.
|
|
1324
|
-
|
|
1325
|
-
|
|
1425
|
+
// Decode clock starts on the first output token, not message_start (TTFT).
|
|
1426
|
+
const sampledAt = Date.now();
|
|
1427
|
+
activeGeneration = { output: 0, lastSampleAt: sampledAt };
|
|
1326
1428
|
startSpeedTimer();
|
|
1327
1429
|
});
|
|
1328
1430
|
pi.on("message_update", (event) => {
|
|
@@ -1350,10 +1452,16 @@ export default function (pi: ExtensionAPI) {
|
|
|
1350
1452
|
const usage = partial?.usage;
|
|
1351
1453
|
const output = finiteNumber(usage?.output);
|
|
1352
1454
|
const timestamp = Date.now();
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
activeGeneration.
|
|
1356
|
-
|
|
1455
|
+
const hasOutputContent = Array.isArray(partial?.content) && partial.content.length > 0;
|
|
1456
|
+
if (activeGeneration && timestamp >= activeGeneration.lastSampleAt) {
|
|
1457
|
+
if (activeGeneration.firstTokenAt === undefined && (hasOutputContent || (output !== undefined && output > 0))) {
|
|
1458
|
+
activeGeneration.firstTokenAt = timestamp;
|
|
1459
|
+
}
|
|
1460
|
+
if (output !== undefined && output >= activeGeneration.output) {
|
|
1461
|
+
activeGeneration.output = output;
|
|
1462
|
+
activeGeneration.lastSampleAt = timestamp;
|
|
1463
|
+
refreshStreamingSpeed();
|
|
1464
|
+
}
|
|
1357
1465
|
}
|
|
1358
1466
|
});
|
|
1359
1467
|
pi.on("message_end", (event) => {
|
|
@@ -1365,7 +1473,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1365
1473
|
activeMinimalTurn.pendingUsage = undefined;
|
|
1366
1474
|
}
|
|
1367
1475
|
if (activeGeneration) {
|
|
1368
|
-
const finalSpeed = outputSpeed((event.message.usage as UsageLike | undefined)?.output, activeGeneration.
|
|
1476
|
+
const finalSpeed = outputSpeed((event.message.usage as UsageLike | undefined)?.output, activeGeneration.firstTokenAt);
|
|
1369
1477
|
if (finalSpeed !== undefined) speed = finalSpeed;
|
|
1370
1478
|
activeGeneration = undefined;
|
|
1371
1479
|
stopSpeedTimer();
|
|
@@ -1431,7 +1539,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
1431
1539
|
toolStarts.delete(event.toolCallId);
|
|
1432
1540
|
const nestedUsage = (event.result as { usage?: UsageLike } | undefined)?.usage;
|
|
1433
1541
|
if (activeMinimalTurn) activeMinimalTurn.usage = addUsage(activeMinimalTurn.usage ?? EMPTY_USAGE, nestedUsage);
|
|
1434
|
-
|
|
1542
|
+
// Nested tool LLM completions must not overwrite a measured main-turn decode rate.
|
|
1543
|
+
if (startedAt !== undefined && speed === undefined) {
|
|
1435
1544
|
const nestedSpeed = outputSpeed(nestedUsage?.output, startedAt);
|
|
1436
1545
|
if (nestedSpeed !== undefined) speed = nestedSpeed;
|
|
1437
1546
|
}
|
|
@@ -1468,6 +1577,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
1468
1577
|
refreshMinimalOutput();
|
|
1469
1578
|
});
|
|
1470
1579
|
pi.on("session_shutdown", () => {
|
|
1580
|
+
// In-flight startup checks this generation before installing its server.
|
|
1581
|
+
settingsWebGeneration++;
|
|
1582
|
+
settingsWeb?.close();
|
|
1583
|
+
settingsWeb = undefined;
|
|
1584
|
+
settingsWebOpening = undefined;
|
|
1471
1585
|
cleanupInputEnhancements?.();
|
|
1472
1586
|
cleanupInputEnhancements = undefined;
|
|
1473
1587
|
persistAgentStatuses?.();
|