Documentation
¶
Overview ¶
Package policy 操作审计门:多种会话执行策略模式(confirm/auto/plan/full)下的 统一操作裁决——每个操作必过、三值裁决、全程留痕。模式改变的是裁决策略,不是移除 审计点;红线(变异工具拒绝、高危恒人审)在矩阵层硬编码,任何模式不可绕过。
裁决分层:例外规则(Policy.Rules,首个命中即胜)→ 模式×风险矩阵 → 兜底 need_human (未知形态 fail-safe)。灰区可挂 Arbiter 仲裁插件,失败/非法输出一律 fail-safe 升人审 ——「只升不降」在 fail-safe 方向恒成立。工具调用面的装饰器见 AuditGate。
沉淀自 bianque engine/policy(v0.9.6):领域包 yaml 路径约定改为显式入参 (LoadOverrides path),其余原样。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuditGate ¶
func AuditGate(g *Gate, op Op, onAudit func(Op, Decision), t tool.InvokableTool) tool.InvokableTool
AuditGate 给工具套操作审计门;gate 为 nil 原样返回(未装配审计门=存量行为)。
Types ¶
type Arbiter ¶
Arbiter 灰区仲裁插件(可选)。契约:只允许返回 auto_proceed/need_human/deny; 失败或非法输出由 Gate fail-safe 升人审——「只升不降」在 fail-safe 方向恒成立。
type Gate ¶
type Gate struct {
// contains filtered or unexported fields
}
Gate 操作审计门。Decide 只读 policy,并发安全,可放工具调用热路径。
type Op ¶
type Op struct {
Type OpType
Mode Mode
Tool string // 工具名(tool_call/execute_step)
Risk int // 1-4(plan_submit);0=未评级
Mutating bool // 工具名命中变异动词段(agentrun.IsMutatingTool)
}
Op 一次待裁决操作。
type Policy ¶
type Policy struct {
AutoMaxRisk int `yaml:"auto_max_risk"`
FullMaxRisk int `yaml:"full_max_risk"`
Rules []Rule `yaml:"rules"`
}
Policy 策略表:代批阈值 + 例外规则。yaml 外置(LoadOverrides,缺文件用 DefaultPolicy 基座;解析失败 fail-fast)。
func DefaultPolicy ¶
func DefaultPolicy() *Policy
DefaultPolicy 内置基座:auto 代批至 L2、full 代批至 L3(L4 恒人工双确认)。
func LoadOverrides ¶
LoadOverrides 读 <fsys>/<path> 外置策略文件(yaml 根键 operation_policy)。 缺文件 → 内置基座(nil error);读取/解析失败 → error(fail-fast,启动即败, 宁拒不启动不带错跑)。阈值 clamp 到基座——外置文件只能调低不能调高 (调高=扩权,须改基座走评审)。path 由宿主传入(如领域包布局约定 "_shared/operation_policy.yaml")。
type Rule ¶
type Rule struct {
ID string `yaml:"id"`
OpTypes []string `yaml:"op_types"` // 空=全部操作类型
Tools []string `yaml:"tools"` // 工具名精确匹配;空=不限
MinRisk int `yaml:"min_risk"` // 含(对 plan_submit 的 Risk 生效;0=不限)
MaxRisk int `yaml:"max_risk"` // 含;0=不限
Mutating *bool `yaml:"mutating"` // nil=不限
Verdict Verdict `yaml:"verdict"` // auto_proceed|need_human|deny|unknown
Reason string `yaml:"reason"`
}
Rule 例外规则(首个命中即裁决,优先于矩阵层)。