MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / execute

Method execute

crates/opencode-tool/src/edit/tool.rs:64–301  ·  view source on GitHub ↗
(
        &self,
        args: serde_json::Value,
        ctx: ToolContext,
    )

Source from the content-addressed store, hash-verified

62 }
63
64 async fn execute(
65 &self,
66 args: serde_json::Value,
67 ctx: ToolContext,
68 ) -> Result<ToolResult, ToolError> {
69 let file_path: String = args["file_path"]
70 .as_str()
71 .ok_or_else(|| ToolError::InvalidArguments("file_path is required".into()))?
72 .to_string();
73
74 let old_string: String = args["old_string"]
75 .as_str()
76 .ok_or_else(|| ToolError::InvalidArguments("old_string is required".into()))?
77 .to_string();
78
79 let new_string: String = args["new_string"]
80 .as_str()
81 .ok_or_else(|| ToolError::InvalidArguments("new_string is required".into()))?
82 .to_string();
83
84 let replace_all = args["replace_all"].as_bool().unwrap_or(false);
85
86 let base_dir = if ctx.directory.is_empty() {
87 &self.directory
88 } else {
89 Path::new(&ctx.directory)
90 };
91
92 let path = if Path::new(&file_path).is_absolute() {
93 PathBuf::from(&file_path)
94 } else {
95 base_dir.join(&file_path)
96 };
97
98 let path_str = path.to_string_lossy().to_string();
99
100 if ctx.is_external_path(&path_str) {
101 let parent = path
102 .parent()
103 .map(|p| p.to_string_lossy().to_string())
104 .unwrap_or_else(|| path_str.clone());
105
106 ctx.ask_permission(
107 crate::PermissionRequest::new("external_directory")
108 .with_pattern(format!("{}/*", parent))
109 .with_metadata("filepath", serde_json::json!(&path_str))
110 .with_metadata("parentDir", serde_json::json!(parent)),
111 )
112 .await?;
113 }
114
115 let title = path
116 .strip_prefix(&ctx.worktree)
117 .unwrap_or(&path)
118 .to_string_lossy()
119 .to_string();
120
121 let ctx_clone = ctx.clone();

Callers

nothing calls this directly

Calls 15

newFunction · 0.85
with_file_lockFunction · 0.85
is_emptyMethod · 0.80
is_external_pathMethod · 0.80
ask_permissionMethod · 0.80
with_metadataMethod · 0.80
with_patternMethod · 0.80
do_file_time_assertMethod · 0.80
always_allowMethod · 0.80
do_publish_busMethod · 0.80
do_lsp_touch_fileMethod · 0.80

Tested by

no test coverage detected