feat(pi-permission-system): AutoReview 改为跟随主模型的对话式工具调用审查

AutoReview:

- 审查器回到 Codex Guardian 风格的对话式审查,默认跟随会话当前主模型
  (每次审查实时读取 ctx.model);provider/model 必须同时设置才固定审查
  模型,只设其一视为配置错误并转人工。
- 结论只通过 approve / reject 两个工具给出,参数仅 reason;不强制
  toolChoice,正文文本(即使是合法 JSON)一律忽略。
- approve 自动放行;reject 转人工并在弹窗显示理由(标注模型生成)。
  超时、Provider 错误、截断、未调用工具、多次调用、参数无效等异常同样
  转人工,并附固定的系统说明;用户按 Esc 中止时直接拒绝。
- 模型调用改为 modelRegistry.streamSimple(...).result():Pi 1.3.0 面向
  扩展的 ModelRegistry 没有 completeSimple,原写法在真实环境中每次都会
  转人工。
- 对话记录保留可信度标注;工具结果在有更短的 pi-compaction 摘要时替换
  为摘要;token 估算改为非 ASCII 字符按 1 token 计;预算可配置。
- 同一条用户消息内完全相同的请求只缓存 approve 结论。
- 默认 reasoning low、总超时 30 秒、最多 2 次尝试、maxOutputTokens 4000。

删除:

- 未发布过的 TypeSafe Jev 分类器实现、DenialCircuitBreaker。
- 整个 annotator 机制(model-explanation、注册表、registerAnnotator、
  provider-timeout);annotators 配置键保留为已弃用并忽略,避免旧配置
  被拒绝。

测试:

- 新增 reviewer / transcript / 弹窗说明 / 默认配置测试;清理重复、恒真
  或只测实现细节的旧测试。
- 使用 deepseek-v4.1-flash 实测 5 个场景各 5 次,25 次结论全部符合预期。

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-19 01:54:17 -07:00
co-authored by Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
parent dec48dab6d
commit 7e6a8faae1
87 changed files with 2831 additions and 2658 deletions
@@ -39,20 +39,15 @@ describe("normalizeInput — non-MCP surfaces", () => {
// every path-bearing or special surface to the catch-all ["*"] exactly as it
// does for any unrecognised extension tool.
describe("path-bearing and special surfaces collapse to '*'", () => {
it("path surface ignores input.path and returns ['*']", () => {
// After #504 removal: path no longer has a special branch.
const result = normalizeInput("path", { path: ".env" }, []);
expect(result.surface).toBe("path");
expect(result.values).toEqual(["*"]);
expect(result.resultExtras).toEqual({});
});
it("read surface ignores input.path and returns ['*']", () => {
const result = normalizeInput("read", { path: ".env" }, []);
expect(result.surface).toBe("read");
expect(result.values).toEqual(["*"]);
expect(result.resultExtras).toEqual({});
it("path-bearing surfaces ignore input.path and return ['*']", () => {
// After #504 removal: path-bearing surfaces no longer have a special
// branch in normalizeInput — the access-path gate handles them (#502).
for (const surface of ["path", "read"]) {
const result = normalizeInput(surface, { path: ".env" }, []);
expect(result.surface).toBe(surface);
expect(result.values).toEqual(["*"]);
expect(result.resultExtras).toEqual({});
}
});
it("missing path also returns ['*'] (unchanged fallback)", () => {
@@ -79,14 +74,9 @@ describe("normalizeInput — non-MCP surfaces", () => {
expect(result.resultExtras).toEqual({});
});
it("falls back to '*' when name is missing", () => {
const result = normalizeInput("skill", {}, []);
expect(result.values).toEqual(["*"]);
});
it("falls back to '*' when name is not a string", () => {
const result = normalizeInput("skill", { name: 99 }, []);
expect(result.values).toEqual(["*"]);
it("falls back to '*' when name is missing or not a string", () => {
expect(normalizeInput("skill", {}, []).values).toEqual(["*"]);
expect(normalizeInput("skill", { name: 99 }, []).values).toEqual(["*"]);
});
});
@@ -98,16 +88,12 @@ describe("normalizeInput — non-MCP surfaces", () => {
expect(result.resultExtras).toEqual({ command: "git status" });
});
it("uses empty string when command is missing", () => {
const result = normalizeInput("bash", {}, []);
expect(result.values).toEqual([""]);
expect(result.resultExtras).toEqual({ command: "" });
});
it("uses empty string when command is not a string", () => {
const result = normalizeInput("bash", { command: 42 }, []);
expect(result.values).toEqual([""]);
expect(result.resultExtras).toEqual({ command: "" });
it("uses empty string when command is missing or not a string", () => {
for (const input of [{}, { command: 42 }]) {
const result = normalizeInput("bash", input, []);
expect(result.values).toEqual([""]);
expect(result.resultExtras).toEqual({ command: "" });
}
});
it("strips leading comment lines from values but keeps original in resultExtras", () => {
@@ -159,18 +145,9 @@ describe("normalizeInput — non-MCP surfaces", () => {
});
describe("normalizeInput — MCP surface", () => {
it("surface is 'mcp'", () => {
const result = normalizeInput("mcp", { tool: "exa:search" }, []);
expect(result.surface).toBe("mcp");
});
it("values end with the catch-all 'mcp' target", () => {
const result = normalizeInput("mcp", { tool: "exa:search" }, []);
expect(result.values.at(-1)).toBe("mcp");
});
it("values include specific targets before the catch-all for a qualified tool call", () => {
const result = normalizeInput("mcp", { tool: "exa:search" }, []);
expect(result.surface).toBe("mcp");
expect(result.values).toContain("exa_search");
expect(result.values).toContain("exa:search");
expect(result.values).toContain("exa");
@@ -239,20 +216,6 @@ describe("buildAccessIntentForSurface", () => {
});
it("emits an access-path intent for a path-bearing tool surface (read)", () => {
const intent = buildAccessIntentForSurface(
"read",
"/test/project/.env",
normalizer,
undefined,
);
expect(intent.kind).toBe("access-path");
if (intent.kind === "access-path") {
expect(intent.surface).toBe("read");
expect(intent.path.value()).toBe("/test/project/.env");
}
});
it("emits a tool intent for a non-path surface (bash)", () => {
const intent = buildAccessIntentForSurface(
"bash",
@@ -343,9 +306,4 @@ describe("buildResolvedIntentFromMatchValues", () => {
agentName: "Explore",
});
});
it("threads an empty agentName through for agent-neutral resolution", () => {
const intent = buildResolvedIntentFromMatchValues("bash", ["ls"], "");
expect(intent.agentName).toBe("");
});
});