diff --git a/packages/cli/src/commands/agent/mode.ts b/packages/cli/src/commands/agent/mode.ts index d567e903f..79fdc4f69 100644 --- a/packages/cli/src/commands/agent/mode.ts +++ b/packages/cli/src/commands/agent/mode.ts @@ -37,6 +37,12 @@ export interface AgentModeOptions extends CommandOptions { list?: boolean } +const missingModeError = (): CommandError => ({ + code: 'MISSING_ARGUMENT', + message: 'Mode argument required unless --list is specified', + details: 'Usage: paseo agent mode | paseo agent mode --list ', +}) + // This command returns two different data shapes (set result vs mode list). // Keep `any` here to match the existing output wrapper generic contract. // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -53,12 +59,7 @@ export async function runModeCommand( // Validate arguments if (!options.list && !normalizedMode) { - const error: CommandError = { - code: 'MISSING_ARGUMENT', - message: 'Mode argument required unless --list is specified', - details: 'Usage: paseo agent mode | paseo agent mode --list ', - } - throw error + throw missingModeError() } let client: Awaited> | undefined @@ -90,27 +91,22 @@ export async function runModeCommand( data: items, schema: modeListSchema, } - } else { - if (!normalizedMode) { - const error: CommandError = { - code: 'MISSING_ARGUMENT', - message: 'Mode argument required unless --list is specified', - details: 'Usage: paseo agent mode | paseo agent mode --list ', - } - throw error - } + } - // Set the agent mode - await client.setAgentMode(resolvedId, normalizedMode) + if (!normalizedMode) { + throw missingModeError() + } - return { - type: 'single', - data: { - agentId: resolvedId.slice(0, 7), - mode: normalizedMode, - }, - schema: setModeSchema, - } + // Set the agent mode + await client.setAgentMode(resolvedId, normalizedMode) + + return { + type: 'single', + data: { + agentId: resolvedId.slice(0, 7), + mode: normalizedMode, + }, + schema: setModeSchema, } } catch (err) { // Re-throw if it's already a CommandError diff --git a/packages/cli/tests/10-agent-mode.test.ts b/packages/cli/tests/10-agent-mode.test.ts index 32f4993f4..4e50c625b 100644 --- a/packages/cli/tests/10-agent-mode.test.ts +++ b/packages/cli/tests/10-agent-mode.test.ts @@ -125,12 +125,10 @@ try { // Should fail because mode is required unless --list is specified assert.notStrictEqual(result.exitCode, 0, 'should fail without mode argument') const output = result.stdout + result.stderr - const hasError = - output.toLowerCase().includes('missing') || - output.toLowerCase().includes('required') || - output.toLowerCase().includes('mode') || - output.toLowerCase().includes('daemon') // If daemon error comes first, that's also valid - assert(hasError, 'error should mention missing mode or connection issue') + assert( + output.includes('Mode argument required unless --list is specified'), + 'error should mention missing mode argument' + ) console.log('✓ agent mode requires mode argument when not using --list\n') } } finally {