ADAPT-Chase commited on
Commit
63aeb6a
·
verified ·
1 Parent(s): 04617c5

Add files using upload-large-folder tool

Browse files
projects/ui/qwen-code/packages/cli/src/ui/commands/corgiCommand.ts ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { CommandKind, type SlashCommand } from './types.js';
8
+
9
+ export const corgiCommand: SlashCommand = {
10
+ name: 'corgi',
11
+ description: 'Toggles corgi mode.',
12
+ kind: CommandKind.BUILT_IN,
13
+ action: (context, _args) => {
14
+ context.ui.toggleCorgiMode();
15
+ },
16
+ };
projects/ui/qwen-code/packages/cli/src/ui/commands/directoryCommand.test.tsx ADDED
@@ -0,0 +1,185 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 { directoryCommand, expandHomeDir } from './directoryCommand.js';
9
+ import { Config, WorkspaceContext } from '@qwen-code/qwen-code-core';
10
+ import { CommandContext } from './types.js';
11
+ import { MessageType } from '../types.js';
12
+ import * as os from 'os';
13
+ import * as path from 'path';
14
+
15
+ describe('directoryCommand', () => {
16
+ let mockContext: CommandContext;
17
+ let mockConfig: Config;
18
+ let mockWorkspaceContext: WorkspaceContext;
19
+ const addCommand = directoryCommand.subCommands?.find(
20
+ (c) => c.name === 'add',
21
+ );
22
+ const showCommand = directoryCommand.subCommands?.find(
23
+ (c) => c.name === 'show',
24
+ );
25
+
26
+ beforeEach(() => {
27
+ mockWorkspaceContext = {
28
+ addDirectory: vi.fn(),
29
+ getDirectories: vi
30
+ .fn()
31
+ .mockReturnValue([
32
+ path.normalize('/home/user/project1'),
33
+ path.normalize('/home/user/project2'),
34
+ ]),
35
+ } as unknown as WorkspaceContext;
36
+
37
+ mockConfig = {
38
+ getWorkspaceContext: () => mockWorkspaceContext,
39
+ isRestrictiveSandbox: vi.fn().mockReturnValue(false),
40
+ getGeminiClient: vi.fn().mockReturnValue({
41
+ addDirectoryContext: vi.fn(),
42
+ }),
43
+ getWorkingDir: () => '/test/dir',
44
+ shouldLoadMemoryFromIncludeDirectories: () => false,
45
+ getDebugMode: () => false,
46
+ getFileService: () => ({}),
47
+ getExtensionContextFilePaths: () => [],
48
+ getFileFilteringOptions: () => ({ ignore: [], include: [] }),
49
+ setUserMemory: vi.fn(),
50
+ setGeminiMdFileCount: vi.fn(),
51
+ } as unknown as Config;
52
+
53
+ mockContext = {
54
+ services: {
55
+ config: mockConfig,
56
+ settings: {
57
+ merged: {
58
+ memoryDiscoveryMaxDirs: 1000,
59
+ },
60
+ },
61
+ },
62
+ ui: {
63
+ addItem: vi.fn(),
64
+ },
65
+ } as unknown as CommandContext;
66
+ });
67
+
68
+ describe('show', () => {
69
+ it('should display the list of directories', () => {
70
+ if (!showCommand?.action) throw new Error('No action');
71
+ showCommand.action(mockContext, '');
72
+ expect(mockWorkspaceContext.getDirectories).toHaveBeenCalled();
73
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
74
+ expect.objectContaining({
75
+ type: MessageType.INFO,
76
+ text: `Current workspace directories:\n- ${path.normalize(
77
+ '/home/user/project1',
78
+ )}\n- ${path.normalize('/home/user/project2')}`,
79
+ }),
80
+ expect.any(Number),
81
+ );
82
+ });
83
+ });
84
+
85
+ describe('add', () => {
86
+ it('should show an error if no path is provided', () => {
87
+ if (!addCommand?.action) throw new Error('No action');
88
+ addCommand.action(mockContext, '');
89
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
90
+ expect.objectContaining({
91
+ type: MessageType.ERROR,
92
+ text: 'Please provide at least one path to add.',
93
+ }),
94
+ expect.any(Number),
95
+ );
96
+ });
97
+
98
+ it('should call addDirectory and show a success message for a single path', async () => {
99
+ const newPath = path.normalize('/home/user/new-project');
100
+ if (!addCommand?.action) throw new Error('No action');
101
+ await addCommand.action(mockContext, newPath);
102
+ expect(mockWorkspaceContext.addDirectory).toHaveBeenCalledWith(newPath);
103
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
104
+ expect.objectContaining({
105
+ type: MessageType.INFO,
106
+ text: `Successfully added directories:\n- ${newPath}`,
107
+ }),
108
+ expect.any(Number),
109
+ );
110
+ });
111
+
112
+ it('should call addDirectory for each path and show a success message for multiple paths', async () => {
113
+ const newPath1 = path.normalize('/home/user/new-project1');
114
+ const newPath2 = path.normalize('/home/user/new-project2');
115
+ if (!addCommand?.action) throw new Error('No action');
116
+ await addCommand.action(mockContext, `${newPath1},${newPath2}`);
117
+ expect(mockWorkspaceContext.addDirectory).toHaveBeenCalledWith(newPath1);
118
+ expect(mockWorkspaceContext.addDirectory).toHaveBeenCalledWith(newPath2);
119
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
120
+ expect.objectContaining({
121
+ type: MessageType.INFO,
122
+ text: `Successfully added directories:\n- ${newPath1}\n- ${newPath2}`,
123
+ }),
124
+ expect.any(Number),
125
+ );
126
+ });
127
+
128
+ it('should show an error if addDirectory throws an exception', async () => {
129
+ const error = new Error('Directory does not exist');
130
+ vi.mocked(mockWorkspaceContext.addDirectory).mockImplementation(() => {
131
+ throw error;
132
+ });
133
+ const newPath = path.normalize('/home/user/invalid-project');
134
+ if (!addCommand?.action) throw new Error('No action');
135
+ await addCommand.action(mockContext, newPath);
136
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
137
+ expect.objectContaining({
138
+ type: MessageType.ERROR,
139
+ text: `Error adding '${newPath}': ${error.message}`,
140
+ }),
141
+ expect.any(Number),
142
+ );
143
+ });
144
+
145
+ it('should handle a mix of successful and failed additions', async () => {
146
+ const validPath = path.normalize('/home/user/valid-project');
147
+ const invalidPath = path.normalize('/home/user/invalid-project');
148
+ const error = new Error('Directory does not exist');
149
+ vi.mocked(mockWorkspaceContext.addDirectory).mockImplementation(
150
+ (p: string) => {
151
+ if (p === invalidPath) {
152
+ throw error;
153
+ }
154
+ },
155
+ );
156
+
157
+ if (!addCommand?.action) throw new Error('No action');
158
+ await addCommand.action(mockContext, `${validPath},${invalidPath}`);
159
+
160
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
161
+ expect.objectContaining({
162
+ type: MessageType.INFO,
163
+ text: `Successfully added directories:\n- ${validPath}`,
164
+ }),
165
+ expect.any(Number),
166
+ );
167
+
168
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
169
+ expect.objectContaining({
170
+ type: MessageType.ERROR,
171
+ text: `Error adding '${invalidPath}': ${error.message}`,
172
+ }),
173
+ expect.any(Number),
174
+ );
175
+ });
176
+ });
177
+ it('should correctly expand a Windows-style home directory path', () => {
178
+ const windowsPath = '%userprofile%\\Documents';
179
+ const expectedPath = path.win32.join(os.homedir(), 'Documents');
180
+ const result = expandHomeDir(windowsPath);
181
+ expect(path.win32.normalize(result)).toBe(
182
+ path.win32.normalize(expectedPath),
183
+ );
184
+ });
185
+ });
projects/ui/qwen-code/packages/cli/src/ui/commands/directoryCommand.tsx ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { SlashCommand, CommandContext, CommandKind } from './types.js';
8
+ import { MessageType } from '../types.js';
9
+ import * as os from 'os';
10
+ import * as path from 'path';
11
+ import { loadServerHierarchicalMemory } from '@qwen-code/qwen-code-core';
12
+
13
+ export function expandHomeDir(p: string): string {
14
+ if (!p) {
15
+ return '';
16
+ }
17
+ let expandedPath = p;
18
+ if (p.toLowerCase().startsWith('%userprofile%')) {
19
+ expandedPath = os.homedir() + p.substring('%userprofile%'.length);
20
+ } else if (p === '~' || p.startsWith('~/')) {
21
+ expandedPath = os.homedir() + p.substring(1);
22
+ }
23
+ return path.normalize(expandedPath);
24
+ }
25
+
26
+ export const directoryCommand: SlashCommand = {
27
+ name: 'directory',
28
+ altNames: ['dir'],
29
+ description: 'Manage workspace directories',
30
+ kind: CommandKind.BUILT_IN,
31
+ subCommands: [
32
+ {
33
+ name: 'add',
34
+ description:
35
+ 'Add directories to the workspace. Use comma to separate multiple paths',
36
+ kind: CommandKind.BUILT_IN,
37
+ action: async (context: CommandContext, args: string) => {
38
+ const {
39
+ ui: { addItem },
40
+ services: { config },
41
+ } = context;
42
+ const [...rest] = args.split(' ');
43
+
44
+ if (!config) {
45
+ addItem(
46
+ {
47
+ type: MessageType.ERROR,
48
+ text: 'Configuration is not available.',
49
+ },
50
+ Date.now(),
51
+ );
52
+ return;
53
+ }
54
+
55
+ const workspaceContext = config.getWorkspaceContext();
56
+
57
+ const pathsToAdd = rest
58
+ .join(' ')
59
+ .split(',')
60
+ .filter((p) => p);
61
+ if (pathsToAdd.length === 0) {
62
+ addItem(
63
+ {
64
+ type: MessageType.ERROR,
65
+ text: 'Please provide at least one path to add.',
66
+ },
67
+ Date.now(),
68
+ );
69
+ return;
70
+ }
71
+
72
+ if (config.isRestrictiveSandbox()) {
73
+ return {
74
+ type: 'message' as const,
75
+ messageType: 'error' as const,
76
+ content:
77
+ 'The /directory add command is not supported in restrictive sandbox profiles. Please use --include-directories when starting the session instead.',
78
+ };
79
+ }
80
+
81
+ const added: string[] = [];
82
+ const errors: string[] = [];
83
+
84
+ for (const pathToAdd of pathsToAdd) {
85
+ try {
86
+ workspaceContext.addDirectory(expandHomeDir(pathToAdd.trim()));
87
+ added.push(pathToAdd.trim());
88
+ } catch (e) {
89
+ const error = e as Error;
90
+ errors.push(`Error adding '${pathToAdd.trim()}': ${error.message}`);
91
+ }
92
+ }
93
+
94
+ if (added.length > 0) {
95
+ try {
96
+ if (config.shouldLoadMemoryFromIncludeDirectories()) {
97
+ const { memoryContent, fileCount } =
98
+ await loadServerHierarchicalMemory(
99
+ config.getWorkingDir(),
100
+ [...config.getWorkspaceContext().getDirectories()],
101
+ config.getDebugMode(),
102
+ config.getFileService(),
103
+ config.getExtensionContextFilePaths(),
104
+ context.services.settings.merged.memoryImportFormat || 'tree', // Use setting or default to 'tree'
105
+ config.getFileFilteringOptions(),
106
+ context.services.settings.merged.memoryDiscoveryMaxDirs,
107
+ );
108
+ config.setUserMemory(memoryContent);
109
+ config.setGeminiMdFileCount(fileCount);
110
+ context.ui.setGeminiMdFileCount(fileCount);
111
+ }
112
+ addItem(
113
+ {
114
+ type: MessageType.INFO,
115
+ text: `Successfully added memory files from the following directories if there are:\n- ${added.join('\n- ')}`,
116
+ },
117
+ Date.now(),
118
+ );
119
+ } catch (error) {
120
+ errors.push(`Error refreshing memory: ${(error as Error).message}`);
121
+ }
122
+ }
123
+
124
+ if (added.length > 0) {
125
+ const gemini = config.getGeminiClient();
126
+ if (gemini) {
127
+ await gemini.addDirectoryContext();
128
+ }
129
+ addItem(
130
+ {
131
+ type: MessageType.INFO,
132
+ text: `Successfully added directories:\n- ${added.join('\n- ')}`,
133
+ },
134
+ Date.now(),
135
+ );
136
+ }
137
+
138
+ if (errors.length > 0) {
139
+ addItem(
140
+ { type: MessageType.ERROR, text: errors.join('\n') },
141
+ Date.now(),
142
+ );
143
+ }
144
+ return;
145
+ },
146
+ },
147
+ {
148
+ name: 'show',
149
+ description: 'Show all directories in the workspace',
150
+ kind: CommandKind.BUILT_IN,
151
+ action: async (context: CommandContext) => {
152
+ const {
153
+ ui: { addItem },
154
+ services: { config },
155
+ } = context;
156
+ if (!config) {
157
+ addItem(
158
+ {
159
+ type: MessageType.ERROR,
160
+ text: 'Configuration is not available.',
161
+ },
162
+ Date.now(),
163
+ );
164
+ return;
165
+ }
166
+ const workspaceContext = config.getWorkspaceContext();
167
+ const directories = workspaceContext.getDirectories();
168
+ const directoryList = directories.map((dir) => `- ${dir}`).join('\n');
169
+ addItem(
170
+ {
171
+ type: MessageType.INFO,
172
+ text: `Current workspace directories:\n${directoryList}`,
173
+ },
174
+ Date.now(),
175
+ );
176
+ },
177
+ },
178
+ ],
179
+ };
projects/ui/qwen-code/packages/cli/src/ui/commands/docsCommand.test.ts ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest';
8
+ import open from 'open';
9
+ import { docsCommand } from './docsCommand.js';
10
+ import { type CommandContext } from './types.js';
11
+ import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
12
+ import { MessageType } from '../types.js';
13
+
14
+ // Mock the 'open' library
15
+ vi.mock('open', () => ({
16
+ default: vi.fn(),
17
+ }));
18
+
19
+ describe('docsCommand', () => {
20
+ let mockContext: CommandContext;
21
+ beforeEach(() => {
22
+ // Create a fresh mock context before each test
23
+ mockContext = createMockCommandContext();
24
+ // Reset the `open` mock
25
+ vi.mocked(open).mockClear();
26
+ });
27
+
28
+ afterEach(() => {
29
+ // Restore any stubbed environment variables
30
+ vi.unstubAllEnvs();
31
+ });
32
+
33
+ it("should add an info message and call 'open' in a non-sandbox environment", async () => {
34
+ if (!docsCommand.action) {
35
+ throw new Error('docsCommand must have an action.');
36
+ }
37
+
38
+ const docsUrl = 'https://qwenlm.github.io/qwen-code-docs/en';
39
+
40
+ await docsCommand.action(mockContext, '');
41
+
42
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
43
+ {
44
+ type: MessageType.INFO,
45
+ text: `Opening documentation in your browser: ${docsUrl}`,
46
+ },
47
+ expect.any(Number),
48
+ );
49
+
50
+ expect(open).toHaveBeenCalledWith(docsUrl);
51
+ });
52
+
53
+ it('should only add an info message in a sandbox environment', async () => {
54
+ if (!docsCommand.action) {
55
+ throw new Error('docsCommand must have an action.');
56
+ }
57
+
58
+ // Simulate a sandbox environment
59
+ vi.stubEnv('SANDBOX', 'gemini-sandbox');
60
+ const docsUrl = 'https://qwenlm.github.io/qwen-code-docs/en';
61
+
62
+ await docsCommand.action(mockContext, '');
63
+
64
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
65
+ {
66
+ type: MessageType.INFO,
67
+ text: `Please open the following URL in your browser to view the documentation:\n${docsUrl}`,
68
+ },
69
+ expect.any(Number),
70
+ );
71
+
72
+ // Ensure 'open' was not called in the sandbox
73
+ expect(open).not.toHaveBeenCalled();
74
+ });
75
+
76
+ it("should not open browser for 'sandbox-exec'", async () => {
77
+ if (!docsCommand.action) {
78
+ throw new Error('docsCommand must have an action.');
79
+ }
80
+
81
+ // Simulate the specific 'sandbox-exec' environment
82
+ vi.stubEnv('SANDBOX', 'sandbox-exec');
83
+ const docsUrl = 'https://qwenlm.github.io/qwen-code-docs/en';
84
+
85
+ await docsCommand.action(mockContext, '');
86
+
87
+ // The logic should fall through to the 'else' block
88
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
89
+ {
90
+ type: MessageType.INFO,
91
+ text: `Opening documentation in your browser: ${docsUrl}`,
92
+ },
93
+ expect.any(Number),
94
+ );
95
+
96
+ // 'open' should be called in this specific sandbox case
97
+ expect(open).toHaveBeenCalledWith(docsUrl);
98
+ });
99
+ });
projects/ui/qwen-code/packages/cli/src/ui/commands/docsCommand.ts ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import open from 'open';
8
+ import process from 'node:process';
9
+ import {
10
+ type CommandContext,
11
+ type SlashCommand,
12
+ CommandKind,
13
+ } from './types.js';
14
+ import { MessageType } from '../types.js';
15
+
16
+ export const docsCommand: SlashCommand = {
17
+ name: 'docs',
18
+ description: 'open full Qwen Code documentation in your browser',
19
+ kind: CommandKind.BUILT_IN,
20
+ action: async (context: CommandContext): Promise<void> => {
21
+ const docsUrl = 'https://qwenlm.github.io/qwen-code-docs/en';
22
+
23
+ if (process.env['SANDBOX'] && process.env['SANDBOX'] !== 'sandbox-exec') {
24
+ context.ui.addItem(
25
+ {
26
+ type: MessageType.INFO,
27
+ text: `Please open the following URL in your browser to view the documentation:\n${docsUrl}`,
28
+ },
29
+ Date.now(),
30
+ );
31
+ } else {
32
+ context.ui.addItem(
33
+ {
34
+ type: MessageType.INFO,
35
+ text: `Opening documentation in your browser: ${docsUrl}`,
36
+ },
37
+ Date.now(),
38
+ );
39
+ await open(docsUrl);
40
+ }
41
+ },
42
+ };
projects/ui/qwen-code/packages/cli/src/ui/commands/editorCommand.test.ts ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { describe, it, expect } from 'vitest';
8
+ import { editorCommand } from './editorCommand.js';
9
+ // 1. Import the mock context utility
10
+ import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
11
+
12
+ describe('editorCommand', () => {
13
+ it('should return a dialog action to open the editor dialog', () => {
14
+ if (!editorCommand.action) {
15
+ throw new Error('The editor command must have an action.');
16
+ }
17
+ const mockContext = createMockCommandContext();
18
+ const result = editorCommand.action(mockContext, '');
19
+
20
+ expect(result).toEqual({
21
+ type: 'dialog',
22
+ dialog: 'editor',
23
+ });
24
+ });
25
+
26
+ it('should have the correct name and description', () => {
27
+ expect(editorCommand.name).toBe('editor');
28
+ expect(editorCommand.description).toBe('set external editor preference');
29
+ });
30
+ });
projects/ui/qwen-code/packages/cli/src/ui/commands/editorCommand.ts ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import {
8
+ CommandKind,
9
+ type OpenDialogActionReturn,
10
+ type SlashCommand,
11
+ } from './types.js';
12
+
13
+ export const editorCommand: SlashCommand = {
14
+ name: 'editor',
15
+ description: 'set external editor preference',
16
+ kind: CommandKind.BUILT_IN,
17
+ action: (): OpenDialogActionReturn => ({
18
+ type: 'dialog',
19
+ dialog: 'editor',
20
+ }),
21
+ };
projects/ui/qwen-code/packages/cli/src/ui/commands/extensionsCommand.test.ts ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ */
6
+
7
+ import { describe, it, expect } from 'vitest';
8
+ import { extensionsCommand } from './extensionsCommand.js';
9
+ import { type CommandContext } from './types.js';
10
+ import { createMockCommandContext } from '../../test-utils/mockCommandContext.js';
11
+ import { MessageType } from '../types.js';
12
+
13
+ describe('extensionsCommand', () => {
14
+ let mockContext: CommandContext;
15
+
16
+ it('should display "No active extensions." when none are found', async () => {
17
+ mockContext = createMockCommandContext({
18
+ services: {
19
+ config: {
20
+ getExtensions: () => [],
21
+ },
22
+ },
23
+ });
24
+
25
+ if (!extensionsCommand.action) throw new Error('Action not defined');
26
+ await extensionsCommand.action(mockContext, '');
27
+
28
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
29
+ {
30
+ type: MessageType.INFO,
31
+ text: 'No active extensions.',
32
+ },
33
+ expect.any(Number),
34
+ );
35
+ });
36
+
37
+ it('should list active extensions when they are found', async () => {
38
+ const mockExtensions = [
39
+ { name: 'ext-one', version: '1.0.0', isActive: true },
40
+ { name: 'ext-two', version: '2.1.0', isActive: true },
41
+ { name: 'ext-three', version: '3.0.0', isActive: false },
42
+ ];
43
+ mockContext = createMockCommandContext({
44
+ services: {
45
+ config: {
46
+ getExtensions: () => mockExtensions,
47
+ },
48
+ },
49
+ });
50
+
51
+ if (!extensionsCommand.action) throw new Error('Action not defined');
52
+ await extensionsCommand.action(mockContext, '');
53
+
54
+ const expectedMessage =
55
+ 'Active extensions:\n\n' +
56
+ ` - \u001b[36mext-one (v1.0.0)\u001b[0m\n` +
57
+ ` - \u001b[36mext-two (v2.1.0)\u001b[0m\n`;
58
+
59
+ expect(mockContext.ui.addItem).toHaveBeenCalledWith(
60
+ {
61
+ type: MessageType.INFO,
62
+ text: expectedMessage,
63
+ },
64
+ expect.any(Number),
65
+ );
66
+ });
67
+ });
projects/ui/qwen-code/packages/cli/src/ui/commands/extensionsCommand.ts ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 extensionsCommand: SlashCommand = {
15
+ name: 'extensions',
16
+ description: 'list active extensions',
17
+ kind: CommandKind.BUILT_IN,
18
+ action: async (context: CommandContext): Promise<void> => {
19
+ const activeExtensions = context.services.config
20
+ ?.getExtensions()
21
+ .filter((ext) => ext.isActive);
22
+ if (!activeExtensions || activeExtensions.length === 0) {
23
+ context.ui.addItem(
24
+ {
25
+ type: MessageType.INFO,
26
+ text: 'No active extensions.',
27
+ },
28
+ Date.now(),
29
+ );
30
+ return;
31
+ }
32
+
33
+ const extensionLines = activeExtensions.map(
34
+ (ext) => ` - \u001b[36m${ext.name} (v${ext.version})\u001b[0m`,
35
+ );
36
+ const message = `Active extensions:\n\n${extensionLines.join('\n')}\n`;
37
+
38
+ context.ui.addItem(
39
+ {
40
+ type: MessageType.INFO,
41
+ text: message,
42
+ },
43
+ Date.now(),
44
+ );
45
+ },
46
+ };