cc_toolgate/eval/decision.rs
1//! Decision types for command evaluation.
2
3/// The gating decision for a command.
4///
5/// Variants are ordered by severity: `Allow < Ask < Deny`.
6/// When evaluating compound commands, the strictest decision across
7/// all segments wins.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
9pub enum Decision {
10 /// Command runs silently without user confirmation.
11 Allow,
12 /// Claude Code prompts the user for confirmation before running.
13 Ask,
14 /// Command is blocked outright and cannot be executed.
15 Deny,
16}
17
18impl Decision {
19 /// Lowercase string for JSON output (`"allow"`, `"ask"`, `"deny"`).
20 pub fn as_str(self) -> &'static str {
21 match self {
22 Decision::Allow => "allow",
23 Decision::Ask => "ask",
24 Decision::Deny => "deny",
25 }
26 }
27
28 /// Uppercase label for human-readable log output (`"ALLOW"`, `"ASK"`, `"DENY"`).
29 pub fn label(self) -> &'static str {
30 match self {
31 Decision::Allow => "ALLOW",
32 Decision::Ask => "ASK",
33 Decision::Deny => "DENY",
34 }
35 }
36}
37
38/// The result of evaluating a command: a decision and a human-readable reason.
39#[derive(Debug, Clone)]
40pub struct RuleMatch {
41 /// The gating decision.
42 pub decision: Decision,
43 /// Human-readable explanation of why this decision was reached.
44 pub reason: String,
45}