@zhushanwen/pi-session-manager 0.1.9 → 0.1.11
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/README.md
CHANGED
|
@@ -4,9 +4,9 @@ agent-managed session pi extension:把 session 的创建/发送/读取/列表/
|
|
|
4
4
|
|
|
5
5
|
## 通道契约
|
|
6
6
|
|
|
7
|
-
- 工具调用经 `ctx.ui.select(SESSION_MANAGER_MARKER, [JSON], {timeout})` 发出,超时按 action 分档(create/history 60s、其余 30s,SSOT 在 `src/index.ts` 的 `SELECT_TIMEOUT_MS`);marker 为 `\
|
|
8
|
-
- 请求体为嵌套形状 `{ action, params }`(形状 SSOT 在 `@
|
|
9
|
-
- 应答方是
|
|
7
|
+
- 工具调用经 `ctx.ui.select(SESSION_MANAGER_MARKER, [JSON], {timeout})` 发出,超时按 action 分档(create/history 60s、其余 30s,SSOT 在 `src/index.ts` 的 `SELECT_TIMEOUT_MS`);marker 为 `\x00TAIJI_SESSION_MANAGER`(NUL 前缀防与普通 select title 冲突,SSOT 在 `@zhushanwen/extension-protocol`)
|
|
8
|
+
- 请求体为嵌套形状 `{ action, params }`(形状 SSOT 在 `@zhushanwen/extension-protocol`);**不要扁平化展开**——runtime event-adapter 按 `data.params` 提取,扁平化会导致 params 丢失
|
|
9
|
+
- 应答方是 taiji runtime 的 `SessionManagerHandler`(select value 通道回写 JSON 字符串;取消/超时返回 null)
|
|
10
10
|
|
|
11
11
|
## 工具(6 个 action)
|
|
12
12
|
|
|
@@ -21,7 +21,7 @@ agent-managed session pi extension:把 session 的创建/发送/读取/列表/
|
|
|
21
21
|
|
|
22
22
|
## 运行要求
|
|
23
23
|
|
|
24
|
-
应答端(runtime handler)在
|
|
24
|
+
应答端(runtime handler)在 taiji 桌面应用内;独立 pi CLI 环境无 handler 时工具将等待至超时(create/history 60s、其余 30s)并返回 cancelled。
|
|
25
25
|
|
|
26
26
|
## 测试
|
|
27
27
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-session-manager",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Pi extension for managing agent-managed sessions — create, send, read history, list, status, abort via ctx.ui.select channel.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"./index.ts"
|
|
10
10
|
]
|
|
11
11
|
},
|
|
12
|
-
"
|
|
12
|
+
"taiji": {
|
|
13
13
|
"role": "universal"
|
|
14
14
|
},
|
|
15
15
|
"keywords": [
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"README.md"
|
|
27
27
|
],
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@
|
|
29
|
+
"@zhushanwen/extension-protocol": "0.11.0",
|
|
30
30
|
"@zhushanwen/pi-extension-logger": "0.6.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// tool-execute.test.ts — U5-A2: each tool's execute calls ctx.ui.select with SESSION_MANAGER_MARKER + JSON payload
|
|
2
2
|
|
|
3
3
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
4
|
-
import { SESSION_MANAGER_MARKER } from "@
|
|
4
|
+
import { SESSION_MANAGER_MARKER } from "@zhushanwen/extension-protocol";
|
|
5
5
|
import registerExtension from "../index.ts";
|
|
6
6
|
|
|
7
7
|
/** Capture registered tools and provide a mock ctx.ui.select. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// tool-registration.test.ts — U5-A1: 6 tools registered with correct name/description/parameters + SESSION_MANAGER_MARKER import
|
|
2
2
|
|
|
3
3
|
import { describe, it, expect, vi } from "vitest";
|
|
4
|
-
import { SESSION_MANAGER_MARKER } from "@
|
|
4
|
+
import { SESSION_MANAGER_MARKER } from "@zhushanwen/extension-protocol";
|
|
5
5
|
import registerExtension from "../index.ts";
|
|
6
6
|
|
|
7
7
|
/** Proxy-based mock: capture registerTool calls for assertion. */
|
|
@@ -61,12 +61,12 @@ describe("U5-A1 tool-registration", () => {
|
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
|
|
64
|
-
it("SESSION_MANAGER_MARKER is imported from @
|
|
64
|
+
it("SESSION_MANAGER_MARKER is imported from @zhushanwen/extension-protocol", () => {
|
|
65
65
|
expect(typeof SESSION_MANAGER_MARKER).toBe("string");
|
|
66
66
|
});
|
|
67
67
|
|
|
68
|
-
it("SESSION_MANAGER_MARKER value is '\\
|
|
69
|
-
expect(SESSION_MANAGER_MARKER).toBe("\
|
|
70
|
-
expect(SESSION_MANAGER_MARKER).toHaveLength(
|
|
68
|
+
it("SESSION_MANAGER_MARKER value is '\\x00TAIJI_SESSION_MANAGER' (NUL prefix, 22 chars)", () => {
|
|
69
|
+
expect(SESSION_MANAGER_MARKER).toBe("\x00TAIJI_SESSION_MANAGER");
|
|
70
|
+
expect(SESSION_MANAGER_MARKER).toHaveLength(22);
|
|
71
71
|
});
|
|
72
72
|
});
|
package/src/index.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
isChannelErrorResult,
|
|
10
10
|
type MarkerRpcResult,
|
|
11
11
|
type SessionManagerAction,
|
|
12
|
-
} from "@
|
|
12
|
+
} from "@zhushanwen/extension-protocol";
|
|
13
13
|
import { getLogger, setPiHandle } from "@zhushanwen/pi-extension-logger";
|
|
14
14
|
import { Type, type Static, type TObject } from "typebox";
|
|
15
15
|
|
|
@@ -68,7 +68,7 @@ function callSessionManager(
|
|
|
68
68
|
action: SessionManagerAction,
|
|
69
69
|
params: Record<string, unknown>,
|
|
70
70
|
): Promise<MarkerRpcResult> {
|
|
71
|
-
// 契约 SSOT:请求体 = 嵌套 { action, params } 形状(协议包 @
|
|
71
|
+
// 契约 SSOT:请求体 = 嵌套 { action, params } 形状(协议包 @zhushanwen/extension-protocol
|
|
72
72
|
// 的 session-manager 模块)。runtime event-adapter 的 marker
|
|
73
73
|
// 分支按 data.params 提取——若扁平化展开({action, ...params})params 会丢失变 {}。
|
|
74
74
|
const payload = JSON.stringify({ action, params });
|
|
@@ -175,7 +175,7 @@ export default function sessionManagerExtension(pi: ExtensionAPI): void {
|
|
|
175
175
|
registerSessionTool(pi, {
|
|
176
176
|
name: "create_managed_session",
|
|
177
177
|
label: "Create Managed Session",
|
|
178
|
-
description: "Create a new agent-managed session in the specified working directory. Optionally provide an initial prompt, which is sent immediately (new sessions are always idle, so it is delivered directly). Returns a session ID and initial status. Requires the
|
|
178
|
+
description: "Create a new agent-managed session in the specified working directory. Optionally provide an initial prompt, which is sent immediately (new sessions are always idle, so it is delivered directly). Returns a session ID and initial status. Requires the taiji desktop runtime; standalone pi CLI will time out.",
|
|
179
179
|
parameters: CreateManagedSessionParams,
|
|
180
180
|
action: "create",
|
|
181
181
|
toParams: (p) => ({ cwd: p.cwd, label: p.label, prompt: p.prompt }),
|
|
@@ -184,7 +184,7 @@ export default function sessionManagerExtension(pi: ExtensionAPI): void {
|
|
|
184
184
|
registerSessionTool(pi, {
|
|
185
185
|
name: "send_to_session",
|
|
186
186
|
label: "Send to Session",
|
|
187
|
-
description: "Send a prompt/message to an existing managed session. The message is asynchronously queued: if the target session is busy (generating/compacting/running bash) it is delivered at its next turn boundary, and {queued: true} is returned immediately. On synchronous failure the tool returns an error result (isError) with a hint (check get_session_status, then retry). Requires the
|
|
187
|
+
description: "Send a prompt/message to an existing managed session. The message is asynchronously queued: if the target session is busy (generating/compacting/running bash) it is delivered at its next turn boundary, and {queued: true} is returned immediately. On synchronous failure the tool returns an error result (isError) with a hint (check get_session_status, then retry). Requires the taiji desktop runtime; standalone pi CLI will time out.",
|
|
188
188
|
parameters: SendToSessionParams,
|
|
189
189
|
action: "send",
|
|
190
190
|
toParams: (p) => ({ sessionId: p.sessionId, prompt: p.prompt }),
|
|
@@ -193,7 +193,7 @@ export default function sessionManagerExtension(pi: ExtensionAPI): void {
|
|
|
193
193
|
registerSessionTool(pi, {
|
|
194
194
|
name: "read_session_history",
|
|
195
195
|
label: "Read Session History",
|
|
196
|
-
description: "Read the conversation history of a managed session. Optionally limit to the last N turns. Requires the
|
|
196
|
+
description: "Read the conversation history of a managed session. Optionally limit to the last N turns. Requires the taiji desktop runtime; standalone pi CLI will time out.",
|
|
197
197
|
parameters: ReadSessionHistoryParams,
|
|
198
198
|
action: "history",
|
|
199
199
|
toParams: (p) => ({ sessionId: p.sessionId, tailTurns: p.tailTurns }),
|
|
@@ -202,7 +202,7 @@ export default function sessionManagerExtension(pi: ExtensionAPI): void {
|
|
|
202
202
|
registerSessionTool(pi, {
|
|
203
203
|
name: "list_my_sessions",
|
|
204
204
|
label: "List My Sessions",
|
|
205
|
-
description: "List all sessions managed by the current agent. Returns session IDs, labels, and statuses. Requires the
|
|
205
|
+
description: "List all sessions managed by the current agent. Returns session IDs, labels, and statuses. Requires the taiji desktop runtime; standalone pi CLI will time out.",
|
|
206
206
|
parameters: ListMySessionsParams,
|
|
207
207
|
action: "list",
|
|
208
208
|
toParams: () => ({}),
|
|
@@ -211,7 +211,7 @@ export default function sessionManagerExtension(pi: ExtensionAPI): void {
|
|
|
211
211
|
registerSessionTool(pi, {
|
|
212
212
|
name: "get_session_status",
|
|
213
213
|
label: "Get Session Status",
|
|
214
|
-
description: "Get the current status of a managed session (active, idle, error, etc.) and its model info. Requires the
|
|
214
|
+
description: "Get the current status of a managed session (active, idle, error, etc.) and its model info. Requires the taiji desktop runtime; standalone pi CLI will time out.",
|
|
215
215
|
parameters: GetSessionStatusParams,
|
|
216
216
|
action: "status",
|
|
217
217
|
toParams: (p) => ({ sessionId: p.sessionId }),
|
|
@@ -220,7 +220,7 @@ export default function sessionManagerExtension(pi: ExtensionAPI): void {
|
|
|
220
220
|
registerSessionTool(pi, {
|
|
221
221
|
name: "abort_session",
|
|
222
222
|
label: "Abort Session",
|
|
223
|
-
description: "Abort a running managed session. The session stops processing; its final status will be 'stopped'. Requires the
|
|
223
|
+
description: "Abort a running managed session. The session stops processing; its final status will be 'stopped'. Requires the taiji desktop runtime; standalone pi CLI will time out.",
|
|
224
224
|
parameters: AbortSessionParams,
|
|
225
225
|
action: "abort",
|
|
226
226
|
toParams: (p) => ({ sessionId: p.sessionId }),
|