summaryrefslogtreecommitdiffstats
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tools/mod.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tools/mod.rs b/src/tools/mod.rs
index a8851ab..060dd7b 100644
--- a/src/tools/mod.rs
+++ b/src/tools/mod.rs
@@ -24,6 +24,30 @@ pub fn approval(name: &str) -> Approval {
24 } 24 }
25} 25}
26 26
27/// Rejects a call that cannot possibly run, before a human is asked to approve
28/// it. An empty `cmd` used to mean an approval prompt for `run: `.
29pub fn validate(name: &str, args: &Value) -> Result<(), String> {
30 let text = |key: &str| args.get(key).and_then(|value| value.as_str()).unwrap_or("");
31 let required = |key: &str| {
32 if text(key).trim().is_empty() {
33 Err(format!("`{key}` is required and must not be empty"))
34 } else {
35 Ok(())
36 }
37 };
38
39 match name {
40 "bash" => required("cmd"),
41 "read" | "write" => required("path"),
42 "edit" => {
43 required("path")?;
44 required("old")
45 }
46 "grep" | "glob" => required("pattern"),
47 _ => Ok(()),
48 }
49}
50
27/// Tools that execute immediately. 51/// Tools that execute immediately.
28pub fn run(name: &str, args: &Value, cancel: &std::sync::atomic::AtomicBool) -> Result<String, String> { 52pub fn run(name: &str, args: &Value, cancel: &std::sync::atomic::AtomicBool) -> Result<String, String> {
29 match name { 53 match name {