Expand description
Scope 守卫 + 限额检查 + 审计日志
两种模式:
- scope 模式(
state.is_scope_mode()):必须持有 api-key,且 scope 匹配 - legacy 模式(没配 keys-file):读工具全放行;写工具走
enable_trading/allow_real_trading两级开关
Enums§
- Guard
Outcome - 守卫结果:Allow 或携带拒绝原因的 JSON
- Tool
Scope - 工具需要的 scope 类别
Functions§
- args_
short_ hash - 计算 args 的短哈希(前 8 hex),用于审计日志(不存原始敏感字段)
- audit 🔒
- 审计日志:key_id / tool / result / reason
- current_
authed_ 🔒key - 从 KeyStore 里按 id 取当前的 KeyRecord(对齐 SIGHUP 热重载)。
- emit_
trade_ outcome - 交易工具执行完后的审计事件:解析 handler 返回的 JSON,success / failure
写入 audit JSONL。
key_id = None时用 “” 占位(legacy 模式)。 - require_
scope - 基础 scope 守卫(用于只读工具)
- require_
tool_ scope - 基于注册表的只读 scope 守卫;若工具未登记则 fail-closed 拒绝。
- require_
trading - 交易写守卫:scope + legacy 兼容 + (可选)限额检查 + (可选)per-call key 覆盖
- scope_
for_ tool - 工具名 → 所需 scope 的中央注册表。