@wonderwhy-er/desktop-commander 0.2.52 ā 0.3.1-alpha.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/LICENSE +20 -20
- package/README.md +1152 -1152
- package/dist/bootstrap.js +0 -0
- package/dist/command-manager.d.ts +7 -2
- package/dist/command-manager.js +16 -11
- package/dist/config-field-definitions.js +0 -0
- package/dist/config-manager.d.ts +55 -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/custom-stdio.js +0 -0
- package/dist/data/onboarding-prompts.json +70 -70
- package/dist/error-handlers.js +0 -0
- package/dist/handlers/filesystem-handlers.d.ts +1 -1
- package/dist/handlers/filesystem-handlers.js +28 -18
- 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 +36 -22
- 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/diagnostics/device-log.d.ts +63 -0
- package/dist/remote-device/diagnostics/device-log.js +219 -0
- package/dist/remote-device/diagnostics/redact.d.ts +1 -0
- package/dist/remote-device/diagnostics/redact.js +76 -0
- package/dist/remote-device/diagnostics/report.d.ts +118 -0
- package/dist/remote-device/diagnostics/report.js +748 -0
- package/dist/remote-device/diagnostics/upload.d.ts +11 -0
- package/dist/remote-device/diagnostics/upload.js +59 -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 +133 -96
- 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 +654 -621
- package/dist/setup-claude-server.js +942 -942
- 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 +14 -6
- package/dist/tools/filesystem.d.ts +30 -6
- package/dist/tools/filesystem.js +246 -140
- package/dist/tools/fuzzySearch.js +9 -9
- package/dist/tools/improved-process-tools.d.ts +9 -3
- package/dist/tools/improved-process-tools.js +181 -78
- 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/prompts.js +1 -1
- package/dist/tools/schemas.d.ts +1 -1
- package/dist/tools/schemas.js +15 -6
- package/dist/track-installation.js +387 -387
- package/dist/types.d.ts +1 -1
- package/dist/types.js +0 -0
- package/dist/ui/config-editor/config-editor-runtime.js +6 -6
- package/dist/ui/config-editor/index.html +13 -13
- package/dist/ui/config-editor/src/app.js +32 -45
- package/dist/ui/config-editor/src/array-modal.js +32 -32
- package/dist/ui/config-editor/styles.css +586 -586
- package/dist/ui/file-preview/index.html +16 -16
- package/dist/ui/file-preview/src/app.js +8 -8
- package/dist/ui/file-preview/src/document-layout.js +31 -31
- package/dist/ui/file-preview/src/document-outline.js +8 -8
- package/dist/ui/file-preview/src/markdown/conflict-dialog.js +33 -33
- package/dist/ui/file-preview/src/markdown/controller.js +9 -9
- package/dist/ui/file-preview/src/markdown/editor.js +31 -31
- package/dist/ui/file-preview/styles.css +1630 -1630
- package/dist/uninstall-claude-server.js +745 -745
- 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/binary.js +4 -4
- 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 +96 -36
- 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 +99 -97
- package/dist/utils/trackTools.js +2 -1
- package/dist/utils/usageTracker.js +49 -49
- 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 +10 -3
- 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
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "2.0.0",
|
|
3
|
-
"description": "Desktop Commander onboarding prompts - V2 simplified (5 prompts only)",
|
|
4
|
-
"prompts": [
|
|
5
|
-
{
|
|
6
|
-
"id": "onb2_01",
|
|
7
|
-
"title": "Organize my Downloads folder",
|
|
8
|
-
"description": "Clean up and organize your messy Downloads folder into relevant subfolders automatically.",
|
|
9
|
-
"prompt": "Let's organize your Downloads folder! \n\nFirst, let me check what we're working with. I'll look at your Downloads folder to see how many files are there and what types.\n\nShould I start by analyzing your Downloads folder?",
|
|
10
|
-
"categories": ["onboarding"],
|
|
11
|
-
"secondaryTag": "Quick Start",
|
|
12
|
-
"votes": 0,
|
|
13
|
-
"gaClicks": 0,
|
|
14
|
-
"icon": "FolderOpen",
|
|
15
|
-
"author": "DC team",
|
|
16
|
-
"verified": true
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"id": "onb2_02",
|
|
20
|
-
"title": "Explain codebase or repository to me",
|
|
21
|
-
"description": "Analyze and explain any codebase - local project or GitHub repository - including architecture, dependencies, and how it works.",
|
|
22
|
-
"prompt": "I'll analyze and explain any codebase for you! š\n\n**What should I analyze?**\n\n*Local project:* `~/work/my-project` (replace with your path)\n*GitHub repo:* `https://github.com/user/repo`\n\nI'll break down the architecture, dependencies, and how everything works together!",
|
|
23
|
-
"categories": ["onboarding"], "secondaryTag": "Code Analysis",
|
|
24
|
-
"votes": 0,
|
|
25
|
-
"gaClicks": 0,
|
|
26
|
-
"icon": "Code",
|
|
27
|
-
"author": "DC team",
|
|
28
|
-
"verified": true
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"id": "onb2_03",
|
|
32
|
-
"title": "Create organized knowledge/documents folder",
|
|
33
|
-
"description": "Set up a well-structured knowledge base or document organization system with templates and suggested categories.",
|
|
34
|
-
"prompt": "Let's create an organized knowledge base! š\n\n**Where should I set it up?**\n\n*I suggest: `~/Documents/Knowledge-Base` (replace with your path) or give me a different location.*\n\nI'll create a clean folder structure with templates and organize any existing documents you have!",
|
|
35
|
-
"categories": ["onboarding"],
|
|
36
|
-
"secondaryTag": "Quick Start",
|
|
37
|
-
"votes": 0,
|
|
38
|
-
"gaClicks": 0,
|
|
39
|
-
"icon": "BookOpen",
|
|
40
|
-
"author": "DC team",
|
|
41
|
-
"verified": true
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
"id": "onb2_04",
|
|
45
|
-
"title": "Analyze my data file",
|
|
46
|
-
"description": "Upload or point to any data file (CSV, JSON, Excel, etc.) and get comprehensive analysis including patterns, insights, and summary reports.",
|
|
47
|
-
"prompt": "I'll help you analyze your data file! \n\nWhat's the path to your data file? (e.g., `/Users/yourname/data.csv`)\n\nOnce you give me the path, I'll start by checking what type of file it is and show you a quick preview, then we can dive deeper step by step.",
|
|
48
|
-
"categories": ["onboarding"],
|
|
49
|
-
"secondaryTag": "Quick Start",
|
|
50
|
-
"votes": 0,
|
|
51
|
-
"gaClicks": 0,
|
|
52
|
-
"icon": "BarChart3",
|
|
53
|
-
"author": "DC team",
|
|
54
|
-
"verified": true
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
"id": "onb2_05",
|
|
58
|
-
"title": "Check system health and resources",
|
|
59
|
-
"description": "Analyze your system's health, resource usage, running processes, and generate a comprehensive system status report.",
|
|
60
|
-
"prompt": "Let me check your system health and resources!\n\nI'll start by looking at your CPU, memory, and disk usage, then check for any performance issues.\n\nShould I begin the system analysis?",
|
|
61
|
-
"categories": ["onboarding"],
|
|
62
|
-
"secondaryTag": "Quick Start",
|
|
63
|
-
"votes": 0,
|
|
64
|
-
"gaClicks": 0,
|
|
65
|
-
"icon": "Activity",
|
|
66
|
-
"author": "DC team",
|
|
67
|
-
"verified": true
|
|
68
|
-
}
|
|
69
|
-
]
|
|
70
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"version": "2.0.0",
|
|
3
|
+
"description": "Desktop Commander onboarding prompts - V2 simplified (5 prompts only)",
|
|
4
|
+
"prompts": [
|
|
5
|
+
{
|
|
6
|
+
"id": "onb2_01",
|
|
7
|
+
"title": "Organize my Downloads folder",
|
|
8
|
+
"description": "Clean up and organize your messy Downloads folder into relevant subfolders automatically.",
|
|
9
|
+
"prompt": "Let's organize your Downloads folder! \n\nFirst, let me check what we're working with. I'll look at your Downloads folder to see how many files are there and what types.\n\nShould I start by analyzing your Downloads folder?",
|
|
10
|
+
"categories": ["onboarding"],
|
|
11
|
+
"secondaryTag": "Quick Start",
|
|
12
|
+
"votes": 0,
|
|
13
|
+
"gaClicks": 0,
|
|
14
|
+
"icon": "FolderOpen",
|
|
15
|
+
"author": "DC team",
|
|
16
|
+
"verified": true
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"id": "onb2_02",
|
|
20
|
+
"title": "Explain codebase or repository to me",
|
|
21
|
+
"description": "Analyze and explain any codebase - local project or GitHub repository - including architecture, dependencies, and how it works.",
|
|
22
|
+
"prompt": "I'll analyze and explain any codebase for you! š\n\n**What should I analyze?**\n\n*Local project:* `~/work/my-project` (replace with your path)\n*GitHub repo:* `https://github.com/user/repo`\n\nI'll break down the architecture, dependencies, and how everything works together!",
|
|
23
|
+
"categories": ["onboarding"], "secondaryTag": "Code Analysis",
|
|
24
|
+
"votes": 0,
|
|
25
|
+
"gaClicks": 0,
|
|
26
|
+
"icon": "Code",
|
|
27
|
+
"author": "DC team",
|
|
28
|
+
"verified": true
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
"id": "onb2_03",
|
|
32
|
+
"title": "Create organized knowledge/documents folder",
|
|
33
|
+
"description": "Set up a well-structured knowledge base or document organization system with templates and suggested categories.",
|
|
34
|
+
"prompt": "Let's create an organized knowledge base! š\n\n**Where should I set it up?**\n\n*I suggest: `~/Documents/Knowledge-Base` (replace with your path) or give me a different location.*\n\nI'll create a clean folder structure with templates and organize any existing documents you have!",
|
|
35
|
+
"categories": ["onboarding"],
|
|
36
|
+
"secondaryTag": "Quick Start",
|
|
37
|
+
"votes": 0,
|
|
38
|
+
"gaClicks": 0,
|
|
39
|
+
"icon": "BookOpen",
|
|
40
|
+
"author": "DC team",
|
|
41
|
+
"verified": true
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"id": "onb2_04",
|
|
45
|
+
"title": "Analyze my data file",
|
|
46
|
+
"description": "Upload or point to any data file (CSV, JSON, Excel, etc.) and get comprehensive analysis including patterns, insights, and summary reports.",
|
|
47
|
+
"prompt": "I'll help you analyze your data file! \n\nWhat's the path to your data file? (e.g., `/Users/yourname/data.csv`)\n\nOnce you give me the path, I'll start by checking what type of file it is and show you a quick preview, then we can dive deeper step by step.",
|
|
48
|
+
"categories": ["onboarding"],
|
|
49
|
+
"secondaryTag": "Quick Start",
|
|
50
|
+
"votes": 0,
|
|
51
|
+
"gaClicks": 0,
|
|
52
|
+
"icon": "BarChart3",
|
|
53
|
+
"author": "DC team",
|
|
54
|
+
"verified": true
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
"id": "onb2_05",
|
|
58
|
+
"title": "Check system health and resources",
|
|
59
|
+
"description": "Analyze your system's health, resource usage, running processes, and generate a comprehensive system status report.",
|
|
60
|
+
"prompt": "Let me check your system health and resources!\n\nI'll start by looking at your CPU, memory, and disk usage, then check for any performance issues.\n\nShould I begin the system analysis?",
|
|
61
|
+
"categories": ["onboarding"],
|
|
62
|
+
"secondaryTag": "Quick Start",
|
|
63
|
+
"votes": 0,
|
|
64
|
+
"gaClicks": 0,
|
|
65
|
+
"icon": "Activity",
|
|
66
|
+
"author": "DC team",
|
|
67
|
+
"verified": true
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
package/dist/error-handlers.js
CHANGED
|
File without changes
|
|
@@ -11,7 +11,7 @@ export declare function handleReadFile(args: unknown): Promise<ServerResult>;
|
|
|
11
11
|
/**
|
|
12
12
|
* Handle read_multiple_files command
|
|
13
13
|
*/
|
|
14
|
-
export declare function handleReadMultipleFiles(args: unknown): Promise<ServerResult>;
|
|
14
|
+
export declare function handleReadMultipleFiles(args: unknown, stillLoadingError?: (filePath: string) => string | undefined): Promise<ServerResult>;
|
|
15
15
|
/**
|
|
16
16
|
* Handle write_file command
|
|
17
17
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFile, readMultipleFiles, writeFile, createDirectory, listDirectory, moveFile, getFileInfo, writePdf, getDefaultEditorMetadata } from '../tools/filesystem.js';
|
|
2
|
+
import { TextFileHandler } from '../utils/files/text.js';
|
|
2
3
|
import { withTimeout } from '../utils/withTimeout.js';
|
|
3
4
|
import { createErrorResponse } from '../error-handlers.js';
|
|
4
5
|
import { configManager } from '../config-manager.js';
|
|
@@ -58,18 +59,22 @@ export async function handleReadFile(args) {
|
|
|
58
59
|
if (!config) {
|
|
59
60
|
return createErrorResponse('Configuration not available');
|
|
60
61
|
}
|
|
62
|
+
// The schema fills in `length: 1000` (the default tools/list shows), so
|
|
63
|
+
// whether the caller sent a length is read from the raw arguments: an
|
|
64
|
+
// omitted length follows the fileReadLineLimit setting, as documented.
|
|
61
65
|
const defaultLimit = config.fileReadLineLimit ?? 1000;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
sheetParam = parseInt(parsed.sheet, 10);
|
|
66
|
-
}
|
|
66
|
+
const lengthGiven = args.length !== undefined;
|
|
67
|
+
// The sheet goes as given: the Excel handler knows the sheet names, so it
|
|
68
|
+
// decides whether "2024" is an index or a sheet named 2024
|
|
67
69
|
const options = {
|
|
68
70
|
isUrl: parsed.isUrl,
|
|
69
71
|
offset: parsed.offset ?? 0,
|
|
70
|
-
length: parsed.length
|
|
71
|
-
sheet:
|
|
72
|
-
range: parsed.range
|
|
72
|
+
length: lengthGiven ? parsed.length : defaultLimit,
|
|
73
|
+
sheet: parsed.sheet,
|
|
74
|
+
range: parsed.range,
|
|
75
|
+
// The preview widget draws an SVG as an image (ui/file-preview/src/image-preview.ts);
|
|
76
|
+
// everyone else reads it as the text it is
|
|
77
|
+
svgAsImage: parsed.origin === 'ui'
|
|
73
78
|
};
|
|
74
79
|
// Resolve to absolute path for local files (not URLs) so "Open in folder" works
|
|
75
80
|
const resolvedFilePath = parsed.isUrl
|
|
@@ -193,9 +198,9 @@ export async function handleReadFile(args) {
|
|
|
193
198
|
/**
|
|
194
199
|
* Handle read_multiple_files command
|
|
195
200
|
*/
|
|
196
|
-
export async function handleReadMultipleFiles(args) {
|
|
201
|
+
export async function handleReadMultipleFiles(args, stillLoadingError) {
|
|
197
202
|
const parsed = ReadMultipleFilesArgsSchema.parse(args);
|
|
198
|
-
const fileResults = await readMultipleFiles(parsed.paths);
|
|
203
|
+
const fileResults = await readMultipleFiles(parsed.paths, stillLoadingError);
|
|
199
204
|
// Create a text summary of all files
|
|
200
205
|
const textSummary = fileResults.map(result => {
|
|
201
206
|
if (result.error) {
|
|
@@ -215,10 +220,13 @@ export async function handleReadMultipleFiles(args) {
|
|
|
215
220
|
const contentItems = [];
|
|
216
221
|
// Add the text summary
|
|
217
222
|
contentItems.push({ type: "text", text: textSummary });
|
|
218
|
-
// Add each file content
|
|
223
|
+
// Add each file content after its path: several images, or a PDF's pages,
|
|
224
|
+
// can't be told apart by their order alone
|
|
219
225
|
for (const result of fileResults) {
|
|
220
226
|
if (!result.error && result.content !== undefined) {
|
|
227
|
+
const header = `\n--- ${result.path} contents: ---\n`;
|
|
221
228
|
if (result.isPdf) {
|
|
229
|
+
contentItems.push({ type: "text", text: header });
|
|
222
230
|
result.payload?.pages.forEach((page, i) => {
|
|
223
231
|
page.images.forEach((image, i) => {
|
|
224
232
|
contentItems.push({
|
|
@@ -235,6 +243,7 @@ export async function handleReadMultipleFiles(args) {
|
|
|
235
243
|
}
|
|
236
244
|
else if (result.isImage && result.mimeType) {
|
|
237
245
|
// For image files, add an image content item
|
|
246
|
+
contentItems.push({ type: "text", text: header });
|
|
238
247
|
contentItems.push({
|
|
239
248
|
type: "image",
|
|
240
249
|
data: result.content,
|
|
@@ -245,7 +254,7 @@ export async function handleReadMultipleFiles(args) {
|
|
|
245
254
|
// For text files, add a text summary
|
|
246
255
|
contentItems.push({
|
|
247
256
|
type: "text",
|
|
248
|
-
text:
|
|
257
|
+
text: `${header}${result.content}`
|
|
249
258
|
});
|
|
250
259
|
}
|
|
251
260
|
}
|
|
@@ -284,13 +293,12 @@ export async function handleWriteFile(args) {
|
|
|
284
293
|
// Get the line limit from configuration
|
|
285
294
|
const config = await configManager.getConfig();
|
|
286
295
|
const MAX_LINES = config.fileWriteLineLimit ?? 50; // Default to 50 if not set
|
|
287
|
-
//
|
|
288
|
-
const
|
|
289
|
-
const lineCount = lines.length;
|
|
296
|
+
// Lines as read_file counts them: a final line break doesn't start another line
|
|
297
|
+
const lineCount = TextFileHandler.countLines(parsed.content);
|
|
290
298
|
let errorMessage = "";
|
|
291
299
|
if (lineCount > MAX_LINES) {
|
|
292
|
-
errorMessage = `ā
File written successfully! (${lineCount} lines)
|
|
293
|
-
|
|
300
|
+
errorMessage = `ā
File written successfully! (${lineCount} lines)
|
|
301
|
+
|
|
294
302
|
š” Performance tip: For optimal speed, consider chunking files into ā¤30 line pieces in future operations.`;
|
|
295
303
|
}
|
|
296
304
|
// Pass the mode parameter to writeFile
|
|
@@ -427,10 +435,12 @@ export async function handleGetFileInfo(args) {
|
|
|
427
435
|
export async function handleWritePdf(args) {
|
|
428
436
|
try {
|
|
429
437
|
const parsed = WritePdfArgsSchema.parse(args);
|
|
430
|
-
await writePdf(parsed.path, parsed.content, parsed.outputPath, parsed.options);
|
|
438
|
+
const ignoredOptions = await writePdf(parsed.path, parsed.content, parsed.outputPath, parsed.options);
|
|
431
439
|
const targetPath = parsed.outputPath || parsed.path;
|
|
432
440
|
return {
|
|
433
441
|
content: [{ type: "text", text: `Successfully wrote PDF to ${targetPath}${parsed.outputPath ? `\nOriginal file: ${parsed.path}` : ''}` }],
|
|
442
|
+
// Which options were ignored, and why: internal (tests), not sent to the client (see utils/internal-facts.ts)
|
|
443
|
+
...(ignoredOptions.length > 0 ? { structuredContent: { ignoredOptions } } : {}),
|
|
434
444
|
};
|
|
435
445
|
}
|
|
436
446
|
catch (error) {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { SearchResult, SearchState, Unsearched } from '../search-manager.js';
|
|
2
|
+
import type { ServerResult } from '../types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The words of the search answers (start_search, get_more_search_results), in
|
|
5
|
+
* one place (#768). Each answer ends saying how the search ended: its outcome
|
|
6
|
+
* (SearchOutcome in search-manager.ts).
|
|
7
|
+
*/
|
|
8
|
+
export declare const SEARCH_WORDS: {
|
|
9
|
+
/** "Total results: ā¦", the same in both answers */
|
|
10
|
+
total: (matches: number, rows: number) => string;
|
|
11
|
+
matchRow: (file: string, line: number | undefined, text: string) => string;
|
|
12
|
+
contextRow: (file: string, line: number | undefined, text: string) => string;
|
|
13
|
+
fileRow: (file: string) => string;
|
|
14
|
+
/** A page with no results */
|
|
15
|
+
noMatches: string;
|
|
16
|
+
noneAtOffset: (offset: number, rows: number) => string;
|
|
17
|
+
noneYet: (offset: number, rows: number) => string;
|
|
18
|
+
/** After a page's results: whether there are more */
|
|
19
|
+
moreResults: (nextOffset: number) => string;
|
|
20
|
+
moreMayCome: string;
|
|
21
|
+
inProgress: string;
|
|
22
|
+
/** How the search ended, by outcome */
|
|
23
|
+
completed: string;
|
|
24
|
+
timedOut: (ms: number | undefined) => string;
|
|
25
|
+
stopped: string;
|
|
26
|
+
maxResults: (n: number | undefined) => string;
|
|
27
|
+
/** Partial, when the only files it couldn't search were ones it may not read: as it always said */
|
|
28
|
+
permissionsOnly: string;
|
|
29
|
+
partial: (reasons: string[]) => string;
|
|
30
|
+
unsearched: {
|
|
31
|
+
permissions: () => string;
|
|
32
|
+
ripgrep_error: (u: Unsearched) => string;
|
|
33
|
+
ripgrep_ended: (u: Unsearched) => string;
|
|
34
|
+
excel_search: (u: Unsearched) => string;
|
|
35
|
+
docx_search: (u: Unsearched) => string;
|
|
36
|
+
excel_file: (u: Unsearched) => string;
|
|
37
|
+
docx_file: (u: Unsearched) => string;
|
|
38
|
+
excel_folder: (u: Unsearched) => string;
|
|
39
|
+
docx_folder: (u: Unsearched) => string;
|
|
40
|
+
};
|
|
41
|
+
/** A failed search's whole answer */
|
|
42
|
+
failedWithError: (sessionId: string, error: string) => string;
|
|
43
|
+
failedRipgrepEnded: (sessionId: string, how: string) => string;
|
|
44
|
+
};
|
|
45
|
+
/** start_search's answer: the search as it is once it started, with its first results */
|
|
46
|
+
export declare function startSearchAnswer(search: SearchState & {
|
|
47
|
+
results: SearchResult[];
|
|
48
|
+
}, args: {
|
|
49
|
+
searchType: 'files' | 'content';
|
|
50
|
+
pattern: string;
|
|
51
|
+
path: string;
|
|
52
|
+
}): ServerResult;
|
|
53
|
+
/** get_more_search_results' answer: one page of a search's results (a negative offset: its last results) */
|
|
54
|
+
export declare function searchResultsAnswer(page: SearchState & {
|
|
55
|
+
results: SearchResult[];
|
|
56
|
+
returnedCount: number;
|
|
57
|
+
hasMoreResults: boolean;
|
|
58
|
+
}, offset: number): ServerResult;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { SHOWN_TEXT_CHARS, MAX_OUTPUT_LINE_CHARS } from '../search-manager.js';
|
|
2
|
+
/**
|
|
3
|
+
* The words of the search answers (start_search, get_more_search_results), in
|
|
4
|
+
* one place (#768). Each answer ends saying how the search ended: its outcome
|
|
5
|
+
* (SearchOutcome in search-manager.ts).
|
|
6
|
+
*/
|
|
7
|
+
export const SEARCH_WORDS = {
|
|
8
|
+
/** "Total results: ā¦", the same in both answers */
|
|
9
|
+
total: (matches, rows) => `${matches === 1 ? '1 match' : `${matches} matches`}${rows > matches ? ` (${rows} rows with context)` : ''}`,
|
|
10
|
+
matchRow: (file, line, text) => `š ${file}:${line} - ${text}`,
|
|
11
|
+
contextRow: (file, line, text) => ` ${file}:${line} Ā· ${text}`,
|
|
12
|
+
fileRow: (file) => `š ${file}`,
|
|
13
|
+
/** A page with no results */
|
|
14
|
+
noMatches: 'No matches found.',
|
|
15
|
+
noneAtOffset: (offset, rows) => `No results at offset ${offset} (${rows} in total).`,
|
|
16
|
+
noneYet: (offset, rows) => `Still running: ${rows === 1 ? '1 result' : `${rows} results`} so far${offset >= 0 ? `, none at offset ${offset} yet` : ''}.`,
|
|
17
|
+
/** After a page's results: whether there are more */
|
|
18
|
+
moreResults: (nextOffset) => `š More results available. Use get_more_search_results with offset: ${nextOffset}`,
|
|
19
|
+
moreMayCome: 'Still running: more may come.',
|
|
20
|
+
inProgress: 'š Search in progress. Use get_more_search_results to get more results.',
|
|
21
|
+
/** How the search ended, by outcome */
|
|
22
|
+
completed: 'ā
Search completed.',
|
|
23
|
+
timedOut: (ms) => `ā±ļø Stopped after ${ms} ms: results may be incomplete.`,
|
|
24
|
+
stopped: 'ā¹ļø Stopped on request: results may be incomplete.',
|
|
25
|
+
maxResults: (n) => `Stopped at maxResults (${n}): there may be more.`,
|
|
26
|
+
/** Partial, when the only files it couldn't search were ones it may not read: as it always said */
|
|
27
|
+
permissionsOnly: 'ā
Search completed.\nā ļø Warning: Some files were inaccessible due to permissions. Results may be incomplete.',
|
|
28
|
+
partial: (reasons) => `ā ļø Completed, but some files couldn't be searched: ${reasons.join('; ')}.`,
|
|
29
|
+
unsearched: {
|
|
30
|
+
permissions: () => 'some files were inaccessible due to permissions',
|
|
31
|
+
ripgrep_error: (u) => `ripgrep: ${u.example}${andMore(u)}`,
|
|
32
|
+
ripgrep_ended: (u) => `ripgrep stopped unexpectedly (${u.example})`,
|
|
33
|
+
excel_search: (u) => `the Excel search failed (${u.example})`,
|
|
34
|
+
docx_search: (u) => `the DOCX search failed (${u.example})`,
|
|
35
|
+
excel_file: (u) => `${counted(u, 'an Excel file', 'Excel files')} couldn't be read (${u.example}${andMore(u)})`,
|
|
36
|
+
docx_file: (u) => `${counted(u, 'a DOCX file', 'DOCX files')} couldn't be read (${u.example}${andMore(u)})`,
|
|
37
|
+
excel_folder: (u) => `${counted(u, 'a folder', 'folders')} couldn't be listed for the Excel search (${u.example}${andMore(u)})`,
|
|
38
|
+
docx_folder: (u) => `${counted(u, 'a folder', 'folders')} couldn't be listed for the DOCX search (${u.example}${andMore(u)})`,
|
|
39
|
+
},
|
|
40
|
+
/** A failed search's whole answer */
|
|
41
|
+
failedWithError: (sessionId, error) => `Search session ${sessionId} encountered an error: ${error}`,
|
|
42
|
+
failedRipgrepEnded: (sessionId, how) => `Search session ${sessionId} failed: ripgrep stopped unexpectedly (${how}).`,
|
|
43
|
+
};
|
|
44
|
+
const andMore = (u) => (u.count > 1 ? ` and ${u.count - 1} more` : '');
|
|
45
|
+
const counted = (u, one, many) => (u.count === 1 ? one : `${u.count} ${many}`);
|
|
46
|
+
/**
|
|
47
|
+
* Which lines a search skipped as too long: how many, in which files. Part of a
|
|
48
|
+
* successful answer, worded so that nobody retries: the same search skips them again.
|
|
49
|
+
*/
|
|
50
|
+
function describeSkippedLines(skipped) {
|
|
51
|
+
const lines = skipped.reduce((sum, { count }) => sum + count, 0);
|
|
52
|
+
const files = skipped.slice(0, 5).map(({ file }) => file || 'a file whose name is not valid UTF-8').join(', ');
|
|
53
|
+
const more = skipped.length > 5 ? ` and ${skipped.length - 5} more files` : '';
|
|
54
|
+
const exclude = skipped.length === 1 ? "that file (filePattern) if it isn't" : "those files (filePattern) if they aren't";
|
|
55
|
+
return `Skipped ${lines === 1 ? 'a line' : `${lines} lines`} over ${Math.round(MAX_OUTPUT_LINE_CHARS / 1024 / 1024)} MB in ${files}${more}: too long to search. ` +
|
|
56
|
+
`Searching again gives the same result; exclude ${exclude} needed.`;
|
|
57
|
+
}
|
|
58
|
+
/** A result as answers list it: a match, a line around one, or a file */
|
|
59
|
+
function resultRow(result) {
|
|
60
|
+
if (result.type !== 'content')
|
|
61
|
+
return SEARCH_WORDS.fileRow(result.file);
|
|
62
|
+
const text = `${result.match?.substring(0, SHOWN_TEXT_CHARS)}${result.match && result.match.length > SHOWN_TEXT_CHARS ? '...' : ''}`;
|
|
63
|
+
return (result.context ? SEARCH_WORDS.contextRow : SEARCH_WORDS.matchRow)(result.file, result.line, text);
|
|
64
|
+
}
|
|
65
|
+
/** How a complete search ended, as its answer's last line(s); undefined while it runs */
|
|
66
|
+
function endedText(state) {
|
|
67
|
+
switch (state.outcome) {
|
|
68
|
+
case 'completed': return SEARCH_WORDS.completed;
|
|
69
|
+
case 'timed_out': return SEARCH_WORDS.timedOut(state.timeLimitMs);
|
|
70
|
+
case 'stopped': return SEARCH_WORDS.stopped;
|
|
71
|
+
case 'max_results': return SEARCH_WORDS.maxResults(state.maxResults);
|
|
72
|
+
case 'partial':
|
|
73
|
+
return state.unsearched.every(u => u.kind === 'permissions')
|
|
74
|
+
? SEARCH_WORDS.permissionsOnly
|
|
75
|
+
: SEARCH_WORDS.partial(state.unsearched.map(u => SEARCH_WORDS.unsearched[u.kind](u)));
|
|
76
|
+
default: return undefined;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** The answer to a search that failed, whichever tool reads it */
|
|
80
|
+
function failedAnswer(state) {
|
|
81
|
+
const failure = state.failure;
|
|
82
|
+
const text = 'error' in failure
|
|
83
|
+
? SEARCH_WORDS.failedWithError(state.sessionId, failure.error)
|
|
84
|
+
: SEARCH_WORDS.failedRipgrepEnded(state.sessionId, failure.ripgrepEnded);
|
|
85
|
+
return {
|
|
86
|
+
content: [{ type: 'text', text }],
|
|
87
|
+
isError: true,
|
|
88
|
+
structuredContent: { sessionId: state.sessionId, isComplete: state.isComplete, outcome: state.outcome },
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** start_search's answer: the search as it is once it started, with its first results */
|
|
92
|
+
export function startSearchAnswer(search, args) {
|
|
93
|
+
if (search.outcome === 'failed')
|
|
94
|
+
return failedAnswer(search);
|
|
95
|
+
let text = `Started ${args.searchType === 'content' ? 'content search' : 'file search'} session: ${search.sessionId}\n`;
|
|
96
|
+
text += `Pattern: "${args.pattern}"\n`;
|
|
97
|
+
text += `Path: ${args.path}\n`;
|
|
98
|
+
text += `Status: ${search.isComplete ? 'COMPLETED' : 'RUNNING'}\n`;
|
|
99
|
+
text += `Runtime: ${Math.round(search.runtime)}ms\n`;
|
|
100
|
+
text += `Total results: ${SEARCH_WORDS.total(search.totalMatches, search.totalResults)}\n\n`;
|
|
101
|
+
if (search.results.length > 0) {
|
|
102
|
+
text += 'Initial results:\n';
|
|
103
|
+
for (const result of search.results.slice(0, 10)) {
|
|
104
|
+
text += `${resultRow(result)}\n`;
|
|
105
|
+
}
|
|
106
|
+
if (search.results.length > 10) {
|
|
107
|
+
text += `... and ${search.results.length - 10} more results\n`;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
text += `\n${endedText(search) ?? SEARCH_WORDS.inProgress}`;
|
|
111
|
+
return {
|
|
112
|
+
content: [{ type: 'text', text }],
|
|
113
|
+
structuredContent: {
|
|
114
|
+
sessionId: search.sessionId,
|
|
115
|
+
isComplete: search.isComplete,
|
|
116
|
+
outcome: search.outcome,
|
|
117
|
+
totalResults: search.totalMatches,
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** get_more_search_results' answer: one page of a search's results (a negative offset: its last results) */
|
|
122
|
+
export function searchResultsAnswer(page, offset) {
|
|
123
|
+
if (page.outcome === 'failed')
|
|
124
|
+
return failedAnswer(page);
|
|
125
|
+
let text = `Search session: ${page.sessionId}\n`;
|
|
126
|
+
text += `Status: ${page.isComplete ? 'COMPLETED' : 'IN PROGRESS'}\n`;
|
|
127
|
+
text += `Runtime: ${Math.round(page.runtime / 1000)}s\n`;
|
|
128
|
+
text += `Total results: ${SEARCH_WORDS.total(page.totalMatches, page.totalResults)}\n`;
|
|
129
|
+
if (page.returnedCount > 0) {
|
|
130
|
+
text += offset < 0
|
|
131
|
+
? `Showing last ${page.returnedCount} results\n`
|
|
132
|
+
: `Showing results ${offset}-${offset + page.returnedCount - 1}\n`;
|
|
133
|
+
}
|
|
134
|
+
text += '\n';
|
|
135
|
+
const nextOffset = offset + page.returnedCount;
|
|
136
|
+
if (page.returnedCount === 0) {
|
|
137
|
+
if (!page.isComplete)
|
|
138
|
+
text += SEARCH_WORDS.noneYet(offset, page.totalResults);
|
|
139
|
+
else
|
|
140
|
+
text += page.totalResults === 0 ? SEARCH_WORDS.noMatches : SEARCH_WORDS.noneAtOffset(offset, page.totalResults);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
text += 'Results:\n';
|
|
144
|
+
for (const result of page.results) {
|
|
145
|
+
text += `${resultRow(result)}\n`;
|
|
146
|
+
}
|
|
147
|
+
if (offset >= 0 && nextOffset < page.totalResults) {
|
|
148
|
+
text += `\n${SEARCH_WORDS.moreResults(nextOffset)}`;
|
|
149
|
+
}
|
|
150
|
+
else if (!page.isComplete) {
|
|
151
|
+
text += `\n${SEARCH_WORDS.moreMayCome}`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (page.skippedLines.length > 0) {
|
|
155
|
+
text += `\n${describeSkippedLines(page.skippedLines)}`;
|
|
156
|
+
}
|
|
157
|
+
const ended = endedText(page);
|
|
158
|
+
if (ended)
|
|
159
|
+
text += `\n${ended}`;
|
|
160
|
+
return {
|
|
161
|
+
content: [{ type: 'text', text }],
|
|
162
|
+
structuredContent: {
|
|
163
|
+
sessionId: page.sessionId,
|
|
164
|
+
isComplete: page.isComplete,
|
|
165
|
+
outcome: page.outcome,
|
|
166
|
+
totalResults: page.totalResults,
|
|
167
|
+
totalMatches: page.totalMatches,
|
|
168
|
+
returnedCount: page.returnedCount,
|
|
169
|
+
hasMoreResults: page.hasMoreResults,
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { searchManager } from '../search-manager.js';
|
|
2
2
|
import { StartSearchArgsSchema, GetMoreSearchResultsArgsSchema, StopSearchArgsSchema } from '../tools/schemas.js';
|
|
3
3
|
import { capture } from '../utils/capture.js';
|
|
4
|
+
import { startSearchAnswer, searchResultsAnswer } from './search-answers.js';
|
|
4
5
|
/**
|
|
5
6
|
* Handle start_search command
|
|
6
7
|
*/
|
|
@@ -26,36 +27,7 @@ export async function handleStartSearch(args) {
|
|
|
26
27
|
earlyTermination: parsed.data.earlyTermination,
|
|
27
28
|
literalSearch: parsed.data.literalSearch,
|
|
28
29
|
});
|
|
29
|
-
|
|
30
|
-
let output = `Started ${searchTypeText} session: ${result.sessionId}\n`;
|
|
31
|
-
output += `Pattern: "${parsed.data.pattern}"\n`;
|
|
32
|
-
output += `Path: ${parsed.data.path}\n`;
|
|
33
|
-
output += `Status: ${result.isComplete ? 'COMPLETED' : 'RUNNING'}\n`;
|
|
34
|
-
output += `Runtime: ${Math.round(result.runtime)}ms\n`;
|
|
35
|
-
output += `Total results: ${result.totalResults}\n\n`;
|
|
36
|
-
if (result.results.length > 0) {
|
|
37
|
-
output += "Initial results:\n";
|
|
38
|
-
for (const searchResult of result.results.slice(0, 10)) {
|
|
39
|
-
if (searchResult.type === 'content') {
|
|
40
|
-
output += `š ${searchResult.file}:${searchResult.line} - ${searchResult.match?.substring(0, 100)}${searchResult.match && searchResult.match.length > 100 ? '...' : ''}\n`;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
output += `š ${searchResult.file}\n`;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (result.results.length > 10) {
|
|
47
|
-
output += `... and ${result.results.length - 10} more results\n`;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (result.isComplete) {
|
|
51
|
-
output += `\nā
Search completed.`;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
output += `\nš Search in progress. Use get_more_search_results to get more results.`;
|
|
55
|
-
}
|
|
56
|
-
return {
|
|
57
|
-
content: [{ type: "text", text: output }],
|
|
58
|
-
};
|
|
30
|
+
return startSearchAnswer(result, parsed.data);
|
|
59
31
|
}
|
|
60
32
|
catch (error) {
|
|
61
33
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -78,68 +50,8 @@ export async function handleGetMoreSearchResults(args) {
|
|
|
78
50
|
};
|
|
79
51
|
}
|
|
80
52
|
try {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
// Permission errors should not block returning found results
|
|
84
|
-
if (results.isError && results.totalResults === 0 && results.error?.trim()) {
|
|
85
|
-
return {
|
|
86
|
-
content: [{
|
|
87
|
-
type: "text",
|
|
88
|
-
text: `Search session ${parsed.data.sessionId} encountered an error: ${results.error}`
|
|
89
|
-
}],
|
|
90
|
-
isError: true,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
// Format results for display
|
|
94
|
-
let output = `Search session: ${parsed.data.sessionId}\n`;
|
|
95
|
-
output += `Status: ${results.isComplete ? 'COMPLETED' : 'IN PROGRESS'}\n`;
|
|
96
|
-
output += `Runtime: ${Math.round(results.runtime / 1000)}s\n`;
|
|
97
|
-
output += `Total results found: ${results.totalResults} (${results.totalMatches} matches)\n`;
|
|
98
|
-
const offset = parsed.data.offset;
|
|
99
|
-
if (offset < 0) {
|
|
100
|
-
// Negative offset - tail behavior
|
|
101
|
-
output += `Showing last ${results.returnedCount} results\n\n`;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
// Positive offset - range behavior
|
|
105
|
-
const startPos = offset;
|
|
106
|
-
const endPos = startPos + results.returnedCount - 1;
|
|
107
|
-
output += `Showing results ${startPos}-${endPos}\n\n`;
|
|
108
|
-
}
|
|
109
|
-
if (results.results.length === 0) {
|
|
110
|
-
if (results.isComplete) {
|
|
111
|
-
output += results.totalResults === 0 ? "No matches found." : "No results in this range.";
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
output += "No results yet, search is still running...";
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
output += "Results:\n";
|
|
119
|
-
for (const result of results.results) {
|
|
120
|
-
if (result.type === 'content') {
|
|
121
|
-
output += `š ${result.file}:${result.line} - ${result.match?.substring(0, 100)}${result.match && result.match.length > 100 ? '...' : ''}\n`;
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
output += `š ${result.file}\n`;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
// Add pagination hints
|
|
129
|
-
if (offset >= 0 && results.hasMoreResults) {
|
|
130
|
-
const nextOffset = offset + results.returnedCount;
|
|
131
|
-
output += `\nš More results available. Use get_more_search_results with offset: ${nextOffset}`;
|
|
132
|
-
}
|
|
133
|
-
if (results.isComplete) {
|
|
134
|
-
output += `\nā
Search completed.`;
|
|
135
|
-
// Warn users if search was incomplete due to permission issues
|
|
136
|
-
if (results.wasIncomplete) {
|
|
137
|
-
output += `\nā ļø Warning: Some files were inaccessible due to permissions. Results may be incomplete.`;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
content: [{ type: "text", text: output }],
|
|
142
|
-
};
|
|
53
|
+
const page = searchManager.readSearchResults(parsed.data.sessionId, parsed.data.offset, parsed.data.length);
|
|
54
|
+
return searchResultsAnswer(page, parsed.data.offset);
|
|
143
55
|
}
|
|
144
56
|
catch (error) {
|
|
145
57
|
const errorMessage = error instanceof Error ? error.message : String(error);
|