@each1024/pi-mini-mode 2.0.19 → 2.0.20

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.
@@ -122,11 +122,12 @@ export function createSkillAutocompleteProvider(current: AutocompleteProvider, l
122
122
  export async function handleInput(state: Enhancements, event: InputEvent, ctx: ExtensionContext): Promise<InputEventResult | undefined> {
123
123
  if (!state.enabled() || event.source !== "interactive" || !event.text.includes("/skill:")) return undefined;
124
124
  const skills = readSkillCommands(state.pi);
125
+ const lang = state.language?.() ?? "zh";
125
126
  const text = await expandSkillTokens(
126
127
  event.text,
127
128
  skills,
128
129
  (path) => readFile(path, "utf8"),
129
- (skill) => ctx.ui.notify(`无法读取技能文件:${skill.path}`, "warning"),
130
+ (skill) => ctx.ui.notify(lang === "en" ? `Cannot read skill file: ${skill.path}` : `无法读取技能文件:${skill.path}`, "warning"),
130
131
  );
131
132
  return text === undefined ? undefined : { action: "transform", text };
132
133
  }
package/lib/link-hover.ts CHANGED
@@ -1,9 +1,105 @@
1
- import { getOsc8LinkAtColumn, sliceByColumn, visibleWidth, type TuiMouseEvent } from "@earendil-works/pi-tui";
1
+ import { sliceByColumn, visibleWidth, type TuiMouseEvent } from "@earendil-works/pi-tui";
2
2
 
3
3
  /** OSC 8 identifies targets; standard mouse events and SGR supply hover feedback.
4
4
  * Cmd is not a modifier in SGR mouse reports. The terminal owns Cmd underlining;
5
5
  * Ctrl reports can provide the same feedback inside a mouse-capturing TUI.
6
6
  */
7
+ const LINK_CACHE_MAX = 2000;
8
+ const LINK_CACHE_MAX_SOURCE = 16384;
9
+ const NO_LINKS: readonly LinkSpan[] = [];
10
+ const linkSpans = new Map<string, LinkSpan[]>();
11
+
12
+ interface LinkSpan {
13
+ start: number;
14
+ end: number;
15
+ url: string;
16
+ }
17
+
18
+ function readAnsi(line: string, pos: number): number {
19
+ if (line.charCodeAt(pos) !== 0x1b) return 0;
20
+ const next = line[pos + 1];
21
+ if (next === "[") {
22
+ let end = pos + 2;
23
+ while (end < line.length && !/[mGKHJ]/.test(line[end])) end++;
24
+ return end < line.length ? end + 1 - pos : 0;
25
+ }
26
+ if (next === "]" || next === "_") {
27
+ let end = pos + 2;
28
+ while (end < line.length) {
29
+ if (line[end] === "\x07") return end + 1 - pos;
30
+ if (line[end] === "\x1b" && line[end + 1] === "\\") return end + 2 - pos;
31
+ end++;
32
+ }
33
+ }
34
+ return 0;
35
+ }
36
+
37
+ /** One left-to-right pass. Columns follow the same ANSI skipping rules as Pi's hit test. */
38
+ function parseLinkSpans(line: string): LinkSpan[] {
39
+ const spans: LinkSpan[] = [];
40
+ let column = 0;
41
+ let index = 0;
42
+ let active: string | undefined;
43
+ let start = 0;
44
+ const close = (next: string | undefined) => {
45
+ if (active !== undefined && column > start) {
46
+ const previous = spans.at(-1);
47
+ if (previous && previous.url === active && previous.end === start) previous.end = column;
48
+ else spans.push({ start, end: column, url: active });
49
+ }
50
+ active = next;
51
+ start = column;
52
+ };
53
+ while (index < line.length) {
54
+ let textEnd = index;
55
+ while (textEnd < line.length && !(line.charCodeAt(textEnd) === 0x1b && readAnsi(line, textEnd) > 0)) textEnd++;
56
+ if (textEnd > index) {
57
+ column += visibleWidth(line.slice(index, textEnd));
58
+ index = textEnd;
59
+ }
60
+ if (index >= line.length) break;
61
+ const length = readAnsi(line, index);
62
+ if (line.startsWith("\x1b]8;", index)) {
63
+ const match = /^\x1b\]8;[^;]*;([^\x07\x1b]*)(?:\x07|\x1b\\)$/.exec(line.slice(index, index + length));
64
+ if (match) close(match[1] || undefined);
65
+ }
66
+ index += length;
67
+ }
68
+ close(undefined);
69
+ return spans;
70
+ }
71
+
72
+ function linksFor(line: string): readonly LinkSpan[] {
73
+ if (!line.includes("\x1b]8;")) return NO_LINKS;
74
+ if (line.length > LINK_CACHE_MAX_SOURCE) return parseLinkSpans(line);
75
+ const cached = linkSpans.get(line);
76
+ if (cached) {
77
+ linkSpans.delete(line);
78
+ linkSpans.set(line, cached);
79
+ return cached;
80
+ }
81
+ const parsed = parseLinkSpans(line);
82
+ if (linkSpans.size >= LINK_CACHE_MAX) {
83
+ const first = linkSpans.keys().next().value;
84
+ if (first !== undefined) linkSpans.delete(first);
85
+ }
86
+ linkSpans.set(line, parsed);
87
+ return parsed;
88
+ }
89
+
90
+ function spanAt(spans: readonly LinkSpan[], column: number): LinkSpan | undefined {
91
+ let lo = 0;
92
+ let hi = spans.length - 1;
93
+ while (lo <= hi) {
94
+ const mid = (lo + hi) >> 1;
95
+ const span = spans[mid];
96
+ if (column < span.start) hi = mid - 1;
97
+ else if (column >= span.end) lo = mid + 1;
98
+ else return span;
99
+ }
100
+ return undefined;
101
+ }
102
+
7
103
  export function createLinkHover(highlight: (text: string) => string) {
8
104
  let rows: string[] = [];
9
105
  let width = 0;
@@ -22,12 +118,9 @@ export function createLinkHover(highlight: (text: string) => string) {
22
118
  hovered.underline = underline;
23
119
  return changed;
24
120
  }
25
- const url = getOsc8LinkAtColumn(source, event.x);
26
- if (!url) return clear();
27
- let start = event.x, end = event.x + 1;
28
- while (start > 0 && getOsc8LinkAtColumn(source, start - 1) === url) start--;
29
- while (end < visibleWidth(source) && getOsc8LinkAtColumn(source, end) === url) end++;
30
- hovered = { row: event.y, start, end, source, underline };
121
+ const span = spanAt(linksFor(source), event.x);
122
+ if (!span) return clear();
123
+ hovered = { row: event.y, start: span.start, end: span.end, source, underline };
31
124
  return true;
32
125
  },
33
126
  render(lines: string[], columns: number): string[] {
@@ -72,6 +72,24 @@ function keysEqual(a: readonly unknown[], b: readonly unknown[]): boolean {
72
72
  return true;
73
73
  }
74
74
 
75
+ /** First row with this y. Each control list is one record per rendered line, so y is unique. */
76
+ function firstAtY<T extends { y: number }>(rows: readonly T[], y: number): T | undefined {
77
+ let lo = 0;
78
+ let hi = rows.length - 1;
79
+ while (lo <= hi) {
80
+ const mid = (lo + hi) >> 1;
81
+ const rowY = rows[mid].y;
82
+ if (rowY < y) lo = mid + 1;
83
+ else if (rowY > y) hi = mid - 1;
84
+ else {
85
+ let index = mid;
86
+ while (index > 0 && rows[index - 1].y === y) index--;
87
+ return rows[index];
88
+ }
89
+ }
90
+ return undefined;
91
+ }
92
+
75
93
  function isSubAgentChildRunning(child: Record<string, unknown>): boolean {
76
94
  const exit = typeof child.exitCode === "number" ? child.exitCode : undefined;
77
95
  const raw = String(child.status ?? child.state ?? "");
@@ -95,6 +113,7 @@ interface TurnRenderResult {
95
113
 
96
114
  export interface UpdateBannerState {
97
115
  version: string;
116
+ previousVersion?: string;
98
117
  collapsed: boolean;
99
118
  toggle: () => void;
100
119
  }
@@ -266,11 +285,12 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
266
285
  promptChoices: () => promptControls.map(control => ({ ...control })),
267
286
  togglePrompt,
268
287
  handleMouse(event: TuiMouseEvent) {
269
- const tool = toolControls.find(control => event.y === control.y && event.x >= 2 && event.x < Math.min(5, control.width));
288
+ const toolAt = firstAtY(toolControls, event.y);
289
+ const tool = toolAt && event.x >= 2 && event.x < Math.min(5, toolAt.width) ? toolAt : undefined;
270
290
  if (event.type === "move") {
271
291
  const linkChanged = linkHover.handleMouse(event);
272
292
  const next = !event.shift && !event.ctrl && !event.alt ? tool : undefined;
273
- const record = processRows.find(row => row.y === event.y);
293
+ const record = firstAtY(processRows, event.y);
274
294
  if (hoveredTool?.id !== next?.id || hoveredProcess?.key !== record?.key || hoveredProcess?.y !== record?.y || linkChanged) {
275
295
  hoveredTool = next;
276
296
  hoveredProcess = record;
@@ -299,7 +319,8 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
299
319
  }
300
320
  }
301
321
  }
302
- const agent = agentControls.find(control => event.y === control.y && event.x >= 0 && event.x < control.width);
322
+ const agentAt = firstAtY(agentControls, event.y);
323
+ const agent = agentAt && event.x >= 0 && event.x < agentAt.width ? agentAt : undefined;
303
324
  if (agent && (event.clickCount ?? 1) === 1) {
304
325
  if (event.type === "press") return { handled: true };
305
326
  if (event.type === "click") {
@@ -310,7 +331,8 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
310
331
  return { handled: true, render: true };
311
332
  }
312
333
  }
313
- const control = promptControls.find(control => event.y === control.y && event.x >= control.x && event.x < control.x + control.width);
334
+ const promptAt = firstAtY(promptControls, event.y);
335
+ const control = promptAt && event.x >= promptAt.x && event.x < promptAt.x + promptAt.width ? promptAt : undefined;
314
336
  if (control && (event.clickCount ?? 1) === 1) {
315
337
  if (event.type === "press") return { handled: true };
316
338
  if (event.type === "click") {
@@ -318,7 +340,8 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
318
340
  return { handled: true, render: true };
319
341
  }
320
342
  }
321
- const sub = subagentControls.find(control => event.y === control.y && event.x >= 0 && event.x < control.width);
343
+ const subAt = firstAtY(subagentControls, event.y);
344
+ const sub = subAt && event.x >= 0 && event.x < subAt.width ? subAt : undefined;
322
345
  if (sub) {
323
346
  if (event.type === "press") return { handled: true };
324
347
  if (event.type === "click") {
@@ -386,6 +409,7 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
386
409
  if (banner) {
387
410
  const renderedBanner = renderUpdateBanner(theme, width, {
388
411
  version: banner.version,
412
+ previousVersion: banner.previousVersion,
389
413
  language: lang,
390
414
  collapsed: banner.collapsed,
391
415
  });
@@ -459,8 +483,20 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
459
483
  calls.length,
460
484
  subChildren.length,
461
485
  ];
486
+ const replies = turn.replies;
487
+ if (replies) for (let i = 0; i < replies.length; i++) key.push(replies[i]);
488
+ for (let i = 0; i < turn.process.length; i++) key.push(turn.process[i]);
489
+ const clocks = turn.thinkingClocks;
490
+ if (clocks) {
491
+ for (let i = 0; i < clocks.length; i++) {
492
+ const clock = clocks[i];
493
+ key.push(clock?.startedAt, clock?.endedAt);
494
+ }
495
+ }
496
+ const outcomes = turn.thinkingOutcomes;
497
+ if (outcomes) for (let i = 0; i < outcomes.length; i++) key.push(outcomes[i]);
462
498
  for (const c of calls) {
463
- key.push(c.id, c.state, c.task, c.output?.length ?? -1, c.output, c.startedAt ?? -1, c.endedAt ?? -1);
499
+ key.push(c.id, c.state, c.task, c.output?.length ?? -1, c.output, c.startedAt ?? -1, c.endedAt ?? -1, c.name, c.tool, c.action, c.command);
464
500
  }
465
501
  for (const sub of subChildren) {
466
502
  key.push(
@@ -734,7 +770,8 @@ export function minimalOutputComponent(theme: ExtensionContext["ui"]["theme"], g
734
770
  for (const deadline of agentDeadlines.values()) if (deadline > Date.now()) agentExpiry = Math.min(agentExpiry, deadline);
735
771
  const linkedRows = linkHover.render(lines, width);
736
772
  const hovered = hoveredProcess;
737
- const hoveredRow = hovered && processRows.find(row => row.key === hovered.key && row.y === hovered.y);
773
+ const hoveredAt = hovered && firstAtY(processRows, hovered.y);
774
+ const hoveredRow = hoveredAt && hoveredAt.key === hovered.key ? hoveredAt : undefined;
738
775
  if (!hoveredRow) return linkedRows;
739
776
  const result = [...linkedRows];
740
777
  const line = result[hoveredRow.y];
@@ -1,3 +1,4 @@
1
+ import type { UiLanguage } from "./settings.ts";
1
2
  import { finiteNumber, formatSpeed, formatUsd, outputSpeed, speedColor, DECODE_SPEED_MIN_OUTPUT, type SpeedColor, type UsageLike } from "./usage.ts";
2
3
 
3
4
  /** Footer redraw cadence while a turn is streaming. */
@@ -33,6 +34,50 @@ export interface SpeedMetric {
33
34
  color?: SpeedColor | "text" | "muted";
34
35
  }
35
36
 
37
+ const SPEED_COPY: Record<UiLanguage, {
38
+ average: string;
39
+ live: string;
40
+ ttft: string;
41
+ decode: string;
42
+ output: string;
43
+ input: string;
44
+ cacheRead: string;
45
+ cacheWrite: string;
46
+ cacheWrite1h: string;
47
+ reasoning: string;
48
+ totalTokens: string;
49
+ cost: string;
50
+ }> = {
51
+ zh: {
52
+ average: "平均速度",
53
+ live: "实时速度",
54
+ ttft: "首字吐字",
55
+ decode: "解码用时",
56
+ output: "输出 token",
57
+ input: "输入 token",
58
+ cacheRead: "缓存读取",
59
+ cacheWrite: "缓存写入",
60
+ cacheWrite1h: "写入 1h",
61
+ reasoning: "推理 token",
62
+ totalTokens: "合计 token",
63
+ cost: "费用",
64
+ },
65
+ en: {
66
+ average: "Avg speed",
67
+ live: "Live speed",
68
+ ttft: "First token",
69
+ decode: "Decode time",
70
+ output: "Output tokens",
71
+ input: "Input tokens",
72
+ cacheRead: "Cache read",
73
+ cacheWrite: "Cache write",
74
+ cacheWrite1h: "Cache write 1h",
75
+ reasoning: "Reasoning tokens",
76
+ totalTokens: "Total tokens",
77
+ cost: "Cost",
78
+ },
79
+ };
80
+
36
81
  interface Sample {
37
82
  t: number;
38
83
  tokens: number;
@@ -148,7 +193,7 @@ export function createTokenSpeedTracker() {
148
193
  let liveBaseTokens = 0;
149
194
  let samples: Sample[] = [];
150
195
  let usage: UsageSnapshot = {};
151
- let frozen: SpeedMetric[] | undefined;
196
+ let frozen: Record<UiLanguage, SpeedMetric[]> | undefined;
152
197
  let runTokens = 0;
153
198
  let runElapsedMs = 0;
154
199
  let currentModelKey = "__default__";
@@ -209,29 +254,30 @@ export function createTokenSpeedTracker() {
209
254
  return outputSpeed(settledCount(), decodeStartedAt ?? firstTokenAt, end);
210
255
  };
211
256
 
212
- const collect = (): SpeedMetric[] => {
257
+ const collect = (lang: UiLanguage = "zh"): SpeedMetric[] => {
258
+ const copy = SPEED_COPY[lang] ?? SPEED_COPY.zh;
213
259
  const rows: SpeedMetric[] = [];
214
260
  const now = lastNow || Date.now();
215
261
  const average = runningAverage(now);
216
- if (average !== undefined) rows.push({ label: "平均速度", value: formatSpeed(average, true), color: speedColor(average) });
217
- if (streaming && lastLive !== undefined) rows.push({ label: "实时速度", value: formatSpeed(lastLive, true), color: speedColor(lastLive) });
262
+ if (average !== undefined) rows.push({ label: copy.average, value: formatSpeed(average, true), color: speedColor(average) });
263
+ if (streaming && lastLive !== undefined) rows.push({ label: copy.live, value: formatSpeed(lastLive, true), color: speedColor(lastLive) });
218
264
  const origin = turnStartedAt ?? assistantStartedAt;
219
265
  if (firstTokenAt !== undefined && origin !== undefined && firstTokenAt > origin) {
220
- rows.push({ label: "首字吐字", value: formatDuration(firstTokenAt - origin), color: "text" });
266
+ rows.push({ label: copy.ttft, value: formatDuration(firstTokenAt - origin), color: "text" });
221
267
  }
222
268
  const decodeStart = streaming ? firstTokenAt : (decodeStartedAt ?? firstTokenAt);
223
269
  const decodeEnd = streaming ? now : segmentEndedAt;
224
270
  if (decodeStart !== undefined && decodeEnd !== undefined && decodeEnd - decodeStart >= SPEED_REFRESH_MS) {
225
- rows.push({ label: "解码用时", value: formatDuration(decodeEnd - decodeStart), color: "text" });
271
+ rows.push({ label: copy.decode, value: formatDuration(decodeEnd - decodeStart), color: "text" });
226
272
  }
227
273
  const counts: Array<[keyof UsageSnapshot, string]> = [
228
- ["output", "输出 token"],
229
- ["input", "输入 token"],
230
- ["cacheRead", "缓存读取"],
231
- ["cacheWrite", "缓存写入"],
232
- ["cacheWrite1h", "写入 1h"],
233
- ["reasoning", "推理 token"],
234
- ["totalTokens", "合计 token"],
274
+ ["output", copy.output],
275
+ ["input", copy.input],
276
+ ["cacheRead", copy.cacheRead],
277
+ ["cacheWrite", copy.cacheWrite],
278
+ ["cacheWrite1h", copy.cacheWrite1h],
279
+ ["reasoning", copy.reasoning],
280
+ ["totalTokens", copy.totalTokens],
235
281
  ];
236
282
  for (const [key, label] of counts) {
237
283
  const value = usage[key];
@@ -239,11 +285,11 @@ export function createTokenSpeedTracker() {
239
285
  rows.push({ label, value: formatCount(value), color: "text" });
240
286
  }
241
287
  if (usage.output === undefined && !streaming && settledCount() >= DECODE_SPEED_MIN_OUTPUT) {
242
- rows.push({ label: "输出 token", value: formatCount(settledCount()), color: "text" });
288
+ rows.push({ label: copy.output, value: formatCount(settledCount()), color: "text" });
243
289
  }
244
- if (usage.cost !== undefined && usage.cost > 0) rows.push({ label: "费用", value: formatUsd(usage.cost), color: "muted" });
290
+ if (usage.cost !== undefined && usage.cost > 0) rows.push({ label: copy.cost, value: formatUsd(usage.cost), color: "muted" });
245
291
  if (rows.length === 0 && displayed !== undefined) {
246
- rows.push({ label: "平均速度", value: formatSpeed(displayed, true), color: speedColor(displayed) });
292
+ rows.push({ label: copy.average, value: formatSpeed(displayed, true), color: speedColor(displayed) });
247
293
  }
248
294
  return rows;
249
295
  };
@@ -435,7 +481,7 @@ export function createTokenSpeedTracker() {
435
481
  } else {
436
482
  displayed = lastReliable;
437
483
  }
438
- frozen = collect();
484
+ frozen = { zh: collect("zh"), en: collect("en") };
439
485
  return average !== undefined;
440
486
  },
441
487
  noteNested(output: unknown, startedAt: number, endedAt: number): boolean {
@@ -453,9 +499,10 @@ export function createTokenSpeedTracker() {
453
499
  streaming(): boolean {
454
500
  return streaming;
455
501
  },
456
- metrics(): SpeedMetric[] {
457
- if (streaming && lastLive === undefined && frozen?.length) return frozen;
458
- return collect();
502
+ metrics(lang: UiLanguage = "zh"): SpeedMetric[] {
503
+ const resolved = lang === "en" ? "en" : "zh";
504
+ if (streaming && lastLive === undefined && frozen?.[resolved]?.length) return frozen[resolved];
505
+ return collect(resolved);
459
506
  },
460
507
  reset() {
461
508
  displayed = undefined;
@@ -44,8 +44,10 @@ export function attachTranscript(tui: unknown, view: TranscriptView, options: No
44
44
  // as a transcript identity check.
45
45
  const renderDescriptor = Object.getOwnPropertyDescriptor(document, "render");
46
46
  const mouseDescriptor = Object.getOwnPropertyDescriptor(document, "handleMouse");
47
+ const invalidateDescriptor = Object.getOwnPropertyDescriptor(document, "invalidate");
47
48
  const originalRender = document.render;
48
49
  const originalMouse = document.handleMouse;
50
+ const originalInvalidate = document.invalidate;
49
51
  const now = options.now ?? Date.now;
50
52
  const schedule = options.schedule ?? ((callback, delay) => {
51
53
  const timer = setTimeout(callback, delay);
@@ -103,8 +105,16 @@ export function attachTranscript(tui: unknown, view: TranscriptView, options: No
103
105
  if (event.y < viewOffset || event.y >= viewOffset + viewHeight) return;
104
106
  return view.handleMouse?.({ ...event, y: event.y - viewOffset, height: viewHeight });
105
107
  };
108
+ // Theme changes call ui.invalidate(), which reaches this document but not the
109
+ // minimal view: it is not a TUI child, and the widget invalidate is a no-op.
110
+ // Turn-line caches omit theme, so refresh them here. Native children still run.
111
+ const invalidate: NonNullable<Component["invalidate"]> = () => {
112
+ originalInvalidate?.call(document);
113
+ view.invalidate?.();
114
+ };
106
115
  document.render = render;
107
116
  document.handleMouse = mouse;
117
+ document.invalidate = invalidate;
108
118
  // Dock events never reach the document. Observe normalized events without
109
119
  // stealing wheel/selection or changing Pi's mouse protocol/listener order.
110
120
  const restoreDock = view.clearHover ? host.children.slice(1).map(child => {
@@ -162,5 +172,9 @@ export function attachTranscript(tui: unknown, view: TranscriptView, options: No
162
172
  if (mouseDescriptor) Object.defineProperty(document, "handleMouse", mouseDescriptor);
163
173
  else { delete document.handleMouse; if (document.handleMouse !== originalMouse) document.handleMouse = originalMouse; }
164
174
  }
175
+ if (document.invalidate === invalidate) {
176
+ if (invalidateDescriptor) Object.defineProperty(document, "invalidate", invalidateDescriptor);
177
+ else { delete (document as Partial<Component>).invalidate; if (document.invalidate !== originalInvalidate) document.invalidate = originalInvalidate; }
178
+ }
165
179
  };
166
180
  }
@@ -1,13 +1,14 @@
1
1
  import { Text, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
2
2
  import { getMarkdownTheme, type ExtensionContext } from "@earendil-works/pi-coding-agent";
3
3
  import { diagramMarkdown, isMarkdownProse, renderMinimalMarkdown } from "./minimal-markdown.ts";
4
+ import type { UiLanguage } from "./settings.ts";
4
5
  import { clean, record, supervisorNotice, supervisorNoticeBody } from "./transcript-notices.ts";
5
6
 
6
7
  const renderMarkdownBody = (body: string, width: number, theme?: ExtensionContext["ui"]["theme"]) => isMarkdownProse(body)
7
8
  ? renderMinimalMarkdown(body, Math.max(1, width), getMarkdownTheme(), theme?.getBgAnsi?.("userMessageBg") ?? "", undefined, diagramMarkdown)
8
9
  : new Text(body, 0, 0).render(Math.max(1, width));
9
10
 
10
- export function compactGoalCard(entry: unknown, theme: ExtensionContext["ui"]["theme"], width: number, expanded: boolean): string[] | undefined {
11
+ export function compactGoalCard(entry: unknown, theme: ExtensionContext["ui"]["theme"], width: number, expanded: boolean, lang: UiLanguage = "zh"): string[] | undefined {
11
12
  const item = record(entry);
12
13
  if (item?.customType !== "pi-codex-goal") return;
13
14
  const data = record(item.data);
@@ -17,7 +18,7 @@ export function compactGoalCard(entry: unknown, theme: ExtensionContext["ui"]["t
17
18
  // worth adding to the compact transcript.
18
19
  if (!objective || width <= 0) return;
19
20
  const status = typeof goal?.status === "string" ? clean(goal.status) : "active";
20
- const control = truncateToWidth(expanded ? "[收起]" : "[详情]", width, "");
21
+ const control = truncateToWidth(lang === "en" ? (expanded ? "[Collapse]" : "[Details]") : (expanded ? "[收起]" : "[详情]"), width, "");
21
22
  const title = theme.fg(expanded ? "accent" : "muted", `${control} ◉ Goal · ${status}`);
22
23
  const hint = theme.fg(expanded ? "accent" : "muted", " · Ctrl+O");
23
24
  const summary = truncateToWidth(objective, Math.max(0, width - visibleWidth(title) - visibleWidth(hint) - 3), "…");
@@ -26,13 +27,13 @@ export function compactGoalCard(entry: unknown, theme: ExtensionContext["ui"]["t
26
27
  return rows;
27
28
  }
28
29
 
29
- export function compactSupervisorNotice(message: unknown, theme: ExtensionContext["ui"]["theme"], width: number, expanded: boolean, label = "", history: unknown[] = [message]): string[] | undefined {
30
- const notice = supervisorNotice(message);
30
+ export function compactSupervisorNotice(message: unknown, theme: ExtensionContext["ui"]["theme"], width: number, expanded: boolean, label = "", history: unknown[] = [message], lang: UiLanguage = "zh"): string[] | undefined {
31
+ const notice = supervisorNotice(message, lang);
31
32
  if (!notice) return;
32
33
  if (width <= 0) return [];
33
34
  const { state, color, summary } = notice;
34
35
  const effectiveLabel = label || (notice.showLabel ? notice.label ?? "" : "");
35
- const control = truncateToWidth(expanded ? "[收起]" : "[详情]", width, "");
36
+ const control = truncateToWidth(lang === "en" ? (expanded ? "[Collapse]" : "[Details]") : (expanded ? "[收起]" : "[详情]"), width, "");
36
37
  const hint = " · Ctrl+O";
37
38
  let heading: string;
38
39
  let summaryText: string;
@@ -56,7 +57,7 @@ export function compactSupervisorNotice(message: unknown, theme: ExtensionContex
56
57
  if (expanded) {
57
58
  const bodies: string[] = [];
58
59
  for (const original of history) {
59
- const body = supervisorNoticeBody(original);
60
+ const body = supervisorNoticeBody(original, lang);
60
61
  if (body && !bodies.includes(body)) bodies.push(body);
61
62
  }
62
63
  for (const body of bodies) {
@@ -1,5 +1,6 @@
1
1
  import type { Component } from "@earendil-works/pi-tui";
2
2
  import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
3
+ import type { UiLanguage } from "./settings.ts";
3
4
  import { compactGoalCard, compactSupervisorNotice } from "./transcript-cards.ts";
4
5
  import { cacheMissLine, formatCacheTokens, isSupervisorReply, record, supervisorNotice } from "./transcript-notices.ts";
5
6
 
@@ -23,6 +24,7 @@ export interface NoticeOptions {
23
24
  supervisor?: {
24
25
  theme: ExtensionContext["ui"]["theme"];
25
26
  expanded: () => boolean;
27
+ language?: () => UiLanguage;
26
28
  handledRunIds?: () => Set<string>;
27
29
  onNotices?: (groups: Map<string | Component, { first: Component; messages: unknown[]; selected: unknown; notice: NonNullable<ReturnType<typeof supervisorNotice>> }>) => void;
28
30
  };
@@ -48,11 +50,12 @@ export function createTurnNoticeRenderer(chat: { children: Component[] }, option
48
50
  return width => {
49
51
  const notices = new Map<number, NoticeRows>();
50
52
  const expanded = options.supervisor?.expanded() ?? false;
53
+ const lang: UiLanguage = options.supervisor?.language?.() ?? "zh";
51
54
  if (expanded !== globalExpanded) { expandedNotices.clear(); globalExpanded = expanded; }
52
55
  const groups = new Map<string | Component, { first: Component; messages: unknown[]; selected: unknown; notice: NonNullable<ReturnType<typeof supervisorNotice>> }>();
53
56
  if (options.supervisor) for (const child of chat.children) {
54
57
  const message = supervisorEnvelope(child);
55
- const notice = supervisorNotice(message);
58
+ const notice = supervisorNotice(message, lang);
56
59
  if (!notice) continue;
57
60
  const key = notice.key ?? child;
58
61
  const group = groups.get(key);
@@ -113,8 +116,8 @@ export function createTurnNoticeRenderer(chat: { children: Component[] }, option
113
116
  continue;
114
117
  }
115
118
  if (child.constructor.name === "CustomEntryComponent"
116
- && !(options.supervisor && supervisorNotice(supervisorEnvelope(child)))) {
117
- const goalRows = options.supervisor && compactGoalCard((child as unknown as { entry?: unknown }).entry, options.supervisor.theme, width, expandedNotices.get(child) ?? false);
119
+ && !(options.supervisor && supervisorNotice(supervisorEnvelope(child), lang))) {
120
+ const goalRows = options.supervisor && compactGoalCard((child as unknown as { entry?: unknown }).entry, options.supervisor.theme, width, expandedNotices.get(child) ?? false, lang);
118
121
  const rows = notices.get(turn) ?? [];
119
122
  if (!goalRows) {
120
123
  rows.push(...child.render(width));
@@ -133,7 +136,7 @@ export function createTurnNoticeRenderer(chat: { children: Component[] }, option
133
136
  if (child.constructor.name === "CustomMessageComponent" || child.constructor.name === "CustomEntryComponent") {
134
137
  const rows = notices.get(turn) ?? [];
135
138
  const message = supervisorEnvelope(child);
136
- const notice = options.supervisor && supervisorNotice(message);
139
+ const notice = options.supervisor && supervisorNotice(message, lang);
137
140
  const key = notice ? notice.key ?? child : child;
138
141
  const group = groups.get(key);
139
142
  if (group && group.first !== child) continue;
@@ -144,11 +147,11 @@ export function createTurnNoticeRenderer(chat: { children: Component[] }, option
144
147
  const open = expandedNotices.get(key) ?? expanded;
145
148
  const label = group.notice.showLabel
146
149
  ? group.notice.label ?? ""
147
- : groups.size > 1 ? group.notice.label || `任务 ${groupKeys.indexOf(key) + 1}` : "";
150
+ : groups.size > 1 ? group.notice.label || (lang === "en" ? `Task ${groupKeys.indexOf(key) + 1}` : `任务 ${groupKeys.indexOf(key) + 1}`) : "";
148
151
  const targets = controls.get(turn) ?? [];
149
152
  targets.push({ y: rows.length, width, key, expanded: open });
150
153
  controls.set(turn, targets);
151
- rows.push(...compactSupervisorNotice(group.selected, options.supervisor.theme, width, open, label, group.messages)!);
154
+ rows.push(...compactSupervisorNotice(group.selected, options.supervisor.theme, width, open, label, group.messages, lang)!);
152
155
  } else rows.push(...child.render(width));
153
156
  notices.set(turn, rows);
154
157
  continue;