@zhushanwen/pi-session-manager 0.6.0 → 0.6.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/README.md +2 -2
- package/package.json +3 -3
- package/src/__tests__/tool-schema.test.ts +10 -0
- package/src/index.ts +16 -4
- package/src/render.ts +4 -11
package/README.md
CHANGED
|
@@ -31,9 +31,9 @@ agent-managed session pi extension:把 session 的创建/发送/读取/列表/
|
|
|
31
31
|
pi install npm:@zhushanwen/pi-session-manager
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
##
|
|
34
|
+
## 工具激活
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
`create_managed_session` 为 direct 常驻——创建入口默认对模型可见(注册不声明 `exposure` 字段,pi SDK 缺省 `direct`)。其余 7 个工具为 `exposure: "deferred"`——不占常驻工具声明,由 pi 内置 `tool_search` 工具检索命中后按需激活。taiji 宿主内开箱即用(宿主启动时已激活 `tool_search`);独立 pi 使用需在 `<agentDir>/settings.json`(默认 `~/.pi/agent/settings.json`)加 `"defaultTools": ["+tool_search"]`(`+` 前缀是增量修饰,保留 read/bash/edit/write 默认集)。注意独立 pi 下即便激活,工具功能仍依赖 taiji runtime handler(见上节「运行要求」)。
|
|
37
37
|
|
|
38
38
|
## 测试
|
|
39
39
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-session-manager",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Pi extension for agent-managed sessions — create, message, monitor, abort, archive, and delete child sessions via ctx.ui.select channel.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"README.md"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@zhushanwen/extension-protocol": "0.
|
|
34
|
-
"@zhushanwen/pi-delivery-port": "0.
|
|
33
|
+
"@zhushanwen/extension-protocol": "0.24.0",
|
|
34
|
+
"@zhushanwen/pi-delivery-port": "0.3.0",
|
|
35
35
|
"@zhushanwen/pi-ext-guards": "0.5.0",
|
|
36
36
|
"@zhushanwen/pi-extension-logger": "0.6.2"
|
|
37
37
|
},
|
|
@@ -25,6 +25,16 @@ describe("U5-A3 tool-schema", () => {
|
|
|
25
25
|
const schemas = getRegisteredSchemas();
|
|
26
26
|
|
|
27
27
|
describe("create_managed_session", () => {
|
|
28
|
+
// exposure 重划终态锚(C-ext-05,2026-10-23 裁决):direct 常驻 = 注册时不写
|
|
29
|
+
// exposure 字段(registerSessionTool 条件展开,与 SDK 缺省 direct 等价,
|
|
30
|
+
// pi-semantics PS-91)——对照下方 delete/archive 的 toBe("deferred") 反向锚;
|
|
31
|
+
// 误写 "deferred" 会把创建入口从模型默认可见集收走,此处红。
|
|
32
|
+
it("is registered as direct (exposure 字段缺省 — SDK 缺省 direct)", () => {
|
|
33
|
+
const tool = getRegisteredTools().find((t) => t.name === "create_managed_session");
|
|
34
|
+
expect(tool).toBeDefined();
|
|
35
|
+
expect(tool?.exposure).toBeUndefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
28
38
|
it("requires cwd (string)", () => {
|
|
29
39
|
const s = schemas.create_managed_session;
|
|
30
40
|
expect(s.type).toBe("object");
|
package/src/index.ts
CHANGED
|
@@ -187,6 +187,13 @@ interface SessionToolConfig<S extends TObject> {
|
|
|
187
187
|
name: string
|
|
188
188
|
label: string
|
|
189
189
|
description: string
|
|
190
|
+
/**
|
|
191
|
+
* 可见性档位(ADR-0136 名单句):缺省 = deferred(七件套);显式 "direct" =
|
|
192
|
+
* 常驻声明(create_managed_session 例外,2026-10-23 裁决)。direct 形态不写
|
|
193
|
+
* exposure 字段(与 SDK 缺省及全仓常驻工具惯例一致,pi-semantics PS-91),
|
|
194
|
+
* helper 条件展开实现。
|
|
195
|
+
*/
|
|
196
|
+
exposure?: "deferred" | "direct"
|
|
190
197
|
/**
|
|
191
198
|
* 识别层(session-manager-archive-delete 四层信息协议):系统提示词 Available tools
|
|
192
199
|
* 清单的一行片段。deferred 工具激活前不在活跃集、带不带都不进清单;激活后带
|
|
@@ -223,10 +230,12 @@ function registerSessionTool<S extends TObject>(pi: ExtensionAPI, cfg: SessionTo
|
|
|
223
230
|
pi.registerTool({
|
|
224
231
|
name: cfg.name,
|
|
225
232
|
label: cfg.label,
|
|
226
|
-
// deferred(tool-declaration-slimming D4):session-manager
|
|
227
|
-
//
|
|
228
|
-
//
|
|
229
|
-
exposure
|
|
233
|
+
// deferred(tool-declaration-slimming D4):session-manager 工具族与 ADR-0136
|
|
234
|
+
// 现行登记一致——除 create_managed_session(direct 常驻,2026-10-23 裁决)外
|
|
235
|
+
// 不常驻声明,tool_search 命中即激活;检索入口 = 启动迁移写入的 +tool_search
|
|
236
|
+
// 条目(runtime pi-codemode-settings)。direct 档不写 exposure 字段(与 SDK
|
|
237
|
+
// 缺省等价,pi-semantics PS-91),条件展开避免传显式 undefined
|
|
238
|
+
...(cfg.exposure !== "direct" ? { exposure: "deferred" as const } : {}),
|
|
230
239
|
promptSnippet: cfg.promptSnippet,
|
|
231
240
|
description: cfg.description,
|
|
232
241
|
parameters: cfg.parameters,
|
|
@@ -267,6 +276,9 @@ export default function sessionManagerExtension(pi: ExtensionAPI): void {
|
|
|
267
276
|
registerSessionTool(pi, {
|
|
268
277
|
name: "create_managed_session",
|
|
269
278
|
label: "Create Managed Session",
|
|
279
|
+
// direct 常驻(2026-10-23 裁决,ADR-0136 补记):创建入口模型默认可见,
|
|
280
|
+
// 其余七件保持 deferred
|
|
281
|
+
exposure: "direct",
|
|
270
282
|
promptSnippet:
|
|
271
283
|
"Create a new managed child session in a working directory, optionally with an initial prompt.",
|
|
272
284
|
description: `Create a new managed child session in a working directory, optionally with an initial prompt.
|
package/src/render.ts
CHANGED
|
@@ -4,19 +4,12 @@
|
|
|
4
4
|
|
|
5
5
|
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
6
6
|
import { Text } from "@earendil-works/pi-tui";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
/** pi toolResult 通用形状(AgentToolResult 的结构最小面,renderResult 入参收窄用)。 */
|
|
10
|
-
interface ToolResultShape { // oe-exempt:20261017:framework:details 数据形状窄 view(单实现消费,非抽象接口)
|
|
11
|
-
content: Array<{ type: string; text?: string }>;
|
|
12
|
-
details?: { summary?: unknown };
|
|
13
|
-
}
|
|
7
|
+
import { readDetailsSummary, resultContentText } from "@zhushanwen/extension-protocol";
|
|
14
8
|
|
|
15
9
|
export function renderSessionManagerResult(result: unknown, options: { expanded: boolean }, theme: Theme): Text {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
if (options.expanded === false && typeof summary === "string" && summary !== "") {
|
|
10
|
+
const summary = readDetailsSummary(result);
|
|
11
|
+
if (options.expanded === false && summary !== undefined) {
|
|
19
12
|
return new Text(theme.fg("dim", summary), 0, 0);
|
|
20
13
|
}
|
|
21
|
-
return new Text(
|
|
14
|
+
return new Text(resultContentText(result), 0, 0);
|
|
22
15
|
}
|