feat: enable permission-aware subagents

This commit is contained in:
叶林立
2026-08-26 10:49:26 +08:00
parent d3bf562189
commit 7571ba6dd9
185 changed files with 48365 additions and 26 deletions
+37 -1
View File
@@ -9,6 +9,40 @@ import test from "node:test";
const repositoryRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
const hasPi = spawnSync("pi", ["--version"], { encoding: "utf8" }).status === 0;
test("enabled subagents wrapper loads with its bundle-owned mandatory permission entry", { skip: !hasPi }, async () => {
const packageJson = JSON.parse(await readFile(join(repositoryRoot, "package.json"), "utf8")) as {
dependencies: Record<string, string>;
files: string[];
pi: { extensions: string[] };
};
assert.ok(packageJson.files.includes("pi-subagents"));
assert.equal(packageJson.dependencies["@tintinweb/pi-subagents"], "file:./pi-subagents");
assert.ok(
packageJson.pi.extensions.includes("./extensions/subagents.ts"),
"the bundle must default-load the locally maintained subagents wrapper",
);
const home = await mkdtemp(join(tmpdir(), "my-pi-subagents-wrapper-load-"));
const result = spawnSync(
"pi",
["--no-extensions", "-e", join(repositoryRoot, "extensions", "subagents.ts"), "--mode", "rpc"],
{
encoding: "utf8",
timeout: 60_000,
env: {
...process.env,
HOME: home,
XDG_CONFIG_HOME: join(home, ".config"),
PI_CODING_AGENT_DIR: join(home, ".pi-agent"),
PI_OFFLINE: "1",
},
},
);
assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);
assert.doesNotMatch(`${result.stdout}\n${result.stderr}`, /Failed to load extension/u);
});
test("all package extensions load together without global registration conflicts", { skip: !hasPi }, async () => {
const packageJson = JSON.parse(await readFile(join(repositoryRoot, "package.json"), "utf8")) as {
dependencies: Record<string, string>;
@@ -36,6 +70,8 @@ test("all package extensions load together without global registration conflicts
"the packed bundle must include the locally maintained Codex Fast mode source",
);
assert.equal(packageJson.dependencies["@ogulcancelik/pi-minimal-footer"], "file:./pi-minimal-footer");
assert.equal(packageJson.dependencies["@tintinweb/pi-subagents"], "file:./pi-subagents");
assert.ok(packageJson.pi.extensions.includes("./extensions/subagents.ts"));
assert.equal(
packageJson.pi.extensions.some((entry) => entry.includes("pi-hermes-memory") || entry.includes("the-forge-flow")),
false,
@@ -51,7 +87,7 @@ test("all package extensions load together without global registration conflicts
await chmod(hippo, 0o755);
const args = ["--no-extensions"];
for (const entry of packageJson.pi.extensions) args.push("-e", resolve(repositoryRoot, entry));
args.push("--help");
args.push("--mode", "rpc");
const result = spawnSync("pi", args, {
encoding: "utf8",