示例:PermissionGate
ts
export class PermissionGate {
async check(tool: Tool, input: unknown): Promise<PermissionDecision> {
if (tool.readonly) {
return { type: "allow" }
}
if (tool.name === "bash") {
return {
type: "ask",
question: `Allow command: ${summarizeCommand(input)}?`,
}
}
return {
type: "ask",
question: `Allow ${tool.name}?`,
}
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
最小安全策略:
- 读工具默认允许。
- 写工具默认询问。
- Bash 默认询问。
- 明确危险动作直接拒绝。