Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions multimodal/tarko/agent-cli/src/core/cli.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/*
* Copyright (c) 2025 Bytedance, Inc. and its affiliates.
* SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -197,22 +198,39 @@ export class AgentCLI {

// Apply agent-specific configurations for commands that run agents
configuredCommand = this.configureAgentCommand(configuredCommand);
configuredCommand.action(
async (agent: string | undefined, cliArguments: AgentCLIArguments = {}) => {
// If agent is provided as positional argument, use it
if (agent) {
cliArguments.agent = agent;
configuredCommand.action(async (...args: any[]) => {
// Handle dynamic arguments due to optional positional parameters [run] [agent]
// CAC passes arguments in this pattern:
// - tarko --agent ./ -> args = [undefined, undefined, cliArguments]
// - tarko run -> args = ['run', undefined, cliArguments]
// - tarko run ./ -> args = ['run', './', cliArguments]
// - tarko ./ -> args = [undefined, './', cliArguments]

// The last argument is always the parsed CLI options object
const cliArguments: AgentCLIArguments = args[args.length - 1] || {};

// The second-to-last argument is the agent parameter
const agent = args[args.length - 2];

// If agent is provided as positional argument, use it
if (agent && typeof agent === 'string') {
// Warn if both positional agent and --agent flag are provided
if (cliArguments.agent && cliArguments.agent !== agent) {
console.warn(
`Warning: Both positional agent '${agent}' and --agent flag '${cliArguments.agent}' provided. Using positional agent '${agent}'.`,
);
}
cliArguments.agent = agent;
}

if (cliArguments.headless) {
// Headless mode - same as old 'run' command
await this.runHeadlessMode(cliArguments);
} else {
// Interactive UI mode - same as old 'start' command
await this.runInteractiveMode(cliArguments);
}
},
);
if (cliArguments.headless) {
// Headless mode - same as old 'run' command
await this.runHeadlessMode(cliArguments);
} else {
// Interactive UI mode - same as old 'start' command
await this.runInteractiveMode(cliArguments);
}
});
}

/**
Expand Down