@wonderwhy-er/desktop-commander 0.2.3 → 0.2.5

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 (47) hide show
  1. package/README.md +72 -4
  2. package/dist/config-manager.d.ts +6 -0
  3. package/dist/config-manager.js +1 -1
  4. package/dist/custom-stdio.d.ts +23 -2
  5. package/dist/custom-stdio.js +167 -12
  6. package/dist/handlers/edit-search-handlers.js +25 -6
  7. package/dist/handlers/terminal-handlers.d.ts +8 -4
  8. package/dist/handlers/terminal-handlers.js +16 -10
  9. package/dist/index-dxt.d.ts +2 -0
  10. package/dist/index-dxt.js +76 -0
  11. package/dist/index-with-startup-detection.d.ts +5 -0
  12. package/dist/index-with-startup-detection.js +180 -0
  13. package/dist/index.js +2 -0
  14. package/dist/server.d.ts +5 -0
  15. package/dist/server.js +345 -42
  16. package/dist/terminal-manager.d.ts +7 -0
  17. package/dist/terminal-manager.js +93 -18
  18. package/dist/tools/client.d.ts +10 -0
  19. package/dist/tools/client.js +13 -0
  20. package/dist/tools/config.d.ts +1 -1
  21. package/dist/tools/config.js +21 -3
  22. package/dist/tools/edit.js +4 -3
  23. package/dist/tools/environment.d.ts +55 -0
  24. package/dist/tools/environment.js +65 -0
  25. package/dist/tools/feedback.d.ts +8 -0
  26. package/dist/tools/feedback.js +132 -0
  27. package/dist/tools/filesystem.js +152 -57
  28. package/dist/tools/improved-process-tools.js +170 -29
  29. package/dist/tools/schemas.d.ts +20 -2
  30. package/dist/tools/schemas.js +20 -2
  31. package/dist/tools/usage.d.ts +5 -0
  32. package/dist/tools/usage.js +24 -0
  33. package/dist/types.d.ts +4 -0
  34. package/dist/utils/capture.js +23 -1
  35. package/dist/utils/early-logger.d.ts +4 -0
  36. package/dist/utils/early-logger.js +35 -0
  37. package/dist/utils/mcp-logger.d.ts +30 -0
  38. package/dist/utils/mcp-logger.js +59 -0
  39. package/dist/utils/smithery-detector.d.ts +94 -0
  40. package/dist/utils/smithery-detector.js +292 -0
  41. package/dist/utils/startup-detector.d.ts +65 -0
  42. package/dist/utils/startup-detector.js +390 -0
  43. package/dist/utils/usageTracker.d.ts +85 -0
  44. package/dist/utils/usageTracker.js +280 -0
  45. package/dist/version.d.ts +1 -1
  46. package/dist/version.js +1 -1
  47. package/package.json +3 -1
package/dist/server.js CHANGED
@@ -1,12 +1,19 @@
1
1
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
- import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ListPromptsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
2
+ import { CallToolRequestSchema, ListToolsRequestSchema, ListResourcesRequestSchema, ListPromptsRequestSchema, InitializeRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
3
3
  import { zodToJsonSchema } from "zod-to-json-schema";
4
- // Shared constants for tool descriptions
5
- const PATH_GUIDANCE = `IMPORTANT: Always use absolute paths (starting with '/' or drive letter like 'C:\\') for reliability. Relative paths may fail as they depend on the current working directory. Tilde paths (~/...) might not work in all contexts. Unless the user explicitly asks for relative paths, use absolute paths.`;
4
+ import { getSystemInfo, getOSSpecificGuidance, getPathGuidance, getDevelopmentToolGuidance } from './utils/system-info.js';
5
+ // Get system information once at startup
6
+ const SYSTEM_INFO = getSystemInfo();
7
+ const OS_GUIDANCE = getOSSpecificGuidance(SYSTEM_INFO);
8
+ const DEV_TOOL_GUIDANCE = getDevelopmentToolGuidance(SYSTEM_INFO);
9
+ 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.`;
6
10
  const CMD_PREFIX_DESCRIPTION = `This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.`;
7
- import { ExecuteCommandArgsSchema, ReadOutputArgsSchema, ForceTerminateArgsSchema, ListSessionsArgsSchema, KillProcessArgsSchema, ReadFileArgsSchema, ReadMultipleFilesArgsSchema, WriteFileArgsSchema, CreateDirectoryArgsSchema, ListDirectoryArgsSchema, MoveFileArgsSchema, SearchFilesArgsSchema, GetFileInfoArgsSchema, SearchCodeArgsSchema, GetConfigArgsSchema, SetConfigValueArgsSchema, ListProcessesArgsSchema, EditBlockArgsSchema, } from './tools/schemas.js';
11
+ import { StartProcessArgsSchema, ReadProcessOutputArgsSchema, InteractWithProcessArgsSchema, ForceTerminateArgsSchema, ListSessionsArgsSchema, KillProcessArgsSchema, ReadFileArgsSchema, ReadMultipleFilesArgsSchema, WriteFileArgsSchema, CreateDirectoryArgsSchema, ListDirectoryArgsSchema, MoveFileArgsSchema, SearchFilesArgsSchema, GetFileInfoArgsSchema, SearchCodeArgsSchema, GetConfigArgsSchema, SetConfigValueArgsSchema, ListProcessesArgsSchema, EditBlockArgsSchema, GetUsageStatsArgsSchema, GiveFeedbackArgsSchema, } from './tools/schemas.js';
8
12
  import { getConfig, setConfigValue } from './tools/config.js';
13
+ import { getUsageStats } from './tools/usage.js';
14
+ import { giveFeedbackToDesktopCommander } from './tools/feedback.js';
9
15
  import { trackToolCall } from './utils/trackTools.js';
16
+ import { usageTracker } from './utils/usageTracker.js';
10
17
  import { VERSION } from './version.js';
11
18
  import { capture, capture_call_tool } from "./utils/capture.js";
12
19
  console.error("Loading server.ts");
@@ -18,6 +25,7 @@ export const server = new Server({
18
25
  tools: {},
19
26
  resources: {}, // Add empty resources capability
20
27
  prompts: {}, // Add empty prompts capability
28
+ logging: {}, // Add logging capability for console redirection
21
29
  },
22
30
  });
23
31
  // Add handler for resources/list method
@@ -34,6 +42,42 @@ server.setRequestHandler(ListPromptsRequestSchema, async () => {
34
42
  prompts: [],
35
43
  };
36
44
  });
45
+ // Store current client info (simple variable)
46
+ let currentClient = { name: 'uninitialized', version: 'uninitialized' };
47
+ // Add handler for initialization method - capture client info
48
+ server.setRequestHandler(InitializeRequestSchema, async (request) => {
49
+ try {
50
+ // Extract and store current client information
51
+ const clientInfo = request.params?.clientInfo;
52
+ if (clientInfo) {
53
+ currentClient = {
54
+ name: clientInfo.name || 'unknown',
55
+ version: clientInfo.version || 'unknown'
56
+ };
57
+ console.log(`Client connected: ${currentClient.name} v${currentClient.version}`);
58
+ }
59
+ // Return standard initialization response
60
+ return {
61
+ protocolVersion: "2024-11-05",
62
+ capabilities: {
63
+ tools: {},
64
+ resources: {},
65
+ prompts: {},
66
+ logging: {},
67
+ },
68
+ serverInfo: {
69
+ name: "desktop-commander",
70
+ version: VERSION,
71
+ },
72
+ };
73
+ }
74
+ catch (error) {
75
+ console.error("Error in initialization handler:", error);
76
+ throw error;
77
+ }
78
+ });
79
+ // Export current client info for access by other modules
80
+ export { currentClient };
37
81
  console.error("Setting up request handlers...");
38
82
  server.setRequestHandler(ListToolsRequestSchema, async () => {
39
83
  try {
@@ -51,7 +95,10 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
51
95
  - fileReadLineLimit (max lines for read_file, default 1000)
52
96
  - fileWriteLineLimit (max lines per write_file call, default 50)
53
97
  - telemetryEnabled (boolean for telemetry opt-in/out)
54
- - version (version of the DesktopCommander)
98
+ - currentClient (information about the currently connected MCP client)
99
+ - clientHistory (history of all clients that have connected)
100
+ - version (version of the DesktopCommander)
101
+ - systemInfo (operating system and environment details)
55
102
  ${CMD_PREFIX_DESCRIPTION}`,
56
103
  inputSchema: zodToJsonSchema(GetConfigArgsSchema),
57
104
  },
@@ -136,7 +183,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
136
183
  description: `
137
184
  Write or append to file contents.
138
185
 
139
- 🎯 CHUNKING IS STANDARD PRACTICE: Always write files in chunks of 25-30 lines maximum.
186
+ CHUNKING IS STANDARD PRACTICE: Always write files in chunks of 25-30 lines maximum.
140
187
  This is the normal, recommended way to write files - not an emergency measure.
141
188
 
142
189
  STANDARD PROCESS FOR ANY FILE:
@@ -144,7 +191,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
144
191
  2. THEN → write_file(filePath, secondChunk, {mode: 'append'}) [≤30 lines]
145
192
  3. CONTINUE → write_file(filePath, nextChunk, {mode: 'append'}) [≤30 lines]
146
193
 
147
- ⚠️ ALWAYS CHUNK PROACTIVELY - don't wait for performance warnings!
194
+ ALWAYS CHUNK PROACTIVELY - don't wait for performance warnings!
148
195
 
149
196
  WHEN TO CHUNK (always be proactive):
150
197
  1. Any file expected to be longer than 25-30 lines
@@ -292,27 +339,132 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
292
339
  },
293
340
  // Terminal tools
294
341
  {
295
- name: "execute_command",
342
+ name: "start_process",
343
+ description: `
344
+ Start a new terminal process with intelligent state detection.
345
+
346
+ PRIMARY TOOL FOR FILE ANALYSIS AND DATA PROCESSING
347
+ This is the ONLY correct tool for analyzing local files (CSV, JSON, logs, etc.).
348
+ The analysis tool CANNOT access local files and WILL FAIL - always use processes for file-based work.
349
+
350
+ CRITICAL RULE: For ANY local file work, ALWAYS use this tool + interact_with_process, NEVER use analysis/REPL tool.
351
+
352
+ ${OS_GUIDANCE}
353
+
354
+ REQUIRED WORKFLOW FOR LOCAL FILES:
355
+ 1. start_process("python3 -i") - Start Python REPL for data analysis
356
+ 2. interact_with_process(pid, "import pandas as pd, numpy as np")
357
+ 3. interact_with_process(pid, "df = pd.read_csv('/absolute/path/file.csv')")
358
+ 4. interact_with_process(pid, "print(df.describe())")
359
+ 5. Continue analysis with pandas, matplotlib, seaborn, etc.
360
+
361
+ COMMON FILE ANALYSIS PATTERNS:
362
+ • start_process("python3 -i") → Python REPL for data analysis (RECOMMENDED)
363
+ • start_process("node -i") → Node.js for JSON processing
364
+ • start_process("cut -d',' -f1 file.csv | sort | uniq -c") → Quick CSV analysis
365
+ • start_process("wc -l /path/file.csv") → Line counting
366
+ • start_process("head -10 /path/file.csv") → File preview
367
+
368
+ INTERACTIVE PROCESSES FOR DATA ANALYSIS:
369
+ 1. start_process("python3 -i") - Start Python REPL for data work
370
+ 2. start_process("node -i") - Start Node.js REPL for JSON/JS
371
+ 3. start_process("bash") - Start interactive bash shell
372
+ 4. Use interact_with_process() to send commands
373
+ 5. Use read_process_output() to get responses
374
+
375
+ SMART DETECTION:
376
+ - Detects REPL prompts (>>>, >, $, etc.)
377
+ - Identifies when process is waiting for input
378
+ - Recognizes process completion vs timeout
379
+ - Early exit prevents unnecessary waiting
380
+
381
+ STATES DETECTED:
382
+ Process waiting for input (shows prompt)
383
+ Process finished execution
384
+ Process running (use read_process_output)
385
+
386
+ ALWAYS USE FOR: Local file analysis, CSV processing, data exploration, system commands
387
+ NEVER USE ANALYSIS TOOL FOR: Local file access (analysis tool is browser-only and WILL FAIL)
388
+
389
+ ${PATH_GUIDANCE}
390
+ ${CMD_PREFIX_DESCRIPTION}`,
391
+ inputSchema: zodToJsonSchema(StartProcessArgsSchema),
392
+ },
393
+ {
394
+ name: "read_process_output",
296
395
  description: `
297
- Execute a terminal command with timeout.
396
+ Read output from a running process with intelligent completion detection.
298
397
 
299
- Command will continue running in background if it doesn't complete within timeout.
398
+ Automatically detects when process is ready for more input instead of timing out.
300
399
 
301
- NOTE: For file operations, prefer specialized tools like read_file, search_code,
302
- list_directory instead of cat, grep, or ls commands.
400
+ SMART FEATURES:
401
+ - Early exit when REPL shows prompt (>>>, >, etc.)
402
+ - Detects process completion vs still running
403
+ - Prevents hanging on interactive prompts
404
+ - Clear status messages about process state
405
+
406
+ REPL USAGE:
407
+ - Stops immediately when REPL prompt detected
408
+ - Shows clear status: waiting for input vs finished
409
+ - Shorter timeouts needed due to smart detection
410
+ - Works with Python, Node.js, R, Julia, etc.
411
+
412
+ DETECTION STATES:
413
+ Process waiting for input (ready for interact_with_process)
414
+ Process finished execution
415
+ Timeout reached (may still be running)
303
416
 
304
- ${PATH_GUIDANCE}
305
417
  ${CMD_PREFIX_DESCRIPTION}`,
306
- inputSchema: zodToJsonSchema(ExecuteCommandArgsSchema),
418
+ inputSchema: zodToJsonSchema(ReadProcessOutputArgsSchema),
307
419
  },
308
420
  {
309
- name: "read_output",
421
+ name: "interact_with_process",
310
422
  description: `
311
- Read new output from a running terminal session.
312
- Set timeout_ms for long running commands.
423
+ Send input to a running process and automatically receive the response.
424
+
425
+ CRITICAL: THIS IS THE PRIMARY TOOL FOR ALL LOCAL FILE ANALYSIS
426
+ For ANY local file analysis (CSV, JSON, data processing), ALWAYS use this instead of the analysis tool.
427
+ The analysis tool CANNOT access local files and WILL FAIL - use processes for ALL file-based work.
428
+
429
+ FILE ANALYSIS PRIORITY ORDER (MANDATORY):
430
+ 1. ALWAYS FIRST: Use this tool (start_process + interact_with_process) for local data analysis
431
+ 2. ALTERNATIVE: Use command-line tools (cut, awk, grep) for quick processing
432
+ 3. NEVER EVER: Use analysis tool for local file access (IT WILL FAIL)
433
+
434
+ REQUIRED INTERACTIVE WORKFLOW FOR FILE ANALYSIS:
435
+ 1. Start REPL: start_process("python3 -i")
436
+ 2. Load libraries: interact_with_process(pid, "import pandas as pd, numpy as np")
437
+ 3. Read file: interact_with_process(pid, "df = pd.read_csv('/absolute/path/file.csv')")
438
+ 4. Analyze: interact_with_process(pid, "print(df.describe())")
439
+ 5. Continue: interact_with_process(pid, "df.groupby('column').size()")
440
+
441
+ SMART DETECTION:
442
+ - Automatically waits for REPL prompt (>>>, >, etc.)
443
+ - Detects errors and completion states
444
+ - Early exit prevents timeout delays
445
+ - Clean output formatting (removes prompts)
446
+
447
+ SUPPORTED REPLs:
448
+ - Python: python3 -i (RECOMMENDED for data analysis)
449
+ - Node.js: node -i
450
+ - R: R
451
+ - Julia: julia
452
+ - Shell: bash, zsh
453
+ - Database: mysql, postgres
454
+
455
+ PARAMETERS:
456
+ - pid: Process ID from start_process
457
+ - input: Code/command to execute
458
+ - timeout_ms: Max wait (default: 8000ms)
459
+ - wait_for_prompt: Auto-wait for response (default: true)
460
+
461
+ Returns execution result with status indicators.
462
+
463
+ ALWAYS USE FOR: CSV analysis, JSON processing, file statistics, data visualization prep, ANY local file work
464
+ NEVER USE ANALYSIS TOOL FOR: Local file access (it cannot read files from disk and WILL FAIL)
313
465
 
314
466
  ${CMD_PREFIX_DESCRIPTION}`,
315
- inputSchema: zodToJsonSchema(ReadOutputArgsSchema),
467
+ inputSchema: zodToJsonSchema(InteractWithProcessArgsSchema),
316
468
  },
317
469
  {
318
470
  name: "force_terminate",
@@ -327,6 +479,16 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
327
479
  description: `
328
480
  List all active terminal sessions.
329
481
 
482
+ Shows session status including:
483
+ - PID: Process identifier
484
+ - Blocked: Whether session is waiting for input
485
+ - Runtime: How long the session has been running
486
+
487
+ DEBUGGING REPLs:
488
+ - "Blocked: true" often means REPL is waiting for input
489
+ - Use this to verify sessions are running before sending input
490
+ - Long runtime with blocked status may indicate stuck process
491
+
330
492
  ${CMD_PREFIX_DESCRIPTION}`,
331
493
  inputSchema: zodToJsonSchema(ListSessionsArgsSchema),
332
494
  },
@@ -350,6 +512,53 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
350
512
  ${CMD_PREFIX_DESCRIPTION}`,
351
513
  inputSchema: zodToJsonSchema(KillProcessArgsSchema),
352
514
  },
515
+ {
516
+ name: "get_usage_stats",
517
+ description: `
518
+ Get usage statistics for debugging and analysis.
519
+
520
+ Returns summary of tool usage, success/failure rates, and performance metrics.
521
+
522
+ ${CMD_PREFIX_DESCRIPTION}`,
523
+ inputSchema: zodToJsonSchema(GetUsageStatsArgsSchema),
524
+ },
525
+ {
526
+ name: "give_feedback_to_desktop_commander",
527
+ description: `
528
+ Open feedback form in browser to provide feedback about Desktop Commander.
529
+
530
+ IMPORTANT: This tool simply opens the feedback form - no pre-filling available.
531
+ The user will fill out the form manually in their browser.
532
+
533
+ WORKFLOW:
534
+ 1. When user agrees to give feedback, just call this tool immediately
535
+ 2. No need to ask questions or collect information
536
+ 3. Tool opens form with only usage statistics pre-filled automatically:
537
+ - tool_call_count: Number of commands they've made
538
+ - days_using: How many days they've used Desktop Commander
539
+ - platform: Their operating system (Mac/Windows/Linux)
540
+ - client_id: Analytics identifier
541
+
542
+ All survey questions will be answered directly in the form:
543
+ - Job title and technical comfort level
544
+ - Company URL for industry context
545
+ - Other AI tools they use
546
+ - Desktop Commander's biggest advantage
547
+ - How they typically use it
548
+ - Recommendation likelihood (0-10)
549
+ - User study participation interest
550
+ - Email and any additional feedback
551
+
552
+ EXAMPLE INTERACTION:
553
+ User: "sure, I'll give feedback"
554
+ Claude: "Perfect! Let me open the feedback form for you."
555
+ [calls tool immediately]
556
+
557
+ No parameters are needed - just call the tool to open the form.
558
+
559
+ ${CMD_PREFIX_DESCRIPTION}`,
560
+ inputSchema: zodToJsonSchema(GiveFeedbackArgsSchema),
561
+ },
353
562
  ],
354
563
  };
355
564
  }
@@ -360,83 +569,177 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
360
569
  });
361
570
  import * as handlers from './handlers/index.js';
362
571
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
572
+ const { name, arguments: args } = request.params;
363
573
  try {
364
- const { name, arguments: args } = request.params;
365
574
  capture_call_tool('server_call_tool', {
366
575
  name
367
576
  });
368
577
  // Track tool call
369
578
  trackToolCall(name, args);
370
579
  // Using a more structured approach with dedicated handlers
580
+ let result;
371
581
  switch (name) {
372
582
  // Config tools
373
583
  case "get_config":
374
584
  try {
375
- return await getConfig();
585
+ result = await getConfig();
376
586
  }
377
587
  catch (error) {
378
588
  capture('server_request_error', { message: `Error in get_config handler: ${error}` });
379
- return {
589
+ result = {
380
590
  content: [{ type: "text", text: `Error: Failed to get configuration` }],
381
591
  isError: true,
382
592
  };
383
593
  }
594
+ break;
384
595
  case "set_config_value":
385
596
  try {
386
- return await setConfigValue(args);
597
+ result = await setConfigValue(args);
387
598
  }
388
599
  catch (error) {
389
600
  capture('server_request_error', { message: `Error in set_config_value handler: ${error}` });
390
- return {
601
+ result = {
391
602
  content: [{ type: "text", text: `Error: Failed to set configuration value` }],
392
603
  isError: true,
393
604
  };
394
605
  }
606
+ break;
607
+ case "get_usage_stats":
608
+ try {
609
+ result = await getUsageStats();
610
+ }
611
+ catch (error) {
612
+ capture('server_request_error', { message: `Error in get_usage_stats handler: ${error}` });
613
+ result = {
614
+ content: [{ type: "text", text: `Error: Failed to get usage statistics` }],
615
+ isError: true,
616
+ };
617
+ }
618
+ break;
619
+ case "give_feedback_to_desktop_commander":
620
+ try {
621
+ result = await giveFeedbackToDesktopCommander(args);
622
+ }
623
+ catch (error) {
624
+ capture('server_request_error', { message: `Error in give_feedback_to_desktop_commander handler: ${error}` });
625
+ result = {
626
+ content: [{ type: "text", text: `Error: Failed to open feedback form` }],
627
+ isError: true,
628
+ };
629
+ }
630
+ break;
395
631
  // Terminal tools
396
- case "execute_command":
397
- return await handlers.handleExecuteCommand(args);
398
- case "read_output":
399
- return await handlers.handleReadOutput(args);
632
+ case "start_process":
633
+ result = await handlers.handleStartProcess(args);
634
+ break;
635
+ case "read_process_output":
636
+ result = await handlers.handleReadProcessOutput(args);
637
+ break;
638
+ case "interact_with_process":
639
+ result = await handlers.handleInteractWithProcess(args);
640
+ break;
400
641
  case "force_terminate":
401
- return await handlers.handleForceTerminate(args);
642
+ result = await handlers.handleForceTerminate(args);
643
+ break;
402
644
  case "list_sessions":
403
- return await handlers.handleListSessions();
645
+ result = await handlers.handleListSessions();
646
+ break;
404
647
  // Process tools
405
648
  case "list_processes":
406
- return await handlers.handleListProcesses();
649
+ result = await handlers.handleListProcesses();
650
+ break;
407
651
  case "kill_process":
408
- return await handlers.handleKillProcess(args);
652
+ result = await handlers.handleKillProcess(args);
653
+ break;
654
+ // Note: REPL functionality removed in favor of using general terminal commands
409
655
  // Filesystem tools
410
656
  case "read_file":
411
- return await handlers.handleReadFile(args);
657
+ result = await handlers.handleReadFile(args);
658
+ break;
412
659
  case "read_multiple_files":
413
- return await handlers.handleReadMultipleFiles(args);
660
+ result = await handlers.handleReadMultipleFiles(args);
661
+ break;
414
662
  case "write_file":
415
- return await handlers.handleWriteFile(args);
663
+ result = await handlers.handleWriteFile(args);
664
+ break;
416
665
  case "create_directory":
417
- return await handlers.handleCreateDirectory(args);
666
+ result = await handlers.handleCreateDirectory(args);
667
+ break;
418
668
  case "list_directory":
419
- return await handlers.handleListDirectory(args);
669
+ result = await handlers.handleListDirectory(args);
670
+ break;
420
671
  case "move_file":
421
- return await handlers.handleMoveFile(args);
672
+ result = await handlers.handleMoveFile(args);
673
+ break;
422
674
  case "search_files":
423
- return await handlers.handleSearchFiles(args);
675
+ result = await handlers.handleSearchFiles(args);
676
+ break;
424
677
  case "search_code":
425
- return await handlers.handleSearchCode(args);
678
+ result = await handlers.handleSearchCode(args);
679
+ break;
426
680
  case "get_file_info":
427
- return await handlers.handleGetFileInfo(args);
681
+ result = await handlers.handleGetFileInfo(args);
682
+ break;
428
683
  case "edit_block":
429
- return await handlers.handleEditBlock(args);
684
+ result = await handlers.handleEditBlock(args);
685
+ break;
430
686
  default:
431
687
  capture('server_unknown_tool', { name });
432
- return {
688
+ result = {
433
689
  content: [{ type: "text", text: `Error: Unknown tool: ${name}` }],
434
690
  isError: true,
435
691
  };
436
692
  }
693
+ // Track success or failure based on result
694
+ if (result.isError) {
695
+ await usageTracker.trackFailure(name);
696
+ console.log(`[FEEDBACK DEBUG] Tool ${name} failed, not checking feedback`);
697
+ }
698
+ else {
699
+ await usageTracker.trackSuccess(name);
700
+ console.log(`[FEEDBACK DEBUG] Tool ${name} succeeded, checking feedback...`);
701
+ // Check if should prompt for feedback (only on successful operations)
702
+ const shouldPrompt = await usageTracker.shouldPromptForFeedback();
703
+ console.log(`[FEEDBACK DEBUG] Should prompt for feedback: ${shouldPrompt}`);
704
+ if (shouldPrompt) {
705
+ console.log(`[FEEDBACK DEBUG] Generating feedback message...`);
706
+ const feedbackResult = await usageTracker.getFeedbackPromptMessage();
707
+ console.log(`[FEEDBACK DEBUG] Generated variant: ${feedbackResult.variant}`);
708
+ // Capture feedback prompt injection event
709
+ const stats = await usageTracker.getStats();
710
+ await capture('feedback_prompt_injected', {
711
+ trigger_tool: name,
712
+ total_calls: stats.totalToolCalls,
713
+ successful_calls: stats.successfulCalls,
714
+ failed_calls: stats.failedCalls,
715
+ days_since_first_use: Math.floor((Date.now() - stats.firstUsed) / (1000 * 60 * 60 * 24)),
716
+ total_sessions: stats.totalSessions,
717
+ message_variant: feedbackResult.variant
718
+ });
719
+ // Inject feedback instruction for the LLM
720
+ if (result.content && result.content.length > 0 && result.content[0].type === "text") {
721
+ const currentContent = result.content[0].text || '';
722
+ result.content[0].text = `${currentContent}${feedbackResult.message}`;
723
+ }
724
+ else {
725
+ result.content = [
726
+ ...(result.content || []),
727
+ {
728
+ type: "text",
729
+ text: feedbackResult.message
730
+ }
731
+ ];
732
+ }
733
+ // Mark that we've prompted (to prevent spam)
734
+ await usageTracker.markFeedbackPrompted();
735
+ }
736
+ }
737
+ return result;
437
738
  }
438
739
  catch (error) {
439
740
  const errorMessage = error instanceof Error ? error.message : String(error);
741
+ // Track the failure
742
+ await usageTracker.trackFailure(name);
440
743
  capture('server_request_error', {
441
744
  error: errorMessage
442
745
  });
@@ -9,6 +9,13 @@ interface CompletedSession {
9
9
  export declare class TerminalManager {
10
10
  private sessions;
11
11
  private completedSessions;
12
+ /**
13
+ * Send input to a running process
14
+ * @param pid Process ID
15
+ * @param input Text to send to the process
16
+ * @returns Whether input was successfully sent
17
+ */
18
+ sendInputToProcess(pid: number, input: string): boolean;
12
19
  executeCommand(command: string, timeoutMs?: number, shell?: string): Promise<CommandExecutionResult>;
13
20
  getNewOutput(pid: number): string | null;
14
21
  /**