@wonderwhy-er/desktop-commander 0.2.52 → 0.3.1-alpha.0
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/command-manager.d.ts +7 -2
- package/dist/command-manager.js +16 -11
- package/dist/config-manager.d.ts +49 -3
- package/dist/config-manager.js +329 -87
- package/dist/config-recovery.d.ts +28 -0
- package/dist/config-recovery.js +81 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.js +9 -0
- package/dist/handlers/filesystem-handlers.d.ts +1 -1
- package/dist/handlers/filesystem-handlers.js +26 -16
- package/dist/handlers/search-answers.d.ts +58 -0
- package/dist/handlers/search-answers.js +172 -0
- package/dist/handlers/search-handlers.js +4 -92
- package/dist/index.js +14 -7
- package/dist/npm-scripts/remote.js +2 -3
- package/dist/remote-device/broadcast-analytics.d.ts +28 -0
- package/dist/remote-device/broadcast-analytics.js +41 -0
- package/dist/remote-device/desktop-commander-integration.js +19 -25
- package/dist/remote-device/device.d.ts +14 -0
- package/dist/remote-device/device.js +137 -30
- package/dist/remote-device/mqtt-enrollment.d.ts +16 -0
- package/dist/remote-device/mqtt-enrollment.js +162 -0
- package/dist/remote-device/mqtt-transport.d.ts +44 -0
- package/dist/remote-device/mqtt-transport.js +197 -0
- package/dist/remote-device/remote-channel.d.ts +12 -0
- package/dist/remote-device/remote-channel.js +55 -8
- package/dist/remote-device/scripts/blocking-offline-update.js +106 -69
- package/dist/remote-device/transport-analytics.d.ts +29 -0
- package/dist/remote-device/transport-analytics.js +44 -0
- package/dist/remote-device/transport-telemetry.d.ts +32 -0
- package/dist/remote-device/transport-telemetry.js +48 -0
- package/dist/search-manager.d.ts +239 -27
- package/dist/search-manager.js +746 -312
- package/dist/server.js +44 -11
- package/dist/terminal-manager.d.ts +138 -21
- package/dist/terminal-manager.js +300 -215
- package/dist/tools/config.d.ts +1 -1
- package/dist/tools/config.js +21 -70
- package/dist/tools/edit.js +12 -4
- package/dist/tools/filesystem.d.ts +30 -6
- package/dist/tools/filesystem.js +246 -140
- package/dist/tools/improved-process-tools.d.ts +9 -3
- package/dist/tools/improved-process-tools.js +171 -68
- package/dist/tools/pdf/extract-images.d.ts +2 -0
- package/dist/tools/pdf/extract-images.js +4 -1
- package/dist/tools/pdf/index.d.ts +5 -3
- package/dist/tools/pdf/index.js +4 -3
- package/dist/tools/pdf/lib/pdf2md.d.ts +8 -1
- package/dist/tools/pdf/lib/pdf2md.js +12 -5
- package/dist/tools/pdf/manipulations.d.ts +12 -1
- package/dist/tools/pdf/manipulations.js +17 -4
- package/dist/tools/pdf/markdown.d.ts +96 -0
- package/dist/tools/pdf/markdown.js +485 -20
- package/dist/tools/pdf/utils.d.ts +2 -2
- package/dist/tools/pdf/utils.js +4 -4
- package/dist/tools/process.js +8 -5
- package/dist/tools/schemas.d.ts +1 -1
- package/dist/tools/schemas.js +15 -6
- package/dist/tools/search.d.ts +32 -0
- package/dist/tools/search.js +202 -0
- package/dist/types.d.ts +1 -1
- package/dist/ui/config-editor/config-editor-runtime.js +6 -6
- package/dist/ui/config-editor/src/app.js +2 -15
- package/dist/utils/ab-test.js +27 -9
- package/dist/utils/atomic-write.d.ts +14 -0
- package/dist/utils/atomic-write.js +80 -0
- package/dist/utils/capture.d.ts +17 -1
- package/dist/utils/capture.js +177 -68
- package/dist/utils/exit-process.d.ts +24 -0
- package/dist/utils/exit-process.js +31 -0
- package/dist/utils/feature-flags.js +2 -1
- package/dist/utils/files/base.d.ts +3 -1
- package/dist/utils/files/docx.d.ts +3 -0
- package/dist/utils/files/docx.js +24 -9
- package/dist/utils/files/excel.d.ts +10 -0
- package/dist/utils/files/excel.js +93 -33
- package/dist/utils/files/factory.d.ts +22 -1
- package/dist/utils/files/factory.js +59 -4
- package/dist/utils/files/image.d.ts +12 -4
- package/dist/utils/files/image.js +19 -8
- package/dist/utils/files/index.d.ts +5 -3
- package/dist/utils/files/index.js +4 -3
- package/dist/utils/files/pdf.js +18 -36
- package/dist/utils/files/text.d.ts +21 -5
- package/dist/utils/files/text.js +90 -86
- package/dist/utils/internal-facts.d.ts +3 -0
- package/dist/utils/internal-facts.js +23 -0
- package/dist/utils/lazy-package.d.ts +23 -0
- package/dist/utils/lazy-package.js +42 -0
- package/dist/utils/open-browser.js +2 -1
- package/dist/utils/process-detection.d.ts +24 -5
- package/dist/utils/process-detection.js +199 -89
- package/dist/utils/process-tree.d.ts +14 -0
- package/dist/utils/process-tree.js +223 -0
- package/dist/utils/rename.d.ts +9 -0
- package/dist/utils/rename.js +74 -0
- package/dist/utils/ripgrep-resolver.js +9 -14
- package/dist/utils/shell.d.ts +42 -0
- package/dist/utils/shell.js +187 -0
- package/dist/utils/system-info.js +9 -7
- package/dist/utils/trackTools.js +2 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -0
- package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -0
- package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +38 -0
- package/node_modules/@desktop-commander/telemetry-contract/transport.js +164 -0
- package/package.json +8 -2
- package/vendor/telemetry-contract/README.md +56 -0
- package/vendor/telemetry-contract/package.json +32 -0
- package/vendor/telemetry-contract/transport.d.ts +38 -0
- package/vendor/telemetry-contract/transport.js +164 -0
- package/vendor/telemetry-contract/transport.test.js +39 -0
package/dist/tools/schemas.js
CHANGED
|
@@ -41,7 +41,10 @@ export const ForceTerminateArgsSchema = z.object({
|
|
|
41
41
|
});
|
|
42
42
|
export const ListSessionsArgsSchema = z.object({});
|
|
43
43
|
export const KillProcessArgsSchema = z.object({
|
|
44
|
-
|
|
44
|
+
// process.kill reads 0 and negative PIDs as process groups: 0 is the server's
|
|
45
|
+
// own (on Windows the server itself), -1 every process the user may signal.
|
|
46
|
+
// A refinement rather than .positive(), so the published schema is unchanged.
|
|
47
|
+
pid: z.number().refine((pid) => pid > 0, { message: 'Number must be greater than 0' }),
|
|
45
48
|
});
|
|
46
49
|
// Filesystem tools schemas
|
|
47
50
|
export const ReadFileArgsSchema = z.object({
|
|
@@ -161,6 +164,12 @@ export const GiveFeedbackArgsSchema = z.object({
|
|
|
161
164
|
// - platform (auto)
|
|
162
165
|
// - client_id (auto)
|
|
163
166
|
});
|
|
167
|
+
/** A whole number (at least `min`, if given), rejected with a message that says so */
|
|
168
|
+
function wholeNumber(name, min) {
|
|
169
|
+
const message = `${name} must be a whole number${min === undefined ? '' : ` of at least ${min}`}`;
|
|
170
|
+
const number = z.number().int({ message });
|
|
171
|
+
return min === undefined ? number : number.min(min, { message });
|
|
172
|
+
}
|
|
164
173
|
// Search schemas (renamed for natural language)
|
|
165
174
|
export const StartSearchArgsSchema = z.object({
|
|
166
175
|
path: z.string(),
|
|
@@ -168,10 +177,10 @@ export const StartSearchArgsSchema = z.object({
|
|
|
168
177
|
searchType: z.enum(['files', 'content']).default('files'),
|
|
169
178
|
filePattern: z.string().optional(),
|
|
170
179
|
ignoreCase: z.boolean().optional().default(true),
|
|
171
|
-
maxResults:
|
|
180
|
+
maxResults: wholeNumber('maxResults', 0).optional(), // 0: no limit
|
|
172
181
|
includeHidden: z.boolean().optional().default(false),
|
|
173
|
-
contextLines:
|
|
174
|
-
timeout_ms:
|
|
182
|
+
contextLines: wholeNumber('contextLines', 0).optional().default(5),
|
|
183
|
+
timeout_ms: wholeNumber('timeout_ms', 0).optional(), // Match process naming convention; 0: no time limit
|
|
175
184
|
earlyTermination: z.boolean().optional(), // Stop search early when exact filename match is found (default: true for files, false for content)
|
|
176
185
|
literalSearch: z.boolean().optional().default(false), // Force literal string matching (-F flag) instead of regex
|
|
177
186
|
// 'ui' marks widget-fired calls (e.g. markdown link-target search);
|
|
@@ -180,8 +189,8 @@ export const StartSearchArgsSchema = z.object({
|
|
|
180
189
|
});
|
|
181
190
|
export const GetMoreSearchResultsArgsSchema = z.object({
|
|
182
191
|
sessionId: z.string(),
|
|
183
|
-
offset:
|
|
184
|
-
length:
|
|
192
|
+
offset: wholeNumber('offset').optional().default(0), // Same as file reading
|
|
193
|
+
length: wholeNumber('length', 1).optional().default(100), // Same as file reading (but smaller default)
|
|
185
194
|
});
|
|
186
195
|
export const StopSearchArgsSchema = z.object({
|
|
187
196
|
sessionId: z.string(),
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface SearchResult {
|
|
2
|
+
file: string;
|
|
3
|
+
line: number;
|
|
4
|
+
match: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function searchCode(options: {
|
|
7
|
+
rootPath: string;
|
|
8
|
+
pattern: string;
|
|
9
|
+
filePattern?: string;
|
|
10
|
+
ignoreCase?: boolean;
|
|
11
|
+
maxResults?: number;
|
|
12
|
+
includeHidden?: boolean;
|
|
13
|
+
contextLines?: number;
|
|
14
|
+
}): Promise<SearchResult[]>;
|
|
15
|
+
export declare function searchCodeFallback(options: {
|
|
16
|
+
rootPath: string;
|
|
17
|
+
pattern: string;
|
|
18
|
+
filePattern?: string;
|
|
19
|
+
ignoreCase?: boolean;
|
|
20
|
+
maxResults?: number;
|
|
21
|
+
excludeDirs?: string[];
|
|
22
|
+
contextLines?: number;
|
|
23
|
+
}): Promise<SearchResult[]>;
|
|
24
|
+
export declare function searchTextInFiles(options: {
|
|
25
|
+
rootPath: string;
|
|
26
|
+
pattern: string;
|
|
27
|
+
filePattern?: string;
|
|
28
|
+
ignoreCase?: boolean;
|
|
29
|
+
maxResults?: number;
|
|
30
|
+
includeHidden?: boolean;
|
|
31
|
+
contextLines?: number;
|
|
32
|
+
}): Promise<SearchResult[]>;
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { spawn } from 'child_process';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import fs from 'fs/promises';
|
|
4
|
+
import { validatePath } from './filesystem.js';
|
|
5
|
+
import { rgPath } from '@vscode/ripgrep';
|
|
6
|
+
import { capture } from "../utils/capture.js";
|
|
7
|
+
// Function to search file contents using ripgrep
|
|
8
|
+
export async function searchCode(options) {
|
|
9
|
+
const { rootPath, pattern, filePattern, ignoreCase = true, maxResults = 1000, includeHidden = false, contextLines = 0 } = options;
|
|
10
|
+
// Validate path for security
|
|
11
|
+
const validPath = await validatePath(rootPath);
|
|
12
|
+
// Build command arguments
|
|
13
|
+
const args = [
|
|
14
|
+
'--json', // Output in JSON format for easier parsing
|
|
15
|
+
'--line-number', // Include line numbers
|
|
16
|
+
];
|
|
17
|
+
if (ignoreCase) {
|
|
18
|
+
args.push('-i');
|
|
19
|
+
}
|
|
20
|
+
if (maxResults) {
|
|
21
|
+
args.push('-m', maxResults.toString());
|
|
22
|
+
}
|
|
23
|
+
if (includeHidden) {
|
|
24
|
+
args.push('--hidden');
|
|
25
|
+
}
|
|
26
|
+
if (contextLines > 0) {
|
|
27
|
+
args.push('-C', contextLines.toString());
|
|
28
|
+
}
|
|
29
|
+
if (filePattern) {
|
|
30
|
+
const patterns = filePattern
|
|
31
|
+
.split('|')
|
|
32
|
+
.map(p => p.trim()) // remove surrounding spaces
|
|
33
|
+
.filter(Boolean); // drop empty tokens
|
|
34
|
+
// If all patterns were empty, return no results
|
|
35
|
+
if (patterns.length === 0) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
patterns.forEach(p => args.push('-g', p));
|
|
39
|
+
}
|
|
40
|
+
// Add pattern and path
|
|
41
|
+
args.push(pattern, validPath);
|
|
42
|
+
// Run ripgrep command
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const results = [];
|
|
45
|
+
const rg = spawn(rgPath, args);
|
|
46
|
+
let stdoutBuffer = '';
|
|
47
|
+
// Store a reference to the child process for potential termination
|
|
48
|
+
const childProcess = rg;
|
|
49
|
+
// Store in a process list - this could be expanded to a global registry
|
|
50
|
+
// of running search processes if needed for management
|
|
51
|
+
globalThis.currentSearchProcess = childProcess;
|
|
52
|
+
rg.stdout.on('data', (data) => {
|
|
53
|
+
stdoutBuffer += data.toString();
|
|
54
|
+
});
|
|
55
|
+
rg.stderr.on('data', (data) => {
|
|
56
|
+
console.error(`ripgrep error: ${data}`);
|
|
57
|
+
});
|
|
58
|
+
rg.on('close', (code) => {
|
|
59
|
+
// Clean up the global reference
|
|
60
|
+
if (globalThis.currentSearchProcess === childProcess) {
|
|
61
|
+
delete globalThis.currentSearchProcess;
|
|
62
|
+
}
|
|
63
|
+
if (code === 0 || code === 1) {
|
|
64
|
+
// Process the buffered output
|
|
65
|
+
const lines = stdoutBuffer.trim().split('\n');
|
|
66
|
+
for (const line of lines) {
|
|
67
|
+
if (!line)
|
|
68
|
+
continue;
|
|
69
|
+
try {
|
|
70
|
+
const result = JSON.parse(line);
|
|
71
|
+
if (result.type === 'match') {
|
|
72
|
+
result.data.submatches.forEach((submatch) => {
|
|
73
|
+
results.push({
|
|
74
|
+
file: result.data.path.text,
|
|
75
|
+
line: result.data.line_number,
|
|
76
|
+
match: submatch.match.text
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
else if (result.type === 'context' && contextLines > 0) {
|
|
81
|
+
results.push({
|
|
82
|
+
file: result.data.path.text,
|
|
83
|
+
line: result.data.line_number,
|
|
84
|
+
match: result.data.lines.text.trim()
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
90
|
+
capture('server_request_error', { error: `Error parsing ripgrep output: ${errorMessage}` });
|
|
91
|
+
console.error(`Error parsing ripgrep output: ${errorMessage}`);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
resolve(results);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
reject(new Error(`ripgrep process exited with code ${code}`));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
// Fallback implementation using Node.js for environments without ripgrep
|
|
103
|
+
export async function searchCodeFallback(options) {
|
|
104
|
+
const { rootPath, pattern, filePattern, ignoreCase = true, maxResults = 1000, excludeDirs = ['node_modules', '.git'], contextLines = 0 } = options;
|
|
105
|
+
const validPath = await validatePath(rootPath);
|
|
106
|
+
const results = [];
|
|
107
|
+
const regex = new RegExp(pattern, ignoreCase ? 'i' : '');
|
|
108
|
+
// Handle filePattern similarly to main implementation
|
|
109
|
+
let fileRegex = null;
|
|
110
|
+
if (filePattern) {
|
|
111
|
+
const patterns = filePattern
|
|
112
|
+
.split('|')
|
|
113
|
+
.map(p => p.trim())
|
|
114
|
+
.filter(Boolean);
|
|
115
|
+
// If all patterns were empty, return no results
|
|
116
|
+
if (patterns.length === 0) {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
// Create a regex that matches any of the patterns
|
|
120
|
+
const combinedPattern = patterns.map(p => p.replace(/\./g, '\\.').replace(/\*/g, '.*').replace(/\?/g, '.')).join('|');
|
|
121
|
+
fileRegex = new RegExp(`^(${combinedPattern})$`);
|
|
122
|
+
}
|
|
123
|
+
async function searchDir(dirPath) {
|
|
124
|
+
if (results.length >= maxResults)
|
|
125
|
+
return;
|
|
126
|
+
try {
|
|
127
|
+
const entries = await fs.readdir(dirPath, { withFileTypes: true });
|
|
128
|
+
for (const entry of entries) {
|
|
129
|
+
if (results.length >= maxResults)
|
|
130
|
+
break;
|
|
131
|
+
const fullPath = path.join(dirPath, entry.name);
|
|
132
|
+
try {
|
|
133
|
+
await validatePath(fullPath);
|
|
134
|
+
if (entry.isDirectory()) {
|
|
135
|
+
if (!excludeDirs.includes(entry.name)) {
|
|
136
|
+
await searchDir(fullPath);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
else if (entry.isFile()) {
|
|
140
|
+
if (!fileRegex || fileRegex.test(entry.name)) {
|
|
141
|
+
const content = await fs.readFile(fullPath, 'utf-8');
|
|
142
|
+
const lines = content.split('\n');
|
|
143
|
+
for (let i = 0; i < lines.length; i++) {
|
|
144
|
+
if (regex.test(lines[i])) {
|
|
145
|
+
// Add the matched line
|
|
146
|
+
results.push({
|
|
147
|
+
file: fullPath,
|
|
148
|
+
line: i + 1,
|
|
149
|
+
match: lines[i].trim()
|
|
150
|
+
});
|
|
151
|
+
// Add context lines
|
|
152
|
+
if (contextLines > 0) {
|
|
153
|
+
const startIdx = Math.max(0, i - contextLines);
|
|
154
|
+
const endIdx = Math.min(lines.length - 1, i + contextLines);
|
|
155
|
+
for (let j = startIdx; j <= endIdx; j++) {
|
|
156
|
+
if (j !== i) { // Skip the match line as it's already added
|
|
157
|
+
results.push({
|
|
158
|
+
file: fullPath,
|
|
159
|
+
line: j + 1,
|
|
160
|
+
match: lines[j].trim()
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (results.length >= maxResults)
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
// Skip files/directories we can't access
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
catch (error) {
|
|
179
|
+
// Skip directories we can't read
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
await searchDir(validPath);
|
|
183
|
+
return results;
|
|
184
|
+
}
|
|
185
|
+
// Main function that tries ripgrep first, falls back to native implementation
|
|
186
|
+
export async function searchTextInFiles(options) {
|
|
187
|
+
try {
|
|
188
|
+
// For better performance and consistency, prefer the search session manager
|
|
189
|
+
// when doing content search, but keep the original direct ripgrep approach as primary
|
|
190
|
+
return await searchCode(options);
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
capture('searchTextInFiles_ripgrep_fallback', {
|
|
194
|
+
error: error instanceof Error ? error.message : 'Unknown error'
|
|
195
|
+
});
|
|
196
|
+
// Use consistent exclusions - remove 'dist' to match ripgrep behavior
|
|
197
|
+
return searchCodeFallback({
|
|
198
|
+
...options,
|
|
199
|
+
excludeDirs: ['node_modules', '.git']
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
}
|
package/dist/types.d.ts
CHANGED