@each1024/pi-mini-mode 1.3.5 → 1.3.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 +14 -8
- package/README.zh-CN.md +16 -8
- package/extensions/footer-status.ts +88 -115
- package/lib/agent-view.ts +74 -28
- package/lib/file-links.ts +80 -0
- package/lib/input-enhancements.ts +622 -0
- package/lib/minimal-markdown.ts +42 -6
- package/lib/minimal-theme.ts +7 -3
- package/lib/transcript-adapter.ts +37 -1
- package/package.json +2 -2
- package/themes/cc-dark.json +1 -1
- package/themes/cc-light.json +1 -1
package/lib/minimal-markdown.ts
CHANGED
|
@@ -3,15 +3,22 @@ import { render } from "grok-mermaid";
|
|
|
3
3
|
|
|
4
4
|
const parser = new Marked();
|
|
5
5
|
|
|
6
|
+
/** A fence's info string is "language [options]"; only the first token names a language. */
|
|
7
|
+
const languageToken = (lang?: string) => lang?.trim().split(/\s+/)[0].toLowerCase() ?? "";
|
|
8
|
+
|
|
6
9
|
/** Theme emphasis remains visible when the terminal's CJK font lacks bold/italic faces. */
|
|
7
10
|
export function minimalMarkdownTheme(base: MarkdownTheme): MarkdownTheme {
|
|
8
11
|
// Inline prose arrives with its default foreground already applied. Remove
|
|
9
12
|
// those foreground codes before wrapping, otherwise they override emphasis.
|
|
10
13
|
const emphasis = (text: string) => base.heading(text.replace(/\x1b\[(?:38;(?:2;\d+;\d+;\d+|5;\d+)|3[0-9]|9[0-7])m/g, ""));
|
|
14
|
+
const highlightCode = base.highlightCode;
|
|
11
15
|
return {
|
|
12
16
|
...base,
|
|
13
17
|
bold: text => emphasis(base.bold(text)),
|
|
14
18
|
italic: text => emphasis(base.italic(text)),
|
|
19
|
+
// highlight.js knows languages, not info strings, so `ts title=x.ts` would
|
|
20
|
+
// otherwise lose highlighting entirely.
|
|
21
|
+
...(highlightCode && { highlightCode: (code: string, lang?: string) => highlightCode(code, languageToken(lang)) }),
|
|
15
22
|
};
|
|
16
23
|
}
|
|
17
24
|
|
|
@@ -92,22 +99,51 @@ export function normalizeProseMarkdown(source: string): string {
|
|
|
92
99
|
return parser.lexer(source).map(rewrite).join("");
|
|
93
100
|
}
|
|
94
101
|
|
|
102
|
+
/** Lexer tokens that are Markdown block structure regardless of how the body looks. */
|
|
103
|
+
const BLOCK_TOKENS = new Set(["code", "heading", "blockquote", "list", "table", "hr"]);
|
|
104
|
+
/** A hard break alone may be a shell continuation, not Markdown prose. */
|
|
105
|
+
const INLINE_TOKENS = new Set(["strong", "em", "del", "codespan", "link", "image"]);
|
|
106
|
+
/** Source that opens like code stays literal even when it also parses as inline Markdown. */
|
|
107
|
+
const LOOKS_LIKE_SOURCE = /^(?:const|let|var|function|class|import|export|SELECT|INSERT|UPDATE|DELETE)\b/m;
|
|
108
|
+
/** Preserve the existing tolerance for unfinished or malformed inline markup. */
|
|
109
|
+
const SLOPPY_EMPHASIS = /(?:\*\*|__|~~|`[^`\n]+`|\[[^\]\n]+\]\([^\n)]+\))/;
|
|
110
|
+
|
|
111
|
+
/** A body that is only a closed or streaming fence must not be sliced mid-block. */
|
|
112
|
+
export function isFencedMarkdown(source: string): boolean {
|
|
113
|
+
const tokens = parser.lexer(source.trim()).filter(token => token.type !== "space");
|
|
114
|
+
return tokens.length === 1 && tokens[0].type === "code";
|
|
115
|
+
}
|
|
116
|
+
|
|
95
117
|
/** Markdown is rendered only for semantic prose bodies; structured tool output stays literal. */
|
|
96
118
|
export function isMarkdownProse(source: string): boolean {
|
|
97
119
|
const text = source.trim();
|
|
98
|
-
if (!text
|
|
120
|
+
if (!text) return false;
|
|
121
|
+
if (/^(?:\{[\s\S]*\}|\[[\s\S]*\])$/.test(text)) {
|
|
99
122
|
try { JSON.parse(text); return false; } catch { /* a Markdown list may start with [ */ }
|
|
100
123
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
124
|
+
// The lexer decides what the body actually is: block structure first, then
|
|
125
|
+
// inline structure. Raw HTML alone is not prose, so `html` tokens are ignored.
|
|
126
|
+
let block = false;
|
|
127
|
+
let inline = false;
|
|
128
|
+
parser.walkTokens(parser.lexer(text), (token) => {
|
|
129
|
+
if (BLOCK_TOKENS.has(token.type)) block = true;
|
|
130
|
+
else if (INLINE_TOKENS.has(token.type)) inline = true;
|
|
131
|
+
});
|
|
132
|
+
if (block) return true;
|
|
133
|
+
if (LOOKS_LIKE_SOURCE.test(text)) return false;
|
|
134
|
+
return inline || SLOPPY_EMPHASIS.test(text);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** A malformed diagram must not break the render, so its own source is the fallback. */
|
|
138
|
+
function diagramArt(source: string) {
|
|
139
|
+
try { return render(source); } catch { return undefined; }
|
|
104
140
|
}
|
|
105
141
|
|
|
106
142
|
/** Keep incomplete, unsupported and over-wide diagrams readable as source. */
|
|
107
143
|
export function diagramMarkdown(source: string, width: number): string {
|
|
108
144
|
return parser.lexer(normalizeProseMarkdown(source)).map((token) => {
|
|
109
|
-
if (token.type !== "code" || token.lang
|
|
110
|
-
const art =
|
|
145
|
+
if (token.type !== "code" || languageToken(token.lang) !== "mermaid") return token.raw;
|
|
146
|
+
const art = diagramArt(token.text);
|
|
111
147
|
if (!art || art.width > width || art.warnings.length) return token.raw;
|
|
112
148
|
return art.plain.map((line) => {
|
|
113
149
|
const content = line || "\u00a0";
|
package/lib/minimal-theme.ts
CHANGED
|
@@ -14,12 +14,16 @@ function ansiColor(ansi: string): RGB | undefined {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
/** User
|
|
17
|
+
/** User uses the theme's soft surface directly; process keeps its secondary tint. */
|
|
18
18
|
export function minimalSurface(theme: ExtensionContext["ui"]["theme"], text: string, user = false): string {
|
|
19
|
-
const
|
|
19
|
+
const background = theme.getBgAnsi?.("userMessageBg") ?? "";
|
|
20
|
+
if (user) return background
|
|
21
|
+
? background + text.replace(/\x1b\[(?:0|49)?m/g, (reset) => reset + background) + "\x1b[49m"
|
|
22
|
+
: theme.bg("userMessageBg", text);
|
|
23
|
+
const base = ansiColor(background);
|
|
20
24
|
const accent = ansiColor(theme.fg("accent", "")) ?? ansiColor(theme.fg("success", ""));
|
|
21
25
|
if (!base || !accent) return theme.bg("userMessageBg", text);
|
|
22
|
-
const weight =
|
|
26
|
+
const weight = 0.07;
|
|
23
27
|
const rgb = base.map((value, i) => Math.round(value * (1 - weight) + accent[i] * weight));
|
|
24
28
|
let prefix = `\x1b[48;2;${rgb.join(";")}m`;
|
|
25
29
|
if (theme.getColorMode?.() === "256color") {
|
|
@@ -137,6 +137,41 @@ export function supervisorNotice(message: unknown) {
|
|
|
137
137
|
body: content,
|
|
138
138
|
};
|
|
139
139
|
}
|
|
140
|
+
if (item?.customType === "subagent-notify") {
|
|
141
|
+
const content = typeof item.content === "string" ? item.content : undefined;
|
|
142
|
+
const header = content?.match(/^(?:Background task|Detached foreground task) (completed|failed|paused|stopped):\s+\*\*([^\*\n]+)\*\*/m);
|
|
143
|
+
if (!content || !header) return;
|
|
144
|
+
const status = header[1];
|
|
145
|
+
const failed = status === "failed" || status === "stopped";
|
|
146
|
+
const attention = status === "paused";
|
|
147
|
+
const workflowRunId = content.match(/^Workflow run:\s*([0-9a-f-]{36})\s*$/mi)?.[1];
|
|
148
|
+
const childRunIds = content.match(/^Child runs:\s*(.+)$/mi)?.[1]
|
|
149
|
+
?.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi) ?? [];
|
|
150
|
+
const runIds = [...new Set([workflowRunId, ...childRunIds].filter((id): id is string => !!id))];
|
|
151
|
+
const runId = workflowRunId || childRunIds[0];
|
|
152
|
+
const metadata = /^(?:Workflow (?:receipt|run):|Child runs:|Session(?: file| share error)?:|Retention-managed|Reconciled detached|Parallel handoff:|Watchdog blockers:)/i;
|
|
153
|
+
let preview = "";
|
|
154
|
+
for (const line of content.split("\n").slice(1)) {
|
|
155
|
+
const text = line.trim();
|
|
156
|
+
if (!text || text.startsWith("Workflow receipt:")) continue;
|
|
157
|
+
if (metadata.test(text)) break;
|
|
158
|
+
preview = text;
|
|
159
|
+
break;
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
key: runId ? JSON.stringify(["subagent-notify", runId]) : undefined,
|
|
163
|
+
runId,
|
|
164
|
+
runIds,
|
|
165
|
+
internal: false,
|
|
166
|
+
alert: failed || attention,
|
|
167
|
+
state: failed ? "执行失败" : attention ? "需要关注" : "已完成",
|
|
168
|
+
color: failed ? "error" as const : attention ? "warning" as const : "muted" as const,
|
|
169
|
+
summary: clean(preview) || (failed ? "子任务失败" : attention ? "等待回复" : "子任务已完成"),
|
|
170
|
+
label: clean(header[2]),
|
|
171
|
+
showLabel: true,
|
|
172
|
+
body: content,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
140
175
|
const details = record(item?.details);
|
|
141
176
|
if (!details) return;
|
|
142
177
|
const event = record(details.event);
|
|
@@ -406,7 +441,8 @@ export function attachTranscript(tui: unknown, view: TranscriptView, options: No
|
|
|
406
441
|
if (group && group.first !== child) continue;
|
|
407
442
|
if (group && options.supervisor) {
|
|
408
443
|
const handled = options.supervisor.handledRunIds?.();
|
|
409
|
-
|
|
444
|
+
const noticeIds = [notice?.runId, ...((notice as { runIds?: string[] } | undefined)?.runIds ?? [])].filter((id): id is string => !!id);
|
|
445
|
+
if (handled && noticeIds.some(id => handled.has(id))) continue;
|
|
410
446
|
const open = expandedNotices.get(key) ?? expanded;
|
|
411
447
|
const label = group.notice.showLabel
|
|
412
448
|
? group.notice.label ?? ""
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@each1024/pi-mini-mode",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.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
|
-
"test": "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"
|
|
8
|
+
"test": "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"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"author": "eachann1024",
|
package/themes/cc-dark.json
CHANGED
package/themes/cc-light.json
CHANGED