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

Method execute

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

Source from the content-addressed store, hash-verified

252 }
253
254 async fn execute(
255 &self,
256 args: serde_json::Value,
257 ctx: ToolContext,
258 ) -> Result<ToolResult, ToolError> {
259 let input: SkillInput =
260 serde_json::from_value(args).map_err(|e| ToolError::InvalidArguments(e.to_string()))?;
261
262 let skills = discover_skills(Path::new(&ctx.directory));
263
264 let skill = skills
265 .iter()
266 .find(|s| s.name == input.skill_name)
267 .ok_or_else(|| {
268 ToolError::InvalidArguments(format!(
269 "Unknown skill: {}. Available skills: {}",
270 input.skill_name,
271 skills
272 .iter()
273 .map(|s| &s.name)
274 .cloned()
275 .collect::<Vec<_>>()
276 .join(", ")
277 ))
278 })?;
279
280 ctx.ask_permission(
281 PermissionRequest::new("skill")
282 .with_pattern(&skill.name)
283 .with_always(&skill.name)
284 .with_metadata("description", serde_json::json!(&skill.description)),
285 )
286 .await?;
287
288 let mut output = format!("<skill_content name=\"{}\">\n\n", skill.name);
289 output.push_str(&format!("# Skill: {}\n\n", skill.name));
290 output.push_str(&skill.content);
291 output.push_str("\n\n");
292 output.push_str(&format!(
293 "Base directory for this skill: {}\n",
294 skill
295 .location
296 .parent()
297 .unwrap_or(Path::new(&ctx.directory))
298 .display()
299 ));
300 output.push_str(
301 "Relative paths in this skill (e.g., scripts/, references/) are relative to this base directory.\n",
302 );
303 output.push_str("Note: file list is sampled.\n\n");
304
305 let sampled_files = sample_skill_files(skill, 10);
306 output.push_str("<skill_files>\n");
307 for file in sampled_files {
308 output.push_str(&format!("<file>{}</file>\n", file.display()));
309 }
310 output.push_str("</skill_files>\n");
311

Callers

nothing calls this directly

Calls 8

discover_skillsFunction · 0.85
newFunction · 0.85
sample_skill_filesFunction · 0.85
findMethod · 0.80
ask_permissionMethod · 0.80
with_metadataMethod · 0.80
with_alwaysMethod · 0.80
with_patternMethod · 0.80

Tested by

no test coverage detected