@zhushanwen/pi-pending-notifications 0.2.0 → 0.2.1
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-pending-notifications",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
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",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"vitest": "^4.1.8"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@
|
|
28
|
+
"@earendil-works/pi-coding-agent": "*",
|
|
29
29
|
"@sinclair/typebox": "*"
|
|
30
30
|
},
|
|
31
31
|
"scripts": {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
/* eslint-disable taste/no-unsafe-cast */
|
|
13
13
|
|
|
14
|
-
import type { ExtensionAPI, ExtensionContext } from "@
|
|
14
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
15
15
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
16
16
|
|
|
17
17
|
import pendingNotificationsExtension from "../index";
|
|
@@ -37,6 +37,7 @@ interface MockSetup {
|
|
|
37
37
|
handlers: HandlerRegistry;
|
|
38
38
|
appendEntryMock: ReturnType<typeof vi.fn>;
|
|
39
39
|
registerToolMock: ReturnType<typeof vi.fn>;
|
|
40
|
+
sendMessageMock: ReturnType<typeof vi.fn>;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
function createMockPi(): MockSetup {
|
|
@@ -67,7 +68,7 @@ function createMockPi(): MockSetup {
|
|
|
67
68
|
},
|
|
68
69
|
} as unknown as ExtensionAPI;
|
|
69
70
|
|
|
70
|
-
return { pi, handlers, appendEntryMock, registerToolMock };
|
|
71
|
+
return { pi, handlers, appendEntryMock, registerToolMock, sendMessageMock };
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
function createMockCtx(entries: MockSessionEntry[], sessionId = "sess-current"): ExtensionContext {
|
|
@@ -375,6 +376,7 @@ describe("pendingNotificationsExtension factory", () => {
|
|
|
375
376
|
});
|
|
376
377
|
});
|
|
377
378
|
|
|
379
|
+
|
|
378
380
|
describe("safeAppendEntry error handling", () => {
|
|
379
381
|
it("appendEntry throwing (stale context) does not break register listener, registry still updated", async () => {
|
|
380
382
|
// listener 先 register(registry) 更新内存,再 safeAppendEntry;appendEntry 抛错被 catch,registry 仍已更新
|
package/src/index.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* workflow 侧通过 deps.eventBus 注入 pi.events(同一总线)。
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import type { ExtensionAPI, ExtensionContext } from "@
|
|
25
|
+
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
26
26
|
import { Type } from "@sinclair/typebox";
|
|
27
27
|
|
|
28
28
|
import {
|
|
@@ -263,9 +263,13 @@ function parseRegisterEvent(data: unknown): ParsedRegister | null {
|
|
|
263
263
|
interface ParsedUnregister {
|
|
264
264
|
id: string;
|
|
265
265
|
reason: string;
|
|
266
|
+
result?: string;
|
|
267
|
+
error?: string;
|
|
268
|
+
patchFile?: string;
|
|
266
269
|
}
|
|
267
270
|
|
|
268
|
-
/** 解析 pending:unregister 事件 data
|
|
271
|
+
/** 解析 pending:unregister 事件 data(容错缺失/类型错误字段)。
|
|
272
|
+
* T2 后 subagent 完成路径携带可选的 result/error/patchFile,供消费侧 sendMessage。 */
|
|
269
273
|
function parseUnregisterEvent(data: unknown): ParsedUnregister | null {
|
|
270
274
|
if (typeof data !== "object" || data === null) return null;
|
|
271
275
|
const d = data as Record<string, unknown>;
|
|
@@ -273,6 +277,9 @@ function parseUnregisterEvent(data: unknown): ParsedUnregister | null {
|
|
|
273
277
|
return {
|
|
274
278
|
id: d.id,
|
|
275
279
|
reason: typeof d.reason === "string" ? d.reason : "completed",
|
|
280
|
+
result: typeof d.result === "string" ? d.result : undefined,
|
|
281
|
+
error: typeof d.error === "string" ? d.error : undefined,
|
|
282
|
+
patchFile: typeof d.patchFile === "string" ? d.patchFile : undefined,
|
|
276
283
|
};
|
|
277
284
|
}
|
|
278
285
|
|
package/src/state.ts
CHANGED
|
@@ -48,9 +48,14 @@ interface RegisterEntryData {
|
|
|
48
48
|
sessionId: unknown;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
/** pending:unregister entry 在 entries
|
|
51
|
+
/** pending:unregister entry 在 entries 里的最小可识别形状。
|
|
52
|
+
* result/error/patchFile 为 subagent 完成通知携带的附加字段(T2 后由 pending-notifications
|
|
53
|
+
* 消费侧读取并 sendMessage 到 LLM)。workflow 的 unregister 不携带这些字段。 */
|
|
52
54
|
interface UnregisterEntryData {
|
|
53
55
|
id: unknown;
|
|
56
|
+
result?: unknown;
|
|
57
|
+
error?: unknown;
|
|
58
|
+
patchFile?: unknown;
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
/** SessionEntry 的最小可识别形状(duck-typed,避免依赖 SDK 具体类型) */
|