execute method
Execute the tool with the given input.
Implementation
@override
Future<ToolResult> execute(Map<String, dynamic> input) async {
final parsed = SkillToolInput.fromJson(input);
final trimmed = parsed.skill.trim();
final commandName = trimmed.startsWith('/')
? trimmed.substring(1)
: trimmed;
final command = _registry.findCommand(commandName);
if (command == null) {
return ToolResult.error('Unknown skill: $commandName');
}
// Track skill usage.
_invokedSkills.add(commandName);
// Check if this should run as a forked sub-agent.
if (command.context == 'fork') {
return _executeForkedSkill(command, commandName, parsed.args);
}
// Inline execution — return the skill metadata so the caller can
// inject the skill content into the conversation.
final allowedTools = command.allowedTools ?? [];
return ToolResult.success(
'Launching skill: $commandName',
metadata: SkillToolInlineOutput(
success: true,
commandName: commandName,
allowedTools: allowedTools.isNotEmpty ? allowedTools : null,
model: command.model,
).toJson(),
);
}