mirror of
https://bitbucket.org/siakitem/my-pi.git
synced 2026-10-26 10:45:22 +00:00
多个扩展各自整段改写系统提示词并按加载顺序接力,任一扩展定死提示词后 其余只能做字符串手术,且各上游的工具说明与组合包实际工具格局冲突。 - 新增 extensions/system-prompt.ts 作为唯一出口(加载列表最后),按 config/prompt/(preamble.md、tools.jsonc、routing.jsonc、sections.jsonc) 组合开场白、工具简介/规则与 <tool_routing> 分区;替代原封面与 tool-routing 扩展,/dump-system-prompt 输出最终提示词。 - pi-chrome、pi-ssh、pi-hermes-memory 改为写命名分区,pi-rtk-optimizer 改写 promptGuidelines,pi-permission-system 直接过滤结构化 skills, 均不再返回 systemPrompt;pi-chrome 未授权时不再每轮冻结提示词。 - 新增 prompt-guard 代理加载第三方扩展(Hashline、FFF、LSP、 context-mode):拦截直接改写提示词并按目录覆盖工具说明;context-mode 去掉与组合包路由冲突的锚点段,保留记忆与恢复快照。 - 消除冲突:bash 简介不再建议 grep/find;Hashline edit 不再称可用 grep 锚点、不再介绍已关闭的 replace_text;context-mode 读写/网页路由提示。 - 守门测试:工具目录覆盖率、禁用用法检查、context-mode 上游原文锁定; AGENTS.md 新增「系统提示词单一所有权」。 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
91 lines
3.0 KiB
TypeScript
91 lines
3.0 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { AgentPrepHandler } from "#src/handlers/before-agent-start";
|
|
|
|
import { makeCheckResult, makeCtx } from "#test/helpers/handler-fixtures";
|
|
import {
|
|
makeRealResolver,
|
|
makeRealSession,
|
|
} from "#test/helpers/session-fixtures";
|
|
|
|
function makeSetup() {
|
|
const { session, permissionManager, sessionRules, configStore, forwarding } =
|
|
makeRealSession();
|
|
const { resolver } = makeRealResolver(permissionManager, sessionRules);
|
|
vi.mocked(permissionManager.check).mockReturnValue(makeCheckResult());
|
|
const warmParser = vi.fn();
|
|
const handler = new AgentPrepHandler(session, resolver, warmParser);
|
|
return {
|
|
handler,
|
|
session,
|
|
permissionManager,
|
|
configStore,
|
|
forwarding,
|
|
warmParser,
|
|
};
|
|
}
|
|
|
|
describe("AgentPrepHandler", () => {
|
|
it("warms the parser and activates the permission session", async () => {
|
|
const { handler, forwarding, warmParser } = makeSetup();
|
|
const ctx = makeCtx();
|
|
|
|
await handler.handle({ systemPrompt: "You are an assistant." }, ctx);
|
|
|
|
expect(warmParser).toHaveBeenCalledTimes(1);
|
|
expect(forwarding.start).toHaveBeenCalledWith(ctx);
|
|
});
|
|
|
|
it("refreshes global permission configuration", async () => {
|
|
const { handler, configStore } = makeSetup();
|
|
const ctx = makeCtx({ isProjectTrusted: () => false });
|
|
|
|
await handler.handle({ systemPrompt: "You are an assistant." }, ctx);
|
|
|
|
expect(configStore.refresh).toHaveBeenCalledWith(ctx, false);
|
|
});
|
|
|
|
it("does not rewrite a prompt without skill entries", async () => {
|
|
const { handler, session } = makeSetup();
|
|
|
|
const result = await handler.handle(
|
|
{ systemPrompt: "You are an assistant." },
|
|
makeCtx(),
|
|
);
|
|
|
|
expect(result).toEqual({});
|
|
expect(session.getActiveSkillEntries()).toEqual([]);
|
|
});
|
|
|
|
it("filters denied skills out of structured systemPromptOptions.skills", async () => {
|
|
const { handler, session, permissionManager } = makeSetup();
|
|
vi.mocked(permissionManager.check).mockImplementation((intent) =>
|
|
makeCheckResult({
|
|
state:
|
|
intent.kind === "tool" &&
|
|
(intent.input as { name?: string })?.name === "dangerous"
|
|
? "deny"
|
|
: "allow",
|
|
}),
|
|
);
|
|
|
|
const options = {
|
|
skills: [
|
|
{ name: "librarian", description: "d", filePath: "/skills/librarian/SKILL.md", baseDir: "/skills/librarian" },
|
|
{ name: "dangerous", description: "d", filePath: "/skills/dangerous/SKILL.md", baseDir: "/skills/dangerous" },
|
|
{ name: "manual", description: "d", filePath: "/skills/manual/SKILL.md", baseDir: "/skills/manual", disableModelInvocation: true },
|
|
],
|
|
};
|
|
const result = await handler.handle(
|
|
{ systemPrompt: "You are an assistant.", systemPromptOptions: options },
|
|
makeCtx(),
|
|
);
|
|
|
|
expect(result).toEqual({});
|
|
expect(options.skills.map((skill) => skill.name)).toEqual(["librarian", "manual"]);
|
|
expect(session.getActiveSkillEntries().map((entry) => entry.name)).toEqual([
|
|
"librarian",
|
|
]);
|
|
});
|
|
});
|