feat(pi-subagents): 重新启用子 Agent 并使用独立的子 Agent 提示词

- 根包恢复 file:./pi-subagents 依赖与 extensions/subagents.ts 加载
  (排在 permission-system 之后、Tool Search 之前),并刷新根锁文件;
  Agent / get_subagent_result / steer_subagent 权限设为 allow,
  子 Agent 内的实际操作仍逐个经权限系统并转发主会话。
- 新增 config/prompt/subagent/:执行者角色 preamble 与组合包自带的
  general-purpose / Explore / Plan 定义(替换上游内置,去掉 bash find
  冲突规则与写死的 Haiku 模型)。
- pi-subagents 新增 basePrompt / bundledAgentsDir / excludedExtensionPaths
  选项:子 Agent 不再嵌入父会话提示词,身份标记置于开头;子会话排除
  pi-ask-user。未传选项时保持上游行为。
- system-prompt.ts:customPrompt 自带开场白时不再覆盖(修复子 Agent 角色
  与 <active_agent> 身份被抹掉);仅凭 customPrompt 上的 <active_agent>
  识别子会话,routing 规则支持 scope,sections 支持 subagentExclude
  (子会话去掉 memory_policy 与 chrome_profile_bridge)。
- pi-hermes-memory:子会话只读,记忆/skill 写入工具返回错误,后台整理、
  纠错检测、会话 flush 与索引写入全部跳过。

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
云服务部-叶林立
2026-10-20 19:43:22 -07:00
co-authored by Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent b817d66a11
commit 360d8cffc8
37 changed files with 2837 additions and 2416 deletions
+147
View File
@@ -0,0 +1,147 @@
/**
* bundled-agents.test.ts — `bundledAgentsDir` extension option: bundle-shipped
* agent .md files register as embedded defaults (isDefault, no source/path),
* sit between embedded defaults and user agents in precedence, and stay out of
* the registry when the option is unset.
*/
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { buildAgentRegistry, getAgentConfig, getDefaultAgentNames, registerAgents } from "../src/agent-types.js";
import { loadBundledAgents } from "../src/custom-agents.js";
import { createPiSubagentsExtension } from "../src/index.js";
let tmpDir: string;
let bundledDir: string;
let originalHome: string | undefined;
let originalAgentDir: string | undefined;
beforeEach(() => {
tmpDir = mkdtempSync(join(tmpdir(), "pi-bundled-agents-"));
bundledDir = join(tmpDir, "bundled");
mkdirSync(bundledDir, { recursive: true });
originalHome = process.env.HOME;
originalAgentDir = process.env.PI_CODING_AGENT_DIR;
process.env.HOME = join(tmpDir, "home");
delete process.env.PI_CODING_AGENT_DIR;
});
afterEach(() => {
if (originalHome == null) delete process.env.HOME;
else process.env.HOME = originalHome;
if (originalAgentDir == null) delete process.env.PI_CODING_AGENT_DIR;
else process.env.PI_CODING_AGENT_DIR = originalAgentDir;
rmSync(tmpDir, { recursive: true, force: true });
registerAgents(new Map());
});
function writeBundled(name: string, content: string) {
writeFileSync(join(bundledDir, `${name}.md`), content);
}
describe("loadBundledAgents", () => {
it("parses agent files with the custom-agent parser and stamps them as built-ins", () => {
writeBundled("scout", `---
name: scout
description: Bundle scout
prompt_mode: append
tools: read, grep
---
Bundle prompt body.`);
const agents = loadBundledAgents(bundledDir);
const scout = agents.get("scout");
expect(scout).toBeDefined();
expect(scout?.description).toBe("Bundle scout");
expect(scout?.systemPrompt).toBe("Bundle prompt body.");
expect(scout?.promptMode).toBe("append");
expect(scout?.builtinToolNames).toEqual(["read", "grep"]);
expect(scout?.isDefault).toBe(true);
expect(scout?.source).toBeUndefined();
expect(scout?.sourcePath).toBeUndefined();
});
it("returns an empty map for a missing or empty directory", () => {
expect(loadBundledAgents(join(tmpDir, "missing")).size).toBe(0);
expect(loadBundledAgents(bundledDir).size).toBe(0);
});
it("skips non-.md files and reserved ':' names", () => {
writeBundled("fine", "---\ndescription: ok\n---\nbody");
writeFileSync(join(bundledDir, "notes.txt"), "not an agent");
writeBundled("bad", "---\nname: 'plugin:scout'\ndescription: bad\n---\nbody");
const agents = loadBundledAgents(bundledDir);
expect([...agents.keys()]).toEqual(["fine"]);
});
});
describe("bundled agent precedence", () => {
it("replaces a same-name embedded default and reports as a default", () => {
writeBundled("Explore", `---
name: Explore
description: Bundled Explore override
prompt_mode: replace
---
Bundled Explore body.`);
const bundled = loadBundledAgents(bundledDir);
const registry = buildAgentRegistry(new Map(), bundled);
expect(registry.get("Explore")?.systemPrompt).toBe("Bundled Explore body.");
expect(registry.get("Explore")?.isDefault).toBe(true);
// Unrelated embedded defaults are untouched.
expect(registry.get("general-purpose")?.systemPrompt).not.toBe("Bundled Explore body.");
});
it("new bundled names join the default set", () => {
writeBundled("bundle-only", "---\ndescription: only in bundle\n---\nbody");
const registry = buildAgentRegistry(new Map(), loadBundledAgents(bundledDir));
expect(registry.get("bundle-only")?.isDefault).toBe(true);
registerAgents(new Map(), loadBundledAgents(bundledDir));
expect(getDefaultAgentNames()).toContain("bundle-only");
expect(getAgentConfig("bundle-only")?.description).toBe("only in bundle");
});
it("user agents still override bundled definitions", () => {
writeBundled("scout", "---\ndescription: bundled\n---\nbundled body");
const user = new Map([
["scout", {
name: "scout",
description: "project override",
systemPrompt: "project body",
promptMode: "replace" as const,
extensions: true as const,
skills: true as const,
source: "project" as const,
sourcePath: "/proj/.pi/agents/scout.md",
}],
]);
const registry = buildAgentRegistry(user, loadBundledAgents(bundledDir));
expect(registry.get("scout")?.description).toBe("project override");
expect(registry.get("scout")?.isDefault).not.toBe(true);
});
});
describe("extension option validation", () => {
it("rejects a path that is both mandatory and excluded", () => {
const dir = mkdtempSync(join(tmpdir(), "pi-subagents-overlap-"));
const path = join(dir, "permission-system.ts");
writeFileSync(path, "export default () => {};\n");
expect(() =>
createPiSubagentsExtension({
mandatoryExtensionPaths: [path],
excludedExtensionPaths: [path],
}),
).toThrow("both mandatory and excluded");
rmSync(dir, { recursive: true, force: true });
});
it("canonicalizes bundledAgentsDir and rejects missing directories", () => {
expect(() =>
createPiSubagentsExtension({ bundledAgentsDir: join(tmpDir, "missing") }),
).toThrow("is unavailable");
expect(() => createPiSubagentsExtension({ bundledAgentsDir: bundledDir })).not.toThrow();
});
});