@each1024/pi-mini-mode 1.3.15 → 2.0.0
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 +53 -43
- package/README.zh-CN.md +53 -46
- package/extensions/footer-status.ts +194 -113
- package/lib/file-links.ts +36 -17
- package/lib/input-enhancements.ts +330 -50
- package/lib/settings-web.ts +7 -2
- package/lib/settings.html +109 -47
- package/lib/terminal-capabilities.ts +45 -0
- package/lib/transcript-adapter.ts +42 -0
- package/package.json +3 -2
|
@@ -5,7 +5,8 @@ import { diagramMarkdown, isFencedMarkdown, renderMinimalMarkdown } from "../lib
|
|
|
5
5
|
import { minimalSurface, paintExpandedHeading } from "../lib/minimal-theme.ts";
|
|
6
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
|
-
import type
|
|
8
|
+
import { installInputEnhancements, type InputEnhancementsCleanup } from "../lib/input-enhancements.ts";
|
|
9
|
+
import { installTerminalCapabilities } from "../lib/terminal-capabilities.ts";
|
|
9
10
|
import { linkMessageFiles } from "../lib/file-links.ts";
|
|
10
11
|
import { homedir } from "node:os";
|
|
11
12
|
import { stripVTControlCharacters } from "node:util";
|
|
@@ -23,6 +24,7 @@ export interface MiniLensSettings {
|
|
|
23
24
|
"pi-mini-mode-ch-show": boolean;
|
|
24
25
|
"pi-mini-mode-session-tokens-show": boolean;
|
|
25
26
|
"pi-mini-mode-cache-tokens-show": boolean;
|
|
27
|
+
"pi-mini-mode-cache-miss-show": boolean;
|
|
26
28
|
"pi-mini-mode-cost-show": boolean;
|
|
27
29
|
"pi-mini-mode-mcp-show": boolean;
|
|
28
30
|
"pi-mini-mode-context-show": boolean;
|
|
@@ -32,6 +34,7 @@ export interface MiniLensSettings {
|
|
|
32
34
|
"pi-mini-mode-speed-unit-show": boolean;
|
|
33
35
|
"pi-mini-mode-minimal-show": boolean;
|
|
34
36
|
"pi-mini-mode-input-enhancements": boolean;
|
|
37
|
+
"pi-mini-mode-image-preview": "hover" | "inline";
|
|
35
38
|
"pi-mini-mode-minimal-thinking-show": boolean;
|
|
36
39
|
"pi-mini-mode-minimal-tools-show": boolean;
|
|
37
40
|
"pi-mini-mode-minimal-output-show": boolean;
|
|
@@ -49,16 +52,18 @@ export const DEFAULT_SETTINGS: Readonly<MiniLensSettings> = {
|
|
|
49
52
|
"pi-mini-mode-branch-show": false,
|
|
50
53
|
"pi-mini-mode-ch-show": true,
|
|
51
54
|
"pi-mini-mode-session-tokens-show": true,
|
|
52
|
-
"pi-mini-mode-cache-tokens-show":
|
|
55
|
+
"pi-mini-mode-cache-tokens-show": false,
|
|
56
|
+
"pi-mini-mode-cache-miss-show": true,
|
|
53
57
|
"pi-mini-mode-cost-show": true,
|
|
54
58
|
"pi-mini-mode-mcp-show": false,
|
|
55
59
|
"pi-mini-mode-context-show": true,
|
|
56
|
-
"pi-mini-mode-context-dots-show":
|
|
60
|
+
"pi-mini-mode-context-dots-show": true,
|
|
57
61
|
"pi-mini-mode-context-percent-show": true,
|
|
58
62
|
"pi-mini-mode-speed-show": true,
|
|
59
63
|
"pi-mini-mode-speed-unit-show": true,
|
|
60
64
|
"pi-mini-mode-minimal-show": true,
|
|
61
65
|
"pi-mini-mode-input-enhancements": true,
|
|
66
|
+
"pi-mini-mode-image-preview": "inline",
|
|
62
67
|
"pi-mini-mode-minimal-thinking-show": true,
|
|
63
68
|
"pi-mini-mode-minimal-tools-show": true,
|
|
64
69
|
"pi-mini-mode-minimal-output-show": true,
|
|
@@ -69,15 +74,16 @@ export const DEFAULT_SETTINGS: Readonly<MiniLensSettings> = {
|
|
|
69
74
|
};
|
|
70
75
|
|
|
71
76
|
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;
|
|
77
|
+
export const FOOTER_FIELDS = ["project-branch", "model", "thinking", "branch", "session-tokens", "cache-tokens", "cache-miss", "ch", "cost", "mcp", "context", "context-percent", "speed"] as const;
|
|
78
|
+
export const FOOTER_STYLE_OPTIONS = ["context-dots", "speed-unit"] as const;
|
|
73
79
|
|
|
74
80
|
const COPY = {
|
|
75
81
|
title: "Pi Mini Mode 设置", preview: "预览(示例数据)", lens: "设置", minimal: "极简输出",
|
|
76
|
-
model: "显示模型", thinking: "显示思考等级", total: "显示会话总 token", cached: "显示会话缓存 token", totalLabel: "Total", cachedLabel: "Cached", cacheHitLabel: "CH", cacheHit: "显示缓存命中率 (CH)", price: "显示会话价格", mcp: "显示已启用 MCP 服务器", context: "显示上下文 token 与进度条", dots: "↳ 使用点阵进度条", percent: "显示上下文百分比", speed: "显示最近生成速度", speedUnit: "↳ 显示 tok/s 单位", inputEnhancements: "输入增强", showThinking: "显示思考", tools: "显示工具调用", output: "显示过程输出", skills: "显示技能", agentUsage: "显示 Agent token 用量", shortcut: "新 Agent 显示 Ctrl+O 提示(6 秒)",
|
|
82
|
+
model: "显示模型", thinking: "显示思考等级", total: "显示会话总 token", cached: "显示会话缓存 token", miss: "显示缓存 miss", totalLabel: "Total", cachedLabel: "Cached", cacheHitLabel: "CH", cacheHit: "显示缓存命中率 (CH)", price: "显示会话价格", mcp: "显示已启用 MCP 服务器", context: "显示上下文 token 与进度条", dots: "↳ 使用点阵进度条", percent: "显示上下文百分比", speed: "显示最近生成速度", speedUnit: "↳ 显示 tok/s 单位", inputEnhancements: "输入增强", showThinking: "显示思考", tools: "显示工具调用", output: "显示过程输出", skills: "显示技能", agentUsage: "显示 Agent token 用量", shortcut: "新 Agent 显示 Ctrl+O 提示(6 秒)",
|
|
77
83
|
totalDescription: "Total:当前会话分支上的全部 token,含工具上报的 LLM 用量。", cachedDescription: "Cached:累计 cache-read + cache-write token(包含在 Total 中)。", cacheHitDescription: "CH(cache hit):cache-read / (input + cache-read)。Cache write 不计入此比率。",
|
|
78
84
|
enableMinimalDescription: "开启统一折叠思考、工具和技能过程;关闭恢复 Pi 默认会话历史。",
|
|
79
85
|
inputEnhancementsDescription: "原生 Ctrl+V 粘贴图片(Windows/WSL:Alt+V);图片显示为 [image1] 标签,光标移入或全屏悬停可预览。空白后 / 选择技能并在光标处插入。Cmd+点击带下划线的图片标签或消息文件路径,用系统默认应用打开;预览及点击需终端支持。关闭仅恢复原生行为。",
|
|
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
|
|
86
|
+
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: "多数功能默认开启;「仅显示分支」「缓存 token」「MCP」默认关,「仅显示分支」与「项目与分支」互斥。可用 /pi-mini-mode-settings 再改。", keepDefaults: "保留默认", configureNow: "立即配置", applyRecommended: "应用推荐配置", chooseTheme: "选择 Pi Mini Mode 主题(将保存全局主题和全屏模式;重启后生效)", themeSaved: "已保存推荐主题和全屏模式。请重启 Pi;项目设置或命令行参数可能覆盖全局设置。", themeSaveFailed: "无法保存推荐的 Pi 主题和全屏模式;未完成首次配置。", themeApplyFailed: "推荐设置已保存,但当前主题未能立即应用;请重启 Pi。",
|
|
81
87
|
} as const;
|
|
82
88
|
|
|
83
89
|
const RECOMMENDED_THEMES = ["cc-dark", "cc-light"] as const;
|
|
@@ -95,7 +101,9 @@ export function parseSettings(value: unknown): MiniLensSettings {
|
|
|
95
101
|
const candidate = value && typeof value === "object" ? value as Record<string, unknown> : {};
|
|
96
102
|
const settings = { ...DEFAULT_SETTINGS };
|
|
97
103
|
for (const id of SETTING_IDS) {
|
|
98
|
-
if (
|
|
104
|
+
if (id === "pi-mini-mode-image-preview") {
|
|
105
|
+
if (candidate[id] === "hover" || candidate[id] === "inline") settings[id] = candidate[id];
|
|
106
|
+
} else if (isBoolean(candidate[id])) settings[id] = candidate[id];
|
|
99
107
|
}
|
|
100
108
|
if (Array.isArray(candidate.footerOrder)) {
|
|
101
109
|
settings.footerOrder = [...new Set(candidate.footerOrder.filter((id): id is typeof FOOTER_FIELDS[number] =>
|
|
@@ -108,17 +116,31 @@ export function parseSettings(value: unknown): MiniLensSettings {
|
|
|
108
116
|
return settings;
|
|
109
117
|
}
|
|
110
118
|
|
|
119
|
+
/** True when saved JSON is missing a boolean key or a footer field, so defaults can be written back. */
|
|
120
|
+
export function settingsNeedBackfill(raw: unknown, parsed: MiniLensSettings): boolean {
|
|
121
|
+
if (!raw || typeof raw !== "object") return true;
|
|
122
|
+
const candidate = raw as Record<string, unknown>;
|
|
123
|
+
for (const id of SETTING_IDS) {
|
|
124
|
+
if (!Object.hasOwn(candidate, id)) return true;
|
|
125
|
+
}
|
|
126
|
+
if (!Array.isArray(candidate.footerOrder)) return false;
|
|
127
|
+
const order = parsed.footerOrder ?? [];
|
|
128
|
+
return FOOTER_FIELDS.some(id => !order.includes(id));
|
|
129
|
+
}
|
|
130
|
+
|
|
111
131
|
/** Pi /model and other selectors own Ctrl+S; the editor exposes getText. */
|
|
112
132
|
export function focusedSelectorOwnsKeys(tui?: { getFocusedComponent?(): unknown } | null): boolean {
|
|
113
133
|
const focused = tui?.getFocusedComponent?.();
|
|
114
134
|
return !!focused && typeof focused === "object" && typeof (focused as { getText?: unknown }).getText !== "function";
|
|
115
135
|
}
|
|
116
136
|
|
|
117
|
-
export async function loadSettings(path = settingsPath()): Promise<{ settings: MiniLensSettings; exists: boolean }> {
|
|
137
|
+
export async function loadSettings(path = settingsPath()): Promise<{ settings: MiniLensSettings; exists: boolean; backfilled: boolean }> {
|
|
118
138
|
try {
|
|
119
|
-
|
|
139
|
+
const raw: unknown = JSON.parse(await readFile(path, "utf8"));
|
|
140
|
+
const settings = parseSettings(raw);
|
|
141
|
+
return { settings, exists: true, backfilled: settingsNeedBackfill(raw, settings) };
|
|
120
142
|
} catch {
|
|
121
|
-
return { settings: { ...DEFAULT_SETTINGS }, exists: false };
|
|
143
|
+
return { settings: { ...DEFAULT_SETTINGS }, exists: false, backfilled: false };
|
|
122
144
|
}
|
|
123
145
|
}
|
|
124
146
|
|
|
@@ -202,6 +224,33 @@ function addUsage(total: SessionUsage, usage: UsageLike | undefined): SessionUsa
|
|
|
202
224
|
};
|
|
203
225
|
}
|
|
204
226
|
|
|
227
|
+
export interface CacheWaste {
|
|
228
|
+
missedTokens: number;
|
|
229
|
+
missCount: number;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Same noise floor as Pi's cache-miss notice. Compaction resets the baseline. */
|
|
233
|
+
export function cacheWaste(entries: ReadonlyArray<{ type?: unknown; message?: { role?: unknown; usage?: UsageLike } }>): CacheWaste {
|
|
234
|
+
let prev = 0;
|
|
235
|
+
let reported = false;
|
|
236
|
+
const totals = { missedTokens: 0, missCount: 0 };
|
|
237
|
+
for (const entry of entries) {
|
|
238
|
+
if (entry.type === "compaction" || entry.type === "branch_summary") { prev = 0; continue; }
|
|
239
|
+
if (entry.type !== "message" || entry.message?.role !== "assistant") continue;
|
|
240
|
+
const usage = entry.message.usage;
|
|
241
|
+
const input = nonNegative(usage?.input);
|
|
242
|
+
const cacheRead = nonNegative(usage?.cacheRead);
|
|
243
|
+
const cacheWrite = nonNegative(usage?.cacheWrite);
|
|
244
|
+
const prompt = input + cacheRead + cacheWrite;
|
|
245
|
+
if (prev > 0 && prompt > 0 && (cacheRead + cacheWrite > 0 || reported)) {
|
|
246
|
+
const missed = Math.min(prev, prompt) - cacheRead;
|
|
247
|
+
if (missed > 1024) { totals.missedTokens += missed; totals.missCount++; }
|
|
248
|
+
}
|
|
249
|
+
if (prompt > 0) { prev = prompt; reported ||= cacheRead + cacheWrite > 0; }
|
|
250
|
+
}
|
|
251
|
+
return totals;
|
|
252
|
+
}
|
|
253
|
+
|
|
205
254
|
/** Aggregate persisted, finalized usage once per active-branch entry. */
|
|
206
255
|
export function sessionUsage(ctx: ExtensionContext): SessionUsage {
|
|
207
256
|
return ctx.sessionManager.getBranch().reduce((total, entry) => {
|
|
@@ -322,6 +371,7 @@ export function statusLine(
|
|
|
322
371
|
mcpCount?: number,
|
|
323
372
|
statuses?: ReadonlyMap<string, string>,
|
|
324
373
|
gitBranch?: string | null,
|
|
374
|
+
waste?: CacheWaste,
|
|
325
375
|
): string {
|
|
326
376
|
if (highlighted === "pi-mini-mode-context-dots-show") highlighted = "pi-mini-mode-context-show";
|
|
327
377
|
const field = (id: keyof MiniLensSettings, color: Parameters<typeof theme.fg>[0], text: string) =>
|
|
@@ -332,6 +382,7 @@ export function statusLine(
|
|
|
332
382
|
const hit = cacheHit(usageTotals);
|
|
333
383
|
const hitText = hit === undefined ? "" : `${COPY.cacheHitLabel} ${hit.toFixed(1)}%`;
|
|
334
384
|
const cachedTokens = usageTotals.cacheRead + usageTotals.cacheWrite;
|
|
385
|
+
const missText = settings["pi-mini-mode-cache-miss-show"] && waste && waste.missCount > 0 ? `Miss ${formatTokens(waste.missedTokens)}` : "";
|
|
335
386
|
const price = usageTotals.cost > 0 ? formatUsd(usageTotals.cost) : "";
|
|
336
387
|
const contextUsage = ctx.getContextUsage();
|
|
337
388
|
const tokens = finiteNumber(contextUsage?.tokens);
|
|
@@ -354,6 +405,7 @@ export function statusLine(
|
|
|
354
405
|
model, thinking,
|
|
355
406
|
"session-tokens": usageTotals.totalTokens > 0 ? `${COPY.totalLabel} ${formatTokens(usageTotals.totalTokens)}` : "",
|
|
356
407
|
"cache-tokens": cachedTokens > 0 ? `${COPY.cachedLabel} ${formatTokens(cachedTokens)}` : "",
|
|
408
|
+
"cache-miss": missText,
|
|
357
409
|
ch: hitText, cost: price, mcp: mcpText,
|
|
358
410
|
context: tokenText,
|
|
359
411
|
"context-percent": percentText, speed: speed === undefined ? "" : formatSpeed(speed, settings["pi-mini-mode-speed-unit-show"]),
|
|
@@ -366,7 +418,7 @@ export function statusLine(
|
|
|
366
418
|
}
|
|
367
419
|
return truncateToWidth([planTag, ...settings.footerOrder.map(id => {
|
|
368
420
|
const key = `pi-mini-mode-${id}-show` as keyof MiniLensSettings;
|
|
369
|
-
const color = id === "speed" ? speedColor(speed) : id === "model" || id === "context-percent" ? "accent" : "muted";
|
|
421
|
+
const color = id === "speed" ? speedColor(speed) : id === "cache-miss" ? "warning" : id === "model" || id === "context-percent" ? "accent" : "muted";
|
|
370
422
|
return settings[key] && values[id] ? field(key, color, values[id]) : "";
|
|
371
423
|
})].filter(Boolean).join(" "), width, "…");
|
|
372
424
|
}
|
|
@@ -387,6 +439,7 @@ export function statusLine(
|
|
|
387
439
|
branchOnly && branchText && field(branchSetting, "muted", branchText),
|
|
388
440
|
settings["pi-mini-mode-session-tokens-show"] && usageTotals.totalTokens > 0 && field("pi-mini-mode-session-tokens-show", "text", `${COPY.totalLabel} ${formatTokens(usageTotals.totalTokens)}`),
|
|
389
441
|
settings["pi-mini-mode-cache-tokens-show"] && cachedTokens > 0 && field("pi-mini-mode-cache-tokens-show", "text", `${COPY.cachedLabel} ${formatTokens(cachedTokens)}`),
|
|
442
|
+
missText && field("pi-mini-mode-cache-miss-show", "warning", missText),
|
|
390
443
|
settings["pi-mini-mode-ch-show"] && hitText && field("pi-mini-mode-ch-show", "text", hitText),
|
|
391
444
|
settings["pi-mini-mode-cost-show"] && price && field("pi-mini-mode-cost-show", "muted", price),
|
|
392
445
|
mcpText && field("pi-mini-mode-mcp-show", "muted", mcpText),
|
|
@@ -399,6 +452,7 @@ export function statusLine(
|
|
|
399
452
|
branchOnly && branchText,
|
|
400
453
|
settings["pi-mini-mode-session-tokens-show"] && usageTotals.totalTokens > 0 && `${COPY.totalLabel} ${formatTokens(usageTotals.totalTokens)}`,
|
|
401
454
|
settings["pi-mini-mode-cache-tokens-show"] && cachedTokens > 0 && `${COPY.cachedLabel} ${formatTokens(cachedTokens)}`,
|
|
455
|
+
missText,
|
|
402
456
|
settings["pi-mini-mode-ch-show"] && hitText,
|
|
403
457
|
settings["pi-mini-mode-cost-show"] && price,
|
|
404
458
|
mcpText,
|
|
@@ -438,10 +492,10 @@ export function isCollapsedReplyChildSetting(id: string): boolean {
|
|
|
438
492
|
|
|
439
493
|
export function settingsItems(settings: MiniLensSettings): SettingItem[] {
|
|
440
494
|
const values = ["on", "off"];
|
|
441
|
-
const labels: Record<Exclude<keyof MiniLensSettings, "onboardingCompleted" | "footerOrder">, string> = {
|
|
495
|
+
const labels: Record<Exclude<keyof MiniLensSettings, "onboardingCompleted" | "footerOrder" | "pi-mini-mode-image-preview">, string> = {
|
|
442
496
|
"pi-mini-mode-project-branch-show": "显示项目名称和分支(互斥)",
|
|
443
497
|
"pi-mini-mode-branch-show": "仅显示分支(思考等级后,互斥)",
|
|
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,
|
|
498
|
+
"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-cache-miss-show": COPY.miss, "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,
|
|
445
499
|
};
|
|
446
500
|
return (Object.keys(labels) as Array<keyof typeof labels>).map((id) => ({
|
|
447
501
|
id, label: labels[id],
|
|
@@ -484,12 +538,18 @@ export interface MinimalTurn {
|
|
|
484
538
|
/** Wall-clock start of this user-request execution; retained across tool and thinking turns. */
|
|
485
539
|
startedAt?: number;
|
|
486
540
|
thinking?: number;
|
|
541
|
+
/** Per-process-index Thinking clocks. Live rows count; completed rows keep endedAt. */
|
|
542
|
+
thinkingClocks?: Array<ThinkingClock | undefined>;
|
|
487
543
|
awaitingResponse?: boolean;
|
|
488
544
|
waitingTools?: Array<{ id: string; name: string; startedAt: number }>;
|
|
489
545
|
}
|
|
490
546
|
|
|
547
|
+
export interface ThinkingClock {
|
|
548
|
+
startedAt: number;
|
|
549
|
+
endedAt?: number;
|
|
550
|
+
}
|
|
551
|
+
|
|
491
552
|
const PROCESS_PREVIEW_LIMIT = 180;
|
|
492
|
-
const THINKING_SCROLL_INTERVAL_MS = 80;
|
|
493
553
|
|
|
494
554
|
function contentText(content: unknown): string {
|
|
495
555
|
if (typeof content === "string") return content.trim();
|
|
@@ -524,6 +584,37 @@ export function formatElapsed(startedAt: number | undefined, now = Date.now()):
|
|
|
524
584
|
return minutes >= 60 ? `${Math.floor(minutes / 60)}:${String(minutes % 60).padStart(2, "0")}:${remainder}` : `${minutes}:${remainder}`;
|
|
525
585
|
}
|
|
526
586
|
|
|
587
|
+
function ensureThinkingClock(turn: MinimalTurn, index: number, startedAt = Date.now()): ThinkingClock {
|
|
588
|
+
const clocks = turn.thinkingClocks ??= [];
|
|
589
|
+
return clocks[index] ??= { startedAt: turn.startedAt ?? startedAt };
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function freezeThinkingClock(turn: MinimalTurn | undefined, index: number | undefined, endedAt = Date.now()): void {
|
|
593
|
+
if (!turn || index === undefined) return;
|
|
594
|
+
const clock = turn.thinkingClocks?.[index];
|
|
595
|
+
if (clock && clock.endedAt === undefined) clock.endedAt = endedAt;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function freezeOpenThinkingClocks(turn: MinimalTurn | undefined, endedAt = Date.now()): void {
|
|
599
|
+
if (!turn?.thinkingClocks) return;
|
|
600
|
+
for (const clock of turn.thinkingClocks) {
|
|
601
|
+
if (clock && clock.endedAt === undefined) clock.endedAt = endedAt;
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
/** Active Thinking counts from the turn start; completed Thinking keeps the frozen stop time. */
|
|
606
|
+
export function formatThinkingElapsed(
|
|
607
|
+
turn: Pick<MinimalTurn, "startedAt" | "thinkingClocks">,
|
|
608
|
+
processIndex: number,
|
|
609
|
+
active: boolean,
|
|
610
|
+
now = Date.now(),
|
|
611
|
+
): string {
|
|
612
|
+
const clock = turn.thinkingClocks?.[processIndex];
|
|
613
|
+
if (active) return formatElapsed(clock?.startedAt ?? turn.startedAt, now);
|
|
614
|
+
if (clock?.endedAt != null) return formatElapsed(clock.startedAt, clock.endedAt);
|
|
615
|
+
return "";
|
|
616
|
+
}
|
|
617
|
+
|
|
527
618
|
function pushProcess(turn: MinimalTurn | undefined, kind: string, value: unknown): void {
|
|
528
619
|
if (!turn) return;
|
|
529
620
|
const text = processText(value);
|
|
@@ -611,12 +702,14 @@ function visibleMinimalTurns(settings: MiniLensSettings, turns: MinimalTurn[]):
|
|
|
611
702
|
return turns.map((turn) => {
|
|
612
703
|
let thinking: number | undefined;
|
|
613
704
|
let visibleCount = 0;
|
|
705
|
+
const thinkingClocks: Array<ThinkingClock | undefined> = [];
|
|
614
706
|
const process = turn.process.filter((line, index) => {
|
|
615
707
|
const visible = line.startsWith("thinking ") ? settings["pi-mini-mode-minimal-thinking-show"]
|
|
616
708
|
: /^(tool|call) /.test(line) ? settings["pi-mini-mode-minimal-tools-show"]
|
|
617
709
|
: line.startsWith("output ") ? settings["pi-mini-mode-minimal-output-show"]
|
|
618
710
|
: line.startsWith("skill ") ? settings["pi-mini-mode-minimal-skills-show"] : true;
|
|
619
711
|
if (visible) {
|
|
712
|
+
if (turn.thinkingClocks?.[index]) thinkingClocks[visibleCount] = turn.thinkingClocks[index];
|
|
620
713
|
if (index === turn.thinking) thinking = visibleCount;
|
|
621
714
|
visibleCount++;
|
|
622
715
|
}
|
|
@@ -628,6 +721,7 @@ function visibleMinimalTurns(settings: MiniLensSettings, turns: MinimalTurn[]):
|
|
|
628
721
|
awaitingResponse: turn.awaitingResponse && settings["pi-mini-mode-minimal-thinking-show"],
|
|
629
722
|
agentCalls: settings["pi-mini-mode-minimal-tools-show"] ? turn.agentCalls : [],
|
|
630
723
|
process,
|
|
724
|
+
thinkingClocks: turn.thinkingClocks ? thinkingClocks : undefined,
|
|
631
725
|
};
|
|
632
726
|
});
|
|
633
727
|
}
|
|
@@ -783,7 +877,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
783
877
|
const control = truncateToWidth(label, inner, "");
|
|
784
878
|
promptControls.push({ index, question: turn.question, y: lines.length + 1 + userRows.length,
|
|
785
879
|
x: 0, width, label });
|
|
786
|
-
userRows.push(theme.fg("accent", control)
|
|
880
|
+
userRows.push(theme.fg("accent", control));
|
|
787
881
|
// The expanded control is this message's heading, so it keeps the band in place of the user surface.
|
|
788
882
|
controlIndex = userRows.length;
|
|
789
883
|
}
|
|
@@ -793,25 +887,30 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
793
887
|
const call = turn.agentCalls?.find(call => call.id === entry.slice(5));
|
|
794
888
|
if (call && isAgentTool(call.tool ?? call.name) && !isExpanded()) return [];
|
|
795
889
|
const display = call && agentCallDisplay(call);
|
|
796
|
-
return call && display ? [{ title: `${isAgentTool(call.tool ?? call.name) ? "Control" : call.name} ${display.summary}`.trim(), detail: display.detail, state: call.state, id: call.id, thinking: false }] : [];
|
|
890
|
+
return call && display ? [{ title: `${isAgentTool(call.tool ?? call.name) ? "Control" : call.name} ${display.summary}`.trim(), detail: display.detail, state: call.state, id: call.id, thinking: false, processIndex, activeThinking: false }] : [];
|
|
797
891
|
}
|
|
798
892
|
const part = entry.match(/^(tool|output|thinking|skill)(?:\s+|$)([\s\S]*)/);
|
|
799
893
|
const thinking = part?.[1] === "thinking";
|
|
800
894
|
const activeThinking = thinking && turn.running && turn.thinking === processIndex;
|
|
801
895
|
const label = ({ tool: "Tool", output: "Output", thinking: "Thinking", skill: "Skill" } as Record<string, string>)[part?.[1] ?? ""] ?? "Process";
|
|
802
|
-
return [{ title: `${label} ${part?.[2] ?? entry}`, detail: part?.[2] ?? entry, state: activeThinking ? "running" : "done", id: thinking ? `thinking:${index}:${processIndex}` : "", thinking }];
|
|
896
|
+
return [{ title: `${label} ${part?.[2] ?? entry}`, detail: part?.[2] ?? entry, state: activeThinking ? "running" : "done", id: thinking ? `thinking:${index}:${processIndex}` : "", thinking, processIndex, activeThinking }];
|
|
803
897
|
});
|
|
804
898
|
// Older in-memory turns may predate call markers.
|
|
805
899
|
for (const call of turn.agentCalls ?? []) {
|
|
806
900
|
if (isAgentTool(call.tool ?? call.name) && !isExpanded()) continue;
|
|
807
901
|
const display = agentCallDisplay(call);
|
|
808
|
-
if (!entries.some(entry => entry.id === call.id)) entries.push({ title: `${isAgentTool(call.tool ?? call.name) ? "Control" : call.name} ${display.summary}`, detail: display.detail, state: call.state, id: call.id, thinking: false });
|
|
902
|
+
if (!entries.some(entry => entry.id === call.id)) entries.push({ title: `${isAgentTool(call.tool ?? call.name) ? "Control" : call.name} ${display.summary}`, detail: display.detail, state: call.state, id: call.id, thinking: false, processIndex: -1, activeThinking: false });
|
|
809
903
|
}
|
|
810
904
|
const agentTurnControls: Array<{ runId: string; y: number; width: number; line: string }> = [];
|
|
811
905
|
const agents = liveAgentView(turn.subAgents ?? [], theme, width, subAgentsExpanded(), true, agentDeadlines, Date.now(), expandedSubagents, agentTurnControls);
|
|
812
906
|
if (entries.length || turn.running || turn.usage || agents.total) {
|
|
813
907
|
const expanded = isExpanded();
|
|
814
|
-
const
|
|
908
|
+
const latestThinking = !expanded ? [...entries].reverse().find(entry => entry.thinking) : undefined;
|
|
909
|
+
const busy = entries.some(entry => entry.state === "running") || (turn.waitingTools?.length ?? 0) > 0;
|
|
910
|
+
const working = turn.running && !busy && !turn.final;
|
|
911
|
+
const limit = expanded ? entries.length : Math.max(0, 6 - (working ? 1 : 0));
|
|
912
|
+
const shown = expanded ? entries : entries.filter(entry => !entry.thinking || entry.state === "running" || entry === latestThinking || expandedThinking.has(entry.id)).slice(-limit);
|
|
913
|
+
if (latestThinking && !shown.includes(latestThinking)) shown.splice(Math.min(shown.length, entries.indexOf(latestThinking)), 0, latestThinking);
|
|
815
914
|
const done = entries.filter(entry => entry.state === "done").length;
|
|
816
915
|
const progressHeader = theme.bold(theme.fg("text", "Agent")) + (entries.length ? theme.fg("muted", ` · ${done}/${entries.length}`) : "")
|
|
817
916
|
+ (agents.total ? theme.bold(theme.fg("text", " Subagent")) + theme.fg("muted", ` ${agents.done + agents.errors}/${agents.total}`)
|
|
@@ -830,10 +929,6 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
830
929
|
} else {
|
|
831
930
|
lines.push("", truncateToWidth(header, width));
|
|
832
931
|
}
|
|
833
|
-
if (!shown.length && turn.running && turn.awaitingResponse && !turn.final) {
|
|
834
|
-
const prefix = theme.fg("dim", `${agents.rows.length ? "├─" : "└─"} `) + theme.fg("accent", `${runningGlyph()} `) + theme.fg("text", theme.bold("Thinking")) + theme.fg("success", ` ${formatElapsed(turn.startedAt)}`) + " ";
|
|
835
|
-
lines.push(truncateToWidth(prefix + theme.fg("text", "…"), width, ""));
|
|
836
|
-
}
|
|
837
932
|
shown.forEach((entry, row) => {
|
|
838
933
|
const waiting = turn.waitingTools?.find(tool => tool.id === entry.id);
|
|
839
934
|
const title = waiting && !entry.title.startsWith("Control ") ? `${waiting.name} running · waiting ${Math.max(0, Math.floor((Date.now() - waiting.startedAt) / 1000))}s` : entry.title;
|
|
@@ -841,12 +936,13 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
841
936
|
const split = text.indexOf(" ");
|
|
842
937
|
const label = split < 0 ? text : text.slice(0, split);
|
|
843
938
|
const body = split < 0 ? "" : text.slice(split + 1);
|
|
844
|
-
const activeThinking = entry.
|
|
845
|
-
const
|
|
939
|
+
const activeThinking = !!entry.activeThinking;
|
|
940
|
+
const elapsed = entry.thinking ? formatThinkingElapsed(turn, entry.processIndex, activeThinking) : "";
|
|
941
|
+
const thinkingElapsed = elapsed ? theme.fg(activeThinking ? "success" : "muted", ` ${elapsed}`) : "";
|
|
846
942
|
const call = turn.agentCalls?.find(call => call.id === entry.id && !isAgentTool(call.tool ?? call.name));
|
|
847
943
|
const controlId = call?.id ?? (entry.thinking ? entry.id : "");
|
|
848
|
-
const open = call ? expandedTools.has(call.id) :
|
|
849
|
-
const identity = open ? "accent" : "text";
|
|
944
|
+
const open = call ? expandedTools.has(call.id) : entry.thinking && expandedThinking.has(entry.id);
|
|
945
|
+
const identity = open || activeThinking ? "accent" : "text";
|
|
850
946
|
const summary = theme.fg(identity, theme.bold(label)) + thinkingElapsed + " ";
|
|
851
947
|
if (controlId && width >= 4) toolControls.push({ id: controlId, y: lines.length, width, title: text });
|
|
852
948
|
if (hoveredTool?.id === controlId && (hoveredTool.y !== lines.length || hoveredTool.width !== width)) clearHover();
|
|
@@ -855,19 +951,13 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
855
951
|
const keepStatus = entry.state === "running" || (open && entry.state === "error");
|
|
856
952
|
const glyph = arrow ? (open ? "▼" : "▶") + (keepStatus ? ` ${status}` : "") : status;
|
|
857
953
|
const glyphColor = entry.state === "error" ? "error" : entry.state === "running" || arrow ? "accent" : "muted";
|
|
858
|
-
const last = row === shown.length - 1 && !agents.rows.length;
|
|
954
|
+
const last = row === shown.length - 1 && !working && !agents.rows.length;
|
|
859
955
|
const prefix = theme.fg(open ? "accent" : "dim", last ? "└─ " : "├─ ") + theme.fg(glyphColor, glyph) + " " + summary;
|
|
860
|
-
if (
|
|
861
|
-
const renderedBody = markdown(body, Math.max(1, visibleWidth(body) + 1), true).join(" ").replace(/\s+/g, " ").trim();
|
|
862
|
-
const bodyWidth = Math.max(0, width - visibleWidth(prefix));
|
|
863
|
-
const overflow = Math.max(0, visibleWidth(renderedBody) - bodyWidth);
|
|
864
|
-
const offset = overflow ? Math.max(0, Math.floor((Date.now() - (turn.startedAt ?? Date.now())) / THINKING_SCROLL_INTERVAL_MS) % (overflow + 9) - 4) : 0;
|
|
865
|
-
lines.push(bandHeading(truncateToWidth(prefix + (bodyWidth ? sliceByColumn(renderedBody, Math.min(overflow, offset), bodyWidth, true) : ""), width, ""), open));
|
|
866
|
-
} else if (label === "Output") {
|
|
956
|
+
if (label === "Output") {
|
|
867
957
|
// Wrapped output hangs under the body column and keeps the tree rail to the next sibling.
|
|
868
958
|
const indent = visibleWidth(prefix);
|
|
869
959
|
const wrapped = markdown(body, Math.max(1, width - indent), true);
|
|
870
|
-
const rail = !last && indent > 0 ? theme.fg("dim", "
|
|
960
|
+
const rail = !last && indent > 0 ? theme.fg("dim", "\u2502") + " ".repeat(indent - 1) : " ".repeat(indent);
|
|
871
961
|
lines.push(truncateToWidth(prefix + (wrapped[0] ?? ""), width, ""));
|
|
872
962
|
for (const extra of wrapped.slice(1)) lines.push(truncateToWidth(rail + extra, width, ""));
|
|
873
963
|
} else {
|
|
@@ -890,7 +980,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
890
980
|
const details = entry.detail.split(/\r?\n/).filter(line => line.trim());
|
|
891
981
|
// ponytail: four diagnostic lines; full output remains in the native transcript.
|
|
892
982
|
lines.push(...details.slice(1, 5).map(line => truncateToWidth(rail + theme.fg("muted", line), width)));
|
|
893
|
-
if (details.length > 5) lines.push(truncateToWidth(rail + theme.fg("muted", `… +${details.length - 5} lines
|
|
983
|
+
if (details.length > 5) lines.push(truncateToWidth(rail + theme.fg("muted", `… +${details.length - 5} lines`), width));
|
|
894
984
|
}
|
|
895
985
|
});
|
|
896
986
|
const agentStartY = lines.length;
|
|
@@ -900,6 +990,11 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
900
990
|
if (c.runId === pinnedSubagentId) pinnedSubagent = { id: c.runId, y: control.y, line: c.line, autoScroll: false };
|
|
901
991
|
}
|
|
902
992
|
lines.push(...agents.rows);
|
|
993
|
+
if (working) {
|
|
994
|
+
const label = turn.awaitingResponse && !shown.length ? "Thinking" : "Working";
|
|
995
|
+
const prefix = theme.fg("dim", "└─ ") + theme.fg("accent", `${runningGlyph()} `) + theme.fg("text", theme.bold(label)) + theme.fg("success", ` ${formatElapsed(turn.startedAt)}`) + " ";
|
|
996
|
+
lines.push(truncateToWidth(prefix + theme.fg("text", "…"), width, ""));
|
|
997
|
+
}
|
|
903
998
|
}
|
|
904
999
|
for (const reply of turn.replies ?? []) lines.push("", ...markdown(reply, width));
|
|
905
1000
|
if (turn.final) lines.push("", ...markdown(turn.final, width));
|
|
@@ -915,6 +1010,8 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
915
1010
|
}
|
|
916
1011
|
|
|
917
1012
|
export default function (pi: ExtensionAPI) {
|
|
1013
|
+
const restoreTerminalCapabilities = installTerminalCapabilities();
|
|
1014
|
+
pi.on("session_shutdown", restoreTerminalCapabilities);
|
|
918
1015
|
attachFooterTidy(pi);
|
|
919
1016
|
attachTitlePlain(pi);
|
|
920
1017
|
let refreshFooter: (() => void) | undefined;
|
|
@@ -1191,7 +1288,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1191
1288
|
else settingsWebOpening ??= (async () => {
|
|
1192
1289
|
const { startSettingsWeb } = await import("../lib/settings-web.ts");
|
|
1193
1290
|
const server = await startSettingsWeb(() => ({
|
|
1194
|
-
settings, defaults: DEFAULT_SETTINGS, order: FOOTER_FIELDS,
|
|
1291
|
+
settings, defaults: DEFAULT_SETTINGS, order: FOOTER_FIELDS, options: FOOTER_STYLE_OPTIONS,
|
|
1195
1292
|
items: settingsItems(settings).filter(item => !isCollapsedReplyChildSetting(item.id)),
|
|
1196
1293
|
// "regular" means minimal output is saved but cannot mount; the page offers a Pi prompt.
|
|
1197
1294
|
tuiMode: lastAttachMode ?? null,
|
|
@@ -1200,8 +1297,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
1200
1297
|
const input = value as Record<string, unknown>;
|
|
1201
1298
|
for (const [key, entry] of Object.entries(input)) {
|
|
1202
1299
|
if (key === "footerOrder") {
|
|
1203
|
-
if (!Array.isArray(entry) ||
|
|
1204
|
-
|| entry.some(id => !(FOOTER_FIELDS as readonly
|
|
1300
|
+
if (!Array.isArray(entry) || new Set(entry).size !== entry.length
|
|
1301
|
+
|| entry.some(id => typeof id !== "string" || !(FOOTER_FIELDS as readonly string[]).includes(id))) throw new TypeError("Invalid order");
|
|
1302
|
+
} else if (key === "pi-mini-mode-image-preview") {
|
|
1303
|
+
if (entry !== "hover" && entry !== "inline") throw new TypeError("Invalid preview mode");
|
|
1205
1304
|
} else if (!SETTING_IDS.includes(key as typeof SETTING_IDS[number]) || typeof entry !== "boolean") throw new TypeError("Invalid setting");
|
|
1206
1305
|
}
|
|
1207
1306
|
const next = parseSettings({ ...settings, ...input, onboardingCompleted: true });
|
|
@@ -1233,7 +1332,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1233
1332
|
let choice: string | undefined;
|
|
1234
1333
|
try {
|
|
1235
1334
|
choice = await ctx.ui.select(
|
|
1236
|
-
`Pi Mini Mode ${COPY.preview}\n\n deepseek-v4-flash high ${COPY.totalLabel} 45K ${COPY.
|
|
1335
|
+
`Pi Mini Mode ${COPY.preview}\n\n deepseek-v4-flash high ${COPY.totalLabel} 45K ${COPY.cacheHitLabel} 40.0% $0.012 500/1.0M ⣿⣀⣀⣀⣀⣀⣀⣀⣀⣀ 1% 120 tok/s\n\n${COPY.onboarding}`,
|
|
1237
1336
|
[COPY.keepDefaults, COPY.configureNow, COPY.applyRecommended],
|
|
1238
1337
|
);
|
|
1239
1338
|
} catch (error) {
|
|
@@ -1261,77 +1360,23 @@ export default function (pi: ExtensionAPI) {
|
|
|
1261
1360
|
await persistSettings(ctx);
|
|
1262
1361
|
if (choice === COPY.configureNow) await openSettings(ctx);
|
|
1263
1362
|
};
|
|
1264
|
-
pi.registerCommand("pi-mini-mode-minimal", {
|
|
1265
|
-
description: "Toggle minimal output (off keeps Pi's default conversation history)",
|
|
1266
|
-
handler: async (args, ctx) => {
|
|
1267
|
-
const normalized = args.trim().toLowerCase();
|
|
1268
|
-
if (ctx.mode !== "tui") {
|
|
1269
|
-
ctx.ui.notify(COPY.minimalRequired, "error");
|
|
1270
|
-
return;
|
|
1271
|
-
}
|
|
1272
|
-
if (normalized && normalized !== "on" && normalized !== "off") {
|
|
1273
|
-
ctx.ui.notify(COPY.minimalUsage, "warning");
|
|
1274
|
-
return;
|
|
1275
|
-
}
|
|
1276
|
-
settings = {
|
|
1277
|
-
...settings,
|
|
1278
|
-
"pi-mini-mode-minimal-show": normalized === "on" ? true : normalized === "off" ? false : !settings["pi-mini-mode-minimal-show"],
|
|
1279
|
-
onboardingCompleted: true,
|
|
1280
|
-
};
|
|
1281
|
-
if (settings["pi-mini-mode-minimal-show"]) nativeOutput = false;
|
|
1282
|
-
mountMinimalOutput(ctx);
|
|
1283
|
-
await persistSettings(ctx);
|
|
1284
|
-
if (settings["pi-mini-mode-minimal-show"] && !restoreTranscript) return;
|
|
1285
|
-
ctx.ui.notify(`${COPY.minimalState}${settings["pi-mini-mode-minimal-show"] ? "on" : "off"}`, "info");
|
|
1286
|
-
},
|
|
1287
|
-
});
|
|
1288
|
-
pi.registerCommand("pi-mini-mode-prompts", {
|
|
1289
|
-
description: "Expand or collapse a user prompt in fullscreen minimal output",
|
|
1290
|
-
handler: async (_args, ctx) => {
|
|
1291
|
-
if (ctx.mode !== "tui" || !restoreTranscript || !promptView) {
|
|
1292
|
-
if (ctx.hasUI) ctx.ui.notify("Prompt folding requires fullscreen minimal output.", "info");
|
|
1293
|
-
return;
|
|
1294
|
-
}
|
|
1295
|
-
const view = promptView;
|
|
1296
|
-
const choices = view.promptChoices();
|
|
1297
|
-
if (!choices.length) { ctx.ui.notify("No user prompts exceed four lines at this width.", "info"); return; }
|
|
1298
|
-
const labels = choices.map(choice => `${choice.index + 1}. ${choice.label} · ${preview(choice.question)}`);
|
|
1299
|
-
const selected = await ctx.ui.select("User prompts · Enter to toggle · Esc to cancel", labels);
|
|
1300
|
-
const choice = choices[labels.indexOf(selected ?? "")];
|
|
1301
|
-
if (choice && promptView === view) { view.togglePrompt(choice.index, choice.question); refreshMinimalOutput(); }
|
|
1302
|
-
},
|
|
1303
|
-
});
|
|
1304
|
-
pi.registerCommand("pi-mini-mode-tools", {
|
|
1305
|
-
description: "Expand or collapse a tool's saved text or thinking in fullscreen minimal output",
|
|
1306
|
-
handler: async (_args, ctx) => {
|
|
1307
|
-
if (ctx.mode !== "tui" || !restoreTranscript || !promptView) {
|
|
1308
|
-
if (ctx.hasUI) ctx.ui.notify("Tool folding requires fullscreen minimal output.", "info");
|
|
1309
|
-
return;
|
|
1310
|
-
}
|
|
1311
|
-
const view = promptView;
|
|
1312
|
-
const choices = view.toolChoices();
|
|
1313
|
-
if (!choices.length) { ctx.ui.notify("No visible tool calls. Ctrl+O shows older calls.", "info"); return; }
|
|
1314
|
-
const labels = choices.map((choice, index) => `${index + 1}. ${choice.expanded ? "收起" : "展开"} · ${preview(choice.title)}`);
|
|
1315
|
-
const selected = await ctx.ui.select("Tool results · Enter to toggle · Esc to cancel", labels);
|
|
1316
|
-
const choice = choices[labels.indexOf(selected ?? "")];
|
|
1317
|
-
if (choice && promptView === view) { view.toggleTool(choice.id); refreshMinimalOutput(); }
|
|
1318
|
-
},
|
|
1319
|
-
});
|
|
1320
1363
|
pi.registerCommand("pi-mini-mode-settings", {
|
|
1321
1364
|
description: "Open HTML settings in the browser",
|
|
1322
1365
|
handler: async (_args, ctx) => openSettings(ctx),
|
|
1323
1366
|
});
|
|
1324
|
-
|
|
1325
|
-
description: "Set up Pi Mini Mode theme and fullscreen mode",
|
|
1326
|
-
handler: async (_args, ctx) => runOnboarding(ctx),
|
|
1327
|
-
});
|
|
1367
|
+
|
|
1328
1368
|
pi.on("session_start", async (_event, ctx) => {
|
|
1369
|
+
(ctx as ExtensionContext & { __applyMinimal?: (on: boolean) => void }).__applyMinimal = (on) => {
|
|
1370
|
+
settings = { ...settings, "pi-mini-mode-minimal-show": on };
|
|
1371
|
+
if (on) nativeOutput = false;
|
|
1372
|
+
mountMinimalOutput(ctx);
|
|
1373
|
+
};
|
|
1329
1374
|
const loaded = await loadSettings(configPath);
|
|
1330
1375
|
settings = loaded.settings;
|
|
1376
|
+
if (loaded.exists && loaded.backfilled) await persistSettings(ctx);
|
|
1331
1377
|
messageCwd = ctx.cwd;
|
|
1332
1378
|
// 输入增强只在会话中生效,会话开始时再加载;传 getter 让开关变更即时生效,重复调用是幂等的。
|
|
1333
|
-
|
|
1334
|
-
cleanupInputEnhancements = installInputEnhancements(pi, ctx, () => settings["pi-mini-mode-input-enhancements"]);
|
|
1379
|
+
cleanupInputEnhancements = installInputEnhancements(pi, ctx, () => settings["pi-mini-mode-input-enhancements"], () => settings["pi-mini-mode-image-preview"]);
|
|
1335
1380
|
minimalTurns = minimalTurnsFromBranch(ctx.sessionManager.getBranch());
|
|
1336
1381
|
activeMinimalTurn = undefined;
|
|
1337
1382
|
pendingMinimalFinal = "";
|
|
@@ -1352,12 +1397,12 @@ export default function (pi: ExtensionAPI) {
|
|
|
1352
1397
|
mountMinimalOutput(ctx);
|
|
1353
1398
|
});
|
|
1354
1399
|
}
|
|
1355
|
-
return [statusLine(ctx, theme, width, sessionUsage(ctx), settings, speed, undefined, mcpCount, footerData?.getExtensionStatuses?.(), footerData?.getGitBranch?.())];
|
|
1400
|
+
return [statusLine(ctx, theme, width, sessionUsage(ctx), settings, speed, undefined, mcpCount, footerData?.getExtensionStatuses?.(), footerData?.getGitBranch?.(), cacheWaste(ctx.sessionManager.getBranch()))];
|
|
1356
1401
|
},
|
|
1357
1402
|
};
|
|
1358
1403
|
});
|
|
1359
1404
|
refresh();
|
|
1360
|
-
if (!
|
|
1405
|
+
if (!settings.onboardingCompleted && ctx.mode === "tui" && ctx.hasUI) await runOnboarding(ctx);
|
|
1361
1406
|
});
|
|
1362
1407
|
const syncMinimalBranch = (_event: unknown, ctx: ExtensionContext) => {
|
|
1363
1408
|
minimalTurns = minimalTurnsFromBranch(ctx.sessionManager.getBranch());
|
|
@@ -1390,9 +1435,23 @@ export default function (pi: ExtensionAPI) {
|
|
|
1390
1435
|
});
|
|
1391
1436
|
pi.on("model_select", refresh);
|
|
1392
1437
|
pi.on("thinking_level_select", refresh);
|
|
1438
|
+
const writeThinkingLine = (turn: MinimalTurn, blockIndex: number, line: string): number => {
|
|
1439
|
+
const existing = minimalMessageIndices.get(blockIndex);
|
|
1440
|
+
if (existing === undefined) {
|
|
1441
|
+
const index = turn.process.length;
|
|
1442
|
+
minimalMessageIndices.set(blockIndex, index);
|
|
1443
|
+
turn.process.push(line);
|
|
1444
|
+
ensureThinkingClock(turn, index);
|
|
1445
|
+
return index;
|
|
1446
|
+
}
|
|
1447
|
+
turn.process[existing] = line;
|
|
1448
|
+
ensureThinkingClock(turn, existing);
|
|
1449
|
+
return existing;
|
|
1450
|
+
};
|
|
1393
1451
|
pi.on("message_start", (event) => {
|
|
1394
1452
|
if (event.message.role === "user") {
|
|
1395
1453
|
if (activeMinimalTurn) {
|
|
1454
|
+
freezeOpenThinkingClocks(activeMinimalTurn);
|
|
1396
1455
|
activeMinimalTurn.final = pendingMinimalFinal;
|
|
1397
1456
|
activeMinimalTurn.running = false;
|
|
1398
1457
|
activeMinimalTurn.thinking = undefined;
|
|
@@ -1414,6 +1473,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1414
1473
|
// Background completions can start a new assistant turn without a user message.
|
|
1415
1474
|
activeMinimalTurn ??= minimalTurns.at(-1);
|
|
1416
1475
|
if (activeMinimalTurn) {
|
|
1476
|
+
freezeThinkingClock(activeMinimalTurn, activeMinimalTurn.thinking);
|
|
1417
1477
|
if (activeMinimalTurn.final) (activeMinimalTurn.replies ??= []).push(activeMinimalTurn.final);
|
|
1418
1478
|
activeMinimalTurn.final = undefined;
|
|
1419
1479
|
activeMinimalTurn.running = true;
|
|
@@ -1432,17 +1492,21 @@ export default function (pi: ExtensionAPI) {
|
|
|
1432
1492
|
pi.on("message_update", (event) => {
|
|
1433
1493
|
const partial = (event.assistantMessageEvent as { partial?: { usage?: UsageLike; content?: Array<Record<string, unknown>> } }).partial;
|
|
1434
1494
|
if (activeMinimalTurn && partial?.content) {
|
|
1495
|
+
const previousThinking = activeMinimalTurn.thinking;
|
|
1435
1496
|
activeMinimalTurn.thinking = undefined;
|
|
1436
1497
|
if (partial.content.length) activeMinimalTurn.awaitingResponse = false;
|
|
1437
1498
|
for (const [blockIndex, item] of partial.content.entries()) {
|
|
1438
1499
|
if (item.type !== "thinking") continue;
|
|
1439
|
-
const line =
|
|
1440
|
-
const index =
|
|
1441
|
-
if (
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1500
|
+
const line = `thinking ${processText(item.thinking ?? item.text)}`;
|
|
1501
|
+
const index = writeThinkingLine(activeMinimalTurn, blockIndex, line);
|
|
1502
|
+
if (blockIndex === partial.content.length - 1 && event.assistantMessageEvent.type !== "thinking_end") {
|
|
1503
|
+
activeMinimalTurn.thinking = index;
|
|
1504
|
+
} else {
|
|
1505
|
+
freezeThinkingClock(activeMinimalTurn, index);
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
if (previousThinking !== undefined && previousThinking !== activeMinimalTurn.thinking) {
|
|
1509
|
+
freezeThinkingClock(activeMinimalTurn, previousThinking);
|
|
1446
1510
|
}
|
|
1447
1511
|
activeMinimalTurn.final = contentText(partial.content) || undefined;
|
|
1448
1512
|
refreshMinimalOutput();
|
|
@@ -1469,6 +1533,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
1469
1533
|
pi.on("message_end", (event) => {
|
|
1470
1534
|
if (event.message.role === "assistant") {
|
|
1471
1535
|
if (activeMinimalTurn) {
|
|
1536
|
+
freezeThinkingClock(activeMinimalTurn, activeMinimalTurn.thinking);
|
|
1537
|
+
freezeOpenThinkingClocks(activeMinimalTurn);
|
|
1472
1538
|
activeMinimalTurn.thinking = undefined;
|
|
1473
1539
|
activeMinimalTurn.awaitingResponse = false;
|
|
1474
1540
|
activeMinimalTurn.usage = addUsage(activeMinimalTurn.usage ?? EMPTY_USAGE, event.message.usage as UsageLike | undefined);
|
|
@@ -1485,6 +1551,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
1485
1551
|
for (const [blockIndex, item] of (content as Array<Record<string, unknown>>).entries()) {
|
|
1486
1552
|
if (item.type !== "thinking" && !(item.type === "text" && content.some((block) => block.type === "toolCall"))) continue;
|
|
1487
1553
|
const line = `${item.type === "thinking" ? "thinking" : "output"} ${processText(item.thinking ?? item.text)}`;
|
|
1554
|
+
if (item.type === "thinking") {
|
|
1555
|
+
freezeThinkingClock(activeMinimalTurn, writeThinkingLine(activeMinimalTurn, blockIndex, line));
|
|
1556
|
+
continue;
|
|
1557
|
+
}
|
|
1488
1558
|
const index = minimalMessageIndices.get(blockIndex);
|
|
1489
1559
|
if (index === undefined) activeMinimalTurn.process.push(line);
|
|
1490
1560
|
else activeMinimalTurn.process[index] = line;
|
|
@@ -1505,6 +1575,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1505
1575
|
pi.on("tool_execution_start", (event) => {
|
|
1506
1576
|
toolStarts.set(event.toolCallId, Date.now());
|
|
1507
1577
|
if (activeMinimalTurn) {
|
|
1578
|
+
freezeThinkingClock(activeMinimalTurn, activeMinimalTurn.thinking);
|
|
1508
1579
|
activeMinimalTurn.thinking = undefined;
|
|
1509
1580
|
activeMinimalTurn.awaitingResponse = false;
|
|
1510
1581
|
(activeMinimalTurn.agentCalls ??= []).push(agentCall(event.toolCallId, event.toolName, event.args));
|
|
@@ -1571,7 +1642,11 @@ export default function (pi: ExtensionAPI) {
|
|
|
1571
1642
|
pi.on("agent_end", refresh);
|
|
1572
1643
|
pi.on("agent_settled", () => {
|
|
1573
1644
|
if (!activeMinimalTurn) return;
|
|
1574
|
-
for (const turn of minimalTurns) {
|
|
1645
|
+
for (const turn of minimalTurns) {
|
|
1646
|
+
freezeOpenThinkingClocks(turn);
|
|
1647
|
+
turn.running = false;
|
|
1648
|
+
turn.thinking = undefined;
|
|
1649
|
+
}
|
|
1575
1650
|
activeMinimalTurn.final = pendingMinimalFinal;
|
|
1576
1651
|
activeMinimalTurn = undefined;
|
|
1577
1652
|
pendingMinimalFinal = "";
|
|
@@ -1610,3 +1685,9 @@ export default function (pi: ExtensionAPI) {
|
|
|
1610
1685
|
stopSpeedTimer();
|
|
1611
1686
|
});
|
|
1612
1687
|
}
|
|
1688
|
+
|
|
1689
|
+
/** @internal tests flip minimal output without a slash command. */
|
|
1690
|
+
export function applyMinimal(ctx: ExtensionContext, on: boolean): void {
|
|
1691
|
+
const hook = (ctx as ExtensionContext & { __applyMinimal?: (on: boolean) => void }).__applyMinimal;
|
|
1692
|
+
hook?.(on);
|
|
1693
|
+
}
|