hematite/tools/
file_edit.rs1use super::tool::{HematiteTool, RiskLevel};
2use serde_json::Value;
3
4#[allow(dead_code)]
5pub struct FileEditTool;
6
7impl HematiteTool for FileEditTool {
8 fn name(&self) -> &'static str {
9 "file_edit"
10 }
11
12 fn description(&self) -> &'static str {
13 "Securely edits specific strings and blocks within a codebase file using precise line-hunk replacements safely bypassing token overload."
14 }
15
16 fn risk_level(&self, _args: &Value) -> RiskLevel {
17 RiskLevel::Moderate }
19
20 fn mutation_label(&self, _args: &Value) -> Option<String> {
21 Some("Surgical Code Mutation".to_string())
22 }
23
24 fn estimate_token_cost(&self, _payload: &Value) -> usize {
25 100 }
27
28 fn security_audit(&self, args: &Value) -> Result<(), String> {
29 let path_str = args.get("path").and_then(|v| v.as_str()).unwrap_or("");
30 let workspace =
31 std::env::current_dir().map_err(|e| format!("Workspace Env Error: {}", e))?;
32 let target = std::path::Path::new(path_str);
33
34 super::guard::path_is_safe(&workspace, target)?;
36
37 Ok(())
38 }
39
40 fn dry_run(&self, payload: Value) -> Result<String, String> {
41 Ok(format!(
42 "Proposed text replacement mapping evaluated smoothly via HUNK logic: {:?}",
43 payload
44 ))
45 }
46
47 fn run(&self, _payload: Value) -> Result<String, String> {
48 Ok("Exact string blocks flawlessly line-replaced in text.".into())
49 }
50}