From 3dcf879c9f2ec681f58f3be7a3c13deda666b511 Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Fri, 3 Apr 2026 00:52:43 -0400 Subject: [PATCH] refactor(cli): slim cursor completion imports - extract cursor subcommand constants into a lightweight module - remove redundant copilot token concatenation from the command catalog --- src/ccs.ts | 5 ++--- src/commands/command-catalog.ts | 6 ++---- src/commands/cursor-command.ts | 20 -------------------- src/cursor/constants.ts | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 27 deletions(-) create mode 100644 src/cursor/constants.ts diff --git a/src/ccs.ts b/src/ccs.ts index 64bfddd6..bdd8487e 100644 --- a/src/ccs.ts +++ b/src/ccs.ts @@ -55,6 +55,7 @@ import { resolveOfficialChannelsLaunchPlan, } from './channels/official-channels-runtime'; import { getOfficialChannelReadiness } from './channels/official-channels-store'; +import { isCursorSubcommandToken } from './cursor/constants'; // Import centralized error handling import { handleError, runCleanup } from './errors'; @@ -467,9 +468,7 @@ async function main(): Promise { // Special case: cursor command (Cursor local proxy integration) // Route known admin subcommands to the command handler, keep all other args as profile passthrough. if (firstArg === 'cursor' && args.length > 1) { - const { isCursorSubcommandToken, handleCursorCommand } = await import( - './commands/cursor-command' - ); + const { handleCursorCommand } = await import('./commands/cursor-command'); const cursorToken = args[1]; if (isCursorSubcommandToken(cursorToken)) { diff --git a/src/commands/command-catalog.ts b/src/commands/command-catalog.ts index a04589e7..1ca8d7f1 100644 --- a/src/commands/command-catalog.ts +++ b/src/commands/command-catalog.ts @@ -1,6 +1,6 @@ import { COPILOT_SUBCOMMANDS } from '../copilot/constants'; +import { CURSOR_SUBCOMMANDS } from '../cursor/constants'; import { CLIPROXY_PROVIDER_IDS } from '../cliproxy/provider-capabilities'; -import { CURSOR_SUBCOMMANDS } from './cursor-command'; export type HelpTopicName = 'profiles' | 'providers' | 'completion' | 'targets'; @@ -310,9 +310,7 @@ export function getPublicRootCommands(): readonly RootCommandEntry[] { export function getAllRootCommandTokens(): string[] { return uniqueStrings( - ROOT_COMMAND_CATALOG.flatMap((entry) => [entry.name, ...(entry.aliases || [])]).concat( - 'copilot' - ) + ROOT_COMMAND_CATALOG.flatMap((entry) => [entry.name, ...(entry.aliases || [])]) ); } diff --git a/src/commands/cursor-command.ts b/src/commands/cursor-command.ts index 4c918f65..6699fba1 100644 --- a/src/commands/cursor-command.ts +++ b/src/commands/cursor-command.ts @@ -20,26 +20,6 @@ import { DEFAULT_CURSOR_CONFIG } from '../config/unified-config-types'; import { renderCursorHelp, renderCursorModels, renderCursorStatus } from './cursor-command-display'; import { ok, fail, info } from '../utils/ui'; -/** Valid cursor subcommands — imported by ccs.ts for routing */ -export const CURSOR_SUBCOMMANDS = [ - 'auth', - 'status', - 'models', - 'start', - 'stop', - 'enable', - 'disable', - 'help', - '--help', - '-h', -] as const; - -export function isCursorSubcommandToken(token?: string): boolean { - return ( - Boolean(token) && CURSOR_SUBCOMMANDS.includes(token as (typeof CURSOR_SUBCOMMANDS)[number]) - ); -} - /** * Handle cursor subcommand. */ diff --git a/src/cursor/constants.ts b/src/cursor/constants.ts new file mode 100644 index 00000000..8a971469 --- /dev/null +++ b/src/cursor/constants.ts @@ -0,0 +1,18 @@ +export const CURSOR_SUBCOMMANDS = [ + 'auth', + 'status', + 'models', + 'start', + 'stop', + 'enable', + 'disable', + 'help', + '--help', + '-h', +] as const; + +export function isCursorSubcommandToken(token?: string): boolean { + return ( + Boolean(token) && CURSOR_SUBCOMMANDS.includes(token as (typeof CURSOR_SUBCOMMANDS)[number]) + ); +}