@wonderwhy-er/desktop-commander 0.2.9 → 0.2.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +7 -40
- package/dist/npm-scripts/setup.d.ts +1 -0
- package/dist/npm-scripts/setup.js +40 -0
- package/dist/npm-scripts/uninstall.d.ts +1 -0
- package/dist/npm-scripts/uninstall.js +40 -0
- package/dist/setup.log +63 -0
- package/dist/track-installation.js +368 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,47 +2,9 @@
|
|
|
2
2
|
import { FilteredStdioServerTransport } from './custom-stdio.js';
|
|
3
3
|
import { server } from './server.js';
|
|
4
4
|
import { configManager } from './config-manager.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { platform } from 'os';
|
|
5
|
+
import { runSetup } from './npm-scripts/setup.js';
|
|
6
|
+
import { runUninstall } from './npm-scripts/uninstall.js';
|
|
8
7
|
import { capture } from './utils/capture.js';
|
|
9
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
10
|
-
const __dirname = dirname(__filename);
|
|
11
|
-
const isWindows = platform() === 'win32';
|
|
12
|
-
// Helper function to properly convert file paths to URLs, especially for Windows
|
|
13
|
-
function createFileURL(filePath) {
|
|
14
|
-
if (isWindows) {
|
|
15
|
-
// Ensure path uses forward slashes for URL format
|
|
16
|
-
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
17
|
-
// Ensure path has proper file:// prefix
|
|
18
|
-
if (normalizedPath.startsWith('/')) {
|
|
19
|
-
return new URL(`file://${normalizedPath}`);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return new URL(`file:///${normalizedPath}`);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
// For non-Windows, we can use the built-in function
|
|
27
|
-
return pathToFileURL(filePath);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async function runSetup() {
|
|
31
|
-
try {
|
|
32
|
-
// Fix for Windows ESM path issue
|
|
33
|
-
const setupScriptPath = join(__dirname, 'setup-claude-server.js');
|
|
34
|
-
const setupScriptUrl = createFileURL(setupScriptPath);
|
|
35
|
-
// Now import using the URL format
|
|
36
|
-
const { default: setupModule } = await import(setupScriptUrl.href);
|
|
37
|
-
if (typeof setupModule === 'function') {
|
|
38
|
-
await setupModule();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
catch (error) {
|
|
42
|
-
console.error('Error running setup:', error);
|
|
43
|
-
process.exit(1);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
8
|
async function runServer() {
|
|
47
9
|
try {
|
|
48
10
|
// Check if first argument is "setup"
|
|
@@ -50,6 +12,11 @@ async function runServer() {
|
|
|
50
12
|
await runSetup();
|
|
51
13
|
return;
|
|
52
14
|
}
|
|
15
|
+
// Check if first argument is "remove"
|
|
16
|
+
if (process.argv[2] === 'remove') {
|
|
17
|
+
await runUninstall();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
53
20
|
const transport = new FilteredStdioServerTransport();
|
|
54
21
|
// Export transport for use throughout the application
|
|
55
22
|
global.mcpTransport = transport;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runSetup(): Promise<void>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { join, dirname } from 'path';
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
3
|
+
import { platform } from 'os';
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = dirname(__filename);
|
|
6
|
+
const isWindows = platform() === 'win32';
|
|
7
|
+
// Helper function to properly convert file paths to URLs, especially for Windows
|
|
8
|
+
function createFileURL(filePath) {
|
|
9
|
+
if (isWindows) {
|
|
10
|
+
// Ensure path uses forward slashes for URL format
|
|
11
|
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
12
|
+
// Ensure path has proper file:// prefix
|
|
13
|
+
if (normalizedPath.startsWith('/')) {
|
|
14
|
+
return new URL(`file://${normalizedPath}`);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return new URL(`file:///${normalizedPath}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// For non-Windows, we can use the built-in function
|
|
22
|
+
return pathToFileURL(filePath);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function runSetup() {
|
|
26
|
+
try {
|
|
27
|
+
// Fix for Windows ESM path issue - go up one level from npm-scripts to main dist
|
|
28
|
+
const setupScriptPath = join(__dirname, '..', 'setup-claude-server.js');
|
|
29
|
+
const setupScriptUrl = createFileURL(setupScriptPath);
|
|
30
|
+
// Now import using the URL format
|
|
31
|
+
const { default: setupModule } = await import(setupScriptUrl.href);
|
|
32
|
+
if (typeof setupModule === 'function') {
|
|
33
|
+
await setupModule();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error('Error running setup:', error);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runUninstall(): Promise<void>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { join, dirname } from 'path';
|
|
2
|
+
import { fileURLToPath, pathToFileURL } from 'url';
|
|
3
|
+
import { platform } from 'os';
|
|
4
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
5
|
+
const __dirname = dirname(__filename);
|
|
6
|
+
const isWindows = platform() === 'win32';
|
|
7
|
+
// Helper function to properly convert file paths to URLs, especially for Windows
|
|
8
|
+
function createFileURL(filePath) {
|
|
9
|
+
if (isWindows) {
|
|
10
|
+
// Ensure path uses forward slashes for URL format
|
|
11
|
+
const normalizedPath = filePath.replace(/\\/g, '/');
|
|
12
|
+
// Ensure path has proper file:// prefix
|
|
13
|
+
if (normalizedPath.startsWith('/')) {
|
|
14
|
+
return new URL(`file://${normalizedPath}`);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
return new URL(`file:///${normalizedPath}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
// For non-Windows, we can use the built-in function
|
|
22
|
+
return pathToFileURL(filePath);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function runUninstall() {
|
|
26
|
+
try {
|
|
27
|
+
// Fix for Windows ESM path issue - go up one level from npm-scripts to main dist
|
|
28
|
+
const uninstallScriptPath = join(__dirname, '..', 'uninstall-claude-server.js');
|
|
29
|
+
const uninstallScriptUrl = createFileURL(uninstallScriptPath);
|
|
30
|
+
// Now import using the URL format
|
|
31
|
+
const { default: uninstallModule } = await import(uninstallScriptUrl.href);
|
|
32
|
+
if (typeof uninstallModule === 'function') {
|
|
33
|
+
await uninstallModule();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
console.error('Error running uninstall:', error);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
}
|
package/dist/setup.log
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
2025-08-21T08:55:05.547Z - ✅ Desktop Commander MCP v0.2.9 successfully added to Claude’s configuration.
|
|
2
|
+
2025-08-21T08:55:05.547Z - Configuration location: /Users/fiberta/Library/Application Support/Claude/claude_desktop_config.json
|
|
3
|
+
2025-08-21T08:55:08.757Z -
|
|
4
|
+
✅ Claude has been restarted automatically!
|
|
5
|
+
2025-08-21T08:55:08.778Z -
|
|
6
|
+
✅ Installation successfully completed! Thank you for using Desktop Commander!
|
|
7
|
+
|
|
8
|
+
2025-08-21T08:55:08.779Z -
|
|
9
|
+
The server is available as "desktop-commander" in Claude's MCP server list
|
|
10
|
+
2025-08-21T08:55:08.779Z - Future updates will install automatically — no need to run this setup again.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
2025-08-21T08:55:08.779Z - 🤔 Need help or have feedback? Happy to jump on a quick call:
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
2025-08-21T08:55:08.779Z - https://calendar.app.google/SHMNZN5MJznJWC5A7
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
2025-08-21T08:55:08.779Z - or join our community: https://discord.com/invite/kQ27sNnZr7
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
2025-08-21T14:58:41.568Z - ✅ Desktop Commander MCP v0.2.9 successfully added to Claude’s configuration.
|
|
23
|
+
2025-08-21T14:58:41.568Z - Configuration location: /Users/fiberta/Library/Application Support/Claude/claude_desktop_config.json
|
|
24
|
+
2025-08-21T14:58:44.701Z -
|
|
25
|
+
✅ Claude has been restarted automatically!
|
|
26
|
+
2025-08-21T14:58:44.728Z -
|
|
27
|
+
✅ Installation successfully completed! Thank you for using Desktop Commander!
|
|
28
|
+
|
|
29
|
+
2025-08-21T14:58:44.728Z -
|
|
30
|
+
The server is available as "desktop-commander" in Claude's MCP server list
|
|
31
|
+
2025-08-21T14:58:44.728Z - Future updates will install automatically — no need to run this setup again.
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
2025-08-21T14:58:44.728Z - 🤔 Need help or have feedback? Happy to jump on a quick call:
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
2025-08-21T14:58:44.728Z - https://calendar.app.google/SHMNZN5MJznJWC5A7
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
2025-08-21T14:58:44.728Z - or join our community: https://discord.com/invite/kQ27sNnZr7
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
2025-08-21T15:01:40.796Z - ✅ Desktop Commander MCP v0.2.9 successfully added to Claude’s configuration.
|
|
44
|
+
2025-08-21T15:01:40.796Z - Configuration location: /Users/fiberta/Library/Application Support/Claude/claude_desktop_config.json
|
|
45
|
+
2025-08-21T15:01:43.911Z -
|
|
46
|
+
✅ Claude has been restarted automatically!
|
|
47
|
+
2025-08-21T15:01:43.932Z -
|
|
48
|
+
✅ Installation successfully completed! Thank you for using Desktop Commander!
|
|
49
|
+
|
|
50
|
+
2025-08-21T15:01:43.932Z -
|
|
51
|
+
The server is available as "desktop-commander" in Claude's MCP server list
|
|
52
|
+
2025-08-21T15:01:43.932Z - Future updates will install automatically — no need to run this setup again.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
2025-08-21T15:01:43.932Z - 🤔 Need help or have feedback? Happy to jump on a quick call:
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
2025-08-21T15:01:43.932Z - https://calendar.app.google/SHMNZN5MJznJWC5A7
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
2025-08-21T15:01:43.932Z - or join our community: https://discord.com/invite/kQ27sNnZr7
|
|
62
|
+
|
|
63
|
+
|
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Installation Source Tracking Script
|
|
5
|
+
* Runs during npm install to detect how Desktop Commander was installed
|
|
6
|
+
*
|
|
7
|
+
* Debug logging can be enabled with:
|
|
8
|
+
* - DEBUG=desktop-commander npm install
|
|
9
|
+
* - DEBUG=* npm install
|
|
10
|
+
* - NODE_ENV=development npm install
|
|
11
|
+
* - DC_DEBUG=true npm install
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { randomUUID } from 'crypto';
|
|
15
|
+
import * as https from 'https';
|
|
16
|
+
import { platform } from 'os';
|
|
17
|
+
import path from 'path';
|
|
18
|
+
import { fileURLToPath } from 'url';
|
|
19
|
+
|
|
20
|
+
// Get current file directory
|
|
21
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
22
|
+
const __dirname = path.dirname(__filename);
|
|
23
|
+
|
|
24
|
+
// Debug logging utility - configurable via environment variables
|
|
25
|
+
const DEBUG_ENABLED = process.env.DEBUG === 'desktop-commander' ||
|
|
26
|
+
process.env.DEBUG === '*' ||
|
|
27
|
+
process.env.NODE_ENV === 'development' ||
|
|
28
|
+
process.env.DC_DEBUG === 'true';
|
|
29
|
+
|
|
30
|
+
const debug = (...args) => {
|
|
31
|
+
if (DEBUG_ENABLED) {
|
|
32
|
+
console.log('[Desktop Commander Debug]', ...args);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const log = (...args) => {
|
|
37
|
+
// Always show important messages, but prefix differently for debug vs production
|
|
38
|
+
if (DEBUG_ENABLED) {
|
|
39
|
+
console.log('[Desktop Commander]', ...args);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Get the client ID from the Desktop Commander config file, or generate a new one
|
|
45
|
+
*/
|
|
46
|
+
async function getClientId() {
|
|
47
|
+
try {
|
|
48
|
+
const { homedir } = await import('os');
|
|
49
|
+
const { join } = await import('path');
|
|
50
|
+
const fs = await import('fs');
|
|
51
|
+
|
|
52
|
+
const USER_HOME = homedir();
|
|
53
|
+
const CONFIG_DIR = join(USER_HOME, '.claude-server-commander');
|
|
54
|
+
const CONFIG_FILE = join(CONFIG_DIR, 'config.json');
|
|
55
|
+
|
|
56
|
+
// Try to read existing config
|
|
57
|
+
if (fs.existsSync(CONFIG_FILE)) {
|
|
58
|
+
const configData = fs.readFileSync(CONFIG_FILE, 'utf8');
|
|
59
|
+
const config = JSON.parse(configData);
|
|
60
|
+
if (config.clientId) {
|
|
61
|
+
debug(`Using existing clientId from config: ${config.clientId.substring(0, 8)}...`);
|
|
62
|
+
return config.clientId;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
debug('No existing clientId found, generating new one');
|
|
67
|
+
// Fallback to random UUID if config doesn't exist or lacks clientId
|
|
68
|
+
return randomUUID();
|
|
69
|
+
} catch (error) {
|
|
70
|
+
debug(`Error reading config file: ${error.message}, using random UUID`);
|
|
71
|
+
// If anything goes wrong, fall back to random UUID
|
|
72
|
+
return randomUUID();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Google Analytics configuration (same as setup script)
|
|
77
|
+
const GA_MEASUREMENT_ID = 'G-NGGDNL0K4L';
|
|
78
|
+
const GA_API_SECRET = '5M0mC--2S_6t94m8WrI60A';
|
|
79
|
+
const GA_BASE_URL = `https://www.google-analytics.com/mp/collect?measurement_id=${GA_MEASUREMENT_ID}&api_secret=${GA_API_SECRET}`;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Detect installation source from environment and process context
|
|
83
|
+
*/
|
|
84
|
+
async function detectInstallationSource() {
|
|
85
|
+
// Check npm environment variables for clues
|
|
86
|
+
const npmConfigUserAgent = process.env.npm_config_user_agent || '';
|
|
87
|
+
const npmExecpath = process.env.npm_execpath || '';
|
|
88
|
+
const npmCommand = process.env.npm_command || '';
|
|
89
|
+
const npmLifecycleEvent = process.env.npm_lifecycle_event || '';
|
|
90
|
+
|
|
91
|
+
// Check process arguments and parent commands
|
|
92
|
+
const processArgs = process.argv.join(' ');
|
|
93
|
+
const processTitle = process.title || '';
|
|
94
|
+
|
|
95
|
+
debug('Installation source detection...');
|
|
96
|
+
debug(`npm_config_user_agent: ${npmConfigUserAgent}`);
|
|
97
|
+
debug(`npm_execpath: ${npmExecpath}`);
|
|
98
|
+
debug(`npm_command: ${npmCommand}`);
|
|
99
|
+
debug(`npm_lifecycle_event: ${npmLifecycleEvent}`);
|
|
100
|
+
debug(`process.argv: ${processArgs}`);
|
|
101
|
+
debug(`process.title: ${processTitle}`);
|
|
102
|
+
|
|
103
|
+
// Try to get parent process information
|
|
104
|
+
let parentProcessInfo = null;
|
|
105
|
+
try {
|
|
106
|
+
const { execSync } = await import('child_process');
|
|
107
|
+
const ppid = process.ppid;
|
|
108
|
+
if (ppid && process.platform !== 'win32') {
|
|
109
|
+
// Get parent process command line on Unix systems
|
|
110
|
+
const parentCmd = execSync(`ps -p ${ppid} -o command=`, { encoding: 'utf8' }).trim();
|
|
111
|
+
parentProcessInfo = parentCmd;
|
|
112
|
+
debug(`parent process: ${parentCmd}`);
|
|
113
|
+
}
|
|
114
|
+
} catch (error) {
|
|
115
|
+
debug(`Could not get parent process info: ${error.message}`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Smithery detection - look for smithery in the process chain
|
|
119
|
+
const smitheryIndicators = [
|
|
120
|
+
npmConfigUserAgent.includes('smithery'),
|
|
121
|
+
npmExecpath.includes('smithery'),
|
|
122
|
+
processArgs.includes('smithery'),
|
|
123
|
+
processArgs.includes('@smithery/cli'),
|
|
124
|
+
processTitle.includes('smithery'),
|
|
125
|
+
parentProcessInfo && parentProcessInfo.includes('smithery'),
|
|
126
|
+
parentProcessInfo && parentProcessInfo.includes('@smithery/cli')
|
|
127
|
+
];
|
|
128
|
+
|
|
129
|
+
if (smitheryIndicators.some(indicator => indicator)) {
|
|
130
|
+
return {
|
|
131
|
+
source: 'smithery',
|
|
132
|
+
details: {
|
|
133
|
+
detection_method: 'process_chain',
|
|
134
|
+
user_agent: npmConfigUserAgent,
|
|
135
|
+
exec_path: npmExecpath,
|
|
136
|
+
command: npmCommand,
|
|
137
|
+
parent_process: parentProcessInfo || 'unknown',
|
|
138
|
+
process_args: processArgs
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Direct NPX usage
|
|
144
|
+
if (npmCommand === 'exec' || processArgs.includes('npx')) {
|
|
145
|
+
return {
|
|
146
|
+
source: 'npx-direct',
|
|
147
|
+
details: {
|
|
148
|
+
user_agent: npmConfigUserAgent,
|
|
149
|
+
command: npmCommand,
|
|
150
|
+
lifecycle_event: npmLifecycleEvent
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Regular npm install
|
|
156
|
+
if (npmCommand === 'install' || npmLifecycleEvent === 'postinstall') {
|
|
157
|
+
return {
|
|
158
|
+
source: 'npm-install',
|
|
159
|
+
details: {
|
|
160
|
+
user_agent: npmConfigUserAgent,
|
|
161
|
+
command: npmCommand,
|
|
162
|
+
lifecycle_event: npmLifecycleEvent
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// GitHub Codespaces
|
|
168
|
+
if (process.env.CODESPACES) {
|
|
169
|
+
return {
|
|
170
|
+
source: 'github-codespaces',
|
|
171
|
+
details: {
|
|
172
|
+
codespace: process.env.CODESPACE_NAME || 'unknown'
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// VS Code
|
|
178
|
+
if (process.env.VSCODE_PID || process.env.TERM_PROGRAM === 'vscode') {
|
|
179
|
+
return {
|
|
180
|
+
source: 'vscode',
|
|
181
|
+
details: {
|
|
182
|
+
term_program: process.env.TERM_PROGRAM,
|
|
183
|
+
vscode_pid: process.env.VSCODE_PID
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// GitPod
|
|
189
|
+
if (process.env.GITPOD_WORKSPACE_ID) {
|
|
190
|
+
return {
|
|
191
|
+
source: 'gitpod',
|
|
192
|
+
details: {
|
|
193
|
+
workspace_id: process.env.GITPOD_WORKSPACE_ID.substring(0, 8) + '...' // Truncate for privacy
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// CI/CD environments
|
|
199
|
+
if (process.env.CI) {
|
|
200
|
+
if (process.env.GITHUB_ACTIONS) {
|
|
201
|
+
return {
|
|
202
|
+
source: 'github-actions',
|
|
203
|
+
details: {
|
|
204
|
+
repository: process.env.GITHUB_REPOSITORY,
|
|
205
|
+
workflow: process.env.GITHUB_WORKFLOW
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
if (process.env.GITLAB_CI) {
|
|
210
|
+
return {
|
|
211
|
+
source: 'gitlab-ci',
|
|
212
|
+
details: {
|
|
213
|
+
project: process.env.CI_PROJECT_NAME
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
if (process.env.JENKINS_URL) {
|
|
218
|
+
return {
|
|
219
|
+
source: 'jenkins',
|
|
220
|
+
details: {
|
|
221
|
+
job: process.env.JOB_NAME
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return {
|
|
226
|
+
source: 'ci-cd-other',
|
|
227
|
+
details: {
|
|
228
|
+
ci_env: 'unknown'
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Docker detection
|
|
234
|
+
if (process.env.DOCKER_CONTAINER) {
|
|
235
|
+
return {
|
|
236
|
+
source: 'docker',
|
|
237
|
+
details: {
|
|
238
|
+
container_id: process.env.HOSTNAME?.substring(0, 8) + '...' || 'unknown'
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Check for .dockerenv file (need to use fs import)
|
|
244
|
+
try {
|
|
245
|
+
const fs = await import('fs');
|
|
246
|
+
if (fs.existsSync('/.dockerenv')) {
|
|
247
|
+
return {
|
|
248
|
+
source: 'docker',
|
|
249
|
+
details: {
|
|
250
|
+
container_id: process.env.HOSTNAME?.substring(0, 8) + '...' || 'unknown'
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
} catch (error) {
|
|
255
|
+
// Ignore fs errors
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Default fallback
|
|
259
|
+
return {
|
|
260
|
+
source: 'unknown',
|
|
261
|
+
details: {
|
|
262
|
+
user_agent: npmConfigUserAgent || 'none',
|
|
263
|
+
command: npmCommand || 'none',
|
|
264
|
+
lifecycle: npmLifecycleEvent || 'none'
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Send installation tracking to analytics
|
|
271
|
+
*/
|
|
272
|
+
async function trackInstallation(installationData) {
|
|
273
|
+
if (!GA_MEASUREMENT_ID || !GA_API_SECRET) {
|
|
274
|
+
debug('Analytics not configured, skipping tracking');
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
try {
|
|
279
|
+
const uniqueUserId = await getClientId();
|
|
280
|
+
log("user id", uniqueUserId)
|
|
281
|
+
// Prepare GA4 payload
|
|
282
|
+
const payload = {
|
|
283
|
+
client_id: uniqueUserId,
|
|
284
|
+
non_personalized_ads: false,
|
|
285
|
+
timestamp_micros: Date.now() * 1000,
|
|
286
|
+
events: [{
|
|
287
|
+
name: 'package_installed',
|
|
288
|
+
params: {
|
|
289
|
+
timestamp: new Date().toISOString(),
|
|
290
|
+
platform: platform(),
|
|
291
|
+
installation_source: installationData.source,
|
|
292
|
+
installation_details: JSON.stringify(installationData.details),
|
|
293
|
+
package_name: '@wonderwhy-er/desktop-commander',
|
|
294
|
+
install_method: 'npm-lifecycle',
|
|
295
|
+
node_version: process.version,
|
|
296
|
+
npm_version: process.env.npm_version || 'unknown'
|
|
297
|
+
}
|
|
298
|
+
}]
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const postData = JSON.stringify(payload);
|
|
302
|
+
|
|
303
|
+
const options = {
|
|
304
|
+
method: 'POST',
|
|
305
|
+
headers: {
|
|
306
|
+
'Content-Type': 'application/json',
|
|
307
|
+
'Content-Length': Buffer.byteLength(postData)
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
await new Promise((resolve, reject) => {
|
|
312
|
+
const req = https.request(GA_BASE_URL, options);
|
|
313
|
+
|
|
314
|
+
const timeoutId = setTimeout(() => {
|
|
315
|
+
req.destroy();
|
|
316
|
+
reject(new Error('Request timeout'));
|
|
317
|
+
}, 5000);
|
|
318
|
+
|
|
319
|
+
req.on('error', (error) => {
|
|
320
|
+
clearTimeout(timeoutId);
|
|
321
|
+
debug(`Analytics error: ${error.message}`);
|
|
322
|
+
resolve(); // Don't fail installation on analytics error
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
req.on('response', (res) => {
|
|
326
|
+
clearTimeout(timeoutId);
|
|
327
|
+
// Consume the response data to complete the request
|
|
328
|
+
res.on('data', () => {}); // Ignore response data
|
|
329
|
+
res.on('end', () => {
|
|
330
|
+
log(`Installation tracked: ${installationData.source}`);
|
|
331
|
+
resolve();
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
req.write(postData);
|
|
336
|
+
req.end();
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
} catch (error) {
|
|
340
|
+
debug(`Failed to track installation: ${error.message}`);
|
|
341
|
+
// Don't fail the installation process
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Main execution
|
|
347
|
+
*/
|
|
348
|
+
async function main() {
|
|
349
|
+
try {
|
|
350
|
+
log('Package installation detected');
|
|
351
|
+
|
|
352
|
+
const installationData = await detectInstallationSource();
|
|
353
|
+
log(`Installation source: ${installationData.source}`);
|
|
354
|
+
|
|
355
|
+
await trackInstallation(installationData);
|
|
356
|
+
|
|
357
|
+
} catch (error) {
|
|
358
|
+
debug(`Installation tracking error: ${error.message}`);
|
|
359
|
+
// Don't fail the installation
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// Only run if this script is executed directly (not imported)
|
|
364
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
365
|
+
main();
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
export { detectInstallationSource, trackInstallation };
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "0.2.
|
|
1
|
+
export declare const VERSION = "0.2.10";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.2.
|
|
1
|
+
export const VERSION = '0.2.10';
|