@zhushanwen/pi-pending-notifications 0.3.1 → 0.3.3

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 (2) hide show
  1. package/package.json +2 -1
  2. package/src/index.ts +9 -8
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhushanwen/pi-pending-notifications",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Cross-extension async operation registration/query mechanism for Pi — prevents message injection during long-running operations.",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -22,6 +22,7 @@
22
22
  "index.ts"
23
23
  ],
24
24
  "devDependencies": {
25
+ "@vitest/coverage-v8": "^4.1.9",
25
26
  "vitest": "^4.1.8"
26
27
  },
27
28
  "peerDependencies": {
package/src/index.ts CHANGED
@@ -75,13 +75,14 @@ interface PendingToolDetails {
75
75
  /**
76
76
  * 模块级 EventBus 监听器 unsubscribe 函数列表。
77
77
  *
78
- * EventBus 是进程级单例(真实 SDK resource-loader 构造一次,跨 /reload、会话切换复用)。
79
- * 工厂函数 pendingNotificationsExtension 每次 reload 都重新执行,若不先移除旧监听器,
80
- * N reload 后 EventBus 上会累积 N 组监听器(>11 后抛 Possible EventEmitter memory leak)。
78
+ * [W4 注释修正] 原 rationale("EventBus 进程级单例 + reload 累积 N 组监听器")在
79
+ * pi 0.84.1 不成立:pi.events.on 的返回值是 runtime.trackEventBusSubscription 跟踪的
80
+ * unsubscribe(loader.js:338-341),runtime.invalidate() 时自动全部退订——session 替换
81
+ * (dispose)与 /reload(invalidate 先于重新 load)都触发;且 session 替换会创建全新
82
+ * ResourceLoader → 全新 eventBus(agent-session-services.js:63-68),旧 bus 整体废弃。
81
83
  *
82
- * 用模块级变量跨 reload 持久:工厂入口先调用上一轮的 unsubscribe 清理旧监听器,
83
- * 再注册新的。这同时修复了多 session 串数据问题——reload 后只有当前闭包的监听器存活,
84
- * currentSessionId 始终是最新 session(旧闭包的过期 currentSessionId 不会再给事件打戳)。
84
+ * 下方的工厂入口手工清理因此是双重冗余(无害):pi 已自动清理 tracked 订阅。
85
+ * 保留是防御性兜底(不依赖 pi 内部清理时机,卸载幂等)。
85
86
  */
86
87
  let unsubscribers: Array<() => void> = [];
87
88
 
@@ -115,11 +116,11 @@ export default function pendingNotificationsExtension(pi: ExtensionAPI): void {
115
116
  }
116
117
  }
117
118
 
118
- // debug 日志:环境变量 PENDING_DEBUG=1 时输出到 console.debug。
119
+ // debug 日志:环境变量 XYZ_AGENT_DEBUG=1 时输出到 console.debug。
119
120
  // 不再写入 session entry(pending:log)——session entries 是 append-only 无法 GC,
120
121
  // 12 处 debug 日志会让长 session 的 entries 线性膨胀,而 goal before-agent-start
121
122
  // 每 turn 全量扫描 getEntries()。状态数据(pending:register/unregister)仍写 entry。
122
- const debugEnabled = process.env.PENDING_DEBUG === "1";
123
+ const debugEnabled = process.env.XYZ_AGENT_DEBUG === "1";
123
124
  function debugLog(level: string, message: string, data?: unknown): void {
124
125
  if (!debugEnabled) return;
125
126
  console.debug(`[pending-notifications:${level}] ${message}`, data ?? "");