@each1024/pi-mini-mode 1.3.6 → 1.3.8

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.
@@ -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 || /^(?:\{[\s\S]*\}|\[[\s\S]*\])$/.test(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
- if (/^(?:\s*```|\s*#{1,6}\s|\s*>\s|\s*(?:[-+*]\s+|\d+[.)]\s))/m.test(text)) return true;
102
- return /(?:\*\*|__|~~|`[^`\n]+`|\[[^\]\n]+\]\([^\n)]+\))/.test(text)
103
- && !/^(?:const|let|var|function|class|import|export|SELECT|INSERT|UPDATE|DELETE)\b/m.test(text);
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?.trim().toLowerCase() !== "mermaid") return token.raw;
110
- const art = render(token.text);
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";
@@ -14,12 +14,16 @@ function ansiColor(ansi: string): RGB | undefined {
14
14
  }
15
15
  }
16
16
 
17
- /** User gets the stronger accent surface; process gets its secondary tint. */
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 base = ansiColor(theme.getBgAnsi?.("userMessageBg") ?? "");
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 = user ? 0.22 : 0.07;
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") {
@@ -123,10 +123,14 @@ export function supervisorNotice(message: unknown) {
123
123
  .map(line => line.trim())
124
124
  .filter(line => line && !/^Run fan-out:/i.test(line))
125
125
  .join(" ");
126
+ const workflowRunId = content.match(/^Workflow run:\s*([0-9a-f-]{36})\s*$/mi)?.[1];
126
127
  const childRunId = content.match(/^Child run:\s*([0-9a-f-]{36})\s*$/mi)?.[1];
128
+ const runIds = [...new Set([childRunId, workflowRunId].filter((id): id is string => !!id))];
127
129
  return {
128
- key: childRunId ? JSON.stringify(["incremental-child", childRunId]) : undefined,
129
- runId: childRunId,
130
+ key: childRunId ? JSON.stringify(["incremental-child", childRunId])
131
+ : workflowRunId ? JSON.stringify(["incremental-child", workflowRunId, header[2]]) : undefined,
132
+ runId: childRunId || workflowRunId,
133
+ runIds,
130
134
  internal: false,
131
135
  alert: failed,
132
136
  state: failed ? "执行失败" : "已完成",
@@ -137,6 +141,42 @@ export function supervisorNotice(message: unknown) {
137
141
  body: content,
138
142
  };
139
143
  }
144
+ if (item?.customType === "subagent-notify") {
145
+ const content = typeof item.content === "string" ? item.content : undefined;
146
+ const header = content?.match(/^(?:Background task|Detached foreground task) (completed|failed|paused|stopped):\s+\*\*([^\*\n]+)\*\*/m);
147
+ if (!content || !header) return;
148
+ const status = header[1];
149
+ const failed = status === "failed" || status === "stopped";
150
+ const attention = status === "paused";
151
+ const workflowRunId = content.match(/^Workflow run:\s*([0-9a-f-]{36})\s*$/mi)?.[1]
152
+ ?? content.match(/^Workflow receipt:\s*.*?([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/mi)?.[1];
153
+ const childRunIds = content.match(/^Child runs:\s*(.+)$/mi)?.[1]
154
+ ?.match(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi) ?? [];
155
+ const runIds = [...new Set([workflowRunId, ...childRunIds].filter((id): id is string => !!id))];
156
+ const runId = workflowRunId || childRunIds[0];
157
+ const metadata = /^(?:Workflow (?:receipt|run):|Child runs:|Session(?: file| share error)?:|Retention-managed|Reconciled detached|Parallel handoff:|Watchdog blockers:)/i;
158
+ let preview = "";
159
+ for (const line of content.split("\n").slice(1)) {
160
+ const text = line.trim();
161
+ if (!text || text.startsWith("Workflow receipt:")) continue;
162
+ if (metadata.test(text)) break;
163
+ preview = text;
164
+ break;
165
+ }
166
+ return {
167
+ key: runId ? JSON.stringify(["subagent-notify", runId]) : undefined,
168
+ runId,
169
+ runIds,
170
+ internal: false,
171
+ alert: failed || attention,
172
+ state: failed ? "执行失败" : attention ? "需要关注" : "已完成",
173
+ color: failed ? "error" as const : attention ? "warning" as const : "muted" as const,
174
+ summary: clean(preview) || (failed ? "子任务失败" : attention ? "等待回复" : "子任务已完成"),
175
+ label: clean(header[2]),
176
+ showLabel: true,
177
+ body: content,
178
+ };
179
+ }
140
180
  const details = record(item?.details);
141
181
  if (!details) return;
142
182
  const event = record(details.event);
@@ -406,7 +446,8 @@ export function attachTranscript(tui: unknown, view: TranscriptView, options: No
406
446
  if (group && group.first !== child) continue;
407
447
  if (group && options.supervisor) {
408
448
  const handled = options.supervisor.handledRunIds?.();
409
- if (handled && notice?.runId && handled.has(notice.runId)) continue;
449
+ const noticeIds = [notice?.runId, ...((notice as { runIds?: string[] } | undefined)?.runIds ?? [])].filter((id): id is string => !!id);
450
+ if (handled && noticeIds.some(id => handled.has(id))) continue;
410
451
  const open = expandedNotices.get(key) ?? expanded;
411
452
  const label = group.notice.showLabel
412
453
  ? group.notice.label ?? ""
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@each1024/pi-mini-mode",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
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-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"
9
9
  },
10
10
  "license": "MIT",
11
11
  "author": "eachann1024",
@@ -22,7 +22,7 @@
22
22
  "muted": "#a1a1aa",
23
23
  "dim": "#71717a",
24
24
  "selectedBg": "#252035",
25
- "userMessageBg": "#1e1e2e",
25
+ "userMessageBg": "#1c273b",
26
26
  "toolPendingBg": "#1b1924",
27
27
  "toolSuccessBg": "#1e1e2e",
28
28
  "toolErrorBg": "#2a1b22",
@@ -22,7 +22,7 @@
22
22
  "muted": "#625f68",
23
23
  "dim": "#76717d",
24
24
  "selectedBg": "#e3e8f5",
25
- "userMessageBg": "#f0eef4",
25
+ "userMessageBg": "#edf2fc",
26
26
  "toolPendingBg": "#f1f3f9",
27
27
  "toolSuccessBg": "#edf7f0",
28
28
  "toolErrorBg": "#fceff1",