From 7f9dafab6841a115ff9dd5eceb00514ddf12b00a Mon Sep 17 00:00:00 2001 From: Mohamed Boudra Date: Mon, 23 Mar 2026 10:33:06 +0700 Subject: [PATCH] refactor(cli): deduplicate command options between top-level and agent subcommands Extract addXxxOptions() builder functions for all 9 shared commands (ls, run, attach, logs, stop, delete, send, inspect, wait) so both paseo and paseo agent use a single source of truth. Fixes drift where agent subcommands were missing --wait-timeout (run), --worktree/--base/--image (run), --since (logs), and --image (send). --- packages/cli/src/cli.ts | 118 ++++----------------- packages/cli/src/commands/agent/attach.ts | 6 ++ packages/cli/src/commands/agent/delete.ts | 8 ++ packages/cli/src/commands/agent/index.ts | 111 ++++--------------- packages/cli/src/commands/agent/inspect.ts | 6 ++ packages/cli/src/commands/agent/logs.ts | 12 ++- packages/cli/src/commands/agent/ls.ts | 15 +++ packages/cli/src/commands/agent/run.ts | 45 +++++++- packages/cli/src/commands/agent/send.ts | 14 ++- packages/cli/src/commands/agent/stop.ts | 10 +- packages/cli/src/commands/agent/wait.ts | 9 +- 11 files changed, 156 insertions(+), 198 deletions(-) diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index 9f3611905..b7d617d2a 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -9,22 +9,21 @@ import { createWorktreeCommand } from "./commands/worktree/index.js"; import { startCommand as daemonStartCommand } from "./commands/daemon/start.js"; import { runStatusCommand as runDaemonStatusCommand } from "./commands/daemon/status.js"; import { runRestartCommand as runDaemonRestartCommand } from "./commands/daemon/restart.js"; -import { runLsCommand } from "./commands/agent/ls.js"; -import { runRunCommand } from "./commands/agent/run.js"; -import { runLogsCommand } from "./commands/agent/logs.js"; -import { runDeleteCommand } from "./commands/agent/delete.js"; -import { runStopCommand } from "./commands/agent/stop.js"; -import { runSendCommand } from "./commands/agent/send.js"; -import { runInspectCommand } from "./commands/agent/inspect.js"; -import { runWaitCommand } from "./commands/agent/wait.js"; -import { runAttachCommand } from "./commands/agent/attach.js"; +import { addLsOptions, runLsCommand } from "./commands/agent/ls.js"; +import { addRunOptions, runRunCommand } from "./commands/agent/run.js"; +import { addLogsOptions, runLogsCommand } from "./commands/agent/logs.js"; +import { addDeleteOptions, runDeleteCommand } from "./commands/agent/delete.js"; +import { addStopOptions, runStopCommand } from "./commands/agent/stop.js"; +import { addSendOptions, runSendCommand } from "./commands/agent/send.js"; +import { addInspectOptions, runInspectCommand } from "./commands/agent/inspect.js"; +import { addWaitOptions, runWaitCommand } from "./commands/agent/wait.js"; +import { addAttachOptions, runAttachCommand } from "./commands/agent/attach.js"; import { withOutput } from "./output/index.js"; import { onboardCommand } from "./commands/onboard.js"; import { addDaemonHostOption, addJsonAndDaemonHostOptions, addJsonOption, - collectMultiple, } from "./utils/command-options.js"; const require = createRequire(import.meta.url); @@ -59,120 +58,39 @@ export function createCli(): Command { // Primary agent commands (top-level) addJsonAndDaemonHostOptions( - program - .command("ls") - .description("List agents. By default excludes archived agents.") - .option("-a, --all", "Include archived agents") - .option("-g, --global", "Legacy no-op (kept for compatibility)") - .option( - "--label ", - "Filter by label (can be used multiple times)", - collectMultiple, - [], - ) - .option("--thinking ", "Filter by thinking option ID"), + addLsOptions(program.command("ls")), ).action(withOutput(runLsCommand)); addJsonAndDaemonHostOptions( - program - .command("run") - .description("Create and start an agent with a task") - .argument("", "The task/prompt for the agent") - .option("-d, --detach", "Run in background (detached)") - .option("--name ", "Assign a name/title to the agent") - .option( - "--provider ", - "Agent provider, or provider/model (e.g. codex or codex/gpt-5.4)", - "claude", - ) - .option( - "--model ", - "Model to use (e.g., claude-sonnet-4-20250514, claude-3-5-haiku-20241022)", - ) - .option("--thinking ", "Thinking option ID to use for this run") - .option("--mode ", "Provider-specific mode (e.g., plan, default, bypass)") - .option("--worktree ", "Create agent in a new git worktree") - .option("--base ", "Base branch for worktree (default: current branch)") - .option( - "--image ", - "Attach image(s) to the initial prompt (can be used multiple times)", - collectMultiple, - [], - ) - .option("--cwd ", "Working directory (default: current)") - .option( - "--label ", - "Add label(s) to the agent (can be used multiple times)", - collectMultiple, - [], - ) - .option( - "--output-schema ", - "Output JSON matching the provided schema file path or inline JSON schema", - ), + addRunOptions(program.command("run")), ).action(withOutput(runRunCommand)); addDaemonHostOption( - program - .command("attach") - .description("Attach to a running agent's output stream") - .argument("", "Agent ID (or prefix)"), + addAttachOptions(program.command("attach")), ).action(runAttachCommand); addDaemonHostOption( - program - .command("logs") - .description("View agent activity/timeline") - .argument("", "Agent ID (or prefix)") - .option("-f, --follow", "Follow log output (streaming)") - .option("--tail ", "Show last n entries") - .option("--filter ", "Filter by event type (tools, text, errors, permissions)") - .option("--since