ADAPT-Chase commited on
Commit
ef4873d
·
verified ·
1 Parent(s): dc006ad

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. projects/ui/qwen-code/packages/cli/src/ui/commands/statsCommand.test.ts +78 -0
  2. projects/ui/qwen-code/packages/cli/src/ui/commands/statsCommand.ts +70 -0
  3. projects/ui/qwen-code/packages/cli/src/ui/commands/terminalSetupCommand.test.ts +85 -0
  4. projects/ui/qwen-code/packages/cli/src/ui/commands/terminalSetupCommand.ts +45 -0
  5. projects/ui/qwen-code/packages/cli/src/ui/commands/themeCommand.test.ts +38 -0
  6. projects/ui/qwen-code/packages/cli/src/ui/commands/themeCommand.ts +17 -0
  7. projects/ui/qwen-code/packages/cli/src/ui/commands/toolsCommand.test.ts +105 -0
  8. projects/ui/qwen-code/packages/cli/src/ui/commands/toolsCommand.ts +71 -0
  9. projects/ui/qwen-code/packages/cli/src/ui/commands/types.ts +196 -0
  10. projects/ui/qwen-code/packages/cli/src/ui/commands/vimCommand.ts +25 -0
  11. projects/ui/qwen-code/packages/cli/src/ui/components/AboutBox.tsx +133 -0
  12. projects/ui/qwen-code/packages/cli/src/ui/components/AsciiArt.ts +33 -0
  13. projects/ui/qwen-code/packages/cli/src/ui/components/AuthDialog.test.tsx +334 -0
  14. projects/ui/qwen-code/packages/cli/src/ui/components/AuthDialog.tsx +182 -0
  15. projects/ui/qwen-code/packages/cli/src/ui/components/AuthInProgress.tsx +62 -0
  16. projects/ui/qwen-code/packages/cli/src/ui/components/AutoAcceptIndicator.tsx +47 -0
  17. projects/ui/qwen-code/packages/cli/src/ui/components/ConsoleSummaryDisplay.tsx +35 -0
  18. projects/ui/qwen-code/packages/cli/src/ui/components/ContextSummaryDisplay.test.tsx +85 -0
  19. projects/ui/qwen-code/packages/cli/src/ui/components/ContextSummaryDisplay.tsx +120 -0
  20. projects/ui/qwen-code/packages/cli/src/ui/components/ContextUsageDisplay.tsx +25 -0
projects/ui/qwen-code/packages/cli/src/ui/commands/statsCommand.test.ts ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { vi, describe, it, expect, beforeEach } from 'vitest';
8
+ import { statsCommand } from './statsCommand.js';
9
+ import { type CommandContext } from './types.js';
10
+ import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
11
+ import { MessageType } from '../types.js';
12
+ import { formatDuration } from '../utils/formatters.js';
13
+
14
+ describe('statsCommand', () => {
15
+ let mockContext: CommandContext;
16
+ const startTime = new Date('2025-07-14T10:00:00.000Z');
17
+ const endTime = new Date('2025-07-14T10:00:30.000Z');
18
+
19
+ beforeEach(() => {
20
+ vi.useFakeTimers();
21
+ vi.setSystemTime(endTime);
22
+
23
+ // 1. Create the mock context with all default values
24
+ mockContext = createMockCommandContext();
25
+
26
+ // 2. Directly set the property on the created mock context
27
+ mockContext.session.stats.sessionStartTime = startTime;
28
+ });
29
+
30
+ it('should display general session stats when run with no subcommand', () => {
31
+ if (!statsCommand.action) throw new Error('Command has no action');
32
+
33
+ statsCommand.action(mockContext, '');
34
+
35
+ const expectedDuration = formatDuration(
36
+ endTime.getTime() - startTime.getTime(),
37
+ );
38
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
39
+ {
40
+ type: MessageType.STATS,
41
+ duration: expectedDuration,
42
+ },
43
+ expect.any(Number),
44
+ );
45
+ });
46
+
47
+ it('should display model stats when using the "model" subcommand', () => {
48
+ const modelSubCommand = statsCommand.subCommands?.find(
49
+ (sc) => sc.name === 'model',
50
+ );
51
+ if (!modelSubCommand?.action) throw new Error('Subcommand has no action');
52
+
53
+ modelSubCommand.action(mockContext, '');
54
+
55
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
56
+ {
57
+ type: MessageType.MODEL_STATS,
58
+ },
59
+ expect.any(Number),
60
+ );
61
+ });
62
+
63
+ it('should display tool stats when using the "tools" subcommand', () => {
64
+ const toolsSubCommand = statsCommand.subCommands?.find(
65
+ (sc) => sc.name === 'tools',
66
+ );
67
+ if (!toolsSubCommand?.action) throw new Error('Subcommand has no action');
68
+
69
+ toolsSubCommand.action(mockContext, '');
70
+
71
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
72
+ {
73
+ type: MessageType.TOOL_STATS,
74
+ },
75
+ expect.any(Number),
76
+ );
77
+ });
78
+ });
projects/ui/qwen-code/packages/cli/src/ui/commands/statsCommand.ts ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { MessageType, HistoryItemStats } from '../types.js';
8
+ import { formatDuration } from '../utils/formatters.js';
9
+ import {
10
+ type CommandContext,
11
+ type SlashCommand,
12
+ CommandKind,
13
+ } from './types.js';
14
+
15
+ export const statsCommand: SlashCommand = {
16
+ name: 'stats',
17
+ altNames: ['usage'],
18
+ description: 'check session stats. Usage: /stats [model|tools]',
19
+ kind: CommandKind.BUILT_IN,
20
+ action: (context: CommandContext) => {
21
+ const now = new Date();
22
+ const { sessionStartTime } = context.session.stats;
23
+ if (!sessionStartTime) {
24
+ context.ui.addItem(
25
+ {
26
+ type: MessageType.ERROR,
27
+ text: 'Session start time is unavailable, cannot calculate stats.',
28
+ },
29
+ Date.now(),
30
+ );
31
+ return;
32
+ }
33
+ const wallDuration = now.getTime() - sessionStartTime.getTime();
34
+
35
+ const statsItem: HistoryItemStats = {
36
+ type: MessageType.STATS,
37
+ duration: formatDuration(wallDuration),
38
+ };
39
+
40
+ context.ui.addItem(statsItem, Date.now());
41
+ },
42
+ subCommands: [
43
+ {
44
+ name: 'model',
45
+ description: 'Show model-specific usage statistics.',
46
+ kind: CommandKind.BUILT_IN,
47
+ action: (context: CommandContext) => {
48
+ context.ui.addItem(
49
+ {
50
+ type: MessageType.MODEL_STATS,
51
+ },
52
+ Date.now(),
53
+ );
54
+ },
55
+ },
56
+ {
57
+ name: 'tools',
58
+ description: 'Show tool-specific usage statistics.',
59
+ kind: CommandKind.BUILT_IN,
60
+ action: (context: CommandContext) => {
61
+ context.ui.addItem(
62
+ {
63
+ type: MessageType.TOOL_STATS,
64
+ },
65
+ Date.now(),
66
+ );
67
+ },
68
+ },
69
+ ],
70
+ };
projects/ui/qwen-code/packages/cli/src/ui/commands/terminalSetupCommand.test.ts ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
8
+ import { terminalSetupCommand } from './terminalSetupCommand.js';
9
+ import * as terminalSetupModule from '../utils/terminalSetup.js';
10
+ import { CommandContext } from './types.js';
11
+
12
+ vi.mock('../utils/terminalSetup.js');
13
+
14
+ describe('terminalSetupCommand', () => {
15
+ beforeEach(() => {
16
+ vi.clearAllMocks();
17
+ });
18
+
19
+ it('should have correct metadata', () => {
20
+ expect(terminalSetupCommand.name).toBe('terminal-setup');
21
+ expect(terminalSetupCommand.description).toContain('multiline input');
22
+ expect(terminalSetupCommand.kind).toBe('built-in');
23
+ });
24
+
25
+ it('should return success message when terminal setup succeeds', async () => {
26
+ vi.spyOn(terminalSetupModule, 'terminalSetup').mockResolvedValue({
27
+ success: true,
28
+ message: 'Terminal configured successfully',
29
+ });
30
+
31
+ const result = await terminalSetupCommand.action({} as CommandContext, '');
32
+
33
+ expect(result).toEqual({
34
+ type: 'message',
35
+ content: 'Terminal configured successfully',
36
+ messageType: 'info',
37
+ });
38
+ });
39
+
40
+ it('should append restart message when terminal setup requires restart', async () => {
41
+ vi.spyOn(terminalSetupModule, 'terminalSetup').mockResolvedValue({
42
+ success: true,
43
+ message: 'Terminal configured successfully',
44
+ requiresRestart: true,
45
+ });
46
+
47
+ const result = await terminalSetupCommand.action({} as CommandContext, '');
48
+
49
+ expect(result).toEqual({
50
+ type: 'message',
51
+ content:
52
+ 'Terminal configured successfully\n\nPlease restart your terminal for the changes to take effect.',
53
+ messageType: 'info',
54
+ });
55
+ });
56
+
57
+ it('should return error message when terminal setup fails', async () => {
58
+ vi.spyOn(terminalSetupModule, 'terminalSetup').mockResolvedValue({
59
+ success: false,
60
+ message: 'Failed to detect terminal',
61
+ });
62
+
63
+ const result = await terminalSetupCommand.action({} as CommandContext, '');
64
+
65
+ expect(result).toEqual({
66
+ type: 'message',
67
+ content: 'Failed to detect terminal',
68
+ messageType: 'error',
69
+ });
70
+ });
71
+
72
+ it('should handle exceptions from terminal setup', async () => {
73
+ vi.spyOn(terminalSetupModule, 'terminalSetup').mockRejectedValue(
74
+ new Error('Unexpected error'),
75
+ );
76
+
77
+ const result = await terminalSetupCommand.action({} as CommandContext, '');
78
+
79
+ expect(result).toEqual({
80
+ type: 'message',
81
+ content: 'Failed to configure terminal: Error: Unexpected error',
82
+ messageType: 'error',
83
+ });
84
+ });
85
+ });
projects/ui/qwen-code/packages/cli/src/ui/commands/terminalSetupCommand.ts ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { MessageActionReturn, SlashCommand, CommandKind } from './types.js';
8
+ import { terminalSetup } from '../utils/terminalSetup.js';
9
+
10
+ /**
11
+ * Command to configure terminal keybindings for multiline input support.
12
+ *
13
+ * This command automatically detects and configures VS Code, Cursor, and Windsurf
14
+ * to support Shift+Enter and Ctrl+Enter for multiline input.
15
+ */
16
+ export const terminalSetupCommand: SlashCommand = {
17
+ name: 'terminal-setup',
18
+ description:
19
+ 'Configure terminal keybindings for multiline input (VS Code, Cursor, Windsurf)',
20
+ kind: CommandKind.BUILT_IN,
21
+
22
+ action: async (): Promise<MessageActionReturn> => {
23
+ try {
24
+ const result = await terminalSetup();
25
+
26
+ let content = result.message;
27
+ if (result.requiresRestart) {
28
+ content +=
29
+ '\n\nPlease restart your terminal for the changes to take effect.';
30
+ }
31
+
32
+ return {
33
+ type: 'message',
34
+ content,
35
+ messageType: result.success ? 'info' : 'error',
36
+ };
37
+ } catch (error) {
38
+ return {
39
+ type: 'message',
40
+ content: `Failed to configure terminal: ${error}`,
41
+ messageType: 'error',
42
+ };
43
+ }
44
+ },
45
+ };
projects/ui/qwen-code/packages/cli/src/ui/commands/themeCommand.test.ts ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { describe, it, expect, beforeEach } from 'vitest';
8
+ import { themeCommand } from './themeCommand.js';
9
+ import { type CommandContext } from './types.js';
10
+ import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
11
+
12
+ describe('themeCommand', () => {
13
+ let mockContext: CommandContext;
14
+
15
+ beforeEach(() => {
16
+ mockContext = createMockCommandContext();
17
+ });
18
+
19
+ it('should return a dialog action to open the theme dialog', () => {
20
+ // Ensure the command has an action to test.
21
+ if (!themeCommand.action) {
22
+ throw new Error('The theme command must have an action.');
23
+ }
24
+
25
+ const result = themeCommand.action(mockContext, '');
26
+
27
+ // Assert that the action returns the correct object to trigger the theme dialog.
28
+ expect(result).toEqual({
29
+ type: 'dialog',
30
+ dialog: 'theme',
31
+ });
32
+ });
33
+
34
+ it('should have the correct name and description', () => {
35
+ expect(themeCommand.name).toBe('theme');
36
+ expect(themeCommand.description).toBe('change the theme');
37
+ });
38
+ });
projects/ui/qwen-code/packages/cli/src/ui/commands/themeCommand.ts ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { CommandKind, OpenDialogActionReturn, SlashCommand } from './types.js';
8
+
9
+ export const themeCommand: SlashCommand = {
10
+ name: 'theme',
11
+ description: 'change the theme',
12
+ kind: CommandKind.BUILT_IN,
13
+ action: (_context, _args): OpenDialogActionReturn => ({
14
+ type: 'dialog',
15
+ dialog: 'theme',
16
+ }),
17
+ };
projects/ui/qwen-code/packages/cli/src/ui/commands/toolsCommand.test.ts ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { describe, it, expect, vi } from 'vitest';
8
+ import { toolsCommand } from './toolsCommand.js';
9
+ import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
10
+ import { MessageType } from '../types.js';
11
+ import { Tool } from '@qwen-code/qwen-code-core';
12
+
13
+ // Mock tools for testing
14
+ const mockTools = [
15
+ {
16
+ name: 'file-reader',
17
+ displayName: 'File Reader',
18
+ description: 'Reads files from the local system.',
19
+ schema: {},
20
+ },
21
+ {
22
+ name: 'code-editor',
23
+ displayName: 'Code Editor',
24
+ description: 'Edits code files.',
25
+ schema: {},
26
+ },
27
+ ] as Tool[];
28
+
29
+ describe('toolsCommand', () => {
30
+ it('should display an error if the tool registry is unavailable', async () => {
31
+ const mockContext = createMockCommandContext({
32
+ services: {
33
+ config: {
34
+ getToolRegistry: () => undefined,
35
+ },
36
+ },
37
+ });
38
+
39
+ if (!toolsCommand.action) throw new Error('Action not defined');
40
+ await toolsCommand.action(mockContext, '');
41
+
42
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
43
+ {
44
+ type: MessageType.ERROR,
45
+ text: 'Could not retrieve tool registry.',
46
+ },
47
+ expect.any(Number),
48
+ );
49
+ });
50
+
51
+ it('should display "No tools available" when none are found', async () => {
52
+ const mockContext = createMockCommandContext({
53
+ services: {
54
+ config: {
55
+ getToolRegistry: () => ({ getAllTools: () => [] as Tool[] }),
56
+ },
57
+ },
58
+ });
59
+
60
+ if (!toolsCommand.action) throw new Error('Action not defined');
61
+ await toolsCommand.action(mockContext, '');
62
+
63
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
64
+ expect.objectContaining({
65
+ text: expect.stringContaining('No tools available'),
66
+ }),
67
+ expect.any(Number),
68
+ );
69
+ });
70
+
71
+ it('should list tools without descriptions by default', async () => {
72
+ const mockContext = createMockCommandContext({
73
+ services: {
74
+ config: {
75
+ getToolRegistry: () => ({ getAllTools: () => mockTools }),
76
+ },
77
+ },
78
+ });
79
+
80
+ if (!toolsCommand.action) throw new Error('Action not defined');
81
+ await toolsCommand.action(mockContext, '');
82
+
83
+ const message = (mockContext.ui.addItem as vi.Mock).mock.calls[0][0].text;
84
+ expect(message).not.toContain('Reads files from the local system.');
85
+ expect(message).toContain('File Reader');
86
+ expect(message).toContain('Code Editor');
87
+ });
88
+
89
+ it('should list tools with descriptions when "desc" arg is passed', async () => {
90
+ const mockContext = createMockCommandContext({
91
+ services: {
92
+ config: {
93
+ getToolRegistry: () => ({ getAllTools: () => mockTools }),
94
+ },
95
+ },
96
+ });
97
+
98
+ if (!toolsCommand.action) throw new Error('Action not defined');
99
+ await toolsCommand.action(mockContext, 'desc');
100
+
101
+ const message = (mockContext.ui.addItem as vi.Mock).mock.calls[0][0].text;
102
+ expect(message).toContain('Reads files from the local system.');
103
+ expect(message).toContain('Edits code files.');
104
+ });
105
+ });
projects/ui/qwen-code/packages/cli/src/ui/commands/toolsCommand.ts ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import {
8
+ type CommandContext,
9
+ type SlashCommand,
10
+ CommandKind,
11
+ } from './types.js';
12
+ import { MessageType } from '../types.js';
13
+
14
+ export const toolsCommand: SlashCommand = {
15
+ name: 'tools',
16
+ description: 'list available Qwen Codetools',
17
+ kind: CommandKind.BUILT_IN,
18
+ action: async (context: CommandContext, args?: string): Promise<void> => {
19
+ const subCommand = args?.trim();
20
+
21
+ // Default to NOT showing descriptions. The user must opt in with an argument.
22
+ let useShowDescriptions = false;
23
+ if (subCommand === 'desc' || subCommand === 'descriptions') {
24
+ useShowDescriptions = true;
25
+ }
26
+
27
+ const toolRegistry = context.services.config?.getToolRegistry();
28
+ if (!toolRegistry) {
29
+ context.ui.addItem(
30
+ {
31
+ type: MessageType.ERROR,
32
+ text: 'Could not retrieve tool registry.',
33
+ },
34
+ Date.now(),
35
+ );
36
+ return;
37
+ }
38
+
39
+ const tools = toolRegistry.getAllTools();
40
+ // Filter out MCP tools by checking for the absence of a serverName property
41
+ const geminiTools = tools.filter((tool) => !('serverName' in tool));
42
+
43
+ let message = 'Available Qwen Code tools:\n\n';
44
+
45
+ if (geminiTools.length > 0) {
46
+ geminiTools.forEach((tool) => {
47
+ if (useShowDescriptions && tool.description) {
48
+ message += ` - \u001b[36m${tool.displayName} (${tool.name})\u001b[0m:\n`;
49
+
50
+ const greenColor = '\u001b[32m';
51
+ const resetColor = '\u001b[0m';
52
+
53
+ // Handle multi-line descriptions
54
+ const descLines = tool.description.trim().split('\n');
55
+ for (const descLine of descLines) {
56
+ message += ` ${greenColor}${descLine}${resetColor}\n`;
57
+ }
58
+ } else {
59
+ message += ` - \u001b[36m${tool.displayName}\u001b[0m\n`;
60
+ }
61
+ });
62
+ } else {
63
+ message += ' No tools available\n';
64
+ }
65
+ message += '\n';
66
+
67
+ message += '\u001b[0m';
68
+
69
+ context.ui.addItem({ type: MessageType.INFO, text: message }, Date.now());
70
+ },
71
+ };
projects/ui/qwen-code/packages/cli/src/ui/commands/types.ts ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { type ReactNode } from 'react';
8
+ import { Content } from '@google/genai';
9
+ import { HistoryItemWithoutId } from '../types.js';
10
+ import { Config, GitService, Logger } from '@qwen-code/qwen-code-core';
11
+ import { LoadedSettings } from '../../config/settings.js';
12
+ import { UseHistoryManagerReturn } from '../hooks/useHistoryManager.js';
13
+ import type { HistoryItem } from '../types.js';
14
+ import { SessionStatsState } from '../contexts/SessionContext.js';
15
+
16
+ // Grouped dependencies for clarity and easier mocking
17
+ export interface CommandContext {
18
+ // Invocation properties for when commands are called.
19
+ invocation?: {
20
+ /** The raw, untrimmed input string from the user. */
21
+ raw: string;
22
+ /** The primary name of the command that was matched. */
23
+ name: string;
24
+ /** The arguments string that follows the command name. */
25
+ args: string;
26
+ };
27
+ // Core services and configuration
28
+ services: {
29
+ // TODO(abhipatel12): Ensure that config is never null.
30
+ config: Config | null;
31
+ settings: LoadedSettings;
32
+ git: GitService | undefined;
33
+ logger: Logger;
34
+ };
35
+ // UI state and history management
36
+ ui: {
37
+ /** Adds a new item to the history display. */
38
+ addItem: UseHistoryManagerReturn['addItem'];
39
+ /** Clears all history items and the console screen. */
40
+ clear: () => void;
41
+ /**
42
+ * Sets the transient debug message displayed in the application footer in debug mode.
43
+ */
44
+ setDebugMessage: (message: string) => void;
45
+ /** The currently pending history item, if any. */
46
+ pendingItem: HistoryItemWithoutId | null;
47
+ /**
48
+ * Sets a pending item in the history, which is useful for indicating
49
+ * that a long-running operation is in progress.
50
+ *
51
+ * @param item The history item to display as pending, or `null` to clear.
52
+ */
53
+ setPendingItem: (item: HistoryItemWithoutId | null) => void;
54
+ /**
55
+ * Loads a new set of history items, replacing the current history.
56
+ *
57
+ * @param history The array of history items to load.
58
+ */
59
+ loadHistory: UseHistoryManagerReturn['loadHistory'];
60
+ /** Toggles a special display mode. */
61
+ toggleCorgiMode: () => void;
62
+ toggleVimEnabled: () => Promise<boolean>;
63
+ setGeminiMdFileCount: (count: number) => void;
64
+ reloadCommands: () => void;
65
+ };
66
+ // Session-specific data
67
+ session: {
68
+ stats: SessionStatsState;
69
+ /** A transient list of shell commands the user has approved for this session. */
70
+ sessionShellAllowlist: Set<string>;
71
+ };
72
+ // Flag to indicate if an overwrite has been confirmed
73
+ overwriteConfirmed?: boolean;
74
+ }
75
+
76
+ /**
77
+ * The return type for a command action that results in scheduling a tool call.
78
+ */
79
+ export interface ToolActionReturn {
80
+ type: 'tool';
81
+ toolName: string;
82
+ toolArgs: Record<string, unknown>;
83
+ }
84
+
85
+ /** The return type for a command action that results in the app quitting. */
86
+ export interface QuitActionReturn {
87
+ type: 'quit';
88
+ messages: HistoryItem[];
89
+ }
90
+
91
+ /**
92
+ * The return type for a command action that results in a simple message
93
+ * being displayed to the user.
94
+ */
95
+ export interface MessageActionReturn {
96
+ type: 'message';
97
+ messageType: 'info' | 'error';
98
+ content: string;
99
+ }
100
+
101
+ /**
102
+ * The return type for a command action that needs to open a dialog.
103
+ */
104
+ export interface OpenDialogActionReturn {
105
+ type: 'dialog';
106
+
107
+ dialog: 'help' | 'auth' | 'theme' | 'editor' | 'privacy' | 'settings';
108
+ }
109
+
110
+ /**
111
+ * The return type for a command action that results in replacing
112
+ * the entire conversation history.
113
+ */
114
+ export interface LoadHistoryActionReturn {
115
+ type: 'load_history';
116
+ history: HistoryItemWithoutId[];
117
+ clientHistory: Content[]; // The history for the generative client
118
+ }
119
+
120
+ /**
121
+ * The return type for a command action that should immediately submit
122
+ * content as a prompt to the Gemini model.
123
+ */
124
+ export interface SubmitPromptActionReturn {
125
+ type: 'submit_prompt';
126
+ content: string;
127
+ }
128
+
129
+ /**
130
+ * The return type for a command action that needs to pause and request
131
+ * confirmation for a set of shell commands before proceeding.
132
+ */
133
+ export interface ConfirmShellCommandsActionReturn {
134
+ type: 'confirm_shell_commands';
135
+ /** The list of shell commands that require user confirmation. */
136
+ commandsToConfirm: string[];
137
+ /** The original invocation context to be re-run after confirmation. */
138
+ originalInvocation: {
139
+ raw: string;
140
+ };
141
+ }
142
+
143
+ export interface ConfirmActionReturn {
144
+ type: 'confirm_action';
145
+ /** The React node to display as the confirmation prompt. */
146
+ prompt: ReactNode;
147
+ /** The original invocation context to be re-run after confirmation. */
148
+ originalInvocation: {
149
+ raw: string;
150
+ };
151
+ }
152
+
153
+ export type SlashCommandActionReturn =
154
+ | ToolActionReturn
155
+ | MessageActionReturn
156
+ | QuitActionReturn
157
+ | OpenDialogActionReturn
158
+ | LoadHistoryActionReturn
159
+ | SubmitPromptActionReturn
160
+ | ConfirmShellCommandsActionReturn
161
+ | ConfirmActionReturn;
162
+
163
+ export enum CommandKind {
164
+ BUILT_IN = 'built-in',
165
+ FILE = 'file',
166
+ MCP_PROMPT = 'mcp-prompt',
167
+ }
168
+
169
+ // The standardized contract for any command in the system.
170
+ export interface SlashCommand {
171
+ name: string;
172
+ altNames?: string[];
173
+ description: string;
174
+
175
+ kind: CommandKind;
176
+
177
+ // Optional metadata for extension commands
178
+ extensionName?: string;
179
+
180
+ // The action to run. Optional for parent commands that only group sub-commands.
181
+ action?: (
182
+ context: CommandContext,
183
+ args: string, // TODO: Remove args. CommandContext now contains the complete invocation.
184
+ ) =>
185
+ | void
186
+ | SlashCommandActionReturn
187
+ | Promise<void | SlashCommandActionReturn>;
188
+
189
+ // Provides argument completion (e.g., completing a tag for `/chat resume <tag>`).
190
+ completion?: (
191
+ context: CommandContext,
192
+ partialArg: string,
193
+ ) => Promise<string[]>;
194
+
195
+ subCommands?: SlashCommand[];
196
+ }
projects/ui/qwen-code/packages/cli/src/ui/commands/vimCommand.ts ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { CommandKind, SlashCommand } from './types.js';
8
+
9
+ export const vimCommand: SlashCommand = {
10
+ name: 'vim',
11
+ description: 'toggle vim mode on/off',
12
+ kind: CommandKind.BUILT_IN,
13
+ action: async (context, _args) => {
14
+ const newVimState = await context.ui.toggleVimEnabled();
15
+
16
+ const message = newVimState
17
+ ? 'Entered Vim mode. Run /vim again to exit.'
18
+ : 'Exited Vim mode.';
19
+ return {
20
+ type: 'message',
21
+ messageType: 'info',
22
+ content: message,
23
+ };
24
+ },
25
+ };
projects/ui/qwen-code/packages/cli/src/ui/components/AboutBox.tsx ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import React from 'react';
8
+ import { Box, Text } from 'ink';
9
+ import { Colors } from '../colors.js';
10
+ import { GIT_COMMIT_INFO } from '../../generated/git-commit.js';
11
+
12
+ interface AboutBoxProps {
13
+ cliVersion: string;
14
+ osVersion: string;
15
+ sandboxEnv: string;
16
+ modelVersion: string;
17
+ selectedAuthType: string;
18
+ gcpProject: string;
19
+ ideClient: string;
20
+ }
21
+
22
+ export const AboutBox: React.FC<AboutBoxProps> = ({
23
+ cliVersion,
24
+ osVersion,
25
+ sandboxEnv,
26
+ modelVersion,
27
+ selectedAuthType,
28
+ gcpProject,
29
+ ideClient,
30
+ }) => (
31
+ <Box
32
+ borderStyle="round"
33
+ borderColor={Colors.Gray}
34
+ flexDirection="column"
35
+ padding={1}
36
+ marginY={1}
37
+ width="100%"
38
+ >
39
+ <Box marginBottom={1}>
40
+ <Text bold color={Colors.AccentPurple}>
41
+ About Qwen Code
42
+ </Text>
43
+ </Box>
44
+ <Box flexDirection="row">
45
+ <Box width="35%">
46
+ <Text bold color={Colors.LightBlue}>
47
+ CLI Version
48
+ </Text>
49
+ </Box>
50
+ <Box>
51
+ <Text>{cliVersion}</Text>
52
+ </Box>
53
+ </Box>
54
+ {GIT_COMMIT_INFO && !['N/A'].includes(GIT_COMMIT_INFO) && (
55
+ <Box flexDirection="row">
56
+ <Box width="35%">
57
+ <Text bold color={Colors.LightBlue}>
58
+ Git Commit
59
+ </Text>
60
+ </Box>
61
+ <Box>
62
+ <Text>{GIT_COMMIT_INFO}</Text>
63
+ </Box>
64
+ </Box>
65
+ )}
66
+ <Box flexDirection="row">
67
+ <Box width="35%">
68
+ <Text bold color={Colors.LightBlue}>
69
+ Model
70
+ </Text>
71
+ </Box>
72
+ <Box>
73
+ <Text>{modelVersion}</Text>
74
+ </Box>
75
+ </Box>
76
+ <Box flexDirection="row">
77
+ <Box width="35%">
78
+ <Text bold color={Colors.LightBlue}>
79
+ Sandbox
80
+ </Text>
81
+ </Box>
82
+ <Box>
83
+ <Text>{sandboxEnv}</Text>
84
+ </Box>
85
+ </Box>
86
+ <Box flexDirection="row">
87
+ <Box width="35%">
88
+ <Text bold color={Colors.LightBlue}>
89
+ OS
90
+ </Text>
91
+ </Box>
92
+ <Box>
93
+ <Text>{osVersion}</Text>
94
+ </Box>
95
+ </Box>
96
+ <Box flexDirection="row">
97
+ <Box width="35%">
98
+ <Text bold color={Colors.LightBlue}>
99
+ Auth Method
100
+ </Text>
101
+ </Box>
102
+ <Box>
103
+ <Text>
104
+ {selectedAuthType.startsWith('oauth') ? 'OAuth' : selectedAuthType}
105
+ </Text>
106
+ </Box>
107
+ </Box>
108
+ {gcpProject && (
109
+ <Box flexDirection="row">
110
+ <Box width="35%">
111
+ <Text bold color={Colors.LightBlue}>
112
+ GCP Project
113
+ </Text>
114
+ </Box>
115
+ <Box>
116
+ <Text>{gcpProject}</Text>
117
+ </Box>
118
+ </Box>
119
+ )}
120
+ {ideClient && (
121
+ <Box flexDirection="row">
122
+ <Box width="35%">
123
+ <Text bold color={Colors.LightBlue}>
124
+ IDE Client
125
+ </Text>
126
+ </Box>
127
+ <Box>
128
+ <Text>{ideClient}</Text>
129
+ </Box>
130
+ </Box>
131
+ )}
132
+ </Box>
133
+ );
projects/ui/qwen-code/packages/cli/src/ui/components/AsciiArt.ts ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ export const shortAsciiLogo = `
8
+ ██████╗ ██╗ ██╗███████╗███╗ ██╗
9
+ ██╔═══██╗██║ ██║██╔════╝████╗ ██║
10
+ ██║ ██║██║ █╗ ██║█████╗ ██╔██╗ ██║
11
+ ██║▄▄ ██║██║███╗██║██╔══╝ ██║╚██╗██║
12
+ ╚██████╔╝╚███╔███╔╝███████╗██║ ╚████║
13
+ ╚══▀▀═╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═══╝
14
+ `;
15
+ export const longAsciiLogo = `
16
+ ██╗ ██████╗ ██╗ ██╗███████╗███╗ ██╗
17
+ ╚██╗ ██╔═══██╗██║ ██║██╔════╝████╗ ██║
18
+ ╚██╗ ██║ ██║██║ █╗ ██║█████╗ ██╔██╗ ██║
19
+ ██╔╝ ██║▄▄ ██║██║███╗██║██╔══╝ ██║╚██╗██║
20
+ ██╔╝ ╚██████╔╝╚███╔███╔╝███████╗██║ ╚████║
21
+ ╚═╝ ╚══▀▀═╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═══╝
22
+ `;
23
+
24
+ export const tinyAsciiLogo = `
25
+ ███ █████████
26
+ ░░░███ ███░░░░░███
27
+ ░░░███ ███ ░░░
28
+ ░░░███░███
29
+ ███░ ░███ █████
30
+ ███░ ░░███ ░░███
31
+ ███░ ░░█████████
32
+ ░░░ ░░░░░░░░░
33
+ `;
projects/ui/qwen-code/packages/cli/src/ui/components/AuthDialog.test.tsx ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
8
+ import { AuthDialog } from './AuthDialog.js';
9
+ import { LoadedSettings, SettingScope } from '../../config/settings.js';
10
+ import { AuthType } from '@qwen-code/qwen-code-core';
11
+ import { renderWithProviders } from '../../test-utils/render.js';
12
+
13
+ describe('AuthDialog', () => {
14
+ const wait = (ms = 50) => new Promise((resolve) => setTimeout(resolve, ms));
15
+
16
+ let originalEnv: NodeJS.ProcessEnv;
17
+
18
+ beforeEach(() => {
19
+ originalEnv = { ...process.env };
20
+ process.env['GEMINI_API_KEY'] = '';
21
+ process.env['GEMINI_DEFAULT_AUTH_TYPE'] = '';
22
+ vi.clearAllMocks();
23
+ });
24
+
25
+ afterEach(() => {
26
+ process.env = originalEnv;
27
+ });
28
+
29
+ it('should show an error if the initial auth type is invalid', () => {
30
+ process.env['GEMINI_API_KEY'] = '';
31
+
32
+ const settings: LoadedSettings = new LoadedSettings(
33
+ {
34
+ settings: { customThemes: {}, mcpServers: {} },
35
+ path: '',
36
+ },
37
+ {
38
+ settings: {
39
+ selectedAuthType: AuthType.USE_GEMINI,
40
+ },
41
+ path: '',
42
+ },
43
+ {
44
+ settings: { customThemes: {}, mcpServers: {} },
45
+ path: '',
46
+ },
47
+ [],
48
+ );
49
+
50
+ const { lastFrame } = renderWithProviders(
51
+ <AuthDialog
52
+ onSelect={() => {}}
53
+ settings={settings}
54
+ initialErrorMessage="GEMINI_API_KEY environment variable not found"
55
+ />,
56
+ );
57
+
58
+ expect(lastFrame()).toContain(
59
+ 'GEMINI_API_KEY environment variable not found',
60
+ );
61
+ });
62
+
63
+ describe('GEMINI_API_KEY environment variable', () => {
64
+ it('should detect GEMINI_API_KEY environment variable', () => {
65
+ process.env['GEMINI_API_KEY'] = 'foobar';
66
+
67
+ const settings: LoadedSettings = new LoadedSettings(
68
+ {
69
+ settings: {
70
+ selectedAuthType: undefined,
71
+ customThemes: {},
72
+ mcpServers: {},
73
+ },
74
+ path: '',
75
+ },
76
+ {
77
+ settings: { customThemes: {}, mcpServers: {} },
78
+ path: '',
79
+ },
80
+ {
81
+ settings: { customThemes: {}, mcpServers: {} },
82
+ path: '',
83
+ },
84
+ [],
85
+ );
86
+
87
+ const { lastFrame } = renderWithProviders(
88
+ <AuthDialog onSelect={() => {}} settings={settings} />,
89
+ );
90
+
91
+ // Since the auth dialog only shows OpenAI option now,
92
+ // it won't show GEMINI_API_KEY messages
93
+ expect(lastFrame()).toContain('OpenAI');
94
+ });
95
+
96
+ it('should not show the GEMINI_API_KEY message if GEMINI_DEFAULT_AUTH_TYPE is set to something else', () => {
97
+ process.env['GEMINI_API_KEY'] = 'foobar';
98
+ process.env['GEMINI_DEFAULT_AUTH_TYPE'] = AuthType.LOGIN_WITH_GOOGLE;
99
+
100
+ const settings: LoadedSettings = new LoadedSettings(
101
+ {
102
+ settings: {
103
+ selectedAuthType: undefined,
104
+ customThemes: {},
105
+ mcpServers: {},
106
+ },
107
+ path: '',
108
+ },
109
+ {
110
+ settings: { customThemes: {}, mcpServers: {} },
111
+ path: '',
112
+ },
113
+ {
114
+ settings: { customThemes: {}, mcpServers: {} },
115
+ path: '',
116
+ },
117
+ [],
118
+ );
119
+
120
+ const { lastFrame } = renderWithProviders(
121
+ <AuthDialog onSelect={() => {}} settings={settings} />,
122
+ );
123
+
124
+ expect(lastFrame()).not.toContain(
125
+ 'Existing API key detected (GEMINI_API_KEY)',
126
+ );
127
+ });
128
+
129
+ it('should show the GEMINI_API_KEY message if GEMINI_DEFAULT_AUTH_TYPE is set to use api key', () => {
130
+ process.env['GEMINI_API_KEY'] = 'foobar';
131
+ process.env['GEMINI_DEFAULT_AUTH_TYPE'] = AuthType.USE_GEMINI;
132
+
133
+ const settings: LoadedSettings = new LoadedSettings(
134
+ {
135
+ settings: {
136
+ selectedAuthType: undefined,
137
+ customThemes: {},
138
+ mcpServers: {},
139
+ },
140
+ path: '',
141
+ },
142
+ {
143
+ settings: { customThemes: {}, mcpServers: {} },
144
+ path: '',
145
+ },
146
+ {
147
+ settings: { customThemes: {}, mcpServers: {} },
148
+ path: '',
149
+ },
150
+ [],
151
+ );
152
+
153
+ const { lastFrame } = renderWithProviders(
154
+ <AuthDialog onSelect={() => {}} settings={settings} />,
155
+ );
156
+
157
+ // Since the auth dialog only shows OpenAI option now,
158
+ // it won't show GEMINI_API_KEY messages
159
+ expect(lastFrame()).toContain('OpenAI');
160
+ });
161
+ });
162
+
163
+ describe('GEMINI_DEFAULT_AUTH_TYPE environment variable', () => {
164
+ it('should select the auth type specified by GEMINI_DEFAULT_AUTH_TYPE', () => {
165
+ process.env['GEMINI_DEFAULT_AUTH_TYPE'] = AuthType.USE_OPENAI;
166
+
167
+ const settings: LoadedSettings = new LoadedSettings(
168
+ {
169
+ settings: {
170
+ selectedAuthType: undefined,
171
+ customThemes: {},
172
+ mcpServers: {},
173
+ },
174
+ path: '',
175
+ },
176
+ {
177
+ settings: { customThemes: {}, mcpServers: {} },
178
+ path: '',
179
+ },
180
+ {
181
+ settings: { customThemes: {}, mcpServers: {} },
182
+ path: '',
183
+ },
184
+ [],
185
+ );
186
+
187
+ const { lastFrame } = renderWithProviders(
188
+ <AuthDialog onSelect={() => {}} settings={settings} />,
189
+ );
190
+
191
+ // This is a bit brittle, but it's the best way to check which item is selected.
192
+ expect(lastFrame()).toContain('● 2. OpenAI');
193
+ });
194
+
195
+ it('should fall back to default if GEMINI_DEFAULT_AUTH_TYPE is not set', () => {
196
+ const settings: LoadedSettings = new LoadedSettings(
197
+ {
198
+ settings: {
199
+ selectedAuthType: undefined,
200
+ customThemes: {},
201
+ mcpServers: {},
202
+ },
203
+ path: '',
204
+ },
205
+ {
206
+ settings: { customThemes: {}, mcpServers: {} },
207
+ path: '',
208
+ },
209
+ {
210
+ settings: { customThemes: {}, mcpServers: {} },
211
+ path: '',
212
+ },
213
+ [],
214
+ );
215
+
216
+ const { lastFrame } = renderWithProviders(
217
+ <AuthDialog onSelect={() => {}} settings={settings} />,
218
+ );
219
+
220
+ // Default is Qwen OAuth (first option)
221
+ expect(lastFrame()).toContain('● 1. Qwen OAuth');
222
+ });
223
+
224
+ it('should show an error and fall back to default if GEMINI_DEFAULT_AUTH_TYPE is invalid', () => {
225
+ process.env['GEMINI_DEFAULT_AUTH_TYPE'] = 'invalid-auth-type';
226
+
227
+ const settings: LoadedSettings = new LoadedSettings(
228
+ {
229
+ settings: {
230
+ selectedAuthType: undefined,
231
+ customThemes: {},
232
+ mcpServers: {},
233
+ },
234
+ path: '',
235
+ },
236
+ {
237
+ settings: { customThemes: {}, mcpServers: {} },
238
+ path: '',
239
+ },
240
+ {
241
+ settings: { customThemes: {}, mcpServers: {} },
242
+ path: '',
243
+ },
244
+ [],
245
+ );
246
+
247
+ const { lastFrame } = renderWithProviders(
248
+ <AuthDialog onSelect={() => {}} settings={settings} />,
249
+ );
250
+
251
+ // Since the auth dialog doesn't show GEMINI_DEFAULT_AUTH_TYPE errors anymore,
252
+ // it will just show the default Qwen OAuth option
253
+ expect(lastFrame()).toContain('● 1. Qwen OAuth');
254
+ });
255
+ });
256
+
257
+ it('should not exit if there is already an error message', async () => {
258
+ const onSelect = vi.fn();
259
+ const settings: LoadedSettings = new LoadedSettings(
260
+ {
261
+ settings: { customThemes: {}, mcpServers: {} },
262
+ path: '',
263
+ },
264
+ {
265
+ settings: {
266
+ selectedAuthType: undefined,
267
+ customThemes: {},
268
+ mcpServers: {},
269
+ },
270
+ path: '',
271
+ },
272
+ {
273
+ settings: { customThemes: {}, mcpServers: {} },
274
+ path: '',
275
+ },
276
+ [],
277
+ );
278
+
279
+ const { lastFrame, stdin, unmount } = renderWithProviders(
280
+ <AuthDialog
281
+ onSelect={onSelect}
282
+ settings={settings}
283
+ initialErrorMessage="Initial error"
284
+ />,
285
+ );
286
+ await wait();
287
+
288
+ expect(lastFrame()).toContain('Initial error');
289
+
290
+ // Simulate pressing escape key
291
+ stdin.write('\u001b'); // ESC key
292
+ await wait();
293
+
294
+ // Should not call onSelect
295
+ expect(onSelect).not.toHaveBeenCalled();
296
+ unmount();
297
+ });
298
+
299
+ it('should allow exiting when auth method is already selected', async () => {
300
+ const onSelect = vi.fn();
301
+ const settings: LoadedSettings = new LoadedSettings(
302
+ {
303
+ settings: { customThemes: {}, mcpServers: {} },
304
+ path: '',
305
+ },
306
+ {
307
+ settings: {
308
+ selectedAuthType: AuthType.USE_GEMINI,
309
+ customThemes: {},
310
+ mcpServers: {},
311
+ },
312
+ path: '',
313
+ },
314
+ {
315
+ settings: { customThemes: {}, mcpServers: {} },
316
+ path: '',
317
+ },
318
+ [],
319
+ );
320
+
321
+ const { stdin, unmount } = renderWithProviders(
322
+ <AuthDialog onSelect={onSelect} settings={settings} />,
323
+ );
324
+ await wait();
325
+
326
+ // Simulate pressing escape key
327
+ stdin.write('\u001b'); // ESC key
328
+ await wait();
329
+
330
+ // Should call onSelect with undefined to exit
331
+ expect(onSelect).toHaveBeenCalledWith(undefined, SettingScope.User);
332
+ unmount();
333
+ });
334
+ });
projects/ui/qwen-code/packages/cli/src/ui/components/AuthDialog.tsx ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { AuthType } from '@qwen-code/qwen-code-core';
8
+ import { Box, Text } from 'ink';
9
+ import React, { useState } from 'react';
10
+ import {
11
+ setOpenAIApiKey,
12
+ setOpenAIBaseUrl,
13
+ setOpenAIModel,
14
+ validateAuthMethod,
15
+ } from '../../config/auth.js';
16
+ import { LoadedSettings, SettingScope } from '../../config/settings.js';
17
+ import { Colors } from '../colors.js';
18
+ import { useKeypress } from '../hooks/useKeypress.js';
19
+ import { OpenAIKeyPrompt } from './OpenAIKeyPrompt.js';
20
+ import { RadioButtonSelect } from './shared/RadioButtonSelect.js';
21
+
22
+ interface AuthDialogProps {
23
+ onSelect: (authMethod: AuthType | undefined, scope: SettingScope) => void;
24
+ settings: LoadedSettings;
25
+ initialErrorMessage?: string | null;
26
+ }
27
+
28
+ function parseDefaultAuthType(
29
+ defaultAuthType: string | undefined,
30
+ ): AuthType | null {
31
+ if (
32
+ defaultAuthType &&
33
+ Object.values(AuthType).includes(defaultAuthType as AuthType)
34
+ ) {
35
+ return defaultAuthType as AuthType;
36
+ }
37
+ return null;
38
+ }
39
+
40
+ export function AuthDialog({
41
+ onSelect,
42
+ settings,
43
+ initialErrorMessage,
44
+ }: AuthDialogProps): React.JSX.Element {
45
+ const [errorMessage, setErrorMessage] = useState<string | null>(
46
+ initialErrorMessage || null,
47
+ );
48
+ const [showOpenAIKeyPrompt, setShowOpenAIKeyPrompt] = useState(false);
49
+ const items = [
50
+ { label: 'Qwen OAuth', value: AuthType.QWEN_OAUTH },
51
+ { label: 'OpenAI', value: AuthType.USE_OPENAI },
52
+ ];
53
+
54
+ const initialAuthIndex = Math.max(
55
+ 0,
56
+ items.findIndex((item) => {
57
+ if (settings.merged.selectedAuthType) {
58
+ return item.value === settings.merged.selectedAuthType;
59
+ }
60
+
61
+ const defaultAuthType = parseDefaultAuthType(
62
+ process.env['GEMINI_DEFAULT_AUTH_TYPE'],
63
+ );
64
+ if (defaultAuthType) {
65
+ return item.value === defaultAuthType;
66
+ }
67
+
68
+ if (process.env['GEMINI_API_KEY']) {
69
+ return item.value === AuthType.USE_GEMINI;
70
+ }
71
+
72
+ return item.value === AuthType.LOGIN_WITH_GOOGLE;
73
+ }),
74
+ );
75
+
76
+ const handleAuthSelect = (authMethod: AuthType) => {
77
+ const error = validateAuthMethod(authMethod);
78
+ if (error) {
79
+ if (
80
+ authMethod === AuthType.USE_OPENAI &&
81
+ !process.env['OPENAI_API_KEY']
82
+ ) {
83
+ setShowOpenAIKeyPrompt(true);
84
+ setErrorMessage(null);
85
+ } else {
86
+ setErrorMessage(error);
87
+ }
88
+ } else {
89
+ setErrorMessage(null);
90
+ onSelect(authMethod, SettingScope.User);
91
+ }
92
+ };
93
+
94
+ const handleOpenAIKeySubmit = (
95
+ apiKey: string,
96
+ baseUrl: string,
97
+ model: string,
98
+ ) => {
99
+ setOpenAIApiKey(apiKey);
100
+ setOpenAIBaseUrl(baseUrl);
101
+ setOpenAIModel(model);
102
+ setShowOpenAIKeyPrompt(false);
103
+ onSelect(AuthType.USE_OPENAI, SettingScope.User);
104
+ };
105
+
106
+ const handleOpenAIKeyCancel = () => {
107
+ setShowOpenAIKeyPrompt(false);
108
+ setErrorMessage('OpenAI API key is required to use OpenAI authentication.');
109
+ };
110
+
111
+ useKeypress(
112
+ (key) => {
113
+ if (showOpenAIKeyPrompt) {
114
+ return;
115
+ }
116
+
117
+ if (key.name === 'escape') {
118
+ // Prevent exit if there is an error message.
119
+ // This means they user is not authenticated yet.
120
+ if (errorMessage) {
121
+ return;
122
+ }
123
+ if (settings.merged.selectedAuthType === undefined) {
124
+ // Prevent exiting if no auth method is set
125
+ setErrorMessage(
126
+ 'You must select an auth method to proceed. Press Ctrl+C twice to exit.',
127
+ );
128
+ return;
129
+ }
130
+ onSelect(undefined, SettingScope.User);
131
+ }
132
+ },
133
+ { isActive: true },
134
+ );
135
+
136
+ if (showOpenAIKeyPrompt) {
137
+ return (
138
+ <OpenAIKeyPrompt
139
+ onSubmit={handleOpenAIKeySubmit}
140
+ onCancel={handleOpenAIKeyCancel}
141
+ />
142
+ );
143
+ }
144
+
145
+ return (
146
+ <Box
147
+ borderStyle="round"
148
+ borderColor={Colors.Gray}
149
+ flexDirection="column"
150
+ padding={1}
151
+ width="100%"
152
+ >
153
+ <Text bold>Get started</Text>
154
+ <Box marginTop={1}>
155
+ <Text>How would you like to authenticate for this project?</Text>
156
+ </Box>
157
+ <Box marginTop={1}>
158
+ <RadioButtonSelect
159
+ items={items}
160
+ initialIndex={initialAuthIndex}
161
+ onSelect={handleAuthSelect}
162
+ />
163
+ </Box>
164
+ {errorMessage && (
165
+ <Box marginTop={1}>
166
+ <Text color={Colors.AccentRed}>{errorMessage}</Text>
167
+ </Box>
168
+ )}
169
+ <Box marginTop={1}>
170
+ <Text color={Colors.AccentPurple}>(Use Enter to Set Auth)</Text>
171
+ </Box>
172
+ <Box marginTop={1}>
173
+ <Text>Terms of Services and Privacy Notice for Qwen Code</Text>
174
+ </Box>
175
+ <Box marginTop={1}>
176
+ <Text color={Colors.AccentBlue}>
177
+ {'https://github.com/QwenLM/Qwen3-Coder/blob/main/README.md'}
178
+ </Text>
179
+ </Box>
180
+ </Box>
181
+ );
182
+ }
projects/ui/qwen-code/packages/cli/src/ui/components/AuthInProgress.tsx ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import React, { useState, useEffect } from 'react';
8
+ import { Box, Text } from 'ink';
9
+ import Spinner from 'ink-spinner';
10
+ import { Colors } from '../colors.js';
11
+ import { useKeypress } from '../hooks/useKeypress.js';
12
+
13
+ interface AuthInProgressProps {
14
+ onTimeout: () => void;
15
+ }
16
+
17
+ export function AuthInProgress({
18
+ onTimeout,
19
+ }: AuthInProgressProps): React.JSX.Element {
20
+ const [timedOut, setTimedOut] = useState(false);
21
+
22
+ useKeypress(
23
+ (key) => {
24
+ if (key.name === 'escape' || (key.ctrl && key.name === 'c')) {
25
+ onTimeout();
26
+ }
27
+ },
28
+ { isActive: true },
29
+ );
30
+
31
+ useEffect(() => {
32
+ const timer = setTimeout(() => {
33
+ setTimedOut(true);
34
+ onTimeout();
35
+ }, 180000);
36
+
37
+ return () => clearTimeout(timer);
38
+ }, [onTimeout]);
39
+
40
+ return (
41
+ <Box
42
+ borderStyle="round"
43
+ borderColor={Colors.Gray}
44
+ flexDirection="column"
45
+ padding={1}
46
+ width="100%"
47
+ >
48
+ {timedOut ? (
49
+ <Text color={Colors.AccentRed}>
50
+ Authentication timed out. Please try again.
51
+ </Text>
52
+ ) : (
53
+ <Box>
54
+ <Text>
55
+ <Spinner type="dots" /> Waiting for auth... (Press ESC or CTRL+C to
56
+ cancel)
57
+ </Text>
58
+ </Box>
59
+ )}
60
+ </Box>
61
+ );
62
+ }
projects/ui/qwen-code/packages/cli/src/ui/components/AutoAcceptIndicator.tsx ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import React from 'react';
8
+ import { Box, Text } from 'ink';
9
+ import { Colors } from '../colors.js';
10
+ import { ApprovalMode } from '@qwen-code/qwen-code-core';
11
+
12
+ interface AutoAcceptIndicatorProps {
13
+ approvalMode: ApprovalMode;
14
+ }
15
+
16
+ export const AutoAcceptIndicator: React.FC<AutoAcceptIndicatorProps> = ({
17
+ approvalMode,
18
+ }) => {
19
+ let textColor = '';
20
+ let textContent = '';
21
+ let subText = '';
22
+
23
+ switch (approvalMode) {
24
+ case ApprovalMode.AUTO_EDIT:
25
+ textColor = Colors.AccentGreen;
26
+ textContent = 'accepting edits';
27
+ subText = ' (shift + tab to toggle)';
28
+ break;
29
+ case ApprovalMode.YOLO:
30
+ textColor = Colors.AccentRed;
31
+ textContent = 'YOLO mode';
32
+ subText = ' (ctrl + y to toggle)';
33
+ break;
34
+ case ApprovalMode.DEFAULT:
35
+ default:
36
+ break;
37
+ }
38
+
39
+ return (
40
+ <Box>
41
+ <Text color={textColor}>
42
+ {textContent}
43
+ {subText && <Text color={Colors.Gray}>{subText}</Text>}
44
+ </Text>
45
+ </Box>
46
+ );
47
+ };
projects/ui/qwen-code/packages/cli/src/ui/components/ConsoleSummaryDisplay.tsx ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import React from 'react';
8
+ import { Box, Text } from 'ink';
9
+ import { Colors } from '../colors.js';
10
+
11
+ interface ConsoleSummaryDisplayProps {
12
+ errorCount: number;
13
+ // logCount is not currently in the plan to be displayed in summary
14
+ }
15
+
16
+ export const ConsoleSummaryDisplay: React.FC<ConsoleSummaryDisplayProps> = ({
17
+ errorCount,
18
+ }) => {
19
+ if (errorCount === 0) {
20
+ return null;
21
+ }
22
+
23
+ const errorIcon = '\u2716'; // Heavy multiplication x (✖)
24
+
25
+ return (
26
+ <Box>
27
+ {errorCount > 0 && (
28
+ <Text color={Colors.AccentRed}>
29
+ {errorIcon} {errorCount} error{errorCount > 1 ? 's' : ''}{' '}
30
+ <Text color={Colors.Gray}>(ctrl+o for details)</Text>
31
+ </Text>
32
+ )}
33
+ </Box>
34
+ );
35
+ };
projects/ui/qwen-code/packages/cli/src/ui/components/ContextSummaryDisplay.test.tsx ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import React from 'react';
8
+ import { render } from 'ink-testing-library';
9
+ import { describe, it, expect, vi } from 'vitest';
10
+ import { ContextSummaryDisplay } from './ContextSummaryDisplay.js';
11
+ import * as useTerminalSize from '../hooks/useTerminalSize.js';
12
+
13
+ vi.mock('../hooks/useTerminalSize.js', () => ({
14
+ useTerminalSize: vi.fn(),
15
+ }));
16
+
17
+ const useTerminalSizeMock = vi.mocked(useTerminalSize.useTerminalSize);
18
+
19
+ const renderWithWidth = (
20
+ width: number,
21
+ props: React.ComponentProps<typeof ContextSummaryDisplay>,
22
+ ) => {
23
+ useTerminalSizeMock.mockReturnValue({ columns: width, rows: 24 });
24
+ return render(<ContextSummaryDisplay {...props} />);
25
+ };
26
+
27
+ describe('<ContextSummaryDisplay />', () => {
28
+ const baseProps = {
29
+ geminiMdFileCount: 1,
30
+ contextFileNames: ['QWEN.md'],
31
+ mcpServers: { 'test-server': { command: 'test' } },
32
+ showToolDescriptions: false,
33
+ ideContext: {
34
+ workspaceState: {
35
+ openFiles: [{ path: '/a/b/c' }],
36
+ },
37
+ },
38
+ };
39
+
40
+ it('should render on a single line on a wide screen', () => {
41
+ const { lastFrame } = renderWithWidth(120, baseProps);
42
+ const output = lastFrame();
43
+ expect(output).toContain(
44
+ 'Using: 1 open file (ctrl+g to view) | 1 QWEN.md file | 1 MCP server (ctrl+t to view)',
45
+ );
46
+ // Check for absence of newlines
47
+ expect(output.includes('\n')).toBe(false);
48
+ });
49
+
50
+ it('should render on multiple lines on a narrow screen', () => {
51
+ const { lastFrame } = renderWithWidth(60, baseProps);
52
+ const output = lastFrame();
53
+ const expectedLines = [
54
+ 'Using:',
55
+ ' - 1 open file (ctrl+g to view)',
56
+ ' - 1 QWEN.md file',
57
+ ' - 1 MCP server (ctrl+t to view)',
58
+ ];
59
+ const actualLines = output.split('\n');
60
+ expect(actualLines).toEqual(expectedLines);
61
+ });
62
+
63
+ it('should switch layout at the 80-column breakpoint', () => {
64
+ // At 80 columns, should be on one line
65
+ const { lastFrame: wideFrame } = renderWithWidth(80, baseProps);
66
+ expect(wideFrame().includes('\n')).toBe(false);
67
+
68
+ // At 79 columns, should be on multiple lines
69
+ const { lastFrame: narrowFrame } = renderWithWidth(79, baseProps);
70
+ expect(narrowFrame().includes('\n')).toBe(true);
71
+ expect(narrowFrame().split('\n').length).toBe(4);
72
+ });
73
+
74
+ it('should not render empty parts', () => {
75
+ const props = {
76
+ ...baseProps,
77
+ geminiMdFileCount: 0,
78
+ mcpServers: {},
79
+ };
80
+ const { lastFrame } = renderWithWidth(60, props);
81
+ const expectedLines = ['Using:', ' - 1 open file (ctrl+g to view)'];
82
+ const actualLines = lastFrame().split('\n');
83
+ expect(actualLines).toEqual(expectedLines);
84
+ });
85
+ });
projects/ui/qwen-code/packages/cli/src/ui/components/ContextSummaryDisplay.tsx ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import React from 'react';
8
+ import { Box, Text } from 'ink';
9
+ import { Colors } from '../colors.js';
10
+ import {
11
+ type IdeContext,
12
+ type MCPServerConfig,
13
+ } from '@qwen-code/qwen-code-core';
14
+ import { useTerminalSize } from '../hooks/useTerminalSize.js';
15
+ import { isNarrowWidth } from '../utils/isNarrowWidth.js';
16
+
17
+ interface ContextSummaryDisplayProps {
18
+ geminiMdFileCount: number;
19
+ contextFileNames: string[];
20
+ mcpServers?: Record<string, MCPServerConfig>;
21
+ blockedMcpServers?: Array<{ name: string; extensionName: string }>;
22
+ showToolDescriptions?: boolean;
23
+ ideContext?: IdeContext;
24
+ }
25
+
26
+ export const ContextSummaryDisplay: React.FC<ContextSummaryDisplayProps> = ({
27
+ geminiMdFileCount,
28
+ contextFileNames,
29
+ mcpServers,
30
+ blockedMcpServers,
31
+ showToolDescriptions,
32
+ ideContext,
33
+ }) => {
34
+ const { columns: terminalWidth } = useTerminalSize();
35
+ const isNarrow = isNarrowWidth(terminalWidth);
36
+ const mcpServerCount = Object.keys(mcpServers || {}).length;
37
+ const blockedMcpServerCount = blockedMcpServers?.length || 0;
38
+ const openFileCount = ideContext?.workspaceState?.openFiles?.length ?? 0;
39
+
40
+ if (
41
+ geminiMdFileCount === 0 &&
42
+ mcpServerCount === 0 &&
43
+ blockedMcpServerCount === 0 &&
44
+ openFileCount === 0
45
+ ) {
46
+ return <Text> </Text>; // Render an empty space to reserve height
47
+ }
48
+
49
+ const openFilesText = (() => {
50
+ if (openFileCount === 0) {
51
+ return '';
52
+ }
53
+ return `${openFileCount} open file${
54
+ openFileCount > 1 ? 's' : ''
55
+ } (ctrl+g to view)`;
56
+ })();
57
+
58
+ const geminiMdText = (() => {
59
+ if (geminiMdFileCount === 0) {
60
+ return '';
61
+ }
62
+ const allNamesTheSame = new Set(contextFileNames).size < 2;
63
+ const name = allNamesTheSame ? contextFileNames[0] : 'context';
64
+ return `${geminiMdFileCount} ${name} file${
65
+ geminiMdFileCount > 1 ? 's' : ''
66
+ }`;
67
+ })();
68
+
69
+ const mcpText = (() => {
70
+ if (mcpServerCount === 0 && blockedMcpServerCount === 0) {
71
+ return '';
72
+ }
73
+
74
+ const parts = [];
75
+ if (mcpServerCount > 0) {
76
+ parts.push(
77
+ `${mcpServerCount} MCP server${mcpServerCount > 1 ? 's' : ''}`,
78
+ );
79
+ }
80
+
81
+ if (blockedMcpServerCount > 0) {
82
+ let blockedText = `${blockedMcpServerCount} Blocked`;
83
+ if (mcpServerCount === 0) {
84
+ blockedText += ` MCP server${blockedMcpServerCount > 1 ? 's' : ''}`;
85
+ }
86
+ parts.push(blockedText);
87
+ }
88
+ let text = parts.join(', ');
89
+ // Add ctrl+t hint when MCP servers are available
90
+ if (mcpServers && Object.keys(mcpServers).length > 0) {
91
+ if (showToolDescriptions) {
92
+ text += ' (ctrl+t to toggle)';
93
+ } else {
94
+ text += ' (ctrl+t to view)';
95
+ }
96
+ }
97
+ return text;
98
+ })();
99
+
100
+ const summaryParts = [openFilesText, geminiMdText, mcpText].filter(Boolean);
101
+
102
+ if (isNarrow) {
103
+ return (
104
+ <Box flexDirection="column">
105
+ <Text color={Colors.Gray}>Using:</Text>
106
+ {summaryParts.map((part, index) => (
107
+ <Text key={index} color={Colors.Gray}>
108
+ {' '}- {part}
109
+ </Text>
110
+ ))}
111
+ </Box>
112
+ );
113
+ }
114
+
115
+ return (
116
+ <Box>
117
+ <Text color={Colors.Gray}>Using: {summaryParts.join(' | ')}</Text>
118
+ </Box>
119
+ );
120
+ };
projects/ui/qwen-code/packages/cli/src/ui/components/ContextUsageDisplay.tsx ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { Text } from 'ink';
8
+ import { Colors } from '../colors.js';
9
+ import { tokenLimit } from '@qwen-code/qwen-code-core';
10
+
11
+ export const ContextUsageDisplay = ({
12
+ promptTokenCount,
13
+ model,
14
+ }: {
15
+ promptTokenCount: number;
16
+ model: string;
17
+ }) => {
18
+ const percentage = promptTokenCount / tokenLimit(model);
19
+
20
+ return (
21
+ <Text color={Colors.Gray}>
22
+ ({((1 - percentage) * 100).toFixed(0)}% context left)
23
+ </Text>
24
+ );
25
+ };