@each1024/pi-mini-mode 2.0.18 → 2.0.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -75,7 +75,7 @@ Enable **Minimal output** in `/pi-mini-mode-settings`.
75
75
  ![Folded process tree in minimal output](https://github.com/user-attachments/assets/eb8c88f6-84af-499e-b105-5395b4f02e66)
76
76
 
77
77
  - **Long prompts, folded.** In fullscreen minimal mode, long user messages show the first four rendered rows. Click the fold control to reveal the rest. Complete fenced code blocks stay intact.
78
- - **Subagents, in plain sight.** Click a subagent row to expand its available activity and message/final output. In minimal mode, this extension uses `Ctrl+S` to expand or collapse completed subagent summaries; Pi's focused selectors keep their own keys. A dispatch receipt or returned tool call is not a completed background task.
78
+ - **Subagents, in plain sight.** Click a subagent row to expand its available activity and message/final output. In minimal mode, this extension uses `Ctrl+S` to expand or collapse completed subagent summaries; Pi's focused selectors keep their own keys. A dispatch receipt or returned tool call is not a completed background task. Without pi-subagents, `pi -p` / `pi --mode json` shell calls are collected as subagent rows too; both kinds show a table of time, steps, input/output tokens and cache hit rate, with per-step usage and session details when expanded.
79
79
  - **A process tree, not a wall of output.** Thinking, tools and skill reads share one chronological tree. The latest summaries stay visible, including the latest thinking; `Ctrl+O` expands or collapses the full process. New questions start collapsed.
80
80
  - **Tool details on demand.** Expand a tool or thinking entry, including the latest thinking, using its fold control. Thinking starts collapsed and only expands or collapses manually, including while running. Tool details show saved text, not the original custom renderer or image output.
81
81
  - **Readable summaries.** Long tool rows keep the command beginning and put the ellipsis at the end; expanding reveals the complete long or multiline input. Live thinking follows the latest returned summary, while completed thinking previews its beginning and expands to the full received text. Empty summaries show their actual state without repeating a tool command; failures and interruptions stop the thinking clock.
package/README.zh-CN.md CHANGED
@@ -75,7 +75,7 @@ pi install git:github.com/eachann1024/pi-mini-mode
75
75
  ![极简输出中的过程树](https://github.com/user-attachments/assets/eb8c88f6-84af-499e-b105-5395b4f02e66)
76
76
 
77
77
  - **长消息,自动折叠。** 全屏极简模式下,长用户消息默认保留前四个显示行。点击折叠控件展开全文。完整代码围栏保持完整。
78
- - **子代理,清晰可查。** 点击子代理行,展开可用的活动记录与消息/最终输出。极简模式下,本扩展用 `Ctrl+S` 展开/收起已完成的子代理摘要;Pi 当前聚焦的选择器保留自己的快捷键。任务派发回执或工具调用返回,不等于后台任务已完成。
78
+ - **子代理,清晰可查。** 点击子代理行,展开可用的活动记录与消息/最终输出。极简模式下,本扩展用 `Ctrl+S` 展开/收起已完成的子代理摘要;Pi 当前聚焦的选择器保留自己的快捷键。任务派发回执或工具调用返回,不等于后台任务已完成。未安装 pi-subagents 时,shell 里的 `pi -p` / `pi --mode json` 调用也会收纳为子代理行;两类子代理都以表格显示用时、步骤、输入/输出 token 和缓存命中率,展开后可看每步用量和会话信息。
79
79
  - **过程是一棵树,而非满屏输出。** 思考、工具与技能读取汇入同一棵时间顺序树,显示最新摘要,包括最新一条思考;`Ctrl+O` 展开/收起完整过程,新问题默认收起。
80
80
  - **工具详情,按需展开。** 点击工具或思考条目的折叠控件,最新一条思考也可以展开。思考默认收起,进行中与结束后均只由手动操作展开或收起。工具详情展示保存的文本,不还原原生自定义渲染器或图片输出。
81
81
  - **把空间留给答案。** 最终 Markdown 流式呈现,不添加额外标题或背景。失败和中断明确标记;折叠只改变显示,不删除原始会话消息。
@@ -1,4 +1,4 @@
1
- import { AGENT_STATUS_ENTRY, savedAgentStatuses, retainAgentStatuses, agentChildren, agentCall, agentStatusesByTurn, attachAgentWidgets, readAgentStatuses } from "../lib/agent-view.ts";
1
+ import { AGENT_STATUS_ENTRY, savedAgentStatuses, retainAgentStatuses, agentChildren, agentCall, agentStatusesByTurn, attachAgentWidgets, readAgentStatuses, isPrintAgentCall } from "../lib/agent-view.ts";
2
2
  import { getAgentDir, SettingsManager, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
3
3
  import { matchesKey, isKeyRelease, isKeyRepeat, type TuiMouseEvent } from "@earendil-works/pi-tui";
4
4
  import { attachTranscript } from "../lib/transcript-adapter.ts";
@@ -16,6 +16,7 @@ import { statusLine } from "../lib/footer-line.ts";
16
16
  import { contentText, minimalTurnsFromBranch, processText, pushProcess, skillNames, type MinimalTurn } from "../lib/minimal-turns.ts";
17
17
  import { minimalOutputComponent } from "../lib/minimal-output.ts";
18
18
  import { createThinkingStream } from "../lib/thinking-stream.ts";
19
+ import { PACKAGE_VERSION, isNewerVersion } from "../lib/update-banner.ts";
19
20
 
20
21
  // Preserve the existing module entry points for consumers and focused checks.
21
22
  export { SETTINGS_FILE_NAME, DEFAULT_SETTINGS, FOOTER_FIELDS, FOOTER_STYLE_OPTIONS, settingsPath, parseSettings, settingsNeedBackfill, loadSettings, saveSettings, settingsItems, type MiniLensSettings } from "../lib/settings.ts";
@@ -25,6 +26,7 @@ export { SPEED_REFRESH_MS } from "../lib/token-speed.ts";
25
26
  export { isPlannotatorPlanningStatus, planCapsule, settingsPreviewLine, statusLine } from "../lib/footer-line.ts";
26
27
  export { formatElapsed, formatToolElapsed, formatThinkingElapsed, minimalTurnsFromBranch, type MinimalTurn, type ThinkingClock } from "../lib/minimal-turns.ts";
27
28
  export { minimalOutputComponent } from "../lib/minimal-output.ts";
29
+ export { PACKAGE_VERSION, UPDATE_RELEASE_DATE, isNewerVersion, renderUpdateBanner } from "../lib/update-banner.ts";
28
30
 
29
31
  /** Pi /model and other selectors own Ctrl+S; the editor exposes getText. */
30
32
  export function focusedSelectorOwnsKeys(tui?: { getFocusedComponent?(): unknown } | null): boolean {
@@ -90,6 +92,10 @@ export default function (pi: ExtensionAPI) {
90
92
  pi.registerMarkdownTransformer?.(messageLinks);
91
93
  let saveChain: Promise<void> = Promise.resolve();
92
94
  const configPath = settingsPath();
95
+ let updateBannerChecked = false;
96
+ let activeUpdateBanner: { sessionKey: string; version: string; previousVersion?: string; collapsed: boolean } | undefined;
97
+ const getSessionKey = (ctx: ExtensionContext) =>
98
+ ctx.sessionManager.getSessionFile?.() ?? (ctx.sessionManager as { getSessionId?(): string | undefined }).getSessionId?.() ?? "";
93
99
 
94
100
  const refresh = () => refreshFooter?.();
95
101
  const refreshMinimalOutput = () => refreshMinimal?.();
@@ -136,7 +142,7 @@ export default function (pi: ExtensionAPI) {
136
142
  refreshMinimal = () => tui.requestRender();
137
143
  // Retain children under their originating user turn, including while idle,
138
144
  // after a follow-up user message, and when rebuilding a saved session.
139
- const sessionKey = ctx.sessionManager.getSessionFile?.() ?? ctx.sessionManager.getSessionId?.() ?? "";
145
+ const sessionKey = getSessionKey(ctx);
140
146
  let statuses = savedAgentStatuses(ctx.sessionManager.getBranch());
141
147
  const persisted = new Map(statuses.map(status => [String(status.runId), JSON.stringify(status)]));
142
148
  const saveStatuses = () => {
@@ -178,6 +184,18 @@ export default function (pi: ExtensionAPI) {
178
184
  cwd: () => ctx.cwd,
179
185
  requestRender: () => tui.requestRender(),
180
186
  write: data => tui.terminal.write(data),
187
+ updateBanner: () => activeUpdateBanner && activeUpdateBanner.sessionKey === sessionKey
188
+ ? {
189
+ version: activeUpdateBanner.version,
190
+ previousVersion: activeUpdateBanner.previousVersion,
191
+ collapsed: activeUpdateBanner.collapsed,
192
+ toggle: () => {
193
+ if (!activeUpdateBanner) return;
194
+ activeUpdateBanner.collapsed = !activeUpdateBanner.collapsed;
195
+ tui.requestRender();
196
+ },
197
+ }
198
+ : undefined,
181
199
  }, () => settings["pi-mini-mode-minimal-record-limit"], () => uiLanguage(settings));
182
200
  // Native info notifications use dim; warning/error notifications retain
183
201
  // their position in the transcript. No plugin names or message matching.
@@ -187,12 +205,13 @@ export default function (pi: ExtensionAPI) {
187
205
  const hideStartupLine = (line: string) => line.replace(/\x1b\[[0-9;]*m/g, "").includes("No models match pattern");
188
206
  // Transcript hover wrappers must surround the compact widget handlers;
189
207
  // unmount in reverse order so neither adapter resurrects stale handlers.
190
- restoreAgentWidgets = attachAgentWidgets(tui, theme, () => subAgentsExpanded, undefined, true);
208
+ restoreAgentWidgets = attachAgentWidgets(tui, theme, () => subAgentsExpanded, undefined, true, () => uiLanguage(settings));
191
209
  restoreTranscript = attachTranscript(tui, view, {
192
210
  turnCount: () => minimalTurns.length,
193
211
  supervisor: {
194
212
  theme,
195
213
  expanded: () => processExpanded,
214
+ language: () => uiLanguage(settings),
196
215
  handledRunIds: () => handledRunIds,
197
216
  onNotices: groups => {
198
217
  let changed = false;
@@ -234,16 +253,24 @@ export default function (pi: ExtensionAPI) {
234
253
  }
235
254
  if (restoreTranscript) {
236
255
  promptView = view;
256
+ let lastWaitFrame = -1;
237
257
  waitingTimer = setInterval(() => {
258
+ const now = Date.now();
238
259
  let changed = false;
239
- if (Date.now() - lastStatusRead >= 1000) {
260
+ const hasRunningPrint = minimalTurns.some(turn => (turn.agentCalls ?? []).some(call => call.state === "running" && isPrintAgentCall(call)));
261
+ if (now - lastStatusRead >= 1000) {
240
262
  const next = retainAgentStatuses(statuses, readAgentStatuses(sessionKey, undefined, statuses));
241
- changed = JSON.stringify(next) !== JSON.stringify(statuses);
263
+ changed = JSON.stringify(next) !== JSON.stringify(statuses) || hasRunningPrint;
242
264
  statuses = next;
243
265
  saveStatuses();
244
- lastStatusRead = Date.now();
266
+ lastStatusRead = now;
267
+ }
268
+ const frame = Math.floor(now / 250);
269
+ const activeAnim = hasRunningPrint || activeMinimalTurn?.running || agentChildren(statuses).some(child => /^(running|active|starting|queued|pending)$/.test(String(child.status ?? child.state)));
270
+ if (changed || now >= view.agentExpiry() || (activeAnim && frame !== lastWaitFrame)) {
271
+ lastWaitFrame = frame;
272
+ tui.requestRender();
245
273
  }
246
- if (changed || Date.now() >= view.agentExpiry() || activeMinimalTurn?.running || agentChildren(statuses).some(child => /^(running|active|starting|queued|pending)$/.test(String(child.status ?? child.state)))) tui.requestRender();
247
274
  }, 100);
248
275
  waitingTimer.unref();
249
276
  }
@@ -349,6 +376,8 @@ export default function (pi: ExtensionAPI) {
349
376
  if (!isRecordLimit(entry)) throw new TypeError("Invalid record limit");
350
377
  } else if (key === "pi-mini-mode-language") {
351
378
  if (!isUiLanguage(entry)) throw new TypeError("Invalid language");
379
+ } else if (key === "lastSeenVersion") {
380
+ if (entry !== undefined && (typeof entry !== "string" || !/^\d+\.\d+\.\d+$/.test(entry))) throw new TypeError("Invalid version");
352
381
  } else if (isLegacyMinimalSetting(key) && typeof entry === "boolean") {
353
382
  // Accept stale settings pages; these former child switches no longer gate output.
354
383
  continue;
@@ -424,16 +453,37 @@ export default function (pi: ExtensionAPI) {
424
453
  };
425
454
  const loaded = await loadSettings(configPath);
426
455
  settings = loaded.settings;
427
- if (loaded.exists && loaded.backfilled) await persistSettings(ctx);
428
456
  messageCwd = ctx.cwd;
429
457
  // 输入增强只在会话中生效,会话开始时再加载;传 getter 让开关变更即时生效,重复调用是幂等的。
430
- cleanupInputEnhancements = installInputEnhancements(pi, ctx, () => settings["pi-mini-mode-input-enhancements"], () => settings["pi-mini-mode-image-preview"]);
458
+ cleanupInputEnhancements = installInputEnhancements(pi, ctx, () => settings["pi-mini-mode-input-enhancements"], () => settings["pi-mini-mode-image-preview"], () => uiLanguage(settings));
431
459
  thinkingStream.stop(activeMinimalTurn, "aborted");
432
460
  thinkingStream.reset();
433
461
  minimalTurns = minimalTurnsFromBranch(ctx.sessionManager.getBranch());
434
462
  activeMinimalTurn = undefined;
435
463
  pendingMinimalFinal = "";
436
464
  minimalToolOutputIndices.clear();
465
+ const currentSessionKey = getSessionKey(ctx);
466
+ if (updateBannerChecked) {
467
+ activeUpdateBanner = undefined;
468
+ if (settings.lastSeenVersion !== PACKAGE_VERSION) {
469
+ settings = { ...settings, lastSeenVersion: PACKAGE_VERSION };
470
+ }
471
+ } else {
472
+ updateBannerChecked = true;
473
+ const prevVersion = settings.lastSeenVersion;
474
+ const versionChanged = isNewerVersion(PACKAGE_VERSION, prevVersion);
475
+ if (prevVersion !== PACKAGE_VERSION) {
476
+ settings = { ...settings, lastSeenVersion: PACKAGE_VERSION };
477
+ }
478
+ if (loaded.exists && (loaded.backfilled || prevVersion !== PACKAGE_VERSION)) {
479
+ await persistSettings(ctx);
480
+ } else if (!loaded.exists && typeof ctx.ui.select !== "function") {
481
+ await saveSettings(settings, configPath).catch(() => {});
482
+ }
483
+ if (loaded.exists && versionChanged && ctx.mode === "tui" && ctx.hasUI && minimalTurns.length === 0) {
484
+ activeUpdateBanner = { sessionKey: currentSessionKey, version: PACKAGE_VERSION, previousVersion: prevVersion, collapsed: false };
485
+ }
486
+ }
437
487
  mountMinimalOutput(ctx);
438
488
  ctx.ui.setFooter((tui, theme, footerData) => {
439
489
  restoreScrollbar?.();
@@ -449,10 +499,11 @@ export default function (pi: ExtensionAPI) {
449
499
  refreshFooter = () => tui.requestRender();
450
500
  speedHover?.dispose();
451
501
  speedHover = attachSpeedHover(tui, theme, () => ({
452
- metrics: settings["pi-mini-mode-speed-show"] ? speeds.metrics() : [],
502
+ metrics: settings["pi-mini-mode-speed-show"] ? speeds.metrics(uiLanguage(settings)) : [],
453
503
  hit: speedHitBox,
454
504
  }));
455
505
  const onBranchChange = footerData?.onBranchChange?.(() => tui.requestRender());
506
+ let cachedFooterUsage: { key: string; last: unknown; usage: ReturnType<typeof sessionUsage>; waste: ReturnType<typeof cacheWaste> } | undefined;
456
507
  return {
457
508
  dispose() {
458
509
  onBranchChange?.();
@@ -476,8 +527,17 @@ export default function (pi: ExtensionAPI) {
476
527
  mountMinimalOutput(ctx);
477
528
  });
478
529
  }
530
+ const sm = ctx.sessionManager as { getLeafId?(): string | null; getEntries?(): unknown[]; getBranch(): any[] };
531
+ const hasFastKey = typeof sm.getLeafId === "function" && typeof sm.getEntries === "function";
532
+ const entries = hasFastKey ? sm.getEntries!() : sm.getBranch();
533
+ const usageKey = hasFastKey ? `${sm.getLeafId!() ?? ""}:${entries.length}` : `b:${entries.length}`;
534
+ const lastEntry = entries.at(-1);
535
+ if (!cachedFooterUsage || cachedFooterUsage.key !== usageKey || cachedFooterUsage.last !== lastEntry) {
536
+ const branch = hasFastKey ? sm.getBranch() : entries;
537
+ cachedFooterUsage = { key: usageKey, last: lastEntry, usage: sessionUsage(ctx), waste: cacheWaste(branch) };
538
+ }
479
539
  const speed = speeds.displayed();
480
- const line = statusLine(ctx, theme, width, sessionUsage(ctx), settings, speed, undefined, mcpCount, footerData?.getExtensionStatuses?.(), footerData?.getGitBranch?.(), cacheWaste(ctx.sessionManager.getBranch()));
540
+ const line = statusLine(ctx, theme, width, cachedFooterUsage.usage, settings, speed, undefined, mcpCount, footerData?.getExtensionStatuses?.(), footerData?.getGitBranch?.(), cachedFooterUsage.waste);
481
541
  const speedText = settings["pi-mini-mode-speed-show"] && speed !== undefined
482
542
  ? formatSpeed(speed, settings["pi-mini-mode-speed-unit-show"])
483
543
  : "";
@@ -561,12 +621,13 @@ export default function (pi: ExtensionAPI) {
561
621
  pendingMinimalFinal = "";
562
622
  // Keep the last completed average visible until this response produces a live sample.
563
623
  // Tool-call-only assistant messages therefore cannot erase a useful rate.
564
- speeds.onAssistantStart(Date.now());
624
+ speeds.onAssistantStart(Date.now(), event.message as { provider?: unknown; model?: unknown });
565
625
  startSpeedTimer();
566
626
  });
567
627
  pi.on("message_update", (event) => {
568
628
  const partial = (event.assistantMessageEvent as { partial?: { usage?: UsageLike; content?: Array<Record<string, unknown>> } }).partial;
569
- if (speeds.onStream({ at: Date.now(), output: finiteNumber(partial?.usage?.output), content: partial?.content, usage: partial?.usage })) {
629
+ const streamEvent = event.assistantMessageEvent as { type?: string; delta?: string } | undefined;
630
+ if (speeds.onStream({ at: Date.now(), output: finiteNumber(partial?.usage?.output), content: partial?.content, usage: partial?.usage, type: streamEvent?.type, delta: streamEvent?.delta })) {
570
631
  refresh();
571
632
  speedHover?.relayout();
572
633
  }
@@ -683,7 +744,7 @@ export default function (pi: ExtensionAPI) {
683
744
  const startedAt = finiteNumber((event as { timestamp?: unknown }).timestamp) ?? Date.now();
684
745
  speeds.onTurnStart(startedAt);
685
746
  });
686
- pi.on("agent_start", refresh);
747
+ pi.on("agent_start", () => { speeds.onRunStart(); refresh(); });
687
748
  pi.on("agent_end", refresh);
688
749
  pi.on("agent_settled", () => {
689
750
  if (!activeMinimalTurn) return;