@zhushanwen/pi-pending-notifications 0.5.0 → 0.5.2
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.
- package/package.json +4 -4
- package/src/index.ts +10 -12
- package/src/state.ts +2 -6
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-pending-notifications",
|
|
3
|
-
"version": "0.5.
|
|
4
|
-
"description": "Cross-extension async operation registration/query mechanism for Pi
|
|
3
|
+
"version": "0.5.2",
|
|
4
|
+
"description": "Cross-extension async operation registration/query mechanism for Pi.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"xyz-agent": {
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"vitest": "^4.1.8"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@earendil-works/pi-coding-agent": "^0.84.
|
|
32
|
+
"@earendil-works/pi-coding-agent": "^0.84.4",
|
|
33
33
|
"typebox": "*"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@zhushanwen/pi-extension-logger": "0.
|
|
36
|
+
"@zhushanwen/pi-extension-logger": "0.4.0"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|
|
39
39
|
"typecheck": "npx tsc --noEmit",
|
package/src/index.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Pending Notifications Extension — 跨 extension 的异步操作注册/查询机制。
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* workflow/subagent 运行时通过 EventBus(pi.events.emit
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* 设计定位:为长耗时异步操作(workflow/subagent/bash 后台任务)提供跨 extension 的
|
|
5
|
+
* 活跃操作注册/查询机制。workflow/subagent/bash 运行时通过 EventBus(pi.events.emit)
|
|
6
|
+
* 广播 register/unregister,本扩展监听这些事件、将状态写入 session entries(pi.appendEntry),
|
|
7
|
+
* 供 LLM 通过 pending_notifications 工具主动查询当前活跃异步操作
|
|
8
|
+
* (goal 不在 before_agent_start 注入等待消息——避免双信息源,pending 感知由 LLM 自行查询)。
|
|
8
9
|
*
|
|
9
10
|
* 文件职责:
|
|
10
11
|
* - state.ts: PendingEntry / PendingRegistry + 纯函数(register/unregister/rebuild)
|
|
11
12
|
* - index.ts(本文件): 工厂入口(注册 events.on 监听 + session 生命周期 + 查询 tool)
|
|
12
13
|
*
|
|
13
|
-
*
|
|
14
|
+
* 事件契约(emit 端在 packages/subagent-core:orchestration/lifecycle.ts 与
|
|
15
|
+
* execution/subagent-service.ts):
|
|
14
16
|
* - emit("pending:register", { id, type, name })
|
|
15
17
|
* - emit("pending:unregister", { id, reason })
|
|
16
18
|
*
|
|
@@ -18,6 +20,8 @@
|
|
|
18
20
|
* - pending:register → { id, type, name, registeredAt, expiresAt?, sessionId }
|
|
19
21
|
* (expiresAt 仅 session 档写入;process 档(D16)省略该字段)
|
|
20
22
|
* - pending:unregister → { id, reason, status }
|
|
23
|
+
* (主路径为事件监听写入的三字段;session_start 补 expired / session_shutdown 补
|
|
24
|
+
* cancelled 的 flush 路径只写 { id, status },省略 reason——消费方只读 id,无行为影响)
|
|
21
25
|
*
|
|
22
26
|
* 监听方式:pi.events.on(Pi 的 EventBus,真实 SDK 为 EventBus.on,非 optional)。
|
|
23
27
|
* workflow 侧通过 deps.eventBus 注入 pi.events(同一总线)。
|
|
@@ -301,13 +305,10 @@ function parseRegisterEvent(data: unknown): ParsedRegister | null {
|
|
|
301
305
|
interface ParsedUnregister {
|
|
302
306
|
id: string;
|
|
303
307
|
reason: string;
|
|
304
|
-
result?: string;
|
|
305
|
-
error?: string;
|
|
306
|
-
patchFile?: string;
|
|
307
308
|
}
|
|
308
309
|
|
|
309
310
|
/** 解析 pending:unregister 事件 data(容错缺失/类型错误字段)。
|
|
310
|
-
* T2
|
|
311
|
+
* T2 通知由 subagent-workflow 自有通道 bg-notify-render 承担,不经本事件。 */
|
|
311
312
|
function parseUnregisterEvent(data: unknown): ParsedUnregister | null {
|
|
312
313
|
if (typeof data !== "object" || data === null) return null;
|
|
313
314
|
const d = data as Record<string, unknown>;
|
|
@@ -315,9 +316,6 @@ function parseUnregisterEvent(data: unknown): ParsedUnregister | null {
|
|
|
315
316
|
return {
|
|
316
317
|
id: d.id,
|
|
317
318
|
reason: typeof d.reason === "string" ? d.reason : "completed",
|
|
318
|
-
result: typeof d.result === "string" ? d.result : undefined,
|
|
319
|
-
error: typeof d.error === "string" ? d.error : undefined,
|
|
320
|
-
patchFile: typeof d.patchFile === "string" ? d.patchFile : undefined,
|
|
321
319
|
};
|
|
322
320
|
}
|
|
323
321
|
|
package/src/state.ts
CHANGED
|
@@ -36,7 +36,7 @@ export type PendingStatus = "active" | "completed" | "failed" | "cancelled" | "e
|
|
|
36
36
|
|
|
37
37
|
/** 一个异步操作的完整描述(= pending:register entry 的 data 字段) */
|
|
38
38
|
export interface PendingEntry {
|
|
39
|
-
/** 操作唯一标识(workflow runId / subagent id) */
|
|
39
|
+
/** 操作唯一标识(workflow runId / subagent id / bash 后台任务 id) */
|
|
40
40
|
id: string;
|
|
41
41
|
/** 操作来源类型 */
|
|
42
42
|
type: PendingType;
|
|
@@ -63,13 +63,9 @@ interface RegisterEntryData {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
/** pending:unregister entry 在 entries 里的最小可识别形状。
|
|
66
|
-
*
|
|
67
|
-
* 消费侧读取并 sendMessage 到 LLM)。workflow 的 unregister 不携带这些字段。 */
|
|
66
|
+
* T2 通知由 subagent-workflow 自有通道 bg-notify-render 承担,不经本事件。 */
|
|
68
67
|
interface UnregisterEntryData {
|
|
69
68
|
id: unknown;
|
|
70
|
-
result?: unknown;
|
|
71
|
-
error?: unknown;
|
|
72
|
-
patchFile?: unknown;
|
|
73
69
|
}
|
|
74
70
|
|
|
75
71
|
/** SessionEntry 的最小可识别形状(duck-typed,避免依赖 SDK 具体类型) */
|