Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src-rust/crates/tools/src/apply_patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ impl Tool for ApplyPatchTool {
let path = ctx.resolve_path(&fp.path);
debug!(path = %path.display(), "ApplyPatch processing file");

if let Err(e) = ctx.check_hosted_repair_path(self.name(), &path) {
return ToolResult::error(e.to_string());
}

// Read current content (or empty string for new files).
let original_content = if path.exists() {
match tokio::fs::read_to_string(&path).await {
Expand Down
5 changes: 5 additions & 0 deletions src-rust/crates/tools/src/batch_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ impl Tool for BatchEditTool {
let path = ctx.resolve_path(&edit.file_path);
debug!(path = %path.display(), index = i, "BatchEdit pre-check");

if let Err(e) = ctx.check_hosted_repair_path(self.name(), &path) {
pre_check_errors.push(format!("Edit {}: {}", i, e));
continue;
}

let content = match tokio::fs::read_to_string(&path).await {
Ok(c) => c,
Err(e) => {
Expand Down
4 changes: 4 additions & 0 deletions src-rust/crates/tools/src/file_edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ impl Tool for FileEditTool {
let path = ctx.resolve_path(&params.file_path);
debug!(path = %path.display(), "Editing file");

if let Err(e) = ctx.check_hosted_repair_path(self.name(), &path) {
return ToolResult::error(e.to_string());
}

// Permission check
if let Err(e) =
ctx.check_permission(self.name(), &format!("Edit {}", path.display()), false)
Expand Down
4 changes: 4 additions & 0 deletions src-rust/crates/tools/src/file_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ impl Tool for FileReadTool {
let path = ctx.resolve_path(&params.file_path);
debug!(path = %path.display(), "Reading file");

if let Err(e) = ctx.check_hosted_repair_path(self.name(), &path) {
return ToolResult::error(e.to_string());
}

// Permission check
if let Err(e) = ctx.check_permission_for_path(
self.name(),
Expand Down
4 changes: 4 additions & 0 deletions src-rust/crates/tools/src/file_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ impl Tool for FileWriteTool {
let path = ctx.resolve_path(&params.file_path);
debug!(path = %path.display(), "Writing file");

if let Err(e) = ctx.check_hosted_repair_path(self.name(), &path) {
return ToolResult::error(e.to_string());
}

// Permission check
if let Err(e) =
ctx.check_permission(self.name(), &format!("Write {}", path.display()), false)
Expand Down
6 changes: 6 additions & 0 deletions src-rust/crates/tools/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ use crate::ToolContext;
/// Try to format a file using any configured formatter.
/// Returns silently if no formatter is configured or the formatter fails.
pub async fn try_format_file(path: &str, ctx: &ToolContext) {
// Hosted repair promises a file-only surface under BypassPermissions.
// Formatters are executable commands and may come from repository config.
if ctx.config.hosted_review_enabled() && ctx.config.hosted_review.allow_file_write_tools {
return;
}

let formatters = &ctx.config.formatter;
if formatters.is_empty() {
return;
Expand Down
7 changes: 7 additions & 0 deletions src-rust/crates/tools/src/glob_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ impl Tool for GlobTool {
.map(|p| ctx.resolve_path(p))
.unwrap_or_else(|| ctx.working_dir.clone());

if let Err(e) = ctx.check_hosted_repair_path(self.name(), &base_dir) {
return ToolResult::error(e.to_string());
}

if let Err(e) = ctx.check_permission_for_path(
self.name(),
&format!("Glob {} in {}", params.pattern, base_dir.display()),
Expand All @@ -88,6 +92,9 @@ impl Tool for GlobTool {
Ok(paths) => {
let mut out = Vec::new();
for path in paths.filter_map(|p| p.ok()) {
if let Err(e) = ctx.check_hosted_repair_path(self.name(), &path) {
return ToolResult::error(e.to_string());
}
if !ctx.path_is_within_workspace(&path) {
if let Err(e) = ctx.check_permission_for_path(
self.name(),
Expand Down
8 changes: 8 additions & 0 deletions src-rust/crates/tools/src/grep_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ impl Tool for GrepTool {
.map(|p| ctx.resolve_path(p))
.unwrap_or_else(|| ctx.working_dir.clone());

if let Err(e) = ctx.check_hosted_repair_path(self.name(), &search_path) {
return ToolResult::error(e.to_string());
}

if let Err(e) = ctx.check_permission_for_path(
self.name(),
&format!("Grep {} in {}", params.pattern, search_path.display()),
Expand Down Expand Up @@ -219,6 +223,10 @@ impl Tool for GrepTool {

let path = entry.path();

if let Err(e) = ctx.check_hosted_repair_path(self.name(), path) {
return ToolResult::error(e.to_string());
}

if !ctx.path_is_within_workspace(path) {
if let Err(e) = ctx.check_permission_for_path(
self.name(),
Expand Down
Loading