Documentation
¶
Overview ¶
Package approval 提供审批策略(Approval Policy)接缝。
对齐上游:packages/core/approval
本文件对应任务 M27:Approval Policy 接缝。
设计要点:
- Policy 枚举:allow-all / deny-all / ask-dangerous / ask-dangerous-tool-edit;
- Effective(生效策略)解析遵循「预设层 → 用户层 → 会话层」三层 override 顺序, 会话层优先级最高(nearest-scope-wins);并记录 Source 用于审计;
- ask→allowed-once 语义:ask 策略通过 User Questions 向用户询问,用户「准许」只对 这一次工具调用放行;下一次同工具调用继续 ask,绝不做按工具名的永久放行;
- 与 M22 PreToolDecision(tools/pre-execute 三态)协同:本包产出 Allow/Deny/Ask 决策。
依赖接缝:User Questions(userq)用于 ask;预设→策略的映射以 PresetPolice 函数注入, 从而 pkg/approval 不反向依赖 pkg/presets(M27 与 M28 相互依赖,靠单向注入破除环)。
Index ¶
- type DangerFunc
- type Decision
- type EffSource
- type Effective
- type Policy
- type PresetPolice
- type Request
- type Service
- func (s *Service) AskCount() int
- func (s *Service) ClearSessionPolicy(sessionID string)
- func (s *Service) Evaluate(req Request) (Decision, error)
- func (s *Service) Resolve(preset string, sessionID string) Effective
- func (s *Service) SetDangerous(m map[string]bool)
- func (s *Service) SetSessionPolicy(sessionID string, p Policy)
- func (s *Service) SetUserPolicy(p Policy)
- func (s *Service) SetUserPolicyByKey(userKey string, p Policy)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DangerFunc ¶
DangerClass 判断某工具是否属于"危险"类别(用于 ask-dangerous 系列触发 ask)。
type PresetPolice ¶
PresetPolice 把预设名映射为审批策略;ok=false 表示该预设未定义、回落默认。
type Request ¶
type Request struct {
// Tool 是工具名。
Tool string
// CallID 是本次工具调用的唯一标识(allowed-once 粒度锚点)。
CallID string
// Preset 是当前权限预设名(决定预设层策略)。
Preset string
// SessionID 是调用会话标识(决定会话层 override;空串表示无会话 override)。
SessionID string
// DangerousOverride 提供危险分类;nil 时按内置白名单。
DangerousOverride DangerFunc
}
Request 是单次工具执行的审批请求。
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service 是审批服务(ctx.approval)。
func New ¶
func New(preset PresetPolice, uq *userq.Service) *Service
New 创建审批服务。preset 注入预设→策略映射;uq 注入用户提问服务; presetLayer 通过 PresetPolice 在运行时求值,不入 scope。
func (*Service) ClearSessionPolicy ¶
ClearSessionPolicy 移除会话层 override。
func (*Service) Evaluate ¶
Evaluate 对一次工具调用给出 allow/deny/ask 决策。
- allow-all → allow;deny-all → deny;
- ask-dangerous / ask-dangerous-tool-edit → 若工具危险则 ask(调用 UQ),否则 allow;
- ask 用户"准许"只放行本次调用(allowed-once),下一次同工具继续 ask。
func (*Service) SetDangerous ¶
SetDangerous 覆写危险工具白名单。
func (*Service) SetSessionPolicy ¶
SetSessionPolicy 设置会话层策略 override(source=session,优先级最高)。
func (*Service) SetUserPolicy ¶
SetUserPolicy 设置用户层策略 override(source=user)。
func (*Service) SetUserPolicyByKey ¶
SetUserPolicyByKey 设置某个用户的策略 override。