Skip to content

Commit 40ee043

Browse files
Test Userclaude
andcommitted
style(learnings): cargo fmt guard.rs after allow annotations
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 65a773a commit 40ee043

1 file changed

Lines changed: 104 additions & 36 deletions

File tree

  • crates/terraphim_agent/src/learnings

crates/terraphim_agent/src/learnings/guard.rs

Lines changed: 104 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,48 +81,119 @@ impl GuardDecision {
8181

8282
/// Known-safe command patterns (exact matches or prefixes).
8383
const ALLOW_PATTERNS: &[&str] = &[
84-
"ls", "ll", "dir",
85-
"cat", "head", "tail", "less", "more",
86-
"echo", "printf",
87-
"pwd", "whoami", "uname", "date", "uptime",
88-
"grep", "rg", "find", "fd",
89-
"git status", "git log", "git diff", "git show", "git branch",
90-
"git push", "git pull", "git fetch", "git clone", "git checkout",
91-
"git add", "git commit", "git merge", "git rebase", "git cherry-pick",
92-
"cargo check", "cargo clippy", "cargo fmt", "cargo doc",
93-
"terraform plan", "terraform validate", "terraform show",
94-
"docker ps", "docker images", "docker logs",
95-
"kubectl get", "kubectl describe", "kubectl logs",
96-
"tar -tvf", "tar --list",
97-
"zipinfo", "unzip -l",
98-
"md5sum", "sha256sum", "sha1sum",
99-
"wc", "sort", "uniq", "cut", "awk", "sed", "tr",
100-
"which", "whereis", "type",
101-
"env", "printenv",
84+
"ls",
85+
"ll",
86+
"dir",
87+
"cat",
88+
"head",
89+
"tail",
90+
"less",
91+
"more",
92+
"echo",
93+
"printf",
94+
"pwd",
95+
"whoami",
96+
"uname",
97+
"date",
98+
"uptime",
99+
"grep",
100+
"rg",
101+
"find",
102+
"fd",
103+
"git status",
104+
"git log",
105+
"git diff",
106+
"git show",
107+
"git branch",
108+
"git push",
109+
"git pull",
110+
"git fetch",
111+
"git clone",
112+
"git checkout",
113+
"git add",
114+
"git commit",
115+
"git merge",
116+
"git rebase",
117+
"git cherry-pick",
118+
"cargo check",
119+
"cargo clippy",
120+
"cargo fmt",
121+
"cargo doc",
122+
"terraform plan",
123+
"terraform validate",
124+
"terraform show",
125+
"docker ps",
126+
"docker images",
127+
"docker logs",
128+
"kubectl get",
129+
"kubectl describe",
130+
"kubectl logs",
131+
"tar -tvf",
132+
"tar --list",
133+
"zipinfo",
134+
"unzip -l",
135+
"md5sum",
136+
"sha256sum",
137+
"sha1sum",
138+
"wc",
139+
"sort",
140+
"uniq",
141+
"cut",
142+
"awk",
143+
"sed",
144+
"tr",
145+
"which",
146+
"whereis",
147+
"type",
148+
"env",
149+
"printenv",
102150
"history",
103-
"man", "help", "info",
104-
"clear", "reset",
105-
"true", "false",
151+
"man",
152+
"help",
153+
"info",
154+
"clear",
155+
"reset",
156+
"true",
157+
"false",
106158
"exit",
107159
];
108160

109161
/// Known-dangerous command patterns (substring matches).
110162
const DENY_PATTERNS: &[&str] = &[
111-
"rm -rf /", "rm -rf /*", "rm -rf ~", "rm -rf $HOME",
112-
"mkfs", "mkfs.ext", "mkfs.xfs", "mkfs.btrfs",
113-
"dd if=/dev/zero", "dd if=/dev/random", "dd if=/dev/urandom",
114-
":(){ :|:& };:", "fork bomb",
115-
"> /dev/sda", "> /dev/hda", "> /dev/nvme",
116-
"chmod -R 777 /", "chmod -R 000 /",
163+
"rm -rf /",
164+
"rm -rf /*",
165+
"rm -rf ~",
166+
"rm -rf $HOME",
167+
"mkfs",
168+
"mkfs.ext",
169+
"mkfs.xfs",
170+
"mkfs.btrfs",
171+
"dd if=/dev/zero",
172+
"dd if=/dev/random",
173+
"dd if=/dev/urandom",
174+
":(){ :|:& };:",
175+
"fork bomb",
176+
"> /dev/sda",
177+
"> /dev/hda",
178+
"> /dev/nvme",
179+
"chmod -R 777 /",
180+
"chmod -R 000 /",
117181
"mv / /dev/null",
118-
"rmdir /", "rmdir /*",
182+
"rmdir /",
183+
"rmdir /*",
119184
"truncate -s 0 /",
120185
"shred -n 0 -z /",
121-
"kill -9 -1", "kill -9 1",
122-
"reboot", "shutdown", "poweroff", "halt",
123-
"init 0", "init 6",
186+
"kill -9 -1",
187+
"kill -9 1",
188+
"reboot",
189+
"shutdown",
190+
"poweroff",
191+
"halt",
192+
"init 0",
193+
"init 6",
124194
"systemctl stop",
125-
"echo .* > /etc/passwd", "echo .* > /etc/shadow",
195+
"echo .* > /etc/passwd",
196+
"echo .* > /etc/shadow",
126197
];
127198

128199
/// Evaluate a command and return the appropriate guard decision.
@@ -216,10 +287,7 @@ mod tests {
216287
evaluate_command("mkfs.ext4 /dev/sda1").tier,
217288
ExecutionTier::Deny
218289
);
219-
assert_eq!(
220-
evaluate_command("chmod -R 777 /").tier,
221-
ExecutionTier::Deny
222-
);
290+
assert_eq!(evaluate_command("chmod -R 777 /").tier, ExecutionTier::Deny);
223291
}
224292

225293
#[test]

0 commit comments

Comments
 (0)