Execute a command asynchronously. This function handles both LocalCommand and PromptCommand types. For PromptCommand, it returns the prompt content that should be sent to the LLM. Args: cmd_name: Name of the command to execute args: Arguments for the command
(
cmd_name: str,
args: str,
context: CommandContext,
)
| 1377 | |
| 1378 | |
| 1379 | async def execute_command_async( |
| 1380 | cmd_name: str, |
| 1381 | args: str, |
| 1382 | context: CommandContext, |
| 1383 | ) -> CommandResult: |
| 1384 | """ |
| 1385 | Execute a command asynchronously. |
| 1386 | |
| 1387 | This function handles both LocalCommand and PromptCommand types. |
| 1388 | For PromptCommand, it returns the prompt content that should be sent to the LLM. |
| 1389 | |
| 1390 | Args: |
| 1391 | cmd_name: Name of the command to execute |
| 1392 | args: Arguments for the command |
| 1393 | context: Command context |
| 1394 | |
| 1395 | Returns: |
| 1396 | CommandResult with the execution result |
| 1397 | """ |
| 1398 | from .engine import CommandEngine |
| 1399 | |
| 1400 | registry = get_command_registry() |
| 1401 | cmd = registry.get(cmd_name) |
| 1402 | |
| 1403 | if cmd is None: |
| 1404 | return CommandResult.error(cmd_name, f"Unknown command: {cmd_name}") |
| 1405 | |
| 1406 | if not cmd.is_enabled(): |
| 1407 | return CommandResult.error(cmd_name, f"Command {cmd_name} is disabled") |
| 1408 | |
| 1409 | engine = CommandEngine( |
| 1410 | registry=registry, |
| 1411 | workspace_root=context.workspace_root, |
| 1412 | context=context, |
| 1413 | ) |
| 1414 | |
| 1415 | # Create a fake command input string for the engine |
| 1416 | command_input = f"/{cmd_name}" |
| 1417 | if args: |
| 1418 | command_input += f" {args}" |
| 1419 | |
| 1420 | return await engine.execute(command_input) |