@wonderwhy-er/desktop-commander 0.2.0 → 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/dist/config-manager.js +2 -0
- package/dist/server.js +208 -49
- package/dist/setup-claude-server.js +34 -6
- package/dist/tools/edit.js +9 -2
- package/dist/tools/filesystem.js +51 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/config-manager.js
CHANGED
|
@@ -3,6 +3,7 @@ import path from 'path';
|
|
|
3
3
|
import { existsSync } from 'fs';
|
|
4
4
|
import { mkdir } from 'fs/promises';
|
|
5
5
|
import os from 'os';
|
|
6
|
+
import { VERSION } from './version.js';
|
|
6
7
|
import { CONFIG_FILE } from './config.js';
|
|
7
8
|
/**
|
|
8
9
|
* Singleton config manager for the server
|
|
@@ -39,6 +40,7 @@ class ConfigManager {
|
|
|
39
40
|
this.config = this.getDefaultConfig();
|
|
40
41
|
await this.saveConfig();
|
|
41
42
|
}
|
|
43
|
+
this.config['version'] = VERSION;
|
|
42
44
|
this.initialized = true;
|
|
43
45
|
}
|
|
44
46
|
catch (error) {
|
package/dist/server.js
CHANGED
|
@@ -43,136 +43,295 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
|
43
43
|
// Configuration tools
|
|
44
44
|
{
|
|
45
45
|
name: "get_config",
|
|
46
|
-
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}`,
|
|
47
56
|
inputSchema: zodToJsonSchema(GetConfigArgsSchema),
|
|
48
57
|
},
|
|
49
58
|
{
|
|
50
59
|
name: "set_config_value",
|
|
51
|
-
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}`,
|
|
52
78
|
inputSchema: zodToJsonSchema(SetConfigValueArgsSchema),
|
|
53
79
|
},
|
|
54
80
|
// Filesystem tools
|
|
55
81
|
{
|
|
56
82
|
name: "read_file",
|
|
57
|
-
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}`,
|
|
58
101
|
inputSchema: zodToJsonSchema(ReadFileArgsSchema),
|
|
59
102
|
},
|
|
60
103
|
{
|
|
61
104
|
name: "read_multiple_files",
|
|
62
|
-
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}`,
|
|
63
117
|
inputSchema: zodToJsonSchema(ReadMultipleFilesArgsSchema),
|
|
64
118
|
},
|
|
65
119
|
{
|
|
66
120
|
name: "write_file",
|
|
67
|
-
description: `
|
|
68
|
-
|
|
69
|
-
|
|
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.
|
|
70
124
|
|
|
71
|
-
REQUIRED
|
|
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:
|
|
72
133
|
1. FIRST → write_file(filePath, firstChunk, {mode: 'rewrite'})
|
|
73
134
|
2. THEN → write_file(filePath, secondChunk, {mode: 'append'})
|
|
74
135
|
3. THEN → write_file(filePath, thirdChunk, {mode: 'append'})
|
|
75
136
|
... and so on for each chunk
|
|
76
137
|
|
|
77
|
-
|
|
78
|
-
|
|
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
|
+
|
|
79
145
|
Files over the line limit (configurable via 'fileWriteLineLimit' setting) WILL BE REJECTED if not broken into chunks as described above.
|
|
80
|
-
Only works within allowed directories.
|
|
146
|
+
Only works within allowed directories.
|
|
147
|
+
|
|
148
|
+
${PATH_GUIDANCE}
|
|
149
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
81
150
|
inputSchema: zodToJsonSchema(WriteFileArgsSchema),
|
|
82
151
|
},
|
|
83
152
|
{
|
|
84
153
|
name: "create_directory",
|
|
85
|
-
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}`,
|
|
86
162
|
inputSchema: zodToJsonSchema(CreateDirectoryArgsSchema),
|
|
87
163
|
},
|
|
88
164
|
{
|
|
89
165
|
name: "list_directory",
|
|
90
|
-
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}`,
|
|
91
175
|
inputSchema: zodToJsonSchema(ListDirectoryArgsSchema),
|
|
92
176
|
},
|
|
93
177
|
{
|
|
94
178
|
name: "move_file",
|
|
95
|
-
description: `
|
|
96
|
-
|
|
97
|
-
|
|
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}`,
|
|
98
187
|
inputSchema: zodToJsonSchema(MoveFileArgsSchema),
|
|
99
188
|
},
|
|
100
189
|
{
|
|
101
190
|
name: "search_files",
|
|
102
|
-
description: `
|
|
191
|
+
description: `
|
|
192
|
+
Finds files by name using a case-insensitive substring matching.
|
|
193
|
+
|
|
103
194
|
Use this instead of 'execute_command' with find/dir/ls for locating files.
|
|
104
|
-
Searches through all subdirectories from the starting path.
|
|
105
|
-
|
|
106
|
-
|
|
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}`,
|
|
107
202
|
inputSchema: zodToJsonSchema(SearchFilesArgsSchema),
|
|
108
203
|
},
|
|
109
204
|
{
|
|
110
205
|
name: "search_code",
|
|
111
|
-
description: `
|
|
206
|
+
description: `
|
|
207
|
+
Search for text/code patterns within file contents using ripgrep.
|
|
208
|
+
|
|
112
209
|
Use this instead of 'execute_command' with grep/find for searching code content.
|
|
113
|
-
Fast and powerful search similar to VS Code search functionality.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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}`,
|
|
118
218
|
inputSchema: zodToJsonSchema(SearchCodeArgsSchema),
|
|
119
219
|
},
|
|
120
220
|
{
|
|
121
221
|
name: "get_file_info",
|
|
122
|
-
description: `
|
|
123
|
-
|
|
124
|
-
|
|
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}`,
|
|
125
237
|
inputSchema: zodToJsonSchema(GetFileInfoArgsSchema),
|
|
126
238
|
},
|
|
127
239
|
// Note: list_allowed_directories removed - use get_config to check allowedDirectories
|
|
128
240
|
// Text editing tools
|
|
129
241
|
{
|
|
130
242
|
name: "edit_block",
|
|
131
|
-
description: `
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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}`,
|
|
142
276
|
inputSchema: zodToJsonSchema(EditBlockArgsSchema),
|
|
143
277
|
},
|
|
144
278
|
// Terminal tools
|
|
145
279
|
{
|
|
146
280
|
name: "execute_command",
|
|
147
|
-
description: `
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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}`,
|
|
151
291
|
inputSchema: zodToJsonSchema(ExecuteCommandArgsSchema),
|
|
152
292
|
},
|
|
153
293
|
{
|
|
154
294
|
name: "read_output",
|
|
155
|
-
description: `
|
|
295
|
+
description: `
|
|
296
|
+
Read new output from a running terminal session.
|
|
297
|
+
|
|
298
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
156
299
|
inputSchema: zodToJsonSchema(ReadOutputArgsSchema),
|
|
157
300
|
},
|
|
158
301
|
{
|
|
159
302
|
name: "force_terminate",
|
|
160
|
-
description: `
|
|
303
|
+
description: `
|
|
304
|
+
Force terminate a running terminal session.
|
|
305
|
+
|
|
306
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
161
307
|
inputSchema: zodToJsonSchema(ForceTerminateArgsSchema),
|
|
162
308
|
},
|
|
163
309
|
{
|
|
164
310
|
name: "list_sessions",
|
|
165
|
-
description: `
|
|
311
|
+
description: `
|
|
312
|
+
List all active terminal sessions.
|
|
313
|
+
|
|
314
|
+
${CMD_PREFIX_DESCRIPTION}`,
|
|
166
315
|
inputSchema: zodToJsonSchema(ListSessionsArgsSchema),
|
|
167
316
|
},
|
|
168
317
|
{
|
|
169
318
|
name: "list_processes",
|
|
170
|
-
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}`,
|
|
171
325
|
inputSchema: zodToJsonSchema(ListProcessesArgsSchema),
|
|
172
326
|
},
|
|
173
327
|
{
|
|
174
328
|
name: "kill_process",
|
|
175
|
-
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}`,
|
|
176
335
|
inputSchema: zodToJsonSchema(KillProcessArgsSchema),
|
|
177
336
|
},
|
|
178
337
|
],
|
|
@@ -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
|
|
|
@@ -676,8 +704,8 @@ export default async function setup() {
|
|
|
676
704
|
await trackEvent('npx_setup_update_config_error', { error: updateError.message });
|
|
677
705
|
throw new Error(`Failed to update config: ${updateError.message}`);
|
|
678
706
|
}
|
|
679
|
-
|
|
680
|
-
logToFile(
|
|
707
|
+
const appVersion = await getVersion()
|
|
708
|
+
logToFile(`Successfully added Desktop Commander MCP v${appVersion} server to Claude configuration!`);
|
|
681
709
|
logToFile(`Configuration location: ${claudeConfigPath}`);
|
|
682
710
|
|
|
683
711
|
if (debugMode) {
|
package/dist/tools/edit.js
CHANGED
|
@@ -75,8 +75,15 @@ export async function performSearchReplace(filePath, block, expectedReplacements
|
|
|
75
75
|
}
|
|
76
76
|
// Get file extension for telemetry using path module
|
|
77
77
|
const fileExtension = path.extname(filePath).toLowerCase();
|
|
78
|
-
// Capture file extension in telemetry without capturing the file path
|
|
79
|
-
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
|
+
});
|
|
80
87
|
// Read file as plain string
|
|
81
88
|
const { content } = await readFile(filePath, false, 0, Number.MAX_SAFE_INTEGER);
|
|
82
89
|
// Make sure content is a string
|
package/dist/tools/filesystem.js
CHANGED
|
@@ -266,15 +266,32 @@ export async function readFileFromDisk(filePath, offset = 0, length) {
|
|
|
266
266
|
// Split into lines for line-based access
|
|
267
267
|
const lines = fullContent.split('\n');
|
|
268
268
|
const totalLines = lines.length;
|
|
269
|
-
// Apply line-based offset and length
|
|
270
|
-
|
|
271
|
-
|
|
269
|
+
// Apply line-based offset and length - handle beyond-file-size scenario
|
|
270
|
+
let startLine = Math.min(offset, totalLines);
|
|
271
|
+
let endLine = Math.min(startLine + length, totalLines);
|
|
272
|
+
// If startLine equals totalLines (reading beyond end), adjust to show some content
|
|
273
|
+
// Only do this if we're not trying to read the whole file
|
|
274
|
+
if (startLine === totalLines && offset > 0 && length < Number.MAX_SAFE_INTEGER) {
|
|
275
|
+
// Show last few lines instead of nothing
|
|
276
|
+
const lastLinesCount = Math.min(10, totalLines); // Show last 10 lines or fewer if file is smaller
|
|
277
|
+
startLine = Math.max(0, totalLines - lastLinesCount);
|
|
278
|
+
endLine = totalLines;
|
|
279
|
+
}
|
|
272
280
|
const selectedLines = lines.slice(startLine, endLine);
|
|
273
281
|
const truncatedContent = selectedLines.join('\n');
|
|
274
|
-
// Add an informational message if truncated
|
|
282
|
+
// Add an informational message if truncated or adjusted
|
|
275
283
|
let content = truncatedContent;
|
|
276
|
-
|
|
277
|
-
|
|
284
|
+
// Only add informational message for normal reads (not when reading entire file)
|
|
285
|
+
const isEntireFileRead = offset === 0 && length >= Number.MAX_SAFE_INTEGER;
|
|
286
|
+
if (!isEntireFileRead) {
|
|
287
|
+
if (offset >= totalLines && totalLines > 0) {
|
|
288
|
+
// Reading beyond end of file case
|
|
289
|
+
content = `[NOTICE: Offset ${offset} exceeds file length (${totalLines} lines). Showing last ${endLine - startLine} lines instead.]\n\n${truncatedContent}`;
|
|
290
|
+
}
|
|
291
|
+
else if (offset > 0 || endLine < totalLines) {
|
|
292
|
+
// Normal partial read case
|
|
293
|
+
content = `[Reading ${endLine - startLine} lines from line ${startLine} of ${totalLines} total lines]\n\n${truncatedContent}`;
|
|
294
|
+
}
|
|
278
295
|
}
|
|
279
296
|
return { content, mimeType, isImage };
|
|
280
297
|
}
|
|
@@ -311,10 +328,15 @@ export async function writeFile(filePath, content, mode = 'rewrite') {
|
|
|
311
328
|
const validPath = await validatePath(filePath);
|
|
312
329
|
// Get file extension for telemetry
|
|
313
330
|
const fileExtension = path.extname(validPath).toLowerCase();
|
|
331
|
+
// Calculate content metrics
|
|
332
|
+
const contentBytes = Buffer.from(content).length;
|
|
333
|
+
const lineCount = content.split('\n').length;
|
|
314
334
|
// Capture file extension and operation details in telemetry without capturing the file path
|
|
315
335
|
capture('server_write_file', {
|
|
316
336
|
fileExtension: fileExtension,
|
|
317
337
|
mode: mode,
|
|
338
|
+
contentBytes: contentBytes,
|
|
339
|
+
lineCount: lineCount
|
|
318
340
|
});
|
|
319
341
|
// Use different fs methods based on mode
|
|
320
342
|
if (mode === 'append') {
|
|
@@ -416,7 +438,8 @@ export async function searchFiles(rootPath, pattern) {
|
|
|
416
438
|
export async function getFileInfo(filePath) {
|
|
417
439
|
const validPath = await validatePath(filePath);
|
|
418
440
|
const stats = await fs.stat(validPath);
|
|
419
|
-
|
|
441
|
+
// Basic file info
|
|
442
|
+
const info = {
|
|
420
443
|
size: stats.size,
|
|
421
444
|
created: stats.birthtime,
|
|
422
445
|
modified: stats.mtime,
|
|
@@ -425,6 +448,27 @@ export async function getFileInfo(filePath) {
|
|
|
425
448
|
isFile: stats.isFile(),
|
|
426
449
|
permissions: stats.mode.toString(8).slice(-3),
|
|
427
450
|
};
|
|
451
|
+
// For text files that aren't too large, also count lines
|
|
452
|
+
if (stats.isFile() && stats.size < 10 * 1024 * 1024) { // Limit to 10MB files
|
|
453
|
+
try {
|
|
454
|
+
// Import the MIME type utilities
|
|
455
|
+
const { getMimeType, isImageFile } = await import('./mime-types.js');
|
|
456
|
+
const mimeType = getMimeType(validPath);
|
|
457
|
+
// Only count lines for non-image, likely text files
|
|
458
|
+
if (!isImageFile(mimeType)) {
|
|
459
|
+
const content = await fs.readFile(validPath, 'utf8');
|
|
460
|
+
const lineCount = content.split('\n').length;
|
|
461
|
+
info.lineCount = lineCount;
|
|
462
|
+
info.lastLine = lineCount - 1; // Zero-indexed last line
|
|
463
|
+
info.appendPosition = lineCount; // Position to append at end
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
catch (error) {
|
|
467
|
+
// If reading fails, just skip the line count
|
|
468
|
+
// This could happen for binary files or very large files
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return info;
|
|
428
472
|
}
|
|
429
473
|
// This function has been replaced with configManager.getConfig()
|
|
430
474
|
// Use get_config tool to retrieve allowedDirectories
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.2.
|
|
1
|
+
export declare const VERSION = "0.2.1";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.2.
|
|
1
|
+
export const VERSION = '0.2.1';
|