File size: 1,705 Bytes
52efc7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | /**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type {
OpenDialogActionReturn,
SlashCommand,
LogoutActionReturn,
} from './types.js';
import { CommandKind } from './types.js';
import { clearCachedCredentialFile } from '@google/gemini-cli-core';
import { SettingScope } from '../../config/settings.js';
const authLoginCommand: SlashCommand = {
name: 'signin',
altNames: ['login'],
description: 'Sign in or change the authentication method',
kind: CommandKind.BUILT_IN,
autoExecute: true,
action: (_context, _args): OpenDialogActionReturn => ({
type: 'dialog',
dialog: 'auth',
}),
};
const authLogoutCommand: SlashCommand = {
name: 'signout',
altNames: ['logout'],
description: 'Sign out and clear all cached credentials',
kind: CommandKind.BUILT_IN,
action: async (context, _args): Promise<LogoutActionReturn> => {
await clearCachedCredentialFile();
// Clear the selected auth type so user sees the auth selection menu
context.services.settings.setValue(
SettingScope.User,
'security.auth.selectedType',
undefined,
);
// Strip thoughts from history instead of clearing completely
context.services.agentContext?.geminiClient.stripThoughtsFromHistory();
// Return logout action to signal explicit state change
return {
type: 'logout',
};
},
};
export const authCommand: SlashCommand = {
name: 'auth',
description: 'Manage authentication',
kind: CommandKind.BUILT_IN,
subCommands: [authLoginCommand, authLogoutCommand],
action: (context, args) =>
// Default to login if no subcommand is provided
authLoginCommand.action!(context, args),
};
|