Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/features/subagents.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Subagents are configured using Markdown files with YAML frontmatter. This format
---
name: agent-name
description: Brief description of when and how to use this agent
tools:
tools:
- tool1
- tool2
- tool3 # Optional
Expand Down Expand Up @@ -170,7 +170,7 @@ Perfect for comprehensive test creation and test-driven development.
---
name: testing-expert
description: Writes comprehensive unit tests, integration tests, and handles test automation with best practices
tools:
tools:
- read_file
- write_file
- read_many_files
Expand Down Expand Up @@ -214,7 +214,7 @@ Specialized in creating clear, comprehensive documentation.
---
name: documentation-writer
description: Creates comprehensive documentation, README files, API docs, and user guides
tools:
tools:
- read_file
- write_file
- read_many_files
Expand Down Expand Up @@ -267,7 +267,7 @@ Focused on code quality, security, and best practices.
---
name: code-reviewer
description: Reviews code for best practices, security issues, performance, and maintainability
tools:
tools:
- read_file
- read_many_files
---
Expand Down Expand Up @@ -311,7 +311,7 @@ Optimized for React development, hooks, and component patterns.
---
name: react-specialist
description: Expert in React development, hooks, component patterns, and modern React best practices
tools:
tools:
- read_file
- write_file
- read_many_files
Expand Down
7 changes: 7 additions & 0 deletions docs/support/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ This guide provides solutions to common issues and debugging tips, including top
- **Solution:** Set the `NODE_EXTRA_CA_CERTS` environment variable to the absolute path of your corporate root CA certificate file.
- Example: `export NODE_EXTRA_CA_CERTS=/path/to/your/corporate-ca.crt`

- **Issue: Unable to display UI after authentication failure**
- **Cause:** If authentication fails after selecting an authentication type, the `security.auth.selectedType` setting may be persisted in `settings.json`. On restart, the CLI may get stuck trying to authenticate with the failed auth type and fail to display the UI.
- **Solution:** Clear the `security.auth.selectedType` configuration item in your `settings.json` file:
- Open `~/.qwen/settings.json` (or `./.qwen/settings.json` for project-specific settings)
- Remove the `security.auth.selectedType` field
- Restart the CLI to allow it to prompt for authentication again

## Frequently asked questions (FAQs)

- **Q: How do I update Qwen Code to the latest version?**
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/context-compress-interactive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe('Interactive Mode', () => {
).toBe(true);

await type(ptyProcess, '/compress');
await new Promise((resolve) => setTimeout(resolve, 100));
await new Promise((resolve) => setTimeout(resolve, 1000));
await type(ptyProcess, '\r');

const foundEvent = await rig.waitForTelemetryEvent(
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -839,5 +839,6 @@ export function saveSettings(settingsFile: SettingsFile): void {
);
} catch (error) {
console.error('Error saving user settings file:', error);
throw error;
}
}
16 changes: 14 additions & 2 deletions packages/cli/src/core/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
type AuthType,
type Config,
getErrorMessage,
logAuth,
AuthEvent,
} from '@qwen-code/qwen-code-core';

/**
Expand All @@ -25,11 +27,21 @@ export async function performInitialAuth(
}

try {
await config.refreshAuth(authType);
await config.refreshAuth(authType, true);
// The console.log is intentionally left out here.
// We can add a dedicated startup message later if needed.

// Log authentication success
const authEvent = new AuthEvent(authType, 'auto', 'success');
logAuth(config, authEvent);
} catch (e) {
return `Failed to login. Message: ${getErrorMessage(e)}`;
const errorMessage = `Failed to login. Message: ${getErrorMessage(e)}`;

// Log authentication failure
const authEvent = new AuthEvent(authType, 'auto', 'error', errorMessage);
logAuth(config, authEvent);

return errorMessage;
}

return null;
Expand Down
18 changes: 13 additions & 5 deletions packages/cli/src/core/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
logIdeConnection,
type Config,
} from '@qwen-code/qwen-code-core';
import { type LoadedSettings } from '../config/settings.js';
import { type LoadedSettings, SettingScope } from '../config/settings.js';
import { performInitialAuth } from './auth.js';
import { validateTheme } from './theme.js';

Expand All @@ -33,10 +33,18 @@ export async function initializeApp(
config: Config,
settings: LoadedSettings,
): Promise<InitializationResult> {
const authError = await performInitialAuth(
config,
settings.merged.security?.auth?.selectedType,
);
const authType = settings.merged.security?.auth?.selectedType;
const authError = await performInitialAuth(config, authType);

// Fallback to user select when initial authentication fails
if (authError) {
settings.setValue(
SettingScope.User,
'security.auth.selectedType',
undefined,
);
}

const themeError = validateTheme(settings);

const shouldOpenAuthDialog =
Expand Down
58 changes: 15 additions & 43 deletions packages/cli/src/ui/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
type HistoryItem,
ToolCallStatus,
type HistoryItemWithoutId,
AuthState,
} from './types.js';
import { MessageType, StreamingState } from './types.js';
import {
Expand All @@ -48,7 +47,6 @@ import { useHistory } from './hooks/useHistoryManager.js';
import { useMemoryMonitor } from './hooks/useMemoryMonitor.js';
import { useThemeCommand } from './hooks/useThemeCommand.js';
import { useAuthCommand } from './auth/useAuth.js';
import { useQwenAuth } from './hooks/useQwenAuth.js';
import { useQuotaAndFallback } from './hooks/useQuotaAndFallback.js';
import { useEditorSettings } from './hooks/useEditorSettings.js';
import { useSettingsCommand } from './hooks/useSettingsCommand.js';
Expand Down Expand Up @@ -93,6 +91,7 @@ import { ShellFocusContext } from './contexts/ShellFocusContext.js';
import { useQuitConfirmation } from './hooks/useQuitConfirmation.js';
import { useWelcomeBack } from './hooks/useWelcomeBack.js';
import { useDialogClose } from './hooks/useDialogClose.js';
import { useInitializationAuthError } from './hooks/useInitializationAuthError.js';
import { type VisionSwitchOutcome } from './components/ModelSwitchDialog.js';
import { processVisionSwitchOutcome } from './hooks/useVisionAutoSwitch.js';
import { useSubagentCreateDialog } from './hooks/useSubagentCreateDialog.js';
Expand Down Expand Up @@ -348,20 +347,13 @@ export const AppContainer = (props: AppContainerProps) => {
onAuthError,
isAuthDialogOpen,
isAuthenticating,
pendingAuthType,
qwenAuthState,
handleAuthSelect,
openAuthDialog,
cancelAuthentication,
} = useAuthCommand(settings, config);

// Qwen OAuth authentication state
const {
isQwenAuth,
isQwenAuthenticating,
deviceAuth,
authStatus,
authMessage,
cancelQwenAuth,
} = useQwenAuth(settings, isAuthenticating);

const { proQuotaRequest, handleProQuotaChoice } = useQuotaAndFallback({
config,
historyManager,
Expand All @@ -370,19 +362,7 @@ export const AppContainer = (props: AppContainerProps) => {
setModelSwitchedFromQuotaError,
});

// Handle Qwen OAuth timeout
const handleQwenAuthTimeout = useCallback(() => {
onAuthError('Qwen OAuth authentication timed out. Please try again.');
cancelQwenAuth();
setAuthState(AuthState.Updating);
}, [onAuthError, cancelQwenAuth, setAuthState]);

// Handle Qwen OAuth cancel
const handleQwenAuthCancel = useCallback(() => {
onAuthError('Qwen OAuth authentication cancelled.');
cancelQwenAuth();
setAuthState(AuthState.Updating);
}, [onAuthError, cancelQwenAuth, setAuthState]);
useInitializationAuthError(initializationResult.authError, onAuthError);

// Sync user tier from config when authentication changes
// TODO: Implement getUserTier() method on Config if needed
Expand All @@ -394,6 +374,8 @@ export const AppContainer = (props: AppContainerProps) => {

// Check for enforced auth type mismatch
useEffect(() => {
// Check for initialization error first

if (
settings.merged.security?.auth?.enforcedType &&
settings.merged.security?.auth.selectedType &&
Expand Down Expand Up @@ -952,7 +934,7 @@ export const AppContainer = (props: AppContainerProps) => {
handleApprovalModeSelect,
isAuthDialogOpen,
handleAuthSelect,
selectedAuthType: settings.merged.security?.auth?.selectedType,
pendingAuthType,
isEditorDialogOpen,
exitEditorDialog,
isSettingsDialogOpen,
Expand Down Expand Up @@ -1194,7 +1176,7 @@ export const AppContainer = (props: AppContainerProps) => {
isVisionSwitchDialogOpen ||
isPermissionsDialogOpen ||
isAuthDialogOpen ||
(isAuthenticating && isQwenAuthenticating) ||
isAuthenticating ||
isEditorDialogOpen ||
showIdeRestartPrompt ||
!!proQuotaRequest ||
Expand All @@ -1217,12 +1199,9 @@ export const AppContainer = (props: AppContainerProps) => {
isConfigInitialized,
authError,
isAuthDialogOpen,
pendingAuthType,
// Qwen OAuth state
isQwenAuth,
isQwenAuthenticating,
deviceAuth,
authStatus,
authMessage,
qwenAuthState,
editorError,
isEditorDialogOpen,
corgiMode,
Expand Down Expand Up @@ -1312,12 +1291,9 @@ export const AppContainer = (props: AppContainerProps) => {
isConfigInitialized,
authError,
isAuthDialogOpen,
pendingAuthType,
// Qwen OAuth state
isQwenAuth,
isQwenAuthenticating,
deviceAuth,
authStatus,
authMessage,
qwenAuthState,
editorError,
isEditorDialogOpen,
corgiMode,
Expand Down Expand Up @@ -1411,9 +1387,7 @@ export const AppContainer = (props: AppContainerProps) => {
handleAuthSelect,
setAuthState,
onAuthError,
// Qwen OAuth handlers
handleQwenAuthTimeout,
handleQwenAuthCancel,
cancelAuthentication,
handleEditorSelect,
exitEditorDialog,
closeSettingsDialog,
Expand Down Expand Up @@ -1447,9 +1421,7 @@ export const AppContainer = (props: AppContainerProps) => {
handleAuthSelect,
setAuthState,
onAuthError,
// Qwen OAuth handlers
handleQwenAuthTimeout,
handleQwenAuthCancel,
cancelAuthentication,
handleEditorSelect,
exitEditorDialog,
closeSettingsDialog,
Expand Down
Loading