From 7fa9325683d02a20bc80e2dbb1471a7ffac97c29 Mon Sep 17 00:00:00 2001 From: A <258483684+la14-1@users.noreply.github.com> Date: Wed, 11 Feb 2026 09:11:41 -0800 Subject: [PATCH] refactor: deduplicate resolveAgentKey/resolveCloudKey into shared resolveEntityKey (#481) Agent: complexity-hunter Co-authored-by: A <6723574+louisgv@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) --- cli/src/commands.ts | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/cli/src/commands.ts b/cli/src/commands.ts index 28046bdf..84dd2e67 100644 --- a/cli/src/commands.ts +++ b/cli/src/commands.ts @@ -137,37 +137,30 @@ export function findClosestKeyByNameOrKey( } /** - * Resolve user input to a valid agent key. + * Resolve user input to a valid entity key (agent or cloud). * Tries: exact key -> case-insensitive key -> display name match (case-insensitive). * Returns the key if found, or null. */ -export function resolveAgentKey(manifest: Manifest, input: string): string | null { - if (manifest.agents[input]) return input; +function resolveEntityKey(manifest: Manifest, input: string, kind: "agent" | "cloud"): string | null { + const collection = getEntityCollection(manifest, kind); + if (collection[input]) return input; + const keys = getEntityKeys(manifest, kind); const lower = input.toLowerCase(); - for (const key of agentKeys(manifest)) { + for (const key of keys) { if (key.toLowerCase() === lower) return key; } - for (const key of agentKeys(manifest)) { - if (manifest.agents[key].name.toLowerCase() === lower) return key; + for (const key of keys) { + if (collection[key].name.toLowerCase() === lower) return key; } return null; } -/** - * Resolve user input to a valid cloud key. - * Tries: exact key -> case-insensitive key -> display name match (case-insensitive). - * Returns the key if found, or null. - */ +export function resolveAgentKey(manifest: Manifest, input: string): string | null { + return resolveEntityKey(manifest, input, "agent"); +} + export function resolveCloudKey(manifest: Manifest, input: string): string | null { - if (manifest.clouds[input]) return input; - const lower = input.toLowerCase(); - for (const key of cloudKeys(manifest)) { - if (key.toLowerCase() === lower) return key; - } - for (const key of cloudKeys(manifest)) { - if (manifest.clouds[key].name.toLowerCase() === lower) return key; - } - return null; + return resolveEntityKey(manifest, input, "cloud"); } interface EntityDef { label: string; labelPlural: string; listCmd: string; opposite: string }