Skip to content

Commit 2acb378

Browse files
authored
fix(tarko): handle CLI parameter order for agent argument (bytedance#1169)
Fix CLI parameter handling issue where `tarko --agent ./` command failed due to incorrect parameter order processing in the run command action handler after PR bytedance#1158. Solution: - Simplified parameter handling based on CAC's actual argument passing pattern - Added user-friendly warnings for conflicting agent parameters - Maintained backward compatibility for all syntax variations Supported syntax: - `tarko --agent ./` (legacy syntax) - `tarko run ./` (new syntax) - `tarko ./` (simplified syntax)
1 parent 69f8505 commit 2acb378

1 file changed

Lines changed: 32 additions & 14 deletions

File tree

  • multimodal/tarko/agent-cli/src/core

multimodal/tarko/agent-cli/src/core/cli.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
/*
23
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
34
* SPDX-License-Identifier: Apache-2.0
@@ -197,22 +198,39 @@ export class AgentCLI {
197198

198199
// Apply agent-specific configurations for commands that run agents
199200
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+
);
205222
}
223+
cliArguments.agent = agent;
224+
}
206225

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+
});
216234
}
217235

218236
/**

0 commit comments

Comments
 (0)