@zhushanwen/pi-plan 0.3.5 → 0.3.7
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 +2 -2
- package/src/__tests__/templates.test.ts +28 -2
- package/src/templates.ts +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhushanwen/pi-plan",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Lightweight plan mode for Pi coding agent",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"@earendil-works/pi-coding-agent": ">=0.73.0",
|
|
19
19
|
"typebox": "*",
|
|
20
20
|
"@earendil-works/pi-ai": "*",
|
|
21
|
-
"@zhushanwen/pi-goal": "0.8.
|
|
21
|
+
"@zhushanwen/pi-goal": "0.8.3"
|
|
22
22
|
},
|
|
23
23
|
"peerDependenciesMeta": {
|
|
24
24
|
"@earendil-works/pi-ai": {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
+
import * as os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
2
4
|
|
|
3
|
-
import { describe, expect,it } from "vitest";
|
|
5
|
+
import { describe, expect, it } from "vitest";
|
|
4
6
|
|
|
5
|
-
import { getBuiltinTemplateDir,listTemplates, loadTemplate } from "../templates.js";
|
|
7
|
+
import { getBuiltinTemplateDir, listTemplates, loadTemplate } from "../templates.js";
|
|
6
8
|
|
|
7
9
|
describe("Template system", () => {
|
|
8
10
|
it("listTemplates returns builtin templates", () => {
|
|
@@ -31,4 +33,28 @@ describe("Template system", () => {
|
|
|
31
33
|
const dir = getBuiltinTemplateDir();
|
|
32
34
|
expect(fs.existsSync(dir)).toBe(true);
|
|
33
35
|
});
|
|
36
|
+
|
|
37
|
+
it("TC8: PI_CODING_AGENT_DIR 隔离目录下扫到全局模板(getAgentDir 派生,不依赖 ~/.pi/agent)", () => {
|
|
38
|
+
const origEnv = process.env.PI_CODING_AGENT_DIR;
|
|
39
|
+
const isolated = fs.mkdtempSync(path.join(os.tmpdir(), "plan-tpl-"));
|
|
40
|
+
try {
|
|
41
|
+
process.env.PI_CODING_AGENT_DIR = isolated;
|
|
42
|
+
fs.mkdirSync(path.join(isolated, "plan-templates"), { recursive: true });
|
|
43
|
+
fs.writeFileSync(path.join(isolated, "plan-templates", "isolated-template.md"), "# t");
|
|
44
|
+
|
|
45
|
+
const templates = listTemplates();
|
|
46
|
+
const names = templates.map((t) => t.name);
|
|
47
|
+
expect(names).toContain("isolated-template");
|
|
48
|
+
// 隔离目录模板 source 为 global(getAgentDir 直接返回 PI_CODING_AGENT_DIR 值,无 .pi/agent 嵌套)
|
|
49
|
+
const tpl = templates.find((t) => t.name === "isolated-template");
|
|
50
|
+
expect(tpl?.source).toBe("global");
|
|
51
|
+
expect(tpl?.path.startsWith(isolated)).toBe(true);
|
|
52
|
+
// 仍能扫到 builtin 模板(最低优先级)
|
|
53
|
+
expect(names).toContain("feature-plan");
|
|
54
|
+
} finally {
|
|
55
|
+
if (origEnv === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
56
|
+
else process.env.PI_CODING_AGENT_DIR = origEnv;
|
|
57
|
+
fs.rmSync(isolated, { recursive: true, force: true });
|
|
58
|
+
}
|
|
59
|
+
});
|
|
34
60
|
});
|
package/src/templates.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as fs from "node:fs";
|
|
2
|
-
import * as os from "node:os";
|
|
3
2
|
import * as path from "node:path";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
5
4
|
|
|
5
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
6
|
+
|
|
6
7
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
8
|
|
|
8
9
|
export interface TemplateInfo {
|
|
@@ -39,8 +40,8 @@ export function listTemplates(projectDir?: string): TemplateInfo[] {
|
|
|
39
40
|
templates.push(...scanTemplateDir(path.join(projectDir, ".pi", "plan-templates"), "project", seen));
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
// 2. Global templates
|
|
43
|
-
templates.push(...scanTemplateDir(path.join(
|
|
43
|
+
// 2. Global templates(getAgentDir 派生,实例隔离:PI_CODING_AGENT_DIR 场景读隔离目录)
|
|
44
|
+
templates.push(...scanTemplateDir(path.join(getAgentDir(), "plan-templates"), "global", seen));
|
|
44
45
|
|
|
45
46
|
// 3. Builtin templates (lowest priority)
|
|
46
47
|
templates.push(...scanTemplateDir(getBuiltinTemplateDir(), "builtin", seen));
|