From 2fb266c01f0a6a5bf10a0fe1662e1f315b732a61 Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Sun, 14 Dec 2025 21:32:45 -0500 Subject: [PATCH] fix(auth): improve default account hint and add reset-default command - Change post-create hint from casual text to warning box - Clearly state that running the command will SWITCH default account - Add `ccs auth reset-default` command to restore original CCS behavior - Add warnBox() UI helper for yellow-bordered warning boxes - Update main help to show default/reset-default commands Closes #106 --- src/auth/auth-commands.ts | 50 ++++++++++++++++++++++++++++++++++-- src/auth/profile-registry.ts | 18 +++++++++++++ src/commands/help-command.ts | 2 ++ src/utils/ui.ts | 13 ++++++++++ 4 files changed, 81 insertions(+), 2 deletions(-) diff --git a/src/auth/auth-commands.ts b/src/auth/auth-commands.ts index 7525ba3e..69882696 100644 --- a/src/auth/auth-commands.ts +++ b/src/auth/auth-commands.ts @@ -30,6 +30,7 @@ import { info, table, infoBox, + warnBox, } from '../utils/ui'; import { getClaudeCliInfo } from '../utils/claude-detector'; import { escapeShellArg } from '../utils/shell-executor'; @@ -98,6 +99,9 @@ class AuthCommands { console.log(` ${color('show ', 'command')} Show profile details`); console.log(` ${color('remove ', 'command')} Remove saved profile`); console.log(` ${color('default ', 'command')} Set default profile`); + console.log( + ` ${color('reset-default', 'command')} Clear default (restore original CCS)` + ); console.log(''); console.log(subheader('Examples')); console.log(` ${dim('# Create & login to work profile')}`); @@ -106,6 +110,9 @@ class AuthCommands { console.log(` ${dim('# Set work as default')}`); console.log(` ${color('ccs auth default work', 'command')}`); console.log(''); + console.log(` ${dim('# Restore original CCS behavior')}`); + console.log(` ${color('ccs auth reset-default', 'command')}`); + console.log(''); console.log(` ${dim('# List all profiles')}`); console.log(` ${color('ccs auth list', 'command')}`); console.log(''); @@ -252,8 +259,17 @@ class AuthCommands { console.log(header('Usage')); console.log(` ${color(`ccs ${profileName} "your prompt here"`, 'command')}`); console.log(''); - console.log('To set as default (so you can use just "ccs"):'); - console.log(` ${color(`ccs auth default ${profileName}`, 'command')}`); + console.log( + warnBox( + `Running the command below will SWITCH your default\n` + + `CCS account to "${profileName}". After this, running\n` + + `"ccs" without a profile name will use this account.\n\n` + + ` ${color(`ccs auth default ${profileName}`, 'command')}\n\n` + + `To restore the original default, run:\n` + + ` ${color('ccs auth reset-default', 'command')}`, + 'Set as Default?' + ) + ); console.log(''); process.exit(0); } else { @@ -611,6 +627,32 @@ class AuthCommands { } } + /** + * Reset default profile (clear the custom default, restore original CCS behavior) + */ + async handleResetDefault(): Promise { + await initUI(); + + try { + // Use unified or legacy based on config mode + if (this.isUnifiedMode()) { + this.registry.clearDefaultUnified(); + } else { + this.registry.clearDefaultProfile(); + } + + console.log(ok('Default profile cleared')); + console.log(''); + console.log('CCS will now use the original behavior:'); + console.log(` ${dim('# Uses your primary Claude account')}`); + console.log(` ${color('ccs "your prompt"', 'command')}`); + console.log(''); + } catch (error) { + console.log(fail((error as Error).message)); + process.exit(1); + } + } + /** * Route auth command to appropriate handler */ @@ -653,6 +695,10 @@ class AuthCommands { await this.handleDefault(commandArgs); break; + case 'reset-default': + await this.handleResetDefault(); + break; + case 'current': await initUI(); console.log(warn('Command "current" has been removed')); diff --git a/src/auth/profile-registry.ts b/src/auth/profile-registry.ts index 6d05ce2a..e3571d8e 100644 --- a/src/auth/profile-registry.ts +++ b/src/auth/profile-registry.ts @@ -217,6 +217,15 @@ export class ProfileRegistry { this._write(data); } + /** + * Clear default profile (restore original CCS behavior) + */ + clearDefaultProfile(): void { + const data = this._read(); + data.default = null; + this._write(data); + } + /** * Check if profile exists */ @@ -284,6 +293,15 @@ export class ProfileRegistry { saveUnifiedConfig(config); } + /** + * Clear default profile in unified config (restore original CCS behavior) + */ + clearDefaultUnified(): void { + const config = loadOrCreateUnifiedConfig(); + config.default = undefined; + saveUnifiedConfig(config); + } + /** * Check if account exists in unified config */ diff --git a/src/commands/help-command.ts b/src/commands/help-command.ts index ff724df0..350e7d9b 100644 --- a/src/commands/help-command.ts +++ b/src/commands/help-command.ts @@ -141,6 +141,8 @@ Claude Code Profile & Model Switcher`.trim(); ['ccs auth --help', 'Show account management commands'], ['ccs auth create ', 'Create new account profile'], ['ccs auth list', 'List all account profiles'], + ['ccs auth default ', 'Set default profile'], + ['ccs auth reset-default', 'Restore original CCS default'], ] ); diff --git a/src/utils/ui.ts b/src/utils/ui.ts index 0ad23222..80ccc59e 100644 --- a/src/utils/ui.ts +++ b/src/utils/ui.ts @@ -301,6 +301,18 @@ export function infoBox(content: string, title?: string): string { }); } +/** + * Render warning box (yellow border) + */ +export function warnBox(content: string, title = 'WARNING'): string { + return box(content, { + title, + borderColor: 'yellow', + borderStyle: 'round', + padding: 1, + }); +} + // ============================================================================= // TABLE RENDERING // ============================================================================= @@ -613,6 +625,7 @@ export const ui = { box, errorBox, infoBox, + warnBox, table, // Progress