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 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'src/tools/fs.rs') 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 } -- cgit v1.2.3