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
+142
View File
@@ -1763,6 +1763,148 @@ describe("mandatory extension policy", () => {
});
});
describe("excluded extension paths", () => {
function excludedEntry(name = "pi-ask-user"): { dir: string; path: string } {
const dir = mkdtempSync(join(tmpdir(), "subagents-excluded-runner-"));
const extDir = join(dir, name);
mkdirSync(extDir, { recursive: true });
const path = join(extDir, "index.ts");
writeFileSync(path, "export default () => {};\n");
return { dir, path };
}
function setup(extensions: true | string[] | false, excludeExtensions?: string[]) {
vi.mocked(getConfig).mockReturnValueOnce(makeConfig({ extensions, excludeExtensions }));
vi.mocked(getAgentConfig).mockReturnValueOnce(
makeAgentConfig({ extensions, excludeExtensions }),
);
vi.mocked(getToolNamesForType).mockReturnValueOnce(BUILTINS_7);
}
it("removes the extension under extensions:true, tools and all", async () => {
const fixture = excludedEntry();
try {
setup(true);
withExtensions({
[fixture.path]: ["ask_user_question"],
"/ext/other.ts": ["other_tool"],
});
const { session } = createSession("OK");
createAgentSession.mockResolvedValue({ session });
const onToolActivity = vi.fn();
await runAgent(ctx, "Explore", "go", {
pi,
excludedExtensionPaths: [fixture.path],
onToolActivity,
});
// Exclusion forces the override on even though extensions:true + no
// frontmatter excludes would otherwise skip it.
expect(lastLoaderOpts().extensionsOverride).toBeDefined();
expect(loaderExtensionsRef.current.extensions.map((e) => e.path))
.not.toContain(fixture.path);
const tools = lastToolsPassed();
expect(tools).not.toContain("ask_user_question");
expect(tools).toContain("other_tool");
expect(onToolActivity).toHaveBeenCalledWith(expect.objectContaining({
toolName: expect.stringContaining("excluded from subagent sessions"),
}));
} finally {
rmSync(fixture.dir, { recursive: true, force: true });
}
});
it("removes the extension even when an `extensions:` name entry selects it", async () => {
const fixture = excludedEntry();
try {
setup(["pi-ask-user"]);
withExtensions({ [fixture.path]: ["ask_user_question"] });
const { session } = createSession("OK");
createAgentSession.mockResolvedValue({ session });
const onToolActivity = vi.fn();
await runAgent(ctx, "Explore", "go", {
pi,
excludedExtensionPaths: [fixture.path],
onToolActivity,
});
expect(loaderExtensionsRef.current.extensions.map((e) => e.path))
.not.toContain(fixture.path);
expect(lastToolsPassed()).not.toContain("ask_user_question");
expect(onToolActivity).toHaveBeenCalledWith(expect.objectContaining({
toolName: expect.stringContaining("excluded from subagent sessions"),
}));
} finally {
rmSync(fixture.dir, { recursive: true, force: true });
}
});
it("removes the extension even when an `extensions:` path entry requests it", async () => {
const fixture = excludedEntry();
try {
setup([fixture.path]);
withExtensions({ [fixture.path]: ["ask_user_question"] });
const { session } = createSession("OK");
createAgentSession.mockResolvedValue({ session });
await runAgent(ctx, "Explore", "go", {
pi,
excludedExtensionPaths: [fixture.path],
});
expect(lastLoaderOpts().additionalExtensionPaths).toBeUndefined();
expect(loaderExtensionsRef.current.extensions.map((e) => e.path))
.not.toContain(fixture.path);
expect(lastToolsPassed()).not.toContain("ask_user_question");
} finally {
rmSync(fixture.dir, { recursive: true, force: true });
}
});
it("is a no-op when empty — no override installed for wildcard agents", async () => {
setup(["*"]);
withExtensions({ "/ext/a.ts": ["tool_a"] });
const { session } = createSession("OK");
createAgentSession.mockResolvedValue({ session });
await runAgent(ctx, "Explore", "go", { pi, excludedExtensionPaths: [] });
expect(lastLoaderOpts().extensionsOverride).toBeUndefined();
expect(lastToolsPassed()).toContain("tool_a");
});
it("keeps mandatory entries while removing excluded ones", async () => {
const mandatoryDir = mkdtempSync(join(tmpdir(), "subagents-mandatory-runner-"));
const mandatoryPath = join(mandatoryDir, "permission-system.ts");
writeFileSync(mandatoryPath, "export default () => {};\n");
const fixture = excludedEntry();
try {
setup(true);
withExtensions({
[mandatoryPath]: ["permission_admin"],
[fixture.path]: ["ask_user_question"],
});
const { session } = createSession("OK");
createAgentSession.mockResolvedValue({ session });
await runAgent(ctx, "Explore", "go", {
pi,
mandatoryExtensionPaths: [mandatoryPath],
excludedExtensionPaths: [fixture.path],
});
const loaded = loaderExtensionsRef.current.extensions.map((e) => e.path);
expect(loaded).toContain(mandatoryPath);
expect(loaded).not.toContain(fixture.path);
} finally {
rmSync(mandatoryDir, { recursive: true, force: true });
rmSync(fixture.dir, { recursive: true, force: true });
}
});
});
describe("agent-runner extension allowlist", () => {
function setupArrayAgent(extensions: string[]) {
vi.mocked(getConfig).mockReturnValueOnce(makeConfig({ extensions }));