@each1024/pi-mini-mode 2.0.5 → 2.0.7
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 +1 -1
- package/README.zh-CN.md +1 -1
- package/extensions/footer-status.ts +51 -33
- package/lib/assistant-images.ts +7 -4
- package/lib/file-links.ts +41 -16
- package/lib/settings.html +18 -2
- package/lib/sticky-tool.ts +14 -2
- package/lib/thinking-preview.ts +35 -0
- package/package.json +3 -2
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
|
-
|
|
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
|
-
|
|
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";
|
|
@@ -35,6 +36,7 @@ export interface MiniLensSettings {
|
|
|
35
36
|
"pi-mini-mode-speed-show": boolean;
|
|
36
37
|
"pi-mini-mode-speed-unit-show": boolean;
|
|
37
38
|
"pi-mini-mode-minimal-show": boolean;
|
|
39
|
+
"pi-mini-mode-minimal-record-limit": number;
|
|
38
40
|
"pi-mini-mode-input-enhancements": boolean;
|
|
39
41
|
"pi-mini-mode-image-preview": "hover" | "inline";
|
|
40
42
|
"pi-mini-mode-minimal-thinking-show": boolean;
|
|
@@ -64,6 +66,7 @@ export const DEFAULT_SETTINGS: Readonly<MiniLensSettings> = {
|
|
|
64
66
|
"pi-mini-mode-speed-show": true,
|
|
65
67
|
"pi-mini-mode-speed-unit-show": true,
|
|
66
68
|
"pi-mini-mode-minimal-show": true,
|
|
69
|
+
"pi-mini-mode-minimal-record-limit": 6,
|
|
67
70
|
"pi-mini-mode-input-enhancements": true,
|
|
68
71
|
"pi-mini-mode-image-preview": "inline",
|
|
69
72
|
"pi-mini-mode-minimal-thinking-show": true,
|
|
@@ -99,12 +102,18 @@ function isBoolean(value: unknown): value is boolean {
|
|
|
99
102
|
return typeof value === "boolean";
|
|
100
103
|
}
|
|
101
104
|
|
|
105
|
+
function isRecordLimit(value: unknown): value is number {
|
|
106
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0;
|
|
107
|
+
}
|
|
108
|
+
|
|
102
109
|
export function parseSettings(value: unknown): MiniLensSettings {
|
|
103
110
|
const candidate = value && typeof value === "object" ? value as Record<string, unknown> : {};
|
|
104
111
|
const settings = { ...DEFAULT_SETTINGS };
|
|
105
112
|
for (const id of SETTING_IDS) {
|
|
106
113
|
if (id === "pi-mini-mode-image-preview") {
|
|
107
114
|
if (candidate[id] === "hover" || candidate[id] === "inline") settings[id] = candidate[id];
|
|
115
|
+
} else if (id === "pi-mini-mode-minimal-record-limit") {
|
|
116
|
+
if (isRecordLimit(candidate[id])) settings[id] = candidate[id];
|
|
108
117
|
} else if (isBoolean(candidate[id])) settings[id] = candidate[id];
|
|
109
118
|
}
|
|
110
119
|
if (Array.isArray(candidate.footerOrder)) {
|
|
@@ -118,7 +127,7 @@ export function parseSettings(value: unknown): MiniLensSettings {
|
|
|
118
127
|
return settings;
|
|
119
128
|
}
|
|
120
129
|
|
|
121
|
-
/** True when saved JSON is missing a
|
|
130
|
+
/** True when saved JSON is missing a setting or a footer field, so defaults can be written back. */
|
|
122
131
|
export function settingsNeedBackfill(raw: unknown, parsed: MiniLensSettings): boolean {
|
|
123
132
|
if (!raw || typeof raw !== "object") return true;
|
|
124
133
|
const candidate = raw as Record<string, unknown>;
|
|
@@ -494,7 +503,7 @@ export function isCollapsedReplyChildSetting(id: string): boolean {
|
|
|
494
503
|
|
|
495
504
|
export function settingsItems(settings: MiniLensSettings): SettingItem[] {
|
|
496
505
|
const values = ["on", "off"];
|
|
497
|
-
const labels: Record<Exclude<keyof MiniLensSettings, "onboardingCompleted" | "footerOrder" | "pi-mini-mode-image-preview">, string> = {
|
|
506
|
+
const labels: Record<Exclude<keyof MiniLensSettings, "onboardingCompleted" | "footerOrder" | "pi-mini-mode-image-preview" | "pi-mini-mode-minimal-record-limit">, string> = {
|
|
498
507
|
"pi-mini-mode-project-branch-show": "显示项目名称和分支(互斥)",
|
|
499
508
|
"pi-mini-mode-branch-show": "仅显示分支(思考等级后,互斥)",
|
|
500
509
|
"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,
|
|
@@ -758,7 +767,7 @@ function visibleMinimalTurns(settings: MiniLensSettings, turns: MinimalTurn[]):
|
|
|
758
767
|
});
|
|
759
768
|
}
|
|
760
769
|
|
|
761
|
-
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, imageOptions?: { cwd(): string; requestRender(): void; write?(data: string): void }) {
|
|
770
|
+
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, imageOptions?: { cwd(): string; requestRender(): void; write?(data: string): void }, getRecordLimit: () => number = () => DEFAULT_SETTINGS["pi-mini-mode-minimal-record-limit"]) {
|
|
762
771
|
const placeholderText = (text: string) => imageOptions ? imagePlaceholders(text, imageOptions.cwd()) : text;
|
|
763
772
|
const markdown = (text: string, width: number, process = false) => renderMinimalMarkdown(text, width, getMarkdownTheme(), theme.getBgAnsi?.("userMessageBg") ?? "",
|
|
764
773
|
{ color: (value) => theme.fg(process ? "muted" : "text", value) }, (source, available) => transformText(placeholderText(diagramMarkdown(source, available))));
|
|
@@ -776,7 +785,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
776
785
|
const expandedSubagents = new Set<string>();
|
|
777
786
|
const expandedTools = new Set<string>();
|
|
778
787
|
const expandedThinking = new Set<string>();
|
|
779
|
-
const
|
|
788
|
+
const thinkingPreviews = new Map<string, { text: string; width: number; rows: number; updatedAt: number }>();
|
|
780
789
|
const agentModes = new Map<number, "all" | "preview" | "closed">();
|
|
781
790
|
const runningTurns = new Set<number>();
|
|
782
791
|
let pinnedToolId: string | undefined;
|
|
@@ -844,6 +853,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
844
853
|
invalidate() { clearHover(); },
|
|
845
854
|
resetProcessView() {
|
|
846
855
|
agentModes.clear(); expandedThinking.clear(); expandedTools.clear(); expandedSubagents.clear();
|
|
856
|
+
thinkingPreviews.clear();
|
|
847
857
|
pinnedToolId = undefined; pinnedAgentIndex = undefined; pinnedSubagentId = undefined;
|
|
848
858
|
},
|
|
849
859
|
clearHover,
|
|
@@ -926,6 +936,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
926
936
|
const thinkingIds = new Set(turns.flatMap((turn, turnIndex) => turn.process.flatMap((entry, processIndex) =>
|
|
927
937
|
entry.startsWith("thinking") ? [`thinking:${turnIndex}:${processIndex}`] : [])));
|
|
928
938
|
for (const id of expandedThinking) if (!thinkingIds.has(id)) expandedThinking.delete(id);
|
|
939
|
+
for (const id of thinkingPreviews.keys()) if (!thinkingIds.has(id)) thinkingPreviews.delete(id);
|
|
929
940
|
const inner = Math.max(1, width - 2 * Math.min(2, Math.floor((width - 1) / 2)));
|
|
930
941
|
const lines: string[] = [];
|
|
931
942
|
// An open heading wears the same full-width selectedBg band as an expanded SubAgent row.
|
|
@@ -975,11 +986,10 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
975
986
|
}
|
|
976
987
|
const agentTurnControls: Array<{ runId: string; y: number; width: number; line: string }> = [];
|
|
977
988
|
const agents = liveAgentView(turn.subAgents ?? [], theme, width, subAgentsExpanded(), true, agentDeadlines, Date.now(), expandedSubagents, agentTurnControls);
|
|
978
|
-
if (agents.total && !entries.length) entries.push({ title: `SubAgent ${agents.done + agents.errors}/${agents.total}`, detail: "", state: agents.running ? "running" : agents.errors ? "error" : "done", id: `agents:${index}`, thinking: false, processIndex: -1, activeThinking: false });
|
|
979
989
|
const active = !!turn.running || agents.running > 0 || entries.some(entry => entry.state === "running") || (turn.waitingTools?.length ?? 0) > 0;
|
|
980
990
|
if (active) runningTurns.add(index);
|
|
981
991
|
else if (runningTurns.delete(index)) {
|
|
982
|
-
// Return to the
|
|
992
|
+
// Return to the configured preview once; a later click can expand everything again.
|
|
983
993
|
if (agentModes.get(index) === "all") {
|
|
984
994
|
agentModes.set(index, "preview");
|
|
985
995
|
expandedThinking.clear();
|
|
@@ -993,8 +1003,10 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
993
1003
|
const expanded = mode === "all";
|
|
994
1004
|
const busy = entries.some(entry => entry.state === "running") || (turn.waitingTools?.length ?? 0) > 0;
|
|
995
1005
|
const working = turn.running && !busy && !turn.final;
|
|
996
|
-
//
|
|
997
|
-
const
|
|
1006
|
+
// Every child keeps its heading; process records share the remaining preview budget.
|
|
1007
|
+
const processLimit = Math.max(0, getRecordLimit() - agents.total);
|
|
1008
|
+
const shown = mode === "closed" ? [] : expanded ? entries : processLimit ? entries.slice(-processLimit) : [];
|
|
1009
|
+
const showWorking = working && (expanded || (!shown.length && !agents.total));
|
|
998
1010
|
const done = entries.filter(entry => entry.state === "done").length;
|
|
999
1011
|
// ponytail: two terminal text frames; use Pi's motion preference if it exposes one.
|
|
1000
1012
|
const sparkle = active ? Math.floor(Date.now() / 360) % 2 ? "✧" : "✦" : "✦";
|
|
@@ -1011,9 +1023,9 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
1011
1023
|
? theme.fg("muted", "会话 ") + theme.bold(theme.fg("text", formatTokens(usage.totalTokens)))
|
|
1012
1024
|
+ theme.fg("muted", " · 缓存 ") + theme.bold(theme.fg("text", formatTokens(usage.cacheRead)))
|
|
1013
1025
|
: "";
|
|
1014
|
-
const recordCount = entries.
|
|
1026
|
+
const recordCount = entries.length + agents.total;
|
|
1015
1027
|
const progressHeader = theme.fg(active ? "accent" : "muted", sparkle + " ") + theme.bold(theme.fg("text", "Agent")) + theme.fg("muted", recordCount ? ` · ${recordCount}` : "");
|
|
1016
|
-
const showAgentRows =
|
|
1028
|
+
const showAgentRows = agents.total > 0;
|
|
1017
1029
|
const caret = theme.fg("muted", expanded ? " ▾" : " ▸");
|
|
1018
1030
|
const elapsedHeader = turn.startedAt == null ? "" : theme.fg("muted", " · ") + theme.fg(active ? "success" : "muted", formatElapsed(turn.startedAt, turn.endedAt ?? Date.now()));
|
|
1019
1031
|
const left = progressHeader + elapsedHeader + caret;
|
|
@@ -1046,7 +1058,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
1046
1058
|
const keepStatus = entry.state === "running" || (open && entry.state === "error");
|
|
1047
1059
|
const glyph = arrow ? (open ? "▼" : "▶") + (keepStatus ? ` ${status}` : "") : status;
|
|
1048
1060
|
const glyphColor = entry.state === "error" ? "error" : entry.state === "running" || arrow ? "accent" : "muted";
|
|
1049
|
-
const last = row === shown.length - 1 && !
|
|
1061
|
+
const last = row === shown.length - 1 && !showWorking && !agents.rows.length;
|
|
1050
1062
|
const prefix = theme.fg(open ? "accent" : "dim", "│ ") + (entry.state === "running" || entry.state === "error" || arrow ? theme.fg(glyphColor, glyph) + " " : "") + summary;
|
|
1051
1063
|
if (label === "Output") {
|
|
1052
1064
|
// Wrapped output hangs under the body column and keeps the tree rail to the next sibling.
|
|
@@ -1056,20 +1068,30 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
1056
1068
|
lines.push(truncateToWidth(prefix + (wrapped[0] ?? ""), width, ""));
|
|
1057
1069
|
for (const extra of wrapped.slice(1)) lines.push(truncateToWidth(rail + extra, width, ""));
|
|
1058
1070
|
} 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
1071
|
const available = Math.max(0, width - visibleWidth(prefix));
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
: entry.
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1072
|
+
if (entry.thinking) {
|
|
1073
|
+
const now = Date.now();
|
|
1074
|
+
const cached = thinkingPreviews.get(entry.id);
|
|
1075
|
+
const previewRows = open ? 1 : 2;
|
|
1076
|
+
const reuse = activeThinking && cached?.text && cached.width === available && cached.rows === previewRows && now - cached.updatedAt < 350;
|
|
1077
|
+
const display = reuse ? cached.text : thinkingPreview(entry.detail, available, previewRows);
|
|
1078
|
+
if (!reuse) thinkingPreviews.set(entry.id, { text: display, width: available, rows: previewRows, updatedAt: now });
|
|
1079
|
+
const fallback = activeThinking ? "等待模型返回思考内容" : "模型未提供可显示的思考内容";
|
|
1080
|
+
const rows = new Text(display || fallback, 0, 0).render(Math.max(1, available)).slice(0, open ? 1 : 2);
|
|
1081
|
+
const color = activeThinking ? "accent" : "muted";
|
|
1082
|
+
lines.push(bandHeading(truncateToWidth(prefix + theme.fg(color, rows[0] ?? ""), width, ""), open));
|
|
1083
|
+
const rail = theme.fg(last ? color : "dim", last ? " " : "│") + " ".repeat(Math.max(0, visibleWidth(prefix) - 1));
|
|
1084
|
+
for (const extra of rows.slice(1)) lines.push(truncateToWidth(rail + theme.fg(color, extra), width, ""));
|
|
1085
|
+
} else {
|
|
1086
|
+
const displayBody = placeholderText(body);
|
|
1087
|
+
const compactBody = linkToolFiles(displayBody, imageOptions?.cwd() ?? process.cwd(), !open);
|
|
1088
|
+
const fittedBody = visibleWidth(compactBody) > available && !open && available > 1
|
|
1089
|
+
? "…" + sliceByColumn(compactBody, visibleWidth(compactBody) - available + 1, available - 1, true)
|
|
1090
|
+
: truncateToWidth(compactBody, available, "…");
|
|
1091
|
+
// sliceByColumn may end before OSC 8's closing sequence.
|
|
1092
|
+
const styledBody = theme.fg(open ? "accent" : "muted", fittedBody + "\x1b]8;;\x07");
|
|
1093
|
+
lines.push(bandHeading(truncateToWidth(prefix + styledBody, width, "…"), open));
|
|
1094
|
+
}
|
|
1073
1095
|
}
|
|
1074
1096
|
if (open && call && call.id === pinnedToolId) pinnedTool = { id: call.id, y: lines.length - 1, line: lines.at(-1)! };
|
|
1075
1097
|
if (open && call) {
|
|
@@ -1083,12 +1105,6 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
1083
1105
|
const rail = width > 5 ? (last ? " " : theme.fg("accent", "│ ")) : "";
|
|
1084
1106
|
const detailWidth = Math.max(1, width - visibleWidth(rail));
|
|
1085
1107
|
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
1108
|
}
|
|
1093
1109
|
});
|
|
1094
1110
|
if (showAgentRows) {
|
|
@@ -1100,10 +1116,10 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
|
|
|
1100
1116
|
}
|
|
1101
1117
|
lines.push(...agents.rows);
|
|
1102
1118
|
}
|
|
1103
|
-
if (
|
|
1119
|
+
if (showWorking) {
|
|
1104
1120
|
const label = turn.awaitingResponse && !shown.length ? "Thinking" : "Working";
|
|
1105
1121
|
const prefix = theme.fg("dim", "└─ ") + theme.fg("accent", `${runningGlyph()} `) + theme.fg("text", theme.bold(label)) + " ";
|
|
1106
|
-
lines.push(truncateToWidth(prefix + theme.fg("
|
|
1122
|
+
lines.push(truncateToWidth(prefix + theme.fg("muted", turn.awaitingResponse ? "等待模型响应" : "等待下一步执行"), width, ""));
|
|
1107
1123
|
}
|
|
1108
1124
|
}
|
|
1109
1125
|
for (const [replyIndex, reply] of (turn.replies ?? []).entries()) lines.push("", ...assistantMarkdown(reply, width, `reply:${index}:${replyIndex}`));
|
|
@@ -1252,7 +1268,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
1252
1268
|
cwd: () => ctx.cwd,
|
|
1253
1269
|
requestRender: () => tui.requestRender(),
|
|
1254
1270
|
write: data => tui.terminal.write(data),
|
|
1255
|
-
});
|
|
1271
|
+
}, () => settings["pi-mini-mode-minimal-record-limit"]);
|
|
1256
1272
|
const hintRemaining = (activeMinimalTurn?.shortcutHintUntil ?? 0) - Date.now();
|
|
1257
1273
|
if (hintRemaining > 0) {
|
|
1258
1274
|
shortcutTimer = setTimeout(() => tui.requestRender(), hintRemaining);
|
|
@@ -1424,6 +1440,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
1424
1440
|
|| entry.some(id => typeof id !== "string" || !(FOOTER_FIELDS as readonly string[]).includes(id))) throw new TypeError("Invalid order");
|
|
1425
1441
|
} else if (key === "pi-mini-mode-image-preview") {
|
|
1426
1442
|
if (entry !== "hover" && entry !== "inline") throw new TypeError("Invalid preview mode");
|
|
1443
|
+
} else if (key === "pi-mini-mode-minimal-record-limit") {
|
|
1444
|
+
if (!isRecordLimit(entry)) throw new TypeError("Invalid record limit");
|
|
1427
1445
|
} else if (!SETTING_IDS.includes(key as typeof SETTING_IDS[number]) || typeof entry !== "boolean") throw new TypeError("Invalid setting");
|
|
1428
1446
|
}
|
|
1429
1447
|
const next = parseSettings({ ...settings, ...input, onboardingCompleted: true });
|
package/lib/assistant-images.ts
CHANGED
|
@@ -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)
|
|
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
|
-
/**
|
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
|
-
import { dirname, isAbsolute, resolve } from "node:path";
|
|
3
|
+
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { Marked, getCapabilities, sliceByColumn, stripTerminalSequences, visibleWidth } from "@earendil-works/pi-tui";
|
|
6
6
|
|
|
@@ -23,6 +23,21 @@ export function localPath(path: string, cwd: string): string {
|
|
|
23
23
|
return path.startsWith("~/") ? resolve(homedir(), path.slice(2)) : isAbsolute(path) ? path : resolve(cwd, path);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/** Otty always underlines OSC 8; ordinary paths use its Cmd-only detection instead. */
|
|
27
|
+
function nativePathLinks(): boolean {
|
|
28
|
+
return process.env.TERM_PROGRAM?.toLowerCase() === "otty"
|
|
29
|
+
&& !process.env.TMUX && !process.env.STY && !/^(tmux|screen)/i.test(process.env.TERM ?? "");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Short forms must remain real paths that Otty can resolve from the pane's cwd. */
|
|
33
|
+
function nativePathLabel(path: string, cwd: string): string {
|
|
34
|
+
const fromCwd = relative(cwd, path);
|
|
35
|
+
if (fromCwd && fromCwd !== ".." && !fromCwd.startsWith("../") && !isAbsolute(fromCwd)) return `./${fromCwd}`;
|
|
36
|
+
const fromHome = relative(homedir(), path);
|
|
37
|
+
if (fromHome && fromHome !== ".." && !fromHome.startsWith("../") && !isAbsolute(fromHome)) return `~/${fromHome}`;
|
|
38
|
+
return path;
|
|
39
|
+
}
|
|
40
|
+
|
|
26
41
|
/** Opening/closing fences must stay intact; quoted paths inside them are not links. */
|
|
27
42
|
function fenceRanges(text: string): Array<[number, number]> {
|
|
28
43
|
const ranges: Array<[number, number]> = [];
|
|
@@ -67,27 +82,35 @@ export const fileLink = (text: string, path: string, underline = true) => `\x1b]
|
|
|
67
82
|
|
|
68
83
|
/** Shorten only visible tool labels; OSC 8 targets retain the complete original path. */
|
|
69
84
|
export function linkToolFiles(text: string, cwd: string, compact: boolean): string {
|
|
70
|
-
const
|
|
85
|
+
const native = nativePathLinks();
|
|
86
|
+
const shorten = (label: string) => compact && !native ? label
|
|
71
87
|
.replace(/\/var\/folders\/[^\s]*\/otty-paste\//g, "…/otty-paste/")
|
|
72
88
|
.replace(/node_modules\/@earendil-works\//g, "…/") : label;
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
89
|
+
const hyperlinks = inputCapabilities().hyperlinks;
|
|
90
|
+
// Image chips already carry a complete target; never shorten or relink it.
|
|
91
|
+
return text.split(/(\x1b\]8;[^\x07]*\x07[\s\S]*?\x1b\]8;;\x07)/g).map((part, index) => {
|
|
92
|
+
if (index % 2) return part;
|
|
93
|
+
if (!hyperlinks && !native) return shorten(part);
|
|
94
|
+
// A path tool's entire argument can contain spaces or punctuation without quotes.
|
|
95
|
+
const matches = part && !/[\x00-\x1f\x7f]/.test(part) && existsSync(localPath(part, cwd))
|
|
96
|
+
? [{ path: part, start: 0, end: part.length }] : filePaths(part);
|
|
97
|
+
let result = "", offset = 0;
|
|
98
|
+
for (const match of matches) {
|
|
99
|
+
const path = localPath(match.path, cwd);
|
|
100
|
+
result += shorten(part.slice(offset, match.start));
|
|
101
|
+
const exists = existsSync(path);
|
|
102
|
+
const label = native && compact && exists ? nativePathLabel(path, cwd) : shorten(part.slice(match.start, match.end));
|
|
103
|
+
result += exists && !native ? fileLink(label, path, false) : label;
|
|
104
|
+
offset = match.end;
|
|
105
|
+
}
|
|
106
|
+
return result + shorten(part.slice(offset));
|
|
107
|
+
}).join("");
|
|
86
108
|
}
|
|
87
109
|
|
|
88
110
|
/** Display-only: normalize local targets without changing persisted messages or remote URLs. */
|
|
89
111
|
export function linkMessageFiles(text: string, cwd: string): string {
|
|
90
112
|
if (!inputCapabilities().hyperlinks) return text;
|
|
113
|
+
const native = nativePathLinks();
|
|
91
114
|
let imageNumber = 0;
|
|
92
115
|
return text.split(/(\x1b\]8;[^\x07]*(?:\x07)[\s\S]*?\x1b\]8;;\x07|\[[^\]\n]*\]\([^\n]*?\))/g).map((part, index) => {
|
|
93
116
|
if (index % 2) {
|
|
@@ -103,7 +126,9 @@ export function linkMessageFiles(text: string, cwd: string): string {
|
|
|
103
126
|
for (const match of matches.reverse()) {
|
|
104
127
|
const path = localPath(match.path, cwd);
|
|
105
128
|
if (!existsSync(path)) continue;
|
|
106
|
-
|
|
129
|
+
const label = native && !match.image ? part.slice(match.start, match.end)
|
|
130
|
+
: fileLink(match.image ? ` #${match.number}` : match.path, path, !match.image);
|
|
131
|
+
part = part.slice(0, match.start) + label + part.slice(match.end);
|
|
107
132
|
}
|
|
108
133
|
return part;
|
|
109
134
|
}).join("");
|
package/lib/settings.html
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*{box-sizing:border-box}body{margin:0;background:var(--background);color:var(--foreground);font:var(--text-base)/1.5 ui-sans-serif,system-ui,sans-serif}main{max-width:1080px;margin:auto;padding:40px 24px 72px}header{display:flex;align-items:flex-start;justify-content:space-between;gap:16px;flex-wrap:wrap}h1{font:italic 400 var(--text-lg)/1.05 "Didot","Bodoni 72","Iowan Old Style","Songti SC","STSong",serif;letter-spacing:.04em;margin:0}h2{font-size:var(--text-sm);font-weight:600;margin:0 0 12px;letter-spacing:.08em;text-transform:uppercase;color:var(--muted)}nav{display:flex;gap:8px;align-items:center}.hint{margin:12px 0 0;color:var(--accent);font-weight:600}section{margin:28px 0}button{font:inherit;color:inherit;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:8px 12px;cursor:pointer}button:disabled{opacity:.4;cursor:default}:focus-visible{outline:2px solid var(--ring);outline-offset:3px}#preview{position:relative;padding:16px 20px;background:var(--preview-bg);color:var(--preview-text);border:1px dashed var(--border);border-radius:var(--radius);font:var(--text-sm)/1.8 ui-monospace,monospace;display:flex;flex-wrap:wrap;align-items:center;gap:4px 12px;height:112px;overflow:auto}#preview button{flex:none;font:inherit;padding:4px 2px;border-color:transparent;background:transparent;color:var(--preview-muted);cursor:grab;white-space:nowrap}#preview button:focus-visible{border-color:var(--accent)}#preview button.over{border-left:2px solid var(--accent)}#preview button.preview-exit{opacity:0;pointer-events:none;transition:opacity 280ms ease-in;position:absolute}#preview .tone-accent{color:var(--preview-accent);font-weight:650}#preview .tone-text{color:var(--preview-text)}#preview .tone-warning{color:var(--preview-warning);font-weight:650}#preview .tone-success{color:var(--preview-success);font-weight:650}#preview .tone-error{color:var(--preview-error);font-weight:650}#preview .tone-muted{color:var(--preview-muted)}#preview #preview-context{flex:1 1 180px;display:flex;align-items:center;gap:8px;min-width:180px}.progress{flex:1;overflow:hidden;text-align:left;color:var(--preview-accent);min-width:0}.grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(220px,1fr));gap:2px 6px}label{display:flex;align-items:center;gap:10px;padding:10px 0;cursor:pointer;-webkit-user-select:none;user-select:none}.grid label{border:1px solid transparent;border-radius:var(--radius);padding:10px}input{accent-color:var(--accent);width:18px;height:18px;flex-shrink:0}.dragging{opacity:.45}#statusbar{position:fixed;top:12px;right:12px;z-index:2;display:flex;align-items:center;gap:10px;max-width:min(520px,calc(100vw - 24px));padding:8px 12px;background:var(--surface);border:1px solid var(--accent);border-radius:var(--radius);box-shadow:0 6px 20px rgb(0 0 0/.12);color:var(--accent);font-size:var(--text-sm);opacity:0;transform:translateY(-6px);transition:opacity 150ms ease-out,transform 150ms ease-out;pointer-events:none}#statusbar.on{opacity:1;transform:none}#statusbar.error{border-color:var(--destructive);color:var(--destructive)}#statusbar #retry{pointer-events:auto}[hidden]{display:none!important}nav button[aria-pressed=true]{border-color:var(--accent);color:var(--accent)}.features{display:grid;grid-template-columns:repeat(auto-fit,minmax(320px,1fr));gap:12px}.feature{display:flex;flex-direction:column;background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:16px 18px}.feature-head{display:flex;align-items:center;justify-content:space-between;gap:12px}.feature-head h3{margin:0;font-size:var(--text-base);font-weight:600}.feature-body{margin:10px 0 0;color:var(--muted);font-size:var(--text-sm);line-height:1.65}.feature-points{margin:10px 0 0;padding-left:1.15em;font-size:var(--text-sm);line-height:1.7}.feature-points li{margin:2px 0}.feature-points li::marker{color:var(--accent)}.feature-hint{margin:auto 0 0;padding-top:12px;color:var(--muted);font:var(--text-sm)/1.6 ui-monospace,monospace;overflow-wrap:anywhere}.feature-hint::before{content:'› ';color:var(--accent)}.preview-mode{display:flex;align-items:center;gap:12px;flex-wrap:wrap;margin:14px 0 0;font-size:var(--text-sm)}.preview-mode select{font:inherit;color:var(--foreground);background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:8px;min-height:44px}.preview-mode select:disabled{opacity:.5}.switch{display:flex;align-items:center;gap:8px;padding:0;font-size:var(--text-sm);color:var(--muted)}.notice{display:flex;gap:16px;align-items:flex-start;justify-content:space-between;flex-wrap:wrap;margin:20px 0 0;padding:14px 16px;background:var(--surface);border:1px solid var(--accent);border-left-width:4px;border-radius:var(--radius)}.notice strong{font-size:var(--text-sm)}.notice p{margin:6px 0 0;color:var(--muted);font-size:var(--text-sm);line-height:1.6;max-width:640px}.notice code{display:block;margin:0 0 8px;padding:8px 10px;background:var(--background);border:1px solid var(--border);border-radius:var(--radius);font:var(--text-sm)/1.5 ui-monospace,monospace;white-space:pre-wrap;overflow-wrap:anywhere;max-width:520px;color:var(--foreground)}#preview{margin-top:12px;margin-bottom:20px}@media(max-width:450px){h1{font-size:2rem}main{padding:24px 16px}#statusbar{top:8px;right:8px;max-width:calc(100vw - 16px)}}@media(prefers-reduced-motion:reduce){#preview button.preview-exit{transition-duration:80ms}}@media(prefers-reduced-motion:reduce){#statusbar{transform:none;transition:opacity 80ms ease-out}}
|
|
8
8
|
@media(hover:hover) and (pointer:fine){#preview button:hover,.grid label:hover,.feature:hover{border-color:var(--accent)}}
|
|
9
9
|
#preview button.preview-highlight{border-color:var(--accent)}#preview button.preview-placeholder{border-style:dashed;opacity:1}
|
|
10
|
+
.preview-mode input[type=number]{font:inherit;color:var(--foreground);background:var(--surface);border:1px solid var(--border);border-radius:var(--radius);padding:8px;width:6em;height:44px}.preview-mode input:disabled{opacity:.5}
|
|
10
11
|
|
|
11
12
|
/* Editorial headings; controls and status data retain readable system fonts. */
|
|
12
13
|
body{background:light-dark(#f6f3ed,#141614)}main{max-width:1160px;padding:32px 32px 88px}header{align-items:flex-start;border-bottom:1px solid var(--border);padding-bottom:36px}h1{font:italic 400 clamp(2.625rem,5vw,3.625rem)/1.06 "Didot","Bodoni 72","Songti SC","STSong",serif;letter-spacing:.02em}.subtitle{font:normal 1.625rem/1.4 "Didot","Bodoni 72","Songti SC","STSong",serif;color:var(--accent);margin:16px 0 0}h2{font:normal 2rem/1.25 "Didot","Bodoni 72","Songti SC","STSong",serif;letter-spacing:0;text-transform:none;color:var(--foreground);margin:0 0 16px}section{margin:0;padding-top:24px}.feature-head h3{font:normal 1.625rem/1.25 "Didot","Bodoni 72","Songti SC","STSong",serif}.feature{padding:20px}.feature:first-child{border-top:3px solid var(--accent)}.feature-body,.feature-points{line-height:1.7}#preview{background:var(--surface);border:1px solid var(--border);padding:16px 24px;height:80px;margin-bottom:12px}.grid label{min-height:44px}@media(max-width:760px){main{padding:20px 16px 64px}header{padding-bottom:20px}.features{grid-template-columns:1fr}h2{font-size:1.75rem}.subtitle{font-size:1.375rem}}
|
|
@@ -41,14 +42,16 @@ const I18N={
|
|
|
41
42
|
fieldsHeading:{zh:'状态栏字段与预览',en:'Status bar items & preview'},
|
|
42
43
|
optionsHeading:{zh:'状态栏样式',en:'Status bar style'},
|
|
43
44
|
on:{zh:'开启',en:'On'},off:{zh:'关闭',en:'Off'},previewModeLabel:{zh:'图片预览方式',en:'Image preview mode'},previewHover:{zh:'光标浮窗',en:'Cursor popup'},previewInline:{zh:'内联卡片(多图排列)',en:'Inline cards (multiple images)'},previewModeHint:{zh:'卡片显示在输入框上方;终端不支持图片时显示占位。',en:'Cards appear above the editor; unsupported terminals show placeholders.'},
|
|
45
|
+
recordLimitLabel:{zh:'折叠时记录数',en:'Collapsed record limit'},
|
|
46
|
+
recordLimitHint:{zh:'默认 6 条。子代理始终显示,每个占一条;剩余额度显示最新执行记录。子代理超过上限时,仅显示全部子代理。',en:'Defaults to 6. Every subagent stays visible and uses one record; remaining slots show the latest execution records. When subagents exceed the limit, only their rows remain.'},
|
|
44
47
|
featureList:{
|
|
45
48
|
zh:[
|
|
46
|
-
{id:'minimal',setting:'pi-mini-mode-minimal-show',title:'极简输出',body:'把对话收成结论:思考、工具与技能汇成一棵按时间排序的可折叠过程树。',points:['长用户消息默认保留前四行,点击展开全文','
|
|
49
|
+
{id:'minimal',setting:'pi-mini-mode-minimal-show',title:'极简输出',body:'把对话收成结论:思考、工具与技能汇成一棵按时间排序的可折叠过程树。',points:['长用户消息默认保留前四行,点击展开全文','子代理始终显示,可展开活动记录与输出','Ctrl+O 展开或收起过程树,新问题默认收起','最终 Markdown 流畅呈现,失败与中断明确标记']},
|
|
47
50
|
{id:'input-enhancements',setting:'pi-mini-mode-input-enhancements',title:'输入增强',body:'让输入框和消息里的图片、技能与文件路径直接可用。',points:['光标移入图片路径即可预览,全屏编辑器同样支持','图片路径收纳为 [image1] 标签,提交时保留原图','空白后输入 / 就地搜索技能并插入光标处','点击图片标签或文件路径,用系统默认应用打开'],hint:'Ctrl+V 粘贴图片(Windows/WSL 使用 Alt+V)'},
|
|
48
51
|
{id:'themes',title:'明暗主题',body:'主题让 Markdown、代码高亮、表格与 Mermaid 图表跟随明暗切换。',points:['用户消息使用主题用户背景色,与正文区分','不支持、不完整或过宽的图表保留源文本'],hint:'回到 Pi,输入 /settings → Theme,选择 cc-dark / cc-light'}
|
|
49
52
|
],
|
|
50
53
|
en:[
|
|
51
|
-
{id:'minimal',setting:'pi-mini-mode-minimal-show',title:'Minimal transcript',body:'Turns the conversation into conclusions: thinking, tools and skills collapse into one chronological, foldable tree.',points:['Long user messages keep four lines; click to expand','
|
|
54
|
+
{id:'minimal',setting:'pi-mini-mode-minimal-show',title:'Minimal transcript',body:'Turns the conversation into conclusions: thinking, tools and skills collapse into one chronological, foldable tree.',points:['Long user messages keep four lines; click to expand','Subagents stay visible; click to expand activity and output','Ctrl+O expands or collapses the full process tree; new questions start collapsed','Final Markdown streams plainly; failures and interrupts are marked']},
|
|
52
55
|
{id:'input-enhancements',setting:'pi-mini-mode-input-enhancements',title:'Input enhancements',body:'Makes images, skills and file paths usable right where you type.',points:['Preview an image as soon as the cursor enters its path, in fullscreen too','Image paths collapse to [image1] labels while keeping the original path on submit','Type / after a space to search skills and insert at the cursor','Click image labels or file paths to open them in the default app'],hint:'Ctrl+V pastes images (Windows/WSL: Alt+V)'},
|
|
53
56
|
{id:'themes',title:'Light and dark themes',body:'Themes keep Markdown, code highlighting, tables and Mermaid diagrams in step with light and dark.',points:['User messages use the theme user background to stand out','Unsupported, incomplete or overly wide diagrams keep their source text'],hint:'In Pi, enter /settings → Theme and choose cc-dark or cc-light'}
|
|
54
57
|
]
|
|
@@ -204,6 +207,19 @@ function feature(item){
|
|
|
204
207
|
const points=document.createElement('ul');points.className='feature-points';
|
|
205
208
|
points.append(...item.points.map(point=>{const li=document.createElement('li');li.textContent=point;return li}));
|
|
206
209
|
card.append(head,body,points);
|
|
210
|
+
if(item.id==='minimal'){
|
|
211
|
+
const label=document.createElement('label');label.className='preview-mode';label.htmlFor='pi-mini-mode-minimal-record-limit';
|
|
212
|
+
const text=document.createElement('span');text.textContent=t('recordLimitLabel');
|
|
213
|
+
const input=document.createElement('input');input.type='number';input.id=label.htmlFor;input.min='1';input.step='1';input.required=true;input.disabled=!state[item.setting];
|
|
214
|
+
input.value=String(state[input.id]??6);input.onchange=()=>{
|
|
215
|
+
const value=Number(input.value);
|
|
216
|
+
if(!input.checkValidity()||!Number.isSafeInteger(value)||value<1){input.value=String(state[input.id]??6);return}
|
|
217
|
+
state[input.id]=value;change();
|
|
218
|
+
};
|
|
219
|
+
label.append(text,input);card.append(label);
|
|
220
|
+
const hint=document.createElement('p');hint.className='feature-hint';hint.textContent=t('recordLimitHint');card.append(hint);
|
|
221
|
+
head.querySelector('input').addEventListener('change',()=>{input.disabled=!state[item.setting]});
|
|
222
|
+
}
|
|
207
223
|
if(item.id==='input-enhancements'){
|
|
208
224
|
const label=document.createElement('label');label.className='preview-mode';label.htmlFor='pi-mini-mode-image-preview';
|
|
209
225
|
const text=document.createElement('span');text.textContent=t('previewModeLabel');
|
package/lib/sticky-tool.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "2.0.7",
|
|
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
|
|
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",
|