forked from QwenLM/qwen-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuiltinCommandLoader.ts
More file actions
164 lines (158 loc) · 6.49 KB
/
Copy pathBuiltinCommandLoader.ts
File metadata and controls
164 lines (158 loc) · 6.49 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type { ICommandLoader } from './types.js';
import type { SlashCommand } from '../ui/commands/types.js';
import type { Config } from '@qwen-code/qwen-code-core';
import { aboutCommand } from '../ui/commands/aboutCommand.js';
import { tasksCommand } from '../ui/commands/tasksCommand.js';
import { agentsCommand } from '../ui/commands/agentsCommand.js';
import { arenaCommand } from '../ui/commands/arenaCommand.js';
import { approvalModeCommand } from '../ui/commands/approvalModeCommand.js';
import { authCommand } from '../ui/commands/authCommand.js';
import { branchCommand } from '../ui/commands/branchCommand.js';
import { btwCommand } from '../ui/commands/btwCommand.js';
import { bugCommand } from '../ui/commands/bugCommand.js';
import { clearCommand } from '../ui/commands/clearCommand.js';
import { deleteCommand } from '../ui/commands/deleteCommand.js';
import { compressCommand } from '../ui/commands/compressCommand.js';
import { contextCommand } from '../ui/commands/contextCommand.js';
import { copyCommand } from '../ui/commands/copyCommand.js';
import { docsCommand } from '../ui/commands/docsCommand.js';
import { doctorCommand } from '../ui/commands/doctorCommand.js';
import { diffCommand } from '../ui/commands/diffCommand.js';
import { directoryCommand } from '../ui/commands/directoryCommand.js';
import { editorCommand } from '../ui/commands/editorCommand.js';
import { exportCommand } from '../ui/commands/exportCommand.js';
import { extensionsCommand } from '../ui/commands/extensionsCommand.js';
import { goalCommand } from '../ui/commands/goalCommand.js';
import { helpCommand } from '../ui/commands/helpCommand.js';
import { hooksCommand } from '../ui/commands/hooksCommand.js';
import { ideCommand } from '../ui/commands/ideCommand.js';
import { createDebugLogger } from '@qwen-code/qwen-code-core';
import { initCommand } from '../ui/commands/initCommand.js';
import { languageCommand } from '../ui/commands/languageCommand.js';
import { mcpCommand } from '../ui/commands/mcpCommand.js';
import { dreamCommand } from '../ui/commands/dreamCommand.js';
import { forgetCommand } from '../ui/commands/forgetCommand.js';
import { memoryCommand } from '../ui/commands/memoryCommand.js';
import { modelCommand } from '../ui/commands/modelCommand.js';
import { manageModelsCommand } from '../ui/commands/manageModelsCommand.js';
import { rememberCommand } from '../ui/commands/rememberCommand.js';
import { planCommand } from '../ui/commands/planCommand.js';
import { permissionsCommand } from '../ui/commands/permissionsCommand.js';
import { trustCommand } from '../ui/commands/trustCommand.js';
import { quitCommand } from '../ui/commands/quitCommand.js';
import { recapCommand } from '../ui/commands/recapCommand.js';
import { renameCommand } from '../ui/commands/renameCommand.js';
import { restoreCommand } from '../ui/commands/restoreCommand.js';
import { resumeCommand } from '../ui/commands/resumeCommand.js';
import { rewindCommand } from '../ui/commands/rewindCommand.js';
import { settingsCommand } from '../ui/commands/settingsCommand.js';
import { skillsCommand } from '../ui/commands/skillsCommand.js';
import { statsCommand } from '../ui/commands/statsCommand.js';
import { summaryCommand } from '../ui/commands/summaryCommand.js';
import { terminalSetupCommand } from '../ui/commands/terminalSetupCommand.js';
import { themeCommand } from '../ui/commands/themeCommand.js';
import { toolsCommand } from '../ui/commands/toolsCommand.js';
import { vimCommand } from '../ui/commands/vimCommand.js';
import { setupGithubCommand } from '../ui/commands/setupGithubCommand.js';
import { insightCommand } from '../ui/commands/insightCommand.js';
import { statuslineCommand } from '../ui/commands/statuslineCommand.js';
const builtinDebugLogger = createDebugLogger('BUILTIN_COMMAND_LOADER');
/**
* Loads the core, hard-coded slash commands that are an integral part
* of the Qwen Code application.
*/
export class BuiltinCommandLoader implements ICommandLoader {
constructor(private config: Config | null) {}
/**
* Gathers all raw built-in command definitions, injects dependencies where
* needed (e.g., config) and filters out any that are not available.
*
* @param _signal An AbortSignal (unused for this synchronous loader).
* @returns A promise that resolves to an array of `SlashCommand` objects.
*/
async loadCommands(_signal: AbortSignal): Promise<SlashCommand[]> {
// Load ideCommand separately with error handling so that a failure
// (e.g., platform-specific process detection on Windows) does not
// prevent ALL built-in commands from loading.
let resolvedIdeCommand: SlashCommand | null = null;
try {
resolvedIdeCommand = await ideCommand();
} catch (error) {
builtinDebugLogger.warn(
'Failed to load IDE command:',
error instanceof Error ? error.message : String(error),
);
}
const allDefinitions: Array<SlashCommand | null> = [
aboutCommand,
agentsCommand,
tasksCommand,
arenaCommand,
approvalModeCommand,
authCommand,
branchCommand,
btwCommand,
bugCommand,
clearCommand,
compressCommand,
contextCommand,
copyCommand,
diffCommand,
deleteCommand,
docsCommand,
doctorCommand,
directoryCommand,
editorCommand,
exportCommand,
extensionsCommand,
helpCommand,
hooksCommand,
resolvedIdeCommand,
initCommand,
languageCommand,
mcpCommand,
...(this.config?.getManagedAutoMemoryEnabled()
? [dreamCommand, forgetCommand]
: []),
goalCommand,
memoryCommand,
modelCommand,
manageModelsCommand,
rememberCommand,
planCommand,
permissionsCommand,
...(this.config?.getFolderTrust() ? [trustCommand] : []),
quitCommand,
recapCommand,
renameCommand,
restoreCommand(this.config),
resumeCommand,
rewindCommand,
skillsCommand,
statsCommand,
summaryCommand,
themeCommand,
toolsCommand,
settingsCommand,
vimCommand,
setupGithubCommand,
terminalSetupCommand,
insightCommand,
statuslineCommand,
];
return allDefinitions
.filter((cmd): cmd is SlashCommand => cmd !== null)
.map((cmd) => ({
...cmd,
source: 'builtin-command' as const,
sourceLabel: 'Built-in',
modelInvocable: false,
userInvocable: cmd.userInvocable ?? true,
}));
}
}