@wonderwhy-er/desktop-commander 0.2.51 → 0.3.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.
Files changed (121) hide show
  1. package/README.md +14 -24
  2. package/dist/command-manager.d.ts +7 -2
  3. package/dist/command-manager.js +16 -11
  4. package/dist/config-manager.d.ts +55 -3
  5. package/dist/config-manager.js +329 -87
  6. package/dist/config-recovery.d.ts +28 -0
  7. package/dist/config-recovery.js +81 -0
  8. package/dist/config.d.ts +1 -0
  9. package/dist/config.js +9 -0
  10. package/dist/handlers/filesystem-handlers.d.ts +1 -1
  11. package/dist/handlers/filesystem-handlers.js +26 -16
  12. package/dist/handlers/search-answers.d.ts +58 -0
  13. package/dist/handlers/search-answers.js +172 -0
  14. package/dist/handlers/search-handlers.js +4 -92
  15. package/dist/index.js +14 -7
  16. package/dist/npm-scripts/remote.js +47 -4
  17. package/dist/remote-device/desktop-commander-integration.d.ts +21 -0
  18. package/dist/remote-device/desktop-commander-integration.js +121 -40
  19. package/dist/remote-device/device-authenticator.d.ts +13 -1
  20. package/dist/remote-device/device-authenticator.js +87 -47
  21. package/dist/remote-device/device.d.ts +14 -0
  22. package/dist/remote-device/device.js +244 -51
  23. package/dist/remote-device/diagnostics/device-log.d.ts +63 -0
  24. package/dist/remote-device/diagnostics/device-log.js +219 -0
  25. package/dist/remote-device/diagnostics/redact.d.ts +1 -0
  26. package/dist/remote-device/diagnostics/redact.js +76 -0
  27. package/dist/remote-device/diagnostics/report.d.ts +118 -0
  28. package/dist/remote-device/diagnostics/report.js +748 -0
  29. package/dist/remote-device/diagnostics/upload.d.ts +11 -0
  30. package/dist/remote-device/diagnostics/upload.js +59 -0
  31. package/dist/remote-device/realtime-health-telemetry.d.ts +35 -0
  32. package/dist/remote-device/realtime-health-telemetry.js +110 -0
  33. package/dist/remote-device/remote-channel.d.ts +86 -5
  34. package/dist/remote-device/remote-channel.js +470 -68
  35. package/dist/remote-device/scripts/blocking-offline-update.js +108 -69
  36. package/dist/remote-device/transport-telemetry.d.ts +32 -0
  37. package/dist/remote-device/transport-telemetry.js +48 -0
  38. package/dist/search-manager.d.ts +239 -27
  39. package/dist/search-manager.js +746 -312
  40. package/dist/server.js +157 -303
  41. package/dist/terminal-manager.d.ts +138 -21
  42. package/dist/terminal-manager.js +300 -215
  43. package/dist/tools/config.d.ts +1 -1
  44. package/dist/tools/config.js +21 -70
  45. package/dist/tools/edit.js +12 -4
  46. package/dist/tools/filesystem.d.ts +30 -6
  47. package/dist/tools/filesystem.js +246 -140
  48. package/dist/tools/improved-process-tools.d.ts +9 -3
  49. package/dist/tools/improved-process-tools.js +171 -68
  50. package/dist/tools/pdf/extract-images.d.ts +2 -0
  51. package/dist/tools/pdf/extract-images.js +4 -1
  52. package/dist/tools/pdf/index.d.ts +5 -3
  53. package/dist/tools/pdf/index.js +4 -3
  54. package/dist/tools/pdf/lib/pdf2md.d.ts +8 -1
  55. package/dist/tools/pdf/lib/pdf2md.js +12 -5
  56. package/dist/tools/pdf/manipulations.d.ts +12 -1
  57. package/dist/tools/pdf/manipulations.js +17 -4
  58. package/dist/tools/pdf/markdown.d.ts +96 -0
  59. package/dist/tools/pdf/markdown.js +485 -20
  60. package/dist/tools/pdf/utils.d.ts +2 -2
  61. package/dist/tools/pdf/utils.js +4 -4
  62. package/dist/tools/process.js +8 -5
  63. package/dist/tools/schemas.d.ts +1 -11
  64. package/dist/tools/schemas.js +15 -14
  65. package/dist/types.d.ts +1 -1
  66. package/dist/ui/config-editor/config-editor-runtime.js +53 -53
  67. package/dist/ui/config-editor/src/app.js +2 -15
  68. package/dist/ui/file-preview/preview-runtime.js +190 -182
  69. package/dist/utils/ab-test.js +27 -9
  70. package/dist/utils/atomic-write.d.ts +14 -0
  71. package/dist/utils/atomic-write.js +80 -0
  72. package/dist/utils/capture.d.ts +17 -1
  73. package/dist/utils/capture.js +177 -68
  74. package/dist/utils/exit-process.d.ts +24 -0
  75. package/dist/utils/exit-process.js +31 -0
  76. package/dist/utils/feature-flags.js +2 -1
  77. package/dist/utils/files/base.d.ts +3 -1
  78. package/dist/utils/files/docx.d.ts +3 -0
  79. package/dist/utils/files/docx.js +24 -9
  80. package/dist/utils/files/excel.d.ts +10 -0
  81. package/dist/utils/files/excel.js +93 -33
  82. package/dist/utils/files/factory.d.ts +22 -1
  83. package/dist/utils/files/factory.js +59 -4
  84. package/dist/utils/files/image.d.ts +12 -4
  85. package/dist/utils/files/image.js +19 -8
  86. package/dist/utils/files/index.d.ts +5 -3
  87. package/dist/utils/files/index.js +4 -3
  88. package/dist/utils/files/pdf.js +18 -36
  89. package/dist/utils/files/text.d.ts +21 -5
  90. package/dist/utils/files/text.js +90 -86
  91. package/dist/utils/internal-facts.d.ts +3 -0
  92. package/dist/utils/internal-facts.js +23 -0
  93. package/dist/utils/lazy-package.d.ts +25 -0
  94. package/dist/utils/lazy-package.js +44 -0
  95. package/dist/utils/open-browser.js +2 -1
  96. package/dist/utils/process-detection.d.ts +24 -5
  97. package/dist/utils/process-detection.js +199 -89
  98. package/dist/utils/process-tree.d.ts +14 -0
  99. package/dist/utils/process-tree.js +223 -0
  100. package/dist/utils/rename.d.ts +9 -0
  101. package/dist/utils/rename.js +74 -0
  102. package/dist/utils/ripgrep-resolver.js +9 -14
  103. package/dist/utils/shell.d.ts +42 -0
  104. package/dist/utils/shell.js +187 -0
  105. package/dist/utils/system-info.d.ts +1 -0
  106. package/dist/utils/system-info.js +40 -25
  107. package/dist/utils/trackTools.js +2 -1
  108. package/dist/utils/usageTracker.d.ts +0 -39
  109. package/dist/utils/usageTracker.js +1 -161
  110. package/dist/version.d.ts +1 -1
  111. package/dist/version.js +1 -1
  112. package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -0
  113. package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -0
  114. package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +38 -0
  115. package/node_modules/@desktop-commander/telemetry-contract/transport.js +164 -0
  116. package/package.json +32 -16
  117. package/vendor/telemetry-contract/README.md +56 -0
  118. package/vendor/telemetry-contract/package.json +32 -0
  119. package/vendor/telemetry-contract/transport.d.ts +38 -0
  120. package/vendor/telemetry-contract/transport.js +164 -0
  121. package/vendor/telemetry-contract/transport.test.js +39 -0
package/dist/server.js CHANGED
@@ -7,21 +7,26 @@ import { getSystemInfo, getOSSpecificGuidance, getPathGuidance, getDevelopmentTo
7
7
  const SYSTEM_INFO = getSystemInfo();
8
8
  const OS_GUIDANCE = getOSSpecificGuidance(SYSTEM_INFO);
9
9
  const DEV_TOOL_GUIDANCE = getDevelopmentToolGuidance(SYSTEM_INFO);
10
- const PATH_GUIDANCE = `IMPORTANT: ${getPathGuidance(SYSTEM_INFO)} 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.`;
10
+ const PATH_GUIDANCE = `${getPathGuidance(SYSTEM_INFO)} Relative paths depend on the current working directory, and tilde paths (~/...) may not resolve in every context. Absolute paths are generally the most reliable.`;
11
11
  const CMD_PREFIX_DESCRIPTION = `This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.`;
12
- import { StartProcessArgsSchema, ReadProcessOutputArgsSchema, InteractWithProcessArgsSchema, ForceTerminateArgsSchema, ListSessionsArgsSchema, KillProcessArgsSchema, ReadFileArgsSchema, ReadMultipleFilesArgsSchema, WriteFileArgsSchema, CreateDirectoryArgsSchema, ListDirectoryArgsSchema, MoveFileArgsSchema, GetFileInfoArgsSchema, GetConfigArgsSchema, SetConfigValueArgsSchema, ListProcessesArgsSchema, EditBlockArgsSchema, GetUsageStatsArgsSchema, GiveFeedbackArgsSchema, StartSearchArgsSchema, GetMoreSearchResultsArgsSchema, StopSearchArgsSchema, ListSearchesArgsSchema, GetPromptsArgsSchema, GetRecentToolCallsArgsSchema, WritePdfArgsSchema, toolArgSchemas, } from './tools/schemas.js';
12
+ const SERVER_INSTRUCTIONS = `Desktop Commander provides tools for working with the user's authorized device.
13
+ - Filesystem tools handle direct file and directory operations within configured access boundaries.
14
+ - Terminal process tools support shell commands, REPLs, and long-running processes. start_process creates a process session; interact_with_process sends input; read_process_output reads later output; force_terminate ends a session.
15
+ - Search tools are session-based. start_search creates a search session; get_more_search_results reads its results; stop_search ends it early.
16
+ - Absolute paths are generally the most reliable because relative paths depend on the active working directory.
17
+ - allowedDirectories and each tool's schema, annotations, and documented constraints define the operational boundaries.`;
18
+ import { StartProcessArgsSchema, ReadProcessOutputArgsSchema, InteractWithProcessArgsSchema, ForceTerminateArgsSchema, ListSessionsArgsSchema, KillProcessArgsSchema, ReadFileArgsSchema, ReadMultipleFilesArgsSchema, WriteFileArgsSchema, CreateDirectoryArgsSchema, ListDirectoryArgsSchema, MoveFileArgsSchema, GetFileInfoArgsSchema, GetConfigArgsSchema, SetConfigValueArgsSchema, ListProcessesArgsSchema, EditBlockArgsSchema, GetUsageStatsArgsSchema, GiveFeedbackArgsSchema, StartSearchArgsSchema, GetMoreSearchResultsArgsSchema, StopSearchArgsSchema, ListSearchesArgsSchema, GetRecentToolCallsArgsSchema, WritePdfArgsSchema, toolArgSchemas, } from './tools/schemas.js';
13
19
  import { detectUnsupportedParams, getSupportedParams, buildUnsupportedParamsWarning, } from './utils/unsupportedParams.js';
14
20
  import { getConfig, setConfigValue } from './tools/config.js';
15
21
  import { getUsageStats } from './tools/usage.js';
16
22
  import { giveFeedbackToDesktopCommander } from './tools/feedback.js';
17
- import { getPrompts } from './tools/prompts.js';
18
23
  import { trackToolCall } from './utils/trackTools.js';
19
24
  import { usageTracker } from './utils/usageTracker.js';
20
25
  import { processDockerPrompt } from './utils/dockerPrompt.js';
21
26
  import { toolHistory } from './utils/toolHistory.js';
22
27
  import { handleWelcomePageOnboarding, skipWelcomePageOnboarding } from './utils/welcome-onboarding.js';
23
28
  import { VERSION } from './version.js';
24
- import { capture, capture_call_tool, runInUiOriginCallContext } from "./utils/capture.js";
29
+ import { addToolCallPaths, capture, capture_call_tool, runInUiOriginCallContext, runWithToolCallPaths } from "./utils/capture.js";
25
30
  import { logToStderr, logger } from './utils/logger.js';
26
31
  import { buildUiToolMeta, CONFIG_EDITOR_RESOURCE_URI, FILE_PREVIEW_RESOURCE_URI, } from './ui/contracts.js';
27
32
  import { listUiResources, readUiResource } from './ui/resources.js';
@@ -190,6 +195,7 @@ server.setRequestHandler(InitializeRequestSchema, async (request) => {
190
195
  name: "desktop-commander",
191
196
  version: VERSION,
192
197
  },
198
+ instructions: SERVER_INSTRUCTIONS,
193
199
  };
194
200
  }
195
201
  catch (error) {
@@ -206,7 +212,7 @@ deferLog('info', 'Setting up request handlers...');
206
212
  function shouldIncludeTool(toolName) {
207
213
  // Exclude these tools for desktop-commander client (DC-specific meta-tools not useful when DC itself is the client)
208
214
  if (currentClient?.name === 'desktop-commander-app') {
209
- if (toolName === 'give_feedback_to_desktop_commander' || toolName === 'get_prompts') {
215
+ if (toolName === 'give_feedback_to_desktop_commander') {
210
216
  return false;
211
217
  }
212
218
  }
@@ -241,6 +247,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
241
247
  annotations: {
242
248
  title: "Get Configuration",
243
249
  readOnlyHint: true,
250
+ openWorldHint: false,
251
+ destructiveHint: false,
244
252
  },
245
253
  },
246
254
  {
@@ -248,8 +256,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
248
256
  description: `
249
257
  Set a specific configuration value by key.
250
258
 
251
- WARNING: Should be used in a separate chat from file operations and
252
- command execution to prevent security issues.
259
+ Security note: configuration changes affect later file and command behavior.
260
+ Isolating them from untrusted file or command content reduces the chance that external content influences configuration.
253
261
 
254
262
  Config keys include:
255
263
  - blockedCommands (array)
@@ -278,7 +286,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
278
286
  Read contents from files and URLs.
279
287
  Read PDF files and extract content as markdown and images.
280
288
 
281
- Prefer this over 'execute_command' with cat/type for viewing files.
289
+ Suitable for reading authorized local files directly without starting a shell command.
282
290
 
283
291
  Supports partial file reading with:
284
292
  - 'offset' (start line, default: 0)
@@ -307,7 +315,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
307
315
  - Text: Uses offset/length for line-based pagination
308
316
  - Excel (.xlsx, .xls, .xlsm): Returns JSON 2D array
309
317
  * sheet: "Sheet1" (name) or "0" (index as string, 0-based)
310
- * range: ALWAYS use FROM:TO format (e.g., "A1:D100", "C1:C1", "B2:B50")
318
+ * range uses FROM:TO format (e.g., "A1:D100", "C1:C1", "B2:B50")
311
319
  * offset/length work as row pagination (optional fallback)
312
320
  - Images (PNG, JPEG, GIF, WebP): Base64 encoded viewable content
313
321
  - PDF: Extracts text content as markdown with page structure
@@ -319,13 +327,12 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
319
327
  Each element shows its body index [0], [1], etc.
320
328
  * WITH offset/length: Returns raw pretty-printed XML with line pagination.
321
329
  Use this to drill into specific sections or see the actual XML for editing.
322
- * EDITING WORKFLOW: 1) read_file to get outline, 2) read_file with offset/length
323
- to see raw XML around what you want to edit, 3) edit_block with old_string/new_string
324
- using XML fragments copied from the read output.
325
- * IMPORTANT: offset MUST be non-zero to get raw XML (use offset=1 to start from line 1).
326
- offset=0 always returns the outline regardless of length.
327
- * For BULK changes (translation, mass replacements): use start_process with Python
328
- zipfile module to find/replace all <w:t> elements at once.
330
+ * Raw DOCX XML output is compatible with edit_block's XML find/replace mode using
331
+ XML fragments copied from the read output.
332
+ * Raw XML mode requires a non-zero offset (offset=1 starts from line 1).
333
+ offset=0 returns the outline regardless of length.
334
+ * Bulk transformations can be performed programmatically against the DOCX archive
335
+ when the task requires changes across many XML text nodes.
329
336
 
330
337
  ${PATH_GUIDANCE}
331
338
  ${CMD_PREFIX_DESCRIPTION}`,
@@ -335,6 +342,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
335
342
  title: "Read File or URL",
336
343
  readOnlyHint: true,
337
344
  openWorldHint: true,
345
+ destructiveHint: false,
338
346
  },
339
347
  },
340
348
  {
@@ -355,6 +363,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
355
363
  annotations: {
356
364
  title: "Read Multiple Files",
357
365
  readOnlyHint: true,
366
+ openWorldHint: false,
367
+ destructiveHint: false,
358
368
  },
359
369
  },
360
370
  {
@@ -362,37 +372,20 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
362
372
  description: `
363
373
  Write or append to file contents.
364
374
 
365
- IMPORTANT: DO NOT use this tool to create PDF files. Use 'write_pdf' for all PDF creation tasks.
366
- DO NOT use this tool to edit DOCX files. Use 'edit_block' with old_string/new_string instead.
367
- To CREATE a new DOCX, use write_file with .docx extension — text content with markdown headings (#, ##, ###) is converted to styled DOCX paragraphs.
368
-
369
- CHUNKING IS STANDARD PRACTICE: Always write files in chunks of 25-30 lines maximum.
370
- This is the normal, recommended way to write files - not an emergency measure.
375
+ PDF creation is handled by the dedicated write_pdf tool.
376
+ Existing DOCX content can be edited with edit_block. New DOCX files can be created here; markdown headings (#, ##, ###) are converted to styled DOCX paragraphs.
371
377
 
372
- STANDARD PROCESS FOR ANY FILE:
373
- 1. FIRST → write_file(filePath, firstChunk, {mode: 'rewrite'}) [≤30 lines]
374
- 2. THEN → write_file(filePath, secondChunk, {mode: 'append'}) [≤30 lines]
375
- 3. CONTINUE → write_file(filePath, nextChunk, {mode: 'append'}) [≤30 lines]
376
-
377
- ALWAYS CHUNK PROACTIVELY - don't wait for performance warnings!
378
-
379
- WHEN TO CHUNK (always be proactive):
380
- 1. Any file expected to be longer than 25-30 lines
381
- 2. When writing multiple files in sequence
382
- 3. When creating documentation, code files, or configuration files
383
-
384
- HANDLING CONTINUATION ("Continue" prompts):
385
- If user asks to "Continue" after an incomplete operation:
386
- 1. Read the file to see what was successfully written
387
- 2. Continue writing ONLY the remaining content using {mode: 'append'}
388
- 3. Keep chunks to 25-30 lines each
378
+ CHUNKED WRITES:
379
+ - Repeated calls with mode='rewrite' followed by mode='append' are supported for longer files.
380
+ - Chunks of roughly 25-30 lines minimize latency when writing long text, multiple files, documentation, code, or configuration files.
381
+ - Files over 50 lines are still written successfully but may generate performance notes.
382
+ - For continuation after a partial write, the existing file state can be inspected before appending the remaining content.
389
383
 
390
384
  FORMAT HANDLING (by extension):
391
385
  - Text files: String content
392
386
  - Excel (.xlsx, .xls, .xlsm): JSON 2D array or {"SheetName": [[...]]}
393
387
  Example: '[["Name","Age"],["Alice",30]]'
394
388
 
395
- Files over 50 lines will generate performance notes but are still written successfully.
396
389
  Only works within allowed directories.
397
390
 
398
391
  ${PATH_GUIDANCE}
@@ -411,10 +404,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
411
404
  description: `
412
405
  Create a new PDF file or modify an existing one.
413
406
 
414
- THIS IS THE ONLY TOOL FOR CREATING AND MODIFYING PDF FILES.
407
+ Dedicated PDF creation and modification tool.
415
408
 
416
- RULES ABOUT FILENAMES:
417
- - When creating a new PDF, 'outputPath' MUST be provided and MUST use a new unique filename (e.g., "result_01.pdf", "analysis_2025_01.pdf", etc.).
409
+ OUTPUT FILES:
410
+ - Creating a PDF requires 'outputPath' with a new filename (e.g., "result_01.pdf", "analysis_2025_01.pdf", etc.).
418
411
 
419
412
  MODES:
420
413
  1. CREATE NEW PDF:
@@ -423,9 +416,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
423
416
 
424
417
  2. MODIFY EXISTING PDF:
425
418
  - Pass array of operations as 'content'.
426
- - NEVER overwrite the original file.
427
- - ALWAYS provide a new filename in 'outputPath'.
428
- - After modifying, show original file path and new file path to user.
419
+ - Modifications preserve the original PDF and require a different filename in 'outputPath'.
420
+ - The result includes the original and output paths for reference.
429
421
 
430
422
  write_pdf(path="doc.pdf", content=[
431
423
  { type: "delete", pageIndexes: [0, 2] },
@@ -482,6 +474,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
482
474
  annotations: {
483
475
  title: "Create Directory",
484
476
  readOnlyHint: false,
477
+ openWorldHint: false,
485
478
  destructiveHint: false,
486
479
  },
487
480
  },
@@ -490,7 +483,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
490
483
  description: `
491
484
  Get a detailed listing of all files and directories in a specified path.
492
485
 
493
- Use this instead of 'execute_command' with ls/dir commands.
486
+ Returns a structured directory listing without starting a shell command.
494
487
  Results distinguish between files and directories with [FILE] and [DIR] prefixes.
495
488
 
496
489
  Supports recursive listing with the 'depth' parameter (default: 2):
@@ -523,6 +516,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
523
516
  annotations: {
524
517
  title: "List Directory Contents",
525
518
  readOnlyHint: true,
519
+ openWorldHint: false,
520
+ destructiveHint: false,
526
521
  },
527
522
  },
528
523
  {
@@ -564,13 +559,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
564
559
  - Finding patterns in code: "console.log statements", "import statements"
565
560
  - User describes functionality: "components that handle login", "files with database queries"
566
561
 
567
- WHEN UNSURE OR USER REQUEST IS AMBIGUOUS:
568
- Run TWO searches in parallel - one for files and one for content:
569
-
570
- Example approach for ambiguous queries like "find authentication stuff":
571
- 1. Start file search: searchType="files", pattern="auth"
572
- 2. Simultaneously start content search: searchType="content", pattern="authentication"
573
- 3. Present combined results: "Found 3 auth-related files and 8 files containing authentication code"
562
+ AMBIGUOUS SEARCHES:
563
+ Queries that could refer to either filenames or file contents can be covered with two
564
+ searches: one with searchType="files" and one with searchType="content".
565
+ Example: "find authentication stuff" can pair a filename search for "auth" with a
566
+ content search for "authentication".
574
567
 
575
568
  SEARCH TYPES:
576
569
  - searchType="files": Find files by name (pattern matches file names)
@@ -580,8 +573,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
580
573
  - Default (literalSearch=false): Patterns are treated as regular expressions
581
574
  - Literal (literalSearch=true): Patterns are treated as exact strings
582
575
 
583
- WHEN TO USE literalSearch=true:
584
- Use literal search when searching for code patterns with special characters:
576
+ literalSearch=true is useful for code patterns with special characters:
585
577
  - Function calls with parentheses and quotes
586
578
  - Array access with brackets
587
579
  - Object methods with dots and parentheses
@@ -612,12 +604,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
612
604
  1. searchType="files", pattern="auth"
613
605
  2. searchType="content", pattern="authentication"
614
606
 
615
- PRO TIP: When user requests are ambiguous about whether they want files or content,
616
- run both searches concurrently and combine results for comprehensive coverage.
607
+ Ambiguous requests can combine file-name and content searches for broader coverage.
617
608
 
618
- Unlike regular search tools, this starts a background search process and returns
619
- immediately with a session ID. Use get_more_search_results to get results as they
620
- come in, and stop_search to stop the search early if needed.
609
+ This tool starts a background search process and returns immediately with a session ID.
610
+ Results are available through get_more_search_results, and stop_search can end the search early.
621
611
 
622
612
  Perfect for large directories where you want to see results immediately and
623
613
  have the option to cancel if the search takes too long or you find what you need.
@@ -628,6 +618,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
628
618
  annotations: {
629
619
  title: "Start Search",
630
620
  readOnlyHint: true,
621
+ openWorldHint: false,
622
+ destructiveHint: false,
631
623
  },
632
624
  },
633
625
  {
@@ -658,6 +650,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
658
650
  annotations: {
659
651
  title: "Get Search Results",
660
652
  readOnlyHint: true,
653
+ openWorldHint: false,
654
+ destructiveHint: false,
661
655
  },
662
656
  },
663
657
  {
@@ -677,6 +671,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
677
671
  annotations: {
678
672
  title: "Stop Search",
679
673
  readOnlyHint: false,
674
+ openWorldHint: false,
680
675
  destructiveHint: false,
681
676
  },
682
677
  },
@@ -694,6 +689,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
694
689
  annotations: {
695
690
  title: "List Active Searches",
696
691
  readOnlyHint: true,
692
+ openWorldHint: false,
693
+ destructiveHint: false,
697
694
  },
698
695
  },
699
696
  {
@@ -718,6 +715,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
718
715
  annotations: {
719
716
  title: "Get File Information",
720
717
  readOnlyHint: true,
718
+ openWorldHint: false,
719
+ destructiveHint: false,
721
720
  },
722
721
  },
723
722
  // Note: list_allowed_directories removed - use get_config to check allowedDirectories
@@ -727,16 +726,15 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
727
726
  description: `
728
727
  Apply surgical edits to files.
729
728
 
730
- BEST PRACTICE: Make multiple small, focused edits rather than one large edit.
731
- Each edit_block call should change only what needs to be changed - include just enough
732
- context to uniquely identify the text being modified.
729
+ Small, focused edits are easier to verify than large multi-purpose replacements.
730
+ old_string can include enough surrounding context to uniquely identify the intended text.
733
731
 
734
732
  FORMAT HANDLING (by extension):
735
733
 
736
734
  EXCEL FILES (.xlsx, .xls, .xlsm) - Range Update mode:
737
735
  Takes:
738
736
  - file_path: Path to the Excel file
739
- - range: ALWAYS use FROM:TO format - "SheetName!A1:C10" or "SheetName!C1:C1"
737
+ - range uses FROM:TO format - "SheetName!A1:C10" or "SheetName!C1:C1"
740
738
  - content: 2D array, e.g., [["H1","H2"],["R1","R2"]]
741
739
 
742
740
  TEXT FILES - Find/Replace mode:
@@ -790,47 +788,27 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
790
788
  {
791
789
  name: "start_process",
792
790
  description: `
793
- Start a new terminal process with intelligent state detection.
794
-
795
- PRIMARY TOOL FOR FILE ANALYSIS AND DATA PROCESSING
796
- This is the ONLY correct tool for analyzing local files (CSV, JSON, logs, etc.).
797
- The analysis tool CANNOT access local files and WILL FAIL - always use processes for file-based work.
791
+ Start a terminal process on the authorized device with intelligent state detection.
798
792
 
799
- CRITICAL RULE: For ANY local file work, ALWAYS use this tool + interact_with_process, NEVER use analysis/REPL tool.
793
+ Suitable for shell commands, interactive REPL sessions, data-processing scripts,
794
+ programmatic file analysis, and other long-running terminal work.
800
795
 
801
796
  ${OS_GUIDANCE}
802
797
 
803
- REQUIRED WORKFLOW FOR LOCAL FILES:
804
- 1. start_process("python3 -i") - Start Python REPL for data analysis
805
- 2. interact_with_process(pid, "import pandas as pd, numpy as np")
806
- 3. interact_with_process(pid, "df = pd.read_csv('/absolute/path/file.csv')")
807
- 4. interact_with_process(pid, "print(df.describe())")
808
- 5. Continue analysis with pandas, matplotlib, seaborn, etc.
809
-
810
- COMMON FILE ANALYSIS PATTERNS:
811
- • start_process("python3 -i") → Python REPL for data analysis (RECOMMENDED)
812
- • start_process("node -i") → Node.js REPL for JSON processing
813
- • start_process("node:local") → Node.js on MCP server (stateless, ES imports, all code in one call)
814
- • start_process("cut -d',' -f1 file.csv | sort | uniq -c") → Quick CSV analysis
815
- • start_process("wc -l /path/file.csv") → Line counting
816
- • start_process("head -10 /path/file.csv") → File preview
817
-
818
- BINARY FILE SUPPORT:
819
- For PDF, Excel, Word, archives, databases, and other binary formats, use process tools with appropriate libraries or command-line utilities.
820
-
821
- INTERACTIVE PROCESSES FOR DATA ANALYSIS:
822
- For code/calculations, use in this priority order:
823
- 1. start_process("python3 -i") - Python REPL (preferred)
824
- 2. start_process("node -i") - Node.js REPL (when Python unavailable)
825
- 3. start_process("node:local") - Node.js fallback (when node -i fails)
826
- 4. Use interact_with_process() to send commands
827
- 5. Use read_process_output() to get responses
828
- When Python is unavailable, prefer Node.js over shell for calculations.
829
- Node.js: Always use ES import syntax (import x from 'y'), not require().
798
+ Examples:
799
+ • start_process("python3 -i") → Start an interactive Python REPL
800
+ • start_process("node -i") → Start an interactive Node.js REPL
801
+ • start_process("node:local") → Run stateless Node.js code on the MCP server
802
+ • start_process("wc -l /path/file.csv") → Run a one-shot shell command
803
+
804
+ Interactive process sessions support follow-up input after they are started.
805
+ Long-running process sessions expose newly available output while they remain active.
806
+ Binary files can be processed with appropriate command-line tools or libraries available
807
+ in the selected process environment.
830
808
 
831
809
  SMART DETECTION:
832
810
  - Detects REPL prompts (>>>, >, $, etc.)
833
- - Identifies when process is waiting for input
811
+ - Identifies when a process is waiting for input
834
812
  - Recognizes process completion vs timeout
835
813
  - Early exit prevents unnecessary waiting
836
814
 
@@ -845,10 +823,6 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
845
823
  - Total duration and time to first output
846
824
  - Complete timeline of all output events with timestamps
847
825
  - Which detection mechanism triggered early exit
848
- Use this to identify missed optimization opportunities and improve detection patterns.
849
-
850
- ALWAYS USE FOR: Local file analysis, CSV processing, data exploration, system commands
851
- NEVER USE ANALYSIS TOOL FOR: Local file access (analysis tool is browser-only and WILL FAIL)
852
826
 
853
827
  ${PATH_GUIDANCE}
854
828
  ${CMD_PREFIX_DESCRIPTION}`,
@@ -899,65 +873,43 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
899
873
  annotations: {
900
874
  title: "Read Process Output",
901
875
  readOnlyHint: true,
876
+ openWorldHint: false,
877
+ destructiveHint: false,
902
878
  },
903
879
  },
904
880
  {
905
881
  name: "interact_with_process",
906
882
  description: `
907
- Send input to a running process and automatically receive the response.
908
-
909
- CRITICAL: THIS IS THE PRIMARY TOOL FOR ALL LOCAL FILE ANALYSIS
910
- For ANY local file analysis (CSV, JSON, data processing), ALWAYS use this instead of the analysis tool.
911
- The analysis tool CANNOT access local files and WILL FAIL - use processes for ALL file-based work.
912
-
913
- FILE ANALYSIS PRIORITY ORDER (MANDATORY):
914
- 1. ALWAYS FIRST: Use this tool (start_process + interact_with_process) for local data analysis
915
- 2. ALTERNATIVE: Use command-line tools (cut, awk, grep) for quick processing
916
- 3. NEVER EVER: Use analysis tool for local file access (IT WILL FAIL)
883
+ Send input to an existing terminal or REPL process and return newly available output.
917
884
 
918
- REQUIRED INTERACTIVE WORKFLOW FOR FILE ANALYSIS:
919
- 1. Start REPL: start_process("python3 -i")
920
- 2. Load libraries: interact_with_process(pid, "import pandas as pd, numpy as np")
921
- 3. Read file: interact_with_process(pid, "df = pd.read_csv('/absolute/path/file.csv')")
922
- 4. Analyze: interact_with_process(pid, "print(df.describe())")
923
- 5. Continue: interact_with_process(pid, "df.groupby('column').size()")
885
+ Useful for interactive shells, Python/Node/R/Julia REPLs, database consoles,
886
+ and long-running commands started with start_process().
924
887
 
925
- BINARY FILE PROCESSING WORKFLOWS:
926
- Use appropriate Python libraries (PyPDF2, pandas, docx2txt, etc.) or command-line tools for binary file analysis.
888
+ Examples:
889
+ - Interactive Python REPL sessions can be started with \`python3 -i\`.
890
+ - Existing interactive sessions accept additional input such as imports or analysis commands.
891
+ - Interactive sessions can return newly available output while they remain active.
927
892
 
928
893
  SMART DETECTION:
929
- - Automatically waits for REPL prompt (>>>, >, etc.)
894
+ - Automatically waits for a recognized prompt when requested
930
895
  - Detects errors and completion states
931
- - Early exit prevents timeout delays
932
- - Clean output formatting (removes prompts)
933
-
934
- SUPPORTED REPLs:
935
- - Python: python3 -i (RECOMMENDED for data analysis)
936
- - Node.js: node -i
937
- - R: R
938
- - Julia: julia
939
- - Shell: bash, zsh
940
- - Database: mysql, postgres
896
+ - Early exit prevents unnecessary waiting
897
+ - Cleans common REPL prompt text from returned output
941
898
 
942
899
  PARAMETERS:
943
- - pid: Process ID from start_process
944
- - input: Code/command to execute
945
- - timeout_ms: Max wait (default: 8000ms)
946
- - wait_for_prompt: Auto-wait for response (default: true)
947
- - verbose_timing: Enable detailed performance telemetry (default: false)
900
+ - pid: Process ID returned by start_process
901
+ - input: Text or command to send to the process
902
+ - timeout_ms: Maximum wait time (default: 8000ms)
903
+ - wait_for_prompt: Whether to wait for a prompt before returning (default: true)
904
+ - verbose_timing: Include detailed timing telemetry (default: false)
948
905
 
949
906
  Returns execution result with status indicators.
950
907
 
951
908
  PERFORMANCE DEBUGGING (verbose_timing parameter):
952
- Set verbose_timing: true to get detailed timing information including:
953
- - Exit reason (early_exit_quick_pattern, early_exit_periodic_check, process_finished, timeout, no_wait)
909
+ When enabled, detailed timing includes:
910
+ - Exit reason
954
911
  - Total duration and time to first output
955
- - Complete timeline of all output events with timestamps
956
- - Which detection mechanism triggered early exit
957
- Use this to identify slow interactions and optimize detection patterns.
958
-
959
- ALWAYS USE FOR: CSV analysis, JSON processing, file statistics, data visualization prep, ANY local file work
960
- NEVER USE ANALYSIS TOOL FOR: Local file access (it cannot read files from disk and WILL FAIL)
912
+ - Timeline of output events
961
913
 
962
914
  ${CMD_PREFIX_DESCRIPTION}`,
963
915
  inputSchema: zodToJsonSchema(InteractWithProcessArgsSchema),
@@ -1002,6 +954,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
1002
954
  annotations: {
1003
955
  title: "List Terminal Sessions",
1004
956
  readOnlyHint: true,
957
+ openWorldHint: false,
958
+ destructiveHint: false,
1005
959
  },
1006
960
  },
1007
961
  {
@@ -1016,6 +970,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
1016
970
  annotations: {
1017
971
  title: "List Running Processes",
1018
972
  readOnlyHint: true,
973
+ openWorldHint: false,
974
+ destructiveHint: false,
1019
975
  },
1020
976
  },
1021
977
  {
@@ -1046,6 +1002,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
1046
1002
  annotations: {
1047
1003
  title: "Get Usage Statistics",
1048
1004
  readOnlyHint: true,
1005
+ openWorldHint: false,
1006
+ destructiveHint: false,
1049
1007
  },
1050
1008
  },
1051
1009
  {
@@ -1069,6 +1027,8 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
1069
1027
  annotations: {
1070
1028
  title: "Get Recent Tool Calls",
1071
1029
  readOnlyHint: true,
1030
+ openWorldHint: false,
1031
+ destructiveHint: false,
1072
1032
  },
1073
1033
  },
1074
1034
  {
@@ -1076,34 +1036,14 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
1076
1036
  description: `
1077
1037
  Open feedback form in browser to provide feedback about Desktop Commander.
1078
1038
 
1079
- IMPORTANT: This tool simply opens the feedback form - no pre-filling available.
1080
- The user will fill out the form manually in their browser.
1081
-
1082
- WORKFLOW:
1083
- 1. When user agrees to give feedback, just call this tool immediately
1084
- 2. No need to ask questions or collect information
1085
- 3. Tool opens form with only usage statistics pre-filled automatically:
1086
- - tool_call_count: Number of commands they've made
1087
- - days_using: How many days they've used Desktop Commander
1088
- - platform: Their operating system (Mac/Windows/Linux)
1089
- - client_id: Analytics identifier
1090
-
1091
- All survey questions will be answered directly in the form:
1092
- - Job title and technical comfort level
1093
- - Company URL for industry context
1094
- - Other AI tools they use
1095
- - Desktop Commander's biggest advantage
1096
- - How they typically use it
1097
- - Recommendation likelihood (0-10)
1098
- - User study participation interest
1099
- - Email and any additional feedback
1100
-
1101
- EXAMPLE INTERACTION:
1102
- User: "sure, I'll give feedback"
1103
- Claude: "Perfect! Let me open the feedback form for you."
1104
- [calls tool immediately]
1105
-
1106
- No parameters are needed - just call the tool to open the form.
1039
+ The form itself collects survey answers; this tool does not accept survey responses or
1040
+ pre-fill them. It automatically includes basic usage metadata:
1041
+ - tool_call_count: Number of commands made
1042
+ - days_using: Number of days Desktop Commander has been used
1043
+ - platform: Operating system (Mac/Windows/Linux)
1044
+ - client_id: Analytics identifier
1045
+
1046
+ No input parameters are required.
1107
1047
 
1108
1048
  ${CMD_PREFIX_DESCRIPTION}`,
1109
1049
  inputSchema: zodToJsonSchema(GiveFeedbackArgsSchema),
@@ -1111,39 +1051,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
1111
1051
  title: "Give Feedback",
1112
1052
  readOnlyHint: false,
1113
1053
  openWorldHint: true,
1054
+ destructiveHint: false,
1114
1055
  },
1115
1056
  },
1116
- {
1117
- name: "get_prompts",
1118
- description: `
1119
- Retrieve a specific Desktop Commander onboarding prompt by ID and execute it.
1120
-
1121
- SIMPLIFIED ONBOARDING V2: This tool only supports direct prompt retrieval.
1122
- The onboarding system presents 5 options as a simple numbered list:
1123
-
1124
- 1. Organize my Downloads folder (promptId: 'onb2_01')
1125
- 2. Explain a codebase or repository (promptId: 'onb2_02')
1126
- 3. Create organized knowledge base (promptId: 'onb2_03')
1127
- 4. Analyze a data file (promptId: 'onb2_04')
1128
- 5. Check system health and resources (promptId: 'onb2_05')
1129
-
1130
- USAGE:
1131
- When user says "1", "2", "3", "4", or "5" from onboarding:
1132
- - "1" → get_prompts(action='get_prompt', promptId='onb2_01')
1133
- - "2" → get_prompts(action='get_prompt', promptId='onb2_02')
1134
- - "3" → get_prompts(action='get_prompt', promptId='onb2_03')
1135
- - "4" → get_prompts(action='get_prompt', promptId='onb2_04')
1136
- - "5" → get_prompts(action='get_prompt', promptId='onb2_05')
1137
-
1138
- The prompt content will be injected and execution begins immediately.
1139
-
1140
- ${CMD_PREFIX_DESCRIPTION}`,
1141
- inputSchema: zodToJsonSchema(GetPromptsArgsSchema),
1142
- annotations: {
1143
- title: "Get Prompts",
1144
- readOnlyHint: true,
1145
- },
1146
- }
1147
1057
  ];
1148
1058
  // Filter tools based on current client
1149
1059
  const filteredTools = allTools.filter(tool => shouldIncludeTool(tool.name));
@@ -1158,6 +1068,19 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
1158
1068
  }
1159
1069
  });
1160
1070
  import * as handlers from './handlers/index.js';
1071
+ import { withoutInternalFacts } from './utils/internal-facts.js';
1072
+ import { stillLoadingError } from './utils/files/index.js';
1073
+ /**
1074
+ * A tool call on an Excel, DOCX or PDF file whose package is still loading
1075
+ * after initialize answers at once with this error (utils/files/factory.ts)
1076
+ * instead of loading it inside the call. Not sent to telemetry, unlike other
1077
+ * errors: it names the file. read_multiple_files answers per file;
1078
+ * get_file_info waits for the load, or loads it itself, and so does a search.
1079
+ */
1080
+ function stillLoading(filePath, action, options) {
1081
+ const error = typeof filePath === 'string' ? stillLoadingError(filePath, action, options) : undefined;
1082
+ return error === undefined ? undefined : { content: [{ type: 'text', text: `Error: ${error}` }], isError: true };
1083
+ }
1161
1084
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
1162
1085
  const args = request.params.arguments;
1163
1086
  // Calls fired programmatically by the widget UIs (file preview, config
@@ -1167,11 +1090,24 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
1167
1090
  // (server_call_tool, server_read_file, server_edit_block, ...). Deliberate
1168
1091
  // UI interactions are tracked separately via mcp_ui_event.
1169
1092
  const isUiOriginCall = !!(args && typeof args === 'object' && args.origin === 'ui');
1170
- if (isUiOriginCall) {
1171
- return runInUiOriginCallContext(() => handleCallToolRequest(request));
1172
- }
1173
- return handleCallToolRequest(request);
1093
+ // Each call keeps the paths it works on, starting with its path arguments,
1094
+ // so telemetry can replace them whole in any error text the call produces
1095
+ return runWithToolCallPaths(() => {
1096
+ addToolCallPaths(...pathArguments(args));
1097
+ if (isUiOriginCall) {
1098
+ return runInUiOriginCallContext(() => handleCallToolRequest(request));
1099
+ }
1100
+ return handleCallToolRequest(request);
1101
+ });
1174
1102
  });
1103
+ /** The values of the tool arguments that hold paths (path, paths, file_path, outputPath, source, destination, shell, ...). */
1104
+ function pathArguments(args) {
1105
+ if (!args || typeof args !== 'object')
1106
+ return [];
1107
+ return Object.entries(args)
1108
+ .filter(([key]) => /path/i.test(key) || key === 'source' || key === 'destination' || key === 'shell')
1109
+ .map(([, value]) => value);
1110
+ }
1175
1111
  async function handleCallToolRequest(request) {
1176
1112
  const { name, arguments: args } = request.params;
1177
1113
  const startTime = Date.now();
@@ -1213,17 +1149,6 @@ async function handleCallToolRequest(request) {
1213
1149
  if (name === 'set_config_value' && args && typeof args === 'object' && 'key' in args) {
1214
1150
  telemetryData.set_config_value_key_name = args.key;
1215
1151
  }
1216
- if (name === 'get_prompts' && args && typeof args === 'object') {
1217
- const promptArgs = args;
1218
- telemetryData.action = promptArgs.action;
1219
- if (promptArgs.category) {
1220
- telemetryData.category = promptArgs.category;
1221
- telemetryData.has_category_filter = true;
1222
- }
1223
- if (promptArgs.promptId) {
1224
- telemetryData.prompt_id = promptArgs.promptId;
1225
- }
1226
- }
1227
1152
  // Track tool call
1228
1153
  trackToolCall(name, args);
1229
1154
  // Using a more structured approach with dedicated handlers
@@ -1266,50 +1191,6 @@ async function handleCallToolRequest(request) {
1266
1191
  };
1267
1192
  }
1268
1193
  break;
1269
- case "get_prompts":
1270
- try {
1271
- result = await getPrompts(args || {});
1272
- // Capture detailed analytics for all successful get_prompts actions
1273
- if (args && typeof args === 'object' && !result.isError) {
1274
- const action = args.action;
1275
- try {
1276
- if (action === 'get_prompt' && args.promptId) {
1277
- // Existing get_prompt analytics
1278
- const { loadPromptsData } = await import('./tools/prompts.js');
1279
- const promptsData = await loadPromptsData();
1280
- const prompt = promptsData.prompts.find(p => p.id === args.promptId);
1281
- if (prompt) {
1282
- await capture('server_get_prompt', {
1283
- prompt_id: prompt.id,
1284
- prompt_title: prompt.title,
1285
- category: prompt.categories[0] || 'uncategorized',
1286
- author: prompt.author,
1287
- verified: prompt.verified,
1288
- // Temporarily disabled for privacy review - Dec 2025
1289
- // anonymous_use_case: (args as any).anonymous_user_use_case || null
1290
- });
1291
- }
1292
- }
1293
- }
1294
- catch (error) {
1295
- // Don't fail the request if analytics fail
1296
- }
1297
- }
1298
- // Track if user used get_prompts after seeing onboarding invitation (for state management only)
1299
- const onboardingState = await usageTracker.getOnboardingState();
1300
- if (onboardingState.attemptsShown > 0 && !onboardingState.promptsUsed) {
1301
- // Mark that they used prompts after seeing onboarding (stops future onboarding messages)
1302
- await usageTracker.markOnboardingPromptsUsed();
1303
- }
1304
- }
1305
- catch (error) {
1306
- capture('server_request_error', { message: `Error in get_prompts handler: ${error}` });
1307
- result = {
1308
- content: [{ type: "text", text: `Error: Failed to retrieve prompts` }],
1309
- isError: true,
1310
- };
1311
- }
1312
- break;
1313
1194
  case "get_recent_tool_calls":
1314
1195
  try {
1315
1196
  result = await handlers.handleGetRecentToolCalls(args);
@@ -1372,17 +1253,22 @@ async function handleCallToolRequest(request) {
1372
1253
  // Note: REPL functionality removed in favor of using general terminal commands
1373
1254
  // Filesystem tools
1374
1255
  case "read_file":
1375
- result = await handlers.handleReadFile(args);
1256
+ result = stillLoading(args?.path, 'read', { isUrl: args?.isUrl === true }) ?? await handlers.handleReadFile(args);
1376
1257
  break;
1377
1258
  case "read_multiple_files":
1378
- result = await handlers.handleReadMultipleFiles(args);
1259
+ result = await handlers.handleReadMultipleFiles(args, (filePath) => stillLoadingError(filePath, 'read'));
1379
1260
  break;
1380
1261
  case "write_file":
1381
- result = await handlers.handleWriteFile(args);
1262
+ result = stillLoading(args?.path, 'write') ?? await handlers.handleWriteFile(args);
1382
1263
  break;
1383
- case "write_pdf":
1384
- result = await handlers.handleWritePdf(args);
1264
+ case "write_pdf": {
1265
+ // Markdown (a new PDF) or page edits, read as the tool reads them;
1266
+ // arguments the tool refuses get its own error
1267
+ const parsed = WritePdfArgsSchema.safeParse(args);
1268
+ const action = parsed.success && typeof parsed.data.content === 'string' ? 'write' : 'edit';
1269
+ result = (parsed.success ? stillLoading(parsed.data.path, action, { isPdf: true }) : undefined) ?? await handlers.handleWritePdf(args);
1385
1270
  break;
1271
+ }
1386
1272
  case "create_directory":
1387
1273
  result = await handlers.handleCreateDirectory(args);
1388
1274
  break;
@@ -1408,7 +1294,7 @@ async function handleCallToolRequest(request) {
1408
1294
  result = await handlers.handleGetFileInfo(args);
1409
1295
  break;
1410
1296
  case "edit_block":
1411
- result = await handlers.handleEditBlock(args);
1297
+ result = stillLoading(args?.file_path, 'edit') ?? await handlers.handleEditBlock(args);
1412
1298
  break;
1413
1299
  default:
1414
1300
  capture('server_unknown_tool', { name });
@@ -1417,6 +1303,8 @@ async function handleCallToolRequest(request) {
1417
1303
  isError: true,
1418
1304
  };
1419
1305
  }
1306
+ // What the client receives (and the history records): facts kept internal are dropped
1307
+ result = withoutInternalFacts(name, result);
1420
1308
  // Add tool call to history (exclude only get_recent_tool_calls to prevent recursion)
1421
1309
  const duration = Date.now() - startTime;
1422
1310
  isError = !!result.isError;
@@ -1438,40 +1326,6 @@ async function handleCallToolRequest(request) {
1438
1326
  else {
1439
1327
  await usageTracker.trackSuccess(name);
1440
1328
  console.log(`[FEEDBACK DEBUG] Tool ${name} succeeded, checking feedback...`);
1441
- // Check if should show onboarding (before feedback - first-time users are priority)
1442
- const shouldShowOnboarding = await usageTracker.shouldShowOnboarding();
1443
- console.log(`[ONBOARDING DEBUG] Should show onboarding: ${shouldShowOnboarding}`);
1444
- if (shouldShowOnboarding) {
1445
- console.log(`[ONBOARDING DEBUG] Generating onboarding message...`);
1446
- const onboardingResult = await usageTracker.getOnboardingMessage();
1447
- console.log(`[ONBOARDING DEBUG] Generated variant: ${onboardingResult.variant}`);
1448
- // Capture onboarding prompt injection event
1449
- const stats = await usageTracker.getStats();
1450
- await capture('server_onboarding_shown', {
1451
- trigger_tool: name,
1452
- total_calls: stats.totalToolCalls,
1453
- successful_calls: stats.successfulCalls,
1454
- days_since_first_use: Math.floor((Date.now() - stats.firstUsed) / (1000 * 60 * 60 * 24)),
1455
- total_sessions: stats.totalSessions,
1456
- message_variant: onboardingResult.variant
1457
- });
1458
- // Inject onboarding message for the LLM
1459
- if (result.content && result.content.length > 0 && result.content[0].type === "text") {
1460
- const currentContent = result.content[0].text || '';
1461
- result.content[0].text = `${currentContent}${onboardingResult.message}`;
1462
- }
1463
- else {
1464
- result.content = [
1465
- ...(result.content || []),
1466
- {
1467
- type: "text",
1468
- text: onboardingResult.message
1469
- }
1470
- ];
1471
- }
1472
- // Mark that we've shown onboarding (to prevent spam)
1473
- await usageTracker.markOnboardingShown(onboardingResult.variant);
1474
- }
1475
1329
  // Check if should prompt for feedback (only on successful operations)
1476
1330
  const shouldPrompt = await usageTracker.shouldPromptForFeedback();
1477
1331
  console.log(`[FEEDBACK DEBUG] Should prompt for feedback: ${shouldPrompt}`);