pi-cc-extensions 1.0.5 → 1.0.6

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.
@@ -417,9 +417,8 @@ export default function sessionReferenceExtension(pi: ExtensionAPI): void {
417
417
 
418
418
  getAvailableReferences = getReferences;
419
419
  if (ctx.mode === "tui") {
420
- // 预取是 detached 的,必须兜住 rejection,否则 stale 错误会变成
421
- // unhandled rejection 直接终止 Pi。
422
- void getReferences().catch(() => {});
420
+ // 不在这里预取:SessionManager.listAll() 会读完整个会话库,大库要几秒,
421
+ // 而启动并不需要结果。首次 @ 输入由 getSuggestions 触发加载。
423
422
  // Register after other session_start handlers. pi-fff claims every @
424
423
  // prefix, so a provider installed before it would never see session mentions.
425
424
  setTimeout(() => {
@@ -50,18 +50,37 @@ export class PromptEditor extends CustomEditor {
50
50
  }
51
51
  }
52
52
 
53
- /** 应用/恢复输入框前缀。enableEditorPrefix=false 时不占扩展点。 */
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 时只撤自己装的那层。 */
54
71
  export function applyPromptEditor(ctx: ExtensionContext): void {
55
72
  if (!ctx?.hasUI || typeof ctx.ui?.setEditorComponent !== "function") return;
56
73
  try {
57
- if (config.enableEditorPrefix) {
58
- ctx.ui.setEditorComponent(
59
- (tui, theme, keybindings) =>
60
- new PromptEditor(tui, theme, keybindings, { embedWorkingStatus: true }),
61
- );
62
- } else {
63
- ctx.ui.setEditorComponent(undefined);
74
+ if (!config.enableEditorPrefix) {
75
+ releasePromptEditor(ctx);
76
+ return;
77
+ }
78
+ if (!active) {
79
+ // pi 的插槽是硬替换、没有栈,先记住是谁占着,撤销时还回去。
80
+ previousEditorFactory = ctx.ui.getEditorComponent?.();
81
+ active = true;
64
82
  }
83
+ ctx.ui.setEditorComponent(promptEditorFactory);
65
84
  } catch (err) {
66
85
  ctx.ui.notify(
67
86
  `prompt editor error: ${err instanceof Error ? err.message : String(err)}`,
@@ -70,8 +89,8 @@ export function applyPromptEditor(ctx: ExtensionContext): void {
70
89
  }
71
90
  }
72
91
 
73
- /** 恢复 pi 原生编辑器。 */
92
+ /** 恢复本扩展占据前的编辑器;未占用时不动作。 */
74
93
  export function clearPromptEditor(ctx: ExtensionContext): void {
75
94
  if (!ctx?.hasUI || typeof ctx.ui?.setEditorComponent !== "function") return;
76
- ctx.ui.setEditorComponent(undefined);
95
+ releasePromptEditor(ctx);
77
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cc-extensions",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "license": "MIT",
5
5
  "description": "Claude Code-style TUI output with some personal touches and handy utilities.",
6
6
  "type": "module",