From e803aa488c3a95193d3e3ae358b640c299f8f121 Mon Sep 17 00:00:00 2001 From: salmonik Date: Mon, 23 Nov 2026 20:36:22 +0100 Subject: License --- src/tools/fs.rs | 38 +++++++++++++++++++++++++++++++------- src/tools/mod.rs | 7 +++++++ src/tools/shell.rs | 23 +++++++++++++---------- 3 files changed, 51 insertions(+), 17 deletions(-) (limited to 'src/tools') diff --git a/src/tools/fs.rs b/src/tools/fs.rs index ac0a475..0075590 100644 --- a/src/tools/fs.rs +++ b/src/tools/fs.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use std::fs; use std::io::{BufRead, BufReader}; use std::path::{Path, PathBuf}; @@ -30,8 +37,15 @@ const SKIP_DIRS: &[&str] = &[ /// human agrees. The file is re-read at apply time, so an edit made while the /// approval prompt was open is not silently discarded. pub enum Change { - Write { path: String, content: String }, - Edit { path: String, old: String, new: String }, + Write { + path: String, + content: String, + }, + Edit { + path: String, + old: String, + new: String, + }, } impl Change { @@ -157,9 +171,11 @@ fn locate(text: &str, old: &str) -> Result { } } - Err("text to replace was not found. Read the file and copy the exact text, \ + Err( + "text to replace was not found. Read the file and copy the exact text, \ including indentation." - .to_string()) + .to_string(), + ) } /// Byte offset in the original text for an offset in the CRLF-normalised text. @@ -262,7 +278,11 @@ pub fn plan_edit(args: &Value) -> Result { pub fn read(args: &Value) -> Result { let path = req(args, "path")?; - let offset = args.get("offset").and_then(|v| v.as_u64()).unwrap_or(1).max(1); + let offset = args + .get("offset") + .and_then(|v| v.as_u64()) + .unwrap_or(1) + .max(1); let offset = usize::try_from(offset) .map_err(|_| format!("offset {offset} is too large for this build"))?; let limit = args @@ -622,7 +642,8 @@ fn walk(dir: &Path, out: &mut Vec) { walk(&path, out); } else if file_type.is_file() { out.push(path); - } else if file_type.is_symlink() && fs::metadata(&path).map(|m| m.is_file()).unwrap_or(false) + } else if file_type.is_symlink() + && fs::metadata(&path).map(|m| m.is_file()).unwrap_or(false) { // Follow file symlinks; symlinked directories are skipped so a loop // cannot walk forever. @@ -679,7 +700,10 @@ fn new_file_preview(path: &str, content: &str) -> String { out.push_str(&format!("+ {}\n", clip(line, 200))); } if lines.len() > PREVIEW_BUDGET { - out.push_str(&format!("… {} more line(s)\n", lines.len() - PREVIEW_BUDGET)); + out.push_str(&format!( + "… {} more line(s)\n", + lines.len() - PREVIEW_BUDGET + )); } out } diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 5d6189f..43176c3 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + pub mod fs; pub mod shell; diff --git a/src/tools/shell.rs b/src/tools/shell.rs index c64bab3..7f909bc 100644 --- a/src/tools/shell.rs +++ b/src/tools/shell.rs @@ -1,3 +1,10 @@ +/* + * This file is part of agent686 + * Copyright (C) 2026 Salmonik + * SPDX-License-Identifier: GPL-3.0-or-later + * https://git.2137697.xyz/agent686 + */ + use std::fs::File; use std::io::{Read, Seek, SeekFrom}; use std::os::unix::process::{CommandExt, ExitStatusExt}; @@ -32,11 +39,7 @@ impl Drop for TempGuard { } } -pub fn bash( - args: &Value, - timeout: Duration, - cancel: &AtomicBool, -) -> Result { +pub fn bash(args: &Value, timeout: Duration, cancel: &AtomicBool) -> Result { let cmd = match args .get("cmd") .or_else(|| args.get("command")) @@ -146,14 +149,14 @@ pub fn bash( } else if aborted { "[aborted by the user]".to_string() } else if timed_out { - format!("[timed out after {:.1}s; process killed]", timeout.as_secs_f64()) + format!( + "[timed out after {:.1}s; process killed]", + timeout.as_secs_f64() + ) } else { match status.code() { Some(code) => format!("[exit {code}]"), - None => format!( - "[killed by signal {}]", - status.signal().unwrap_or_default() - ), + None => format!("[killed by signal {}]", status.signal().unwrap_or_default()), } }; -- cgit v1.2.3