@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.
- package/README.md +72 -4
- package/dist/config-manager.d.ts +6 -0
- package/dist/config-manager.js +1 -1
- package/dist/custom-stdio.d.ts +23 -2
- package/dist/custom-stdio.js +167 -12
- package/dist/handlers/edit-search-handlers.js +25 -6
- package/dist/handlers/terminal-handlers.d.ts +8 -4
- package/dist/handlers/terminal-handlers.js +16 -10
- package/dist/index-dxt.d.ts +2 -0
- package/dist/index-dxt.js +76 -0
- package/dist/index-with-startup-detection.d.ts +5 -0
- package/dist/index-with-startup-detection.js +180 -0
- package/dist/index.js +2 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.js +345 -42
- package/dist/terminal-manager.d.ts +7 -0
- package/dist/terminal-manager.js +93 -18
- package/dist/tools/client.d.ts +10 -0
- package/dist/tools/client.js +13 -0
- package/dist/tools/config.d.ts +1 -1
- package/dist/tools/config.js +21 -3
- package/dist/tools/edit.js +4 -3
- package/dist/tools/environment.d.ts +55 -0
- package/dist/tools/environment.js +65 -0
- package/dist/tools/feedback.d.ts +8 -0
- package/dist/tools/feedback.js +132 -0
- package/dist/tools/filesystem.js +152 -57
- package/dist/tools/improved-process-tools.js +170 -29
- package/dist/tools/schemas.d.ts +20 -2
- package/dist/tools/schemas.js +20 -2
- package/dist/tools/usage.d.ts +5 -0
- package/dist/tools/usage.js +24 -0
- package/dist/types.d.ts +4 -0
- package/dist/utils/capture.js +23 -1
- package/dist/utils/early-logger.d.ts +4 -0
- package/dist/utils/early-logger.js +35 -0
- package/dist/utils/mcp-logger.d.ts +30 -0
- package/dist/utils/mcp-logger.js +59 -0
- package/dist/utils/smithery-detector.d.ts +94 -0
- package/dist/utils/smithery-detector.js +292 -0
- package/dist/utils/startup-detector.d.ts +65 -0
- package/dist/utils/startup-detector.js +390 -0
- package/dist/utils/usageTracker.d.ts +85 -0
- package/dist/utils/usageTracker.js +280 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example integration of startup detection in your server.ts file
|
|
3
|
+
* This shows how to add startup detection to your existing server
|
|
4
|
+
*/
|
|
5
|
+
import { FilteredStdioServerTransport } from './custom-stdio.js';
|
|
6
|
+
import { server } from './server.js';
|
|
7
|
+
import { configManager } from './config-manager.js';
|
|
8
|
+
import { getStartupInfo, getStartupMethod, isProduction, isDevelopment, isDocker, isCi } from './utils/startup-detector.js';
|
|
9
|
+
import { capture } from './utils/capture.js';
|
|
10
|
+
import { join, dirname } from 'path';
|
|
11
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
12
|
+
import { platform } from 'os';
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = dirname(__filename);
|
|
15
|
+
const isWindows = platform() === 'win32';
|
|
16
|
+
function createFileURL(filePath) {
|
|
17
|
+
if (isWindows) {
|
|
18
|
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
19
|
+
if (normalizedPath.startsWith('/')) {
|
|
20
|
+
return new URL(`file://${normalizedPath}`);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return new URL(`file:///${normalizedPath}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return pathToFileURL(filePath);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function runSetup() {
|
|
31
|
+
try {
|
|
32
|
+
const setupScriptPath = join(__dirname, 'setup-claude-server.js');
|
|
33
|
+
const setupScriptUrl = createFileURL(setupScriptPath);
|
|
34
|
+
const { default: setupModule } = await import(setupScriptUrl.href);
|
|
35
|
+
if (typeof setupModule === 'function') {
|
|
36
|
+
await setupModule();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
console.error('Error running setup:', error);
|
|
41
|
+
process.exit(1);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async function runServer() {
|
|
45
|
+
try {
|
|
46
|
+
// Check if first argument is "setup"
|
|
47
|
+
if (process.argv[2] === 'setup') {
|
|
48
|
+
await runSetup();
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
// ============ NEW: Startup Detection Integration ============
|
|
52
|
+
const startupInfo = getStartupInfo();
|
|
53
|
+
const startupMethod = getStartupMethod();
|
|
54
|
+
// Log startup information
|
|
55
|
+
console.error(`🚀 Desktop Commander starting via: ${startupMethod}`);
|
|
56
|
+
console.error(`📍 Environment: ${startupInfo.environment}`);
|
|
57
|
+
console.error(`🔍 Detection confidence: ${startupInfo.confidence}%`);
|
|
58
|
+
if (startupInfo.details.evidence.length > 0) {
|
|
59
|
+
console.error(`📝 Evidence: ${startupInfo.details.evidence.join(', ')}`);
|
|
60
|
+
}
|
|
61
|
+
// Conditional behavior based on startup method
|
|
62
|
+
if (isProduction()) {
|
|
63
|
+
console.error('🏭 Production mode: Enhanced error handling enabled');
|
|
64
|
+
// Enable production-specific features
|
|
65
|
+
process.on('uncaughtException', (error) => {
|
|
66
|
+
console.error('[PRODUCTION] Uncaught exception:', error);
|
|
67
|
+
// More robust error handling in production
|
|
68
|
+
process.exit(1);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
else if (isDevelopment()) {
|
|
72
|
+
console.error('🛠️ Development mode: Debug features enabled');
|
|
73
|
+
// Enable development-specific features
|
|
74
|
+
}
|
|
75
|
+
if (isDocker()) {
|
|
76
|
+
console.error('🐳 Docker environment detected');
|
|
77
|
+
// Docker-specific configuration
|
|
78
|
+
}
|
|
79
|
+
if (isCi()) {
|
|
80
|
+
console.error('🤖 CI/CD environment detected');
|
|
81
|
+
// CI-specific behavior (minimal logging, etc.)
|
|
82
|
+
}
|
|
83
|
+
// Log startup analytics
|
|
84
|
+
capture('desktop_commander_startup', {
|
|
85
|
+
startup_method: startupInfo.method,
|
|
86
|
+
environment: startupInfo.environment,
|
|
87
|
+
confidence: startupInfo.confidence,
|
|
88
|
+
npm_script: startupInfo.details.npmScript || null,
|
|
89
|
+
ci_platform: startupInfo.details.ciPlatform || null,
|
|
90
|
+
docker_container: startupInfo.details.dockerContainer || false
|
|
91
|
+
});
|
|
92
|
+
// Adjust logging verbosity based on environment
|
|
93
|
+
const logLevel = isProduction() ? 'error' :
|
|
94
|
+
isDevelopment() ? 'debug' :
|
|
95
|
+
isCi() ? 'warn' : 'info';
|
|
96
|
+
console.error(`📊 Log level set to: ${logLevel}`);
|
|
97
|
+
// ========================================================
|
|
98
|
+
const transport = new FilteredStdioServerTransport();
|
|
99
|
+
// Enhanced error handling with startup context
|
|
100
|
+
process.on('uncaughtException', async (error) => {
|
|
101
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
102
|
+
if (errorMessage.includes('JSON') && errorMessage.includes('Unexpected token')) {
|
|
103
|
+
process.stderr.write(`[desktop-commander] JSON parsing error: ${errorMessage}\n`);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
// Include startup context in error capture
|
|
107
|
+
capture('run_server_uncaught_exception', {
|
|
108
|
+
error: errorMessage,
|
|
109
|
+
startup_method: startupInfo.method,
|
|
110
|
+
environment: startupInfo.environment
|
|
111
|
+
});
|
|
112
|
+
process.stderr.write(`[desktop-commander] Uncaught exception: ${errorMessage}\n`);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
});
|
|
115
|
+
process.on('unhandledRejection', async (reason) => {
|
|
116
|
+
const errorMessage = reason instanceof Error ? reason.message : String(reason);
|
|
117
|
+
if (errorMessage.includes('JSON') && errorMessage.includes('Unexpected token')) {
|
|
118
|
+
process.stderr.write(`[desktop-commander] JSON parsing rejection: ${errorMessage}\n`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
capture('run_server_unhandled_rejection', {
|
|
122
|
+
error: errorMessage,
|
|
123
|
+
startup_method: startupInfo.method,
|
|
124
|
+
environment: startupInfo.environment
|
|
125
|
+
});
|
|
126
|
+
process.stderr.write(`[desktop-commander] Unhandled rejection: ${errorMessage}\n`);
|
|
127
|
+
process.exit(1);
|
|
128
|
+
});
|
|
129
|
+
capture('run_server_start', {
|
|
130
|
+
startup_method: startupInfo.method,
|
|
131
|
+
environment: startupInfo.environment
|
|
132
|
+
});
|
|
133
|
+
try {
|
|
134
|
+
console.error("Loading configuration...");
|
|
135
|
+
await configManager.loadConfig();
|
|
136
|
+
console.error("Configuration loaded successfully");
|
|
137
|
+
}
|
|
138
|
+
catch (configError) {
|
|
139
|
+
console.error(`Failed to load configuration: ${configError instanceof Error ? configError.message : String(configError)}`);
|
|
140
|
+
console.error(configError instanceof Error && configError.stack ? configError.stack : 'No stack trace available');
|
|
141
|
+
console.error("Continuing with in-memory configuration only");
|
|
142
|
+
}
|
|
143
|
+
console.error("Connecting server...");
|
|
144
|
+
await server.connect(transport);
|
|
145
|
+
console.error("✅ Server connected successfully");
|
|
146
|
+
console.error(`🎯 Running in ${startupInfo.environment} environment via ${startupMethod}`);
|
|
147
|
+
}
|
|
148
|
+
catch (error) {
|
|
149
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
150
|
+
console.error(`FATAL ERROR: ${errorMessage}`);
|
|
151
|
+
console.error(error instanceof Error && error.stack ? error.stack : 'No stack trace available');
|
|
152
|
+
process.stderr.write(JSON.stringify({
|
|
153
|
+
type: 'error',
|
|
154
|
+
timestamp: new Date().toISOString(),
|
|
155
|
+
message: `Failed to start server: ${errorMessage}`,
|
|
156
|
+
startup_method: getStartupInfo().method
|
|
157
|
+
}) + '\n');
|
|
158
|
+
capture('run_server_failed_start_error', {
|
|
159
|
+
error: errorMessage,
|
|
160
|
+
startup_method: getStartupInfo().method
|
|
161
|
+
});
|
|
162
|
+
process.exit(1);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
runServer().catch(async (error) => {
|
|
166
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
167
|
+
console.error(`RUNTIME ERROR: ${errorMessage}`);
|
|
168
|
+
console.error(error instanceof Error && error.stack ? error.stack : 'No stack trace available');
|
|
169
|
+
process.stderr.write(JSON.stringify({
|
|
170
|
+
type: 'error',
|
|
171
|
+
timestamp: new Date().toISOString(),
|
|
172
|
+
message: `Fatal error running server: ${errorMessage}`,
|
|
173
|
+
startup_method: getStartupInfo().method
|
|
174
|
+
}) + '\n');
|
|
175
|
+
capture('run_server_fatal_error', {
|
|
176
|
+
error: errorMessage,
|
|
177
|
+
startup_method: getStartupInfo().method
|
|
178
|
+
});
|
|
179
|
+
process.exit(1);
|
|
180
|
+
});
|
package/dist/index.js
CHANGED
|
@@ -51,6 +51,8 @@ async function runServer() {
|
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
const transport = new FilteredStdioServerTransport();
|
|
54
|
+
// Export transport for use throughout the application
|
|
55
|
+
global.mcpTransport = transport;
|
|
54
56
|
// Handle uncaught exceptions
|
|
55
57
|
process.on('uncaughtException', async (error) => {
|
|
56
58
|
const errorMessage = error instanceof Error ? error.message : String(error);
|