@herbertgao/pi-extensions 2026.10.7 → 2026.10.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.
Files changed (56) hide show
  1. package/README.md +4 -4
  2. package/THIRD_PARTY_NOTICES.md +2 -2
  3. package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +28 -27
  4. package/node_modules/@herbertgao/pi-cc-extensions/README.md +6 -6
  5. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +16 -27
  6. package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +49 -48
  7. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/compact-thinking.ts +2 -3
  8. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/context.ts +0 -60
  9. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/reference/index.ts +2 -3
  10. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/footer-layout.ts +105 -23
  11. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/footer.ts +59 -43
  12. package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +96 -0
  13. package/node_modules/@herbertgao/pi-cc-extensions/extensions/index.ts +6 -0
  14. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +36 -34
  15. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/default-mode.ts +7 -4
  16. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +3 -2
  17. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/scroll.ts +23 -8
  18. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/sticky-prompt.ts +2 -2
  19. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +24 -12
  20. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/codemode.ts +121 -6
  21. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/diff-limits.ts +3 -2
  22. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/diff-palette.ts +39 -8
  23. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/diff-presentation.ts +2 -2
  24. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +13 -13
  25. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/message-display.ts +3 -2
  26. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/names.ts +49 -49
  27. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/result.ts +24 -0
  28. package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/tool-state.ts +51 -2
  29. package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
  30. package/node_modules/@herbertgao/pi-cc-extensions/themes/cc-dark.json +71 -70
  31. package/node_modules/@herbertgao/pi-cc-extensions/themes/cc-light.json +71 -70
  32. package/node_modules/@tifan/pi-inline-skills/package.json +5 -1
  33. package/node_modules/@tifan/pi-inline-skills/src/index.ts +5 -2
  34. package/node_modules/pi-provider-qoder/dist/index.js +136 -31
  35. package/node_modules/pi-provider-qoder/package.json +1 -1
  36. package/node_modules/pi-typesafe/README.md +3 -3
  37. package/node_modules/pi-typesafe/dist/backends.d.ts +7 -2
  38. package/node_modules/pi-typesafe/dist/backends.js +42 -0
  39. package/node_modules/pi-typesafe/dist/batch.d.ts +10 -6
  40. package/node_modules/pi-typesafe/dist/batch.js +20 -9
  41. package/node_modules/pi-typesafe/dist/client.d.ts +4 -1
  42. package/node_modules/pi-typesafe/dist/client.js +5 -4
  43. package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
  44. package/node_modules/pi-typesafe/dist/index.js +1 -1
  45. package/node_modules/pi-typesafe/dist/schema.d.ts +18 -3
  46. package/node_modules/pi-typesafe/dist/schema.js +29 -3
  47. package/node_modules/pi-typesafe/package.json +1 -1
  48. package/node_modules/pi-web-access/CHANGELOG.md +16 -0
  49. package/node_modules/pi-web-access/README.md +5 -2
  50. package/node_modules/pi-web-access/dist/index.js +13 -2
  51. package/node_modules/pi-web-access/dist/mcp-cli.js +14 -3
  52. package/node_modules/pi-web-access/extract.ts +4 -2
  53. package/node_modules/pi-web-access/package.json +1 -1
  54. package/node_modules/pi-web-access/searxng.ts +2 -1
  55. package/node_modules/pi-web-access/ssrf-protection.ts +11 -0
  56. package/package.json +6 -6
@@ -11,7 +11,6 @@ import {
11
11
  import { Key, Markdown, matchesKey, visibleWidth } from "@earendil-works/pi-tui";
12
12
  import { type Color, rgbColor } from "@earendil-works/pi-tui";
13
13
  import { padLine } from "../utils/format.ts";
14
- import { mouseBaseButton, parseSgrMousePacket } from "../utils/sgr-mouse.ts";
15
14
 
16
15
  export type ContextPart = {
17
16
  label: string;
@@ -35,53 +34,6 @@ type ContextPreview = {
35
34
  content: string;
36
35
  };
37
36
 
38
- /** Pi 居中 overlay 的屏幕起点。没有 renderedOverlayLayouts 时用它,避免把 1-based 屏幕坐标当局部坐标。 */
39
- function centeredOverlayOrigin(
40
- tui: any,
41
- margin: number,
42
- maxHeightPercent: number,
43
- width: number,
44
- height: number,
45
- ) {
46
- const termWidth = Math.max(1, tui.terminal?.columns ?? 80);
47
- const termHeight = Math.max(1, tui.terminal?.rows ?? 24);
48
- const availWidth = Math.max(1, termWidth - margin * 2);
49
- const availHeight = Math.max(1, termHeight - margin * 2);
50
- const maxHeight = Math.max(
51
- 1,
52
- Math.min(Math.floor((termHeight * maxHeightPercent) / 100), availHeight),
53
- );
54
- const effectiveHeight = Math.min(height, maxHeight);
55
- return {
56
- col: Math.max(
57
- margin,
58
- Math.min(margin + Math.floor((availWidth - width) / 2), termWidth - margin - width),
59
- ),
60
- row: Math.max(
61
- margin,
62
- Math.min(
63
- margin + Math.floor((availHeight - effectiveHeight) / 2),
64
- termHeight - margin - effectiveHeight,
65
- ),
66
- ),
67
- };
68
- }
69
-
70
- function localMouseFromSgr(
71
- tui: any,
72
- mouse: { code: number; col: number; row: number; final: "M" | "m" },
73
- fallback: { col: number; row: number },
74
- ) {
75
- const layout = tui.renderedOverlayLayouts?.at(-1) ?? fallback;
76
- return {
77
- col: mouse.col - 1 - layout.col,
78
- row: mouse.row - 1 - layout.row,
79
- release: mouse.final === "m",
80
- motion: (mouse.code & 32) !== 0,
81
- baseButton: mouseBaseButton(mouse.code),
82
- };
83
- }
84
-
85
37
  function normalizePreviewText(text: string): string {
86
38
  return text
87
39
  .replace(/\r\n?/g, "\n")
@@ -170,7 +122,6 @@ export async function showTextPreview(
170
122
  }
171
123
  | undefined;
172
124
  let scrollbarDragOffset: number | null = null;
173
- let screenOrigin = { col: 0, row: 0 };
174
125
  const markdownView = new Markdown(content, 0, 0, getMarkdownTheme());
175
126
 
176
127
  const scrollTo = (nextOffset: number): void => {
@@ -326,11 +277,6 @@ export async function showTextPreview(
326
277
  else if (matchesKey(data, "pageDown")) scrollTo(scrollOffset + pageSize);
327
278
  else if (matchesKey(data, Key.home)) scrollTo(0);
328
279
  else if (matchesKey(data, Key.end)) scrollTo(totalLines - pageSize);
329
- else {
330
- const mouse = parseSgrMousePacket(data);
331
- if (!mouse) return;
332
- handlePreviewMouse(localMouseFromSgr(tui, mouse, screenOrigin));
333
- }
334
280
  },
335
281
  // overlay 事件对象路径:官方 dispatchMouseToOverlay 把鼠标派到
336
282
  // handleMouse,event.x/y 是相对弹框左上角的 0-based 局部坐标,
@@ -425,7 +371,6 @@ export async function showTextPreview(
425
371
  `${border("│")}${padLine(theme.fg("dim", ` ${status}`), inner)}${border("│")}`,
426
372
  border(`╰${"─".repeat(inner)}╯`),
427
373
  ];
428
- screenOrigin = centeredOverlayOrigin(tui, 2, 80, width, lines.length);
429
374
  return lines;
430
375
  },
431
376
  };
@@ -763,7 +708,6 @@ export default function contextUsageExtension(pi: ExtensionAPI) {
763
708
  let escHitbox: { row: number; startCol: number; endCol: number } | undefined;
764
709
  let escHovered = false;
765
710
  let hoveredKey: PreviewKey | undefined;
766
- let screenOrigin = { col: 0, row: 0 };
767
711
 
768
712
  /** context 主弹框鼠标共用处:handleInput(raw SGR)与 handleMouse(overlay
769
713
  * 事件对象)同一套 hover/选中/关闭行为。返回 true 表示被预览消费。 */
@@ -840,9 +784,6 @@ export default function contextUsageExtension(pi: ExtensionAPI) {
840
784
  done(visiblePreviews[selectedPreviewIndex]?.key);
841
785
  return;
842
786
  }
843
- const mouse = parseSgrMousePacket(data);
844
- if (!mouse) return;
845
- handleDialogMouse(localMouseFromSgr(tui, mouse, screenOrigin));
846
787
  },
847
788
  // overlay 事件对象路径:event.x/y 是弹框局部 0-based 坐标,
848
789
  // 与 hitbox 同基准。click 是 press+release 的合成,动作已在
@@ -933,7 +874,6 @@ export default function contextUsageExtension(pi: ExtensionAPI) {
933
874
  ]
934
875
  : [];
935
876
  });
936
- screenOrigin = centeredOverlayOrigin(tui, 1, 90, width, visibleHeight);
937
877
 
938
878
  return lines;
939
879
  },
@@ -419,9 +419,8 @@ export default function sessionReferenceExtension(pi: ExtensionAPI): void {
419
419
 
420
420
  getAvailableReferences = getReferences;
421
421
  if (ctx.mode === "tui") {
422
- // 预取是 detached 的,必须兜住 rejection,否则 stale 错误会变成
423
- // unhandled rejection 直接终止 Pi。
424
- void getReferences().catch(() => {});
422
+ // 不在这里预取:SessionManager.listAll() 会读完整个会话库,大库要几秒,
423
+ // 而启动并不需要结果。首次 @ 输入由 getSuggestions 触发加载。
425
424
  // Register after other session_start handlers. pi-fff claims every @
426
425
  // prefix, so a provider installed before it would never see session mentions.
427
426
  setTimeout(() => {
@@ -6,7 +6,45 @@
6
6
  export const PI_USAGE_KEY = "pi-usage";
7
7
  export const PI_USAGE_SOURCE = "@narumitw/pi-usage";
8
8
  const LEGACY_PI_USAGE_KEYS = new Set(["localUsage", "piUsage"]);
9
- export const SKIP_FOOTER_STATUS_KEY = "model";
9
+
10
+ /** 内置芯片。不是 setStatus key,由本扩展自己画。 */
11
+ export const FOOTER_MODEL_KEY = "model";
12
+ export const FOOTER_CONTEXT_KEY = "context";
13
+ export const FOOTER_CACHE_KEY = "cache";
14
+ export const FOOTER_RATE_KEY = "rate";
15
+ export const FOOTER_COST_KEY = "cost";
16
+ export const FOOTER_CWD_KEY = "cwd";
17
+ export const FOOTER_GIT_KEY = "git";
18
+
19
+ /** 默认第一行,顺序与改成可排布之前的硬编码一致。 */
20
+ export const DEFAULT_FOOTER_LINE1_KEYS = [
21
+ FOOTER_MODEL_KEY,
22
+ FOOTER_CONTEXT_KEY,
23
+ FOOTER_CACHE_KEY,
24
+ FOOTER_RATE_KEY,
25
+ FOOTER_COST_KEY,
26
+ PI_USAGE_KEY,
27
+ ] as const;
28
+
29
+ /** 默认第二行。cwd 在前,git 在后。 */
30
+ export const DEFAULT_FOOTER_LINE2_KEYS = [FOOTER_CWD_KEY, FOOTER_GIT_KEY] as const;
31
+
32
+ /** 改成可排布之前就写死的项。pi-usage 不算:旧配置里本来就有它。 */
33
+ const LEGACY_FIXED_FOOTER_KEYS = [
34
+ FOOTER_MODEL_KEY,
35
+ FOOTER_CONTEXT_KEY,
36
+ FOOTER_CACHE_KEY,
37
+ FOOTER_RATE_KEY,
38
+ FOOTER_COST_KEY,
39
+ FOOTER_CWD_KEY,
40
+ FOOTER_GIT_KEY,
41
+ ] as const;
42
+
43
+ const BUILTIN_FOOTER_KEYS = new Set<string>(LEGACY_FIXED_FOOTER_KEYS);
44
+
45
+ export function isBuiltinFooterKey(key: string): boolean {
46
+ return BUILTIN_FOOTER_KEYS.has(key);
47
+ }
10
48
 
11
49
  export type FooterLineId = 1 | 2 | 3;
12
50
 
@@ -19,18 +57,20 @@ export type FooterChipLayout = {
19
57
 
20
58
  export const DEFAULT_FOOTER_CHIP_LAYOUT: FooterChipLayout = {
21
59
  footerHiddenKeys: [],
22
- footerLine1Keys: [PI_USAGE_KEY],
23
- footerLine2Keys: [],
60
+ footerLine1Keys: [...DEFAULT_FOOTER_LINE1_KEYS],
61
+ footerLine2Keys: [...DEFAULT_FOOTER_LINE2_KEYS],
24
62
  footerLine3Keys: [],
25
63
  };
26
64
 
65
+ /** 别的扩展写的 model 状态与本扩展的模型芯片重名,不当插件芯片接纳。配置里的 model 不受影响。 */
27
66
  export function isSkippedFooterStatusKey(key: string): boolean {
28
- return key === SKIP_FOOTER_STATUS_KEY;
67
+ return key === FOOTER_MODEL_KEY;
29
68
  }
30
69
 
31
- /** 未单独配置时的默认行:usage 类和本包用量在 line1,其余 line2。不会默认进 line3。 */
70
+ /** 未单独配置时的默认行:内置项按原来的行,usage 类在 line1,其余 line2。不会默认进 line3。 */
32
71
  export function defaultFooterLine(key: string): FooterLineId {
33
- if (key === PI_USAGE_KEY) return 1;
72
+ if ((DEFAULT_FOOTER_LINE1_KEYS as readonly string[]).includes(key)) return 1;
73
+ if ((DEFAULT_FOOTER_LINE2_KEYS as readonly string[]).includes(key)) return 2;
34
74
  if (/usage|quota|balance/i.test(key)) return 1;
35
75
  return 2;
36
76
  }
@@ -43,7 +83,7 @@ export function normalizeFooterKeyList(value: unknown): string[] {
43
83
  if (typeof item !== "string") continue;
44
84
  let key = item.trim();
45
85
  if (LEGACY_PI_USAGE_KEYS.has(key)) key = PI_USAGE_KEY;
46
- if (!key || isSkippedFooterStatusKey(key) || seen.has(key)) continue;
86
+ if (!key || seen.has(key)) continue;
47
87
  seen.add(key);
48
88
  out.push(key);
49
89
  }
@@ -60,37 +100,81 @@ function takeUnique(keys: string[], seen: Set<string>): string[] {
60
100
  return out;
61
101
  }
62
102
 
63
- /** 跨行去重(line1 → line2 → line3);补上 pi-usage 槽位。 */
103
+ /**
104
+ * 旧配置只排插件芯片,内置项是硬编码的。
105
+ * 三条行都没出现过内置 key 时,按原位置补上,已有插件顺序不动。
106
+ */
107
+ function ensureBuiltinKeys(
108
+ line1: string[],
109
+ line2: string[],
110
+ line3: string[],
111
+ ): { footerLine1Keys: string[]; footerLine2Keys: string[]; footerLine3Keys: string[] } {
112
+ const seen = new Set([...line1, ...line2, ...line3]);
113
+ if (LEGACY_FIXED_FOOTER_KEYS.some((key) => seen.has(key))) {
114
+ return { footerLine1Keys: line1, footerLine2Keys: line2, footerLine3Keys: line3 };
115
+ }
116
+ const line1Builtins = DEFAULT_FOOTER_LINE1_KEYS.filter((key) => key !== PI_USAGE_KEY);
117
+ const usageAt = line1.indexOf(PI_USAGE_KEY);
118
+ const footerLine1Keys =
119
+ usageAt >= 0
120
+ ? [...line1.slice(0, usageAt), ...line1Builtins, ...line1.slice(usageAt)]
121
+ : [...line1Builtins, ...line1];
122
+ return {
123
+ footerLine1Keys,
124
+ footerLine2Keys: [...DEFAULT_FOOTER_LINE2_KEYS, ...line2],
125
+ footerLine3Keys: line3,
126
+ };
127
+ }
128
+
129
+ /** 跨行去重(line1 → line2 → line3);旧配置补上内置芯片。 */
64
130
  export function normalizeFooterChipLayout(source: Record<string, unknown>): FooterChipLayout {
65
131
  const hasHidden = Array.isArray(source.footerHiddenKeys);
66
132
  const hasAnyLine = [source.footerLine1Keys, source.footerLine2Keys, source.footerLine3Keys].some(
67
133
  Array.isArray,
68
134
  );
69
- const seen = new Set<string>();
70
- let footerLine1Keys = takeUnique(normalizeFooterKeyList(source.footerLine1Keys), seen);
71
- const footerLine2Keys = takeUnique(normalizeFooterKeyList(source.footerLine2Keys), seen);
72
- const footerLine3Keys = takeUnique(normalizeFooterKeyList(source.footerLine3Keys), seen);
73
- const footerHiddenKeys = normalizeFooterKeyList(source.footerHiddenKeys);
74
-
75
- if (!seen.has(PI_USAGE_KEY)) {
76
- footerLine1Keys = [PI_USAGE_KEY, ...footerLine1Keys];
77
- }
78
135
  if (!hasHidden && !hasAnyLine) {
79
- return { ...DEFAULT_FOOTER_CHIP_LAYOUT };
136
+ return {
137
+ footerHiddenKeys: [],
138
+ footerLine1Keys: [...DEFAULT_FOOTER_LINE1_KEYS],
139
+ footerLine2Keys: [...DEFAULT_FOOTER_LINE2_KEYS],
140
+ footerLine3Keys: [],
141
+ };
80
142
  }
81
- return { footerHiddenKeys, footerLine1Keys, footerLine2Keys, footerLine3Keys };
143
+ const seen = new Set<string>();
144
+ const line1 = takeUnique(normalizeFooterKeyList(source.footerLine1Keys), seen);
145
+ const line2 = takeUnique(normalizeFooterKeyList(source.footerLine2Keys), seen);
146
+ const line3 = takeUnique(normalizeFooterKeyList(source.footerLine3Keys), seen);
147
+ return {
148
+ footerHiddenKeys: normalizeFooterKeyList(source.footerHiddenKeys),
149
+ ...ensureBuiltinKeys(line1, line2, line3),
150
+ };
82
151
  }
83
152
 
84
- /** 面板描述用:pi-usage 数据来自 @narumitw/pi-usage,其它芯片用来源 setStatus key。 */
153
+ const BUILTIN_FOOTER_LABEL: Record<string, string> = {
154
+ [FOOTER_MODEL_KEY]: "Model and thinking level",
155
+ [FOOTER_CONTEXT_KEY]: "Context window bar",
156
+ [FOOTER_CACHE_KEY]: "Cache hit rate",
157
+ [FOOTER_RATE_KEY]: "Output rate",
158
+ [FOOTER_COST_KEY]: "Session cost",
159
+ [FOOTER_CWD_KEY]: "Working directory and session name",
160
+ [FOOTER_GIT_KEY]: "Branch and change stats",
161
+ };
162
+
163
+ /** 面板描述用:内置项写明内容,pi-usage 注明来源,其它芯片用来源 setStatus key。 */
85
164
  export function footerChipSource(key: string): string {
86
165
  return key === PI_USAGE_KEY ? PI_USAGE_SOURCE : key;
87
166
  }
88
167
 
89
168
  export function footerChipDescription(key: string, liveText: string): string {
169
+ const builtin = BUILTIN_FOOTER_LABEL[key];
170
+ if (builtin) {
171
+ const live = liveText.trim();
172
+ return live ? `${builtin} · ${live}` : builtin;
173
+ }
90
174
  const source = footerChipSource(key);
91
175
  const live = liveText.trim();
92
176
  if (live) return `${live} · from ${source}`;
93
- if (key === PI_USAGE_KEY) return `From ${source}. No text right now.`;
177
+ if (key === PI_USAGE_KEY) return `From ${PI_USAGE_SOURCE}. No text right now.`;
94
178
  return `inactive · from ${source}`;
95
179
  }
96
180
 
@@ -151,7 +235,6 @@ export function moveFooterKeyToLine(
151
235
  key: string,
152
236
  line: FooterLineId,
153
237
  ): FooterChipLayout {
154
- if (isSkippedFooterStatusKey(key)) return layout;
155
238
  const current = footerLineOfKey(layout, key);
156
239
  if (current === line) return layout;
157
240
  const stripped: FooterChipLayout = {
@@ -193,7 +276,6 @@ export function reorderFooterKey(
193
276
  }
194
277
 
195
278
  export function toggleFooterKeyHidden(layout: FooterChipLayout, key: string): FooterChipLayout {
196
- if (isSkippedFooterStatusKey(key)) return layout;
197
279
  const hidden = new Set(layout.footerHiddenKeys);
198
280
  if (hidden.has(key)) hidden.delete(key);
199
281
  else hidden.add(key);
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * 自定义底栏:chips + zentui 图标/句子
3
3
  *
4
- * 第一行:model thinking · ██████░░░░ 45%/200k · 󰆼 42% · $0.01 · 用户排到 line1 的插件芯片
5
- * 第二行:cwd in session on  branch (+16 −1) · 用户排到 line2 的插件芯片
6
- * 第三行:仅当 line3 有可见插件芯片时出现
4
+ * 默认第一行:model thinking · ██████░░░░ 45%/200k · 󰆼 42% · $0.01 · pi-usage · 其余 line1 芯片
5
+ * 默认第二行:cwd in session ·  branch (+16 −1) · 其余 line2 芯片
6
+ * 第三行:仅当 line3 有可见芯片时出现
7
+ * model / context / cache / rate / cost / cwd / git 与插件芯片同一套排布,可换行、调序、隐藏
7
8
  *
8
9
  * - line1 短芯片,· 分隔;缓存用 zentui 󰆼,费用 success
9
10
  * - line2 用 zentui 句式 in / on + 
@@ -23,7 +24,15 @@ import { stripAnsi } from "../../utils/ansi-text.ts";
23
24
  import { formatFooterCost } from "./footer-currency.ts";
24
25
  import { formatTokenCount } from "../../utils/format.ts";
25
26
  import {
27
+ FOOTER_CACHE_KEY,
28
+ FOOTER_CONTEXT_KEY,
29
+ FOOTER_COST_KEY,
30
+ FOOTER_CWD_KEY,
31
+ FOOTER_GIT_KEY,
32
+ FOOTER_MODEL_KEY,
33
+ FOOTER_RATE_KEY,
26
34
  PI_USAGE_KEY,
35
+ isBuiltinFooterKey,
27
36
  isSkippedFooterStatusKey,
28
37
  resolveFooterChipLayout,
29
38
  visibleFooterPluginTexts,
@@ -31,6 +40,7 @@ import {
31
40
  } from "./footer-layout.ts";
32
41
  import { createGitStatsRefresher, readGitStats, type GitStats } from "./git-stats.ts";
33
42
  import { MCP_STATUS_KEY, buildMcpChip } from "./mcp-chip.ts";
43
+ import { inputTextIndent } from "./prompt-editor.ts";
34
44
  import { currentTtftMs, displayTokenRate, formatTokenRate } from "./token-rate.ts";
35
45
 
36
46
  export { parseGitStats } from "./git-stats.ts";
@@ -144,11 +154,11 @@ function ownMcpChip(): string {
144
154
  return cachedMcpChip && !cachedExtensionStatuses.has(MCP_STATUS_KEY) ? cachedMcpChip : "";
145
155
  }
146
156
 
147
- /** 面板用:当前 setStatus 文案 + 本包 pi-usage / MCP(无文案时为空字符串)。 */
157
+ /** 面板用:当前 setStatus 文案 + 本包 pi-usage / MCP(无文案时为空字符串)。内置项由配置保证在列表里。 */
148
158
  export function getFooterStatusSnapshot(): Map<string, string> {
149
159
  const out = new Map<string, string>();
150
160
  for (const [key, text] of cachedExtensionStatuses) {
151
- if (isSkippedFooterStatusKey(key)) continue;
161
+ if (isSkippedFooterStatusKey(key) || isBuiltinFooterKey(key)) continue;
152
162
  out.set(key, text);
153
163
  }
154
164
  out.set(PI_USAGE_KEY, cachedLocalUsageText);
@@ -418,21 +428,6 @@ const createCustomFooterFactory =
418
428
  if (mcpChip) pluginTexts.set(MCP_STATUS_KEY, mcpChip);
419
429
  const layout = resolveFooterChipLayout(layoutFromConfig(), [...pluginTexts.keys()]);
420
430
  const dimPlugin = (text: string) => colorUsageChip(theme, text);
421
- const line1Plugins = visibleFooterPluginTexts(
422
- layout.footerLine1Keys,
423
- layout.footerHiddenKeys,
424
- pluginTexts,
425
- ).map(dimPlugin);
426
- const line2Plugins = visibleFooterPluginTexts(
427
- layout.footerLine2Keys,
428
- layout.footerHiddenKeys,
429
- pluginTexts,
430
- ).map(dimPlugin);
431
- const line3Plugins = visibleFooterPluginTexts(
432
- layout.footerLine3Keys,
433
- layout.footerHiddenKeys,
434
- pluginTexts,
435
- ).map(dimPlugin);
436
431
 
437
432
  const pctLabel = percent === null || percent === undefined ? "?" : `${Math.floor(percent)}%`;
438
433
  const cachePct = getCachePct();
@@ -447,22 +442,13 @@ const createCustomFooterFactory =
447
442
  config.footerTokenRateTtft,
448
443
  )
449
444
  : "";
450
- const rateChip = rateLabel ? theme.fg("dim", rateLabel) : "";
451
- const costChip =
445
+ const costLabel =
452
446
  cost || usingSubscription
453
- ? theme.fg(
454
- "dim",
455
- formatFooterCost(cost, config.footerCurrency, config.footerCurrencyRate),
456
- ) + (usingSubscription ? theme.fg("warning", " sub") : "")
447
+ ? formatFooterCost(cost, config.footerCurrency, config.footerCurrencyRate)
457
448
  : "";
458
- const line1 = joinChips([
459
- modelChip(theme, modelLabel, model?.reasoning ? thinkingLevelStr : "", thinkingColor),
460
- barGauge(percent ?? 0) + theme.fg("dim", ` ${pctLabel}/${fmt(contextWindow)}`),
461
- cacheLabel ? theme.fg("dim", cacheLabel) : "",
462
- rateChip,
463
- costChip,
464
- ...line1Plugins,
465
- ]);
449
+ const costChip = costLabel
450
+ ? theme.fg("dim", costLabel) + (usingSubscription ? theme.fg("warning", " sub") : "")
451
+ : "";
466
452
 
467
453
  const gitColor = theme.getThinkingBorderColor("medium");
468
454
  let place = theme.fg("accent", cwdLabel);
@@ -471,6 +457,7 @@ const createCustomFooterFactory =
471
457
  place += theme.fg("muted", " in ") + theme.fg("success", sessionName);
472
458
  }
473
459
  const branch = footerData.getGitBranch();
460
+ let gitChip = "";
474
461
  if (branch) {
475
462
  const s = gitStats;
476
463
  let stats = "";
@@ -484,16 +471,45 @@ const createCustomFooterFactory =
484
471
  theme.fg("error", `−${s.del}`) +
485
472
  theme.fg("dim", ")");
486
473
  const gitLabel = glyphs.git ? `${glyphs.git} ${branch}` : branch;
487
- place += theme.fg("muted", " on ") + gitColor(gitLabel) + stats;
474
+ gitChip = gitColor(gitLabel) + stats;
488
475
  }
489
- const line2 = joinChips([place, ...line2Plugins]);
490
- const line3 = joinChips(line3Plugins);
491
-
492
- return [
493
- truncateToWidth(line1, width),
494
- ...(line2 ? [truncateToWidth(line2, width)] : []),
495
- ...(line3 ? [truncateToWidth(line3, width)] : []),
496
- ];
476
+
477
+ const builtinChips = new Map<string, string>([
478
+ [
479
+ FOOTER_MODEL_KEY,
480
+ modelChip(theme, modelLabel, model?.reasoning ? thinkingLevelStr : "", thinkingColor),
481
+ ],
482
+ [
483
+ FOOTER_CONTEXT_KEY,
484
+ barGauge(percent ?? 0) + theme.fg("dim", ` ${pctLabel}/${fmt(contextWindow)}`),
485
+ ],
486
+ [FOOTER_CACHE_KEY, cacheLabel ? theme.fg("dim", cacheLabel) : ""],
487
+ [FOOTER_RATE_KEY, rateLabel ? theme.fg("dim", rateLabel) : ""],
488
+ [FOOTER_COST_KEY, costChip],
489
+ [FOOTER_CWD_KEY, place],
490
+ [FOOTER_GIT_KEY, gitChip],
491
+ ]);
492
+
493
+ const lineOf = (keys: readonly string[]) =>
494
+ joinChips(
495
+ keys
496
+ .filter((key) => !layout.footerHiddenKeys.includes(key))
497
+ .map((key) => {
498
+ if (isBuiltinFooterKey(key)) return builtinChips.get(key) ?? "";
499
+ const text = visibleFooterPluginTexts([key], [], pluginTexts)[0];
500
+ return text ? dimPlugin(text) : "";
501
+ }),
502
+ );
503
+ const line1 = lineOf(layout.footerLine1Keys);
504
+ const line2 = lineOf(layout.footerLine2Keys);
505
+ const line3 = lineOf(layout.footerLine3Keys);
506
+
507
+ // 对齐输入文本起始列:editorPaddingX + `❯ ` 的 2 列(随编辑器 render 实时更新)。
508
+ const indent = " ".repeat(inputTextIndent());
509
+ const fit = (line: string) =>
510
+ indent + truncateToWidth(line, Math.max(1, width - indent.length));
511
+
512
+ return [fit(line1), ...(line2 ? [fit(line2)] : []), ...(line3 ? [fit(line3)] : [])];
497
513
  };
498
514
 
499
515
  return {
@@ -0,0 +1,96 @@
1
+ /**
2
+ * 输入框 `❯` 提示符(issue #68)。
3
+ *
4
+ * `PromptEditor` 继承 `CustomEditor`:pi 的 setCustomEditorComponent 会自动接线
5
+ * onSubmit/onChange/actionHandlers/autocomplete/工作状态指示器,本扩展只管渲染。
6
+ *
7
+ * `❯ ` 恒占左侧 2 列:渲染前把 paddingX 抬到「用户值 + 2」(直接改字段绕过
8
+ * setter,避免每帧 requestRender 自激),渲染后恢复。首内容行前两列换成
9
+ * `❯ `,其后仍保留用户 editorPaddingX 的空格。
10
+ * `❯` 颜色直接用 `borderColor`,随 thinking 等级 / bash mode 自动联动。
11
+ *
12
+ * `userPaddingX` 记录渲染时读到的用户 editorPaddingX(pi 通过 setPaddingX
13
+ * 同步进本编辑器),footer 用 `inputTextIndent()` 对齐输入文本起始列:
14
+ * 前缀开 = userPaddingX + 2,关 = userPaddingX。
15
+ */
16
+ import { CustomEditor, type ExtensionContext } from "@earendil-works/pi-coding-agent";
17
+ import { config } from "../../config/config.ts";
18
+
19
+ /** `❯ ` 固定 2 列:glyph + 尾随空格。 */
20
+ const PROMPT_GLYPH = "❯";
21
+ const PROMPT_COLS = 2;
22
+
23
+ /** 最近一次 render 读到的用户 editorPaddingX;未启用过提示符时为 0。 */
24
+ let userPaddingX = 0;
25
+
26
+ /** 输入文本起始列:footer 按它对齐。 */
27
+ export function inputTextIndent(): number {
28
+ return config.enableEditorPrefix ? userPaddingX + PROMPT_COLS : userPaddingX;
29
+ }
30
+
31
+ export class PromptEditor extends CustomEditor {
32
+ render(width: number): string[] {
33
+ // ❯ + 用户 padding:文本从 userPaddingX+2 列开始。
34
+ const self = this as unknown as { paddingX: number };
35
+ const saved = self.paddingX;
36
+ userPaddingX = saved;
37
+ self.paddingX = saved + PROMPT_COLS;
38
+ try {
39
+ const lines = super.render(width);
40
+ // 布局:lines[0] 顶边框,lines[1..n-2] 内容,lines[n-1] 底边框(autocomplete 在底边框后追加,
41
+ // 首内容行恒为 index 1)。开头是 paddingX 个纯空格,前两列换成 ❯+空格,剩余 padding 保留;
42
+ // 续行不动——Claude Code 行为。
43
+ if (lines.length > 2 && lines[1].startsWith(" ")) {
44
+ lines[1] = this.borderColor(PROMPT_GLYPH) + " " + lines[1].slice(2);
45
+ }
46
+ return lines;
47
+ } finally {
48
+ self.paddingX = saved;
49
+ }
50
+ }
51
+ }
52
+
53
+ type EditorFactory = Parameters<ExtensionContext["ui"]["setEditorComponent"]>[0];
54
+
55
+ const promptEditorFactory: EditorFactory = (tui, theme, keybindings) =>
56
+ new PromptEditor(tui, theme, keybindings, { embedWorkingStatus: true });
57
+
58
+ /** 是否正占着插槽;占据前的工厂用于原样还回去。 */
59
+ let active = false;
60
+ let previousEditorFactory: EditorFactory | undefined;
61
+
62
+ /** 撤销本扩展占据的插槽;从未占用就不碰插槽。 */
63
+ function releasePromptEditor(ctx: ExtensionContext): void {
64
+ if (!active) return;
65
+ ctx.ui.setEditorComponent(previousEditorFactory);
66
+ active = false;
67
+ previousEditorFactory = undefined;
68
+ }
69
+
70
+ /** 应用输入框前缀;enableEditorPrefix=false 时只撤自己装的那层。 */
71
+ export function applyPromptEditor(ctx: ExtensionContext): void {
72
+ if (!ctx?.hasUI || typeof ctx.ui?.setEditorComponent !== "function") return;
73
+ try {
74
+ if (!config.enableEditorPrefix) {
75
+ releasePromptEditor(ctx);
76
+ return;
77
+ }
78
+ if (!active) {
79
+ // pi 的插槽是硬替换、没有栈,先记住是谁占着,撤销时还回去。
80
+ previousEditorFactory = ctx.ui.getEditorComponent?.();
81
+ active = true;
82
+ }
83
+ ctx.ui.setEditorComponent(promptEditorFactory);
84
+ } catch (err) {
85
+ ctx.ui.notify(
86
+ `prompt editor error: ${err instanceof Error ? err.message : String(err)}`,
87
+ "error",
88
+ );
89
+ }
90
+ }
91
+
92
+ /** 恢复本扩展占据前的编辑器;未占用时不动作。 */
93
+ export function clearPromptEditor(ctx: ExtensionContext): void {
94
+ if (!ctx?.hasUI || typeof ctx.ui?.setEditorComponent !== "function") return;
95
+ releasePromptEditor(ctx);
96
+ }
@@ -5,6 +5,7 @@ import { config } from "./config/config.ts";
5
5
  import piAliases from "./feature/shell/aliases.ts";
6
6
  import { installFlushDockedBash } from "./feature/shell/flush-docked-bash.ts";
7
7
  import customFooter from "./feature/shell/footer.ts";
8
+ import { applyPromptEditor } from "./feature/shell/prompt-editor.ts";
8
9
  import piStartupHeader, { installEarlyStartupHeader } from "./feature/shell/startup-header.ts";
9
10
  import workingMessage from "./feature/shell/working-message.ts";
10
11
 
@@ -42,6 +43,11 @@ export default function (pi: ExtensionAPI): void {
42
43
  if (config.enableWorkingMessage) workingMessage(pi);
43
44
  customFooter(pi);
44
45
 
46
+ // 输入框 ❯ 提示符:session_start 时按配置应用;setEditorComponent 是一次性替换。
47
+ pi.on("session_start", (_event, ctx) => {
48
+ applyPromptEditor(ctx);
49
+ });
50
+
45
51
  // Renderer 必须先注册 lifecycle handler,shutdown 时才能先解开外层 compact
46
52
  // patch,thinking 随后才能恢复原生原型;bridge 转发给稍后安装的 controller。
47
53
  let compactThinking: CompactThinkingController | undefined;