@zhushanwen/pi-agent-ext 1.2.2 → 1.3.0
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 +1 -1
- package/src/__tests__/agent-ext.test.ts +8 -23
- package/src/index.ts +7 -12
package/package.json
CHANGED
|
@@ -3,18 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 复用 system-prompt-trace index-wiring.test.ts 的 Proxy 假体模式:
|
|
5
5
|
* - pi 用 Proxy 假体:捕获 registerCommand 注册的命令定义 + appendEntry 落点
|
|
6
|
-
* - ctx 只需 index.ts 实际消费的字段(
|
|
6
|
+
* - ctx 只需 index.ts 实际消费的字段(getSystemPrompt),
|
|
7
7
|
* 以 ExtensionCommandContext 最小形状驱动 handler(SDK 双参契约 (args, ctx))
|
|
8
8
|
* - index.ts 对 @earendil-works/pi-coding-agent 是 type-only import(运行时擦除),
|
|
9
9
|
* 无需 vi.mock SDK 模块
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
* - __taiji_reload__(host 触发的 skill/extension 重载内部命令)→ ctx.reload()
|
|
11
|
+
* 锚定命令注册面 + handler 行为:
|
|
13
12
|
* - __taiji_get_system_prompt__(Trace 视图「现取当前值」通道)→ pi.appendEntry
|
|
14
13
|
* 写 taiji:current-system-prompt custom entry(fullText/charCount/fetchedAt 形状)
|
|
15
14
|
*
|
|
16
15
|
* [HISTORICAL] session tree 导航命令(旧品牌时期命名)及其测试随命令删除一并移除
|
|
17
16
|
* (2026-08-31,桥接对端 runtime 消费端已在 monorepo 时代删除)。
|
|
17
|
+
* [HISTORICAL] __taiji_reload__ 及其测试随 W5 skill 变更→pi reload 编排退役一并移除
|
|
18
|
+
* (2026-09-25,消费端已 D7 切源 taiji SkillRegistry,pi 侧列表滞后归 ADR-0050 降级)。
|
|
18
19
|
*
|
|
19
20
|
* 运行:cd extensions/taiji/agent-ext && npx vitest run
|
|
20
21
|
*/
|
|
@@ -63,20 +64,17 @@ function createWiringHarness(): WiringHarness {
|
|
|
63
64
|
return { pi, commands, entries };
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
/** ctx 假体(index.ts 实际消费:
|
|
67
|
+
/** ctx 假体(index.ts 实际消费:getSystemPrompt;vi.fn 捕获调用)。 */
|
|
67
68
|
function createCtx(prompt = "current system prompt"): {
|
|
68
69
|
ctx: ExtensionCommandContext;
|
|
69
|
-
reload: ReturnType<typeof vi.fn>;
|
|
70
70
|
getSystemPrompt: ReturnType<typeof vi.fn>;
|
|
71
71
|
} {
|
|
72
|
-
const reload = vi.fn();
|
|
73
72
|
const getSystemPrompt = vi.fn(() => prompt);
|
|
74
73
|
const ctx = {
|
|
75
74
|
cwd: "/home/user/project",
|
|
76
|
-
reload,
|
|
77
75
|
getSystemPrompt,
|
|
78
76
|
} as unknown as ExtensionCommandContext;
|
|
79
|
-
return { ctx,
|
|
77
|
+
return { ctx, getSystemPrompt };
|
|
80
78
|
}
|
|
81
79
|
|
|
82
80
|
/** 以 SDK 双参契约 (args, ctx) 驱动已注册命令 handler。 */
|
|
@@ -98,14 +96,11 @@ async function loadExtension(): Promise<(pi: ExtensionAPI) => void> {
|
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
describe("index.ts wiring SDK 契约", () => {
|
|
101
|
-
it("
|
|
99
|
+
it("注册恰好一个命令(__taiji_get_system_prompt__),带非空 description", async () => {
|
|
102
100
|
const ext = await loadExtension();
|
|
103
101
|
const h = createWiringHarness();
|
|
104
102
|
ext(h.pi);
|
|
105
|
-
expect([...h.commands.keys()]
|
|
106
|
-
"__taiji_get_system_prompt__",
|
|
107
|
-
"__taiji_reload__",
|
|
108
|
-
]);
|
|
103
|
+
expect([...h.commands.keys()]).toEqual(["__taiji_get_system_prompt__"]);
|
|
109
104
|
for (const def of h.commands.values()) {
|
|
110
105
|
expect(typeof def.description).toBe("string");
|
|
111
106
|
expect(def.description.length).toBeGreaterThan(0);
|
|
@@ -113,16 +108,6 @@ describe("index.ts wiring SDK 契约", () => {
|
|
|
113
108
|
}
|
|
114
109
|
});
|
|
115
110
|
|
|
116
|
-
it("__taiji_reload__ handler → 调 ctx.reload()(host 触发的 skill/extension 重载,无参)", async () => {
|
|
117
|
-
const ext = await loadExtension();
|
|
118
|
-
const h = createWiringHarness();
|
|
119
|
-
ext(h.pi);
|
|
120
|
-
const { ctx, reload } = createCtx();
|
|
121
|
-
await runCommand(h, "__taiji_reload__", "", ctx);
|
|
122
|
-
expect(reload).toHaveBeenCalledTimes(1);
|
|
123
|
-
expect(reload).toHaveBeenCalledWith();
|
|
124
|
-
});
|
|
125
|
-
|
|
126
111
|
it("__taiji_get_system_prompt__ → appendEntry 写 taiji:current-system-prompt(fullText/charCount/fetchedAt 形状,不写其他 customType)", async () => {
|
|
127
112
|
const ext = await loadExtension();
|
|
128
113
|
const h = createWiringHarness();
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* taiji extension for Pi — internal commands for the host.
|
|
3
3
|
*
|
|
4
|
-
* Registers `/
|
|
5
|
-
* skill/extension reload, and `/__taiji_get_system_prompt__` for the Trace
|
|
4
|
+
* Registers `/__taiji_get_system_prompt__` for the Trace
|
|
6
5
|
* view fetch-current button.
|
|
7
6
|
*
|
|
8
7
|
* [HISTORICAL] The former session tree navigation command was removed
|
|
@@ -10,21 +9,17 @@
|
|
|
10
9
|
* monorepo era, so the command had no reachable caller. See the ADR-0008
|
|
11
10
|
* note in the retired-decisions genealogy of docs/adr/decisions.md for the
|
|
12
11
|
* original design.
|
|
12
|
+
* [HISTORICAL] `/__taiji_reload__` was removed (2026-09-25): the W5
|
|
13
|
+
* skill-change→pi-reload orchestration was retired — slash menu and composer
|
|
14
|
+
* injection resolve skills from the taiji SkillRegistry (D7 source switch),
|
|
15
|
+
* so a full pi reload (extension ctx invalidate + clearExtensionCache, which
|
|
16
|
+
* broke background-task completion notifications in the stale module world)
|
|
17
|
+
* bought nothing but stale-pi-side lists, accepted per ADR-0050 degradation.
|
|
13
18
|
*/
|
|
14
19
|
|
|
15
20
|
import type { ExtensionAPI, ExtensionCommandContext } from "@earendil-works/pi-coding-agent";
|
|
16
21
|
|
|
17
22
|
export default function (pi: ExtensionAPI): void {
|
|
18
|
-
// W5: builtin internal reload command. `/__taiji_reload__` 由 host 在 skill 文件变动时
|
|
19
|
-
// 经 client.prompt 发起(不经 LLM),handler 调 pi ctx.reload() 重扫 skill + 重建 runtime。
|
|
20
|
-
// 双下划线前缀 = 内部命令(前端 W4 internal-command-filter 过滤 `/__` 前缀不显示)。
|
|
21
|
-
pi.registerCommand('__taiji_reload__', {
|
|
22
|
-
description: 'Internal: reload skills/extensions/prompts (triggered by host on skill file change)',
|
|
23
|
-
handler: async (_args: string, ctx: ExtensionCommandContext) => {
|
|
24
|
-
await ctx.reload();
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
23
|
// [fetch-current-system-prompt] Trace 视图「现取当前值」通道(session-trace design §3.1
|
|
29
24
|
// 失败路径 / D2):pi RPC 无 get_system_prompt 命令、getSystemPrompt() 只在 extension
|
|
30
25
|
// API,且现取不能依赖可禁的留痕包(system-prompt-trace 是 feature tier)——挂本
|