From 0974f85d7efcf6f318d0ea75726391a2f57ede9d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 6 Apr 2026 14:21:10 +0100 Subject: [PATCH] fix(cli): preserve routed command arg typing --- src/cli/command-path-matches.ts | 8 +++- src/cli/program/routed-command-definitions.ts | 45 ++++++++++--------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/src/cli/command-path-matches.ts b/src/cli/command-path-matches.ts index d0b5e6ef391..45d333ef6ec 100644 --- a/src/cli/command-path-matches.ts +++ b/src/cli/command-path-matches.ts @@ -5,6 +5,12 @@ export type CommandPathMatchRule = exact?: boolean; }; +function isStructuredCommandPathMatchRule( + rule: CommandPathMatchRule, +): rule is Extract { + return !Array.isArray(rule); +} + export function matchesCommandPath( commandPath: string[], pattern: readonly string[], @@ -17,7 +23,7 @@ export function matchesCommandPath( } export function matchesCommandPathRule(commandPath: string[], rule: CommandPathMatchRule): boolean { - if (Array.isArray(rule)) { + if (!isStructuredCommandPathMatchRule(rule)) { return matchesCommandPath(commandPath, rule); } return matchesCommandPath(commandPath, rule.pattern, { exact: rule.exact }); diff --git a/src/cli/program/routed-command-definitions.ts b/src/cli/program/routed-command-definitions.ts index 6442d0f255b..61666179e98 100644 --- a/src/cli/program/routed-command-definitions.ts +++ b/src/cli/program/routed-command-definitions.ts @@ -1,5 +1,4 @@ import { defaultRuntime } from "../../runtime.js"; -import type { CliRoutedCommandId } from "../command-catalog.js"; import { parseAgentsListRouteArgs, parseConfigGetRouteArgs, @@ -17,15 +16,21 @@ export type RoutedCommandDefinition = { runParsedArgs: (args: TArgs) => Promise; }; -export const routedCommandDefinitions: Record = { - health: { +function defineRoutedCommand( + definition: RoutedCommandDefinition, +): RoutedCommandDefinition { + return definition; +} + +export const routedCommandDefinitions = { + health: defineRoutedCommand({ parseArgs: parseHealthRouteArgs, runParsedArgs: async (args) => { const { healthCommand } = await import("../../commands/health.js"); await healthCommand(args, defaultRuntime); }, - }, - status: { + }), + status: defineRoutedCommand({ parseArgs: parseStatusRouteArgs, runParsedArgs: async (args) => { if (args.json) { @@ -44,54 +49,54 @@ export const routedCommandDefinitions: Record { const { runDaemonStatus } = await import("../daemon-cli/status.js"); await runDaemonStatus(args); }, - }, - sessions: { + }), + sessions: defineRoutedCommand({ parseArgs: parseSessionsRouteArgs, runParsedArgs: async (args) => { const { sessionsCommand } = await import("../../commands/sessions.js"); await sessionsCommand(args, defaultRuntime); }, - }, - "agents-list": { + }), + "agents-list": defineRoutedCommand({ parseArgs: parseAgentsListRouteArgs, runParsedArgs: async (args) => { const { agentsListCommand } = await import("../../commands/agents.js"); await agentsListCommand(args, defaultRuntime); }, - }, - "config-get": { + }), + "config-get": defineRoutedCommand({ parseArgs: parseConfigGetRouteArgs, runParsedArgs: async (args) => { const { runConfigGet } = await import("../config-cli.js"); await runConfigGet(args); }, - }, - "config-unset": { + }), + "config-unset": defineRoutedCommand({ parseArgs: parseConfigUnsetRouteArgs, runParsedArgs: async (args) => { const { runConfigUnset } = await import("../config-cli.js"); await runConfigUnset(args); }, - }, - "models-list": { + }), + "models-list": defineRoutedCommand({ parseArgs: parseModelsListRouteArgs, runParsedArgs: async (args) => { const { modelsListCommand } = await import("../../commands/models.js"); await modelsListCommand(args, defaultRuntime); }, - }, - "models-status": { + }), + "models-status": defineRoutedCommand({ parseArgs: parseModelsStatusRouteArgs, runParsedArgs: async (args) => { const { modelsStatusCommand } = await import("../../commands/models.js"); await modelsStatusCommand(args, defaultRuntime); }, - }, + }), };