@wonderwhy-er/desktop-commander 0.1.39 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +88 -5
- package/dist/config-manager.d.ts +2 -0
- package/dist/config-manager.js +5 -1
- package/dist/config.d.ts +1 -0
- package/dist/config.js +1 -0
- package/dist/handlers/filesystem-handlers.js +37 -3
- package/dist/handlers/fuzzy-search-log-handlers.d.ts +13 -0
- package/dist/handlers/fuzzy-search-log-handlers.js +179 -0
- package/dist/server.js +219 -42
- package/dist/setup-claude-server.js +34 -26
- package/dist/tools/edit.js +55 -7
- package/dist/tools/filesystem.d.ts +7 -5
- package/dist/tools/filesystem.js +97 -25
- package/dist/tools/schemas.d.ts +9 -0
- package/dist/tools/schemas.js +3 -0
- package/dist/utils/fuzzySearchLogger.d.ts +30 -0
- package/dist/utils/fuzzySearchLogger.js +126 -0
- package/dist/utils/trackTools.d.ts +6 -0
- package/dist/utils/trackTools.js +54 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +7 -2
package/dist/server.js
CHANGED
|
@@ -3,8 +3,10 @@ import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSche
|
|
|
3
3
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
4
4
|
// Shared constants for tool descriptions
|
|
5
5
|
const PATH_GUIDANCE = `IMPORTANT: Always use absolute paths (starting with '/' or drive letter like 'C:\\') for reliability. Relative paths may fail as they depend on the current working directory. Tilde paths (~/...) might not work in all contexts. Unless the user explicitly asks for relative paths, use absolute paths.`;
|
|
6
|
+
const CMD_PREFIX_DESCRIPTION = `This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.`;
|
|
6
7
|
import { ExecuteCommandArgsSchema, ReadOutputArgsSchema, ForceTerminateArgsSchema, ListSessionsArgsSchema, KillProcessArgsSchema, ReadFileArgsSchema, ReadMultipleFilesArgsSchema, WriteFileArgsSchema, CreateDirectoryArgsSchema, ListDirectoryArgsSchema, MoveFileArgsSchema, SearchFilesArgsSchema, GetFileInfoArgsSchema, SearchCodeArgsSchema, GetConfigArgsSchema, SetConfigValueArgsSchema, ListProcessesArgsSchema, EditBlockArgsSchema, } from './tools/schemas.js';
|
|
7
8
|
import { getConfig, setConfigValue } from './tools/config.js';
|
|
9
|
+
import { trackToolCall } from './utils/trackTools.js';
|
|
8
10
|
import { VERSION } from './version.js';
|
|
9
11
|
import { capture } from "./utils/capture.js";
|
|
10
12
|
console.error("Loading server.ts");
|
|
@@ -41,122 +43,295 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
41
43
|
// Configuration tools
|
|
42
44
|
{
|
|
43
45
|
name: "get_config",
|
|
44
|
-
description:
|
|
46
|
+
description: `
|
|
47
|
+
Get the complete server configuration as JSON. Config includes fields for:
|
|
48
|
+
- blockedCommands (array of blocked shell commands)
|
|
49
|
+
- defaultShell (shell to use for commands)
|
|
50
|
+
- allowedDirectories (paths the server can access)
|
|
51
|
+
- fileReadLineLimit (max lines for read_file, default 1000)
|
|
52
|
+
- fileWriteLineLimit (max lines per write_file call, default 50)
|
|
53
|
+
- telemetryEnabled (boolean for telemetry opt-in/out)
|
|
54
|
+
- version (version of the DesktopCommander)
|
|
55
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
45
56
|
inputSchema: zodToJsonSchema(GetConfigArgsSchema),
|
|
46
57
|
},
|
|
47
58
|
{
|
|
48
59
|
name: "set_config_value",
|
|
49
|
-
description:
|
|
60
|
+
description: `
|
|
61
|
+
Set a specific configuration value by key.
|
|
62
|
+
|
|
63
|
+
WARNING: Should be used in a separate chat from file operations and
|
|
64
|
+
command execution to prevent security issues.
|
|
65
|
+
|
|
66
|
+
Config keys include:
|
|
67
|
+
- blockedCommands (array)
|
|
68
|
+
- defaultShell (string)
|
|
69
|
+
- allowedDirectories (array of paths)
|
|
70
|
+
- fileReadLineLimit (number, max lines for read_file)
|
|
71
|
+
- fileWriteLineLimit (number, max lines per write_file call)
|
|
72
|
+
- telemetryEnabled (boolean)
|
|
73
|
+
|
|
74
|
+
IMPORTANT: Setting allowedDirectories to an empty array ([]) allows full access
|
|
75
|
+
to the entire file system, regardless of the operating system.
|
|
76
|
+
|
|
77
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
50
78
|
inputSchema: zodToJsonSchema(SetConfigValueArgsSchema),
|
|
51
79
|
},
|
|
52
80
|
// Filesystem tools
|
|
53
81
|
{
|
|
54
82
|
name: "read_file",
|
|
55
|
-
description: `
|
|
83
|
+
description: `
|
|
84
|
+
Read the contents of a file from the file system or a URL with optional offset and length parameters.
|
|
85
|
+
|
|
86
|
+
Prefer this over 'execute_command' with cat/type for viewing files.
|
|
87
|
+
|
|
88
|
+
Supports partial file reading with:
|
|
89
|
+
- 'offset' (start line, default: 0)
|
|
90
|
+
- 'length' (max lines to read, default: configurable via 'fileReadLineLimit' setting, initially 1000)
|
|
91
|
+
|
|
92
|
+
When reading from the file system, only works within allowed directories.
|
|
93
|
+
Can fetch content from URLs when isUrl parameter is set to true
|
|
94
|
+
(URLs are always read in full regardless of offset/length).
|
|
95
|
+
|
|
96
|
+
Handles text files normally and image files are returned as viewable images.
|
|
97
|
+
Recognized image types: PNG, JPEG, GIF, WebP.
|
|
98
|
+
|
|
99
|
+
${PATH_GUIDANCE}
|
|
100
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
56
101
|
inputSchema: zodToJsonSchema(ReadFileArgsSchema),
|
|
57
102
|
},
|
|
58
103
|
{
|
|
59
104
|
name: "read_multiple_files",
|
|
60
|
-
description: `
|
|
105
|
+
description: `
|
|
106
|
+
Read the contents of multiple files simultaneously.
|
|
107
|
+
|
|
108
|
+
Each file's content is returned with its path as a reference.
|
|
109
|
+
Handles text files normally and renders images as viewable content.
|
|
110
|
+
Recognized image types: PNG, JPEG, GIF, WebP.
|
|
111
|
+
|
|
112
|
+
Failed reads for individual files won't stop the entire operation.
|
|
113
|
+
Only works within allowed directories.
|
|
114
|
+
|
|
115
|
+
${PATH_GUIDANCE}
|
|
116
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
61
117
|
inputSchema: zodToJsonSchema(ReadMultipleFilesArgsSchema),
|
|
62
118
|
},
|
|
63
119
|
{
|
|
64
120
|
name: "write_file",
|
|
65
|
-
description: `
|
|
121
|
+
description: `
|
|
122
|
+
Write or append to file contents with a configurable line limit per call (default: 50 lines).
|
|
123
|
+
THIS IS A STRICT REQUIREMENT. ANY file with more than the configured limit MUST BE written in chunks or IT WILL FAIL.
|
|
124
|
+
|
|
125
|
+
⚠️ IMPORTANT: PREVENTATIVE CHUNKING REQUIRED in these scenarios:
|
|
126
|
+
1. When content exceeds 2,000 words or 30 lines
|
|
127
|
+
2. When writing MULTIPLE files one after another (each next file is more likely to be truncated)
|
|
128
|
+
3. When the file is the LAST ONE in a series of operations in the same message
|
|
129
|
+
|
|
130
|
+
ALWAYS split files writes in to multiple smaller writes PREEMPTIVELY without asking the user in these scenarios.
|
|
131
|
+
|
|
132
|
+
REQUIRED PROCESS FOR LARGE NEW FILE WRITES OR REWRITES:
|
|
133
|
+
1. FIRST → write_file(filePath, firstChunk, {mode: 'rewrite'})
|
|
134
|
+
2. THEN → write_file(filePath, secondChunk, {mode: 'append'})
|
|
135
|
+
3. THEN → write_file(filePath, thirdChunk, {mode: 'append'})
|
|
136
|
+
... and so on for each chunk
|
|
137
|
+
|
|
138
|
+
HANDLING TRUNCATION ("Continue" prompts):
|
|
139
|
+
If user asked to "Continue" after unfinished file write:
|
|
140
|
+
1. First, read the file to find out what content was successfully written
|
|
141
|
+
2. Identify exactly where the content was truncated
|
|
142
|
+
3. Continue writing ONLY the remaining content using {mode: 'append'}
|
|
143
|
+
4. Split the remaining content into smaller chunks (15-20 lines per chunk)
|
|
144
|
+
|
|
145
|
+
Files over the line limit (configurable via 'fileWriteLineLimit' setting) WILL BE REJECTED if not broken into chunks as described above.
|
|
146
|
+
Only works within allowed directories.
|
|
147
|
+
|
|
148
|
+
${PATH_GUIDANCE}
|
|
149
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
66
150
|
inputSchema: zodToJsonSchema(WriteFileArgsSchema),
|
|
67
151
|
},
|
|
68
152
|
{
|
|
69
153
|
name: "create_directory",
|
|
70
|
-
description: `
|
|
154
|
+
description: `
|
|
155
|
+
Create a new directory or ensure a directory exists.
|
|
156
|
+
|
|
157
|
+
Can create multiple nested directories in one operation.
|
|
158
|
+
Only works within allowed directories.
|
|
159
|
+
|
|
160
|
+
${PATH_GUIDANCE}
|
|
161
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
71
162
|
inputSchema: zodToJsonSchema(CreateDirectoryArgsSchema),
|
|
72
163
|
},
|
|
73
164
|
{
|
|
74
165
|
name: "list_directory",
|
|
75
|
-
description: `
|
|
166
|
+
description: `
|
|
167
|
+
Get a detailed listing of all files and directories in a specified path.
|
|
168
|
+
|
|
169
|
+
Use this instead of 'execute_command' with ls/dir commands.
|
|
170
|
+
Results distinguish between files and directories with [FILE] and [DIR] prefixes.
|
|
171
|
+
Only works within allowed directories.
|
|
172
|
+
|
|
173
|
+
${PATH_GUIDANCE}
|
|
174
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
76
175
|
inputSchema: zodToJsonSchema(ListDirectoryArgsSchema),
|
|
77
176
|
},
|
|
78
177
|
{
|
|
79
178
|
name: "move_file",
|
|
80
|
-
description: `
|
|
81
|
-
|
|
82
|
-
|
|
179
|
+
description: `
|
|
180
|
+
Move or rename files and directories.
|
|
181
|
+
|
|
182
|
+
Can move files between directories and rename them in a single operation.
|
|
183
|
+
Both source and destination must be within allowed directories.
|
|
184
|
+
|
|
185
|
+
${PATH_GUIDANCE}
|
|
186
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
83
187
|
inputSchema: zodToJsonSchema(MoveFileArgsSchema),
|
|
84
188
|
},
|
|
85
189
|
{
|
|
86
190
|
name: "search_files",
|
|
87
|
-
description: `
|
|
191
|
+
description: `
|
|
192
|
+
Finds files by name using a case-insensitive substring matching.
|
|
193
|
+
|
|
88
194
|
Use this instead of 'execute_command' with find/dir/ls for locating files.
|
|
89
|
-
Searches through all subdirectories from the starting path.
|
|
90
|
-
|
|
91
|
-
|
|
195
|
+
Searches through all subdirectories from the starting path.
|
|
196
|
+
|
|
197
|
+
Has a default timeout of 30 seconds which can be customized using the timeoutMs parameter.
|
|
198
|
+
Only searches within allowed directories.
|
|
199
|
+
|
|
200
|
+
${PATH_GUIDANCE}
|
|
201
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
92
202
|
inputSchema: zodToJsonSchema(SearchFilesArgsSchema),
|
|
93
203
|
},
|
|
94
204
|
{
|
|
95
205
|
name: "search_code",
|
|
96
|
-
description: `
|
|
206
|
+
description: `
|
|
207
|
+
Search for text/code patterns within file contents using ripgrep.
|
|
208
|
+
|
|
97
209
|
Use this instead of 'execute_command' with grep/find for searching code content.
|
|
98
|
-
Fast and powerful search similar to VS Code search functionality.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
210
|
+
Fast and powerful search similar to VS Code search functionality.
|
|
211
|
+
|
|
212
|
+
Supports regular expressions, file pattern filtering, and context lines.
|
|
213
|
+
Has a default timeout of 30 seconds which can be customized.
|
|
214
|
+
Only searches within allowed directories.
|
|
215
|
+
|
|
216
|
+
${PATH_GUIDANCE}
|
|
217
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
103
218
|
inputSchema: zodToJsonSchema(SearchCodeArgsSchema),
|
|
104
219
|
},
|
|
105
220
|
{
|
|
106
221
|
name: "get_file_info",
|
|
107
|
-
description: `
|
|
108
|
-
|
|
109
|
-
|
|
222
|
+
description: `
|
|
223
|
+
Retrieve detailed metadata about a file or directory including:
|
|
224
|
+
- size
|
|
225
|
+
- creation time
|
|
226
|
+
- last modified time
|
|
227
|
+
- permissions
|
|
228
|
+
- type
|
|
229
|
+
- lineCount (for text files)
|
|
230
|
+
- lastLine (zero-indexed number of last line, for text files)
|
|
231
|
+
- appendPosition (line number for appending, for text files)
|
|
232
|
+
|
|
233
|
+
Only works within allowed directories.
|
|
234
|
+
|
|
235
|
+
${PATH_GUIDANCE}
|
|
236
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
110
237
|
inputSchema: zodToJsonSchema(GetFileInfoArgsSchema),
|
|
111
238
|
},
|
|
112
239
|
// Note: list_allowed_directories removed - use get_config to check allowedDirectories
|
|
113
240
|
// Text editing tools
|
|
114
241
|
{
|
|
115
242
|
name: "edit_block",
|
|
116
|
-
description: `
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
243
|
+
description: `
|
|
244
|
+
Apply surgical text replacements to files.
|
|
245
|
+
|
|
246
|
+
BEST PRACTICE: Make multiple small, focused edits rather than one large edit.
|
|
247
|
+
Each edit_block call should change only what needs to be changed - include just enough
|
|
248
|
+
context to uniquely identify the text being modified.
|
|
249
|
+
|
|
250
|
+
Takes:
|
|
251
|
+
- file_path: Path to the file to edit
|
|
252
|
+
- old_string: Text to replace
|
|
253
|
+
- new_string: Replacement text
|
|
254
|
+
- expected_replacements: Optional parameter for number of replacements
|
|
255
|
+
|
|
256
|
+
By default, replaces only ONE occurrence of the search text.
|
|
257
|
+
To replace multiple occurrences, provide the expected_replacements parameter with
|
|
258
|
+
the exact number of matches expected.
|
|
259
|
+
|
|
260
|
+
UNIQUENESS REQUIREMENT: When expected_replacements=1 (default), include the minimal
|
|
261
|
+
amount of context necessary (typically 1-3 lines) before and after the change point,
|
|
262
|
+
with exact whitespace and indentation.
|
|
263
|
+
|
|
264
|
+
When editing multiple sections, make separate edit_block calls for each distinct change
|
|
265
|
+
rather than one large replacement.
|
|
266
|
+
|
|
267
|
+
When a close but non-exact match is found, a character-level diff is shown in the format:
|
|
268
|
+
common_prefix{-removed-}{+added+}common_suffix to help you identify what's different.
|
|
269
|
+
|
|
270
|
+
Similar to write_file, there is a configurable line limit (fileWriteLineLimit) that warns
|
|
271
|
+
if the edited file exceeds this limit. If this happens, consider breaking your edits into
|
|
272
|
+
smaller, more focused changes.
|
|
273
|
+
|
|
274
|
+
${PATH_GUIDANCE}
|
|
275
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
126
276
|
inputSchema: zodToJsonSchema(EditBlockArgsSchema),
|
|
127
277
|
},
|
|
128
278
|
// Terminal tools
|
|
129
279
|
{
|
|
130
280
|
name: "execute_command",
|
|
131
|
-
description: `
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
281
|
+
description: `
|
|
282
|
+
Execute a terminal command with timeout.
|
|
283
|
+
|
|
284
|
+
Command will continue running in background if it doesn't complete within timeout.
|
|
285
|
+
|
|
286
|
+
NOTE: For file operations, prefer specialized tools like read_file, search_code,
|
|
287
|
+
list_directory instead of cat, grep, or ls commands.
|
|
288
|
+
|
|
289
|
+
${PATH_GUIDANCE}
|
|
290
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
135
291
|
inputSchema: zodToJsonSchema(ExecuteCommandArgsSchema),
|
|
136
292
|
},
|
|
137
293
|
{
|
|
138
294
|
name: "read_output",
|
|
139
|
-
description:
|
|
295
|
+
description: `
|
|
296
|
+
Read new output from a running terminal session.
|
|
297
|
+
|
|
298
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
140
299
|
inputSchema: zodToJsonSchema(ReadOutputArgsSchema),
|
|
141
300
|
},
|
|
142
301
|
{
|
|
143
302
|
name: "force_terminate",
|
|
144
|
-
description:
|
|
303
|
+
description: `
|
|
304
|
+
Force terminate a running terminal session.
|
|
305
|
+
|
|
306
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
145
307
|
inputSchema: zodToJsonSchema(ForceTerminateArgsSchema),
|
|
146
308
|
},
|
|
147
309
|
{
|
|
148
310
|
name: "list_sessions",
|
|
149
|
-
description:
|
|
311
|
+
description: `
|
|
312
|
+
List all active terminal sessions.
|
|
313
|
+
|
|
314
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
150
315
|
inputSchema: zodToJsonSchema(ListSessionsArgsSchema),
|
|
151
316
|
},
|
|
152
317
|
{
|
|
153
318
|
name: "list_processes",
|
|
154
|
-
description:
|
|
319
|
+
description: `
|
|
320
|
+
List all running processes.
|
|
321
|
+
|
|
322
|
+
Returns process information including PID, command name, CPU usage, and memory usage.
|
|
323
|
+
|
|
324
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
155
325
|
inputSchema: zodToJsonSchema(ListProcessesArgsSchema),
|
|
156
326
|
},
|
|
157
327
|
{
|
|
158
328
|
name: "kill_process",
|
|
159
|
-
description:
|
|
329
|
+
description: `
|
|
330
|
+
Terminate a running process by PID.
|
|
331
|
+
|
|
332
|
+
Use with caution as this will forcefully terminate the specified process.
|
|
333
|
+
|
|
334
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
160
335
|
inputSchema: zodToJsonSchema(KillProcessArgsSchema),
|
|
161
336
|
},
|
|
162
337
|
],
|
|
@@ -174,6 +349,8 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
|
174
349
|
capture('server_call_tool', {
|
|
175
350
|
name
|
|
176
351
|
});
|
|
352
|
+
// Track tool call
|
|
353
|
+
trackToolCall(name, args);
|
|
177
354
|
// Using a more structured approach with dedicated handlers
|
|
178
355
|
switch (name) {
|
|
179
356
|
// Config tools
|
|
@@ -49,10 +49,38 @@ async function getNpmVersion() {
|
|
|
49
49
|
|
|
50
50
|
const getVersion = async () => {
|
|
51
51
|
try {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
if (process.env.npm_package_version) {
|
|
53
|
+
return process.env.npm_package_version;
|
|
54
|
+
} else {
|
|
55
|
+
const packageJsonPath = join(__dirname, 'package.json');
|
|
56
|
+
if (existsSync(packageJsonPath)) {
|
|
57
|
+
const packageJsonContent = readFileSync(packageJsonPath, 'utf8');
|
|
58
|
+
const packageJson = JSON.parse(packageJsonContent);
|
|
59
|
+
if (packageJson.version) {
|
|
60
|
+
return packageJson.version;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
throw new Error('Version not found in environment variable or package.json');
|
|
66
|
+
} catch (error) {
|
|
67
|
+
try {
|
|
68
|
+
const packageJson = await import('./package.json', { with: { type: 'json' } });
|
|
69
|
+
if (packageJson.default?.version) {
|
|
70
|
+
return packageJson.default.version;
|
|
71
|
+
}
|
|
72
|
+
} catch (importError) {
|
|
73
|
+
// Try older syntax as fallback
|
|
74
|
+
try {
|
|
75
|
+
const packageJson = await import('./package.json', { assert: { type: 'json' } });
|
|
76
|
+
if (packageJson.default?.version) {
|
|
77
|
+
return packageJson.default.version;
|
|
78
|
+
}
|
|
79
|
+
} catch (legacyImportError) {
|
|
80
|
+
// Log the error for debugging
|
|
81
|
+
logToFile(`Failed to import package.json: ${legacyImportError.message}`, true);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
56
84
|
}
|
|
57
85
|
};
|
|
58
86
|
|
|
@@ -385,26 +413,6 @@ function updateSetupStep(index, status, error = null) {
|
|
|
385
413
|
}
|
|
386
414
|
}
|
|
387
415
|
|
|
388
|
-
try {
|
|
389
|
-
// Only dependency is node-machine-id
|
|
390
|
-
const machineIdInitStep = addSetupStep('initialize_machine_id');
|
|
391
|
-
try {
|
|
392
|
-
const machineIdModule = await import('node-machine-id');
|
|
393
|
-
// Get a unique user ID
|
|
394
|
-
uniqueUserId = machineIdModule.machineIdSync();
|
|
395
|
-
updateSetupStep(machineIdInitStep, 'completed');
|
|
396
|
-
} catch (error) {
|
|
397
|
-
// Fall back to a semi-unique identifier if machine-id is not available
|
|
398
|
-
uniqueUserId = `${platform()}-${process.env.USER || process.env.USERNAME || 'unknown'}-${Date.now()}`;
|
|
399
|
-
updateSetupStep(machineIdInitStep, 'fallback', error);
|
|
400
|
-
}
|
|
401
|
-
} catch (error) {
|
|
402
|
-
addSetupStep('initialize_machine_id', 'failed', error);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
416
|
async function execAsync(command) {
|
|
409
417
|
const execStep = addSetupStep(`exec_${command.substring(0, 20)}...`);
|
|
410
418
|
return new Promise((resolve, reject) => {
|
|
@@ -696,8 +704,8 @@ export default async function setup() {
|
|
|
696
704
|
await trackEvent('npx_setup_update_config_error', { error: updateError.message });
|
|
697
705
|
throw new Error(`Failed to update config: ${updateError.message}`);
|
|
698
706
|
}
|
|
699
|
-
|
|
700
|
-
logToFile(
|
|
707
|
+
const appVersion = await getVersion()
|
|
708
|
+
logToFile(`Successfully added Desktop Commander MCP v${appVersion} server to Claude configuration!`);
|
|
701
709
|
logToFile(`Configuration location: ${claudeConfigPath}`);
|
|
702
710
|
|
|
703
711
|
if (debugMode) {
|
package/dist/tools/edit.js
CHANGED
|
@@ -4,6 +4,8 @@ import { capture } from '../utils/capture.js';
|
|
|
4
4
|
import { EditBlockArgsSchema } from "./schemas.js";
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { detectLineEnding, normalizeLineEndings } from '../utils/lineEndingHandler.js';
|
|
7
|
+
import { configManager } from '../config-manager.js';
|
|
8
|
+
import { fuzzySearchLogger } from '../utils/fuzzySearchLogger.js';
|
|
7
9
|
/**
|
|
8
10
|
* Threshold for fuzzy matching - similarity must be at least this value to be considered
|
|
9
11
|
* (0-1 scale where 1 is perfect match and 0 is completely different)
|
|
@@ -73,14 +75,24 @@ export async function performSearchReplace(filePath, block, expectedReplacements
|
|
|
73
75
|
}
|
|
74
76
|
// Get file extension for telemetry using path module
|
|
75
77
|
const fileExtension = path.extname(filePath).toLowerCase();
|
|
76
|
-
// Capture file extension in telemetry without capturing the file path
|
|
77
|
-
capture('server_edit_block', {
|
|
78
|
+
// Capture file extension and string sizes in telemetry without capturing the file path
|
|
79
|
+
capture('server_edit_block', {
|
|
80
|
+
fileExtension: fileExtension,
|
|
81
|
+
oldStringLength: block.search.length,
|
|
82
|
+
oldStringLines: block.search.split('\n').length,
|
|
83
|
+
newStringLength: block.replace.length,
|
|
84
|
+
newStringLines: block.replace.split('\n').length,
|
|
85
|
+
expectedReplacements: expectedReplacements
|
|
86
|
+
});
|
|
78
87
|
// Read file as plain string
|
|
79
|
-
const { content } = await readFile(filePath);
|
|
88
|
+
const { content } = await readFile(filePath, false, 0, Number.MAX_SAFE_INTEGER);
|
|
80
89
|
// Make sure content is a string
|
|
81
90
|
if (typeof content !== 'string') {
|
|
82
91
|
throw new Error('Wrong content for file ' + filePath);
|
|
83
92
|
}
|
|
93
|
+
// Get the line limit from configuration
|
|
94
|
+
const config = await configManager.getConfig();
|
|
95
|
+
const MAX_LINES = config.fileWriteLineLimit ?? 50; // Default to 50 if not set
|
|
84
96
|
// Detect file's line ending style
|
|
85
97
|
const fileLineEnding = detectLineEnding(content);
|
|
86
98
|
// Normalize search string to match file's line endings
|
|
@@ -109,11 +121,22 @@ export async function performSearchReplace(filePath, block, expectedReplacements
|
|
|
109
121
|
// Replace all occurrences using split and join for multiple replacements
|
|
110
122
|
newContent = newContent.split(normalizedSearch).join(normalizeLineEndings(block.replace, fileLineEnding));
|
|
111
123
|
}
|
|
124
|
+
// Check if search or replace text has too many lines
|
|
125
|
+
const searchLines = block.search.split('\n').length;
|
|
126
|
+
const replaceLines = block.replace.split('\n').length;
|
|
127
|
+
const maxLines = Math.max(searchLines, replaceLines);
|
|
128
|
+
let warningMessage = "";
|
|
129
|
+
if (maxLines > MAX_LINES) {
|
|
130
|
+
const problemText = searchLines > replaceLines ? 'search text' : 'replacement text';
|
|
131
|
+
warningMessage = `\n\nWARNING: The ${problemText} has ${maxLines} lines (maximum: ${MAX_LINES}).
|
|
132
|
+
|
|
133
|
+
RECOMMENDATION: For large search/replace operations, consider breaking them into smaller chunks with fewer lines.`;
|
|
134
|
+
}
|
|
112
135
|
await writeFile(filePath, newContent);
|
|
113
136
|
return {
|
|
114
137
|
content: [{
|
|
115
138
|
type: "text",
|
|
116
|
-
text: `Successfully applied ${expectedReplacements} edit${expectedReplacements > 1 ? 's' : ''} to ${filePath}`
|
|
139
|
+
text: `Successfully applied ${expectedReplacements} edit${expectedReplacements > 1 ? 's' : ''} to ${filePath}${warningMessage}`
|
|
117
140
|
}],
|
|
118
141
|
};
|
|
119
142
|
}
|
|
@@ -142,6 +165,27 @@ export async function performSearchReplace(filePath, block, expectedReplacements
|
|
|
142
165
|
const diff = highlightDifferences(block.search, fuzzyResult.value);
|
|
143
166
|
// Count character codes in diff
|
|
144
167
|
const characterCodeData = getCharacterCodeData(block.search, fuzzyResult.value);
|
|
168
|
+
// Create comprehensive log entry
|
|
169
|
+
const logEntry = {
|
|
170
|
+
timestamp: new Date(),
|
|
171
|
+
searchText: block.search,
|
|
172
|
+
foundText: fuzzyResult.value,
|
|
173
|
+
similarity: similarity,
|
|
174
|
+
executionTime: executionTime,
|
|
175
|
+
exactMatchCount: count,
|
|
176
|
+
expectedReplacements: expectedReplacements,
|
|
177
|
+
fuzzyThreshold: FUZZY_THRESHOLD,
|
|
178
|
+
belowThreshold: similarity < FUZZY_THRESHOLD,
|
|
179
|
+
diff: diff,
|
|
180
|
+
searchLength: block.search.length,
|
|
181
|
+
foundLength: fuzzyResult.value.length,
|
|
182
|
+
fileExtension: fileExtension,
|
|
183
|
+
characterCodes: characterCodeData.report,
|
|
184
|
+
uniqueCharacterCount: characterCodeData.uniqueCount,
|
|
185
|
+
diffLength: characterCodeData.diffLength
|
|
186
|
+
};
|
|
187
|
+
// Log to file
|
|
188
|
+
await fuzzySearchLogger.log(logEntry);
|
|
145
189
|
// Combine all fuzzy search data for single capture
|
|
146
190
|
const fuzzySearchData = {
|
|
147
191
|
similarity: similarity,
|
|
@@ -165,8 +209,10 @@ export async function performSearchReplace(filePath, block, expectedReplacements
|
|
|
165
209
|
type: "text",
|
|
166
210
|
text: `Exact match not found, but found a similar text with ${Math.round(similarity * 100)}% similarity (found in ${executionTime.toFixed(2)}ms):\n\n` +
|
|
167
211
|
`Differences:\n${diff}\n\n` +
|
|
168
|
-
`To replace this text, use the exact text found in the file
|
|
169
|
-
|
|
212
|
+
`To replace this text, use the exact text found in the file.\n\n` +
|
|
213
|
+
`Log entry saved for analysis. Use the following command to check the log:\n` +
|
|
214
|
+
`Check log: ${await fuzzySearchLogger.getLogPath()}`
|
|
215
|
+
}], // TODO
|
|
170
216
|
};
|
|
171
217
|
}
|
|
172
218
|
else {
|
|
@@ -181,7 +227,9 @@ export async function performSearchReplace(filePath, block, expectedReplacements
|
|
|
181
227
|
type: "text",
|
|
182
228
|
text: `Search content not found in ${filePath}. The closest match was "${fuzzyResult.value}" ` +
|
|
183
229
|
`with only ${Math.round(similarity * 100)}% similarity, which is below the ${Math.round(FUZZY_THRESHOLD * 100)}% threshold. ` +
|
|
184
|
-
`(Fuzzy search completed in ${executionTime.toFixed(2)}ms)`
|
|
230
|
+
`(Fuzzy search completed in ${executionTime.toFixed(2)}ms)\n\n` +
|
|
231
|
+
`Log entry saved for analysis. Use the following command to check the log:\n` +
|
|
232
|
+
`Check log: ${await fuzzySearchLogger.getLogPath()}`
|
|
185
233
|
}],
|
|
186
234
|
};
|
|
187
235
|
}
|
|
@@ -22,19 +22,21 @@ export declare function readFileFromUrl(url: string): Promise<FileResult>;
|
|
|
22
22
|
/**
|
|
23
23
|
* Read file content from the local filesystem
|
|
24
24
|
* @param filePath Path to the file
|
|
25
|
-
* @param
|
|
25
|
+
* @param offset Starting line number to read from (default: 0)
|
|
26
|
+
* @param length Maximum number of lines to read (default: from config or 1000)
|
|
26
27
|
* @returns File content or file result with metadata
|
|
27
28
|
*/
|
|
28
|
-
export declare function readFileFromDisk(filePath: string): Promise<FileResult>;
|
|
29
|
+
export declare function readFileFromDisk(filePath: string, offset?: number, length?: number): Promise<FileResult>;
|
|
29
30
|
/**
|
|
30
31
|
* Read a file from either the local filesystem or a URL
|
|
31
32
|
* @param filePath Path to the file or URL
|
|
32
|
-
* @param returnMetadata Whether to return metadata with the content
|
|
33
33
|
* @param isUrl Whether the path is a URL
|
|
34
|
+
* @param offset Starting line number to read from (default: 0)
|
|
35
|
+
* @param length Maximum number of lines to read (default: from config or 1000)
|
|
34
36
|
* @returns File content or file result with metadata
|
|
35
37
|
*/
|
|
36
|
-
export declare function readFile(filePath: string, isUrl?: boolean): Promise<FileResult>;
|
|
37
|
-
export declare function writeFile(filePath: string, content: string): Promise<void>;
|
|
38
|
+
export declare function readFile(filePath: string, isUrl?: boolean, offset?: number, length?: number): Promise<FileResult>;
|
|
39
|
+
export declare function writeFile(filePath: string, content: string, mode?: 'rewrite' | 'append'): Promise<void>;
|
|
38
40
|
export interface MultiFileResult {
|
|
39
41
|
path: string;
|
|
40
42
|
content?: string;
|