@each1024/pi-mini-mode 2.0.5 → 2.0.6

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
@@ -217,7 +217,7 @@ For a real terminal smoke test, run `python3 test/minimal-pty.py`. It needs Pyth
217
217
  <details>
218
218
  <summary><strong>Publishing</strong></summary>
219
219
 
220
- Normal releases are published from this machine with the npm token in `.npmrc` (`npm publish --access public`). `publish.yml` is only a manual backup (`workflow_dispatch` on `main`): it runs `npm ci`, `npm run check`, and `npm test`, then `scripts/publish.mjs`. That script publishes the higher of the local version baseline and npm's highest historically published stable version plus one patch, changes the version only in the runner (no version commit or tag), and skips commits that are already published. Raise the baseline in `package.json` and the lockfile for a major or minor release.
220
+ Complete and commit the task, then run `npm run release` from a clean checkout. It selects one version above every historically published stable npm version, updates package.json and the lockfile, checks types, commits and pushes to main, publishes to npm, verifies the package and latest tag, and creates the matching Git tag. Versions start at `2.0.6`; the final number continues through 100 and beyond and does not reset when the feature version changes. Pi uses the same npm version. Ordinary pushes do not publish. The manual CI backup publishes the committed version exactly and never changes it. Failed publication stops without a second publish.
221
221
 
222
222
  The backup workflow needs the package’s npm Trusted Publisher configured for this GitHub repository and `publish.yml`. It uses OIDC and provenance and does not use an npm token.
223
223
 
package/README.zh-CN.md CHANGED
@@ -210,7 +210,7 @@ python3 test/minimal-pty.py
210
210
  <details>
211
211
  <summary><strong>发布</strong></summary>
212
212
 
213
- 日常发布在本机完成,使用 `.npmrc` 中的 npm token(`npm publish --access public`)。`publish.yml` 只作为手动备份(在 `main` 上 `workflow_dispatch`):先执行 `npm ci`、`npm run check` 和 `npm test`,再运行 `scripts/publish.mjs`。该脚本发布本地版本基线与 npm 最新稳定版本再加一个 patch 中的较高者,版本只在 runner 中变更(不创建版本提交或 tag),并跳过已经发布过的提交。发布 major 或 minor 时,同时提高 `package.json` 和 lockfile 中的基线。
213
+ 每轮改动完成并提交后,在干净的工作区运行 `npm run release`。入口统一确定高于 npm 全部历史稳定版本的版本号,同步 package.json 与 lockfile,执行类型检查,提交并推送 main,发布 npm,核验包内容与 latest,最后创建同名 Git 标签。新流程从 `2.0.6` 开始,末位持续累加,可超过 100,功能版本升级也不归零。Pi 使用同一 npm 版本。普通推送不触发发布;手动 CI 备用入口只发布已提交的版本,不自行升号。发布失败立即停止,不重复发布。
214
214
 
215
215
  备份流程需要为该包配置指向此 GitHub 仓库及 `publish.yml` 的 npm Trusted Publisher。它使用 OIDC 和 provenance,不使用 npm token。
216
216
 
@@ -12,6 +12,7 @@ import { installTerminalCapabilities } from "../lib/terminal-capabilities.ts";
12
12
  import { linkMessageFiles, linkToolFiles } from "../lib/file-links.ts";
13
13
  import { homedir } from "node:os";
14
14
  import { stripVTControlCharacters } from "node:util";
15
+ import { thinkingPreview } from "../lib/thinking-preview.ts";
15
16
  import { basename, dirname, join } from "node:path";
16
17
  import attachFooterTidy from "../lib/footer-tidy.ts";
17
18
  import attachTitlePlain from "../lib/title-plain.ts";
@@ -776,6 +777,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
776
777
  const expandedSubagents = new Set<string>();
777
778
  const expandedTools = new Set<string>();
778
779
  const expandedThinking = new Set<string>();
780
+ const thinkingPreviews = new Map<string, { text: string; width: number; rows: number; updatedAt: number }>();
779
781
  const PROCESS_PREVIEW_ROWS = 6;
780
782
  const agentModes = new Map<number, "all" | "preview" | "closed">();
781
783
  const runningTurns = new Set<number>();
@@ -844,6 +846,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
844
846
  invalidate() { clearHover(); },
845
847
  resetProcessView() {
846
848
  agentModes.clear(); expandedThinking.clear(); expandedTools.clear(); expandedSubagents.clear();
849
+ thinkingPreviews.clear();
847
850
  pinnedToolId = undefined; pinnedAgentIndex = undefined; pinnedSubagentId = undefined;
848
851
  },
849
852
  clearHover,
@@ -926,6 +929,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
926
929
  const thinkingIds = new Set(turns.flatMap((turn, turnIndex) => turn.process.flatMap((entry, processIndex) =>
927
930
  entry.startsWith("thinking") ? [`thinking:${turnIndex}:${processIndex}`] : [])));
928
931
  for (const id of expandedThinking) if (!thinkingIds.has(id)) expandedThinking.delete(id);
932
+ for (const id of thinkingPreviews.keys()) if (!thinkingIds.has(id)) thinkingPreviews.delete(id);
929
933
  const inner = Math.max(1, width - 2 * Math.min(2, Math.floor((width - 1) / 2)));
930
934
  const lines: string[] = [];
931
935
  // An open heading wears the same full-width selectedBg band as an expanded SubAgent row.
@@ -1056,20 +1060,30 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
1056
1060
  lines.push(truncateToWidth(prefix + (wrapped[0] ?? ""), width, ""));
1057
1061
  for (const extra of wrapped.slice(1)) lines.push(truncateToWidth(rail + extra, width, ""));
1058
1062
  } else {
1059
- const displayBody = placeholderText(activeThinking ? stripVTControlCharacters(entry.detail).replace(/[\x00-\x1f\x7f]/g, " ").replace(/\s+/g, " ").trim() : body);
1060
- const compactBody = entry.thinking ? displayBody
1061
- : linkToolFiles(displayBody, imageOptions?.cwd() ?? process.cwd(), !open);
1062
1063
  const available = Math.max(0, width - visibleWidth(prefix));
1063
- const fittedBody = visibleWidth(compactBody) > available && (activeThinking || (!entry.thinking && !open)) && available > 1
1064
- ? "…" + sliceByColumn(compactBody, visibleWidth(compactBody) - available + 1, available - 1, true)
1065
- : truncateToWidth(compactBody, available, "…");
1066
- const styledBody = activeThinking
1067
- ? theme.fg("accent", fittedBody)
1068
- : entry.thinking
1069
- ? markdown(fittedBody, Math.max(1, visibleWidth(fittedBody) + 1), true).join(" ").replace(/\s+/g, " ").trim()
1070
- // sliceByColumn may end before OSC 8's closing sequence.
1071
- : theme.fg(open ? "accent" : "muted", fittedBody + "\x1b]8;;\x07");
1072
- lines.push(bandHeading(truncateToWidth(prefix + styledBody, width, "…"), open));
1064
+ if (entry.thinking) {
1065
+ const now = Date.now();
1066
+ const cached = thinkingPreviews.get(entry.id);
1067
+ const previewRows = open ? 1 : 2;
1068
+ const reuse = activeThinking && cached?.text && cached.width === available && cached.rows === previewRows && now - cached.updatedAt < 350;
1069
+ const display = reuse ? cached.text : thinkingPreview(entry.detail, available, previewRows);
1070
+ if (!reuse) thinkingPreviews.set(entry.id, { text: display, width: available, rows: previewRows, updatedAt: now });
1071
+ const fallback = activeThinking ? "等待模型返回思考内容" : "模型未提供可显示的思考内容";
1072
+ const rows = new Text(display || fallback, 0, 0).render(Math.max(1, available)).slice(0, open ? 1 : 2);
1073
+ const color = activeThinking ? "accent" : "muted";
1074
+ lines.push(bandHeading(truncateToWidth(prefix + theme.fg(color, rows[0] ?? ""), width, ""), open));
1075
+ const rail = theme.fg(last ? color : "dim", last ? " " : "│") + " ".repeat(Math.max(0, visibleWidth(prefix) - 1));
1076
+ for (const extra of rows.slice(1)) lines.push(truncateToWidth(rail + theme.fg(color, extra), width, ""));
1077
+ } else {
1078
+ const displayBody = placeholderText(body);
1079
+ const compactBody = linkToolFiles(displayBody, imageOptions?.cwd() ?? process.cwd(), !open);
1080
+ const fittedBody = visibleWidth(compactBody) > available && !open && available > 1
1081
+ ? "…" + sliceByColumn(compactBody, visibleWidth(compactBody) - available + 1, available - 1, true)
1082
+ : truncateToWidth(compactBody, available, "…");
1083
+ // sliceByColumn may end before OSC 8's closing sequence.
1084
+ const styledBody = theme.fg(open ? "accent" : "muted", fittedBody + "\x1b]8;;\x07");
1085
+ lines.push(bandHeading(truncateToWidth(prefix + styledBody, width, "…"), open));
1086
+ }
1073
1087
  }
1074
1088
  if (open && call && call.id === pinnedToolId) pinnedTool = { id: call.id, y: lines.length - 1, line: lines.at(-1)! };
1075
1089
  if (open && call) {
@@ -1083,12 +1097,6 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
1083
1097
  const rail = width > 5 ? (last ? " " : theme.fg("accent", "│ ")) : "";
1084
1098
  const detailWidth = Math.max(1, width - visibleWidth(rail));
1085
1099
  lines.push(...markdown(entry.detail, detailWidth, true).map(line => truncateToWidth(rail + line, width, "")));
1086
- } else if (expanded && entry.state === "error" && entry.detail) {
1087
- const rail = last ? " " : theme.fg("dim", "│ ");
1088
- const details = entry.detail.split(/\r?\n/).filter(line => line.trim());
1089
- // ponytail: four diagnostic lines; full output remains in the native transcript.
1090
- lines.push(...details.slice(1, 5).map(line => truncateToWidth(rail + theme.fg("muted", line), width)));
1091
- if (details.length > 5) lines.push(truncateToWidth(rail + theme.fg("muted", `… +${details.length - 5} lines`), width));
1092
1100
  }
1093
1101
  });
1094
1102
  if (showAgentRows) {
@@ -1103,7 +1111,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
1103
1111
  if (working && (expanded || !shown.length)) {
1104
1112
  const label = turn.awaitingResponse && !shown.length ? "Thinking" : "Working";
1105
1113
  const prefix = theme.fg("dim", "└─ ") + theme.fg("accent", `${runningGlyph()} `) + theme.fg("text", theme.bold(label)) + " ";
1106
- lines.push(truncateToWidth(prefix + theme.fg("text", "…"), width, ""));
1114
+ lines.push(truncateToWidth(prefix + theme.fg("muted", turn.awaitingResponse ? "等待模型响应" : "等待下一步执行"), width, ""));
1107
1115
  }
1108
1116
  }
1109
1117
  for (const [replyIndex, reply] of (turn.replies ?? []).entries()) lines.push("", ...assistantMarkdown(reply, width, `reply:${index}:${replyIndex}`));
@@ -9,7 +9,7 @@ const parser = new Marked();
9
9
  export interface AssistantImageSpan { start: number; end: number; path: string }
10
10
 
11
11
  /** Parse image syntax before bare paths, retaining source offsets for placement. */
12
- export function assistantImageSpans(source: string, cwd: string): AssistantImageSpan[] {
12
+ export function assistantImageSpans(source: string, cwd: string, allowMissing = false): AssistantImageSpan[] {
13
13
  const spans: AssistantImageSpan[] = [];
14
14
  let cursor = 0;
15
15
  let offset = 0;
@@ -40,12 +40,15 @@ export function assistantImageSpans(source: string, cwd: string): AssistantImage
40
40
  spans.push({ start: match.start, end: match.end, path: localPath(match.path, cwd) });
41
41
  }
42
42
  }
43
- return spans.filter(span => existsSync(span.path)).sort((a, b) => a.start - b.start);
43
+ return spans.filter(span => existsSync(span.path) || (allowMissing
44
+ && !/[*?]/.test(span.path)
45
+ && /^(?:!\[|\/|~\/|\.{1,2}\/|[a-z]:[\\/])/i.test(source.slice(span.start, span.end))))
46
+ .sort((a, b) => a.start - b.start);
44
47
  }
45
48
 
46
- /** User messages and tool steps expose one linked chip without reserving image height. */
49
+ /** Keep explicit image references compact even after clipboard files have expired. */
47
50
  export function imagePlaceholders(source: string, cwd: string): string {
48
- const spans = assistantImageSpans(source, cwd);
51
+ const spans = assistantImageSpans(source, cwd, true);
49
52
  for (let index = spans.length - 1; index >= 0; index--) {
50
53
  const span = spans[index];
51
54
  source = source.slice(0, span.start) + fileLink(` 图片 ${index + 1}`, span.path, false) + source.slice(span.end);
package/lib/file-links.ts CHANGED
@@ -70,19 +70,24 @@ export function linkToolFiles(text: string, cwd: string, compact: boolean): stri
70
70
  const shorten = (label: string) => compact ? label
71
71
  .replace(/\/var\/folders\/[^\s]*\/otty-paste\//g, "…/otty-paste/")
72
72
  .replace(/node_modules\/@earendil-works\//g, "…/") : label;
73
- if (!inputCapabilities().hyperlinks) return shorten(text);
74
- // A path tool's entire argument can contain spaces or punctuation without quotes.
75
- const matches = text && !/[\x00-\x1f\x7f]/.test(text) && existsSync(localPath(text, cwd))
76
- ? [{ path: text, start: 0, end: text.length }] : filePaths(text);
77
- let result = "", offset = 0;
78
- for (const match of matches) {
79
- const path = localPath(match.path, cwd);
80
- result += shorten(text.slice(offset, match.start));
81
- const label = shorten(text.slice(match.start, match.end));
82
- result += existsSync(path) ? fileLink(label, path) : label;
83
- offset = match.end;
84
- }
85
- return result + shorten(text.slice(offset));
73
+ const hyperlinks = inputCapabilities().hyperlinks;
74
+ // Image chips already carry a complete target; never shorten or relink it.
75
+ return text.split(/(\x1b\]8;[^\x07]*\x07[\s\S]*?\x1b\]8;;\x07)/g).map((part, index) => {
76
+ if (index % 2) return part;
77
+ if (!hyperlinks) return shorten(part);
78
+ // A path tool's entire argument can contain spaces or punctuation without quotes.
79
+ const matches = part && !/[\x00-\x1f\x7f]/.test(part) && existsSync(localPath(part, cwd))
80
+ ? [{ path: part, start: 0, end: part.length }] : filePaths(part);
81
+ let result = "", offset = 0;
82
+ for (const match of matches) {
83
+ const path = localPath(match.path, cwd);
84
+ result += shorten(part.slice(offset, match.start));
85
+ const label = shorten(part.slice(match.start, match.end));
86
+ result += existsSync(path) ? fileLink(label, path, false) : label;
87
+ offset = match.end;
88
+ }
89
+ return result + shorten(part.slice(offset));
90
+ }).join("");
86
91
  }
87
92
 
88
93
  /** Display-only: normalize local targets without changing persisted messages or remote URLs. */
@@ -11,7 +11,7 @@ interface StickyToolView {
11
11
  /** ponytail: Pi 0.85 layoutRoot + optional internal layout-node export;
12
12
  * replace discovery with a public primary-scroll/layout getter when available. */
13
13
  export function attachStickyTool(tui: unknown, document: Component, view: StickyToolView, setMinHeight: (height: number) => void = () => {}): (() => void) | undefined {
14
- const host = tui as { mode?: string; terminal?: { rows: number }; layoutRoot?: Component; setLayoutRoot?: (root: Component) => void; requestRender?: () => void };
14
+ const host = tui as { mode?: string; terminal?: { rows: number }; layoutRoot?: Component; setLayoutRoot?: (root: Component) => void; requestRender?: () => void; scrollToEndIndicator?: () => string };
15
15
  if (host.mode !== "fullscreen" || !host.layoutRoot || !host.setLayoutRoot || !host.requestRender) return;
16
16
  let getNode: typeof GetLayoutNode;
17
17
  try { getNode = createRequire(import.meta.url)("@earendil-works/pi-tui/dist/layout-node.js").getLayoutNode; }
@@ -41,12 +41,20 @@ export function attachStickyTool(tui: unknown, document: Component, view: Sticky
41
41
  const transcript = scroll;
42
42
  let currentId: string | undefined;
43
43
  let shown: { id: string; line: string } | undefined;
44
+ let contentHeight = 0;
45
+ // Pi shows this indicator whenever follow-end is suspended, including at the
46
+ // content end. Keep expansion's reading position but only hint at hidden rows.
47
+ const indicatorDescriptor = Object.getOwnPropertyDescriptor(host, "scrollToEndIndicator");
48
+ const originalIndicator = host.scrollToEndIndicator;
49
+ const indicator = () => transcript.scrollTop + transcript.viewportHeight < contentHeight
50
+ ? originalIndicator?.call(host) ?? "" : "";
51
+ if (originalIndicator) host.scrollToEndIndicator = indicator;
44
52
  const heading: Component = {
45
53
  invalidate() {},
46
54
  render(width) {
47
55
  // Measure the unchanged document before moving the existing ScrollView.
48
56
  setMinHeight(0);
49
- document.render(transcript.getContentWidth(width));
57
+ contentHeight = document.render(transcript.getContentWidth(width)).length;
50
58
  const target = view.pinnedTool();
51
59
  if (!target) {
52
60
  currentId = undefined;
@@ -95,6 +103,10 @@ export function attachStickyTool(tui: unknown, document: Component, view: Sticky
95
103
  return () => {
96
104
  view.unpinTool();
97
105
  setMinHeight(0);
106
+ if (host.scrollToEndIndicator === indicator) {
107
+ if (indicatorDescriptor) Object.defineProperty(host, "scrollToEndIndicator", indicatorDescriptor);
108
+ else delete host.scrollToEndIndicator;
109
+ }
98
110
  if (host.layoutRoot === root) host.setLayoutRoot!(originalRoot);
99
111
  };
100
112
  }
@@ -0,0 +1,35 @@
1
+ import { Text, visibleWidth } from "@earendil-works/pi-tui";
2
+ import { stripVTControlCharacters } from "node:util";
3
+
4
+ const sentences = new Intl.Segmenter(undefined, { granularity: "sentence" });
5
+ const words = new Intl.Segmenter(undefined, { granularity: "word" });
6
+ const graphemes = new Intl.Segmenter(undefined, { granularity: "grapheme" });
7
+
8
+ /** Latest sentence, retaining its predecessor while a new sentence is still short. */
9
+ export function thinkingPreview(source: string, columns: number, maxRows = 1): string {
10
+ if (columns <= 0) return "";
11
+ const paragraphs = stripVTControlCharacters(source).replace(/[\x00-\x08\x0b-\x1f\x7f]/g, " ")
12
+ .split(/\n+/).map(line => line.replace(/\s+/g, " ").trim()).filter(Boolean);
13
+ const paragraph = paragraphs.at(-1) ?? "";
14
+ if (!paragraph) return "";
15
+ const parts = [...sentences.segment(paragraph)].map(part => part.segment.trim()).filter(Boolean);
16
+ let latest = parts.at(-1) ?? paragraph;
17
+ if (visibleWidth(latest) < 12 && parts.length > 1) latest = `${parts.at(-2)} ${latest}`;
18
+ const fits = (text: string) => visibleWidth(text) <= columns * maxRows && new Text(text, 0, 0).render(columns).length <= maxRows;
19
+ if (fits(latest)) return latest;
20
+
21
+ // Keep a contiguous suffix starting at a word boundary instead of sliding mid-word.
22
+ let suffix = "";
23
+ for (const { segment } of [...words.segment(latest)].reverse()) {
24
+ if (!fits(`…${(segment + suffix).trimStart()}`)) break;
25
+ suffix = segment + suffix;
26
+ }
27
+ if (!suffix.trim()) {
28
+ // An oversized word/path still respects emoji and combining-character boundaries.
29
+ for (const { segment } of [...graphemes.segment(latest)].reverse()) {
30
+ if (!fits(`…${segment + suffix}`)) break;
31
+ suffix = segment + suffix;
32
+ }
33
+ }
34
+ return suffix.trim() ? `…${suffix.trimStart()}` : "";
35
+ }
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@each1024/pi-mini-mode",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "A compact Pi footer with live usage metrics, theme-aware settings previews, and configurable progress bars.",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "check": "tsc --noEmit -p tsconfig.json",
8
8
  "test": "node test/settings-web.mjs && node test/footer-tidy.mjs && node test/footer-status-self-check.mjs && node test/settings-interaction.mjs && node test/transcript-adapter.mjs && node test/prompt-folding.mjs && node test/tool-folding.mjs && node test/sticky-tool.mjs && node test/minimal-markdown.mjs && node test/agent-view.mjs && node test/publish-self-check.mjs && node test/compaction-transcript.mjs && node test/input-enhancements.mjs && node test/user-message-surface.mjs && node test/settings-package.mjs",
9
- "prepublishOnly": "node scripts/publish.mjs --check && npm run check && npm test"
9
+ "prepublishOnly": "node scripts/publish.mjs --check && npm run check",
10
+ "release": "node scripts/release.mjs"
10
11
  },
11
12
  "license": "MIT",
12
13
  "author": "eachann1024",