@each1024/pi-mini-mode 2.0.17 → 2.0.19
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 +70 -11
- package/lib/agent-render.ts +352 -14
- package/lib/agent-state.ts +109 -6
- package/lib/agent-view.ts +4 -1
- package/lib/assistant-images.ts +30 -3
- package/lib/file-links.ts +24 -3
- package/lib/input-editor.ts +26 -5
- package/lib/minimal-output.ts +417 -83
- package/lib/minimal-turns.ts +18 -2
- package/lib/print-agent.ts +712 -0
- package/lib/settings.ts +6 -2
- package/lib/token-speed.ts +219 -30
- package/lib/update-banner.ts +161 -0
- package/lib/usage.ts +41 -8
- package/package.json +2 -1
package/lib/assistant-images.ts
CHANGED
|
@@ -8,8 +8,20 @@ import { commitImageCursor } from "./image-placement.ts";
|
|
|
8
8
|
const parser = new Marked();
|
|
9
9
|
export interface AssistantImageSpan { start: number; end: number; path: string }
|
|
10
10
|
|
|
11
|
+
const spansCache = new Map<string, AssistantImageSpan[]>();
|
|
12
|
+
const placeholdersCache = new Map<string, string>();
|
|
13
|
+
const IMAGE_CACHE_MAX = 800;
|
|
14
|
+
|
|
15
|
+
export function clearAssistantImageCaches(): void {
|
|
16
|
+
spansCache.clear();
|
|
17
|
+
placeholdersCache.clear();
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
/** Parse image syntax before bare paths, retaining source offsets for placement. */
|
|
12
21
|
export function assistantImageSpans(source: string, cwd: string, allowMissing = false): AssistantImageSpan[] {
|
|
22
|
+
const cacheKey = `${allowMissing ? 1 : 0}|${cwd}|${source}`;
|
|
23
|
+
const cached = spansCache.get(cacheKey);
|
|
24
|
+
if (cached !== undefined) return cached;
|
|
13
25
|
const spans: AssistantImageSpan[] = [];
|
|
14
26
|
let cursor = 0;
|
|
15
27
|
let offset = 0;
|
|
@@ -40,20 +52,35 @@ export function assistantImageSpans(source: string, cwd: string, allowMissing =
|
|
|
40
52
|
spans.push({ start: match.start, end: match.end, path: localPath(match.path, cwd) });
|
|
41
53
|
}
|
|
42
54
|
}
|
|
43
|
-
|
|
55
|
+
const result = spans.filter(span => existsSync(span.path) || (allowMissing
|
|
44
56
|
&& !/[*?]/.test(span.path)
|
|
45
57
|
&& /^(?:!\[|\/|~\/|\.{1,2}\/|[a-z]:[\\/])/i.test(source.slice(span.start, span.end))))
|
|
46
58
|
.sort((a, b) => a.start - b.start);
|
|
59
|
+
if (spansCache.size >= IMAGE_CACHE_MAX) {
|
|
60
|
+
const first = spansCache.keys().next().value;
|
|
61
|
+
if (first !== undefined) spansCache.delete(first);
|
|
62
|
+
}
|
|
63
|
+
spansCache.set(cacheKey, result);
|
|
64
|
+
return result;
|
|
47
65
|
}
|
|
48
66
|
|
|
49
67
|
/** Keep explicit image references compact even after clipboard files have expired. */
|
|
50
68
|
export function imagePlaceholders(source: string, cwd: string): string {
|
|
69
|
+
const cacheKey = `${cwd}|${source}`;
|
|
70
|
+
const cached = placeholdersCache.get(cacheKey);
|
|
71
|
+
if (cached !== undefined) return cached;
|
|
72
|
+
let out = source;
|
|
51
73
|
const spans = assistantImageSpans(source, cwd, true);
|
|
52
74
|
for (let index = spans.length - 1; index >= 0; index--) {
|
|
53
75
|
const span = spans[index];
|
|
54
|
-
|
|
76
|
+
out = out.slice(0, span.start) + fileLink(` 图片 ${index + 1}`, span.path, false) + out.slice(span.end);
|
|
77
|
+
}
|
|
78
|
+
if (placeholdersCache.size >= IMAGE_CACHE_MAX) {
|
|
79
|
+
const first = placeholdersCache.keys().next().value;
|
|
80
|
+
if (first !== undefined) placeholdersCache.delete(first);
|
|
55
81
|
}
|
|
56
|
-
|
|
82
|
+
placeholdersCache.set(cacheKey, out);
|
|
83
|
+
return out;
|
|
57
84
|
}
|
|
58
85
|
|
|
59
86
|
/** Load once outside render, then reuse Pi's Image IDs and complete height rows. */
|
package/lib/file-links.ts
CHANGED
|
@@ -65,14 +65,24 @@ export function filePaths(text: string) {
|
|
|
65
65
|
// BEL survives Markdown's backslash-escape parsing, unlike the ST terminator.
|
|
66
66
|
export const fileLink = (text: string, path: string, underline = true) => `\x1b]8;;${pathToFileURL(path).href}\x07${underline ? `\x1b[4m${text}\x1b[24m` : text}\x1b]8;;\x07`;
|
|
67
67
|
|
|
68
|
+
const linkToolFilesCache = new Map<string, string>();
|
|
69
|
+
const FILE_LINK_CACHE_MAX = 800;
|
|
70
|
+
|
|
71
|
+
export function clearFileLinkCaches(): void {
|
|
72
|
+
linkToolFilesCache.clear();
|
|
73
|
+
}
|
|
74
|
+
|
|
68
75
|
/** Shorten only visible tool labels; OSC 8 targets retain the complete original path. */
|
|
69
76
|
export function linkToolFiles(text: string, cwd: string, compact: boolean): string {
|
|
77
|
+
const hyperlinks = inputCapabilities().hyperlinks;
|
|
78
|
+
const cacheKey = `${compact ? 1 : 0}|${hyperlinks ? 1 : 0}|${cwd}|${text}`;
|
|
79
|
+
const cached = linkToolFilesCache.get(cacheKey);
|
|
80
|
+
if (cached !== undefined) return cached;
|
|
70
81
|
const shorten = (label: string) => compact ? label
|
|
71
82
|
.replace(/\/var\/folders\/[^\s]*\/otty-paste\//g, "…/otty-paste/")
|
|
72
83
|
.replace(/node_modules\/@earendil-works\//g, "…/") : label;
|
|
73
|
-
const hyperlinks = inputCapabilities().hyperlinks;
|
|
74
84
|
// Image chips already carry a complete target; never shorten or relink it.
|
|
75
|
-
|
|
85
|
+
const out = text.split(/(\x1b\]8;[^\x07]*\x07[\s\S]*?\x1b\]8;;\x07)/g).map((part, index) => {
|
|
76
86
|
if (index % 2) return part;
|
|
77
87
|
if (!hyperlinks) return shorten(part);
|
|
78
88
|
// A path tool's entire argument can contain spaces or punctuation without quotes.
|
|
@@ -89,6 +99,12 @@ export function linkToolFiles(text: string, cwd: string, compact: boolean): stri
|
|
|
89
99
|
}
|
|
90
100
|
return result + shorten(part.slice(offset));
|
|
91
101
|
}).join("");
|
|
102
|
+
if (linkToolFilesCache.size >= FILE_LINK_CACHE_MAX) {
|
|
103
|
+
const first = linkToolFilesCache.keys().next().value;
|
|
104
|
+
if (first !== undefined) linkToolFilesCache.delete(first);
|
|
105
|
+
}
|
|
106
|
+
linkToolFilesCache.set(cacheKey, out);
|
|
107
|
+
return out;
|
|
92
108
|
}
|
|
93
109
|
|
|
94
110
|
/** Display-only: normalize local targets without changing persisted messages or remote URLs. */
|
|
@@ -104,7 +120,12 @@ export function linkMessageFiles(text: string, cwd: string): string {
|
|
|
104
120
|
return existsSync(path) ? `${prefix}<${pathToFileURL(path).href}>${suffix}` : original;
|
|
105
121
|
});
|
|
106
122
|
}
|
|
107
|
-
const
|
|
123
|
+
const spaced = [...part.matchAll(/(?:^|[\s"'`])((?:\/|~\/|\.\.?\/)[^\n"'`<>()[\]{},。;!?]+?\.(?:png|jpe?g|gif|webp))(?=$|[\s"'`<>()[\]{},。;!?])/gi)]
|
|
124
|
+
.map(match => ({ path: match[1], start: match.index + match[0].length - match[1].length, end: match.index + match[0].length }))
|
|
125
|
+
.filter(match => isAbsolute(match.path) && match.path.includes(" ") && existsSync(match.path));
|
|
126
|
+
const matches = [...spaced, ...filePaths(part).filter(match => !spaced.some(full => match.start >= full.start && match.start < full.end))]
|
|
127
|
+
.sort((a, b) => a.start - b.start)
|
|
128
|
+
.map(match => ({ ...match, image: /\.(png|jpe?g|gif|webp)$/i.test(match.path) && existsSync(localPath(match.path, cwd)), number: 0 }));
|
|
108
129
|
for (const match of matches) if (match.image) match.number = ++imageNumber;
|
|
109
130
|
for (const match of matches.reverse()) {
|
|
110
131
|
const path = localPath(match.path, cwd);
|
package/lib/input-editor.ts
CHANGED
|
@@ -51,11 +51,32 @@ export function liveUI(ctx?: ExtensionContext): ExtensionContext["ui"] | undefin
|
|
|
51
51
|
function wrapEditor(inner: EditorComponent, cwd: string, isEnabled: () => boolean, isInline: () => boolean, theme: ExtensionContext["ui"]["theme"], inlineState: Enhancements, onCursor: () => void, onHoverEditor: (editor: EditorComponent, event: TuiMouseEvent) => void, onEditorRender: () => void = () => {}): EditorComponent {
|
|
52
52
|
const attachments = new Map<string, string>();
|
|
53
53
|
const sources = new Map<string, string>();
|
|
54
|
-
const expand = (text: string) =>
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
const expand = (text: string) => {
|
|
55
|
+
let result = "";
|
|
56
|
+
let cursor = 0;
|
|
57
|
+
for (const match of text.matchAll(/\[img\d+\]/g)) {
|
|
58
|
+
const label = match[0];
|
|
59
|
+
const index = match.index;
|
|
60
|
+
const path = sources.get(label) ?? attachments.get(label);
|
|
61
|
+
if (path === undefined) continue;
|
|
62
|
+
const chunk = text.slice(cursor, index);
|
|
63
|
+
const prev = result.length > 0 || chunk.length > 0 ? (chunk || result).slice(-1) : "";
|
|
64
|
+
const next = text[index + label.length] ?? "";
|
|
65
|
+
const quote = (prev === `"` || prev === `'` || prev === "`") && next === prev ? prev : "";
|
|
66
|
+
const before = quote ? (chunk.length > 1 ? chunk.slice(-2, -1) : result.slice(-1)) : prev;
|
|
67
|
+
const after = quote ? (text[index + label.length + 1] ?? "") : next;
|
|
68
|
+
const lead = before && !/\s/.test(before) ? " " : "";
|
|
69
|
+
const trail = after && !/\s/.test(after) ? " " : "";
|
|
70
|
+
if (quote) {
|
|
71
|
+
result += chunk.slice(0, -1) + lead + quote + path + quote + trail;
|
|
72
|
+
cursor = index + label.length + 1;
|
|
73
|
+
} else {
|
|
74
|
+
result += chunk + lead + path + trail;
|
|
75
|
+
cursor = index + label.length;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return result + text.slice(cursor);
|
|
79
|
+
};
|
|
59
80
|
const compact = (text: string) => {
|
|
60
81
|
if (!isEnabled()) return text;
|
|
61
82
|
const replacements = imagePathsInLine(text).map(match => {
|