|
| 1 | +/* eslint-disable @typescript-eslint/no-explicit-any */ |
1 | 2 | /* |
2 | 3 | * Copyright (c) 2025 Bytedance, Inc. and its affiliates. |
3 | 4 | * SPDX-License-Identifier: Apache-2.0 |
@@ -197,22 +198,39 @@ export class AgentCLI { |
197 | 198 |
|
198 | 199 | // Apply agent-specific configurations for commands that run agents |
199 | 200 | configuredCommand = this.configureAgentCommand(configuredCommand); |
200 | | - configuredCommand.action( |
201 | | - async (agent: string | undefined, cliArguments: AgentCLIArguments = {}) => { |
202 | | - // If agent is provided as positional argument, use it |
203 | | - if (agent) { |
204 | | - cliArguments.agent = agent; |
| 201 | + configuredCommand.action(async (...args: any[]) => { |
| 202 | + // Handle dynamic arguments due to optional positional parameters [run] [agent] |
| 203 | + // CAC passes arguments in this pattern: |
| 204 | + // - tarko --agent ./ -> args = [undefined, undefined, cliArguments] |
| 205 | + // - tarko run -> args = ['run', undefined, cliArguments] |
| 206 | + // - tarko run ./ -> args = ['run', './', cliArguments] |
| 207 | + // - tarko ./ -> args = [undefined, './', cliArguments] |
| 208 | + |
| 209 | + // The last argument is always the parsed CLI options object |
| 210 | + const cliArguments: AgentCLIArguments = args[args.length - 1] || {}; |
| 211 | + |
| 212 | + // The second-to-last argument is the agent parameter |
| 213 | + const agent = args[args.length - 2]; |
| 214 | + |
| 215 | + // If agent is provided as positional argument, use it |
| 216 | + if (agent && typeof agent === 'string') { |
| 217 | + // Warn if both positional agent and --agent flag are provided |
| 218 | + if (cliArguments.agent && cliArguments.agent !== agent) { |
| 219 | + console.warn( |
| 220 | + `Warning: Both positional agent '${agent}' and --agent flag '${cliArguments.agent}' provided. Using positional agent '${agent}'.`, |
| 221 | + ); |
205 | 222 | } |
| 223 | + cliArguments.agent = agent; |
| 224 | + } |
206 | 225 |
|
207 | | - if (cliArguments.headless) { |
208 | | - // Headless mode - same as old 'run' command |
209 | | - await this.runHeadlessMode(cliArguments); |
210 | | - } else { |
211 | | - // Interactive UI mode - same as old 'start' command |
212 | | - await this.runInteractiveMode(cliArguments); |
213 | | - } |
214 | | - }, |
215 | | - ); |
| 226 | + if (cliArguments.headless) { |
| 227 | + // Headless mode - same as old 'run' command |
| 228 | + await this.runHeadlessMode(cliArguments); |
| 229 | + } else { |
| 230 | + // Interactive UI mode - same as old 'start' command |
| 231 | + await this.runInteractiveMode(cliArguments); |
| 232 | + } |
| 233 | + }); |
216 | 234 | } |
217 | 235 |
|
218 | 236 | /** |
|
0 commit comments