1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//! Standardized exit codes for dcg commands.
//!
//! These codes are stable and documented for agent/robot mode consumption.
//! See ADR-002 for the design rationale.
//!
//! # Exit Code Contract
//!
//! | Code | Constant | Meaning |
//! |------|----------|---------|
//! | 0 | `EXIT_SUCCESS` | Success / Allow |
//! | 1 | `EXIT_DENIED` | Command denied/blocked |
//! | 2 | `EXIT_WARNING` | Warning (with --fail-on warn) |
//! | 3 | `EXIT_CONFIG_ERROR` | Configuration error |
//! | 4 | `EXIT_PARSE_ERROR` | Parse/input error |
//! | 5 | `EXIT_IO_ERROR` | IO error |
//!
//! # Usage
//!
//! ```rust,ignore
//! use dcg::exit_codes::{EXIT_SUCCESS, EXIT_DENIED};
//!
//! fn main() {
//! let result = evaluate_command("rm -rf /");
//! std::process::exit(if result.is_denied() {
//! EXIT_DENIED
//! } else {
//! EXIT_SUCCESS
//! });
//! }
//! ```
use ExitCode;
/// Command completed successfully (allowed, passed, healthy).
///
/// Used when:
/// - A command is allowed by dcg
/// - A subcommand completes without errors
/// - Health checks pass
pub const EXIT_SUCCESS: i32 = 0;
/// Command was denied/blocked by a security rule.
///
/// Used when:
/// - A destructive command is blocked
/// - A pattern match triggers a deny decision
/// - Hook mode returns a deny verdict
pub const EXIT_DENIED: i32 = 1;
/// Command triggered a warning (with --fail-on warn).
///
/// Used when:
/// - A command matches a medium/low severity pattern
/// - Scan finds warnings but not errors
/// - Used with `--fail-on warn` to treat warnings as failures
pub const EXIT_WARNING: i32 = 2;
/// Configuration error (invalid config file, missing required config).
///
/// Used when:
/// - Config file has syntax errors
/// - Required config values are missing
/// - Config validation fails
pub const EXIT_CONFIG_ERROR: i32 = 3;
/// Parse/input error (invalid JSON, malformed command).
///
/// Used when:
/// - Hook input is not valid JSON
/// - CLI arguments are invalid
/// - Input file cannot be parsed
pub const EXIT_PARSE_ERROR: i32 = 4;
/// IO error (file not found, permission denied, network error).
///
/// Used when:
/// - Config file not found
/// - Permission denied reading/writing files
/// - Database access fails
pub const EXIT_IO_ERROR: i32 = 5;
/// Convert an exit code constant to [`std::process::ExitCode`].
///
/// This is useful for returning from `main()` with the correct exit code.
///
/// # Example
///
/// ```rust,ignore
/// use dcg::exit_codes::{to_exit_code, EXIT_DENIED};
///
/// fn main() -> std::process::ExitCode {
/// to_exit_code(EXIT_DENIED)
/// }
/// ```
pub const
/// Exit the process with the given exit code.
///
/// This is a convenience wrapper around [`std::process::exit`] that
/// takes our exit code constants.
///
/// # Example
///
/// ```rust,ignore
/// use dcg::exit_codes::{exit_with, EXIT_CONFIG_ERROR};
///
/// if config.is_invalid() {
/// eprintln!("Invalid configuration");
/// exit_with(EXIT_CONFIG_ERROR);
/// }
/// ```
!
/// Trait for converting evaluation results to exit codes.
///
/// Implement this trait for types that represent command evaluation results.