feat(policy): 未分类工具默认拦截,问清只读还是改动、登记后才放行(POLICY_VERSION 0.5.0)

This commit is contained in:
QQ 2026-11-10 21:08:56 +08:00
parent 646f33589c
commit 6edacc3065
1 changed files with 9 additions and 2 deletions

View File

@ -4,7 +4,7 @@ import path from 'node:path'
import { createWorkbenchHost, resolveStorePath } from './workbench/host/index.mjs'
const PRESET_ID = 'sansheng-liubu'
export const POLICY_VERSION = '0.4.0'
export const POLICY_VERSION = '0.5.0'
/**
* 默认不强制任何 provider/model:宿主未必注册了这些适配器,强行指定会让整轮请求
@ -173,7 +173,14 @@ export function evaluateToolPolicy(role, toolName, tasks = [], options = {}) {
audit({ action: 'management-tool', role, toolName, decision: 'allow', approvalId: approval.id })
return undefined
}
if (!MUTATING_TOOLS.has(toolName)) return undefined
if (!MUTATING_TOOLS.has(toolName)) {
// 走到这里的不是禁用工具,也过了签字与管理工具两关。剩下两类:
// 登记在册的只读工具、刚核验过人工签字的签字类工具,放行;
// 其余从没登记过的工具一律先拦——「没在名单里」不等于只读安全,
// 问清它只读还是会改动、登记进对应分类后才放行。
if (READ_ONLY_TOOLSET.includes(toolName) || HUMAN_SIGNATURE_TOOLS.has(toolName)) return undefined
return `${toolName} 尚未登记分类,未知工具默认拦截:请先确认它只读还是会改动,只读的登记进只读工具集、会改动的登记进写入分类,再放行。`
}
if (READ_ONLY_ROLES.has(role)) return `${role} 是只读规划、审核或调度角色,不得调用写入型工具 ${toolName}。`
if (!EXECUTION_ROLES.has(role)) return `${role} 不是获准的执行部门,不能调用 ${toolName}。`
if (!ROLE_ALLOWED_MUTATIONS[role]?.has(toolName)) return `${toolName} 不属于 ${role} 的职责范围。`