@wonderwhy-er/desktop-commander 0.3.1-alpha.0 → 0.3.1-alpha.2

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 (76) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +1152 -1152
  3. package/dist/bootstrap.js +0 -0
  4. package/dist/command-manager.js +0 -0
  5. package/dist/config-field-definitions.js +0 -0
  6. package/dist/config-manager.d.ts +6 -0
  7. package/dist/config-manager.js +1 -1
  8. package/dist/config-recovery.js +0 -0
  9. package/dist/config.js +0 -0
  10. package/dist/custom-stdio.js +0 -0
  11. package/dist/data/onboarding-prompts.json +70 -70
  12. package/dist/error-handlers.js +0 -0
  13. package/dist/handlers/filesystem-handlers.js +2 -2
  14. package/dist/index.js +0 -0
  15. package/dist/npm-scripts/remote.js +34 -19
  16. package/dist/remote-device/diagnostics/device-log.d.ts +63 -0
  17. package/dist/remote-device/diagnostics/device-log.js +219 -0
  18. package/dist/remote-device/diagnostics/redact.d.ts +1 -0
  19. package/dist/remote-device/diagnostics/redact.js +76 -0
  20. package/dist/remote-device/diagnostics/report.d.ts +118 -0
  21. package/dist/remote-device/diagnostics/report.js +748 -0
  22. package/dist/remote-device/diagnostics/upload.d.ts +11 -0
  23. package/dist/remote-device/diagnostics/upload.js +59 -0
  24. package/dist/remote-device/scripts/blocking-offline-update.js +133 -133
  25. package/dist/search-manager.js +0 -0
  26. package/dist/server.js +610 -610
  27. package/dist/setup-claude-server.js +942 -942
  28. package/dist/terminal-manager.js +0 -0
  29. package/dist/tools/edit.js +2 -2
  30. package/dist/tools/fuzzySearch.js +9 -9
  31. package/dist/tools/improved-process-tools.js +10 -10
  32. package/dist/tools/pdf/extract-images.js +1 -1
  33. package/dist/tools/prompts.js +1 -1
  34. package/dist/track-installation.js +387 -387
  35. package/dist/types.js +0 -0
  36. package/dist/ui/config-editor/index.html +13 -13
  37. package/dist/ui/config-editor/src/app.js +30 -30
  38. package/dist/ui/config-editor/src/array-modal.js +32 -32
  39. package/dist/ui/config-editor/styles.css +586 -586
  40. package/dist/ui/file-preview/index.html +16 -16
  41. package/dist/ui/file-preview/src/app.js +8 -8
  42. package/dist/ui/file-preview/src/document-layout.js +31 -31
  43. package/dist/ui/file-preview/src/document-outline.js +8 -8
  44. package/dist/ui/file-preview/src/markdown/conflict-dialog.js +33 -33
  45. package/dist/ui/file-preview/src/markdown/controller.js +9 -9
  46. package/dist/ui/file-preview/src/markdown/editor.js +31 -31
  47. package/dist/ui/file-preview/styles.css +1630 -1630
  48. package/dist/uninstall-claude-server.js +745 -745
  49. package/dist/utils/files/binary.js +4 -4
  50. package/dist/utils/files/excel.js +3 -3
  51. package/dist/utils/lazy-package.d.ts +5 -3
  52. package/dist/utils/lazy-package.js +6 -4
  53. package/dist/utils/system-info.js +90 -90
  54. package/dist/utils/usageTracker.js +49 -49
  55. package/dist/version.d.ts +1 -1
  56. package/dist/version.js +1 -1
  57. package/node_modules/@desktop-commander/telemetry-contract/README.md +56 -56
  58. package/node_modules/@desktop-commander/telemetry-contract/package.json +32 -32
  59. package/node_modules/@desktop-commander/telemetry-contract/transport.d.ts +38 -38
  60. package/node_modules/@desktop-commander/telemetry-contract/transport.js +164 -164
  61. package/package.json +29 -15
  62. package/vendor/telemetry-contract/README.md +56 -56
  63. package/vendor/telemetry-contract/package.json +32 -32
  64. package/vendor/telemetry-contract/transport.d.ts +38 -38
  65. package/vendor/telemetry-contract/transport.js +164 -164
  66. package/vendor/telemetry-contract/transport.test.js +39 -39
  67. package/dist/remote-device/broadcast-analytics.d.ts +0 -28
  68. package/dist/remote-device/broadcast-analytics.js +0 -41
  69. package/dist/remote-device/mqtt-enrollment.d.ts +0 -16
  70. package/dist/remote-device/mqtt-enrollment.js +0 -162
  71. package/dist/remote-device/mqtt-transport.d.ts +0 -44
  72. package/dist/remote-device/mqtt-transport.js +0 -197
  73. package/dist/remote-device/transport-analytics.d.ts +0 -29
  74. package/dist/remote-device/transport-analytics.js +0 -44
  75. package/dist/tools/search.d.ts +0 -32
  76. package/dist/tools/search.js +0 -202
@@ -0,0 +1,11 @@
1
+ /** The signed-in user's id from ~/.desktop-commander-device/device.json, or null. */
2
+ export declare function savedUserId(home: string): string | null;
3
+ export interface UploadOptions {
4
+ /** From /api/mcp-info; null when the server names none, and then nothing is uploaded. */
5
+ diagnosticsUrl: string | null;
6
+ userId: string | null;
7
+ deviceId: string | null;
8
+ timeoutMs?: number;
9
+ }
10
+ /** POSTs the zip and resolves the report id; rejects with a short reason. */
11
+ export declare function uploadReport(zip: Buffer, options: UploadOptions): Promise<string>;
@@ -0,0 +1,59 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ /**
4
+ * Sends the diagnostics zip to Desktop Commander's diagnostics Worker, which
5
+ * stores it for 7 days and answers with a report id the user gives support.
6
+ *
7
+ * The address comes only from the server's /api/mcp-info `diagnosticsUrl`, so
8
+ * the Worker can move without a release. When the server names none, nothing
9
+ * is uploaded and the zip stays saved.
10
+ * The ids only sort the upload into a folder: the user id is the saved access
11
+ * token's `sub`, read locally like blocking-offline-update.js reads `exp`, and
12
+ * the device id is device.json's. Nothing is refreshed, nothing signs in, and
13
+ * device.json is only read.
14
+ */
15
+ const UPLOAD_TIMEOUT_MS = 30000;
16
+ const ID_SHAPED = /^[A-Za-z0-9_-]{1,64}$/;
17
+ /** The longest piece of the Worker's error message that is shown. */
18
+ const MAX_MESSAGE_CHARS = 200;
19
+ /** The signed-in user's id from ~/.desktop-commander-device/device.json, or null. */
20
+ export function savedUserId(home) {
21
+ try {
22
+ const config = JSON.parse(fs.readFileSync(path.join(home, '.desktop-commander-device', 'device.json'), 'utf8'));
23
+ const token = config?.session?.access_token;
24
+ if (typeof token !== 'string')
25
+ return null;
26
+ const { sub } = JSON.parse(Buffer.from(token.split('.')[1] ?? '', 'base64url').toString('utf8'));
27
+ return typeof sub === 'string' && ID_SHAPED.test(sub) ? sub : null;
28
+ }
29
+ catch {
30
+ return null;
31
+ }
32
+ }
33
+ /** POSTs the zip and resolves the report id; rejects with a short reason. */
34
+ export async function uploadReport(zip, options) {
35
+ const url = options.diagnosticsUrl;
36
+ if (!url)
37
+ throw new Error('the server named no upload address');
38
+ const headers = { 'Content-Type': 'application/zip' };
39
+ if (options.userId)
40
+ headers['X-DC-User-Id'] = options.userId;
41
+ if (options.deviceId)
42
+ headers['X-DC-Device-Id'] = options.deviceId;
43
+ const response = await fetch(url, {
44
+ method: 'POST',
45
+ headers,
46
+ body: new Uint8Array(zip),
47
+ signal: AbortSignal.timeout(options.timeoutMs ?? UPLOAD_TIMEOUT_MS),
48
+ });
49
+ const body = await response.json().catch(() => null);
50
+ if (!response.ok) {
51
+ // The Worker answers errors as {code, message}: show its message, on one short line
52
+ const message = typeof body?.message === 'string' ? body.message.replace(/\s+/g, ' ').trim().slice(0, MAX_MESSAGE_CHARS) : '';
53
+ throw new Error(`the server answered ${response.status}${message ? `: ${message}` : ''}`);
54
+ }
55
+ const id = body?.id;
56
+ if (typeof id !== 'string' || !ID_SHAPED.test(id))
57
+ throw new Error('the server gave no report id');
58
+ return id;
59
+ }
@@ -1,133 +1,133 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Blocking script to update device status to offline
5
- * Runs synchronously during shutdown to ensure DB update completes
6
- *
7
- * Usage: node blocking-offline-update.js <deviceId> <supabaseUrl> <supabaseKey> <accessToken> [refreshToken]
8
- * Without a refreshToken only a still-valid accessToken can be used.
9
- *
10
- * Ends through exitProcess(), never process.exit(): process.exit() right after
11
- * the update's fetch() can abort Node on Windows with exit code 0xC0000409
12
- * (see src/utils/exit-process.ts), and the parent then reports a failed update.
13
- */
14
-
15
- import { createClient } from '@supabase/supabase-js';
16
-
17
- // The build copies this script to dist/remote-device/scripts/, next to the
18
- // compiled dist/utils/exit-process.js. Run from a source checkout (npm run
19
- // device:start starts it with plain node, without tsx) it loads the checkout's
20
- // build, dist/utils/exit-process.js (npm install builds it), which works on
21
- // every Node version. Without a build it falls back to
22
- // src/utils/exit-process.ts, which only Node 22.18+ loads (by stripping types).
23
- const ifNotFound = (importNext) => (error) => {
24
- if (error.code !== 'ERR_MODULE_NOT_FOUND') throw error;
25
- return importNext();
26
- };
27
- const { exitProcess, EXIT_GRACE_MS } = await import('../../utils/exit-process.js')
28
- .catch(ifNotFound(() => import('../../../dist/utils/exit-process.js')))
29
- .catch(ifNotFound(() => import('../../utils/exit-process.ts')));
30
-
31
- // Parse command line arguments
32
- const [deviceId, supabaseUrl, supabaseKey, accessToken, refreshToken] = process.argv.slice(2);
33
-
34
- if (!deviceId || !supabaseUrl || !supabaseKey || !accessToken) {
35
- console.error('❌ Missing required arguments');
36
- console.error('Usage: node blocking-offline-update.js <deviceId> <supabaseUrl> <supabaseKey> <accessToken> [refreshToken]');
37
- exitProcess(1);
38
- } else {
39
- await markDeviceOffline();
40
- }
41
-
42
- async function markDeviceOffline() {
43
- // The parent (setOffline() in remote-channel.ts) kills this script 3000ms
44
- // after starting it. The update gets that time, counted from the start of
45
- // the process, minus what the process may need to end once it gives up.
46
- const PARENT_TIMEOUT_MS = 3000;
47
- const deadline = new AbortController();
48
- const timeoutHandle = setTimeout(() => {
49
- console.error('⏱️ Timeout: Update took too long');
50
- exitProcess(2); // Exit code 2 for timeout
51
- // Ends the requests still in flight, which would keep the process alive
52
- deadline.abort();
53
- }, PARENT_TIMEOUT_MS - EXIT_GRACE_MS - performance.now());
54
-
55
- const auth = { persistSession: false, autoRefreshToken: false };
56
- const fetchBeforeDeadline = (input, init) => fetch(input, { ...init, signal: deadline.signal });
57
-
58
- // Update device status to offline, stamping the exact shutdown moment so
59
- // "last seen X ago" is precise for clean shutdowns (the periodic
60
- // bookkeeping write only runs on the slow capable cadence).
61
- // The token goes straight to PostgREST as a Bearer header: setSession()
62
- // would first spend a GoTrue round trip of the budget re-validating it.
63
- const markOffline = (token) => createClient(supabaseUrl, supabaseKey, {
64
- auth,
65
- global: { headers: { Authorization: `Bearer ${token}` }, fetch: fetchBeforeDeadline }
66
- })
67
- .from('mcp_devices')
68
- .update({ status: 'offline', last_seen: new Date().toISOString() })
69
- .eq('id', deviceId);
70
-
71
- function tokenLooksLive(token) {
72
- try {
73
- const { exp } = JSON.parse(Buffer.from(token.split('.')[1], 'base64url').toString('utf8'));
74
- return typeof exp === 'number' && exp * 1000 > Date.now() + 5000;
75
- } catch {
76
- // Not a JWT we can read: treat it as expired and refresh the session
77
- return false;
78
- }
79
- }
80
-
81
- // refreshSession(), not setSession(): setSession() validates a token that
82
- // looks live on this machine's clock via /user instead of refreshing it.
83
- // Resolves with the new access token, or undefined after reporting why there is none.
84
- async function refreshedToken() {
85
- if (!refreshToken) {
86
- console.error('❌ Auth error: access token not usable and no refresh token');
87
- return undefined;
88
- }
89
- const client = createClient(supabaseUrl, supabaseKey, { auth, global: { fetch: fetchBeforeDeadline } });
90
- const { data, error: authError } = await client.auth.refreshSession({ refresh_token: refreshToken });
91
-
92
- if (authError || !data.session) {
93
- console.error('❌ Auth error:', authError?.message ?? 'no session returned');
94
- return undefined;
95
- }
96
- return data.session.access_token;
97
- }
98
-
99
- // Resolves with the exit code
100
- async function update() {
101
- try {
102
- // An expired token (e.g. the machine just woke) is refreshed first. A 401
103
- // means it only looked live on this machine's clock: refresh and retry once.
104
- let result = tokenLooksLive(accessToken) ? await markOffline(accessToken) : null;
105
- if (!result || result.status === 401) {
106
- const token = await refreshedToken();
107
- if (!token) {
108
- return 3; // Exit code 3 for auth error
109
- }
110
- result = await markOffline(token);
111
- }
112
-
113
- const { error } = result;
114
-
115
- if (error) {
116
- console.error('❌ DB update error:', error.message);
117
- return 4; // Exit code 4 for DB error
118
- }
119
-
120
- console.log('✓ Device marked as offline');
121
- return 0; // Success
122
-
123
- } catch (error) {
124
- console.error('❌ Unexpected error:', error.message);
125
- return 5; // Exit code 5 for unexpected error
126
- }
127
- }
128
-
129
- const code = await update();
130
- clearTimeout(timeoutHandle);
131
- // After a timeout the exit code stays 2 (only exitProcess()'s first call counts)
132
- exitProcess(code);
133
- }
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Blocking script to update device status to offline
5
+ * Runs synchronously during shutdown to ensure DB update completes
6
+ *
7
+ * Usage: node blocking-offline-update.js <deviceId> <supabaseUrl> <supabaseKey> <accessToken> [refreshToken]
8
+ * Without a refreshToken only a still-valid accessToken can be used.
9
+ *
10
+ * Ends through exitProcess(), never process.exit(): process.exit() right after
11
+ * the update's fetch() can abort Node on Windows with exit code 0xC0000409
12
+ * (see src/utils/exit-process.ts), and the parent then reports a failed update.
13
+ */
14
+
15
+ import { createClient } from '@supabase/supabase-js';
16
+
17
+ // The build copies this script to dist/remote-device/scripts/, next to the
18
+ // compiled dist/utils/exit-process.js. Run from a source checkout (npm run
19
+ // device:start starts it with plain node, without tsx) it loads the checkout's
20
+ // build, dist/utils/exit-process.js (npm install builds it), which works on
21
+ // every Node version. Without a build it falls back to
22
+ // src/utils/exit-process.ts, which only Node 22.18+ loads (by stripping types).
23
+ const ifNotFound = (importNext) => (error) => {
24
+ if (error.code !== 'ERR_MODULE_NOT_FOUND') throw error;
25
+ return importNext();
26
+ };
27
+ const { exitProcess, EXIT_GRACE_MS } = await import('../../utils/exit-process.js')
28
+ .catch(ifNotFound(() => import('../../../dist/utils/exit-process.js')))
29
+ .catch(ifNotFound(() => import('../../utils/exit-process.ts')));
30
+
31
+ // Parse command line arguments
32
+ const [deviceId, supabaseUrl, supabaseKey, accessToken, refreshToken] = process.argv.slice(2);
33
+
34
+ if (!deviceId || !supabaseUrl || !supabaseKey || !accessToken) {
35
+ console.error('❌ Missing required arguments');
36
+ console.error('Usage: node blocking-offline-update.js <deviceId> <supabaseUrl> <supabaseKey> <accessToken> [refreshToken]');
37
+ exitProcess(1);
38
+ } else {
39
+ await markDeviceOffline();
40
+ }
41
+
42
+ async function markDeviceOffline() {
43
+ // The parent (setOffline() in remote-channel.ts) kills this script 3000ms
44
+ // after starting it. The update gets that time, counted from the start of
45
+ // the process, minus what the process may need to end once it gives up.
46
+ const PARENT_TIMEOUT_MS = 3000;
47
+ const deadline = new AbortController();
48
+ const timeoutHandle = setTimeout(() => {
49
+ console.error('⏱️ Timeout: Update took too long');
50
+ exitProcess(2); // Exit code 2 for timeout
51
+ // Ends the requests still in flight, which would keep the process alive
52
+ deadline.abort();
53
+ }, PARENT_TIMEOUT_MS - EXIT_GRACE_MS - performance.now());
54
+
55
+ const auth = { persistSession: false, autoRefreshToken: false };
56
+ const fetchBeforeDeadline = (input, init) => fetch(input, { ...init, signal: deadline.signal });
57
+
58
+ // Update device status to offline, stamping the exact shutdown moment so
59
+ // "last seen X ago" is precise for clean shutdowns (the periodic
60
+ // bookkeeping write only runs on the slow capable cadence).
61
+ // The token goes straight to PostgREST as a Bearer header: setSession()
62
+ // would first spend a GoTrue round trip of the budget re-validating it.
63
+ const markOffline = (token) => createClient(supabaseUrl, supabaseKey, {
64
+ auth,
65
+ global: { headers: { Authorization: `Bearer ${token}` }, fetch: fetchBeforeDeadline }
66
+ })
67
+ .from('mcp_devices')
68
+ .update({ status: 'offline', last_seen: new Date().toISOString() })
69
+ .eq('id', deviceId);
70
+
71
+ function tokenLooksLive(token) {
72
+ try {
73
+ const { exp } = JSON.parse(Buffer.from(token.split('.')[1], 'base64url').toString('utf8'));
74
+ return typeof exp === 'number' && exp * 1000 > Date.now() + 5000;
75
+ } catch {
76
+ // Not a JWT we can read: treat it as expired and refresh the session
77
+ return false;
78
+ }
79
+ }
80
+
81
+ // refreshSession(), not setSession(): setSession() validates a token that
82
+ // looks live on this machine's clock via /user instead of refreshing it.
83
+ // Resolves with the new access token, or undefined after reporting why there is none.
84
+ async function refreshedToken() {
85
+ if (!refreshToken) {
86
+ console.error('❌ Auth error: access token not usable and no refresh token');
87
+ return undefined;
88
+ }
89
+ const client = createClient(supabaseUrl, supabaseKey, { auth, global: { fetch: fetchBeforeDeadline } });
90
+ const { data, error: authError } = await client.auth.refreshSession({ refresh_token: refreshToken });
91
+
92
+ if (authError || !data.session) {
93
+ console.error('❌ Auth error:', authError?.message ?? 'no session returned');
94
+ return undefined;
95
+ }
96
+ return data.session.access_token;
97
+ }
98
+
99
+ // Resolves with the exit code
100
+ async function update() {
101
+ try {
102
+ // An expired token (e.g. the machine just woke) is refreshed first. A 401
103
+ // means it only looked live on this machine's clock: refresh and retry once.
104
+ let result = tokenLooksLive(accessToken) ? await markOffline(accessToken) : null;
105
+ if (!result || result.status === 401) {
106
+ const token = await refreshedToken();
107
+ if (!token) {
108
+ return 3; // Exit code 3 for auth error
109
+ }
110
+ result = await markOffline(token);
111
+ }
112
+
113
+ const { error } = result;
114
+
115
+ if (error) {
116
+ console.error('❌ DB update error:', error.message);
117
+ return 4; // Exit code 4 for DB error
118
+ }
119
+
120
+ console.log('✓ Device marked as offline');
121
+ return 0; // Success
122
+
123
+ } catch (error) {
124
+ console.error('❌ Unexpected error:', error.message);
125
+ return 5; // Exit code 5 for unexpected error
126
+ }
127
+ }
128
+
129
+ const code = await update();
130
+ clearTimeout(timeoutHandle);
131
+ // After a timeout the exit code stays 2 (only exitProcess()'s first call counts)
132
+ exitProcess(code);
133
+ }
File without changes